private void SavePricePointBySubArea(IRMS.Entities.GeneralMemoConcession genMemoObj)
        {
            PricePointManager PPointManager = new PricePointManager();
            List<PriceGroup> _PriceGroupList = new List<PriceGroup>();
            _PriceGroupList = _PGManager.PriceGroupConcession();

            PricePoint pricePointObj;
            int iTotalRow = gvMarkdownList.Rows.Count;
            int iRow = 0;

            foreach (PriceGroup pgroupItem in _PriceGroupList)
            {
                for (iRow = 0; iRow < iTotalRow; iRow++)
                {
                    pricePointObj = new PricePoint();
                    pricePointObj.StyleNo = gvMarkdownList.Rows[iRow].Cells[2].Text;
                    pricePointObj.BrandName = DDLBrand.SelectedValue;
                    pricePointObj.PGNo = pgroupItem.PGNo;
                    pricePointObj.Price_Type = genMemoObj.PriceType;
                    pricePointObj.Price = Convert.ToDecimal(gvMarkdownList.Rows[iRow].Cells[5].Text) + Convert.ToDecimal(_PGManager.AddValueToRegularPrice(pgroupItem.PGNo));
                    pricePointObj.Date_Posted = genMemoObj.MemoDate;
                    pricePointObj.f_Date = genMemoObj.FromDate;
                    pricePointObj.t_Date = genMemoObj.ToDate;
                    pricePointObj.Group_No = Convert.ToInt32(DDLSubArea.SelectedItem.Value);
                    //pricePointObj.Group_No = genMemoObj.GroupNumber;
                    pricePointObj.Memo_ID = genMemoObj.RecordNumber;
                    pricePointObj.Memo_No = genMemoObj.MemoNumber;
                    PPointManager.Save(pricePointObj);
                }
            }

            iTotalRow = gvNewMarkdown.Rows.Count;
            foreach (PriceGroup pgroupItem in _PriceGroupList)
            {
                for (iRow = 0; iRow < iTotalRow; iRow++)
                {
                    pricePointObj = new PricePoint();
                    pricePointObj.StyleNo = gvNewMarkdown.Rows[iRow].Cells[2].Text;
                    pricePointObj.BrandName = DDLBrand.SelectedValue;
                    pricePointObj.PGNo = pgroupItem.PGNo;
                    pricePointObj.Price_Type = genMemoObj.PriceType;
                    pricePointObj.Price = Convert.ToDecimal(gvNewMarkdown.Rows[iRow].Cells[5].Text) + Convert.ToDecimal(_PGManager.AddValueToRegularPrice(pgroupItem.PGNo));
                    pricePointObj.Date_Posted = genMemoObj.MemoDate;
                    pricePointObj.f_Date = genMemoObj.FromDate;
                    pricePointObj.t_Date = genMemoObj.ToDate;
                    pricePointObj.Group_No = Convert.ToInt32(DDLSubArea.SelectedItem.Value);
                    //pricePointObj.Group_No = genMemoObj.GroupNumber;
                    pricePointObj.Memo_ID = genMemoObj.RecordNumber;
                    pricePointObj.Memo_No = genMemoObj.MemoNumber;
                    PPointManager.Save(pricePointObj);
                }
            }
        }
        private void SavePricePointByArea(IRMS.Entities.GeneralMemoConcession genMemoObj)
        {
            PricePointManager PPointManager = new PricePointManager();
            List<PriceGroup> _PriceGroupList = new List<PriceGroup>();
            _PriceGroupList = _PGManager.PriceGroupConcession();

            switch (genMemoObj.GroupNumber)
            {
                case 0:
                    {
                        _GroupAreaMemoManager.GroupAreaMemoByAllAreas();
                    }
                    break;
                case 99:
                    {
                        _GroupAreaMemoManager.GroupAreaMemoByAllProvinces();
                    }
                    break;
                default:
                    {
                        _GroupAreaMemoManager.GroupAreaMemoByAreaNumber(genMemoObj.GroupNumber);
                    }
                    break;
            }

            _GroupAreaMemoList = _GroupAreaMemoManager.GroupAreaMemoList;

            PricePoint pricePointObj;
            int iTotalRow = gvMarkdownList.Rows.Count;
            int iRow = 0;

            foreach (GroupAreaMemoClass gAreaMemo in _GroupAreaMemoList)
            {
                foreach (PriceGroup pgroupItem in _PriceGroupList)
                {
                    for (iRow = 0; iRow < iTotalRow; iRow++)
                    {
                        pricePointObj = new PricePoint();
                        pricePointObj.StyleNo = gvMarkdownList.Rows[iRow].Cells[2].Text;
                        pricePointObj.BrandName = genMemoObj.BrandName;
                        pricePointObj.PGNo = pgroupItem.PGNo;
                        pricePointObj.Price = Convert.ToDecimal(gvMarkdownList.Rows[iRow].Cells[5].Text) + Convert.ToDecimal(_PGManager.AddValueToRegularPrice(pgroupItem.PGNo));
                        pricePointObj.Price_Type = genMemoObj.PriceType;
                        pricePointObj.Date_Posted = genMemoObj.MemoDate;
                        pricePointObj.f_Date = genMemoObj.FromDate;
                        pricePointObj.Group_No = gAreaMemo.AreaGroupNo;
                        pricePointObj.Memo_ID = genMemoObj.RecordNumber;
                        pricePointObj.Memo_No = genMemoObj.MemoNumber;
                        PPointManager.Save(pricePointObj);
                    }
                }
            }

            iTotalRow = gvNewMarkdown.Rows.Count;
            foreach (GroupAreaMemoClass gAreaMemo in _GroupAreaMemoList)
            {
                foreach (PriceGroup pgroupItem in _PriceGroupList)
                {
                    for (iRow = 0; iRow < iTotalRow; iRow++)
                    {
                        pricePointObj = new PricePoint();
                        pricePointObj.StyleNo = gvNewMarkdown.Rows[iRow].Cells[2].Text;
                        pricePointObj.BrandName = genMemoObj.BrandName;
                        pricePointObj.PGNo = pgroupItem.PGNo;
                        pricePointObj.Price = Convert.ToDecimal(gvNewMarkdown.Rows[iRow].Cells[5].Text) + Convert.ToDecimal(_PGManager.AddValueToRegularPrice(pgroupItem.PGNo));
                        pricePointObj.Price_Type = genMemoObj.PriceType;
                        pricePointObj.Date_Posted = genMemoObj.MemoDate;
                        pricePointObj.f_Date = genMemoObj.FromDate;
                        pricePointObj.Group_No = gAreaMemo.AreaGroupNo;
                        pricePointObj.Memo_ID = genMemoObj.RecordNumber;
                        pricePointObj.Memo_No = genMemoObj.MemoNumber;
                        PPointManager.Save(pricePointObj);
                    }
                }
            }
        }
        private void SavePricePointByCustomer(IRMS.Entities.GeneralMemoConcession genMemoObj)
        {
            PricePointManager PPointManager = new PricePointManager();
            CustomerInfoManager custInfoManager = new CustomerInfoManager();

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

            PricePoint pricePointObj;
            int iTotalRow = gvMarkdownList.Rows.Count;
            int iRow = 0;

            for (iRow = 0; iRow < iTotalRow; iRow++)
            {
                pricePointObj = new PricePoint();
                pricePointObj.StyleNo = gvMarkdownList.Rows[iRow].Cells[2].Text;
                pricePointObj.BrandName = DDLBrand.SelectedValue;
                pricePointObj.Price_Type = genMemoObj.PriceType;
                pricePointObj.PGNo = custInfoManager.GetCustomerByKey(genMemoObj.GroupNumber).PriceGroupNo;
                pricePointObj.Price = Convert.ToDecimal(gvMarkdownList.Rows[iRow].Cells[5].Text) + Convert.ToDecimal(_PGManager.AddValueToRegularPrice(pricePointObj.PGNo));
                pricePointObj.Date_Posted = genMemoObj.MemoDate;
                pricePointObj.f_Date = genMemoObj.FromDate;
                pricePointObj.t_Date = genMemoObj.ToDate;
                pricePointObj.Group_No = genMemoObj.GroupNumber;
                pricePointObj.Memo_ID = genMemoObj.RecordNumber;
                pricePointObj.Memo_No = genMemoObj.MemoNumber;
                PPointManager.Save(pricePointObj);
            }

            iTotalRow = gvNewMarkdown.Rows.Count;
            for (iRow = 0; iRow < iTotalRow; iRow++)
            {
                pricePointObj = new PricePoint();
                pricePointObj.StyleNo = gvNewMarkdown.Rows[iRow].Cells[2].Text;
                pricePointObj.BrandName = DDLBrand.SelectedValue;
                pricePointObj.Price_Type = genMemoObj.PriceType;
                pricePointObj.PGNo = custInfoManager.GetCustomerByKey(genMemoObj.GroupNumber).PriceGroupNo;
                pricePointObj.Price = Convert.ToDecimal(gvNewMarkdown.Rows[iRow].Cells[5].Text) + Convert.ToDecimal(_PGManager.AddValueToRegularPrice(pricePointObj.PGNo));
                pricePointObj.Date_Posted = genMemoObj.MemoDate;
                pricePointObj.f_Date = genMemoObj.FromDate;
                pricePointObj.t_Date = genMemoObj.ToDate;
                pricePointObj.Group_No = genMemoObj.GroupNumber;
                pricePointObj.Memo_ID = genMemoObj.RecordNumber;
                pricePointObj.Memo_No = genMemoObj.MemoNumber;
                PPointManager.Save(pricePointObj);
            }
        }
        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;
        }
        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 LoadMDMemoInfo()
        {
            GroupAreaMemoManager gAMM = new GroupAreaMemoManager();
            PricePointManager ppM = new PricePointManager();

            _GenMemoObj = GMCM.GetGeneralMemoConcessionByKey(Convert.ToInt64(Session["MemoID"]));
            _GenMemoObj.RecordNumber = Convert.ToInt32(Session["MemoID"]);
            Session["GenMemoObject"] = _GenMemoObj;

            txtMemoNumber.Text = _GenMemoObj.MemoNumber;
            txtMemoDate.Text = _GenMemoObj.MemoDate.ToShortDateString();
            txtBrandName.Text = _GenMemoObj.BrandName;

            txtApplyPricePoint.Text = _GenMemoObj.PriceType;
            txtEffectivityDate.Text = _GenMemoObj.FromDate.ToShortDateString();

            if (_GenMemoObj.PriceType.ToUpper() == "AREA")
            {
                pnlAreaGroup.Visible = true;
                pnlSubAreaGroup.Visible = false;
                mvApplyPricePoint.SetActiveView(vAreaGroup);
                lblSubArea.Visible = false;
                txtSubAreaGroup.Visible = false;
                txtAreaGroup.Text = gAMM.GetAreaGroupMemoByKey(_GenMemoObj.GroupNumber).GroupName.ToUpper();
            }
            else if (_GenMemoObj.PriceType.ToUpper() == "SUB-AREA")
            {
                pnlSubAreaGroup.Visible = true;
                pnlAreaGroup.Visible = false;
                //lblSubArea.Visible = true;
                mvApplyPricePoint.SetActiveView(vAreaGroup);
                lblSubArea.Visible = true;
                txtSubAreaGroup.Visible = true;
                txtAreaGroup.Text = gAMM.GetAreaGroupMemoByKey(_GenMemoObj.GroupNumber).GroupName.ToUpper();
                List<int> GroupNoList = ppM.GetDistinctGroupNoByMemoNo(_GenMemoObj.MemoNumber);

                if (GroupNoList.Count > 1)
                    txtSubAreaGroup.Text = "ALL";
                else
                    txtSubAreaGroup.Text = new SubGroupAreaManager().GetSubGroupArea(GroupNoList[0]).GroupName.ToUpper();

                txtPromoPeriodTo.Text = _GenMemoObj.ToDate.ToShortDateString();
            }
            else
            {
                mvApplyPricePoint.SetActiveView(vCustomer);
            }

            switch (_GenMemoObj.GroupNumber)
            {
                case 0:
                    {
                        txtAreaGroup.Text = "ALL";
                    }
                    break;
                case 99:
                    {
                        txtAreaGroup.Text = "ALL PROVINCES";
                    }
                    break;
            }
            LoadMDMemoList();
        }
        protected void gvItems_SelectedIndexChangedEx(object sender, EventArgs e)
        {
            _GenMemoObj = (IRMS.Entities.GeneralMemoConcession)Session["GenMemoObject"];
            PriceManager pM = new PriceManager();
            PricePointManager ppM = new PricePointManager();

            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)
            {
                this.lblDuplicateCount.Text = "{0} items found!";
                lblDuplicateCount.Text = string.Format(lblDuplicateCount.Text, 1);
                hfDuplicateStylePopupExtender.Show();
                return;
            }

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

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

            int GroupNo = -1;

            GroupNo = _GenMemoObj.GroupNumber;
            if (_GenMemoObj.PriceType == "AREA")
            {
                if (GroupNo == 0)
                    GroupNo = 1;
                else
                {
                    if (GroupNo == 99)
                        GroupNo = 2;
                }
            }

            pPoint = ppM.GetStyleCurrentPrice1(gvItems.SelectedRow.Cells[1].Text, txtBrandName.Text, _GenMemoObj.PriceType, GroupNo);

            //GET MARKDOWN PRICE IF ANY
            if (pPoint != null)
            {
                dResult = Convert.ToDouble(pPoint.Price);
                lblPriceStatus.Text = "MARKDOWN";
            }

            txtCurrentPrice.Text = string.Format("{0:0.00}", dResult);
            btnAddNewItem_ModalPopupExtender.Show();
        }
        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();
        }