Advertisement
Placido_GDD

FrmEmployee

May 15th, 2022
720
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. using BLL;
  11. using DAL;
  12. using DAL.DTO;
  13. using System.IO;
  14.  
  15. namespace PersonelTracking
  16. {
  17.     public partial class FrmEmployee : Form
  18.     {
  19.         public FrmEmployee()
  20.         {
  21.             InitializeComponent();
  22.         }
  23.  
  24.         private void label1_Click(object sender, EventArgs e)
  25.         {
  26.  
  27.         }
  28.  
  29.         private void txtPassword_TextChanged(object sender, EventArgs e)
  30.         {
  31.  
  32.         }
  33.  
  34.         private void txtName1_TextChanged(object sender, EventArgs e)
  35.         {
  36.  
  37.         }
  38.  
  39.         private void txtSurname_TextChanged(object sender, EventArgs e)
  40.         {
  41.  
  42.         }
  43.  
  44.         private void textBox1_TextChanged(object sender, EventArgs e)
  45.         {
  46.  
  47.         }
  48.  
  49.         private void txtName_Click(object sender, EventArgs e)
  50.         {
  51.  
  52.         }
  53.  
  54.         private void btnClose_Click(object sender, EventArgs e)
  55.         {
  56.             this.Close();
  57.         }
  58.  
  59.         private void txtUserNo_TextChanged(object sender, EventArgs e)
  60.         {
  61.            
  62.         }
  63.  
  64.         private void txtUserNo_KeyPress(object sender, KeyPressEventArgs e)
  65.         {
  66.             e.Handled = General.isNumber(e);
  67.         }
  68.  
  69.         private void txtSalary_KeyPress(object sender, KeyPressEventArgs e)
  70.         {
  71.             e.Handled = General.isNumber(e);
  72.         }
  73.         EmployeeDTO dto = new EmployeeDTO();
  74.         private void FrmEmployee_Load(object sender, EventArgs e)
  75.         {
  76.             dto = EmployeeBLL.GetAll();
  77.             cmbDepartment.DataSource = dto.Departments;
  78.             cmbDepartment.DisplayMember = "Department Name";
  79.             cmbDepartment.ValueMember = "ID";
  80.             cmbPosition.DataSource = dto.Positions;
  81.             cmbPosition.DisplayMember = "Position Name";
  82.             cmbPosition.ValueMember = "ID";
  83.             cmbDepartment.SelectedIndex = -1;
  84.             cmbPosition.SelectedIndex = -1;
  85.             combofull = true;
  86.         }
  87.  
  88.         bool combofull = false;
  89.        
  90.  
  91.         private void cmbDepartment_SelectedIndexChanged(object sender, EventArgs e)
  92.         {
  93.             if (combofull)
  94.             {
  95.                 int departmentID = Convert.ToInt32(cmbDepartment.SelectedValue);
  96.                 cmbPosition.DataSource = dto.Positions.Where(x => x.DepartmentID == departmentID).ToList();
  97.             }
  98.            
  99.  
  100.         }
  101.  
  102.         string fileName = "";
  103.         private void pictureBox1_Click(object sender, EventArgs e)
  104.         {
  105.  
  106.         }
  107.  
  108.         private void btnBrowse_Click(object sender, EventArgs e)
  109.         {
  110.             if (openFileDialog1.ShowDialog() == DialogResult.OK)
  111.             {
  112.                 pictureBox1.Load(openFileDialog1.FileName);
  113.                 txtImagePath.Text = openFileDialog1.FileName;
  114.                 string Unique= Guid.NewGuid().ToString();
  115.                 fileName += Unique + openFileDialog1.SafeFileName;
  116.             }
  117.         }
  118.  
  119.         private void btnSave_Click(object sender, EventArgs e)
  120.         {
  121.             if (txtUserNo.Text.Trim() == "")
  122.             {
  123.                 MessageBox.Show("User Number is Empty");
  124.             }
  125.             else if (txtPassword.Text.Trim() == "")
  126.             {
  127.                 MessageBox.Show("Password is Empty");
  128.             }
  129.             else if (txtName1.Text.Trim() == "")
  130.             {
  131.                 MessageBox.Show("Name is Empty");
  132.             }
  133.             else if (txtSurname.Text.Trim() == "")
  134.             {
  135.                 MessageBox.Show("Surname is Empty");
  136.             }
  137.             else if (txtSalary.Text.Trim() == "")
  138.             {
  139.                 MessageBox.Show("Salary is Empty");
  140.             }
  141.             else if (cmbDepartment.SelectedIndex == -1)
  142.             {
  143.                 MessageBox.Show("Please select a department");
  144.             }
  145.             else if (cmbPosition.SelectedIndex == -1)
  146.             {
  147.                 MessageBox.Show("Please select a position");
  148.             }
  149.             else
  150.             {
  151.                 EMPLOYEE employee = new EMPLOYEE();
  152.                 employee.UserNumber = Convert.ToInt32(txtUserNo.Text);
  153.                 employee.Password = txtPassword.Text;
  154.                 employee.IsAdmin = chAdmin.Checked;
  155.                 employee.Name = txtName1.Text;
  156.                 employee.Surname = txtSurname.Text;
  157.                 employee.Salary = Convert.ToInt32(txtSalary.Text);
  158.                 employee.DepartmentID = Convert.ToInt32(cmbDepartment.SelectedValue);
  159.                 employee.PositionID = Convert.ToInt32(cmbPosition.SelectedValue);
  160.                 employee.Address = txtAddress.Text;
  161.                 employee.Birthday = dateTimePicker1.Value;
  162.                 employee.ImagePath = fileName;
  163.                 EmployeeBLL.AddEmployee(employee);
  164.                 File.Copy(txtImagePath.Text, @"images\\" + fileName);
  165.                 MessageBox.Show("Employee was added");
  166.                 txtUserNo.Clear();
  167.                 txtPassword.Clear();
  168.                 chAdmin.Checked = false;
  169.                 txtName1.Clear();
  170.                 txtSurname.Clear();
  171.                 txtSalary.Clear();
  172.                 txtAddress.Clear();
  173.                 pictureBox1.Image = null;
  174.                 combofull = false;
  175.                 cmbDepartment.SelectedIndex = -1;
  176.                 cmbPosition.DataSource = dto.Positions;
  177.                 cmbPosition.SelectedIndex = -1;
  178.                 combofull = true;
  179.                 dateTimePicker1.Value = DateTime.Today;
  180.             }
  181.         }
  182.     }
  183. }
  184.  
Advertisement
RAW Paste Data Copied
Advertisement