private void LoadFields()
 {
     try
     {
         CMSBL cmsBL = new CMSBL();
         DataTable pageDT = cmsBL.GetPage(hdnSiteID.Value, hdnChildPageID.Value);
         foreach (DataRow pageDR in pageDT.Rows)
         {
             txtPageName.Text = pageDR["PAGE_NAME"].ToString();
             txtPageCaption.Text = pageDR["PAGE_CAPTION"].ToString();
             txtMetaTitle.Text = pageDR["META_TITLE"].ToString();
             txtMetaKeywords.Text = pageDR["META_KEYWORDS"].ToString();
             txtMetaDescription.Text = pageDR["META_DESC"].ToString();
             ddlSortNumber.SelectedValue = pageDR["CHILD_SORT_PAGE_NUM"].ToString();
             string isPublished = pageDR["IS_PUBLISHED"].ToString();
             hdnMaxSortNum.Value = pageDR["CHILD_SORT_PAGE_NUM"].ToString();
             if (isPublished == "1")
                 rbYes.Checked = true;
             else
                 rbNo.Checked = true;
         }
     }
     catch (Exception ex)
     {
     }
 }
        private void LoadTreeView()
        {
            try
            {
                CMSBL cmsBL = new CMSBL();
                DataSet dsTreeView = cmsBL.GetClientTreeview(hdnSiteID.Value);
                DataTable dtOutline = new DataTable();
                DataTable dtTree = new DataTable();

                dtOutline = dsTreeView.Tables[0];
                dtTree = dsTreeView.Tables[1];

                foreach (DataRow drOutline in dtOutline.Rows)
                {
                    TreeNode node = new TreeNode(drOutline["PAGE_NAME"].ToString());
                    DataRow[] drChilds = dtTree.Select("PAGE_ID=" + drOutline["PAGE_ID"].ToString(), "CHILD_SORT_PAGE_NUM");
                    tvContent.Nodes.Add(node);
                    foreach (DataRow drChild in drChilds)
                    {
                        TreeNode childNode = new TreeNode(drChild["PAGE_NAME"].ToString());
                        node.ChildNodes.Add(childNode);
                    }

                }
            }
            catch (Exception ex)
            {

            }
        }
        private void GetHtmlContent(string pageName)
        {
            try
            {
                CMSBL cmsBL = new CMSBL();
                DataTable dtHtmlContent = cmsBL.GetHtmlContent(hdnSiteID.Value, pageName);
                foreach (DataRow drHtmlContent in dtHtmlContent.Rows)
                {
                    literal1.Text = Server.HtmlDecode(drHtmlContent["HTML_TEXT"].ToString().Replace("'", "'"));
                }
            }
            catch (Exception ex)
            {

            }
        }
 private void LoadFields()
 {
     try
     {
         CMSBL cmsBL = new CMSBL();
         DataTable pageDT = cmsBL.GetPage(hdnSiteID.Value, hdnChildPageID.Value);
         foreach (DataRow pageDR in pageDT.Rows)
         {
             txtPageName.Text = pageDR["PAGE_NAME"].ToString();
             txtPageCaption.Text = pageDR["PAGE_CAPTION"].ToString();
             txtMetaTitle.Text = pageDR["META_TITLE"].ToString();
             txtMetaKeywords.Text = pageDR["META_KEYWORDS"].ToString();
             txtMetaDescription.Text = pageDR["META_DESC"].ToString();
         }
     }
     catch (Exception ex)
     {
     }
 }
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            int returnNumber = -1;
            int rowNumber = 0;
            rowNumber = GetSelectedRow();

            if (rowNumber >= 0)
            {
                string companyID = dgSites.Items[rowNumber].Cells[2].Text;
                string siteID = dgSites.Items[rowNumber].Cells[0].Text;

                CMSBL cmsBL = new CMSBL();
                returnNumber = cmsBL.DeleteSite(companyID, siteID, _userName);
            }

            /*for (int i = 0; i < dgSites.Items.Count; i++)
            {
                CheckBox chkFlag;
                chkFlag = (CheckBox)dgSites.Items[i].Cells[0].FindControl("chkSelect");
                if (chkFlag.Checked)
                {
                    string companyID = dgSites.Items[i].Cells[2].Text;
                    string siteID = dgSites.Items[i].Cells[0].Text;

                    CMSBL cmsBL = new CMSBL();
                    returnNumber = cmsBL.DeleteSite(companyID, siteID, _userName);
                }
            }*/

            if (returnNumber > 0)
            {
                lblMessage.Text = "Successfully deleted the site.";
                lblMessage.ForeColor = System.Drawing.Color.Green;
                LoadSiteDetails();
            }
            else
            {
                lblMessage.Text = "Site Not Deleted.";
                lblMessage.ForeColor = System.Drawing.Color.Red;
            }
        }
        protected void tvContent_SelectedNodeChanged(object sender, EventArgs e)
        {
            try
            {
                DateTime startTime = DateTime.Parse(hdnStartTime.Value);
                TimeSpan timeDiff = DateTime.Now.Subtract(startTime);
                double dTime = Convert.ToDouble(timeDiff.TotalSeconds);
                if (dTime > 10)
                {
                    CMSBL cmsBL = new CMSBL();
                    //cmsBL.CaptureContentUsage("", "", "", dTime.ToString(), "");
                }
                hdnStartTime.Value = System.DateTime.Now.TimeOfDay.ToString(); ;
                string pageName = tvContent.SelectedNode.Value;
                GetHtmlContent(pageName);
            }
            catch (Exception ex)
            {

            }
        }
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            int returnNumber = -1;
            int rowNumber = 0;
            rowNumber = GetSelectedRow();
            if (rowNumber >= 0)
            {
                string pageID = dgOutline.Items[rowNumber].Cells[0].Text;

                CMSBL cmsBL = new CMSBL();
                returnNumber = cmsBL.DeleteOutline(hdnSiteID.Value, pageID);
            }

            /*for (int i = 0; i < dgOutline.Items.Count; i++)
            {
                CheckBox chkFlag;
                chkFlag = (CheckBox)dgOutline.Items[i].Cells[0].FindControl("chkSelect");
                if (chkFlag.Checked)
                {
                    string pageID = dgOutline.Items[i].Cells[0].Text;

                    CMSBL cmsBL = new CMSBL();
                    returnNumber = cmsBL.DeleteOutline(hdnSiteID.Value, pageID);
                }
            }*/

            if (returnNumber > 0)
            {
                lblMessage.Text = "Successfully deleted the Outline.";
                lblMessage.ForeColor = System.Drawing.Color.Green;
                LoadOutlineDetails();
            }
            else
            {
                lblMessage.Text = "Outline Not Deleted.";
                lblMessage.ForeColor = System.Drawing.Color.Red;
            }
        }
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            int returnNumber = -1;
            int rowNumber = 0;
            rowNumber = GetSelectedRow();
            if (rowNumber >= 0)
            {
                string childPageID = dgPages.Items[rowNumber].Cells[0].Text;
                CMSBL cmsBL = new CMSBL();
                returnNumber = cmsBL.DeletePage(hdnSiteID.Value, hdnPageID.Value, childPageID);
            }

            if (returnNumber == 1)
            {
                lblMessage.Text = "Page Deleted Successfully.";
                lblMessage.ForeColor = System.Drawing.Color.Green;
                LoadPageDetails();
            }
            else
            {
                lblMessage.Text = "Page Not Deleted.";
                lblMessage.ForeColor = System.Drawing.Color.Red;
            }
        }
        private void SavePage()
        {
            try
            {
                int returnNumber = -1;
                int sortNumber = 0;
                int childPageNumber = -1;
                string pageModID = "0";
                string pageName = txtPageName.Text.Replace("'", "''");
                string pageCaption = txtPageCaption.Text.Replace("'", "''");
                string metaTitle = txtMetaTitle.Text.Replace("'", "''");
                string metaDesc = txtMetaDescription.Text.Replace("'", "''");
                string metaKey = txtMetaKeywords.Text.Replace("'", "''");

                CMSBL cmsBL = new CMSBL();

                if (lblTitle.Text == "Add Page")
                {
                    bool duplicatePage = cmsBL.DuplicatePageName(hdnSiteID.Value, pageName);

                    if (duplicatePage)
                    {
                        lblMessage.Text = "Duplicate Page Name";
                        lblMessage.ForeColor = System.Drawing.Color.Red;
                        return;
                    }
                }

                SqlServer sqlServer = new SqlServer(Util.SqlConnectionString()); ;

                string isPublished = "";
                if (rbYes.Checked)
                    isPublished = "1";
                else if (rbNo.Checked)
                    isPublished = "0";

                //sortNumber = cmsBL.GetDuplicatePageSort(hdnSiteID.Value, hdnPageID.Value, ddlSortNumber.SelectedValue);

                if (sortNumber == 0)
                {
                    childPageNumber = cmsBL.JMD_PAGE_SAVE(hdnChildPageID.Value, hdnSiteName.Value, pageName, pageCaption,
                    metaTitle, metaDesc, metaKey, "",
                    isPublished, "0", "0", "Admin", "Admin", "Admin", "Admin", "Admin", "Admin", "0", "0", "0", "1");

                    if (lblTitle.Text == "Update Page")
                    {
                        DataSet dsPageMod = new DataSet();
                        dsPageMod = sqlServer.JMD_LOAD_MODS(hdnSiteName.Value, pageName);
                        if (dsPageMod.Tables[0].Rows.Count > 0)
                        {
                            DataRow[] dr = dsPageMod.Tables[0].Select("PAGE_NAME='" + pageName + "'");
                            if (dr.Length > 0)
                                pageModID = dr[0]["PAGE_MOD_ID"].ToString();
                        }

                        returnNumber = cmsBL.UpdateTreeview(hdnSiteID.Value, hdnPageID.Value, childPageNumber.ToString(), ddlSortNumber.SelectedValue, _userName);
                    }
                    else
                    {
                        returnNumber = cmsBL.CreateTreeview(hdnSiteID.Value, hdnPageID.Value, childPageNumber.ToString(), ddlSortNumber.SelectedValue, _userName);
                    }

                    sqlServer.JMD_PAGE_MOD_SAVE(pageModID, hdnSiteName.Value, pageName, "7",
                    "Mod_" + pageName, "7", "1", "0", "Admin;Guests;Registered;",
                    "Admin;", "Admin;", "Admin;", "Admin;", "0");

                    if (lblTitle.Text == "Add Page")
                    {
                        lblMessage.Text = "Successfully added the new Page.";
                    }
                    else
                    {
                        lblMessage.Text = "Successfully updated the Page.";
                    }
                    lblMessage.ForeColor = System.Drawing.Color.Green;

                }
                else
                {
                    lblMessage.Text = "Sort Number already exist.";
                    lblMessage.ForeColor = System.Drawing.Color.Red;
                }
            }
            catch (Exception ex)
            {
                lblMessage.Text = "Page Not Updated.";
                lblMessage.ForeColor = System.Drawing.Color.Red;
            }
        }
        private void LoadPageDetails()
        {
            try
            {
                CMSBL cmsBL = new CMSBL();
                DataTable siteDT = cmsBL.GetAllPages(hdnSiteID.Value, hdnPageID.Value);

                dgPages.DataSource = siteDT;
                dgPages.DataBind();

                /*if ((dgPages.Items.Count % dgPages.PageSize == 1) &&
                    (dgPages.CurrentPageIndex == dgPages.PageCount - 1) &&
                    (dgPages.CurrentPageIndex != 0))
                {
                    dgPages.CurrentPageIndex = dgPages.CurrentPageIndex - 1;
                }*/
            }
            catch (Exception ex)
            {

            }
        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                CMSBL cmsBL = new CMSBL();
                int returnNumber = -1;
                int folderNumber = -1;
                int siteNumber = -1;
                string siteName = txtSiteName.Text.Replace("'", "''");
                string companyName = ddlCompany.SelectedValue.ToString();

                folderNumber = cmsBL.GetDuplicateFolder(txtFolderName.Text);

                if (lblTitle.Text == "Add Company-Site")
                {
                    siteNumber = cmsBL.GetDuplicateSite(siteName, companyName);

                    if (siteNumber == 0 && folderNumber == 0)
                    {
                        returnNumber = cmsBL.CreateSite(companyName, siteName, "", ddlStyleSheet.SelectedValue.ToString(), "", txtFolderName.Text, _userName);
                        if (returnNumber == 1)
                        {
                            createFolder(txtFolderName.Text);
                            cmsBL.UpdateModuleMaster(companyName, siteName, _userName);
                        }
                    }
                }
                else if (lblTitle.Text == "Update Company-Site")
                {
                        returnNumber = cmsBL.UpdateSite(ddlCompany.SelectedValue.ToString(), siteName, "", ddlStyleSheet.SelectedValue.ToString(), "", txtFolderName.Text, _userName);
                }

                if (returnNumber == 1)
                {
                    if (lblTitle.Text == "Add Company-Site")
                    {
                        lblMessage.Text = "Successfully added a new site.";
                    }
                    else
                    {
                        lblMessage.Text = "Successfully updated the site.";
                    }
                    lblMessage.ForeColor = System.Drawing.Color.Green;

                }
                else if (siteNumber == 10)
                {
                    lblMessage.Text = "Site already exist";
                    lblMessage.ForeColor = System.Drawing.Color.Red;
                }
                else if (folderNumber == 11)
                {
                    lblMessage.Text = "Folder already exist";
                    lblMessage.ForeColor = System.Drawing.Color.Red;
                }
                else
                {
                    lblMessage.Text = "Site Not Updated";
                    lblMessage.ForeColor = System.Drawing.Color.Red;
                }
            }
            catch (Exception ex)
            {

            }
        }
 private void LoadFields(string companyID, string siteID)
 {
     try
     {
         CMSBL cmsBL = new CMSBL();
         DataTable siteDT = cmsBL.GetSite(companyID, siteID);
         foreach (DataRow siteDR in siteDT.Rows)
         {
             txtSiteName.Text = siteDR["SITE_NAME"].ToString();
             ddlCompany.SelectedValue = siteDR["COMPANYID"].ToString();
             ddlStyleSheet.SelectedValue = siteDR["STYLE_SHEET"].ToString();
             txtFolderName.Text = siteDR["SITE_FOLDER"].ToString();
         }
     }
     catch (Exception ex)
     {
     }
 }
        private void LoadCompany()
        {
            try
            {
                CMSBL cmsBL = new CMSBL();
                DataTable companyDT = cmsBL.GetAllCompany();
                ddlCompany.Items.Clear();
                ddlCompany.Items.Add(new ListItem("Select Company", "Select Company"));
                foreach (DataRow companyDR in companyDT.Rows)
                {
                    ddlCompany.Items.Add(new ListItem(companyDR["COMPANYNAME"].ToString(), companyDR["COMPANYID"].ToString()));
                }
            }
            catch (Exception ex)
            {

            }
        }
        private void SavePage()
        {
            try
            {
                int returnNumber = -1;
                int childPageNumber = -1;
                string pageModID = "0";
                string pageName = txtPageName.Text.Replace("'", "''");
                string pageCaption = txtPageCaption.Text.Replace("'", "''");
                string metaTitle = txtMetaTitle.Text.Replace("'", "''");
                string metaDesc = txtMetaDescription.Text.Replace("'", "''");
                string metaKey = txtMetaKeywords.Text.Replace("'", "''");

                CMSBL cmsBL = new CMSBL();
                if (lblTitle.Text == "Add Page")
                {
                    bool duplicatePage = cmsBL.DuplicatePageName(hdnSiteID.Value, pageName);

                    if (duplicatePage)
                    {
                        lblMessage.Text = "Duplicate Page Name";
                        lblMessage.ForeColor = System.Drawing.Color.Red;
                        return;
                    }
                }

                SqlServer sqlServer = new SqlServer(Util.SqlConnectionString());

                childPageNumber = cmsBL.JMD_PAGE_SAVE(hdnChildPageID.Value, hdnSiteName.Value, pageName, pageCaption,
                metaTitle, metaDesc, metaKey, "",
                "1", "0", "0", "Admin", "Admin", "Admin", "Admin", "Admin", "Admin", "0", "0", "0", "1");

                if (lblTitle.Text == "Update Page")
                {
                    DataSet dsPageMod = new DataSet();
                    dsPageMod = sqlServer.JMD_LOAD_MODS(hdnSiteName.Value, pageName);
                    if (dsPageMod.Tables[0].Rows.Count > 0)
                    {
                        DataRow[] dr = dsPageMod.Tables[0].Select("PAGE_NAME='" + pageName + "'");
                        if (dr.Length > 0)
                            pageModID = dr[0]["PAGE_MOD_ID"].ToString();
                    }
                }

                sqlServer.JMD_PAGE_MOD_SAVE(pageModID, hdnSiteName.Value, pageName, "7",
                    "Mod_" + pageName, "7", "1", "0", "Admin;Guests;Registered;",
                    "Admin;", "Admin;", "Admin;", "Admin;", "0");

                lblMessage.Text = "Page Updated Successfully";
                lblMessage.ForeColor = System.Drawing.Color.Green;

            }
            catch (Exception ex)
            {
                lblMessage.Text = "Page Not Updated";
                lblMessage.ForeColor = System.Drawing.Color.Red;
            }
        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                CMSBL cmsBL = new CMSBL();
                int returnNumber = -1;
                int sortNumber = -1;
                string outlineName = txtOutlineName.Text.Replace("'", "''");
                string outlineRemark = txtOutlineRemark.Text.Replace("'", "''");

                sortNumber = cmsBL.GetDuplicateOutlineSort(hdnSiteID.Value, ddlSortNumber.SelectedValue);

                if (sortNumber == 0)
                {
                    if (lblTitle.Text == "Add Outline")
                    {
                        returnNumber = cmsBL.GetDuplicateOutline(hdnSiteID.Value, outlineName);

                        if (returnNumber == 0)
                        {
                            returnNumber = cmsBL.CreateOutline(hdnSiteID.Value, outlineName, outlineRemark, ddlSortNumber.SelectedValue, "Y", _userName);
                        }
                    }
                    else if (lblTitle.Text == "Update Outline")
                    {
                        returnNumber = cmsBL.UpdateOutline(hdnSiteID.Value, hdnPageID.Value, outlineName, outlineRemark, ddlSortNumber.SelectedValue, _userName);
                    }
                }
                if (returnNumber == 1)
                {
                    if (lblTitle.Text == "Add Outline")
                    {
                        lblMessage.Text = "Successfully added the new Outline.";
                    }
                    else
                    {
                        lblMessage.Text = "Successfully updated the Outline.";
                    }
                    lblMessage.ForeColor = System.Drawing.Color.Green;

                }
                else if (returnNumber == 10)
                {
                    lblMessage.Text = "Outline already exist.";
                    lblMessage.ForeColor = System.Drawing.Color.Red;
                }
                else if (sortNumber == 10)
                {
                    lblMessage.Text = "Sort Number already exist.";
                    lblMessage.ForeColor = System.Drawing.Color.Red;
                }
                else
                {
                    if (lblTitle.Text == "Add Outline")
                    {
                        lblMessage.Text = "Outline Not Added.";
                    }
                    else
                    {
                        lblMessage.Text = "Outline Not Updated.";
                    }
                    lblMessage.ForeColor = System.Drawing.Color.Red;
                }
            }
            catch (Exception ex)
            {

            }
        }
 private void LoadFields(string siteID, string pageID)
 {
     try
     {
         CMSBL cmsBL = new CMSBL();
         DataTable siteDT = cmsBL.GetOutline(siteID, pageID);
         foreach (DataRow siteDR in siteDT.Rows)
         {
             txtOutlineName.Text = siteDR["PAGE_NAME"].ToString();
             txtOutlineRemark.Text = siteDR["PAGE_REMARK"].ToString();
             ddlSortNumber.SelectedValue = siteDR["SORT_NUMBER"].ToString();
             hdnMaxSortNum.Value = siteDR["SORT_NUMBER"].ToString();
         }
     }
     catch (Exception ex)
     {
     }
 }