/// <summary> /// 文件流水号规范化 /// </summary> /// <param name="kind"></param> /// <param name="tableName"></param> /// <param name="fileDir"></param> /// <param name="bd"></param> /// <param name="prevObj"></param> private void FormatFileNumber(string kind, string tableName, string fileDir, BaseDao bd, string pwjm, int bits) { string wjm, wjm_prefix, pwjm_prefix; string newWjm; int lastNumber = 0; int count = 0; int total = bd.CountNormalPM(kind); int CSIZE = 10000; while (count < total) { int end; if (count + CSIZE > total) end = total; else end = count + CSIZE; //取出指定表的所有记录, 一次取出CSIZE的记录 //ICollection<Object> List = bd.GetAllPM_WJM(kind, tableName); ICollection<Object> List = bd.GetAllPM_WJM(kind, tableName, count+1, end); //遍历每一条记录 foreach (Object obj in List) { //防止假死 Application.DoEvents(); //取出文件名 wjm = (string)obj; if (wjm == null || "".Equals(wjm)) continue; wjm_prefix = CommonMethod.GetWjmPrefix(wjm); pwjm_prefix = CommonMethod.GetWjmPrefix(pwjm); //判断该文件是否采用上一个文件的编号 if (CommonMethod.ContinueNumber(pwjm_prefix, wjm_prefix)) { newWjm = bd.SetNextWjm(kind, tableName, wjm, wjm_prefix, lastNumber + 1, bits); lastNumber = lastNumber + 1; } else //重新编号,从1开始 { newWjm = bd.SetNextWjm(kind, tableName, wjm, wjm_prefix, 1, bits); lastNumber = 0; } if (!newWjm.Equals(wjm)) { CommonMethod.FileRename(wjm, newWjm, fileDir); } this.normalListBox.Items.Insert(0, newWjm); //更新文件名 pwjm = wjm; count++; this.normalLabel.Text = "文件名规范完成数:" + count; int percent = (int)(count * 100.0 / normal_count); if (percent > 100) percent = 100; this.normalProgressBar.Value = percent; } } }
/// <summary> /// 进行数据库表的规范 /// </summary> /// <param name="kind"></param> /// <param name="bd"></param> /// <param name="prevObj"></param> private void FormatDBTable(string kind, BaseDao bd, Object prevObj) { //清除历史记录 this.compLabel.Text = ""; this.origListBox.Items.Clear(); this.badListBox.Items.Clear(); this.encryListBox.Items.Clear(); this.normalListBox.Items.Clear(); this.recordProgressBar.Value = 0; //创建四张表:正常、加密、异常、重复的表 bd.CreateTable(kind); int count = 0; int total = bd.CountPM(kind); int CSize = 10000; while (count < total) { int end; if (count + CSize > total) end = total; else end = count + CSize; //按照查重字段排序 //ICollection<Object> list = bd.GetALL_PM(); ICollection<Object> list = bd.GetPart_PM(kind, count+1, end); normal_count = 0; //遍历每一条记录,根据文件名进行分类 foreach (Object obj in list) { Application.DoEvents(); Object nowObj = obj; //返回文件名字段 string wjm = bd.GetWjm(ref nowObj); //显示在listbox中 if (wjm != null && !wjm.Equals("NoExist")) this.origListBox.Items.Insert(0, wjm); //字段规范 bd.SemiConvert(ref nowObj); count++; this.compLabel.Text = "根据文件分类完成数:" + count; this.recordProgressBar.Value = (int)(count * 100.0 / total); //判断重复 if (bd.IsReplicate(ref nowObj, ref prevObj)) { //重复,插入到“重复表”中 bd.InsertDiff_PM(kind + "_PM_REP", ref nowObj); continue; } //分类, 0:正常,1:加密,2:异常 int ret = 2; if (wjm.Equals("NoExist")) ret = 0; //不存在文件名字段 else { ret = CommonMethod.ClassifyByWjm(this.fileDirTextBox.Text, wjm); } switch (ret)//根据分类插入到不同表 { case 0: //插入到正常表中 normal_count++; bd.InsertDiff_PM(kind + "_PM_NORMAL", ref nowObj); //拷贝文件到指定路径 if (!wjm.Equals("NoExist")) CommonMethod.FileMove(wjm, this.fileDirTextBox.Text, this.normalTextBox.Text); //显示在listbox中 if (wjm != null && !wjm.Equals("NoExist")) this.normalListBox.Items.Insert(0, wjm); break; case 1: //插入到加密表中 bd.InsertDiff_PM(kind + "_PM_ENCRY", ref nowObj); //拷贝文件到指定路径 CommonMethod.FileMove(wjm, this.fileDirTextBox.Text, this.encryTextBox.Text); //显示在listbox中 if (wjm != null) this.encryListBox.Items.Insert(0, wjm); break; case 2: //插入到异常表中 bd.InsertDiff_PM(kind + "_PM_BAD", ref nowObj); //显示在listbox中 if (wjm != null) this.badListBox.Items.Insert(0, wjm); break; default: //do nothing break; } //更新记录 prevObj = nowObj; this.Refresh(); } } this.compLabel.Text = "总共完成数:" + count; this.recordProgressBar.Value = 100; this.Refresh(); }