예제 #1
0
 public int CompareTo(NgayGio ngayGio)
 {
     if (this.Nam > ngayGio.Nam)
     {
         return(1);
     }
     else if (this.Nam == ngayGio.Nam)
     {
         if (this.Thang > ngayGio.Thang)
         {
             return(1);
         }
         else if (this.Thang == ngayGio.Thang)
         {
             if (this.Ngay > ngayGio.Ngay)
             {
                 return(1);
             }
             else if (this.Ngay == ngayGio.Ngay)
             {
                 return(0);
             }
         }
     }
     return(-1);
 }
예제 #2
0
 public NhanVien(string hoTen, string chucVu, NgayGio ngaySinh, double heSoLuong)
 {
     this.HoTen     = hoTen;
     this.ChucVu    = chucVu;
     this.NgaySinh  = ngaySinh;
     this.HeSoLuong = heSoLuong;
 }
예제 #3
0
        public static NgayGio Parse(string chuoiCanChuyen)
        {
            string[] chuoiNgayGio = chuoiCanChuyen.Split('/');

            NgayGio ngayGio = new NgayGio(int.Parse(chuoiNgayGio[0]), int.Parse(chuoiNgayGio[1]), int.Parse(chuoiNgayGio[2]));

            return(ngayGio);
        }
예제 #4
0
        }// Sap xep theo he so luong

        private void QuickSortEmployeeByYearOld(int left, int right, int typeSort)
        {
            int i = left, j = right;

            NgayGio middleNgaySinh = this[(i + j) / 2].NgaySinh;

            while (i <= j)
            {
                if (typeSort == 1)
                {
                    while (this[i].NgaySinh.CompareTo(middleNgaySinh) > 0)
                    {
                        i++;
                    }

                    while (this[j].NgaySinh.CompareTo(middleNgaySinh) < 0)
                    {
                        j--;
                    }
                }
                else
                {
                    while (this[i].NgaySinh.CompareTo(middleNgaySinh) < 0)
                    {
                        i++;
                    }

                    while (this[j].NgaySinh.CompareTo(middleNgaySinh) > 0)
                    {
                        j--;
                    }
                }


                if (i <= j)
                {
                    Swap(this[i], this[j]);

                    i++;
                    j--;
                }
            }

            if (left < j)
            {
                QuickSortEmployeeByYearOld(left, j, typeSort);
            }

            if (i < right)
            {
                QuickSortEmployeeByYearOld(i, right, typeSort);
            }
        }// Sap xep theo tuổi (dua vao ngay sinh)
예제 #5
0
        private void dgvDanhSachNhanVien_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > -1 && e.ColumnIndex == 4)
            {
                if (MessageBox.Show("Bạn có chắc muốn xóa nhân viên này không?", "Cảnh báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation) == DialogResult.OK)
                {
                    NhanVien employee = new DoAnThucTapCoSo.NhanVien();
                    employee.HoTen     = dgvDanhSachNhanVien.SelectedCells[0].OwningRow.Cells["clHoTen"].Value.ToString();
                    employee.NgaySinh  = NgayGio.Parse(dgvDanhSachNhanVien.SelectedCells[0].OwningRow.Cells["clNgaySinh"].Value.ToString());
                    employee.ChucVu    = dgvDanhSachNhanVien.SelectedCells[0].OwningRow.Cells["clChucVu"].Value.ToString();
                    employee.HeSoLuong = double.Parse(dgvDanhSachNhanVien.SelectedCells[0].OwningRow.Cells["clHeSoLuong"].Value.ToString());

                    danhSachNhanVien.Delete(employee);

                    ShowDataToDatagridView(this.danhSachNhanVien);

                    isSaved = false;
                }
            }
        }
예제 #6
0
        private void LoadDataFromFile(string filePath)// Đọc dữ liệu từ file và đưa lên datagridview
        {
            //try
            {
                StreamReader sr = new StreamReader(filePath, Encoding.UTF8);

                int countLine = 0;

                string thongTinDocDuoc;

                while ((thongTinDocDuoc = sr.ReadLine()) != null)
                {
                    countLine++;
                    if (thongTinDocDuoc.Contains("Họ và tên\t\tChức vụ\t\tNgày sinh\tHệ số lương"))
                    {
                        continue;
                    }

                    if (thongTinDocDuoc == "")
                    {
                        continue;
                    }

                    string[] nhanVienString = thongTinDocDuoc.Split('\t');

                    string[] thongTinNhanVien = new string[nhanVienString.Length];

                    int j = 0;
                    foreach (string item in nhanVienString)
                    {
                        if (item == "")
                        {
                            continue;
                        }
                        else
                        {
                            thongTinNhanVien[j] = item.Trim();
                            j++;
                        }
                    }

                    NgayGio  ngaySinh;
                    NhanVien nhanVien;
                    try
                    {
                        ngaySinh = NgayGio.Parse(thongTinNhanVien[2]);
                    }
                    catch (NgayGioException)
                    {
                        MessageBox.Show("Tại dòng " + countLine + ": Ngày sinh không hợp lệ\n" + NgayGioException.ErrorMessage, "Lỗi định dạng ngày giờ khi lấy dữ liệu từ file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        sr.Close();
                        return;
                    }
                    try
                    {
                        nhanVien = new NhanVien(thongTinNhanVien[0], thongTinNhanVien[1], ngaySinh, double.Parse(thongTinNhanVien[3]));

                        danhSachNhanVien.AddLast(nhanVien);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Tại dòng " + countLine + ":\n" + "Hệ số lương phải là số", "Lỗi định dạng hệ số lương khi lấy dữ liệu từ file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        sr.Close();
                        return;
                    }

                    thongTinDocDuoc = sr.ReadLine();
                }

                sr.Close();

                ShowDataToDatagridView(this.danhSachNhanVien);
            }
        }
예제 #7
0
 public NhanVien()
 {
     NgaySinh = new NgayGio();
 }