WebAPI/Controllers/CJGL/Sc_ProcessExchangeBillController.cs
@@ -10,6 +10,7 @@
using System.Web.Http;
using System.Windows.Forms;
using WebAPI.Models;
using System.Linq;
namespace WebAPI.Controllers
{
@@ -51,6 +52,7 @@
            string msg4 = sArray[2].ToString();
            string msg5 = sArray[3].ToString();
            string HBillSubType = sArray[4].ToString();
            string msg6 = sArray.Length > 5 ? sArray[5] : ""; // 这里安全了
            string HComputerName = SystemInformation.ComputerName; //设备名称    
            string UserName = "";
@@ -90,7 +92,7 @@
                {
                    UserName = oItem.HMaker;  //制单人
                    oItem.HBillType = "3772";
                    oItem.HBillSubType = HBillSubType == "SUB" ? HBillSubType : "3772";
                    oItem.HBillSubType = HBillSubType == "SUB" ? HBillSubType : oItem.HBillSubType;
                    oItem.HYear = DBUtility.ClsPub.isLong(DateTime.Now.Year);
                    oItem.HPeriod = DBUtility.ClsPub.isLong(DateTime.Now.Month);
                    oItem.HDate = HBillSubType == "SUB" ? DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd")) : oItem.HDate;
@@ -123,59 +125,65 @@
                    oBill.DetailColl.Add(oItemSub);
                }
                //返工表体数据
                //按 },{来拆分数组 //去掉【和】
                List<Model.Sc_ProcessExchangeBillSub_HRelationBack> ls2 = new List<Model.Sc_ProcessExchangeBillSub_HRelationBack>();
                if (!string.IsNullOrEmpty(msg6))
                {
                    // 只有 msg6 不为空才走这里
                    msg6 = msg6.Substring(1, msg6.Length - 2);
                    msg6 = msg6.Replace("\\", "");
                    msg6 = msg6.Replace("\n", "");
                    // 这里必须传 msg6,不是 msg3!!!
                    ls2 = oListModels.getObjectByJson_Sc_ProcessExchangeBillSub_HRelationBack(msg6);
                }
                int i2 = 0;
                foreach (Model.Sc_ProcessExchangeBillSub_HRelationBack oItemSub2 in ls2)
                {
                    i2++;
                    oItemSub2.HEntryID = i2;
                    oItemSub2.HEntryCloseDate = DBUtility.ClsPub.isDate(DateTime.Now);
                    // 在这里直接给默认值!
                    // ======================
                    oItemSub2.HProcExchInterID = oItemSub2.HProcExchInterID > 0 ? oItemSub2.HProcExchInterID : 0;
                    oItemSub2.HProcExchEntryID = oItemSub2.HProcExchEntryID > 0 ? oItemSub2.HProcExchEntryID : 0;
                    oItemSub2.HProcExchBillNo = string.IsNullOrEmpty(oItemSub2.HProcExchBillNo) ? "" : oItemSub2.HProcExchBillNo;
                    oItemSub2.HICMOInterID = oItemSub2.HICMOInterID > 0 ? oItemSub2.HICMOInterID : 0;
                    oItemSub2.HICMOEntryID = oItemSub2.HICMOEntryID > 0 ? oItemSub2.HICMOEntryID : 0;
                    oItemSub2.HICMOBillNo = string.IsNullOrEmpty(oItemSub2.HICMOBillNo) ? "" : oItemSub2.HICMOBillNo;
                    oItemSub2.HStationOutInterID = oItemSub2.HStationOutInterID > 0 ? oItemSub2.HStationOutInterID : 0;
                    oItemSub2.HStationOutBillNo = string.IsNullOrEmpty(oItemSub2.HStationOutBillNo) ? "" : oItemSub2.HStationOutBillNo;
                    oBill.DetailColl2.Add(oItemSub2);
                }
                //保存
                //保存完毕后处理
                bool bResult;
                if (msg5 == "xz")
                {
                    LogService.Write("用户:" + msg4 + ",日期:" + DateTime.Now + ",新增工序流转卡单据:" + oBill.omodel.HBillNo);
                    // bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                    bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                    bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                    //测试语句===========================================================================================================
                    string msg_str = "";
                    string sql_str = "select a.HQty HQty_Main,b.HQty HQty_Sub " +
                                "from Sc_ProcessExchangeBillMain as a " +
                                "inner join Sc_ProcessExchangeBillSub as b on a.HInterID = b.HInterID " +
                                "where a.HInterID = " + oBill.omodel.HInterID;
                    DataSet ds_str = oCN.RunProcReturn(sql_str, "Sc_ProcessExchangeBillMain");
                    if (ds_str.Tables[0].Rows.Count > 0)
                    {
                        msg_str = "HQty_Main:" + ds_str.Tables[0].Rows[0]["HQty_Main"].ToString() + ";HQty_Sub:";
                        for (int j = 0; j < ds_str.Tables[0].Rows.Count; j++)
                        {
                            msg_str += ds_str.Tables[0].Rows[j]["HQty_Sub"].ToString() + ",";
                        }
                    }
                    //==============================================================================================================
                    oCN.RunProc("Insert into System_log (GeginDate, userid, WorkstationName, WorkList, SystemName, NetuserName, State) select GETDATE(),'" + msg4 + "','" + HComputerName + "','" + "新增工序流转卡单据:" + oBill.omodel.HBillNo + msg_str + "','LMES-工序流转卡模块','" + DBUtility.ClsPub.IPAddress + "','新增单据'", ref DBUtility.ClsPub.sExeReturnInfo);
                    oCN.RunProc("Insert into System_log (GeginDate, userid, WorkstationName, WorkList, SystemName, NetuserName, State) select GETDATE(),'" + msg4 + "','" + HComputerName + "','" + "新增工序流转卡单据:" + oBill.omodel.HBillNo  + "','LMES-工序流转卡模块','" + DBUtility.ClsPub.IPAddress + "','新增单据'", ref DBUtility.ClsPub.sExeReturnInfo);
                }
                else
                {
                    LogService.Write("用户:" + msg4 + ",日期:" + DateTime.Now + ",修改工序流转卡单据:" + oBill.omodel.HBillNo);
                    bResult = oBill.ModifyBill(oBill.omodel.HInterID, ref DBUtility.ClsPub.sExeReturnInfo);
                    //测试语句===========================================================================================================
                    string msg_str = "";
                    string sql_str = "select a.HQty HQty_Main,b.HQty HQty_Sub " +
                                "from Sc_ProcessExchangeBillMain as a " +
                                "inner join Sc_ProcessExchangeBillSub as b on a.HInterID = b.HInterID " +
                                "where a.HInterID = " + oBill.omodel.HInterID;
                    DataSet ds_str = oCN.RunProcReturn(sql_str, "Sc_ProcessExchangeBillMain");
                    if (ds_str.Tables[0].Rows.Count > 0)
                    {
                        msg_str = "HQty_Main:" + ds_str.Tables[0].Rows[0]["HQty_Main"].ToString() + ";HQty_Sub:";
                        for (int j = 0; j < ds_str.Tables[0].Rows.Count; j++)
                        {
                            msg_str += ds_str.Tables[0].Rows[j]["HQty_Sub"].ToString() + ",";
                        }
                    }
                    //==============================================================================================================
                    oCN.RunProc("Insert into System_log (GeginDate, userid, WorkstationName, WorkList, SystemName, NetuserName, State) select GETDATE(),'" + msg4 + "','" + HComputerName + "','" + "修改工序流转卡单据:" + oBill.omodel.HBillNo + msg_str + "','LMES-工序流转卡模块','" + DBUtility.ClsPub.IPAddress + "','修改单据'", ref DBUtility.ClsPub.sExeReturnInfo);
                    oCN.RunProc("Insert into System_log (GeginDate, userid, WorkstationName, WorkList, SystemName, NetuserName, State) select GETDATE(),'" + msg4 + "','" + HComputerName + "','" + "修改工序流转卡单据:" + oBill.omodel.HBillNo + "','LMES-工序流转卡模块','" + DBUtility.ClsPub.IPAddress + "','修改单据'", ref DBUtility.ClsPub.sExeReturnInfo);
                }
                if (bResult)
                {
@@ -207,7 +215,6 @@
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "[0000-1-050]保存成功!";
                    //WebAPIController.Add_Log("送货单下推", UserName, "生成送货单");
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
@@ -2846,5 +2853,54 @@
        }
        #endregion
        #region[新增时获取表体数据(返工申请单)]
        [Route("Sc_ProcessExchangeBill/GetProcExchangeWorkBackList")]
        [HttpGet]
        public object GetProcExchangeWorkBackList(string HInterID)
        {
            DataSet ds;
            try
            {
                //拆分并过滤出有效数字ID
                var idList = HInterID.Split(',')  // 1. 按逗号分割字符串
                      .Select(s => s.Trim())  // 2. 去除每个元素的空格
                      .Where(s => int.TryParse(s, out _))  // 3. 只保留能转成数字的字符串
                      .ToList();  // 4. 转成List集合
                // 构建安全的 IN 子句
                string inClause = string.Join(",", idList);
                List<object> columnNameList = new List<object>();
                SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                ds = oCN.RunProcReturn("select * from h_v_Sc_ProcExchWorkBackBillList_Query where 1=1 and hmainid in (" + inClause + ")", "h_v_Sc_ProcExchWorkBackBillList_Query");
                //添加列名
                foreach (DataColumn col in ds.Tables[0].Columns)
                {
                    Type dataType = col.DataType;
                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
                    columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                }
                objJsonResult.code = "0";
                objJsonResult.count = 1;
                objJsonResult.list = columnNameList;
                objJsonResult.Message = "[0000-1-037]获取信息成功!";
                objJsonResult.data = ds.Tables[0];
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "[0000-1-038]没有返回任何记录!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
    }
}