private void Sửa_Click(object sender, EventArgs e) { CTPhieuNhap_DTO a = new CTPhieuNhap_DTO(); a.MaSP = Masp; a.SoPhieuNhap = Sopn; if (txtDonGiaMua.Text == "" || txtSoLuong.Text == "") { MessageBox.Show("Bạn còn dữ liệu chưa nhập"); return; } a.DonGia = Int16.Parse(txtDonGiaMua.Text); a.SLNhap = Int16.Parse(txtSoLuong.Text); a.ThanhTien = a.DonGia * a.SLNhap; if (a.SLNhap == 0) { MessageBox.Show("Số lượng phải lớn hơn 0"); return; } if (a.DonGia == 0) { MessageBox.Show("Đơn giá phải lớn hơn 0"); return; } ct.CapNhapCTPhieuNhap(a); MessageBox.Show("Cập nhật thành công"); RefToMom.load(); }
public List <CTPhieuNhap_DTO> LayPhieuNhapTheoMa(int MaPN) { List <CTPhieuNhap_DTO> ds = new List <CTPhieuNhap_DTO>(); DataTable data = DataProvider.Instance.ExecuteQuery("LayCTPhieuNhapTheoMa @MaPN", new object[] { MaPN }); foreach (DataRow item in data.Rows) { CTPhieuNhap_DTO nhapHang = new CTPhieuNhap_DTO(item); ds.Add(nhapHang); } return(ds); }
public List <CTPhieuNhap_DTO> DanhDachCTPhieuNhap() { List <CTPhieuNhap_DTO> listCTPN = new List <CTPhieuNhap_DTO>(); #region Tạo Kết Nối SqlConnection con = DataProvider.TaoKetNoi(); #endregion if (con != null) { #region Tạo đối tượng truy vấn SqlCommand command = new SqlCommand(); command.CommandText = @"SELECT MaPhieuNhap,MaNguyenLieu,SoLuong,DonGiaCTPN,ThanhTien from CTPhieuNhap where TrangThai = 1"; command.Connection = con; SqlDataReader dataReader = command.ExecuteReader(); #endregion while (dataReader.Read()) { CTPhieuNhap_DTO ctpn = new CTPhieuNhap_DTO(); if (dataReader.IsDBNull(0) != null) { ctpn.MaPhieuNhap = (int)dataReader[0]; } if (dataReader.IsDBNull(1) != null) { ctpn.MaNguyenLieu = (int)dataReader["MaNguyenLieu"]; } if (dataReader.IsDBNull(2) != null) { ctpn.SoLuong = (int)dataReader["SoLuong"]; } if (dataReader.IsDBNull(3) != null) { ctpn.DonGiaCTPN = (decimal)dataReader["DonGiaCTPN"]; } if (dataReader.IsDBNull(4) != null) { ctpn.ThanhTien = (decimal)dataReader["ThanhTien"]; } listCTPN.Add(ctpn); } #region đóng kết nối dataReader.Close(); con.Close(); #endregion } return(listCTPN); }
private void btnXoaCTPhieuNhap_Click(object sender, EventArgs e) { if (dataGridViewQLDSCTHD.SelectedRows.Count > 0) { CTPhieuNhap_DTO ctpn = (CTPhieuNhap_DTO)dataGridViewQLDSCTHD.SelectedRows[0].DataBoundItem; if (MessageBox.Show("Bạn có chắc muốn xóa sản phẩm trong Phiếu Nhập " + ctpn.MaPhieuNhap + " không?", "Cảnh báo", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { CTPhieuNhap_BUS pn1 = new CTPhieuNhap_BUS(); pn1.XoaDanhSachCTPN(ctpn); MessageBox.Show("Đã xóa thành công Sản phẩm trong phiếu nhập"); Load_fromCTNhapHang(); } } }
public List <CTPhieuNhap_DTO> Search(CTPhieuNhap_DTO a, int kieusp, int loaisp) { var pmh = DB.CTPhieuNhapSearch(a.SoPhieuNhap, a.SLNhap, a.DonGia, a.ThanhTien, kieusp, loaisp); var MyQuery = (from pm in pmh select new CTPhieuNhap_DTO { SoPhieuNhap = pm.SoPhieuNhap, MaSP = pm.MaSP, SLNhap = pm.SLNhap ?? default(int), DonGia = pm.DonGia ?? default(decimal), ThanhTien = pm.ThanhTien ?? default(decimal), TenKieuSP = pm.TenKieuSP, TenLoaiSP = pm.TenLoaiSP, MaKieuSP = pm.MaKieuSP ?? default(int), MaLoaiSP = pm.MaLoaiSP ?? default(int) }); return(MyQuery.ToList()); }
public void themDanhSachCTPN(CTPhieuNhap_DTO ctpnDTO, int trangthai) { List <CTPhieuNhap_DTO> listPN = new List <CTPhieuNhap_DTO>(); #region Tạo Kết Nối SqlConnection con = DataProvider.TaoKetNoi(); #endregion if (con != null) { SqlCommand command = new SqlCommand(); command.CommandText = string.Format("INSERT INTO CTPhieuNhap(MaPhieuNhap,MaNguyenLieu,SoLuong,DonGiaCTPN,ThanhTien,TrangThai) VALUES({0}, {1}, {2}, {3}, {4},{5})" , ctpnDTO.MaPhieuNhap, ctpnDTO.MaNguyenLieu, ctpnDTO.SoLuong, ctpnDTO.DonGiaCTPN, ctpnDTO.ThanhTien, trangthai); command.Connection = con; command.ExecuteNonQuery(); DataProvider.NgatKetNoi(con); } }
public void XoaDanhSachCTPN(CTPhieuNhap_DTO ctpnDTO) { List <CTPhieuNhap_DTO> listCTPN = new List <CTPhieuNhap_DTO>(); #region Tạo Kết Nối SqlConnection con = DataProvider.TaoKetNoi(); #endregion if (con != null) { SqlCommand command = new SqlCommand(); command.CommandText = @"UPDATE CTPhieuNhap set TrangThai = 0 where MaPhieuNhap = @MaPhieuNhap"; command.Parameters.AddWithValue(@"MaPhieuNhap", ctpnDTO.MaPhieuNhap); command.Connection = con; command.ExecuteNonQuery(); DataProvider.NgatKetNoi(con); } }
public void ThemChiTietNhap(CTPhieuNhap_DTO a) { CTPHIEUNHAP b = new CTPHIEUNHAP(); b.ThanhTien = a.ThanhTien; b.SoPhieuNhap = a.SoPhieuNhap; b.SLNhap = a.SLNhap; b.MaSP = a.MaSP; b.DonGia = a.DonGia; DB.CTPHIEUNHAPs.InsertOnSubmit(b); var obj = DB.PHIEUNHAPs.Single(x => x.SoPhieuNhap == a.SoPhieuNhap); obj.TongTien += a.ThanhTien; var c = DB.SANPHAMs.Single(x => x.MaSP == a.MaSP); c.SoLuongTon += a.SLNhap; //obj.NgayLap = DateTime.Parse(a.NgayLap); //DB.SubmitChanges(); DB.SubmitChanges(); }
private void btnThemHD_Click(object sender, EventArgs e) { if (txtMaPN.Text.Trim() == "") { MessageBox.Show("Chưa Nhập Mã Phiếu", "Thông Báo", MessageBoxButtons.OK); txtMaPN.Focus(); return; } if (cbbTenNL.Text.Trim() == "") { MessageBox.Show("Chưa Nhập Tên Nguyên Liệu", "Thông Báo", MessageBoxButtons.OK); cbbTenNL.Focus(); return; } if (txtSL.Text.Trim() == "") { MessageBox.Show("Chưa Nhập Số Lượng", "Thông Báo", MessageBoxButtons.OK); txtSL.Focus(); return; } CTPhieuNhap_DTO ctpnThem = new CTPhieuNhap_DTO(); ctpnThem.MaPhieuNhap = int.Parse(txtMaPN.Text); ctpnThem.MaNguyenLieu = int.Parse(cbbTenNL.SelectedValue.ToString()); //npThem.MaPN = int.Parse("1"); ctpnThem.SoLuong = int.Parse(txtSL.Text); ctpnThem.DonGiaCTPN = (decimal)double.Parse(txtDonGia.Text); ctpnThem.ThanhTien = (decimal)double.Parse(txtThanhTien.Text); CTPhieuNhap_BUS ctpn = new CTPhieuNhap_BUS(); ctpn.ThemDanhSachCTPN(ctpnThem, 1); Load_fromCTNhapHang(); double TongTien = double.Parse(txtTongTien.Text); double thanhtien = double.Parse(txtThanhTien.Text); double kq = TongTien + thanhtien; txtTongTien.Text = kq.ToString(); }
public void CapNhapCTPhieuNhap(CTPhieuNhap_DTO a) { decimal tamp; int tam; var b = DB.CTPHIEUNHAPs.Single(x => x.SoPhieuNhap == a.SoPhieuNhap && x.MaSP == a.MaSP); b.MaSP = a.MaSP; b.DonGia = a.DonGia; tam = (a.SLNhap - b.SLNhap) ?? default(int); b.SLNhap = a.SLNhap; tamp = (a.ThanhTien - b.ThanhTien) ?? default(decimal); b.ThanhTien = a.ThanhTien; b.SoPhieuNhap = a.SoPhieuNhap; var obj = DB.PHIEUNHAPs.Single(x => x.SoPhieuNhap == a.SoPhieuNhap); obj.TongTien += tamp; var c = DB.SANPHAMs.Single(x => x.MaSP == a.MaSP); c.SoLuongTon += tam; DB.SubmitChanges(); }
public void XoaDanhSachCTPN(CTPhieuNhap_DTO ctpnDTO) { CTPhieuNhap_DAO objsanPham_DAO = new CTPhieuNhap_DAO(); objsanPham_DAO.XoaDanhSachCTPN(ctpnDTO); }
public void ThemDanhSachCTPN(CTPhieuNhap_DTO ctpnDTO, int trangthai) { CTPhieuNhap_DAO objsanPham_DAO = new CTPhieuNhap_DAO(); objsanPham_DAO.themDanhSachCTPN(ctpnDTO, trangthai); }
private void btnSearch_Click(object sender, EventArgs e) { CTPhieuNhap_DTO a = new CTPhieuNhap_DTO(); //a.SoPhieuMua = Int16.Parse(cbbSoPhieuMua.SelectedValue.ToString()); int kieusp = -1; int loaisp = -1; if (txtSoPhieuNhap.Text == "") { a.SoPhieuNhap = -1; } else { a.SoPhieuNhap = Int16.Parse(txtSoPhieuNhap.Text); } if (txtSoLuong.Text == "") { a.SLNhap = -1; } else { a.SLNhap = Int16.Parse(txtSoLuong.Text); } if (txtCTTongTien.Text == "") { a.ThanhTien = -1; } else { a.ThanhTien = Int16.Parse(txtCTTongTien.Text); } if (txtDonGia.Text == "") { a.DonGia = -1; } else { a.DonGia = Int16.Parse(txtDonGia.Text); } if (cbbKieuSP.Text != "") { kieusp = Int16.Parse(cbbKieuSP.SelectedValue.ToString()); } if (cbbLoaiSP.Text != "") { loaisp = Int16.Parse(cbbLoaiSP.SelectedValue.ToString()); } dataGridView1.DataSource = ctpn.Search(a, kieusp, loaisp); dataGridView1.Columns["SoPhieuNhap"].HeaderText = "Số phiếu nhập"; dataGridView1.Columns["MaSP"].HeaderText = "Mã sản phẩm"; dataGridView1.Columns["SLNhap"].HeaderText = "Số lượng nhập"; dataGridView1.Columns["DonGia"].HeaderText = "Đơn giả"; dataGridView1.Columns["ThanhTien"].HeaderText = "Thành tiền"; dataGridView1.Columns["MaSP"].Visible = false; dataGridView1.Columns["MaKieuSP"].Visible = false; dataGridView1.Columns["MaLoaiSP"].Visible = false; dataGridView1.Columns["TenKieuSP"].HeaderText = "Kiểu sản phẩm"; dataGridView1.Columns["TenLoaiSP"].HeaderText = "Loại sản phẩm"; dataGridView1.Columns["TenKieuSP"].DisplayIndex = 2; dataGridView1.Columns["TenLoaiSP"].DisplayIndex = 3; }
private void btnThem_Click(object sender, EventArgs e) { int kieusp = Int16.Parse(cbbKieuSP.SelectedValue.ToString()); int loaisp = Int16.Parse(cbbLoaiSP.SelectedValue.ToString()); int sopn = Int16.Parse(cbbSoPhieuNhap.Text); if (txtDonGia.Text == "" || txtSoLuong.Text == "") { MessageBox.Show("Bạn còn dữ liệu chưa nhập"); return; } int masp = 0; if (ct.KiemTraSP(kieusp, loaisp) == -1) { DialogResult dr = MessageBox.Show("Sản phẩm này chưa được lưu trong cơ sở dữ liệu, bạn có muốn thêm sản phẩm mới không?", "Cảnh Báo", MessageBoxButtons.OKCancel); if (dr == DialogResult.OK) { FormThemSP them = new FormThemSP(); them.ShowDialog(); if (them.DialogResult == DialogResult.Cancel) { cbbKieuSP.DataSource = ct.LayKieuSP(); cbbKieuSP.DisplayMember = "TenKieuSP"; cbbKieuSP.ValueMember = "MaKieuSP"; cbbLoaiSP.DataSource = ct.LayLoaiSP(); cbbLoaiSP.DisplayMember = "TenLoaiSP"; cbbLoaiSP.ValueMember = "MaLoaiSP"; } if (ct.KiemTraSP(kieusp, loaisp) == -1) { return; } masp = ct.KiemTraSP(kieusp, loaisp); } else { return; } } else { masp = ct.KiemTraSP(kieusp, loaisp); } CTPhieuNhap_DTO a = new CTPhieuNhap_DTO(); a.SoPhieuNhap = sopn; a.SLNhap = Int16.Parse(txtSoLuong.Text); a.DonGia = Decimal.Parse(txtDonGia.Text); a.ThanhTien = a.DonGia * a.SLNhap; if (a.SLNhap == 0) { MessageBox.Show("Số lượng phải lớn hơn 0"); return; } if (a.DonGia == 0) { MessageBox.Show("Đơn giá phải lớn hơn 0"); return; } a.MaSP = masp; if (ctp.Check(sopn, masp)) { ctp.ThemChiTietNhap(a); MessageBox.Show("Thêm thành công"); RefToMom.load(); } else { MessageBox.Show("Sản phẩm này đã được nhập trong phiếu này"); } }