Ejemplo n.º 1
0
    protected void MagicItemCommand(object sender, MagicItemEventArgs e)
    {
        if (e.CommandName == "Save")
        {
            using (ISession session = new Session())
            {
                ReturnHead head = null;
                if (this.IsNew)
                {
                    head = new ReturnHead();
                    try
                    {
                        head.LogisReturn(session, this.drpLocation.SelectedValue, this.txtSNNumber.Text, Cast.Int(this.drpReason.SelectedValue, 0), this.chkIsMalicious.Checked, this.chkHasTransported.Checked, this.txtNote.Text.Trim(), SecuritySession.CurrentUser.UserId);
                        head.OrderNumber = ERPUtil.NextOrderNumber(head.OrderTypeCode);
                        session.BeginTransaction();
                        head.Create(session);
                        session.Commit();

                        this.Response.Redirect("LogisReturnScan.aspx?ordNum=" + head.OrderNumber + "&return=" + WebUtil.escape("LogisReturnLine.aspx?ordNum=" + head.OrderNumber + "&return=" + WebUtil.escape(this.ReturnUrl)));
                    }
                    catch (Exception er)
                    {
                        session.Rollback();
                        WebUtil.ShowError(this, er);
                    }

                    return;
                }

                try
                {
                    head = ReturnHead.Retrieve(session, this.OrderNumber);
                    head.LogisReturn(session, this.drpLocation.SelectedValue, this.txtSNNumber.Text, Cast.Int(this.drpReason.SelectedValue, 0), this.chkIsMalicious.Checked, this.chkHasTransported.Checked, this.txtNote.Text.Trim(), SecuritySession.CurrentUser.UserId);
                    session.BeginTransaction();
                    head.Update(session, "Note", "LocationCode", "ReasonID", "ReasonText", "IsMalicious", "RefOrderID", "RefOrderNumber", "OrginalOrderNumber", "LogisticsName", "LogisticsID", "MemberName", "MemberID", "HasTransported");
                    session.Commit();
                    WebUtil.ShowMsg(this, "保存成功");
                }
                catch (Exception er2)
                {
                    session.Rollback();
                    WebUtil.ShowError(this, er2);
                }
            }
        }
    }
    protected void MagicItemCommand(object sender, MagicItemEventArgs e)
    {
        if (e.CommandName == "Save")
        {
            using (ISession session = new Session())
            {
                ReturnHead head = null;
                #region 更新退货单的情况
                if (!this.IsNew)
                {
                    head = ReturnHead.Retrieve(session, this.txtOrderNumber.Text.Trim());
                    if (head == null)
                    {
                        WebUtil.ShowError(this, "退货单" + this.txtOrderNumber.Text.Trim() + "不存在");
                        return;
                    }
                    if (head.Status != ReturnStatus.New)
                    {
                        WebUtil.ShowError(this, "退货单" + head.OrderNumber + "不是新建状态,无法更新");
                        return;
                    }
                    try
                    {
                        session.BeginTransaction();
                        if (head.OrderTypeCode == ReturnHead.ORDER_TYPE_MBR_RTN)
                        {
                            head.MemberReturn(session, this.drpLocation.SelectedValue, this.txtSNNumber.Text, Cast.Int(this.drpReason.SelectedValue, 0), this.chk.Checked, this.txtNote.Text.Trim(), SecuritySession.CurrentUser.UserId);
                            head.Update(session, "Note", "LocationCode", "ReasonID", "ReasonText", "IsMalicious", "RefOrderID", "RefOrderNumber", "OrginalOrderNumber", "LogisticsName", "LogisticsID", "MemberName", "MemberID");
                        }
                        else
                        {
                            head.ExchangeReturn(session, this.drpLocation.SelectedValue, Cast.Int(this.drpReason.SelectedValue), this.txtNote.Text, 0);
                            head.Update(session, "Note", "LocationCode", "ReasonID", "ReasonText");
                        }
                        session.Commit();
                        WebUtil.ShowMsg(this, "保存成功");
                    }
                    catch (Exception er2)
                    {
                        session.Rollback();
                        WebUtil.ShowError(this, er2);
                    }
                    return;
                }
                #endregion
                //根据发货单查询是否存在退货单,2个作用
                //1. 换货的情况下,创建换货订单同时已经创建了换货退货单,这种情况要更新一下换货退货单资料(仓库、退货原因、备注)而不用新增
                //2. 目前不允许一个订单多次退货,即发货单如果已经用于创建退货单,则不再允许创建第2个了
                IList<ReturnHead> heads = ReturnHead.QueryBySNNumber(session, this.txtSNNumber.Text.Trim());
                #region 从来没有(会员退货、物流退货、内部退货),允许退货,以下代码创建新的会员退货单
                if (heads.Count <= 0)
                {
                    head = new ReturnHead();
                    try
                    {
                        head.MemberReturn(session, this.drpLocation.SelectedValue, this.txtSNNumber.Text, Cast.Int(this.drpReason.SelectedValue, 0), this.chk.Checked, this.txtNote.Text.Trim(), SecuritySession.CurrentUser.UserId);
                        head.OrderNumber = ERPUtil.NextOrderNumber(head.OrderTypeCode);
                        session.BeginTransaction();
                        head.Create(session);
                        session.Commit();

                        this.Response.Redirect("MemberReturnScan.aspx?ordNum=" + head.OrderNumber + "&return=" + WebUtil.escape("MemberReturnLine.aspx?ordNum=" + head.OrderNumber + "&return=" + WebUtil.escape(this.ReturnUrl)));
                    }
                    catch (Exception er)
                    {
                        session.Rollback();
                        WebUtil.ShowError(this, er);
                    }

                    return;
                }
                #endregion
                int countOfNewChangeReturn = this.CountOfNewChangeReturn(heads);
                #region 有新建状态的换货单,直接调出该换货单,更新其资料,更新完后跳转到退货扫描界面
                //如果已经部分退货过一次,下面的代码允许继续换货
                if (countOfNewChangeReturn > 0)
                {
                    foreach (ReturnHead h in heads)
                        if (h.Status == ReturnStatus.New && h.OrderTypeCode == ReturnHead.ORDER_TYPE_EXCHANGE_RTN)
                        {
                            head = h;
                            break;
                        }
                    if (head != null)
                    {
                        try
                        {
                            head.ExchangeReturn(session, this.drpLocation.SelectedValue, Cast.Int(this.drpReason.SelectedValue), this.txtNote.Text.Trim(), SecuritySession.CurrentUser.UserId);
                            session.BeginTransaction();
                            head.Update(session, "LocationCode", "ReasonID", "ReasonText", "Note");
                            session.Commit();
                            this.Response.Redirect("ExchangeReturnScan.aspx?ordNum=" + head.OrderNumber + "&return=" + WebUtil.escape("MemberReturnLine.aspx?ordNum=" + head.OrderNumber + "&return=" + WebUtil.escape(WebUtil.Param("return"))));
                            return;
                        }
                        catch (Exception er5)
                        {
                            session.Rollback();
                            WebUtil.ShowError(this, er5);
                        }
                    }
                    return;
                }
                #endregion
                #region 如果有未完成的退货单,必须完成后才可以新建另外的退货
                foreach (ReturnHead h in heads)
                {
                    if (h.Status != ReturnStatus.Close)
                    {
                        WebUtil.ShowError(this, "与发货单" + h.RefOrderNumber + "相关的退货单" + h.OrderNumber + "还没有完成,无法创建另外的退货单");
                        return;
                    }
                }
                #endregion
                #region 如果没有创建过任何会员退货、物流退货、内部退货,则允许创建一个(这几种退货只能退一次)
                if (this.IsAllChangeReturn(heads))
                {
                    head = new ReturnHead();
                    try
                    {
                        head.MemberReturn(session, this.drpLocation.SelectedValue, this.txtSNNumber.Text, Cast.Int(this.drpReason.SelectedValue, 0), this.chk.Checked, this.txtNote.Text.Trim(), SecuritySession.CurrentUser.UserId);
                        head.OrderNumber = ERPUtil.NextOrderNumber(head.OrderTypeCode);
                        session.BeginTransaction();
                        head.Create(session);
                        session.Commit();

                        this.Response.Redirect("MemberReturnScan.aspx?ordNum=" + head.OrderNumber + "&return=" + WebUtil.escape("MemberReturnLine.aspx?ordNum=" + head.OrderNumber + "&return=" + WebUtil.escape(this.ReturnUrl)));
                    }
                    catch (Exception er)
                    {
                        session.Rollback();
                        WebUtil.ShowError(this, er);
                    }

                    return;
                }
                #endregion
                #region 其它情况将无法再创建会员退货单
                if (this.IsNew)
                {
                    WebUtil.ShowError(this, "同一个订单(发货单)不允许多次退货,系统无法再创建退货单");
                    return;
                }
                #endregion
            }
        }
    }