private void buttonYes_Click(object sender, EventArgs e) { bool flag = true; if (dataGridViewLoaiPhieuXuat.Rows[Index].Cells["ColTenLoaiPhieuXuat"].Value == null) { MessageBox.Show("Tên loại phiếu xuất không được để trống"); dataGridViewLoaiPhieuXuat.CurrentCell = dataGridViewLoaiPhieuXuat.Rows[Index].Cells["ColTenLoaiPhieuXuat"]; dataGridViewLoaiPhieuXuat.BeginEdit(true); flag = false; } if (flag) { LoaiPhieuXuatDTO loaiPhieuXuatDTO = new LoaiPhieuXuatDTO(); loaiPhieuXuatDTO.TenLoaiPhieuXuat = dataGridViewLoaiPhieuXuat.Rows[Index].Cells["ColTenLoaiPhieuXuat"].Value.ToString(); if (Status == 1) //Thêm loại phiếu xuất { loaiPhieuXuatDTO.MaLoaiPhieuXuat = LoaiPhieuXuatBUS.CreateLoaiPhieuXuatId(); dataGridViewLoaiPhieuXuat.Rows[Index].Cells["ColMaLoaiPhieuXuat"].Value = loaiPhieuXuatDTO.MaLoaiPhieuXuat; dataGridViewLoaiPhieuXuat.Rows[Index].Cells["ColSTT"].Value = (Index + 1).ToString(); if (LoaiPhieuXuatBUS.InsertLoaiPhieuXuat(loaiPhieuXuatDTO)) { dataGridViewLoaiPhieuXuat.Rows[Index].ReadOnly = true; MessageBox.Show("Thêm thành công"); } else { dataGridViewLoaiPhieuXuat.Rows.RemoveAt(Index); MessageBox.Show("Thêm thất bại"); } } else if (Status == 2) { loaiPhieuXuatDTO.MaLoaiPhieuXuat = dataGridViewLoaiPhieuXuat.Rows[Index].Cells["ColMaLoaiPhieuXuat"].Value.ToString(); if (LoaiPhieuXuatBUS.UpdateLoaiPhieuXuatById(loaiPhieuXuatDTO)) { dataGridViewLoaiPhieuXuat.Rows[Index].ReadOnly = true; MessageBox.Show("Cập nhật thành công"); } else { MessageBox.Show("Cập nhật thất bại"); dataGridViewLoaiPhieuXuat.Rows[Index].Cells["ColTenLoaiPhieuXuat"].Value = BackupThamSoDTO.TenLoaiPhieuXuat; dataGridViewLoaiPhieuXuat.Rows[Index].ReadOnly = true; } } Reset(); } else { dataGridViewLoaiPhieuXuat.BeginEdit(true); } }
private void buttonXoa_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("Xóa loại phiếu xuất", "loại phiếu xuất", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); //Lấy vị trí xóa if (result == DialogResult.Yes) { int i; Index = dataGridViewLoaiPhieuXuat.CurrentRow.Index; string id = dataGridViewLoaiPhieuXuat.CurrentRow.Cells["ColMaLoaiPhieuXuat"].Value.ToString(); int stt = int.Parse(dataGridViewLoaiPhieuXuat.CurrentRow.Cells["ColSTT"].Value.ToString()); if (LoaiPhieuXuatBUS.DeleteLoaiPhieuXuatById(id)) { dataGridViewLoaiPhieuXuat.Rows.RemoveAt(Index); if (dataGridViewLoaiPhieuXuat.Rows.Count > 0) { bool flag = false; for (i = 0; i < Index; i++) { if (dataGridViewLoaiPhieuXuat.Rows[i].Visible == true) { flag = true; } } for (i = Index; i < dataGridViewLoaiPhieuXuat.Rows.Count; i++) { if (dataGridViewLoaiPhieuXuat.Rows[i].Visible == true) { dataGridViewLoaiPhieuXuat.Rows[i].Cells["ColSTT"].Value = stt.ToString(); stt++; flag = true; } } if (flag == false) { buttonDisabled(); } } else { buttonDisabled(); } } } }
/* * Hàm Khoi Tao * Tải danh sách loại phiếu xuất */ private void KhoiTao() { List <LoaiPhieuXuatDTO> listLoaiPhieuXuatDTO = LoaiPhieuXuatBUS.SelectLoaiPhieuXuatAll(); if (listLoaiPhieuXuatDTO != null) { LoaiPhieuXuatDTO loaiPhieuXuatDTO = new LoaiPhieuXuatDTO(); dataGridViewLoaiPhieuXuat.Rows.Clear(); for (int i = 0; i < listLoaiPhieuXuatDTO.Count; i++) { loaiPhieuXuatDTO = listLoaiPhieuXuatDTO[i]; dataGridViewLoaiPhieuXuat.Rows.Add((i + 1).ToString(), loaiPhieuXuatDTO.MaLoaiPhieuXuat, loaiPhieuXuatDTO.TenLoaiPhieuXuat); dataGridViewLoaiPhieuXuat.Rows[i].ReadOnly = true; } buttonLamLai.Enabled = true; buttonEnabled(); } else { buttonLamLai.Enabled = false; buttonDisabled(); } }