private void btnChiTietPn_Click(object sender, EventArgs e) { try { bool maddh = f.CheckNullValueTextEdit(madhTbox); bool mavt = f.CheckNullValueTextEdit(MavtTbox); bool soluongnhap = f.CheckNullValue(SoluongTbox); bool dongia = f.CheckNullValue(DongiaTbox); if (maddh && mavt && soluongnhap && dongia) // check null value { int soluong = Int32.Parse(SoluongTbox.Text.ToString()); decimal tong_gianhap = Convert.ToDecimal(DongiaTbox.Text.ToString()); bool check_soluongnhap = CheckSoluongNhap(soluong); bool check_dongia = CheckGiaNhap(tong_gianhap); if (check_soluongnhap)// check so luong nhap so voi so luong trong don hang` { if (check_dongia) { if (gridViewChiTietPhieuNhap.RowCount == 0) { chitietPN.Rows.Add(madhTbox.Text, MavtTbox.Text, TenVTTbox.Text, soluong, (tong_gianhap * soluong), DonviTbox.Text); gridControl1.DataSource = chitietPN; gridControl1.DataBindings.Clear(); } else { for (int j = 0; j < gridViewChiTietPhieuNhap.RowCount; j++) { if (MavtTbox.Text.ToString() == (gridViewChiTietPhieuNhap.GetRowCellValue(j, gridViewChiTietPhieuNhap.Columns[1]).ToString())) { //int soluong_truocdo_trongPN = Int32.Parse(gridViewChiTietPhieuNhap.GetRowCellValue(j, gridViewChiTietPhieuNhap.Columns[3]).ToString());// số lượng trước đó trong CT phiếu nhập //int soluong_lan2_cuaPN_theoVT = soluong + soluong_truocdo_trongPN; //bool check_nhaplan2_theoma = CheckSoluongNhapLan2TheoMa(soluong_lan2_cuaPN_theoVT); gridViewChiTietPhieuNhap.DeleteRow(j); chitietPN.Rows.Add(madhTbox.Text, MavtTbox.Text, TenVTTbox.Text, soluong, (tong_gianhap * soluong), DonviTbox.Text); gridControl1.DataSource = chitietPN; gridControl1.DataBindings.Clear(); break; } else { if (j == (gridViewChiTietPhieuNhap.RowCount - 1)) { chitietPN.Rows.Add(madhTbox.Text, MavtTbox.Text, TenVTTbox.Text, soluong, (tong_gianhap * soluong), DonviTbox.Text); gridControl1.DataSource = chitietPN; gridControl1.DataBindings.Clear(); break; } } } } for (int j = 0; j < 6; j++) { gridViewChiTietPhieuNhap.Columns[j].OptionsColumn.AllowEdit = false; gridViewChiTietPhieuNhap.Columns[4].OptionsColumn.AllowEdit = true; } } } } } catch { MessageBox.Show("co loi"); } }