lu
2024-12-19 1210460a95ba58f219d38e545dcaf9e21383d18f
DevApp/Gs.DevApp/DevFrm/BasicData/Frm_MesWorkshop.cs
@@ -1,8 +1,7 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
@@ -18,50 +17,41 @@
    public partial class Frm_MesWorkshop : XtraForm
    {
        private List<FilterEntity> _filterList = new List<FilterEntity>();
        private readonly string _webServiceName = "MesWorkshopManager/";
        private readonly string _webServiceName = "SysDepartmentManager/";
        public Frm_MesWorkshop()
        {
            InitializeComponent();
            toolBarMenu1.btnAddClick += ToolBarMenu1_btnAddClick;
            toolBarMenu1.btnEscClick += ToolBarMenu1_btnEscClick;
            toolBarMenu1.btnEdtClick += ToolBarMenu1_btnEdtClick;
            toolBarMenu1.btnSaveClick += ToolBarMenu1_btnSaveClick;
            toolBarMenu1.btnLoadClick += ToolBarMenu1_btnLoadClick;
            toolBarMenu1.btnDelClick += ToolBarMenu1_btnDelClick1;
            toolBarMenu1.btnEscClick += ToolBarMenu1_btnEscClick;
            toolBarMenu1.btnQueryClick += ToolBarMenu1_btnQueryClick;
            toolBarMenu1.btnChkClick += ToolBarMenu1_btnChkClick;
            toolBarMenu1.btnFChkClick += ToolBarMenu1_btnFChkClick;
            gcMain.MouseDoubleClick += GcMain_MouseDoubleClick;
            getPageList(1, UtilityHelper.GetPageSize());
            Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameterMx(gvMx1);
            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;
            gridView1.CustomDrawRowIndicator += (s, e) =>
            {
                if (e.Info.IsRowIndicator && e.RowHandle >= 0)
                    e.Info.DisplayText = (e.RowHandle + 1).ToString();
            };
            gridView1.CustomDrawEmptyForeground += (s, e) =>
            {
                var str = "暂未查找到匹配的数据!";
                var f = new Font("微软雅黑", 16);
                var r = new Rectangle(gridView1.GridControl.Width / 2 - 100,
                    e.Bounds.Top + 45, e.Bounds.Right - 5, e.Bounds.Height - 5);
                e.Graphics.DrawString(str, f, Brushes.Gray, r);
            };
        }
        /// <summary>
        ///     双击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GcMain_MouseDoubleClick(object sender, MouseEventArgs e)
        private void GridView1_ColumnFilterChanged(object sender, EventArgs e)
        {
            var rowGuid =
                UtilityHelper.GetCurrentDoubleRow(gridView1, e, "guid");
            if (!string.IsNullOrEmpty(rowGuid))
                getModel(rowGuid, false, 999);
            _filterList = Gs.DevApp.ToolBox.UtilityHelper.GetDilter(gridView1.Columns);
            Task.Delay(100);
            getPageList(1);
        }
        /// <summary>
        ///     分页事件
@@ -70,7 +60,7 @@
        /// <param name="pageSize"></param>
        private void PageBar1_PagerEvent(int curPage, int pageSize)
        {
            getPageList(curPage, pageSize);
            getPageList(curPage);
        }
        /// <summary>
@@ -80,6 +70,9 @@
        /// <param name="e"></param>
        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);
            frm.UpdateParent += Frm_UpdateParent;
            frm.ShowDialog();
@@ -93,87 +86,7 @@
        private void Frm_UpdateParent(object sender, UpdateParentEventArgs e)
        {
            _filterList = e.FilterList;
            getPageList(1, pageBar1.RowsCount);
        }
        /// <summary>
        ///     反审核
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <exception cref="NotImplementedException"></exception>
        private void ToolBarMenu1_btnFChkClick(object sender, EventArgs e)
        {
            toolBarMenu1.guidKey = "";
            string rowGuid, rowName;
            (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1,
                lbGuid, txt_name, gridView1);
            toolBarMenu1.guidKey = rowGuid;
        }
        /// <summary>
        ///     审核事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnChkClick(object sender, EventArgs e)
        {
            toolBarMenu1.guidKey = "";
            string rowGuid, rowName;
            (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1,
                lbGuid, txt_name, gridView1);
            toolBarMenu1.guidKey = rowGuid;
        }
        /// <summary>
        ///     取消事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnEscClick(object sender, EventArgs e)
        {
            UtilityHelper.JumpToTab(xtraTabControl1, 0);
        }
        /// <summary>
        ///     删除事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnDelClick1(object sender, EventArgs e)
        {
            string rowGuid = "", rowName = "";
            (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1,
                lbGuid, txt_name, gridView1);
            if (string.IsNullOrEmpty(rowGuid))
            {
                MsgHelper.Warning("请先选择你要操作的行!");
                return;
            }
            if (!MsgHelper.AskQuestion("你选择了【" + rowName + "】,确定删除吗?"))
                return;
            var lst = new List<string>();
            lst.Add(rowGuid);
            var _obj = lst;
            try
            {
                var strJson = UtilityHelper.HttpPost("",
                    _webServiceName + "DeleteModel",
                    JsonConvert.SerializeObject(_obj));
                var _rtn = UtilityHelper.ReturnToDynamic(strJson);
                if (_rtn.rtnCode > 0)
                {
                    UtilityHelper.JumpToTab(xtraTabControl1, 0);
                    getPageList(1, UtilityHelper.GetPageSize());
                }
                MsgHelper.Warning("提示:" + _rtn.rtnMsg);
            }
            catch (Exception ex)
            {
                MsgHelper.Warning("提示:" + ex.Message);
            }
            getPageList(1);
        }
        /// <summary>
@@ -183,112 +96,18 @@
        /// <param name="e"></param>
        private void ToolBarMenu1_btnLoadClick(object sender, EventArgs e)
        {
            UtilityHelper.JumpToTab(xtraTabControl1, 0);
            getPageList(1, UtilityHelper.GetPageSize());
        }
        /// <summary>
        ///     修改事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnEdtClick(object sender, EventArgs e)
        {
            string rowGuid = "", rowName = "";
            (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1,
                lbGuid, txt_name, gridView1);
            if (string.IsNullOrEmpty(rowGuid))
            if (xtraTabControl1.SelectedTabPageIndex == 1)
                getModel(lbGuid.Text.Trim());
            else
            {
                MsgHelper.Warning("请先选择你要操作的行!");
                return;
            }
            getModel(rowGuid, true, 1);
        }
        /// <summary>
        ///     新增事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnAddClick(object sender, EventArgs e)
        {
            UtilityHelper.JumpToTab(xtraTabControl1, 1);
            lbGuid.Text = "";
            var gridViews = new List<GridView>();
            gridViews.Add(gvMx1);
            UtilityHelper.CleanValueByControl(panel1.Controls, true, gridViews);
            UtilityHelper.SetDefaultTable(gcMx1, gvMx1);
        }
        /// <summary>
        ///     保存事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnSaveClick(object sender, EventArgs e)
        {
            toolBarMenu1.isSetBtn = false;
            if (string.IsNullOrEmpty(txt_workshopNo.Text.Trim()))
            {
                MsgHelper.Warning("编号不能为空!");
                txt_workshopNo.Focus();
                return;
            }
            if (string.IsNullOrEmpty(txt_name.Text.Trim()))
            {
                MsgHelper.Warning("名称不能为空!");
                txt_name.Focus();
                return;
            }
            gvMx1.CloseEditor();
            gvMx1.UpdateCurrentRow();
            var lst = new List<dynamic>();
            for (var i = 0; i < gvMx1.DataRowCount; i++)
            {
                var row = gvMx1.GetDataRow(i);
                if (row != null)
                    lst.Add(new
                    {
                        guid = UtilityHelper.ToGuid(row["guid"].ToString()),
                        lineNo = row["lineNo"].ToString(),
                        name = row["name"].ToString(),
                        remark = row["remark"].ToString(),
                        isStatus = row["isStatus"].ToString()
                    });
            }
            var _obj = new
            {
                guid = UtilityHelper.ToGuid(lbGuid.Text.Trim()), //主建
                workshopNo = txt_workshopNo.Text.Trim(),
                name = txt_name.Text.Trim(),
                remark = txt_remark.Text.Trim(),
                isStatus = txt_isStatus.Checked,
                list = lst
            };
            try
            {
                var strJson = UtilityHelper.HttpPost("",
                    _webServiceName + "EditModel",
                    JsonConvert.SerializeObject(_obj));
                var _rtn = UtilityHelper.ReturnToDynamic(strJson);
                MsgHelper.Warning("提示:" + _rtn.rtnMsg);
                if (_rtn.rtnCode > 0)
                _filterList.Clear();
                if (gridView1.ActiveFilter.Count > 0)
                {
                    lbGuid.Text = _rtn.rtnData;
                    toolBarMenu1.isSetBtn = true;
                    var gridViews = new List<GridView>();
                    gridViews.Add(gvMx1);
                    UtilityHelper.ChangeEnableByControl(panel1.Controls, false,
                        gridViews);
                    gridView1.ColumnFilterChanged -= GridView1_ColumnFilterChanged;
                    gridView1.ActiveFilter.Clear();
                    gridView1.ColumnFilterChanged += GridView1_ColumnFilterChanged;
                }
            }
            catch (Exception ex)
            {
                MsgHelper.Warning("提示:" + ex.Message);
                getPageList(1);
            }
        }
@@ -296,14 +115,11 @@
        /// </summary>
        /// <param name="curPage">第几页</param>
        /// <param name="pageSize">每页几条</param>
        private void getPageList(int curPage, int pageSize)
        private void getPageList(int curPage)
        {
            var _sbSqlWhere = new StringBuilder();
            foreach (var itm in _filterList)
                _sbSqlWhere.Append(" and " + itm.fileId + itm.fileOper + "'" +
                                   itm.fileValue + "'");
            var pgq = new PageQueryModel(curPage, pageSize, "create_date",
                "asc", "", _sbSqlWhere.ToString());
            var _sbSqlWhere = UtilityHelper.GetSearchWhere(_filterList);
            var pgq = new PageQueryModel(curPage, this.pageBar1.RowsCount, "a.create_date",
            "asc", "", _sbSqlWhere.ToString());
            var json = JsonConvert.SerializeObject(pgq);
            try
            {
@@ -314,14 +130,18 @@
                {
                    DataTable dt = dd.rtnData.list;
                    gcMain.BindingContext = new BindingContext();
                    gcMain.DataSource = dt;
                    gcMain.ForceInitialize();
                    int dddd = dd.rtnData.pages;//总页
                    pageBar1.TotalPages = dddd;
                    pageBar1.RecordCount = dd.rtnData.total;//记录总数
                    gridView1.ColumnFilterChanged -= GridView1_ColumnFilterChanged;
                    if (dt.Rows.Count > 0)
                    {
                        gcMain.DataSource = dt;
                        gcMain.ForceInitialize();
                    }
                    else
                        UtilityHelper.SetDefaultTable(gcMain, gridView1);
                    gridView1.ColumnFilterChanged += GridView1_ColumnFilterChanged;
                    pageBar1.TotalPages = dd.rtnData.pages;//总页
                    pageBar1.CurrentPage = curPage;//当前页
                    pageBar1.RowsCount = pageSize;//每页显示
                    pageBar1.setTxt();
                    pageBar1.RecordCount = dd.rtnData.total;//总记录数
                }
                else
                {
@@ -332,17 +152,18 @@
            {
                MsgHelper.Warning("提示:" + ex.Message);
            }
        }
        private void getModel(string strGuid, bool isEdit, int tabIdx)
        }
        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;
            }
            UtilityHelper.JumpToTab(xtraTabControl1, tabIdx);
            var _obj = new
            {
                guid = strGuid //主建
@@ -390,9 +211,119 @@
            }
        }
        /// <summary>
        ///     反审核
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <exception cref="NotImplementedException"></exception>
        private void ToolBarMenu1_btnFChkClick(object sender, EventArgs e)
        {
            _toolCk(0);
        }
        /// <summary>
        ///     取消事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnEscClick(object sender, EventArgs e)
        {
            UtilityHelper.JumpToTab(xtraTabControl1, 0);
        }
        /// <summary>
        ///     审核事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnChkClick(object sender, EventArgs e)
        {
            _toolCk(1);
        }
        /// <summary>
        ///     修改事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnEdtClick(object sender, EventArgs e)
        {
            string rowGuid = "", rowName = "";
            (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1,
                lbGuid, txt_departmentcode, gridView1);
            if (string.IsNullOrEmpty(rowGuid))
            {
                MsgHelper.Warning("请先选择你要操作的行!");
                return;
            }
            Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 3);
            List<DevExpress.XtraGrid.Views.Grid.GridView> gvList = new List<DevExpress.XtraGrid.Views.Grid.GridView>();
            gvList.Add(gvMx1);
            UtilityHelper.ChangeEnableByControl(panel1.Controls, true, gvList);
        }
        /// <summary>
        ///     保存事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnSaveClick(object sender, EventArgs e)
        {
            toolBarMenu1.isSetBtn = false;
            if (string.IsNullOrEmpty(txt_departmentcode.Text.Trim()))
            {
                MsgHelper.Warning("名称不能为空!");
                txt_departmentcode.Focus();
                return;
            }
            gvMx1.CloseEditor();
            gvMx1.UpdateCurrentRow();
            var lst = new List<dynamic>();
            for (var i = 0; i < gvMx1.DataRowCount; i++)
            {
                var row = gvMx1.GetDataRow(i);
                if (row != null)
                    lst.Add(new
                    {
                        guid = UtilityHelper.ToGuid(row["guid"].ToString()),
                        lineNo = row["lineNo"].ToString(),
                        name = row["name"].ToString(),
                        remark = row["remark"].ToString(),
                        isStatus = row["isStatus"].ToString()
                    });
            }
            var _obj = new
            {
                guid = UtilityHelper.ToGuid(lbGuid.Text.Trim()), //主建
                list = lst
            };
            try
            {
                var strJson = UtilityHelper.HttpPost("",
                    _webServiceName + "EditModel",
                    JsonConvert.SerializeObject(_obj));
                var _rtn = UtilityHelper.ReturnToDynamic(strJson);
                MsgHelper.Warning("提示:" + _rtn.rtnMsg);
                if (_rtn.rtnCode > 0)
                {
                    lbGuid.Text = _rtn.rtnData;
                    toolBarMenu1.isSetBtn = true;
                    var gridViews = new List<GridView>();
                    gridViews.Add(gvMx1);
                    UtilityHelper.ChangeEnableByControl(panel1.Controls, false,
                        gridViews);
                }
            }
            catch (Exception ex)
            {
                MsgHelper.Warning("提示:" + ex.Message);
            }
        }
        private void repositoryItemButtonEdit1_ButtonClick(object sender,
            ButtonPressedEventArgs e)
        {
            gvMx1.CloseEditor();
            gvMx1.UpdateCurrentRow();
            var rowhandle = gvMx1.FocusedRowHandle;
            if (rowhandle < 0)
                return;
@@ -416,7 +347,7 @@
                        _webServiceName + "DeleteModelMx",
                        JsonConvert.SerializeObject(lst));
                    var _rtn = UtilityHelper.ReturnToDynamic(strJson);
                    if (_rtn.rtnCode > 0) getModel(lbGuid.Text, true, 1);
                    if (_rtn.rtnCode > 0) getModel(lbGuid.Text);
                    MsgHelper.Warning("提示:" + _rtn.rtnMsg);
                }
                catch (Exception ex)
@@ -425,5 +356,60 @@
                }
            }
        }
        /// <summary>
        /// 工具条事件
        /// </summary>
        /// <param name="inFieldValue"></param>
        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_departmentname, gridView1, "departmentname");
            if (string.IsNullOrEmpty(rowGuid))
            {
                MsgHelper.Warning("请先选择你要操作的行!");
                return;
            }
            if (!MsgHelper.AskQuestion("你选择了【" + rowName + "】,确定" + strMsg + "吗?"))
                return;
            var _obj = new
            {
                guid = rowGuid,
                ckValue = _inFieldValue,
                parameter = "SYS_DEPARTMENT,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());
                    else
                        getPageList(this.pageBar1.CurrentPage);
                }
            }
            catch (Exception ex)
            {
                MsgHelper.Warning("提示:" + ex.Message);
            }
        }
    }
}