lu
2024-10-23 bd06bb837fa0c7edeeae56cb0fe4fb844f53fb2f
DevApp/Gs.DevApp/DevFrm/Sys/DocNoRule.cs
@@ -1,10 +1,9 @@
using DevExpress.XtraEditors.Controls;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using Gs.DevApp.Entity;
using Gs.DevApp.ToolBox;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Windows.Forms;
@@ -21,10 +20,11 @@
            this.toolBarMenu1.btnLoadClick += ToolBarMenu1_btnLoadClick;
            this.toolBarMenu1.btnDelClick += ToolBarMenu1_btnDelClick1;
            this.toolBarMenu1.btnEscClick += ToolBarMenu1_btnEscClick;
            this.toolBarMenu1.btnChkClick += ToolBarMenu1_btnChkClick;
            this.toolBarMenu1.btnFChkClick += ToolBarMenu1_btnFChkClick;
            gcMain.MouseDoubleClick += GcMain_MouseDoubleClick;
            gridView1.ColumnFilterChanged += GridView1_ColumnFilterChanged;
            pageBar1.PagerEvent += PageBar1_PagerEvent;
            getPageList(1, UtilityHelper.GetPageSize());
            pageBar1.PagerEvent += PageBar1_PagerEvent;
            getTree();
            txt_docCode.EditValueChanged += Txt_docCode_EditValueChanged;
            txxtItem1.EditValueChanged += TxxtItem1_EditValueChanged;
@@ -32,20 +32,8 @@
            txxtItem3.EditValueChanged += TxxtItem1_EditValueChanged;
            txxtItem4.EditValueChanged += TxxtItem1_EditValueChanged;
            txt_noLength.ValueChanged += Txt_noLength_ValueChanged;
            txt_flagIncludeDocCode.CheckedChanged += Txt_flagIncludeDocCode_CheckedChanged;
            txt_flagSpilitNo.CheckedChanged += Txt_flagIncludeDocCode_CheckedChanged;
        }
        private void GridView1_ColumnFilterChanged(object sender, EventArgs e)
        {
            //// 获取GridView组件
            //GridView view = sender as GridView;
            //// 确保view不为null
            //if (view == null) return;
            //// 获取应用的筛选器信息
            //string filter = view.ActiveFilterString;
            //MessageBox.Show(filter);
            //getPageList(1, UtilityHelper.GetPageSize());
            txt_isIncludeDoc.CheckedChanged += Txt_flagIncludeDocCode_CheckedChanged;
            txt_isSpilit.CheckedChanged += Txt_flagIncludeDocCode_CheckedChanged;
        }
        /// <summary>
        /// 双击事件
@@ -54,19 +42,12 @@
        /// <param name="e"></param>
        private void GcMain_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            GridHitInfo info = gridView1.CalcHitInfo(e.Location);
            if (info.InRow)
            string rowGuid = Gs.DevApp.ToolBox.UtilityHelper.GetCurrentDoubleRow(gridView1, e, "guid");
            if (!string.IsNullOrEmpty(rowGuid))
            {
                GridView view = info.View as GridView;
                if (view != null)
                {
                    DataRow row = view.GetDataRow(info.RowHandle);
                    if (row != null)
                    {
                        string rowGuid = (row["guid"].ToString());
                        getModel(rowGuid, false, 999);
                    }
                }
                getModel(rowGuid, false, 999);
                txxtItem1.Enabled = txxtItem2.Enabled = txxtItem3.Enabled = txxtItem4.Enabled = false;
            }
        }
        /// <summary>
@@ -79,13 +60,38 @@
            getPageList(curPage, pageSize);
        }
        /// <summary>
        /// 反审核
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <exception cref="NotImplementedException"></exception>
        private void ToolBarMenu1_btnFChkClick(object sender, EventArgs e)
        {
            this.toolBarMenu1.guidKey = "";
            string rowGuid, rowName;
            (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, lbGuid, txt_docCode, gridView1);
            this.toolBarMenu1.guidKey = rowGuid;
        }
        /// <summary>
        /// 审核事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnChkClick(object sender, EventArgs e)
        {
            this.toolBarMenu1.guidKey = "";
            string rowGuid, rowName;
            (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, lbGuid, txt_docCode, gridView1);
            this.toolBarMenu1.guidKey = rowGuid;
        }
        /// <summary>
        /// 取消事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnEscClick(object sender, EventArgs e)
        {
            UtilityHelper.ChangeTab(xtraTabControl1, 0);
            UtilityHelper.JumpToTab(xtraTabControl1, 0);
        }
        /// <summary>
        /// 删除事件
@@ -94,26 +100,26 @@
        /// <param name="e"></param>
        private void ToolBarMenu1_btnDelClick1(object sender, EventArgs e)
        {
            DataRow dr = gridView1.GetFocusedDataRow();
            if (dr == null || string.IsNullOrEmpty(dr["guid"].ToString()))
            string rowGuid, rowName;
            (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, lbGuid, txt_docCode, gridView1);
            if (string.IsNullOrEmpty(rowGuid))
            {
                ToolBox.MsgHelper.Warning("请先选择你要操作的行!");
                return;
            }
            if (!MsgHelper.AskQuestion("你选择了【" + dr["docCode"].ToString() + "】,确定删除吗?"))
            if (!MsgHelper.AskQuestion("你选择了【" + rowName + "】,确定删除吗?"))
                return;
            var _obj = new
            {
                guidList = dr["guid"].ToString(),//主建
            };
            string strJson = "";
            List<string> lst = new List<string>();
            lst.Add(rowGuid);
            var _obj = lst;
            try
            {
                strJson = UtilityHelper.HttpPost("", "DocNoRule/DeleteModel", JsonConvert.SerializeObject(_obj));
                ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.GetDataByJson(strJson);
                string strJson = UtilityHelper.HttpPost("", "DocNoRule/DeleteModel", JsonConvert.SerializeObject(_obj));
                ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson);
                if (_rtn.rtnCode > 0)
                {
                    UtilityHelper.ChangeTab(xtraTabControl1, 0);
                    UtilityHelper.JumpToTab(xtraTabControl1, 0);
                    getPageList(1, UtilityHelper.GetPageSize());
                }
                ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg);
@@ -130,7 +136,7 @@
        /// <param name="e"></param>
        private void ToolBarMenu1_btnLoadClick(object sender, EventArgs e)
        {
            UtilityHelper.ChangeTab(xtraTabControl1, 0);
            UtilityHelper.JumpToTab(xtraTabControl1, 0);
            getPageList(1, UtilityHelper.GetPageSize());
        }
        /// <summary>
@@ -140,15 +146,15 @@
        /// <param name="e"></param>
        private void ToolBarMenu1_btnEdtClick(object sender, EventArgs e)
        {
            DataRow dr = gridView1.GetFocusedDataRow();
            if (dr == null || string.IsNullOrEmpty(dr["guid"].ToString()))
            string rowGuid, rowName;
            (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, lbGuid, txt_docCode, gridView1);
            if (string.IsNullOrEmpty(rowGuid))
            {
                ToolBox.MsgHelper.Warning("请先选择你要操作的行!");
                return;
            }
            txxtItem1.Enabled = txxtItem2.Enabled = txxtItem3.Enabled = txxtItem4.Enabled = false;
            getModel(dr["guid"].ToString(), true, 1);
            txxtItem1.Enabled = txxtItem2.Enabled = txxtItem3.Enabled = txxtItem4.Enabled = true;
            getModel(rowGuid, true, 1);
            txxtItem1.Enabled = txxtItem2.Enabled = txxtItem3.Enabled = txxtItem4.Enabled = panelControl1.Enabled = true;
        }
        /// <summary>
        /// 新增事件
@@ -157,11 +163,11 @@
        /// <param name="e"></param>
        private void ToolBarMenu1_btnAddClick(object sender, EventArgs e)
        {
            UtilityHelper.ChangeTab(xtraTabControl1, 1);
            UtilityHelper.JumpToTab(xtraTabControl1, 1);
            lbGuid.Text = "";
            UtilityHelper.CleanValue(this.panel1.Controls, true);
            UtilityHelper.CleanValueByControl(this.panel1.Controls, true);
            txxtItem1.SelectedIndex = txxtItem2.SelectedIndex = txxtItem3.SelectedIndex = txxtItem4.SelectedIndex = 0;
            txxtItem1.Enabled = txxtItem2.Enabled = txxtItem3.Enabled = txxtItem4.Enabled = panelControl1.Enabled = true;
        }
        /// <summary>
        /// 保存事件
@@ -177,39 +183,38 @@
                txt_docCode.Focus();
                return;
            }
            if (txt_ruleFormat.Text.Length <= 0)
            if ((txxtItem1.SelectedIndex + txxtItem2.SelectedIndex + txxtItem3.SelectedIndex + txxtItem4.SelectedIndex) <= 0)
            {
                ToolBox.MsgHelper.Warning("请至少选择一个参数!");
                txxtItem1.Focus();
                return;
            }
            if (txt_docFormat.Text.Length <= 0)
            {
                ToolBox.MsgHelper.Warning("请先配置参数!");
                txt_docCode.Focus();
                return;
            }
            if (txt_resetZero.SelectedIndex <= 0)
            {
                Gs.DevApp.ToolBox.MsgHelper.Warning("请选择归零方式!");
                txt_resetZero.Focus();
                return;
            }
            var _obj = new
            {
                guid = lbGuid.Text.Trim(),//主建
                docCode = txt_docCode.EditValue.ToString(),
                ruleFormat = txt_ruleFormat.Text.ToString(),
                //currentValue = txt_currentValue.Text.ToString(),
                docFormat = txt_docFormat.Text.ToString(),
                noLength = txt_noLength.Value.ToString(),
                resetZero = txt_resetZero.SelectedIndex.ToString(),
                flagSpilitNo = txt_flagSpilitNo.Checked ? 1 : 2,
                flagIncludeDocCode = txt_flagIncludeDocCode.Checked ? 1 : 2,
                resetZero = txt_resetZero.Checked,
                isSpilit = txt_isSpilit.Checked,
                isIncludeDoc = txt_isIncludeDoc.Checked,
            };
            try
            {
                string strJson = UtilityHelper.HttpPost("", "DocNoRule/EditModel", JsonConvert.SerializeObject(_obj));
                ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.GetDataByJson(strJson);
                ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson);
                ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg);
                if (_rtn.rtnCode > 0)
                {
                    lbGuid.Text = _rtn.rtnData;
                    toolBarMenu1.isSetBtn = true;
                    UtilityHelper.ChangeEnable(this.panel1.Controls, false);
                    UtilityHelper.ChangeEnableByControl(this.panel1.Controls, false);
                }
            }
            catch (Exception ex)
@@ -224,12 +229,12 @@
        /// <param name="pageSize">每页几条</param>
        private void getPageList(int curPage, int pageSize)
        {
            PageQueryModel pgq = new PageQueryModel(curPage, pageSize, "createTime", "asc", "", "");
            PageQueryModel pgq = new PageQueryModel(curPage, pageSize, "doc_Code", "asc", "", "");
            string json = JsonConvert.SerializeObject(pgq);
            try
            {
                string strReturn = UtilityHelper.HttpPost("", "DocNoRule/GetListPage", json);
                ReturnModel<PageListModel> dd = UtilityHelper.GetTableByJson(strReturn);
                ReturnModel<PageListModel> dd = UtilityHelper.ReturnToTablePage(strReturn);
                DataTable dt = dd.rtnData.list;
                gcMain.BindingContext = new BindingContext();
                gcMain.DataSource = dt;
@@ -253,7 +258,7 @@
                ToolBox.MsgHelper.Warning("请先选择你要操作的行!");
                return;
            }
            UtilityHelper.ChangeTab(xtraTabControl1, tabIdx);
            UtilityHelper.JumpToTab(xtraTabControl1, tabIdx);
            var _obj = new
            {
                guid = strGuid,//主建
@@ -261,15 +266,14 @@
            try
            {
                string strJson = UtilityHelper.HttpPost("", "DocNoRule/GetModel", JsonConvert.SerializeObject(_obj));
                ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.GetDataByJson(strJson);
                ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson);
                if (_rtn.rtnCode > 0)
                {
                    dynamic dy = _rtn.rtnData;
                    lbGuid.Text = strGuid;
                    UtilityHelper.SetValueByObj(this.panel1.Controls, dy, isEdit);
                    txt_docCode.EditValue = dy.docCode.ToString();
                    txxtItem1.Enabled = txxtItem2.Enabled = txxtItem3.Enabled = txxtItem4.Enabled = false;
                    string _rule = dy.ruleFormat.ToString();
                    string _rule = dy.docFormat.ToString();
                    string[] _ary = _rule.Split(new char[] { '<' }, StringSplitOptions.RemoveEmptyEntries);
                    if (_ary.Length > 0)
                        txxtItem1.Text = "<" + _ary[0];
@@ -291,10 +295,8 @@
        private void getTree()
        {
            // 创建数据表
            DataTable dataTable = new DataTable();
            dataTable.Columns.Add("docCode", typeof(string));
            // 添加数据行
            dataTable.Rows.Add("DH(到货单)");
            dataTable.Rows.Add("QO(报价单)");
            dataTable.Rows.Add("PO(采购订单)");
@@ -307,11 +309,10 @@
            dataTable.Rows.Add("IV(销售发票)");
            dataTable.Rows.Add("IN(入库)");
            dataTable.Rows.Add("PN(生产库)");
            // 设置LookUpEdit的数据源
            txt_docCode.Properties.DataSource = dataTable;
            txt_docCode.Properties.DisplayMember = "docCode"; // 显示的列
            txt_docCode.Properties.ValueMember = "docCode";     // 实际值的列
            txt_docCode.Properties.TextEditStyle = TextEditStyles.Standard;
            txt_docCode.Properties.TextEditStyle = TextEditStyles.DisableTextEditor;
        }
        private void Txt_flagIncludeDocCode_CheckedChanged(object sender, EventArgs e)
@@ -330,31 +331,25 @@
        }
        private void DoPreviewCode()
        {
            if (txt_docCode.Enabled == false
                || txxtItem1.Enabled==false
                || txxtItem2.Enabled == false
                || txxtItem3.Enabled == false
            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_ruleFormat.Text = text;
            if (txt_docCode.EditValue == null)
            {
                ToolBox.MsgHelper.Warning("请先选择单据类型");
                txt_docCode.Focus();
                return;
            }
            if (txt_ruleFormat.Text == "")
            txt_docFormat.Text = text;
            if (txt_docFormat.Text == "")
            {
                lblPreview.Text = "请定义规则.";
            }
            else
            {
                // txtRuleFormat="<年年>", "<年年年年>", "<月月>", "<日日>" });
                var preview = txt_ruleFormat.Text;
                var preview = txt_docFormat.Text;
                var length = int.Parse(txt_noLength.Value.ToString());
                var docCode = "";
                if (txt_flagIncludeDocCode.Checked)
                if (txt_isIncludeDoc.Checked)
                {
                    docCode = txt_docCode.EditValue.ToString();
                }
@@ -364,7 +359,7 @@
                preview = preview.Replace("<年年>", "24");
                preview = preview.Replace("<月月>", "06");
                preview = preview.Replace("<日日>", "18");
                preview = preview + (txt_flagSpilitNo.Checked ? "-" : "") + "8".PadLeft(length, '0');
                preview = preview + (txt_isSpilit.Checked ? "-" : "") + "8".PadLeft(length, '0');
                lblPreview.Text = "生成编号:" + preview;
            }
        }