Beispiel #1
0
        private void GenerateReport(string fn1, string fn2, string xmlType, string outputDir, bool showAlert)
        {
            CLog               log           = CLog.CreateInstance();
            List <CLogRec>     logList       = log.GetLogs();
            List <CSummaryRec> logSummary    = log.GetSummary();
            string             strReportName = "CmpReport_ " +
                                               System.IO.Path.GetFileName(fn2).Split('.').First() + "_" +
                                               DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") +
                                               ".xlsx";
            string strLogName = "CmpLog_" +
                                DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") +
                                ".txt";

            if (logList.Count > 0)
            {
                List <IXmlSettingReportDictionary> dicList = new List <IXmlSettingReportDictionary>();
                IXmlSetting currentSetting =
                    m_SettingFactory.ReadSettingCollection(m_ToolSetting.GetXmlSettingFilePath().Value)
                    .GetSetting(xmlType);
                foreach (List <IXmlSettingReportDictionary> tmpList
                         in from IXmlSettingNode tmp
                         in currentSetting.GetNodes
                         select tmp.GetDictionarys)
                {
                    dicList.AddRange(tmpList);
                }

                Microsoft.Office.Interop.Excel.Application objExcel     = null;
                Microsoft.Office.Interop.Excel.Workbook    objWorkbook  = null;
                Microsoft.Office.Interop.Excel.Worksheet   objWorksheet = null;
                try
                {
                    objExcel = new Microsoft.Office.Interop.Excel.Application();

                    objExcel.Visible             = false;
                    objExcel.SheetsInNewWorkbook = 3;
                    objWorkbook = objExcel.Workbooks.Add();

                    //write report issue dictionary
                    objWorksheet      = objWorkbook.Worksheets[1];
                    objWorksheet.Name = "Report Dictionary";

                    string[] aTitle = new[] { "Issue Source",
                                              "Issue Category",
                                              "Issue Instruction" };
                    int intLineNo = 1;
                    List <CXmlSettingRptDicRep> listOfRptDic =
                        (from tmp in dicList
                         select new CXmlSettingRptDicRep
                    {
                        source = tmp.issue_source,
                        category = tmp.issue_category,
                        instruction = tmp.issue_instruction
                    }
                        ).ToList();
                    SaifeiAsm.ExcelHelper.WriteData(objWorksheet,
                                                    ref intLineNo,
                                                    SaifeiAsm.ExcelHelper.ObjectParseMethord.UsingFields,
                                                    listOfRptDic,
                                                    aTitle);
                    intLineNo = intLineNo + 2;
                    objWorksheet.Cells[intLineNo, 2] = "General Notes:";
                    foreach (string strGeneralNote in currentSetting.GeneralNotes)
                    {
                        objWorksheet.Cells[intLineNo, 3] = strGeneralNote;
                        intLineNo = intLineNo + 1;
                    }
                    //write report summary
                    objWorksheet      = objWorkbook.Worksheets[2];
                    objWorksheet.Name = "Report Summary";
                    aTitle            = new[] { "Section",
                                                "Attribute Name",
                                                "Count" };
                    intLineNo = 1;
                    SaifeiAsm.ExcelHelper.WriteData <CSummaryRec>(objWorksheet,
                                                                  ref intLineNo,
                                                                  SaifeiAsm.ExcelHelper.ObjectParseMethord.UsingFields,
                                                                  logSummary,
                                                                  aTitle);
                    //write report content
                    objWorksheet      = objWorkbook.Worksheets[3];
                    objWorksheet.Name = "Compare Report";
                    aTitle            = new[] { "TimeStamp",
                                                "Category",
                                                "Source",
                                                "Indentifier",
                                                "Path",
                                                "Attribute Name",
                                                "Old Attribute Name",
                                                "New Attribute Name" };
                    intLineNo = 1;
                    SaifeiAsm.ExcelHelper.WriteData <CLogRec>(objWorksheet,
                                                              ref intLineNo,
                                                              SaifeiAsm.ExcelHelper.ObjectParseMethord.UsingFields,
                                                              logList,
                                                              aTitle);
                    objWorkbook.SaveAs(outputDir + "\\" + strReportName);
                    objWorkbook.Close();
                    objExcel.Visible = true;
                    objExcel.Quit();
                    objWorksheet = null;
                    objWorkbook  = null;
                    objExcel     = null;
                }
                catch (Exception e)
                {
                    System.Windows.MessageBox.Show("Error happened: '"
                                                   + e.Message
                                                   + "' Report could not be generated.");
                }
                finally
                {
                    if (objWorksheet != null)
                    {
                        objWorksheet = null;
                    }
                    if (objWorkbook != null)
                    {
                        objWorkbook.Close();
                        objWorkbook = null;
                    }
                    if (objExcel != null)
                    {
                        objExcel.Quit();
                        objExcel = null;
                    }
                }
            }

            if (showAlert && logList.Count > 0)
            {
                System.Windows.MessageBox.Show("Compare Report is Generated.\n" +
                                               "Please Check Folder '" + outputDir + "'.");
            }
            else if (logList.Count > 0)
            {
                RecordTextLog(outputDir + "\\" + strLogName,
                              "Differents is found between '" + fn1 + "' and '" + fn2
                              + "'. Please check compare report " + outputDir + "\\" + strReportName);
            }
            else
            {
                RecordTextLog(outputDir + "\\" + strLogName,
                              "Files '" + fn1 + "' and '" + fn2
                              + "' are identical per compare setting.");
            }
        }