public UCchuli(BuzhouInfo buzhouinfo) { InitializeComponent(); myinfo = buzhouinfo; lbl_buzhou.Text = myinfo._name; //构造步骤详情 if (myinfo._name.Contains("替换")) { control_xiangqing = new UCBuzhou(myinfo._zhengze, myinfo._tihuan) { Dock = DockStyle.Fill }; (control_xiangqing as UCBuzhou).tb_zhengze.TextChanged += Tb_zhengze_TextChanged; (control_xiangqing as UCBuzhou).tb_tihuan.TextChanged += Tb_tihuan_TextChanged; (control_xiangqing as UCBuzhou).tb_zhengze.Leave += UCchuli_Leave; (control_xiangqing as UCBuzhou).tb_tihuan.Leave += UCchuli_Leave; } else if (myinfo._name.Contains("缀") || myinfo._name.Contains("清除")) { control_xiangqing = new System.Windows.Forms.TextBox() { Dock = DockStyle.Fill, Text = myinfo._text, Multiline = true }; ((TextBox)control_xiangqing).TextChanged += UCchuli_TextChanged; ((TextBox)control_xiangqing).Leave += UCchuli_Leave; } }
/// <summary> /// 点击导入按钮时触发的事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Lbl_daoru_Click(object sender, EventArgs e) { //选择模板文件 OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "极简模板|*.jxx"; if (ofd.ShowDialog() == DialogResult.OK) { //获得文件流 List <string> list_json = new List <string>(); StreamReader sr = new StreamReader(ofd.FileName); while (!sr.EndOfStream) { string str = sr.ReadLine(); list_json.Add(str); } foreach (string item in list_json) { //反序列化为buzhouinfo BuzhouInfo mybuzhou = JsonConvert.DeserializeObject <BuzhouInfo>(item); //buzhouinfo添加到settinglistguize中 Setting.list_guize.Add(mybuzhou); } //刷新dgvguize UpdateDgvGuize(); } }
private void GetGuize() { Setting.list_guize.Clear(); for (int i = 0; i < dgv_guize.Rows.Count; i++) { var row = dgv_guize.Rows[i]; BuzhouInfo myinfo = new BuzhouInfo(); try { myinfo._name = row.Cells["类型"].Value.ToString(); } catch { myinfo._name = string.Empty; } try { myinfo._selfname = row.Cells["名称"].Value.ToString(); } catch { myinfo._selfname = string.Empty; } try { myinfo._updatedate = row.Cells["修改时间"].Value.ToString(); } catch { myinfo._updatedate = string.Empty; } try { myinfo._zhengze = row.Cells["正则表达式"].Value.ToString(); } catch { myinfo._zhengze = string.Empty; } try { myinfo._tihuan = row.Cells["替换为"].Value.ToString(); } catch { myinfo._tihuan = string.Empty; } try { myinfo._text = row.Cells["文本"].Value.ToString(); } catch { myinfo._text = string.Empty; } Setting.list_guize.Add(myinfo); } }
private void Dgv_guize_SelectionChanged(object sender, EventArgs e) { try { //获得当前选中行 int index = dgv_guize.SelectedRows[0].Index; //获得对应的buzhouinfo BuzhouInfo mybuzhou = Setting.list_guize[index]; //显示处理详情控件 //显示详情控件 Control control_xiangqing = null; if (mybuzhou._name.Contains("替换")) { control_xiangqing = new UCBuzhou(mybuzhou._zhengze, mybuzhou._tihuan) { Dock = DockStyle.Fill }; (control_xiangqing as UCBuzhou).tb_zhengze.TextChanged += Tb_zhengze_TextChanged; (control_xiangqing as UCBuzhou).tb_tihuan.TextChanged += Tb_tihuan_TextChanged; (control_xiangqing as UCBuzhou).tb_zhengze.Leave += UCchuli_Leave; (control_xiangqing as UCBuzhou).tb_tihuan.Leave += UCchuli_Leave; } else if (mybuzhou._name.Contains("缀") || mybuzhou._name.Contains("清除")) { control_xiangqing = new System.Windows.Forms.TextBox() { Dock = DockStyle.Fill, Text = mybuzhou._text, Multiline = true }; control_xiangqing.TextChanged += UCchuli_TextChanged; control_xiangqing.Leave += UCchuli_Leave; } panel_xiangqing.Controls.Clear(); panel_xiangqing.Controls.Add(control_xiangqing); } catch { } }
/// <summary> /// 点击整体提取按钮时触发得事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void 正则提取ToolStripMenuItem_Click(object sender, EventArgs e) { //构造一个步骤info,显示在界面中 BuzhouInfo mybuzhou = new BuzhouInfo(((ToolStripMenuItem)sender).Text); mybuzhou._selfname = tb_guizemingcheng.Text; mybuzhou._updatedate = DateTime.Now.ToString("yyyy-MM-dd"); if (mybuzhou._name.Contains("替换")) { mybuzhou._zhengze = "正则表达式……"; mybuzhou._tihuan = "替换为……"; } else if (mybuzhou._name.Contains("添加")) { mybuzhou._text = "请输入……"; } else if (mybuzhou._name.Contains("清除换行符")) { mybuzhou._text = "清除换行符……"; } //形成一个datatable,绑定到dgvguize中 DataTable mydt0 = dgv_guize.DataSource as DataTable; //判断dgv_data是否有值 if (mydt0 == null) { mydt0 = new DataTable(); mydt0.Columns.Add("序号"); mydt0.Columns.Add("类型"); mydt0.Columns.Add("名称"); mydt0.Columns.Add("修改时间"); mydt0.Columns.Add("正则表达式"); mydt0.Columns.Add("替换为"); mydt0.Columns.Add("文本"); } mydt0.Rows.Add(new string[] { (mydt0.Rows.Count + 1).ToString(), mybuzhou._selfname, mybuzhou._name, mybuzhou._updatedate, mybuzhou._zhengze, mybuzhou._tihuan, mybuzhou._text }); dgv_guize.DataSource = null; dgv_guize.DataSource = mydt0; //添加选择复选框列 if (!dgv_guize.Columns.Contains("选择")) { DataGridViewCheckBoxColumn mycol = new DataGridViewCheckBoxColumn(); mycol.Name = "选择"; mycol.HeaderText = "选择"; mycol.DisplayIndex = 0; dgv_guize.Columns.Add(mycol); } Application.DoEvents(); GetGuize(); //显示详情控件 Control control_xiangqing = null; if (mybuzhou._name.Contains("替换")) { control_xiangqing = new UCBuzhou(mybuzhou._zhengze, mybuzhou._tihuan) { Dock = DockStyle.Fill }; (control_xiangqing as UCBuzhou).tb_zhengze.TextChanged += Tb_zhengze_TextChanged; (control_xiangqing as UCBuzhou).tb_tihuan.TextChanged += Tb_tihuan_TextChanged; (control_xiangqing as UCBuzhou).tb_zhengze.Leave += UCchuli_Leave; (control_xiangqing as UCBuzhou).tb_tihuan.Leave += UCchuli_Leave; } else if (mybuzhou._name.Contains("缀") || mybuzhou._name.Contains("清除")) { control_xiangqing = new System.Windows.Forms.TextBox() { Dock = DockStyle.Fill, Text = mybuzhou._text, Multiline = true }; control_xiangqing.TextChanged += UCchuli_TextChanged; control_xiangqing.Leave += UCchuli_Leave; } //添加步骤详情 panel_xiangqing.Controls.Clear(); panel_xiangqing.Controls.Add(control_xiangqing); Application.DoEvents(); //UpdateDgvGuize(); //选中新添加的最后一行 dgv_guize.ClearSelection(); Application.DoEvents(); dgv_guize.CurrentCell = dgv_guize.Rows[mydt0.Rows.Count - 1].Cells[0]; Application.DoEvents(); //显示最后一条的步骤详情 //清空处理前,处理后 tb_chuliqian.Clear(); tb_chulihou.Clear(); //实例化一个UC处理 //string buzhouleixing = ((ToolStripMenuItem)sender).Text; //UC.UCchuli myuc = new UCchuli(buzhouleixing, tb_guizemingcheng.Text) //{ // Dock = DockStyle.Top, //}; //myuc.lbl_buzhou.Click += DisplayXiangqing; //myuc.update_buzhou += GetBuzhou; //myuc.update_shili += ChuLiShili; ////myuc.tableLayoutPanel1.BackColor = Color.SteelBlue; //panel_chuli.Controls.Add(myuc); //panel_chuli.Controls.SetChildIndex(myuc, 0); ////当前uclbl高亮 //foreach (UCchuli uc in Setting.list_ucchuli) //{ // uc.lbl_buzhou.BackColor = Color.LightGray; // uc.lbl_buzhou.ForeColor = Color.Black; //} ////高两 //myuc.lbl_buzhou.BackColor = Color.SteelBlue; //myuc.lbl_buzhou.ForeColor = Color.White; //更新步骤列表setting //GetBuzhou(); }