/// Function Header*******************************************************
 /// Function Name: BindEvents
 /// Function Type: Function
 /// Functionality: used to get bind the events
 /// Input: 
 /// Output: 
 /// Return Value:
 /// Note: 
 /// *********************************************************************
 private void BindFavoriteList()
 {
     BLL.NewsLib oNewsLib = new BLL.NewsLib();
     GVFavoriteList.DataSource = oNewsLib.GetFavoriteListByUserName(AppLib.GetLoggedInUserName(), "User");
     GVFavoriteList.DataBind();
     oNewsLib = null;
 }
 private void BindNewsAnnouncements()
 {
     BLL.NewsLib oNewsLib = new BLL.NewsLib();
     dlNewsAnnouncments.DataSource = oNewsLib.GetAllNewsAnnouncements();
     dlNewsAnnouncments.DataBind();
     oNewsLib = null;
 }
    protected void GVNews_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("EditNews"))
        {
            Entity.NewsInfo oNewsInfo = new Entity.NewsInfo();
            BLL.NewsLib oNewsLib = new BLL.NewsLib();
            oNewsInfo = oNewsLib.GetNewsAnnouncementsById(Convert.ToInt32(e.CommandArgument));
            if (oNewsInfo != null)
            {
                txtHeading.Text = oNewsInfo.StrHeading;
                txtDescription.Text = oNewsInfo.StrDescription;
                chkIsHome.Checked = oNewsInfo.ChrIsHomePage.Equals('Y') ? true : false;
                chkIsActive.Checked = oNewsInfo.ChrIsActive.Equals('Y') ? true : false;
                txtDirectLink.Text = oNewsInfo.StrDirectLink;
                if (txtDirectLink.Text.Trim().Equals(string.Empty))
                {
                    ViewState["strOldFileName"] = oNewsInfo.StrPDFFilename;
                    ancPrevious.Visible = true;
                    ancPrevious.HRef = AppConfig.GetBaseSiteUrl() + AppConfig.GetNewsAnnouncementsPDFPath() + oNewsInfo.StrPDFFilename;
                }

                ViewState["intNewsAnnouncementsId"] = e.CommandArgument.ToString();
                oNewsInfo = null;
                oNewsLib = null;
            }
        }
        else if (e.CommandName.Equals("DeleteNews"))
        {

            BLL.NewsLib oNewsLib = new BLL.NewsLib();
            oNewsLib.DeleteNewsAnnouncements(Convert.ToInt32(e.CommandArgument));
            lblMsg.Text = "News & Announcements has been deleted successfully.";

            oNewsLib = null;
            ClearControls();
            BindNewsAnnouncements();
        }
        else if (e.CommandName.Equals("StatusChanged"))
        {

            BLL.NewsLib oNewsLib = new BLL.NewsLib();
            oNewsLib.UpdateNewsAnnouncementsStatus(Convert.ToInt32(e.CommandArgument));
            lblMsg.Text = "News & Announcements status has been changed successfully.";
            oNewsLib = null;
            ClearControls();
            BindNewsAnnouncements();
        }
    }
    protected void GVNews_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("EditNews"))
        {
            Entity.NewsInfo oNewsInfo = new Entity.NewsInfo();
            BLL.NewsLib oNewsLib = new BLL.NewsLib();
            oNewsInfo = oNewsLib.GetNewsLettersById(Convert.ToInt32(e.CommandArgument));
            if (oNewsInfo != null)
            {
                // if (!odataReader.DtCancelOn.ToString().Equals("1/1/1999 12:00:00 AM"))
                txttitle.Text = oNewsInfo.StrTitle;
                txtDescription.Text = oNewsInfo.StrDescription;
                if (!oNewsInfo.StrNewsletterDate.ToString().Equals("1/1/1999 12:00:00 AM"))
                    txtDate.Text = oNewsInfo.StrNewsletterDate.ToShortDateString();

                chkIsActive.Checked = oNewsInfo.ChrIsActive.Equals('Y') ? true : false;
                ViewState["strOldFileName"] = oNewsInfo.StrPDFFilename;
                ancPrevious.Visible = true;
                ancPrevious.HRef = AppConfig.GetBaseSiteUrl() + AppConfig.GetNewsLettersPDFPath() + oNewsInfo.StrPDFFilename;
                ViewState["intNewsLetterId"] = e.CommandArgument.ToString();
            }
        }
        else if (e.CommandName.Equals("DeleteNews"))
        {

            BLL.NewsLib oNewsLib = new BLL.NewsLib();
            oNewsLib.DeleteNewsletter(Convert.ToInt32(e.CommandArgument));
            lblMsg.Text = "Newsletter has been deleted successfully.";

            oNewsLib = null;
            ClearControls();
            BindNewsAnnouncements();
        }
        else if (e.CommandName.Equals("StatusChanged"))
        {

            BLL.NewsLib oNewsLib = new BLL.NewsLib();
            oNewsLib.UpdateNewsletterStatus(Convert.ToInt32(e.CommandArgument));
            lblMsg.Text = "Newsletter status has been changed successfully.";
            oNewsLib = null;
            ClearControls();
            BindNewsAnnouncements();
        }
    }
    protected void GVNewsLetter_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("AddToFavorite"))
        {
            LinkButton lnkBtnFavorite = (LinkButton)e.CommandSource;
            Entity.UserInfo oUserInfo = new Entity.UserInfo();
            oUserInfo.IntFavoriteTypeId = 0;
            oUserInfo.IntFavoriteId = 0;
            if (lnkBtnFavorite.Text == "Remove from Favorite")
                oUserInfo.IntFavoriteId = Convert.ToInt32(e.CommandArgument);

            oUserInfo.StrUserId = AppLib.GetLoggedInUserName();
            oUserInfo.StrTitle = "";
            oUserInfo.StrFavoriteType = "Newsletter";
            oUserInfo.DtCreatedOn = DateTime.Now;
            oUserInfo.IntFavoriteTypeId = Convert.ToInt32(e.CommandArgument);
            BLL.UserLib oUserLib = new BLL.UserLib();
            oUserLib.NewsletterAddToFavorite(oUserInfo);

            oUserInfo = null;
            oUserLib = null;
            BindNewsLetters();
        }
        else if (e.CommandName.Equals("PathNewslettersFile"))
        {
            Entity.NewsInfo oNewsInfo = new Entity.NewsInfo();
            BLL.NewsLib oNewsLib = new BLL.NewsLib();

            oNewsInfo = oNewsLib.GetNewsLettersById(Convert.ToInt32(e.CommandArgument));
            if (oNewsInfo != null)
            {

                GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
                LinkButton lnkNewslettes = (LinkButton)row.FindControl("lnkNewsletters");
                ViewState["strOldFileName"] = oNewsInfo.StrPDFFilename;
                string Path = AppConfig.GetBaseSiteUrl() + AppConfig.GetNewsLettersPDFPath() + oNewsInfo.StrPDFFilename;
                Response.Write("<script type='text/javascript'>detailedresults=window.open('" + Path + "', 'popUpWindow', 'height=700,width=900,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no, status=yes');</script>");
            }
        }
    }
    private void AddUpdateQuestionnareDetails()
    {
        BLL.NewsLib oNewsLib = new BLL.NewsLib();
        Entity.NewsInfo oNewsInfo = new Entity.NewsInfo();
        oNewsInfo.IntNewsLetterId = 0;
        oNewsInfo.StrTitle = txttitle.Text.Trim();
        oNewsInfo.StrDescription = txtDescription.Text.Trim();

        if (oNewsInfo.StrDescription.Length > 500)
            oNewsInfo.StrDescription = oNewsInfo.StrDescription.Substring(0, 490);

        if (!txtDate.Text.Equals(string.Empty))
            oNewsInfo.StrNewsletterDate = Convert.ToDateTime(txtDate.Text);
        else
            oNewsInfo.StrNewsletterDate = Convert.ToDateTime("01/01/1999");

        oNewsInfo.ChrIsActive = chkIsActive.Checked ? 'Y' : 'N';
        oNewsInfo.DtCreatedOn = DateTime.Now;

        oNewsInfo.StrPDFFilename = string.Empty;
        if (ViewState["strOldFileName"] != null)
        {
            oNewsInfo.StrPDFFilename = ViewState["strOldFileName"].ToString();
        }

        string strpath = string.Empty;
        try
        {
            if (fupPDF.HasFile)
            {

                strpath = Request.PhysicalApplicationPath + AppConfig.GetNewsLettersPDFPath();

                if (ViewState["strOldFileName"] != null)
                {
                    if (System.IO.File.Exists(strpath + ViewState["strOldFileName"]))
                    {
                        System.IO.File.Delete(strpath + ViewState["strOldFileName"]);
                    }
                }

                string strFileName = DateTime.Now.ToString("MMddyyyyHHmmss");
                strFileName = AppLib.UploadCompanyExcelForUserRegRequest(ref fupPDF, strFileName, strpath);
                oNewsInfo.StrPDFFilename = strFileName;
            }
        }
        catch
        {
        }

        if (ViewState["intNewsLetterId"] != null)
        {
            oNewsInfo.IntNewsLetterId = Convert.ToInt32(ViewState["intNewsLetterId"]);
            if (oNewsLib.UpdateNewsletter(oNewsInfo) > 0)
            {
                lblMsg.Text = "Newsletter has been updated successfully.";
                ViewState["intNewsLetterId"] = null;
                ViewState["strOldFileName"] = null;
                ClearControls();
                BindNewsAnnouncements();
            }
            else
            {
                lblMsg.Text = "Newsletter already exists.";
            }
        }
        else
        {
            if (oNewsLib.SaveNewsletter(oNewsInfo) > 0)
            {
                lblMsg.Text = "Newsletter has been added successfully.";
                ClearControls();
                BindNewsAnnouncements();
            }
            else
            {
                lblMsg.Text = "Newsletter already exists.";
            }
        }
        oNewsInfo = null;
        oNewsLib = null;
    }
 /// Function Header*******************************************************
 /// Function Name: BindLibrary
 /// Function Type: Function
 /// Functionality: used to bind announcements
 /// Input: 
 /// Output: 
 /// Return Value:
 /// Note: 
 /// *********************************************************************
 private void BindLibrary()
 {
     BLL.NewsLib oNewsLib = new BLL.NewsLib();
     GVLibrary.DataSource = oNewsLib.GetUserFavoriteLibrary(AppLib.GetLoggedInUserName(), "User");
     GVLibrary.DataBind();
     oNewsLib = null;
 }
    private void BindDetails()
    {
        if (Request.QueryString["type"] != null && Request.QueryString["id"] != null && Request.QueryString["fid"] != null)
        {
            BLL.NewsLib oNewsLib = new BLL.NewsLib();
            Entity.NewsInfo oNewsInfo = new Entity.NewsInfo();

            if (Request.QueryString["type"].ToString().ToLower().Equals("newsletter"))
            {
                trNewsletter.Visible = true;
                oNewsInfo = new Entity.NewsInfo();
                oNewsLib = new BLL.NewsLib();
                oNewsInfo = oNewsLib.GetNewsLettersById(Convert.ToInt32(Request.QueryString["id"]));
                if (oNewsInfo != null)
                {
                    lblNewsletterDescription.Text = oNewsInfo.StrDescription;
                    if (!oNewsInfo.StrNewsletterDate.ToString().Equals("1/1/1999 12:00:00 AM"))
                        lblNewsletterDate.Text = oNewsInfo.StrNewsletterDate.ToShortDateString();

                    if (!oNewsInfo.StrPDFFilename.Equals("na.pdf"))
                    {
                        ancPrevious.Visible = true;
                        ancPrevious.HRef = AppConfig.GetBaseSiteUrl() + AppConfig.GetNewsLettersPDFPath() + oNewsInfo.StrPDFFilename;
                    }
                    else
                    {
                        trNewsletterPDF.Visible = false;
                    }
                }
            }
            else if (Request.QueryString["type"].ToString().ToLower().Equals("event"))
            {
                trEvent.Visible = true;
                if (Request.QueryString["id"] != null)
                {
                    int _intEventId = 0;
                    _intEventId = Convert.ToInt32(Request.QueryString["id"]);
                    Entity.EventInfo oEventInfo = new Entity.EventInfo();
                    BLL.EventsLib oEventsLib = new BLL.EventsLib();
                    oEventInfo = oEventsLib.GetEventByEventId(_intEventId);
                    if (oEventInfo != null)
                    {
                        lblEventActivity.Text = oEventInfo.StrActivity;
                        lblEventComments.Text = oEventInfo.StrComments;
                        lblEventDate.Text = oEventInfo.DtEventDate.ToShortDateString();
                        lblEventLocation.Text = oEventInfo.StrLocation;
                    }

                    oEventsLib = null;
                    oEventInfo = null;
                }
            }
            else if (Request.QueryString["type"].ToString().ToLower().Equals("newsannouncements"))
            {
                trNewsAnnouncement.Visible = true;
                oNewsInfo = new Entity.NewsInfo();
                oNewsLib = new BLL.NewsLib();
                oNewsInfo = oNewsLib.GetNewsAnnouncementsById(Convert.ToInt32(Request.QueryString["id"]));
                if (oNewsInfo != null)
                {
                    lblNewsAnnouncementDescription.Text = oNewsInfo.StrDescription;
                    lblNewsAnnouncementDirectLink.Text = oNewsInfo.StrDirectLink;
                    if (lblNewsAnnouncementDirectLink.Text.Trim().Equals(string.Empty))
                    {
                        trNewsAnnouncementDirectLink.Visible = false;
                        trNewsAnnouncementPDF.Visible = true;
                        ancPreviousNewsAnnoucment.HRef = AppConfig.GetBaseSiteUrl() + AppConfig.GetNewsAnnouncementsPDFPath() + oNewsInfo.StrPDFFilename;
                    }
                    else
                    {
                        trNewsAnnouncementDirectLink.Visible = true;
                        trNewsAnnouncementPDF.Visible = false;
                    }

                    oNewsInfo = null;
                    oNewsLib = null;
                }
            }
            else if (Request.QueryString["type"].ToString().ToLower().Equals("library"))
            {
                trLibrary.Visible = true;
                Entity.LibraryInfo oLibraryInfo = new Entity.LibraryInfo();
                BLL.LibraryLib oLibraryLib = new BLL.LibraryLib();
                oLibraryInfo = oLibraryLib.GetLibraryByLibraryId(Convert.ToInt32(Request.QueryString["id"]));
                if (oLibraryInfo != null)
                {
                    lblLibraryDescription.Text = oLibraryInfo.StrDescription;
                    if (!oLibraryInfo.DtLibraryDate.ToString().Equals("1/1/1999 12:00:00 AM"))
                        lblLibraryDate.Text = oLibraryInfo.DtLibraryDate.ToShortDateString();

                    if (oLibraryInfo.StrLocationType.ToLower().Equals("pdf") || oLibraryInfo.StrLocationType.ToLower().Equals("video"))
                    {
                        trLibraryLink.Visible = false;
                        ancLibraryPDF.Visible = true;
                        ancLibraryPDF.HRef = AppConfig.GetBaseSiteUrl() + AppConfig.GetLibrariesFilePath() + oLibraryInfo.StrLocation;
                    }
                    else
                    {
                        trLibraryPDF.Visible = false;
                        lblLibraryWebsiteLink.Text = oLibraryInfo.StrLocation;
                    }

                    lblLibraryCategoryType.Text = oLibraryInfo.StrLocationType;
                    lblLibraryCategory.Text = oLibraryInfo.StrCategory;

                    oLibraryInfo = null;
                    oLibraryLib = null;
                }
            }
        }
    }
    private void BindFavoriteDetails()
    {
        if (Request.QueryString["type"] != null && Request.QueryString["id"] != null && Request.QueryString["fid"] != null)
        {
            BLL.NewsLib oNewsLib = new BLL.NewsLib();
            Entity.NewsInfo oNewsInfo = new Entity.NewsInfo();
            oNewsInfo = oNewsLib.GetFavoriteListByFavoriteId(Convert.ToInt32(Request.QueryString["fid"]));
            if (oNewsInfo != null)
                txtFavoriteTitle.Text = oNewsInfo.StrTitle;

            oNewsLib = null;
            oNewsInfo = null;
        }
    }
    private void AddUpdateQuestionnareDetails()
    {
        if (fupPDF.HasFile)
        {
            if (!txtDirectLink.Text.Trim().Equals(string.Empty))
            {
                lblMsg.Text = "You can not Upload or Enter Direct Link simultaneously.";
                return;
            }
        }

        BLL.NewsLib oNewsLib = new BLL.NewsLib();
        Entity.NewsInfo oNewsInfo = new Entity.NewsInfo();
        oNewsInfo.IntNewsAnnouncementsId = 0;

        oNewsInfo.StrHeading = txtHeading.Text.Trim();
        oNewsInfo.StrDescription = txtDescription.Text.Trim();

        if (oNewsInfo.StrDescription.Length > 500)
            oNewsInfo.StrDescription = oNewsInfo.StrDescription.Substring(0, 499);

        oNewsInfo.ChrIsHomePage = chkIsHome.Checked ? 'Y' : 'N';
        oNewsInfo.ChrIsActive = chkIsActive.Checked ? 'Y' : 'N';
        oNewsInfo.StrDirectLink = string.Empty;
        oNewsInfo.DtCreatedOn = DateTime.Now;
        oNewsInfo.StrPDFFilename = string.Empty;
        if (ViewState["strOldFileName"] != null)
            oNewsInfo.StrPDFFilename = ViewState["strOldFileName"].ToString();

        string strpath = string.Empty;
        try
        {
            if (fupPDF.HasFile)
            {
                strpath = Request.PhysicalApplicationPath + AppConfig.GetNewsAnnouncementsPDFPath();

                if (ViewState["strOldFileName"] != null)
                {
                    if (System.IO.File.Exists(strpath + ViewState["strOldFileName"]))
                        System.IO.File.Delete(strpath + ViewState["strOldFileName"]);
                }

                string strFileName = DateTime.Now.ToString("MMddyyyyHHmmss");
                strFileName = AppLib.UploadCompanyExcelForUserRegRequest(ref fupPDF, strFileName, strpath);
                oNewsInfo.StrPDFFilename = strFileName;
            }
            else
            {
                oNewsInfo.StrDirectLink = txtDirectLink.Text.Trim();
            }
        }
        catch
        { //lblMsg.Text = "Invalid file/Content. Please download the template and fill the proper details.";

        }

        if (ViewState["intNewsAnnouncementsId"] != null)
        {
            oNewsInfo.IntNewsAnnouncementsId = Convert.ToInt32(ViewState["intNewsAnnouncementsId"]);
            if (oNewsLib.UpdateNewsAnnouncements(oNewsInfo) > 0)
            {
                lblMsg.Text = "News & Announcements has been updated successfully.";
                ViewState["intNewsAnnouncementsId"] = null;
                ViewState["strOldFileName"] = null;
                ClearControls();
                BindNewsAnnouncements();
            }
            else
            {
                lblMsg.Text = "News & Announcements already exists.";
            }
        }
        else
        {
            if (oNewsLib.SaveNewsAnnouncements(oNewsInfo) > 0)
            {
                lblMsg.Text = "News & Announcements has been added successfully.";
                ClearControls();
                BindNewsAnnouncements();
            }
            else
            {
                lblMsg.Text = "News & Announcements already exists.";
            }
        }
        oNewsInfo = null;
        oNewsLib = null;
    }
 /// Function Header*******************************************************
 /// Function Name: BindAnnouncements
 /// Function Type: Function
 /// Functionality: used to bind announcements
 /// Input: 
 /// Output: 
 /// Return Value:
 /// Note: 
 /// *********************************************************************
 private void BindEvents()
 {
     BLL.NewsLib oNewsLib = new BLL.NewsLib();
        /* GVEvents.DataSource = oNewsLib.GetUserFavoriteEvents(AppLib.GetLoggedInUserName(), "User");
     GVEvents.DataBind();*/
     oNewsLib = null;
 }
 /// Function Header*******************************************************
 /// Function Name: BindNewsLetters
 /// Function Type: Function
 /// Functionality: used to bind newsletter
 /// Input: 
 /// Output: 
 /// Return Value:
 /// Note: 
 /// *********************************************************************
 private void BindNewsLetters()
 {
     BLL.NewsLib oNewsLib = new BLL.NewsLib();
     GVNewsLetter.DataSource = oNewsLib.GetUserFavoriteNewsLetters(AppLib.GetLoggedInUserName(), "User");
     GVNewsLetter.DataBind();
     oNewsLib = null;
 }