cdk
2025-11-01 cbb5315301b1490b57497212256c5255e5eb7eb6
DevApp/Gs.DevApp/DevFrm/Ck/Frm_MesItemQt.cs
@@ -7,6 +7,7 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Threading.Tasks;
using System.Windows.Forms;
@@ -20,6 +21,7 @@
        string _ucBm = "";//领料部门
        string _ucHzlx = "";//货主类型
        string _ucHz = "";//货主
        string _ucGys = "";//供应商
        public Frm_MesItemQt()
        {
            InitializeComponent();
@@ -39,6 +41,8 @@
            toolBarMenu1.btnCaiGouFchkClick += ToolBarMenu1_btnCaiGouFchkClick;
            toolBarMenu1.btnCaiWuChkClick += ToolBarMenu1_btnCaiWuChkClick;
            toolBarMenu1.btnCaiWuFchkClick += ToolBarMenu1_btnCaiWuFchkClick;
            toolBarMenu1.btnPrintClick += ToolBarMenu1_btnPrintClick;
            toolBarMenu1.btnWjClick += ToolBarMenu1_btnWjClick;
            this.toolBarMenu1.getXmlConfig();
            Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameterMx(gvMx1);
            Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameter(gridView1, picCheckBox, this, "isChk", "", (value) =>
@@ -63,45 +67,205 @@
                ucLookHuoZhu1.OrgId = _orgId;
                ucLookHuoZhu1.HzId = _ucHz;
                ucLookHuoZhu1.SetHzLx(_ucHzlx);
                System.Text.StringBuilder sbWhere = new System.Text.StringBuilder();
                sbWhere.Append(" and a.FSubsidiary ='" + _orgId + "'");
                var _obj = new PageQueryModel(1, 999999, "item_no", "asc", "", sbWhere.ToString(), "");
                var json = JsonConvert.SerializeObject(_obj);
                try
                {
                    var strReturn = UtilityHelper.HttpPost("", "MesItemsManager/GetListSelect", json);
                    var rtn = UtilityHelper.ReturnToTablePage(strReturn);
                    var dt = rtn.rtnData.list;
                    this.repositoryItemSearchLookUpEdit1.DataSource = dt;
                }
                catch (Exception ex)
                {
                    MsgHelper.ShowError("提示:" + ex.Message);
                }
            };
            //选择领用组织
            txt_qt024.EditChanged += (s, e) =>
            {
                string _orgId = txt_qt024.GetId();
                if (string.IsNullOrEmpty(_orgId))
                    return;
                ucLookHuoZhu1.SetHzId(_ucHz);
                _bindLookSearch(txt_qt035.Text.Trim(), "","");
                txt_qt013.getSuppler(_orgId, _ucKh);
                txt_qt009.getSuppler(_orgId, _ucBm);
                txt_qt009.getSuppler(_orgId, _ucBm, " len(a.departmentcode)>2 ");
                txt_wwgys.getSuppler(_orgId, _ucGys);
            };
            //选择领用组织2025年-10-24已被禁用,为考虑性能,删除
            //txt_qt024.EditChanged += (s, e) =>
            //{
            //    string _orgId = txt_qt024.GetId();
            //    if (string.IsNullOrEmpty(_orgId))
            //        return;
            //    txt_qt013.getSuppler(_orgId, _ucKh);
            //    txt_qt009.getSuppler(_orgId, _ucBm);
            //    txt_wwgys.getSuppler(_orgId, _ucGys);
            //};
            //选择来源单号
            txt_qt035.ButtonClick += (s, e) =>
            {
                string strSrmNo = "";
                SelectDaa frm = new SelectDaa();
                string _orgId = txt_qt023.GetId();
                SelectDaa frm = new SelectDaa(_orgId);
                frm.UpdateParent += (ss, ee) =>
                {
                    var lst = new List<dynamic>();
                    lst = ee.DynamicList;
                    strSrmNo = lst[0].guid;
                    string strSrmNo = lst[0].guid;
                    string strGdlx = lst[0].gdlx;
                    string strGdlxWlid = lst[0].gdlxWlid;
                    txt_qt035.Text = strSrmNo;
                    _bindLookSearch(txt_qt035.Text.Trim(), strGdlx, strGdlxWlid);
                    #region 选择工单后带出下面的物料 2025-09-27
                    //try
                    //{
                    //    var _obj = new
                    //    {
                    //        strDaaNo = strSrmNo,//主建
                    //    };
                    //    var strReturn = UtilityHelper.HttpPost("",
                    //        "WomdaaManager/SelectDaaMx",
                    //        JsonConvert.SerializeObject(_obj));
                    //    var dt = UtilityHelper.ReturnToList(strReturn);
                    //    DataTable _newTable = dt.rtnData;
                    //    DataTable _oldTable = (DataTable)gcMx1.DataSource;
                    //    foreach (DataRow dddddd in _newTable.Rows)
                    //    {
                    //        DataRow _row = _oldTable.NewRow();
                    //        _row["qd002"] = dddddd["itemNo"].ToString();
                    //        _row["qd003"] = dddddd["itemName"].ToString();
                    //        _row["qd004"] = dddddd["itemModel"].ToString();
                    //        _row["qd009dw"] = dddddd["dwName"].ToString();
                    //        _row["itemId"] = dddddd["itemId"].ToString();
                    //        _row["depotName"] = dddddd["depotName"].ToString();
                    //        _row["depotId"] = dddddd["depotId"].ToString();
                    //        _row["kcQty"] = dddddd["kcQty"].ToString();
                    //        _oldTable.Rows.Add(_row);
                    //    }
                    //    gcMx1.BindingContext = new BindingContext();
                    //    gcMx1.DataSource = _oldTable;
                    //    gcMx1.ForceInitialize();
                    //    gvMx1.BestFitColumns();
                    //    Gs.DevApp.ToolBox.UtilityHelper.SetGridLayout(gvMx1);
                    //}
                    //catch (Exception ex)
                    //{
                    //    MessageBox.Show(ex.Message);
                    //}
                    #endregion
                };
                frm.ShowDialog();
            };
            #region 2025-08-27 复制beg
            btnCopyXls.Click += (s, e) =>
            {
                string kcZz = txt_qt023.GetId();
                if (string.IsNullOrEmpty(kcZz))
                {
                    Gs.DevApp.ToolBox.MsgHelper.ShowError("请先选择库存组织后才能使用复制功能!");
                    txt_qt023.Focus();
                    return;
                }
                string filePath = AppContext.BaseDirectory + "xlsCopy.xls";
                if (File.Exists(filePath))
                {
                    var frm = new CopyXls(kcZz, lbGuid.Text.Trim(), OrderType.其它出库.ToString());
                    frm.UpdateParent += (ss, ee) =>
                    {
                        try
                        {
                            var lst = ee.DynamicList;
                            DataTable _Table = (DataTable)gcMx1.DataSource;
                            foreach (dynamic dym in lst)
                            {
                                DataRow _row = _Table.NewRow();
                                _row["qd002"] = dym.itemNo;
                                _row["qd003"] = dym.itemName;
                                _row["qd004"] = dym.itemModel;
                                _row["qd009dw"] = dym.dwName;
                                _row["itemId"] = dym.itemId;
                                _row["qd007"] = dym.sl;
                                _row["qd010"] = dym.bz;
                                //默认仓库和仓库数量
                                _row["depotName"] = dym.depotName;
                                _row["depotId"] = dym.depotId;
                                _row["kcQty"] = dym.kcQty;
                                _Table.Rows.Add(_row);
                            }
                            gcMx1.BindingContext = new BindingContext();
                            gcMx1.DataSource = _Table;
                            gcMx1.ForceInitialize();
                            gvMx1.CloseEditor();
                            gvMx1.PostEditor();
                            gvMx1.UpdateCurrentRow();
                            gvMx1.BestFitColumns();
                        }
                        catch (Exception ex)
                        {
                            Gs.DevApp.ToolBox.MsgHelper.ShowError(ex.Message);
                        }
                    };
                    frm.ShowDialog();
                }
                else
                {
                    Gs.DevApp.ToolBox.MsgHelper.ShowError("找不到xlsCopy.xls文件,请联系管理员!");
                }
            };
            #endregion
            #region 2025-08-27 增加委外供应商
            txt_qtlx.SelectedIndexChanged += (s, e) =>
            {
                int idx = txt_qtlx.SelectedIndex;
                if (idx == 7)
                {
                    layItemWwgys.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
                }
                else
                {
                    layItemWwgys.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
                    txt_wwgys.SetIdOrCode("");
                }
            };
            #endregion
        }
        /// <summary>
        /// 来源明细限制,
        /// </summary>
        /// <param name="strGdlx">工单类型,如果是维修,根据物料找</param>
        private void _bindLookSearch(string daaNo,  string strGdlx,string gdlxWlid)
        {
            System.Text.StringBuilder sbWhere = new System.Text.StringBuilder();
            sbWhere.Append(" and a.FSubsidiary ='" + txt_qt023.GetId() + "'");
            if (daaNo.Trim().Length > 0)
            {
                if (strGdlx == "W-维修返工" || strGdlx == "C-拆机返工")
                {
                    sbWhere.Append("  and a.item_id in (");
                    sbWhere.Append("  select  dab.dab003  from WOMDAA daa left join WOMDAB dab on daa.guid=dab.daaGuid   ");
                    sbWhere.Append("   where  daa.guid=( select top 1  ddddd.guid as dddddGuid from WOMDAA ddddd where  ddddd.daa002='"+ gdlxWlid + "' and  ddddd.daa025 in('F-量产','S-试产') order by ddddd.daa001 desc )");
                    sbWhere.Append(" )");
                }
                else {
                    sbWhere.Append("  and a.item_id in (");
                    sbWhere.Append("  select dab.dab003 from WOMDAB dab where dab.dab001 = '" + txt_qt035.Text.Trim() + "'");
                    sbWhere.Append(" )");
                }
            }
            var _obj = new PageQueryModel(1, 999999, "item_no", "asc", "", sbWhere.ToString(), "");
            var json = JsonConvert.SerializeObject(_obj);
            try
            {
                var strReturn = UtilityHelper.HttpPost("", "MesItemsManager/GetListSelect", json);
                var rtn = UtilityHelper.ReturnToTablePage(strReturn);
                DataTable dt = rtn.rtnData.list;
                //如果没有,再读一遍
                if (dt == null || dt.Rows.Count <= 1)
                {
                    _bindLookSearch("","", "");
                }
                else
                {
                    this.gridView2.IndicatorWidth = 60;
                    this.gridView2.CustomDrawRowIndicator += (ss, ee) =>
                    {
                        if (ee.Info.IsRowIndicator && ee.RowHandle >= 0)
                            ee.Info.DisplayText = (ee.RowHandle + 1).ToString();
                    };
                    this.repositoryItemSearchLookUpEdit1.DataSource = dt;
                    // repositoryItemSearchLookUpEdit1.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup;
                    //repositoryItemSearchLookUpEdit1.PopupFormSize = new System.Drawing.Size(500, 300);
                }
            }
            catch (Exception ex)
            {
                MsgHelper.ShowError("提示:" + ex.Message);
            }
        }
        private void GridView1_ColumnFilterChanged(object sender, EventArgs e)
@@ -262,7 +426,7 @@
            }
            //2025/07/12加上修改状态下不能修改
            txt_qt023.IsReadly = true;
            txt_qt024.IsReadly = true;
            //txt_qt024.IsReadly = true;
            ucLookHuoZhu1.Enabled = false;
        }
        /// <summary>
@@ -281,7 +445,7 @@
            ucLookHuoZhu1.Enabled = true;
            //增加时,默认组织
            string deftOrg = UtilityHelper.GetFirstOrg(txt_qt023);
            string deftOrg2 = UtilityHelper.GetFirstOrg(txt_qt024);
            //string deftOrg2 = UtilityHelper.GetFirstOrg(txt_qt024);
        }
        /// <summary>
        /// 保存事件
@@ -296,11 +460,13 @@
            string inHz = ucLookHuoZhu1.GetHzId();//货主
            string inRkyy = txt_qt010.Text.Trim();//原因
            string inDjlx = txt_qt019.Text.Trim();//单据类型
            string inLyOrg = txt_qt024.GetId();//领用组织
           // string inLyOrg = txt_qt024.GetId();//领用组织
            string inLyOrg = inOrgId;//领用组织等于库存组织
            string inLyCus = txt_qt013.GetId();//领用客户
            string inLyDepart = txt_qt009.GetId();//领用部门
            string inKcfx = txt_qt020.Text.Trim();//库存方向
            string qtlx = txt_qtlx.Text.Trim();//后来增加的类型
            string wwgys = txt_wwgys.GetId();
            if (string.IsNullOrEmpty(inOrgId))
            {
                Gs.DevApp.ToolBox.MsgHelper.ShowError("请选择库存组织!");
@@ -317,22 +483,45 @@
                Gs.DevApp.ToolBox.MsgHelper.ShowError("请选择货主!");
                return;
            }
            if (string.IsNullOrEmpty(inLyOrg))
            {
                Gs.DevApp.ToolBox.MsgHelper.ShowError("请选择领用组织!");
                txt_qt024.Focus();
                return;
            }
            //if (string.IsNullOrEmpty(inLyOrg))
            //{
            //    Gs.DevApp.ToolBox.MsgHelper.ShowError("请选择领用组织!");
            //    txt_qt024.Focus();
            //    return;
            //}
            if (txt_qtlx.SelectedIndex <= 0)
            {
                Gs.DevApp.ToolBox.MsgHelper.ShowError("请选择入库类型!");
                Gs.DevApp.ToolBox.MsgHelper.ShowError("请选择出库类型!");
                txt_qtlx.Focus();
                return;
            }
            if (string.IsNullOrEmpty(inLyCus) && string.IsNullOrEmpty(inLyDepart))
            //这是非委外的防呆
            if (txt_qtlx.SelectedIndex != 7)
            {
                Gs.DevApp.ToolBox.MsgHelper.ShowError("客户或部门必选一个!");
                return;
                if (string.IsNullOrEmpty(inLyCus) && string.IsNullOrEmpty(inLyDepart))
                {
                    Gs.DevApp.ToolBox.MsgHelper.ShowError("客户或部门必选一个!");
                    return;
                }
                if (!string.IsNullOrEmpty(wwgys))
                {
                    Gs.DevApp.ToolBox.MsgHelper.ShowError("出库类型不为【7:无源单委外退料】,请不要选择委外供应商!");
                    return;
                }
            }
            //这是委外的防呆
            if (txt_qtlx.SelectedIndex == 7)
            {
                if (string.IsNullOrEmpty(wwgys))
                {
                    Gs.DevApp.ToolBox.MsgHelper.ShowError("出库类型为【7:无源单委外退料】,请选择委外供应商!");
                    return;
                }
                if (!string.IsNullOrEmpty(inLyCus))
                {
                    Gs.DevApp.ToolBox.MsgHelper.ShowError("出库类型为【7:无源单委外退料】,不用选择客户!");
                    return;
                }
            }
            var _obj = new
            {
@@ -347,7 +536,8 @@
                inLyDepart = inLyDepart,//领用部门
                inKcfx = inKcfx,//库存方向
                inSource = txt_qt035.EditValue,//工单号
                qtlx=qtlx,
                qtlx = qtlx,
                wwgys = wwgys,
                list = new List<dynamic>(),
            };
            gvMx1.CloseEditor();
@@ -439,7 +629,8 @@
                    {
                        gcMain1.DataSource = dt;
                        gcMain1.ForceInitialize();
                        gridView1.BestFitColumns(); Gs.DevApp.ToolBox.UtilityHelper.SetGridLayout(gridView1);
                        gridView1.BestFitColumns();
                        Gs.DevApp.ToolBox.UtilityHelper.SetGridLayout(gridView1);
                    }
                    else
                        UtilityHelper.SetDefaultTable(gcMain1, gridView1);
@@ -489,6 +680,11 @@
                    _ucBm = dy.qt009;
                    _ucHzlx = dy.qt025;
                    _ucHz = dy.qt018;
                    _ucGys = dy.wwgys;//委外供应商
                                      // ucLookHuoZhu1.OrgId = _orgId;
                    ucLookHuoZhu1.HzId = _ucHz;
                    ucLookHuoZhu1.SetHzLx(_ucHzlx);
                    ucLookHuoZhu1.SetHzId(_ucHz);
                    lbGuid.Text = strGuid;
                    List<DevExpress.XtraGrid.Views.Grid.GridView> gvList = new List<DevExpress.XtraGrid.Views.Grid.GridView>();
                    gvList.Add(gvMx1);
@@ -497,6 +693,7 @@
                    _ucBm = "";
                    _ucHzlx = "";
                    _ucHz = "";
                    _ucGys = "";
                    ucLookHuoZhu1.Enabled = isEdit;
                    JObject _job = JObject.Parse(strJson);
                    JArray array = new JArray();
@@ -527,7 +724,16 @@
            }
        }
        /// <summary>
        /// 完结
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <exception cref="NotImplementedException"></exception>
        private void ToolBarMenu1_btnWjClick(object sender, EventArgs e)
        {
            _toolCk(2);
        }
        /// <summary>
        ///     审核事件
        /// </summary>
@@ -626,6 +832,9 @@
                case 0:
                    strMsg = "反审核";
                    break;
                case 2:
                    strMsg = "完结";
                    break;
                case 20:
                    strMsg = "售后审核";
                    break;
@@ -684,7 +893,6 @@
                        int rowHandle = gridView1.LocateByValue("guid", rowGuid);
                        gridView1.FocusedRowHandle = rowHandle;
                    }
                }
                else
                    MsgHelper.ShowError(_rtn.rtnData.outMsg.ToString());
@@ -701,12 +909,18 @@
            gvMx1.SetFocusedRowCellValue("qd002", SelectedDataRow["itemNo"]);
            gvMx1.SetFocusedRowCellValue("qd003", SelectedDataRow["itemName"]);
            gvMx1.SetFocusedRowCellValue("qd004", SelectedDataRow["itemModel"]);
            gvMx1.SetFocusedRowCellValue("qd009", SelectedDataRow["dwName"]);
            gvMx1.SetFocusedRowCellValue("qd009dw", SelectedDataRow["dwName"]);
            gvMx1.SetFocusedRowCellValue("itemId", SelectedDataRow["id"]);
            gvMx1.SetFocusedRowCellValue("depotName", SelectedDataRow["depotName"]);
            gvMx1.SetFocusedRowCellValue("depotId", SelectedDataRow["depotId"]);
            gvMx1.SetFocusedRowCellValue("kcQty", SelectedDataRow["kcQty"]);
            gvMx1.CloseEditor();
            gvMx1.PostEditor();
            gvMx1.UpdateCurrentRow();
            gvMx1.BestFitColumns();
            Gs.DevApp.ToolBox.UtilityHelper.SetGridLayout(gvMx1);
        }
        /// <summary>
        /// 删除明细
@@ -764,22 +978,53 @@
            var rowhandle = gvMx1.FocusedRowHandle;
            if (rowhandle < 0)
                return;
            var dr = gvMx1.GetDataRow(rowhandle);
            var strItemId = dr["itemId"].ToString();
            if (string.IsNullOrEmpty(strItemId))
            {
                MsgHelper.ShowError("提示:请先选择物料!");
                return;
            }
            var strOrgGuid = txt_qt023.GetId();
            if (string.IsNullOrEmpty(strOrgGuid))
            {
                MsgHelper.ShowError("提示:请先选择库存组织!");
                return;
            }
            ;
            SelectCk frm = new SelectCk(strOrgGuid);
            SelectCk frm = new SelectCk(strOrgGuid, strItemId);
            frm.UpdateParent += (ss, ee) =>
            {
                var lst = new List<dynamic>();
                lst = ee.DynamicList;
                gvMx1.SetFocusedRowCellValue("depotName", lst[0].name);
                gvMx1.SetFocusedRowCellValue("depotId", lst[0].guid);
                gvMx1.SetFocusedRowCellValue("kcQty", lst[0].kcQty);
                gvMx1.BestFitColumns();
            };
            frm.ShowDialog();
        }
        private void ToolBarMenu1_btnPrintClick(object sender, EventArgs e)
        {
            //guidKey, rptParameter
            string rowGuid, rowName;
            (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1,
                lbGuid, txt_qtck, gridView1, "qtck");
            if (string.IsNullOrEmpty(rowGuid))
            {
                MsgHelper.ShowError("请先选择你要操作的行!");
                return;
            }
            this.toolBarMenu1.rptParameter = "rpt_QTCK{"
                                               + ""
                                               + "," + ""
                                               + "," + ""
                                               + "," + ""
                                               + "," + ""
                                               + "}";
            this.toolBarMenu1.guidKey = rowGuid;
        }
    }
}