コード例 #1
0
        private static void Main(string[] args)
        {
            Console.WriteLine("SQL!");

            EmployeeRepo        repo = new EmployeeRepo();
            EmployeeSalaryModel employeeSalaryPayroll = new EmployeeSalaryModel();
            EmployeePayroll     employeePayroll       = new EmployeePayroll();

            employeePayroll.EmployeeName = "Johnny";
            employeePayroll.BasicPay     = 200900;
            employeePayroll.StartDate    = DateTime.Now;
            employeePayroll.Gender       = "M";
            employeePayroll.PhoneNumber  = "7677173446";
            employeePayroll.Address      = "Bangur Rd";
            employeePayroll.Department   = "HR";
            employeePayroll.Deductions   = 1050;
            employeePayroll.TaxablePay   = 17000;
            employeePayroll.Tax          = 1800;
            employeePayroll.NetPay       = 18000;

            //repo.AddEmployee(employeePayroll);

            Console.WriteLine("-------------");

            //repo.GetAllEmployee();

            employeeSalaryPayroll.EmployeeId = 3;
            employeeSalaryPayroll.payroll_id = 1;
            employeeSalaryPayroll.department = "Finance";
            employeeSalaryPayroll.basic_pay  = 2345678;
            employeeSalaryPayroll.name       = "UpdatedName";
            employeeSalaryPayroll.start_Date = "01-01-20";

            repo.UpdateEmployee(employeeSalaryPayroll);
        }
コード例 #2
0
        public int UpdateEmployee(EmployeeSalaryModel model)
        {
            int salary = 0;

            try
            {
                using (connection)
                {
                    SqlConnection       connection   = new SqlConnection(connectionString);
                    EmployeeSalaryModel displayModel = new EmployeeSalaryModel();

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

                    command.Parameters.AddWithValue("@payroll_id", model.payroll_id);
                    command.Parameters.AddWithValue("@basic_pay", model.payroll_id);
                    command.Parameters.AddWithValue("@start_Date", model.start_Date);
                    command.Parameters.AddWithValue("@id", model.EmployeeId);
                    command.Parameters.AddWithValue("@department", model.department);
                    command.Parameters.AddWithValue("@name", model.name);

                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            displayModel.EmployeeId = reader.GetInt32(0);
                            displayModel.payroll_id = reader.GetInt32(1);
                            displayModel.basic_pay  = reader.GetInt32(2);
                            displayModel.start_Date = reader.GetString(3);
                            displayModel.name       = reader.GetString(4);
                            displayModel.department = reader.GetString(5);
                            salary = displayModel.payroll_id;
                        }
                    }
                    else
                    {
                        Console.WriteLine("No Data found!");
                    }
                    reader.Close();
                    return(salary);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                connection.Close();
                return(0);
            }
            finally
            {
                connection.Close();
            }
        }