Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
RSEnalotto 1.0 - SuperenalottoDlg.cpp

SuperenalottoDlg.cpp

Caricato da: Piero Tofy
Scarica il programma completo

  1. // SuperenalottoDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Superenalotto.h"
  6. #include "SuperenalottoDlg.h"
  7. #include <iostream.h>
  8. #include <fstream.h>
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CAboutDlg dialog used for App About
  19.  
  20. class CAboutDlg : public CDialog
  21. {
  22. public:
  23.         CAboutDlg();
  24.  
  25. // Dialog Data
  26.         //{{AFX_DATA(CAboutDlg)
  27.         enum { IDD = IDD_ABOUTBOX };
  28.         //}}AFX_DATA
  29.  
  30.         // ClassWizard generated virtual function overrides
  31.         //{{AFX_VIRTUAL(CAboutDlg)
  32.         protected:
  33.         virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  34.         //}}AFX_VIRTUAL
  35.  
  36. // Implementation
  37. protected:
  38.         //{{AFX_MSG(CAboutDlg)
  39.         //}}AFX_MSG
  40.         DECLARE_MESSAGE_MAP()
  41. };
  42.  
  43. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  44. {
  45.         //{{AFX_DATA_INIT(CAboutDlg)
  46.         //}}AFX_DATA_INIT
  47. }
  48.  
  49. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  50. {
  51.         CDialog::DoDataExchange(pDX);
  52.         //{{AFX_DATA_MAP(CAboutDlg)
  53.         //}}AFX_DATA_MAP
  54. }
  55.  
  56. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  57.         //{{AFX_MSG_MAP(CAboutDlg)
  58.                 // No message handlers
  59.         //}}AFX_MSG_MAP
  60. END_MESSAGE_MAP()
  61.  
  62. /////////////////////////////////////////////////////////////////////////////
  63. // CSuperenalottoDlg dialog
  64.  
  65. CSuperenalottoDlg::CSuperenalottoDlg(CWnd* pParent /*=NULL*/)
  66.         : CDialog(CSuperenalottoDlg::IDD, pParent)
  67. {
  68.         //{{AFX_DATA_INIT(CSuperenalottoDlg)
  69.         m_bChk0 = FALSE;
  70.         m_bChk1 = FALSE;
  71.         m_bChk2 = FALSE;
  72.         m_bChk3 = FALSE;
  73.         m_bChk4 = FALSE;
  74.         m_bChk5 = FALSE;
  75.         m_bChk6 = FALSE;
  76.         i_CountScArchivio=0;
  77.         //}}AFX_DATA_INIT
  78.         m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  79. }
  80.  
  81. void CSuperenalottoDlg::DoDataExchange(CDataExchange* pDX)
  82. {
  83.         CDialog::DoDataExchange(pDX);
  84.         //{{AFX_DATA_MAP(CSuperenalottoDlg)
  85.         DDX_Control(pDX, IDC_PSBAR, m_cPsbar);
  86.         DDX_Check(pDX, IDC_CHK0, m_bChk0);
  87.         DDX_Check(pDX, IDC_CHK1, m_bChk1);
  88.         DDX_Check(pDX, IDC_CHK2, m_bChk2);
  89.         DDX_Check(pDX, IDC_CHK3, m_bChk3);
  90.         DDX_Check(pDX, IDC_CHK4, m_bChk4);
  91.         DDX_Check(pDX, IDC_CHK5, m_bChk5);
  92.         DDX_Check(pDX, IDC_CHK6, m_bChk6);
  93.         //}}AFX_DATA_MAP
  94. }
  95.  
  96. BEGIN_MESSAGE_MAP(CSuperenalottoDlg, CDialog)
  97.         //{{AFX_MSG_MAP(CSuperenalottoDlg)
  98.         ON_WM_SYSCOMMAND()
  99.         ON_WM_PAINT()
  100.         ON_WM_QUERYDRAGICON()
  101.         ON_COMMAND(IDM_FILE_EXIT, OnFileExit)
  102.         ON_BN_CLICKED(IDC_BIARCHIVIO, OnBiarchivio)
  103.         ON_BN_CLICKED(IDC_BISISTEMA, OnBiSistema)
  104.         ON_BN_CLICKED(IDC_BLSISTEMA, OnBlSistema)
  105.         ON_BN_CLICKED(IDC_BLARCHIVIO, OnBlarchivio)
  106.         ON_BN_CLICKED(IDC_CHK3, OnChk3)
  107.         ON_BN_CLICKED(IDC_CHK0, OnChk0)
  108.         ON_BN_CLICKED(IDC_CHK1, OnChk1)
  109.         ON_BN_CLICKED(IDC_CHK2, OnChk2)
  110.         ON_BN_CLICKED(IDC_CHK4, OnChk4)
  111.         ON_BN_CLICKED(IDC_CHK5, OnChk5)
  112.         ON_BN_CLICKED(IDC_CHK6, OnChk6)
  113.         ON_BN_CLICKED(IDC_BSEXPORT, OnBsexport)
  114.         ON_EN_UPDATE(IDC_EE0, OnUpdateEe0)
  115.         ON_EN_UPDATE(IDC_EE1, OnUpdateEe1)
  116.         ON_EN_UPDATE(IDC_EE2, OnUpdateEe2)
  117.         ON_EN_UPDATE(IDC_EE3, OnUpdateEe3)
  118.         ON_EN_UPDATE(IDC_EE4, OnUpdateEe4)
  119.         ON_EN_UPDATE(IDC_EE5, OnUpdateEe5)
  120.         ON_EN_UPDATE(IDC_EE6, OnUpdateEe6)
  121.         ON_BN_CLICKED(IDC_BESEGUI, OnBesegui)
  122.         ON_COMMAND(IDM_INFO_ABOUT, OnInfoAbout)
  123.         //}}AFX_MSG_MAP
  124. END_MESSAGE_MAP()
  125.  
  126. /////////////////////////////////////////////////////////////////////////////
  127. // CSuperenalottoDlg message handlers
  128.  
  129. BOOL CSuperenalottoDlg::OnInitDialog()
  130. {
  131.         CDialog::OnInitDialog();
  132.  
  133.         // Add "About..." menu item to system menu.
  134.  
  135.         // IDM_ABOUTBOX must be in the system command range.
  136.         ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  137.         ASSERT(IDM_ABOUTBOX < 0xF000);
  138.  
  139.         CMenu* pSysMenu = GetSystemMenu(FALSE);
  140.         if (pSysMenu != NULL)
  141.         {
  142.                 CString strAboutMenu;
  143.                 strAboutMenu.LoadString(IDS_ABOUTBOX);
  144.                 if (!strAboutMenu.IsEmpty())
  145.                 {
  146.                         pSysMenu->AppendMenu(MF_SEPARATOR);
  147.                         pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  148.                 }
  149.         }
  150.  
  151.         SetIcon(m_hIcon, TRUE);                 // Set big icon
  152.         SetIcon(m_hIcon, FALSE);                // Set small icon
  153.        
  154.         // TODO: Add extra initialization here
  155.         UpdateData(FALSE);
  156.         i_CountScExport = 0;
  157.         i_CountScSistema = 0;
  158.         s_ArchivioFileName="Enalotto.txt";
  159.         s_SistemaFileName="Sviluppo.txt";
  160.         s_ArchivioPath=GetProgramDir() + "\\" + s_ArchivioFileName;
  161.         s_SistemaPath=GetProgramDir() + "\\" + s_SistemaFileName;
  162.  
  163.  
  164.         if (File_Exists(s_ArchivioPath)){
  165.                 SetDlgItemText(IDC_BIARCHIVIO,"File: " + s_ArchivioFileName);
  166.                 b_ArchivioFileSelected = TRUE;
  167.         }
  168.         if (File_Exists(s_SistemaPath)){
  169.                 SetDlgItemText(IDC_BISISTEMA,"File: " + s_SistemaFileName);
  170.                 b_SistemaFileSelected=TRUE;
  171.         }
  172.  
  173.         //i_ArchivioLines = GetFileLines(s_ArchivioPath);
  174.         //i_SistemaLines = GetFileLines(s_SistemaPath);
  175.  
  176.         return TRUE;  // return TRUE  unless you set the focus to a control
  177. }
  178.  
  179. void CSuperenalottoDlg::OnSysCommand(UINT nID, LPARAM lParam)
  180. {
  181.         if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  182.         {
  183.                 CAboutDlg dlgAbout;
  184.                 dlgAbout.DoModal();
  185.         }
  186.         else
  187.         {
  188.                 CDialog::OnSysCommand(nID, lParam);
  189.         }
  190. }
  191.  
  192. // If you add a minimize button to your dialog, you will need the code below
  193. //  to draw the icon.  For MFC applications using the document/view model,
  194. //  this is automatically done for you by the framework.
  195.  
  196. void CSuperenalottoDlg::OnPaint()
  197. {
  198.  
  199.         if (IsIconic())
  200.         {
  201.                 CPaintDC dc(this); // device context for painting
  202.  
  203.                 SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  204.  
  205.                 // Center icon in client rectangle
  206.                 int cxIcon = GetSystemMetrics(SM_CXICON);
  207.                 int cyIcon = GetSystemMetrics(SM_CYICON);
  208.                 CRect rect;
  209.                 GetClientRect(&rect);
  210.                 int x = (rect.Width() - cxIcon + 1) / 2;
  211.                 int y = (rect.Height() - cyIcon + 1) / 2;
  212.  
  213.                 // Draw the icon
  214.                 dc.DrawIcon(x, y, m_hIcon);
  215.         }
  216.         else
  217.         {
  218.                 CDialog::OnPaint();
  219.         }
  220. }
  221.  
  222. HCURSOR CSuperenalottoDlg::OnQueryDragIcon()
  223. {
  224.         return (HCURSOR) m_hIcon;
  225. }
  226.  
  227. void CSuperenalottoDlg::OnFileExit()
  228. {
  229.         OnOK();
  230. }
  231.  
  232. void CSuperenalottoDlg::GetArchivio()
  233. {
  234.         char c_Date[9]="";
  235.         int i_Number=0;
  236.         int i_CountNumber=0;
  237.         bool b_is_zero = FALSE;
  238.  
  239.         ifstream in(s_ArchivioPath, ios::in);
  240.  
  241.         do{
  242.                 //La data
  243.                 in >> c_Date;
  244.                 //ID della sestina (non serve)
  245.                 in >> i_Number;
  246.  
  247.                 //Numeri
  248.                 while(i_CountNumber<6){
  249.                         in >> i_Number;
  250.                        
  251.                         sc_Archivio[i_CountScArchivio].SetNumber(i_CountNumber++,i_Number);
  252.                
  253.                         if (!i_Number) b_is_zero = TRUE;
  254.                 }
  255.        
  256.                 //Numeri Jolly che non va contato...
  257.                 in >> i_Number;
  258.  
  259.                 if (b_is_zero) i_CountScArchivio--;
  260.  
  261.                 i_CountNumber=0;
  262.                 i_CountScArchivio++;
  263.                 b_is_zero = FALSE;
  264.  
  265.                 //Visualizza lo stato sulla progress bar...
  266.                 SetProgressBar((100*i_CountScArchivio)/i_ArchivioLines);
  267.                
  268.         }while(!in.eof());
  269.  
  270.         in.close();
  271.  
  272.         //Toglie l'ultimo record...
  273.         i_CountScArchivio--;
  274.  
  275.         SetProgressBar(0);
  276.  
  277. }
  278.  
  279. CString CSuperenalottoDlg::GetProgramDir()
  280. {
  281.         /* Funzione presa su Internet per determinare la dir corrente */
  282.  
  283.     CString RtnVal;
  284.     char FileName[MAX_PATH];
  285.     GetModuleFileName(AfxGetInstanceHandle(), FileName, MAX_PATH);
  286.     RtnVal = FileName;
  287.     RtnVal = RtnVal.Left(RtnVal.ReverseFind('\\'));
  288.     return RtnVal;
  289. }
  290.  
  291. void CSuperenalottoDlg::GetSistema()
  292. {
  293.         int i_Number=0;
  294.         int i_Count;
  295.         int i_Value;
  296.  
  297.         Sestina *sc_Sestina = new Sestina();
  298.         ifstream in(s_SistemaPath, ios::in);
  299.  
  300.         InitMaxSistemaNumbers();
  301.  
  302.         do{
  303.                 sc_Sestina->SetMaxValue(0);
  304.                 //Prende i numeri e li assegna ad un oggetto Sestina
  305.                 for (i_Count=0; i_Count<6; i_Count++){
  306.                         in >> i_Number;
  307.                         sc_Sestina->SetNumber(i_Count,i_Number);
  308.                 }
  309.  
  310.                 //Confronta la sestina con tutte quelle dell'archivio...
  311.                 for (i_Count=0; i_Count<i_CountScArchivio; i_Count++){
  312.                         i_Value = ConfrontaSestine(sc_Sestina,&sc_Archivio[i_Count]);
  313.                         if (i_Value > sc_Sestina->GetMaxValue()) sc_Sestina->SetMaxValue(i_Value);
  314.                 }
  315.                
  316.                 //Incrementa il contatore...
  317.                 i_MaxSistemaNumbers[sc_Sestina->GetMaxValue()]++;
  318.                 i_CountScSistema++;
  319.  
  320.                 SetProgressBar((100*i_CountScSistema)/i_SistemaLines);
  321.         }while(!in.eof());
  322.  
  323.         //Decrementa se a EOF c'è una riga vuota (che viene considerata come sestina)
  324.         i_CountScSistema--;
  325.         i_MaxSistemaNumbers[sc_Sestina->GetMaxValue()]--;
  326.  
  327.         in.close();
  328. }
  329.  
  330.  
  331.  
  332. bool CSuperenalottoDlg::File_Exists(CString s_Path)
  333. {
  334.         ifstream in(s_Path,ios::nocreate);
  335.         if (!in){
  336.                 in.close();
  337.                 return FALSE;
  338.         }else{
  339.                 in.close();
  340.                 return TRUE;
  341.         }
  342. }
  343.  
  344.  
  345.  
  346. void CSuperenalottoDlg::OnBiarchivio()
  347. {
  348.         // TODO: Add your control notification handler code here
  349.         CFileDialog m_ldFile(TRUE);
  350.  
  351.         if (m_ldFile.DoModal()==IDOK){
  352.                 s_ArchivioFileName = m_ldFile.GetFileName();
  353.                 s_ArchivioPath = m_ldFile.GetPathName();
  354.                 if (File_Exists(s_ArchivioPath)){
  355.                         b_ArchivioFileSelected = TRUE;
  356.                         SetDlgItemText(IDC_BIARCHIVIO,"File: " + s_ArchivioFileName);
  357.                 }else{
  358.                         b_ArchivioFileSelected = FALSE;
  359.                         SetDlgItemText(IDC_BIARCHIVIO,"File: Non trovato");
  360.                 }
  361.  
  362.         }
  363. }
  364.  
  365. int CSuperenalottoDlg::ConfrontaSestine(Sestina *sc1, Sestina *sc2)
  366. {
  367.         int i_Count1;
  368.         int i_Count2;
  369.         int i_Points=0;
  370.  
  371.         //Giri mentali assurdi per colpa dei puntatori di C++...
  372.         if (!sc1->GetMaxValueInitStatus()){
  373.                 sc1->SetMaxValue(0);
  374.                 sc1->SetMaxValueInitStatus(TRUE);
  375.         }
  376.  
  377.         for (i_Count1=0; i_Count1<6; i_Count1++){
  378.                 for (i_Count2=0; i_Count2<6; i_Count2++){
  379.                         if (sc1->GetNumber(i_Count1)==sc2->GetNumber(i_Count2)) i_Points++;
  380.                 }
  381.         }
  382.        
  383.         return i_Points;
  384. }
  385.  
  386. //Funzione con overloading per il numero jolly...
  387. int CSuperenalottoDlg::ConfrontaSestine(Sestina *sc1, Sestina *sc2, int i_Jolly)
  388. {
  389.         int i_Count1;
  390.         int i_Count2;
  391.         int i_Points=0;
  392.         bool b_Jolly_is_here = FALSE;
  393.  
  394.         //Giri mentali assurdi per colpa dei puntatori di C++...
  395.         if (!sc1->GetMaxValueInitStatus()){
  396.                 sc1->SetMaxValue(0);
  397.                 sc1->SetMaxValueInitStatus(TRUE);
  398.         }
  399.  
  400.         //Confronta i numeri normali...
  401.         for (i_Count1=0; i_Count1<6; i_Count1++){
  402.                 for (i_Count2=0; i_Count2<6; i_Count2++){
  403.                         if (sc1->GetNumber(i_Count1)==sc2->GetNumber(i_Count2)) i_Points++;
  404.                 }
  405.         }
  406.  
  407.         //... e il Jolly...
  408.         for (i_Count1=0; i_Count1<6; i_Count1++){
  409.                 if (sc1->GetNumber(i_Count1) == i_Jolly){
  410.                         b_Jolly_is_here = TRUE;
  411.                 }
  412.         }
  413.        
  414.         // 7 = 5+1, 6 = 6, 5 = 5....
  415.         if (b_Jolly_is_here && i_Points == 5) return 7;
  416.  
  417.         return i_Points;
  418. }
  419.  
  420.  
  421.  
  422.  
  423.  
  424. void CSuperenalottoDlg::ConfrontaArchivio()
  425. {
  426.         int i_Count1;
  427.         int i_Count2;
  428.         int i_Value=0;
  429.  
  430.         for (i_Count1 = 0; i_Count1 < i_CountScArchivio; i_Count1++){
  431.                 for (i_Count2 = (i_Count1+1); i_Count2 < i_CountScArchivio; i_Count2++){
  432.                         i_Value = ConfrontaSestine(&sc_Archivio[i_Count1],&sc_Archivio[i_Count2]);
  433.                         if (i_Value > sc_Archivio[i_Count1].GetMaxValue()) sc_Archivio[i_Count1].SetMaxValue(i_Value);
  434.                 }
  435.                 SetProgressBar((100*(i_Count1+1))/i_CountScArchivio);
  436.         }
  437. }
  438.  
  439. void CSuperenalottoDlg::ViewArchivio()
  440. {
  441.         int i_Count=0;
  442.         CString s_Result;
  443.  
  444.         InitMaxArchivioNumbers();
  445.  
  446.         for (i_Count=0; i_Count<i_CountScArchivio; i_Count++)
  447.                 i_MaxArchivioNumbers[sc_Archivio[i_Count].GetMaxValue()]++;
  448.  
  449.         i_Count=0;
  450.  
  451.         s_Result.Format("%d hanno ottenuto %d",i_MaxArchivioNumbers[i_Count],i_Count);
  452.         SetDlgItemText(IDC_SA0,s_Result);
  453.  
  454.         s_Result.Format("%d hanno ottenuto %d",i_MaxArchivioNumbers[++i_Count],i_Count);
  455.         SetDlgItemText(IDC_SA1,s_Result);
  456.  
  457.         s_Result.Format("%d hanno ottenuto %d",i_MaxArchivioNumbers[++i_Count],i_Count);
  458.         SetDlgItemText(IDC_SA2,s_Result);
  459.        
  460.         s_Result.Format("%d hanno ottenuto %d",i_MaxArchivioNumbers[++i_Count],i_Count);
  461.         SetDlgItemText(IDC_SA3,s_Result);
  462.        
  463.         s_Result.Format("%d hanno ottenuto %d",i_MaxArchivioNumbers[++i_Count],i_Count);
  464.         SetDlgItemText(IDC_SA4,s_Result);
  465.        
  466.         s_Result.Format("%d hanno ottenuto %d",i_MaxArchivioNumbers[++i_Count],i_Count);
  467.         SetDlgItemText(IDC_SA5,s_Result);
  468.        
  469.         s_Result.Format("%d hanno ottenuto %d",i_MaxArchivioNumbers[++i_Count],i_Count);
  470.         SetDlgItemText(IDC_SA6,s_Result);
  471.  
  472.         s_Result.Format("Totale: %d",i_CountScArchivio);
  473.         SetDlgItemText(IDC_SACOUNT,s_Result);
  474.  
  475.         SetProgressBar(0);
  476. }
  477.  
  478. void CSuperenalottoDlg::ViewSistema()
  479. {
  480.         int i_Count=0;
  481.         CString s_Result;
  482.  
  483.         s_Result.Format("%d hanno ottenuto %d",i_MaxSistemaNumbers[i_Count],i_Count);
  484.         SetDlgItemText(IDC_SS0,s_Result);
  485.  
  486.         s_Result.Format("%d hanno ottenuto %d",i_MaxSistemaNumbers[++i_Count],i_Count);
  487.         SetDlgItemText(IDC_SS1,s_Result);
  488.        
  489.         s_Result.Format("%d hanno ottenuto %d",i_MaxSistemaNumbers[++i_Count],i_Count);
  490.         SetDlgItemText(IDC_SS2,s_Result);
  491.        
  492.         s_Result.Format("%d hanno ottenuto %d",i_MaxSistemaNumbers[++i_Count],i_Count);
  493.         SetDlgItemText(IDC_SS3,s_Result);
  494.        
  495.         s_Result.Format("%d hanno ottenuto %d",i_MaxSistemaNumbers[++i_Count],i_Count);
  496.         SetDlgItemText(IDC_SS4,s_Result);
  497.        
  498.         s_Result.Format("%d hanno ottenuto %d",i_MaxSistemaNumbers[++i_Count],i_Count);
  499.         SetDlgItemText(IDC_SS5,s_Result);
  500.        
  501.         s_Result.Format("%d hanno ottenuto %d",i_MaxSistemaNumbers[++i_Count],i_Count);
  502.         SetDlgItemText(IDC_SS6,s_Result);
  503.  
  504.         s_Result.Format("Totale: %d",i_CountScSistema);
  505.         SetDlgItemText(IDC_SSCOUNT,s_Result);
  506.  
  507.         ViewExportCount();
  508.  
  509.         SetProgressBar(0);
  510. }
  511.  
  512. void CSuperenalottoDlg::OnBiSistema()
  513. {
  514.         // TODO: Add your control notification handler code here
  515.         CFileDialog m_ldFile(TRUE);
  516.  
  517.         if (m_ldFile.DoModal()==IDOK){
  518.                 s_SistemaFileName = m_ldFile.GetFileName();
  519.                 s_SistemaPath = m_ldFile.GetPathName();
  520.                
  521.                 if (File_Exists(s_SistemaPath)){
  522.                         b_SistemaFileSelected = TRUE;
  523.                         SetDlgItemText(IDC_BISISTEMA,"File: " + s_SistemaFileName);
  524.                 }else{
  525.                         b_SistemaFileSelected = FALSE;
  526.                         SetDlgItemText(IDC_BISISTEMA,"File: Non trovato");
  527.                 }
  528.         }
  529. }
  530.  
  531. void CSuperenalottoDlg::OnBlSistema()
  532. {
  533.         // TODO: Add your control notification handler code here
  534.         if (b_ArchivioIsLoaded){
  535.                 if (b_SistemaFileSelected){
  536.  
  537.                         i_CountScSistema = 0;
  538.                        
  539.                         i_SistemaLines=GetFileLines(s_SistemaPath);
  540.  
  541.                         UnCheckAll();
  542.  
  543.                         InitMaxSistemaNumbers();
  544.  
  545.                         AfxBeginThread(CreateSistemaThread,this);
  546.  
  547.                         b_SistemaIsLoaded = TRUE;
  548.                 }else{
  549.                         ShowStatus("Non riesco a caricare il sistema, assicurati di aver selezionato un file valido.");
  550.                 }
  551.         }else{
  552.                 ShowStatus("Non riesco a caricare il sistema, assicurati di aver caricato l'archivio storico.");
  553.         }
  554. }
  555.  
  556.  
  557. void CSuperenalottoDlg::OnBlarchivio()
  558. {
  559.         // TODO: Add your control notification handler code here
  560.  
  561.         if (b_ArchivioFileSelected){
  562.                 i_CountScArchivio = 0;
  563.  
  564.                 InitMaxArchivioNumbers();
  565.  
  566.                 UnCheckAll();
  567.  
  568.                 b_SistemaIsLoaded = FALSE;
  569.                
  570.                 i_ArchivioLines=GetFileLines(s_ArchivioPath);
  571.  
  572.                 AfxBeginThread(CreateArchivioThread,this);
  573.  
  574.                 b_ArchivioIsLoaded = TRUE;
  575.         }else{
  576.                 ShowStatus("Non riesco a caricare l'archivio, assicurati di aver selezionato un file valido.");
  577.         }
  578. }
  579.  
  580. void CSuperenalottoDlg::ShowStatus(CString s_Status)
  581. {
  582.         SetDlgItemText(IDC_STATUS,"Status: " + s_Status);
  583. }
  584.  
  585. void CSuperenalottoDlg::ViewExportCount()
  586. {
  587.         CString s_Result;
  588.  
  589.         s_Result.Format("Eliminate: %d",(i_CountScSistema-i_CountScExport));
  590.         SetDlgItemText(IDC_SEDELETED,s_Result);
  591.  
  592.         s_Result.Format("Totale: %d",i_CountScExport);
  593.         SetDlgItemText(IDC_SECOUNT,s_Result);
  594. }
  595.  
  596. void CSuperenalottoDlg::AddExportCount(int i_Number)
  597. {
  598.         i_CountScExport += i_MaxSistemaNumbers[i_Number];
  599.         b_is_checked[i_Number]=TRUE;
  600.         ViewExportCount();
  601. }
  602.  
  603. void CSuperenalottoDlg::SubExportCount(int i_Number)
  604. {
  605.         i_CountScExport -= i_MaxSistemaNumbers[i_Number];
  606.         b_is_checked[i_Number]=FALSE;
  607.         ViewExportCount();
  608. }
  609.  
  610. void CSuperenalottoDlg::OnChk0()
  611. {
  612.         // TODO: Add your control notification handler code here
  613.         UpdateData(TRUE);
  614.         if (!b_SistemaIsLoaded){
  615.                 m_bChk0 = FALSE;
  616.                 UpdateData(FALSE);
  617.         }
  618.         if (m_bChk0){
  619.                 AddExportCount(0);
  620.         }else{
  621.                 SubExportCount(0);
  622.         }
  623. }
  624.  
  625. void CSuperenalottoDlg::OnChk1()
  626. {
  627.         // TODO: Add your control notification handler code here
  628.         UpdateData(TRUE);
  629.         if (!b_SistemaIsLoaded){
  630.                 m_bChk1 = FALSE;
  631.                 UpdateData(FALSE);
  632.         }
  633.         if (m_bChk1){
  634.                 AddExportCount(1);
  635.         }else{
  636.                 SubExportCount(1);
  637.         }
  638. }
  639.  
  640. void CSuperenalottoDlg::OnChk2()
  641. {
  642.         // TODO: Add your control notification handler code here
  643.         UpdateData(TRUE);
  644.         if (!b_SistemaIsLoaded){
  645.                 m_bChk2 = FALSE;
  646.                 UpdateData(FALSE);
  647.         }
  648.         if (m_bChk2){
  649.                 AddExportCount(2);
  650.         }else{
  651.                 SubExportCount(2);
  652.         }
  653. }
  654.  
  655. void CSuperenalottoDlg::OnChk3()
  656. {
  657.         // TODO: Add your control notification handler code here
  658.         UpdateData(TRUE);
  659.         if (!b_SistemaIsLoaded){
  660.                 m_bChk3 = FALSE;
  661.                 UpdateData(FALSE);
  662.         }
  663.         if (m_bChk3){
  664.                 AddExportCount(3);
  665.         }else{
  666.                 SubExportCount(3);
  667.         }
  668. }
  669.  
  670. void CSuperenalottoDlg::OnChk4()
  671. {
  672.         // TODO: Add your control notification handler code here
  673.         UpdateData(TRUE);
  674.         if (!b_SistemaIsLoaded){
  675.                 m_bChk4 = FALSE;
  676.                 UpdateData(FALSE);
  677.         }
  678.         if (m_bChk4){
  679.                 AddExportCount(4);
  680.         }else{
  681.                 SubExportCount(4);
  682.         }
  683. }
  684.  
  685. void CSuperenalottoDlg::OnChk5()
  686. {
  687.         // TODO: Add your control notification handler code here
  688.         UpdateData(TRUE);
  689.         if (!b_SistemaIsLoaded){
  690.                 m_bChk5 = FALSE;
  691.                 UpdateData(FALSE);
  692.         }
  693.         if (m_bChk5){
  694.                 AddExportCount(5);
  695.         }else{
  696.                 SubExportCount(5);
  697.         }
  698. }
  699.  
  700. void CSuperenalottoDlg::OnChk6()
  701. {
  702.         // TODO: Add your control notification handler code here
  703.         UpdateData(TRUE);
  704.         if (!b_SistemaIsLoaded){
  705.                 m_bChk6 = FALSE;
  706.                 UpdateData(FALSE);
  707.         }
  708.         if (m_bChk6){
  709.                 AddExportCount(6);
  710.         }else{
  711.                 SubExportCount(6);
  712.         }
  713. }
  714.  
  715. bool CSuperenalottoDlg::SetExportPath()
  716. {
  717.         CFileDialog m_svFile(FALSE);
  718.  
  719.         if (m_svFile.DoModal()==IDOK){
  720.                 s_ExportFileName = m_svFile.GetFileName();
  721.                 s_ExportPath = m_svFile.GetPathName();
  722.                 return TRUE;
  723.         }else{
  724.                 return FALSE;
  725.         }
  726. }
  727.  
  728. void CSuperenalottoDlg::OnBsexport()
  729. {
  730.         // TODO: Add your control notification handler code here
  731.         if (b_ArchivioIsLoaded && b_SistemaIsLoaded){
  732.                 if (i_CountScExport){
  733.                         if(SetExportPath()){
  734.                                 AfxBeginThread(CreateExportThread,this);
  735.                                 SetProgressBar(0);
  736.                         }
  737.                 }else{
  738.                         ShowStatus("Che cosa salvo se non hai selezionato niente?");
  739.                 }
  740.         }else{
  741.                 ShowStatus("Non posso salvare i dati se prima non li ho caricati.");
  742.         }
  743. }
  744.  
  745.  
  746. void CSuperenalottoDlg::WriteExport()
  747. {
  748.         int i_Count;
  749.         int i_CountExport=0;
  750.         int i_Number;
  751.         int i_Value;
  752.         Sestina *sc_Sestina = new Sestina();
  753.  
  754.         ifstream in(s_SistemaPath, ios::in);
  755.         ofstream out(s_ExportPath,ios::trunc);
  756.  
  757.        
  758.         do{
  759.                 //Prende i numeri e li assegna ad un oggetto Sestina
  760.                 for (i_Count=0; i_Count<6; i_Count++){
  761.                         in >> i_Number;
  762.                         sc_Sestina->SetNumber(i_Count,i_Number);
  763.                 }
  764.  
  765.                 //Confronta la sestina con tutte quelle dell'archivio...
  766.                 for (i_Count=0; i_Count<i_CountScArchivio; i_Count++){
  767.                         i_Value = ConfrontaSestine(sc_Sestina,&sc_Archivio[i_Count]);
  768.                         if (i_Value > sc_Sestina->GetMaxValue()) sc_Sestina->SetMaxValue(i_Value);
  769.                 }
  770.  
  771.                 //Scrive le sestine se hanno il segno di spunta e sono una sestina valida...
  772.                 if (b_is_checked[sc_Sestina->GetMaxValue()]){ //&& i_Number
  773.                         for (i_Count=0; i_Count<6; i_Count++){
  774.                                 out << sc_Sestina->GetNumber(i_Count);
  775.                                 if (i_Count<5) out << " ";
  776.                         }
  777.                         out << endl;
  778.                 }
  779.                 i_Number=0;
  780.                 sc_Sestina->SetMaxValue(0);
  781.                 SetProgressBar((100*(++i_CountExport))/i_CountScExport);
  782.         }while(!in.eof());
  783.  
  784.         in.close();
  785.         out.close();
  786.  
  787.         SetProgressBar(0);
  788. }
  789.  
  790. int CSuperenalottoDlg::GetFileLines(CString s_Path)
  791. {
  792.         int i_nLines=0;
  793.         char buffer[40];
  794.  
  795.         ifstream in(s_Path, ios::in);
  796.        
  797.         while (in.getline(buffer,40)) i_nLines++;
  798.  
  799.         in.close();
  800.  
  801.         return i_nLines;
  802. }
  803.  
  804. void CSuperenalottoDlg::SetProgressBar(int i_Value)
  805. {
  806.         m_cPsbar.SendMessage(PBM_SETPOS,i_Value,0);
  807. }
  808.  
  809. void CSuperenalottoDlg::InitMaxArchivioNumbers()
  810. {
  811.         int i_Count;
  812.         for (i_Count=0; i_Count<7; i_Count++)
  813.                 i_MaxArchivioNumbers[i_Count]=0;
  814. }
  815.  
  816. void CSuperenalottoDlg::InitMaxSistemaNumbers()
  817. {
  818.         int i_Count;
  819.         for (i_Count=0; i_Count<7; i_Count++)
  820.                 i_MaxSistemaNumbers[i_Count]=0;
  821. }
  822.  
  823. void CSuperenalottoDlg::ControllaNumero(int CURCONTROL, int NEXTCONTROL, int i_Number)
  824. {
  825.         int i_Value;
  826.         CWnd *CWControl;
  827.         CWControl = GetDlgItem(NEXTCONTROL);
  828.         i_Value=GetDlgItemInt(CURCONTROL);
  829.  
  830.         if (i_Value>90 || i_Value == NULL){
  831.                 SetDlgItemInt(CURCONTROL,1);
  832.                 i_EstrazioneNumbers[i_Number]=0;
  833.         }else{
  834.                 if (i_Value>=10) CWControl->SetFocus();
  835.                 i_EstrazioneNumbers[i_Number]=i_Value;
  836.         }
  837. }
  838.  
  839.  
  840. void CSuperenalottoDlg::OnUpdateEe0()
  841. {
  842.         ControllaNumero(IDC_EE0,IDC_EE1,0);
  843. }
  844.  
  845. void CSuperenalottoDlg::OnUpdateEe1()
  846. {
  847.         ControllaNumero(IDC_EE1,IDC_EE2,1);
  848. }
  849.  
  850. void CSuperenalottoDlg::OnUpdateEe2()
  851. {
  852.         ControllaNumero(IDC_EE2,IDC_EE3,2);
  853. }
  854.  
  855. void CSuperenalottoDlg::OnUpdateEe3()
  856. {
  857.         ControllaNumero(IDC_EE3,IDC_EE4,3);
  858. }
  859.  
  860. void CSuperenalottoDlg::OnUpdateEe4()
  861. {
  862.         ControllaNumero(IDC_EE4,IDC_EE5,4);
  863. }
  864.  
  865. void CSuperenalottoDlg::OnUpdateEe5()
  866. {
  867.         ControllaNumero(IDC_EE5,IDC_EE6,5);
  868. }
  869.  
  870. void CSuperenalottoDlg::OnUpdateEe6()
  871. {
  872.         ControllaNumero(IDC_EE6,IDC_BESEGUI,6);
  873. }
  874.  
  875. void CSuperenalottoDlg::OnBesegui()
  876. {
  877.         // TODO: Add your control notification handler code here
  878.  
  879.         int i_Count;
  880.         bool b_ArgsAreOK = TRUE;
  881.  
  882.         for(i_Count=0; i_Count<7; i_Count++){
  883.                 i_MaxEstrazioneNumbers[i_Count]=0; //Cancella i precendeti risultati
  884.                 if (!i_EstrazioneNumbers[i_Count]) b_ArgsAreOK = FALSE;
  885.         }
  886.         i_MaxEstrazioneNumbers[7]=0; //cancella il precendete risultato (per non fare un altro for)..
  887.  
  888.  
  889.         if (b_SistemaFileSelected){
  890.                 if (b_ArgsAreOK){
  891.  
  892.                         i_SistemaLines=GetFileLines(s_SistemaPath);
  893.                
  894.                         AfxBeginThread(CreateEstrazioneThread,this);
  895.                        
  896.                 }else{
  897.                         ShowStatus("Non riesco ad elaborare la richiesta, assicurati di aver inserito tutti i numeri.");
  898.                 }
  899.         }else{
  900.                 ShowStatus("Non riesco ad elaborare la richiesta, assicurati di aver selezionato un sistema valido.");
  901.         }
  902. }
  903.  
  904. void CSuperenalottoDlg::ConfrontaEstrazione()
  905. {
  906.         int i_Count;
  907.         int i_Number;
  908.         int i_CountScEstrazione = 0;
  909.         int i_Jolly = i_EstrazioneNumbers[6];
  910.  
  911.         Sestina *sc_SisSestina = new Sestina();
  912.         Sestina *sc_EstSestina = new Sestina();
  913.  
  914.  
  915.         ifstream in(s_SistemaPath, ios::in);
  916.  
  917.         //Assegna ad un oggetto sestina i valori immessi dall'utente...
  918.         for (i_Count=0; i_Count<6; i_Count++){
  919.                 sc_EstSestina->SetNumber(i_Count,i_EstrazioneNumbers[i_Count]);
  920.         }
  921.        
  922.         do{
  923.                 //Prende i numeri dal file sistema e li assegna ad un oggetto Sestina
  924.                 for (i_Count=0; i_Count<6; i_Count++){
  925.                         in >> i_Number;
  926.                         sc_SisSestina->SetNumber(i_Count,i_Number);
  927.                 }
  928.  
  929.                 i_MaxEstrazioneNumbers[ConfrontaSestine(sc_SisSestina,sc_EstSestina,i_Jolly)]++;
  930.                 SetProgressBar((100*(++i_CountScEstrazione))/i_SistemaLines);
  931.                
  932.         }while(!in.eof());
  933.  
  934.         //Decrementa se a EOF c'è una riga vuota (che viene considerata come sestina)
  935.         i_CountScEstrazione--;
  936.         i_MaxEstrazioneNumbers[ConfrontaSestine(sc_SisSestina,sc_EstSestina,i_Jolly)]--;
  937.  
  938.         SetProgressBar(0);
  939.  
  940.         in.close();
  941. }
  942.  
  943.  
  944. static UINT CreateArchivioThread(LPVOID pParam)
  945. {
  946.         CSuperenalottoDlg *pClass = (CSuperenalottoDlg*)pParam;
  947.  
  948.         pClass->ShowStatus("Sto caricando in memoria l'archivio storico...");
  949.         pClass->GetArchivio();
  950.  
  951.         pClass->ShowStatus("Sto elaborando l'archivio storico...");
  952.         pClass->ConfrontaArchivio();
  953.  
  954.         pClass->ShowStatus("Mi preparo a visualizzare i dati dell'archivio...");
  955.         pClass->ViewArchivio();
  956.  
  957.         pClass->ShowStatus("Pronto");
  958.  
  959.         return 0;
  960. }
  961.  
  962. static UINT CreateSistemaThread(LPVOID pParam)
  963. {
  964.         CSuperenalottoDlg *pClass = (CSuperenalottoDlg*)pParam;
  965.        
  966.         pClass->ShowStatus("Sto caricando ed elaborando il sistema...");
  967.         pClass->GetSistema();
  968.  
  969.         pClass->ShowStatus("Mi preparo a visualizzare i dati del sistema...");
  970.         pClass->ViewSistema();
  971.  
  972.         pClass->ShowStatus("Pronto");
  973.  
  974.         return 0;
  975. }
  976.  
  977. static UINT CreateExportThread(LPVOID pParam)
  978. {
  979.         CSuperenalottoDlg *pClass = (CSuperenalottoDlg*)pParam;
  980.  
  981.         pClass->ShowStatus("Sto caricando, elaborando e scrivendo il sistema ridotto...");
  982.         pClass->WriteExport();
  983.  
  984.         pClass->ShowStatus("Ho salvato il sistema ridotto in " + pClass->s_ExportPath);
  985.  
  986.         return 0;
  987. }
  988.  
  989. static UINT CreateEstrazioneThread(LPVOID pParam)
  990. {
  991.         CSuperenalottoDlg *pClass = (CSuperenalottoDlg*)pParam;
  992.  
  993.         pClass->ShowStatus("Sto caricando e confrontando il sistema...");
  994.         pClass->ConfrontaEstrazione();
  995.  
  996.         pClass->ShowStatus("Visualizzo i risultati...");
  997.         pClass->ViewEstrazione();
  998.  
  999.         pClass->ShowStatus("Pronto");
  1000.  
  1001.         return 0;
  1002. }
  1003.  
  1004.  
  1005. void CSuperenalottoDlg::ViewEstrazione()
  1006. {
  1007.         int i_Count=0;
  1008.         CString s_Message;
  1009.  
  1010.         s_Message.Format("Risultati dell'estrazione con il sistema:\n\n%d hanno ottenuto %d\n%d hanno ottenuto %d\n%d hanno ottenuto %d\n%d hanno ottenuto %d\n%d hanno ottenuto %d\n%d hanno ottenuto %d\n%d hanno ottenuto %s\n%d hanno ottenuto %d",
  1011.                 i_MaxEstrazioneNumbers[0],0,
  1012.                 i_MaxEstrazioneNumbers[1],1,
  1013.                 i_MaxEstrazioneNumbers[2],2,
  1014.                 i_MaxEstrazioneNumbers[3],3,
  1015.                 i_MaxEstrazioneNumbers[4],4,
  1016.                 i_MaxEstrazioneNumbers[5],5,
  1017.                 i_MaxEstrazioneNumbers[7],"5+1",
  1018.                 i_MaxEstrazioneNumbers[6],6);
  1019.  
  1020.         MessageBox(s_Message,"Risultati",MB_OK);
  1021. }
  1022.  
  1023. void CSuperenalottoDlg::OnInfoAbout()
  1024. {
  1025.         // TODO: Add your command handler code here
  1026.         CAboutDlg *ca_AboutWin = new CAboutDlg();
  1027.         ca_AboutWin->DoModal();
  1028. }
  1029.  
  1030. void CSuperenalottoDlg::UnCheckAll()
  1031. {
  1032.         m_bChk0 = FALSE;
  1033.         m_bChk1 = FALSE;
  1034.         m_bChk2 = FALSE;
  1035.         m_bChk3 = FALSE;
  1036.         m_bChk4 = FALSE;
  1037.         m_bChk5 = FALSE;
  1038.         m_bChk6 = FALSE;
  1039.         UpdateData(FALSE);
  1040.  
  1041.         i_CountScExport = 0;
  1042.         ViewExportCount();
  1043. }