public frmListSupplier_Update(string code) { InitializeComponent(); statusForm = false;//form o tinh trang update Class.clsListSupplier cls = new Class.clsListSupplier(); cls.SupplierCode = code; DataTable dt = cls.tbSupplier_Get(); if (dt.Rows.Count > 0) { txtSupplierCode.Enabled = false; txtSupplierCode.Text = dt.Rows[0]["SupplierCode"].ToString(); txtSupplierName.Text = dt.Rows[0]["SupplierName"].ToString(); txtAddress.Text = dt.Rows[0]["Address"].ToString(); txtTelephone.Text = dt.Rows[0]["Telephone"].ToString(); txtMail.Text = dt.Rows[0]["Mail"].ToString(); txtGroup.Text = dt.Rows[0]["Group"].ToString(); txtContact.Text = dt.Rows[0]["Contact"].ToString(); txtNote.Text = dt.Rows[0]["Note"].ToString(); } this.Text = "Cập nhật nhà cung cấp: "+ dt.Rows[0]["SupplierName"].ToString(); }
//Xử lý nút xóa private void btnDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (gridItemDetail.FocusedRowHandle > -1) { waiting.ShowWaitForm(); string code = gridItemDetail.GetFocusedRowCellValue(colSupplierCode).ToString(); Class.clsListSupplier cls = new Class.clsListSupplier(); cls.SupplierCode = code; Class.clsListOrder clsorder = new Class.clsListOrder(); DataTable dt = new DataTable(); dt = clsorder.tbOrder_GetList(); for (int i = 0; i < dt.Rows.Count; i++) { if (dt.Rows[i]["SupplierCode"].ToString() == cls.SupplierCode) { MessageBox.Show("Nhà cung cấp này đang còn đơn hàng.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } if (MessageBox.Show("Bạn có chắc chắn muốn xoá hay không ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { try { cls.Delete(); MessageBox.Show("Xóa thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); tbSupplier_GetList(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } waiting.CloseWaitForm(); }
private void btnSaveNew_Click(object sender, EventArgs e) { Class.clsListSupplier cls = new Class.clsListSupplier(); //Ran buoc du lieu form if (txtSupplierCode.Text.Trim() == "") { MessageBox.Show("Bạn chưa nhập mã nhà cung cấp.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); txtSupplierCode.Focus(); return; } if (txtSupplierName.Text.Trim() == "") { MessageBox.Show("Bạn chưa nhập tên nhà cung cấp.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); txtSupplierName.Focus(); return; } if (statusForm) { DataTable dt = cls.tbSupplier_GetList(); for (int i = 0; i <= dt.Rows.Count - 1; i++) if (dt.Rows[i]["SupplierCode"].ToString() == txtSupplierCode.Text) { MessageBox.Show("Đã tồn tại nhà cung cấp này !", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); txtSupplierCode.Focus(); return; } //Class.clsListSupplier cls = new Class.clsListSupplier(); cls.SupplierCode = txtSupplierCode.Text; cls.SupplierName = txtSupplierName.Text; cls.Address = txtAddress.Text; cls.Telephone = txtTelephone.Text; cls.Mail = txtMail.Text; cls.Group = txtGroup.Text; cls.Contact = txtContact.Text; cls.Note = txtNote.Text; if (cls.Insert()) { MessageBox.Show("Thêm thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); save = true; //this.Close(); } else { MessageBox.Show("Thêm thất bại.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } else { //Class.clsListSupplier cls = new Class.clsListSupplier(); cls.SupplierCode = txtSupplierCode.Text; cls.SupplierName = txtSupplierName.Text; cls.Address = txtAddress.Text; cls.Telephone = txtTelephone.Text; cls.Mail = txtMail.Text; cls.Group = txtGroup.Text; cls.Contact = txtContact.Text; cls.Note = txtNote.Text; if (cls.Update()) { MessageBox.Show("Sửa thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); save = true; // this.Close(); } else { MessageBox.Show("Sửa thất bại.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } Addnew(); }
void LoadListSupplier() { Class.clsListSupplier cls = new Class.clsListSupplier(); DataTable dt = cls.tbSupplier_GetList(); cboSupplier.Properties.DataSource = dt; cboSupplier.Properties.DisplayMember = "SupplierName"; cboSupplier.Properties.ValueMember = "SupplierCode"; //cboSupplier.EditValue = dt.Rows[0]["SupplierCode"]; }
//load Grid view void tbSupplier_GetList() { Class.clsListSupplier cls = new Class.clsListSupplier(); DataTable dt = cls.tbSupplier_GetList(); gridItem.DataSource = dt; }