lu
2024-12-23 2066a7e10e20433f7445431d6d34a9026c29f663
DevApp/Gs.DevApp/DevFrm/QC/Frm_MesQmCheckitemDt.cs
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
@@ -31,33 +30,29 @@
            toolBarMenu1.btnEscClick += ToolBarMenu1_btnEscClick;
            toolBarMenu1.btnQueryClick += ToolBarMenu1_btnQueryClick;
            toolBarMenu1.btnChkClick += ToolBarMenu1_btnChkClick;
            toolBarMenu1.btnFChkClick += ToolBarMenu1_btnFChkClick;
            toolBarMenu1.btnPiZhunClick += ToolBarMenu1_btnPiZhunClick;
            gcMain.MouseDoubleClick += GcMain_MouseDoubleClick;
            Gs.DevApp.ToolBox.UtilityHelper.SetGridSear(gridView1);
            Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameterMx(gvMx1);
            Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameter(gridView1, picCheckBox, this, "foneChecked", "", (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;
            //初始化物料选择和各种下拉
            _setIno();
            btnSave.Click += BtnSave_Click;
        }
        private void GridView1_ColumnFilterChanged(object sender, EventArgs e)
        {
            _filterList = Gs.DevApp.ToolBox.UtilityHelper.GetDilter(gridView1.Columns);
            Task.Delay(100);
            getPageList(1);
        }
        /// <summary>
        ///     双击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GcMain_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            var rowGuid =
                UtilityHelper.GetCurrentDoubleRow(gridView1,
                    e, "guid");
            if (!string.IsNullOrEmpty(rowGuid))
                getModel(rowGuid, false, 999);
        }
        /// <summary>
@@ -102,39 +97,7 @@
        /// <param name="e"></param>
        private void ToolBarMenu1_btnPiZhunClick(object sender, EventArgs e)
        {
            string rowGuid, rowName;
            (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1,
                lbGuid, txt_itemNo, gridView1);
            try
            {
                string strJson = UtilityHelper.HttpPost("", _webServiceName + "Approval", JsonConvert.SerializeObject(rowGuid));
                ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson);
                if (_rtn.rtnCode > 0)
                {
                    UtilityHelper.JumpToTab(xtraTabControl1, 0);
                    getPageList(1);
                }
                ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg);
            }
            catch (Exception ex)
            {
                ToolBox.MsgHelper.Warning("提示:" + ex.Message);
            }
        }
        /// <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_itemNo, gridView1);
            toolBarMenu1.guidKey = rowGuid;
            _toolCk(2);
        }
        /// <summary>
@@ -144,11 +107,7 @@
        /// <param name="e"></param>
        private void ToolBarMenu1_btnChkClick(object sender, EventArgs e)
        {
            toolBarMenu1.guidKey = "";
            string rowGuid, rowName;
            (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1,
                lbGuid, txt_itemNo, gridView1);
            toolBarMenu1.guidKey = rowGuid;
            _toolCk(1);
        }
        /// <summary>
        ///     取消事件
@@ -167,37 +126,7 @@
        /// <param name="e"></param>
        private void ToolBarMenu1_btnDelClick1(object sender, EventArgs e)
        {
            string rowGuid = "", rowName = "";
            (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, lbGuid, txt_itemNo, gridView1);
            if (string.IsNullOrEmpty(rowGuid))
            {
                MsgHelper.Warning("请先选择你要操作的行!");
                return;
            }
            if (!MsgHelper.AskQuestion("你选择了【" + rowName + "】的检验标准,确定删除吗?"))
                return;
            var lst = new List<dynamic>();
            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);
                }
                MsgHelper.Warning("提示:" + _rtn.rtnMsg);
            }
            catch (Exception ex)
            {
                MsgHelper.Warning("提示:" + ex.Message);
            }
            _toolCk(-1);
        }
        /// <summary>
@@ -208,7 +137,7 @@
        private void ToolBarMenu1_btnLoadClick(object sender, EventArgs e)
        {
            if (xtraTabControl1.SelectedTabPageIndex == 1)
                getModel(lbGuid.Text.Trim(), false, 999);
                getModel(lbGuid.Text.Trim());
            else
            {
                _filterList.Clear();
@@ -236,7 +165,9 @@
                MsgHelper.Warning("请先选择你要操作的行!");
                return;
            }
            getModel(rowGuid, true, 1);
            Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 3);
            UtilityHelper.ChangeEnableByControl(panel1.Controls, true);
        }
        /// <summary>
@@ -246,14 +177,13 @@
        /// <param name="e"></param>
        private void ToolBarMenu1_btnAddClick(object sender, EventArgs e)
        {
            UtilityHelper.JumpToTab(xtraTabControl1, 1);
            lbGuid.Text = "";
            var gridViews =
                new List<GridView>();
            Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 4);
            var gridViews = new List<GridView>();
            gridViews.Add(gvMx1);
            UtilityHelper.CleanValueByControl(panel1.Controls, true,
                gridViews);
            UtilityHelper.CleanValueByControl(panel1.Controls, true, gridViews);
            UtilityHelper.SetDefaultTable(gcMx1, gvMx1);
            xtraTabPageCopy.PageEnabled = false;
        }
        /// <summary>
@@ -264,8 +194,8 @@
        private void ToolBarMenu1_btnSaveClick(object sender, EventArgs e)
        {
            toolBarMenu1.isSetBtn = false;
            string _ItemId = txt_ItemId.GetId()
; if (string.IsNullOrEmpty(_ItemId))
            string _ItemId = txt_ItemId.GetId();
            if (string.IsNullOrEmpty(_ItemId))
            {
                MsgHelper.Warning("请选择物料!");
                txt_ItemId.Focus();
@@ -294,14 +224,12 @@
                        FdownAllow = row["FdownAllow"].ToString(),
                    });
            }
            var _obj = new MesQmCheckitem
            {
                Guid = UtilityHelper.ToGuid(lbGuid.Text.Trim()),
                ItemId = long.Parse(_ItemId),
                Memo = txt_memo.Text.Trim(),
                ItemNo = txt_itemNo.Text.Trim(),
                Isenabled = txt_isenabled.Checked,
                Ftype = "1",
                Fversion = Gs.DevApp.ToolBox.UtilityHelper.ToLong(txt_fversion.Text.Trim()),
                list = lst
@@ -336,7 +264,6 @@
        /// <param name="pageSize">每页几条</param>
        private void getPageList(int curPage)
        {
            var _sbSqlWhere = UtilityHelper.GetSearchWhere(_filterList);
            var pgq = new PageQueryModel(curPage, this.pageBar1.RowsCount,
                "a.create_date", "asc", "", _sbSqlWhere.ToString());
@@ -376,15 +303,17 @@
        }
        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);
            xtraTabPageCopy.PageEnabled = !isEdit;
            var _obj = new
            {
                guid = strGuid //主建
@@ -409,7 +338,6 @@
                    var _job = JObject.Parse(strJson);
                    var array = new JArray();
                    foreach (var a in _job["rtnData"]["list"]) array.Add(a);
                    var dt =
                        JsonConvert.DeserializeObject<DataTable>(
                            array.ToString());
@@ -421,9 +349,9 @@
                    }
                    else
                    {
                        UtilityHelper.SetDefaultTable(gcMx1,
                            gvMx1);
                        UtilityHelper.SetDefaultTable(gcMx1,gvMx1);
                    }
                    UtilityHelper.SetDefaultTable(gridControl2, gridView2);
                }
                else
                {
@@ -436,36 +364,65 @@
            }
        }
        /// <summary>
        /// 工具条事件
        /// </summary>
        /// <param name="inFieldValue"></param>
        private void _toolCk(int _inFieldValue)
        {
            string strMsg = "";
            switch (_inFieldValue)
            {
                case -1:
                    strMsg = "删除";
                    break;
                case 1:
                    strMsg = "审核";
                    break;
                case 2:
                    strMsg = "批准";
                    break;
            };
            toolBarMenu1.guidKey = "";
            string rowGuid, rowName;
            (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, lbGuid, txt_itemNo, gridView1, "itemNo");
            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());
                    else
                        getPageList(this.pageBar1.CurrentPage);
                }
            }
            catch (Exception ex)
            {
                MsgHelper.Warning("提示:" + ex.Message);
            }
        }
        #region 以下为种种下拉
        private  DataTable ListToTable<T>(List<T> items)
        {
            DataTable dataTable = new DataTable(typeof(T).Name);
            // 获取所有的属性
            PropertyInfo[] Props = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
            foreach (PropertyInfo prop in Props)
            {
                // 设置列的名字和数据类型
                dataTable.Columns.Add(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType);
            }
            // 遍历所有的对象
            foreach (T item in items)
            {
                var values = new object[Props.Length];
                for (int i = 0; i < Props.Length; i++)
                {
                    // 插入属性值到datatable
                    values[i] = Props[i].GetValue(item, null);
                }
                dataTable.Rows.Add(values);
            }
            return dataTable;
        }
        private void _setIno()
        {
            txt_ItemId.EditChanged += (s, e) =>
@@ -478,11 +435,17 @@
                var frm = new SelectCheckDt();
                frm.UpdateParent += (ss, ee) =>
                {
                    var lst = new List<dynamic>();
                    lst = ee.DynamicList;
                    DataTable table = ListToTable(lst);
                    var lst = ee.DynamicList;
                    var json = JsonConvert.SerializeObject(lst);
                    DataTable _newTable = (DataTable)JsonConvert.DeserializeObject(json, (typeof(DataTable)));
                    DataTable _oldTable = (DataTable)gridControl2.DataSource;
                    DataRow[] sourceRows = _newTable.Select();
                    for (int i = 0; i < sourceRows.Length; i++)
                    {
                        _oldTable.ImportRow(sourceRows[i]);
                    }
                    gridControl2.BindingContext = new BindingContext();
                    gridControl2.DataSource = table;
                    gridControl2.DataSource = _oldTable;
                    gridControl2.ForceInitialize();
                };
                frm.ShowDialog();
@@ -650,7 +613,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)
@@ -660,6 +623,73 @@
            }
        }
        #endregion
        /// <summary>
        /// 删除复制项
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void repositoryItemButtonEdit3_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            gridView2.CloseEditor();
            gridView2.UpdateCurrentRow();
            var rowhandle = gridView2.FocusedRowHandle;
            if (rowhandle < 0)
                return;
            if (e.Button.Index == 0)
            {
                var dr = gridView2.GetDataRow(rowhandle);
                if (!MsgHelper.AskQuestion("你选择了1条数据,确定删除吗?"))
                    return;
                gridView2.DeleteRow(rowhandle);
                return;
            }
        }
        /// <summary>
        /// 提交物料复制
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <exception cref="NotImplementedException"></exception>
        private void BtnSave_Click(object sender, EventArgs e)
        {
            int _rows = gridView2.RowCount;
            if (_rows <= 0)
            {
                MsgHelper.ShowInformation("请选择你需要复制的物料!");
                return;
            }
            if (!MsgHelper.AskQuestion("你选择了" + _rows.ToString() + "条数据,确定保存吗?"))
                return;
            System.Text.StringBuilder _sbGuids = new System.Text.StringBuilder();
            for (var i = 0; i < gridView2.DataRowCount; i++)
            {
                var row = gridView2.GetDataRow(i);
                if (_sbGuids.Length > 0)
                    _sbGuids.Append(",");
                Guid? _guid = UtilityHelper.ToGuid(row["guid"].ToString());
                _sbGuids.Append(_guid.ToString());
            }
            var _obj = new
            {
                sourceGuid = UtilityHelper.ToGuid(lbGuid.Text.Trim()),
                itemGuids = _sbGuids.ToString()
            };
            try
            {
                var strJson = UtilityHelper.HttpPost("", _webServiceName + "ItemsComyMx", JsonConvert.SerializeObject(_obj));
                var _rtn = UtilityHelper.ReturnToDynamic(strJson);
                MsgHelper.Warning("提示:" + _rtn.rtnMsg);
                if (_rtn.rtnCode > 0)
                {
                    UtilityHelper.SetDefaultTable(gridControl2, gridView2);
                }
            }
            catch (Exception ex)
            {
                MsgHelper.Warning("提示:" + ex.Message);
            }
        }
    }
}