コード例 #1
0
ファイル: Form1.cs プロジェクト: ljhbeer/backup
 public void ClearData()
 {
     LP.Clear();
     SP.Clear();
     LDicDuplication.Clear();
     SDicDuplication.Clear();
     LSpecial.Clear();
     SSpecial.Clear();
     _Same.Clear();
 }
コード例 #2
0
ファイル: Form1.cs プロジェクト: ljhbeer/backup
        private void CompareTable(ExcelSheetTable S, ExcelSheetTable L)
        {
            if (!CompareListString(S.Titles.Select(r => r.Text).ToList(), L.Titles.Select(r => r.Text).ToList()))
            {
                textBoxOut.Text = "两张表的表头不一致,无法比较";
                return;
            }
            ClearData();
            string        str = "", strL = "", strS = "", strLS = "";
            StringBuilder strb = new StringBuilder();
            StringBuilder strT = new StringBuilder();
            Dictionary <string, Cells> LDic = ListToDictionary(L.Names, ref strL);
            Dictionary <string, Cells> SDic = ListToDictionary(S.Names, ref strS);

            Dictionary <string, Cells> LDicSpecial = new Dictionary <string, Cells>();
            Dictionary <string, Cells> SDicSpecial = new Dictionary <string, Cells>();

            /////////////////////////////////////////////////////  Duplication
            if (checkBoxCopyDuplicationL.Checked)
            {
                LDicDuplication = FindDuplication(L.Names);
            }
            if (checkBoxCopyDuplicationS.Checked)
            {
                SDicDuplication = FindDuplication(S.Names);
            }
            if (strS != "")
            {
                str += "\r\n============小表中以下值存在重复============\r\n" + strS;
            }
            if (strL != "")
            {
                str += "\r\n============大表中以下值存在重复============\r\n" + strL;
            }

            foreach (Cells c in S.Names)
            {
                if (!LDic.ContainsKey(c.Text))
                {
                    strLS += c + "\t";
                }
            }

            ////////////////////////////////////////////////  Special
            if (checkBoxTagS.Checked || checkBoxSkipDuplicate.Checked)  //排除重复
            {
                foreach (Cells c in S.Names)
                {
                    if (!LDic.ContainsKey(c.Text) && !SDicDuplication.ContainsKey(c.Text))
                    {
                        SSpecial.Add(new Point(c.Row, c.Col));
                        if (!SDicSpecial.ContainsKey(c.Text))
                        {
                            SDicSpecial[c.Text] = c;
                        }
                    }
                }
            }
            if (checkBoxTagL.Checked || checkBoxSkipDuplicate.Checked)
            {
                foreach (Cells c in L.Names)
                {
                    if (!SDic.ContainsKey(c.Text) && !LDicDuplication.ContainsKey(c.Text))
                    {
                        LSpecial.Add(new Point(c.Row, c.Col));
                        if (!LDicSpecial.ContainsKey(c.Text))
                        {
                            LDicSpecial[c.Text] = c;
                        }
                    }
                }
            }
            if (strLS != "")
            {
                strLS = "\r\n============小表中的以下值在大表中不存在============\r\n" + strLS;
            }
            if (str != "")
            {
                textBoxOut.Text = str + strLS;
                if (!checkBoxSkipDuplicate.Checked)
                {
                    MessageBox.Show("存在重复值,没有进一步比对,可选择忽略之后,继续比对");
                    return;
                }
            }
            ///////////////////////// DIF
            SP    = new List <Point>();
            LP    = new List <Point>();
            _Same = new List <List <Cells> >();
            foreach (Cells c1 in S.Names)
            {
                if (str != "" &&
                    (SDicDuplication.ContainsKey(c1.Text) ||
                     SDicSpecial.ContainsKey(c1.Text)))
                {
                    continue;
                }
                Cells c2 = LDic[c1.Text];
                for (int col = 1; col < S.ColCount - 1; col++)
                {
                    if (S.CellValue(c1.Row, S.NameCol + col) != L.CellValue(c2.Row, L.NameCol + col))
                    {
                        SP.Add(new Point(c1.Row, S.NameCol + col));
                        LP.Add(new Point(c2.Row, L.NameCol + col));
                        strb.AppendLine(c1.Text + " " + PointTostring(new Point(c1.Row, col)) + "=" + S.CellValue(c1.Row, S.NameCol + col) + "\t"
                                        + PointTostring(new Point(c2.Row, col)) + "=" + L.CellValue(c2.Row, L.NameCol + col));
                    }
                }
                _Same.Add(new List <Cells>()
                {
                    c1, c2
                });
            }
            string str1 = strb.ToString();

            if (str1 == "")
            {
                MessageBox.Show("除忽略项外,待比较项目完全相同");
            }
            else
            {
                str1 = "\r\n============以下单元格内容两表不一致 (行号,列号)============\r\n" + str1;
            }
            textBoxOut.Text = str + strLS + str1;
        }