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); //切换到入库单录入页面 } } }
private void DetailTextBoxToModel(TPurchasePlanDetail tinfo) { MMS_PurchasePlanDetail detail = tinfo.DetDetail; detail.PurchaseBillCode = txtPurchasePlanBillCode.Text; //入库单号 detail.ProductCode = txtProductCode.Text; //货品代码 detail.Memo = txtComm.Text; //手写备注 if (!string.IsNullOrEmpty(txtQuantity.Text)) //数量 { detail.Quantity = Convert.ToInt32(txtQuantity.Text); } detail.Price = Convert.ToDouble(txtPrice.Text.ToString().Trim()); detail.AuditAccount = FindListAuditUser(txtProductCode.Text.ToString()).ToString(); }
private void ModelToDetailTextBox(TPurchasePlanDetail tinfo) { //调用业务层方法取货品信息实体 MMS_MaterialInfo Material = MaterialInfoService.Instance.GetProductInfoByCode(tinfo.DetDetail.ProductCode); // MMS_ProductInfo product = ProductInfoService.Instance.GetProductInfoByCode(tinfo.DetDetail.ProductCode); MMS_PurchasePlanDetail detail = tinfo.DetDetail; txtProductCode.Text = detail.ProductCode; //货品代码 txtShortName.Text = Material.Material_Name; //货品简称 txtSpecs.Text = Material.Material_Specification; //规格 ddlUnit.Text = Material.Material_Unit; //计量单位 txtVendor.Text = Material.Material_Supplier; //供应商 txtQuantity.Text = detail.Quantity.ToString(); //数量 txtComm.Text = detail.Memo.ToString(); // txtPrice.Text = hidPrice.Value.ToString(); }
/// <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); }
/// <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); }