protected void rptLabelPriceLevels_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            RepeaterItem item = e.Item;

            if (item.ItemIndex > -1 && item.DataItem is PriceLevelBO)
            {
                PriceLevelBO objPriceLevel = (PriceLevelBO)item.DataItem;

                Literal litLabelCellHeader = (Literal)item.FindControl("litLabelCellHeader");
                litLabelCellHeader.Text = objPriceLevel.Name + "<em>( " + objPriceLevel.Volume + " )</em>";

                TextBox txtCellData = (TextBox)item.FindControl("txtCellData");
                txtCellData.Attributes.Add("qid", objPriceLevel.ID.ToString());
                txtCellData.CssClass = "level" + objPriceLevel.ID.ToString();
            }
            else if (item.ItemIndex > -1 && item.DataItem is LabelPriceMarkupBO)
            {
                LabelPriceMarkupBO objLabelPriceMarckup = (LabelPriceMarkupBO)item.DataItem;

                Literal litLabelCellHeader = (Literal)item.FindControl("litLabelCellHeader");
                litLabelCellHeader.Text = objLabelPriceMarckup.objPriceLevel.Name + "<em>( " + objLabelPriceMarckup.objPriceLevel.Volume + " )</em>";

                HiddenField hdnCellID = (HiddenField)item.FindControl("hdnCellID");
                hdnCellID.Value = objLabelPriceMarckup.ID.ToString();

                Label lblLabelCellData = (Label)item.FindControl("lblLabelCellData");
                lblLabelCellData.Attributes.Add("qid", objLabelPriceMarckup.PriceLevel.ToString());
                lblLabelCellData.Text = objLabelPriceMarckup.Markup.ToString();
            }
        }
        protected void dgLabelPriceMarckups_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            DataGridItem item = e.Item;

            if (item.ItemIndex > -1 && item.DataItem is IGrouping <int, LabelPriceMarkupBO> )
            {
                var lstLabelPriceMarckups = ((IGrouping <int, LabelPriceMarkupBO>)item.DataItem).ToList();
                LabelPriceMarkupBO objLabelPriceMarckup = lstLabelPriceMarckups[0];

                ((System.Web.UI.WebControls.WebControl)(item)).CssClass = "irow_" + objLabelPriceMarckup.Label.ToString();

                Literal litLabel = (Literal)item.FindControl("litLabel");
                litLabel.Text = objLabelPriceMarckup.Label.ToString();

                Literal lblLabel = (Literal)item.FindControl("lblLabel");
                lblLabel.Text = objLabelPriceMarckup.objLabel.Name;

                Repeater rptLabelPriceLevels = (Repeater)item.FindControl("rptLabelPriceLevels");
                rptLabelPriceLevels.DataSource = lstLabelPriceMarckups;
                rptLabelPriceLevels.DataBind();

                HyperLink linkLabelEdit = (HyperLink)item.FindControl("linkLabelEdit");
                linkLabelEdit.Attributes.Add("qid", objLabelPriceMarckup.Label.ToString());
                linkLabelEdit.Attributes.Add("isType", "label");

                HyperLink linkLabelDelete = (HyperLink)item.FindControl("linkLabelDelete");
                linkLabelDelete.Attributes.Add("qid", objLabelPriceMarckup.Label.ToString());
                linkLabelDelete.Attributes.Add("isType", "label");
            }
        }
        /// <summary>
        /// Process the page data.
        /// </summary>
        private void ProcessForm(int distributorID, bool isDelete, bool isEdit, string isType)
        {
            try
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    if (isEdit)
                    {
                        //Delete Statment
                        if (isDelete)
                        {
                            ReturnIntViewBO objReturnIntView = new ReturnIntViewBO();
                            if (isType == "distributor")
                            {
                                objReturnIntView = DistributorPriceMarkupBO.DeleteDistributorPriceMarkup(distributorID);
                                if (objReturnIntView.RetVal == 0)
                                {
                                    return;
                                }
                            }

                            if (isType == "label")
                            {
                                objReturnIntView = PriceMarkupLabelBO.DeleteLabelPriceMarkup(distributorID);
                                if (objReturnIntView.RetVal == 0)
                                {
                                    return;
                                }
                            }
                        }
                        else
                        {
                            if (isType == "distributor")
                            {
                                foreach (RepeaterItem item in this.rptPriceLevels.Items)
                                {
                                    HiddenField hdnCellID   = (HiddenField)item.FindControl("hdnCellID");
                                    TextBox     txtCellData = (TextBox)item.FindControl("txtCellData");

                                    int markup = int.Parse(hdnCellID.Value);

                                    DistributorPriceMarkupBO objPriceMarckup = new DistributorPriceMarkupBO(this.ObjContext);
                                    if (markup > 0)
                                    {
                                        objPriceMarckup.ID = int.Parse(hdnCellID.Value.Trim());
                                        objPriceMarckup.GetObject();
                                    }

                                    if (isEdit)
                                    {
                                        objPriceMarckup.Distributor = (distributorID > 0) ? distributorID : 0;
                                    }
                                    objPriceMarckup.PriceLevel = int.Parse(txtCellData.Attributes["qid"].ToString());
                                    objPriceMarckup.Markup     = Convert.ToDecimal(decimal.Parse(txtCellData.Text.Trim()).ToString("0.00"));
                                }
                            }

                            if (isType == "label")
                            {
                                foreach (RepeaterItem item in this.rptPriceLevels.Items)
                                {
                                    HiddenField hdnCellID   = (HiddenField)item.FindControl("hdnCellID");
                                    TextBox     txtCellData = (TextBox)item.FindControl("txtCellData");

                                    int Labelmarkup = int.Parse(hdnCellID.Value);

                                    LabelPriceMarkupBO objLabelPriceMarkup = new LabelPriceMarkupBO(this.ObjContext);

                                    if (Labelmarkup > 0)
                                    {
                                        objLabelPriceMarkup.ID = int.Parse(hdnCellID.Value.Trim());
                                        objLabelPriceMarkup.GetObject();
                                    }

                                    objLabelPriceMarkup.Label      = distributorID;
                                    objLabelPriceMarkup.PriceLevel = int.Parse(txtCellData.Attributes["qid"].ToString());
                                    objLabelPriceMarkup.Markup     = Convert.ToDecimal(decimal.Parse(txtCellData.Text.Trim()).ToString("0.00"));
                                }
                            }
                        }
                    }
                    else
                    {
                        foreach (RepeaterItem item in this.rptPriceLevels.Items)
                        {
                            int         distributor = int.Parse(this.ddlDistributors.SelectedValue);
                            HiddenField hdnCellID   = (HiddenField)item.FindControl("hdnCellID");
                            TextBox     txtCellData = (TextBox)item.FindControl("txtCellData");

                            int markup = int.Parse(hdnCellID.Value);

                            DistributorPriceMarkupBO objPriceMarckup = new DistributorPriceMarkupBO(this.ObjContext);
                            if (markup > 0)
                            {
                                objPriceMarckup.ID = int.Parse(hdnCellID.Value.Trim());
                                objPriceMarckup.GetObject();
                            }

                            if (distributor > 0)
                            {
                                objPriceMarckup.Distributor = (int?)distributor;
                            }
                            objPriceMarckup.PriceLevel = int.Parse(txtCellData.Attributes["qid"].ToString());
                            objPriceMarckup.Markup     = Convert.ToDecimal(decimal.Parse(txtCellData.Text.Trim()).ToString("0.00"));
                        }
                    }

                    this.ObjContext.SaveChanges();
                    ts.Complete();
                }
            }
            catch (Exception ex)
            {
                // Log the error
                IndicoLogging.log.Error("Error occured while Adding, upadting and deleting the PriceMarkups", ex);
            }
        }
        private void PopulateDataGrid()
        {
            // Hide Controls
            this.dvEmptyContent.Visible   = false;
            this.dvDataContent.Visible    = false;
            this.dvNoSearchResult.Visible = false;

            // Search text
            string searchText = this.txtSearch.Text.ToLower().Trim();

            // Populate Items
            DistributorPriceMarkupBO objPriceMarckup     = new DistributorPriceMarkupBO();
            LabelPriceMarkupBO       objLabelPriceMarkup = new LabelPriceMarkupBO();

            List <IGrouping <int, DistributorPriceMarkupBO> > lstPriceMarckups     = new List <IGrouping <int, DistributorPriceMarkupBO> >();
            List <IGrouping <int, LabelPriceMarkupBO> >       lstLabelPriceMarkups = new List <IGrouping <int, LabelPriceMarkupBO> >();

            if ((searchText != string.Empty) && (searchText != "search"))
            {
                lstPriceMarckups = (from o in objPriceMarckup.SearchObjects().AsQueryable().OrderBy(SortExpression).ToList()
                                    where o.Distributor != 0 && o.objDistributor.Name.ToLower().Contains(searchText)
                                    orderby(int) o.Distributor
                                    group o by(int) o.Distributor into g
                                    select g).ToList();

                lstLabelPriceMarkups = (from o in objLabelPriceMarkup.SearchObjects().AsQueryable().ToList()
                                        where o.Label != 0 && o.objLabel.Name.ToLower().Contains(searchText)
                                        orderby(int) o.Label
                                        group o by(int) o.Label into g
                                        select g).ToList();
            }
            else
            {
                lstPriceMarckups = (from o in objPriceMarckup.SearchObjects().AsQueryable().OrderBy(SortExpression).ToList()
                                    orderby(int) o.Distributor
                                    group o by(int) o.Distributor into g
                                    select g).ToList();

                lstLabelPriceMarkups = (from o in objLabelPriceMarkup.SearchObjects().AsQueryable().ToList()
                                        orderby(int) o.Label
                                        group o by(int) o.Label into g
                                        select g).ToList();
            }

            if (lstPriceMarckups.Count > 0)
            {
                this.dgPriceMarckups.AllowPaging = (lstPriceMarckups.Count > this.dgPriceMarckups.PageSize);
                this.dgPriceMarckups.DataSource  = lstPriceMarckups;
                this.dgPriceMarckups.DataBind();

                this.dvDataContent.Visible = true;
            }
            else if ((searchText != string.Empty && searchText != "search"))
            {
                this.lblSerchKey.Text = searchText;

                this.dvDataContent.Visible    = true;
                this.dvNoSearchResult.Visible = true;
            }
            else
            {
                this.dvEmptyDistributor.Visible = true;
            }

            if (lstLabelPriceMarkups.Count > 0)
            {
                this.dgLabelPriceMarckups.AllowPaging = (lstLabelPriceMarkups.Count > this.dgLabelPriceMarckups.PageSize);
                this.dgLabelPriceMarckups.DataSource  = lstLabelPriceMarkups;
                this.dgLabelPriceMarckups.DataBind();
            }
            else if ((searchText != string.Empty && searchText != "search"))
            {
                this.lblLabelSerchKey.Text = searchText;

                this.dvDataContent.Visible         = true;
                this.dvNoSearchResultLabel.Visible = true;
            }
            else
            {
                this.dvEmptyLabel.Visible = true;
            }

            if (lstPriceMarckups.Count == 0 && lstLabelPriceMarkups.Count == 0)
            {
                this.dvEmptyContent.Visible     = true;
                this.btnAddPriceMarckup.Visible = false;
            }

            this.dgPriceMarckups.Visible      = (lstPriceMarckups.Count > 0);
            this.dgLabelPriceMarckups.Visible = (lstLabelPriceMarkups.Count > 0);
        }