protected void btnAddStyle_Click(object sender, EventArgs e)
 {
     List<ITEM> selected_items = STYLES;
     foreach (GridViewRow row in this.gvProductList.Rows)
     {
         CheckBox chkItem = (CheckBox)row.FindControl("chkItems");
         Image imgItem = (Image)row.FindControl("imgStyle");
         ITEM item = new ITEM
         {
             StyleNumber = row.Cells[4].Text,
             Brand = row.Cells[7].Text,
             CostPrice = decimal.Parse(imgItem.AlternateText),
             Description  =  (row.Cells[5].Text),
              APType = imgItem.ToolTip
         };
         if (chkItem.Checked)
         {
             if (!IsAlreadySelected(selected_items, item.StyleNumber, item.Description))
             {
                 selected_items.Add(item);
             }
         }
     }
     CheckHasSelected(selected_items);
     gvSelectedStyles.DataSource = selected_items;
     gvSelectedStyles.DataBind();
        UncheckSelectedStyles();
 }
        public void GetSelectedItems()
        {
            List<ITEM> selected_items = new List<ITEM>();
            foreach (GridViewRow row in this.gvItems.Rows)
            {
                CheckBox chkItem = (CheckBox)row.FindControl("chkItems");
                ITEM item = new ITEM
                {
                    StyleNumber = row.Cells[3].Text,
                    Description = row.Cells[4].Text
                };
                if (chkItem.Checked)
                {
                    selected_items.Add(item);
                }
            }
            gvSelectedItems.DataSource = selected_items;
            gvSelectedItems.DataBind();

            lblBarCode.Text = GenerateBarCode(DDLBrands.SelectedValue);
            lblSelectedItemsModalHandler_ModalPopupExtender.Show();
        }
 private StylePrice getSRP(ITEM item_, StylePrice price_)
 {
     DataTable price = PManager.GetSRP(int.Parse(hfPGNo.Value), item_.StyleNumber);
     foreach (DataRow row in price.Rows)
     {
         switch (int.Parse(hfPGNo.Value))
         {
             case 1:
                 price_ = new StylePrice
                 {
                     ID = int.Parse(row[0].ToString()),
                     StyleNo = item_.StyleNumber,
                     Price = decimal.Parse(row[6].ToString()),
                     PriceType = "REGULAR PRICE",
                     GrpNo = item_.Description,
                     GenMemoID = (int)item_.CostPrice, // as quantity
                     PGNo = item_.Box.ToString(),// as box number
                     APType = item_.APType
                 };
                 break;
             case 2:
                 price_ = new StylePrice
                 {
                     ID = int.Parse(row[0].ToString()),
                     StyleNo = item_.StyleNumber,
                     Price = decimal.Parse(row[7].ToString()),
                     PriceType = "REGULAR PRICE",
                     GrpNo = item_.Description,
                     PGNo = item_.Box.ToString(),// as box number
                     GenMemoID = (int)item_.CostPrice, // as quantity
                     APType = item_.APType
                 };
                 break;
             case 3:
                 price_ = new StylePrice
                 {
                     ID = int.Parse(row[0].ToString()),
                     StyleNo = item_.StyleNumber,
                     Price = decimal.Parse(row[8].ToString()),
                     PriceType = "REGULAR PRICE",
                     GrpNo = item_.Description,
                     PGNo = item_.Box.ToString(),// as box number
                     GenMemoID = (int)item_.CostPrice, // as quantity
                     APType = item_.APType
                 };
                 break;
             case 4:
                 price_ = new StylePrice
                 {
                     ID = int.Parse(row[0].ToString()),
                     StyleNo = item_.StyleNumber,
                     Price = decimal.Parse(row[9].ToString()),
                     PriceType = "REGULAR PRICE",
                     GrpNo = item_.Description,
                     PGNo = item_.Box.ToString(),// as box number
                     GenMemoID = (int)item_.CostPrice, // as quantity
                     APType = item_.APType
                 };
                 break;
             case 5:
                 price_ = new StylePrice
                 {
                     ID = int.Parse(row[0].ToString()),
                     StyleNo = item_.StyleNumber,
                     Price = decimal.Parse(row[10].ToString()),
                     PriceType = "REGULAR PRICE",
                     GrpNo = item_.Description,
                     PGNo = item_.Box.ToString(),// as box number
                     GenMemoID = (int)item_.CostPrice, // as quantity
                     APType = item_.APType
                 };
                 break;
             case 6:
                 price_ = new StylePrice
                 {
                     ID = int.Parse(row[0].ToString()),
                     StyleNo = item_.StyleNumber,
                     Price = decimal.Parse(row[11].ToString()),
                     PriceType = "REGULAR PRICE",
                     GrpNo = item_.Description,
                     PGNo = item_.Box.ToString(),// as box number
                     GenMemoID = (int)item_.CostPrice, // as quantity
                     APType = item_.APType
                 };
                 break;
             case 7:
                 price_ = new StylePrice
                 {
                     ID = int.Parse(row[0].ToString()),
                     StyleNo = item_.StyleNumber,
                     Price = decimal.Parse(row[12].ToString()),
                     PriceType = "REGULAR PRICE",
                     GrpNo = item_.Description,
                     PGNo = item_.Box.ToString(),// as box number
                     GenMemoID = (int)item_.CostPrice, // as quantity
                     APType = item_.APType
                 };
                 break;
             case 8:
                 price_ = new StylePrice
                 {
                     ID = int.Parse(row[0].ToString()),
                     StyleNo = item_.StyleNumber,
                     Price = decimal.Parse(row[13].ToString()),
                     PriceType = "REGULAR PRICE",
                     GrpNo = item_.Description,
                     PGNo = item_.Box.ToString(),// as box number
                     GenMemoID = (int)item_.CostPrice, // as quantity
                     APType = item_.APType
                 };
                 break;
             case 9:
                 price_ = new StylePrice
                 {
                     ID = int.Parse(row[0].ToString()),
                     StyleNo = item_.StyleNumber,
                     Price = decimal.Parse(row[14].ToString()),
                     PriceType = "REGULAR PRICE",
                     PGNo = item_.Box.ToString(),// as box number
                     GenMemoID = (int)item_.CostPrice, // as quantity
                     APType = item_.APType
                 };
                 break;
             case 10:
                 price_ = new StylePrice
                 {
                     ID = int.Parse(row[0].ToString()),
                     StyleNo = item_.StyleNumber,
                     Price = decimal.Parse(row[15].ToString()),
                     PriceType = "REGULAR PRICE",
                     GrpNo = item_.Description,
                     PGNo = item_.Box.ToString(),// as box number
                     GenMemoID = (int)item_.CostPrice, // as quantity
                     APType = item_.APType
                 };
                 break;
             case 11:
                 price_ = new StylePrice
                 {
                     ID = int.Parse(row[0].ToString()),
                     StyleNo = item_.StyleNumber,
                     Price = decimal.Parse(row[16].ToString()),
                     PriceType = "REGULAR PRICE",
                     GrpNo = item_.Description,
                     PGNo = item_.Box.ToString(),// as box number
                     GenMemoID = (int)item_.CostPrice, // as quantity
                     APType = item_.APType
                 };
                 break;
             case 12:
                 price_ = new StylePrice
                 {
                     ID = int.Parse(row[0].ToString()),
                     StyleNo = item_.StyleNumber,
                     Price = decimal.Parse(row[17].ToString()),
                     PriceType = "REGULAR PRICE",
                     GrpNo = item_.Description,
                     PGNo = item_.Box.ToString(),// as box number
                     GenMemoID = (int)item_.CostPrice, // as quantity
                     APType = item_.APType
                 };
                 break;
             case 13:
                 price_ = new StylePrice
                 {
                     ID = int.Parse(row[0].ToString()),
                     StyleNo = item_.StyleNumber,
                     Price = decimal.Parse(row[18].ToString()),
                     PriceType = "REGULAR PRICE",
                     GrpNo = item_.Description,
                     PGNo = item_.Box.ToString(),// as box number
                     GenMemoID = (int)item_.CostPrice, // as quantity
                     APType = item_.APType
                 };
                 break;
             case 14:
                 price_ = new StylePrice
                 {
                     ID = int.Parse(row[0].ToString()),
                     StyleNo = item_.StyleNumber,
                     Price = decimal.Parse(row[19].ToString()),
                     PriceType = "REGULAR PRICE",
                     GrpNo = item_.Description,
                     PGNo = item_.Box.ToString(),// as box number
                     GenMemoID = (int)item_.CostPrice, // as quantity
                     APType = item_.APType
                 };
                 break;
             case 15:
                 price_ = new StylePrice
                 {
                     ID = int.Parse(row[0].ToString()),
                     StyleNo = item_.StyleNumber,
                     Price = decimal.Parse(row[20].ToString()),
                     PriceType = "REGULAR PRICE",
                     GrpNo = item_.Description,
                     PGNo = item_.Box.ToString(),// as box number
                     GenMemoID = (int)item_.CostPrice, // as quantity
                     APType = item_.APType
                 };
                 break;
             case 16:
                 price_ = new StylePrice
                 {
                     ID = int.Parse(row[0].ToString()),
                     StyleNo = item_.StyleNumber,
                     Price = decimal.Parse(row[21].ToString()),
                     PriceType = "REGULAR PRICE",
                     GrpNo = item_.Description,
                     PGNo = item_.Box.ToString(),// as box number
                     GenMemoID = (int)item_.CostPrice, // as quantity
                     APType = item_.APType
                 };
                 break;
         }
     }
     return price_;
 }
        protected void btnAddSelected_Click(object sender, EventArgs e)
        {
            try
            {
                IList<PullOutLetterDetail> BoxItems = getSelectedStylesForBoxes();
                IList<ITEM> BoxesStyles = new List<ITEM>();
                List<StylePrice> BOX_PRICES = new List<StylePrice>();

                IList<PullOutLetterDetail> SackItems = getSelectedStylesForSacks();
                IList<ITEM> SacksStyles = new List<ITEM>();
                List<StylePrice> SACK_PRICES = new List<StylePrice>();

                List<Container> boxContainers = boxesContainer();
                List<Container> sackContainers = sacksContainer();

                long totalQty = long.Parse(txtTotalQTY.Text);
                long totalBoxContainersQty = BoxItems.Sum(b => b.Quantity);
                long totalSackContainersQty = SackItems.Sum(s => s.Quantity);
                long totalContainersQty = (totalBoxContainersQty + totalSackContainersQty);

                #region populate for boxes
                foreach (GridViewRow row in gvStyles.Rows)
                {
                    CheckBox chkItem = (CheckBox)row.FindControl("chkItems");
                    TextBox txtQuantity = (TextBox)row.FindControl("txtQty");
                    CheckBox chkIsLostTag = (CheckBox)row.FindControl("chkIsLostTag");
                    if (chkItem.Checked)
                    {
                        int qty;
                        if (string.IsNullOrEmpty(txtQuantity.Text) || int.TryParse(txtQuantity.Text, out qty) == false)
                        {
                            txtQuantity.Text = "1";
                        }

                        //for boxes
                        if (chkBoxList.Items.Count > 0)
                        {
                            for (int i = 0; i < chkBoxList.Items.Count; i++)
                            {
                                if (chkBoxList.Items[i].Selected)
                                {
                                    ITEM style = new ITEM
                                    {
                                        APType = chkIsLostTag.Checked.ToString(),
                                        Brand = hfFromBrand.Value,
                                        CostPrice = decimal.Parse(txtQuantity.Text), //as quantity
                                        Description = row.Cells[4].Text,
                                        StyleNumber = row.Cells[2].Text,
                                        Box = int.Parse(chkBoxList.Items[i].Value)
                                    };
                                    if (!isAlreadySelected(BoxItems, style.StyleNumber, int.Parse(chkBoxList.Items[i].Value)))
                                    {
                                        BoxesStyles.Add(style);
                                    }
                                }
                            }
                        }

                        //for sacks
                        if (chkSackList.Items.Count > 0)
                        {
                            for (int i = 0; i < this.chkSackList.Items.Count; i++)
                            {
                                if (chkSackList.Items[i].Selected)
                                {
                                    ITEM style = new ITEM
                                    {
                                        APType = chkIsLostTag.Checked.ToString(),
                                        Brand =hfFromBrand.Value,
                                        CostPrice = decimal.Parse(txtQuantity.Text), //as quantity
                                        Description = row.Cells[4].Text,
                                        StyleNumber = row.Cells[2].Text,
                                        Box = int.Parse(chkSackList.Items[i].Value)
                                    };
                                    if (!isAlreadySelected(SackItems, style.StyleNumber, int.Parse(chkSackList.Items[i].Value)))
                                    {
                                        SacksStyles.Add(style);
                                    }
                                }
                            }
                        }

                    }
                }

                if (totalQty > totalContainersQty)
                {
                    this.lblErrorMessage.Text = "";
                    this.hfErrorModalHandLer_ModalPopupExtender.Show();
                    return;
                }

                //for boxes
                if (chkBoxList.Items.Count > 0)
                {
                    foreach (ITEM item_ in BoxesStyles)
                    {
                        StylePrice price_ = new StylePrice();
                        price_ = PricePointManager.GetStyleCurrentPrice(item_.StyleNumber, int.Parse(hfPGMDNo.Value),
                           int.Parse(hfAreaGroupNo.Value), int.Parse(hfSubAreaGroupNo.Value), int.Parse(hfCustomerNumber.Value));
                        if (price_ != null)
                        {
                            price_.PriceType = "MARKDOWN";
                            price_.PGNo = item_.Box.ToString();//as boxNumber
                            price_.GrpNo = item_.Description; //as Description
                            price_.APType = item_.APType;
                            price_.StyleNo = item_.StyleNumber;
                            price_.SRP = getSRP(item_, price_).Price;
                            price_.GenMemoID = (int)item_.CostPrice; // as quantity
                            BOX_PRICES.Add(price_);
                        }
                        else
                        {
                            price_ = getSRP(item_, price_);
                            BOX_PRICES.Add(price_);
                        }
                    }

                    foreach (StylePrice price_ in BOX_PRICES)
                    {
                        PullOutLetterDetail pd = new PullOutLetterDetail
                        {
                            ContainerNumber = int.Parse(price_.PGNo),
                            StyleDescription = price_.GrpNo,
                            Quantity = price_.GenMemoID,
                            SRP = price_.Price,
                            StyleNumber = price_.StyleNo,
                            TtlAmount = (price_.GenMemoID * price_.Price),
                            IsLostTag = bool.Parse(price_.APType)
                           ,
                            ContainerType = "BOX",
                            PullOutLetterCode = hfPullOutLetterCode.Value
                        };
                        BoxItems.Add(pd);
                    }

                    gvSelectedStyles.DataSource = BoxItems.OrderBy(s => s.ContainerNumber).ThenBy(s => s.StyleNumber);
                    gvSelectedStyles.DataBind();
                }
                //for sacks
                if (chkSackList.Items.Count > 0)
                {
                    foreach (ITEM item_ in SacksStyles)
                    {
                        StylePrice price_ = new StylePrice();
                        price_ = PricePointManager.GetStyleCurrentPrice(item_.StyleNumber, int.Parse(hfPGMDNo.Value),
                           int.Parse(hfAreaGroupNo.Value), int.Parse(hfSubAreaGroupNo.Value), int.Parse(hfCustomerNumber.Value));
                        if (price_ != null)
                        {
                            price_.PriceType = "MARKDOWN";
                            price_.PGNo = item_.Box.ToString();//as boxNumber
                            price_.GrpNo = item_.Description; //as Description
                            price_.APType = item_.APType;
                            price_.StyleNo = item_.StyleNumber;
                            price_.SRP = getSRP(item_, price_).Price;
                            price_.GenMemoID = (int)item_.CostPrice; // as quantity
                            SACK_PRICES.Add(price_);
                        }
                        else
                        {
                            price_ = getSRP(item_, price_);
                            SACK_PRICES.Add(price_);
                        }
                    }

                    foreach (StylePrice price_ in SACK_PRICES)
                    {
                        PullOutLetterDetail pd = new PullOutLetterDetail
                        {
                            ContainerNumber = int.Parse(price_.PGNo),
                            StyleDescription = price_.GrpNo,
                            Quantity = price_.GenMemoID,
                            SRP = price_.Price,
                            StyleNumber = price_.StyleNo,
                            TtlAmount = (price_.GenMemoID * price_.Price),
                            IsLostTag = bool.Parse(price_.APType),
                            ContainerType = "SACK",
                            PullOutLetterCode = hfPullOutLetterCode.Value
                        };
                        SackItems.Add(pd);
                    }

                    this.gvSelectedStylesForSacks.DataSource = SackItems.OrderBy(s => s.ContainerNumber).ThenBy(s => s.StyleNumber);
                    gvSelectedStylesForSacks.DataBind();
                }
                uncheckSelectedStyles();
                #endregion
            }
            catch (Exception ex)
            {
                lblErrorMessage.Text = ex.Message;
                hfErrorModalHandLer_ModalPopupExtender.Show();
                //throw;
            }
        }
        protected void btnSaveSelectedStyles_Click(object sender, EventArgs e)
        {
            List<PullOutLetterDetail> selectedItems = new List<PullOutLetterDetail>();

            IList<ITEM> ContainerStyles = new List<ITEM>();
            List<StylePrice> STYLE_PRICES = new List<StylePrice>();

            int containerNumber = 0;
            string containerType = string.Empty;
            if (pnlContainerOptions.Visible)
            {
                containerType = rdioContainers.SelectedValue.ToString().Split('#')[0];
                containerNumber = int.Parse(rdioContainers.SelectedValue.ToString().Split('#')[1]);
            }
            else
            {
               containerType= gvContainers.SelectedValue.ToString().Split('#')[0];
               containerNumber =int.Parse(gvContainers.SelectedValue.ToString().Split('#')[1]);
            }
            #region populate for boxes
            foreach (GridViewRow row in gvStyles.Rows)
            {
                CheckBox chkItem = (CheckBox)row.FindControl("chkStyles");
                TextBox txtQuantity = (TextBox)row.FindControl("txtQty");
                if (chkItem.Checked)
                {
                    int qty;
                    if (string.IsNullOrEmpty(txtQuantity.Text) || int.TryParse(txtQuantity.Text, out qty) == false)
                    {
                        txtQuantity.Text = "1";
                    }

                    if (rdioContainers.Items.Count > 0)
                    {
                        ITEM style = new ITEM
                        {
                            APType = "False",
                            Brand = txtBrand.Text,
                            CostPrice = decimal.Parse(txtQuantity.Text), //as quantity
                            Description = row.Cells[4].Text,
                            StyleNumber = row.Cells[2].Text,
                            Box = containerNumber
                        };
                         ContainerStyles.Add(style);
                     }
                }
            }

            if (rdioContainers.Items.Count > 0)
            {
                foreach (ITEM item_ in ContainerStyles)
                {
                    StylePrice price_ = new StylePrice();
                    price_ = PricePointManager.GetStyleCurrentPrice(item_.StyleNumber, int.Parse(hfPGMDNo.Value),
                       int.Parse(hfAreaGroupNo.Value), int.Parse(hfSubAreaGroupNo.Value), int.Parse(hfCustomerNumber.Value));
                    if (price_ != null)
                    {
                        price_.PriceType = "MARKDOWN";
                        price_.PGNo = item_.Box.ToString();//as boxNumber
                        price_.GrpNo = item_.Description; //as Description
                        price_.APType = item_.APType;
                        price_.StyleNo = item_.StyleNumber;
                        price_.SRP = getSRP(item_, price_).Price;
                        price_.GenMemoID = (int)item_.CostPrice; // as quantity
                        STYLE_PRICES.Add(price_);
                    }
                    else
                    {
                        price_ = getSRP(item_, price_);
                        STYLE_PRICES.Add(price_);
                    }
                }

                foreach (StylePrice price_ in STYLE_PRICES)
                {
                    PullOutLetterDetail pd = new PullOutLetterDetail
                    {
                        ContainerNumber = int.Parse(price_.PGNo),
                        StyleDescription = price_.GrpNo,
                        Quantity = price_.GenMemoID,
                        SRP = price_.Price,
                        StyleNumber = price_.StyleNo,
                        TtlAmount = (price_.GenMemoID * price_.Price),
                        IsLostTag = bool.Parse(price_.APType),
                        ContainerType =containerType,
                        PullOutLetterCode = hfPullOutCode.Value
                    };
                    selectedItems.Add(pd);
                }

                POLDetailManager.Save(selectedItems);
                PullOutLetter pullOutLetter = POLManager.FetchById(int.Parse(Request.QueryString["PullOutId"]));
                pullOutLetter.TotalQuantity += (int)selectedItems.Sum(s => s.Quantity);
                POLManager.Save(pullOutLetter);
                ReloadDetailsView();

            }
            #endregion
        }
 private List<ITEM> GetSelectedStyles()
 {
     List<ITEM> selected_items = new List<ITEM>();
     foreach (GridViewRow row in this.gvSelectedStyles.Rows)
     {
         CheckBox chkItem = (CheckBox)row.FindControl("chkItems");
       Image imgItem = (Image)row.FindControl("imgStyle");
         ITEM item = new ITEM
         {
             StyleNumber = row.Cells[2].Text,
             Brand = row.Cells[3].Text,
             CostPrice = decimal.Parse(imgItem.AlternateText.Split('-')[0]),
             Description  = imgItem.ToolTip,
             APType = imgItem.AlternateText.Split('-')[1]
         };
         if (!chkItem.Checked)
         {
             selected_items.Add(item);
         }
     }
     return selected_items;
 }
        private StylePrice GetSRP(ITEM item_, StylePrice price_)
        {
            DataTable price = PManager.GetSRP(CUSTOMER.PriceGroupNo, item_.StyleNumber);
            foreach (DataRow row in price.Rows)
            {
                switch (CUSTOMER.PriceGroupNo)
                {
                    case 1:
                        price_ = new StylePrice
                        {
                            ID = int.Parse(row[0].ToString()),
                            StyleNo = item_.StyleNumber,
                            Price = decimal.Parse(row[6].ToString()),
                            PriceType = "REGULAR PRICE",
                             GrpNo = item_.Description,
                              PGNo = item_.CostPrice.ToString("###,###.00"),
                              APType = item_.APType
                        };
                        break;
                    case 2:
                        price_ = new StylePrice
                        {
                            ID = int.Parse(row[0].ToString()),
                            StyleNo = item_.StyleNumber,
                            Price = decimal.Parse(row[7].ToString()),
                            PriceType = "REGULAR PRICE",
                            GrpNo = item_.Description,
                            PGNo = item_.CostPrice.ToString("###,###.00"),
                            APType = item_.APType
                        };
                        break;
                    case 3:
                        price_ = new StylePrice
                        {
                            ID = int.Parse(row[0].ToString()),
                            StyleNo = item_.StyleNumber,
                            Price = decimal.Parse(row[8].ToString()),
                            PriceType = "REGULAR PRICE",
                            GrpNo = item_.Description,
                            PGNo = item_.CostPrice.ToString("###,###.00"),
                            APType = item_.APType
                        };
                        break;
                    case 4:
                        price_ = new StylePrice
                        {
                            ID = int.Parse(row[0].ToString()),
                            StyleNo = item_.StyleNumber,
                            Price = decimal.Parse(row[9].ToString()),
                            PriceType = "REGULAR PRICE",
                            GrpNo = item_.Description,
                            PGNo = item_.CostPrice.ToString("###,###.00"),
                            APType = item_.APType
                        };
                        break;
                    case 5:
                        price_ = new StylePrice
                        {
                            ID = int.Parse(row[0].ToString()),
                            StyleNo = item_.StyleNumber,
                            Price = decimal.Parse(row[10].ToString()),
                            PriceType = "REGULAR PRICE",
                            GrpNo = item_.Description,
                            PGNo = item_.CostPrice.ToString("###,###.00"),
                            APType = item_.APType
                        };
                        break;
                    case 6:
                        price_ = new StylePrice
                        {
                            ID = int.Parse(row[0].ToString()),
                            StyleNo = item_.StyleNumber,
                            Price = decimal.Parse(row[11].ToString()),
                            PriceType = "REGULAR PRICE",
                            GrpNo = item_.Description,
                            PGNo = item_.CostPrice.ToString("###,###.00"),
                            APType = item_.APType
                        };
                        break;
                    case 7:
                        price_ = new StylePrice
                        {
                            ID = int.Parse(row[0].ToString()),
                            StyleNo = item_.StyleNumber,
                            Price = decimal.Parse(row[12].ToString()),
                            PriceType = "REGULAR PRICE",
                            GrpNo = item_.Description,
                            PGNo = item_.CostPrice.ToString("###,###.00"),
                            APType = item_.APType
                        };
                        break;
                    case 8:
                        price_ = new StylePrice
                        {
                            ID = int.Parse(row[0].ToString()),
                            StyleNo = item_.StyleNumber,
                            Price = decimal.Parse(row[13].ToString()),
                            PriceType = "REGULAR PRICE",
                            GrpNo = item_.Description,
                            PGNo = item_.CostPrice.ToString("###,###.00"),
                            APType = item_.APType
                        };
                        break;
                    case 9:
                        price_ = new StylePrice
                        {
                            ID = int.Parse(row[0].ToString()),
                            StyleNo = item_.StyleNumber,
                            Price = decimal.Parse(row[14].ToString()),
                            PriceType = "REGULAR PRICE",
                            PGNo = item_.CostPrice.ToString("###,###.00"),
                            APType = item_.APType
                        };
                        break;
                    case 10:
                        price_ = new StylePrice
                        {
                            ID = int.Parse(row[0].ToString()),
                            StyleNo = item_.StyleNumber,
                            Price = decimal.Parse(row[15].ToString()),
                            PriceType = "REGULAR PRICE",
                            GrpNo = item_.Description,
                            PGNo = item_.CostPrice.ToString("###,###.00"),
                            APType = item_.APType
                        };
                        break;
                    case 11:
                        price_ = new StylePrice
                        {
                            ID = int.Parse(row[0].ToString()),
                            StyleNo = item_.StyleNumber,
                            Price = decimal.Parse(row[16].ToString()),
                            PriceType = "REGULAR PRICE",
                            GrpNo = item_.Description,
                            PGNo = item_.CostPrice.ToString("###,###.00"),
                            APType = item_.APType
                        };
                        break;
                    case 12:
                        price_ = new StylePrice
                        {
                            ID = int.Parse(row[0].ToString()),
                            StyleNo = item_.StyleNumber,
                            Price = decimal.Parse(row[17].ToString()),
                            PriceType = "REGULAR PRICE",
                            GrpNo = item_.Description,
                            PGNo = item_.CostPrice.ToString("###,###.00"),
                            APType = item_.APType
                        };
                        break;
                    case 13:
                        price_ = new StylePrice
                        {
                            ID = int.Parse(row[0].ToString()),
                            StyleNo = item_.StyleNumber,
                            Price = decimal.Parse(row[18].ToString()),
                            PriceType = "REGULAR PRICE",
                            GrpNo = item_.Description,
                            PGNo = item_.CostPrice.ToString("###,###.00"),
                            APType = item_.APType
                        };
                        break;
                    case 14:
                        price_ = new StylePrice
                        {
                            ID = int.Parse(row[0].ToString()),
                            StyleNo = item_.StyleNumber,
                            Price = decimal.Parse(row[19].ToString()),
                            PriceType = "REGULAR PRICE",
                            GrpNo = item_.Description,
                            PGNo = item_.CostPrice.ToString("###,###.00"),
                            APType = item_.APType
                        };
                        break;
                    case 15:
                        price_ = new StylePrice
                        {
                            ID = int.Parse(row[0].ToString()),
                            StyleNo = item_.StyleNumber,
                            Price = decimal.Parse(row[20].ToString()),
                            PriceType = "REGULAR PRICE",
                            GrpNo = item_.Description,
                            PGNo = item_.CostPrice.ToString("###,###.00"),
                            APType = item_.APType
                        };
                        break;
                    case 16:
                        price_ = new StylePrice
                        {
                            ID = int.Parse(row[0].ToString()),
                            StyleNo = item_.StyleNumber,
                            Price = decimal.Parse(row[21].ToString()),
                            PriceType = "REGULAR PRICE",
                            GrpNo = item_.Description,
                            PGNo = item_.CostPrice.ToString("###,###.00"),
                            APType = item_.APType
                        };
                        break;

                }

            }
            return price_;
        }
        protected void btnAddToDetails_Click(object sender, EventArgs e)
        {
            IList<PullOutLetterDetail> BoxItems = getSelectedStylesForBoxes();
            int containerNumber = int.Parse(gvPOLSummaries.SelectedValue.ToString());
            string containerType = gvPOLSummaries.SelectedDataKey[1].ToString();
            long totalQty =long.Parse(gvPOLSummaries.SelectedDataKey[2].ToString());
            long totalQtyPerContainer = BoxItems.Where(i => i.ContainerType == containerType && i.ContainerNumber == containerNumber).Sum(i => i.Quantity);
            int totalSelectedStyleTobeAdded = 0;
            try
            {

                IList<ITEM> ContainerStyles = new List<ITEM>();
                List<StylePrice> CONTAINER_PRICES = new List<StylePrice>();

                #region populate for boxes
                foreach (GridViewRow row in gvStyles.Rows)
                {
                    CheckBox chkItem = (CheckBox)row.FindControl("chkItems");
                    TextBox txtQuantity = (TextBox)row.FindControl("txtQty");
                    CheckBox chkIsLostTag = (CheckBox)row.FindControl("chkIsLostTag");

                    if (chkItem.Checked)
                    {
                        int qty;
                        if (string.IsNullOrEmpty(txtQuantity.Text) || int.TryParse(txtQuantity.Text, out qty) == false)
                        {
                            txtQuantity.Text = "1";
                        }
                        ITEM style = new ITEM
                        {
                            APType = chkIsLostTag.Checked.ToString(),
                            Brand = hfFromBrand.Value,
                            CostPrice = decimal.Parse(txtQuantity.Text), //as quantity
                            Description = row.Cells[4].Text,
                            StyleNumber = row.Cells[2].Text,
                            Box = containerNumber
                        };
                        if (!isAlreadySelected(BoxItems, style.StyleNumber, containerNumber))
                        {
                            totalSelectedStyleTobeAdded+=(int)style.CostPrice;
                            ContainerStyles.Add(style);
                        }
                    }
                }

                if ((totalQtyPerContainer + totalSelectedStyleTobeAdded) > totalQty)
                {
                    lblErrorMessage.Text = "Container " + containerType + ":" + containerNumber + " is greater than " + totalQty.ToString() + " Styles!";
                    hfErrorModalHandLer_ModalPopupExtender.Show();
                    return;
                }

                //for boxes
                    foreach (ITEM item_ in ContainerStyles)
                    {
                        StylePrice price_ = new StylePrice();
                        price_ = PricePointManager.GetStyleCurrentPrice(item_.StyleNumber, int.Parse(hfPGMDNo.Value),
                           int.Parse(hfAreaGroupNo.Value), int.Parse(hfSubAreaGroupNo.Value), int.Parse(hfCustomerNumber.Value));
                        if (price_ != null)
                        {
                            price_.PriceType = "MARKDOWN";
                            price_.PGNo = item_.Box.ToString();//as boxNumber
                            price_.GrpNo = item_.Description; //as Description
                            price_.APType = item_.APType;
                            price_.StyleNo = item_.StyleNumber;
                            price_.SRP = getSRP(item_, price_).Price;
                            price_.GenMemoID = (int)item_.CostPrice; // as quantity
                            CONTAINER_PRICES.Add(price_);
                        }
                        else
                        {
                            price_ = getSRP(item_, price_);
                            CONTAINER_PRICES.Add(price_);
                        }
                    }

                    foreach (StylePrice price_ in CONTAINER_PRICES)
                    {
                        PullOutLetterDetail pd = new PullOutLetterDetail
                        {
                            ContainerNumber = int.Parse(price_.PGNo),
                            StyleDescription = price_.GrpNo,
                            Quantity = price_.GenMemoID,
                            SRP = price_.Price,
                            StyleNumber = price_.StyleNo,
                            TtlAmount = (price_.GenMemoID * price_.Price),
                            IsLostTag = bool.Parse(price_.APType)
                           ,
                            ContainerType = containerType,
                            PullOutLetterCode = hfPullOutLetterCode.Value
                        };
                        BoxItems.Add(pd);
                    }

                    lblTotalSelected.Text = "Total Styles:" + BoxItems.Count.ToString("###,##0");
                    lblTotalAmount.Text = "Total Amt:" + BoxItems.Sum(i => i.TtlAmount).ToString("###,##0.00");
                    gvSelectedStyles.DataSource = BoxItems.OrderBy(s => s.ContainerNumber).ThenBy(s => s.StyleNumber);
                    gvSelectedStyles.DataBind();

                #endregion
            }
            catch (Exception ex)
            {
                lblErrorMessage.Text = ex.Message;
                hfErrorModalHandLer_ModalPopupExtender.Show();
               // throw;
            }
            btnSaveTransfer.Enabled = true;
        }
        protected void btnSaveLostTag_Click(object sender, EventArgs e)
        {
            try
            {
                IList<PullOutLetterDetail> BoxItems = getSelectedStylesForBoxes();
                IList<ITEM> BoxesStyles = new List<ITEM>();
                List<StylePrice> BOX_PRICES = new List<StylePrice>();

                IList<PullOutLetterDetail> SackItems = getSelectedStylesForSacks();
                IList<ITEM> SacksStyles = new List<ITEM>();
                List<StylePrice> SACK_PRICES = new List<StylePrice>();

                List<Container> boxContainers = boxesContainer();
                List<Container> sackContainers = sacksContainer();

                #region populate for boxes

                        //for boxes
                        if (!string.IsNullOrEmpty(chkBoxList.SelectedValue))
                        {
                                    ITEM style = new ITEM
                                    {
                                        APType = "True",
                                        Brand = txtBrand.Text,
                                        CostPrice = decimal.Parse(txtLostTagQty.Text), //as quantity
                                        Description = "N/A",
                                        StyleNumber ="LOST TAG",
                                        Box = int.Parse(chkBoxList.SelectedValue)
                                    };
                                    BoxesStyles.Add(style);
                        }

                        //for sacks
                        if (!string.IsNullOrEmpty(chkSackList.SelectedValue))
                        {
                                    ITEM style = new ITEM
                                    {
                                        APType = "True",
                                        Brand = txtBrand.Text,
                                        CostPrice = decimal.Parse(txtLostTagQty.Text), //as quantity
                                        Description = "N/A",
                                        StyleNumber ="LOST TAG",
                                        Box = int.Parse(chkSackList.SelectedValue)
                                    };
                                    SacksStyles.Add(style);
                        }

                //for boxes
                if (!string.IsNullOrEmpty(chkBoxList.SelectedValue))
                {
                    foreach (ITEM item_ in BoxesStyles)
                    {
                        StylePrice price_ = new StylePrice();
                            price_.PriceType = "N/A";
                            price_.PGNo = item_.Box.ToString();//as boxNumber
                            price_.GrpNo = item_.Description; //as Description
                            price_.APType = item_.APType;
                            price_.StyleNo = item_.StyleNumber;
                            price_.SRP = 00;
                            price_.GenMemoID = (int)item_.CostPrice; // as quantity
                            BOX_PRICES.Add(price_);
                    }

                    foreach (StylePrice price_ in BOX_PRICES)
                    {
                        PullOutLetterDetail pd = new PullOutLetterDetail
                        {
                            ContainerNumber = int.Parse(price_.PGNo),
                            StyleDescription = price_.GrpNo,
                            Quantity = price_.GenMemoID,
                            SRP = price_.Price,
                            StyleNumber = price_.StyleNo,
                            TtlAmount = (price_.GenMemoID * price_.Price),
                            IsLostTag = bool.Parse(price_.APType)
                           ,
                            ContainerType = "BOX",
                            PullOutLetterCode = hfPullOutLetterCode.Value
                        };
                        BoxItems.Add(pd);
                    }

                    gvSelectedStyles.DataSource = BoxItems.OrderBy(s => s.ContainerNumber).ThenBy(s => s.StyleNumber);
                    gvSelectedStyles.DataBind();
                }
                //for sacks
                if (!string.IsNullOrEmpty(chkSackList.SelectedValue))
                {
                    foreach (ITEM item_ in SacksStyles)
                    {
                        StylePrice price_ = new StylePrice();
                            price_.PriceType = "N/A";
                            price_.PGNo = item_.Box.ToString();//as boxNumber
                            price_.GrpNo = item_.Description; //as Description
                            price_.APType = item_.APType;
                            price_.StyleNo = item_.StyleNumber;
                            price_.SRP = 00;
                            price_.GenMemoID = (int)item_.CostPrice; // as quantity
                            SACK_PRICES.Add(price_);
                    }

                    foreach (StylePrice price_ in SACK_PRICES)
                    {
                        PullOutLetterDetail pd = new PullOutLetterDetail
                        {
                            ContainerNumber = int.Parse(price_.PGNo),
                            StyleDescription = price_.GrpNo,
                            Quantity = price_.GenMemoID,
                            SRP = price_.Price,
                            StyleNumber = price_.StyleNo,
                            TtlAmount = (price_.GenMemoID * price_.Price),
                            IsLostTag = bool.Parse(price_.APType),
                            ContainerType = "SACK",
                            PullOutLetterCode = hfPullOutLetterCode.Value
                        };
                        SackItems.Add(pd);
                    }

                    this.gvSelectedStylesForSacks.DataSource = SackItems.OrderBy(s => s.ContainerNumber).ThenBy(s => s.StyleNumber);
                    gvSelectedStylesForSacks.DataBind();
                }
                uncheckSelectedStyles();
                #endregion
            }
            catch (Exception ex)
            {
                lblErrorMessage.Text = ex.Message;
                hfErrorModalHandLer_ModalPopupExtender.Show();
                throw;
            }
        }