public void EditOrder(OrderEditDto orderEditDto, bool changeOneToMany = false) { if (changeOneToMany) { List <OrderBox> orderBoxes = SnHelper.GetListboxNumber(orderEditDto.SnMin, orderEditDto.OnLineQuantity).Select(item => new OrderBox() { //设置外键Id OrderId = orderEditDto.OrderId, //盒号 BoxNumber = item, //新建时间 OrderBoxCreateTime = DateTime.Now }).ToList(); var editEntity = _mapper.Map <OrderPlacing>(orderEditDto); //editEntity.OrderBoxes = orderBoxes; _orderBoxRepository.DelOrderBox(editEntity.OrderId); _orderBoxRepository.AddOrderAllBoxes(orderBoxes); _orderRepository.Update(editEntity); _unitOfWork.SaveChanges(); } else { var editEntity = _mapper.Map <OrderPlacing>(orderEditDto); _orderRepository.Update(editEntity); _unitOfWork.SaveChanges(); } }
/// <summary> /// 初始管号 回车 显示当前订单 最后一个SN号 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SnMinTxtBox_KeyDown(object sender, KeyEventArgs e) { if (this.SnMinTxtBox.Text.Length < 8) { MessageBox.Show("请输入正确的SN,sn长度有问题"); return; } if (e.KeyCode == Keys.Enter) { //界面显示此次订单最大SN 以便核对 this.lbSnMax.Text = SnHelper.SNlast(this.SnMinTxtBox.Text, Convert.ToInt32(this.OnlineQuantityTxtBox.Text)); } }
/// <summary> /// 初始管号 回车 显示当前订单 最后一个SN号 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SnMinTxtBox_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { //界面显示此次订单最大SN 以便核对 this.SnMaxTxtBox.Text = SnHelper.SnLast(this.SnMinTxtBox.Text, Convert.ToInt32(this.OnlineQuantityTxtBox.Text)); //修改时 程序更改序列号 数据绑定没生效 在此赋值一下 if (_orderEdit != null) { _orderEdit.SnMax = this.SnMaxTxtBox.Text; } } }
//数量变化时 自动更新最后一个SN private void OnlineQuantityTxtBox_TextChanged(object sender, EventArgs e) { //确保序列号是OK的 if (RegexHelper.RegSn.IsMatch(this.SnMinTxtBox.Text)) { //界面显示此次订单最大SN 以便核对 this.SnMaxTxtBox.Text = SnHelper.SnLast(this.SnMinTxtBox.Text, Convert.ToInt32(this.OnlineQuantityTxtBox.Text)); //修改时 程序更改序列号 数据绑定没生效 在此赋值一下 if (_orderEdit != null) { _orderEdit.SnMax = this.SnMaxTxtBox.Text; } } }
private void tb_SN_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (this.tb_SN_Init.Text.Length <= 12) { MessageBox.Show("扫描到的序列号有问题!,小于12位,请手动输入!"); this.tb_SN_Init.SelectAll(); return; } this.tb_SN_Last.Text = SnHelper.SnLast(this.tb_SN_Init.Text, 50); btnSearchStart_Click(null, null); } }
private void textBox_PlanNo_Last_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { var planId = this.textBox_PlanNo_Last.Text.Trim(); using (_dbcontext = new FlowManageSystemEntities()) { orderRepositoy = new OrderRepository(_dbcontext); if (!orderRepositoy.PlanNoExist(planId)) { MessageBox.Show("计划单号不存在,请输入正确的单号!!!"); return; } var order = orderRepositoy.getOrderByPlanNo(planId); var snMin = order.SnMin; var snMax = order.SnMax; var needDo = order.OnLineQuantity; //根据SN范围查询已经做了测试的 using (_opwayDbContext = new ATSDATABASEEntities()) { opwayDataRepository = new OpwayDataRepository(_opwayDbContext); //拿到已做的数量更新界面 var count = 0; if (this.cBox_LastUndo.Checked == true) { var listFinishedSn = opwayDataRepository.GetLastTestFinishedSN(snMin, snMax); var AllList = SnHelper.GetSnlist(snMin, needDo); count = listFinishedSn.Count(); //更新界面未做的SN this.ltBox_LastUndo.DataSource = AllList.Except(listFinishedSn).ToList(); } else { count = opwayDataRepository.GetLastTestCount(snMin, snMax); } this.lbLastTestFinished.Text = count.ToString(); } } } }
public void AddOrder(OrderAddDto orderAddDto) { List <OrderBox> orderBoxes = SnHelper.GetListboxNumber(orderAddDto.SnMin, orderAddDto.OnLineQuantity).Select(item => new OrderBox() { //设置外键Id OrderId = orderAddDto.OrderId, //盒号 BoxNumber = item, //新建时间 OrderBoxCreateTime = DateTime.Now }).ToList(); var newEntity = _mapper.Map <OrderPlacing>(orderAddDto); newEntity.OrderBoxes = orderBoxes; _orderRepository.Insert(newEntity); _unitOfWork.SaveChanges(); ; }
/// <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); } } }
private void btnSearchStart_Click(object sender, EventArgs e) { if (this.tb_SN_Init.Text.Length <= 12) { MessageBox.Show("扫描到的序列号有问题!,小于12位,请手动输入!"); this.tb_SN_Init.SelectAll(); return; } var snMin = this.tb_SN_Init.Text.Trim(); var snMax = this.tb_SN_Last.Text.Trim(); var allSnList = SnHelper.GetSnlist(snMin, snMax); this.listLost.DataSource = null; dgvOPWAYData.DataSource = null; var strQuery = $"SELECT [SN] FROM [ATSDATABASE].[dbo].[OPWAYDATA] as [A] WHERE [A].[SN] BETWEEN '{snMin}' AND '{snMax}'"; //表格展示 if (chb_dgv.Checked == true) { strQuery = $"SELECT * FROM [ATSDATABASE].[dbo].[OPWAYDATA] as [A] WHERE [A].[SN] BETWEEN '{snMin}' AND '{snMax}'"; } if (rdoTest.Checked) // 测试数据查询 { strQuery += " AND [A].[EMM] !=''"; } else //调试数据 { strQuery += " AND [A].[EMM] =''"; } if (chb_Result.Checked == true) { strQuery += " AND [A].[PF] = 'PASS'"; } if (cbx_TakeLastSN.Checked == true) { //SELECT [SN] FROM OPWAYDATA as A WHERE SN BETWEEN 'OP19030502001' AND 'OP19030504000' AND EMM !='' AND PF = 'PASS' AND A.DataId= (SELECT MAX(DataId) FROM OPWAYDATA as B WHERE B.SN = A.SN) strQuery += " AND [A].[DataId]= (SELECT MAX([DataId]) FROM [ATSDATABASE].[dbo].[OPWAYDATA] as [B] WHERE [B].[SN] = [A].[SN])"; } using (_opwayDbContext = new GwContext()) { List <string> snList; if (chb_dgv.Checked == true) { var list = _opwayDbContext.Database.SqlQuery <OPWAYDATA>(strQuery).ToList(); dgvOPWAYData.DataSource = list; snList = list.Select(o => o.SN).ToList(); } else { snList = _opwayDbContext.Database.SqlQuery <string>(strQuery).ToList(); } //更新界面数字 this.tb_Result.Text = snList.Count().ToString(); if (chb_lost.Checked == true) { var list = allSnList.Except(snList).ToList(); this.txtcount.Text = list.Count().ToString() + "个"; this.listLost.DataSource = list; } } }