Пример #1
0
 public bool AddNewEmployee(EmpDetails newRecord)
 {
     try
     {
         using (SqlConnection connection = new SqlConnection(connString))
             using (SqlCommand command = new SqlCommand("Employee.AddNewEmployee", connection))
             {
                 command.CommandType = CommandType.StoredProcedure;
                 command.Parameters.Add("FirstName", SqlDbType.VarChar, 256).Value         = newRecord.Emp_FirstName.ToDbParameter();
                 command.Parameters.Add("LastName", SqlDbType.VarChar, 256).Value          = newRecord.Emp_LastName.ToDbParameter();
                 command.Parameters.Add("GenderID", SqlDbType.Int).Value                   = newRecord.Emp_GenderID.ToDbParameter();
                 command.Parameters.Add("AddLine1", SqlDbType.VarChar, int.MaxValue).Value = newRecord.Emp_AddLine1;
                 command.Parameters.Add("AddLine2", SqlDbType.VarChar, int.MaxValue).Value = newRecord.Emp_AddLine2.ToDbParameter();
                 command.Parameters.Add("Mobile", SqlDbType.BigInt).Value                  = newRecord.Emp_MobileNo;
                 command.Parameters.Add("HouseNo", SqlDbType.BigInt).Value                 = newRecord.Emp_HouseNo.ToDbParameter();
                 command.Parameters.Add("PrivelegeID", SqlDbType.Bit).Value                = newRecord.Emp_PrivelegeID;
                 command.Parameters.Add("Password", SqlDbType.VarChar, 256).Value          = newRecord.Emp_Password.ToDbParameter();
                 command.Parameters.Add("LastLogin", SqlDbType.DateTime).Value             = newRecord.Emp_LastLogin.ToDbParameter();
                 connection.Open();
                 if (command.ExecuteNonQuery() != 0)
                 {
                     return(true);
                 }
                 else
                 {
                     return(false);
                 }
             }
     }
     catch (Exception ex)
     {
         MessageBox.Show("ERROR: " + ex, "SQL Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
     }
     return(false);
 }
Пример #2
0
 private void Btn_AdminAdd_Click(object sender, RoutedEventArgs e)
 {
     if (tb_AdminFirstName.Text == "" || tb_AdminFirstName.Text == "*" ||
         tb_AdminAddLine1.Text == "" || tb_AdminAddLine1.Text == "*" ||
         tb_AdminMobileNo.Text == "" || tb_AdminMobileNo.Text == "*" ||
         tb_AdminPassword.Text == "" || tb_AdminPassword.Text == "*")
     {
         MessageBox.Show("Please fill up necessary fields. (marked with *)");
         Clear_EmpDetails(1);
     }
     else
     {
         EmpDetails newRecord = new EmpDetails();
         newRecord.Emp_FirstName = tb_AdminFirstName.Text;
         newRecord.Emp_LastName  = tb_AdminLastName.Text;
         newRecord.Emp_GenderID  = comboBox_AdminGender.SelectedIndex;
         newRecord.Emp_AddLine1  = tb_AdminAddLine1.Text;
         newRecord.Emp_AddLine2  = tb_AdminAddLine2.Text;
         if (tb_AdminHouseNo.Text != "")
         {
             newRecord.Emp_HouseNo = Convert.ToInt64(tb_AdminHouseNo.Text);
         }
         else
         {
             newRecord.Emp_HouseNo = 0;
         }
         newRecord.Emp_MobileNo    = Convert.ToInt64(tb_AdminMobileNo.Text);
         newRecord.Emp_Password    = tb_AdminPassword.Text;
         newRecord.Emp_PrivelegeID = Convert.ToBoolean(comboBox_AdminPrivilege.SelectedIndex);
         newRecord.Emp_LastLogin   = null;
         AdminDAL aD = new AdminDAL();
         if (aD.AddNewEmployee(newRecord))
         {
             MessageBox.Show($"User {newRecord.Emp_FirstName} has been successfully added.");
             glob_User = newRecord;
         }
         else
         {
             MessageBox.Show($"User {newRecord.Emp_FirstName} was not added.");
         }
     }
 }
Пример #3
0
        public EmpDetails SearchByEmpID(long searchID)
        {
            EmpDetails resultDet = new EmpDetails();

            try
            {
                using (SqlConnection connection = new SqlConnection(connString))
                    using (SqlCommand command = new SqlCommand("Employee.SearchByEmpID", connection))
                    {
                        command.CommandType = CommandType.StoredProcedure;
                        command.Parameters.AddWithValue("Id", searchID);
                        connection.Open();
                        using (SqlDataReader reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                resultDet.EmployeeID      = reader.GetInt64(0);
                                resultDet.Emp_FirstName   = reader.GetString(1);
                                resultDet.Emp_LastName    = reader.SafeGetString(2);
                                resultDet.Emp_GenderID    = reader.GetInt32(3);
                                resultDet.Emp_AddLine1    = reader.GetString(4);
                                resultDet.Emp_AddLine2    = reader.SafeGetString(5);
                                resultDet.Emp_MobileNo    = reader.GetInt64(6);
                                resultDet.Emp_HouseNo     = reader.GetInt64(7);
                                resultDet.Emp_PrivelegeID = reader.GetBoolean(8);
                                resultDet.Emp_Password    = reader.GetString(9);
                                resultDet.Emp_LastLogin   = reader.SafeGetDateTime(10);
                            }
                        }
                        connection.Close();
                    }
            }
            catch (Exception ex)
            {
                MessageBox.Show("ERROR: " + ex, "SQL Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
            }
            return(resultDet);
        }
Пример #4
0
 private void Btn_AdminSearch_Click(object sender, RoutedEventArgs e)
 {
     if (tb_AdminEmpId.Text == "")
     {
         MessageBox.Show("Please enter Employee ID to search.");
     }
     else
     {
         long       searchID = Convert.ToInt64(tb_AdminEmpId.Text);
         AdminDAL   aD       = new AdminDAL();
         EmpDetails results  = aD.SearchByEmpID(searchID);
         tb_AdminFirstName.Text                = results.Emp_FirstName;
         tb_AdminLastName.Text                 = results.Emp_LastName;
         tb_AdminAddLine1.Text                 = results.Emp_AddLine1;
         tb_AdminAddLine2.Text                 = results.Emp_AddLine2;
         tb_AdminMobileNo.Text                 = Convert.ToString(results.Emp_MobileNo);
         tb_AdminHouseNo.Text                  = Convert.ToString(results.Emp_HouseNo);
         comboBox_AdminGender.SelectedIndex    = results.Emp_GenderID;
         tb_AdminPassword.Text                 = results.Emp_Password;
         comboBox_AdminPrivilege.SelectedIndex = Convert.ToInt32(results.Emp_PrivelegeID);
         glob_User = results;
     }
 }