public void InitPageParameter(string repackNo)
    {
        IList <TransformerDetail> repackDetailInList  = new List <TransformerDetail>();
        IList <TransformerDetail> repackDetailOutList = new List <TransformerDetail>();

        if (repackNo != string.Empty)
        {
            Repack repack = TheRepackMgr.LoadRepack(repackNo, true);
            IList <TransformerDetail> transformerDetailList = TransformerHelper.ConvertRepackDetailListToTransformerDetailList(repack.RepackDetails);
            foreach (TransformerDetail transformerDetail in transformerDetailList)
            {
                if (transformerDetail.IOType == BusinessConstants.IO_TYPE_IN)
                {
                    repackDetailInList.Add(transformerDetail);
                }
                else if (transformerDetail.IOType == BusinessConstants.IO_TYPE_OUT)
                {
                    repackDetailOutList.Add(transformerDetail);
                }
            }
        }

        this.GV_InList.DataSource = repackDetailInList;
        this.GV_InList.DataBind();
        this.GV_OutList.DataSource = repackDetailOutList;
        this.GV_OutList.DataBind();
    }
    public void InitPageParameter(string repackNo)
    {
        Repack repack = TheRepackMgr.LoadRepack(repackNo);

        this.lbRepackNo.Text   = repack.RepackNo;
        this.lbCreateUser.Text = repack.CreateUser.Name;
        this.lbCreateDate.Text = repack.CreateDate.ToString("yyyy-MM-dd");
        this.lblRepackNo.Text  = RepackHelper.GetRepackLabel(this.RepackType, true);
    }
    protected void btnPrint_Click(object sender, EventArgs e)
    {
        string         repackNo = this.lbRepackNo.Text;
        IList <object> list     = new List <object>();
        Repack         repack   = TheRepackMgr.LoadRepack(repackNo, true);

        list.Add(repack);
        string printUrl = TheReportMgr.WriteToFile("Repack.xls", list);

        Page.ClientScript.RegisterStartupScript(GetType(), "method", " <script language='javascript' type='text/javascript'>PrintOrder('" + printUrl + "'); </script>");
    }
    protected void btnRepack_Click(object sender, EventArgs e)
    {
        try
        {
            if (this.RepackType == BusinessConstants.CODE_MASTER_REPACK_TYPE_VALUE_REPACK)
            {
                if (this.IsQty)
                {
                    if (this.tbLocation.Text.Trim() == string.Empty)
                    {
                        ShowErrorMessage("MasterData.Inventory.Repack.Location.Empty");
                        return;
                    }

                    if (this.OutTransformerDetailList == null || this.OutTransformerDetailList.Count == 0)
                    {
                        ShowErrorMessage("MasterData.Inventory.Repack.Error.RepackDetailEmpty");
                        return;
                    }

                    IList <RepackDetail> repackDetailList = new List <RepackDetail>();


                    IDictionary <string, decimal> ItemDic = new Dictionary <string, decimal>();

                    foreach (TransformerDetail transformerDetail in OutTransformerDetailList)
                    {
                        RepackDetail outRepackDetail = new RepackDetail();

                        outRepackDetail.IOType = BusinessConstants.IO_TYPE_OUT;

                        outRepackDetail.Hu  = TheHuMgr.LoadHu(transformerDetail.HuId);
                        outRepackDetail.Qty = outRepackDetail.Hu.Qty * outRepackDetail.Hu.UnitQty;

                        if (ItemDic.ContainsKey(outRepackDetail.Hu.Item.Code))
                        {
                            ItemDic[outRepackDetail.Hu.Item.Code] += outRepackDetail.Qty;
                        }
                        else
                        {
                            ItemDic.Add(outRepackDetail.Hu.Item.Code, outRepackDetail.Qty);
                        }
                        repackDetailList.Add(outRepackDetail);
                    }
                    if (repackDetailList.Count > 0)
                    {
                        foreach (string item in ItemDic.Keys)
                        {
                            IList <LocationLotDetail> locationLotDetailList = TheLocationLotDetailMgr.GetLocationLotDetail(this.tbLocation.Text.Trim(), item, false, false, BusinessConstants.PLUS_INVENTORY, null, false);
                            if (locationLotDetailList == null || locationLotDetailList.Count == 0)
                            {
                                ShowErrorMessage("MasterData.Inventory.Repack.LocationLotDetail.Empty");
                                return;
                            }

                            decimal locQty = (from l in locationLotDetailList select l.Qty).Sum();
                            decimal outQty = ItemDic[item];
                            if (outQty > locQty)
                            {
                                ShowErrorMessage("MasterData.Inventory.LocationLotDetail.LessThanHuQty", item, locQty.ToString("0.########"), outQty.ToString("0.########"));
                                return;
                            }

                            foreach (LocationLotDetail locationLotDetail in locationLotDetailList)
                            {
                                RepackDetail inRepackDetail = new RepackDetail();
                                inRepackDetail.LocationLotDetail = locationLotDetail;
                                inRepackDetail.IOType            = BusinessConstants.IO_TYPE_IN;
                                repackDetailList.Add(inRepackDetail);
                                if (locationLotDetail.Qty < outQty)
                                {
                                    inRepackDetail.Qty = locationLotDetail.Qty;
                                    outQty            -= inRepackDetail.Qty;
                                }
                                else
                                {
                                    inRepackDetail.Qty = outQty;
                                    break;
                                }
                            }
                        }
                    }


                    Repack repack = TheRepackMgr.CreateRepack(repackDetailList, this.CurrentUser);

                    if (this.IsQty)
                    {
                        RepackEvent(repack.RepackNo, e);
                    }
                }
                else
                {
                    ExecuteSubmit();
                    Repack     repack = TheRepackMgr.LoadRepack(this.CacheResolver.Code, true);
                    IList <Hu> huList = new List <Hu>();
                    foreach (RepackDetail repackDet in repack.RepackDetails)
                    {
                        if (repackDet.IOType == BusinessConstants.IO_TYPE_OUT && repackDet.LocationLotDetail.Hu != null &&
                            repackDet.LocationLotDetail.Hu.PrintCount == 0)
                        {
                            huList.Add(repackDet.LocationLotDetail.Hu);
                        }
                    }

                    if (huList.Count > 0)
                    {
                        IList <object> huDetailObj = new List <object>();

                        huDetailObj.Add(huList);
                        huDetailObj.Add(CurrentUser.Code);
                        string huTemplate = TheEntityPreferenceMgr.LoadEntityPreference(BusinessConstants.ENTITY_PREFERENCE_CODE_DEFAULT_HU_TEMPLATE).Value;
                        if (huTemplate != null && huTemplate.Length > 0)
                        {
                            string barCodeUrl = TheReportMgr.WriteToFile(huTemplate, huDetailObj, "BarCode.xls");
                            Page.ClientScript.RegisterStartupScript(GetType(), "method", " <script language='javascript' type='text/javascript'>PrintOrder('" + barCodeUrl + "'); </script>");
                        }
                    }
                }
            }
            else if (this.RepackType == BusinessConstants.CODE_MASTER_REPACK_TYPE_VALUE_DEVANNING)
            {
                UpdateOutTransformer();
                ExecuteSubmit();
            }
            if (RepackEvent != null && !this.IsQty)
            {
                RepackEvent(this.CacheResolver.Code, e);
            }
        }
        catch (BusinessErrorException ex)
        {
            ShowErrorMessage(ex);
        }
    }