/// <summary> /// 提交销退申请信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tsbtnSubmit_Click(object sender, EventArgs e) { this.dgvDrugDetailList.EndEdit(); bool flag = false; foreach (DataGridViewRow dr in this.dgvDrugDetailList.Rows) { if (Convert.ToDecimal(dr.Cells["退货数量"].Value) > 0) { flag = true; if (Convert.ToInt32(dr.Cells["dgvcmbReturnReason"].Value) == 0) { MessageBox.Show("您编辑的(" + dr.Cells["商品名称"].Value.ToString() + ")退货理由没有填写。"); dgvDrugDetailList.ClearSelection(); dgvDrugDetailList.CurrentCell = dr.Cells["dgvcmbReturnReason"]; dgvDrugDetailList.BeginEdit(false); return; } if (Convert.ToDecimal(dr.Cells["不可入库数量"].Value) > 0 && Convert.ToInt32(dr.Cells["不可入库处理办法"].Value) == 0) { MessageBox.Show("您编辑的(" + dr.Cells["商品名称"].Value.ToString() + ")不可入库处理办法没有填写。"); dgvDrugDetailList.ClearSelection(); dgvDrugDetailList.CurrentCell = dr.Cells["不可入库处理办法"]; dgvDrugDetailList.BeginEdit(false); return; } } if (Convert.ToDecimal(dr.Cells["退货数量"].Value) != Convert.ToDecimal(dr.Cells["可入库数量"].Value) + Convert.ToDecimal(dr.Cells["不可入库数量"].Value)) { MessageBox.Show("您填写的(" + dr.Cells["商品名称"].Value.ToString() + ")数量有误!\n" + "其退货数量为:" + dr.Cells[退货数量.Name].Value + "不等于可入库数量和可入库数量之和。"); dgvDrugDetailList.ClearSelection(); dr.Selected = true; return; } if (Convert.ToDecimal(dr.Cells["退货数量"].Value) < 0 || Convert.ToDecimal(dr.Cells["可入库数量"].Value) < 0 || Convert.ToDecimal(dr.Cells["不可入库数量"].Value) < 0) { MessageBox.Show("您填写的(" + dr.Cells["商品名称"].Value.ToString() + ")数量有负值!\n"); dgvDrugDetailList.ClearSelection(); dr.Selected = true; return; } Models.SalesOrderReturnDetail sord = (SalesOrderReturnDetail)dr.DataBoundItem; if (sord.IsReissue) { decimal cansaleNum = this.PharmacyDatabaseService.GetDrugInventoryRecordByCondition(out msg, sord.productName, sord.BatchNumber).Sum(r => r.CanSaleNum); if (cansaleNum < sord.ReturnAmount) { MessageBox.Show("当前库存中该药品(名称:" + sord.productName + ",批次号:" + sord.BatchNumber + ")可销售数量小于补发数量,不能执行补发操作!"); return; } } } if (!flag) { MessageBox.Show("列表中没有填写需要退货的数量,无法执行退货流程,您至少需要填写一个品种的退货数量。"); return; } try { string message; SalesOrderReturn orderReturn = new SalesOrderReturn(); orderReturn.Id = Guid.NewGuid(); orderReturn.IsReissue = this.ckbIsReissue.Checked; orderReturn.SalesOrderID = OrderInfo.Id; orderReturn.CreateUserId = AppClientContext.CurrentUser.Id; //orderReturn.OrderReturnCode = this.ucbcSalesReturn.GenarateCode(); orderReturn.OrderReturnReason = this.txtReason.Text; orderReturn.OrderReturnStatusValue = (int)OrderReturnStatus.Waitting; orderReturn.OutInventoryID = OutInfo.Id; //没办法,只能这么写了,获取用户ID Employee[] emp = this.PharmacyDatabaseService.AllEmployees(out msg); var em = emp.FirstOrDefault(r => r.Name.Equals(this.OrderInfo.SalerName)); if (em == null) { MessageBox.Show("该单据异常,销售员:" + this.OrderInfo.SalerName + "被人为删除。此单据为该销售员所定制,系统当前无该销售员信息,所以暂时无法退货,解决办法是恢复该销售员信息,并且锁定该销售员,如果系统中确实无法找到该销售员信息,则可按照姓名新增员工信息和用户信息。"); return; } Guid uid = em.Users.First().Id; orderReturn.SellerID = uid; listSalesOrderReturnDetail = listSalesOrderReturnDetail.Where(r => r.ReturnAmount > 0).ToList(); orderReturn.SalesOrderReturnDetails = listSalesOrderReturnDetail.ToArray(); //调用服务器端 message = PharmacyDatabaseService.AddSalesOrderReturnAndDetail(orderReturn); if (message.Length > 0) { MessageBox.Show(message); } else { orderReturn = this.PharmacyDatabaseService.GetSalesOrderReturn(out msg, orderReturn.Id); this.PharmacyDatabaseService.WriteLog(AppClientContext.CurrentUser.Id, "成功提交销售退货操作:" + orderReturn.OrderReturnCode); MessageBox.Show("成功提交退货申请,单号:" + orderReturn.OrderReturnCode + ",请销售员登陆,执行审核!"); this.tsbtnSubmit.Enabled = false; this.Dispose(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } }