/// <summary> /// 操作业务 /// </summary> /// <param name="buyingBill">单据信息数据集</param> /// <param name="listInfo">单据明细信息</param> /// <param name="error">错误信息</param> /// <returns>成功返回True,失败返回False</returns> public bool OperationInfo(Out_BuyingBill buyingBill, DataTable listInfo, out string error) { error = null; try { DepotManagementDataContext dataContext = CommentParameter.DepotDataContext; var varData = from a in dataContext.Out_BuyingBill where a.ID == buyingBill.ID select a; if (varData.Count() == 1) { Out_BuyingBill lnqBill = varData.Single(); lnqBill.Statua = "已完成"; lnqBill.Director = BasicInfo.LoginID; lnqBill.DirectTime = ServerTime.Time; for (int i = 0; i < listInfo.Rows.Count; i++) { Out_DetailAccount lnqDetail = new Out_DetailAccount(); lnqDetail.Bill_ID = buyingBill.ID.ToString(); lnqDetail.BillFinishTime = ServerTime.Time; lnqDetail.Confirmor = BasicInfo.LoginID; lnqDetail.GoodsID = Convert.ToInt32(listInfo.Rows[i]["GoodsID"]); lnqDetail.OperationCount = -Convert.ToDecimal(listInfo.Rows[i]["挂账数量"]); lnqDetail.BatchNo = listInfo.Rows[i]["规格"].ToString(); lnqDetail.Proposer = buyingBill.Recorder; lnqDetail.Remark = "【挂账单】" + listInfo.Rows[i]["备注"].ToString(); lnqDetail.SecStorageID = buyingBill.ClientCode; lnqDetail.StorageID = GetStockInfo(buyingBill.ClientCode, Convert.ToInt32(listInfo.Rows[i]["GoodsID"])); if (!new BusinessOperation().OperationDetailAndStock(dataContext, lnqDetail, out error)) { return(false); } } } else { error = "数据不唯一"; return(false); } dataContext.SubmitChanges(); return(true); } catch (Exception ex) { error = ex.Message; return(false); } }
/// <summary> /// 操作业务明细与库存 /// </summary> /// <param name="dataContext">数据上下文</param> /// <param name="detailAccount">业务明细数据集</param> /// <param name="error">错误信息</param> /// <returns>成功返回True,失败返回False</returns> public bool OperationDetailAndStock(DepotManagementDataContext dataContext, Out_DetailAccount detailAccount, out string error) { error = null; try { var varData = from a in dataContext.Out_DetailAccount where a.Bill_ID == detailAccount.Bill_ID && a.GoodsID == detailAccount.GoodsID && a.SecStorageID == detailAccount.SecStorageID && a.StorageID == detailAccount.StorageID select a; if (varData.Count() > 0) { error = "数据重复"; return(false); } else { if (!OperationStock(dataContext, detailAccount, out error)) { return(false); } dataContext.Out_DetailAccount.InsertOnSubmit(detailAccount); } return(true); } catch (Exception ex) { error = ex.Message; return(false); } }
/// <summary> /// 操作库存 /// </summary> /// <param name="dataContext">数据上下文</param> /// <param name="outDetail">业务明细数据集</param> /// <param name="error">错误信息</param> /// <returns>成功返回True,失败返回False</returns> public bool OperationStock(DepotManagementDataContext dataContext, Out_DetailAccount outDetail, out string error) { error = null; try { if (IntegrativeQuery.IsSalesStorage(outDetail.SecStorageID)) { return(true); } var varData = from a in dataContext.Out_Stock where a.GoodsID == outDetail.GoodsID && a.SecStorageID == outDetail.SecStorageID && a.StorageID == outDetail.StorageID select a; F_GoodsPlanCost lnqGoods = IntegrativeQuery.QueryGoodsInfo(Convert.ToInt32(outDetail.GoodsID)); if (varData.Count() == 0) { if (outDetail.OperationCount < 0) { error = "不能添加负数的库存记录" + "[" + lnqGoods.GoodsCode + "] [" + lnqGoods.GoodsName + "] [" + lnqGoods.Spec + "]"; return(false); } else { Out_Stock lnqStock = new Out_Stock(); lnqStock.GoodsID = Convert.ToInt32(outDetail.GoodsID); lnqStock.Remark = outDetail.Remark; lnqStock.SecStorageID = outDetail.SecStorageID; lnqStock.StockQty = Convert.ToDecimal(outDetail.OperationCount); lnqStock.Date = ServerTime.Time; lnqStock.Personnel = BasicInfo.LoginName; lnqStock.StorageID = outDetail.StorageID; dataContext.Out_Stock.InsertOnSubmit(lnqStock); } } else if (varData.Count() == 1) { Out_Stock lnqStock = varData.Single(); decimal dcSum = Convert.ToDecimal(lnqStock.StockQty) + Convert.ToDecimal(outDetail.OperationCount); if (dcSum < 0) { error = "不允许库存数量为负数" + "[" + lnqGoods.GoodsCode + "] [" + lnqGoods.GoodsName + "] [" + lnqGoods.Spec + "]"; return(false); } else { lnqStock.StockQty = Convert.ToDecimal(lnqStock.StockQty) + Convert.ToDecimal(outDetail.OperationCount); lnqStock.Date = ServerTime.Time; lnqStock.Personnel = BasicInfo.LoginName; } } else { error = "库存数据不唯一" + "[" + lnqGoods.GoodsCode + "] [" + lnqGoods.GoodsName + "] [" + lnqGoods.Spec + "]"; return(false); } return(true); } catch (Exception ex) { error = ex.Message; return(false); } }
/// <summary> /// 删除单据 /// </summary> /// <param name="billNo">单据号</param> /// <param name="error">错误信息</param> /// <returns>成功返回True,失败返回False</returns> public bool DeleteBill(string billNo, out string error) { error = null; DepotManagementDataContext dataContext = CommentParameter.DepotDataContext; dataContext.Connection.Open(); dataContext.Transaction = dataContext.Connection.BeginTransaction(); try { var varData = from a in dataContext.Out_ManeuverBill where a.Bill_ID == billNo select a; if (varData.Count() != 1) { error = "数据为空或者不唯一"; return(false); } else { Out_ManeuverBill billInfo = varData.Single(); foreach (var item in varData) { Out_UniqueIdentifierData lnqIdentifier = new Out_UniqueIdentifierData(); lnqIdentifier.Bill_ID = item.Bill_ID; if (!m_serverIdentifier.DeleteIdentifier(dataContext, lnqIdentifier, out error)) { return(false); } } if (billInfo.AssociatedBillNo != null && billInfo.AssociatedBillNo.Contains("YXTK")) { var varMarketing = from a in dataContext.S_MarketingBill where a.DJH == varData.Single().AssociatedBillNo select a; dataContext.S_MarketingBill.DeleteAllOnSubmit(varMarketing); m_billMessageServer.DestroyMessage(billInfo.AssociatedBillNo); } var varAfterService = from a in dataContext.Out_AfterServicePartsApplyBill where a.Bill_ID == billInfo.AssociatedBillNo select a; foreach (var item in varAfterService) { item.BillStatus = "新建单据"; } var varDetail = from a in dataContext.Out_ManeuverList where a.Bill_ID == billInfo.Bill_ID select a; List <Out_ManeuverList> lstList = varDetail.ToList(); dataContext.Out_ManeuverBill.DeleteAllOnSubmit(varData); dataContext.SubmitChanges(); foreach (Out_ManeuverList detail in lstList) { var varAccount = from a in dataContext.Out_DetailAccount where a.Bill_ID == billInfo.Bill_ID && a.GoodsID == detail.GoodsID && a.SecStorageID == billInfo.OutStorageID && a.StorageID == detail.StorageID select a; if (varAccount.Count() == 1) { Out_DetailAccount lnqAccount = varAccount.Single(); lnqAccount.OperationCount = -lnqAccount.OperationCount; if (!m_serverBusiness.OperationStock(dataContext, lnqAccount, out error)) { throw new Exception(error); } } dataContext.Out_DetailAccount.DeleteAllOnSubmit(varAccount); dataContext.SubmitChanges(); } } dataContext.Transaction.Commit(); return(true); } catch (Exception ex) { dataContext.Transaction.Rollback(); error = ex.Message; return(false); } }
/// <summary> /// 操作业务 /// </summary> /// <param name="maneuverBill">单据信息数据集</param> /// <param name="listInfo">单据明细信息</param> /// <param name="error">错误信息</param> /// <returns>成功返回True,失败返回False</returns> public bool OperationInfo(Out_ManeuverBill maneuverBill, DataTable listInfo, out string error) { error = null; DepotManagementDataContext dataContext = CommentParameter.DepotDataContext; dataContext.Connection.Open(); dataContext.Transaction = dataContext.Connection.BeginTransaction(); try { var varData = from a in dataContext.Out_ManeuverBill where a.Bill_ID == maneuverBill.Bill_ID select a; if (varData.Count() == 1) { Out_ManeuverBill lnqBill = varData.Single(); switch (lnqBill.BillStatus) { case "等待主管审核": lnqBill.BillStatus = "等待出库"; lnqBill.Verify = BasicInfo.LoginName; lnqBill.VerifyTime = ServerTime.Time; break; case "等待出库": lnqBill.BillStatus = "等待发货"; lnqBill.Shipper = BasicInfo.LoginName; lnqBill.ShipperTime = ServerTime.Time; for (int i = 0; i < listInfo.Rows.Count; i++) { if (listInfo.Rows[i]["发货数量"] == null || listInfo.Rows[i]["发货数量"].ToString() == "" || Convert.ToDecimal(listInfo.Rows[i]["发货数量"]) == 0) { listInfo.Rows[i]["发货数量"] = listInfo.Rows[i]["申请数量"]; } } if (!DeleteList(dataContext, maneuverBill.Bill_ID, out error)) { throw new Exception(error); } if (!InsertList(dataContext, maneuverBill.Bill_ID, listInfo, out error)) { throw new Exception(error); } dataContext.SubmitChanges(); CheckUniqueIdentifierCode(dataContext, maneuverBill); for (int i = 0; i < listInfo.Rows.Count; i++) { Out_DetailAccount lnqDetail = new Out_DetailAccount(); lnqDetail.Bill_ID = lnqBill.Bill_ID; lnqDetail.BillFinishTime = ServerTime.Time; lnqDetail.Confirmor = BasicInfo.LoginName; lnqDetail.GoodsID = Convert.ToInt32(listInfo.Rows[i]["物品ID"]); lnqDetail.OperationCount = -Convert.ToDecimal(listInfo.Rows[i]["发货数量"]); lnqDetail.Proposer = lnqBill.Proposer; lnqDetail.Remark = listInfo.Rows[i]["备注"].ToString(); lnqDetail.SecStorageID = lnqBill.OutStorageID; lnqDetail.StorageID = listInfo.Rows[i]["账务库房ID"].ToString(); if (!m_serverBusiness.OperationDetailAndStock(dataContext, lnqDetail, out error)) { throw new Exception(error); } } break; case "等待发货": lnqBill.BillStatus = "等待收货"; lnqBill.LogisticsBillNo = maneuverBill.LogisticsBillNo; lnqBill.LogisticsName = maneuverBill.LogisticsName; lnqBill.Phone = maneuverBill.Phone; lnqBill.ExcShipper = BasicInfo.LoginName; lnqBill.ExcShipperTime = ServerTime.Time; break; case "等待收货": lnqBill.BillStatus = "等待入库"; lnqBill.ExcConfirmor = BasicInfo.LoginName; lnqBill.ExcConfirmorTime = ServerTime.Time; break; case "等待入库": lnqBill.BillStatus = "已完成"; lnqBill.Confirmor = BasicInfo.LoginName; lnqBill.ConfirmorTime = ServerTime.Time; for (int i = 0; i < listInfo.Rows.Count; i++) { if (listInfo.Rows[i]["收货数量"] == null || listInfo.Rows[i]["收货数量"].ToString() == "" || Convert.ToDecimal(listInfo.Rows[i]["收货数量"]) == 0) { listInfo.Rows[i]["收货数量"] = listInfo.Rows[i]["发货数量"]; } } //删除明细 if (!DeleteList(dataContext, maneuverBill.Bill_ID, out error)) { throw new Exception(error); } //添加明细 if (!InsertList(dataContext, maneuverBill.Bill_ID, listInfo, out error)) { throw new Exception(error); } dataContext.SubmitChanges(); for (int i = 0; i < listInfo.Rows.Count; i++) { Out_DetailAccount lnqDetail = new Out_DetailAccount(); lnqDetail.Bill_ID = lnqBill.Bill_ID; lnqDetail.BillFinishTime = ServerTime.Time; lnqDetail.Confirmor = lnqBill.Confirmor; lnqDetail.GoodsID = Convert.ToInt32(listInfo.Rows[i]["物品ID"]); lnqDetail.OperationCount = Convert.ToDecimal(listInfo.Rows[i]["收货数量"]); lnqDetail.Proposer = lnqBill.Proposer; lnqDetail.Remark = listInfo.Rows[i]["备注"].ToString(); lnqDetail.SecStorageID = lnqBill.InStorageID; lnqDetail.StorageID = listInfo.Rows[i]["账务库房ID"].ToString(); //操作外部业务明细与库存 if (!m_serverBusiness.OperationDetailAndStock(dataContext, lnqDetail, out error)) { throw new Exception(error); } } dataContext.SubmitChanges(); if (!InsertProductStock(dataContext, lnqBill.Bill_ID, out error)) { throw new Exception(error); } break; default: break; } } else { error = "数据重复或者为空"; throw new Exception(error); } dataContext.SubmitChanges(); dataContext.Transaction.Commit(); return(true); } catch (Exception ex) { dataContext.Transaction.Rollback(); error = ex.Message; return(false); } }