protected void btnAddBox_Click(object sender, EventArgs e)
        {
            List<Container> containerBoxList = boxesContainer();
            List<Container> containerSackList = sacksContainer();
            int boxesCount = containerBoxList.Count;
            int lastBoxNumber = 0;
            if (boxesCount > 0)
            {
                lastBoxNumber = int.Parse(containerBoxList.Max(s => s.BoxNumber.Split(':')[1])) + 1;
            }
            else
            {
                lastBoxNumber = (lastBoxNumber + 1);
            }
            Container newContainer = new Container
            {
                BoxNumber = "BOX#:" + (lastBoxNumber),
                ImageUrl = Constant.ActiveBoxImageUrl,
                ItemsQuantity = 0,
                StylesQuantity = 0,
                TotalAmount = 0,
                Type = "Box"
                ,
                IsSelected = true
            };

            foreach (var box in containerBoxList)
            {
                box.IsSelected = false;
                box.ImageUrl = Constant.BoxImageUrl;
            }

            containerBoxList.Add(newContainer);
            chkBoxList.Items.Clear();
            if (containerBoxList.Count > 0)
            {
                foreach (var item in containerBoxList)
                {
                    chkBoxList.Items.Add(new ListItem(item.BoxNumber.Split(':')[1], item.BoxNumber.Split(':')[1]));
                }
                chkBoxList.SelectedValue = lastBoxNumber.ToString();
                chkSackList.SelectedIndex = -1;
                this.btnRemoveBox.Visible = true;
                this.pnlChkBoxList.Visible = true;
            }
            rptrBoxes.DataSource = containerBoxList;
            rptrBoxes.DataBind();

            foreach (var sack in containerSackList)
            {
                sack.ImageUrl = Constant.SackImageUrl;
                sack.IsSelected = false;
            }
            this.rptrSacks.DataSource = containerSackList;
            rptrSacks.DataBind();
        }
 protected void btnRemoveContainer_Click(object sender, EventArgs e)
 {
     List<Container> containers = containerList();
     Container conTainerToRemove = new Container
     {
          BoxNumber = gvContainers.SelectedRow.Cells[1].Text
          , Type = gvContainers.SelectedRow.Cells[3].Text
     };
     containers.RemoveAll(s=>s.BoxNumber == conTainerToRemove.BoxNumber && s.Type ==conTainerToRemove.Type);
     gvContainers.DataSource = containers.OrderBy(s => s.Type).ThenBy(s => s.BoxNumber);
     gvContainers.DataBind();
     countTotalQuantities(containers);
 }
 protected void btnAddContainer_Click(object sender, EventArgs e)
 {
     List<Container> containers = containerList();
     string containerLastNumber = "0";
     containerLastNumber = containers.Where(s => s.Type == rdioBoxOrSack.SelectedValue).Max(s => s.BoxNumber)?? "0";
     Container newContainer = new Container
     {
       BoxNumber = (int.Parse(containerLastNumber)+1).ToString(),
       ImageUrl = imgBoxOrSack.ImageUrl ,
       Type = rdioBoxOrSack.SelectedValue,
       ItemsQuantity = int.Parse(txtTotalQty.Text),
     };
     containers.Add(newContainer);
     gvContainers.DataSource = containers.OrderBy(s=>s.Type).ThenBy(s=>s.BoxNumber);
     gvContainers.DataBind();
     countTotalQuantities(containers);
 }
        /// <summary>
        /// Count Style Summary for every Containers
        /// </summary>
        /// <param name="pullOutDetails"></param>
        /// <param name="containerType"></param>
        /// <param name="lblCounter"></param>
        /// <param name="rptrContainer"></param>
        /// <param name="selectedStyles"></param>
        /// <param name="containers"></param>
        private void countStylesSummaries(IList<PullOutLetterDetail> pullOutDetails,
            string containerType, Label lblCounter, Repeater rptrContainer, GridView selectedStyles, List<Container> containers)
        {
            List<Container> containerList = new List<Container>();
            long totalQuantity = 0;
            long quantityPerContainer = 0;
            decimal totalAmount = 0;
            int styleQuantity = 0;
            string imageUrl = string.Empty;
            if (containerType == "Box")
            {
                imageUrl = "~/Resources/Box64.png";
            }
            else
            {
                imageUrl = "~/Resources/Sack64.png";
            }
            foreach (var container in containers)
            {
                var result = (from style in pullOutDetails
                              where style.ContainerNumber == int.Parse(container.BoxNumber.Split(':')[1])
                              select style).ToList();
                quantityPerContainer = result.Sum(s => s.Quantity);

                totalAmount = result.Sum(s => s.TtlAmount);
                totalQuantity += quantityPerContainer;
                styleQuantity = result.Count;
                Container container_ = new Container
                {
                    BoxNumber = container.BoxNumber,
                    ItemsQuantity = quantityPerContainer,
                    StylesQuantity = styleQuantity,
                    TotalAmount = totalAmount
                     ,
                    ImageUrl = container.ImageUrl,
                    IsSelected = container.IsSelected,
                    Type = containerType
                };
                containerList.Add(container_);
            }

            lblCounter.Text = "COUNT: " + selectedStyles.Rows.Count.ToString() + "/" + totalQuantity;
            rptrContainer.DataSource = containerList;
            rptrContainer.DataBind();
        }
 /// <summary>
 /// Fetch All Box Containers
 /// </summary>
 /// <returns>List of Box Container</returns>
 private List<Container> boxesContainer()
 {
     List<Container> containerBoxList = new List<Container>();
     foreach (RepeaterItem rptrItem in this.rptrBoxes.Items)
     {
         CheckBox chkBox = (CheckBox)rptrItem.FindControl("chkBox");
         Label lblItemsQuantity = (Label)rptrItem.FindControl("lblItemsQuantity");
         Label lblStylesQuantity = (Label)rptrItem.FindControl("lblStylesQuantity");
         Label lblTotalAmount = (Label)rptrItem.FindControl("lblTotalAmount");
         Image imgbox = (Image)rptrItem.FindControl("imgbox");
         Container boxContainer = new Container
         {
             BoxNumber = chkBox.ToolTip,
             ItemsQuantity = int.Parse(lblItemsQuantity.Text.Split(':')[1]),
             StylesQuantity = int.Parse(lblStylesQuantity.Text.Split(':')[1]),
             Type = "Box",
             TotalAmount = decimal.Parse(lblTotalAmount.Text.Split(':')[1]),
             ImageUrl = imgbox.ImageUrl.ToString(),
             IsSelected = bool.Parse(imgbox.ToolTip.ToString())
         };
         containerBoxList.Add(boxContainer);
     }
     return containerBoxList;
 }
        protected void btnRemoveSack_Click(object sender, EventArgs e)
        {
            List<Container> containerSackList = new List<Container>();
            List<Container> selectedSacksToRemove = new List<Container>();
            List<Container> containerBoxList = boxesContainer();
            foreach (RepeaterItem rptrItem in this.rptrSacks.Items)
            {
                CheckBox chkBox = (CheckBox)rptrItem.FindControl("chkBox");
                Label lblItemsQuantity = (Label)rptrItem.FindControl("lblItemsQuantity");
                Label lblStylesQuantity = (Label)rptrItem.FindControl("lblStylesQuantity");
                Label lblTotalAmount = (Label)rptrItem.FindControl("lblTotalAmount");
                Image imgSack = (Image)rptrItem.FindControl("imgSack");
                Container boxContainer = new Container
                {
                    BoxNumber = chkBox.ToolTip,
                    ItemsQuantity = int.Parse(lblItemsQuantity.Text.Split(':')[1]),
                    StylesQuantity = int.Parse(lblStylesQuantity.Text.Split(':')[1]),
                    Type = "Sack",
                    ImageUrl = imgSack.ImageUrl,
                    IsSelected = bool.Parse(imgSack.ToolTip),
                    TotalAmount = decimal.Parse(lblTotalAmount.Text.Split(':')[1])
                };
                if (chkBox.Checked)
                {
                    selectedSacksToRemove.Add(boxContainer);
                }
                containerSackList.Add(boxContainer);
            }

            foreach (Container container in selectedSacksToRemove)
            {
                containerSackList.RemoveAll(s => s.BoxNumber == container.BoxNumber);
            }
            this.chkSackList.Items.Clear();
            string activeContainer = string.Empty;
            if (containerSackList.Count > 0)
            {
                foreach (var item in containerSackList)
                {
                    string chkValue = item.BoxNumber.Split(':')[1];
                    chkSackList.Items.Add(new ListItem(chkValue, chkValue));
                    if (item.IsSelected)
                    {
                        activeContainer = chkValue;
                    }
                }
                if (!string.IsNullOrEmpty(activeContainer))
                {
                    chkSackList.SelectedValue = activeContainer;
                }
            }
            else
            {
                btnRemoveSack.Visible = false;
                pnlChkSackList.Visible = false;
            }
            rptrSacks.DataSource = containerSackList;
            rptrSacks.DataBind();
            reFetchSelectedStyleForSacksAffectedByRemovingSack(selectedSacksToRemove);
        }
        private void initializeContainers()
        {
            List<Container> boxContainers = new List<Container>();
            List<Container> sackContainers = new List<Container>();
            List<Container> containers = new List<Container>();

            List<PullOutLetterDetail> containerDetails = POLDetailManager.FetchAll().Where(s =>
                                                           s.PullOutLetterCode == hfPullOutCode.Value).OrderBy(s => s.ContainerType).ThenBy(s => s.ContainerNumber)
                                                           .ToList();

            List<PullOutLetterDetail> boxDetails = new List<PullOutLetterDetail>();
            List<PullOutLetterDetail> sackDetails = new List<PullOutLetterDetail>();

            long totalQty = 0;
            decimal totalAmt = 0;
            foreach (var item in containerDetails)
            {
                if (item.ContainerType == "BOX")
                {
                    boxDetails.Add(item);
                    Container container = new Container
                    {
                        BoxNumber = "BOX#" + item.ContainerNumber
                         ,
                        ImageUrl = "~/Resources/Box.png",

                    };
                    containers.Add(container);
                }
                else
                {
                    sackDetails.Add(item);
                    Container container = new Container
                    {
                        BoxNumber = "SACK#" + item.ContainerNumber
                        ,
                        ImageUrl = "~/Resources/Sack32.png"
                    };
                    containers.Add(container);
                }
                totalQty += item.Quantity;
                totalAmt += item.TtlAmount;
            }

            var Con = (from con in containers
                       select new { BoxNumber = con.BoxNumber, ImageUrl = con.ImageUrl, qty = con.ItemsQuantity }).Distinct();

            txtSummary.Text = "SUMMARY TOTAL QTY: " + totalQty.ToString() + " TOTAL AMOUNT: " + totalAmt.ToString("###,###.00");
            lblTotalCotainer.Text = "TOTAL CONTAINER: " + Con.ToList().Count.ToString();
            gvBoxContainerDetails.DataSource = containerDetails;
            gvBoxContainerDetails.DataBind();
            gvContainers.DataSource = Con;
            gvContainers.DataBind();

            rdioContainers.DataSource = Con;
            rdioContainers.DataTextField = "BoxNumber";
            rdioContainers.DataValueField = "BoxNumber";
            rdioContainers.DataBind();
            rdioContainers.SelectedIndex = 0;
            rdioLostTagContainers.DataSource = Con;
            rdioLostTagContainers.DataTextField = "BoxNumber";
            rdioLostTagContainers.DataValueField = "BoxNumber";
            rdioLostTagContainers.DataBind();
            rdioLostTagContainers.SelectedIndex = 0;
        }
 private List<Container> containerList()
 {
     List<Container> containers = new List<Container>();
     foreach (GridViewRow  row in gvContainers.Rows)
     {
         Image imgContainer = (Image)row.FindControl("imgContainer");
         Container container = new Container
         {
             BoxNumber = row.Cells[1].Text,
             ImageUrl = imgContainer.ImageUrl,
             ItemsQuantity =int.Parse(row.Cells[2].Text),
             Type = row.Cells[3].Text
         };
         containers.Add(container);
     }
     return containers ?? new List<Container>();
 }
 private List<Container> containerList()
 {
     List<Container> containers = new List<Container>();
     var summaries = POLSummaryManager.FetchAll().Where(s => s.PullOutCode == hfPullOutLetterCode.Value);
     foreach (var summary in summaries)
     {
         string imgUrl = string.Empty;
         if (summary.ContainerType =="Box")
         {
             imgUrl = Constant.BoxImageUrl;
         }
         else
         {
             imgUrl = Constant.SackImageUrl;
         }
         Container container = new Container
         {
             BoxNumber =summary.ContainerNumber.ToString(),
             ImageUrl = imgUrl,
             ItemsQuantity = summary.TotalQuantity,
             Type = summary.ContainerType,
              StylesQuantity = summary.RecordNumber, // as recordNumber container field
         };
         containers.Add(container);
     }
     return containers ?? new List<Container>();
 }
        private void generateContainers(int numberOfBoxes, int numberOfSacks)
        {
            List<Container> boxes = new List<Container>();
            List<Container> sacks = new List<Container>();
            List<Container> containers = new List<Container>();
            chkBoxList.Items.Clear();
            chkSackList.Items.Clear();

            for (int i = 1; i <= numberOfBoxes; i++)
            {
                chkBoxList.Items.Add(new ListItem(i.ToString(), i.ToString()));
                bool is_active = false;
                string ImageUrl = string.Empty ;
                if (i==1)
                {
                    is_active = true;
                    ImageUrl = "~/Resources/Box64active.png";
                }
                else
                {
                    ImageUrl = "~/Resources/Box64.png";
                }
                Container box = new Container
                {
                    BoxNumber = "BOX#:" + i,
                    ItemsQuantity = 0,
                    StylesQuantity = 0,
                    ImageUrl = ImageUrl
                    , IsSelected = is_active
                };
                boxes.Add(box);
                containers.Add(box);
            }
            chkBoxList.SelectedValue ="1";
            for (int i = 1; i <= numberOfSacks; i++)
            {
                chkSackList.Items.Add(new ListItem(i.ToString(), i.ToString()));
                Container sack = new Container
                {
                    BoxNumber = "SACK#:" + i,
                    ItemsQuantity = 0,
                    StylesQuantity = 0,
                    ImageUrl ="~/Resources/Sack64.png"
                };
                sacks.Add(sack);
                containers.Add(sack);
            }
            if (boxes.Count > 0)
            {
                rptrBoxes.DataSource = boxes;
                rptrBoxes.DataBind();
                pnlChkBoxList.Visible = true;
                btnRemoveBox.Visible = true;
            }
            else
            {
                pnlChkBoxList.Visible = false;
                btnRemoveBox.Visible = false;
            }

            if (sacks.Count > 0)
            {
                rptrSacks.DataSource = sacks;
                rptrSacks.DataBind();
                pnlSelectedStyleForSacks.Visible = true;
                pnlChkSackList.Visible = true;
            }
            else
            {
                pnlChkSackList.Visible = false;
                pnlSelectedStyleForSacks.Visible = false;
                btnRemoveSack.Visible = false;
            }
        }
        private void initializeContainers()
        {
            List<Container> boxContainers = new List<Container>();
            List<Container> sackContainers = new List<Container>();
            List<Container> containers = new List<Container>();

            List<PullOutLetterDetail> containerDetails = POLDetailManager.FetchAll().Where(s =>
                                                            s.PullOutLetterCode == hfPullOutCode.Value)
                                                            .ToList();

            List<PullOutLetterDetail> boxDetails = new List<PullOutLetterDetail>();
            List<PullOutLetterDetail> sackDetails = new List<PullOutLetterDetail>();
            int totalStyles = containerDetails.Select(a => a.StyleNumber).Distinct().ToList().Count;
            long totalQty = 0;
            decimal totalAmt = 0;
            foreach (var item in containerDetails)
            {
                if (item.ContainerType == "BOX")
                {
                    boxDetails.Add(item);
                    Container container = new Container
                    {
                        BoxNumber = "BOX#" + item.ContainerNumber
                         ,
                        ImageUrl = "~/Resources/Box.png",

                    };
                    containers.Add(container);
                }
                else
                {
                    sackDetails.Add(item);
                    Container container = new Container
                    {
                        BoxNumber = "SACK#" + item.ContainerNumber
                        ,
                        ImageUrl = "~/Resources/Sack32.png"
                    };
                    containers.Add(container);
                }
                totalQty += item.Quantity;
                totalAmt += item.TtlAmount;
            }

            //PullOutLetterDetail pullOutSummary = new PullOutLetterDetail
            //{
            //    ContainerType = "GRAND TOTAL:",
            //    Quantity = totalQty,
            //    StyleNumber = totalStyles.ToString(),
            //    TtlAmount = totalAmt,
            //    SRP = decimal.Parse("0"),

            //};
            //containerDetails.Add(pullOutSummary);

            var Con = (from con in containers
                       select new { BoxNumber = con.BoxNumber, ImageUrl = con.ImageUrl, qty = con.ItemsQuantity }).Distinct();

            this.lblTotalQty.Text = totalQty.ToString();
            this.lblTotalPrice.Text =totalAmt.ToString("###,###.00");
            lblTotalNumberOfContainer.Text =Con.ToList().Count.ToString();

            gvContainers.DataSource = Con;
            gvContainers.DataBind();

            List<PullOutLetterDetail> detailsSummaries = new List<PullOutLetterDetail>();

            foreach (var item in Con.ToList())
            {
                PullOutLetterDetail pdSum = new PullOutLetterDetail();

                foreach (var cd in containerDetails)
                {
                    if (item.BoxNumber.Split('#')[0]==cd.ContainerType && int.Parse(item.BoxNumber.Split('#')[1])==cd.ContainerNumber)
                    {
                             pdSum.ContainerNumber = cd.ContainerNumber;
                             pdSum.ContainerType = cd.ContainerType;
                             pdSum.IsLostTag = cd.IsLostTag;
                             pdSum.Quantity +=  cd.Quantity;
                             pdSum.TtlAmount += cd.TtlAmount;
                             pdSum.ContainerType = "TOTAL " + cd.ContainerType + "#" + cd.ContainerNumber;
                             pdSum.StyleDescription = "";
                             cd.ContainerType = "";
                             cd.StyleDescription = "pc.";
                             detailsSummaries.Add(cd);
                    }
                }
                detailsSummaries.Add(pdSum);
            }

            gvDetails.DataSource = containerDetails;
            gvDetails.DataBind();
               // detailsSummaries.Add(pullOutSummary);
            gvBoxContainerDetails.DataSource = detailsSummaries;
            gvBoxContainerDetails.DataBind();

            lblBranch.Text = Request.QueryString["Branch"];
            lblCustomer.Text = Request.QueryString["Customer"];
            lblseries.Text = Request.QueryString["Series"];
        }