Скачиваний:
23
Добавлен:
02.05.2014
Размер:
11.96 Кб
Скачать
// JennyDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Jenny.h"
#include "JennyDlg.h"
#include "fstream.h"
#include "math.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
 CAboutDlg();

// Dialog Data
 //{{AFX_DATA(CAboutDlg)
 enum { IDD = IDD_ABOUTBOX };
 //}}AFX_DATA

 // ClassWizard generated virtual function overrides
 //{{AFX_VIRTUAL(CAboutDlg)
 protected:
 virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
 //}}AFX_VIRTUAL

// Implementation
protected:
 //{{AFX_MSG(CAboutDlg)
 //}}AFX_MSG
 DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
 //{{AFX_DATA_INIT(CAboutDlg)
 //}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
 CDialog::DoDataExchange(pDX);
 //{{AFX_DATA_MAP(CAboutDlg)
 //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
 //{{AFX_MSG_MAP(CAboutDlg)
  // No message handlers
 //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CJennyDlg dialog

CJennyDlg::CJennyDlg(CWnd* pParent /*=NULL*/)
 : CDialog(CJennyDlg::IDD, pParent)
{
 //{{AFX_DATA_INIT(CJennyDlg)
 m_f1 = _T("");
 m_f2 = _T("");
 //}}AFX_DATA_INIT
 // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CJennyDlg::DoDataExchange(CDataExchange* pDX)
{
 CDialog::DoDataExchange(pDX);
 //{{AFX_DATA_MAP(CJennyDlg)
 DDX_Control(pDX, IDC_LIST3, m_cod2);
 DDX_Control(pDX, IDC_LIST2, m_cod3);
 DDX_Control(pDX, IDC_LIST1, m_cod);
 DDX_Text(pDX, IDC_EDIT1, m_f1);
 DDX_Text(pDX, IDC_EDIT2, m_f2);
 //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CJennyDlg, CDialog)
 //{{AFX_MSG_MAP(CJennyDlg)
 ON_WM_SYSCOMMAND()
 ON_WM_PAINT()
 ON_WM_QUERYDRAGICON()
 ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
 ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
 ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
 //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CJennyDlg message handlers

BOOL CJennyDlg::OnInitDialog()
{
 CDialog::OnInitDialog();

 // Add "About..." menu item to system menu.

 // IDM_ABOUTBOX must be in the system command range.
 ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
 ASSERT(IDM_ABOUTBOX < 0xF000);

 CMenu* pSysMenu = GetSystemMenu(FALSE);
 if (pSysMenu != NULL)
 {
  CString strAboutMenu;
  strAboutMenu.LoadString(IDS_ABOUTBOX);
  if (!strAboutMenu.IsEmpty())
  {
   pSysMenu->AppendMenu(MF_SEPARATOR);
   pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  }
 }

 // Set the icon for this dialog.  The framework does this automatically
 //  when the application's main window is not a dialog
 SetIcon(m_hIcon, TRUE); // Set big icon
 SetIcon(m_hIcon, FALSE); // Set small icon
 
 // TODO: Add extra initialization here
 
 return TRUE;  // return TRUE  unless you set the focus to a control
}

void CJennyDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
 if ((nID & 0xFFF0) == IDM_ABOUTBOX)
 {
  CAboutDlg dlgAbout;
  dlgAbout.DoModal();
 }
 else
 {
  CDialog::OnSysCommand(nID, lParam);
 }
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CJennyDlg::OnPaint() 
{
 if (IsIconic())
 {
  CPaintDC dc(this); // device context for painting

  SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

  // Center icon in client rectangle
  int cxIcon = GetSystemMetrics(SM_CXICON);
  int cyIcon = GetSystemMetrics(SM_CYICON);
  CRect rect;
  GetClientRect(&rect);
  int x = (rect.Width() - cxIcon + 1) / 2;
  int y = (rect.Height() - cyIcon + 1) / 2;

  // Draw the icon
  dc.DrawIcon(x, y, m_hIcon);
 }
 else
 {
  CDialog::OnPaint();
 }
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CJennyDlg::OnQueryDragIcon()
{
 return (HCURSOR) m_hIcon;
}

int CJennyDlg::OnButton1() //начало обработки первого файла
{
UpdateData(true); 
int n=0;
int in=0;
int f1st = 3;
char tmp[100];
char F1[100][100][100];

for(int cou = m_cod.GetCount();cou > -1;cou--)
{
m_cod.DeleteString(cou);
}
for(cou = m_cod3.GetCount();cou > -1;cou--)
{
m_cod3.DeleteString(cou);
}



if(m_f1==""){m_cod.AddString("Введите название файла!");return 0;}
ifstream f1(m_f1);

if(f1.fail()){m_cod.AddString("Невозможно открыть файл!");}
while(!f1.eof())
{
f1.getline(tmp,sizeof(tmp)+1,'\t');       
strncpy(F1[(in)/(f1st)][in%(f1st)],tmp,30);
if(in%(f1st)==0)                                                
 {                                                               
  if((in)/(f1st)>0)                                            
  {                                                              
   for(int i=0;i<sizeof(F1[in/(f1st)][in%(f1st)]);i++)           
   F1[(in)/(f1st)][in%(f1st)][i]=F1[(in)/(f1st)][in%(f1st)][i+1];
  }                                                              
 }                                                               
  in++;                                  
}
f1.close();

n = in/(f1st);  

ofstream f6("cor1.txt");

CString st;
CString st2,st3;
for(int i=0;i<n;i++)
{
st=F1[i][0];
st2 = F1[i][1];
st3=F1[i][2];
m_cod.AddString(st+"\t"+st2+"\t"+st3); 
}


CString re;
 for(i=0;i<in/f1st;i++)
 for(int j=i+1;j<in/f1st;j++)
{
  if((strcmpi(F1[i][0],F1[j][0]))==0){re=F1[i][0];m_cod.AddString("Код <" + re + "> должен быть уникальным!");strcpy(F1[i][0],"");strcpy(F1[j][0],"");}

  
if(((strcmpi(F1[i][1],F1[j][1]))==0)&&((strcmpi(F1[i][2],F1[j][2]))==0))
{
if((strcmpi(F1[i][0],F1[j][0]))!=0){re=F1[i][1];m_cod.AddString("У одного альбома <" + re + "> не может быть двух разных кодов!!!");}
}

if(((strcmpi(F1[i][1],F1[j][1]))==0)&&((strcmpi(F1[i][2],F1[j][2]))==0))
{
if((strcmpi(F1[i][0],F1[j][0]))==0){re=F1[i][0];m_cod.AddString("Альбом <" + re + "> записан больше 1 раза!!!");}
}

}


for(int y=0;y<n;y++)
 for(int h=0;h<20;h++)
{

  if((F1[y][0][h]<'0'||F1[y][0][h]>'9')&&strlen(F1[y][0])>h){re=F1[y][0];m_cod.AddString("Код диска <" + re + "> не может");m_cod.AddString("содержать буквы!!!");}
     if((F1[y][1][h]<'9'&&F1[y][1][h]>'0')&&strlen(F1[y][1])>h){re=F1[y][1];m_cod.AddString("Название диска <" + re + "> не может");m_cod.AddString("содержать цифры!!!");}
   if((F1[y][2][h]<'9'&&F1[y][2][h]>'0')&&strlen(F1[y][2])>h){re=F1[y][2];m_cod.AddString("Название исполнителя <" + re + "> не может");m_cod.AddString("содержать цифры!!!");}
} 

for(y=0;y<n;y++)
{
 if((strcmpi(F1[y][0],""))==0){int lkl = 0;}
 else f6 << F1[y][0] << "\t" << F1[y][1] << "\t" << F1[y][2] <<"\t\n";
} 

return 0;
 
}

int CJennyDlg::OnButton2() //обработка второго файла
{
UpdateData(true);
char F2[100][100][100];
int z=0;
int in=0;
int f2st=4;
char tmp[100];
CString st,st1,st2,st3;
for(int cou = m_cod2.GetCount();cou > -1;cou--)
{
m_cod2.DeleteString(cou);
}
for(cou = m_cod3.GetCount();cou > -1;cou--)
{
m_cod3.DeleteString(cou);
}


if(m_f2==""){m_cod2.AddString("Введите название файла!");return 0;}
ifstream f2(m_f2);
if(f2.fail()){m_cod2.AddString("Невозможно открыть файл!");return 0;}
while(!f2.eof())
{
 f2.getline(tmp,sizeof(tmp)+1,'\t');       
strncpy(F2[(in)/(f2st)][in%(f2st)],tmp,50);
  
  if(in%(f2st)==0)                                                
  {                                                               
   if((in)/(f2st)>0)                                            
   {                                                              
    for(int i=0;i<sizeof(F2[in/(f2st)][in%(f2st)]);i++)           
    F2[(in)/(f2st)][in%(f2st)][i]=F2[(in)/(f2st)][in%(f2st)][i+1];
   }                                                              
  }                                                               

  in++;                                  
 }
f2.close();

z=in/(f2st); 

for(int i=0;i<z;i++)
{
st=F2[i][0];
st1=F2[i][1];
st2=F2[i][2];
st3=F2[i][3];
m_cod2.AddString(st+"\t"+st1+"\t"+st2+"\t"+st3);
} 



for(int y=0;y<z;y++)
 for(int h=0;h<20;h++)
{
CString re;
 if((F2[y][0][h]<'0'||F2[y][0][h]>'9')&&strlen(F2[y][0])>h){re=F2[y][0];m_cod2.AddString("Код диска <" + re + "> не может");m_cod2.AddString("содержать буквы!!!");}
    if((F2[y][3][h]<'0'||F2[y][3][h]>'9')&&strlen(F2[y][3])>h){re=F2[y][0];m_cod2.AddString("Количесто дисков <" + re + "> не может");m_cod2.AddString("содержать буквы!!!");}
 if((F2[y][2][h]<'0'||F2[y][2][h]>'9')&&strlen(F2[y][2])>h){re=F2[y][0];m_cod2.AddString("Дата <" + re + "> не может");m_cod2.AddString("содержать буквы!!!");}
 if((F2[y][1][h]<'9'&&F2[y][1][h]>'0')&&strlen(F2[y][1])>h){re=F2[y][1];m_cod2.AddString("Название магазина <" + re + "> не может");m_cod2.AddString("содержать цифры!!!");}
}




return 0; 
}


void CJennyDlg::OnButton3() 
{
UpdateData(true);
const int f1st=3,f2st=4;
int in=0,n=0,z=0;
char tmp[100];
int k=0;
int sumpd=0,sumo=0;                  
      
char F1[100][100][100];
char F2[50][f2st][50];
//char tmp2[100];
 
ifstream f("cor1.txt");
ifstream f2(m_f2);
 

while(!f.eof())
{
f.getline(tmp,sizeof(tmp)+1,'\t');       
strncpy(F1[(in)/(f1st)][in%(f1st)],tmp,50);

if(in%(f1st)==0)                                                
 {                                                               
  if((in)/(f1st)>0)                                            
  {                                                              
   for(int i=0;i<sizeof(F1[in/(f1st)][in%(f1st)]);i++)           
   F1[(in)/(f1st)][in%(f1st)][i]=F1[(in)/(f1st)][in%(f1st)][i+1];
  }                                                              
 }                                                               
  in++;                                  
}
f.close();
n = in/(f1st);  

in=0;

while(!f2.eof())
{
 f2.getline(tmp,sizeof(tmp)+1,'\t');       

 strncpy(F2[(in)/(f2st)][in%(f2st)],tmp,50);
  
  if(in%(f2st)==0)                                                
  {                                                               
   if((in)/(f2st)>0)                                            
   {                                                              
    for(int i=0;i<sizeof(F2[in/(f2st)][in%(f2st)]);i++)           
    F2[(in)/(f2st)][in%(f2st)][i]=F2[(in)/(f2st)][in%(f2st)][i+1];
   }                                                              
  }                                                               

  in++;                                  
 }

f2.close();

z=in/(f2st); 
char tmp2[100];
char tmp3[500];

strncpy(tmp2,F2[0][2],50);
CString st,st1,st2,st3,st4;
 
ofstream f3("f3.txt");
for (int v=0;v<z+1;v++)
{
if(((strcmpi(F2[v][2],"}"))!=0)&&(v!=0))
{
 strncpy(tmp2,F2[v][2],50);
f3<<"Общая сумма продаж по дате: "<< sumpd <<" дисков\n\n";
sumo = sumo + sumpd;
sumpd=0;
}

for(int u=0;u<z;u++)
     for(int y=0;y<n;y++)
   {
     if((strcmpi(F2[u][0],F1[y][0]))==0)
    {
      if((strcmpi(F2[u][2],tmp2))==0)
   {
    
 
  f3<<F2[u][2]<<"\t"<<F1[y][1]<<"\t"<<F2[u][1]<<"\t" << F2[u][3]<<"\n";
        strncpy(F2[u][2],"}",50);
  sumpd+=atoi(F2[u][3]);
   } 
    }

   } 
 
}
f3 << "Общаяя сумма продаж по всем датам: " << sumo << " дисков";
f3.close();
ifstream f7("f3.txt");
in=0;

while(!f7.eof())
{
f7.getline(tmp3,sizeof(tmp3)+1,'\n');
strcpy(F1[0][in],tmp3);
in++;
}

for(int p=0;p<in;p++)
{
m_cod3.AddString(F1[0][p]);

}



}

	

Соседние файлы в папке Jenny_dodelal