Example #1
0
        /// <summary>
        /// 比对流程
        /// </summary>
        public string CompareTable(List <WhereModel> list, string tempfilename, PgsBar pgs)
        {
            try
            {
                string retmsg;
                List <TableCompareModel> source = isourcedal.GetTableListForModel(list);
                pgs.PgsScoroll(10, "源数据读取完成");
                List <TableCompareModel> target = itargetdal.GetTableListForModel(list);
                pgs.PgsScoroll(10, "目标数据读取完成");
                TableCompareList tblist = CompareTableList(source, target);
                pgs.PgsScoroll(10, "缺失表比对完成");
                pgs.SetPgsMax(tblist.tablelist.Count + 41);
                foreach (TableCompareModel model in tblist.tablelist)
                {
                    CompareColumn(model);
                    pgs.PgsScoroll(1, model.Tablename + "比对完成");
                }

                //完全匹配的表去掉
                tblist.tablelist.RemoveAll(x => x.Column.Count == 0);

                pgs.PgsScoroll(1, "正在生成比对结果");
                tblist.tablelist.AddRange(tblist.notablelist);
                if (CreateXmlFile(tblist.tablelist, GetXMLPath(tempfilename), out retmsg))
                {
                    pgs.SetMax("比对完成");
                }
                else
                {
                    pgs.PgsScoroll(0, retmsg);
                }
                return(retmsg);
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Example #2
0
        /// <summary>
        /// 表比对
        /// </summary>
        /// <param name="sourcelist"></param>
        /// <param name="targetlist"></param>
        /// <returns></returns>
        public TableCompareList CompareTableList(List <TableCompareModel> sourcelist, List <TableCompareModel> targetlist)
        {
            TableCompareList tblist = new TableCompareList();

            List <TableCompareModel> outlist = new List <TableCompareModel>();
            List <TableCompareModel> inlist  = new List <TableCompareModel>();

            #region 特殊情况(只有一个数据库存在数据)
            if (sourcelist.Count == 0 && targetlist.Count == 0)
            {
                return(null);
            }
            else if (sourcelist.Count != 0 && targetlist.Count == 0)
            {
                tblist.Isequal = "10";
                foreach (TableCompareModel tcmodel in sourcelist)
                {
                    tcmodel.Isequal = "10";
                }
                tblist.notablelist = sourcelist;
                return(tblist);
            }
            else if (sourcelist.Count == 0 && targetlist.Count != 0)
            {
                tblist.Isequal = "01";
                foreach (TableCompareModel tcmodel in targetlist)
                {
                    tcmodel.Isequal = "01";
                }
                tblist.notablelist = targetlist;
                return(tblist);
            }
            #endregion

            tblist.Isequal = "01";
            for (int i = 0; i < 2; i++)//两张表要相互
            {
                #region 表互换比较
                //第一次比较是为了找出源数据库中存在的表而目标数据库中不存在的表,同时对都有的表进行字段的匹配
                //第二次比较是为了找出目标数据库中存在的表而源数据库中不存在的表
                if (i == 0)
                {
                    outlist = sourcelist;
                    inlist  = targetlist;
                }
                else
                {
                    outlist = targetlist;
                    inlist  = sourcelist;
                }
                #endregion

                bool flag = false;
                foreach (TableCompareModel outmodel in outlist)//比较表名是否匹配
                {
                    flag = false;
                    string tbname = outmodel.Tablename;
                    foreach (TableCompareModel inmodel in inlist)
                    {
                        if (tbname == inmodel.Tablename)//匹配
                        {
                            if (i == 0)
                            {
                                inmodel.Isequal = "11";
                                tblist.tablelist.Add(inmodel);
                            }
                            flag = true;
                            break;
                        }
                    }
                    if (!flag)//表名不匹配
                    {
                        outmodel.Isequal = i == 0 ? "10" : "01";
                        tblist.notablelist.Add(outmodel);
                    }
                }
            }

            return(tblist);
        }