protected void cmdEdit1_ItemCommand(object sender, MagicItemEventArgs args) { if (args.CommandName == "Save") { HtmlInputText input = null; using (ISession session = new Session()) { try { IList<ReturnLine> lines = new List<ReturnLine>(); foreach (RepeaterItem item in this.repeatControl.Items) { input = item.FindControl("hidQty") as HtmlInputText; int sndid = Cast.Int(input.Attributes["vv_sndid"]); decimal returnQty = Cast.Decimal(input.Value); if (sndid <= 0 || returnQty <= 0M) continue; ReturnLine line = new ReturnLine(); line.RefOrderLineID = sndid; line.Quantity = returnQty; lines.Add(line); } if (lines.Count <= 0) this.Response.Redirect(this.ReturnUrl); ReturnHead head = ReturnHead.Retrieve(session, this.OrderNumber); session.BeginTransaction(); head.UpdateOrCreateLines(session, lines); session.Commit(); this.Response.Redirect(this.ReturnUrl); } catch (Exception er) { session.Rollback(); WebUtil.ShowError(this, er); } } } }
protected void MagicItemCommand(object sender, MagicItemEventArgs e) { if (e.CommandName == "Save") { #region ���� IList<ReturnLine> linesToSave = new List<ReturnLine>(); foreach (RepeaterItem item in this.repeatControl.Items) { HtmlInputCheckBox chk = item.FindControl("checkbox") as HtmlInputCheckBox; DropDownList drp = item.FindControl("drpArea") as DropDownList; TextBox text; ReturnLine line = new ReturnLine(); line.OrderNumber = this.OrderNumber; line.LineNumber = chk.Value.Trim(); line.AreaCode = drp.SelectedValue; text = item.FindControl("txtSection") as TextBox; line.SectionCode = text.Text.Trim(); linesToSave.Add(line); } using (ISession session = new Session()) { try { //��� ReturnHead head = ReturnHead.Retrieve(session, this.OrderNumber); if (head == null) return; session.BeginTransaction(); head.UpdateLines(session, linesToSave); session.Commit(); WebUtil.ShowMsg(this, "����ɹ�"); } catch (Exception er) { session.Rollback(); WebUtil.ShowError(this, er); } } #endregion } else if (e.CommandName == "Release") { #region ���� using (ISession session = new Session()) { try { session.BeginTransaction(); ReturnHead head = ReturnHead.Retrieve(session, this.OrderNumber); head.Release(session); session.Commit(); WebUtil.ShowMsg(this, "�����ɹ�"); this.QueryAndBindData(session, head); this.SetView(head); } catch (Exception er) { session.Rollback(); WebUtil.ShowError(this, er); } } #endregion } else if (e.CommandName == "Close") { #region �ر� using (ISession session = new Session()) { try { ReturnHead head = ReturnHead.Retrieve(session, this.OrderNumber); if (head == null) return; session.BeginTransaction(); head.Close(session); session.Commit(); WebUtil.ShowMsg(this, "�˻���" + head.OrderNumber + "�Ѿ����"); this.QueryAndBindData(session, head); this.SetView(head); } catch (Exception er) { session.Rollback(); WebUtil.ShowError(this, er); } } #endregion } }
public void UpdateOrCreateLines(ISession session, IList<ReturnLine> toSave) { //ȷ�������˻�����ִ�и÷��� if (this.OrderTypeCode == ORDER_TYPE_EXCHANGE_RTN) return; log.DebugFormat("to create or save rtn lines, count:{0}", toSave == null ? 0 : toSave.Count); if (toSave == null || toSave.Count <= 0) return; if (this.Status != ReturnStatus.New) throw new Exception("�˻��������½�״̬��������"); //�����˻����ڲ��˻�����ȫ�ˣ���֧�ֲ����˻� if (this.OrderTypeCode == ORDER_TYPE_LOGISTICS_RTN || this.OrderTypeCode == ORDER_TYPE_INNER_RTN) { int snLineCount = session.CreateEntityQuery<CRMSNLine>().Where(Exp.Eq("SNID", this.RefOrderID)).Count(); if (snLineCount != toSave.Count) throw new Exception("������" + this.RefOrderNumber + "��ϸ(" + snLineCount.ToString() + "��)���˻���ϸ(" + toSave.Count.ToString() + "��)��һ��"); } bool updateHeadLineNum = false; foreach (ReturnLine line in toSave) { if (line.RefOrderLineID <= 0 || line.Quantity <= 0M) { if (this.OrderTypeCode == ORDER_TYPE_LOGISTICS_RTN || this.OrderTypeCode == ORDER_TYPE_INNER_RTN) throw new Exception("�˻���ϸ����������Ч"); continue; } bool checkCreate = true; if (this.OrderTypeCode == ORDER_TYPE_MBR_RTN) { //��Ա�˻��ſ��Էֶ��ɨ���˻���ϸ ReturnLine existsLine = ReturnLine.Retrieve(session, this.OrderNumber, line.RefOrderLineID); if (existsLine != null) { log.DebugFormat("rtn line({0}) exists, rtn qty:{1}", line.RefOrderLineID, line.Quantity); existsLine.Quantity += line.Quantity; existsLine.Update(session, "Quantity"); checkCreate = false; } } if (checkCreate) { CRMSNLine snline = CRMSNLine.Retrieve(session, line.RefOrderLineID); if (snline == null) throw new Exception("��������ϸ" + line.RefOrderLineID.ToString() + "������"); //�����˻����ڲ��˻�����ȫ�� if ((this.OrderTypeCode == ORDER_TYPE_LOGISTICS_RTN || this.OrderTypeCode == ORDER_TYPE_INNER_RTN) && line.Quantity != snline.Quantity) throw new Exception("�˻����������ڷ�������"); ReturnLine existsLine = new ReturnLine(); existsLine.OrderNumber = this.OrderNumber; existsLine.LineNumber = this.NextLineNumber(); updateHeadLineNum = true; existsLine.RefOrderLineID = snline.ID; existsLine.SKUID = snline.SKUID; existsLine.TransTypeCode = " "; existsLine.Quantity = line.Quantity; existsLine.DeliverQuantity = snline.Quantity; existsLine.Price = snline.Price; IList<WHArea> areas = ERPUtil.GetWHArea(session, this.OrderTypeCode, null, this.LocationCode); if (areas.Count == 1) existsLine.AreaCode = areas[0].AreaCode; log.DebugFormat("to create rtn line, qty:{0}", line.Quantity); existsLine.Create(session); } } if (updateHeadLineNum) this.Update(session, "CurrentLineNumber"); }
public void UpdateOrCreateLines(ISession session, IList <ReturnLine> toSave) { //确保换货退货不会执行该方法 if (this.OrderTypeCode == ORDER_TYPE_EXCHANGE_RTN) { return; } log.DebugFormat("to create or save rtn lines, count:{0}", toSave == null ? 0 : toSave.Count); if (toSave == null || toSave.Count <= 0) { return; } if (this.Status != ReturnStatus.New) { throw new Exception("退货单不是新建状态,无法更新"); } //物流退货、内部退货必须全退,不支持部分退货 if (this.OrderTypeCode == ORDER_TYPE_LOGISTICS_RTN || this.OrderTypeCode == ORDER_TYPE_INNER_RTN) { int snLineCount = session.CreateEntityQuery <CRMSNLine>().Where(Exp.Eq("SNID", this.RefOrderID)).Count(); if (snLineCount != toSave.Count) { throw new Exception("发货单" + this.RefOrderNumber + "明细(" + snLineCount.ToString() + "项)与退货明细(" + toSave.Count.ToString() + "项)不一致"); } } bool updateHeadLineNum = false; foreach (ReturnLine line in toSave) { if (line.RefOrderLineID <= 0 || line.Quantity <= 0M) { if (this.OrderTypeCode == ORDER_TYPE_LOGISTICS_RTN || this.OrderTypeCode == ORDER_TYPE_INNER_RTN) { throw new Exception("退货明细或者数量无效"); } continue; } bool checkCreate = true; if (this.OrderTypeCode == ORDER_TYPE_MBR_RTN) { //会员退货才可以分多次扫描退货明细 ReturnLine existsLine = ReturnLine.Retrieve(session, this.OrderNumber, line.RefOrderLineID); if (existsLine != null) { log.DebugFormat("rtn line({0}) exists, rtn qty:{1}", line.RefOrderLineID, line.Quantity); existsLine.Quantity += line.Quantity; existsLine.Update(session, "Quantity"); checkCreate = false; } } if (checkCreate) { CRMSNLine snline = CRMSNLine.Retrieve(session, line.RefOrderLineID); if (snline == null) { throw new Exception("发货单明细" + line.RefOrderLineID.ToString() + "不存在"); } //物流退货、内部退货必须全退 if ((this.OrderTypeCode == ORDER_TYPE_LOGISTICS_RTN || this.OrderTypeCode == ORDER_TYPE_INNER_RTN) && line.Quantity != snline.Quantity) { throw new Exception("退货数量不等于发货数量"); } ReturnLine existsLine = new ReturnLine(); existsLine.OrderNumber = this.OrderNumber; existsLine.LineNumber = this.NextLineNumber(); updateHeadLineNum = true; existsLine.RefOrderLineID = snline.ID; existsLine.SKUID = snline.SKUID; existsLine.TransTypeCode = " "; existsLine.Quantity = line.Quantity; existsLine.DeliverQuantity = snline.Quantity; existsLine.Price = snline.Price; IList <WHArea> areas = ERPUtil.GetWHArea(session, this.OrderTypeCode, null, this.LocationCode); if (areas.Count == 1) { existsLine.AreaCode = areas[0].AreaCode; } log.DebugFormat("to create rtn line, qty:{0}", line.Quantity); existsLine.Create(session); } } if (updateHeadLineNum) { this.Update(session, "CurrentLineNumber"); } }