public int UpdateEmployee(SalaryDetailModel model)
        {
            int salary = 0;

            try
            {
                using (connection)
                {
                    connection = new SqlConnection(connectionstring);
                    SalaryDetailModel displayModel = new SalaryDetailModel();

                    SqlCommand command = new SqlCommand("Sp_UpdateEmployee_Payroll", connection);
                    command.CommandType = CommandType.StoredProcedure;

                    command.Parameters.AddWithValue("@S_id", model.SalaryId);
                    //command.Parameters.AddWithValue("@EmployeeName", model.EmployeeName);
                    //command.Parameters.AddWithValue("@Designation", model.Designation);
                    command.Parameters.AddWithValue("@salary", model.Salary);
                    command.Parameters.AddWithValue("@month", model.Month);
                    command.Parameters.AddWithValue("@E_id", model.EmployeeId);

                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            displayModel.EmployeeId   = reader.GetInt32(0);
                            displayModel.EmployeeName = reader.GetString(1);
                            displayModel.Designation  = reader.GetString(2);
                            displayModel.Month        = reader.GetString(3);
                            displayModel.SalaryId     = reader.GetInt32(4);
                            displayModel.Salary       = reader.GetInt32(5);

                            salary = displayModel.Salary;
                        }
                    }
                    else
                    {
                        Console.WriteLine("No Data found");
                    }
                    reader.Close();
                    return(salary);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                connection.Close();
                return(0);
            }
            finally
            {
                connection.Close();
            }
        }
        public double UpdateEmployeeSalary(SalaryUpdateModel salaryUpdateModel)
        {
            SqlConnection SalaryConnection = new SqlConnection(connectionString);
            double        salary           = 0;

            try
            {
                using (SalaryConnection)
                {
                    SalaryDetailModel displayModel = new SalaryDetailModel();
                    SqlCommand        command      = new SqlCommand("spUpdateEmployeeSalary", SalaryConnection);
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddWithValue("@id", salaryUpdateModel.EmployeeId);
                    command.Parameters.AddWithValue("@name", salaryUpdateModel.EmployeeName);
                    command.Parameters.AddWithValue("@salary", salaryUpdateModel.EmployeeSalary);
                    SalaryConnection.Open();

                    SqlDataReader dr = command.ExecuteReader();

                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            displayModel.EmployeeId     = dr.GetInt32(0);
                            displayModel.EmployeeName   = dr.GetString(1);
                            displayModel.SalaryId       = dr.GetInt32(2);
                            displayModel.EmployeeSalary = Convert.ToDouble(dr.GetDecimal(3));


                            Console.WriteLine("{0}, {1}, {2}, {3}", displayModel.EmployeeId, displayModel.EmployeeName, displayModel.SalaryId, displayModel.EmployeeSalary);
                            Console.WriteLine("\n");

                            salary = displayModel.EmployeeSalary;
                        }
                    }
                    else
                    {
                        Console.WriteLine("No data found");
                    }

                    dr.Close();

                    SalaryConnection.Close();
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            finally
            {
                SalaryConnection.Close();
            }
            return(salary);
        }
Beispiel #3
0
        public int UpdateEmployeeSalary(SalaryUpdateModel salaryUpdateModel)
        {
            SqlConnection SalaryConnection = ConnectionSetup();
            int           salary           = 0;

            try
            {
                using (SalaryConnection)
                {
                    SalaryDetailModel displayModel = new SalaryDetailModel();
                    SqlCommand        command      = new SqlCommand("spUpdateEmployeeSalary", SalaryConnection);
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    var cmd = new SqlCommand("Select Id from Employee where Name='Terissa'", SalaryConnection);
                    SalaryConnection.Open();

                    var reader = cmd.ExecuteReader();

                    if (reader.Read())
                    {
                        salaryUpdateModel.SalaryId = Convert.ToInt32(reader.GetInt32(0));
                    }
                    reader.Close();
                    command.Parameters.AddWithValue("@id", salaryUpdateModel.SalaryId);
                    command.Parameters.AddWithValue("@salary", salaryUpdateModel.EmployeeSalary);
                    SqlDataReader dr = command.ExecuteReader();
                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            displayModel.EmployeeId     = Convert.ToInt32(dr["Id"]);
                            displayModel.EmployeeName   = dr["Name"].ToString();
                            displayModel.EmployeeSalary = Convert.ToInt32(dr["Salary"]);
                            Console.WriteLine(displayModel.EmployeeId + " " + displayModel.EmployeeName + " " + displayModel.EmployeeSalary);
                            Console.WriteLine("\n");
                            salary = displayModel.EmployeeSalary;
                        }
                    }
                    else
                    {
                        Console.WriteLine("No data found.");
                    }
                }
                return(salary);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
            finally
            {
                SalaryConnection.Close();
            }
        }
Beispiel #4
0
        public SalaryDetailModel getEmployeeObject(string empName)
        {
            SalaryDetailModel salaryDetail     = new SalaryDetailModel();
            SqlConnection     SalaryConnection = ConnectionSetup();

            try
            {
                using (SalaryConnection)
                {
                    SalaryConnection.Open();
                    SqlCommand    command = new SqlCommand("sqRetrieveEmployeeSalary", SalaryConnection);
                    SqlDataReader dr      = command.ExecuteReader();
                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            String Employeename = dr["empName"].ToString();
                            if (Employeename.Equals(empName))
                            {
                                salaryDetail.EmployeeName   = empName;
                                salaryDetail.EmployeeId     = (int)dr["empId"];
                                salaryDetail.EmployeeSalary = Convert.ToDouble(dr["basicPay"]);
                                salaryDetail.Deductions     = Convert.ToDouble(dr["deductions"]);
                                salaryDetail.TaxablePay     = Convert.ToDouble(dr["taxablePay"]);
                                salaryDetail.NetPay         = Convert.ToDouble(dr["netPay"]);
                                salaryDetail.tax            = Convert.ToDouble(dr["tax"]);
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                throw new Exception(exception.Message);
            }
            finally
            {
                SalaryConnection.Close();
            }
            return(salaryDetail);
        }