/// <summary> /// 审核退回 /// </summary> /// <param name="id"> </param> /// <param name="isAudit"> </param> /// <returns> </returns> public bool AuditReturnPurchasePlan(int id, bool isAudit, string operatorCode) { try { TPurchasePlan TPlan = dao.GetPurchasePlan(id); //调用数据访问层方法取采购计划单 if (TPlan.Content.AuditFlag == true) { throw new Exception("该计划已生成订单,不能重复生成订单"); } if (operatorCode == "end") { TPlan.Content.PayMode = "4"; //二级退回标识 } else { TPlan.Content.PayMode = "3"; //一级退回标识 } dao.UpdateInfo(TPlan.Content); } catch (Exception ex) { throw new Exception(ex.Message); } return(true); }
private void LoadData() { TPurchasePlan infoList = _TPurchasePlan; //调用业务层返回货品信息列表 List <MMS_MaterialInfo> productList = MaterialInfoService.Instance.GetAllInfo(); //调用业务层返回字典信息列表 List <Base_DictionaryInfo> dictList = DictionaryInfoService.Instance.GetAllInfo(); //将入库单货品与货品信息、字典保关联 var query = from info in infoList.Detail where info.OprType != OperateType.otDelete join product in productList on info.DetDetail.ProductCode equals product.Material_ID.ToString() select new { Id = info.DetDetail.ID, info.DetDetail.PurchaseBillCode, product.Material_ID, product.Material_Name, product.Material_Specification, product.Material_Supplier, Unit = product.Material_Unit, info.DetDetail.Quantity, info.DetDetail.CheckQuantity, info.DetDetail.Price, Amount = info.DetDetail.Quantity * info.DetDetail.Price, info.DetDetail.Memo }; dgvInfo.DataKeyNames = new[] { "Id" }; //设置GridView数据主键 dgvInfo.DataSource = query.ToList(); //设置GridView数据源 dgvInfo.DataBind(); //计算数量及金额汇总信息 lblTotalQuantity.Text = infoList.Detail.Sum(itm => itm.DetDetail.Quantity).ToString("#"); // lblTotalAmount.Text = infoList.Detail.Sum(itm => itm.DetDetail.Quantity*itm.DetDetail.Price).ToString("#.##"); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindDict("Unit", ddlUnit); //将计量单位下拉框绑定字典 if (Request.QueryString["ID"] == null) //入库单录入页面 { _TPurchasePlan = null; ClearTextBox(); //清除入库单相关服务器控件的内容 } else //入库单修改页面 { id = Request.QueryString["ID"]; //调用业务规则层-入库单服务类方法获得要修改的实体 _TPurchasePlan = PurchasePlanService.Instance.GetPurchasePlan(Convert.ToInt32(id)); ModelToTextBox(_TPurchasePlan); //将入库单实体赋值给对应的服务器控件 } LoadData(); //加载GridView数据 EntryDetailInputPage(false); //切换到入库单页面 if (Request.QueryString["Audit"] != null || Request.QueryString["Query"] != null) { SetReadOnly(); //如果是审核或查询页面调用的,设置所有输入控件只读 } // lblOperator.Text = LoginManager.GetUserName(Context.User.Identity.Name); } }
private void ModelToTextBox(TPurchasePlan info) { if (!string.IsNullOrEmpty(info.Content.Provider)) //供应商 { //hidProvider.Value = info.Content.Provider; Base_ClientInfo tempClient = ClientInfoService.Instance.GetClientInfoByCode(info.Content.Provider); if (tempClient != null) { //txtProviderName.Text = tempClient.ShortName; //hidProviderName.Value = tempClient.ShortName; } } txtPurchasePlanBillCode.Text = info.Content.PurchaseBillCode; //入库单号 txtPurchasePlanDate.Text = info.Content.PurchaseDate.ToString(); //入库日期 txtDeptName.Text = info.Content.DeptName; lblOperator.Text = user_idao.GetUserInfo(info.Content.Operator).Rows[0]["User_Name"].ToString(); //if (!string.IsNullOrEmpty(info.Content.CheckMan)) //经办人 //{ // //hidPurchaseMan.Value = info.Content.CheckMan; // //EmployeeInfo tempEmployee = EmployeeInfoService.Instance.GetEmployeeInfoByCode(info.Content.CheckMan); // //if (tempEmployee != null) // //{ // // txTPurchasePlanManName.Text = tempEmployee.Name; // // hidPurchaseManName.Value = tempEmployee.Name; // //} //} }
/// <summary> /// 保存采购计划 /// </summary> /// <param name="obj"> 自定义采购计划实体 </param> /// <returns> 计划主表ID号 </returns> public int SavePurchasePlan(TPurchasePlan obj) { if (obj.Content.ID != null && obj.Content.ID > 0) { MMS_PurchasePlanContent content = dao.GetInfo(obj.Content.ID); if (content.AuditFlag == true) { throw new Exception("该单据已经审核" + content.PurchaseBillCode); } } return(dao.SavePurchasePlan(obj)); }
private void TextBoxToModel(TPurchasePlan info) { info.Content.AuditFlag = false; //info.Content.InvoiceCode = txtInvoiceCode.Text; //info.Content.Provider = hidProvider.Value; info.Content.PurchaseBillCode = txtPurchasePlanBillCode.Text; if (!string.IsNullOrEmpty(txtPurchasePlanDate.Text)) { info.Content.PurchaseDate = Convert.ToDateTime(txtPurchasePlanDate.Text); } //info.Content.CheckMan = hidPurchaseMan.Value; }
protected void btnOK_Click(object sender, EventArgs e) { if (Convert.ToDecimal(txtUseQuantity.Text.ToString()) >= Convert.ToDecimal(txtQuantity.Text.ToString().Trim())) { TPurchasePlan info = _TPurchasePlan; if (string.IsNullOrEmpty(detailId)) //插入操作 { //创建入库货品实例 TPurchasePlanDetail tinfoDetail = new TPurchasePlanDetail(); tinfoDetail.DetDetail = new MMS_PurchasePlanDetail(); if (info.Detail.Count > 0) //新插入的以-1开始,以后渐减 { //设置新录入入库货品的主键ID,以-1开始,以后渐减 int minId = info.Detail.Min(itm => itm.DetDetail.ID); if (minId < 0) { tinfoDetail.DetDetail.ID = minId - 1; } else { tinfoDetail.DetDetail.ID = -1; } } else //该入库单没有货品信息 { tinfoDetail.DetDetail.ID = -1; } DetailTextBoxToModel(tinfoDetail); //将入库货品赋值给实体 tinfoDetail.OprType = OperateType.otInsert; info.Detail.Add(tinfoDetail); //将操作实体添加到入库货品集合中 _TPurchasePlan = info; ClearDetailTextBox(); //清除入库货品服务器控件内容 LoadData(); //加载Gridview数据 } else //编辑操作 { //根据入库货品ID取实体 TPurchasePlanDetail tinfoDetail = info.Detail.First(itm => itm.DetDetail.ID == Convert.ToInt32(detailId)); DetailTextBoxToModel(tinfoDetail); //将服务器控件赋给实体 if (tinfoDetail.OprType != OperateType.otInsert) //如果是新插入的仍保留插入状态 { tinfoDetail.OprType = OperateType.otUpdate; } _TPurchasePlan = info; LoadData(); //加载GridView数据 EntryDetailInputPage(false); //切换到入库单录入页面 } } }
/// <summary> /// 保存采购计划单组合实体 /// </summary> /// <param name="obj"> 实体id号 </param> /// <returns> 自定义组合实体 </returns> public int SavePurchasePlan(TPurchasePlan obj) { if (obj.OprType == OperateType.otInsert) //传入的是插入操作标志 { dc.MMS_PurchasePlanContent.InsertOnSubmit(obj.Content); //执行插入操作 } else if (obj.OprType == OperateType.otUpdate) //传入的是修改操作标志 { var query = from item in dc.MMS_PurchasePlanContent where item.ID == obj.Content.ID select item; BatchEvaluate.Eval(obj.Content, query.First()); //调用Eval方法进行实体间赋值 } else if (obj.OprType == OperateType.otDelete) //传入的是删除操作标志 { dc.MMS_PurchasePlanContent.DeleteOnSubmit(obj.Content); //执行删除操作 } foreach (TPurchasePlanDetail item in obj.Detail) //遍历采购计划货品明细 { if (item.OprType == OperateType.otInsert) //传入的是插入操作标志 { dc.MMS_PurchasePlanDetail.InsertOnSubmit(item.DetDetail); //执行插入操作 } else if (item.OprType == OperateType.otUpdate) //传入的是修改操作标志 { var query = from itm in dc.MMS_PurchasePlanDetail where itm.ID == item.DetDetail.ID select itm; BatchEvaluate.Eval(item.DetDetail, query.First()); //执行修改操作 } else if (item.OprType == OperateType.otDelete) //传入的是删除操作标志 { dc.MMS_PurchasePlanDetail.DeleteOnSubmit(item.DetDetail); //执行删除操作 } } try { dc.SubmitChanges(ConflictMode.ContinueOnConflict); //最后提交操作 } catch (ChangeConflictException e) { foreach (ObjectChangeConflict occ in dc.ChangeConflicts) { occ.Resolve(RefreshMode.KeepChanges); } } return(obj.Content.ID); //返回新添加计划单的主键值 }
/// <summary> /// 审核采购计划 /// </summary> /// <param name="id"> </param> /// <param name="isAudit"> </param> /// <returns> </returns> public bool AuditPurchasePlan(int id, bool isAudit, string operatorCode) { try { TPurchasePlan TPlan = dao.GetPurchasePlan(id); //调用数据访问层方法取采购计划单 if (TPlan.Content.AuditFlag == true) { throw new Exception("该计划已生成订单,不能重复生成订单"); } if (TPlan.Detail.Count > 0) { foreach (TPurchasePlanDetail d in TPlan.Detail) { if (d.DetDetail.AuditAccount == RequestSession.GetSessionUser().UserAccount.ToString().Trim()) { d.DetDetail.AuditResult = "1"; } dao.UpdateInfoDetail(d.DetDetail); } // auditdetail = TPlan.Detail.FindAll(p => p.DetDetail.AuditResult != "1").Count; } if (operatorCode == "end") { TPlan.Content.AuditFlag = true; } else { TPlan.Content.PayMode = "2"; } dao.UpdateInfo(TPlan.Content); } catch (Exception ex) { throw new Exception(ex.Message); } return(true); }
/// <summary> /// 根据主键值获得采购计划单组合实体 /// </summary> /// <param name="id"> 实体id号 </param> /// <returns> 自定义组合实体 </returns> public TPurchasePlan GetPurchasePlan(int id) { TPurchasePlan resu = new TPurchasePlan(); //创建采购计划单实体 resu.OprType = OperateType.otNone; //取采购计划主内容信息赋值给实体 resu.Content = dc.MMS_PurchasePlanContent.Where(itm => itm.ID == id).First(); //取采购计划货品明细信息 List <MMS_PurchasePlanDetail> tempList = dc.MMS_PurchasePlanDetail.Where(itm => itm.PurchaseBillCode == resu.Content.PurchaseBillCode).ToList(); foreach (MMS_PurchasePlanDetail item in tempList) { TPurchasePlanDetail TPlanDetail = new TPurchasePlanDetail(); TPlanDetail.OprType = OperateType.otNone; TPlanDetail.DetDetail = item; resu.Detail.Add(TPlanDetail); //将采购计划货品添加到实体的采购货品列表 } return(resu); }
public bool AuditPurchaseDetailPlan(int id, bool isAudit, string operatorCode) { try { TPurchasePlan TPlan = dao.GetPurchasePlan(id); //调用数据访问层方法取采购计划单 if (operatorCode == "end") { TPlan.Content.AuditFlag = true; } dao.UpdateInfo(TPlan.Content); } catch (Exception ex) { throw new Exception(ex.Message); } return(true); }
/// <summary> /// GridView行命令事件,点击GridView行按钮时触发的事件 /// </summary> /// <param name="sender"> </param> /// <param name="e"> </param> protected void dgvInfo_RowCommand(object sender, GridViewCommandEventArgs e) { if (!string.IsNullOrEmpty(e.CommandName)) //判断命令名是否为空 { if (e.CommandName == "Edi") //如果触发的是详细信息按钮事件 { int index = Convert.ToInt32(e.CommandArgument); //取GridView行索引 GridView grid = (GridView)e.CommandSource; //取当前操作的GridView int tempId = Convert.ToInt32(grid.DataKeys[index].Value); detailId = tempId.ToString(); TPurchasePlanDetail detail = _TPurchasePlan.Detail.FirstOrDefault(itm => itm.DetDetail.ID == tempId); ModelToDetailTextBox(detail); //将实体赋值给对应的服务器控件 EntryDetailInputPage(true); //切换到货品录入页面 } else if (e.CommandName == "Del") { int index = Convert.ToInt32(e.CommandArgument); //取GridView行索引 GridView grid = (GridView)e.CommandSource; //取当前操作的GridView int id = Convert.ToInt32(grid.DataKeys[index].Value); //取GridView主键值 TPurchasePlan temp = _TPurchasePlan; TPurchasePlanDetail tempDetail = temp.Detail.First(itm => itm.DetDetail.ID == id); if (tempDetail.OprType == OperateType.otInsert) //如果是新插入的直接将其删除 { temp.Detail.Remove(tempDetail); } else //如是不是新插入的置删除标志 { tempDetail.OprType = OperateType.otDelete; } _TPurchasePlan = temp; LoadData(); } else if (e.CommandName == "Page") { LoadData(); } } }
/// <summary> /// 自动生成采购计划 /// </summary> /// <param name="oprCode"> </param> /// <returns> </returns> public TPurchasePlan GeneralPurchasePlan(string oprCode) { TPurchasePlan tplan = new TPurchasePlan(); //创建采购计划单 //设置采购计划主信息操作类型为插入以在调用数据访问层做添加处理 tplan.OprType = OperateType.otInsert; tplan.Content = new MMS_PurchasePlanContent(); //创建采购计划单主信息 //生成采购计划单号 tplan.Content.PurchaseBillCode = BatchEvaluate.GeneralCode(); tplan.Content.PurchaseDate = DateTime.Now; //设置采购日期 tplan.Content.Provider = ""; //采购供应商 tplan.Content.PurchaseMan = ""; //采购经办人 tplan.Content.AuditFlag = false; //采购计划确认标志 //取允许采购的货品信息列表 List <MMS_ProductInfo> productList = ProductInfoService.Instance.GetAllInfo().Where(itm => itm.IsStop == null || itm.IsStop == false).ToList(); //取所有库存信息列表 List <MMS_Store> storeList = StoreService.Instance.GetAllInfo(); //用LINQ将库存信息按货品代码进行分组汇总 var query = from store in storeList group store by store.ProductCode into g orderby g.Key select new { ProductCode = g.Key, Quantity = g.Sum(itm => itm.Quantity) }; //循环遍历货品信息列表 foreach (var product in productList) { int qty = 0; if (query.Count() != 0) //取该货品的库存汇总数量 { var store = query.FirstOrDefault(itm => itm.ProductCode == product.ProductCode); if (store != null) { qty = store.Quantity; } } if (qty < product.MinStore) //如果该货品的库存汇总数量小于最低库存 { //创建采购计划货品实例 TPurchasePlanDetail tDetail = new TPurchasePlanDetail(); //设置为插入操作以便数据访问层处理 tDetail.OprType = OperateType.otInsert; tDetail.DetDetail = new MMS_PurchasePlanDetail(); tDetail.DetDetail.PurchaseBillCode = tplan.Content.PurchaseBillCode; //计划单号 tDetail.DetDetail.ProductCode = product.ProductCode; //货品代码 tDetail.DetDetail.Quantity = (product.MinStore ?? 0) - qty; //货品数量 //调用入库单服务类的GetLastPurchasePrice方法取货品单价 tDetail.DetDetail.Price = daoPur.GetLastPurchasePrice(tplan.Content.Provider, product.ProductCode); tDetail.DetDetail.Memo = ""; //注备 tplan.Detail.Add(tDetail); //将采购计划货品实体添加到采购计划单中 } } int cnt = dao.SavePurchasePlan(tplan); //调用数据访问层的保存采购计划单方法 tplan.Content.ID = cnt; //返回新生成计划单的主键值 return(tplan); }
protected void btnSave_Click(object sender, EventArgs e) { if (Page.IsValid) { TPurchasePlan info = _TPurchasePlan; if (info.Detail.Count == 0) { Response.Write("<Script>window.alert('请先录入明细信息!')</Script>"); return; } TextBoxToModel(info); if (string.IsNullOrEmpty(id)) //插入 { info.Content.Operator = RequestSession.GetSessionUser().UserId.ToString(); info.Content.PurchaseMan = FindAuditUser(info.Detail).Trim(); info.Content.PayMode = "1"; info.Content.InvoiceType = findDeptManage().Rows[0]["Organization_Address"].ToString().Trim(); // info.Content.DeptName = findDeptManage().Rows[0]["Organization_Name"].ToString().Trim(); info.Content.DeptName = txtDeptName.Text.ToString().Trim(); info.Content.OperateDate = DateTime.Now; info.OprType = OperateType.otInsert; } else //修改 { info.OprType = OperateType.otUpdate; } //再循环一次查找入库单是否有库存,解决并发领料的问题 if (info.Detail.Count > 0) { int detailqua = 0; foreach (TPurchasePlanDetail d in info.Detail) { detailqua = info.Detail.FindAll(p => p.DetDetail.ProductCode == d.DetDetail.ProductCode && p.DetDetail.Price == d.DetDetail.Price).Sum(s => s.DetDetail.Quantity); int total = storenum(d.DetDetail.ProductCode.ToString(), Convert.ToDecimal(d.DetDetail.Price)); if (total < detailqua) { // info.Detail.Remove(d); Response.Write("<Script>window.alert('物料编码为" + d.DetDetail.ProductCode + "的物料,您的领料数量:" + detailqua + "大于库存:" + total + "!')</Script>"); //Response.Write("<Script>window.alert('物料编码为" + d.DetDetail.ProductCode + "的物料,领用数量已超过库存数或此时他人已在您先一步领取!')</Script>"); return; } } } int tempId = PurchasePlanService.Instance.SavePurchasePlan(info); //PurchasePlanService.Instance.SavePurchase(info); if (tempId > 0) { _TPurchasePlan = PurchasePlanService.Instance.GetPurchasePlan(tempId); id = tempId.ToString(); ModelToTextBox(_TPurchasePlan); LoadData(); } Response.Write("<Script>window.alert('保存成功!')</Script>"); } }