예제 #1
0
파일: Form1.cs 프로젝트: ljhbeer/backup
 private void comboBoxSSheetName_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (checkBoxCompareSingle.Checked)
     {
         ExcelBook E = new ExcelBook(m_cfg.XlsName);
         DataTable S = null, L = null;
         try
         {
             if (!checkBoxRedTitle.Checked)
             {
                 ExcelSingleSheet ES = new ExcelSingleSheet(E.ExcelSheet(comboBoxSSheetName.SelectedItem.ToString()));
                 if (!ES.CanCheckSingleSheet(ref S, ref L))
                 {
                     MessageBox.Show(ES.Msg);
                     return;
                 }
             }
             else
             {
                 ExcelSingleRedSheet ES = new ExcelSingleRedSheet(E.ExcelSheet(comboBoxSSheetName.SelectedItem.ToString()));
                 if (!ES.CanCheckSingleSheet(ref S, ref L, checkBoxMultiBlackSkip.Checked))
                 {
                     MessageBox.Show(ES.Msg);
                     return;
                 }
             }
             dgvL.DataSource = L;
             dgvS.DataSource = S;
         }
         finally
         {
             E = null;
             ExcelBook.excel.Workbooks.Close();
         }
     }
 }
예제 #2
0
파일: Form1.cs 프로젝트: ljhbeer/backup
        private void CompareRedSingleSheetClick()
        {
            DataTable DL = (DataTable)dgvL.DataSource;
            DataTable DS = (DataTable)dgvS.DataSource;

            if (DL == null || DS == null || DL.Columns.Count != DS.Columns.Count)
            {
                return;
            }
            for (int i = 0; i < DL.Columns.Count; i++)
            {
                if (DL.Columns[i].ColumnName != DS.Columns[i].ColumnName)
                {
                    MessageBox.Show("两边待比较的表头不一致");
                    return;
                }
            }

            ExcelBook           E = new ExcelBook(m_cfg.XlsName);
            ExcelSingleRedSheet ES = new ExcelSingleRedSheet(E.ExcelSheet(comboBoxSSheetName.SelectedItem.ToString()));
            ExcelRedSheetTable  S = null, L = null;

            string cmptablename = "";

            try
            {
                if (!ES.CanCheckSingleSheet(ref S, ref L, ref cmptablename, checkBoxMultiBlackSkip.Checked))
                {
                    MessageBox.Show("S=" + (S != null) + " " + "L=" + (L != null) + " SL两表之一可能未完成");
                    return;
                }
                if (checkBoxClearBackColor.Checked)
                {
                    S.ClearBackColor();
                    L.ClearBackColor();
                }
                CompareTable(S, L);
                if (checkBoxTagL.Checked || checkBoxTagS.Checked)
                {
                    if (LSpecial.Count > 0 || SSpecial.Count > 0)
                    {
                        ES.FormatExcelRange(SSpecial, _colorSpe, "特有", S.TagCol);
                        ES.FormatExcelRange(LSpecial, _colorSpe, "特有", L.TagCol);
                    }
                }
                if (checkBoxCopyDuplicationL.Checked || checkBoxCopyDuplicationS.Checked)
                {
                    if (LDicDuplication.Count > 0 || SDicDuplication.Count > 0)
                    {
                        List <int> LDuplication = new List <int>();
                        List <int> SDuplication = new List <int>();
                        foreach (List <int> l in LDicDuplication.Values)
                        {
                            LDuplication.AddRange(l);
                        }
                        foreach (List <int> l in SDicDuplication.Values)
                        {
                            SDuplication.AddRange(l);
                        }

                        List <Point> SD = SDuplication.Select(r => new Point(r, S.NameCol)).ToList();
                        List <Point> LD = LDuplication.Select(r => new Point(r, L.NameCol)).ToList();
                        ES.FormatExcelRange(SD, _colorDup, "重复", S.TagCol);
                        ES.FormatExcelRange(LD, _colorDup, "重复", L.TagCol);
                    }
                }
                if (checkBoxDifL.Checked || checkBoxDifS.Checked)
                {
                    if (LP.Count > 0 || SP.Count > 0)
                    {
                        ES.FormatExcelRange(SP, _colorDif, "不同", S.TagCol + 1);
                        ES.FormatExcelRange(LP, _colorDif, "不同", L.TagCol + 1);
                    }
                }

                for (int i = 0; i < _Same.Count; i++)
                {
                    if (_Same[i].Count == 2)
                    {
                        Cells c = _Same[i][0];
                        ES.SortExcelRange(new Point(c.Row, c.Col), cmptablename + i, S.TagCol);
                        c = _Same[i][1];
                        ES.SortExcelRange(new Point(c.Row, c.Col), cmptablename + i, L.TagCol);
                    }
                }
                /////
                ES.SetExcelRangeTag(1, cmptablename + "比较结果", S.TagCol);
                ES.SetExcelRangeTag(1, cmptablename + "比较结果", L.TagCol);
            }
            catch (Exception ex)
            {
                MessageBox.Show("程序有点小问题\r\n" + ex.Message);
            }
            finally
            {
                S = null;
                L = null;
                ExcelBook.excel.ActiveWorkbook.Save();
                ExcelBook.excel.Workbooks.Close();
            }
        }