yusijie
2025-02-12 d19fcd70a3b11339eb0c50b5c734eeca855a9a95
WebAPI/Controllers/SCGL/Èռƻ®¹ÜÀí/Sc_WorkBillSortBillController.cs
@@ -1,4 +1,5 @@
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
@@ -11,12 +12,13 @@
{
    public class Sc_WorkBillSortBillController : ApiController
    {
        private json objJsonResult = new json();
        private json objJsonResult = new json();
        public DataSet ds = new DataSet();
        public WebServer webserver = new WebServer();
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
        Sc_WorkBillSortBillMain omdelMian = new Sc_WorkBillSortBillMain();
        List<Sc_WorkBillSortBillSub> omodelsub = new List<Sc_WorkBillSortBillSub>();
        Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
        #region æ—¥è®¡åˆ’工单 åˆ—表
        [Route("Sc_WorkBillSortBill/Sc_WorkBillSortBillList")]
@@ -25,6 +27,7 @@
        {
            try
            {
                List<object> columnNameList = new List<object>();
                //查看权限
                if (!DBUtility.ClsPub.Security_Log("Sc_WorkBillSortBill_Query", 1, false, user))
                {
@@ -35,12 +38,21 @@
                    return objJsonResult;
                }
                ds = oCN.RunProcReturn("select * from  h_v_JIT_Sc_WorkBillSortBillList where 1=1" + sWhere + "order by hmainid desc ", "h_v_JIT_Sc_WorkBillSortBillList");
                ds = oCN.RunProcReturn("select * from  h_v_JIT_Sc_WorkBillSortBillList_Left where 1=1" + sWhere + " order by å•据号 desc ", "h_v_JIT_Sc_WorkBillSortBillList");
                    foreach (DataColumn col in ds.Tables[0].Columns)//遍历ds中第一个表(Tables[0])的所有列(Columns)每次循环中,col变量会持有当前列的引用
                    {
                        Type dataType = col.DataType; //获取当前数据类型传入 è‡ªå®šä¹‰å˜é‡datadataType
                        string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}"; //字符串拼接         // å°†åˆ—名和数据类型信息拼接成一个JSON格式的字符串
                        columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                objJsonResult.data = ds.Tables[0];//代码将第一个DataTable(索引为0)赋值给objJsonResult的data属性
                objJsonResult.list = columnNameList;//将columnNameList赋值给objJsonResult的list属性
                return objJsonResult;
            }
            catch (Exception e)
@@ -87,12 +99,11 @@
            string msg2 = sArray[0].ToString();
            string msg3 = sArray[1].ToString();
            int hentryid = int.Parse(sArray[2].ToString());//子表的顺序id
            int OperationType = int.Parse(sArray[3].ToString());//数据类型 1添加 3修改
            string user = sArray[4].ToString();
            int OperationType = int.Parse(sArray[2].ToString());//数据类型 1添加 3修改
            string user = sArray[3].ToString();
            try
            {
                if (!DBUtility.ClsPub.Security_Log("JIT_ComplementGoodBill_Edit", 1, false, user))
                if (!DBUtility.ClsPub.Security_Log("Sc_WorkBillSortBill_Edit", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
@@ -103,7 +114,11 @@
                omdelMian = Newtonsoft.Json.JsonConvert.DeserializeObject<Sc_WorkBillSortBillMain>(msg2);
                string BillType = "4610";
                ds = ds = oCN.RunProcReturn($"select * from  h_v_JIT_Sc_WorkBillSortBillList where hmainid={omdelMian.HInterID} and  å•据号='{omdelMian.HBillNo}'", "h_v_JIT_Sc_WorkBillSortBillList");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    OperationType = 3;
                }
                if (OperationType == 1)//新增
                {
@@ -137,6 +152,18 @@
                }
                else if (OperationType == 3)
                {
                    ds = oCN.RunProcReturn($"select * from  Sc_WorkBillSortBillMain where HMainSourceInterID={omdelMian.HMainSourceInterID}" +
                      $" and HMainSourceEntryID={omdelMian.HMainSourceEntryID} and HICMOBillNo='{omdelMian.HICMOBillNo}' and HICMOEntrySEQ={omdelMian.HICMOEntrySEQ} and HSourceID={omdelMian.HSourceID}", "Sc_WorkBillSortBillMain");
                    if ((ds.Tables[0].Rows.Count == 1 && ds.Tables[0].Rows[0]["HInterID"].ToString() != omdelMian.HInterID.ToString()))
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "生产资源有重复,请修改!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    //修改
                    oCN.RunProc($"update Sc_WorkBillSortBillMain set HDate='{omdelMian.HDate}',HUpDater='{omdelMian.HMaker}',HUpDateDate=GETDATE()" +
                                  $", HRemark='{omdelMian.HRemark}', HPrintQty={(omdelMian.HPrintQty == null ? 0 : omdelMian.HPrintQty)}" +
@@ -168,7 +195,7 @@
                                  $", HHangUp='{(omdelMian.HHangUp == true ? 1 : 0)}' where HInterID={omdelMian.HInterID}");
                }
                //保存子表
                objJsonResult = AddBillSub(msg3, hentryid);
                objJsonResult = AddBillSub(msg3);
                if (objJsonResult.code == "0")
                {
                    objJsonResult.code = "0";
@@ -194,24 +221,21 @@
            }
        }
        public json AddBillSub(string msg3, int hentryid)
        public json AddBillSub(string msg3)
        {
            //获取表格数据
            ds = oCN.RunProcReturn($"select * from  h_v_JIT_Sc_WorkBillSortBillList where å•据号='{omdelMian.HBillNo}'", "h_v_JIT_Sc_WorkBillSortBillList");
            //删除子表
            oCN.RunProc("delete from Sc_WorkBillSortBillSub where HInterID='" + omdelMian.HInterID.ToString() + "' and HEntryID='" + hentryid + "'");
            oCN.RunProc("delete from Sc_WorkBillSortBillSub where HInterID='" + omdelMian.HInterID.ToString() + "'");
            omodelsub = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Sc_WorkBillSortBillSub>>(msg3);
            int i = 1;
            //插入子表
            foreach (Models.Sc_WorkBillSortBillSub oSub in omodelsub)
            {
                oCN.RunProc("insert into Sc_WorkBillSortBillSub(HInterID,HEntryID,HRemark,HMasterDate,HQty" +
                oCN.RunProc("insert into Sc_WorkBillSortBillSub(HInterID,HSEQ,HRemark,HMasterDate,HQty" +
                            ", HRptFinishQty, HTimes, HUseTimes, HBTimes, HETimes" +
                            ", HDateSub, HCloseMan, HEntryCloseDate, HCloseTypeSub, HColumn" +
                            ", HLockedSub, HComplete, HStatusTag, HIsHandModify)" +
                            $"values({omdelMian.HInterID}, {(hentryid == -1 ? i : omodelsub.Count==1? hentryid:i==1? hentryid:(i+ds.Tables[0].Rows.Count-1))}, '{oSub.HRemark}', '{oSub.HMasterDate}', {(oSub.HQty == null ? 0: oSub.HQty)}" +
                            $"values({omdelMian.HInterID}, {i}, '{oSub.HRemark}', '{oSub.HMasterDate}', {(oSub.HQty == null ? 0: oSub.HQty)}" +
                            $", {(oSub.HRptFinishQty == null ? 0: oSub.HRptFinishQty)}, {(oSub.HTimes == null ? 0: oSub.HTimes)}, {(oSub.HUseTimes == null ? 0: oSub.HUseTimes)}, '{oSub.HBTimes}', '{oSub.HETimes}'" +
                            $", '{oSub.HDateSub}', '{oSub.HCloseMan}', '{oSub.HEntryCloseDate}', {(oSub.HCloseTypeSub == true ? 1 : 0)}, '{oSub.HColumn}'" +
                            $", '{(oSub.HLockedSub == true ? 1 : 0)}', '{oSub.HComplete}', '{(oSub.HStatusTag == true ? 1 : 0)}', '{(oSub.HIsHandModify == true ? 1 : 0)}')");
@@ -230,7 +254,7 @@
        #region æ—¥è®¡åˆ’工单 åˆ é™¤
        [Route("Sc_WorkBillSortBill/DelWorkBillSortBillList")]
        [HttpGet]
        public object DelWorkBillSortBillList(string HInterID, string HEntryID, string User)
        public object DelWorkBillSortBillList(string HInterID,int DataType, string User)
        {
            try
            {
@@ -243,30 +267,88 @@
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                ds = oCN.RunProcReturn("select * from h_v_JIT_Sc_WorkBillSortBillList where 1=1 and hmainid=" + HInterID, "h_v_JIT_Sc_WorkBillSortBillList");
                if (ds.Tables[0].Rows.Count > 0)
                //DataType 1=日计划工单 å¤šé€‰åˆ é™¤   2=日计划平台多选删除
                if (DataType == 1)
                {
                    if (ds.Tables[0].Rows[0]["单据状态"].ToString() != "1")
                    var NumData = HInterID.Split(',');
                    for (int i = 0; i < NumData.Length; i++)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "当前单据不能删除!";
                        objJsonResult.data = null;
                        return objJsonResult;
                        var NumData_T = NumData[i].Split('_');
                        ds = oCN.RunProcReturn("select * from h_v_JIT_Sc_WorkBillSortBillList_Left where 1=1 and hmainid=" + NumData_T[0], "h_v_JIT_Sc_WorkBillSortBillList");
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            if (ds.Tables[0].Rows[0]["单据状态"].ToString() != "1")
                            {
                                objJsonResult.code = "0";
                                objJsonResult.count = 0;
                                objJsonResult.Message = "当前单据不能删除!";
                                objJsonResult.data = null;
                                return objJsonResult;
                            }
                            oCN.BeginTran();//开启事务
                            if (ds.Tables[0].Rows.Count == 1)
                            {
                                oCN.RunProc($"delete from Sc_WorkBillSortBillMain where HInterID={ NumData_T[0]}");
                            }
                            oCN.RunProc($"delete from Sc_WorkBillSortBillSub where HInterID={ NumData_T[0]} and HEntryID={ NumData_T[1]}");
                            oCN.Commit();//结束事务
                        }
                    }
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除成功!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else if (DataType == 2)
                {
                    var NumData = HInterID.Split(',');
                    oCN.BeginTran();//开启事务
                    //获取系统参数
                    string sReturn = "";
                    oSystemParameter.ShowBill(ref sReturn);
                    if (ds.Tables[0].Rows.Count == 1)
                    for (int i = 0; i < NumData.Length; i++)
                    {
                        oCN.RunProc($"delete from Sc_WorkBillSortBillMain where HInterID={HInterID}");
                        if (oSystemParameter.omodel.WMS_CampanyName == "添康科技")
                        {
                            oCN.BeginTran();//开启事务
                            oCN.RunProc($"delete from Sc_WorkBillSortBillSub where HInterID={ NumData[i]}");
                            oCN.RunProc($"delete from Sc_WorkBillSortBillMain where HInterID={ NumData[i]}");
                            oCN.Commit();//结束事务
                        }
                        else
                        {
                            ds = oCN.RunProcReturn("select * from h_v_JIT_Sc_WorkBillSortBillList where 1=1 and hmainid=" + NumData[i], "h_v_JIT_Sc_WorkBillSortBillList");
                            if (ds.Tables[0].Rows.Count > 0)
                            {
                                if (ds.Tables[0].Rows[0]["单据状态"].ToString() != "1")
                                {
                                    objJsonResult.code = "0";
                                    objJsonResult.count = 0;
                                    objJsonResult.Message = "当前单据不能删除!";
                                    objJsonResult.data = null;
                                    return objJsonResult;
                                }
                                oCN.BeginTran();//开启事务
                                oCN.RunProc($"delete from Sc_WorkBillSortBillSub where HInterID={ NumData[i]}");
                                oCN.RunProc($"delete from Sc_WorkBillSortBillMain where HInterID={ NumData[i]}");
                                oCN.Commit();//结束事务
                            }
                        }
                    }
                    oCN.RunProc($"delete from Sc_WorkBillSortBillSub where HInterID={HInterID} and HEntryID={HEntryID}");
                    oCN.Commit();//结束事务
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "删除成功!";
@@ -313,11 +395,11 @@
                if (ds.Tables[0].Rows.Count > 0)
                {
                    if (ds.Tables[0].Rows[0]["单据状态"].ToString() == "2")
                    if (ds.Tables[0].Rows[0]["单据状态"].ToString() == "3")
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "当前单据正在审核,不能关闭!";
                        objJsonResult.Message = "当前单据已关闭!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
@@ -352,5 +434,66 @@
            }
        }
        #endregion
        #region æ—¥è®¡åˆ’工单 åå…³é—­
        [Route("Sc_WorkBillSortBill/CancelCloseBillWorkBillSortBillList")]
        [HttpGet]
        public object CancelCloseBillWorkBillSortBillList(string HInterID, string User)
        {
            try
            {
                //关闭权限
                if (!DBUtility.ClsPub.Security_Log_second("Sc_WorkBillSortBill_Close", 1, false, User))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无权限关闭!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                ds = oCN.RunProcReturn("select * from h_v_JIT_Sc_WorkBillSortBillList where 1=1 and hmainid=" + HInterID, "h_v_JIT_Sc_WorkBillSortBillList");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    if (ds.Tables[0].Rows[0]["单据状态"].ToString() != "3")
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "当前单据没有处于关闭状态!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                    oCN.BeginTran();//开启事务
                    string HBillStatus = ds.Tables[0].Rows[0]["审核人"].ToString() == "" ? "1" : "2";
                    oCN.RunProc("update Sc_WorkBillSortBillMain set HBillStatus='" + HBillStatus + "',HCloseMan='',HCloseDate=null   where HInterID=" + HInterID + "");
                    oCN.Commit();//结束事务
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "关闭成功!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "当前单据不存在,无法关闭!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                oCN.RollBack();//回滚事务
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
    }
}