//Methods
 public void AddNewRow(ClassDataFile dataFile, ref ClassImportInfoDataTable infoTable)
 {
     DataRow newRow = infoTable.infoTable.NewRow();
     newRow["File_Name"] = dataFile.FileName;
     newRow["Self_Check_Result"] = "";
     newRow["AuditFile_Check_Result"] = "Not Checked Yet";
     infoTable.infoTable.Rows.Add(newRow);
     infoTable.infoTable.AcceptChanges();
 }
        public static List<ClassDataFile> CompileFileList(string pickUpLocation, ref ClassImportInfoDataTable infoTable, bool useAuditFile)
        {
            List<ClassDataFile> fileList = new List<ClassDataFile>();
            String[] filePaths = Directory.GetFiles(pickUpLocation);
            ClassDataFile[] datFiles = new ClassDataFile[filePaths.Count()];
            int count = 0;

            if (useAuditFile)
            {
                string auditFileLocation = Properties.Settings.Default.AuditFileLocation;
                ClassAuditFile auditFile = new ClassAuditFile(auditFileLocation);
                DataTables.ClassAuditEntriesDataTable auditEntriesTable = new DataTables.ClassAuditEntriesDataTable();
                auditEntriesTable = DataTables.ClassAuditEntriesDataTable.FillEntriesTable(auditFile);

                if (auditEntriesTable.entriesTable.Rows.Count >= 1)
                {
                    foreach (String fileLoc in filePaths)
                    {
                        datFiles[count] = new ClassDataFile(filePaths[count]);
                        infoTable.AddNewRow(datFiles[count], ref infoTable);
                        string message = string.Empty;

                        message = ClassAuditing.SelfCheck(datFiles[count]);
                        infoTable.UpdateRow(datFiles[count], "Self_Check_Result", message, ref infoTable);

                        message = ClassAuditing.AuditFileCheck(datFiles[count], auditEntriesTable);
                        infoTable.UpdateRow(datFiles[count], "AuditFile_Check_Result", message, ref infoTable);

                        //• ONLY ADD FILE TO LIST IF AUDIT PASSED
                        if ((datFiles[count].PassedSelfCheck == true) && (datFiles[count].PassedAuditFileCheck == true))
                            fileList.Add(datFiles[count]);

                        count++;
                    }

                }
            }
            else
            {
                foreach (String fileLoc in filePaths)
                {
                    datFiles[count] = new ClassDataFile(filePaths[count]);
                    infoTable.AddNewRow(datFiles[count], ref infoTable);
                    string message = string.Empty;

                    message = ClassAuditing.SelfCheck(datFiles[count]);
                    infoTable.UpdateRow(datFiles[count], "Self_Check_Result", message, ref infoTable);

                    //• ONLY ADD FILE TO LIST IF AUDIT PASSED
                    if (datFiles[count].PassedSelfCheck == true)
                        fileList.Add(datFiles[count]);

                    count++;
                }
            }
            return fileList;
        }
Esempio n. 3
0
        //This class sould contain the static methods for the two types of Auditing, als use static properties for the messages.
        public static DataTable CheckForInCompleteAudits(string connectionString, ClassAuditEntriesDataTable entriesTable, ref ClassImportInfoDataTable infoTable)
        {
            DataTable _resultTable = new DataTable();
            _resultTable = ClassSQLAccess.SelectInCompletesAudits(connectionString, entriesTable);

            if (_resultTable.Rows.Count >= 1)
                UpdateInCompleteAudits(_resultTable, entriesTable, ref infoTable, connectionString);

            return _resultTable;
        }
Esempio n. 4
0
        public static void SaveTableToCSV(ClassImportInfoDataTable infoTable, string csvFilePath, string fileName)
        {
            int columns = infoTable.infoTable.Columns.Count;
            int rows = infoTable.infoTable.Rows.Count;

            try
            {
                StreamWriter sw = new StreamWriter(csvFilePath + "\\" + fileName, false);

                for (int i = 0; i < columns; i++)
                {
                    sw.Write(infoTable.infoTable.Columns[i]);

                    if (i < columns - 1)
                    {
                        sw.Write(",");
                    }
                }

                sw.Write(sw.NewLine);

                foreach (DataRow dr in infoTable.infoTable.Rows)
                {
                    for (int i = 0; i < columns; i++)
                    {
                        if (!Convert.IsDBNull(dr[i]))
                        {
                            sw.Write(dr[i].ToString());
                        }

                        if (i < columns - 1)
                        {
                            sw.Write(",");
                        }
                    }

                    sw.Write(sw.NewLine);
                }

                sw.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 5
0
        public static void UpdateInCompleteAudits(DataTable table, ClassAuditEntriesDataTable entriesTable, ref ClassImportInfoDataTable infoTable, string connectionString)
        {
            string message;
            foreach (DataRow dataRow in table.Rows)
            {
                ClassDataFile datFile = new ClassDataFile(dataRow);
                infoTable.AddNewRow(datFile, ref infoTable);
                message = ClassGatherInfo.VerifyFileIntact(datFile, entriesTable);

                message = AuditFileCheck(datFile, entriesTable);
                infoTable.UpdateRow(datFile, "AuditFile_Check_Result", message, ref infoTable);

                //• ONLY UPDATE THE ENTRY IF AUDIT PASSED
                if (datFile.PassedAuditFileCheck)
                    ClassSQLAccess.UpdateIncompleteAudit(datFile, connectionString);
            }
        }
        public string SaveTableToExcel(ClassImportInfoDataTable infoTable, string ExcelFilePath, string fileName)
        {
            Excel.Application exApp;
            exApp = new Excel.Application();

            Excel.Workbook exWorkBook;
            exWorkBook = exApp.Workbooks.Add(Type.Missing);

            Excel.Worksheet exWorkSheet;
            exWorkSheet = (Microsoft.Office.Interop.Excel.Worksheet)exWorkBook.ActiveSheet;
            exWorkSheet.Name = fileName;

            int columns = infoTable.infoTable.Columns.Count;
            int rows = infoTable.infoTable.Rows.Count;

            // column headings
            for (int i = 0; i < columns; i++)
            {
                exWorkSheet.Cells[1, (i + 1)] = infoTable.infoTable.Columns[i].ColumnName;
            }

            // rows
            for (int i = 0; i < rows; i++)
            {
                // to do: format datetime values before printing
                for (int j = 0; j < columns; j++)
                {
                    exWorkSheet.Cells[(i + 2), (j + 1)] = infoTable.infoTable.Rows[i][j];
                }
            }

            if (ExcelFilePath != null && ExcelFilePath != "")
            {
                try
                {
                    exWorkSheet.SaveAs(ExcelFilePath + fileName);
                    exApp.Quit();
                }
                catch (Exception ex)
                {
                    throw new Exception("ExportToExcel: Excel file could not be saved! Check filepath.\n"
                        + ex.Message);
                }
            }
            else    // no filepath is given
            {
                exApp.Visible = true;
            }
            return "Saved";
        }
 public void UpdateRow(ClassDataFile dataFile, string resultType, string resultMessage, ref ClassImportInfoDataTable infoTable)
 {
     DataRow row = infoTable.infoTable.Select("File_Name = '" + dataFile.FileName + "'").FirstOrDefault();
     row[resultType] = resultMessage.ToString();
     infoTable.infoTable.AcceptChanges();
 }