public void Execute() { CTHoadon check = null; using (var repo = new CTHoadonViewRepository()) { repo.CTHoadonId = this.item.CTHoadonId; check = repo.Execute(); } if (check != null) //đã tồn tại { using (var repo = new CTHoadonUpdateRepository()) { repo.item = this.item; repo.Execute(); } } else { using (var repo = new CTHoadonInsertRepository()) { repo.item = this.item; repo.Execute(); } } }
//Sửa private void toolStripMenuItem2_Click(object sender, EventArgs e) { CTHoadon b = new CTHoadon(); b.Macthd = txt_macthd.Text.Trim(); b.Masp = cbo_tensp.SelectedValue.ToString(); b.Madv = cbo_tengoitap.SelectedValue.ToString(); b.Dongia = float.Parse(cmb_gia.Text); b.Soluong = int.Parse(txt_sl.Text); b.Tien = float.Parse(txt_tien.Text); if (b.Macthd == null || b.Macthd == "") { throw new Exception(); } if (BUS.BUS.sua_cthd(b) == 1) { MessageBox.Show("Sửa thành công"); txt_macthd.Enabled = false; } // else { MessageBox.Show("lỗi"); } string ma = txt_mahd.Text; dgv_ct.DataSource = BUS.BUS.xuat_cthd(ma); txt_macthd.Enabled = false; tongtien(); }
public CTHoadon Execute() { CTHoadon data = null; using (var conn = new SqlConnection(ConnectionString)) { using (var cmd = conn.CreateCommand()) { conn.Open(); cmd.CommandText = "SELECT * FROM CTHoadon WHERE CTHoadonId = @CTHoadonId"; cmd.Parameters.Add(new SqlParameter { ParameterName = "@CTHoadonId", Value = this.CTHoadonId, SqlDbType = System.Data.SqlDbType.NVarChar }); using (var reader = cmd.ExecuteReader()) { if (reader.Read()) { data = new CTHoadon { CTHoadonId = Convert.ToString(reader["CTHoadonId"].vSafe()), HoadonId = Convert.ToString(reader["HoadonId"].vSafe()), HanghoaId = Convert.ToString(reader["HanghoaId"].vSafe()), TenHanghoa = Convert.ToString(reader["TenHanghoa"].vSafe()), Soluong = Convert.ToInt64(reader["Soluong"].vSafe()), Dongia = Convert.ToInt64(reader["Dongia"].vSafe()), Ghichu = Convert.ToString(reader["Ghichu"].vSafe()) }; } } } conn.Close(); } return(data); }
public static int xoa_cthd(CTHoadon a) { SqlParameter[] para = new SqlParameter[] { new SqlParameter("@macthd", a.Macthd), }; return(DataProvider.ExecuteNonQuery("xoa_cthd", para)); }
private void btn_luu_Click(object sender, EventArgs e) { if (themhd) { Hoadon a = new Hoadon(); a.Mahd = txt_mahd.Text.Trim(); a.Manv = cmb_tennv.SelectedValue.ToString(); a.Makh = cmb_kh.SelectedValue.ToString(); a.Ngaylap = dtp_ngaylap.Value; a.Tongtien = float.Parse(txt_tongtien.Text); // txt_tongtien.Text = "0"; if (a.Mahd == null || a.Mahd == "") { throw new Exception(); } if (BUS.BUS.them_hd(a) == 1) { MessageBox.Show("Thêm Thành Công"); txt_mahd.Enabled = false; } xuat(); } else if (themct) { CTHoadon b = new CTHoadon(); b.Macthd = txt_macthd.Text.Trim(); b.Masp = txt_mahd.Text.Trim(); b.Madv = cbo_tengoitap.SelectedValue.ToString(); b.Dongia = float.Parse(cmb_gia.Text); b.Soluong = int.Parse(txt_sl.Text); b.Tien = float.Parse(txt_tien.Text); if (BUS.BUS.them_cthd(b) == 1) { MessageBox.Show("Thêm Thành Công"); txt_macthd.Enabled = false; } string ma = txt_mahd.Text; dgv_ct.DataSource = BUS.BUS.xuat_cthd(ma); txt_macthd.Enabled = false; tongtien(); } else { if (txt_tongtien.Text != "0" && txt_tongtien.Text != null) { if (MessageBox.Show("Bạn có muốn lưu tổng tiền ", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { luutien(); MessageBox.Show("đã lưu tổng tiền"); } } } }
public static int sua_cthd(CTHoadon a) { SqlParameter[] para = new SqlParameter[] { new SqlParameter("@macthd", a.Macthd), new SqlParameter("@masp", a.Masp), new SqlParameter("@madv", a.Madv), new SqlParameter("@dongia", a.Dongia), new SqlParameter("@sl", a.Soluong), new SqlParameter("@tien", a.Tien), }; return(DataProvider.ExecuteNonQuery("sua_cthd", para)); }
//Xóa private void toolStripMenuItem3_Click(object sender, EventArgs e) { CTHoadon a = new CTHoadon(); a.Macthd = txt_macthd.Text.Trim(); if (BUS.BUS.xoa_cthd(a) != 1) { MessageBox.Show("Không xóa được"); } else { MessageBox.Show("Xóa Thành Công"); } reset1(); reset2(); string ma = txt_mahd.Text; dgv_ct.DataSource = BUS.BUS.xuat_cthd(ma); txt_macthd.Enabled = false; tongtien(); }
public static int xoa_cthd(CTHoadon a) { return(DAO.xoa_cthd(a)); }
public static int sua_cthd(CTHoadon a) { return(DAO.sua_cthd(a)); }
public static int them_cthd(CTHoadon a) { return(DAO.them_cthd(a)); }