Exemplo n.º 1
0
 private void btnOkSua_Click(object sender, EventArgs e)
 {
     if ((txtMaSach.Text != "") && (txtTenSach.Text != "") && (txtNamXB.Text != "") && (txtSoTrang.Text != "") && (txtGia.Text != "") && (txtSoBan.Text != "") && (txtSoBanTon.Text != "") && (cboTacGia.SelectedValue != null) && (cboTheLoai.SelectedValue != null) && (cboNXB.SelectedValue != null))
     {
         try
         {
             Sach_DTO sach = new Sach_DTO(txtMaSach.Text, txtTenSach.Text, Convert.ToString(cboTacGia.SelectedValue), Convert.ToString(cboTheLoai.SelectedValue), Convert.ToString(cboNXB.SelectedValue), Convert.ToInt32(txtNamXB.Text), Convert.ToInt32(txtSoTrang.Text), Convert.ToInt32(txtGia.Text), Convert.ToInt32(txtSoBan.Text), Convert.ToInt32(txtSoBanTon.Text));
             BUS_OBJ.suaSach(sach);
             HienThiDuLieu();
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
         finally
         {
             btnCancel_Click(sender, e);
             //if (conn.State == ConnectionState.Open) conn.Close();
         }
     }
     else
     {
         if (cboTacGia.SelectedValue == null)
         {
             MetroFramework.MetroMessageBox.Show(this, "Chưa có tác giả này.", "Lỗi.", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             cboTacGia.Focus();
         }
         else if (cboTheLoai.SelectedValue == null)
         {
             MetroFramework.MetroMessageBox.Show(this, "Chưa có thể loại này.", "Lỗi.", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             cboTheLoai.Focus();
         }
         else if (cboNXB.SelectedValue == null)
         {
             MetroFramework.MetroMessageBox.Show(this, "Chưa có NXB này.", "Lỗi.", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             cboNXB.Focus();
         }
         else
         {
             MetroFramework.MetroMessageBox.Show(this, "Nhập thiếu dữ liệu.", "Lỗi.", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             if (txtSoBanTon.Text == "")
             {
                 txtSoBanTon.Focus();
             }
             if (txtSoBan.Text == "")
             {
                 txtSoBan.Focus();
             }
             if (txtGia.Text == "")
             {
                 txtGia.Focus();
             }
             if (txtSoTrang.Text == "")
             {
                 txtSoTrang.Focus();
             }
             if (txtNamXB.Text == "")
             {
                 txtNamXB.Focus();
             }
             if (txtTenSach.Text == "")
             {
                 txtTenSach.Focus();
             }
             if (txtMaSach.Text == "")
             {
                 txtMaSach.Focus();
             }
         }
     }
 }