private void frmSupplierSearch_Load(object sender, EventArgs e) { bSup = new bSupplier(); dgvCusList.DataSource = bSup.getAllSupplier(); FormatDataGridview(); rdoID.Checked = true; txtSearch.AutoCompleteMode = AutoCompleteMode.Suggest; txtSearch.AutoCompleteSource = AutoCompleteSource.CustomSource; }
private void frmSupplierManager_Load(object sender, EventArgs e) { //Set giao diện lúc load bSup = new bSupplier(); btnSave.Enabled = false; label2.Text = ""; //Load dữ liệu datagridview dgvSupList.DataSource = bSup.getAllSupplier(); FormatDataGridview(); setOnOffEditTextbox(0); }
//Tìm kiếm Auto Complete void AutoComplete() { if (rdoID.Checked) { foreach (eSupplier sup in bSup.getAllSupplier()) { txtSearch.AutoCompleteCustomSource.Add(sup.SupplierId); } } else if (rdoPhone.Checked) { foreach (eSupplier sup in bSup.getAllSupplier()) { txtSearch.AutoCompleteCustomSource.Add(sup.Phone); } } else { foreach (eSupplier sup in bSup.getAllSupplier()) { txtSearch.AutoCompleteCustomSource.Add(sup.SupplierName); } } }
private void btnSave_Click(object sender, EventArgs e) { if (txtSupID.Text.Length == 0 || txtSupName.Text.Length == 0 || txtPhone.Text.Length == 0 || txtAddress.Text.Length == 0) { MessageBox.Show("Không chừa trống dữ liệu nhập !", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (txtSupID.Text.KiemTraMaNCC() == false) { MessageBox.Show("Mã máy có 4 chữ số !", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } eSupplier sup = new eSupplier(); sup.SupplierId = txtSupID.Text; sup.SupplierName = txtSupName.Text; sup.Address = txtAddress.Text; sup.Phone = txtPhone.Text; if (btnSave.Text.Equals("Lưu thêm")) { try { int result = bSup.insertSupplier(sup); if (result == 1) { clearTextbox(); btnSave.Enabled = false; btnSave.Text = "Lưu"; btnSave.BackColor = Color.Gainsboro; btnNew.Text = "Thêm"; btnNew.BackColor = Color.Gainsboro; label2.Text = ""; setOnOffEditTextbox(0); btnSave.ForeColor = Color.Black; btnNew.ForeColor = Color.Black; btnUpdate.Enabled = true; btnDelete.Enabled = true; MessageBox.Show("Thêm nhà cung cấp mới thành công !", "Thêm NCC", MessageBoxButtons.OK, MessageBoxIcon.Information); dgvSupList.DataSource = bSup.getAllSupplier(); } else { MessageBox.Show("Mã nhà cung cấp bị trùng ! Vui lòng thử lại !", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { bSup.updateSupplier(sup); btnSave.Enabled = false; btnSave.Text = "Lưu"; btnSave.BackColor = Color.Gainsboro; btnUpdate.Text = "Sửa"; btnUpdate.BackColor = Color.Gainsboro; label2.Text = ""; setOnOffEditTextbox(0); btnSave.ForeColor = Color.Black; btnUpdate.ForeColor = Color.Black; btnNew.Enabled = true; btnDelete.Enabled = true; MessageBox.Show("Cập nhập nhà cung cấp thành công !", "Cập nhập", MessageBoxButtons.OK, MessageBoxIcon.Information); dgvSupList.DataSource = bSup.getAllSupplier(); } }