lu
2024-12-07 c733a40f757501b3b1c95fec58e009e9703786ec
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,15 +30,16 @@
            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.SetGridSear(gridView1, picCheckBox, this, "foneChecked", "");
            Gs.DevApp.ToolBox.UtilityHelper.SetGridSearMx(gvMx1);
            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);
@@ -102,39 +102,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 +112,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 +131,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>
@@ -237,6 +171,7 @@
                return;
            }
            getModel(rowGuid, true, 1);
        }
        /// <summary>
@@ -254,6 +189,7 @@
            UtilityHelper.CleanValueByControl(panel1.Controls, true,
                gridViews);
            UtilityHelper.SetDefaultTable(gcMx1, gvMx1);
            xtraTabPageCopy.PageEnabled = false;
        }
        /// <summary>
@@ -264,8 +200,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 +230,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 +270,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());
@@ -383,8 +316,8 @@
                MsgHelper.Warning("请先选择你要操作的行!");
                return;
            }
            UtilityHelper.JumpToTab(xtraTabControl1, tabIdx);
            xtraTabPageCopy.PageEnabled = !isEdit;
            var _obj = new
            {
                guid = strGuid //主建
@@ -423,6 +356,8 @@
                        UtilityHelper.SetDefaultTable(gcMx1,
                            gvMx1);
                    }
                    UtilityHelper.SetDefaultTable(gridControl2,
                         gridView2);
                }
                else
                {
@@ -435,36 +370,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(), false, 999);
                    else
                        getPageList(1);
                }
            }
            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) =>
@@ -477,11 +441,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();
@@ -659,6 +629,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);
            }
        }
    }
}