一、触发事件
using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; using YKERP.UserControls; using YKERP.Common; using YKERP.Business; using System.Collections; using YKERP.Utils.Extensions; namespace YKERP._CategoryMgt { public partial class UserCategoryMgt : YKBaseControl { public string Glo_Div_1 = null, Glo_Div_2 = null, Glo_Div_3 = null; public UserCategoryMgt() { InitializeComponent(); Load += (s, e) => { InitDataCategory(); //加载部类 }; //部类 BtnCategoryEdit.Enabled = false; gridview_product.SelectionChangedEx((rows) => { BtnCategoryEdit.Enabled = rows.Count == 1; }); gridview_product.GetCheckedOnFocusRowChanged(); gridview_product.FocusedRowChanged += (s, e) => { var hdrLargeClass = gridview_product.GetSelectedRow()?.ToSpecObject<Model>(); if (hdrLargeClass != null) GridPageLargeClass.LoadData(GridDataLargeClass, "YKERP-ZSJ-0066", new Hashtable() { ["div_num_id"] = hdrLargeClass.div_num_id }); else GridPageLargeClass.ClearData(); }; gridView2.FocusedRowChanged += (s, e) => { var hdrLargeClass = gridview_product.GetSelectedRow()?.ToSpecObject<Model>(); var pty1_num_id = gridView2.GetSelectedRow()?["pty1_num_id"].ToStr(); if (pty1_num_id.IsValid()) GridPageMiddleClass.LoadData(GridDataMiddleClass, "YKERP-ZSJ-0067", new Hashtable() { ["div_num_id"] = hdrLargeClass.div_num_id, ["pty1_num_id"] = pty1_num_id, }); else GridPageMiddleClass.ClearData(); }; gridView3.FocusedRowChanged += (s, e) => { var hdrLargeClass = gridview_product.GetSelectedRow()?.ToSpecObject<Model>(); var pty2_num_id = gridView3.GetSelectedRow()?["pty2_num_id"].ToStr(); if (pty2_num_id.IsValid()) GridPageSubclass.LoadData(GridDataSubclass, "YKERP-ZSJ-0068", new Hashtable() { ["div_num_id"] = hdrLargeClass.div_num_id, ["pty2_num_id"] = pty2_num_id, }); else GridPageSubclass.ClearData(); }; GridPageCategory.OnDataSourcePostBind += (dt) => { bool enable = dt.Rows.Count > 0; btnAddLargeClass.Enabled = enable; btnEditLargeClass.Enabled = enable; btnDelLargeClass.Enabled = enable; btnAddMiddleClass.Enabled = enable; btnEditMiddleClass.Enabled = enable; btnDelMiddleClass.Enabled = enable; btnAddSubclass.Enabled = enable; btnEditSubclass.Enabled = enable; btnDelSubclass.Enabled = enable; }; } public void LargerData() { var row = gridview_product?.GetFocusedDataRow(); GridPageLargeClass.LoadData(GridDataLargeClass, "YKERP-ZSJ-0066", new Hashtable() { ["div_num_id"] = row["div_num_id"].ToString() }); } public void MiddleData() { var row = gridview_product?.GetFocusedDataRow(); var rows = gridView2?.GetFocusedDataRow(); GridPageMiddleClass.LoadData(GridDataMiddleClass, "YKERP-ZSJ-0067", new Hashtable() { ["div_num_id"] = row["div_num_id"], ["pty1_num_id"] = rows["pty1_num_id"], }); } public void SubData() { var row = gridView2?.GetFocusedDataRow(); var rows = gridView3?.GetFocusedDataRow(); GridPageMiddleClass.LoadData(GridDataSubclass, "YKERP-ZSJ-0068", new Hashtable() { ["div_num_id"] = row["div_num_id"], ["pty2_num_id"] = rows["pty2_num_id"], }); } /// <summary> /// 部类数据 /// </summary> private void InitDataCategory() { GridPageCategory.ClearQueryField(); GridPageCategory.IN_SQLID = "YKERP-ZSJ-0065"; GridPageCategory.IN_GRID_CONTROL = GridDataCategory; GridPageCategory.InitPages(); } void LoadDivData() { GridPageCategory.LoadData(GridDataCategory, "YKERP-ZSJ-0065", new Hashtable()); } private void BtnAddCategory_Click(object sender, EventArgs e) { AddOrEditCategory AddOrEdit = new AddOrEditCategory(null) { FlushOri = LoadDivData }; AddOrEdit.StartPosition = FormStartPosition.CenterScreen; //AddOrEdit.myRefresh += InitDataCategory; AddOrEdit.Text = "新增"; AddOrEdit.ShowDialog(); } private void BtnCategoryEdit_Click(object sender, EventArgs e) { int[] rows = gridview_product.GetSelectedRows(); //获取GridView 选中的数据行信息 if (rows.Length == 0) { MessageHelper.InfoMsg("请勾选一行记录。"); return; } else if (rows.Length == 1) { } else { MessageHelper.InfoMsg("请选择一行记录进行编辑。"); return; } } private void btnDelCategory_Click(object sender, EventArgs e) { //var selectedItems = gridview_ChildNode.GetSelectedRows().ToList().Select(i => gridview_ChildNode.GetRow(i).ToSpecObject<IntelligentAllotChildNode>()).ToList(); //gridview_ChildNode.DeleteSelectedRows(); int[] rows = gridview_product.GetSelectedRows(); //获取GridView 选中的数据行信息 if (rows.Length == 0) { MessageHelper.InfoMsg("请勾选一行记录。"); return; } else { List<int> selectRows; List<string> custcode = new List<string>(); selectRows = this.gridview_product.GetSelectedRows().ToList(); foreach (int i in selectRows) { custcode.Add(Convert.ToString(this.gridview_product.GetDataRow(i)["series"].ToString())); /* if (this.gridview_Parent.GetDataRow(i)["group_num_id"].ToInt() == GlobalNode.ToInt()) { ChildNodeData.DataSource = null; this.GlobalNode = null; }*/ } //string depaid = string.Join(",", custcode); System.String[] str = custcode.ToArray(); bool res = UnitOfWork<DAL>.Resolve.DelCategory(str, out string errors); if (errors != null) { MessageHelper.InfoMsg(errors); } else { MessageHelper.InfoMsg("删除成功"); InitDataCategory(); } } } /// <summary> /// 大类新增 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAddLargeClass_Click(object sender, EventArgs e) { Dictionary<string, string> data = new Dictionary<string, string>(); var row = gridview_product?.GetFocusedDataRow(); data.Add("div_num_id", row["div_num_id"].ToString()); data.Add("series", null); AddOrEditLargeClass AddOrEdit = new AddOrEditLargeClass(data) { FreshData = () => { LargerData(); } }; AddOrEdit.StartPosition = FormStartPosition.CenterScreen; //AddOrEdit.myRefresh += InitDataLargeClass; AddOrEdit.Text = "新增"; AddOrEdit.ShowDialog(); } private void btnAddMiddleClass_Click(object sender, EventArgs e) { Dictionary<string, string> data = new Dictionary<string, string>(); var row = gridview_product?.GetFocusedDataRow(); data.Add("div_num_id", row["div_num_id"].ToString()); var rows = gridView2?.GetFocusedDataRow(); data.Add("pty1_num_id", rows["pty1_num_id"].ToString()); data.Add("series", null); AddOrEditMiddleClass AddOrEdit = new AddOrEditMiddleClass(data) { FreshData = () => { MiddleData(); } }; AddOrEdit.StartPosition = FormStartPosition.CenterScreen; //AddOrEdit.myRefresh += InitDataLargeClass; AddOrEdit.Text = "新增"; AddOrEdit.ShowDialog(); } private void btnDelMiddleClass_Click(object sender, EventArgs e) { int[] rows = gridView3.GetSelectedRows(); //获取GridView 选中的数据行信息 if (rows.Length == 0) { MessageHelper.InfoMsg("请勾选一行记录。"); return; } else { List<int> selectRows; List<string> custcode = new List<string>(); selectRows = this.gridView3.GetSelectedRows().ToList(); foreach (int i in selectRows) { custcode.Add(Convert.ToString(this.gridView3.GetDataRow(i)["series"].ToString())); /* if (this.gridview_Parent.GetDataRow(i)["group_num_id"].ToInt() == GlobalNode.ToInt()) { ChildNodeData.DataSource = null; this.GlobalNode = null; }*/ } //string depaid = string.Join(",", custcode); System.String[] str = custcode.ToArray(); bool res = UnitOfWork<DAL>.Resolve.DelMiddleClass(str, out string errors); if (errors != null) { MessageHelper.InfoMsg(errors); } else { MessageHelper.InfoMsg("删除成功"); MiddleData(); } } } private void btnAddSubclass_Click(object sender, EventArgs e) { Dictionary<string, string> data = new Dictionary<string, string>(); var row = gridview_product?.GetFocusedDataRow(); data.Add("div_num_id", row["div_num_id"].ToString()); var rows = gridView3?.GetFocusedDataRow(); data.Add("pty2_num_id", rows["pty2_num_id"].ToString()); data.Add("series", null); AddOrEditSubclass AddOrEdit = new AddOrEditSubclass(data) { FreshData = () => { SubData(); } }; AddOrEdit.StartPosition = FormStartPosition.CenterScreen; //AddOrEdit.myRefresh += InitDataLargeClass; AddOrEdit.Text = "新增"; AddOrEdit.ShowDialog(); } private void btnEditMiddleClass_Click(object sender, EventArgs e) { int[] rows = gridView3.GetSelectedRows(); //获取GridView 选中的数据行信息 if (rows.Length == 0) { MessageHelper.InfoMsg("请勾选一行记录。"); return; } else if (rows.Length == 1) { int selectRow = gridView3.GetSelectedRows()[0]; // MessageBox.Show(gridview_Parent.GetFocusedDataRow()["series"].ToString()); //this.gridview_Parent.GetRowCellValue(selectRow, "series").ToString() Dictionary<string, string> data = new Dictionary<string, string>(); data.Add("series", this.gridView3.GetRowCellValue(selectRow, "series").ToString()); data.Add("div_num_id", this.gridView3.GetRowCellValue(selectRow, "div_num_id").ToString()); data.Add("pty1_num_id", this.gridView3.GetRowCellValue(selectRow, "pty1_num_id").ToString()); data.Add("pty2_num_id", this.gridView3.GetRowCellValue(selectRow, "pty2_num_id").ToString()); data.Add("pty2_sim_no", this.gridView3.GetRowCellValue(selectRow, "pty2_sim_no").ToString()); data.Add("pty2_name", this.gridView3.GetRowCellValue(selectRow, "pty2_name").ToString()); data.Add("en_pty2_name", this.gridView3.GetRowCellValue(selectRow, "en_pty2_name").ToString()); AddOrEditMiddleClass AddOrEdit = new AddOrEditMiddleClass(data) { FreshData = () => { MiddleData(); } }; AddOrEdit.StartPosition = FormStartPosition.CenterScreen; //AddOrEdit.myRefresh += InitDataLargeClass; AddOrEdit.Text = "编辑"; AddOrEdit.ShowDialog(); } else { MessageHelper.InfoMsg("请选择一行记录进行编辑。"); return; } } private void btnEditSubclass_Click(object sender, EventArgs e) { int[] rows = gridView4.GetSelectedRows(); //获取GridView 选中的数据行信息 if (rows.Length == 0) { MessageHelper.InfoMsg("请勾选一行记录。"); return; } else if (rows.Length == 1) { int selectRow = gridView4.GetSelectedRows()[0]; // MessageBox.Show(gridview_Parent.GetFocusedDataRow()["series"].ToString()); //this.gridview_Parent.GetRowCellValue(selectRow, "series").ToString() Dictionary<string, string> data = new Dictionary<string, string>(); data.Add("series", this.gridView4.GetRowCellValue(selectRow, "series").ToString()); data.Add("div_num_id", this.gridView4.GetRowCellValue(selectRow, "div_num_id").ToString()); data.Add("pty2_num_id", this.gridView4.GetRowCellValue(selectRow, "pty2_num_id").ToString()); data.Add("pty3_num_id", this.gridView4.GetRowCellValue(selectRow, "pty3_num_id").ToString()); data.Add("pty3_sim_no", this.gridView4.GetRowCellValue(selectRow, "pty3_sim_no").ToString()); data.Add("pty3_name", this.gridView4.GetRowCellValue(selectRow, "pty3_name").ToString()); data.Add("en_pty3_name", this.gridView4.GetRowCellValue(selectRow, "en_pty3_name").ToString()); data.Add("lasted_purprice_min_percent", this.gridView4.GetRowCellValue(selectRow, "lasted_purprice_min_percent").ToString()); data.Add("lasted_purprice_max_percent", this.gridView4.GetRowCellValue(selectRow, "lasted_purprice_max_percent").ToString()); data.Add("fm", this.gridView4.GetRowCellValue(selectRow, "fm").ToString()); AddOrEditSubclass AddOrEdit = new AddOrEditSubclass(data) { FreshData = () => { SubData(); } }; AddOrEdit.StartPosition = FormStartPosition.CenterScreen; //AddOrEdit.myRefresh += InitDataLargeClass; AddOrEdit.Text = "编辑"; AddOrEdit.ShowDialog(); } else { MessageHelper.InfoMsg("请选择一行记录进行编辑。"); return; } } private void btnDelSubclass_Click(object sender, EventArgs e) { int[] rows = gridView4.GetSelectedRows(); //获取GridView 选中的数据行信息 if (rows.Length == 0) { MessageHelper.InfoMsg("请勾选一行记录。"); return; } else { List<int> selectRows; List<string> custcode = new List<string>(); selectRows = this.gridView4.GetSelectedRows().ToList(); foreach (int i in selectRows) { custcode.Add(Convert.ToString(this.gridView4.GetDataRow(i)["series"].ToString())); /* if (this.gridview_Parent.GetDataRow(i)["group_num_id"].ToInt() == GlobalNode.ToInt()) { ChildNodeData.DataSource = null; this.GlobalNode = null; }*/ } //string depaid = string.Join(",", custcode); System.String[] str = custcode.ToArray(); bool res = UnitOfWork<DAL>.Resolve.DelSubClass(str, out string errors); if (errors != null) { MessageHelper.InfoMsg(errors); } else { MessageHelper.InfoMsg("删除成功"); SubData(); } } } private void gridview_product_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e) { switch (e.Button) { case MouseButtons.Right: break; case MouseButtons.Left: if (e.Clicks > 1) //双击 { var selectRow = gridview_product.GetFocusedDataRow(); // MessageBox.Show(gridview_Parent.GetFocusedDataRow()["series"].ToString()); //this.gridview_Parent.GetRowCellValue(selectRow, "series").ToString() Dictionary<string, string> data = new Dictionary<string, string>(); data.Add("series", selectRow["series"].ToString()); data.Add("div_num_id", selectRow["div_num_id"].ToString()); data.Add("div_sim_no", selectRow["div_sim_no"].ToString()); data.Add("div_name", selectRow["div_name"].ToString() ); data.Add("en_div_name", selectRow["en_div_name"].ToString()); AddOrEditCategory AddOrEdit = new AddOrEditCategory(data) { FlushOri = LoadDivData }; AddOrEdit.StartPosition = FormStartPosition.CenterScreen; AddOrEdit.myRefresh += InitDataCategory; AddOrEdit.Text = "编辑"; AddOrEdit.ShowDialog(); } break; default: break; } } /// <summary> /// 大类编辑 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnEditLargeClass_Click(object sender, EventArgs e) { int[] rows = gridView2.GetSelectedRows(); //获取GridView 选中的数据行信息 if (rows.Length == 0) { MessageHelper.InfoMsg("请勾选一行记录。"); return; } else if (rows.Length == 1) { int selectRow = gridView2.GetSelectedRows()[0]; // MessageBox.Show(gridview_Parent.GetFocusedDataRow()["series"].ToString()); //this.gridview_Parent.GetRowCellValue(selectRow, "series").ToString() Dictionary<string, string> data = new Dictionary<string, string>(); data.Add("series", this.gridView2.GetRowCellValue(selectRow, "series").ToString()); data.Add("div_num_id", this.gridView2.GetRowCellValue(selectRow, "div_num_id").ToString()); data.Add("pty1_num_id", this.gridView2.GetRowCellValue(selectRow, "pty1_num_id").ToString()); data.Add("pty1_sim_no", this.gridView2.GetRowCellValue(selectRow, "pty1_sim_no").ToString()); data.Add("pty1_name", this.gridView2.GetRowCellValue(selectRow, "pty1_name").ToString()); data.Add("en_pty1_name", this.gridView2.GetRowCellValue(selectRow, "en_pty1_name").ToString()); AddOrEditLargeClass AddOrEdit = new AddOrEditLargeClass(data) { FreshData = () => { LargerData(); } }; AddOrEdit.StartPosition = FormStartPosition.CenterScreen; //AddOrEdit.myRefresh += InitDataLargeClass; AddOrEdit.Text = "编辑"; AddOrEdit.ShowDialog(); } else { MessageHelper.InfoMsg("请选择一行记录进行编辑。"); return; } } /// <summary> /// 大类删除 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDelLargeClass_Click(object sender, EventArgs e) { int[] rows = gridView2.GetSelectedRows(); //获取GridView 选中的数据行信息 if (rows.Length == 0) { MessageHelper.InfoMsg("请勾选一行记录。"); return; } else { List<int> selectRows; List<string> custcode = new List<string>(); selectRows = this.gridView2.GetSelectedRows().ToList(); foreach (int i in selectRows) { custcode.Add(Convert.ToString(this.gridView2.GetDataRow(i)["series"].ToString())); /* if (this.gridview_Parent.GetDataRow(i)["group_num_id"].ToInt() == GlobalNode.ToInt()) { ChildNodeData.DataSource = null; this.GlobalNode = null; }*/ } //string depaid = string.Join(",", custcode); System.String[] str = custcode.ToArray(); bool res = UnitOfWork<DAL>.Resolve.DelLargeClass(str, out string errors); if (errors != null) { MessageHelper.InfoMsg(errors); } else { MessageHelper.InfoMsg("删除成功"); LargerData(); } } } } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using YKERP.BaseForms; using YKERP.Business; using YKERP.Common; namespace YKERP._CategoryMgt { public partial class AddOrEditLargeClass : YKBaseForm { private string series = null; public Action FreshData; public AddOrEditLargeClass(Dictionary<string, string> data) { InitializeComponent(); Load +=(s,e)=>{ if (data["div_num_id"].ToString() != "") { txt_div_num_id.ReadOnly = true; txt_div_num_id.Text = data["div_num_id"].ToString(); } else { this.Close(); } if (data["series"]!=null) { txt_div_1.Text = data["pty1_num_id"].ToString(); txt_div_sim_no.Text = data["pty1_sim_no"].ToString(); txt_div_name.Text = data["pty1_name"].ToString(); txt_en_div_name.Text = data["en_pty1_name"].ToString(); this.series = data["series"].ToString(); txt_div_1.ReadOnly=true; } }; } private void btn_AddOrEdit_Click(object sender, EventArgs e) { if (Convert.ToInt32(txt_div_1.Text) == 0) { MessageHelper.InfoMsg("请填写大类编码"); return; } if (string.IsNullOrWhiteSpace(txt_div_sim_no.Text) || string.IsNullOrWhiteSpace(txt_div_name.Text) || string.IsNullOrWhiteSpace(txt_en_div_name.Text)) { MessageHelper.InfoMsg("请将信息填写完成"); return; } object data = new { div_num_id = txt_div_num_id.Text, //商品部类 pty1_num_id= txt_div_1.Text,//商品大类 pty1_sim_no = txt_div_sim_no.Text, pty1_name = txt_div_name.Text, en_pty1_name = txt_en_div_name.Text, user_num_id = 666 }; var res = UnitOfWork<DAL>.Resolve.AddOrEditLargeClass(data, out string errors); if (errors != null) { MessageHelper.InfoMsg(errors); return; } else { if (this.series == null) MessageHelper.InfoMsg("新增成功"); else MessageHelper.InfoMsg("编辑成功"); this.Close(); FreshData?.Invoke(); //myRefresh(this.div_num_id.ToInt()); } } } }