Exemple #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         int skuid = WebUtil.ParamInt("sku", 0);
         if (skuid <= 0)
         {
             this.divMsg.InnerText = "无效的SKU";
             return;
         }
         using (ISession session = new Session())
         {
             ItemSpec spec = ItemSpec.Retrieve(session, skuid);
             if (spec == null)
             {
                 this.divMsg.InnerText = "SKU " + skuid.ToString() + "不存在";
                 return;
             }
             //显示sku信息
             this.lblItemCode.Text = spec.ItemCode;
             this.lblSize.Text     = spec.SizeCode;
             ItemMaster master = ItemMaster.Retrieve(session, spec.ItemCode);
             this.lblItemName.Text = master == null ? "" : master.ItemName;
             ItemColor color = ItemColor.Retrieve(session, spec.ColorCode);
             this.lblColor.Text  = spec.ColorCode + " " + (color == null ? "" : color.ColorText);
             this.lblOVSQty.Text = spec.EnableOS ? RenderUtil.FormatNumber(spec.OSQty, "#0.##", "0") : "0";
             //现有库存
             StockSummary sto = StockSummary.Retrieve(session, skuid);
             this.lblStockQty.Text  = sto == null ? "0" : RenderUtil.FormatNumber(sto.StockQty, "#0.##");
             this.lblFrozenQty.Text = sto == null ? "0" : RenderUtil.FormatNumber(sto.FrozenQty, "#0.##");
             //在途采购记录
             IList <POLine> lines = POHead.PipelineInvQuery(session, skuid);
             this.repeater.DataSource = lines;
             this.repeater.DataBind();
             decimal pipelineStockQty = 0M;
             //计算汇总在途量
             foreach (POLine line in lines)
             {
                 pipelineStockQty += (line.PurchaseQty - line.ReceiveQty);
             }
             this.lblPipelineStock.Text = RenderUtil.FormatNumber(pipelineStockQty, "#0.##");
             if (lines.Count <= 0)
             {
                 this.divMsg.InnerText = "该SKU没有在途采购";
             }
             else
             {
                 this.divMsg.InnerText = "";
             }
         }
     }
 }
    protected void MagicItemCommand(object sender, MagicItemEventArgs e)
    {
        if (e.CommandName == "Save")
        {
            #region 保存
            //txtPurchaseQty txtPlanDate txtPrice
            bool updated = false;
            using (_session = new Session())
            {
                POHead head = POHead.Retrieve(_session, this.OrderNumber);
                if (head == null || head.Status != POStatus.New)
                {
                    return;
                }

                _session.BeginTransaction();
                try
                {
                    foreach (RepeaterItem item in this.rptPL.Items)
                    {
                        HtmlInputCheckBox chk = item.FindControl("checkbox") as HtmlInputCheckBox;
                        if (!string.IsNullOrEmpty(chk.Value))
                        {
                            HtmlInputText txtPurchaseQty = item.FindControl("txtPurchaseQty") as HtmlInputText;
                            HtmlInputText txtPlanDate    = item.FindControl("txtPlanDate") as HtmlInputText;
                            HtmlInputText txtPrice       = item.FindControl("txtPrice") as HtmlInputText;
                            POLine        poLine         = POLine.Retrieve(_session, this.OrderNumber, chk.Value);
                            if (poLine == null || poLine.LineStatus != POLineStatus.Open)
                            {
                                continue;
                            }

                            poLine.PurchaseQty = Cast.Decimal(txtPurchaseQty.Value, poLine.PurchaseQty);
                            poLine.PlanDate    = Cast.DateTime(txtPlanDate.Value, poLine.PlanDate);
                            poLine.Price       = Cast.Decimal(txtPrice.Value, poLine.Price);
                            poLine.TaxID       = 0;
                            poLine.TaxValue    = 0M;
                            //含税额(含税采购成本)  TaxInclusiveAmt 含税额 = 数量*单价
                            poLine.TaxInclusiveAmt = poLine.PurchaseQty * poLine.Price;
                            //不含税额(采购成本) TaxExlusiveAmt 含税额-税额
                            poLine.TaxExlusiveAmt = 0M; // poLine.TaxInclusiveAmt / (1 + poLine.TaxValue);
                            //税额    TaxAmt  税额 = 不含税额*税率
                            poLine.TaxAmt = 0M;         //poLine.TaxExlusiveAmt * poLine.TaxValue;
                            poLine.Update(_session, "PurchaseQty", "TaxID", "TaxValue", "PlanDate", "Price", "TaxInclusiveAmt");
                            updated = true;
                        }
                    }
                    //更新统计信息
                    if (updated)
                    {
                        UpdatePOLineAndPoHead(_session, head);
                    }
                    _session.Commit();
                    if (updated)
                    {
                        BindPOLine(_session, head);
                        WebUtil.ShowMsg(this, "采购订单明细保存成功", "操作成功");
                    }
                }
                catch (Exception ex)
                {
                    _session.Rollback();
                    WebUtil.ShowError(this, ex);
                }
            }
            #endregion
        }
        else if (e.CommandName == "Cancel")
        {
            #region 取消明细
            bool updated = false;
            using (_session = new Session())
            {
                POHead head = POHead.Retrieve(_session, this.OrderNumber);
                if (head.Status != POStatus.Release)
                {
                    return;
                }

                _session.BeginTransaction();
                try
                {
                    foreach (RepeaterItem item in this.rptPL.Items)
                    {
                        HtmlInputCheckBox chk = item.FindControl("checkbox") as HtmlInputCheckBox;
                        if (chk != null && chk.Checked && !string.IsNullOrEmpty(chk.Value))
                        {
                            POLine poLine = POLine.Retrieve(_session, this.OrderNumber, chk.Value);
                            if (poLine == null || poLine.LineStatus != POLineStatus.Open)
                            {
                                continue;
                            }
                            poLine.LineStatus = POLineStatus.Cancel;
                            poLine.ModifyUser = Magic.Security.SecuritySession.CurrentUser.UserId;
                            poLine.ModifyTime = DateTime.Now;
                            poLine.Update(_session, "LineStatus", "ModifyUser", "ModifyTime");
                            updated = true;
                        }
                    }
                    //再次统计 POLine
                    if (updated)
                    {
                        UpdatePOLineAndPoHead(_session, head);
                    }
                    _session.Commit();

                    if (updated)
                    {
                        BindPOLine(_session, head);
                        WebUtil.ShowMsg(this, "选择的明细已经取消", "操作成功");
                    }
                }
                catch (Exception ex)
                {
                    _session.Rollback();
                    WebUtil.ShowError(this, ex);
                }
            }
            #endregion
        }
        else if (e.CommandName == "Delete")
        {
            #region  除明细
            bool deleted = false;
            using (_session = new Session())
            {
                POHead head = POHead.Retrieve(_session, this.OrderNumber);
                if (head == null || head.Status != POStatus.New)
                {
                    return;
                }

                _session.BeginTransaction();
                try
                {
                    foreach (RepeaterItem item in this.rptPL.Items)
                    {
                        HtmlInputCheckBox chk = item.FindControl("checkbox") as HtmlInputCheckBox;
                        if (chk != null && chk.Checked && !string.IsNullOrEmpty(chk.Value))
                        {
                            POLine line = POLine.Retrieve(_session, this.OrderNumber, chk.Value);
                            if (line.LineStatus != POLineStatus.Open)
                            {
                                continue;
                            }
                            line.Delete(_session);
                            deleted = true;
                        }
                    }
                    //再次统计 POLine
                    if (deleted)
                    {
                        UpdatePOLineAndPoHead(_session, head);
                    }
                    _session.Commit();

                    if (deleted)
                    {
                        BindPOLine(_session, head);
                        WebUtil.ShowMsg(this, "选择的明细已经删除", "操作成功");
                    }
                }
                catch (Exception ex)
                {
                    _session.Rollback();
                    WebUtil.ShowError(this, ex);
                }
            }
            #endregion
        }
        else if (e.CommandName == "Release" || e.CommandName == "Close")
        {
            #region 发布,关闭
            using (_session = new Session())
            {
                try
                {
                    POHead head = POHead.Retrieve(_session, this.OrderNumber);
                    _session.BeginTransaction();
                    if (e.CommandName == "Release")
                    {
                        head.Release(_session);
                    }
                    else
                    {
                        head.Close(_session);
                    }
                    _session.Commit();

                    BindPOLine(_session, head);
                    this.SetView(_session, head);
                    WebUtil.ShowMsg(this, "订单已经" + (e.CommandName == "Release" ? "发布" : "关闭"), "操作成功");
                }
                catch (Exception er)
                {
                    _session.Rollback();
                    WebUtil.ShowError(this, er);
                }
            }
            #endregion
        }
        else if (e.CommandName == "QuickAdd")
        {
            #region 快速添加
            using (_session = new Session())
            {
                //检查
                string   itemCode = this.txtItemCode.Value.Trim();
                string   color    = this.txtColorCode.Value.Trim().ToUpper();
                string   size     = this.txtSizeCode.Value.Trim().ToUpper();
                decimal  qty      = Cast.Decimal(this.txtPurchaseQty.Value.Trim(), 0M);
                decimal  price    = Cast.Decimal(this.txtPrice.Value.Trim(), 0M);
                DateTime date     = Cast.DateTime(this.txtDemandDate.Value.Trim(), new DateTime(1900, 1, 1));

                if (qty <= 0M)
                {
                    this.txtAlertMsg.InnerText = string.Format("采购数量{0}不是有效的数字", this.txtPurchaseQty.Value.Trim());
                    return;
                }
                if (price <= 0M)
                {
                    this.txtAlertMsg.InnerText = string.Format("单价{0}不是有效的数字", this.txtPrice.Value.Trim());
                    return;
                }
                if (date <= new DateTime(1900, 1, 1))
                {
                    this.txtAlertMsg.InnerText = string.Format("无效的需求日期{0}", this.txtDemandDate.Value.Trim());
                    return;
                }

                IList <ItemMaster> masters = _session.CreateEntityQuery <ItemMaster>()
                                             .Where(Exp.Eq("ItemCode", itemCode)).List <ItemMaster>();
                if (masters == null || masters.Count <= 0)
                {
                    this.txtAlertMsg.InnerText = string.Format("货号{0}不存在", itemCode);
                    return;
                }
                ItemColor objColor = ItemColor.Retrieve(_session, color);
                if (objColor == null)
                {
                    this.txtAlertMsg.InnerText = string.Format("颜色代码{0}不存在", color);
                    return;
                }
                IList <ItemSpec> skus = _session.CreateEntityQuery <ItemSpec>()
                                        .Where(Exp.Eq("ItemID", masters[0].ItemID) & Exp.Eq("ColorCode", objColor.ColorCode) & Exp.Eq("SizeCode", size))
                                        .List <ItemSpec>();
                if (skus == null || skus.Count <= 0)
                {
                    this.txtAlertMsg.InnerText = string.Format("不存在货号:{0} 颜色:{1} 尺码:{2}的SKU", itemCode, color, size);
                    return;
                }
                ItemSize objSize = ItemSize.Retrieve(_session, size, masters[0].CategoryID);
                if (objSize == null)
                {
                    this.txtAlertMsg.InnerText = string.Format("尺码{0}不存在", size);
                    return;
                }

                //添加操作
                POHead head = POHead.Retrieve(_session, this.OrderNumber);
                POLine line = new POLine();
                line.OrderNumber          = this.OrderNumber;
                line.LineNumber           = head.NextLineNumber();
                line.LineStatus           = POLineStatus.Open;
                line.SKUID                = skus[0].SKUID;
                line.PurchaseQty          = qty;
                line.Price                = price;
                line.TaxID                = 0;
                line.TaxValue             = 0M;
                line.TaxInclusiveAmt      = line.PurchaseQty * line.Price;
                line.TaxExlusiveAmt       = 0M; // line.TaxInclusiveAmt / (1 + line.TaxValue);
                line.TaxAmt               = 0M; //line.TaxExlusiveAmt * line.TaxValue;
                line.PlanDate             = date;
                line.ActualDate           = new DateTime(1900, 1, 1);
                line.ReceiveQty           = 0M;
                line.IQCQty               = 0M;
                line.UnfinishedReceiveQty = 0M;
                line.ModifyUser           = SecuritySession.CurrentUser.UserId;
                line.ModifyTime           = DateTime.Now;
                line.UnitID               = 0;

                try
                {
                    _session.BeginTransaction();
                    line.Create(_session);
                    head.Update(_session, "CurrentLineNumber");
                    this.UpdatePOLineAndPoHead(_session, head);
                    _session.Commit();
                    BindPOLine(_session, head);
                    this.txtAlertMsg.InnerText = "添加成功,订单行号为" + line.LineNumber;
                    this.txtPurchaseQty.Value  = "";
                }
                catch (Exception er)
                {
                    _session.Rollback();
                    WebUtil.ShowError(this, er);
                }
            }
            #endregion
        }
    }