Exemple #1
0
    private void SaveItem(INVCheckLine objLine, string ItemName, string SizeText, string ColorText, string LocationName, string AreaName, string SectionName)
    {
        DataSet dt = Session["InvAdjustmentItem"] as DataSet;

        if ((dt != null) || (dt.Tables[0].Rows.Count == 0))
        {
            // Add`
            //    SELECT A.BeforeQty AS BeforeQty,A.CurrentQty AS CurrentQty,C.ItemCode AS ItemCode,B.SKUID AS SKUID,
            //C.ItemName AS ItemName,E.SizeText AS SizeText,D.ColorText AS ColorText,
            //L.Name AS LocationName,R.Name AS AreaName,S.Text AS SectionName,L.LocationCode AS LocationCode,
            //R.AreaCode AS AreaCode,S.SectionCode AS SectionCode
            DataRow dtRow = dt.Tables[0].NewRow();
            dtRow["CurrentQty"]   = objLine.CurrentQty;
            dtRow["BeforeQty"]    = objLine.BeforeQty;
            dtRow["ItemCode"]     = "";
            dtRow["SKUID"]        = objLine.SKUID;
            dtRow["ItemName"]     = ItemName;
            dtRow["SizeText"]     = SizeText;
            dtRow["ColorText"]    = ColorText;
            dtRow["LocationName"] = LocationName;
            dtRow["AreaName"]     = AreaName;
            dtRow["SectionName"]  = SectionName;
            dtRow["LocationCode"] = objLine.LocationCode;
            dtRow["AreaCode"]     = objLine.AreaCode;
            dtRow["SectionCode"]  = objLine.SectionCode;
            dt.Tables[0].Rows.Add(dtRow);
        }
        else
        {
            dt.Tables[0].Rows[0]["CurrentQty"] = objLine.CurrentQty;
        }

        Session["InvAdjustmentItem"] = dt;

        this.rptInvCheck.DataSource = dt;
        this.rptInvCheck.DataBind();
    }
Exemple #2
0
    private void SaveCheckOrder()
    {
        try
        {
            DataSet ds = Session["InvAdjustmentItem"] as DataSet;

            Dictionary <int, int> lstCurrentQuantity = new Dictionary <int, int>();
            for (int i = 0; i < this.rptInvCheck.Items.Count; i++)
            {
                TextBox objBox = this.rptInvCheck.Items[i].FindControl("txtCurrentQuantity") as TextBox;
                System.Web.UI.HtmlControls.HtmlInputHidden objSKU = this.rptInvCheck.Items[i].FindControl("hidSKUID") as System.Web.UI.HtmlControls.HtmlInputHidden;
                try
                {
                    lstCurrentQuantity.Add(Cast.Int(objSKU.Value), Cast.Int(objBox.Text));
                }
                catch (Exception ex)
                {
                    WebUtil.ShowMsg(this, "调整数量非法,请重新输入!");
                    return;
                }
            }

            using (_session = new Session())
            {
                _session.BeginTransaction();
                try
                {
                    INVCheckHead objHead = INVCheckHead.Retrieve(_session, this.txtInvCheckNumber.Text);

                    bool blnInsert = false;
                    if (objHead == null)
                    {
                        blnInsert             = true;
                        objHead               = new INVCheckHead();
                        objHead.CreateTime    = DateTime.Now;
                        objHead.CreateUser    = Magic.Security.SecuritySession.CurrentUser.UserId;
                        objHead.Note          = this.txtMemo.Text;
                        objHead.OrderNumber   = Magic.ERP.ERPUtil.NextOrderNumber(Magic.ERP.Orders.INVCheckHead.ORDER_TYPE_ADJ);
                        objHead.OrderTypeCode = INVCheckHead.ORDER_TYPE_ADJ;
                        objHead.Status        = Magic.ERP.INVCheckStatus.New;
                        objHead.Create(_session);
                    }
                    else
                    {
                        if ((objHead.Status == Magic.ERP.INVCheckStatus.Release) || (objHead.Status == Magic.ERP.INVCheckStatus.Close))
                        {
                            WebUtil.ShowMsg(this, "发布以后的盘点单不可以进行修改");
                            return;
                        }

                        objHead.Note = this.txtMemo.Text;
                        blnInsert    = false;
                        _session.CreateEntityQuery <INVCheckLine>().Where(Exp.Eq("OrderNumber", objHead.OrderNumber)).Delete();
                    }

                    objHead.CurrentLineNumber = "";


                    List <INVCheckLine> List = new List <INVCheckLine>();
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        INVCheckLine objLine = new INVCheckLine();
                        objLine.SKUID        = Cast.Int(ds.Tables[0].Rows[i]["SKUID"]);
                        objLine.AreaCode     = Cast.String(ds.Tables[0].Rows[i]["AreaCode"]);
                        objLine.BeforeQty    = Cast.Decimal(ds.Tables[0].Rows[i]["BeforeQty"]);
                        objLine.CurrentQty   = lstCurrentQuantity[objLine.SKUID];
                        objLine.LineNumber   = objHead.NextLineNumber();
                        objLine.LocationCode = Cast.String(ds.Tables[0].Rows[i]["LocationCode"]);
                        objLine.OrderNumber  = objHead.OrderNumber;
                        objLine.SectionCode  = Cast.String(ds.Tables[0].Rows[i]["SectionCode"]);
                        objLine.Create(_session);
                    }

                    objHead.Update(_session, "CurrentLineNumber");

                    this.txtInvCheckNumber.Text = objHead.OrderNumber;
                    _session.Commit();
                }
                catch (Exception ex)
                {
                    _session.Rollback();
                    throw ex;
                }
            }
            WebUtil.ShowMsg(this, "库存盘点单保存成功", "操作成功");
        }
        catch (Exception ex)
        {
            logger.Info("保存库存盘点单", ex);
            WebUtil.ShowMsg(this, "发生未处理的异常,请刷新页面重新操作,或者联系系统管理员");
        }
    }
Exemple #3
0
    protected void MagicItemCommand(object sender, MagicItemEventArgs e)
    {
        if (e.CommandName == "Save")
        {
            SaveCheckOrder();
        }

        if (e.CommandName == "Close")
        {
            try
            {
                if (this.txtInvCheckNumber.Text.Trim().Length == 0)
                {
                    WebUtil.ShowMsg(this, "只有签核通过的库存调整单才可以关闭!");
                    return;
                }

                using (_session = new Session())
                {
                    Magic.ERP.Orders.INVCheckHead objhead = Magic.ERP.Orders.INVCheckHead.Retrieve(_session, this.txtInvCheckNumber.Text.Trim());
                    if ((objhead.Status == Magic.ERP.INVCheckStatus.Release) && (objhead.ApproveResult == Magic.ERP.ApproveStatus.Approve))
                    {
                        Magic.ERP.ERPUtil.CommitWHTrans(_session, objhead);
                    }
                    else
                    {
                        WebUtil.ShowMsg(this, "只有签核通过的库存调整单才可以关闭!");
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                WebUtil.ShowMsg(this, "关闭库存调整单失败,请与管理员联系!");
            }
        }

        if (e.CommandName == "Insert")
        {
            try
            {
                if (this.hidSkuId.Value.Trim().Length == 0)
                {
                    WebUtil.ShowMsg(this, "请先选择物料!");
                    return;
                }
                string strSKUID       = this.hidSkuId.Value;
                string strLocation    = this.ddlLocation.SelectedValue;
                string strArea        = this.ddlArea.SelectedValue;
                string strSection     = this.ddlSection.SelectedValue;
                int    intNewQuantity = 0;
                try
                {
                    intNewQuantity = int.Parse(this.txtNewQuantity.Text);
                    if (intNewQuantity < 0)
                    {
                        WebUtil.ShowMsg(this, "物料库存数量必须为整数,请重新输入!");
                        return;
                    }
                }
                catch (Exception ex)
                {
                    WebUtil.ShowMsg(this, "物料库存数量必须为整数,请重新输入!");
                    return;
                }

                using (_session = new Session())
                {
                }

                Magic.ERP.Orders.INVCheckLine objLine = new INVCheckLine();
                objLine.AreaCode     = strArea;
                objLine.BeforeQty    = int.Parse(this.txtOldQuantity.Value);
                objLine.CurrentQty   = intNewQuantity;
                objLine.LineNumber   = "";
                objLine.LocationCode = strLocation;
                objLine.OrderNumber  = this.txtInvCheckNumber.Text;
                objLine.SectionCode  = strSection;
                objLine.SKUID        = int.Parse(strSKUID);

                SaveItem(objLine, this.txtItemName.Value, this.txtItemSize.Value, this.txtItemColor.Value, this.ddlLocation.SelectedItem.Text,
                         this.ddlArea.SelectedItem.Text, this.ddlSection.SelectedItem.Text);

                if (this.tblAddItem.Style["display"] == null)
                {
                    this.tblAddItem.Style.Add("display", "none");
                }
                else
                {
                    this.tblAddItem.Style["display"] = "none";
                }

                this.txtItemName.Value         = "";
                this.txtItemColor.Value        = "";
                this.txtItemSize.Value         = "";
                this.ddlLocation.SelectedIndex = 0;
                this.txtOldQuantity.Value      = "0";
                this.txtNewQuantity.Text       = "";
                this.ddlArea.Items.Clear();
                this.ddlSection.Items.Clear();
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                WebUtil.ShowError(this, ex);
            }
        }

        if (e.CommandName == "Return")
        {
            string strURL = "StockAdjustmentManage.aspx";
            if ((WebUtil.Param("return") != null) && (WebUtil.Param("return").Length > 0))
            {
                strURL = WebUtil.Param("return").Trim();
            }
            Response.Redirect(strURL);
        }
    }
Exemple #4
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);
        }
    }
Exemple #6
0
    protected void MagicItemCommand(object sender, MagicItemEventArgs e)
    {
        if (e.CommandName == "Save")
        {
            if (this.FileUpload1.FileName.Trim().Length <= 0)
            {
                WebUtil.ShowMsg(this, "请选择盘点结果文件");
                return;
            }
            string fileName = this.FileUpload1.FileName;
            if (!fileName.EndsWith(".xls"))
            {
                WebUtil.ShowMsg(this, "请选择有效的Excel文件");
                return;
            }
            string filePath = System.IO.Path.Combine(DownloadUtil.DownloadFolder, "CK_IMP_" + DateTime.Now.ToString("yyMMdd_HHmmss") + ".xls");
            this.FileUpload1.SaveAs(filePath);
            IList <INVCheckLine> lines = new List <INVCheckLine>();

            #region 读取文件
            ExcelApp       excelapp   = null;
            ExcelWorkbook  excelBook  = null;
            ExcelWorksheet excelSheet = null;
            try
            {
                excelapp = new ExcelApp();
                excelapp.DisplayAlerts = false;
                excelBook  = excelapp.Open(filePath, 0);
                excelSheet = excelBook.Worksheets(1);
                int     rowIndex = 2;
                string  lineNum  = Cast.String(excelSheet.Range(rowIndex, rowIndex, 1, 1).Value).Trim();
                decimal qty;
                while (lineNum.Length == 4)
                {
                    qty = Cast.Decimal(excelSheet.Range(rowIndex, rowIndex, 9, 9).Value, 0M);
                    INVCheckLine line = new INVCheckLine();
                    line.LineNumber = lineNum;
                    line.CurrentQty = qty;
                    lines.Add(line);
                    rowIndex++;
                    lineNum = Cast.String(excelSheet.Range(rowIndex, rowIndex, 1, 1).Value).Trim();
                }
            }
            catch (Exception er)
            {
                WebUtil.ShowError(this, er.Message);
                return;
            }
            finally
            {
                if (excelSheet != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(excelSheet.COMObject);
                }
                if (excelBook != null)
                {
                    excelBook.Close();
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(excelBook.COMObject);
                }
                if (excelapp != null)
                {
                    excelapp.Quit();
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(excelapp.COMObject);
                }
            }
            #endregion

            using (ISession session = new Session())
            {
                try
                {
                    INVCheckHead head = INVCheckHead.Retrieve(session, WebUtil.Param("ordNum"));
                    if (head == null)
                    {
                        WebUtil.ShowError(this, "盘点单" + WebUtil.Param("ordNum") + "不存在");
                        return;
                    }
                    session.BeginTransaction();
                    head.ClearCheckQty(session);
                    head.UpdateLines(session, lines);
                    session.Commit();
                }
                catch (Exception er)
                {
                    session.Rollback();
                    WebUtil.ShowError(this, er.Message);
                    return;
                }
            }

            this.Response.Redirect(WebUtil.Param("return"));
        }
    }