1
wtt
3 天以前 35626914ad4ec78ff71bef1c2d52a9d04ee67954
WebAPI/Controllers/CJGL/Cj_SingleStationController.cs
@@ -7,6 +7,7 @@
using System.Data;
using System.Data.SqlClient;
using System.Web.Http;
using WebAPI.Controllers.SCGL;
using WebAPI.Models;
namespace WebAPI.Controllers.CJGL
@@ -16,7 +17,7 @@
        private json objJsonResult = new json();
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
        Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
        DataSet ds;
        DataSet ds,ds2;
        #region 工序单品不良采集  用户查询关联字段
        [Route("Cj_SingleStation/Cj_CollectionOfSingleProductDefectsUserList")]
@@ -382,14 +383,21 @@
                        if (ds.Tables[0].Rows.Count == 0)
                        {
                            //判断当前流转卡是否墨西哥的
                            ds = oCN.RunProcReturn("select HPRDORGID from Sc_ProcessExchangeBillMain with(nolock) where HBillNo = '" + HBarCode + "' ", "Sc_ProcessExchangeBillMain");
                            if (ds.Tables[0].Rows[0]["HPRDORGID"].ToString() != "7667152")
                            ds2 = oCN.RunProcReturn("select HPRDORGID from Sc_ProcessExchangeBillMain with(nolock) where HBillNo = '" + HBarCode + "' ", "Sc_ProcessExchangeBillMain");
                            if (ds2.Tables[0].Rows[0]["HPRDORGID"].ToString() != "7667152")
                            {
                                objJsonResult.code = "0";
                                objJsonResult.count = 0;
                                objJsonResult.Message = "[3791-2-018]卡号:" + HBarCode + ",流转卡未开工!";
                                objJsonResult.data = null;
                                return objJsonResult;
                                //获取生产状态临时表数据
                                ds = oCN.RunProcReturn("select  * from Sc_ICMOBillStatus_Tmp where HSourceBillNo='" + HBarCode + "' and HProcID='" + HProcID + "'", "Sc_ICMOBillStatus_Tmp");
                                //传入 生产状态临时补 单据类型、主id、源单子ID、源单单号、当前登录人、源单单据类型
                                objJsonResult = SaveMESBeginWorkFrom_ZD(ds.Tables[0].Rows[0]["HBillType"].ToString(),ds.Tables[0].Rows[0]["HInterID"].ToString(), ds.Tables[0].Rows[0]["HSourceEntryID"].ToString(), ds.Tables[0].Rows[0]["HSourceBillNo"].ToString(),user, ds.Tables[0].Rows[0]["HSourceBillType"].ToString());
                                if (objJsonResult.code == "0")
                                {
                                    objJsonResult.code = "0";
                                    objJsonResult.count = 0;
                                    objJsonResult.Message = objJsonResult.Message;
                                    objJsonResult.data = null;
                                    return objJsonResult;
                                }
                            }                                                 
                        }   
                    }
@@ -804,8 +812,24 @@
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                oCN.Commit();
                if (double.Parse(ds.Tables[0].Rows[0][0].ToString()) == 0)
                {
                    //传入流转卡 单据类型、主id、子ID、单号、当前登录人、单据类型
                    objJsonResult = SaveMESEndWorkFrom_ZD("3772", HProcExchInterID, HProcExchEntryID, HProcExchBillNo, user, "");
                    if (objJsonResult.code == "0")
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "出站单保存成功,自动完工生成失败" + objJsonResult.Message;
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;
@@ -2446,6 +2470,340 @@
        }
        #endregion
        #region 工序单品过站自动开、完工
        //自动开工
        public json SaveMESBeginWorkFrom_ZD(string HBillType, string HSourceInterID, string HSourceEntryID, string HSourceBillNo, string user, string HSourceBillType)
        {
            //保存权限
            if (!DBUtility.ClsPub.Security_Log_second("MES_MESBeginWorkBill_Edit", 1, false, user))
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "无保存权限!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            //判断会计期是否合理
            string s = "";
            int sYear = 0;
            int sPeriod = 0;
            if (DBUtility.Xt_BaseBillFun.Fun_AllowYearPeriod(DateTime.Now, ref sYear, ref sPeriod, ref s) == false)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = s;
                objJsonResult.data = null;
                return objJsonResult;
            }
            try
            {
                ds = oCN.RunProcReturn("exec h_p_JIT_GetInfoByICMOStatusInterID @HSourceInterID=" + HSourceInterID + ",@HSourceEntryID=" + HSourceEntryID + ",@HSourceBillNo='" + HSourceBillNo + "',@HSourceBillType='" + HBillType + "'", "h_p_JIT_GetInfoByICMOStatusInterID");
                Models.ClsSc_MESBeginWorkBillMain ClsSc_MESBeginWorkBillMain = new Models.ClsSc_MESBeginWorkBillMain();
                ClsSc_MESBeginWorkBillMain.HProcID = int.Parse(ds.Tables[0].Rows[0]["HProcID"].ToString());
                ClsSc_MESBeginWorkBillMain.HMaterID = int.Parse(ds.Tables[0].Rows[0]["HMaterID"].ToString());
                ClsSc_MESBeginWorkBillMain.HSourceID = int.Parse(ds.Tables[0].Rows[0]["HSourceID"].ToString());
                ClsSc_MESBeginWorkBillMain.HMainSourceBillNo = ds.Tables[0].Rows[0]["HSourceBillNo"].ToString();
                ClsSc_MESBeginWorkBillMain.HMainSourceInterID = int.Parse(ds.Tables[0].Rows[0]["HSourceInterID"].ToString());
                ClsSc_MESBeginWorkBillMain.HMainSourceEntryID = ds.Tables[0].Rows[0]["HSourceEntryID"].ToString();
                ClsSc_MESBeginWorkBillMain.HMainSourceBillType = HSourceBillType == null ? "" : HSourceBillType;
                ClsSc_MESBeginWorkBillMain.HDeptID = int.Parse(ds.Tables[0].Rows[0]["HDeptID"].ToString());
                ClsSc_MESBeginWorkBillMain.HICMOInterID = int.Parse(ds.Tables[0].Rows[0]["HICMOInterID"].ToString());
                ClsSc_MESBeginWorkBillMain.HICMOEntryID = int.Parse(ds.Tables[0].Rows[0]["HICMOEntryID"].ToString());
                ClsSc_MESBeginWorkBillMain.HICMOBillNo = ds.Tables[0].Rows[0]["HICMOBillNo"].ToString();
                ClsSc_MESBeginWorkBillMain.HProcExchInterID = int.Parse(ds.Tables[0].Rows[0]["HProcExchInterID"].ToString());
                ClsSc_MESBeginWorkBillMain.HProcExchEntryID = int.Parse(ds.Tables[0].Rows[0]["HProcExchEntryID"].ToString());
                ClsSc_MESBeginWorkBillMain.HProcExchBillNo = ds.Tables[0].Rows[0]["HProcExchBillNo"].ToString();
                ClsSc_MESBeginWorkBillMain.HPeopleSum =1;
                //获取班次
                DataSet set = oCN.RunProcReturn("exec h_p_Gy_GetWorkShiftInfo " + int.Parse(ds.Tables[0].Rows[0]["HDeptID"].ToString()) + "," + int.Parse(ds.Tables[0].Rows[0]["HCenterID"].ToString()), "h_p_Gy_GetWorkShiftInfo");
                if (set.Tables[0].Rows.Count > 0)
                {
                    ClsSc_MESBeginWorkBillMain.HWorkShiftID = int.Parse(set.Tables[0].Rows[0]["HInterID"].ToString());
                }
                ds = oCN.RunProcReturn("select * from h_v_xt_UserAssociationSelect where Czymc='" + user + "'", "h_v_xt_UserAssociationSelect");
                if (ds.Tables[0].Rows[0]["HEmployeeID"].ToString() == "0")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "自动开工保存失败!用户没有绑定职员!";
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
                ClsSc_MESBeginWorkBillMain.HGroupID = int.Parse(ds.Tables[0].Rows[0]["HGroupID"].ToString());
                ClsSc_MESBeginWorkBillMain.HEmpID = int.Parse(ds.Tables[0].Rows[0]["HEmployeeID"].ToString());
                DLL.ClsSc_MESBeginWorkBill oBill = new DLL.ClsSc_MESBeginWorkBill();
                List<Models.ClsSc_MESBeginWorkBillMain> lsmain = new List<Models.ClsSc_MESBeginWorkBillMain>();
                lsmain.Add(ClsSc_MESBeginWorkBillMain);
                ClsXt_SystemParameter oClsXt_SystemParameter = new ClsXt_SystemParameter();
                DBUtility.ClsPub.CurUserName = user;
                foreach (Models.ClsSc_MESBeginWorkBillMain oItem in lsmain)
                {
                    oItem.HBillNo = DBUtility.ClsPub.CreateBillCode("3787", ref DBUtility.ClsPub.sExeReturnInfo, true);
                    oItem.HBillType = "3787";
                    oItem.HBillSubType = "3787";
                    oItem.HBillStatus = 1;   //单据状态(1未审,2审核通过,3关闭,4作废,5审核退回,6审核中,7已阅,8已回复,9结案,10验证,11下达,12开工,13申请审批,15申请检验,16 判定合格,17判定不合格)
                    oItem.HYear = DBUtility.ClsPub.isLong(DateTime.Now.Year);
                    oItem.HPeriod = DBUtility.ClsPub.isLong(DateTime.Now.Month);
                    oItem.HMaker = user;
                    oItem.HMakeDate = DBUtility.ClsPub.isStrNull(DateTime.Now.ToString("yyyy-MM-dd"));
                    oItem.HBarCodeMakeDate = Convert.ToDateTime(DBUtility.ClsPub.isStrNull(DateTime.Now.ToString("yyyy-MM-dd"))); //扫描日期(年-月-日-时-分-秒)
                    oItem.HRemark = "自动开工";
                    oBill.omodel = oItem;
                }
                oCN.BeginTran();
                //保存
                //保存完毕后处理
                bool bResult = false;
                if (oBill.omodel.HInterID == 0)
                {
                    bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                }
                ds = oCN.RunProcReturn("select * from Sc_MESBeginWorkBillMain where HBillNo='" + oBill.omodel.HBillNo + "'", "Sc_MESBeginWorkBillMain");
                if (ds.Tables[0].Rows.Count == 0)
                {
                    oCN.RollBack();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "查无单据!";
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
                string sAutoCheck = oClsXt_SystemParameter.GetSingleSystemParameter("Sc_MESBeginWorkBill_AutoCheck", ref DBUtility.ClsPub.sExeReturnInfo);
                if (sAutoCheck == "Y")
                {
                    if (!oBill.CheckBill(long.Parse(ds.Tables[0].Rows[0]["HInterID"].ToString()), ref DBUtility.ClsPub.sExeReturnInfo))
                    {
                        oCN.RollBack();
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "审核失败!";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                }
                oCN.Commit();
                if (bResult)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "保存成功!";
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "保存失败!" + DBUtility.ClsPub.sExeReturnInfo;
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = e.Message;
                objJsonResult.data = 1;
                return objJsonResult;
            }
        }
        //自动完工
        public json SaveMESEndWorkFrom_ZD(string HBillType, long HSourceInterID, long HSourceEntryID, string HSourceBillNo, string user, string HSourceBillType)
        {
            SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
            //保存权限
            if (!DBUtility.ClsPub.Security_Log_second("MES_MESEndWorkBill_Edit", 1, false, user))
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "无完工单保存权限!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            //判断会计期是否合理
            string s = "";
            int sYear = 0;
            int sPeriod = 0;
            if (DBUtility.Xt_BaseBillFun.Fun_AllowYearPeriod(DateTime.Now, ref sYear, ref sPeriod, ref s) == false)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = s;
                objJsonResult.data = null;
                return objJsonResult;
            }
            try
            {
                ds = oCN.RunProcReturn("exec h_p_JIT_GetInfoByICMOStatusInterID @HSourceInterID=" + HSourceInterID + ",@HSourceEntryID=" + HSourceEntryID + ",@HSourceBillNo='" + HSourceBillNo + "',@HSourceBillType='" + HBillType + "'", "h_p_JIT_GetInfoByICMOStatusInterID");
                Models.ClsSc_MESEndWorkBillMain ClsSc_MESEndWorkBillMain = new Models.ClsSc_MESEndWorkBillMain();
                ClsSc_MESEndWorkBillMain.HProcID = int.Parse(ds.Tables[0].Rows[0]["HProcID"].ToString());
                ClsSc_MESEndWorkBillMain.HMaterID = int.Parse(ds.Tables[0].Rows[0]["HMaterID"].ToString());
                ClsSc_MESEndWorkBillMain.HSourceID = int.Parse(ds.Tables[0].Rows[0]["HSourceID"].ToString());
                ClsSc_MESEndWorkBillMain.HMainSourceBillNo = ds.Tables[0].Rows[0]["HSourceBillNo"].ToString();
                ClsSc_MESEndWorkBillMain.HMainSourceInterID = int.Parse(ds.Tables[0].Rows[0]["HSourceInterID"].ToString());
                ClsSc_MESEndWorkBillMain.HMainSourceEntryID = long.Parse(ds.Tables[0].Rows[0]["HSourceEntryID"].ToString());
                ClsSc_MESEndWorkBillMain.HMainSourceBillType = HSourceBillType == null ? "" : HSourceBillType;
                ClsSc_MESEndWorkBillMain.HDeptID = int.Parse(ds.Tables[0].Rows[0]["HDeptID"].ToString());
                ClsSc_MESEndWorkBillMain.HICMOInterID = int.Parse(ds.Tables[0].Rows[0]["HICMOInterID"].ToString());
                ClsSc_MESEndWorkBillMain.HICMOEntryID = int.Parse(ds.Tables[0].Rows[0]["HICMOEntryID"].ToString());
                ClsSc_MESEndWorkBillMain.HICMOBillNo = ds.Tables[0].Rows[0]["HICMOBillNo"].ToString();
                ClsSc_MESEndWorkBillMain.HProcExchInterID = int.Parse(ds.Tables[0].Rows[0]["HProcExchInterID"].ToString());
                ClsSc_MESEndWorkBillMain.HProcExchEntryID = int.Parse(ds.Tables[0].Rows[0]["HProcExchEntryID"].ToString());
                ClsSc_MESEndWorkBillMain.HProcExchBillNo = ds.Tables[0].Rows[0]["HProcExchBillNo"].ToString();
                //获取班次
                DataSet set = oCN.RunProcReturn("exec h_p_Gy_GetWorkShiftInfo " + int.Parse(ds.Tables[0].Rows[0]["HDeptID"].ToString()) + "," + int.Parse(ds.Tables[0].Rows[0]["HCenterID"].ToString()), "h_p_Gy_GetWorkShiftInfo");
                if (set.Tables[0].Rows.Count > 0)
                {
                    ClsSc_MESEndWorkBillMain.HWorkShiftID = int.Parse(set.Tables[0].Rows[0]["HInterID"].ToString());
                }
                ds = oCN.RunProcReturn("select * from h_v_Cj_GetDefValByUser where 用户名称='" + user + "'", "h_v_xt_UserAssociationSelect");
                if (ds.Tables[0].Rows[0]["HEmpID"].ToString() == "0")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "保存失败!用户没有绑定职员!";
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
                ClsSc_MESEndWorkBillMain.HGroupID = int.Parse(ds.Tables[0].Rows[0]["HGroupID"].ToString());
                ClsSc_MESEndWorkBillMain.HEmpID = int.Parse(ds.Tables[0].Rows[0]["HEmpID"].ToString());
                DLL.ClsSc_MESEndWorkBill oBill = new DLL.ClsSc_MESEndWorkBill();
                List<Models.ClsSc_MESEndWorkBillMain> lsmain = new List<Models.ClsSc_MESEndWorkBillMain>();
                lsmain.Add(ClsSc_MESEndWorkBillMain);
                ClsXt_SystemParameter oClsXt_SystemParameter = new ClsXt_SystemParameter();
                DBUtility.ClsPub.CurUserName = user;
                foreach (Models.ClsSc_MESEndWorkBillMain oItem in lsmain)
                {
                    oItem.HBillNo = DBUtility.ClsPub.CreateBillCode("3788", ref DBUtility.ClsPub.sExeReturnInfo, true);
                    oItem.HBillType = "3788";
                    oItem.HBillSubType = "3788";
                    oItem.HReportType = "3";//(1条码扫描,2机器汇报,3手工录入)
                    oItem.HBillStatus = 1;   //单据状态(1未审,2审核通过,3关闭,4作废,5审核退回,6审核中,7已阅,8已回复,9结案,10验证,11下达,12开工,13申请审批,15申请检验,16 判定合格,17判定不合格)
                    oItem.HYear = DBUtility.ClsPub.isLong(DateTime.Now.Year);
                    oItem.HPeriod = DBUtility.ClsPub.isLong(DateTime.Now.Month);
                    oItem.HMaker = user;
                    oItem.HMakeDate = DBUtility.ClsPub.isStrNull(DateTime.Now.ToString("yyyy-MM-dd"));
                    oItem.HBarCodeMakeDate = Convert.ToDateTime(DBUtility.ClsPub.isStrNull(DateTime.Now.ToString("yyyy-MM-dd"))); //扫描日期(年-月-日-时-分-秒)
                    oItem.HRemark = "自动完工";
                    oBill.omodel = oItem;
                }
                oCN.BeginTran();
                //保存
                //保存完毕后处理
                bool bResult = false;
                if (oBill.omodel.HInterID == 0)
                {
                    bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                    if (!bResult)
                    {
                        oCN.RollBack();
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "保存失败!" + DBUtility.ClsPub.sExeReturnInfo;
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                }
                ds = oCN.RunProcReturn("select * from Sc_MESEndWorkBillMain where HBillNo='" + oBill.omodel.HBillNo + "'", "Sc_MESEndWorkBillMain");
                if (ds.Tables[0].Rows.Count == 0)
                {
                    oCN.RollBack();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "查无单据!";
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
                string sAutoCheck = oClsXt_SystemParameter.GetSingleSystemParameter("Sc_MESEndWorkBill_AutoCheck", ref DBUtility.ClsPub.sExeReturnInfo);
                if (sAutoCheck == "Y")
                {
                    if (!oBill.CheckBill(long.Parse(ds.Tables[0].Rows[0]["HInterID"].ToString()), ref DBUtility.ClsPub.sExeReturnInfo))
                    {
                        oCN.RollBack();
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "审核失败!";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                }
                oCN.Commit();
                if (bResult)
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "保存成功!";
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "自动完工保存失败!" + DBUtility.ClsPub.sExeReturnInfo;
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = e.Message;
                objJsonResult.data = 1;
                return objJsonResult;
            }
        }
        #endregion
        #region 小卫单品过站接口
        #region  工序单品过站 扫条码码校验返回信息(只用于验证批次是否入库)