yusijie
2024-12-20 d2b5cb03e2ab7d672203f41ef8b1709c087e6d4a
WebAPI/Controllers/»ù´¡×ÊÁÏ/Éú²ú»ù´¡×ÊÁÏ/Gy_ShiftsController.cs
@@ -28,6 +28,8 @@
        DAL.ClsGy_Shifts_Ctl oBill = new DAL.ClsGy_Shifts_Ctl();
        DAL.ClsGy_Shifts_View oBillHlp = new DAL.ClsGy_Shifts_View();
        public DAL.ClsGy_WorkShift_Ctl BillOld1 = new DAL.ClsGy_WorkShift_Ctl();   //对应单据类  ç­æ¬¡è¡¨2
        public DAL.ClsGy_WorkShift_Ctl BillNew1 = new DAL.ClsGy_WorkShift_Ctl();   //对应单据类  ç­æ¬¡è¡¨2
        #region ç­æ¬¡åˆ—表
        /// <summary>
@@ -515,7 +517,7 @@
            }
        }
        #endregion
        #endregion
        #region æ˜¾ç¤ºç­æ¬¡ä¿¡æ¯
        /// <summary>
@@ -557,5 +559,319 @@
        #endregion
        #region ç­æ¬¡è¡¨2
        #region ç­æ¬¡è¡¨2 æ–°å¢ž/编辑
        [Route("Gy_ShiftsController/SaveGy_WorkShift")]
        [HttpPost]
        public object SaveGy_WorkShift([FromBody] JObject oMain)
        {
            var _value = oMain["oMain"].ToString();
            string msg1 = _value.ToString();
            string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            string msg2 = sArray[0].ToString();
            string msg3 = sArray[1].ToString(); //子表
            string refSav = sArray[2].ToString();//操作方式数据类型 1添加 3修改 2 å¤åˆ¶
            string msg4 = sArray[3].ToString();//用户名
            DBUtility.ClsPub.CurUserName = msg4;
            string s = "";
            try
            {
                //编辑权限
                if (!DBUtility.ClsPub.Security_Log_second("Gy_WorkShift_Edit", 1, false, msg4))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无保存权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                // Gy_WorkShift
                DAL.ClsGy_WorkShift_Ctl oBill = new DAL.ClsGy_WorkShift_Ctl();
                msg2 = msg2.Replace("\\", "");
                msg2 = msg2.Replace("\n", "");  //\n
                msg2 = "[" + msg2.ToString() + "]";
                List<Model.ClsGy_WorkShiftMain> lsmain = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Model.ClsGy_WorkShiftMain>>(msg2);
                foreach (Model.ClsGy_WorkShiftMain oItem in lsmain)
                {
                    if (refSav == "Update")
                    {
                        if (BillOld1.ShowBill(oItem.HInterID, ref s) == false)
                        {
                            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
                msg3 = "[" + msg3.ToString() + "]";
                List<Model.ClsGy_WorkShiftSub> ls = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Model.ClsGy_WorkShiftSub>>(msg3);
                int i = 0;
                foreach (Model.ClsGy_WorkShiftSub oItemSub in ls)
                {
                    i++;
                    oItemSub.HEntryID = i;
                    oBill.DetailColl.Add(oItemSub);
                }
                //保存
                //保存完毕后处理
                bool bResult;
                if (refSav == "Add")
                {
                    bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
                }
                else if (refSav == "Update")
                {
                    bResult = oBill.ModifyBill(oBill.omodel.HInterID, ref DBUtility.ClsPub.sExeReturnInfo);
                }
                else
                {
                    bResult = false;
                }
                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.ToString();
                objJsonResult.data = 1;
                return objJsonResult;
            }
        }
        #endregion
        #region ç­æ¬¡è¡¨2 ç¼–辑回显列表
        [Route("Gy_ShiftsController/Edit_Gy_WorkShift")]
        [HttpGet]
        public object Edit_Gy_WorkShift(string HID)
        {
            try
            {
                List<object> columnNameList = new List<object>();
                string sql = "select * from h_v_Gy_WorkShiftEdit where HInterID='" + HID + "'";
                ds = oCn.RunProcReturn(sql, "h_v_Gy_WorkShiftEdit");
                //添加列名
                foreach (DataColumn col in ds.Tables[0].Columns)
                {
                    Type dataType = col.DataType;
                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
                    columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                objJsonResult.list = columnNameList;
                return objJsonResult;
            }
            catch (Exception ex)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "查询数据异常,请与管理员联系!" + ex.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region ç­æ¬¡è¡¨2列表
        [Route("Gy_ShiftsController/Get_Gy_WorkShiftList")]
        [HttpGet]
        public object Get_Gy_WorkShiftList(string sWhere, string HMaker)
        {
            try
            {
                List<object> columnNameList = new List<object>();
                //查看权限
                if (!DBUtility.ClsPub.Security_Log("Gy_WorkShift_Query", 1, false, HMaker))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无查看权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (sWhere == null || sWhere.Equals(""))
                {
                    string sql = "select * from h_v_Gy_WorkShiftList order by HInterID desc";
                    ds = oCn.RunProcReturn(sql, "h_v_Gy_WorkShiftList");
                }
                else
                {
                    string sql1 = "select * from h_v_Gy_WorkShiftList where 1 = 1 ";
                    string sql = sql1 + sWhere + " order by HInterID desc";
                    ds = oCn.RunProcReturn(sql, "h_v_Gy_WorkShiftList");
                }
                //添加列名
                foreach (DataColumn col in ds.Tables[0].Columns)
                {
                    Type dataType = col.DataType;
                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
                    columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                objJsonResult.list = columnNameList;
                return objJsonResult;
            }
            catch (Exception ex)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "查询数据异常,请与管理员联系!" + ex.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region ç­æ¬¡è¡¨2 åˆ é™¤
        [Route("Gy_ShiftsController/DeleteGy_WorkShift")]
        [HttpGet]
        public object DeleteGy_WorkShift(string HInterID, string user)
        {
            try
            {
                string s = "";
                DAL.ClsGy_WorkShift_Ctl BillOld = new DAL.ClsGy_WorkShift_Ctl();
                //查看权限
                if (!DBUtility.ClsPub.Security_Log("Gy_WorkShift_Delete", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无删除权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (HInterID == null || HInterID.Equals(""))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "HInterID不能为空!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                if (BillOld.ShowBill(long.Parse(HInterID), ref s) == false)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "此单据有误!";
                    objJsonResult.data = 1;
                    return objJsonResult;
                }
                oCn.BeginTran();
                oCn.RunProc("delete from Gy_WorkShift where HInterID = " + HInterID);
                oCn.RunProc("delete from Gy_WorkShiftSub where HInterID= " + HInterID);
                oCn.Commit();
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "删除成功";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                oCn.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #endregion
        #region æ˜¾ç¤ºç­æ¬¡ä¿¡æ¯
        /// <summary>
        /// æ ¹æ®åŸºç¡€èµ„æ–™ID æŸ¥æ‰¾è®°å½•
        /// </summary>
        [Route("Gy_ShiftsController/Get_HWorkShift")]
        [HttpGet]
        public object Get_HWorkShift(int HDeptID,int HCenterID)
        {
            try
            {
                ds = oCn.RunProcReturn("exec h_p_Gy_GetWorkShiftInfo  '"+HDeptID+"','"+HCenterID+"'", "h_p_Gy_GetWorkShiftInfo");
                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
    }
}