Example #1
0
 private void txtMaSach_KeyUp(object sender, KeyEventArgs e)
 {
     if (txtMaSach.Text != "")
     {
         int     masach = Convert.ToInt32(txtMaSach.Text);
         SachDTO sach   = sachBUS.LaySachTonKhoTheoMa(masach);
         if (sach.MaSach == 0)
         {
             MessageBox.Show("Không có mã sách này!");
             txtMaSach.Clear();
         }
         else
         {
             txtTenSach.Text = sach.Ten;
             int rowIndex = -1;
             for (var i = 0; i < dgvCTHDBanHang.Rows.Count; i++)
             {
                 if (Convert.ToInt32(dgvCTHDBanHang.Rows[i].Cells["colMaSach"].Value) == sach.MaSach)
                 {
                     rowIndex = i;
                     break;
                 }
             }
             if (rowIndex == -1)
             {
                 txtSoLuong.Text = sach.SoLuong.ToString();
             }
             else
             {
                 txtSoLuong.Text = (sach.SoLuong - Convert.ToInt32(dgvCTHDBanHang.Rows[rowIndex].Cells["colSoLuong"].Value)).ToString();
             }
             txtGiaBia.Text = sach.GiaBia.ToString();
             txtSLBan.Text  = "1";
         }
     }
     else
     {
         txtTenSach.Clear();
         txtSoLuong.Clear();
         txtGiaBia.Clear();
         txtSLBan.Clear();
     }
 }