chenhaozhe
2025-05-30 edcd7574e709748c5d3ccc0bd54930414ddcfc9a
WebAPI/Controllers/MateOutController.cs
@@ -2736,6 +2736,114 @@
        }
        #endregion
        #region  工厂日历保存(批量)
        [Route("MaterOutEntryReport/Sc_ShopCalendarSaveList")]
        [HttpPost]
        public object Sc_ShopCalendarSaveList([FromBody] JObject sMainSub)
        {
            try
            {
                var _value = sMainSub["sMainSub"].ToString();
                string msg1 = _value.ToString();
                oCN.BeginTran();
                //保存主表
                objJsonResult = AddBillMainList(msg1);
                if (objJsonResult.code == "0")
                {
                    oCN.RollBack();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = objJsonResult.Message;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                oCN.Commit();
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "单据保存成功!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        public class ClsHSourceList
        {
            public long HItemID { get; set; }
        }
        public class ClsHWorkHourList
        {
            public DateTime date { get; set; }
            public string week { get; set; }
            public double workHours { get; set; }
        }
        public json AddBillMainList(string msg1)
        {
            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            string msg2 = sArray[0].ToString();//资源列表
            string msg3 = sArray[1].ToString();//数据列表
            string user = sArray[2].ToString();
            try
            {
                if (!DBUtility.ClsPub.Security_Log("Gy_PlanShifts_Edit", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无保存权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                List<ClsHSourceList> HSourceList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsHSourceList>>(msg2);
                List<ClsHWorkHourList> HWorkHourList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsHWorkHourList>>(msg3);
                //遍历更新数据
                foreach (ClsHSourceList HSource in HSourceList)
                {
                    long HSourceID = HSource.HItemID;
                    foreach (ClsHWorkHourList HWorkHour in HWorkHourList)
                    {
                        DateTime date = HWorkHour.date;
                        double workHours = HWorkHour.workHours;
                        ds = oCN.RunProcReturn("select * from Gy_PlanShifts where HDate='" + date + "' and HSourceID=" + HSourceID, "Gy_PlanShifts");
                        string sql = "";
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            sql = $"update Gy_PlanShifts set HOverTimes='" + workHours + "' where  HDate ='" + date + "' and HSourceID=" + HSourceID;
                        }
                        else
                        {
                            sql = $"insert into Gy_PlanShifts(HDate,HSourceID,HShiftsID,HOverTimes,HClassCount," +
                              "HRemark,HUseFlag)values" +
                              $"('{date}','{HSourceID}',0,'{workHours}','1'" +
                              $",'','未检测')";
                        }
                        oCN.RunProc(sql);
                    }
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = null;
                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
        #region  工厂日历批改上班工时
        [Route("Gy_PlanShifts/BulkWorkTime")]
        [HttpGet]