Ejemplo n.º 1
0
 protected void MagicItemCommand(object sender, MagicItemEventArgs e)
 {
     if (e.CommandName == "Delete")
     {
         #region  除
         using (ISession session = new Session())
         {
             try
             {
                 bool deleted = false;
                 session.BeginTransaction();
                 foreach (RepeaterItem item in this.repeatControl.Items)
                 {
                     HtmlInputCheckBox chk = item.FindControl("checkbox") as HtmlInputCheckBox;
                     if (chk.Checked)
                     {
                         log.DebugFormat("Delete - sto adj line: ordNum={0}, lineNum={1}", this.OrderNumber, chk.Value);
                         INVCheckLine.Delete(session, this.OrderNumber, chk.Value);
                         deleted = true;
                     }
                 }
                 session.Commit();
                 if (deleted)
                 {
                     this.QueryAndBindData(session, INVCheckHead.Retrieve(session, this.OrderNumber));
                     WebUtil.ShowMsg(this, "选择的明细已经删除");
                 }
             }
             catch (Exception er)
             {
                 session.Rollback();
                 log.Error("Error - delete sto adj line: ", er);
                 WebUtil.ShowError(this, er);
             }
         }
         #endregion
     }
     else if (e.CommandName == "Release")
     {
         #region 发布
         using (ISession session = new Session())
         {
             try
             {
                 INVCheckHead head = INVCheckHead.Retrieve(session, this.OrderNumber);
                 session.BeginTransaction();
                 log.DebugFormat("Release - sto adj: {0}", this.OrderNumber);
                 head.Release(session);
                 session.Commit();
                 WebUtil.ShowMsg(this, "发布成功");
                 this.QueryAndBindData(session, head);
                 this.SetView(head);
             }
             catch (Exception er)
             {
                 session.Rollback();
                 log.Error("Error - release sto adj: ", er);
                 WebUtil.ShowError(this, er);
             }
         }
         #endregion
     }
     else if (e.CommandName == "Close")
     {
         #region 关闭
         using (ISession session = new Session())
         {
             try
             {
                 INVCheckHead head = INVCheckHead.Retrieve(session, this.OrderNumber);
                 session.BeginTransaction();
                 log.DebugFormat("Close - sto adj: {0}", this.OrderNumber);
                 head.Close(session);
                 session.Commit();
                 WebUtil.ShowMsg(this, string.Format("库存调整单{0}已经关闭", this.OrderNumber));
                 this.QueryAndBindData(session, head);
                 this.SetView(head);
             }
             catch (Exception er)
             {
                 session.Rollback();
                 log.Error("Error - close sto adj: ", er);
                 WebUtil.ShowError(this, er);
             }
         }
         #endregion
     }
 }
    protected void MagicItemCommand(object sender, MagicItemEventArgs e)
    {
        try
        {
            if (e.CommandName == "Download")
            {
                #region  载
                DataSet      ds   = null;
                INVCheckHead head = null;
                using (ISession session = new Session())
                {
                    head = INVCheckHead.Retrieve(session, this.OrderNumber);
                    Magic.Framework.ORM.Query.ObjectQuery query = session.CreateObjectQuery(string.Format(@"
select l.LineNumber as LineNumber,l.AreaCode as AreaCode,l.SectionCode as SectionCode
    ,s.BarCode as SKU,m.ItemCode as ItemCode
    ,s.ColorCode as ColorCode,color.ColorText as ColorText,s.SizeCode as SizeCode
    ,{0} as BeforeQty,l.CurrentQty as CurrentQty,m.ItemName as ItemName
from INVCheckLine l
inner join ItemSpec s on l.SKUID=s.SKUID
inner join ItemMaster m on m.ItemID=s.ItemID
left join ItemColor color on color.ColorCode=s.ColorCode
where l.OrderNumber=?ordNum {1}
order by l.LineNumber"
                                                                                                          , head.CheckType == INVCheckType.Implicit && head.Status == INVCheckStatus.Confirm ? "'-'" : "l.BeforeQty"
                                                                                                          , this.drpViewType.SelectedValue == "2" ? "and l.BeforeQty<>l.CurrentQty" : ""))
                                                                  .Attach(typeof(INVCheckLine)).Attach(typeof(ItemSpec)).Attach(typeof(ItemMaster))
                                                                  .Attach(typeof(ItemColor)).Attach(typeof(ItemSize))
                                                                  .SetValue("?ordNum", this.OrderNumber, "l.OrderNumber");
                    if (this.drpArea.SelectedValue.Trim().Length > 0)
                    {
                        query.And(Exp.Eq("l.AreaCode", this.drpArea.SelectedValue.Trim()));
                    }
                    if (this.txtSKU.Text.Trim().Length > 0)
                    {
                        query.And(Exp.Like("s.BarCode", "%" + this.txtSKU.Text.Trim() + "%"));
                    }
                    if (this.txtItemCode.Text.Trim().Length > 0)
                    {
                        query.And(Exp.Like("m.ItemCode", "%" + this.txtItemCode.Text.Trim() + "%"));
                    }
                    if (this.txtName.Text.Trim().Length > 0)
                    {
                        query.And(Exp.Like("m.ItemName", "%" + this.txtName.Text.Trim() + "%"));
                    }
                    if (this.txtColor.Text.Trim().Length > 0)
                    {
                        query.And(Exp.Like("s.ColorCode", "%" + this.txtColor.Text.Trim().ToUpper() + "%"));
                    }
                    if (this.txtSize.Text.Trim().Length > 0)
                    {
                        query.And(Exp.Like("s.SizeCode", "%" + this.txtSize.Text.Trim().ToUpper() + "%"));
                    }
                    ds = query.DataSet();
                }
                if (ds == null)
                {
                    WebUtil.ShowError(this, "没有数据下载或者下载出错了");
                    return;
                }

                string fileName = DownloadUtil.DownloadXls("StockCheck_" + DateTime.Now.ToString("yyMMdd") + ".xls", "CK",
                                                           new List <DownloadFormat>()
                {
                    new DownloadFormat(DataType.NumberText, "行号", "LineNumber"),
                    new DownloadFormat(DataType.Text, "库位", "AreaCode"),
                    new DownloadFormat(DataType.NumberText, "货架", "SectionCode"),
                    new DownloadFormat(DataType.NumberText, "SKU", "SKU"),
                    new DownloadFormat(DataType.NumberText, "货号", "ItemCode"),
                    new DownloadFormat(DataType.Text, "颜色", "ColorCode", "ColorText"),
                    new DownloadFormat(DataType.Text, "尺码", "SizeCode"),
                    new DownloadFormat((head.CheckType == INVCheckType.Implicit && head.Status == INVCheckStatus.Confirm ? DataType.Text : DataType.Number), "系统数量", "BeforeQty"),
                    new DownloadFormat(DataType.Number, "盘点数量", "CurrentQty"),
                    new DownloadFormat(DataType.Text, "商品名称", "ItemName")
                }, ds);
                this.frameDownload.Attributes["src"] = fileName;
                #endregion
            }
            else if (e.CommandName == "Save")
            {
                #region 保存
                using (ISession session = new Session())
                {
                    try
                    {
                        session.BeginTransaction();

                        foreach (RepeaterItem item in this.repeatControl.Items)
                        {
                            TextBox text = item.FindControl("txtQty") as TextBox;
                            if (text == null)
                            {
                                continue;
                            }
                            string lineNum = text.Attributes["lineNumber"];
                            if (string.IsNullOrEmpty(lineNum) || lineNum.Trim().Length <= 0)
                            {
                                continue;
                            }
                            INVCheckLine line = INVCheckLine.Retrieve(session, this.OrderNumber, lineNum);
                            if (line != null)
                            {
                                line.CurrentQty = Cast.Decimal(text.Text, line.CurrentQty);
                                line.Update(session, "CurrentQty");
                            }
                        }

                        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
                    {
                        INVCheckHead head = INVCheckHead.Retrieve(session, this.OrderNumber);
                        session.BeginTransaction();
                        head.Release(session);
                        session.Commit();
                        WebUtil.ShowMsg(this, "发布成功");
                        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
                    {
                        INVCheckHead head = INVCheckHead.Retrieve(session, this.OrderNumber);
                        session.BeginTransaction();
                        head.Close(session);
                        session.Commit();
                        WebUtil.ShowMsg(this, "关闭成功,本次盘点任务已经完成");
                        this.SetView(head);
                    }
                    catch (Exception er)
                    {
                        session.Rollback();
                        WebUtil.ShowError(this, er);
                    }
                }
                #endregion
            }
        }
        catch (Exception err)
        {
            WebUtil.ShowError(this, err);
        }
    }