public bool Update(PHIEU_THANH_LY ptl) { try { SqlConnection con = new SqlConnection(db.connectionStr); SqlCommand cmd = new SqlCommand("update_PhieuTL", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@ptl_id", SqlDbType.NVarChar, 50); cmd.Parameters.Add("@nhacc_id", SqlDbType.NVarChar, 20); cmd.Parameters.Add("@kho_id", SqlDbType.NVarChar, 20); cmd.Parameters.Add("@httl", SqlDbType.NVarChar, 50); cmd.Parameters.Add("@ngaytl", SqlDbType.DateTime); cmd.Parameters.Add("@ghichu", SqlDbType.NVarChar, 200); cmd.Parameters["@ptl_id"].Value = ptl.Ptl_id; cmd.Parameters["@nhacc_id"].Value = ptl.Nhacc; cmd.Parameters["@kho_id"].Value = ptl.Kho_id; cmd.Parameters["@httl"].Value = ptl.Httl; cmd.Parameters["@ngaytl"].Value = ptl.Ptl_ngay; cmd.Parameters["@ghichu"].Value = ptl.Ptl_ghichu; con.Open(); int result = cmd.ExecuteNonQuery(); con.Close(); return(result > 0); } catch { } return(true); }
public bool Insert(PHIEU_THANH_LY ptl) { try { SqlConnection con = new SqlConnection(db.connectionStr); SqlCommand cmd = new SqlCommand("insert_PhieuTL", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@ptl_id", SqlDbType.NVarChar, 50); cmd.Parameters.Add("@nhacc_id", SqlDbType.NVarChar, 20); cmd.Parameters.Add("@kho_id", SqlDbType.NVarChar, 20); cmd.Parameters.Add("@httl", SqlDbType.NVarChar, 50); cmd.Parameters.Add("@ngaytl", SqlDbType.DateTime); cmd.Parameters.Add("@ghichu", SqlDbType.NVarChar, 200); cmd.Parameters["@ptl_id"].Value = ptl.Ptl_id; cmd.Parameters["@nhacc_id"].Value = ptl.Nhacc; cmd.Parameters["@kho_id"].Value = ptl.Kho_id; cmd.Parameters["@httl"].Value = ptl.Httl; cmd.Parameters["@ngaytl"].Value = ptl.Ptl_ngay; cmd.Parameters["@ghichu"].Value = ptl.Ptl_ghichu; con.Open(); int result = cmd.ExecuteNonQuery(); con.Close(); return(result > 0); } catch { if (KiemTraTrung(ptl.Ptl_id) != 0) { MessageBox.Show("Thêm không thành công do trùng mã phiếu thanh lý", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } return(false); }
private void btnLuu_Click(object sender, EventArgs e) { if (KiemTraRong() == "") { PHIEU_THANH_LY ptl = LayTTPTL(); if (dieukien) { if (daoPTL.Insert(ptl)) { MessageBox.Show("Thêm thành công"); lbMAPTL.Text = txtMaPTL.Text; xuLyControl(true); txtMaPTL.ReadOnly = true; } } else { if (daoPTL.Update(ptl)) { MessageBox.Show("Sửa thành công"); xuLyControl(true); txtMaPTL.ReadOnly = true; } } GetPhieuNhap(); } }
private PHIEU_THANH_LY LayTTPTL() { string ma_ptl = txtMaPTL.Text; string httl_ma = cbbHTTL.Text; DateTime ngay = dtpNgayTL.Value; string kho_id = cbbKho.SelectedValue.ToString(); string ncc_id = cbbNhaCC.SelectedValue.ToString(); string ghichu = txtGhiChu.Text; PHIEU_THANH_LY ptl = new PHIEU_THANH_LY(ma_ptl, ncc_id, kho_id, httl_ma, ngay, ghichu); return(ptl); }