Exemple #1
0
        public static bool UpdateUserInformation(staffinfo stf)
        {
            bool updateresult = false;
            int rowsAffected = 0;
            SqlConnection myconn = null;
            try
            {
                myconn = new SqlConnection();
                SqlCommand comm = new SqlCommand();
                myconn.ConnectionString = connectionString;
                myconn.Open();
                comm.Connection = myconn;

                comm.CommandText = "Update StaffInfo set Section=@sect, Designation=@desig, Functions=@funct, Role=@role where UserID=@uid";
                comm.Parameters.AddWithValue("@uid", stf.Uid);
                comm.Parameters.AddWithValue("@sect", stf.Section);
                comm.Parameters.AddWithValue("@desig", stf.Designation);
                comm.Parameters.AddWithValue("@funct", stf.Function);
                comm.Parameters.AddWithValue("@role", stf.Role);
                rowsAffected = comm.ExecuteNonQuery();
                if (rowsAffected > 0)
                {
                    updateresult = true;
                }
            }
            catch
            {

            }
            finally
            {
                myconn.Close();
            }
            return updateresult;
        }
        protected void NextBtn_Click(object sender, EventArgs e)
        {
            ArrayList listofSectionItems = new ArrayList();
            ArrayList listofFunctionItems = new ArrayList();
            bool chkresult = true;
            string name = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(NameTbx.Text.Trim());
            string uid = UserIdTbx.Text.ToLower().Trim();
            string sect = "";
            string funct = "";
            int count1 = 1;
            int count2 = 1;

            foreach (ListItem listItem in listSection1.Items)
            {
                if (listItem.Selected == true)
                {
                    listofSectionItems.Add(listItem.Text);
                }
            }

            foreach (string s in listofSectionItems)
            {
                if (count1 == listofSectionItems.Count)
                {
                    sect += s;
                }
                else
                {
                    sect += s + ", ";
                }
                count1++;
            }
            
            foreach (ListItem listItem in listSection2.Items)
            {
                if (listItem.Selected == true)
                {
                    listofFunctionItems.Add(listItem.Text);
                }
            }

            foreach (string f in listofFunctionItems)
            {
                if (count2 == listofFunctionItems.Count)
                {
                    funct += f;
                }
                else
                {
                    funct += f + ", ";
                }
                count2++;
            }

            if (chkresult == true)
            {
                lblValidatorSection.Text = "";
                lblValidatorSection0.Text = "";
                string[] design = designationTbx.Text.Trim().Split('/');
                string designation = "";
                if (design.LongLength > 0)
                {
                    int counter = 0;
                    foreach (string de in design)
                    {
                        if (de != "")
                        {
                            if (counter > 0)
                            {
                                designation += "/" + CultureInfo.CurrentCulture.TextInfo.ToTitleCase(de.Trim());
                            }
                            else
                            {
                                designation += CultureInfo.CurrentCulture.TextInfo.ToTitleCase(de.Trim());
                            }
                            counter++;
                        }
                    }
                }
                else
                {
                    designation = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(designationTbx.Text.Trim());
                }

                    string role = ddlRole.Text;

                    staffinfo stf = null;

                    if (name != "" && uid != "" && sect != "")
                    {
                        bool chk = dbmanager.CheckUserIDExist(uid);
                        if (sect.Contains("ALL"))
                        {
                            sect = "ALL";
                        }
                        if (chk == false)
                        {
                            stf = new staffinfo(name, designation, sect, funct, uid, role);
                            Session["User"] = stf;
                            mainView.ActiveViewIndex = 1;
                            InformationLbl.Text = "Please preview what you have selected. If the information is incorrect, click 'Back' to re-select.";

                            string summary = "";
                            summary += "<br><table><tr><td><b>New system user information<b></td></tr></table></br>";
                            summary += "<table>";
                            summary += "<tr><td><b>Name:</b></td><td>" + name + "</td></tr>";
                            summary += "<tr><td><b>Designation:</b></td><td>" + designation + "</td></tr>";
                            summary += "<tr><td><b>Section:</b></td><td>" + sect.Replace(';', ',') + "</td></tr>";
                            summary += "<tr><td><b>Function:</b></td><td>" + funct.Replace(';', ',') + "</td></tr>";
                            summary += "<tr><td><b>User ID:</b></td><td>" + uid + "</td></tr>";
                            summary += "<tr><td><b>Role:</b></td><td>" + role + "</td></tr>";
                            summary += "</table>";

                            SummaryLbl.Text = summary;
                        }
                        else
                        {
                            lblValidatorUserId.ForeColor = System.Drawing.Color.Red;
                            lblValidatorUserId.Text = "Id already exist. Please enter another id.";
                        }
                    }
                }
            }        
Exemple #3
0
        public static ArrayList GetAllStaffBySection(string sectionlimit)
        {
            staffinfo staff = null;

            SqlConnection myconn = null;
            ArrayList listofSection = new ArrayList();
            string[] strsec = sectionlimit.Split(',');
            try
            {
                if (strsec.LongLength > 0)
                {
                    foreach (string secti in strsec)
                    {
                        myconn = new SqlConnection();
                        SqlCommand comm = new SqlCommand();
                        myconn.ConnectionString = connectionString;
                        myconn.Open();
                        comm.Connection = myconn;
                        comm.CommandText = "select * from StaffInfo WHERE (StaffInfo.Section LIKE '%'+@sect OR StaffInfo.Section LIKE '%'+@sect + '%' OR StaffInfo.Section LIKE @sect + '%' OR StaffInfo.Section=@sect)";

                        comm.Parameters.AddWithValue("@sect", secti);

                        SqlDataReader dr = comm.ExecuteReader();
                        while (dr.Read())
                        {
                            string staffname = dr["Name"].ToString();
                            string designation = dr["Designation"].ToString();
                            string section = dr["Section"].ToString();
                            string function = dr["Functions"].ToString();
                            string uid = dr["UserID"].ToString();
                            string role = dr["Role"].ToString();

                            staff = new staffinfo(staffname, designation, section, function, uid, role);
                            listofSection.Add(staff);

                        }
                        dr.Close();

                    }
                }
            }

            catch (SqlException)
            {
                return listofSection;
            }

            finally
            {
                myconn.Close();
            }
            return listofSection;
        }
Exemple #4
0
        public static ArrayList GetAllStaffDetailsByFunctionSection(string function, string section)
        {
            SqlConnection myconn = null;
            ArrayList listofStaff = new ArrayList();
            try
            {
                myconn = new SqlConnection();
                SqlCommand comm = new SqlCommand();
                myconn.ConnectionString = connectionString;
                myconn.Open();
                comm.Connection = myconn;
                comm.CommandText = "select * from StaffInfo where (Section LIKE '%'+ @section OR Section LIKE '%'+ @section + '%' OR Section LIKE @section+'%' OR Section=@section) and Functions = @function;";
                comm.Parameters.AddWithValue("@function", function);
                comm.Parameters.AddWithValue("@section", section);
                SqlDataReader dr = comm.ExecuteReader();
                while (dr.Read())
                {
                    //string staffID = dr["UserID"].ToString();
                    ////Question q2 = new Question(qID, question, include);
                    //listofStaff.Add(staffID);
                    string staffname = dr["Name"].ToString();
                    string designation = dr["Designation"].ToString();
                    string sect = dr["Section"].ToString();
                    string funct = dr["Functions"].ToString();
                    string uid = dr["UserID"].ToString();
                    string role = dr["Role"].ToString();

                    staffinfo staff = new staffinfo(staffname, designation, sect, funct, uid, role);
                    listofStaff.Add(staff);
                }
                dr.Close();
            }

            catch (SqlException)
            {
                return listofStaff;
            }

            finally
            {
                myconn.Close();
            }
            return listofStaff;
        }
Exemple #5
0
        //Manage User Module

        public static ArrayList GetAllStaffDetails()
        {
            SqlConnection myconn = null;
            staffinfo staff = null;
            ArrayList listofstaff = new ArrayList();
            try
            {
                myconn = new SqlConnection();
                SqlCommand comm = new SqlCommand();
                myconn.ConnectionString = connectionString;
                myconn.Open();
                comm.Connection = myconn;
                comm.CommandText = "select * from StaffInfo order by Name";

                SqlDataReader dr = comm.ExecuteReader();
                while (dr.Read())
                {
                    string staffname = dr["Name"].ToString();
                    string designation = dr["Designation"].ToString();
                    string section = dr["Section"].ToString();
                    string function = dr["Functions"].ToString();
                    string uid = dr["UserID"].ToString();
                    string role = dr["Role"].ToString();

                    staff = new staffinfo(staffname, designation, section, function, uid, role);
                    listofstaff.Add(staff);
                }
                dr.Close();
            }

            catch (SqlException)
            {
                return listofstaff;
            }

            finally
            {
                myconn.Close();
            }
            return listofstaff;
        }
Exemple #6
0
        public static ArrayList GetAllStaffDetailsByOfficerPermission(staffinfo stafff)
        {
            SqlConnection myconn = null;
            staffinfo staff = null;
            ArrayList listofstaff = new ArrayList();
            try
            {
                if (stafff.Role == "Director" || stafff.Role == "Admin")
                {
                    myconn = new SqlConnection();
                    SqlCommand comm = new SqlCommand();
                    myconn.ConnectionString = connectionString;
                    myconn.Open();
                    comm.Connection = myconn;
                    comm.CommandText = "select * from StaffInfo order by Name";

                    SqlDataReader dr = comm.ExecuteReader();
                    while (dr.Read())
                    {
                        string staffname = dr["Name"].ToString();
                        string designation = dr["Designation"].ToString();
                        string section = dr["Section"].ToString();
                        string function = dr["Functions"].ToString();
                        string uid = dr["UserID"].ToString();
                        string role = dr["Role"].ToString();

                        staff = new staffinfo(staffname, designation, section, function, uid, role);
                        listofstaff.Add(staff);
                    }
                    dr.Close();
                }

                else if (stafff.Role == "Officer" && stafff.Function == "Manager")
                {
                    myconn = new SqlConnection();
                    SqlCommand comm = new SqlCommand();
                    myconn.ConnectionString = connectionString;
                    myconn.Open();
                    comm.Connection = myconn;
                    comm.CommandText = "select * from StaffInfo WHERE StaffInfo.Functions != 'Director' AND StaffInfo.Functions != 'AD' AND StaffInfo.Functions != 'DD' AND StaffInfo.Functions != 'Manager' order by Name";

                    SqlDataReader dr = comm.ExecuteReader();
                    while (dr.Read())
                    {
                        string staffname = dr["Name"].ToString();
                        string designation = dr["Designation"].ToString();
                        string section = dr["Section"].ToString();
                        string function = dr["Functions"].ToString();
                        string uid = dr["UserID"].ToString();
                        string role = dr["Role"].ToString();

                        staff = new staffinfo(staffname, designation, section, function, uid, role);
                        listofstaff.Add(staff);
                    }
                    dr.Close();
                }
                else if (stafff.Role == "Officer")
                {
                    myconn = new SqlConnection();
                    SqlCommand comm = new SqlCommand();
                    myconn.ConnectionString = connectionString;
                    myconn.Open();
                    comm.Connection = myconn;
                    comm.CommandText = "select * from StaffInfo WHERE StaffInfo.Functions != 'Director' AND StaffInfo.Functions != 'AD' AND StaffInfo.Functions != 'DD' order by Name";

                    SqlDataReader dr = comm.ExecuteReader();
                    while (dr.Read())
                    {
                        string staffname = dr["Name"].ToString();
                        string designation = dr["Designation"].ToString();
                        string section = dr["Section"].ToString();
                        string function = dr["Functions"].ToString();
                        string uid = dr["UserID"].ToString();
                        string role = dr["Role"].ToString();

                        staff = new staffinfo(staffname, designation, section, function, uid, role);
                        listofstaff.Add(staff);
                    }
                    dr.Close();
                }
            }

            catch (SqlException)
            {
                return listofstaff;
            }

            finally
            {
                myconn.Close();
            }
            return listofstaff;
        }
Exemple #7
0
        //Check login
        public static staffinfo GetLoginUserId(string userid)
        {
            SqlConnection con = new SqlConnection();
            con.ConnectionString = connectionString;
            staffinfo stf = null;
            try
            {
                con.Open();
                SqlCommand comm = new SqlCommand();
                comm.Connection = con;
                comm.CommandText = "Select * from StaffInfo where UserID=@uid";
                comm.Parameters.AddWithValue("@uid", userid);
                SqlDataReader dr = comm.ExecuteReader();
                if (dr.Read())
                {
                    string staffname = dr["Name"].ToString();
                    string designation = dr["Designation"].ToString();
                    string section = dr["Section"].ToString();
                    string function = dr["Functions"].ToString();
                    string uid = dr["UserID"].ToString();
                    string role = dr["Role"].ToString();

                    stf = new staffinfo(staffname, designation, section, function, uid, role);
                }
                dr.Close();
            }

            catch (SqlException)
            {

            }

            finally
            {
                con.Close();
            }
            return stf;
        }
Exemple #8
0
        public static bool InsertStaffInformation(staffinfo staf)
        {
            bool result = false;
            SqlConnection myconn = null;
            int rowsAffected = 0;

            try
            {
                myconn = new SqlConnection();
                SqlCommand comm = new SqlCommand();
                myconn.ConnectionString = connectionString;
                myconn.Open();
                comm.Connection = myconn;

                comm.CommandText = "insert into StaffInfo" +
                    "(Name,Designation,Section,Functions,UserID,Role) values" +
                    "(@name,@designation,@section,@funct,@uid,@role)";
                comm.Parameters.AddWithValue("@name", staf.Name);
                comm.Parameters.AddWithValue("@designation", staf.Designation);
                comm.Parameters.AddWithValue("@section", staf.Section);
                comm.Parameters.AddWithValue("@funct", staf.Function);
                comm.Parameters.AddWithValue("@uid", staf.Uid);
                comm.Parameters.AddWithValue("@role", staf.Role);
                rowsAffected = comm.ExecuteNonQuery();
                if (rowsAffected > 0)
                {
                    result = true;
                }
            }
            catch (SqlException)
            {
            }
            finally
            {
                myconn.Close();
            }
            return result;
        }
Exemple #9
0
        public static ArrayList GetAllUserIDViaLikeNameSection(string name, ArrayList sec)
        {
            ArrayList listofstaff = new ArrayList();
            SqlConnection myconn = null;
            staffinfo staff = null;
            try
            {
                foreach (string sect in sec)
                {
                    myconn = new SqlConnection();
                    SqlCommand comm = new SqlCommand();
                    myconn.ConnectionString = connectionString;
                    myconn.Open();
                    comm.Connection = myconn;

                    comm.CommandText = "select * from StaffInfo where Name LIKE '%" + name + "%' and Section=@sec";
                    comm.Parameters.AddWithValue("@sec", sect);

                    SqlDataReader dr = comm.ExecuteReader();
                    while (dr.Read())
                    {
                        string staffname = dr["Name"].ToString();
                        string designation = dr["Designation"].ToString();
                        string section = dr["Section"].ToString();
                        string function = dr["Functions"].ToString();
                        string userid = dr["UserID"].ToString();
                        string role = dr["Role"].ToString();

                        staff = new staffinfo(staffname, designation, section, function, userid, role);
                        listofstaff.Add(staff);
                    }
                    dr.Close();
                }
            }

            catch (SqlException)
            {
                return listofstaff;
            }

            finally
            {
                myconn.Close();
            }
            return listofstaff;
        }
Exemple #10
0
        public static staffinfo GetStaffDetailsViaName(string name)
        {
            SqlConnection myconn = null;
            staffinfo staff = null;
            try
            {
                myconn = new SqlConnection();
                SqlCommand comm = new SqlCommand();
                myconn.ConnectionString = connectionString;
                myconn.Open();
                comm.Connection = myconn;
                comm.CommandText = "select * from StaffInfo where Name=@name";
                comm.Parameters.AddWithValue("@name", name);

                SqlDataReader dr = comm.ExecuteReader();
                while (dr.Read())
                {
                    string staffname = dr["Name"].ToString();
                    string designation = dr["Designation"].ToString();
                    string section = dr["Section"].ToString();
                    string function = dr["Functions"].ToString();
                    string userid = dr["UserID"].ToString();
                    string role = dr["Role"].ToString();

                    staff = new staffinfo(staffname, designation, section, function, userid, role);
                }
                dr.Close();
            }

            catch (SqlException)
            {
                return staff;
            }

            finally
            {
                myconn.Close();
            }
            return staff;
        }
Exemple #11
0
        public static ArrayList GetAllUserIDViaLikeNameLimit(string name, string usersections)
        {
            ArrayList listofstaff = new ArrayList();
            SqlConnection myconn = null;
            staffinfo staff = null;
            try
            {
                string[] listofsection = usersections.Split(',');
                if (listofsection.LongLength > 0)
                {

                    myconn = new SqlConnection();
                    SqlCommand comm = new SqlCommand();
                    myconn.ConnectionString = connectionString;
                    myconn.Open();
                    comm.Connection = myconn;
                    comm.CommandText = "select * from StaffInfo where (Name LIKE '%" + name + "%' OR Name LIKE '" + name + "%' OR Name LIKE '%" + name + "' OR Name='" + name + "')";

                    SqlDataReader dr = comm.ExecuteReader();
                    while (dr.Read())
                    {
                        string staffname = dr["Name"].ToString();
                        string designation = dr["Designation"].ToString();
                        string section = dr["Section"].ToString();
                        string function = dr["Functions"].ToString();
                        string userid = dr["UserID"].ToString();
                        string role = dr["Role"].ToString();

                        staff = new staffinfo(staffname, designation, section, function, userid, role);
                        listofstaff.Add(staff);
                    }
                    dr.Close();

                }
            }

            catch (SqlException)
            {
                return listofstaff;
            }

            finally
            {
                myconn.Close();
            }
            return listofstaff;
        }
        private ArrayList ReadListOfDataFromCSVStaffInfo(DataTable listofStaffInformation)
        {
            ArrayList listofStaff = new ArrayList();
            try
            {
                int emptyvalue = 0;
                int invalidrelation = 0;
                int invaliddataformat = 0;
                StringBuilder SqlQuery = new StringBuilder();
                SqlQuery.Append("");

                if (listofStaffInformation.Rows.Count != 0)
                {
                    foreach (DataRow dr in listofStaffInformation.Rows)
                    {
                        if (dr["UserID"].ToString() != "")
                        {
                            string designationstring = "";
                            bool checksec = false;
                            string staffname = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(dr["Name"].ToString().Trim());
                            string designation = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(dr["Designation"].ToString().Trim());

                            string[] designarray = designation.Split('/');

                            if (designarray.LongLength > 0)
                            {
                                int counter = 0;
                                foreach (string de in designarray)
                                {
                                    if (de != "")
                                    {
                                        if (counter > 0)
                                        {
                                            designationstring += "/" + CultureInfo.CurrentCulture.TextInfo.ToTitleCase(de.Trim());
                                        }
                                        else
                                        {
                                            designationstring += CultureInfo.CurrentCulture.TextInfo.ToTitleCase(de.Trim());
                                        }
                                        counter++;
                                    }
                                }
                            }
                            else
                            {
                                designationstring = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(designation);
                            }
                            string section = dr["Section"].ToString().Trim();
                            string sectionstring = "";
                            string[] secinfo = section.Split(',');
                            string[] secarray = RemoveDuplicates(secinfo);
                            int countstring = 0;
                            foreach (string se in secarray)
                            {
                                if (se != "")
                                {

                                    checksec = dbmanager.CheckSectionExist(se.Trim());
                                    if (checksec == true)
                                    {
                                        if (countstring > 0)
                                        {
                                            sectionstring += "," + se.Trim();
                                        }
                                        else
                                        {
                                            sectionstring += se.Trim();
                                        }
                                        countstring++;
                                    }
                                    if (checksec == false)
                                    {
                                        break;
                                    }
                                }
                            }

                            string function = dr["Functions"].ToString().Trim();

                            bool checkfunc = dbmanager.CheckFunctionExist(function);

                            string staffuid = dr["UserID"].ToString().ToLower().Trim();
                            string role = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(dr["Role"].ToString().Trim());

                            bool checkrole = dbmanager.CheckRoleExist(role);

                            if (staffname != "" && staffuid != "" && checksec == true && checkfunc == true && checkrole == true)
                            {
                                if (sectionstring.Contains("ALL"))
                                {
                                    sectionstring = "ALL";
                                }
                                staffinfo staffinfo = new staffinfo(staffname, designationstring, sectionstring, function, staffuid, role);
                                listofStaff.Add(staffinfo);
                            }
                            else if (checksec == false || checkfunc == false || checkrole == false)
                            {
                                invalidrelation++;
                            }
                            if (staffname.Length > 100 || staffuid.Length > 30)
                            {
                                invaliddataformat++;
                            }
                        }
                        else
                        {
                            emptyvalue++;
                        }
                    }
                    if (invalidrelation > 0)
                    {
                        listofStaff.Clear();
                        MessageBoxShow(invalidrelation + " record(s) found with invalid data. might need relation data from other tables.");
                    }
                    if (invaliddataformat > 0)
                    {
                        listofStaff.Clear();
                        MessageBoxShow(invaliddataformat + " record(s) found with invalid data format.");
                    }
                    if (emptyvalue > 0)
                    {
                        listofStaff.Clear();
                        MessageBoxShow(emptyvalue + " record(s) found with empty data field.");
                    }
                }
                else
                {
                    StaffErrorMsgLbl.ForeColor = System.Drawing.Color.Red;
                    StaffErrorMsgLbl.Text = "Fail to read file.";
                }
            }
            catch
            {
                StaffErrorMsgLbl.ForeColor = System.Drawing.Color.Red;
                StaffErrorMsgLbl.Text = "Invalid data format found.";
            }
            return listofStaff;
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                if (ddlChooseFunct.SelectedValue == "Update User's section")
                {
                    ArrayList listofSectionItems = new ArrayList();

                    string sect = "";
                    int count = 1;

                    foreach (ListItem listItem in listSection.Items)
                    {
                        if (listItem.Selected == true)
                        {
                            listofSectionItems.Add(listItem.Text);
                        }
                    }
                    foreach (string s in listofSectionItems)
                    {
                        if (count == listofSectionItems.Count)
                        {
                            sect += s;
                        }
                        else
                        {
                            sect += s + ",";
                        }
                        count++;
                    }
                    staffinfo staff = dbmanager.GetStaffDetailsViaUid(lblID.Text);
                    staffinfo updatestaff = new staffinfo(staff.Name, staff.Designation, sect, staff.Function, staff.Uid, staff.Role);
                    bool passfail = dbmanager.UpdateUserInformation(updatestaff);
                    if (passfail == true)
                    {

                        MessageBoxShow("Successfully updated user's section.");
                        lbluser.Visible = true;
                        Label1.Visible = true;
                        Label2.Visible = true;
                        Label3.Visible = true;
                        lblID.Visible = true;
                        lblName.Visible = true;
                        lblSection.Visible = true;
                        lblDesignation.Visible = true;
                        Label4.Visible = true;
                        lblRole.Visible = true;
                        btnChange.Visible = true;
                        btnSubmit.Visible = true;
                        listSection.Visible = true;
                        ddlRole.Visible = false;
                        Label6.Visible = true;
                        lblDesignation.Visible = true;
                        ddlDesignation.Visible = false;
                        ddlFunctions.Visible = false;
                        lblFunctions.Visible = true;
                        lblSuccess.Text = "Successfully updated user's section.";
                        Page_Load(null, EventArgs.Empty);

                    }

                }
                else if (ddlChooseFunct.SelectedValue == "Update User's Role")
                {
                    staffinfo staff = dbmanager.GetStaffDetailsViaUid(lblID.Text);
                    staffinfo updatestaff = new staffinfo(staff.Name, staff.Designation, staff.Section, staff.Function, staff.Uid, ddlRole.SelectedValue);
                    bool passfail = dbmanager.UpdateUserInformation(updatestaff);
                    if (passfail == true)
                    {
                        MessageBoxShow("Successfully updated user's Role.");
                        lbluser.Visible = true;
                        Label1.Visible = true;
                        Label2.Visible = true;
                        Label3.Visible = true;
                        lblID.Visible = true;
                        lblName.Visible = true;
                        lblSection.Visible = true;
                        lblDesignation.Visible = true;
                        Label4.Visible = true;
                        lblRole.Visible = true;
                        btnChange.Visible = true;
                        btnSubmit.Visible = true;
                        listSection.Visible = false;
                        ddlRole.Visible = true;
                        Label6.Visible = true;
                        lblDesignation.Visible = true;
                        ddlDesignation.Visible = false;
                        ddlFunctions.Visible = false;
                        lblFunctions.Visible = true;
                        lblSuccess.Text = "Successfully updated user's Role.";
                        Page_Load(null, EventArgs.Empty);

                    }
                }
                else if (ddlChooseFunct.SelectedValue == "Update User's Function")
                {
                    staffinfo staff = dbmanager.GetStaffDetailsViaUid(lblID.Text);
                    staffinfo updatestaff = new staffinfo(staff.Name, staff.Designation, staff.Section, ddlFunctions.SelectedValue, staff.Uid, staff.Role);
                    bool passfail = dbmanager.UpdateUserInformation(updatestaff);
                    if (passfail == true)
                    {
                        MessageBoxShow("Successfully updated user's Function.");
                        lbluser.Visible = true;
                        Label1.Visible = true;
                        Label2.Visible = true;
                        Label3.Visible = true;
                        lblID.Visible = true;
                        lblName.Visible = true;
                        lblSection.Visible = true;
                        lblDesignation.Visible = true;
                        Label4.Visible = true;
                        lblRole.Visible = true;
                        btnChange.Visible = true;
                        btnSubmit.Visible = true;
                        listSection.Visible = false;
                        ddlRole.Visible = false;
                        Label6.Visible = true;
                        lblDesignation.Visible = true;
                        ddlDesignation.Visible = false;
                        ddlFunctions.Visible = true;
                        lblFunctions.Visible = true;
                        lblSuccess.Text = "Successfully updated user's Function.";
                        Page_Load(null, EventArgs.Empty);

                    }
                }
                else if (ddlChooseFunct.SelectedValue == "Update User's Designation")
                {
                    staffinfo staff = dbmanager.GetStaffDetailsViaUid(lblID.Text);
                    staffinfo updatestaff = new staffinfo(staff.Name, ddlDesignation.SelectedValue, staff.Section, staff.Function, staff.Uid, staff.Role);
                    bool passfail = dbmanager.UpdateUserInformation(updatestaff);
                    if (passfail == true)
                    {
                        MessageBoxShow("Successfully updated user's Designation.");
                        lbluser.Visible = true;
                        Label1.Visible = true;
                        Label2.Visible = true;
                        Label3.Visible = true;
                        lblID.Visible = true;
                        lblName.Visible = true;
                        lblSection.Visible = true;
                        lblDesignation.Visible = true;
                        Label4.Visible = true;
                        lblRole.Visible = true;
                        btnChange.Visible = true;
                        btnSubmit.Visible = true;
                        listSection.Visible = false;
                        ddlRole.Visible = false;
                        Label6.Visible = true;
                        lblDesignation.Visible = true;
                        ddlDesignation.Visible = true;
                        ddlFunctions.Visible = false;
                        lblFunctions.Visible = true;
                        lblSuccess.Text = "Successfully updated user's Designation.";
                        Page_Load(null, EventArgs.Empty);

                    }
                }
                else
                {
                    MessageBoxShow("Failed to update.");
                }

            }
            catch
            {
                MessageBoxShow("An error occurred!");
            }

        }
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!Page.IsPostBack)
            {
                if (Session["Role"] != null)
                {
                    string role = Session["Role"].ToString();
                    if (role != "Admin")
                    {
                        Response.Redirect("accessdenied.aspx");
                    }

                }
                else
                {
                    Response.Redirect("accessdenied.aspx");
                }
            }


            ListBox1.Visible = false;
            ListBox2.Visible = false;
            ListBox3.Visible = false;
            ListBox4.Visible = false;
            ListBox5.Visible = false;
            ListBox6.Visible = false;
            ListBox7.Visible = false;
            ListBox8.Visible = false;
            ListBox9.Visible = false;
            ListBox10.Visible = false;
            ListBox11.Visible = false;
            ListBox12.Visible = false;
            ListBox13.Visible = false;
            ListBox14.Visible = false;
            ListBox15.Visible = false;
            ListBox16.Visible = false;
            ListBox17.Visible = false;
            ListBox18.Visible = false;
            ListBox19.Visible = false;
            ListBox20.Visible = false;

            Panel2.Visible = false;
            Panel3.Visible = false;
            Panel4.Visible = false;
            Panel5.Visible = false;
            Panel6.Visible = false;
            Panel7.Visible = false;
            Panel8.Visible = false;
            Panel9.Visible = false;
            Panel10.Visible = false;
            Panel11.Visible = false;
            Panel12.Visible = false;
            Panel13.Visible = false;
            Panel14.Visible = false;
            Panel15.Visible = false;
            Panel16.Visible = false;
            Panel17.Visible = false;
            Panel18.Visible = false;
            Panel19.Visible = false;
            Panel20.Visible = false;
            Panel21.Visible = false;


            if (ddlChooseFunct.SelectedValue == "Update User's section")
            {

                ArrayList listofsection = dbmanager.GetAllSection();

                string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Appraisal_System"].ConnectionString.ToString();
                SqlConnection myconn = null;

                staffinfo staff = null;

                for (int i = 0; i < listofsection.Count; i++)
                {

                    if (i == 0)
                    {
                        Panel2.GroupingText = listofsection[i].ToString();
                        Panel2.Visible = true;

                    }
                    else if (i == 1)
                    {
                        Panel3.GroupingText = listofsection[i].ToString();
                        Panel3.Visible = true;
                    }
                    else if (i == 2)
                    {
                        Panel4.GroupingText = listofsection[i].ToString();
                        Panel4.Visible = true;
                    }

                    //TextBox abc = new TextBox();
                    //abc.Visible = true;

                    //Panel a = new Panel();
                    //a.GroupingText = listofsection[i].ToString();
                    //a.CssClass = "defaultPanel";
                    //a.Enabled = true;
                    //a.Visible = true;
                    //a.Height = 150;
                    //a.Width = 400;
                    //Panel1.Controls.Add(a);

                    //ListBox stafflist = new ListBox();
                    //stafflist.Enabled = true;
                    //stafflist.Visible = true;
                    //stafflist.ID = "stafflist" + i;
                    //stafflist.Width = 300;


                    //a.Controls.Add(stafflist);


                    ArrayList listofstaff = new ArrayList();

                    ArrayList listboxlist = new ArrayList();

                    try
                    {
                        myconn = new SqlConnection();
                        SqlCommand comm = new SqlCommand();
                        myconn.ConnectionString = connectionString;
                        myconn.Open();
                        comm.Connection = myconn;
                        comm.CommandText = "select * from StaffInfo order by Name";

                        SqlDataReader dr = comm.ExecuteReader();
                        while (dr.Read())
                        {

                            string staffname = dr["Name"].ToString();
                            string designation = dr["Designation"].ToString();
                            string section = dr["Section"].ToString();
                            string function = dr["Functions"].ToString();
                            string uid = dr["UserID"].ToString();
                            string role = dr["Role"].ToString();

                            staff = new staffinfo(staffname, designation, section, function, uid, role);
                            string[] split = section.Split(',');
                            ArrayList splitted = new ArrayList();
                            foreach (string word in split)
                            {
                                splitted.Add(word);
                            }

                            for (int p = 0; p < splitted.Count; p++)
                            {
                                if (splitted[p].ToString() == listofsection[i].ToString())
                                {
                                    listboxlist.Add(staffname + " " + uid);

                                }
                            }

                            listofstaff.Add(staff);

                        }
                        dr.Close();
                    }

                    catch (SqlException)
                    {

                    }

                    finally
                    {
                        myconn.Close();
                    }
                    if (i == 0)
                    {
                        ListBox1.Visible = true;
                        ListBox1.DataSource = listboxlist;
                        ListBox1.DataBind();
                    }
                    else if (i == 1)
                    {
                        ListBox2.Visible = true;
                        ListBox2.DataSource = listboxlist;
                        ListBox2.DataBind();
                    }
                    else if (i == 2)
                    {
                        ListBox3.Visible = true;
                        ListBox3.DataSource = listboxlist;
                        ListBox3.DataBind();
                    }

                    //stafflist.AutoPostBack = true;
                    //stafflist.DataSource = listboxlist;
                    //stafflist.DataBind();


                    //stafflist.SelectedIndexChanged += new EventHandler(this.ListBox1_SelectedIndexChanged);
                    //Label1.Text = stafflist.SelectedValue;


                    //Label name = new Label();
                    //name.Visible = true;
                    //name.Enabled = true;
                    //name.Text = listofsection[i].ToString();
                    //name.ID = "section" + i;


                    //a.Controls.Add(name);
                    //AjaxControlToolkit.DragPanelExtender ab = new AjaxControlToolkit.DragPanelExtender();
                    //ab.Enabled = true;
                    //ab.ID = "dragpanel"+i;
                    //ab.DragHandleID = name.ID;

                    //ab.TargetControlID = name.ID;

                    btnChange.Text = "Change user's section";

                }
            }
            else if (ddlChooseFunct.SelectedValue == "Update User's Role")
            {
                ArrayList listofsection = dbmanager.GetAllRole();

                string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Appraisal_System"].ConnectionString.ToString();
                SqlConnection myconn = null;


                staffinfo staff = null;

                for (int i = 0; i < listofsection.Count; i++)
                {

                    if (i == 0)
                    {
                        Panel2.GroupingText = listofsection[i].ToString();
                        Panel2.Visible = true;
                    }
                    else if (i == 1)
                    {
                        Panel3.GroupingText = listofsection[i].ToString();
                        Panel3.Visible = true;
                    }
                    else if (i == 2)
                    {
                        Panel4.GroupingText = listofsection[i].ToString();
                        Panel4.Visible = true;
                    }
                    else if (i == 3)
                    {
                        Panel5.GroupingText = listofsection[i].ToString();
                        Panel5.Visible = true;
                    }
                    else if (i == 4)
                    {
                        Panel6.GroupingText = listofsection[i].ToString();
                        Panel6.Visible = true;
                    }

                    //TextBox abc = new TextBox();
                    //abc.Visible = true;

                    //Panel a = new Panel();
                    //a.GroupingText = listofsection[i].ToString();
                    //a.CssClass = "defaultPanel";
                    //a.Enabled = true;
                    //a.Visible = true;
                    //a.Height = 150;
                    //a.Width = 400;
                    //Panel1.Controls.Add(a);

                    //ListBox stafflist = new ListBox();
                    //stafflist.Enabled = true;
                    //stafflist.Visible = true;
                    //stafflist.ID = "stafflist" + i;
                    //stafflist.Width = 300;


                    //a.Controls.Add(stafflist);


                    ArrayList listofstaff = new ArrayList();

                    ArrayList listboxlist = new ArrayList();

                    try
                    {
                        myconn = new SqlConnection();
                        SqlCommand comm = new SqlCommand();
                        myconn.ConnectionString = connectionString;
                        myconn.Open();
                        comm.Connection = myconn;
                        comm.CommandText = "select * from StaffInfo order by Name";

                        SqlDataReader dr = comm.ExecuteReader();
                        while (dr.Read())
                        {

                            string staffname = dr["Name"].ToString();
                            string designation = dr["Designation"].ToString();
                            string section = dr["Section"].ToString();
                            string function = dr["Functions"].ToString();
                            string uid = dr["UserID"].ToString();
                            string role = dr["Role"].ToString();

                            staff = new staffinfo(staffname, designation, section, function, uid, role);
                            if (role == listofsection[i].ToString())
                            {
                                listboxlist.Add(staffname + " " + uid);

                            }

                            listofstaff.Add(staff);

                        }
                        dr.Close();

                    }
                    catch (SqlException)
                    {

                    }
                    finally
                    {
                        myconn.Close();
                    }

                    if (i == 0)
                    {
                        ListBox1.Visible = true;
                        ListBox1.DataSource = listboxlist;
                        ListBox1.DataBind();
                    }
                    else if (i == 1)
                    {
                        ListBox2.Visible = true;
                        ListBox2.DataSource = listboxlist;
                        ListBox2.DataBind();
                    }
                    else if (i == 2)
                    {
                        ListBox3.Visible = true;
                        ListBox3.DataSource = listboxlist;
                        ListBox3.DataBind();
                    }
                    else if (i == 3)
                    {
                        ListBox4.Visible = true;
                        ListBox4.DataSource = listboxlist;
                        ListBox4.DataBind();
                    }
                    else if (i == 4)
                    {
                        ListBox5.Visible = true;
                        ListBox5.DataSource = listboxlist;
                        ListBox5.DataBind();
                    }

                }
                btnChange.Text = "Change user's role";


            }
            else if (ddlChooseFunct.SelectedValue == "Update User's Function")
            {
                ArrayList listofsection = dbmanager.GetAllFunctionName();

                string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Appraisal_System"].ConnectionString.ToString();
                SqlConnection myconn = null;

                staffinfo staff = null;

                for (int i = 0; i < listofsection.Count; i++)
                {

                    if (i == 0)
                    {
                        Panel2.GroupingText = listofsection[i].ToString();
                        Panel2.Visible = true;

                    }
                    else if (i == 1)
                    {
                        Panel3.GroupingText = listofsection[i].ToString();
                        Panel3.Visible = true;
                    }
                    else if (i == 2)
                    {
                        Panel4.GroupingText = listofsection[i].ToString();
                        Panel4.Visible = true;
                    }
                    else if (i == 3)
                    {
                        Panel5.GroupingText = listofsection[i].ToString();
                        Panel5.Visible = true;
                    }
                    else if (i == 4)
                    {
                        Panel6.GroupingText = listofsection[i].ToString();
                        Panel6.Visible = true;
                    }
                    else if (i == 5)
                    {
                        Panel7.GroupingText = listofsection[i].ToString();
                        Panel7.Visible = true;
                    }
                    else if (i == 6)
                    {
                        Panel8.GroupingText = listofsection[i].ToString();
                        Panel8.Visible = true;
                    }
                    
                    //TextBox abc = new TextBox();
                    //abc.Visible = true;

                    //Panel a = new Panel();
                    //a.GroupingText = listofsection[i].ToString();
                    //a.CssClass = "defaultPanel";
                    //a.Enabled = true;
                    //a.Visible = true;
                    //a.Height = 150;
                    //a.Width = 400;
                    //Panel1.Controls.Add(a);

                    //ListBox stafflist = new ListBox();
                    //stafflist.Enabled = true;
                    //stafflist.Visible = true;
                    //stafflist.ID = "stafflist" + i;
                    //stafflist.Width = 300;


                    //a.Controls.Add(stafflist);


                    ArrayList listofstaff = new ArrayList();

                    ArrayList listboxlist = new ArrayList();

                    try
                    {
                        myconn = new SqlConnection();
                        SqlCommand comm = new SqlCommand();
                        myconn.ConnectionString = connectionString;
                        myconn.Open();
                        comm.Connection = myconn;
                        comm.CommandText = "select * from StaffInfo order by Name";

                        SqlDataReader dr = comm.ExecuteReader();
                        while (dr.Read())
                        {

                            string staffname = dr["Name"].ToString();
                            string designation = dr["Designation"].ToString();
                            string section = dr["Section"].ToString();
                            string function = dr["Functions"].ToString();
                            string uid = dr["UserID"].ToString();
                            string role = dr["Role"].ToString();

                            staff = new staffinfo(staffname, designation, section, function, uid, role);
                            if (function == listofsection[i].ToString())
                            {
                                listboxlist.Add(staffname + " " + uid);

                            }

                            listofstaff.Add(staff);

                        }
                        dr.Close();
                    }

                    catch (SqlException)
                    {

                    }

                    finally
                    {
                        myconn.Close();
                    }
                    if (i == 0)
                    {
                        ListBox1.Visible = true;
                        ListBox1.DataSource = listboxlist;
                        ListBox1.DataBind();
                    }
                    else if (i == 1)
                    {
                        ListBox2.Visible = true;
                        ListBox2.DataSource = listboxlist;
                        ListBox2.DataBind();
                    }
                    else if (i == 2)
                    {
                        ListBox3.Visible = true;
                        ListBox3.DataSource = listboxlist;
                        ListBox3.DataBind();
                    }
                    else if (i == 3)
                    {
                        ListBox4.Visible = true;
                        ListBox4.DataSource = listboxlist;
                        ListBox4.DataBind();
                    }
                    else if (i == 4)
                    {
                        ListBox5.Visible = true;
                        ListBox5.DataSource = listboxlist;
                        ListBox5.DataBind();
                    }
                    else if (i == 5)
                    {
                        ListBox6.Visible = true;
                        ListBox6.DataSource = listboxlist;
                        ListBox6.DataBind();
                    }
                    else if (i == 6)
                    {
                        ListBox7.Visible = true;
                        ListBox7.DataSource = listboxlist;
                        ListBox7.DataBind();
                    }
                    
                }
                btnChange.Text = "Change user's Function";


            }
            else if (ddlChooseFunct.SelectedValue == "Update User's Designation")
            {
                ArrayList listofsection = dbmanager.GetAllDesignation();

                string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Appraisal_System"].ConnectionString.ToString();
                SqlConnection myconn = null;

                staffinfo staff = null;

                for (int i = 0; i < listofsection.Count; i++)
                {

                    if (i == 0)
                    {
                        Panel2.GroupingText = listofsection[i].ToString();
                        Panel2.Visible = true;

                    }
                    else if (i == 1)
                    {
                        Panel3.GroupingText = listofsection[i].ToString();
                        Panel3.Visible = true;
                    }
                    else if (i == 2)
                    {
                        Panel4.GroupingText = listofsection[i].ToString();
                        Panel4.Visible = true;
                    }
                    else if (i == 3)
                    {
                        Panel5.GroupingText = listofsection[i].ToString();
                        Panel5.Visible = true;
                    }
                    else if (i == 4)
                    {
                        Panel6.GroupingText = listofsection[i].ToString();
                        Panel6.Visible = true;
                    }
                    else if (i == 5)
                    {
                        Panel7.GroupingText = listofsection[i].ToString();
                        Panel7.Visible = true;
                    }
                    
                    //TextBox abc = new TextBox();
                    //abc.Visible = true;

                    //Panel a = new Panel();
                    //a.GroupingText = listofsection[i].ToString();
                    //a.CssClass = "defaultPanel";
                    //a.Enabled = true;
                    //a.Visible = true;
                    //a.Height = 150;
                    //a.Width = 400;
                    //Panel1.Controls.Add(a);

                    //ListBox stafflist = new ListBox();
                    //stafflist.Enabled = true;
                    //stafflist.Visible = true;
                    //stafflist.ID = "stafflist" + i;
                    //stafflist.Width = 300;


                    //a.Controls.Add(stafflist);


                    ArrayList listofstaff = new ArrayList();

                    ArrayList listboxlist = new ArrayList();

                    try
                    {
                        myconn = new SqlConnection();
                        SqlCommand comm = new SqlCommand();
                        myconn.ConnectionString = connectionString;
                        myconn.Open();
                        comm.Connection = myconn;
                        comm.CommandText = "select * from StaffInfo order by Name";

                        SqlDataReader dr = comm.ExecuteReader();
                        while (dr.Read())
                        {

                            string staffname = dr["Name"].ToString();
                            string designation = dr["Designation"].ToString();
                            string section = dr["Section"].ToString();
                            string function = dr["Functions"].ToString();
                            string uid = dr["UserID"].ToString();
                            string role = dr["Role"].ToString();

                            staff = new staffinfo(staffname, designation, section, function, uid, role);
                            if (designation == listofsection[i].ToString())
                            {
                                listboxlist.Add(staffname + " " + uid);

                            }

                            listofstaff.Add(staff);

                        }
                        dr.Close();
                    }

                    catch (SqlException)
                    {

                    }

                    finally
                    {
                        myconn.Close();
                    }
                    if (i == 0)
                    {
                        ListBox1.Visible = true;
                        ListBox1.DataSource = listboxlist;
                        ListBox1.DataBind();
                    }
                    else if (i == 1)
                    {
                        ListBox2.Visible = true;
                        ListBox2.DataSource = listboxlist;
                        ListBox2.DataBind();
                    }
                    else if (i == 2)
                    {
                        ListBox3.Visible = true;
                        ListBox3.DataSource = listboxlist;
                        ListBox3.DataBind();
                    }
                    else if (i == 3)
                    {
                        ListBox4.Visible = true;
                        ListBox4.DataSource = listboxlist;
                        ListBox4.DataBind();
                    }
                    else if (i == 4)
                    {
                        ListBox5.Visible = true;
                        ListBox5.DataSource = listboxlist;
                        ListBox5.DataBind();
                    }
                    else if (i == 5)
                    {
                        ListBox6.Visible = true;
                        ListBox6.DataSource = listboxlist;
                        ListBox6.DataBind();
                    }
                    
                }
                btnChange.Text = "Change user's Designation";


            }
        }
        protected void UpdateBtn_Click(object sender, EventArgs e)
        {
            try
            {
                #region update fields
                try
                {

                    bool chkresult = true;
                    int count = 1;
                    string sect = "";
                    ArrayList listofSectionItem = new ArrayList();

                    for (int i = 0; i < listSection.Items.Count; i++)
                    {
                        if (listSection.Items[i].Selected == true)
                        {
                            listofSectionItem.Add(listSection.Items[i].Text);
                        }
                    }
                    foreach (string s in listofSectionItem)
                    {
                        if (count == listofSectionItem.Count)
                        {
                            sect += s;
                        }
                        else
                        {
                            sect += s + ",";
                        }
                        count++;
                    }
                    if (listofSectionItem.Count == 0)
                    {
                        MessageBoxShowWithOutRedirect("Please select at least one section.");
                        chkresult = false;
                    }
                    if (chkresult == true)
                    {
                        if (sect.Contains("ALL"))
                        {
                            sect = "ALL";
                        }
                        string name = lblStaffName.Text;
                        string designation = lblStaffDesignation.Text;
                        string function = ddlFunction.Text;
                        string role = ddlRole.Text;
                        string uid = lblUid.Text;
                        staffinfo stf = new staffinfo(name, designation, sect, function, uid, role);
                        bool result = dbmanager.UpdateUserInformation(stf);
                        {
                            if (result == true)
                            {
                                MessageBoxShow("Updated successfully.");
                            }
                            else
                            {
                                MessageBoxShow("Fail to update.");
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBoxShow(ex.Message);
                }
                #endregion

            }
            catch (Exception ex)
            {
                MessageBoxShow(ex.Message);
            }
        }