using DevExpress.XtraEditors; using Gs.DevApp.Entity; using Gs.DevApp.ToolBox; using Gs.DevApp.UserControl; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Data; using System.Threading.Tasks; using System.Windows.Forms; namespace Gs.DevApp.DevFrm { public partial class Frm_SalesDeliver : DevExpress.XtraEditors.XtraForm { string _webServiceName = "SalesDeliverManager/"; List _filterList = new List(); public Frm_SalesDeliver() { InitializeComponent(); this.toolBarMenu1.btnAddClick += ToolBarMenu1_btnAddClick; this.toolBarMenu1.btnEdtClick += ToolBarMenu1_btnEdtClick; this.toolBarMenu1.btnSaveClick += ToolBarMenu1_btnSaveClick; this.toolBarMenu1.btnLoadClick += ToolBarMenu1_btnLoadClick; this.toolBarMenu1.btnDelClick += ToolBarMenu1_btnDelClick1; this.toolBarMenu1.btnEscClick += ToolBarMenu1_btnEscClick; this.toolBarMenu1.btnQueryClick += ToolBarMenu1_btnQueryClick; toolBarMenu1.btnChkClick += ToolBarMenu1_btnChkClick; toolBarMenu1.btnFChkClick += ToolBarMenu1_btnFChkClick; toolBarMenu1.btnLogClick += ToolBarMenu1_btnLogClick; this.toolBarMenu1.getXmlConfig(); Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameterMx(gvMx1); Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameter(gridView1, picCheckBox, this, "chkStatus", "", (value) => { Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 0); },tips); Gs.DevApp.ToolBox.UtilityHelper.SetTabParameter(gridView1, xtraTabControl1, pageBar1, (value) => { getModel(value); }, (value) => { getPageList(this.pageBar1.CurrentPage); }, lbGuid); getPageList(1); pageBar1.PagerEvent += PageBar1_PagerEvent; //设置销售单 txt_salesId.getSuppler("", ""); this.txt_salesId.EditChanged += (s, e) => { string _sqGuid = txt_salesId.GetId(); if (string.IsNullOrEmpty(_sqGuid)) return; txt_fSalesManIDTxt.Text = txt_salesId.GetSalesUserName(); txt_fCustomerIDTxt.Text = txt_salesId.GetSalesCusName(); txt_fSaleOrgIdTxt.Text = txt_salesId.GetSalesOrgName(); txt_fSaleOrgIdTxt.Text = txt_salesId.GetSalesOrgName(); txt_shf.Text = txt_salesId.GetSalesShf(); txt_shName.Text = txt_salesId.GetSalesShfName(); System.Text.StringBuilder sbWhere = new System.Text.StringBuilder(); var _obj = new PageQueryModel(1, 999999, "item_no", "asc", "", sbWhere.ToString(), _sqGuid); var json = JsonConvert.SerializeObject(_obj); try { var strReturn = UtilityHelper.HttpPost("", "SalesManager/SelectFormMx", json); var rtn = UtilityHelper.ReturnToTablePage(strReturn); var dt = rtn.rtnData.list; this.repositoryItemSearchLookUpEdit1.DataSource = dt; } catch (Exception ex) { MsgHelper.Warning("提示:" + ex.Message); } }; } private void GridView1_ColumnFilterChanged(object sender, EventArgs e) { _filterList= Gs.DevApp.ToolBox.UtilityHelper.GetDilter(gridView1.Columns, gridView1); Task.Delay(100); getPageList(1); } /// /// 分页事件 /// /// /// private void PageBar1_PagerEvent(int curPage, int pageSize) { getPageList(curPage); } /// /// 查询事件 /// /// /// private void ToolBarMenu1_btnQueryClick(object sender, EventArgs e) { gridView1.ColumnFilterChanged -= GridView1_ColumnFilterChanged; gridView1.ActiveFilter.Clear(); gridView1.ColumnFilterChanged += GridView1_ColumnFilterChanged; var frm = new ShowFilter(gridView1.Columns, _filterList, this.GetType().FullName); frm.UpdateParent += Frm_UpdateParent; frm.ShowDialog(); } /// /// 查询回调 /// /// /// private void Frm_UpdateParent(object sender, UpdateParentEventArgs e) { _filterList = e.FilterList; getPageList(1); } /// /// 取消事件 /// /// /// private void ToolBarMenu1_btnEscClick(object sender, EventArgs e) { Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 1); } /// /// 删除事件 /// /// /// private void ToolBarMenu1_btnDelClick1(object sender, EventArgs e) { string rowGuid = "", rowName = ""; (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, lbGuid, txt_billNo, gridView1, "billNo"); if (string.IsNullOrEmpty(rowGuid)) { MsgHelper.Warning("请先选择你要操作的行!"); return; } if (!MsgHelper.AskQuestion("你选择了【" + rowName + "】,确定删除吗?")) return; var _obj = new { guid = rowGuid, mxGuid = Guid.Empty.ToString(), }; try { var strJson = UtilityHelper.HttpPost("", _webServiceName + "DeleteModelOrMx", JsonConvert.SerializeObject(_obj)); var _rtn = UtilityHelper.ReturnToDynamic(strJson); if (_rtn.rtnCode > 0) { if (xtraTabControl1.SelectedTabPageIndex == 0) { } else Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 2); getPageList(this.pageBar1.CurrentPage); } MsgHelper.Warning("提示:" + _rtn.rtnMsg); } catch (Exception ex) { MsgHelper.Warning("提示:" + ex.Message); } } /// /// 刷新事件 /// /// /// private void ToolBarMenu1_btnLoadClick(object sender, EventArgs e) { if (xtraTabControl1.SelectedTabPageIndex == 1) getModel(lbGuid.Text.Trim()); else { //_filterList.Clear(); //if (gridView1.ActiveFilter.Count > 0) //{ // gridView1.ColumnFilterChanged -= GridView1_ColumnFilterChanged; // gridView1.ActiveFilter.Clear(); // gridView1.ColumnFilterChanged += GridView1_ColumnFilterChanged; //} //getPageList(1); getPageList(this.pageBar1.CurrentPage); } } /// /// 修改事件 /// /// /// private void ToolBarMenu1_btnEdtClick(object sender, EventArgs e) { string rowGuid = "", rowName = ""; (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, lbGuid, txt_billNo, gridView1, "billno"); if (string.IsNullOrEmpty(rowGuid)) { ToolBox.MsgHelper.Warning("请先选择你要操作的行!"); return; } Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 3); if (xtraTabControl1.SelectedTabPageIndex == 1) { getModel(rowGuid); } else { List gvList = new List(); gvList.Add(gvMx1); UtilityHelper.ChangeEnableByControl(layoutMx1.Controls, true, gvList); } } /// /// 新增事件 /// /// /// private void ToolBarMenu1_btnAddClick(object sender, EventArgs e) { lbGuid.Text = ""; Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 4); List gridViews = new List(); gridViews.Add(gvMx1); UtilityHelper.CleanValueByControl(this.layoutMx1.Controls, true, gridViews); Gs.DevApp.ToolBox.UtilityHelper.SetDefaultTable(gcMx1, gvMx1); } /// /// 保存事件 /// /// /// private void ToolBarMenu1_btnSaveClick(object sender, EventArgs e) { toolBarMenu1.isSetBtn = false; string djlx = txt_fBillTypeID.Text.ToString(); string FNote = txt_fNote.Text.ToString(); string _sqGuid = txt_salesId.GetId(); if (txt_fBillTypeID.SelectedIndex < 0) { Gs.DevApp.ToolBox.MsgHelper.Warning("请选择单据类型!"); txt_fBillTypeID.Focus(); return; } if (string.IsNullOrEmpty(_sqGuid)) { Gs.DevApp.ToolBox.MsgHelper.Warning("请选择销售单!"); txt_salesId.Focus(); return; } var _obj = new { guid = UtilityHelper.ToGuid(lbGuid.Text.Trim()), //主建 djlx = djlx,//单据类型 salesId = _sqGuid,//销售单号 inRemark = FNote.Trim(),//备注 list = new List(), }; gvMx1.CloseEditor(); gvMx1.PostEditor(); gvMx1.UpdateCurrentRow(); if (gvMx1.DataRowCount <= 0) { MsgHelper.ShowError("明细不能为空,请选择你的申请明细!"); return; } for (var i = 0; i < gvMx1.DataRowCount; i++) { var row = gvMx1.GetDataRow(i); if (row != null) { Guid? _guid = UtilityHelper.ToGuid(row["id"].ToString()); string _msl = row["fMustQty"].ToString(); if (string.IsNullOrEmpty(_msl)) { MsgHelper.ShowError("数量不能为空!"); return; } if (string.IsNullOrEmpty(row["YjfhDate"].ToString())) { MsgHelper.ShowError("预计发货时间不能为空!"); return; } _obj.list.Add(new { Guid = _guid, SalesDetailId = (row["salesDetailId"].ToString()), Sqsl = (row["fMustQty"].ToString()), Bz = (row["fEntrynote"].ToString()), Yjsj = (row["YjfhDate"].ToString()), }); } } try { string strJson = UtilityHelper.HttpPost("", _webServiceName + "EditModel", JsonConvert.SerializeObject(_obj)); ReturnModel _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson); ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg); if (_rtn.rtnCode > 0) { lbGuid.Text = _rtn.rtnData.outGuid; txt_billNo.Text = _rtn.rtnData.outNo; toolBarMenu1.isSetBtn = true; List gvList = new List(); gvList.Add(gvMx1); UtilityHelper.ChangeEnableByControl(this.layoutMx1.Controls, false, gvList); toolBarMenu1.currentAction = ""; Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 6); } } catch (Exception ex) { ToolBox.MsgHelper.Warning("提示:" + ex.Message); } } /// /// 日志 /// /// /// private void ToolBarMenu1_btnLogClick(object sender, EventArgs e) { toolBarMenu1.guidKey = ""; string rowGuid, rowName; (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, lbGuid, txt_billNo, gridView1); toolBarMenu1.guidKey = rowGuid; } /// /// /// /// 第几页 /// 每页几条 private void getPageList(int curPage) { var _sbSqlWhere = UtilityHelper.GetSearchWhere(_filterList); PageQueryModel pgq = new PageQueryModel(curPage, this.pageBar1.RowsCount, "create_date", "asc", "", _sbSqlWhere.ToString()); string json = JsonConvert.SerializeObject(pgq); try { var strReturn = UtilityHelper.HttpPost("", _webServiceName + "GetListPage", json); ReturnModel dd = UtilityHelper.ReturnToTablePage(strReturn); if (dd.rtnCode > 0) { DataTable dt = dd.rtnData.list; gcMain1.BindingContext = new BindingContext(); gridView1.ColumnFilterChanged -= GridView1_ColumnFilterChanged; if (dt.Rows.Count > 0) { gcMain1.DataSource = dt; gcMain1.ForceInitialize(); gridView1.BestFitColumns(); Gs.DevApp.ToolBox.UtilityHelper.SetGridLayout(gridView1); } else UtilityHelper.SetDefaultTable(gcMain1, gridView1); gridView1.ColumnFilterChanged += GridView1_ColumnFilterChanged; pageBar1.TotalPages = dd.rtnData.pages;//总页 pageBar1.CurrentPage = curPage;//当前页 pageBar1.RecordCount = dd.rtnData.total;//总记录数 } else { ToolBox.MsgHelper.ShowError("提示:" + dd.rtnMsg); } } catch (Exception ex) { ToolBox.MsgHelper.ShowError("提示:" + 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)) { ToolBox.MsgHelper.Warning("请先选择你要操作的行!"); return; } var _obj = new { guid = strGuid,//主建 }; try { string strJson = UtilityHelper.HttpPost("", _webServiceName + "GetModel", 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); 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); } } else ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg); } catch (Exception ex) { ToolBox.MsgHelper.Warning("提示:" + ex.Message); } } /// /// 审核事件 /// /// /// private void ToolBarMenu1_btnChkClick(object sender, EventArgs e) { _toolCk(1); } /// /// 反审核 /// /// /// /// private void ToolBarMenu1_btnFChkClick(object sender, EventArgs e) { _toolCk(0); } /// /// 工具条事件 /// /// private void _toolCk(int _inFieldValue) { string strMsg = ""; switch (_inFieldValue) { case 1: strMsg = "审核"; break; case 0: strMsg = "反审核"; break; }; toolBarMenu1.guidKey = ""; string rowGuid, rowName; (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, lbGuid, txt_billNo, gridView1, "billNo"); if (string.IsNullOrEmpty(rowGuid)) { MsgHelper.Warning("请先选择你要操作的行!"); return; } if (!MsgHelper.AskQuestion("你选择了【" + rowName + "】,确定" + strMsg + "吗?")) return; var _obj = new { guid = rowGuid, inFieldValue = _inFieldValue, }; try { var strJson = UtilityHelper.HttpPost("", _webServiceName + "EditModelSubmit", JsonConvert.SerializeObject(_obj)); var _rtn = UtilityHelper.ReturnToDynamic(strJson); MsgHelper.Warning(_rtn.rtnData.outMsg.ToString()); if (_rtn.rtnCode > 0 && _rtn.rtnData.outSum * 1 > 0) { if (xtraTabControl1.SelectedTabPageIndex == 1) { getModel(lbGuid.Text.Trim()); } int rowHandle = gridView1.LocateByValue(1, gridView1.Columns["guid"], rowGuid); gridView1.FocusedRowHandle = rowHandle; UtilityHelper.SetCheckIco(gridView1, "chkStatus", "fApproverID", "fApproveDate", picCheckBox, this, _inFieldValue.ToString()); } } catch (Exception ex) { MsgHelper.Warning("提示:" + ex.Message); } } private void repositoryItemSearchLookUpEdit1_EditValueChanged(object sender, EventArgs e) { SearchLookUpEdit LookupEdit = sender as SearchLookUpEdit; DataRowView SelectedDataRow = (DataRowView)LookupEdit.GetSelectedDataRow(); gvMx1.SetFocusedRowCellValue("salesDetailId", SelectedDataRow["id"].ToString()); gvMx1.SetFocusedRowCellValue("billNo", SelectedDataRow["billNo"].ToString()); gvMx1.SetFocusedRowCellValue("itemNo", SelectedDataRow["itemNo"].ToString()); gvMx1.SetFocusedRowCellValue("itemName", SelectedDataRow["itemName"].ToString()); gvMx1.SetFocusedRowCellValue("itemModel", SelectedDataRow["itemModel"].ToString()); gvMx1.SetFocusedRowCellValue("dwXs", SelectedDataRow["xxdw"].ToString()); gvMx1.SetFocusedRowCellValue("dwJj", SelectedDataRow["jjdw"].ToString()); gvMx1.SetFocusedRowCellValue("jjSl", SelectedDataRow["priceUnitQty"].ToString()); gvMx1.SetFocusedRowCellValue("deliveryDate", SelectedDataRow["deliveryDate"].ToString()); gvMx1.SetFocusedRowCellValue("xsSl", SelectedDataRow["qty"].ToString()); gvMx1.SetFocusedRowCellValue("isFree", SelectedDataRow["isFree"].ToString()); gvMx1.SetFocusedRowCellValue("hzlx", SelectedDataRow["hzlx"].ToString()); gvMx1.SetFocusedRowCellValue("hz", SelectedDataRow["hz"].ToString()); gvMx1.SetFocusedRowCellValue("xxbz", SelectedDataRow["xxbz"].ToString()); gvMx1.SetFocusedRowCellValue("fhsx", SelectedDataRow["fhsx"].ToString()); gvMx1.SetFocusedRowCellValue("fhxx", SelectedDataRow["fhxx"].ToString()); gvMx1.SetFocusedRowCellValue("jsOrg", SelectedDataRow["jsOrg"].ToString()); gvMx1.SetFocusedRowCellValue("gyOrg", SelectedDataRow["gyOrg"].ToString()); gvMx1.SetFocusedRowCellValue("kcOrg", SelectedDataRow["kcOrg"].ToString()); gvMx1.CloseEditor(); gvMx1.PostEditor(); gvMx1.UpdateCurrentRow(); } private void repositoryItemButtonEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { var rowhandle = gvMx1.FocusedRowHandle; if (rowhandle < 0) return; if (e.Button.Index == 0) { var dr = gvMx1.GetDataRow(rowhandle); var mxGuid = dr["id"].ToString(); if (!MsgHelper.AskQuestion("你选择了1条数据,确定删除吗?")) return; if (string.IsNullOrEmpty(mxGuid)) { gvMx1.DeleteRow(rowhandle); return; } var _obj = new { guid = lbGuid.Text.Trim(), mxGuid = mxGuid, }; try { var strJson = UtilityHelper.HttpPost("", _webServiceName + "DeleteModelOrMx", JsonConvert.SerializeObject(_obj)); var _rtn = UtilityHelper.ReturnToDynamic(strJson); if (_rtn.rtnCode > 0) { if (_rtn.rtnCode > 0) getModel(lbGuid.Text); } MsgHelper.Warning("提示:" + _rtn.rtnMsg); } catch (Exception ex) { MsgHelper.Warning("提示:" + ex.Message); } } } } }