private void btnLuu_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                this.vo_PN.MaNhaCungCap = this.cboNCC.SelectedValue.ToString();
                foreach (vo_HangHoa _voHH in this.dsHangHoaCuaPhieuNhap)
                {
                    if (_voHH.SoLuong > 0)
                    {
                        this.vo_PN.DsHangHoa.Add(_voHH);
                    }
                }
                int id = this.bus_PN.AddPhieuNhapHang(this.vo_PN);
                if (id > 0)
                {
                    this.vo_PN = new vo_PhieuNhapHang();
                    this.InitValue();
                    this.lvHangHoa.ItemsSource          = this.bus_HH.GetAllHangHoa();
                    this.iGridViewPhieuNhap.ItemsSource = this.dsHangHoaCuaPhieuNhap;
                    this.DataContext = this.vo_PN;

                    MessageBox.Show("Thêm phiếu nhập thành công!", "Thành công!", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi!", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 2
0
 //update ghi chu phieu nhap
 public int UpdateGhiChuPhieuNhap(vo_PhieuNhapHang _vo)
 {
     try
     {
         dao_PhieuNhapHang dao = new dao_PhieuNhapHang();
         int id = dao.UpdateGhiChuPhieuNhap(_vo);
         return(id);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 3
0
 private void tbvPhieuNhap_RowDoubleClick(object sender, DevExpress.Xpf.Grid.RowDoubleClickEventArgs e)
 {
     try
     {
         vo_PhieuNhapHang          _voPN        = (vo_PhieuNhapHang)this.iGridViewPhieuNhap.SelectedItem;
         pl_windowChiTietPhieuNhap _plChiTietPN = new pl_windowChiTietPhieuNhap(_voPN);
         _plChiTietPN.ShowDialog();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Loi!", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Ejemplo n.º 4
0
        public pl_windowChiTietPhieuNhap(vo_PhieuNhapHang _vo)
        {
            try
            {
                this.bus_PN = new bus_PhieuNhapHang();
                InitializeComponent();

                vo_PN            = this.bus_PN.GetChiTietPhieuNhapHang(_vo.MaPhieuNhap);
                this.DataContext = vo_PN;
                this.iGridViewPhieuNhap.ItemsSource = vo_PN.DsHangHoa;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Loi!", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 5
0
        // tra ve so hang hoa da them thanh cong
        public int InsertChiTietPhieuNhap(params object[] oParams)
        {
            try
            {
                if (oParams != null)
                {
                    vo_PhieuNhapHang vo_PN = (vo_PhieuNhapHang)oParams[0];
                    ObservableCollection <vo_HangHoa> dsHangHoa = vo_PN.DsHangHoa;

                    int soHangHoa = 0;
                    foreach (vo_HangHoa vo in dsHangHoa)
                    {
                        ConnectionString cnn   = new ConnectionString();
                        string           query = "INSERT INTO CHITIETPHIEUNHAPHANG(MAHANGHOA, MAPHIEUNHAP, SOLUONG, DONGIA) output 1 " +
                                                 "VALUES(@maHH, @maPN, @soLuong, @donGia)";
                        string[]    arrParam  = new string[] { "@maHH", "@maPN", "@soLuong", "@donGia" };
                        SqlDbType[] arrType   = new SqlDbType[] { SqlDbType.NVarChar, SqlDbType.NVarChar, SqlDbType.Int, SqlDbType.Int };
                        object[]    arrvalues = new object[] { vo.MaHangHoa, vo_PN.MaPhieuNhap, vo.SoLuong, vo.GiaVon };
                        cnn.conn.ExecuteQueryReturnID(query, arrParam, arrvalues, arrType);


                        string           _query = "UPDATE HANGHOA SET GIABAN=@giaban, GIAVON=@giavon, TONKHO=@tonkho, GIAGIAM=@giagiam OUTPUT INSERTED.ID WHERE MAHANGHOA=@mahh";
                        ConnectionString _cnn   = new ConnectionString();

                        string[]    _arrParam = new string[] { "@giaban", "@giavon", "@tonkho", "@ghichu", "@giagiam", "@mahh" };
                        SqlDbType[] _arrType  = new SqlDbType[] { SqlDbType.Int, SqlDbType.Int, SqlDbType.Int,
                                                                  SqlDbType.NVarChar, SqlDbType.Int, SqlDbType.NVarChar };
                        object[] _arrvalues = new object[] { vo.GiaBan, vo.GiaVon, vo.TonKho + vo.SoLuong, vo.GhiChu, vo.GiaGiam, vo.MaHangHoa };
                        int      id         = cnn.conn.ExecuteQueryReturnID(_query, _arrParam, _arrvalues, _arrType);
                        soHangHoa++;
                    }
                    return(soHangHoa);
                }

                return(0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 6
0
 public int UpdateGhiChuPhieuNhap(params object[] oParams)
 {
     try
     {
         if (oParams != null)
         {
             vo_PhieuNhapHang vo        = (vo_PhieuNhapHang)oParams[0];
             ConnectionString cnn       = new ConnectionString();
             string           query     = "UPDATE PHIEUNHAPHANG SET GHICHU=@ghichu output INSERTED.ID WHERE ID=@id";
             string[]         arrParam  = new string[] { "@ghichu", "@id" };
             SqlDbType[]      arrType   = new SqlDbType[] { SqlDbType.NVarChar, SqlDbType.Int };
             object[]         arrvalues = new object[] { vo.GhiChu, vo.Id };
             return(cnn.conn.ExecuteQueryReturnID(query, arrParam, arrvalues, arrType));
         }
         return(0);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 7
0
        // them phieu nhap va chi tiet phieu nhap
        public int AddPhieuNhapHang(vo_PhieuNhapHang vo)
        {
            try
            {
                dao_PhieuNhapHang dao = new dao_PhieuNhapHang();
                vo.ThoiGian = Utilities.DotNetToVietNam(DateTime.Now.ToString());
                int id = dao.InsertPhieuNhap(vo);

                // neu insert phieu nhap thanh cong va tra ve id > 0 thi insert chi tiet
                if (id > 0)
                {
                    int num = dao.InsertChiTietPhieuNhap(vo);
                    // tra ve so hang hoa da dc them vao
                    return(num);
                }

                return(0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 8
0
 public int UpdatePhieuNhap(params object[] oParams)
 {
     try
     {
         if (oParams != null)
         {
             vo_PhieuNhapHang vo    = (vo_PhieuNhapHang)oParams[0];
             ConnectionString cnn   = new ConnectionString();
             string           query = "UPDATE PHIEUNHAPHANG SET TONGTIENCANTRA=@tongtien, DATRA=@datra, THOIGIAN=@thoigian, GHICHU=@ghichu, MANHACUNGCAP=@ghichu, MANHANVIEN=@maNV, TONGGIAM=@tongGiam " +
                                      "WHERE ID=@id";
             string[]    arrParam = new string[] { "@tongtien", "@datra", "@thoigian", "@ghichu", "@maNCC", "@maNV", "@tongGiam", "@id" };
             SqlDbType[] arrType  = new SqlDbType[] { SqlDbType.BigInt, SqlDbType.BigInt, SqlDbType.NVarChar, SqlDbType.NVarChar, SqlDbType.NVarChar,
                                                      SqlDbType.NVarChar, SqlDbType.BigInt, SqlDbType.Int };
             object[] arrvalues = new object[] { vo.TongTien, vo.DaTra, vo.ThoiGian, vo.GhiChu, vo.MaNhaCungCap, vo.MaNhanVien, vo.TongGiam, vo.Id };
             return(cnn.conn.ExecuteQueryReturnID(query, arrParam, arrvalues, arrType));
         }
         return(0);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 9
0
 public int InsertPhieuNhap(params object[] oParams)
 {
     try
     {
         if (oParams != null)
         {
             vo_PhieuNhapHang vo    = (vo_PhieuNhapHang)oParams[0];
             ConnectionString cnn   = new ConnectionString();
             string           query = "INSERT INTO PHIEUNHAPHANG(MAPHIEUNHAP, TONGTIENCANTRA, DATRA, THOIGIAN, GHICHU, MANHACUNGCAP, MANHANVIEN, TONGGIAM) output INSERTED.ID " +
                                      "VALUES (@mapn, @tongtien, @datra, @thoigian, @ghichu, @maNCC, @maNV, @tongGiam)";
             string[]    arrParam = new string[] { "@mapn", "@tongtien", "@datra", "@thoigian", "@ghichu", "@maNCC", "@maNV", "@tongGiam" };
             SqlDbType[] arrType  = new SqlDbType[] { SqlDbType.NVarChar, SqlDbType.Int, SqlDbType.Int, SqlDbType.NVarChar, SqlDbType.NVarChar, SqlDbType.NVarChar,
                                                      SqlDbType.NVarChar, SqlDbType.Int };
             object[] arrvalues = new object[] { vo.MaPhieuNhap, vo.TongTien, vo.DaTra, vo.ThoiGian, vo.GhiChu, vo.MaNhaCungCap, vo.MaNhanVien, vo.TongGiam };
             return(cnn.conn.ExecuteQueryReturnID(query, arrParam, arrvalues, arrType));
         }
         return(0);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 10
0
        // lay chi tiet phieu nhap hang
        public vo_PhieuNhapHang GetChiTietPhieuNhapHang(string _code)
        {
            try
            {
                dao_PhieuNhapHang dao          = new dao_PhieuNhapHang();
                vo_PhieuNhapHang  vo_phieuNhap = new vo_PhieuNhapHang();

                //lay thong tin phieu nhap
                DataTable dt = dao.GetPhieuNhapById(_code);
                if (dt != null && dt.Rows.Count > 0)
                {
                    vo_phieuNhap.DaTra        = int.Parse(dt.Rows[0]["DATRA"].ToString());
                    vo_phieuNhap.GhiChu       = dt.Rows[0]["GHICHU"].ToString();
                    vo_phieuNhap.Id           = int.Parse(dt.Rows[0]["ID"].ToString());
                    vo_phieuNhap.MaNhaCungCap = dt.Rows[0]["MANHACUNGCAP"].ToString();
                    vo_phieuNhap.NhaCungCap   = dt.Rows[0]["TENNHACUNGCAP"].ToString();
                    vo_phieuNhap.MaNhanVien   = dt.Rows[0]["MANHANVIEN"].ToString();
                    vo_phieuNhap.TenNhanVien  = dt.Rows[0]["HOTEN"].ToString();
                    vo_phieuNhap.MaPhieuNhap  = dt.Rows[0]["MAPHIEUNHAP"].ToString();
                    vo_phieuNhap.ThoiGian     = Utilities.DotNetToVietNam(dt.Rows[0]["THOIGIAN"].ToString());
                    vo_phieuNhap.TongGiam     = int.Parse(dt.Rows[0]["TONGGIAM"].ToString());
                    vo_phieuNhap.TongTien     = int.Parse(dt.Rows[0]["TONGTIENCANTRA"].ToString());
                    vo_phieuNhap.DsHangHoa    = new ObservableCollection <vo_HangHoa>();
                }


                // lay danh sach hang hoa trong phieu nhap
                DataTable dtDsHangHoa = dao.GetDanhSachHangHoaByPhieuNhap(_code);

                if (dtDsHangHoa != null && dtDsHangHoa.Rows.Count > 0)
                {
                    foreach (DataRow dr in dtDsHangHoa.Rows)
                    {
                        vo_HangHoa vo = new vo_HangHoa();
                        // lay nhung du lieu can thiet
                        vo.MaHangHoa  = dr["MAHANGHOA"].ToString();
                        vo.TenHangHoa = dr["TENHANGHOA"].ToString();
                        vo.SoLuong    = int.Parse(dr["SOLUONG"].ToString());
                        //don gia
                        vo.GiaVon = int.Parse(dr["DONGIA"].ToString());
                        //gia giam
                        if (string.IsNullOrEmpty(dr["GIAGIAM"].ToString()))
                        {
                            vo.GiaGiam = 0;
                        }
                        else
                        {
                            vo.GiaGiam = int.Parse(dr["GIAGIAM"].ToString());
                        }
                        vo.LoaiHangHoa = dr["LOAIHANGHOA"].ToString();

                        vo_phieuNhap.DsHangHoa.Add(vo);
                    }
                }
                return(vo_phieuNhap);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }