Exemplo n.º 1
0
        //------------------- Add and get ---------
        public DisplayEmployeeDetails AddEmployee(DisplayEmployeeDetails model)
        {
            Salary salary = new Salary();

            try
            {
                var sqlFormattedDate = model.HireDate.ToString("MM/dd/yyyy");
                using (this.connection)
                {
                    SqlCommand command = new SqlCommand("spAddEmployee", this.connection);
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@EName", model.EName);
                    command.Parameters.AddWithValue("@Gender", model.Gender);
                    command.Parameters.AddWithValue("@HireDay", sqlFormattedDate);
                    command.Parameters.AddWithValue("@DeptNo", model.DeptNo);
                    command.Parameters.AddWithValue("@Email", model.Email ?? "");
                    command.Parameters.AddWithValue("@BirthDay", model.BirthDay ?? "");
                    command.Parameters.AddWithValue("@JobDiscription", model.JobDiscription ?? "");
                    command.Parameters.AddWithValue("@ProfileImage", model.Image ?? "");
                    this.connection.Open();
                    Object result = command.ExecuteScalar();
                    this.connection.Close();
                    if (result != null)
                    {
                        salary.EmpId       = Convert.ToInt32(result.ToString());
                        salary.EmpSal      = model.EmpSal;
                        salary.SalaryMonth = model.SalaryMonth;
                        this.AddEmployeeSalary(salary);
                        return(model);
                    }
                    return(null);
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            finally
            {
                this.connection.Close();
            }
        }
 public DisplayEmployeeDetails GetEmployeeById(int id)
 {
     try
     {
         using (this.connection)
         {
             DisplayEmployeeDetails employee = new DisplayEmployeeDetails();
             SqlCommand             command  = new SqlCommand("spGetEmployeeById", this.connection);
             command.CommandType = CommandType.StoredProcedure;
             command.Parameters.AddWithValue("@EmpId", id);
             this.connection.Open();
             SqlDataReader dataReader = command.ExecuteReader();
             if (dataReader.HasRows)
             {
                 while (dataReader.Read())
                 {
                     employee.EmpId          = Convert.ToInt32(dataReader["EmpId"]);
                     employee.EName          = dataReader["EName"].ToString();
                     employee.Gender         = Convert.ToChar(dataReader["Gender"]);
                     employee.DeptNo         = Convert.ToInt32(dataReader["DeptNo"]);
                     employee.DeptName       = dataReader["DeptName"].ToString();
                     employee.EmpSal         = Convert.ToDouble(dataReader["EmpSal"]);
                     employee.HireDate       = Convert.ToDateTime(dataReader["HireDay"]);
                     employee.Image          = dataReader["ProfileImage"].ToString();
                     employee.JobDiscription = dataReader["JobDiscription"].ToString();
                 }
                 return(employee);
             }
             return(null);
         }
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
     finally
     {
         this.connection.Close();
     }
 }
Exemplo n.º 3
0
 //----------------------------------------------------------------------
 //--------- Update Employee --------------------------------------------
 public DisplayEmployeeDetails UpdateEmployee(DisplayEmployeeDetails details)
 {
     try
     {
         using (this.connection)
         {
             this.connection.Open();
             using (var transaction = this.connection.BeginTransaction())
             {
                 SqlCommand employeeUpdate = new SqlCommand("spUpdateEmployee", this.connection, transaction);
                 employeeUpdate.CommandType = CommandType.StoredProcedure;
                 employeeUpdate.Parameters.AddWithValue("@EmpId", details.EmpId);
                 employeeUpdate.Parameters.AddWithValue("@EName", details.EName);
                 employeeUpdate.Parameters.AddWithValue("@Gender", details.Gender);
                 employeeUpdate.Parameters.AddWithValue("@HireDay", details.HireDate);
                 employeeUpdate.Parameters.AddWithValue("@DeptNo", details.DeptNo);
                 employeeUpdate.Parameters.AddWithValue("@JobDiscription", details.JobDiscription == null?"" : details.JobDiscription);
                 employeeUpdate.Parameters.AddWithValue("@SalaryMonth", details.SalaryMonth);
                 employeeUpdate.Parameters.AddWithValue("@EmpSal", details.EmpSal);
                 employeeUpdate.Parameters.AddWithValue("@ProfileImage", details.Image ?? "");
                 var result = employeeUpdate.ExecuteNonQuery();
                 transaction.Commit();
                 if (result != 0)
                 {
                     return(details);
                 }
                 return(null);
             }
         }
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
     finally
     {
         this.connection.Close();
     }
 }
 public DisplayEmployeeDetails UpdateEmployee(DisplayEmployeeDetails details)
 {
     return(this.repo.UpdateEmployee(details));
 }
 public DisplayEmployeeDetails AddEmployee(DisplayEmployeeDetails model)
 {
     return(this.repo.AddEmployee(model));
 }
Exemplo n.º 6
0
        protected void BindTextBoxValues(int empId)
        {
            try
            {
                DisplayEmployeeDetails displayEmployee = employee.GetEmployeeById(empId);
                EmpId.Text = displayEmployee.EmpId.ToString();
                name.Text  = displayEmployee.EName;
                if (displayEmployee.Image == "../Assets/Ellipse -3")
                {
                    profile1.Checked = true;
                }
                if (displayEmployee.Image == "../Assets/Ellipse -1")
                {
                    profile2.Checked = true;
                }
                if (displayEmployee.Image == "../Assets/Ellipse -8")
                {
                    profile3.Checked = true;
                }
                if (displayEmployee.Image == "../Assets/Ellipse -7")
                {
                    profile4.Checked = true;
                }
                if (displayEmployee.Gender == 'M')
                {
                    male.Checked   = true;
                    female.Checked = false;
                }
                else
                {
                    male.Checked   = false;
                    female.Checked = true;
                }
                switch (displayEmployee.DeptName)
                {
                case "HR":
                    hr.Checked = true;
                    break;

                case "Sales":
                    sales.Checked = true;
                    break;

                case "Finance":
                    finance.Checked = true;
                    break;

                case "Engineer":
                    engineer.Checked = true;
                    break;

                case "Others":
                    others.Checked = true;
                    break;
                }

                salary.Text = displayEmployee.EmpSal.ToString();
                string d         = displayEmployee.HireDate.Day.ToString();
                int    m         = displayEmployee.HireDate.Month;
                string monthName = DateTimeFormatInfo.CurrentInfo.GetAbbreviatedMonthName(m);
                string y         = displayEmployee.HireDate.Year.ToString();
                day.Items[day.SelectedIndex].Text     = d.ToString();
                month.Items[month.SelectedIndex].Text = monthName.ToString();
                year.Items[year.SelectedIndex].Text   = y.ToString();
                notes.Text = displayEmployee.JobDiscription;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }