using DevExpress.XtraEditors.Controls; using Gs.DevApp.Entity; using Gs.DevApp.ToolBox; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Data; using System.Windows.Forms; namespace Gs.DevApp.DevFrm.PDA { public partial class Frm_AreaBind : DevExpress.XtraEditors.XtraForm { public Frm_AreaBind() { InitializeComponent(); this.toolBarMenu1.getXmlConfig(); Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameterMx(gvMx1); Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameterMx(gvMx2); Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameter(gridView1, null, null, "", "", (value) => { Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 0); }, tips); Gs.DevApp.ToolBox.UtilityHelper.SetTabParameter(gridView1, xtraTabControl1, null, (value) => { getModel(value); }, (value) => { }, lbGuid); getPageList(1); Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameter(gridView1); } /// /// /// 第几页 /// 每页几条 private void getPageList(int curPage) { string _where = " and 1=1 and a.s_type='仓库分区' and a.pid<>'00000000-0000-0000-0000-000000000000'"; var pgq = new PageQueryModel(1, 999999, "a.defect_name", "asc", "", _where); var json = JsonConvert.SerializeObject(pgq); try { var strReturn = UtilityHelper.HttpPost("", "MesDefectCodeManager/GetListPage", json); var dd = UtilityHelper.ReturnToTablePage(strReturn); var dt = dd.rtnData.list; if (dt.Rows.Count > 0) { gcMain1.DataSource = dt; gcMain1.ForceInitialize(); gridView1.BestFitColumns(); Gs.DevApp.ToolBox.UtilityHelper.SetGridLayout(gridView1); } else UtilityHelper.SetDefaultTable(gcMain1, gridView1); } catch (Exception ex) { MsgHelper.Warning("提示:" + ex.Message); } } private void getModel(string strGuid) { bool isEdit = false; if (toolBarMenu1.currentAction == "add") return; if (toolBarMenu1.currentAction == "edit") isEdit = true; if (string.IsNullOrEmpty(strGuid)) { MsgHelper.Warning("请先选择你要操作的行!"); return; } var _obj = new { guid = strGuid //主建 }; try { var strJson = UtilityHelper.HttpPost("", "MesDefectCodeManager/GetModel2", JsonConvert.SerializeObject(_obj)); ReturnModel _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson); if (_rtn.rtnCode > 0) { dynamic dy = _rtn.rtnData; lbGuid.Text = strGuid; List gvList = new List(); gvList.Add(gvMx1); gvList.Add(gvMx2); UtilityHelper.SetValueByObj(this.layoutMx1.Controls, dy, isEdit, gvList); JObject _job = JObject.Parse(strJson); JArray array = new JArray(); foreach (var a in _job["rtnData"]["list"]) { array.Add(a); } DataTable dt = JsonConvert.DeserializeObject(array.ToString()); if (dt.Rows.Count > 0) { gcMx1.BindingContext = new BindingContext(); gcMx1.DataSource = dt; gcMx1.ForceInitialize(); gvMx1.BestFitColumns(); Gs.DevApp.ToolBox.UtilityHelper.SetGridLayout(gvMx1); } else { Gs.DevApp.ToolBox.UtilityHelper.SetDefaultTable(gcMx1, gvMx1); } JArray array2 = new JArray(); foreach (var a in _job["rtnData"]["list2"]) { array2.Add(a); } DataTable dt2 = JsonConvert.DeserializeObject(array2.ToString()); if (dt2.Rows.Count > 0) { gcMx2.BindingContext = new BindingContext(); gcMx2.DataSource = dt2; gcMx2.ForceInitialize(); gvMx2.BestFitColumns(); Gs.DevApp.ToolBox.UtilityHelper.SetGridLayout(gvMx2); } else { Gs.DevApp.ToolBox.UtilityHelper.SetDefaultTable(gcMx2, gvMx2); } } else { MsgHelper.Warning("提示:" + _rtn.rtnMsg); } } catch (Exception ex) { MsgHelper.Warning("提示:" + ex.Message); } } /// /// 绑定人员 /// /// /// private void repositoryItemButtonEdit2_ButtonClick(object sender, ButtonPressedEventArgs e) { if (e.Button.Index == 0) { var rowhandle = gridView1.FocusedRowHandle; var dr = gridView1.GetDataRow(rowhandle); var userGuid = dr["guid"].ToString(); var frm = new SelectUser(userGuid); frm.ShowDialog(); } } /// /// 绑定物料 /// /// /// private void repositoryItemButtonEdit3_ButtonClick(object sender, ButtonPressedEventArgs e) { if (e.Button.Index == 0) { var rowhandle = gridView1.FocusedRowHandle; var dr = gridView1.GetDataRow(rowhandle); var userGuid = dr["guid"].ToString(); var frm = new SelectItem(userGuid); frm.ShowDialog(); } } /// /// 删除人员 /// /// /// private void rptDel1_ButtonClick(object sender, ButtonPressedEventArgs e) { delBind(e, gvMx1); } /// /// 删除物料 /// /// /// private void rptDel2_ButtonClick(object sender, ButtonPressedEventArgs e) { delBind(e,gvMx2); } private void delBind(ButtonPressedEventArgs e, DevExpress.XtraGrid.Views.Grid.GridView gv) { var rowhandle = gv.FocusedRowHandle; if (rowhandle < 0) return; if (e.Button.Index == 0) { var dr = gv.GetDataRow(rowhandle); var mxGuid = dr["guid"].ToString(); if (!MsgHelper.AskQuestion("你选择了1条数据,确定删除吗?")) return; var _obj = new { guidList = mxGuid, }; try { var strJson = UtilityHelper.HttpPost("", "MesSysPageviewManager/" + "DeleteUserBind", JsonConvert.SerializeObject(_obj)); var _rtn = UtilityHelper.ReturnToDynamic(strJson); if (_rtn.rtnCode > 0) { if (_rtn.rtnCode > 0) { getModel(lbGuid.Text.Trim()); } } MsgHelper.Warning("提示:" + _rtn.rtnMsg); } catch (Exception ex) { MsgHelper.Warning("提示:" + ex.Message); } } } } }