Пример #1
0
        private void cmbPage_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.currentPageIndex = Convert.ToInt32(cmbPage.SelectedItem.ToString());
            lbCurrentPage.Text    = this.currentPageIndex.ToString();
            this.firstRow         = this.pageSize * (this.currentPageIndex - 1); //Dong dau
            this.lastRow          = this.pageSize * (this.currentPageIndex);     //Dong cuoi cua 1 trang duoc chon.
            //MessageBox.Show(fistRow + " " + lastRow);
            bool    isSort   = cbSort.Checked;
            bool    isSearch = cbSearch.Checked;
            string  ten      = txtSearch.Text;
            DataSet ds       = new DataSet();

            myNhanVienBUL.CurrentRecords(isSort, isSearch, ten, ds, firstRow, pageSize);
            var empList = ds.Tables[0].AsEnumerable().Select(dataRow => new NhanVienDTO {
                ID                   = dataRow.Field <int>("ID"),
                HoTen                = dataRow.Field <string>("HoTen"),
                Khoa_PhongBan        = dataRow.Field <string>("Khoa_PhongBan"),
                TrinhDo_ChucVu       = dataRow.Field <int>("TrinhDo_ChucVu"),
                PhuCap               = dataRow.Field <int>("PhuCap"),
                SoTietDay_SoNgayCong = dataRow.Field <int>("SoTietDay_SoNgayCong"),
                HeSoLuong            = (float)dataRow.Field <double>("HeSoLuong"),
                TongLuong            = (float)dataRow.Field <double>("TongLuong"),
                LoaiNhanVien         = dataRow.Field <int>("LoaiNhanVien"),
            }).ToList();

            List <NhanVienDTO> list = empList;
            DataTable          dt   = new DataTable();

            dt.Columns.Add("ID", typeof(string));
            dt.Columns.Add("Họ tên", typeof(string));
            dt.Columns.Add("Khoa - Phòng ban", typeof(string));
            dt.Columns.Add("Trình độ - Chức vụ", typeof(string));
            dt.Columns.Add("Phụ cấp", typeof(int));
            dt.Columns.Add("Số tiết dạy - Số ngày công", typeof(int));
            dt.Columns.Add("Tổng lương", typeof(float));
            foreach (NhanVienDTO item in list)
            {
                DataRow dr = dt.NewRow();
                dr["ID"]                         = item.ID;
                dr["Họ tên"]                     = item.HoTen;
                dr["Khoa - Phòng ban"]           = item.Khoa_PhongBan;
                dr["Trình độ - Chức vụ"]         = convertTrinhDo(item.LoaiNhanVien.ToString(), item.TrinhDo_ChucVu.ToString());
                dr["Phụ cấp"]                    = item.PhuCap;
                dr["Số tiết dạy - Số ngày công"] = item.SoTietDay_SoNgayCong;
                dr["Tổng lương"]                 = item.TongLuong;
                dt.Rows.Add(dr);
            }

            dgv.DataSource = dt;
        }