WebAPI/DLL/ClsSc_MESReturnStepWorkBill.cs
@@ -3,6 +3,7 @@
using System.Data;
using System.Linq;
using System.Web;
using ViewAPI;
namespace WebAPI.DLL
{
@@ -91,19 +92,19 @@
            try
            {
                //获取当前工序工序号以及判断是否末道工序
                string sql = string.Format(@"select max(b.HProcNo) HProcNo  from Sc_ProcessPlanMain a
                               inner join   Sc_ProcessPlanSub  b on a.HInterID=b.HInterID
                               where b.HSourceBillNo='" + omodel.HSourceBillNo+"' and b.HSourceInterID='"+omodel.HSourceInterID+"'  and b.HSourceEntryID='"+omodel.HSourceEntryID+"'");
                DataSet ds= oCn.RunProcReturn(sql, "Sc_ProcessPlanMain");
                //string sql = string.Format(@"select max(b.HProcNo) HProcNo  from Sc_ProcessPlanMain a
                //               inner join   Sc_ProcessPlanSub  b on a.HInterID=b.HInterID
                //               where b.HSourceBillNo='" + omodel.HSourceBillNo+"' and b.HSourceInterID='"+omodel.HSourceInterID+"'  and b.HSourceEntryID='"+omodel.HSourceEntryID+"'");
                //DataSet ds= oCn.RunProcReturn(sql, "Sc_ProcessPlanMain");
                //查询最大工序及判断当前工序是否小于最大工序
                if (ds.Tables[0].Rows.Count > 0 && int.Parse(ds.Tables[0].Rows[0]["HProcNo"].ToString()) > omodel.HProcID)
                {
                    omodel.HProcNo = omodel.HProcNo + 5;
                }
                else
                {
                    omodel.HProcNo = omodel.HProcNo + 5; //末道工序序号加5
                }
                //if (ds.Tables[0].Rows.Count > 0 && int.Parse(ds.Tables[0].Rows[0]["HProcNo"].ToString()) > omodel.HProcID)
                //{
                //    omodel.HProcNo = omodel.HProcNo + 5;
                //}
                //else
                //{
                //    omodel.HProcNo = omodel.HProcNo + 5; //末道工序序号加5
                //}
                //得到mainid
                omodel.HInterID = DBUtility.ClsPub.CreateBillID(BillType, ref DBUtility.ClsPub.sExeReturnInfo);
@@ -113,38 +114,41 @@
                oCn.RunProc("Insert Into Sc_ProcessPlanMain " +
                "(HBillType,HBillSubType,HInterID,HBillNo,HBillStatus,HDate,HMaker,HMakeDate" +
                ",HYear,HPeriod,HRemark" +
                ",HICMOInterID,HICMOBillNo,HMaterID" +
                ",HICMOInterID,HICMOBillNo,HMaterID,HMaterNumber,HPlanQty,HExplanation,HInnerBillNo" +
                ") " +
                " values('" + this.BillType + "','" + this.HBillSubType + "'," + omodel.HInterID.ToString() + ",'" + omodel.HBillNo + "'," + omodel.HBillStatus.ToString() + ",getdate(),'" + DBUtility.ClsPub.CurUserName + "',getdate()" +
                "," + omodel.HYear.ToString() + "," + omodel.HPeriod.ToString() + ",'" + omodel.HRemark + "'" +
                "," + omodel.HICMOInterID.ToString() + ",'" + omodel.HICMOBillNo + "'," +  omodel.HMaterID.ToString() +
                 ") ");
                "," + omodel.HICMOInterID.ToString() + ",'" + omodel.HICMOBillNo + "'," +  omodel.HMaterID.ToString() + ",'" + omodel.HMaterNumber + "','" + omodel.HQty + "'" +
                ",'报工台返工工序申请','') ");
                //插入子表
                oCn.RunProc("Insert Into Sc_ProcessPlanSub " +
                    "(HInterID,HEntryID,HBillNo" +
                    ",HICMOInterID,HICMOBillNo,HProcNo,HProcID" +
                    ",HGroupID,HDeptID,HWorkerID,HQty,HPlanBeginDate,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HSourceID" +
                    ") " +
                    " values(" + omodel.HInterID.ToString() + ",0,'" + omodel.HBillNo +
                    "'," + omodel.HICMOInterID.ToString() + ",'" + omodel.HICMOBillNo + "','" + omodel.HProcNo + "'," + omodel.HProcID.ToString() + "," + omodel.HGroupID.ToString() +
                    "," + omodel.HDeptID.ToString() + "," + omodel.HWorkerID.ToString() + "," + omodel.HQty.ToString() + ",'" + omodel.HPlanBeginDate.ToString() +"',"+ omodel.HSourceInterID.ToString()+
                    ","+ omodel.HSourceEntryID.ToString()+",'"+ omodel.HSourceBillNo+"','"+ omodel.HSourceBillType+","+ omodel.HSourceID.ToString()+
                     ") ");
                   "(HInterID,HEntryID,HBillNo" +
                   ",HICMOInterID,HICMOBillNo,HProcNo,HProcID,HProcNumber" +
                   ",HGroupID,HDeptID,HWorkerID,HQty,HPlanBeginDate,HPlanEndDate,HSeOrderInterID,HSeOrderEntryID,HSeOrderBillNo,HRemark,HRelationQty" +
                   ",HRelationMoney,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HSourceID" +
                   ") " +
                   " values(" + omodel.HInterID.ToString() + ",1,'" + omodel.HBillNo +
                   "'," + omodel.HICMOInterID.ToString() + ",'" + omodel.HICMOBillNo + "','" + omodel.HProcNo + "'," + omodel.HProcID.ToString() + ",''," + omodel.HGroupID.ToString() +
                   "," + omodel.HDeptID.ToString() + "," + omodel.HWorkerID.ToString() + "," + omodel.HQty.ToString() + ",'" + omodel.HPlanBeginDate.ToString() + "',getdate(),'0','0','','报工台返工工序','0'" +
                   ",'0'," + omodel.HSourceInterID.ToString() + "," + omodel.HSourceEntryID.ToString() + ",'" + omodel.HSourceBillNo + "','" + omodel.HSourceBillType + "'," + omodel.HSourceID.ToString() + ")");
                //新增生产状态临时表
                string sql1 = string.Format(@"insert into Sc_ICMOBillStatus_Tmp(HYear,HPeriod,HBillType,HDate,HDeptID,HICMOInterID,HICMOEntryID,HICMOBillNo,HYX,HSplitNO,HICMOStatus,HMaterID
                                    ,HMaterNumber,HUnitID,HUnitNumber,HSourceID,HSourceNumber,HSplitPlanQty,HSplitRelationQty,HDatePlanQty
                                    ,HUnitFinishQty,HDateFinishQty,HBadQty,HUnitBadQty,HWasterQty,HSumTimes,HFinishFlag,HCurWorkFlag,HCurQualityFlag
                                    ,HBeginDate,HEndDate,HRemark,HSourceInterID,HSourceEntryID,HSourceBillNo
                                    ,HSourceBillType,HRelationInterID,HEnoughMaterFlag,HProcID,HPlanQty)
                                    select HYear,HPeriod,HBillType,HDate,HDeptID,HICMOInterID,HICMOEntryID,HICMOBillNo,HYX,HSplitNO,HICMOStatus,HMaterID
                                    ,HMaterNumber,HUnitID,HUnitNumber,HSourceID,HSourceNumber,HPlanQty,HSplitPlanQty,HSplitRelationQty,HDatePlanQty
                                    ,HUnitFinishQty,HDateFinishQty,HBadQty,HUnitBadQty,HWasterQty,HSumTimes,HFinishFlag,HCurWorkFlag,HCurQualityFlag
                                    ,HBeginDate,HEndDate,HRemark,HSourceInterID,HSourceEntryID,HSourceBillNo
                                    ,HSourceBillType,HRelationInterID,HEnoughMaterFlag,HProcID,'"+omodel.HQty.ToString()+"' " +
                                    ,HSourceBillType,HRelationInterID,HEnoughMaterFlag,HProcID)
                                    select datepart(yyyy,GETDATE()),datepart(mm,GETDATE()),'3722',getdate(),'" + omodel.HDeptID+"','"+omodel.HICMOInterID + "','"+omodel.HSourceEntryID+"','"+omodel.HSourceBillNo+"','1','1',0,'"+omodel.HMaterID+"'" +
                                    ",HMaterNumber,HUnitID,HUnitNumber,HSourceID,HSourceNumber,'"+omodel.HQty+"',HSplitPlanQty,HSplitRelationQty,'"+omodel.HQty+"'" +
                                    ",'0','0','0','0','0','0','0','0','0'" +
                                    ",getdate(),getdate(),'返工计划','"+omodel.HICMOInterID + "','"+omodel.HSourceEntryID+"','"+omodel.HSourceBillNo+"'" +
                                    ",'"+omodel.HSourceBillType+"','0','0','"+omodel.HProcID+"'" +
                                    "from Sc_ICMOBillStatus_Tmp where HSourceBillNo='"+omodel.HSourceBillNo.ToString()+"'" +
                                    " and HSourceInterID='"+omodel.HSourceInterID+"' and HSourceEntryID='"+omodel.HMainSourceEntryID.ToString()+"'" +
                                    " and HSourceID='"+omodel.HSourceID.ToString()+"' and HProcID='"+omodel.HProcID.ToString()+"'");
                oCn.RunProc(sql);
                oCn.RunProc(sql1);
                sReturn = "新增单据成功!";
                oCn.Commit();
                return true;
@@ -156,5 +160,164 @@
                throw (e);
            }
        }
        //显示单据
        public override bool ShowBill(Int64 lngBillKey, ref string sReturn)
        {
            try
            {
                //查询主表
                DataSet Ds;
                Ds = oCn.RunProcReturn("Select * from Sc_ProcessPlanMain Where HInterID=" + lngBillKey.ToString(), "Sc_ProcessPlanMain");
                if (Ds.Tables[0].Rows.Count == 0)
                {
                    sReturn = "单据未找到!";
                    return false;
                }
                //赋值
                omodel.HYear = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HYear"]);
                omodel.HPeriod = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HPeriod"]);
                omodel.HBillType = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HBillType"]);
                omodel.HBillSubType = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HBillSubType"]);
                omodel.HInterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HInterID"]);
                omodel.HDate = DBUtility.ClsPub.isDate(Ds.Tables[0].Rows[0]["HDate"]);
                omodel.HBillNo = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HBillNo"]);
                omodel.HBillStatus = DBUtility.ClsPub.isInt(Ds.Tables[0].Rows[0]["HBillStatus"]);
                omodel.HCheckItemNowID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HCheckItemNowID"]);
                omodel.HCheckItemNextID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HCheckItemNextID"]);
                //
                omodel.HICMOInterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HICMOInterID"]);
                omodel.HICMOBillNo = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HICMOBillNo"]);
                omodel.HMaterID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HMaterID"]);
                omodel.HMaterNumber = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HMaterNumber"]);
                omodel.HUnitID = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HUnitID"]);
                omodel.HUnitNumber = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HUnitNumber"]);
                omodel.HPlanQty = DBUtility.ClsPub.isDoule(Ds.Tables[0].Rows[0]["HPlanQty"]);
                omodel.HPlanBeginDate = DBUtility.ClsPub.isDate(Ds.Tables[0].Rows[0]["HPlanBeginDate"]);
                omodel.HPlanEndDate = DBUtility.ClsPub.isDate(Ds.Tables[0].Rows[0]["HPlanEndDate"]);
                omodel.HExplanation = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HExplanation"]);
                omodel.HRemark = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HRemark"]);
                omodel.HInnerBillNo = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HInnerBillNo"]);
                //
                omodel.HBacker = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HBacker"]);
                omodel.HBackDate = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HBackDate"]);
                omodel.HChecker = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HChecker"]);
                omodel.HCheckDate = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HCheckDate"]);
                omodel.HMaker = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HMaker"]);
                omodel.HMakeDate = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HMakeDate"]);
                omodel.HUpDater = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HUpDater"]);
                omodel.HUpDateDate = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HUpDateDate"]);
                omodel.HCloseMan = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HCloseMan"]);
                omodel.HCloseDate = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HCloseDate"]);
                omodel.HCloseType = DBUtility.ClsPub.isBool(Ds.Tables[0].Rows[0]["HCloseType"]);
                omodel.HDeleteMan = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HDeleteMan"]);
                omodel.HDeleteDate = DBUtility.ClsPub.isStrNull(Ds.Tables[0].Rows[0]["HDeleteDate"]);
                //循环
                DataSet DsSub;
                DsSub = oCn.RunProcReturn("Select * from Sc_ProcessPlanSub Where HInterID=" + lngBillKey.ToString() + " order by HEntryID ", "Sc_ProcessPlanSub");
                DetailColl.Clear();//清空
                for (int i = 0; i < DsSub.Tables[0].Rows.Count; i++)
                {
                    Model.ClsSc_ProcessPlanSub oSub = new Model.ClsSc_ProcessPlanSub();
                    oSub.HInterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HInterID"]);
                    oSub.HEntryID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HEntryID"]);
                    //
                    oSub.HBillNo = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HBillNo"]);
                    oSub.HBatchNo = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HBatchNo"]);
                    oSub.HProcNo = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HProcNo"]);
                    oSub.HProcID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HProcID"]);
                    oSub.HProcNumber = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HProcNumber"]);
                    oSub.HWorkRemark = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HWorkRemark"]);
                    oSub.HCenterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HCenterID"]);
                    oSub.HDeptID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HDeptID"]);
                    oSub.HDeptNumber = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HDeptNumber"]);
                    oSub.HGroupID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HGroupID"]);
                    oSub.HGroupNumber = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HGroupNumber"]);
                    oSub.HWorkerID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HWorkerID"]);
                    oSub.HWorkerNumber = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HWorkerNumber"]);
                    oSub.HSourceID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HSourceID"]);
                    oSub.HQty = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["HQty"]);
                    oSub.HTimeUnit = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HTimeUnit"]);
                    oSub.HPlanWorkTimes = DBUtility.ClsPub.isSingle(DsSub.Tables[0].Rows[i]["HPlanWorkTimes"]);
                    oSub.HPlanBeginDate = DBUtility.ClsPub.isDate(DsSub.Tables[0].Rows[i]["HPlanBeginDate"]);
                    oSub.HPlanEndDate = DBUtility.ClsPub.isDate(DsSub.Tables[0].Rows[i]["HPlanEndDate"]);
                    oSub.HICMOInterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HICMOInterID"]);
                    oSub.HICMOBillNo = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HICMOBillNo"]);
                    oSub.HSeOrderInterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HSeOrderInterID"]);
                    oSub.HSeOrderEntryID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HSeOrderEntryID"]);
                    oSub.HSeOrderBillNo = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HSeOrderBillNo"]);
                    oSub.HWorkingQty = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["HWorkingQty"]);
                    //
                    oSub.HCloseMan = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HCloseMan"]);
                    oSub.HCloseType = DBUtility.ClsPub.isBool(DsSub.Tables[0].Rows[i]["HCloseType"]);
                    oSub.HRemark = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HRemark"]);
                    oSub.HSourceInterID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HSourceInterID"]);
                    oSub.HSourceEntryID = DBUtility.ClsPub.isLong(DsSub.Tables[0].Rows[i]["HSourceEntryID"]);
                    oSub.HSourceBillNo = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HSourceBillNo"]);
                    oSub.HSourceBillType = DBUtility.ClsPub.isStrNull(DsSub.Tables[0].Rows[i]["HSourceBillType"]);
                    oSub.HRelationQty = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["HRelationQty"]);
                    oSub.HRelationMoney = DBUtility.ClsPub.isDoule(DsSub.Tables[0].Rows[i]["HRelationMoney"]);
                    oSub.HBeginDayQty = DBUtility.ClsPub.isSingle(DsSub.Tables[0].Rows[i]["HBeginDayQty"]);
                    oSub.HBeginFixQty = DBUtility.ClsPub.isSingle(DsSub.Tables[0].Rows[i]["HBeginFixQty"]);
                    oSub.HFixWorkDays = DBUtility.ClsPub.isSingle(DsSub.Tables[0].Rows[i]["HFixWorkDays"]);
                    oSub.HTrunWorkDays = DBUtility.ClsPub.isSingle(DsSub.Tables[0].Rows[i]["HTrunWorkDays"]);
                    oSub.HReadyTimes = DBUtility.ClsPub.isSingle(DsSub.Tables[0].Rows[i]["HReadyTimes"]);
                    oSub.HReadyTime = DBUtility.ClsPub.isSingle(DsSub.Tables[0].Rows[i]["HReadyTime"]);
                    oSub.HQueueTime = DBUtility.ClsPub.isSingle(DsSub.Tables[0].Rows[i]["HQueueTime"]);
                    oSub.HMoveTime = DBUtility.ClsPub.isSingle(DsSub.Tables[0].Rows[i]["HMoveTime"]);
                    DetailColl.Add(oSub);
                }
                sReturn = "显示单据成功!";
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                throw (e);
            }
        }
        //审核
        public bool CheckBill(Int64 lngBillKey, ref string sReturn)
        {
            try
            {
                string HChecker = DBUtility.ClsPub.CurUserName;
                string HCheckDate = DBUtility.ClsPub.GetServerDate(-1);
                //更新工序计划单审核人、审核时间
                oCn.RunProc(" Update " + MvarItemKey + " set HChecker='" + HChecker + "',HCheckDate='" + HCheckDate + "' Where HInterID=" + lngBillKey.ToString());
                //更新(工序汇报单、生产状态临时表)不良数量=不良数量-返工数量
                sReturn = "";
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                throw (e);
            }
        }
        //反审核
        public bool AbandonCheck(Int64 lngBillKey, ref string sReturn)
        {
            if (isUse(lngBillKey, ref sReturn))
            {
                return false;
            }
            try
            {
                oCn.RunProc(" Update " + MvarItemKey + " set HChecker='',HCheckDate=null Where HInterID=" + lngBillKey.ToString());
                //更新(工序汇报单、生产状态临时表)不良数量=不良数量-返工数量
                sReturn = "";
                return true;
            }
            catch (Exception e)
            {
                sReturn = e.Message;
                throw (e);
            }
        }
    }
}