/// <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 ctx = CommentParameter.DepotDataContext; try { var varData = from a in ctx.WS_ConsumptionBill where a.BillNo == billNo select a; if (varData.Count() != 1) { throw new Exception("数据不唯一"); } else { WS_ConsumptionBill tempBill = varData.Single(); if (tempBill.BillStatus == ConsumptionBillStatus.单据已完成.ToString()) { throw new Exception("单据已完成,无法删除"); } if (tempBill.Proposer != BasicInfo.LoginName) { throw new Exception("只有申请人本人才能删除单据"); } } ctx.WS_ConsumptionBill.DeleteAllOnSubmit(varData); IWorkShopProductCode serverProductCode = ServerModuleFactory.GetServerModule <IWorkShopProductCode>(); serverProductCode.DeleteProductCodeDetail(ctx, billNo); ctx.SubmitChanges(); return(true); } catch (Exception ex) { error = ex.Message; return(false); } }
/// <summary> /// 单据明细操作 /// </summary> /// <param name="ctx">数据上下文</param> /// <param name="billNo">单据号</param> /// <param name="list">单据明细</param> void ListControl(DepotManagementDataContext ctx, WS_CannibalizeBill billInfo, List <WS_CannibalizeWSCode> listCannibalizeWSCode, DataTable list) { try { var varData = from a in ctx.WS_CannibalizeList where a.BillNo == billInfo.BillNo select a; ctx.WS_CannibalizeList.DeleteAllOnSubmit(varData); IWorkShopProductCode serverProductCode = ServerModuleFactory.GetServerModule <IWorkShopProductCode>(); foreach (DataRow dr in list.Rows) { WS_CannibalizeList tempList = new WS_CannibalizeList(); tempList.BillNo = billInfo.BillNo; tempList.BatchNo = dr["批次号"].ToString(); tempList.GoodsID = Convert.ToInt32(dr["物品ID"]); tempList.OperationCount = Convert.ToDecimal(dr["数量"]); tempList.Remark = dr["备注"].ToString(); foreach (WS_CannibalizeWSCode item in listCannibalizeWSCode) { if (!serverProductCode.CheckProductCodeCount(billInfo.BillNo, item.WSCode, tempList.GoodsID, item.OperationType, Convert.ToDecimal(dr["数量"]))) { throw new Exception(UniversalFunction.GetGoodsMessage(tempList.GoodsID) + " 产品编码数量与操作数量不一致"); } } if (list.Select(" 物品ID = " + tempList.GoodsID + " AND 批次号 = '" + tempList.BatchNo + "'").Length > 1) { throw new Exception(UniversalFunction.GetGoodsMessage(tempList.GoodsID) + "【批次号】:" + tempList.BatchNo + "数据重复,请重新核对"); } ctx.WS_CannibalizeList.InsertOnSubmit(tempList); } } catch (Exception ex) { throw new Exception(ex.Message); } }