Tuesday, January 3, 2012

SharePoint Object Model Code based on the page title...!

using System;
using System.Runtime.InteropServices;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Serialization;
using System.Security;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;
using System.Collections.Specialized;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
using System.Configuration;
using System.Data;
using System.Drawing;
[assembly: AllowPartiallyTrustedCallers]
namespace TestWebPart1
{
    [Guid("8b9866d6-3cb4-4fca-a753-a1af844420e4")]
    public class TestWebPart1 : System.Web.UI.WebControls.WebParts.WebPart
    {
       
        public TestWebPart1()
        {
        }
        #region GlobalDeclarations
        DropDownList ddlCategory;
        CheckBoxList chkCategory;
        RadioButtonList rbCategory;
        SPGridView sgvLinks;
        SPGridView sgvImages;
        SPGridView sgvEntireRowBackColor;
        SPGridView sgvSingleRowBackColor;
        TextBox txtUserName;
        TextBox txtPassWord;
        RequiredFieldValidator rfvUserName;
        RequiredFieldValidator rfvPassWord;
        Button btnSave;
        Button btnSearch;
        Button btnUpdate;
        Button btnDelete;
        Button btnDeleteCancel;
        Button btnCancel;
        DataSet dsetSingleRowBackColor = new DataSet();
        DataTable dtSingleRowBackColor = new DataTable();
        DataSet dsetEntireRowBackcolor = new DataSet();
        DataTable dtEntireRowBackcolor = new DataTable();
        DataSet dsetImages = new DataSet();
        DataTable dtImages = new DataTable();
        DataSet dsetLinks = new DataSet();
        DataTable dtLinks = new DataTable();
        string strStyleValign = string.Empty;
        string strError = string.Empty;
        #endregion
        #region GlobalDeclarationforEmpInfo
        TextBox txtEmpNo, txtEmpName, txtEmpAge, txtEmpPhoneNumber, txtEmpEmailID, txtCountry, txtState;
        DropDownList ddlCountry, ddlState,ddlCountryInStatePage;
        Button btnEmpSave, btnEmpSearch, btnEmpdelete, btnEmpUpdate, btnEmpCancel, btnAddCountry, btnAddCountryCancel, btnAddState;
        RadioButton rbMale, rbFemale;
        RequiredFieldValidator rfvEmpNo, rfvEmpName, rfvEmpAge, rfvEmpPhoneNumber, rfvEmpEmailID, rfvEmpCountry, rfvEmpState, rfvAddCountry, rfvAddState, rfvCountryInStatePage;
        #endregion
        protected override void Render(HtmlTextWriter writer)
        {
            strStyleValign = "vertical-align:top;";
            writer.Write(strError);
            try
            {
                if (Page.Request.Url.ToString().Contains("TopFiveTasks.aspx"))
                {
                    # region TopfiveTasks
                    SPWeb currentWeb = SPControl.GetContextWeb(Context);
                    SPList lstTasks = currentWeb.Lists["Tasks"];
                    if (lstTasks != null)
                    {
                        SPQuery sQuery = new SPQuery();
                        sQuery.Query = "<OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy><Where><Neq><FieldRef Name='Status' /><Value Type='Choice'>Completed</Value></Neq></Where>";
                        //sQuery.Query = "<Query><OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy></Query>";
                        sQuery.RowLimit = 5;
                        SPListItemCollection tasksList = lstTasks.GetItems(sQuery);
                        //SPListItem item = tasksList.Add();
                        writer.Write("<Table width='100%' style='"+strStyleValign+"'>");
                        if (tasksList.Count > 0)
                        {
                            writer.Write("<Tr>");
                            writer.Write("<Td colspan='3' align='Center'>");
                            writer.Write("<Strong>");
                            writer.Write("<Font color='Red'>");
                            writer.Write("Top five tasks");
                            writer.Write("</Font>");
                            writer.Write("</Strong>");
                            writer.Write("</Td>");
                            writer.Write("</Tr>");
                            writer.Write("<Tr>");
                            writer.Write("<Td>");
                            writer.Write("Task Name");
                            writer.Write("</Td>");
                            writer.Write("<Td>");
                            writer.Write("Task Status");
                            writer.Write("</Td>");
                            writer.Write("<Td>");
                            writer.Write("Task Priority");
                            writer.Write("</Td>");
                            writer.Write("</Tr>");
                            foreach (SPListItem sQueryItem in tasksList)
                            {
                                string strTitle = string.Empty;
                                strTitle = sQueryItem["Title"].ToString();
                                string strStatus = string.Empty;
                                string strPriority = string.Empty;
                                string strUrl = currentWeb.Url + "/Lists/Tasks/DispForm.aspx?ID=" + sQueryItem.ID + "&source=" + Page.Request.Url;
                                writer.Write("<Tr>");
                                writer.Write("<Td>");
                                writer.Write("<A href='" + strUrl + "'>" + strTitle + "</A>");
                                writer.Write("</Td>");
                                writer.Write("<Td>");
                                if (sQueryItem["Status"] != null)
                                {
                                    strStatus = sQueryItem["Status"].ToString().Substring(sQueryItem["Status"].ToString().LastIndexOf("#") + 1);
                                }
                                else
                                {
                                    strStatus = "--";
                                }
                                writer.Write(strStatus);
                                writer.Write("</Td>");
                                writer.Write("<Td>");
                                if (sQueryItem["Priority"] != null)
                                {
                                    strPriority = sQueryItem["Priority"].ToString().Substring(sQueryItem["Priority"].ToString().LastIndexOf("#") + 1);
                                }
                                else
                                {
                                    strPriority = "--";
                                }
                                writer.Write(strPriority);
                                writer.Write("</Td>");
                                writer.Write("</Tr>");
                            }
                        }
                        else
                        {
                            writer.Write("<Tr>");
                            writer.Write("<Td colspan='3' align='Center'>");
                            writer.Write("There are no Active Tasks");
                            writer.Write("</Td>");
                            writer.Write("</Tr>");
                        }
                    }
                    else
                    {
                        writer.Write("<Tr>");
                        writer.Write("<Td colspan='3' align='Center'>");
                        writer.Write("Taks List Not available");
                        writer.Write("</Td>");
                        writer.Write("</Tr>");
                    }
                    writer.Write("</Table>");
                    #endregion
                }
                else if (Page.Request.Url.ToString().Contains("LookUp.aspx"))
                {
                    #region LookUp
                    writer.Write("<Table style='"+strStyleValign+"'>");
                    writer.Write("<Tr>");
                    writer.Write("<Td Colspan='2' Align='Center'>");
                    writer.Write("LookUp program with different Asp.Net server controls using SpQuery");
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                    writer.Write("<Tr>");
                    writer.Write("<Td>");
                    writer.Write("Select Category");
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                    writer.Write("<Tr>");
                    writer.Write("<Td>");
                    ddlCategory.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                    writer.Write("<Tr>");
                    writer.Write("<Td>");
                    writer.Write("Select Category");
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                    writer.Write("<Tr>");
                    writer.Write("<Td>");
                    chkCategory.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                    writer.Write("<Tr>");
                    writer.Write("<Td>");
                    writer.Write("Select Category");
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                    writer.Write("<Tr>");
                    writer.Write("<Td>");
                    rbCategory.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                    writer.Write("</Table>");
                    #endregion
                }
                else if (Page.Request.Url.ToString().Contains("default.aspx"))
                {
                    #region MyLinks
                    writer.Write("<Table width='100%' style='"+strStyleValign+"'>");
                    writer.Write("<Tr>");
                    writer.Write("<Td>");
                    sgvLinks.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                    writer.Write("</Table>");
                    #endregion
                }
                else if (Page.Request.Url.ToString().Contains("SpGridView Images according to status.aspx"))
                {
                    #region ImagesBasedonstatus
                    writer.Write("<Table width='100%' style='"+strStyleValign+"'>");
                    writer.Write("<Tr>");
                    writer.Write("<Td>");
                    sgvImages.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                    writer.Write("</Table>");
                    #endregion
                }
                else if (Page.Request.Url.ToString().Contains("Current User Tasks.aspx"))
                {
                    #region Current User Tasks                   
                    SPWeb currentWeb = SPControl.GetContextWeb(Context);
                    SPList lstTasks = currentWeb.Lists["Tasks"];
                    if (lstTasks != null)
                    {
                        SPQuery sQuery = new SPQuery();
                        sQuery.Query = "<OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy><Where><Eq><FieldRef Name='AssignedTo' /><Value Type='User'>"+currentWeb.CurrentUser.Name+"</Value></Eq></Where>";
                        //sQuery.Query = "<Query><OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy></Query>";
                        //sQuery.RowLimit = 5;
                        SPListItemCollection tasksList = lstTasks.GetItems(sQuery);
                        //SPListItem item = tasksList.Add();
                        writer.Write("<Table width='100%' style='" + strStyleValign + "'>");
                        if (tasksList.Count > 0)
                        {
                            writer.Write("<Tr>");
                            writer.Write("<Td colspan='3' align='Center'>");
                            writer.Write("<Strong>");
                            writer.Write("<Font color='Red'>");
                            writer.Write("Current User Tasks");
                            writer.Write("</Font>");
                            writer.Write("</Strong>");
                            writer.Write("</Td>");
                            writer.Write("</Tr>");
                            writer.Write("<Tr>");
                            writer.Write("<Td>");
                            writer.Write("Task Name");
                            writer.Write("</Td>");
                            writer.Write("<Td>");
                            writer.Write("Task Status");
                            writer.Write("</Td>");
                            writer.Write("<Td>");
                            writer.Write("Task Priority");
                            writer.Write("</Td>");
                            writer.Write("</Tr>");
                            foreach (SPListItem sQueryItem in tasksList)
                            {
                                string strTitle = string.Empty;
                                strTitle = sQueryItem["Title"].ToString();
                                string strStatus = string.Empty;
                                string strPriority = string.Empty;
                                string strUrl = currentWeb.Url + "/Lists/Tasks/DispForm.aspx?ID=" + sQueryItem.ID + "&source=" + Page.Request.Url;
                                writer.Write("<Tr>");
                                writer.Write("<Td>");
                                writer.Write("<A href='" + strUrl + "'>" + strTitle + "</A>");
                                writer.Write("</Td>");
                                writer.Write("<Td>");
                                if (sQueryItem["Status"] != null)
                                {
                                    strStatus = sQueryItem["Status"].ToString().Substring(sQueryItem["Status"].ToString().LastIndexOf("#") + 1);
                                }
                                else
                                {
                                    strStatus = "--";
                                }
                                writer.Write(strStatus);
                                writer.Write("</Td>");
                                writer.Write("<Td>");
                                if (sQueryItem["Priority"] != null)
                                {
                                    strPriority = sQueryItem["Priority"].ToString().Substring(sQueryItem["Priority"].ToString().LastIndexOf("#") + 1);
                                }
                                else
                                {
                                    strPriority = "--";
                                }
                                writer.Write(strPriority);
                                writer.Write("</Td>");
                                writer.Write("</Tr>");
                            }
                        }
                        else
                        {
                            writer.Write("<Tr>");
                            writer.Write("<Td colspan='3' align='Center'>");
                            writer.Write("There are no Active Tasks");
                            writer.Write("</Td>");
                            writer.Write("</Tr>");
                        }
                    }
                    else
                    {
                        writer.Write("<Tr>");
                        writer.Write("<Td colspan='3' align='Center'>");
                        writer.Write("Taks List Not available");
                        writer.Write("</Td>");
                        writer.Write("</Tr>");
                    }
                    writer.Write("</Table>");
                    #endregion
                }
                else if (Page.Request.Url.ToString().Contains("SpGridView Multiple Row Backcolor.aspx"))
                {
                    #region SpGridView Multiple Row Backcolor
                    writer.Write("<Table width='100%' style='" + strStyleValign + "'>");
                    writer.Write("<Tr>");
                    writer.Write("<Td>");
                    sgvEntireRowBackColor.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                    writer.Write("</Table>");
                    #endregion
                }
                else if (Page.Request.Url.ToString().Contains("SpGridView Single Row Backcolor.aspx"))
                {
                    #region SpGridView Single Row Backcolor
                    writer.Write("<Table width='100%' style='" + strStyleValign + "'>");
                    writer.Write("<Tr>");
                    writer.Write("<Td>");
                    sgvSingleRowBackColor.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                    writer.Write("</Table>");
                    #endregion
                }
                else if (Page.Request.Url.ToString().Contains("Insertion into SharePoint List.aspx"))
                {
                    #region InsertRecord
                    writer.Write("<Table style='"+strStyleValign+"'>");
                    writer.Write("<Tr>");
                    writer.Write("<Td>");
                    writer.Write("Enter UserName");
                    writer.Write("</Td>");
                    writer.Write("<Td>");
                    txtUserName.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("<Td>");
                    rfvUserName.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                    writer.Write("<Tr>");
                    writer.Write("<Td>");
                    writer.Write("Enter PassWord");
                    writer.Write("</Td>");
                    writer.Write("<Td>");
                    txtPassWord.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("<Td>");
                    rfvPassWord.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                    writer.Write("<Tr>");
                    writer.Write("<Td colspan='3' Align='Center'>");
                    btnSave.RenderControl(writer);
                    writer.Write("&nbsp;");
                    btnCancel.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                    writer.Write("</Table>");
                    #endregion
                }
                else if (Page.Request.Url.ToString().Contains("Search With SharePoint List.aspx"))
                {
                    #region SearchRecord
                    writer.Write("<Table style='" + strStyleValign + "'>");
                    writer.Write("<Tr>");
                    writer.Write("<Td>");
                    writer.Write("Enter UserName");
                    writer.Write("</Td>");
                    writer.Write("<Td>");
                    txtUserName.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("<Td>");
                    rfvUserName.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                    writer.Write("<Tr>");
                    writer.Write("<Td>");
                    writer.Write("Enter PassWord");
                    writer.Write("</Td>");
                    writer.Write("<Td>");
                    txtPassWord.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("<Td>");
                    rfvPassWord.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                    writer.Write("<Tr>");
                    writer.Write("<Td colspan='3' Align='Center'>");
                    btnSearch.RenderControl(writer);
                    writer.Write("&nbsp;");
                    btnUpdate.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                    writer.Write("</Table>");
                    #endregion
                }
                else if (Page.Request.Url.ToString().Contains("Delete a Record in SharePoint List.aspx"))
                {
                    #region DeleteRecord
                    writer.Write("<Table style='" + strStyleValign + "'>");
                    writer.Write("<Tr>");
                    writer.Write("<Td>");
                    writer.Write("Enter Respective UserName to Delete");
                    writer.Write("</Td>");
                    writer.Write("<Td>");
                    txtUserName.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("<Td>");
                    rfvUserName.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                    writer.Write("<Tr>");
                    writer.Write("<Td>");
                    btnDelete.RenderControl(writer);
                    writer.Write("&nbsp;");
                    btnDeleteCancel.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                    writer.Write("</Table>");
                    #endregion
                }
                else if (Page.Request.Url.ToString().Contains("Job Information.aspx"))
                {
                    #region JobInformation
                    writer.Write("<Table style='"+strStyleValign+"'>");
                    writer.Write("<Tr>");
                    writer.Write("<Td>");
                    writer.Write("Enter Employee Number");
                    writer.Write("</Td>");
                    writer.Write("<Td>");
                    txtEmpNo.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("<Td>");
                    rfvEmpNo.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                    writer.Write("<Tr>");
                    writer.Write("<Td>");
                    writer.Write("Enter Employee Name");
                    writer.Write("</Td>");
                    writer.Write("<Td>");
                    txtEmpName.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("<Td>");
                    rfvEmpName.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                    writer.Write("<Tr>");
                    writer.Write("<Td>");
                    writer.Write("Enter Employee Age");
                    writer.Write("</Td>");
                    writer.Write("<Td>");
                    txtEmpAge.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("<Td>");
                    rfvEmpAge.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                   
                    writer.Write("<Tr>");
                    writer.Write("<Td>");
                    writer.Write("Select Gender");
                    writer.Write("</Td>");
                    writer.Write("<Td Colspan='2'>");
                    writer.Write("<Table>");
                    writer.Write("<Tr>");
                    writer.Write("<Td>");
                    rbMale.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                    writer.Write("<Tr>");
                    writer.Write("<Td>");
                    rbFemale.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                    writer.Write("</Table>");
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                    writer.Write("<Tr>");
                    writer.Write("<Td>");
                    writer.Write("Select Country");
                    writer.Write("</Td>");
                    writer.Write("<Td>");
                    ddlCountry.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("<Td>");
                    rfvEmpCountry.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                    writer.Write("<Tr>");
                    writer.Write("<Td>");
                    writer.Write("Select State");
                    writer.Write("</Td>");
                    writer.Write("<Td>");
                    ddlState.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("<Td>");
                    rfvEmpState.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                    writer.Write("<Tr>");
                    writer.Write("<Td>");
                    writer.Write("Enter Phone/Mobile Number");
                    writer.Write("</Td>");
                    writer.Write("<Td>");
                    txtEmpPhoneNumber.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("<Td>");
                    rfvEmpPhoneNumber.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                    writer.Write("<Tr>");
                    writer.Write("<Td>");
                    writer.Write("Enter EmailID");
                    writer.Write("</Td>");
                    writer.Write("<Td>");
                    txtEmpEmailID.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("<Td>");
                    rfvEmpEmailID.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                    writer.Write("<Tr>");
                    writer.Write("<Td colspan='3' Align='Center'>");
                    writer.Write("<Table>");
                    writer.Write("<Tr>");
                    writer.Write("<Td>");
                    btnEmpSave.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("<Td>");
                    btnEmpSearch.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("<Td>");
                    btnEmpUpdate.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("<Td>");
                    btnEmpdelete.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                    writer.Write("</Table>");
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                    writer.Write("</Table>");
                    #endregion
                }
                else if (Page.Request.Url.ToString().Contains("Add New Country.aspx"))
                {
                    #region Add New Country
                    writer.Write("<Table style='" + strStyleValign + "'>");
                    writer.Write("<Tr>");
                    writer.Write("<Td>");
                    writer.Write("Add New Country");
                    writer.Write("</Td>");
                    writer.Write("<Td>");
                    txtCountry.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("<Td>");
                    rfvAddCountry.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                    writer.Write("<Tr>");
                    writer.Write("<Td Colspan='3' Align='Center'>");
                    writer.Write("<Table>");
                    writer.Write("<Tr>");
                    writer.Write("<Td>");
                    btnAddCountry.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("<Td>");
                    btnAddCountryCancel.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                    writer.Write("</Table>");
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                    writer.Write("</Table>");
                    #endregion
                }
                else if (Page.Request.Url.ToString().Contains("Add New State.aspx"))
                {
                    #region Add New State
                    writer.Write("<Table style='" + strStyleValign + "'>");
                    writer.Write("<Tr>");
                    writer.Write("<Td>");
                    writer.Write("Select Country");
                    writer.Write("</Td>");
                    writer.Write("<Td>");
                    ddlCountryInStatePage.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("<Td>");
                    rfvCountryInStatePage.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                    writer.Write("<Tr>");
                    writer.Write("<Td>");
                    writer.Write("Enter State");
                    writer.Write("</Td>");
                    writer.Write("<Td>");
                    txtState.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("<Td>");
                    rfvAddState.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                    writer.Write("<Tr>");
                    writer.Write("<Td Align='Center'>");
                    btnAddState.RenderControl(writer);
                    writer.Write("</Td>");
                    writer.Write("</Tr>");
                    writer.Write("</Table>");
                    #endregion
                }
            }
            catch (Exception ex)
            {
                writer.Write(ex.ToString());
            }
        }
        public void clear()
        {
            txtUserName.Text = "";
            txtPassWord.Text = "";
            txtUserName.Focus();
        }
        protected override void CreateChildControls()
        {
            try
            {
                SPWeb currentWeb = SPControl.GetContextWeb(Context);
                if (Page.Request.Url.ToString().Contains("LookUp.aspx"))
                {
                    # region LookUpProgram
                    SPList category = currentWeb.Lists["Category"];
                    //strError += "LookUp1";
                    SPQuery sQuery = new SPQuery();
                    //strError += "LookUp2";
                    sQuery.Query = "<OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy>";
                    //strError += "LookUp3";
                    SPListItemCollection categoryList = category.GetItems(sQuery);
                    //strError += "LookUp4";
                    ddlCategory = new DropDownList();
                    //strError += "LookUp5";
                    ddlCategory.ID = "ddlCategory";
                    //strError += "LookUp6";
                    if (categoryList.Count > 0)
                    {
                        //strError += "LookUp7";
                        foreach (SPListItem sQueryItem in categoryList)
                        {
                            //strError += "LookUp8";
                            ddlCategory.Items.Add(sQueryItem.Title.ToString());
                            //strError += "LookUp9";
                        }
                    }
                    //strError += "LookUp10";
                    this.Controls.Add(ddlCategory);
                    //strError += "LookUp11";
                    ddlCategory.Items.Insert(0, "Select Category");
                    //strError += "LookUp12";
                    chkCategory = new CheckBoxList();
                    //strError += "LookUp13";
                    chkCategory.ID = "chkCategory";
                    //strError += "LookUp14";
                    if (categoryList.Count > 0)
                    {
                        //strError += "LookUp15";
                        foreach (SPListItem sQueryItemCheckBox in categoryList)
                        {
                            //strError += "LookUp16";
                            chkCategory.Items.Add(sQueryItemCheckBox.Title.ToString());
                            //strError += "LookUp17";
                        }
                    }
                    this.Controls.Add(chkCategory);
                    //strError += "LookUp18";
                    rbCategory = new RadioButtonList();
                    //strError += "LookUp19";
                    rbCategory.ID = "rbCategory";
                    //strError += "LookUp20";
                    if (categoryList.Count > 0)
                    {
                        //strError += "LookUp22";
                        foreach (SPListItem sQueryItemRadioButton in categoryList)
                        {
                            //strError += "LookUp23";
                            rbCategory.Items.Add(sQueryItemRadioButton.Title.ToString());
                            //strError += "LookUp24";
                        }
                    }
                    this.Controls.Add(rbCategory);
                    #endregion
                }
              
                if (Page.Request.Url.ToString().Contains("default.aspx"))
                {
                    #region LinksGrid
                    sgvLinks = new SPGridView();
                    sgvLinks.ID = "sgvLinks";
                    sgvLinks.AutoGenerateColumns = false;
                    sgvLinks.Attributes.Add("runat", "server");
                    this.Controls.Add(sgvLinks);
                    BoundField bUrl = new BoundField();
                    bUrl.DataField = "Hyperlink";
                    bUrl.Visible = false;
                    sgvLinks.Columns.Add(bUrl);
                    HyperLinkField HLinkName = new HyperLinkField();
                    HLinkName.DataTextField = "HyperlinkDescription";
                    HLinkName.DataNavigateUrlFields = new string[] { "Hyperlink" };
                    HLinkName.DataNavigateUrlFormatString = "{0}";
                    HLinkName.HeaderText = "Link Name";
                    sgvLinks.Columns.Add(HLinkName);
                    sgvLinks.DataSource = getLinks();
                    sgvLinks.DataBind();
 
                    #endregion
                }
                if (Page.Request.Url.ToString().Contains("SpGridView Images according to status.aspx"))
                {
                    #region ImagesGrid
                    sgvImages = new SPGridView();
                    sgvImages.ID = "sgvImages";
                    sgvImages.AutoGenerateColumns = false;
                    sgvImages.Attributes.Add("runat", "server");
                    sgvImages.RowDataBound += new GridViewRowEventHandler(sgvImages_RowDataBound);
                    //0th index
                    BoundField bUrlImages = new BoundField();
                    bUrlImages.HeaderText = "Url";
                    bUrlImages.DataField = "ImageProgramUrl";
                    bUrlImages.Visible = false;
                    sgvImages.Columns.Add(bUrlImages);
                    //1st index
                    HyperLinkField ImageProgramTaskName = new HyperLinkField();
                    ImageProgramTaskName.DataTextField = "Title";
                    ImageProgramTaskName.DataNavigateUrlFields = new string[] { "ImageProgramUrl" };
                    ImageProgramTaskName.DataNavigateUrlFormatString = "{0}";
                    ImageProgramTaskName.HeaderText = "Task Name";
                    sgvImages.Columns.Add(ImageProgramTaskName);
                    //2nd index
                    BoundField ImageStatus = new BoundField();
                    ImageStatus.DataField = "Status";
                    ImageStatus.HeaderText = "Status";
                    sgvImages.Columns.Add(ImageStatus);
                    //3rd index
                    BoundField ImagePriority = new BoundField();
                    ImagePriority.DataField = "Priority";
                    ImagePriority.HeaderText = "Priority";
                    sgvImages.Columns.Add(ImagePriority);
                    sgvImages.DataSource = getImages();
                    sgvImages.DataBind();
                    this.Controls.Add(sgvImages);

                    #endregion
                }
                if (Page.Request.Url.ToString().Contains("SpGridView Multiple Row Backcolor.aspx"))
                {
                    #region EntireRowBackColor
                    sgvEntireRowBackColor = new SPGridView();
                    sgvEntireRowBackColor.ID = "sgvEntireRowBackColor";
                    sgvEntireRowBackColor.AutoGenerateColumns = false;
                    sgvEntireRowBackColor.Attributes.Add("runat", "server");
                    sgvEntireRowBackColor.RowDataBound += new GridViewRowEventHandler(sgvEntireRowBackColor_RowDataBound);
                    BoundField bUrlEntireRowBackColor = new BoundField();
                    bUrlEntireRowBackColor.HeaderText = "Url";
                    bUrlEntireRowBackColor.DataField = "getBackColorEntireRowUrl";
                    bUrlEntireRowBackColor.Visible = false;
                    sgvEntireRowBackColor.Columns.Add(bUrlEntireRowBackColor);
                    HyperLinkField EntireRowBackColorTaskName = new HyperLinkField();
                    EntireRowBackColorTaskName.DataTextField = "Title";
                    EntireRowBackColorTaskName.DataNavigateUrlFields = new string[] { "getBackColorEntireRowUrl" };
                    EntireRowBackColorTaskName.DataNavigateUrlFormatString = "{0}";
                    EntireRowBackColorTaskName.HeaderText = "Task Name";
                    sgvEntireRowBackColor.Columns.Add(EntireRowBackColorTaskName);
                    BoundField EntireRowBackColorStatus = new BoundField();
                    EntireRowBackColorStatus.DataField = "Status";
                    EntireRowBackColorStatus.HeaderText = "Status";
                    sgvEntireRowBackColor.Columns.Add(EntireRowBackColorStatus);
                    BoundField EntireRowBackColorPriority = new BoundField();
                    EntireRowBackColorPriority.DataField = "Priority";
                    EntireRowBackColorPriority.HeaderText = "Priority";
                    sgvEntireRowBackColor.Columns.Add(EntireRowBackColorPriority);
                    sgvEntireRowBackColor.DataSource = getBackColorEntireRow();
                    sgvEntireRowBackColor.DataBind();
                    this.Controls.Add(sgvEntireRowBackColor);
                    #endregion
                }
                if (Page.Request.Url.ToString().Contains("SpGridView Single Row Backcolor.aspx"))
                {
                    #region SingleRowBackcolor
                    sgvSingleRowBackColor = new SPGridView();
                    sgvSingleRowBackColor.ID = "sgvSingleRowBackColor";
                    sgvSingleRowBackColor.ForeColor = System.Drawing.Color.White;
                    sgvSingleRowBackColor.AutoGenerateColumns = false;
                    sgvSingleRowBackColor.Attributes.Add("runat", "server");
                    sgvSingleRowBackColor.RowDataBound += new GridViewRowEventHandler(sgvSingleRowBackColor_RowDataBound);
                    BoundField bUrlSingleRowBackColor = new BoundField();
                    bUrlSingleRowBackColor.HeaderText = "Url";
                    bUrlSingleRowBackColor.DataField = "getBackColorSingleRowUrl";
                    bUrlSingleRowBackColor.Visible = false;
                    sgvSingleRowBackColor.Columns.Add(bUrlSingleRowBackColor);
                    HyperLinkField SingleRowBackColorTaskName = new HyperLinkField();
                    SingleRowBackColorTaskName.DataTextField = "Title";
                    SingleRowBackColorTaskName.DataNavigateUrlFields = new string[] { "getBackColorSingleRowUrl" };
                    SingleRowBackColorTaskName.DataNavigateUrlFormatString = "{0}";
                    SingleRowBackColorTaskName.HeaderText = "Task Name";
                    sgvSingleRowBackColor.Columns.Add(SingleRowBackColorTaskName);
 
                    BoundField SingleRowBackColorStatus = new BoundField();
                    SingleRowBackColorStatus.DataField = "Status";
                    SingleRowBackColorStatus.HeaderText = "Status";
                    sgvSingleRowBackColor.Columns.Add(SingleRowBackColorStatus);
                    BoundField SingleRowBackColorPriority = new BoundField();
                    SingleRowBackColorPriority.DataField = "Priority";
                    SingleRowBackColorPriority.HeaderText = "Priority";
                    sgvSingleRowBackColor.Columns.Add(SingleRowBackColorPriority);
                    sgvSingleRowBackColor.DataSource = getBackColorSingleRow();
                    sgvSingleRowBackColor.DataBind();
                    this.Controls.Add(sgvSingleRowBackColor);
                    #endregion
                }
                if (Page.Request.Url.ToString().Contains("Insertion into SharePoint List.aspx") || Page.Request.Url.ToString().Contains("Search With SharePoint List.aspx") || Page.Request.Url.ToString().Contains("Delete a Record in SharePoint List.aspx"))
                {
                    #region DDLandDMLOperations
                    txtUserName = new TextBox();
                    txtUserName.ID = "txtUserName";
                    this.Controls.Add(txtUserName);
                    strError += "txtUserName Created";
                    rfvUserName = new RequiredFieldValidator();
                    rfvUserName.ID = "rfvUserName";
                    rfvUserName.ControlToValidate = txtUserName.ID;
                    rfvUserName.ErrorMessage = "UserName Required";
                    this.Controls.Add(rfvUserName);
                    strError += "rfvUserName Created";
                    txtPassWord = new TextBox();
                    txtPassWord.ID = "txtPassWord";
                    this.Controls.Add(txtPassWord);
                    strError += "txtPassWord Created";
                    rfvPassWord = new RequiredFieldValidator();
                    rfvPassWord.ID = "rfvPassWord";
                    rfvPassWord.ControlToValidate = txtPassWord.ID;
                    rfvPassWord.ErrorMessage = "PassWord Required";
                    this.Controls.Add(rfvPassWord);
                    strError += "rfvPassWord Created";
                    btnSave = new Button();
                    btnSave.ID = "btnSave";
                    btnSave.Text = "Save Record";
                    btnSave.Click += new EventHandler(btnSave_Click);
                    this.Controls.Add(btnSave);
                    strError += "btnSave Created";
                    btnCancel = new Button();
                    btnCancel.ID = "btnCancel";
                    btnCancel.CausesValidation = false;
                    btnCancel.Text = "Cancel";
                    btnCancel.Click += new EventHandler(btnCancel_Click);
                    this.Controls.Add(btnCancel);
                    strError += "btnCancel Created";
                    btnSearch = new Button();
                    btnSearch.ID = "btnSearch";
                    btnSearch.Text = "Search Record";
                    btnSearch.CausesValidation = false;
                    btnSearch.Click += new EventHandler(btnSearch_Click);
                    this.Controls.Add(btnSearch);
                    strError += "btnSearch Created";
                    btnUpdate = new Button();
                    btnUpdate.ID = "btnUpdate";
                    btnUpdate.Text = "Update Record";
                    btnUpdate.Click += new EventHandler(btnUpdate_Click);
                    this.Controls.Add(btnUpdate);
                    strError += "btnUpdate Created";
                    btnDelete = new Button();
                    btnDelete.ID = "btnDelete";
                    btnDelete.Text = "Delete Record";
                    btnDelete.Click += new EventHandler(btnDelete_Click);
                    this.Controls.Add(btnDelete);
                    strError += "btnDelete Created";
                    btnDeleteCancel = new Button();
                    btnDeleteCancel.ID = "btnCancel";
                    btnDeleteCancel.Text = "Cancel";
                    btnDeleteCancel.CausesValidation = false;
                    btnDeleteCancel.Click += new EventHandler(btnDeleteCancel_Click);
                    this.Controls.Add(btnDeleteCancel);
                    strError += "btnDeleteCancel Created";
                    #endregion
                }
                if (Page.Request.Url.ToString().Contains(" Job Information.aspx"))
                {
                    #region EmpInfo
                    txtEmpNo = new TextBox();
                    txtEmpNo.ID = "txtEmpNo";
                    this.Controls.Add(txtEmpNo);
                    //strError += "txtEmpNo";
                    rfvEmpNo = new RequiredFieldValidator();
                    rfvEmpNo.ID = "rfvEmpNo";
                    rfvEmpNo.ControlToValidate = txtEmpNo.ID;
                    rfvEmpNo.ErrorMessage = "Please enter Employee number";
                    this.Controls.Add(rfvEmpNo);
                    txtEmpName = new TextBox();
                    txtEmpName.ID = "txtEmpName";
                    this.Controls.Add(txtEmpName);
                    //strError += "txtEmpName";
                    txtEmpAge = new TextBox();
                    txtEmpAge.ID = "txtEmpAge";
                    this.Controls.Add(txtEmpAge);
                    strError += "txtEmpAge";
                    txtEmpPhoneNumber = new TextBox();
                    txtEmpPhoneNumber.ID = "txtEmpPhoneNumber";
                    this.Controls.Add(txtEmpPhoneNumber);
                    strError += "txtEmpPhoneNumber";
                    txtEmpEmailID = new TextBox();
                    txtEmpEmailID.ID = "txtEmpEmailID";
                    this.Controls.Add(txtEmpEmailID);
                    strError += "txtEmpEmailID";
                    ddlCountry = new DropDownList();
                    ddlCountry.ID = "ddlCountry";
                    ddlCountry.AutoPostBack = true;
                    SPList CountryList = currentWeb.Lists["Country"];
                    SPQuery sCountryQuery = new SPQuery();
                    sCountryQuery.Query = "<OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy>";
                    SPListItemCollection CountryCollection = CountryList.GetItems(sCountryQuery);
                    if (CountryCollection.Count > 0)
                    {
                        foreach (SPListItem sCountryQueryItem in CountryCollection)
                        {
                            ddlCountry.Items.Add(sCountryQueryItem.Title.ToString());
                        }
                    }
                    ddlCountry.SelectedIndexChanged += new EventHandler(ddlCountry_SelectedIndexChanged);
                    this.Controls.Add(ddlCountry);
                    //ddlCountry.Items.Insert(0, new ListItem("Select Country"));
                    ddlCountry.Items.Insert(0, new ListItem("Select Country", "0"));
                    strError += "ddlCountry";
                    ddlState = new DropDownList();
                    ddlState.ID = "ddlState";
                    SPList StateList = currentWeb.Lists["States"];
                    SPQuery sStateQuery = new SPQuery();
                    sStateQuery.Query = "<OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy>";
                    SPListItemCollection StateCollection = StateList.GetItems(sStateQuery);
                    if (StateCollection.Count > 0)
                    {
                        foreach (SPListItem sStateQueryItem in StateCollection)
                        {
                            ddlState.Items.Add(sStateQueryItem.Title.ToString());
                        }
                    }
                    this.Controls.Add(ddlState);
                    //ddlState.Items.Insert(0, new ListItem("Select State"));
                    ddlState.Items.Insert(0, new ListItem("Select State", "0"));
                    strError += "ddlState";
                    ddlCountryInStatePage = new DropDownList();
                    ddlCountryInStatePage.ID = "ddlCountryInStatePage";
                    SPList CountryListinDifferentPage = currentWeb.Lists["Country"];
                    SPQuery sQueryCountryInStatePage = new SPQuery();
                    sQueryCountryInStatePage.Query = "<OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy>";
                    SPListItemCollection CountryInStatePageCollection = CountryListinDifferentPage.GetItems(sQueryCountryInStatePage);
                    if (CountryInStatePageCollection.Count > 0)
                    {
                        foreach (SPListItem sCountryInStatePageItem in CountryInStatePageCollection)
                        {
                            ddlCountryInStatePage.Items.Add(sCountryInStatePageItem.Title.ToString());
                        }
                    }
                    this.Controls.Add(ddlCountryInStatePage);
                    //ddlCountryInStatePage.Items.Insert(0, new ListItem("Select Country"));
                    ddlCountryInStatePage.Items.Insert(0, new ListItem("Select Country", "0"));
                    rfvEmpName = new RequiredFieldValidator();
                    rfvEmpName.ID = "rfvEmpName";
                    rfvEmpName.ControlToValidate = txtEmpName.ID;
                    rfvEmpName.ErrorMessage = "Employee ID Required";
                    this.Controls.Add(rfvEmpName);
                    rfvEmpPhoneNumber = new RequiredFieldValidator();
                    rfvEmpPhoneNumber.ID = "rfvEmpPhoneNumber";
                    rfvEmpPhoneNumber.ControlToValidate = txtEmpPhoneNumber.ID;
                    rfvEmpPhoneNumber.ErrorMessage = "Employee Phone/Mobile Number Required.";
                    this.Controls.Add(rfvEmpPhoneNumber);
                    rfvEmpAge = new RequiredFieldValidator();
                    rfvEmpAge.ID = "rfvEmpAge";
                    rfvEmpAge.ControlToValidate = txtEmpAge.ID;
                    rfvEmpAge.ErrorMessage = "Employee Age Required";
                    this.Controls.Add(rfvEmpAge);
                    rfvEmpEmailID = new RequiredFieldValidator();
                    rfvEmpEmailID.ID = "rfvEmpEmailID";
                    rfvEmpEmailID.ControlToValidate = txtEmpEmailID.ID;
                    rfvEmpEmailID.ErrorMessage = "Employee EmailID Required.";
                    this.Controls.Add(rfvEmpEmailID);
                    rfvEmpCountry = new RequiredFieldValidator();
                    rfvEmpCountry.ID = "rfvEmpCountry";
                    rfvEmpCountry.ControlToValidate = ddlCountry.ID;
                    rfvEmpCountry.InitialValue = "Select Country";
                    rfvEmpCountry.ErrorMessage = "Country Required";
                    this.Controls.Add(rfvEmpCountry);
                    rfvEmpState = new RequiredFieldValidator();
                    rfvEmpState.ID = "rfvEmpState";
                    rfvEmpState.ControlToValidate = ddlState.ID;
                    rfvEmpState.InitialValue = "Select State";
                    rfvEmpState.ErrorMessage = "State Required";
                    this.Controls.Add(rfvEmpState);
                    rbMale = new RadioButton();
                    rbMale.ID = "rbMale";
                    rbMale.Text = "Male";
                    rbMale.Checked = true;
                    rbMale.GroupName = "Gender";
                    this.Controls.Add(rbMale);
 

                    rbFemale = new RadioButton();
                    rbFemale.ID = "rbFemale";
                    rbFemale.Text = "Female";
                    rbFemale.GroupName = "Gender";
                    this.Controls.Add(rbFemale);
                    btnEmpSave = new Button();
                    btnEmpSave.ID = "btnEmpSave";
                    btnEmpSave.Text = "Save Record";
                    btnEmpSave.Click += new EventHandler(btnEmpSave_Click);
                    this.Controls.Add(btnSave);
                    btnEmpSearch = new Button();
                    btnEmpSearch.ID = "btnEmpSearch";
                    btnEmpSearch.Text = "Search Record";
                    btnEmpSearch.CausesValidation = false;
                    btnEmpSearch.Click += new EventHandler(btnEmpSearch_Click);
                    this.Controls.Add(btnEmpSearch);
                    btnEmpUpdate = new Button();
                    btnEmpUpdate.ID = "btnEmpUpdate";
                    btnEmpUpdate.Text = "Update Record";
                    btnEmpUpdate.Click += new EventHandler(btnEmpUpdate_Click);
                    this.Controls.Add(btnEmpUpdate);
                    btnEmpdelete = new Button();
                    btnEmpdelete.ID = "btnEmpdelete";
                    btnEmpdelete.Text = "Delete Record";
                    btnEmpdelete.Click += new EventHandler(btnEmpdelete_Click);
                    this.Controls.Add(btnEmpdelete);

                    btnEmpCancel = new Button();
                    btnEmpCancel.ID = "btnEmpCancel";
                    btnEmpCancel.Text = "Cancel";
                    btnEmpCancel.Click += new EventHandler(btnEmpCancel_Click);
                    this.Controls.Add(btnEmpCancel);
                    btnAddCountry = new Button();
                    btnAddCountry.ID = "btnAddCountry";
                    btnAddCountry.Text = "Add New Country";
                    btnAddCountry.Click += new EventHandler(btnAddCountry_Click);
                    this.Controls.Add(btnAddCountry);
                    btnAddCountryCancel = new Button();
                    btnAddCountryCancel.ID = "btnAddCountryCancel";
                    btnAddCountryCancel.Text = "Cancel";
                    btnAddCountryCancel.Click += new EventHandler(btnAddCountryCancel_Click);
                    this.Controls.Add(btnAddCountryCancel);
                    btnAddState = new Button();
                    btnAddState.ID = "btnAddState";
                    btnAddState.Text = "Save Record";
                    btnAddState.Click += new EventHandler(btnAddState_Click);
                    this.Controls.Add(btnAddState);
                    txtCountry = new TextBox();
                    txtCountry.ID = "txtCountry";
                    this.Controls.Add(txtCountry);
                    txtState = new TextBox();
                    txtState.ID = "txtState";
                    this.Controls.Add(txtState);
                    rfvAddCountry = new RequiredFieldValidator();
                    rfvAddCountry.ID = "rfvAddCountry";
                    rfvAddCountry.ControlToValidate = txtCountry.ID;
                    rfvAddCountry.ErrorMessage = "Country Required";
                    this.Controls.Add(rfvAddCountry);
                    rfvAddState = new RequiredFieldValidator();
                    rfvAddState.ID = "rfvAddState";
                    rfvAddState.ControlToValidate = txtState.ID;
                    rfvAddState.ErrorMessage = "State Required";
                    this.Controls.Add(rfvAddState);
                    rfvCountryInStatePage = new RequiredFieldValidator();
                    rfvCountryInStatePage.ID = "rfvCountryInStatePage";
                    rfvCountryInStatePage.ControlToValidate = ddlCountryInStatePage.ID;
                    rfvCountryInStatePage.InitialValue = "Select Country";
                    rfvCountryInStatePage.ErrorMessage = "Country Required";
                    this.Controls.Add(rfvCountryInStatePage);
                    #endregion
                }
               
            }
            catch (Exception ex)
            {
                strError += ex.ToString();
            }
        }
        void btnAddState_Click(object sender, EventArgs e)
        {
            try
            {
                SPWeb currentWeb = SPControl.GetContextWeb(Context);
                SPList StatesList = currentWeb.Lists["States"];
                SPListItemCollection myColl = StatesList.Items;
                SPListItem item = myColl.Add();
                item["Title"] = txtState.Text;
                item["Country"] = ddlCountryInStatePage.SelectedItem.Value;
                item.Update();
                Page.Response.Redirect(currentWeb.Url + "/UserPages/Add New State.aspx");
            }
            catch (Exception ex)
            {
                strError += ex.ToString();
            }
        }
        void btnEmpUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                SPWeb currentWeb = SPControl.GetContextWeb(Context);
                SPList EmployeeList = currentWeb.Lists["Employee Details"];
                SPListItemCollection mycoll = EmployeeList.Items;
                foreach (SPListItem item in mycoll)
                {
                    if (item["Title"].ToString() == txtEmpNo.Text)
                    {
                        item["EmployeeCountry"] = ddlCountry.SelectedValue.ToString();
                        item["EmployeeState"] = ddlState.SelectedValue.ToString();
                        item["EmployeeName"] = txtEmpName.Text;
                        item["EmployeeAge"] = txtEmpAge.Text;
                        item["EmployeePhoneNumber"] = txtEmpPhoneNumber.Text;
                        item["EmployeeEmailID"] = txtEmpEmailID.Text;
                        if (rbMale.Checked == true)
                        {
                            item["Gender"] = "Male";
                        }
                        else
                        {
                            item["Gender"] = "Female";
                        }
                        strError += "Item Updated Successfully";
                        break;
                    }
                }
                Page.Response.Redirect(currentWeb.Url + "/UserPages/Job Information.aspx");
            }
            catch (Exception ex)
            {
                strError += ex.ToString();
            }
        }
        void btnAddCountryCancel_Click(object sender, EventArgs e)
        {
            try
            {
                SPWeb currentWeb = SPControl.GetContextWeb(Context);
                Page.Response.Redirect(currentWeb.Url + "/UserPages/Add New Country.aspx");
            }
            catch (Exception ex)
            {
                strError += ex.ToString();
            }
        }
        void btnAddCountry_Click(object sender, EventArgs e)
        {
            try
            {
                SPWeb currentWeb = SPControl.GetContextWeb(Context);
                SPList CountryList = currentWeb.Lists["Country"];
                SPListItemCollection mycoll = CountryList.Items;
                SPListItem item = mycoll.Add();
                item["Title"] = txtCountry.Text;
                item.Update();
                string strMessage = txtCountry.Text + " Added Successfully to Country List";
                strError += strMessage;
                txtCountry.Text = "";
            }
            catch (Exception ex)
            {
                strError += ex.ToString();
            }
        }
        void ddlCountry_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                ddlState.Items.Clear();
                SPWeb currentWeb = SPControl.GetContextWeb(Context);
                SPList StatesList = currentWeb.Lists["States"];
                SPQuery sFilterStates = new SPQuery();
                sFilterStates.Query = "<Where><Eq><FieldRef Name='Country' /><Value Type='Lookup'>"+ddlCountry.SelectedItem.Value+"</Value></Eq></Where>";
                SPListItemCollection statesColl = StatesList.GetItems(sFilterStates);
                foreach (SPListItem statesItem in statesColl)
                {
                    if (statesItem["Country"].ToString() == ddlCountry.SelectedItem.Value.ToString())
                    {
                        ddlState.Items.Add(statesItem.Title.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                strError += ex.ToString();
            }
        }
        void btnEmpCancel_Click(object sender, EventArgs e)
        {
            try
            {
               
            }
            catch (Exception ex)
            {
                strError += ex.ToString();
            }
        }
        void btnEmpdelete_Click(object sender, EventArgs e)
        {
            try
            {
                SPWeb currentWeb = SPControl.GetContextWeb(Context);
                SPList EmployeeList = currentWeb.Lists["Employee Details"];
                SPListItemCollection myColl = EmployeeList.Items;
                foreach (SPListItem item in myColl)
                {
                    if (item["Title"].ToString() == txtEmpNo.Text)
                    {
                        item.Delete();
                        Page.Response.Redirect(currentWeb.Url + "/UserPages/Job%20Information.aspx");
                    }
                }
            }
            catch (Exception ex)
            {
                strError += ex.ToString();
            }
        }
        void btnEmpSearch_Click(object sender, EventArgs e)
        {
            try
            {
                SPWeb currentWeb = SPControl.GetContextWeb(Context);
                SPList EmployeeList = currentWeb.Lists["Employee Details"];
                SPQuery sQuery = new SPQuery();
                sQuery.Query = "";
                SPListItemCollection EmployeeColl = EmployeeList.GetItems(sQuery);
                foreach (SPListItem sQueryItem in EmployeeColl)
                {
                    if (sQueryItem["Title"].ToString().ToLower() == txtEmpNo.Text.ToString().ToLower())
                    {
                        txtEmpName.Text = sQueryItem["EmployeeName"].ToString();
                        txtEmpAge.Text = sQueryItem["EmployeeAge"].ToString();
                        txtEmpPhoneNumber.Text = sQueryItem["EmployeePhoneNumber"].ToString();
                        txtEmpEmailID.Text = sQueryItem["EmployeeEmailID"].ToString();
                        if(sQueryItem["Gender"].ToString().Trim().ToLower()  == "Male".ToLower())
                        {
                            rbMale.Checked = true;
                        }
                        else
                        {
                            rbFemale.Checked = true;
                        }
                        ddlCountry.Text = sQueryItem["EmployeeCountry"].ToString();
                        ddlState.Text = sQueryItem["EmployeeState"].ToString();
                        strError += "Record Found";
                    }
                }
            }
            catch (Exception ex)
            {
                strError += ex.ToString();
            }
        }
        void btnEmpSave_Click(object sender, EventArgs e)
        {
            try
            {
                SPWeb currentWeb = SPControl.GetContextWeb(Context);
                SPList EmployeeList = currentWeb.Lists["Employee Details"];
                SPListItemCollection mycoll = EmployeeList.Items;
                SPListItem item = mycoll.Add();
                item["Title"] = txtEmpNo.Text;
                item["EmployeeName"] = txtEmpName.Text;
                item["EmployeeAge"] = txtEmpAge.Text;
                item["EmployeeCountry"] = ddlCountry.SelectedItem.Value.ToString();
                item["EmployeeState"] = ddlState.SelectedItem.Value.ToString();
                item["EmployeePhoneNumber"] = txtEmpPhoneNumber.Text;
                item["EmployeeEmailID"] = txtEmpEmailID.Text;
                if (rbMale.Checked)
                {
                    item["Gender"] = "Male";
                }
                else
                {
                    item["Gender"] = "Female";
                }
                item.Update();
                //strError += "Employee Info Inserted Successfully";
                Page.Response.Redirect(currentWeb.Url + "/UserPages/Job%20Information.aspx");
            }
            catch (Exception ex)
            {
                strError += ex.ToString();
            }
        }
        void btnDeleteCancel_Click(object sender, EventArgs e)
        {
            try
            {
                txtUserName.Text = "";
                txtUserName.Focus();
            }
            catch (Exception ex)
            {
                strError += ex.ToString();
            }
        }
        void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                SPWeb currentWeb = SPControl.GetContextWeb(Context);
                SPList LoginList = currentWeb.Lists["Login"];
                SPListItemCollection myColl = LoginList.Items;
                foreach (SPListItem item in myColl)
                {
                    if (item["Title"].ToString() == txtUserName.Text)
                    {
                        item.Delete();
                        txtUserName.Text = "";
                        break;
                    }
                }
                strError += "Record deleted successfully";
            }
            catch (Exception ex)
            {
                strError += ex.ToString();
            }
        }
        void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                SPWeb currentWeb = SPControl.GetContextWeb(Context);
                SPList LoginList = currentWeb.Lists["Login"];
                SPListItemCollection mycoll = LoginList.Items;
                foreach (SPListItem item in mycoll)
                {
                    if (item["Title"].ToString() == txtUserName.Text)
                    {
                        item["Password"] = txtPassWord.Text;
                        strError += "Record Updation Successful";
                        clear();
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                strError += ex.ToString();
            }
        }
        void btnSearch_Click(object sender, EventArgs e)
        {
            try
            {
                SPWeb currentWeb = SPControl.GetContextWeb(Context);
                SPList LoginList = currentWeb.Lists["Login"];
                SPQuery sQuery = new SPQuery();
                sQuery.Query = "<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>"+txtUserName.Text+"</Value></Eq></Where>";
                SPListItemCollection myColl = LoginList.GetItems(sQuery);
                foreach (SPListItem sQueryItem in myColl)
                {
                    if (sQueryItem["Title"].ToString() == txtUserName.ToString())
                    {
                        txtPassWord.Text = sQueryItem["Password"].ToString();
                        strError += "Record Found " +txtUserName.Text;
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                strError += ex.ToString();
            }
        }
        void btnCancel_Click(object sender, EventArgs e)
        {
            try
            {
                clear();
            }
            catch (Exception ex)
            {
                strError += ex.ToString();
            }
        }
        void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                SPWeb currentWeb = SPControl.GetContextWeb(Context);
                SPList LoginList = currentWeb.Lists["Login"];
                SPListItemCollection mycoll = LoginList.Items;
                SPListItem item = mycoll.Add();
                item["Title"] = txtUserName.Text;
                item["Password"] = txtPassWord.Text;
                item.Update();
                clear();
                strError += "Record Insertion Successful";
            }
            catch (Exception ex)
            {
                strError += ex.ToString();
            }
        }
        void sgvSingleRowBackColor_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            try
            {
                if (e.Row.Cells[2].Text == "In Progress")
                {
                    e.Row.Cells[2].BackColor = System.Drawing.Color.Orange;
                    e.Row.Cells[2].ForeColor = System.Drawing.Color.White;
                }
                else if (e.Row.Cells[2].Text == "Not Started")
                {
                    e.Row.Cells[2].BackColor = System.Drawing.Color.Red;
                    e.Row.Cells[2].ForeColor = System.Drawing.Color.White;
                }
                else if (e.Row.Cells[2].Text == "Deferred")
                {
                    e.Row.Cells[2].BackColor = System.Drawing.Color.SkyBlue;
                    e.Row.Cells[2].ForeColor = System.Drawing.Color.White;
                }
                else if (e.Row.Cells[2].Text == "Completed")
                {
                    e.Row.Cells[2].BackColor = System.Drawing.Color.Green;
                    e.Row.Cells[2].ForeColor = System.Drawing.Color.White;
                }
                else if (e.Row.Cells[2].Text == "Waiting on someone else")
                {
                    e.Row.Cells[2].BackColor = System.Drawing.Color.Yellow;
                    e.Row.Cells[2].ForeColor = System.Drawing.Color.White;
                }
            }
            catch (Exception ex)
            {
                strError += ex.ToString();
            }
        }
        void sgvEntireRowBackColor_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            try
            {
                if (e.Row.Cells[2].Text == "In Progress")
                {
                    e.Row.BackColor = System.Drawing.Color.Orange;
                    e.Row.ForeColor = System.Drawing.Color.White;
                }
                else if (e.Row.Cells[2].Text == "Not Started")
                {
                    e.Row.BackColor = System.Drawing.Color.Red;
                    e.Row.ForeColor = System.Drawing.Color.White;
                }
                else if (e.Row.Cells[2].Text == "Deferred")
                {
                    e.Row.BackColor = System.Drawing.Color.SkyBlue;
                    e.Row.ForeColor = System.Drawing.Color.White;
                }
                else if (e.Row.Cells[2].Text == "Completed")
                {
                    e.Row.BackColor = System.Drawing.Color.Green;
                    e.Row.ForeColor = System.Drawing.Color.White;
                }
                else if (e.Row.Cells[2].Text == "Waiting on someone else")
                {
                    e.Row.BackColor = System.Drawing.Color.Yellow;
                    e.Row.ForeColor = System.Drawing.Color.White;
                }
            }
            catch (Exception ex)
            {
                strError += ex.ToString();
            }
        }
        void sgvImages_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            try
            {
                SPWeb currentWeb = SPControl.GetContextWeb(Context);
                string strImageUrl=string.Empty;
                if (e.Row.Cells[2].Text == "In Progress")
                {
                    strImageUrl = currentWeb.Url + "/UserPages/Images/In Progress.Jpg";
                    e.Row.Cells[2].Text = "<Img src='"+strImageUrl+"' height='20' width='20' Alt='In Progress' border='0' />";
                }
                else if (e.Row.Cells[2].Text == "Not Started")
                {
                    strImageUrl = currentWeb.Url + "/UserPages/Images/Not Started.Jpg";
                    e.Row.Cells[2].Text = "<Img src='" + strImageUrl + "' height='20' width='20' Alt='Not Started' border='0' />";
                }
                else if (e.Row.Cells[2].Text == "Deferred")
                {
                    strImageUrl = currentWeb.Url + "/UserPages/Images/Deferred.Jpg";
                    e.Row.Cells[2].Text = "<Img src='" + strImageUrl + "' height='20' width='20' Alt='Deferred' border='0' />";
                }
                else if (e.Row.Cells[2].Text == "Completed")
                {
                    strImageUrl = currentWeb.Url + "/UserPages/Images/Completed.Jpg";
                    e.Row.Cells[2].Text = "<Img src='" + strImageUrl + "' height='20' width='20' Alt='Completed' border='0' />";
                }
                else if (e.Row.Cells[2].Text == "Waiting on someone else")
                {
                    strImageUrl = currentWeb.Url + "/UserPages/Images/Waiting on someone else.Jpg";
                    e.Row.Cells[2].Text = "<Img src='" + strImageUrl + "' height='20' width='20' Alt='Waiting on someone else' border='0' />";
                }
            }
            catch (Exception ex)
            {
                strError+=ex.ToString();
            }
        }
        public DataSet getBackColorSingleRow()
        {
            try
            {
                dtSingleRowBackColor.Columns.Add("getBackColorSingleRowUrl");
                dtSingleRowBackColor.Columns.Add("Title");
                dtSingleRowBackColor.Columns.Add("Status");
                dtSingleRowBackColor.Columns.Add("Priority");
                string strTitle = string.Empty;
                string strStatus = string.Empty;
                string strPriority = string.Empty;
                string strUrl = string.Empty;
                SPWeb currentWeb = SPControl.GetContextWeb(Context);
                SPList tasksList = currentWeb.Lists["Tasks"];
                SPQuery sQuery = new SPQuery();
                sQuery.Query = "<OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy>";
                SPListItemCollection SingleRowBackcolorTasksColl = tasksList.GetItems(sQuery);
                if (tasksList != null)
                {
                    if (SingleRowBackcolorTasksColl.Count > 0)
                    {
                        foreach (SPListItem SingleRowBackcolorItem in SingleRowBackcolorTasksColl)
                        {
                            strUrl = currentWeb.Url + "/Lists/Tasks/DispForm.aspx?ID=" + SingleRowBackcolorItem.ID + "&Source=" + Page.Request.Url;
                            strTitle = SingleRowBackcolorItem.Title.ToString();
                            if (SingleRowBackcolorItem["Status"] != null)
                            {
                                strStatus = SingleRowBackcolorItem["Status"].ToString();
                                strStatus = strStatus.Substring(strStatus.LastIndexOf("#") + 1);
                            }
                            else
                            {
                                strStatus = "--";
                            }
                            if (SingleRowBackcolorItem["Priority"] != null)
                            {
                                strPriority = SingleRowBackcolorItem["Priority"].ToString();
                                strPriority = strPriority.Substring(strPriority.LastIndexOf("#") + 1);
                            }
                            else
                            {
                                strPriority = "--";
                            }
                            DataRow drow = dtSingleRowBackColor.NewRow();
                            drow["getBackColorSingleRowUrl"] = strUrl;
                            drow["Title"] = strTitle;
                            drow["Status"] = strStatus;
                            drow["Priority"] = strPriority;
                            dtSingleRowBackColor.Rows.Add(drow);
                        }
                       
                    }
                }
                dsetSingleRowBackColor.Tables.Clear();
                dsetSingleRowBackColor.Tables.Add(dtSingleRowBackColor);
                return dsetSingleRowBackColor;
            }
            catch (Exception ex)
            {
                strError += ex.ToString();
                return null;
            }
        }
        public DataSet getBackColorEntireRow()
        {
            try
            {
                dtEntireRowBackcolor.Columns.Add("getBackColorEntireRowUrl");
                dtEntireRowBackcolor.Columns.Add("Title");
                dtEntireRowBackcolor.Columns.Add("Status");
                dtEntireRowBackcolor.Columns.Add("Priority");
                string strTitle = string.Empty;
                string strStatus = string.Empty;
                string strPriority = string.Empty;
                string strUrl = string.Empty;
                SPWeb currentWeb = SPControl.GetContextWeb(Context);
                SPList tasksList = currentWeb.Lists["Tasks"];
                SPQuery sQuery = new SPQuery();
                sQuery.Query = "<OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy>";
                SPListItemCollection EntireRowBackcolorTasksColl = tasksList.GetItems(sQuery);
                if (tasksList != null)
                {
                    if (EntireRowBackcolorTasksColl.Count > 0)
                    {
                        foreach (SPListItem EntireRowBackcolorItem in EntireRowBackcolorTasksColl)
                        {
                          
                            strUrl = currentWeb.Url + "/Lists/Tasks/DispForm.aspx?ID=" + EntireRowBackcolorItem.ID + "&Source=" + Page.Request.Url;
                            strTitle = EntireRowBackcolorItem.Title.ToString();
                            if (EntireRowBackcolorItem["Status"] != null)
                            {
                                strStatus = EntireRowBackcolorItem["Status"].ToString();
                                strStatus = strStatus.Substring(strStatus.LastIndexOf("#") + 1);
                            }
                            else
                            {
                                strStatus = "--";
                            }
                            if (EntireRowBackcolorItem["Priority"] != null)
                            {
                                strPriority = EntireRowBackcolorItem["Priority"].ToString();
                                strPriority = strPriority.Substring(strPriority.LastIndexOf("#") + 1);
                            }
                            else
                            {
                                strPriority = "--";
                            }
                            DataRow drow = dtEntireRowBackcolor.NewRow();
                            drow["getBackColorEntireRowUrl"] = strUrl;
                            drow["Title"] = strTitle;
                            drow["Status"] = strStatus;
                            drow["Priority"] = strPriority;
                            dtEntireRowBackcolor.Rows.Add(drow);
                        }
                       
                    }
                }
                dsetEntireRowBackcolor.Tables.Clear();
                dsetEntireRowBackcolor.Tables.Add(dtEntireRowBackcolor);
                return dsetEntireRowBackcolor;
            }
            catch (Exception ex)
            {
                strError += ex.ToString();
                return null;
            }
        }
        public DataSet getImages()
        {
            try
            {
                dtImages.Columns.Add("ImageProgramUrl");
                dtImages.Columns.Add("Title");
                dtImages.Columns.Add("Status");
                dtImages.Columns.Add("Priority");
                string strTitle = string.Empty;
                string strStatus = string.Empty;
                string strPriority = string.Empty;
                string strUrl = string.Empty;
                SPWeb currentWeb = SPControl.GetContextWeb(Context);
                SPList tasksList = currentWeb.Lists["Tasks"];
                SPQuery sQuery = new SPQuery();
                sQuery.Query = "<OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy>";
                SPListItemCollection imageTasksColl = tasksList.GetItems(sQuery);
                if (tasksList != null)
                {
                    if (imageTasksColl.Count > 0)
                    {
                        foreach (SPListItem imageItem in imageTasksColl)
                        {
                            strUrl = currentWeb.Url + "/Lists/Tasks/DispForm.aspx?ID=" + imageItem.ID + "&Source=" + Page.Request.Url;
                            strTitle = imageItem.Title.ToString();
                            if (imageItem["Status"] != null)
                            {
                                strStatus = imageItem["Status"].ToString();
                                strStatus = strStatus.Substring(strStatus.LastIndexOf("#") + 1);
                            }
                            else
                            {
                                strStatus = "--";
                            }
                            if (imageItem["Priority"] != null)
                            {
                                strPriority = imageItem["Priority"].ToString();
                                strPriority = strPriority.Substring(strPriority.LastIndexOf("#") + 1);
                            }
                            else
                            {
                                strPriority = "--";
                            }
                            DataRow drow = dtImages.NewRow();
                            drow["ImageProgramUrl"] = strUrl;
                            drow["Title"] = strTitle;
                            drow["Status"] = strStatus;
                            drow["Priority"] = strPriority;
                            dtImages.Rows.Add(drow);
                        }
                       
                    }
                }
                dsetImages.Tables.Clear();
                dsetImages.Tables.Add(dtImages);
                return dsetImages;
            }
            catch (Exception ex)
            {
                strError += ex.ToString();
                return null;
            }
        }
        public DataSet getLinks()
        {
            try
            {
                dtLinks.Columns.Add("Hyperlink");
                dtLinks.Columns.Add("HyperlinkDescription");
                string strHyperlink = string.Empty;
                string strHyperlinkDescription = string.Empty;
                SPWeb currentWeb = SPControl.GetContextWeb(Context);
                SPList LinksList = currentWeb.Lists["My Program Links"];
                SPQuery sQuery = new SPQuery();
                sQuery.Query = "<OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy>";
                SPListItemCollection LinksListCollection = LinksList.GetItems(sQuery);
                if (LinksList != null)
                {
                    if (LinksListCollection.Count > 0)
                    {
                        foreach (SPListItem linkItem in LinksListCollection)
                        {
                            string strResultFromDataBase = string.Empty;
                            strResultFromDataBase = linkItem["URL"].ToString();
                            strHyperlink = strResultFromDataBase.Substring(0, strResultFromDataBase.IndexOf(','));
                            strHyperlinkDescription = strResultFromDataBase.Substring(strResultFromDataBase.IndexOf(',')+1);
                            DataRow drow = dtLinks.NewRow();
                            drow["Hyperlink"] = strHyperlink;
                            drow["HyperlinkDescription"] = strHyperlinkDescription;
                            dtLinks.Rows.Add(drow);
                        }
                       
                    }
                }
                dsetLinks.Tables.Clear();
                dsetLinks.Tables.Add(dtLinks);
                return dsetLinks;
            }
            catch (Exception ex)
            {
                strError += ex.ToString();
                return null;
            }
        }
    }
 
}

No comments:

Post a Comment