1
wtt
9 天以前 1a5256ee25e90967f9058061906643ab4142c434
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;
                }
@@ -893,6 +900,37 @@
                                            加工车间代码 HDeptNumber,加工车间 HDeptName,出站报废关联数量 HRelationQty_OutBad,SN过站控制 HSNCtrl,HRoutingInterID HRoutingBillMainID,HRoutingEntryID HRoutingBillEntryID
                                            from h_v_Sc_ProcessExchangeBillQuerySub");
                ds = oCN.RunProcReturn(sql+ " where hmainid="+ HInterID + "  order by cast(流水号 as int) ", "h_v_Sc_ProcessExchangeBillQuerySub");
                objJsonResult.code = "0";
                objJsonResult.count = 1;
                objJsonResult.Message = "[0000-1-037]获取信息成功!";
                objJsonResult.data = ds.Tables[0];
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "[0000-1-045]没有返回任何记录!" + e.ToString();
                objJsonResult.data = null;
            }
            return objJsonResult;
        }
        // 工序流转卡返工信息
        [Route("Sc_ProcessExchangeBill/GetProcessExchangeBillSub_Back")]
        [HttpGet]
        public object GetProcessExchangeBillSub_Back(string HInterID)
        {
            DataSet ds;
            try
            {
                SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                string sql = string.Format(@"SELECT ISNULL(HSourceInterID, 0) AS HSourceInterID,ISNULL(HSourceEntryID, 0) AS HSourceEntryID,ISNULL(HSourceBillNo, '') AS HSourceBillNo,
                ISNULL(HSourceBillType, '') AS HSourceBillType,ISNULL(HProcExchInterID, 0) AS HProcExchInterID,ISNULL(HProcExchEntryID, 0) AS HProcExchEntryID,
                ISNULL(HProcExchBillNo, '') AS HProcExchBillNo,ISNULL(HICMOInterID, 0) AS HICMOInterID,ISNULL(HICMOEntryID, 0) AS HICMOEntryID,
                ISNULL(HICMOBillNo, '') AS HICMOBillNo,ISNULL(HStationOutInterID, 0) AS HStationOutInterID,ISNULL(HStationOutBillNo, '') AS HStationOutBillNo
                FROM Sc_ProcessExchangeBillSub_HRelationBack where HInterID=" + HInterID + "  order by HEntryID ");
                ds = oCN.RunProcReturn(sql, "Sc_ProcessExchangeBillSub_HRelationBack");
                objJsonResult.code = "0";
                objJsonResult.count = 1;
                objJsonResult.Message = "[0000-1-037]获取信息成功!";
@@ -2846,60 +2884,49 @@
        }
        #endregion
        #region  每日运行状态分析(做单情况)
        /// <summary>
        /// 返回设备点检任务
        ///参数:string sql。
        ///返回值:object。
        /// </summary>
        [Route("Sc_ProcessExchangeBill/DailyRunStateList")]
        #region[新增时获取表体数据(返工申请单)]
        [Route("Sc_ProcessExchangeBill/GetProcExchangeWorkBackList")]
        [HttpGet]
        public object DailyRunStateList(string sWhere, string user)
        public object GetProcExchangeWorkBackList(string HInterID)
        {
            DataSet ds;
            try
            {
                Dictionary<object, object> dic = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<object, object>>(sWhere);
                //拆分并过滤出有效数字ID
                var idList = HInterID.Split(',')  // 1. 按逗号分割字符串
                      .Select(s => s.Trim())  // 2. 去除每个元素的空格
                      .Where(s => int.TryParse(s, out _))  // 3. 只保留能转成数字的字符串
                      .ToList();  // 4. 转成List集合
                string HBeginDate = dic["HBeginDate"].ToString();
                string HEndDate = dic["HEndDate"].ToString();
                // 构建安全的 IN 子句
                string inClause = string.Join(",", idList);
                List<object> columnNameList = new List<object>();
                ds = oCN.RunProcReturn("exec h_p_Cs_ProcDailyRunStateReport  '" + HBeginDate + "','" + HEndDate + "'", "h_p_Cs_ProcDailyRunStateReport");
                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");
                if (ds.Tables[0].Rows.Count != 0 || ds != null)
                //添加列名
                foreach (DataColumn col in ds.Tables[0].Columns)
                {
                    //添加列名
                    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 = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "Sucess!";
                    objJsonResult.data = ds;
                    objJsonResult.list = columnNameList;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无数据";
                    objJsonResult.data = null;
                    return objJsonResult;
                    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 = "Exception!" + e.ToString();
                objJsonResult.Message = "[0000-1-038]没有返回任何记录!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }