Esempio n. 1
0
        /// <summary>
        /// 上传线表
        /// </summary>
        private bool UpLoadLineSheet()
        {
            if (String.IsNullOrEmpty(this.textEditLineSheet.Text))
            {
                MessageBox.Show("线表表单为空!请选择点表", "提示");
                return(true);
            }

            DataSet   dataSetLine   = ExcelToDataSet(excelPath, this.textEditLineSheet.Text.Trim());
            DataTable dataTableLine = dataSetLine.Tables[0];

            dataTableLine.Columns.Add("FileName", typeof(string));
            dataTableLine.Columns.Add("Uploadtime", typeof(string));
            for (int i = 0; i < dataTableLine.Rows.Count; i++)
            {
                dataTableLine.Rows[i]["FileName"] = Path.GetFileNameWithoutExtension(excelPath);

                dataTableLine.Rows[i]["Uploadtime"] = DateTime.Now.ToString();
            }

            Maticsoft.BLL.cjpll cjpllBLL = new Maticsoft.BLL.cjpll();

            List <Maticsoft.Model.cjpll> cjpllModelList = cjpllBLL.DataTableToList(dataTableLine);

            Maticsoft.BLL.cjpllback          cjpllBackBLL       = new Maticsoft.BLL.cjpllback();
            List <Maticsoft.Model.cjpllback> cjplpBackModelList = cjpllBackBLL.DataTableToList(dataTableLine);

            Maticsoft.BLL.exportinfo   exportinfoBLL   = new Maticsoft.BLL.exportinfo();
            Maticsoft.Model.exportinfo exportinfoModel = new Maticsoft.Model.exportinfo();



            for (int i = 0; i < cjpllModelList.Count; i++)
            {
                List <Maticsoft.Model.exportinfo> exportinfosModelList = exportinfoBLL.GetModelList("");

                //不重复的数据
                if (!cjpllBLL.Exists(cjpllModelList[i].Exp_No0, cjpllModelList[i].Exp_No1))
                {
                    cjpllBLL.Add(cjpllModelList[i]);
                }
                else
                {
                    //存在就更新原始数据中的线表属性,因为可能修改了其它属性信息
                    cjpllBLL.Update(cjpllModelList[i]);

                    //备份的数据库中,不重复的数据,则插入,否则,则更新
                    if (!cjpllBackBLL.Exists(cjpllModelList[i].Exp_No0, cjpllModelList[i].Exp_No1))
                    {
                        cjpllBackBLL.Add(cjplpBackModelList[i]);
                    }
                    else
                    {
                        cjpllBackBLL.Update(cjplpBackModelList[i]);
                    }
                }

                //导出配置表(exportinfo)中有配置数据,则对比
                if (exportinfosModelList.Count > 0)
                {
                    Int32 flag = 0;
                    //导出表的配置
                    for (int j = 0; j < exportinfosModelList.Count; j++)
                    {
                        if (exportinfosModelList[j].Address != cjpllModelList[i].Address ||
                            !cjpllModelList[i].FileName.Contains(exportinfosModelList[j].Basin) ||
                            !cjpllModelList[i].FileName.Contains(exportinfosModelList[j].Strname) ||
                            !cjpllModelList[i].FileName.Contains(exportinfosModelList[j].Plot))
                        {
                            flag++;
                        }
                    }

                    if (flag == exportinfosModelList.Count)
                    {
                        string[] tempArr = cjpllModelList[i].FileName.Split('-');
                        //导出配置表(exportinfo)中没有配置数据,则直接插入
                        exportinfoModel.Address = cjpllModelList[i].Address;

                        exportinfoModel.Basin   = tempArr.Length > 0 ? tempArr[0] : string.Empty;
                        exportinfoModel.Strname = tempArr.Length > 1 ? tempArr[1] : string.Empty;
                        exportinfoModel.Plot    = tempArr.Length > 2 ? tempArr[2].Substring(0, tempArr[2].IndexOf("_")) : string.Empty;

                        exportinfoModel.FileName = cjpllModelList[i].FileName;
                        exportinfoBLL.Add(exportinfoModel);
                    }
                }
                else
                {
                    string[] tempArr = cjpllModelList[i].FileName.Split('-');
                    //导出配置表(exportinfo)中没有配置数据,则直接插入
                    exportinfoModel.Address = cjpllModelList[i].Address;

                    exportinfoModel.Basin   = tempArr.Length > 0 ? tempArr[0] : string.Empty;
                    exportinfoModel.Strname = tempArr.Length > 1 ? tempArr[1] : string.Empty;
                    exportinfoModel.Plot    = tempArr.Length > 2 ? tempArr[2].Substring(0, tempArr[2].IndexOf("_")) : string.Empty;

                    exportinfoModel.FileName = cjpllModelList[i].FileName;
                    exportinfoBLL.Add(exportinfoModel);
                }
            }



            return(false);
        }
Esempio n. 2
0
        public static void asynExportInfoTabl()
        {
            // List<string> list = new List<string>();
            //点表
            Maticsoft.BLL.cjplp          cjplpBLL       = new Maticsoft.BLL.cjplp();
            List <Maticsoft.Model.cjplp> cjplpModelList = cjplpBLL.GetFileNames();

            //线表
            Maticsoft.BLL.cjpll          cjpllBLL       = new Maticsoft.BLL.cjpll();
            List <Maticsoft.Model.cjpll> cjpllModelList = cjpllBLL.GetFileNames();

            Maticsoft.BLL.exportinfo          exportinfoBLL        = new Maticsoft.BLL.exportinfo();
            Maticsoft.Model.exportinfo        exportinfoModel      = new Maticsoft.Model.exportinfo();
            List <Maticsoft.Model.exportinfo> exportinfosModelList = exportinfoBLL.GetModelList("");

            if (cjplpModelList.Count > 0)
            {
                //第一种情况:对于数据库中有的,但是同步表中没有的,需要增加
                var exp2 = cjplpModelList.Where(a => !exportinfosModelList.Exists(t => a.FileName.Contains(t.FileName))).ToList();
                // Console.WriteLine("--查找student1集合中存在,而student2不存在的数据--");
                foreach (var item in exp2)
                {
                    // Console.WriteLine("{0} \t {1} \t {2}", item.name, item.subject, item.score);
                    string[] tempArr = item.FileName.Split('-');
                    //导出配置表(exportinfo)中没有配置数据,则直接插入
                    exportinfoModel.Address  = item.Address;
                    exportinfoModel.Basin    = tempArr.Length > 0 ? tempArr[0] : string.Empty;
                    exportinfoModel.Strname  = tempArr.Length > 1 ? tempArr[1] : string.Empty;
                    exportinfoModel.Plot     = tempArr.Length > 2 ? tempArr[2].Substring(0, tempArr[2].IndexOf("_")) : string.Empty;
                    exportinfoModel.FileName = item.FileName;
                    exportinfoBLL.Add(exportinfoModel);
                }
            }

            if (cjpllModelList.Count > 0)
            {
                //第一种情况:对于数据库中有的,但是同步表中没有的,需要增加
                var exp2 = cjpllModelList.Where(a => !exportinfosModelList.Exists(t => a.FileName.Contains(t.FileName))).ToList();
                // Console.WriteLine("--查找student1集合中存在,而student2不存在的数据--");
                foreach (var item in exp2)
                {
                    // Console.WriteLine("{0} \t {1} \t {2}", item.name, item.subject, item.score);
                    string[] tempArr = item.FileName.Split('-');
                    //导出配置表(exportinfo)中没有配置数据,则直接插入
                    exportinfoModel.Address  = item.Address;
                    exportinfoModel.Basin    = tempArr.Length > 0 ? tempArr[0] : string.Empty;
                    exportinfoModel.Strname  = tempArr.Length > 1 ? tempArr[1] : string.Empty;
                    exportinfoModel.Plot     = tempArr.Length > 2 ? tempArr[2].Substring(0, tempArr[2].IndexOf("_")) : string.Empty;
                    exportinfoModel.FileName = item.FileName;
                    exportinfoBLL.Add(exportinfoModel);
                }
            }

            if (exportinfosModelList.Count > 0)
            {
                //第二种情况:对于数据库中有的,但是同步表中没有的,需要增加
                List <Maticsoft.Model.exportinfo> expPoint = exportinfosModelList.Where(a => !cjplpModelList.Exists(t => a.FileName.Contains(t.FileName))).ToList();
                List <Maticsoft.Model.exportinfo> exLine   = exportinfosModelList.Where(a => !cjpllModelList.Exists(t => a.FileName.Contains(t.FileName))).ToList();
                // Console.WriteLine("--查找student1集合中存在,而student2不存在的数据--");

                List <Maticsoft.Model.exportinfo> resultExportinfosList = expPoint.Union(exLine).ToList();
                foreach (Maticsoft.Model.exportinfo item in resultExportinfosList)
                {
                    exportinfoBLL.Delete(item.id);
                }
            }
        }