public List <DTO_ChiTietPhieuNhap> timkiem(string tukhoa) { List <DTO_ChiTietPhieuNhap> ds = new List <DTO_ChiTietPhieuNhap>(); string query = string.Empty; query += "SELECT * FROM [tblcthoadonnhap]"; query += "WHERE [mahoadon] = @tukhoa"; using (SqlConnection con = new SqlConnection(connectionString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = con; cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = query; cmd.Parameters.AddWithValue("@tukhoa", tukhoa); try { con.Open(); SqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows == true) { while (reader.Read()) { DTO_ChiTietPhieuNhap ctpn = new DTO_ChiTietPhieuNhap(); ctpn.Id = long.Parse(reader["id"].ToString()); ctpn.MaHD = long.Parse(reader["mahoadon"].ToString()); ctpn.Mahang = long.Parse(reader["mahang"].ToString()); ctpn.DonGiaBan = long.Parse(reader["dongiaban"].ToString()); ctpn.SoLuong = int.Parse(reader["soLuong"].ToString()); ds.Add(ctpn); } } con.Close(); con.Dispose(); } catch { con.Close(); return(null); } } } return(ds); }
public List <DTO_ChiTietPhieuNhap> LayDanhSachChiTiet(long mahoadon) { List <DTO_ChiTietPhieuNhap> ds = new List <DTO_ChiTietPhieuNhap>(); string query = string.Empty; query = "select a.id,a.mahoadon,a.mahang,b.ten,a.dongiaban,a.soluong from tblcthoadonnhap a , tblhang b where a.mahang = b.id and a.mahoadon = " + mahoadon; using (SqlConnection con = new SqlConnection(connectionString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = con; cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = query; try { con.Open(); SqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows == true) { while (reader.Read()) { DTO_ChiTietPhieuNhap ctpn = new DTO_ChiTietPhieuNhap(); ctpn.Id = long.Parse(reader["id"].ToString()); ctpn.MaHD = long.Parse(reader["mahoadon"].ToString()); ctpn.TenHang = reader["ten"].ToString(); ctpn.DonGiaBan = long.Parse(reader["dongiaban"].ToString()); ctpn.SoLuong = int.Parse(reader["soLuong"].ToString()); ctpn.Mahang = long.Parse(reader["mahang"].ToString()); ds.Add(ctpn); } } con.Close(); con.Dispose(); } catch { con.Close(); return(null); } } } return(ds); }
public bool SuaChiTietPX(DTO_ChiTietPhieuNhap ctpn) { string query = string.Empty; query = "UPDATE [tblcthoadonnhap] " + "SET [mahoadon] = @mahoadon , [mahang] = @mahang,[dongiaban] = @dongiaban, [soluong] = @soluong " + "WHERE [id] = @id"; //query = "SuaDaiLy"; using (SqlConnection con = new SqlConnection(connectionString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = con; cmd.CommandType = System.Data.CommandType.Text; //cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.CommandText = query; cmd.Parameters.AddWithValue("@mahoadon", ctpn.MaHD); cmd.Parameters.AddWithValue("@mahang", ctpn.Mahang); cmd.Parameters.AddWithValue("@dongiaban", ctpn.DonGiaBan); cmd.Parameters.AddWithValue("@soluong", ctpn.SoLuong); cmd.Parameters.AddWithValue("@id", ctpn.Id); try { con.Open(); if (cmd.ExecuteNonQuery() > 0) { con.Close(); con.Dispose(); return(true); } else { con.Close(); return(false); } } catch { con.Close(); return(false); } } } }
private void btnDelete_Click(object sender, RoutedEventArgs e) { MessageBoxResult result = MessageBox.Show("Bạn có muốn xóa dòng này?", "Confirmation", MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { if (dgvChiTietPhieuNhap.SelectedItem != null) { DTO_ChiTietPhieuNhap obj = dgvChiTietPhieuNhap.SelectedItem as DTO_ChiTietPhieuNhap; String id = obj.MaChiTietPhieuNhap; BUS_ChiTietPhieuNhap.Delete(id); dgvChiTietPhieuNhap.ItemsSource = BUS_ChiTietPhieuNhap.showDataByPhieuNhap(item.MaPhieuNhap); calTongTien(true, obj.ThanhTien); calSoLuongNhap(true); } } }
public void insert(DTO_ChiTietPhieuNhap obj) { using (CellphoneComponentEntities db = new CellphoneComponentEntities()) { var resultMaHangHoa = db.Database .SqlQuery <String>("select MaHangHoa from dbo.HangHoa where TenHangHoa = N'" + obj.TenHangHoa + "'") .FirstOrDefault(); ChiTietPhieuNhap ctpn = new ChiTietPhieuNhap(); ctpn.MaChiTietPhieuNhap = obj.MaChiTietPhieuNhap; ctpn.MaHangHoa = resultMaHangHoa; ctpn.MaPhieuNhap = obj.MaPhieuNhap; ctpn.SoLuong = obj.SoLuong; ctpn.GiaNhap = obj.GiaNhap; ctpn.ThanhTien = obj.ThanhTien; db.ChiTietPhieuNhaps.Add(ctpn); db.SaveChanges(); } }
public bool ThemChiTiet(DTO_ChiTietPhieuNhap chitiet) { string query = string.Empty; query += "INSERT [dbo].[tblcthoadonnhap] ([mahoadon], [mahang], [dongiaban], [soluong])"; query += "VALUES (@mahoadon, @mahang, @dongiaban, @soluong)"; using (SqlConnection con = new SqlConnection(connectionString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = con; cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = query; cmd.Parameters.AddWithValue("@mahoadon", chitiet.MaHD); cmd.Parameters.AddWithValue("@mahang", chitiet.Mahang); cmd.Parameters.AddWithValue("@dongiaban", chitiet.DonGiaBan); cmd.Parameters.AddWithValue("@soluong", chitiet.SoLuong); try { con.Open(); if (cmd.ExecuteNonQuery() > 0) { con.Close(); con.Dispose(); return(true); } else { con.Close(); return(false); } } catch { con.Close(); return(false); } } } }
public void update(DTO_ChiTietPhieuNhap obj) { using (CellphoneComponentEntities db = new CellphoneComponentEntities()) { var resultMaHangHoa = db.Database .SqlQuery <String>("select MaHangHoa from dbo.HangHoa where TenHangHoa = N'" + obj.TenHangHoa + "'") .FirstOrDefault(); ChiTietPhieuNhap ctpn = new ChiTietPhieuNhap(); ctpn.MaChiTietPhieuNhap = obj.MaChiTietPhieuNhap; ctpn.MaHangHoa = resultMaHangHoa; ctpn.MaPhieuNhap = obj.MaPhieuNhap; ctpn.SoLuong = obj.SoLuong; ctpn.GiaNhap = obj.GiaNhap; ctpn.ThanhTien = obj.ThanhTien; db.ChiTietPhieuNhaps.Attach(ctpn); db.Entry(obj).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } }
private void btnThemHang_Click(object sender, EventArgs e) { long mahang = 0; if (btnThemHang.Text == "Xác Nhận") { if (checkvalid()) { DTO_Hang hang = new DTO_Hang(); DTO_ChiTietPhieuNhap ct = new DTO_ChiTietPhieuNhap(); //hàng mới if (rbHangMoi.Checked) { hang.TenMatHang = txttenhang1.Text; hang.CongDung = txtCongDung.Text; hang.XuatXu = txtXuatSu.Text; hang.ThanhPhan = txtThanhPhan.Text; hang.MaDVT = long.Parse(cbDVT.SelectedValue.ToString()); hang.MaNhomHang = long.Parse(cbMaNhom.SelectedValue.ToString()); hang.SoLuong = int.Parse(numSoLuongHang.Value.ToString()); hang.GiaNhap = double.Parse(numGiaNhap.Value.ToString()); hang.GiaBan = double.Parse(numGiaBan.Value.ToString()); if (hanghoa.ThemMatHang(hang)) { hang.MaMatHang = hanghoa.timMaHang(hang.TenMatHang); MessageBox.Show("Thêm hàng thành công!"); } else { MessageBox.Show("Thêm hàng thất bại \nvui lòng kiểm tra lại!"); return; } } else if (rbHangSan.Checked) { hang = hanghoa.timHang(long.Parse(cbtenhang.SelectedValue.ToString())); if (hanghoa.suaSoluongHangTrongKho(long.Parse(cbtenhang.SelectedValue.ToString()), (int)numSoLuongHang.Value)) { MessageBox.Show("Thêm hàng thành công!"); } else { MessageBox.Show("Thêm hàng thất bại \nvui lòng kiểm tra lại!"); return; } } //mahang = hanghoa.timMaHang(hang.TenMatHang); ct.MaHD = long.Parse(txtId.Text); ct.Mahang = hang.MaMatHang; ct.SoLuong = (int)numSoLuongHang.Value; ct.DonGiaBan = long.Parse(numGiaNhap.Value.ToString()); if (ctpn.ThemChiTietPX(ct)) { dataCTPhieuThu.DataSource = ctpn.LayDanhSachChiTietPhieuNhap(long.Parse(txtId.Text)); DTO_PhieuThu phieuthu = new DTO_PhieuThu(); phieuthu.Id = long.Parse(txtId.Text); //phieuthu.MaNCC = long.Parse(cbMancc.SelectedValue.ToString()); phieuthu.Sotien = ct.SoLuong * ct.DonGiaBan; pt.capnhapphieuthu(phieuthu); dataPhieuThu.DataSource = pt.LayDanhSachPhieuThu(); reset(); } else { MessageBox.Show("Thêm hàng thất bại \nvui lòng kiểm tra lại!"); return; } rbHangSan.Checked = true; SetDefault(false); btnThemHang.Enabled = true; btnThemHang.Text = "Thêm Hàng"; btnXoaHang.Text = "Xóa Hàng"; } } else { SetDefault(true); btnThemHang.Text = "Xác Nhận"; btnXoaHang.Text = "Hủy"; reset(); } }
public void Update(DTO_ChiTietPhieuNhap obj) { ChiTietPhieuNhap.Instance.update(obj); }
public void Insert(DTO_ChiTietPhieuNhap obj) { ChiTietPhieuNhap.Instance.insert(obj); }
public bool SuaChiTietPX(DTO_ChiTietPhieuNhap ctpn) { return(ChiTietPhieuNhap.SuaChiTietPX(ctpn)); }
public bool ThemChiTietPX(DTO_ChiTietPhieuNhap ctpn) { return(ChiTietPhieuNhap.ThemChiTiet(ctpn)); }