private void btnLuu_Click(object sender, EventArgs e) { PhieuNhapDTO phieuNhap = new PhieuNhapDTO(); phieuNhap.MaPN = txtPhieu.Text; phieuNhap.NCC = txtMaNCC.Text; phieuNhap.KhoXuat = int.Parse(cbKhoXuat.SelectedValue.ToString()); phieuNhap.Ngay = txtNgay.Text; phieuNhap.NgayGiao = txtNgayGiao.Text; phieuNhap.HanThanhToan = txtHanThanhToan.Text; phieuNhap.GhiChu = txtGhiChu.Text; phieuNhap.TongTien = tongTien; PhieuNhapBUS phieuNhapBUS = new PhieuNhapBUS(); phieuNhapBUS.LuuPhieuNhap(phieuNhap); int i = 0; foreach (DataGridViewRow row in dgvNhapHang.Rows) { CT_PhieuNhap cT_PhieuNhap = new CT_PhieuNhap(); cT_PhieuNhap.MaPN = txtPhieu.Text; cT_PhieuNhap.STT = i; cT_PhieuNhap.TenHang = row.Cells["TenHang"].Value.ToString(); cT_PhieuNhap.DonVi = 1; cT_PhieuNhap.DonGia = float.Parse(row.Cells["DonGia"].Value.ToString()); cT_PhieuNhap.ThanhTien = float.Parse(row.Cells["ThanhTien"].Value.ToString()); phieuNhapBUS = new PhieuNhapBUS(); phieuNhapBUS.LuuCTPhieuNhap(cT_PhieuNhap); } MessageBox.Show("Lưu thành công"); }
private void KhoiTao() { int stt = 1; List <PhieuNhapDTO> listPhieuNhapDTO = PhieuNhapBUS.SelectPhieuNhapAll(); if (listPhieuNhapDTO != null) { dataGridView_TraCuuNhapHang.Rows.Clear(); PhieuNhapDTO item = new PhieuNhapDTO(); for (int i = 0; i < listPhieuNhapDTO.Count; i++) { item = listPhieuNhapDTO[i]; dataGridView_TraCuuNhapHang.Rows.Add( (stt++).ToString(), item.MaPhieuNhap, DonHangBUS.SelectDonHangById(item.MaDonHang).MaDonHang, DonHangBUS.SelectDonHangById(item.MaDonHang).NgayLap.ToString("dd/MM/yyy"), item.NgayNhan.ToString("dd/MM/yyy"), NhanVienBUS.SelectNhanVienById(item.MaNhanVien).TenNhanVien); } //Data enableButton(); } else { disableButton(); } }
public int InsertPHIEUNHAP(PhieuNhapDTO pn) { int flag = -1; try { string sql = "insert into PHIEUNHAP(NgayNhap) values(" + pn.MaPhieuNhap + "," + pn.NgayNhap + ")"; kn.Connect(); int nRow = kn.ExecuteNonQuery(CommandType.Text, sql, new SqlParameter { ParameterName = "MaPhieuNhap", Value = pn.MaPhieuNhap }, new SqlParameter { ParameterName = "NgayNhap", Value = pn.NgayNhap }); if (nRow > 0) { flag = 1; } } catch (Exception ex) { throw ex; } finally { kn.Disconnect(); } return(flag); }
public static List <PhieuNhapDTO> GetDSPN() { List <PhieuNhapDTO> DSPN = new List <PhieuNhapDTO>(); using (dbMainDataContext dbMain = new dbMainDataContext()) { var query = from p in dbMain.PhieuNhaps select p; foreach (var row in query) { PhieuNhapDTO pn = new PhieuNhapDTO(); pn.Maphieunhap = row.MaPhieuNhap; pn.Ngaynhap = row.NgayNhap.ToString(); if (row.TongTien == 0) { pn.Tongtien = "0"; } else { pn.Tongtien = row.TongTien.ToString("###,###,###' 'VNĐ"); } DSPN.Add(pn); } } return(DSPN); }
public int InsertCHITIETPHIEU(PhieuNhapDTO pn) { int flag = -1; try { string sql = "insert into CHITIETPHIEU(MaPhieuNhap,MaSach,SoLuongNhap) values(" + pn.MaPhieuNhap + "," + pn.MaSach + "," + pn.SoLuong + ")"; kn.Connect(); int nRow = kn.ExecuteNonQuery(CommandType.Text, sql, new SqlParameter { ParameterName = "MaPhieuNhap", Value = pn.MaPhieuNhap }, new SqlParameter { ParameterName = "MaSach", Value = pn.MaSach }, new SqlParameter { ParameterName = "SoLuongNhap", Value = pn.SoLuong }); if (nRow > 0) { flag = 1; } } catch (Exception ex) { throw ex; } finally { kn.Disconnect(); } return(flag); }
private void btnSua_Click(object sender, EventArgs e) { try { string manhap = txtMaNhap.Text; string ngaynhap = dTimeNgayNhap.Value.ToString("MM/dd/yyyy"); string manv = cbbMaNv.SelectedValue.ToString(); PhieuNhapDTO pn = new PhieuNhapDTO(manhap, ngaynhap, manv); if (txtMaNhap.Text.Equals("")) { MessageBox.Show("Nhập thiếu thông tin.", "Thông báo!"); } else { if (PhieuNhapBUS.Instance.SuaPhieuNhap(pn) > 0) { LoadDS(); MessageBox.Show("Sửa thành công.", "Thông báo!"); } else { MessageBox.Show("Sửa không thành công.", "Thông báo!"); } } } catch (Exception) { MessageBox.Show("Lỗi", "Thông báo!"); } }
private void button2_Click_2(object sender, EventArgs e) { try { TongTien = 0; PhieuNhapDTO PN = new PhieuNhapDTO(); PN.year = dtpPN.Value.Year; PN.month = dtpPN.Value.Month; PN.day = dtpPN.Value.Day; PN.ma_phieu_nhap = txtMaPN.Text; /* * string ma = txtTenKHHD.Text; * KhachHangDTO kHang = new KhachHangDTO(); * kHang = KhachHangBUS.Search_KH(ma); * hd.ma_kh = kHang.ma_kh; */ PN.ma_ncc = cbxNCC.SelectedValue.ToString(); PN.ma_nv = cbxNVLPN.SelectedValue.ToString(); PhieuNhapBUS.Insert_PN(PN); MessageBox.Show("Thêm thành công!", "Thông báo", MessageBoxButtons.OK); load_data(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public static List <PhieuNhapDTO> SelectPhieuNhapByMaDonHang(string MaDonHang) { List <SqlParameter> sqlParamas = new List <SqlParameter>(); sqlParamas.Add(new SqlParameter("@MaDonHang", MaDonHang)); DataTable dataTable = DataProvider.ExecuteReader("usp_SelectPhieuNhapByMaDonHang", sqlParamas); List <PhieuNhapDTO> listPhieuNhapDTO = new List <PhieuNhapDTO>(); if (dataTable.Rows.Count > 0) { foreach (DataRow dataRow in dataTable.Rows) { PhieuNhapDTO phieuNhapDTO = new PhieuNhapDTO(); phieuNhapDTO.MaPhieuNhap = dataRow["MaPhieuNhap"].ToString(); phieuNhapDTO.MaDonHang = dataRow["MaDonHang"].ToString(); phieuNhapDTO.NgayNhan = DateTime.Parse(dataRow["NgayNhan"].ToString()); phieuNhapDTO.MaNhanVien = dataRow["MaNhanVien"].ToString(); listPhieuNhapDTO.Add(phieuNhapDTO); } } else { listPhieuNhapDTO = null; } return(listPhieuNhapDTO); }
public string insert(PhieuNhapDTO obj) { string query = string.Empty; query += "INSERT INTO [tblphieunhap] ([masach],[maphieunhap],[ngaynhap],[soluong])"; query += "VALUES (@masach,@maphieunhap,@ngaynhap,@soluong)"; using (SqlConnection conn = new SqlConnection(connectionString)) { using (SqlCommand comm = new SqlCommand()) { comm.Connection = conn; comm.CommandType = CommandType.Text; comm.CommandText = query; comm.Parameters.AddWithValue("@masach", obj.MaSach); comm.Parameters.AddWithValue("@maphieunhap", obj.MaPhieuNhap); comm.Parameters.AddWithValue("@ngaynhap", obj.NgayNhap); comm.Parameters.AddWithValue("@soluong", obj.SoLuong); try { conn.Open(); comm.ExecuteNonQuery(); } catch (Exception ex) { conn.Close(); return("Thêm phiếu nhập thất bại\n" + ex.Message + "\n"); } } } return("0"); }
public static bool UpdatePhieuNhapById(PhieuNhapDTO phieuNhapDTO) { List <SqlParameter> sqlParamas = new List <SqlParameter>(); sqlParamas.Add(new SqlParameter("@MaPhieuNhap", phieuNhapDTO.MaPhieuNhap)); sqlParamas.Add(new SqlParameter("@MaDonHang", phieuNhapDTO.MaDonHang)); sqlParamas.Add(new SqlParameter("@NgayNhan", phieuNhapDTO.NgayNhan)); sqlParamas.Add(new SqlParameter("@MaNhanVien", phieuNhapDTO.MaNhanVien)); return(DataProvider.ExecuteNoneQuery("usp_UpdatePhieuNhapById", sqlParamas)); }
public static PhieuNhap MappingPhieuNhap(this PhieuNhapDTO phieuNhapDTO) { return(new PhieuNhap { Id = phieuNhapDTO.Id, Ten = phieuNhapDTO.Ten, NgayNhap = phieuNhapDTO.NgayNhap, NhaCungCapId = phieuNhapDTO.NhaCungCapId, }); }
public PhieuNhapDTO ConvertPhieuNhapToPhieuNhapDTO(PhieuNhapSach coupon) { PhieuNhapDTO dto = new PhieuNhapDTO(); dto.Id = coupon.Id; dto.IdNxb = (int)coupon.IdNxb; dto.TenNXB = db.NhaXuatBan.Where(n => n.Id == coupon.IdNxb).FirstOrDefault().TenNxb; dto.NgayNhap = coupon.NgayNhap.Value.ToShortDateString(); dto.TongTien = GetPriceForCoupon(coupon.Id); return(dto); }
public static double SumSL_theongay(PhieuNhapDTO pn1, PhieuNhapDTO pn2) { try { string select = string.Format("SELECT SUM(so_luong) FROM db_chi_tiet_pn inner join db_phieu_nhap on db_chi_tiet_pn.ma_phieu_nhap = db_phieu_nhap.ma_phieu_nhap WHERE db_phieu_nhap.ngay_lap_pn between '{0}/{1}/{2}' and '{3}/{4}/{5}'", pn1.year, pn1.month, pn1.day, pn2.year, pn2.month, pn2.day); return(Sum(select)); } catch (Exception ex) { throw ex; } }
public static double SumCTPN_TheoMa(PhieuNhapDTO pn1) { try { string select = string.Format("SELECT SUM(tong) FROM db_chi_tiet_pn WHERE ma_phieu_nhap ='{0}';", pn1.ma_phieu_nhap); return(Sum(select)); } catch (Exception ex) { throw ex; } }
public List <PhieuNhapDTO> loadPhieuNhapList() { List <PhieuNhapDTO> tableList = new List <PhieuNhapDTO>(); DataTable data = DataProvider.Instance.executeQuery("select * from NguyenLieu"); foreach (DataRow item in data.Rows) { PhieuNhapDTO table = new PhieuNhapDTO(item); tableList.Add(table); } return(tableList); }
private void Load_Update()//Khởi Tạo Load Update { PhieuNhapDTO phieuNhapDTO = PhieuNhapBUS.SelectPhieuNhapById(MaPhieuNhap); txtMaPhieuNhap.Text = MaPhieuNhap; NgayNhap = phieuNhapDTO.NgayNhan; txtNgayNhan.Text = NgayNhap.ToString("dd/MM/yyyy"); txtMaNhanVien.Text = phieuNhapDTO.MaNhanVien.ToString(); txtNhanVienNhanHang.Text = NhanVienBUS.SelectNhanVienById(phieuNhapDTO.MaNhanVien).TenNhanVien; txtDonDatHang.ReadOnly = true; txtDonDatHang.Text = phieuNhapDTO.MaDonHang.ToString(); }
public bool themchitietphieunhap(PhieuNhapDTO p) { if (pnDAO.GetPhieuNhapByName(p.MaPhieuNhap, p.MaSach) == null) { pnDAO.InsertCHITIETPHIEU(p); return(true); } else { return(false); } }
public static double SumGTPN_theongay(PhieuNhapDTO pn1, PhieuNhapDTO pn2) { try { string select = string.Format("SELECT SUM(tong_tien) FROM db_phieu_nhap WHERE ngay_lap_pn between '{0}/{1}/{2}' and '{3}/{4}/{5}'", pn1.year, pn1.month, pn1.day, pn2.year, pn2.month, pn2.day); return(Sum(select)); } catch (Exception ex) { throw ex; } }
public int UpdatePN(PhieuNhapDTO phieuNhap) { int result = 0; string Query = "Update PhieuNhap set NgayNhap ='" + phieuNhap.NgayNhap.ToShortDateString() + "'where MaPN = '" + phieuNhap.MaPN + "'"; try { result = DBcon.ExecuteSPNoneQuery(Query); } catch (SqlException ex) { } return(result); }
public int InsertPN(PhieuNhapDTO phieuNhap) { int result = 0; string Query = "Insert into PhieuNhap(MaPN, NgayNhap) values('" + phieuNhap.MaPN + "', N'" + phieuNhap.NgayNhap.ToShortDateString() + "')"; try { result = DBcon.ExecuteSPNoneQuery(Query); } catch (SqlException ex) { } return(result); }
private void txtTongthanhtoan_TextChanged(object sender, EventArgs e) { try { PhieuNhapDTO pn = new PhieuNhapDTO(); pn.ma_phieu_nhap = txtMaPN.Text; pn.tongtien = long.Parse(txtTongthanhtoan.Text); PhieuNhapBUS.Update_PN(pn); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public static void update_PN(PhieuNhapDTO pn) { try { cnn = DataProvider.ConnectData(); string update = string.Format("UPDATE db_phieu_nhap SET tong_tien='{1}' WHERE ma_phieu_nhap='{0}';", pn.ma_phieu_nhap, pn.tongtien); DataProvider.Execute(cnn, update); cnn.Close(); } catch (Exception ex) { throw ex; } }
/// <summary> /// xoa thong tin 1 phieu nhap /// </summary> /// <param name="pn"></param> public static void Delete_PN(PhieuNhapDTO pn) { try { cnn = DataProvider.ConnectData(); string select = string.Format("delete from db_chi_tiet_pn where ma_phieu_nhap='{0}';delete from db_phieu_nhap where ma_phieu_nhap='{0}';", pn.ma_phieu_nhap); DataProvider.Execute(cnn, select); cnn.Close(); } catch (Exception ex) { throw ex; } }
private void btnNhapHang_Click(object sender, EventArgs e) { PhieuNhapDTO phieuNhap = new PhieuNhapDTO(); phieuNhap.NhaCungCap = (int)cmbNhaCungCap.SelectedValue; phieuNhap.NgayLap = DateTime.Now; phieuNhap.TongTien = Convert.ToDouble(lblTongTien.Text.Remove(lblTongTien.Text.Length - 1)); phieuNhap.TrangThai = true; List <CTPhieuNhapDTO> lsCTPhieuNhap = new List <CTPhieuNhapDTO>(); foreach (DataGridViewRow row in dgvCTPhieuNhap.Rows) { string donGia = row.Cells["colDonGia"].Value.ToString(); CTPhieuNhapDTO ctPhieuNhap = new CTPhieuNhapDTO(); ctPhieuNhap.MaPhieuNhap = Convert.ToInt32(lblMaPhieu.Text); ctPhieuNhap.MaNguyenLieu = Convert.ToInt32(row.Cells["colMaNguyenLieu"].Value); ctPhieuNhap.SoLuong = Convert.ToDouble(row.Cells["colSoLuong"].Value); ctPhieuNhap.DonViTinh = row.Cells["colDonViTinh"].Value.ToString(); ctPhieuNhap.DonGia = Convert.ToDouble(donGia.Remove(donGia.Length - 1)); if (row.Cells["colGhiChu"].Value != null) { ctPhieuNhap.GhiChu = row.Cells["colGhiChu"].Value.ToString(); } else { ctPhieuNhap.GhiChu = string.Empty; } lsCTPhieuNhap.Add(ctPhieuNhap); } if (PhieuNhapBUS.LuuPhieuNhap(phieuNhap, lsCTPhieuNhap)) { if (DialogResult.Yes == MessageBox.Show("Bạn có muốn in phiếu nhập?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { FrmHienThiBaoCao frm = new FrmHienThiBaoCao(); frm.HienThiPhieuNhapMoiNhat(); FrmMain.Instance.TopMost = false; frm.Show(); } LamMoi(); dgvCTPhieuNhap.Rows.Clear(); } else { MessageBox.Show("Lưu phiếu nhập thất bại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// thêm danh 1 phiếu nhập /// </summary> /// <param name="pn"></param> public static void insert_PN(PhieuNhapDTO pn) { try { cnn = DataProvider.ConnectData(); string insert = string.Format("insert into db_phieu_nhap(ma_phieu_nhap,ma_nv,ma_ncc,ngay_lap_pn,tong_tien) values ('{0}','{1}','{2}','{3}/{4}/{5}','{6}');", pn.ma_phieu_nhap, pn.ma_nv, pn.ma_ncc, pn.year, pn.month, pn.day, pn.tongtien); DataProvider.Execute(cnn, insert); cnn.Close(); } catch (Exception ex) { throw ex; } }
public List <PhieuNhapDTO> LoadDsPhieuNhap() { List <PhieuNhapDTO> dspn = new List <PhieuNhapDTO>(); string sql = "SP_PHIEUNHAP_DS"; DataTable rs = DataProvider.Instance.ExecuteQuery(sql); foreach (DataRow items in rs.Rows) { string manhap = items["MASONHAP"].ToString(); string ngaynhap = items["NGAYNHAP"].ToString(); string nv = items["TENNV"].ToString(); PhieuNhapDTO pn = new PhieuNhapDTO(manhap, ngaynhap, nv); dspn.Add(pn); } return(dspn); }
private void btnthem_Click(object sender, EventArgs e) { int dem = dsphieunhap.Rows.Count; this.Size = new Size(760, 511); PhieuNhapDTO p = new PhieuNhapDTO(); p.NgayNhap = dtpick.Value; if (PhieuNhapBUS.themphieunhap(p) == false) { MessageBox.Show("Tạo Phiếu Nhập thất bại"); } HienThiDanhSach(); txtmaphieunhap.Text = dsphieunhap.Rows[dem].Cells[0].Value.ToString(); }
public bool ThemPhieuNhap(PhieuNhapDTO pn) { bool ktra = true; try { string sql = "SP_PHIEUNHAP_THEM @MASONHAP , @NGAYNHAP , @MANV"; DataProvider.Instance.ExecuteNonQuery(sql, new object[] { pn.SMaPhieuNhap, pn.SNgayNhap, pn.SMaNv }); ktra = true; } catch (Exception) { ktra = false; } return(ktra); }
public static PhieuNhapDTO GetByName(int maphieunhap, int masach) { string sql = "select * from CHITIETPHIEU where ((MaPhieuNhap=" + maphieunhap + ")AND(MaSach = " + masach + "))"; DataTable dt = DataAccess.ExcuQuery(sql); if (dt.Rows.Count == 0) { return(null); } else { PhieuNhapDTO phieuNhap = new PhieuNhapDTO(); phieuNhap.MaPhieuNhap = (int)dt.Rows[0].ItemArray[0]; return(phieuNhap); } }
public List <PhieuNhapDTO> TimPhieuNhap(string manhap) { List <PhieuNhapDTO> dspn = new List <PhieuNhapDTO>(); string sql = "SP_PHIEUNHAP_TIM @MASONHAP"; DataTable rs = DataProvider.Instance.ExecuteQuery(sql, new object[] { manhap }); foreach (DataRow items in rs.Rows) { string mn = items["MASONHAP"].ToString(); string ngaynhap = items["NGAYNHAP"].ToString(); string nv = items["TENNV"].ToString(); PhieuNhapDTO pn = new PhieuNhapDTO(mn, ngaynhap, nv); dspn.Add(pn); } return(dspn); }