public BaoCaoNgayForm(QuanLyBaoCaoForm form, int id) : this() { parentForm = form; BcId = id; NgayBcTb.ReadOnly = true; BomCb.Enabled = false; NgBcCb.Enabled = false; CtrCb.Enabled = false; try { Cursor.Current = Cursors.WaitCursor; var db = new CkpEntities(); var bc = (from b in db.BaoCaoNgay where b.Id == id && b.TrangThai == 1 select b).FirstOrDefault(); //in case a record has been deleted, which cause the combo boxes selected index set to -1 //add the deleted record back to the combobox if (bc.MayBom.TrangThai == 0) { BomCb.Items.Add(bc.MayBom.Id + " - " + bc.MayBom.TenBom); BomIds.Add(bc.MayBom.Id); } if (bc.NhanVien.TrangThai == 0) { NgBcCb.Items.Add(bc.NhanVien.Id + "." + bc.NhanVien.HoTen + " - " + bc.NhanVien.ChucVu); NvIds.Add(bc.NhanVien.Id); } if (bc.CongTrinh.TrangThai == 0) { CtrCb.Items.Add(bc.CongTrinh.TenCongTrinh); CtrIds.Add(bc.CongTrinh.Id); KhCb.Items.Add(bc.KhachHang.Id + " - " + bc.KhachHang.TenCongTy); KhIds.Add(bc.KhachHang.Id); } foreach (var vb in bc.ViTriBom_BaoCao) { if (vb.ViTriBom.TrangThai == 0) { VtCb1.Items.Add(vb.ViTriBom.ViTri); VtCb2.Items.Add(vb.ViTriBom.ViTri); VtCb3.Items.Add(vb.ViTriBom.ViTri); VtIds.Add(vb.ViTriBom.Id); } } foreach (var dg in bc.CongTrinh.DonGiaBom) { if (dg.TrangThai == 0 && !DgCb1.Items.Contains(dg.TenDonGia)) { DgCb1.Items.Add(dg.TenDonGia); DgCb2.Items.Add(dg.TenDonGia); DgCb3.Items.Add(dg.TenDonGia); DgIds.Add(dg.Id); } } var cbc = (DataGridViewComboBoxColumn)NhanLucGrid.Columns[0]; foreach (var nv in bc.NhanLuc_BaoCao) { var item = nv.NhanVien.Id + "." + nv.NhanVien.HoTen; if (nv.NhanVien.TrangThai == 0 && !cbc.Items.Contains(item)) { cbc.Items.Add(item); } } NgayBcTb.Text = bc.NgayBaoCao.Value.ToString("ddMMyyyy"); BomCb.SelectedIndex = BomCb.FindStringExact(bc.MayBom.Id + " - " + bc.MayBom.TenBom); NgBcCb.SelectedIndex = NgBcCb.FindStringExact(bc.NhanVien.Id + "." + bc.NhanVien.HoTen + " - " + bc.NhanVien.ChucVu); CtrCb.SelectedIndex = CtrCb.FindStringExact(bc.CongTrinh.TenCongTrinh); KhCb.SelectedIndex = KhCb.FindStringExact(bc.KhachHang.Id + " - " + bc.KhachHang.TenCongTy); DcTb.Text = bc.CongTrinh.DiaChi; GcRtb.Text = bc.GhiChu; ViTriBom_BaoCao[] vtarr = new ViTriBom_BaoCao[] { null, null, null }; var vitri = bc.ViTriBom_BaoCao.ToList(); foreach (var dg in bc.CongTrinh.DonGiaBom.Where(d => d.TrangThai == 1)) { DgCb1.Items.Add(dg.TenDonGia); DgCb2.Items.Add(dg.TenDonGia); DgCb3.Items.Add(dg.TenDonGia); DgIds.Add(dg.Id); } for (int i = 0; i < vitri.Count; i++) { vtarr[i] = vitri[i]; if (vtarr[0] != null) { VtCb1.SelectedIndex = VtCb1.FindStringExact(vtarr[0].ViTriBom.ViTri); TangTb1.Text = vtarr[0].Tang.HasValue ? vtarr[0].Tang.Value.ToString() : ""; SlTb1.Text = vtarr[0].SoLuong.HasValue ? vtarr[0].SoLuong.Value.ToString() : ""; DvCb1.SelectedIndex = DvCb1.FindStringExact(vtarr[0].DonVi); DgTtTb1.Text = vtarr[0].DonGia.HasValue ? vtarr[0].DonGia.Value.ToString("N0") : ""; DgStTb1.Text = vtarr[0].DonGiaVat.HasValue ? vtarr[0].DonGiaVat.Value.ToString("N0") : ""; DgCb1.SelectedIndex = vtarr[0].DonGiaId.HasValue ? DgCb1.FindStringExact(vtarr[0].DonGiaBom.TenDonGia) : -1; GcTb1.Text = vtarr[0].GhiChu; TangTb1.Enabled = true; SlTb1.Enabled = true; DvCb1.Enabled = true; DgTtTb1.Enabled = true; DgStTb1.Enabled = true; GcTb1.Enabled = true; DgCb1.Enabled = true; } if (vtarr[1] != null) { VtCb2.SelectedIndex = VtCb2.FindStringExact(vtarr[1].ViTriBom.ViTri); TangTb2.Text = vtarr[1].Tang.HasValue ? vtarr[1].Tang.Value.ToString() : ""; SlTb2.Text = vtarr[1].SoLuong.HasValue ? vtarr[1].SoLuong.Value.ToString() : ""; DvCb2.SelectedIndex = DvCb2.FindStringExact(vtarr[1].DonVi); DgTtTb2.Text = vtarr[1].DonGia.HasValue ? vtarr[1].DonGia.Value.ToString("N0") : ""; DgStTb2.Text = vtarr[1].DonGiaVat.HasValue ? vtarr[1].DonGiaVat.Value.ToString("N0") : ""; DgCb2.SelectedIndex = vtarr[1].DonGiaId.HasValue ? DgCb2.FindStringExact(vtarr[1].DonGiaBom.TenDonGia) : -1; GcTb2.Text = vtarr[1].GhiChu; TangTb2.Enabled = true; SlTb2.Enabled = true; DvCb2.Enabled = true; DgTtTb2.Enabled = true; DgStTb2.Enabled = true; GcTb2.Enabled = true; DgCb2.Enabled = true; } if (vtarr[2] != null) { VtCb3.SelectedIndex = VtCb3.FindStringExact(vtarr[2].ViTriBom.ViTri); TangTb3.Text = vtarr[2].Tang.HasValue ? vtarr[2].Tang.Value.ToString() : ""; SlTb3.Text = vtarr[2].SoLuong.HasValue ? vtarr[2].SoLuong.Value.ToString() : ""; DvCb3.SelectedIndex = DvCb3.FindStringExact(vtarr[2].DonVi); DgTtTb3.Text = vtarr[2].DonGia.HasValue ? vtarr[2].DonGia.Value.ToString("N0") : ""; DgStTb3.Text = vtarr[2].DonGiaVat.HasValue ? vtarr[2].DonGiaVat.Value.ToString("N0") : ""; DgCb3.SelectedIndex = vtarr[2].DonGiaId.HasValue ? DgCb3.FindStringExact(vtarr[2].DonGiaBom.TenDonGia) : -1; GcTb3.Text = vtarr[2].GhiChu; TangTb3.Enabled = true; SlTb3.Enabled = true; DvCb3.Enabled = true; DgTtTb3.Enabled = true; DgStTb3.Enabled = true; GcTb3.Enabled = true; DgCb3.Enabled = true; } } if (DgCb1.SelectedIndex != -1) { DgInfoBtn1.Enabled = true; } if (DgCb2.SelectedIndex != -1) { DgInfoBtn2.Enabled = true; } if (DgCb3.SelectedIndex != -1) { DgInfoBtn3.Enabled = true; } foreach (var nl in bc.NhanLuc_BaoCao) { NhanLucGrid.Rows.Add( nl.NhanVien.Id + "." + nl.NhanVien.HoTen, nl.KhoiLuongBom, nl.DonGiaKhoi); } Cursor.Current = Cursors.Default; } catch (Exception ex) { Cursor.Current = Cursors.Default; MessageBox.Show(ex.GetBaseException().Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void QlyBaoCaoBtn_Click(object sender, EventArgs e) { var form = new QuanLyBaoCaoForm(); form.Show(); }