public bool suaCTPT(DTO_CTPhieuTra tv) { try { // Ket noi connect.Open(); // Query string string SQL = string.Format("UPDATE CTPT " + "SET MASP = '{1}', SOLUONG = {2}, THANHTIEN = {3} " + "WHERE MAPT= '{0}' ", tv.MAPT, tv.MASP, tv.SOLUONG, tv.THANHTIEN); // Command (mặc định command type = text nên chúng ta khỏi fải làm gì nhiều). SqlCommand cmd = new SqlCommand(SQL, connect); // Query và kiểm tra if (cmd.ExecuteNonQuery() > 0) { return(true); } } catch (Exception e) { } finally { // Dong ket noi connect.Close(); } return(false); }
public bool themCTPT(DTO_CTPhieuTra tv)// THẮNG { try { // Ket noi connect.Open(); string SQL = string.Format("INSERT INTO CTPT(MAPT,MASP,SOLUONG,THANHTIEN) " + "VALUES ('{0}', '{1}', {2} , {3} )", tv.MAPT, tv.MASP, tv.SOLUONG, tv.THANHTIEN);// DỮ LIỆU NHẬP VÀO // Command (mặc định command type = text nên chúng ta khỏi fải làm gì nhiều). SqlCommand cmd = new SqlCommand(SQL, connect); // Query và kiểm tra if (cmd.ExecuteNonQuery() > 0) { return(true); } } catch (Exception e) { } finally { // Dong ket noi connect.Close(); } return(false); }
private void pictureBox3_Click(object sender, EventArgs e) { Stelia_BUS.Stelia_BUS bus = new Stelia_BUS.Stelia_BUS(); if (dataGridView1.Rows.Count == 0) { PushNoti noti1 = new PushNoti("Error", "Chưa có chi tiết phiếu trả!"); noti1.Width = this.Width; this.Controls.Add(noti1); noti1.Show(); noti1.ShowNoti(); } DTO_PhieuTra PT = new DTO_PhieuTra(txtMaPT.Text, txtMaNCC.Text, DateChange.ToString(dateNgNhap.DateTime), "0", "0", richTextBox1.Text); string error = CheckThongTin.check_Nhap(PT); if (error != "") { PushNoti noti1 = new PushNoti("Error", error); noti1.Width = this.Width; this.Controls.Add(noti1); noti1.Show(); noti1.ShowNoti(); return; } if (bus.themData(PT) == false) { PushNoti noti1 = new PushNoti("Error", "Thêm phiếu trả không thành công!"); noti1.Width = this.Width; this.Controls.Add(noti1); noti1.Show(); noti1.ShowNoti(); return; } int SL = 0; int GT = 0; foreach (DataGridViewRow row in dataGridView1.Rows) { DTO_CTPhieuTra ctpn = new DTO_CTPhieuTra(PT.MAPT, row.Cells[0].Value.ToString(), row.Cells[2].Value.ToString(), row.Cells[3].Value.ToString()); SL += int.Parse(row.Cells[2].Value.ToString()); GT += int.Parse(row.Cells[3].Value.ToString()); DTO_SanPham[] sp = bus.search_SANPHAM(row.Cells[0].Value.ToString()); sp[0].SLUONG = (int.Parse(sp[0].SLUONG) - int.Parse(row.Cells[2].Value.ToString())).ToString(); bus.suaData(sp[0]); bus.themData(ctpn); } PT.TONGSL = SL.ToString(); PT.TONGTIEN = GT.ToString(); bus.suaData(PT); DialogResult = DialogResult.OK; Close(); }
public bool suaData(DTO_CTPhieuTra tv) { return(ctpt.suaCTPT(tv)); }
public bool themData(DTO_CTPhieuTra tv) { return(ctpt.themCTPT(tv)); }