private void SaveMemoBySubArea()
        {
            GeneralMemoConcessionDetailManager GMCDM = new GeneralMemoConcessionDetailManager();
            PricePointManager PPM = new PricePointManager();
            IRMS.Entities.GeneralMemoConcession genMemoObj = new IRMS.Entities.GeneralMemoConcession();

            SubGroupAreaManager _SubGroupAreaManager = new SubGroupAreaManager();
            List<SubGroupAreaClass> _SubGroupAreaList = new List<SubGroupAreaClass>();

            genMemoObj.MemoDate = new IRMS.BusinessLogic.DataAccess.ISERVELibrary().GetServerDate();

            genMemoObj.Header = txtMemoHeader.Text;
            genMemoObj.Intro = txtIntroduction.Text;
            genMemoObj.BrandName = DDLBrand.SelectedItem.Text;

            genMemoObj.GroupNumber = Convert.ToInt32(DDLAreaGroup.SelectedItem.Value);
            genMemoObj.PriceType = rdioApplyPricePointTo.SelectedValue.ToUpperInvariant();

            genMemoObj.FromDate = new IRMS.BusinessLogic.DataAccess.ISERVELibrary().GetServerDate();
            genMemoObj.ToDate = Convert.ToDateTime(txtPromoPeriodTo.Text);
            genMemoObj.Message = txtMessage.Text;
            genMemoObj.Footer = txtFooter.Text;
            //genMemoObj.Status = rdioStatus.SelectedValue;
            genMemoObj.Status = "Pending";
            genMemoObj.Remark = txtRemarks.Text;

            genMemoObj.MemoNumber = txtMemoNo.Text;
            GMCM.Save(ref genMemoObj, true);
            SaveGenMemoDetail(genMemoObj);
            SavePricePointBySubArea(genMemoObj);
            txtMemoNo.Text = genMemoObj.MemoNumber;
        }
        private void SaveGenMemoDetail(IRMS.Entities.GeneralMemoConcession genMemoObj)
        {
            GeneralMemoConcessionDetailManager GMCDManager = new GeneralMemoConcessionDetailManager();
            IRMS.Entities.GeneralMemoConcessionDetail genMemoDetailObj;
            int iTotal = gvMarkdownList.Rows.Count;

            for (int iRow = 0; iRow < iTotal; iRow++)
            {
                genMemoDetailObj = new IRMS.Entities.GeneralMemoConcessionDetail();
                genMemoDetailObj.GeneralMemoID = genMemoObj.RecordNumber;
                genMemoDetailObj.MemoNumber = genMemoObj.MemoNumber;
                genMemoDetailObj.StyleNumber = gvMarkdownList.Rows[iRow].Cells[2].Text;
                genMemoDetailObj.BrandName = DDLBrand.SelectedItem.Text;
                genMemoDetailObj.StyleDescription = gvMarkdownList.Rows[iRow].Cells[3].Text;
                genMemoDetailObj.MDPrice = Convert.ToInt32(Convert.ToDecimal(gvMarkdownList.Rows[iRow].Cells[5].Text));
                genMemoDetailObj.CurrentPrice = Convert.ToDecimal(gvMarkdownList.Rows[iRow].Cells[4].Text);

                genMemoDetailObj.Price1 = Convert.ToDecimal(gvMarkdownList.Rows[iRow].Cells[6].Text);
                genMemoDetailObj.Price2 = Convert.ToDecimal(gvMarkdownList.Rows[iRow].Cells[7].Text);
                genMemoDetailObj.Price3 = Convert.ToDecimal(gvMarkdownList.Rows[iRow].Cells[8].Text);
                genMemoDetailObj.Price4 = Convert.ToDecimal(gvMarkdownList.Rows[iRow].Cells[9].Text);
                genMemoDetailObj.Price5 = Convert.ToDecimal(gvMarkdownList.Rows[iRow].Cells[10].Text);
                genMemoDetailObj.Price6 = Convert.ToDecimal(gvMarkdownList.Rows[iRow].Cells[11].Text);
                genMemoDetailObj.Price7 = Convert.ToDecimal(gvMarkdownList.Rows[iRow].Cells[12].Text);

                genMemoDetailObj.ynFurther = true;

                GMCDManager.Save(genMemoDetailObj);
            }

            iTotal = gvNewMarkdown.Rows.Count;
            for (int iRow = 0; iRow < iTotal; iRow++)
            {
                genMemoDetailObj = new IRMS.Entities.GeneralMemoConcessionDetail();
                genMemoDetailObj.GeneralMemoID = genMemoObj.RecordNumber;
                genMemoDetailObj.MemoNumber = genMemoObj.MemoNumber;
                genMemoDetailObj.StyleNumber = gvNewMarkdown.Rows[iRow].Cells[2].Text;
                genMemoDetailObj.BrandName = DDLBrand.SelectedItem.Text;
                genMemoDetailObj.StyleDescription = gvNewMarkdown.Rows[iRow].Cells[3].Text;
                genMemoDetailObj.MDPrice = Convert.ToInt32(Convert.ToDecimal(gvNewMarkdown.Rows[iRow].Cells[5].Text));
                genMemoDetailObj.CurrentPrice = Convert.ToDecimal(gvNewMarkdown.Rows[iRow].Cells[4].Text);

                genMemoDetailObj.Price1 = Convert.ToDecimal(gvNewMarkdown.Rows[iRow].Cells[6].Text);
                genMemoDetailObj.Price2 = Convert.ToDecimal(gvNewMarkdown.Rows[iRow].Cells[7].Text);
                genMemoDetailObj.Price3 = Convert.ToDecimal(gvNewMarkdown.Rows[iRow].Cells[8].Text);
                genMemoDetailObj.Price4 = Convert.ToDecimal(gvNewMarkdown.Rows[iRow].Cells[9].Text);
                genMemoDetailObj.Price5 = Convert.ToDecimal(gvNewMarkdown.Rows[iRow].Cells[10].Text);
                genMemoDetailObj.Price6 = Convert.ToDecimal(gvNewMarkdown.Rows[iRow].Cells[11].Text);
                genMemoDetailObj.Price7 = Convert.ToDecimal(gvNewMarkdown.Rows[iRow].Cells[12].Text);

                genMemoDetailObj.ynFurther = false;
                GMCDManager.Save(genMemoDetailObj);
            }
        }
        protected void btnAddMemoOk_ClickEx(object sender, EventArgs e)
        {
            List<IRMS.Entities.GeneralMemoConcessionDetail> DuplicateGenMemoDetailList = new List<IRMS.Entities.GeneralMemoConcessionDetail>();

            GeneralMemoConcessionDetailManager GMCDManager = new GeneralMemoConcessionDetailManager();
            List<IRMS.Entities.GeneralMemoConcessionDetail> GenMemoDetailsList = new List<IRMS.Entities.GeneralMemoConcessionDetail>();

            List<PriceGroup> _PriceGroupList = new List<PriceGroup>();

            _PriceGroupList = _PGManager.PriceGroupConcession();

            dtMarkdownList = (DataTable)Session["LIST"];
            dtNewMarkdownList = (DataTable)Session["NEWLIST"];

            //DataRow dtRow;
            GenMemoDetailsList = GMCDManager.GetGeneralMemoConcessionDetailByID(Convert.ToInt64(gvAddMemo.SelectedValue));
            bool bResult = false;
            foreach (IRMS.Entities.GeneralMemoConcessionDetail genMemoConcessionItem in GenMemoDetailsList)
            {
                var ItemFoundResult = (from myRow in dtMarkdownList.AsEnumerable()
                                       where myRow.Field<string>("STYLE #") == genMemoConcessionItem.StyleNumber
                                       select myRow);

                if (ItemFoundResult.Count() > 0)
                    bResult = true;
                else
                {
                    dtNewMarkdownList = (DataTable)Session["NEWLIST"];
                    ItemFoundResult = (from myRow in dtNewMarkdownList.AsEnumerable()
                                       where myRow.Field<string>("STYLE #") == genMemoConcessionItem.StyleNumber
                                       select myRow);

                    bResult = (ItemFoundResult.Count() > 0);
                }

                if (bResult == true)
                    DuplicateGenMemoDetailList.Add(genMemoConcessionItem);
                else
                {
                    if (genMemoConcessionItem.ynFurther == true)
                        AddMemoDetail(genMemoConcessionItem, ref dtMarkdownList);
                    else
                        AddMemoDetail(genMemoConcessionItem, ref dtNewMarkdownList);
                }
            }
            Session["LIST"] = dtMarkdownList;
            Session["NEWLIST"] = dtNewMarkdownList;

            gvMarkdownList.DataSource = (DataTable)Session["LIST"];
            gvMarkdownList.DataBind();

            gvNewMarkdown.DataSource = (DataTable)Session["NEWLIST"];
            gvNewMarkdown.DataBind();

            gvItems.SelectedIndex = -1;
            this.lblDuplicateCount.Text = "{0} items found!";

            if (DuplicateGenMemoDetailList.Count > 0)
            {
                lblDuplicateCount.Text = string.Format(lblDuplicateCount.Text, DuplicateGenMemoDetailList.Count);
                HiddenField2_ModalPopupExtender.Show();
            }
        }
        protected void gvItems_SelectedIndexChangedEx(object sender, EventArgs e)
        {
            PriceManager pM = new PriceManager();
            PricePointManager ppM = new PricePointManager();
            GeneralMemoConcessionDetailManager gMCDM = new GeneralMemoConcessionDetailManager();

            bool bResult = false;

            dtMarkdownList = (DataTable)Session["LIST"];
            var ItemFoundResult = (from myRow in dtMarkdownList.AsEnumerable()
                                   where myRow.Field<string>("STYLE #") == gvItems.SelectedRow.Cells[1].Text
                                   select myRow);

            if (ItemFoundResult.Count() > 0)
                bResult = true;
            else
            {
                dtNewMarkdownList = (DataTable)Session["NEWLIST"];
                ItemFoundResult = (from myRow in dtNewMarkdownList.AsEnumerable()
                                   where myRow.Field<string>("STYLE #") == gvItems.SelectedRow.Cells[1].Text
                                   select myRow);

                bResult = (ItemFoundResult.Count() > 0);
            }

            if (bResult == true)
            {
                this.lblDuplicateCount.Text = "{0} items found!";
                lblDuplicateCount.Text = string.Format(lblDuplicateCount.Text, 1);
                hfDuplicateStylePopupExtender.Show();
                txtCurrentPrice.Text = "";
                txtMarkDownPrice.Text = "0.00";
                return;
            }

            Double dResult = 0;
            //GET REGULAR PRICE
            dResult = Convert.ToDouble(pM.GetSRPByStyle(gvItems.SelectedRow.Cells[1].Text, DDLBrand.SelectedItem.Text).Price_2);
            lblPriceStatus.Text = "NEW";

            //GET MARKDOWN PRICE IF ANY
            PricePoint pPoint = new PricePoint();

            int GroupNo = -1;

            switch (rdioApplyPricePointTo.SelectedIndex)
            {
                case 0:
                    {
                        _GroupAreaMemoManager.GroupAreaMemo();
                        GroupNo = _GroupAreaMemoManager.GroupAreaMemoList[DDLAreaGroup.SelectedIndex].GroupNo;
                        if (GroupNo == 0)
                            GroupNo = 1;
                        else
                        {
                            if (GroupNo == 99)
                                GroupNo = 2;
                        }
                        break;
                    }
                case 1:
                    {
                        GroupNo = Convert.ToInt32(DDLSubArea.SelectedItem.Value);
                        break;
                    }
                case 2:
                    {
                        GroupNo = Convert.ToInt32(Session["CUSTOMER MD"]);
                        break;
                    }
            }

            pPoint = ppM.GetStyleCurrentPrice1(gvItems.SelectedRow.Cells[1].Text, DDLBrand.SelectedItem.Text,rdioApplyPricePointTo.SelectedValue.ToUpperInvariant(),GroupNo);
            if (pPoint != null)
            {
                dResult =  Convert.ToDouble(pPoint.Price);
                lblPriceStatus.Text = "MARKDOWN";
            }

            txtCurrentPrice.Text = string.Format("{0:0.00}",dResult);
            btnAddNewItem_ModalPopupExtender.Show();
        }
        private void LoadMDMemoList()
        {
            List<IRMS.Entities.GeneralMemoConcessionDetail> DuplicateGenMemoDetailList = new List<IRMS.Entities.GeneralMemoConcessionDetail>();

            GeneralMemoConcessionDetailManager GMCDManager = new GeneralMemoConcessionDetailManager();
            List<IRMS.Entities.GeneralMemoConcessionDetail> GenMemoDetailsList = new List<IRMS.Entities.GeneralMemoConcessionDetail>();

            List<PriceGroup> _PriceGroupList = new List<PriceGroup>();
            _PriceGroupList = _PGManager.PriceGroupConcession();

            DataRow dtRow;
            DataRow dtNewRow;
            GenMemoDetailsList = GMCDManager.GetGeneralMemoConcessionDetailByID(Convert.ToInt64(Session["MemoID"]));
            foreach (IRMS.Entities.GeneralMemoConcessionDetail genMemoConcessionItem in GenMemoDetailsList)
            {
                if (genMemoConcessionItem.ynFurther == true)
                {
                    dtRow = dtMarkdownList.NewRow();
                    dtRow["STYLE #"] = genMemoConcessionItem.StyleNumber;
                    dtRow["DESCRIPTION"] = genMemoConcessionItem.StyleDescription;
                    dtRow["CURRENT PRICE"] = string.Format("{0:0.00}",genMemoConcessionItem.CurrentPrice);
                    dtRow["MARKDOWN PRICE"] = string.Format("{0:0.00}",genMemoConcessionItem.MDPrice);

                    foreach (PriceGroup pgroupItem in _PriceGroupList)
                    {
                        dtRow[pgroupItem.GroupField.ToString()] = string.Format("{0:0.00}", (Convert.ToDouble(genMemoConcessionItem.MDPrice) + Convert.ToDouble(_PGManager.AddValueToRegularPrice(pgroupItem.PGNo))));
                    }

                    dtMarkdownList.Rows.Add(dtRow);
                }
                else
                {
                    dtNewRow = dtNewMarkdownList.NewRow();
                    dtNewRow["STYLE #"] = genMemoConcessionItem.StyleNumber;
                    dtNewRow["DESCRIPTION"] = genMemoConcessionItem.StyleDescription;
                    dtNewRow["CURRENT PRICE"] = string.Format("{0:0.00}", genMemoConcessionItem.CurrentPrice);
                    dtNewRow["MARKDOWN PRICE"] = string.Format("{0:0.00}", genMemoConcessionItem.MDPrice);

                    foreach (PriceGroup pgroupItem in _PriceGroupList)
                    {
                        dtNewRow[pgroupItem.GroupField.ToString()] = string.Format("{0:0.00}", (Convert.ToDouble(genMemoConcessionItem.MDPrice) + Convert.ToDouble(_PGManager.AddValueToRegularPrice(pgroupItem.PGNo))));
                    }
                    dtNewMarkdownList.Rows.Add(dtNewRow);
                }

            }
            Session["LIST"] = dtMarkdownList;
            Session["NEWLIST"] = dtNewMarkdownList;

            gvMarkdownList.DataSource = (DataTable)Session["LIST"];
            gvMarkdownList.DataBind();

            gvNewMarkdownList.DataSource = (DataTable)Session["NEWLIST"];
            gvNewMarkdownList.DataBind();
        }
        protected void btnUpdateGeneralMemo_ClickEx(object sender, EventArgs e)
        {
            DateTime ApprovedDate;
            _GenMemoObj = GMCM.GetGeneralMemoConcessionByKey(Convert.ToInt64(Session["MemoID"]));

            PricePointManager PPM = new PricePointManager();
            ApprovedDate = PPM.GetApprovedDate(_GenMemoObj.MemoNumber);

            PPM.DeleteByMemoNo(_GenMemoObj.MemoNumber);

            GeneralMemoConcessionDetailManager GMCDManager = new GeneralMemoConcessionDetailManager();
            GMCDManager.DeleteByMemoID(_GenMemoObj.RecordNumber);

             if (_GenMemoObj.PriceType.ToUpper() == "AREA")
                SavePricePointByArea(_GenMemoObj,ApprovedDate);

            if (_GenMemoObj.PriceType.ToUpper() == "SUB-AREA")
                SavePricePointBySubArea(_GenMemoObj,ApprovedDate);

            if (_GenMemoObj.PriceType.ToUpper() == "CUSTOMER")
                SavePricePointByCustomer(_GenMemoObj,ApprovedDate);

            SaveGenMemoDetail(_GenMemoObj);

            lblNewMemoNo.Text = string.Format(lblNewMemoNo.Text, txtMemoNumber.Text);
            hfMemoNoPopupExtender.Show();
        }