private void BzhRuleForm_Load(object sender, EventArgs e) { if (_ruleInfo != null) { tb_rulename.Text = _ruleInfo.ruleName; BzhRuleRoot _myRoot = (_ruleInfo._root as BzhRuleRoot); tb_explain.Text = _myRoot._shuoming; //大标题 cbb_dbthj.Text = _myRoot._dbthjType; nud_dbthjvalue.Value = _myRoot._dbthjValue; cbb_dbtdq.Text = _myRoot._dbtdqType; cbb_dbtkh.Text = _myRoot._dbtkh.ToString(); tb_dbtzt.Text = _myRoot._dbtzt; nud_dbtzh.Value = _myRoot._dbtzh; cb_dbtct.Checked = _myRoot._dbtct; nud_dbtsj.Value = _myRoot._dbtsj; //副标题 cbb_fbthj.Text = _myRoot._fbthjType; nud_fbthjvalue.Value = _myRoot._fbthjValue; cbb_fbtdq.Text = _myRoot._fbtdqType; cbb_fbtkh.Text = _myRoot._fbtkh.ToString(); tb_fbtzt.Text = _myRoot._fbtzt; nud_fbtzh.Value = _myRoot._fbtzh; cb_fbtct.Checked = _myRoot._fbtct; nud_fbtsj.Value = _myRoot._fbtsj; //正文 cbb_zwhj.Text = _myRoot._zwhjType; nud_zwhjvalue.Value = _myRoot._zwhjValue; cbb_zwdq.Text = _myRoot._zwdqType; cbb_zwkh.Text = _myRoot._zwkh.ToString(); tb_zwzt.Text = _myRoot._zwzt; nud_zwzh.Value = _myRoot._zwzh; cb_zwct.Checked = _myRoot._zwct; nud_zwsj.Value = _myRoot._zwsj; //一级标题 cbb_yjbthj.Text = _myRoot._yjbthjType; nud_yjbthjvalue.Value = _myRoot._yjbthjValue; cbb_yjbtdq.Text = _myRoot._yjbtdqType; cbb_yjbtkh.Text = _myRoot._yjbtkh.ToString(); tb_yjbtzt.Text = _myRoot._yjbtzt; nud_yjbtzh.Value = _myRoot._yjbtzh; cb_yjbtct.Checked = _myRoot._yjbtct; nud_yjbtsj.Value = _myRoot._yjbtsj; //二级标题 cbb_ejbthj.Text = _myRoot._ejbthjType; nud_ejbthjvalue.Value = _myRoot._ejbthjValue; cbb_ejbtdq.Text = _myRoot._ejbtdqType; cbb_ejbtkh.Text = _myRoot._ejbtkh.ToString(); tb_ejbtzt.Text = _myRoot._ejbtzt; nud_ejbtzh.Value = _myRoot._ejbtzh; cb_ejbtct.Checked = _myRoot._ejbtct; nud_ejbtsj.Value = _myRoot._ejbtsj; //三级标题 cbb_sjbthj.Text = _myRoot._sjbthjType; nud_sjbthjvalue.Value = _myRoot._sjbthjValue; cbb_sjbtdq.Text = _myRoot._sjbtdqType; cbb_sjbtkh.Text = _myRoot._sjbtkh.ToString(); tb_sjbtzt.Text = _myRoot._sjbtzt; nud_sjbtzh.Value = _myRoot._sjbtzh; cb_sjbtct.Checked = _myRoot._sjbtct; nud_sjbtsj.Value = _myRoot._sjbtsj; //页边距 nud_zuobianju.Value = _myRoot._zuobianju; nud_youbianju.Value = _myRoot._youbianju; nud_shangbianju.Value = _myRoot._shangbianju; nud_xiabianju.Value = _myRoot._xiabianju; //页眉设置 tb_ymnr.Text = _myRoot._yemeinr; tb_ymzt.Text = _myRoot._yemeizt; nud_ymzh.Value = _myRoot._yemeizh; cb_ymct.Checked = _myRoot._yemeict; cbb_ymjz.Text = _myRoot._yemeijz; //页脚设置 tb_yjnr.Text = _myRoot._yjnr; tb_yjzt.Text = _myRoot._yjzt; nud_yjzh.Value = _myRoot._yjzh; cb_yjct.Checked = _myRoot._yjct; cbb_yjjz.Text = _myRoot._yjjz; //页码设置 cbb_ymags.Text = _myRoot._ymgs; cbb_ymazt.Text = _myRoot._ymzt; cbb_ymajz.Text = _myRoot._ymjz; //文中空行消除 cb_xckh.Checked = _myRoot._khxc; //标注名称 tb_name.Text = _myRoot._bzmc; //文本范围 tb_fanwei.Text = _myRoot._wbfw; //文本内容 tb_neirong.Text = _myRoot._wbnr; } }
/// <summary> /// 点击保存按钮时触发的事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void lbl_baocun_Click(object sender, EventArgs e) { BzhRuleRoot _myRoot = new BzhRuleRoot(); _myRoot._shuoming = tb_explain.Text; //大标题 _myRoot._dbthjType = cbb_dbthj.Text; _myRoot._dbthjValue = nud_dbthjvalue.Value; _myRoot._dbtdqType = cbb_dbtdq.Text; _myRoot._dbtkh = Convert.ToInt32(cbb_dbtkh.Text); _myRoot._dbtzt = tb_dbtzt.Text; _myRoot._dbtzh = nud_dbtzh.Value; _myRoot._dbtct = cb_dbtct.Checked; _myRoot._dbtsj = nud_dbtsj.Value; //副标题 ; _myRoot._fbthjType = cbb_fbthj.Text; _myRoot._fbthjValue = nud_fbthjvalue.Value; _myRoot._fbtdqType = cbb_fbtdq.Text; _myRoot._fbtkh = Convert.ToInt32(cbb_fbtkh.Text); _myRoot._fbtzt = tb_fbtzt.Text; _myRoot._fbtzh = nud_fbtzh.Value; _myRoot._fbtct = cb_fbtct.Checked; _myRoot._fbtsj = nud_fbtsj.Value; //正文 ; _myRoot._zwhjType = cbb_zwhj.Text; _myRoot._zwhjValue = nud_zwhjvalue.Value; _myRoot._zwdqType = cbb_zwdq.Text; _myRoot._zwkh = Convert.ToInt32(cbb_zwkh.Text); _myRoot._zwzt = tb_zwzt.Text; _myRoot._zwzh = nud_zwzh.Value; _myRoot._zwct = cb_zwct.Checked; _myRoot._zwsj = nud_zwsj.Value; //一级标题 ; _myRoot._yjbthjType = cbb_yjbthj.Text; _myRoot._yjbthjValue = nud_yjbthjvalue.Value; _myRoot._yjbtdqType = cbb_yjbtdq.Text; _myRoot._yjbtkh = Convert.ToInt32(cbb_yjbtkh.Text); _myRoot._yjbtzt = tb_yjbtzt.Text; _myRoot._yjbtzh = nud_yjbtzh.Value; _myRoot._yjbtct = cb_yjbtct.Checked; _myRoot._yjbtsj = nud_yjbtsj.Value; //二级标题 ; _myRoot._ejbthjType = cbb_ejbthj.Text; _myRoot._ejbthjValue = nud_ejbthjvalue.Value; _myRoot._ejbtdqType = cbb_ejbtdq.Text; _myRoot._ejbtkh = Convert.ToInt32(cbb_ejbtkh.Text); _myRoot._ejbtzt = tb_ejbtzt.Text; _myRoot._ejbtzh = nud_ejbtzh.Value; _myRoot._ejbtct = cb_ejbtct.Checked; _myRoot._ejbtsj = nud_ejbtsj.Value; //三级标题 ; _myRoot._sjbthjType = cbb_sjbthj.Text; _myRoot._sjbthjValue = nud_sjbthjvalue.Value; _myRoot._sjbtdqType = cbb_sjbtdq.Text; _myRoot._sjbtkh = Convert.ToInt32(cbb_sjbtkh.Text); _myRoot._sjbtzt = tb_sjbtzt.Text; _myRoot._sjbtzh = nud_sjbtzh.Value; _myRoot._sjbtct = cb_sjbtct.Checked; _myRoot._sjbtsj = nud_sjbtsj.Value; //页边距 ; _myRoot._zuobianju = nud_zuobianju.Value; _myRoot._youbianju = nud_youbianju.Value; _myRoot._shangbianju = nud_shangbianju.Value; _myRoot._xiabianju = nud_xiabianju.Value; //页眉设置 ; _myRoot._yemeinr = tb_ymnr.Text; _myRoot._yemeizt = tb_ymzt.Text; _myRoot._yemeizh = nud_ymzh.Value; _myRoot._yemeict = cb_ymct.Checked; _myRoot._yemeijz = cbb_ymjz.Text; //页脚设置 ; _myRoot._yjnr = tb_yjnr.Text; _myRoot._yjzt = tb_yjzt.Text; _myRoot._yjzh = nud_yjzh.Value; _myRoot._yjct = cb_yjct.Checked; _myRoot._yjjz = cbb_yjjz.Text; //页码设置 ; _myRoot._ymgs = cbb_ymags.Text; _myRoot._ymzt = cbb_ymazt.Text; _myRoot._ymjz = cbb_ymajz.Text; //文中空行消除 ; _myRoot._khxc = cb_xckh.Checked; //标注名称 ; _myRoot._bzmc = tb_name.Text; //文本范围 ; _myRoot._wbfw = tb_fanwei.Text; //文本内容 ; _myRoot._wbnr = tb_neirong.Text; //构造一个ruleinfo _ruleInfo = new RuleInfo(tb_rulename.Text, SystemInfo._currentModule, _myRoot, SystemInfo._userInfo._shiming, DateTime.Now.ToString("yyyy-MM-dd")); //保存到数据库的规则信息表中 _ruleInfo.SaveRuleInfo(); this.DialogResult = DialogResult.OK; }
/// <summary> /// 点击开始按钮时触发的事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void lbl_kaishi_Click(object sender, EventArgs e) { //修改程序状态为执行,刷新状态信息 lbl_zhuangtai.Text = "正在进行数据解析……"; lbl_kaishi.Enabled = false; lbl_kaishi.BackColor = Color.Gray; statue = 1; //获得文件夹下所有的文件名 for (int i = folderIndex; i < dgv_task.Rows.Count; i++) { folderIndex = i;//时刻记录当前程序执行到的文件夹位置 string folder = dgv_task.Rows[i].Cells[1].Value.ToString(); string[] files = Directory.GetFiles(folder); for (int k = fileIndex; k < files.Length; k++) { //计算百分率 double _processRate = 100 * Convert.ToDouble(k + 1) / Convert.ToDouble(files.Length); dgv_task.Rows[i].Cells[3].Value = $"{_processRate.ToString("00.00")}%"; Application.DoEvents(); //如果用户终止了或者暂停了程序,就跳出循环 if (statue == 0 || statue == 2) { return; } fileIndex = k;//时刻记录当前程序执行到的文件位置 string file = files[k]; #region 1、文件名格式标准化 /*1、开始文件名格式标准化*/ string path = Path.GetDirectoryName(file); string fileOriginal = Path.GetFileNameWithoutExtension(file); string extension = Path.GetExtension(file); string filename = string.Empty;//用于存放改后的文件名 //判断“文件名标准化”格式,如果不是“无”,则进行文件名格式标准化 if (!SystemInfo._userInfo._wjmbzh.Equals("无")) { //拆分出路径和文件名 ///拆分后的文件名集合,对list进行处理,如果是\d星,那么要和前一项合并 List <string> list = Regex.Split(fileOriginal, @"\.").ToList(); for (int j = 0; j < list.Count; j++) { if (Regex.IsMatch(list[j], @"\d星")) { list[j] = $"{list[j - 1] }.{list[j]}"; list.RemoveAt(j - 1); break; } } //获得文件名标准格式下的所有rule名称 FormatInfo fi = new FormatInfo(SystemInfo._userInfo._wjmbzh); fi.GetFormatInfo(); List <string> rules = Regex.Split(fi._formatSet, @"\|").ToList(); //对每一个rule循环,获得设置root foreach (string rule in rules) { RuleInfo myri = new RuleInfo(rule, "文件名标准化"); myri.GetRuleInfo(); WjmRuleRoot myroot = ((WjmRuleRoot)myri._root); //判断位置,得到操作目标,对每种可能的目标进行判断操作 if (myroot.position[0].Equals("整个文件名")) { //对操作目标进行操作 if (!myroot.delete.Trim().Equals(string.Empty)) { filename = Regex.Replace(fileOriginal, myroot.delete.Trim(), ""); } else if (!myroot.replace0.Trim().Equals(string.Empty)) { filename = Regex.Replace(fileOriginal, myroot.replace0.Trim(), myroot.replace); } } else if (myroot.position[0].Equals("文件名前")) { //新增内容 if (!myroot.newText.Trim().Equals(string.Empty)) { filename = $"{myroot.newText}{fileOriginal}"; } } else if (myroot.position[0].Equals("文件名后")) { //新增内容 if (!myroot.newText.Trim().Equals(string.Empty)) { filename = $"{fileOriginal}{myroot.newText}"; } } else if (Regex.IsMatch(myroot.position[0], @"文件名第\d项前")) { //获得数字,然后获得目标文本 int index = Convert.ToInt32(Regex.Match(myroot.position[0], @"\d").Value); string target = list[index - 1]; //新增内容 if (!myroot.newText.Trim().Equals(string.Empty)) { target = $"{myroot.newText.Trim()}{target}"; } list[index - 1] = target; filename = string.Join(".", list); } else if (Regex.IsMatch(myroot.position[0], @"文件名第\d项后")) { //获得数字,然后获得目标文本 int index = Convert.ToInt32(Regex.Match(myroot.position[0], @"\d").Value); string target = list[index - 1]; //新增内容 if (!myroot.newText.Trim().Equals(string.Empty)) { target = $"{target}{myroot.newText.Trim()}"; } list[index - 1] = target; filename = string.Join(".", list); } //给文件改名 File.Move($"{file}", $"{path}\\{filename}{extension}"); } } else//如果不进行文件名标准化,那么新得文件名和原先一样 { filename = fileOriginal; } string currentFilename = $"{path}\\{filename}{extension}"; #endregion #region 2、文档格式标准化 //判断“文档格式标准化”格式,如果用户不是选择了“无”,则执行文件格式标准化 if (!SystemInfo._userInfo._wjbzh.Equals("无")) { //获得标准化规则 FormatInfo _format = new FormatInfo(SystemInfo._userInfo._wjbzh); _format.GetFormatInfo(); string _rule = Regex.Split(_format._formatSet, @"\|")[0]; RuleInfo _ruleInfo = new RuleInfo(_rule, "格式标准化"); _ruleInfo.GetRuleInfo(); BzhRuleRoot _root = _ruleInfo._root as BzhRuleRoot; //调整文档格式,包括大标题,副标题,正文,一级标题,二级标题,三级标题,页边距, MyMethod.UpdateFormat2(currentFilename, _root); //文本标注,暂时 放一放 } #endregion #region 3、查重清洗 //判断用户选择的查重清洗格式,如果不等于,则进行查重清洗 if (!SystemInfo._userInfo._ccqx.Equals("无")) { } #endregion #region 4、基础解析 //判断用户选择的基础解析格式,如果不等于无,则进行基础解析 JJDocument _jjDoc = new JJDocument(currentFilename); if (!SystemInfo._userInfo._jcjx.Equals("无")) { var listbase = _jjDoc.GetBaseAnalysis(); _jjDoc.SaveList2Excel(listbase); } #endregion #region 5、内容解析 //判断用户选择的内容解析格式,如果不等于无,则进行内容解析 if (!SystemInfo._userInfo._nrjx.Equals("无")) { var listneirong = _jjDoc.GetNeirongAnalysis(); _jjDoc.SaveList2Excel(listneirong); } #endregion #region 6、大数据版 //判断用户选择的大数据版,如果不等于无,则进行大数据版 if (!SystemInfo._userInfo._dsjb.Equals("无")) { } #endregion } } //执行完成提示,完成并将系统状态还原为0 statue = 0; lbl_kaishi.Enabled = true; lbl_kaishi.ForeColor = Color.White; lbl_kaishi.BackColor = Color.MediumSeaGreen; lbl_zhuangtai.Text = "已就绪,请点击\"开始\"执行解析"; MessageBox.Show("本次数据处理已完成!"); }