using DBUtility; using Model; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web; using System.Web.Http; using WebAPI.Models; namespace WebAPI.Controllers.仓存管理.领料发货 { public class Kf_MateOutRequestBillController : ApiController { public DBUtility.ClsPub.Enum_BillStatus BillStatus;//单据状态(新增,修改,浏览,更新单价,变更) private json objJsonResult = new json(); public DataSet ds = new DataSet(); public SQLHelper.ClsCN oCn = new SQLHelper.ClsCN(); public string HManagerID { get; private set; } #region 领用申请单列表 [Route("Kf_MateOutRequestBill/GetMateOutRequestBillList")] [HttpGet] public object GetMoveMateRequestBillList(string sWhere, string user) { try { ////判断是否有查询权限 //if (!DBUtility.ClsPub.Security_Log("Kf_MoveMateRequestBill_Query", 1, false, user)) //{ // objJsonResult.code = "0"; // objJsonResult.count = 0; // objJsonResult.Message = "无权限查询!"; // objJsonResult.data = null; // return objJsonResult; //} string sql1 = string.Format("select * from h_v_IF_MateOutRequestBillList where 1=1 "); if (sWhere == null || sWhere.Equals("")) { ds = oCn.RunProcReturn(sql1 + " order by hmainid desc", "h_v_IF_MateOutRequestBillList"); } else { string sql = sql1 + sWhere + " order by hmainid desc"; ds = oCn.RunProcReturn(sql, "h_v_IF_MateOutRequestBillList"); } objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "Sucess!"; objJsonResult.data = ds.Tables[0]; return objJsonResult; } catch (Exception ex) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "没有返回任何记录!" + ex.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 领用申请单 保存/编辑功能 [Route("Kf_MateOutRequestBill/MateOutRequestBillEdit")] [HttpPost] public object MateOutRequestBillEdit([FromBody] JObject sMainSub) { try { var _value = sMainSub["sMainSub"].ToString(); string msg1 = _value.ToString(); oCn.BeginTran(); //保存主表 objJsonResult = AddBillMain(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) { oCn.RollBack(); objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "保存失败!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } public json AddBillMain(string msg1) { string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); string msg2 = sArray[0].ToString(); //主表数据 string msg3 = sArray[1].ToString(); //子表数据 int OperationType = int.Parse(sArray[2].ToString()); // 数据类型 1添加 3修改 string user = sArray[3].ToString(); string msg_allVal = sArray[4].ToString(); //主表+子表所有数据 try { msg2 = "[" + msg2.ToString() + "]"; List mainList = Newtonsoft.Json.JsonConvert.DeserializeObject>(msg2); long HInterID = mainList[0].HInterID;//递入type得到的单据ID string HBillNo = mainList[0].HBillNo;//递入type得到的单据号 long HPRDORGID = mainList[0].HPRDORGID;//生产组织 DateTime HDate = mainList[0].HDate;//日期 string HRemark = mainList[0].HRemark;//备注 long HEmpID = mainList[0].HEmpID;//业务员 long HDeptID = mainList[0].HDeptID;//部门 long HManagerID = mainList[0].HManagerID;//主管 long HSecManagerID = mainList[0].HSecManagerID;//验收 long HKeeperID = mainList[0].HKeeperID;//保管员 string HMaker = user;//制单人 string HExplanation = mainList[0].HExplanation;//摘要 string HInnerBillNo = mainList[0].HInnerBillNo;//内部单据号 string HBillType = mainList[0].HBillType; string HBillSubType = mainList[0].HBillSubType; long HBillStatus = mainList[0].HBillStatus; string HMakeDate = mainList[0].HMakeDate; string HChecker = mainList[0].HChecker; string HCheckDate = mainList[0].HCheckDate; string HUpDater = mainList[0].HUpDater; string HUpDateDate = mainList[0].HUpDateDate; string HDeleteMan = mainList[0].HDeleteMan; string HDeleteDate = mainList[0].HDeleteDate; string HCloseMan = mainList[0].HCloseMan; string HCloseDate = mainList[0].HCloseDate; string HICCard = mainList[0].HICCard; string HSUPPLYType = mainList[0].HSUPPLYType;//发料方式 ds = oCn.RunProcReturn("select * from h_v_IF_MateOutRequestBillList where hmainid=" + HInterID + " and 单据号='" + HBillNo + "'", "h_v_IF_MateOutRequestBillList"); if ((OperationType == 1 || OperationType == 2) && ds.Tables[0].Rows.Count == 0)//新增 { //主表 oCn.RunProc(@"Insert Into Kf_MateOutRequestBillMain (HInterID,HBillNo,HDate,HBillType,HBillSubType,HBillStatus,HYear,HPeriod,HEmpID,HManagerID,HSecManagerID,HKeeperID,HDeptID,HMaker,HMakeDate,HChecker,HCheckDate,HUpDater,HUpDateDate,HDeleteMan,HDeleteDate,HCloseMan,HCloseDate,HRemark,HExplanation,HInnerBillNo,HICCard,HSUPPLYType,HPRDORGID) values(" + HInterID +",'"+ HBillNo +"','"+ HDate +"','"+ 1242 +"','"+ 1242 +"',"+ HBillStatus +","+ DateTime.Now.Year +","+ DateTime.Now.Month +","+ HEmpID +","+ HManagerID +","+ HSecManagerID +","+ HKeeperID +","+ HDeptID +",'"+ HMaker +"','"+ HMakeDate +"','"+ HChecker +"','"+ HCheckDate +"','"+ HUpDater +"','"+ HUpDateDate +"','"+ HDeleteMan +"','"+ HDeleteDate +"','"+ HCloseMan +"','"+ HCloseDate +"','"+ HRemark +"','"+ HExplanation +"','"+ HInnerBillNo + "','" + HICCard + "','" + HSUPPLYType + "'," + HPRDORGID + ")"); } else if (OperationType == 3 || ds.Tables[0].Rows.Count != 0) { //修改 oCn.RunProc("update Kf_MateOutRequestBillMain set " + "HRemark='" + HRemark + "', HChecker='" + HMaker + "', HCheckDate=getdate()" + "' where HInterID=" + HInterID); //删除子表 oCn.RunProc("delete from Kf_MateOutRequestBillSub where HInterID='" + HInterID + "'"); } //保存子表 objJsonResult = AddBillSub(msg3, HInterID, OperationType); 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; 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; } } public json AddBillSub(string msg3, long HInterID, int OperationType) { List DetailColl = Newtonsoft.Json.JsonConvert.DeserializeObject>(msg3); int i = 0; foreach (ClsKf_MateOutRequestBillSub oSub in DetailColl) { i++; if (oSub.HQty <= 0 || oSub.HQty == null) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "第" + i + "行,数量不能为0或者小于0"; objJsonResult.data = null; return objJsonResult; } if (oSub.HMaterID == 0) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "第" + i + "行,物料不能为空"; objJsonResult.data = null; return objJsonResult; } //if (oSub.HSourceID == 0) //{ // objJsonResult.code = "0"; // objJsonResult.count = 0; // objJsonResult.Message = "第" + i + "行,生产资源不能为空"; // objJsonResult.data = null; // return objJsonResult; //} if (oSub.HUnitID == 0) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "第" + i + "行,计量单位不能为空"; objJsonResult.data = null; return objJsonResult; } DataSet Cs; Int64 NewHEntryID = 1; Cs = oCn.RunProcReturn("select MAX(HEntryID)HEntryID from Kf_MateOutRequestBillSub", "Kf_MateOutRequestBillSub"); if (Cs.Tables[0].Rows.Count != 0 && ClsPub.isLong(Cs.Tables[0].Rows[0]["HEntryID"].ToString()) != 0) { NewHEntryID = ClsPub.isLong(Cs.Tables[0].Rows[0]["HEntryID"].ToString()); NewHEntryID += 1; } string sql = $@"Insert into Kf_MateOutRequestBillSub (HInterID,HEntryID,HDate,HRemark,HMTONo,HMaterID,HUnitID,HBatchNO,HWHID,HSPID,HQtyMust,HQty,HRelationQty, HRelationMoney,HPrice,HMoney,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HICMOInterID,HICMOEntryID, HICMOBillNo,HPOOrderInterID,HPOOrderEntryID,HPOOrderBillNo) values({HInterID},{NewHEntryID},getdate(),'{oSub.HRemark}','{oSub.HMTONo}',{oSub.HMaterID},{oSub.HUnitID}, '{oSub.HBatchNO}',{oSub.HWHID},{oSub.HSPID},{oSub.HQtyMust},{(oSub.HQty == null ? 0 : oSub.HQty)},{oSub.HRelationQty},{oSub.HRelationMoney}, {oSub.HPrice},{oSub.HMoney},{oSub.HSourceInterID},{oSub.HSourceEntryID},'{oSub.HSourceBillNo}','{oSub.HSourceBillType}',{oSub.HICMOInterID}, {oSub.HICMOEntryID},'{oSub.HICMOBillNo}',{oSub.HPOOrderInterID},{oSub.HPOOrderEntryID},'{oSub.HPOOrderBillNo}')"; oCn.RunProc(sql); } objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = null; objJsonResult.data = null; return objJsonResult; } #endregion /// ///删除功能 /// /// [Route("Kf_MateOutRequestBill/DeltetKf_MateOutRequestBill")] [HttpGet] public object DeltetKf_MateOutRequestBill(string HInterID) { try { oCn.BeginTran(); oCn.RunProc("Delete From Kf_MateOutRequestBillMain where HInterID = " + HInterID); oCn.RunProc("Delete From Kf_MateOutRequestBillSub 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; } } } }