private void mAHANGDataGridView_CellClick(object sender, DataGridViewCellEventArgs e) { bool kt = true; int index = mAHANGDataGridView.CurrentCell.RowIndex; int sltru = Int32.Parse(mAHANGDataGridView.Rows[index].Cells[2].Value.ToString()); sltru--; mAHANGDataGridView.Rows[index].Cells[2].Value = sltru; for (int i = 0; i < DGV_GioHang.Rows.Count; i++) { if (mAHANGDataGridView.Rows[index].Cells[0].Value.ToString() == DGV_GioHang.Rows[i].Cells[0].Value.ToString()) { int slcong = Int32.Parse(DGV_GioHang.Rows[i].Cells[2].Value.ToString()); slcong++; DGV_GioHang.Rows[i].Cells[2].Value = slcong; kt = false; break; } } if (kt) { int row = 0; DGV_GioHang.Rows.Add(); row = DGV_GioHang.Rows.Count - 1; DGV_GioHang.Rows[row].Cells[0].Value = mAHANGDataGridView.Rows[index].Cells[0].Value.ToString(); DGV_GioHang.Rows[row].Cells[1].Value = mAHANGDataGridView.Rows[index].Cells[1].Value.ToString(); DGV_GioHang.Rows[row].Cells[2].Value = 1; DGV_GioHang.Rows[row].Cells[3].Value = mAHANGDataGridView.Rows[index].Cells[3].Value.ToString(); DGV_GioHang.Refresh(); } xuLy_TongTien_ThanhToan_No(); }
private void GV_MatHang_CellClick(object sender, DataGridViewCellEventArgs e) { try { bool kt = true; int index = GV_MatHang.CurrentCell.RowIndex; int sltru = Int32.Parse(GV_MatHang.Rows[index].Cells[2].Value.ToString()); sltru--; GV_MatHang.Rows[index].Cells[2].Value = sltru; for (int i = 0; i < DGV_GioHang.Rows.Count; i++) { if (GV_MatHang.Rows[index].Cells[0].Value.ToString() == DGV_GioHang.Rows[i].Cells[0].Value.ToString()) { int slcong = Int32.Parse(DGV_GioHang.Rows[i].Cells[2].Value.ToString()); slcong++; DGV_GioHang.Rows[i].Cells[2].Value = slcong; kt = false; break; } } if (kt) { int row = 0; DGV_GioHang.Rows.Add(); row = DGV_GioHang.Rows.Count - 1; DGV_GioHang.Rows[row].Cells[0].Value = GV_MatHang.Rows[index].Cells[0].Value.ToString(); DGV_GioHang.Rows[row].Cells[1].Value = GV_MatHang.Rows[index].Cells[1].Value.ToString(); DGV_GioHang.Rows[row].Cells[2].Value = 1; DGV_GioHang.Rows[row].Cells[3].Value = GV_MatHang.Rows[index].Cells[3].Value.ToString(); DGV_GioHang.Refresh(); } xuLy_TongTien_ThanhToan_No(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }