private void btn_searchHT_Click_1(object sender, EventArgs e) { string item = txt_searchHT.Text.Trim(); HangTonBLL hangBLL = new HangTonBLL(); grvHangTon.DataSource = hangBLL.Search(item); }
public void Load_Data_HangTon() { HangTonBLL hangBLL = new HangTonBLL(); grvHangTon.DataSource = hangBLL.GetData(); txtIDHANG.Enabled = false; txtTenHang.Enabled = false; txtDVT.Enabled = false; txtSoLuong.Enabled = false; txtGiaNhap.Enabled = false; txtGiaXuat.Enabled = false; }
private void Excute_HT(string query) { if (query == "insert") { try { HangTon ht = new HangTon(); //mã tự động tăng int count = 0; count = grvHangTon.Rows.Count; //đếm tất cả các dòng của data grv rồi gán cho count string str = ""; int str2 = 0; str = Convert.ToString(grvHangTon.Rows[count - 2].Cells[0].Value); str2 = Convert.ToInt32((str.Remove(0, 1))); if (str2 + 1 < 10) { ht.IDHANG = txtIDHANG.Text = "H00" + (str2 + 1).ToString(); } else if (str2 + 1 < 100) { ht.IDHANG = txtIDHANG.Text = "H0" + (str2 + 1).ToString(); } // //// ht.TenMatHang = txtTenHang.Text.Trim(); ht.DonViTinh = txtDVT.Text.Trim(); //ht.SoLuong = int.Parse(txtSoLuong.ToString()); //ht.GiaNhap = int.Parse(txtGiaNhap.ToString()); //ht.GiaXuat = int.Parse(txtGiaXuat.ToString()); HangTonBLL hangBLL = new HangTonBLL(); // //check xem co trung hay khong if (!(hangBLL.CheckID(txtIDHANG.Text.Trim()))) { hangBLL.Insert(ht); Load_Data_HangTon(); MessageBox.Show("Thêm thành công", "Thông báo", MessageBoxButtons.OK); } else { MessageBox.Show("Mã " + txtIDHANG.Text.Trim() + " đã tồn tại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { MessageBox.Show("Thêm bị lỗi: " + ex.Message.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } if (query == "update") { try { HangTon ht = new HangTon(); ht.IDHANG = txtIDHANG.Text.Trim(); ht.TenMatHang = txtTenHang.Text.Trim(); ht.DonViTinh = txtDVT.Text.Trim(); //ht.SoLuong = int.Parse(txtSoLuong.ToString()); //ht.GiaNhap = int.Parse(txtGiaNhap.ToString()); //ht.GiaXuat = int.Parse(txtGiaXuat.ToString()); // // HangTonBLL hangBLL = new HangTonBLL(); hangBLL.Update(ht); Load_Data_HangTon(); MessageBox.Show("Sửa thành công", "Thông báo", MessageBoxButtons.OK); } catch (Exception ex) { MessageBox.Show("Sửa bị lỗi: " + ex.Message.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } if (query == "delete") { try { string id = txtIDHANG.Text.Trim(); HangTonBLL hangBLL = new HangTonBLL(); hangBLL.Delete(id); Load_Data_HangTon(); MessageBox.Show("Đã xóa thành công:"); } catch (Exception ex) { MessageBox.Show("Không thể xóa: " + ex.Message.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }