Advertisement
Guest User

Untitled

a guest
Sep 4th, 2015
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.48 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace NETLAB1Kabanchuk
  12. {
  13.     class Employee
  14.     {
  15.         private string fio;
  16.         private int salary;
  17.         private int exp;
  18.         private double ndfl;
  19.         private double prize;
  20.  
  21.         public Employee(string fio, int salary, int exp)
  22.         {
  23.             this.fio = fio;
  24.             this.salary = salary;
  25.             this.exp = exp;
  26.         }
  27.  
  28.         public string getFio() { return this.fio; }
  29.  
  30.         public int getSalary() { return this.salary; }
  31.  
  32.         public int getExp() { return this.exp; }
  33.  
  34.         public double getNDFL() { return this.ndfl; }
  35.  
  36.         public double getPrize() { return this.prize; }
  37.  
  38.         public void setNdfl(double ndfl) { this.ndfl = ndfl; }
  39.  
  40.         public void setPrize(double prize) { this.prize = prize; }
  41.  
  42.     }
  43.  
  44.     class Student
  45.     {
  46.         private string name;
  47.         private int phone;
  48.         private int[] marks;
  49.  
  50.         public Student(string name, int phone, int[] marks)
  51.         {
  52.             this.name = name;
  53.             this.phone = phone;
  54.             this.marks = marks;
  55.         }
  56.  
  57.         public int getAverageMark()
  58.         {
  59.             int average = 0;
  60.             for (int i = 0; i < marks.Length; i++)
  61.                 average += marks[i];
  62.             return average / marks.Length;
  63.         }
  64.  
  65.         public string getName() { return this.name; }
  66.  
  67.         public int getPhone() { return this.phone; }
  68.  
  69.         public int getMark(int index) { return this.marks[index]; }
  70.     }
  71.  
  72.     public partial class Lab1 : Form
  73.     {
  74.         List<Student> Students = new List<Student>();
  75.         List<Employee> Employees = new List<Employee>();
  76.         public Lab1()
  77.         {
  78.             InitializeComponent();
  79.         }
  80.  
  81.         public void listsInicialize()
  82.         {
  83.             Students.Add(new Student("Олег", 323545, new int[] { 1, 2, 3, 6, 8} ));
  84.             Students.Add(new Student("Василий", 342345, new int[] { 4, 8, 6, 9, 10 }));
  85.             Students.Add(new Student("Андрей", 78955, new int[] { 7, 2, 4, 2, 4 }));
  86.             Students.Add(new Student("Максим", 88545, new int[] { 6, 5, 2, 5, 7 }));
  87.             Students.Add(new Student("Владимир", 323545, new int[] { 5, 8, 3, 8, 2 }));
  88.             Students.Add(new Student("Сергей", 342345, new int[] { 4, 6, 8, 6, 7 }));
  89.             Students.Add(new Student("Егор", 78955, new int[] { 4, 2, 4, 2, 4 }));
  90.             Students.Add(new Student("Валерий", 88545, new int[] { 2, 2, 2, 2, 2 }));
  91.  
  92.             Employees.Add(new Employee("Иванов Олег", 10000, 2));
  93.             Employees.Add(new Employee("Борисов Василий", 50000, 3));
  94.             Employees.Add(new Employee("Сергеев Андрей", 35000, 5));
  95.             Employees.Add(new Employee("Турчин Максим", 90000, 10));
  96.             Employees.Add(new Employee("Игорев Владимир", 25000, 20));
  97.             Employees.Add(new Employee("Максимов Сергей", 60000, 15));
  98.             Employees.Add(new Employee("Денисов Егор", 55000, 30));
  99.             Employees.Add(new Employee("Сталин Валерий", 12000, 40));
  100.         }
  101.  
  102.         private void Form1_Load(object sender, EventArgs e)
  103.         {
  104.             DataTable table = new DataTable();
  105.             table.Columns.Add("Имена");
  106.             table.Columns.Add("Номера телефонов");
  107.             table.Columns.Add("Математика");
  108.             table.Columns.Add("Физика");
  109.             table.Columns.Add("Биология");
  110.             table.Columns.Add("География");
  111.             table.Columns.Add("Информатика");
  112.             table.Columns.Add("Средняя оценка");
  113.  
  114.             listsInicialize();
  115.  
  116.             for (int i = 0; i < Students.Count; i++)
  117.             {
  118.                 table.Rows.Add(new String[] {
  119.                     Students[i].getName(),
  120.                     Convert.ToString(Students[i].getPhone()),
  121.                     Convert.ToString(Students[i].getMark(0)),
  122.                     Convert.ToString(Students[i].getMark(1)),
  123.                     Convert.ToString(Students[i].getMark(2)),
  124.                     Convert.ToString(Students[i].getMark(3)),
  125.                     Convert.ToString(Students[i].getMark(4)),
  126.                 });
  127.             }
  128.             dataGridView1.DataSource = table;
  129.  
  130.  
  131.             DataTable table_e = new DataTable();
  132.             table_e.Columns.Add("ФИО");
  133.             table_e.Columns.Add("Оклад");
  134.             table_e.Columns.Add("Стаж");
  135.             table_e.Columns.Add("Итоговая ЗП");
  136.  
  137.             for (int i = 0; i < Employees.Count; i++)
  138.             {
  139.                 table_e.Rows.Add(new String[] {
  140.                     Employees[i].getFio(),
  141.                     Employees[i].getSalary().ToString(),
  142.                     Employees[i].getExp().ToString(),
  143.                 });
  144.             }
  145.             dataGridView2.DataSource = table_e;
  146.         }
  147.  
  148.         private void firstTableStart_Click(object sender, EventArgs e)
  149.         {
  150.             for (int i = 0; i < Students.Count; i++)
  151.             {
  152.                 int average = Students[i].getAverageMark();
  153.                 dataGridView1.Rows[i].Cells[7].Value = Students[i].getAverageMark();
  154.  
  155.                 if (average > 4)
  156.                     dataGridView1.Rows[i].Cells[7].Style.BackColor = Color.FromName(colorsGood.SelectedItem.ToString());
  157.                 else if (average > 3)
  158.                     dataGridView1.Rows[i].Cells[7].Style.BackColor = Color.FromName(colorsAverage.SelectedItem.ToString());
  159.                 else
  160.                     dataGridView1.Rows[i].Cells[7].Style.BackColor = Color.FromName(colorsBad.SelectedItem.ToString());
  161.             }
  162.         }
  163.  
  164.         private void secondTableStart_Click(object sender, EventArgs e)
  165.         {
  166.             for (int i = 0; i < Employees.Count; i++)
  167.             {
  168.                 double salary = Employees[i].getSalary();
  169.                 double prize = 0;
  170.                 double exp = Employees[i].getExp();
  171.                 double ndfl = Convert.ToInt32(NDFL.Text);
  172.  
  173.                 if (exp > 10)
  174.                 {
  175.                     prize = 20;
  176.                     Employees[i].setPrize((Employees[i].getSalary() * 20) / 100);
  177.                 }
  178.                 else if (exp > 5)
  179.                 {
  180.                     prize = 15;
  181.                     Employees[i].setPrize((Employees[i].getSalary() * 15) / 100);
  182.                 }
  183.                 else
  184.                 {
  185.                     prize = 10;
  186.                     Employees[i].setPrize((Employees[i].getSalary() * 10) / 100);
  187.                 }
  188.  
  189.                 double result = (salary + (salary * (prize / 100))) - (salary * (ndfl / 100));
  190.  
  191.                 dataGridView2.Rows[i].Cells[3].Value = result;
  192.  
  193.                 Employees[i].setNdfl((salary*ndfl)/100);
  194.             }
  195.         }
  196.  
  197.         private void getLogsButton_Click(object sender, EventArgs e)
  198.         {
  199.             int index = (int)dataGridView2.CurrentRow.Index;
  200.             MessageBox.Show(Employees[index].getFio() +
  201.                         ", НДФЛ = " + Employees[index].getNDFL() +
  202.                        ", Премия = " + Employees[index].getPrize()
  203.             );
  204.         }
  205.  
  206.     }
  207.  
  208. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement