private NguyenLieu getDataNL() { NguyenLieu nl = new NguyenLieu(); float dg = 0; int sl = 0; nl.MaNL = txtMaNL.Text; nl.TenNL = txtTenNL.Text; dg = float.Parse(txtDonGia.Text); nl.DonGia = dg; sl = int.Parse(txtSoLuongCon.Text); nl.DonViTinh = cbDVT.Text; nl.SoLuongCon = sl; return(nl); }
private void btnXoa_Click(object sender, EventArgs e) { NguyenLieu nl = getDataNL(); if (MessageBox.Show("Bạn có chắc muốn xóa nguyên liệu này?", "Xác Nhận", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { if (nlBO.XoaNL(nl)) { MessageBox.Show("Xóa thành công"); } else { MessageBox.Show("Không thể xóa"); } } bindData(); }
private void btnLuu_Click(object sender, EventArgs e) { NguyenLieu nl = getDataNL(); if (txtMaNL.Text == "" || txtDonGia.Text == "" || cbDVT.Text == "" || txtSoLuongCon.Text == "" || txtTenNL.Text == "") { MessageBox.Show("Bạn cần nhập đủ thông tin"); } else { if (btnSua.Enabled == false) { if (nlBO.kiemTraNL(txtMaNL.Text) == false) { if (nlBO.ThemNL(nl)) { MessageBox.Show("Thêm thành công"); } else { MessageBox.Show("Lỗi nhập dữ liệu"); } } else { MessageBox.Show("Đã có mã nguyên liệu " + txtMaNL.Text + " trong hệ thống"); } } else { if (nlBO.SuaNL(nl)) { MessageBox.Show("Sửa thành công"); } else { MessageBox.Show("Không thể sửa thông tin"); } } } bindData(); btnSua.Enabled = true; }