/* * - Khi bấm cập nhật hóa đơn thêm sản phẩm thì sẽ kiểm tra thông tin đầy đủ với chính xác chưa nếu chưa thì sẽ xuất ra messagbox * - Ngược lại sẽ lưu dữ liệu vào model rv và thực hiện việc cập nhật qua class ReceiveNoteDao * - Nếu thực hiện thành công thì sẽ load lại dữ liệu và trả lại trạng thái ban đầu của các textbox và button * - Nếu thực hiện không thành công thì sẽ xuất ra MessageBox */ private void bt_capNhat_quanLyNhapSanPham_Click(object sender, EventArgs e) { if (!checkInfo()) { MessageBox.Show("Hãy điền đủ và chính xác thông tin"); return; } else { model.ReceiveNote rv = new model.ReceiveNote(); rv.id_employee = int.Parse(lb_maNhanVien_quanLySanPhamNhanVien.Text.ToString()); rv.id_product = tb_maSanPham_quanLyNhapSanPham.Text.ToString(); rv.amount = int.Parse(tb_soLuong_quanLyNhapSanPham.Text.ToString()); rv.total_price_receive = float.Parse(tb_gia_quanLyNhapSanPham.Text.ToString()); rv.date_receive = dtp_ngayNhap_quanLyNhapSanPham.Value; rv.name_provider = tb_nhaCungCap_quanLyNhapSanPham.Text.ToString(); rv.address_provider = tb_diaChi_quanLyNhapSanPham.Text.ToString(); rv.phone_number_provider = tb_sdtNhaCungCap_quanLyNhapSanPham.Text.ToString(); if (receive_note_dao.updateById(rv, id)) { if (product_dao.updateAmountProduct(rv.id_product, amount, rv.amount)) { MessageBox.Show("Cập nhật hóa đơn nhập sản phẩm thành công"); dgv_sanPham_quanLyNhapSanPham.ClearSelection(); loadData(); bt_refresh_quanLyNhapSanPham_Click(null, null); commandButtonManagement.notAdjustItem(); notifyOtherControlDataChange(TypeDataChange.PRODUCT); return; } else { MessageBox.Show("Cập nhật hóa đơn nhập sản phẩm không thành công"); return; } } else { MessageBox.Show("Cập nhật hóa đơn nhập sản phẩm không thành công"); return; } } }
//Add new receive note public bool addReceiveNote(model.ReceiveNote receive_note) { String sql = "insert into RECEIVEDNOTE values(@idEmployee, @idProduct, @amount, @price, @date, @nameProvider, @address, @phone)"; DbParameter param1 = df.createParam("@idEmployee", receive_note.id_employee); DbParameter param2 = df.createParam("@idProduct", receive_note.id_product); DbParameter param3 = df.createParam("@amount", receive_note.amount); DbParameter param4 = df.createParam("@price", receive_note.total_price_receive); DbParameter param5 = df.createParam("@date", receive_note.date_receive); DbParameter param6 = df.createParam("@nameProvider", receive_note.name_provider); DbParameter param7 = df.createParam("@address", receive_note.address_provider); DbParameter param8 = df.createParam("@phone", receive_note.phone_number_provider); DbParameter[] parameters = { param1, param2, param3, param4, param5, param6, param7, param8 }; int rows = receive_note_helper.insertUpdateDelete(sql, parameters); return(rows == 1); }
//update receive note by id receive note public bool updateById(model.ReceiveNote receive_note, int id) { String sql = "update RECEIVEDNOTE set ID_EMPLOYEE = @idEmployee, ID_PRODUCT = @idProduct, AMOUNT = @amount " + ",TOTAL_PRICE_RECEIVE = @price, DATE_RECIVE = @date, NAME_PROVIDER = @nameProvider, PROVIDER_ADDRESS = @address," + "PHONE_NUMBER_PROVIDER = @phone where ID_RECEIVE like @id "; DbParameter param1 = df.createParam("@idEmployee", receive_note.id_employee); DbParameter param2 = df.createParam("@idProduct", receive_note.id_product); DbParameter param3 = df.createParam("@amount", receive_note.amount); DbParameter param4 = df.createParam("@price", receive_note.total_price_receive); DbParameter param5 = df.createParam("@date", receive_note.date_receive); DbParameter param6 = df.createParam("@nameProvider", receive_note.name_provider); DbParameter param7 = df.createParam("@address", receive_note.address_provider); DbParameter param8 = df.createParam("@phone", receive_note.phone_number_provider); DbParameter param9 = df.createParam("@id", id); DbParameter[] parameters = { param1, param2, param3, param4, param5, param6, param7, param8, param9 }; int rows = receive_note_helper.insertUpdateDelete(sql, parameters); return(rows == 1); }