Пример #1
0
    protected void MagicItemCommand(object sender, MagicItemEventArgs e)
    {
        if (e.CommandName != "Save")
        {
            return;
        }

        using (ISession session = new Session())
        {
            try
            {
                IList <StockInLine> lines = new List <StockInLine>();
                StockInHead         head  = StockInHead.Retrieve(session, this.OrderNumber);
                foreach (RepeaterItem item in this.repeatControl.Items)
                {
                    TextBox text = item.FindControl("txtQty") as TextBox;
                    decimal qty  = Cast.Decimal(text.Text, 0M);
                    if (qty <= 0M)
                    {
                        continue;
                    }

                    HtmlInputCheckBox chk  = item.FindControl("checkbox") as HtmlInputCheckBox;
                    StockInLine       line = new StockInLine();
                    line.OrderNumber   = this.OrderNumber;
                    line.StockDetailID = Cast.Int(chk.Value);
                    line.LineNumber    = Cast.String(chk.Attributes["line"]);
                    line.Quantity      = qty;
                    line.Price         = 0M;
                    lines.Add(line);
                }
                if (lines.Count <= 0)
                {
                    log.Debug("Save - assist item req line: no lines need to be saved");
                    return;
                }

                session.BeginTransaction();
                head.CreateOrUpdateLines(session, lines);
                session.Commit();

                log.DebugFormat("Save - assist item req line: {0} lines were created or updated", lines.Count);
                WebUtil.ShowMsg(this, "辅料领用明细已经保存");
                this.QueryAndBindData(session, this.magicPagerMain.CurrentPageIndex, this.magicPagerMain.PageSize, true);
            }
            catch (Exception er)
            {
                log.Error("Save - to add assist item req line: ", er);
                session.Rollback();
                WebUtil.ShowError(this, er);
            }
        }
    }
Пример #2
0
    protected void MagicItemCommand(object sender, MagicItemEventArgs e)
    {
        if (e.CommandName == "Save")
        {
            #region 保存
            using (ISession session = new Session())
            {
                IList <StockInLine>       linesToSave = new List <StockInLine>();
                System.Text.StringBuilder error       = new System.Text.StringBuilder();
                foreach (RepeaterItem item in this.repeatControl.Items)
                {
                    HtmlInputCheckBox chk = item.FindControl("checkbox") as HtmlInputCheckBox;
                    TextBox           text;
                    StockInLine       line = StockInLine.Retrieve(session, this.OrderNumber, chk.Value);
                    text             = item.FindControl("txtQty") as TextBox;
                    line.Quantity    = Cast.Decimal(text.Text.Trim());
                    text             = item.FindControl("txtSec") as TextBox;
                    line.SectionCode = text.Text.Trim();
                    DropDownList drp = item.FindControl("drpArea") as DropDownList;
                    line.AreaCode = drp.SelectedValue;

                    if (string.IsNullOrEmpty(line.AreaCode) || line.AreaCode.Trim().Length <= 0)
                    {
                        error.Append(chk.Attributes["sku"]).Append("未选择库位;");
                    }
                    else if (!string.IsNullOrEmpty(line.SectionCode) && line.SectionCode.Trim().Length > 0)
                    {
                        WHSection section = WHSection.Retrieve(session, line.AreaCode, line.SectionCode);
                        if (section == null)
                        {
                            error.Append(chk.Attributes["sku"])
                            .Append("库位").Append(line.AreaCode).Append("中不存在货架").Append(line.SectionCode).Append(";");
                        }
                    }

                    linesToSave.Add(line);
                }
                if (error.Length > 0)
                {
                    WebUtil.ShowError(this, error.ToString());
                    return;
                }

                try
                {
                    //检查
                    StockInHead head = StockInHead.Retrieve(session, this.OrderNumber);
                    if (head == null)
                    {
                        return;
                    }
                    session.BeginTransaction();
                    head.CreateOrUpdateLines(session, linesToSave);
                    session.Commit();
                    WebUtil.ShowMsg(this, "保存成功");
                }
                catch (Exception er)
                {
                    session.Rollback();
                    WebUtil.ShowError(this, er);
                }
            }
            #endregion
        }
        else if (e.CommandName == "Delete")
        {
            #region  除
            using (ISession session = new Session())
            {
                try
                {
                    session.BeginTransaction();
                    foreach (RepeaterItem item in this.repeatControl.Items)
                    {
                        HtmlInputCheckBox chk = item.FindControl("checkbox") as HtmlInputCheckBox;
                        if (chk.Checked)
                        {
                            StockInLine line = StockInLine.Retrieve(session, this.OrderNumber, chk.Value.Trim());
                            if (line != null)
                            {
                                line.Delete(session);
                            }
                        }
                    }
                    session.Commit();
                    this.QueryAndBindData(session, null);
                    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
                {
                    StockInHead head = StockInHead.Retrieve(session, this.OrderNumber);
                    session.BeginTransaction();
                    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
                {
                    StockInHead head = StockInHead.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
        }
        else if (e.CommandName == "Add")
        {
            #region 添加明细
            using (ISession session = new Session())
            {
                ItemSpec sku = ItemSpec.Retrieve(session, this.txtSku.Text.Trim().ToUpper());
                if (sku == null)
                {
                    WebUtil.ShowError(this, "SKU: " + this.txtSku.Text.Trim() + "不存在");
                    return;
                }
                StockInHead head = StockInHead.Retrieve(session, this.OrderNumber);
                StockInLine line = new StockInLine();
                line.OrderNumber   = this.OrderNumber;
                line.LocationCode  = head.LocationCode;
                line.LineNumber    = head.NextLineNumber();
                line.AreaCode      = "";
                line.SectionCode   = "";
                line.Price         = sku.AvgMoveCost;
                line.Quantity      = 0M;
                line.RefQuantity   = 0M;
                line.SKUID         = sku.SKUID;
                line.StockDetailID = 0;
                line.UnitID        = 0;

                bool isError = false;
                try
                {
                    session.BeginTransaction();
                    line.Create(session);
                    head.Update(session, "CurrentLineNumber");
                    session.Commit();
                }
                catch (Exception er)
                {
                    session.Rollback();
                    WebUtil.ShowError(this, er);
                    isError = true;
                }

                if (!isError)
                {
                    this.txtSku.Text = "";
                    this.QueryAndBindData(session, head);
                    this.SetView(head);
                }
            }
            #endregion
        }
    }
Пример #3
0
    protected void MagicItemCommand(object sender, MagicItemEventArgs e)
    {
        if (e.CommandName == "Save")
        {
            #region 保存
            using (ISession session = new Session())
            {
                IList <StockInLine> linesToSave = new List <StockInLine>();
                foreach (RepeaterItem item in this.repeatControl.Items)
                {
                    HtmlInputCheckBox chk = item.FindControl("checkbox") as HtmlInputCheckBox;
                    TextBox           text;
                    StockInLine       line = StockInLine.Retrieve(session, this.OrderNumber, chk.Value);
                    text          = item.FindControl("txtQty") as TextBox;
                    line.Quantity = Cast.Decimal(text.Text.Trim());

                    linesToSave.Add(line);
                }

                try
                {
                    //检查
                    StockInHead head = StockInHead.Retrieve(session, this.OrderNumber);
                    if (head == null)
                    {
                        return;
                    }
                    session.BeginTransaction();
                    head.CreateOrUpdateLines(session, linesToSave);
                    session.Commit();
                    WebUtil.ShowMsg(this, "保存成功");
                }
                catch (Exception er)
                {
                    session.Rollback();
                    WebUtil.ShowError(this, er);
                }
            }
            #endregion
        }
        else if (e.CommandName == "Delete")
        {
            #region  除
            using (ISession session = new Session())
            {
                try
                {
                    session.BeginTransaction();
                    foreach (RepeaterItem item in this.repeatControl.Items)
                    {
                        HtmlInputCheckBox chk = item.FindControl("checkbox") as HtmlInputCheckBox;
                        if (chk.Checked)
                        {
                            StockInLine line = StockInLine.Retrieve(session, this.OrderNumber, chk.Value.Trim());
                            if (line != null)
                            {
                                line.Delete(session);
                            }
                        }
                    }
                    session.Commit();
                    this.QueryAndBindData(session, null);
                    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
                {
                    StockInHead head = StockInHead.Retrieve(session, this.OrderNumber);
                    session.BeginTransaction();
                    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
                {
                    StockInHead head = StockInHead.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
        }
    }