using System; using System.Collections.Generic; using System.Data; using System.Windows.Forms; using DevExpress.XtraEditors; using DevExpress.XtraEditors.Controls; using Gs.DevApp.Entity; using Gs.DevApp.ToolBox; using Newtonsoft.Json; namespace Gs.DevApp.DevFrm.Sys { public partial class DocNoRule : XtraForm { public DocNoRule() { InitializeComponent(); toolBarMenu1.btnAddClick += ToolBarMenu1_btnAddClick; toolBarMenu1.btnEdtClick += ToolBarMenu1_btnEdtClick; toolBarMenu1.btnSaveClick += ToolBarMenu1_btnSaveClick; toolBarMenu1.btnLoadClick += ToolBarMenu1_btnLoadClick; toolBarMenu1.btnDelClick += ToolBarMenu1_btnDelClick1; toolBarMenu1.btnEscClick += ToolBarMenu1_btnEscClick; toolBarMenu1.btnChkClick += ToolBarMenu1_btnChkClick; toolBarMenu1.btnFChkClick += ToolBarMenu1_btnFChkClick; Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameter(gridView1, picCheckBox, this, "checkStatus", "", (value) => { Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 0); }); Gs.DevApp.ToolBox.UtilityHelper.SetTabParameter(gridView1, xtraTabControl1, pageBar1, (value) => { getModel(value); }, (value) => { getPageList(this.pageBar1.CurrentPage); }); getPageList(1); pageBar1.PagerEvent += PageBar1_PagerEvent; getTree(); txt_docCode.EditValueChanged += (s, e) => { DoPreviewCode(); }; txxtItem1.EditValueChanged += (s, e) => { DoPreviewCode(); }; txxtItem2.EditValueChanged += (s, e) => { DoPreviewCode(); }; txxtItem3.EditValueChanged += (s, e) => { DoPreviewCode(); }; txxtItem4.EditValueChanged += (s, e) => { DoPreviewCode(); }; txt_noLength.ValueChanged += (s, e) => { DoPreviewCode(); }; txt_isIncludeDoc.CheckedChanged += (s, e) => { DoPreviewCode(); }; txt_isSpilit.CheckedChanged += (s, e) => { DoPreviewCode(); }; } /// /// 分页事件 /// /// /// private void PageBar1_PagerEvent(int curPage, int pageSize) { getPageList(1); } /// /// 反审核 /// /// /// /// private void ToolBarMenu1_btnFChkClick(object sender, EventArgs e) { _toolCk(0); } /// /// 审核事件 /// /// /// private void ToolBarMenu1_btnChkClick(object sender, EventArgs e) { _toolCk(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_docCode, gridView1, "docCode"); if (string.IsNullOrEmpty(rowGuid)) { MsgHelper.Warning("请先选择你要操作的行!"); return; } if (!MsgHelper.AskQuestion("你选择了【" + rowName + "】,确定删除吗?")) return; var lst = new List(); lst.Add(rowGuid); var _obj = lst; try { var strJson = UtilityHelper.HttpPost("", "DocNoRule/DeleteModel", 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_docCode, gridView1); if (string.IsNullOrEmpty(rowGuid)) { MsgHelper.Warning("请先选择你要操作的行!"); return; } Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 3); UtilityHelper.ChangeEnableByControl(panel1.Controls, true); txxtItem1.Enabled = txxtItem2.Enabled = txxtItem3.Enabled = txxtItem4.Enabled = panelControl1.Enabled = true; } /// /// 新增事件 /// /// /// private void ToolBarMenu1_btnAddClick(object sender, EventArgs e) { lbGuid.Text = ""; Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 4); UtilityHelper.CleanValueByControl(panel1.Controls, true); txxtItem1.SelectedIndex = txxtItem2.SelectedIndex = txxtItem3.SelectedIndex = txxtItem4.SelectedIndex = 0; txxtItem1.Enabled = txxtItem2.Enabled = txxtItem3.Enabled = txxtItem4.Enabled = panelControl1.Enabled = true; } /// /// 保存事件 /// /// /// private void ToolBarMenu1_btnSaveClick(object sender, EventArgs e) { toolBarMenu1.isSetBtn = false; if (txt_docCode.EditValue == null || string.IsNullOrEmpty(txt_docCode.EditValue.ToString())) { MsgHelper.Warning("请先选择单据类型!"); txt_docCode.Focus(); return; } if (txxtItem1.SelectedIndex + txxtItem2.SelectedIndex + txxtItem3.SelectedIndex + txxtItem4.SelectedIndex <= 0) { MsgHelper.Warning("请至少选择一个参数!"); txxtItem1.Focus(); return; } if (txt_docFormat.Text.Length <= 0) { MsgHelper.Warning("请先配置参数!"); txt_docCode.Focus(); return; } var _obj = new { guid = UtilityHelper.ToGuid(lbGuid.Text.Trim()), //主建 docCode = txt_docCode.EditValue.ToString(), docFormat = txt_docFormat.Text, noLength = txt_noLength.Value.ToString(), resetZero = txt_resetZero.Checked, isSpilit = txt_isSpilit.Checked, isIncludeDoc = txt_isIncludeDoc.Checked }; try { var strJson = UtilityHelper.HttpPost("", "DocNoRule/EditModel", JsonConvert.SerializeObject(_obj)); var _rtn = UtilityHelper.ReturnToDynamic(strJson); MsgHelper.Warning("提示:" + _rtn.rtnMsg); if (_rtn.rtnCode > 0) { lbGuid.Text = _rtn.rtnData; toolBarMenu1.isSetBtn = true; UtilityHelper.ChangeEnableByControl(panel1.Controls, false); } } catch (Exception ex) { MsgHelper.Warning("提示:" + ex.Message); } } /// /// /// 第几页 /// 每页几条 private void getPageList(int curPage) { var pgq = new PageQueryModel(curPage, this.pageBar1.RowsCount, "doc_Code"); var json = JsonConvert.SerializeObject(pgq); try { var strReturn = UtilityHelper.HttpPost("", "DocNoRule/GetListPage", json); var dd = UtilityHelper.ReturnToTablePage(strReturn); if (dd.rtnCode > 0) { DataTable dt = dd.rtnData.list; gcMain.BindingContext = new BindingContext(); gcMain.DataSource = dt; gcMain.ForceInitialize(); pageBar1.TotalPages = dd.rtnData.pages;//总页 pageBar1.CurrentPage = curPage;//当前页 pageBar1.RecordCount = dd.rtnData.total;//总记录数 gridView1.BestFitColumns(); } else { ToolBox.MsgHelper.ShowError("提示:" + dd.rtnMsg); } } 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("", "DocNoRule/GetModel", JsonConvert.SerializeObject(_obj)); var _rtn = UtilityHelper.ReturnToDynamic(strJson); if (_rtn.rtnCode > 0) { var dy = _rtn.rtnData; lbGuid.Text = strGuid; UtilityHelper.SetValueByObj(panel1.Controls, dy, isEdit); txt_docCode.EditValue = dy.docCode.ToString(); string _rule = dy.docFormat.ToString(); var _ary = _rule.Split(new[] { '<' }, StringSplitOptions.RemoveEmptyEntries); if (_ary.Length > 0) txxtItem1.Text = "<" + _ary[0]; if (_ary.Length > 1) txxtItem2.Text = "<" + _ary[1]; if (_ary.Length > 2) txxtItem3.Text = "<" + _ary[2]; if (_ary.Length > 3) txxtItem4.Text = "<" + _ary[3]; txxtItem1.Enabled = txxtItem2.Enabled = txxtItem3.Enabled = txxtItem4.Enabled = panelControl1.Enabled = false; } else { MsgHelper.Warning("提示:" + _rtn.rtnMsg); } } catch (Exception ex) { MsgHelper.Warning("提示:" + ex.Message); } } private void getTree() { var dataTable = new DataTable(); dataTable.Columns.Add("docCode", typeof(string)); dataTable.Rows.Add("CGDH(到货单)");//V dataTable.Rows.Add("CGJY(检验单)");//V dataTable.Rows.Add("DBSQ(调拨申请单)");//V dataTable.Rows.Add("GDPC(工单排产)");//V dataTable.Rows.Add("WWPC(委外排产)");//V dataTable.Rows.Add("CKSQ(出库申请)");//V dataTable.Rows.Add("RKSQ(入库申请)");//V dataTable.Rows.Add("TL(退料单)"); dataTable.Rows.Add("IN(入库单)"); dataTable.Rows.Add("SC(生产工单)"); dataTable.Rows.Add("OUT(出库单)"); dataTable.Rows.Add("HB(物料合并)"); dataTable.Rows.Add("QTSQ(其他入库申请)"); txt_docCode.Properties.DataSource = dataTable; txt_docCode.Properties.DisplayMember = "docCode"; // 显示的列 txt_docCode.Properties.ValueMember = "docCode"; // 实际值的列 txt_docCode.Properties.TextEditStyle = TextEditStyles.DisableTextEditor; } private void DoPreviewCode() { if (txt_docCode.Enabled == false || txxtItem1.Enabled == false || txxtItem2.Enabled == false || txxtItem3.Enabled == false || txxtItem4.Enabled == false) return; var text = txxtItem1.Text + txxtItem2.Text + txxtItem3.Text + txxtItem4.Text; txt_docFormat.Text = text; if (txt_docFormat.Text == "") { lblPreview.Text = "请定义规则."; } else { var preview = txt_docFormat.Text; var length = int.Parse(txt_noLength.Value.ToString()); var docCode = ""; if (txt_isIncludeDoc.Checked) docCode = txt_docCode.EditValue.ToString(); preview = docCode + preview; preview = preview.Replace("<无>", ""); preview = preview.Replace("<年年年年>", "2024"); preview = preview.Replace("<年年>", "24"); preview = preview.Replace("<月月>", "06"); preview = preview.Replace("<日日>", "18"); preview = preview + (txt_isSpilit.Checked ? "-" : "") + "8".PadLeft(length, '0'); lblPreview.Text = "样例:" + preview; } } /// /// 工具条事件 /// /// 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_docCode, gridView1, "docCode"); if (string.IsNullOrEmpty(rowGuid)) { MsgHelper.Warning("请先选择你要操作的行!"); return; } if (!MsgHelper.AskQuestion("你选择了【" + rowName + "】,确定" + strMsg + "吗?")) return; var _obj = new { guid = rowGuid, ckValue = _inFieldValue, parameter = "SYS_DOC_RULE,check_date,check_status,check_by" }; try { var strJson = UtilityHelper.HttpPost("", "General/GeneralCheck", JsonConvert.SerializeObject(_obj)); var _rtn = UtilityHelper.ReturnToDynamic(strJson); MsgHelper.Warning(_rtn.rtnData.outMsg.ToString()); if (_rtn.rtnCode > 0) { if (xtraTabControl1.SelectedTabPageIndex == 1) { getModel(lbGuid.Text.Trim()); } int rowHandle = gridView1.LocateByValue(1, gridView1.Columns["guid"], rowGuid); gridView1.FocusedRowHandle = rowHandle; UtilityHelper.SetCheckIco(gridView1, "checkStatus", "", "", picCheckBox, this, _inFieldValue.ToString()); } } catch (Exception ex) { MsgHelper.Warning("提示:" + ex.Message); } } } }