YL
2021-08-30 ff8e4d1a22ff39fda122cb914efd3c37e78d42fc
WebAPI/Controllers/SCGL/Sc_QualityReportBillController.cs
@@ -10,24 +10,18 @@
namespace WebAPI.Controllers
{
    //生产汇报Controller
    public class Sc_ICMOReportBillController : ApiController
    //质量汇报单Controller
    //数据库主表Sc_QualityReportBillMain
    //数据库子表Sc_QualityReportBillSub
    public class Sc_QualityReportBillController : ApiController
    {
        public DBUtility.ClsPub.Enum_BillStatus BillStatus;
        private json objJsonResult = new json();
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
        DataSet ds;
        #region  生产汇报单
        #region  生产汇报单列表
        /// <summary>
        /// 返回生产汇报单列表
        ///参数:string sql。
        ///返回值:object。
        /// </summary>
        [Route("Sc_ICMOReportBill/list")]
        #region 返回生产质量汇报单列表
        [Route("Sc_QualityReportBill/list")]
        [HttpGet]
        public object list(string sWhere)
        {
@@ -35,337 +29,13 @@
            {
                if (sWhere == null || sWhere.Equals(""))
                {
                    ds = oCN.RunProcReturn("select * from h_v_IF_ICMOReportBillList " + sWhere, "h_v_IF_ICMOReportBillList");
                    ds = oCN.RunProcReturn("select * from h_v_Sc_QualityReportBillListDetail " + sWhere, "h_v_Sc_QualityReportBillListDetail");
                }
                else
                {
                    string sql1 = "select * from h_v_IF_ICMOReportBillList where 1 = 1 ";
                    string sql1 = "select * from h_v_Sc_QualityReportBillListDetail where 1 = 1 ";
                    string sql = sql1 + sWhere;
                    ds = oCN.RunProcReturn(sql, "h_v_IF_ICMOReportBillList");
                }
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "Sucess!";
                    objJsonResult.data = ds.Tables[0];
                    return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region 生产汇报单编辑时获取表头数据
        [Route("Sc_ICMOReportBill/Sc_GetICMOReportBillListCheckDetai")]
        [HttpGet]
        public ApiResult<DataSet> Sc_GetICMOReportBillListCheckDetai(string HID)
        {
            if (string.IsNullOrEmpty(HID))
                return new ApiResult<DataSet> { code = -1, msg = "ID不能为空" };
            SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
            var dataSet = oCN.RunProcReturn("select top 1 * from h_v_IF_ICMOReportBillList_Edit  where hmainid= " + HID + " ", "h_v_IF_ICMOReportBillList_Edit");
            if (dataSet == null || dataSet.Tables[0].Rows.Count == 0)
                return new ApiResult<DataSet> { code = -1, msg = "不存在生产汇报单号" };
            return new ApiResult<DataSet> { code = 1, msg = "查询成功", data = dataSet };
        }
        #endregion
        #region 生产汇报单编辑时获取表体数据
        [Route("Sc_ICMOReportBill/Sc_ICMOReportBillListProjectDetai")]
        [HttpGet]
        public object Sc_ICMOReportBillListProjectDetai(string sqlWhere)
        {
            DataSet ds;
            try
            {
                SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                if (sqlWhere == null || sqlWhere.Equals(""))
                {
                    ds = oCN.RunProcReturn(string.Format(@"SELECT HMaterID,物料代码 HMaterCode,物料名称 HMaterName,规格型号 HMaterSpec,
                                            HUnitID, 计量单位代码 HUnitCode, 计量单位 HUnitName,HSourceID,生产资源代码 HSourceCode,生产资源 HSourceName,
                                            HWorkerid,操作员代码 HWorkerCode,操作员 HWorkerName,生产数量 HQty,表体备注 HRemark
                                            FROM h_v_IF_ICMOReportBillList_Edit"), "h_v_IF_ICMOReportBillList_Edit");
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "获取信息成功!";
                    objJsonResult.data = ds.Tables[0];
                }
                else
                {
                    //string sql1 = "select HRepairCheckID,HRepairCheckContent,HManagerID,HRemark  from Sc_MouldRepairCheckBillSub where 1 = 1 ";
                    string sql1 = string.Format(@"SELECT HMaterID,物料代码 HMaterCode,物料名称 HMaterName,规格型号 HMaterSpec,
                                            HUnitID, 计量单位代码 HUnitCode, 计量单位 HUnitName,HSourceID,生产资源代码 HSourceCode,生产资源 HSourceName,
                                            HWorkerid,操作员代码 HWorkerCode,操作员 HWorkerName,生产数量 HQty,表体备注 HRemark
                                            FROM h_v_IF_ICMOReportBillList_Edit where 1 = 1 ");
                    string sql = sql1 + sqlWhere;
                    ds = oCN.RunProcReturn(sql, "h_v_IF_ICMOReportBillList_Edit");
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "获取信息成功!";
                    objJsonResult.data = ds.Tables[0];
                }
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "没有返回任何记录!" + e.ToString();
                objJsonResult.data = null;
            }
            return objJsonResult;
        }
        #endregion
        #region 生产汇报单保存/编辑
        /// <summary>
        /// 保存模具领用单
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        [Route("Sc_ICMOReportBill/SaveGetICMOReportBillList")]
        [HttpPost]
        public object SaveGetICMOReportBillList([FromBody] JObject msg)
        {
            var _value = msg["msg"].ToString();
            string msg1 = _value.ToString();
            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            string msg2 = sArray[0].ToString();
            string msg3 = sArray[1].ToString();
            string UserName = "";
            ListModels oListModels = new ListModels();
            try
            {
                DLL.ClsSc_ICMOReportBill oBill = new DLL.ClsSc_ICMOReportBill();
                List<Model.ClsSc_ICMOReportBillMain> lsmain = new List<Model.ClsSc_ICMOReportBillMain>();
                msg2 = msg2.Replace("\\", "");
                msg2 = msg2.Replace("\n", "");  //\n
                lsmain = oListModels.getObjectByJson_Gy_ICMOReportBillMain(msg2);
                foreach (Model.ClsSc_ICMOReportBillMain oItem in lsmain)
                {
                    //oItem.HMaker = "";
                    UserName = oItem.HMaker;  //制单人
                    oItem.HBillType = "3711";
                    oItem.HBillSubType = "3711";
                    //oItem.HBillNo = "";    //单据号
                    //oItem.HDate = DBUtility.ClsPub.isDate(DateTime.Now.ToString("yyyy-MM-dd"));//  --日期
                    //oItem.HInnerBillNo = "";  //  --内部单据号
                    oItem.HYear = DBUtility.ClsPub.isLong(DateTime.Now.Year);
                    oItem.HMakeDate = DBUtility.ClsPub.isStrNull(DateTime.Now.ToString("yyyy-MM-dd"));
                    //oItem.HEquipID = 0;    //设备ID(Gy_EquipMent)
                    //oItem.HPeriod = 0;
                    //oItem.HCheckBeginDate = DBUtility.ClsPub.isDate(DateTime.Now.ToString("yyyy-MM-dd"));  //  --维修日期
                    //oItem.HCheckResult = "";     //验收结论--(正常,异常)
                    //oItem.HEmpID = 0;           //验收人(Gy_Employee)
                    //oItem.HManagerID = 0;      //负责人(Gy_Employee)
                    //oItem.HDeptID = 0;        //验收部门(Gy_Department)
                    //oItem.HExplanation = "";  //摘要(故障描述)
                    //oItem.HRemark = "";       //备注
                    //oItem.HMainSourceInterID = oItem.HInterID;
                    //oItem.HInterID = DBUtility.ClsPub.CreateBillID_SRMProd("1103", ref DBUtility.ClsPub.sExeReturnInfo);
                    if (DBUtility.ClsPub.isStrNull(oItem.HDate) == "")
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "保存失败!没有单据日期,无法保存!";
                        objJsonResult.data = 1;
                        return objJsonResult;
                    }
                    oBill.omodel = oItem;
                }
                //表体数据
                //按 },{来拆分数组 //去掉【和】
                msg3 = msg3.Substring(1, msg3.Length - 2);
                msg3 = msg3.Replace("\\", "");
                msg3 = msg3.Replace("\n", "");  //\n
                //msg2 = msg2.Replace("'", "’");
                List<Model.ClsSc_ICMOReportBillSub> ls = new List<Model.ClsSc_ICMOReportBillSub>();
                ls = oListModels.getObjectByJson_Gy_ICMOReportBillSub(msg3);
                int i = 0;
                foreach (Model.ClsSc_ICMOReportBillSub oItemSub in ls)
                {
                    i++;
                    oItemSub.HEntryID = i;
                    //oItemSub.HRepairCheckID = 0;   //验收项目ID
                    //oItemSub.HRepairCheckContent = ""; //验收内容
                    //oItemSub.HManagerID = 0;   //负责人ID
                    //oItemSub.HCloseMan = "";       //行关闭
                    oItemSub.HEntryCloseDate = DBUtility.ClsPub.isDate(DateTime.Now);
                    oItemSub.HCloseType = false;   //关闭类型
                    //oItemSub.HRemark = "";         //备注
                    oItemSub.HSourceInterID = 0;     // 源单主内码
                    oItemSub.HSourceEntryID = 0;   //源单子内码
                    //oItemSub.HSourceBillNo = "";  //源单单号
                    //oItemSub.HSourceBillType = ""; //源单类型
                    //oItemSub.HRelationQty = 0;     //关联数量
                    //oItemSub.HRelationMoney = 0;   //关联金额
                    //oItemSub.HRepairID = 0;       //维修项目
                    //oItemSub.HRepairExplanation ="";   //维修要求
                    //oItemSub.HMoney = 0;        //维修费用
                    oBill.DetailColl.Add(oItemSub);
                }
                //保存
                //保存完毕后处理
                bool bResult;
                if (oBill.omodel.HInterID == 0)
                {
                    // bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                    bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                }
                else
                {
                    bResult = oBill.ModifyBill(oBill.omodel.HInterID, ref DBUtility.ClsPub.sExeReturnInfo);
                }
                if (bResult)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "保存成功!";
                    //WebAPIController.Add_Log("送货单下推", UserName, "生成送货单");
                    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.ToString();
                objJsonResult.data = 1;
                return objJsonResult;
            }
        }
        #endregion
        #region 生产汇报单删除功能
        /// <summary>
        /// 模具处理领用单删除功能
        /// </summary>
        /// <returns></returns>
        [Route("Sc_ICMOReportBill/DeltetICMOReportBill")]
        [HttpGet]
        public object DeltetMouldLifeChangeBill(string HInterID)
        {
            //编辑权限
            //if (!DBUtility.ClsPub.Security_Log("Sc_ICMOReportBill_Delete", 1, true, DBUtility.ClsPub.CurUserName))
            //{
            //    objJsonResult.code = "0";
            //    objJsonResult.count = 0;
            //    objJsonResult.Message = "无删除权限!";
            //    objJsonResult.data = null;
            //    return objJsonResult;
            //}
            Int64 lngBillKey = 0;
            lngBillKey = DBUtility.ClsPub.isLong(HInterID);
            if (lngBillKey == 0)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "单据ID为空!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            DLL.ClsSc_ICMOReportBill oBill = new DLL.ClsSc_ICMOReportBill();
            if (oBill.ShowBill(lngBillKey, ref DBUtility.ClsPub.sExeReturnInfo))
            {
                if (oBill.omodel.HBillStatus > 1)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "单据当前处于不能删除状态,不能删除!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (oBill.omodel.HChecker != "")
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "单据已经审核,不能删除!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                bool IsDete = oBill.DeleteBill(oBill.omodel.HInterID, ref DBUtility.ClsPub.sExeReturnInfo);
                if (IsDete)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 1;
                    objJsonResult.Message = DBUtility.ClsPub.sExeReturnInfo;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = DBUtility.ClsPub.sExeReturnInfo;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
            }
            else
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "单据未找到";
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #endregion
        /// <summary>
        /// 返回生产质量汇报单列表
        ///参数:string sql。
        ///返回值:object。
        /// </summary>
        [Route("Sc_AssemblyBill/list1")]
        [HttpGet]
        public object list1(string sWhere)
        {
            try
            {
                if (sWhere == null || sWhere.Equals(""))
                {
                    ds = oCN.RunProcReturn("select * from h_v_Sc_AssemblyBillList " + sWhere, "h_v_Sc_AssemblyBillList");
                }
                else
                {
                    string sql1 = "select * from h_v_Sc_AssemblyBillList where 1 = 1 ";
                    string sql = sql1 + sWhere;
                    ds = oCN.RunProcReturn(sql, "h_v_Sc_AssemblyBillList");
                    ds = oCN.RunProcReturn(sql, "h_v_Sc_QualityReportBillListDetail");
                }
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
@@ -393,7 +63,162 @@
                return objJsonResult;
            }
        }
        #endregion
        //
        #region 质量汇报单根据源单类型获取信息-源单为生产状态临时表(3722)
        [Route("Sc_QualityReportBill/get_ICMOBillStatus_Tmp")]
        [HttpGet]
        public object get_ICMOBillStatus_Tmp(int HInterID, int HEntryID, string HBillType)
        {
            try
            {
                if (HInterID == 0 || HBillType.Equals(""))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "参数不全,获取源单信息失败!HInterID:" + HInterID + ";HEntryID:" + HEntryID + ";HBillType:" + HBillType + ";";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    ds = oCN.RunProcReturn
                        ("select a.HInterID,a.HBillType,a.HICMOBillNo,a.HICMOInterID,a.HMaterID" +
                        ",m.HNumber HMaterNumber,m.HName HMaterName,m.HModel HMaterModel " +
                        " from Sc_ICMOBillStatus_Tmp a " +
                        " left join Gy_Material m on a.HMaterID=m.HItemID " +
                        " Where a.HInterID=" + HInterID + " and a.HBillType="+ HBillType, "Sc_ICMOBillStatus_Tmp");
                }
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "查询数据异常,请与管理员联系!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    objJsonResult.Message = "返回记录成功!";
                    objJsonResult.data = ds.Tables[0];
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "查询数据异常,请与管理员联系!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region 质量汇报单扫不良条码保存信息
        [Route("Sc_QualityReportBill/set_SaveBarCode")]
        [HttpPost]
        public object set_SaveBarCode([FromBody] JObject oMain)
        {
            var msg1 = oMain["oMain"].ToString();
            //保存单据
            return objJsonResult = AddBillMain(msg1);
        }
        public json AddBillMain(string msg1)
        {
            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            string msg = sArray[0].ToString();
            string OperationType = sArray[1].ToString().Trim();
            bool bResult;
            try
            {
                msg = "[" + msg.ToString() + "]";
                List<Model.ClsSc_ICMOBillQualityStatus_Tmp> mainList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Model.ClsSc_ICMOBillQualityStatus_Tmp>>(msg);
                DAL.ClsQC_FirstPieceCheckBill BillNew = new DAL.ClsQC_FirstPieceCheckBill();
                //判断会计期是否合理
                string s = "";
                int sYear = 0;
                int sPeriod = 0;
                DateTime HDate = mainList[0].HMakeDate;
                if (DBUtility.Xt_BaseBillFun.Fun_AllowYearPeriod(HDate, ref sYear, ref sPeriod, ref s) == false)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = s;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                BillNew.omodel.HYear = sYear;
                BillNew.omodel.HPeriod = sPeriod;
                //固定赋值=================================
                BillNew.omodel.HInterID = mainList[0].HInterID;//递入type得到的单据ID
                //BillNew.omodel.HBillNo = mainList[0].HBillNo;//递入type得到的单据号
                //BillNew.omodel.HDate = HDate;
                //BillNew.omodel.HRemark = mainList[0].HRemark;//备注
                //BillNew.omodel.HMaker = mainList[0].HMaker;
                //BillNew.omodel.HSourceID = ClsPub.isLong(mainList[0].HSourceID);
                //BillNew.omodel.HICMOInterID = ClsPub.isLong(mainList[0].HICMOInterID);
                //BillNew.omodel.HICMOBillNo = ClsPub.isStrNull(mainList[0].HICMOBillNo);
                //BillNew.omodel.HICMOInterID = ClsPub.isLong(mainList[0].HICMOInterID);
                //BillNew.omodel.HICMOQty = ClsPub.isLong(mainList[0].HICMOQty);
                //BillNew.omodel.HProcExchInterID = ClsPub.isLong(mainList[0].HProcExchInterID);
                //BillNew.omodel.HProcExchEntryID = ClsPub.isLong(mainList[0].HProcExchEntryID);
                //BillNew.omodel.HProcExchBillNo = ClsPub.isStrNull(mainList[0].HProcExchBillNo);
                //BillNew.omodel.HProcExchQty = ClsPub.isLong(mainList[0].HProcExchQty);
                //BillNew.omodel.HMaterID = ClsPub.isLong(mainList[0].HMaterID);
                //BillNew.omodel.HFirstCheckEmp = ClsPub.isLong(mainList[0].HFirstCheckEmp);
                //BillNew.omodel.HLastResult = ClsPub.isBool(mainList[0].HLastResult);
                //BillNew.omodel.HMainSourceInterID = ClsPub.isLong(mainList[0].HMainSourceInterID);
                //BillNew.omodel.HMainSourceEntryID = ClsPub.isLong(mainList[0].HMainSourceEntryID);
                //BillNew.omodel.HMainSourceBillNo = ClsPub.isStrNull(mainList[0].HMainSourceBillNo);
                //BillNew.omodel.HMainSourceBillType = ClsPub.isStrNull(mainList[0].HMainSourceBillType);
                BillNew.omodel.HBillStatus = 1;
                //保存完毕后处理
                if (OperationType.Equals("1") || OperationType.Equals("2"))
                {
                    bResult = BillNew.AddBill(ref ClsPub.sExeReturnInfo);
                }
                else if (OperationType.Equals("3"))
                {
                    bResult = BillNew.ModifyBill(BillNew.omodel.HInterID, ref ClsPub.sExeReturnInfo);
                }
                else
                {
                    ClsPub.sExeReturnInfo = "无效的操作类型!";
                    bResult = false;
                }
                //提示
                if (bResult == true)
                {
                    objJsonResult.code = "1";
                    objJsonResult.count = 1;
                    //objJsonResult.Message = "单据存盘完毕!单据号:" + mainList[0].HBillNo.Trim();
                    objJsonResult.Message = ClsPub.sExeReturnInfo + "单据号:" ;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                else
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "保存失败!原因:" + ClsPub.sExeReturnInfo;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
    }
}