Esempio n. 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            userInMemory holdUser = new userInMemory(getValuesFromFields());
            using (SqlCommand cmd = new SqlCommand("procedure_EditStaff", con))
            {
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add("@StaffID", SqlDbType.Int).Value = holdUser.StaffID;
                cmd.Parameters.Add("@PermLevel", SqlDbType.Int).Value = holdUser.PermLevel;
                cmd.Parameters.Add("@Forename", SqlDbType.VarChar, 20).Value = holdUser.Forename;
                cmd.Parameters.Add("@Surname", SqlDbType.VarChar, 30).Value = holdUser.Surname;
                cmd.Parameters.Add("@Title", SqlDbType.VarChar, 10).Value = holdUser.Title;
                cmd.Parameters.Add("@Gender", SqlDbType.Char, 1).Value = holdUser.Gender;
                cmd.Parameters.Add("@DOB", SqlDbType.Date).Value = holdUser.DOB;
                cmd.Parameters.Add("@Role", SqlDbType.VarChar, 20).Value = holdUser.Role;
                cmd.Parameters.Add("@EmploymentBasis", SqlDbType.Char, 4).Value = holdUser.EmploymentBasis;
                cmd.Parameters.Add("@Address1", SqlDbType.VarChar, 50).Value = holdUser.Address1;
                cmd.Parameters.Add("@Address2", SqlDbType.VarChar, 50).Value = holdUser.Address2;
                cmd.Parameters.Add("@City", SqlDbType.VarChar, 20).Value = holdUser.City;
                cmd.Parameters.Add("@Postcode", SqlDbType.VarChar, 10).Value = holdUser.Postcode;
                cmd.Parameters.Add("@ContactNumber", SqlDbType.VarChar, 20).Value = holdUser.ContactNumber;
                cmd.Parameters.Add("@Email", SqlDbType.VarChar, 50).Value = holdUser.Email;

                cmd.ExecuteNonQuery();
            }
            if (qualificationsToAdd != null)
            {
                using (SqlCommand cmd = new SqlCommand("procedure_ClearQualification"))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("StaffID", SqlDbType.Int).Value = holdUser.StaffID;
                    cmd.ExecuteNonQuery();
                }
                foreach (string qualification in qualificationsToAdd)
                {
                    using (SqlCommand cmd = new SqlCommand("procedure_AddQualification"))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add("StaffID", SqlDbType.Int).Value = holdUser.StaffID;
                        cmd.Parameters.Add("Field", SqlDbType.VarChar, 15).Value = qualification;
                        cmd.ExecuteNonQuery();
                    }
                }
            }
            userToEdit = holdUser;
        }
Esempio n. 2
0
 private void btnLoad_Click(object sender, EventArgs e)
 {
     qualificationsToAdd = null;
     if (splitContainer1.Panel2Collapsed)
     {
         splitContainer1.Panel2Collapsed = false;
         tblSearch.Visible = false;
         btnLoad.Text = "Search";
     
     int staffIDToEdit;
     if (!int.TryParse(lbxResults.SelectedItem.ToString().Substring(0, 3), out staffIDToEdit))
     {
         MessageBox.Show("Not a valid user");
         return;
     }
     using (SqlCommand cmd = new SqlCommand("procedure_GetUser", con))
     {
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.Parameters.Add("@StaffID", SqlDbType.Int).Value = staffIDToEdit;
         SqlDataReader dr = cmd.ExecuteReader();
         while (dr.Read())
         {
             string[] dataArray = new string[16];
             for (int i = 0; i < 16; i++)
             {
                 dataArray[i] = dr[i].ToString();
             }
             userToEdit = new userInMemory(dataArray);
         }
         dr.Close();
         if (userToEdit.UserSet)
         {
             lblStaffID.Text = userToEdit.StaffID.ToString();
             nudPermLevel.Value = userToEdit.PermLevel;
             tbxForename.Text = userToEdit.Forename;
             tbxSurname.Text = userToEdit.Surname;
             cbxTitle.SelectedIndex = cbxTitle.FindStringExact(userToEdit.Title);
             if (userToEdit.Gender.ToString().ToUpper() == "M") rbtnMale.Checked = true;
             else rbtnFemale.Checked = true;
             dtpDOB.Value = userToEdit.DOB;
             cbxRole.SelectedIndex = cbxRole.FindStringExact(userToEdit.Role);
             if (userToEdit.EmploymentBasis.ToString().ToUpper().StartsWith("F")) rbtnFullTime.Checked = true;
             else rbtnPartTime.Checked = true;
             tbxAddress1.Text = userToEdit.Address1;
             tbxAddress2.Text = userToEdit.Address2;
             tbxCity.Text = userToEdit.City;
             tbxPostcode.Text = userToEdit.Postcode;
             tbxContactNo.Text = userToEdit.ContactNumber;
             tbxEmail.Text = userToEdit.Email;
         }
     }
     }
     else
     {
         splitContainer1.Panel2Collapsed = true;
         tblSearch.Visible = true;
         btnLoad.Text = "Load";
     }
 }