public void AddAdmin(AdminObject admin)
        {
            DBConnect objDB = new DBConnect();
            SqlCommand objcomm = new SqlCommand();

            objcomm.CommandType = CommandType.StoredProcedure;
            objcomm.CommandText = "sp_addadmin";

            objcomm.Parameters.Add("@tuid", admin.tuid);
            objcomm.Parameters.Add("@firstName", admin.firstName);
            objcomm.Parameters.Add("@lastName", admin.lastName);
            objcomm.Parameters.Add("@department", admin.department);
            objcomm.Parameters.Add("@accessLevel", admin.accessLevel);

            objDB.DoUpdateUsingCmdObj(objcomm);
        }
Exemple #2
0
        protected void AddAdminSubmit_Click(object sender, EventArgs e)
        {
            String logMessage = String.Empty;

            Int32 userTuid = Int32.Parse((string)Session["AuthorizedUserTUID"]);//User TUID is used for existed Admin record editing

            AddAdminModalError.Visible = false;
            EditAdminTuidHeaderLabel.Visible = false;
            EditAdminTuidLabel.Visible = false;
            AddAdminTuidLabel.Visible = true;
            AddAdminTuidTextBox.Visible = true;

            String notValidTuidMessage = String.Empty;
            Int32 tuid = 0;
            Boolean result = false;

            AdminObject admin = new AdminObject();
            StoredProcedures sp = new StoredProcedures();

            List<String> EmptyControls = new List<string>();

            if (AddAdminModalHeader.InnerText == "Add Administrator" && AddAdminTuidTextBox.Text != String.Empty)
            {
                result = Int32.TryParse(AddAdminTuidTextBox.Text, out tuid);

                if (result)
                {
                    if (AddAdminTuidTextBox.Text.Length > 9 || AddAdminTuidTextBox.Text.Length < 9)
                    {
                        notValidTuidMessage = "Please enter a valid 9 digits TUID.</br>";
                    }
                }
                else
                {
                    notValidTuidMessage = "Please enter a valid 9 digits TUID.</br>";
                }
            }

            if (result == false)
            {
                AddAdminModalError.Visible = true;
                AddAdminModalError.InnerHtml = notValidTuidMessage;
            }

            if (AddAdminTuidTextBox.Text == String.Empty)
            {
                EmptyControls.Add("TUID");
            }

            if (AddAdminFirstNameTextBox.Text == String.Empty)
            {
                EmptyControls.Add("First Name");
            }

            if (AddAdminLastNameTextBox.Text == String.Empty)
            {
                EmptyControls.Add("Last Name");
            }

            if (AddAdminDeptDropDownList.SelectedValue == "Select")
            {
                EmptyControls.Add("Department");
            }

            if (AddAdminAccessLevelDropDownList.SelectedValue == "Select")
            {
                EmptyControls.Add("Access Level");
            }

            if (AddAdminFirstNameTextBox.Text == string.Empty || AddAdminLastNameTextBox.Text == string.Empty || AddAdminDeptDropDownList.SelectedValue == "Select" || AddAdminAccessLevelDropDownList.SelectedValue == "Select")
            {

                String errorFields = String.Empty;

                foreach (String field in EmptyControls)
                {

                    if (errorFields == String.Empty)
                    {

                        errorFields = field;
                    }
                    else
                    {

                        errorFields += ", " + field;
                    }
                }

                AddAdminModalError.Visible = true;
                AddAdminModalError.InnerHtml = notValidTuidMessage + "Please complete the following filelds: " + errorFields + ".";

                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "addAdmin", "$('#addAdmin').modal();", true);

            }
            else
            {
                try
                {
                    admin.tuid = Int32.Parse(AddAdminTuidTextBox.Text);

                    logMessage = "Added new administrator. ";
                }
                catch
                {
                    admin.tuid = Int32.Parse(EditAdminTuidLabel.Text);

                    logMessage = "Edited administrator info. ";
                }

                admin.firstName = AddAdminFirstNameTextBox.Text;
                admin.lastName = AddAdminLastNameTextBox.Text;
                admin.department = AddAdminDeptDropDownList.SelectedValue;
                admin.accessLevel = AddAdminAccessLevelDropDownList.SelectedValue;

                sp.AddAdmin(admin);

                AddAdminTuidTextBox.Text = String.Empty;
                AddAdminFirstNameTextBox.Text = String.Empty;
                AddAdminLastNameTextBox.Text = String.Empty;

                AddAdminDeptDropDownList.SelectedValue = "Select";
                AddAdminAccessLevelDropDownList.SelectedValue = "Select";

                DisplayAdmins();
            }
        }