public async Task <string> VerifyForCollection(OrderPlacing order, int storageNumber) { //数据库记录的已经入库的数量 var dbCount = order.OrderStorageCount; //订单要做的数量 var count = order.OnLineQuantity; //理想情况下 入库完后的数量 var planCount = storageNumber + dbCount; //入库数量不能大于订单要求做的数量 if (planCount > count) { return(await Task.FromResult("当前订单数量: " + count + $" 已入库数量:{dbCount} 本次入库数量:" + storageNumber + "请核实!")); } var snMin = order.SnMin; var snMax = order.SnMax; if (_opwayDataRepository.GetLastTestCount(snMin, snMax) < planCount) { return(await Task.FromResult("本次入库数量不能大于终测通过的数量!!!")); } return(string.Empty); }
//修改时进入这个窗体 查询也进入 public FrmOrderAddOrModify(OrderPlacing orderPlacing, bool modify = true) { InitializeComponent(); initData(); this._orderPlacing = orderPlacing; beforModifyCount = orderPlacing.OnLineQuantity; beforModifySnMin = orderPlacing.SnMin; if (modify) { Modify = true; this.Text = "订单修改"; this.btnOrder.Text = "确认修改"; } else { this.Text = "订单查询"; this.btnOrder.Enabled = false; this.btnClear.Enabled = false; } //设置界面绑定 this.OrderDateTimePic.DataBindings.Add("Text", orderPlacing, "OrderDate"); this.TypeTxtBox.DataBindings.Add("Text", orderPlacing, "Type"); this.PlanNoTxtBox.DataBindings.Add("Text", orderPlacing, "PlanNo"); this.FinishedProductNocBox.DataBindings.Add("Text", orderPlacing, "FinishedProductNo"); this.ProductTypecBox.DataBindings.Add("Text", orderPlacing, "ProductTypeNo"); this.OnlineQuantityTxtBox.DataBindings.Add("Text", orderPlacing, "OnLineQuantity"); this.SnMinTxtBox.DataBindings.Add("Text", orderPlacing, "SnMin"); this.SnMaxTxtBox.DataBindings.Add("Text", orderPlacing, "SnMax"); this.LableRequireTxtBox.DataBindings.Add("Text", orderPlacing, "LabelingRequirements"); this.TestReportTxtBox.DataBindings.Add("Text", orderPlacing, "TestReport"); this.CodingRequireTxtBox.DataBindings.Add("Text", orderPlacing, "CodingRequirements"); this.PackingRequireTxtBox.DataBindings.Add("Text", orderPlacing, "PackingRequirement"); this.SpecialRequireTxtBox.DataBindings.Add("Text", orderPlacing, "SpecialRequirement"); this.TestSoftConfigFIleTxtBox.DataBindings.Add("Text", orderPlacing, "TestSoftConfigFile"); this.RemarkTxtBox.DataBindings.Add("Text", orderPlacing, "Remark"); this.CustonRequireTimePic.DataBindings.Add("Text", orderPlacing, "CustomDemandDate"); this.PlanOnlineTimePic.DataBindings.Add("Text", orderPlacing, "PlannedLaunchDate"); this.PlanStorageTimePic.DataBindings.Add("Text", orderPlacing, "PlanStorageDate"); this.ProductDaysTxtBox.DataBindings.Add("Text", orderPlacing, "DaysOfProduction"); }
public async Task <string> VerifyForCollection(OrderPlacing order, int collectionNumber) { var onlineCount = order.OnLineQuantity; //当前已经领取数量 var hasCount = order.OrderCollectionCount; //现在领取后的数量大于 订单计划做的数量 不允许 if (onlineCount < (hasCount + collectionNumber)) { return(await Task.FromResult("领取物料后的数量 怎么能大于下单数量呢?请核对")); } return(string.Empty); }
/// <summary> /// 生成订单和 对应的盒号 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnOrder_Click(object sender, EventArgs e) { try { using (_dbcontext = new FlowManageSystemEntities()) { orderRepositoy = new OrderRepository(_dbcontext); orderBoxRepository = new OrderBoxRepository(_dbcontext); OrderPlacing orderPlacing = new OrderPlacing() { OrderDate = Convert.ToDateTime(this.OrderDateTimePic.Text), Type = this.TypeTxtBox.Text, PlanNo = this.PlanNoTxtBox.Text, FinishedProductNo = this.FinishedProductNocBox.Text, ProductTypeNo = this.ProductTypecBox.Text, OnLineQuantity = Convert.ToInt32(this.OnlineQuantityTxtBox.Text), SnMin = SnMinTxtBox.Text, SnMax = SnMinTxtBox.Text, LabelingRequirements = this.LableRequireTxtBox.Text, TestReport = this.TestReportTxtBox.Text, CodingRequirements = this.CodingRequireTxtBox.Text, PackingRequirement = this.PackingRequireTxtBox.Text, SpecialRequirement = this.SpecialRequireTxtBox.Text, TestSoftConfigFile = this.TestSoftConfigFIleTxtBox.Text, Remark = this.RemarkTxtBox.Text, CustomDemandDate = Convert.ToDateTime(this.CustonRequireTimePic.Text), PlannedLaunchDate = Convert.ToDateTime(this.PlanOnlineTimePic.Text), PlanStorageDate = Convert.ToDateTime(this.PlanStorageTimePic.Text), DaysOfProduction = Convert.ToByte(this.ProductDaysTxtBox.Text), OrderCreateTime = DateTime.Now }; //注意此处一对多关联数据的保存 设置关联 IEnumerable <OrderBox> orderBoxes = SnHelper.GetListboxNumber(this.SnMinTxtBox.Text, Convert.ToInt32(this.OnlineQuantityTxtBox.Text)).Select(item => new OrderBox() { //设置导航属性 OrderPlacing = orderPlacing, //设置外键Id OrderId = orderPlacing.OrderId, //盒号 BoxNumber = item, //新建时间 OrderBoxCreateTime = DateTime.Now }); //添加所有 多的 一端数据 orderBoxRepository.AddOrderAllBoxes(orderBoxes); //添加 一的 一端数据 //下单 orderRepositoy.AddOrder(orderPlacing); //一对多的数据一起保存 两个仓储公用一个dbcontext 可以防止添加部分失败 会以一个事务的形式保存 _dbcontext.SaveChanges(); MessageBox.Show("下单成功!"); } } catch (Exception ex) { MessageBox.Show("下单失败,请检查数据" + ex.Message); } }
/// <summary> /// 生成订单和 对应的盒号 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnOrder_Click(object sender, EventArgs e) { //此时是修改 重复的绑值太恶心了 用数据绑定 if (Modify) { var unitOfWork = new UnitOfWork(); var orderBoxService = new OrderBoxService(unitOfWork, unitOfWork.OrderBoxRepository); var orderService = new OrderService(unitOfWork, unitOfWork.OrderRepository); //判断是否修改了订单数量 修改了 删除盒号 重新生成 if ((beforModifyCount != _orderPlacing.OnLineQuantity) || (beforModifySnMin != _orderPlacing.SnMin)) { //生成订单盒 注意此处一对多关联数据的保存 设置关联 IEnumerable <OrderBox> orderBoxes = SnHelper.GetListboxNumber(this.SnMinTxtBox.Text, Convert.ToInt32(this.OnlineQuantityTxtBox.Text)).Select(item => new OrderBox() { //设置导航属性 OrderPlacing = _orderPlacing, //设置外键Id OrderId = _orderPlacing.OrderId, //盒号 BoxNumber = item, //新建时间 OrderBoxCreateTime = DateTime.Now }); try { //添加所有 多的 一端数据 orderBoxService.AddOrderBoxAfterDel(_orderPlacing.OrderId, orderBoxes); } catch (Exception ex) { MessageBox.Show(ex.Message); } } try { orderService.UpdateOrder(_orderPlacing); MessageBox.Show("修改成功!"); this.Dispose(); } catch (Exception ex) { MessageBox.Show(ex.Message); } #region old //using (_dbcontext = new FlowManageSystemEntities()) //{ // orderRepositoy = new OrderRepository(_dbcontext); // //判断是否修改了订单数量 修改了 删除盒号 重新生成 // if ((beforModifyCount != _orderPlacing.OnLineQuantity) || (beforModifySnMin != _orderPlacing.SnMin)) // { // orderBoxRepository = new OrderBoxRepository(_dbcontext); // //生成订单盒 // //注意此处一对多关联数据的保存 设置关联 // IEnumerable<OrderBox> orderBoxes = SnHelper.GetListboxNumber(this.SnMinTxtBox.Text, Convert.ToInt32(this.OnlineQuantityTxtBox.Text)).Select(item => new OrderBox() // { // //设置导航属性 // OrderPlacing = _orderPlacing, // //设置外键Id // OrderId = _orderPlacing.OrderId, // //盒号 // BoxNumber = item, // //新建时间 // OrderBoxCreateTime = DateTime.Now // }); // //添加所有 多的 一端数据 // orderBoxRepository.AddOrderBoxAfterDel(_orderPlacing.OrderId, orderBoxes); // } // if (orderRepositoy.Edit(_orderPlacing) != 0) // { // MessageBox.Show("修改成功!"); // this.Dispose(); // } //} #endregion } else { try { var unitOfWork = new UnitOfWork(); var orderBoxService = new OrderBoxService(unitOfWork, unitOfWork.OrderBoxRepository); var orderService = new OrderService(unitOfWork, unitOfWork.OrderRepository); OrderPlacing orderPlacing = new OrderPlacing() { OrderDate = Convert.ToDateTime(this.OrderDateTimePic.Text), Type = this.TypeTxtBox.Text, PlanNo = this.PlanNoTxtBox.Text, FinishedProductNo = this.FinishedProductNocBox.Text, ProductTypeNo = this.ProductTypecBox.Text, OnLineQuantity = Convert.ToInt32(this.OnlineQuantityTxtBox.Text), SnMin = SnMinTxtBox.Text, SnMax = this.SnMaxTxtBox.Text, LabelingRequirements = this.LableRequireTxtBox.Text, TestReport = this.TestReportTxtBox.Text, CodingRequirements = this.CodingRequireTxtBox.Text, PackingRequirement = this.PackingRequireTxtBox.Text, SpecialRequirement = this.SpecialRequireTxtBox.Text, TestSoftConfigFile = this.TestSoftConfigFIleTxtBox.Text, Remark = this.RemarkTxtBox.Text, CustomDemandDate = Convert.ToDateTime(this.CustonRequireTimePic.Text), PlannedLaunchDate = Convert.ToDateTime(this.PlanOnlineTimePic.Text), PlanStorageDate = Convert.ToDateTime(this.PlanStorageTimePic.Text), DaysOfProduction = Convert.ToByte(this.ProductDaysTxtBox.Text), OrderCreateTime = DateTime.Now, StorageFinishedFlag = "0" }; if (orderService.PlanNoExist(this.PlanNoTxtBox.Text.Trim())) { MessageBox.Show("当前计划单号" + this.PlanNoTxtBox.Text + "数据库已存在"); this.PlanNoTxtBox.Select(); return; } //注意此处一对多关联数据的保存 设置关联 IEnumerable <OrderBox> orderBoxes = SnHelper.GetListboxNumber(this.SnMinTxtBox.Text, Convert.ToInt32(this.OnlineQuantityTxtBox.Text)).Select(item => new OrderBox() { //设置导航属性 OrderPlacing = orderPlacing, //设置外键Id OrderId = orderPlacing.OrderId, //盒号 BoxNumber = item, //新建时间 OrderBoxCreateTime = DateTime.Now }); //添加所有 多的 一端数据 orderBoxService.AddOrderAllBoxes(orderBoxes); //添加 一的 一端数据 //下单 orderService.InsertOrder(orderPlacing); ////一对多的数据一起保存 两个仓储公用一个dbcontext 可以防止添加部分失败 会以一个事务的形式保存 //_dbcontext.SaveChanges(); this.lbInfo.Text = orderPlacing.PlanNo + "下单成功!"; btnClear_Click(null, null); #region old //using (_dbcontext = new FlowManageSystemEntities()) //{ // orderRepositoy = new OrderRepository(_dbcontext); // orderBoxRepository = new OrderBoxRepository(_dbcontext); // OrderPlacing orderPlacing = new OrderPlacing() // { // OrderDate = Convert.ToDateTime(this.OrderDateTimePic.Text), // Type = this.TypeTxtBox.Text, // PlanNo = this.PlanNoTxtBox.Text, // FinishedProductNo = this.FinishedProductNocBox.Text, // ProductTypeNo = this.ProductTypecBox.Text, // OnLineQuantity = Convert.ToInt32(this.OnlineQuantityTxtBox.Text), // SnMin = SnMinTxtBox.Text, // SnMax = this.SnMaxTxtBox.Text, // LabelingRequirements = this.LableRequireTxtBox.Text, // TestReport = this.TestReportTxtBox.Text, // CodingRequirements = this.CodingRequireTxtBox.Text, // PackingRequirement = this.PackingRequireTxtBox.Text, // SpecialRequirement = this.SpecialRequireTxtBox.Text, // TestSoftConfigFile = this.TestSoftConfigFIleTxtBox.Text, // Remark = this.RemarkTxtBox.Text, // CustomDemandDate = Convert.ToDateTime(this.CustonRequireTimePic.Text), // PlannedLaunchDate = Convert.ToDateTime(this.PlanOnlineTimePic.Text), // PlanStorageDate = Convert.ToDateTime(this.PlanStorageTimePic.Text), // DaysOfProduction = Convert.ToByte(this.ProductDaysTxtBox.Text), // OrderCreateTime = DateTime.Now, // StorageFinishedFlag = "0" // }; // if (orderRepositoy.PlanNoExist(this.PlanNoTxtBox.Text.Trim())) // { // MessageBox.Show("当前计划单号" + this.PlanNoTxtBox.Text + "数据库已存在"); // this.PlanNoTxtBox.Select(); // return; // } // //注意此处一对多关联数据的保存 设置关联 // IEnumerable<OrderBox> orderBoxes = SnHelper.GetListboxNumber(this.SnMinTxtBox.Text, Convert.ToInt32(this.OnlineQuantityTxtBox.Text)).Select(item => new OrderBox() // { // //设置导航属性 // OrderPlacing = orderPlacing, // //设置外键Id // OrderId = orderPlacing.OrderId, // //盒号 // BoxNumber = item, // //新建时间 // OrderBoxCreateTime = DateTime.Now // }); // //添加所有 多的 一端数据 // orderBoxRepository.AddOrderAllBoxes(orderBoxes); // //添加 一的 一端数据 //下单 // orderRepositoy.AddOrder(orderPlacing); // //一对多的数据一起保存 两个仓储公用一个dbcontext 可以防止添加部分失败 会以一个事务的形式保存 // _dbcontext.SaveChanges(); // this.lbInfo.Text = orderPlacing.PlanNo + "下单成功!"; // btnClear_Click(null, null); //} #endregion } catch (Exception ex) { MessageBox.Show("下单失败,请检查数据是否符合规范" + ex.Message); } } }