Ejemplo n.º 1
0
        //Fired when backgroundWorker is done
        private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            shouldClose = true;       //The user now has permission to kill date pop so don't get mad
            Dispatcher.Invoke(() => { //We have to invoke this other stuff because its crossthreaded
                if (errorCount > 0)   //Don't worrry about opening the file unless we have errors
                {
                    MessageBox.Show("The Date Check Tool finished and found errors.");

                    DataBaseTools dbTools = new DataBaseTools();
                    dbTools.writeToTable(outTable, filePath);

                    System.Diagnostics.Process.Start("msaccess.exe", filePath);    //Opens the text file in notepad
                    System.Diagnostics.Process.Start("notepad.exe", "output.txt"); //Opens the text file in notepad
                }
                else
                {
                    MessageBox.Show("The Date Check Tool finished and found no errors.");
                }

                errorCount = 0;
            });
        }
Ejemplo n.º 2
0
        private void browseButton_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openDialog = new OpenFileDialog();

            openDialog.Filter = "Access 2007 (*.accdb)|*accdb|Access 2000-2003 (*.mdb)|*.mdb"; //Set file filter for MS Access files only

            if (openDialog.ShowDialog() == true)                                               //Check if a file gets opened
            {
                filePath = openDialog.FileName;                                                //Looks like we haven't added a filepath for this page yet so add a new one

                tableComboBox.Items.Clear();                                                   //Clear out the existing items so we don't have table names from different files
                tableComboBox.Items.Add("Select Table...");
                tableComboBox.Text = "Select Table...";

                nameLabel.Content = System.IO.Path.GetFileName(openDialog.FileName);     //Display the filename in the fileLabel
                DataBaseTools dbTools = new DataBaseTools();
                foreach (string tableName in dbTools.getTableNames(openDialog.FileName)) //Pull tables names out of the access db file and iterate over them
                {
                    tableComboBox.Items.Add(tableName);                                  //Add the table names to the comboxbox so the user can select the one he or she wants
                }
            }
        }
Ejemplo n.º 3
0
        //A method that returns an array that will later be written to a text file each element is a line of a text file
        private string[] getBadDates()
        {
            DataTable table;

            outTable = new DataTable();
            List <string> errorTypeCount = new List <string>();
            List <string> writeContents  = new List <string>();

            string[] columNames = { "STNID", "WISLRID", "END_VALID", "START_VALID" };

            DataBaseTools dbTools = new DataBaseTools();

            dbTools.progressUpdated      += dbTools_ProgressUpdated;
            dbTools.didReceiveFatalError += dbTools_didReceiveFatalError;
            table = dbTools.getDataTable(filePath, tableName);

            string stnId;
            string wislrId;
            string recordCreated;
            string recordHistoric;
            string startValid;
            string endValid;
            int    localErrorCount; //Local errorCount keeps up with errors per row while errorCount is total erros over the whole file the error count is displayed once date check is done

            int[] errors = { 0, 0, 0, 0 };

            foreach (string name in columNames)
            {
                outTable.Columns.Add(name);
            }

            for (int i = 0; i < table.Rows.Count; i++)
            {
                stnId           = table.Rows[i].ItemArray[0].ToString();
                wislrId         = table.Rows[i].ItemArray[3].ToString();
                recordCreated   = table.Rows[i].ItemArray[12].ToString();
                recordHistoric  = table.Rows[i].ItemArray[13].ToString();
                startValid      = table.Rows[i].ItemArray[14].ToString();
                endValid        = table.Rows[i].ItemArray[15].ToString();
                localErrorCount = 0;

                writeContents.Add("STNID: " + stnId + " WISLRID: " + wislrId + " {");        //The rows aren't always the same in our datatables and the datatable in access so we give them the stnid and wislrid

                if (string.IsNullOrEmpty(recordHistoric) && !string.IsNullOrEmpty(endValid)) //No end valid date for record historic
                {
                    writeContents.Add(Environment.NewLine + "    There is no Record Historic for End Valid (" + endValid + ")" + Environment.NewLine);
                    errors[0]++;
                    localErrorCount++;
                }

                if (DateTools.getLaterDate(endValid, startValid) == startValid)
                {
                    writeContents.Add(Environment.NewLine + "    Start Valid is more recent than End Valid (" + endValid + ")" + Environment.NewLine); //End valid is earlier than the start valid
                    errors[1]++;
                    localErrorCount++;
                }

                if (DateTools.getLaterDate(recordHistoric, startValid) == startValid) //Start valid is more recent than record historic
                {
                    writeContents.Add(Environment.NewLine + "    Start Valid is more recent than Record Historic" + Environment.NewLine);
                    errors[2]++;
                    localErrorCount++;
                }

                if (DateTools.getLaterDate(recordCreated, startValid) == startValid) //Start valid is more recent than record created
                {
                    writeContents.Add(Environment.NewLine + "    Start Valid is more recent than Record Created" + Environment.NewLine);
                    errors[3]++;
                    localErrorCount++;
                }

                if (localErrorCount == 0) //If we don't have errors here remove the opening line and brace
                {
                    writeContents.RemoveAt(writeContents.Count - 1);
                }
                else //If we have local errors close it off with a brace and a new line
                {
                    errorCount += localErrorCount; //Keep track of all errors
                    writeContents.Add("}\n");

                    DataRow currentRow = outTable.NewRow();
                    currentRow["STNID"]       = stnId;
                    currentRow["WISLRID"]     = wislrId;
                    currentRow["END_VALID"]   = endValid;
                    currentRow["START_VALID"] = startValid;
                    outTable.Rows.Add(currentRow);
                }
            }

            errorTypeCount.Add("Error types:\nThere is no Record Historic for End Valid: " + errors[0] + "\n");
            errorTypeCount.Add("Start Valid is more recent than End Valid: " + errors[1] + "\n");
            errorTypeCount.Add("Start Valid is more recent than Record Historic: " + errors[2] + "\n");
            errorTypeCount.Add("Start Valid is more recent than Record Created: " + errors[3] + "\n" + Environment.NewLine);

            return(errorTypeCount.ToArray().Concat(writeContents.ToArray()).ToArray()); //Return array of lines
        }