|  |  | 
 |  |  | using Newtonsoft.Json.Linq; | 
 |  |  | using Model; | 
 |  |  | using Newtonsoft.Json.Linq; | 
 |  |  | using Pub_Class; | 
 |  |  | using System; | 
 |  |  | using System.Collections; | 
 |  |  | 
 |  |  |         /// </summary> | 
 |  |  |         [Route("Xs_SeOutStockBill/list")] | 
 |  |  |         [HttpGet] | 
 |  |  |         public object list(string sWhere) | 
 |  |  |         public object list(string sWhere,string user) | 
 |  |  |         { | 
 |  |  |             try | 
 |  |  |             { | 
 |  |  |                 //判断是否有查询权限 | 
 |  |  |                 if (!DBUtility.ClsPub.Security_Log("Xs_SeOutStockBillQuery", 1, false, user)) | 
 |  |  |                 { | 
 |  |  |                     objJsonResult.code = "0"; | 
 |  |  |                     objJsonResult.count = 0; | 
 |  |  |                     objJsonResult.Message = "无权限查询!"; | 
 |  |  |                     objJsonResult.data = null; | 
 |  |  |                     return objJsonResult; | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 if (sWhere == null || sWhere.Equals("")) | 
 |  |  |                 { | 
 |  |  |                     ds = oCN.RunProcReturn("select * from h_v_IF_SeOutStockBillList " + sWhere, "h_v_IF_SeOutStockBillList"); | 
 |  |  |                     ds = oCN.RunProcReturn("select * from h_v_IF_SeOutStockBillList order by hmainid desc", "h_v_IF_SeOutStockBillList"); | 
 |  |  |                 } | 
 |  |  |                 else | 
 |  |  |                 { | 
 |  |  |                     string sql1 = "select * from h_v_IF_SeOutStockBillList where 1 = 1 "; | 
 |  |  |                     string sql = sql1 + sWhere; | 
 |  |  |                     string sql = sql1 + sWhere+ " order by hmainid desc"; | 
 |  |  |                     ds = oCN.RunProcReturn(sql, "h_v_IF_SeOutStockBillList"); | 
 |  |  |                 } | 
 |  |  |                 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 = "Sucess!"; | 
 |  |  |                     objJsonResult.data = ds.Tables[0]; | 
 |  |  |                     return objJsonResult; | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 //if (ds.Tables[0].Rows.Count != 0 || ds != null) | 
 |  |  |                 //{ | 
 |  |  |                 objJsonResult.code = "1"; | 
 |  |  |                 objJsonResult.count = 1; | 
 |  |  |                 objJsonResult.Message = "Sucess!"; | 
 |  |  |                 objJsonResult.data = ds.Tables[0]; | 
 |  |  |                 return objJsonResult; | 
 |  |  |                 //} | 
 |  |  |                 //else | 
 |  |  |                 //{ | 
 |  |  |                 //objJsonResult.code = "0"; | 
 |  |  |                 //objJsonResult.count = 0; | 
 |  |  |                 //objJsonResult.Message = "无数据"; | 
 |  |  |                 //objJsonResult.data = null; | 
 |  |  |                 //return objJsonResult; | 
 |  |  |                 //} | 
 |  |  |             } | 
 |  |  |             catch (Exception e) | 
 |  |  |             { | 
 |  |  | 
 |  |  |         /// <returns></returns> | 
 |  |  |         [Route("Xs_SeOutStockBill/DeltetSeOutStockBill")] | 
 |  |  |         [HttpGet] | 
 |  |  |         public object DeltetSeOutStockBill(string HInterID) | 
 |  |  |         public object DeltetSeOutStockBill(string HInterID,string user) | 
 |  |  |         { | 
 |  |  |             try | 
 |  |  |             { | 
 |  |  |                 //判断是否有删除权限 | 
 |  |  |                 if (!DBUtility.ClsPub.Security_Log("Xs_SeOutStockBill_Drop", 1, false, user)) | 
 |  |  |                 { | 
 |  |  |                     objJsonResult.code = "0"; | 
 |  |  |                     objJsonResult.count = 0; | 
 |  |  |                     objJsonResult.Message = "无权限删除!"; | 
 |  |  |                     objJsonResult.data = null; | 
 |  |  |                     return objJsonResult; | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 oCN.BeginTran(); | 
 |  |  |                 oCN.RunProc("Delete From Xs_SeOutStockBillMain where HInterID = " + HInterID); | 
 |  |  |                 oCN.RunProc("Delete From Xs_SeOutStockBillSub where HInterID = " + HInterID); | 
 |  |  | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         #region 发货通知单 保存/编辑功能 | 
 |  |  |         [Route("Xs_SeOutStockBill/SeOutStockBillEdit")] | 
 |  |  |         [HttpPost] | 
 |  |  |         public object SeOutStockBillEdit([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<ClsXs_SeOutStockBillMain> mainList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsXs_SeOutStockBillMain>>(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 HWHID = mainList[0].HWHID;//仓库 | 
 |  |  |                 long HManagerID = mainList[0].HManagerID;//主管 | 
 |  |  |                 long HCurID = mainList[0].HCurID;//币别 | 
 |  |  |                 Single HExRate = mainList[0].HExRate;//汇率 | 
 |  |  |                 string HMaker = user;//制单人 | 
 |  |  |                 string HExplanation = mainList[0].HExplanation;//摘要 | 
 |  |  |                 string HInnerBillNo = mainList[0].HInnerBillNo;//内部单据号  | 
 |  |  |                 long HCusID = mainList[0].HCusID; //客户 | 
 |  |  |                 string HAddress = mainList[0].HAddress;//地址 | 
 |  |  |                 long HSSID = mainList[0].HSSID;//结算方式 | 
 |  |  |  | 
 |  |  |                 long HDFflag = Convert.ToInt32(mainList[0].HDFflag); //是否垫付 | 
 |  |  |  | 
 |  |  |  | 
 |  |  |                 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; | 
 |  |  |                 long HERPInterID = mainList[0].HERPInterID; | 
 |  |  |                 string HERPBillType = mainList[0].HERPBillType; | 
 |  |  |                 long HSALEORGID = mainList[0].HSALEORGID; | 
 |  |  |                 long HDELIVERYORGID = mainList[0].HDELIVERYORGID; | 
 |  |  |                 long HOWNERID = mainList[0].HOWNERID; | 
 |  |  |                 string HOWNERTYPEID = mainList[0].HOWNERTYPEID; | 
 |  |  |  | 
 |  |  |                 ds = oCN.RunProcReturn("select * from h_v_IF_SeOutStockBillList where hmainid=" + HInterID + " and 单据号='" + HBillNo + "'", "h_v_IF_SeOutStockBillList"); | 
 |  |  |  | 
 |  |  |                 if ((OperationType == 1 || OperationType == 2) && ds.Tables[0].Rows.Count == 0)//新增 | 
 |  |  |                 { | 
 |  |  |                     //主表 | 
 |  |  |                     oCN.RunProc(@"Insert Into Xs_SeOutStockBillMain    | 
 |  |  |                         (HInterID,HYear,HPeriod,HBillType,HBillSubType,HDate,HBillNo,HBillStatus | 
 |  |  |                        ,HCusID,HManagerID,HDeptID,HRemark,HMaker,HMakeDate | 
 |  |  |                        ,HAddress,HSSID,HCurID,HWHID,HExRate,HEmpID,HExplanation,HInnerBillNo | 
 |  |  |                        ,HSALEORGID,HDELIVERYORGID,HOWNERID,HOWNERTYPEID | 
 |  |  |                        ,HChecker,HCheckDate,HCloseMan,HCloseDate,HERPInterID,HERPBillType,HDFflag) | 
 |  |  |                         values(" + HInterID + "," + DateTime.Now.Year + "," + DateTime.Now.Month + ",'" + 1402 + "','" + | 
 |  |  |                     1402 + "','" + HDate + "','" + HBillNo + "'," + HBillStatus + "," + HCusID + | 
 |  |  |                     "," + HManagerID + "," + HDeptID + ",'" + HRemark + "','" + HMaker + "','" + HMakeDate + | 
 |  |  |                     "','" + HAddress + "'," + HSSID + "," + HCurID + "," + HWHID + "," + HExRate + "," + HEmpID + ",'" + | 
 |  |  |                     HExplanation + "','" + HInnerBillNo + "'," + HSALEORGID + "," + HDELIVERYORGID + "," + HOWNERID + ",'" | 
 |  |  |                     + HOWNERTYPEID + "','" + HChecker + "','" + HCheckDate + "','" + HCloseMan + "','" + HCloseDate + "'," + HERPInterID + | 
 |  |  |                     ",'" + HERPBillType + "'," + HDFflag + ")"); | 
 |  |  |                 } | 
 |  |  |                 else if (OperationType == 3 || ds.Tables[0].Rows.Count != 0) | 
 |  |  |                 { //修改 | 
 |  |  |                     oCN.RunProc("update Xs_SeOutStockBillMain  set " + | 
 |  |  |                                 "HRemark='" + HRemark + "', HChecker='" + HMaker + "', HCheckDate=getdate()" + "' where HInterID=" + HInterID); | 
 |  |  |  | 
 |  |  |                     //删除子表 | 
 |  |  |                     oCN.RunProc("delete from Xs_SeOutStockBillSub 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<ClsXs_SeOutStockBillSub> DetailColl = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsXs_SeOutStockBillSub>>(msg3); | 
 |  |  |  | 
 |  |  |             int i = 0; | 
 |  |  |             foreach (ClsXs_SeOutStockBillSub 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 Xs_SeOutStockBillSub", "Xs_SeOutStockBillSub"); | 
 |  |  |                 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; | 
 |  |  |                 } | 
 |  |  |  | 
 |  |  |                 oCN.RunProc($@"Insert into Xs_SeOutStockBillSub  | 
 |  |  |                 (HInterID,HEntryID,HMaterID,HUnitID,HQty,HPrice,HMoney,HWHID,HSPID,HRemark | 
 |  |  |                ,HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HSeOrderInterID,HSeOrderEntryID,HSeORderBillNo | 
 |  |  |                ,HOWNERID,HOWNERTYPEID,HSETTLEORGID,HMoveStockQty | 
 |  |  |                ,HRelationQty,HAuxPropID,HBatchNO,HMTONo,HERPInterID,HERPEntryID)  | 
 |  |  |                  values({HInterID},{NewHEntryID},{oSub.HMaterID},{oSub.HUnitID},{oSub.HQty} | 
 |  |  |                 ,{oSub.HPrice},{oSub.HMoney},{oSub.HWHID},{oSub.HSPID},'{oSub.HRemark}',{oSub.HSourceInterID},{oSub.HSourceEntryID},'{oSub.HSourceBillNo}','{oSub.HSourceBillType}',{oSub.HSeOrderInterID},{oSub.HSeOrderEntryID},'{oSub.HSeORderBillNo}',{oSub.HOWNERID},'{oSub.HOWNERTYPEID}',{oSub.HSETTLEORGID},{oSub.HMoveStockQty},{oSub.HRelationQty} | 
 |  |  |                 ,{oSub.HAuxPropID},'{oSub.HBatchNO}','{oSub.HMTONo}',{oSub.HERPInterID},{oSub.HERPEntryID})"); | 
 |  |  |             } | 
 |  |  |  | 
 |  |  |             objJsonResult.code = "1"; | 
 |  |  |             objJsonResult.count = 1; | 
 |  |  |             objJsonResult.Message = null; | 
 |  |  |             objJsonResult.data = null; | 
 |  |  |             return objJsonResult; | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         #endregion | 
 |  |  |  | 
 |  |  |         // | 
 |  |  |     } |