Example #1
0
        public static List <SanPhamDTO> SelectSanPhamAll()
        {
            DataTable dataTable = new DataTable();

            dataTable = DataProvider.ExecuteReader("usp_SelectSanPhamAll");
            List <SanPhamDTO> lstspDTO = new List <SanPhamDTO>();

            if (dataTable.Rows.Count > 0)
            {
                foreach (DataRow dtRow in dataTable.Rows)
                {
                    SanPhamDTO spDTO = new SanPhamDTO();
                    spDTO.MaSanPham     = dtRow["MaSanPham"].ToString();
                    spDTO.TenSanPham    = dtRow["TenSanPham"].ToString();
                    spDTO.CV            = int.Parse(dtRow["CV"].ToString());
                    spDTO.DonGia        = float.Parse(dtRow["DonGia"].ToString());
                    spDTO.DonGiaTV      = float.Parse(dtRow["DonGiaTV"].ToString());
                    spDTO.SoLuongTon    = int.Parse(dtRow["SoLuongTon"].ToString());
                    spDTO.MaLoaiSanPham = dtRow["MaLoaiSanPham"].ToString();
                    //select sp.MaSanPham, sp.TenSanPham, sp.CV, sp.DonGia, sp.DonGiaTV, sp.SoLuongTon, sp.MaLoaiSanPham
                    lstspDTO.Add(spDTO);
                }
            }
            else
            {
                lstspDTO = null;
            }
            return(lstspDTO);
        }
Example #2
0
        public void testSuaSanPham()
        {
            this.sp1 = new SanPhamDTO("1", "Sữa tắm siêu cấp mướt lông", "CSCM", "15", "6000", "30000");
            this.sp2 = new SanPhamDTO("2", "Áo lụa Mông Cổ", "PKCM", "10", "25000", "80000");
            this.sp3 = new SanPhamDTO("3", "Thuốc an thần liều cao", "DPCM", "15", "72000", "200000");

            this.sanphamDAO.Update(this.sp1);
            Assert.AreEqual("Sữa tắm siêu cấp mướt lông", sanphamDAO.GetSanPham()[0].TenSP);
            Assert.AreEqual("15", sanphamDAO.GetSanPham()[0].SLTonKho);
            Assert.AreNotEqual("Sữa tắm mướt lông", sanphamDAO.GetSanPham()[0].TenSP);
            Assert.AreNotEqual("30", sanphamDAO.GetSanPham()[0].SLTonKho);

            this.sanphamDAO.Update(this.sp2);
            Assert.AreEqual("PKCM", sanphamDAO.GetSanPham()[1].MaLSP);
            Assert.AreEqual("25000", sanphamDAO.GetSanPham()[1].DGNhap);
            Assert.AreNotEqual("DDCM", sanphamDAO.GetSanPham()[1].MaLSP);
            Assert.AreNotEqual("20000", sanphamDAO.GetSanPham()[1].DGNhap);

            this.sanphamDAO.Update(this.sp3);
            Assert.AreEqual("Thuốc an thần liều cao", sanphamDAO.GetSanPham()[2].TenSP);
            Assert.AreEqual("72000", sanphamDAO.GetSanPham()[2].DGNhap);
            Assert.AreEqual("200000", sanphamDAO.GetSanPham()[2].DGBan);
            Assert.AreNotEqual("Thuốc an thần", sanphamDAO.GetSanPham()[2].TenSP);
            Assert.AreNotEqual("60000", sanphamDAO.GetSanPham()[2].DGNhap);
            Assert.AreNotEqual("180000", sanphamDAO.GetSanPham()[2].DGBan);
        }
Example #3
0
        private void luuDuLieu()
        {
            if (chon == null)
            {
                chon = new SanPhamDTO();
            }

            chon.MaSP          = txtMaSP.Text;
            chon.TenSP         = txtTenSP.Text;
            chon.DoTuoi        = txtDoTuoi.Text;
            chon.MoTa          = rtxtMoTa.Text;
            chon.Gia           = decimal.Parse(txtGia.Text.ToString());
            chon.HinhAnh       = chon.MaSP + ".JPG";
            chon.SoLuongTonKho = 0;
            chon.MaLoaiSP      = cmbLoaiSP.SelectedValue.ToString();
            chon.MaNSX         = cmbNSX.SelectedValue.ToString();


            if (chkTinhTrang.Checked == false)
            {
                chon.TinhTrang = 0;
            }
            else
            {
                chon.TinhTrang = 1;
            }
        }
Example #4
0
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        GridView    gv  = (GridView)sender;
        GridViewRow row = GridView1.Rows[e.RowIndex];

        string     sMaSP = gv.DataKeys[e.RowIndex]["MaSP"].ToString();
        SanPhamDTO spDTO = new SanPhamDTO();

        spDTO.Ma = int.Parse(sMaSP);
        if (gv.Rows.Count == 1)
        {
            CurrentPage--;
        }

        string sAvatar = row.Cells[2].Text;

        try
        {
            FileInfo file = new FileInfo(Server.MapPath(sAvatar));
            if (file.Exists)
            {
                File.Delete(Server.MapPath(sAvatar));
            }
        }
        catch
        {
        }

        SanPhamBUS.XoaSanPham(spDTO);

        BindItemsList();
    }
Example #5
0
        private void ThemItem(SanPhamDTO item)
        {
            ListViewItem lvi = new ListViewItem(item.TenSP);

            lvi.Text = item.TenSP + " \n " + item.GiaTien.ToString("#,##0 VNĐ");
            lvi.SubItems.Add(item.MaSP);
            lvi.ImageKey = item.MaSP + "_1";
            //lvi.ToolTipText = item.GiaTien.ToString("#,##0 VNĐ");
            //lvi.SubItems.Add(item.SoLuong.ToString());
            //lvi.SubItems.Add(item.GiaTien.ToString());
            //lvi.SubItems.Add(item.CPU);
            //lvi.SubItems.Add(item.RAM);
            //lvi.SubItems.Add(item.OCung);
            //lvi.SubItems.Add(item.CDDVD);
            //lvi.SubItems.Add(item.VGA);
            //lvi.SubItems.Add(item.ManHinh);
            //lvi.SubItems.Add(item.KetNoi);
            //lvi.SubItems.Add(item.BanPhim);
            //lvi.SubItems.Add(item.TanNhiet);
            //lvi.SubItems.Add(item.TichHop);
            //lvi.SubItems.Add(item.TrongLuong);
            //lvi.SubItems.Add(item.Pin);
            //lvi.SubItems.Add(item.MaLoaiSP);
            //lvi.SubItems.Add(item.MaNSX);
            //lvi.SubItems.Add(item.MaNCC);
            //lvi.SubItems.Add(item.NgayRaMat.ToString());
            //lvi.SubItems.Add(item.TrangThai.ToString());
            lvwDanhSachSP.Items.Add(lvi);
        }
Example #6
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            int    categoryid, Price, userid;
            string id, name, des;

            id         = txtID.Text.Trim();
            name       = txtTenDT.Text.Trim();
            categoryid = int.Parse(txtMaloai.Text.Trim());
            des        = txtMota.Text.Trim();
            Price      = int.Parse(txtGia.Text.Trim());

            userid = int.Parse(txtUserID.Text.Trim());

            SanPhamDTO spo = new SanPhamDTO(id, name, categoryid, des, Price, userid);

            try
            {
                int i = new SanPhamBUS().Add(spo);
                dgvSanPham.DataSource = GetProductGUI();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #7
0
 public DataTable SearchSP6(SanPhamDTO sp)
 {
     return(DBcon.GetTable("select sp.MaSP, sp.TenSP, lsp.TenLoai, ncc.TenNCC, " +
                           " sp.GioiTinh, kc.KichCo, sp.DonGia, sp.GhiChu from SanPham as sp," +
                           " LoaiSP as lsp, NhaCungCap as ncc, KichCo as kc " +
                           "where sp.MaLoai = lsp.MaLoai and sp.MaNCC = ncc.MaNCC and sp.MaKichCo = kc.MaKichCo and sp.GioiTinh like N'%" + sp.GioiTinh + "%'"));
 }
        protected void btnCapNhat_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                SanPhamBUS insertSanPham = new SanPhamBUS();
                SanPhamDTO sanPham       = new SanPhamDTO();

                sanPham.IdDanhMucSanPham        = int.Parse(dropDanhMucSanPham.SelectedItem.Value);
                sanPham.TenSanPham              = txtTenSanPham.Text;       // txtTenSanPham là ID của TextBox
                sanPham.MoTaSanPham             = CKEditorControlMoTa.Text; //txtTenSanPham là ID của TextBox
                sanPham.HinhSanPham.LinkSanPham = fileuploadHinhSanPham.FileBytes;
                // fileuploadHinhSanPham là ID của điều khiển FileUpLoad
                sanPham.GiaSanPham     = int.Parse(txtGia.Text); // txtGia là ID của TextBox
                insertSanPham._sanPham = sanPham;
                try
                {
                    insertSanPham.Insert();
                }
                catch
                {
                    Response.Redirect("../Trangloi.aspx");
                }
                // tắt khúc này vì chưa có trang SanPham.aspx nên khi add thành công thì nó chuyển qua trang SanPham sẽ lỗi
                //Response.Redirect("SanPham.aspx");
            }
        }
Example #9
0
        //---------------Sự kiện cho nút tạo và gửi đơn hàng-----------------

        protected void ImageButtonTaovaguidonhang_Click(object sender, EventArgs e)
        {
            DonHangDTO donHang = new DonHangDTO();

            SanPhamDTO[] dsSanPham = new SanPhamDTO[gridgiohang.Rows.Count];
            foreach (GridViewRow grow in gridgiohang.Rows)
            {
                if (grow.RowType == DataControlRowType.DataRow)
                {
                    SanPhamDTO sanPham = new SanPhamDTO();
                    DataKey    data    = gridgiohang.DataKeys[grow.DataItemIndex];
                    sanPham.IdSanPham = int.Parse(data.Values["IdSanPham"].ToString());
                    Label lblTenSanPham = (Label)grow.FindControl("lblTenSanPham");
                    sanPham.TenSanPham = lblTenSanPham.Text;
                    Label lblSoLuong = (Label)grow.FindControl("lblSoLuong");
                    sanPham.SoLuong = int.Parse(lblSoLuong.Text);
                    Label lblDonGia = (Label)grow.FindControl("lblDonGia");
                    sanPham.GiaSanPham = Convert.ToInt32(lblDonGia.Text.Replace("VND", "").Replace(",", ""));
                    dsSanPham.SetValue(sanPham, grow.DataItemIndex);
                }
            }
            _donhang.ChiTietDonHang.SanPham = dsSanPham;
            _donhang.IdNguoiDung            = _NguoiDungHienTai.IdNguoiDung;
            //Giả lập tạo TransactionID
            _donhang.MaGiaoDich = Guid.NewGuid().ToString();
            GuiDonHang();
        }
Example #10
0
        public List <SanPhamDTO> GetLSPWK(string MaLSP)
        {
            string            sql  = "SELECT * FROM SanPham WHERE MaLoaiSanPham ='" + MaLSP + "' ";
            List <SanPhamDTO> list = new List <SanPhamDTO>();

            Connect();
            string MaSP, TenSP, SLTonKho, DGNhap, DGBan;

            try
            {
                SqlDataReader rd = myExecuteDataReader(sql);
                while (rd.Read())
                {
                    MaSP     = rd[0].ToString();
                    TenSP    = rd[1].ToString();
                    MaLSP    = rd[2].ToString();
                    SLTonKho = rd[3].ToString();
                    DGNhap   = rd[4].ToString();
                    DGBan    = rd[5].ToString();

                    SanPhamDTO sp = new SanPhamDTO(MaSP, TenSP, MaLSP, SLTonKho, DGNhap, DGBan);
                    list.Add(sp);
                }
                rd.Close();
                return(list);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                Disconnect();
            }
        }
        protected void btnCapNhat_Click(object sender, EventArgs e)
        {
            SanPhamDTO sp  = SanPhamBUS.LayDSSanPhamCapNhat(txtmasp.Text);
            SanPhamDTO sp2 = SanPhamBUS.LayDSSanPhamCapNhat(txtmasp.Text);

            sp.TenSP    = txtTenSP.Text;
            sp.ThongTin = txtThongTin.Text;
            sp.GiaTien  = Convert.ToInt32(txtGiaTien.Text);
            sp.MaLoaiSp = ddlSanPham.SelectedValue.ToString();
            if (imgHinhSanPham.HasFile)
            {
                string sTenfile;
                sTenfile = imgHinhSanPham.FileName;
                imgHinhSanPham.SaveAs(MapPath("../images/" + sTenfile));
                sp.AnhMinhHoa = sTenfile.ToString();
            }
            else
            {
                sp2.AnhMinhHoa = sp.AnhMinhHoa;
            }
            if (SanPhamBUS.CapNhatSP(sp, txtmasp.Text))
            {
                load();
                Response.Write("<script>alert('Cập nhật sản phẩm thành công!')</script>");
            }
            else
            {
                Response.Write("<script>alert('Cập nhật sản phẩm thất bại!')</script>");
            }
        }
Example #12
0
 private void btnTimsp_Click(object sender, EventArgs e)
 {
     try
     {
         SanPhamDTO     sp     = new SanPhamDTO();
         LoaiSanPhamDTO loaisp = new LoaiSanPhamDTO();
         if (cbxTimTheoSP.SelectedIndex == 0)
         {
             sp.ma_sp = txtTimTheosp.Text;
             if (SanPhamBUS.Search_MaSP(sp).Rows.Count == 0)
             {
                 MessageBox.Show("Không có thông tin bạn cần tìm", "Thông báo", MessageBoxButtons.OK);
             }
             else
             {
                 dgvSanPham.DataSource = SanPhamBUS.Search_MaSP(sp);
             }
         }
         if (cbxTimTheoSP.SelectedIndex == 1)
         {
             loaisp.ten_loai_sp = txtTimTheosp.Text;
             if (SanPhamBUS.Search_LoaiSP(loaisp).Rows.Count == 0)
             {
                 MessageBox.Show("Không có thông tin bạn cần tìm", "Thông báo", MessageBoxButtons.OK);
             }
             else
             {
                 dgvSanPham.DataSource = SanPhamBUS.Search_LoaiSP(loaisp);
             }
         }
         if (cbxTimTheoSP.SelectedIndex == 2)
         {
             sp.ten_sp = txtTimTheosp.Text;
             if (SanPhamBUS.Search_TenSP(sp).Rows.Count == 0)
             {
                 MessageBox.Show("Không có thông tin bạn cần tìm", "Thông báo", MessageBoxButtons.OK);
             }
             else
             {
                 dgvSanPham.DataSource = SanPhamBUS.Search_TenSP(sp);
             }
         }
         if (cbxTimTheoSP.SelectedIndex == 3)
         {
             sp.hang_san_xuat = txtTimTheosp.Text;
             if (SanPhamBUS.Search_HSXSP(sp).Rows.Count == 0)
             {
                 MessageBox.Show("Không có thông tin bạn cần tìm", "Thông báo", MessageBoxButtons.OK);
             }
             else
             {
                 dgvSanPham.DataSource = SanPhamBUS.Search_HSXSP(sp);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Example #13
0
    /// <summary>
    /// Build DataTable to bind Main Items List
    /// </summary>
    /// <returns>DataTable</returns>
    private DataTable GetDataTable()
    {
        DataTable dtItems = new DataTable();
        string    sMaLoai = Server.UrlDecode(Request.QueryString["MaLoai"]);

        if (sMaLoai == null)
        {
            sMaLoai = "0";
        }
        string     sKey   = Server.UrlDecode(Request.QueryString["Key"]);
        string     sMaNSX = Server.UrlDecode(Request.QueryString["MaNSX"]);
        SanPhamDTO spDTO  = new SanPhamDTO();

        if (txtGiaNho.Text == "")
        {
            spDTO.GiaNho = -1;
        }
        else
        {
            spDTO.GiaNho = int.Parse(txtGiaNho.Text);
        }
        if (txtGiaLon.Text == "")
        {
            spDTO.GiaLon = -1;
        }
        else
        {
            spDTO.GiaLon = int.Parse(txtGiaLon.Text);
        }
        spDTO.Key    = sKey;
        spDTO.NSX    = sMaNSX;
        spDTO.LoaiSP = int.Parse(sMaLoai);
        dtItems      = SanPhamBUS.LayThongTinSanPham(spDTO);
        return(dtItems);
    }
Example #14
0
        public static SanPhamDTO SelectSanPhamById(string MaSanPham)
        {
            List <SqlParameter> sqlParams = new List <SqlParameter>();

            sqlParams.Add(new SqlParameter("@MaSanPham", MaSanPham));
            DataTable dataTable = new DataTable();

            dataTable = DataProvider.ExecuteReader("usp_SelectSanPhamById", sqlParams);
            SanPhamDTO spDTO = new SanPhamDTO();

            if (dataTable.Rows.Count > 0)
            {
                DataRow dtRow = dataTable.Rows[0];
                //List<SanPhamDTO> lstspDTO = new List<SanPhamDTO>();

                spDTO.MaSanPham     = dtRow["MaSanPham"].ToString();
                spDTO.TenSanPham    = dtRow["TenSanPham"].ToString();
                spDTO.CV            = int.Parse(dtRow["CV"].ToString());
                spDTO.DonGia        = float.Parse(dtRow["DonGia"].ToString());
                spDTO.DonGiaTV      = float.Parse(dtRow["DonGiaTV"].ToString());
                spDTO.SoLuongTon    = int.Parse(dtRow["SoLuongTon"].ToString());
                spDTO.MaLoaiSanPham = dtRow["MaLoaiSanPham"].ToString();
                //select sp.MaSanPham, sp.TenSanPham, sp.CV, sp.DonGia, sp.DonGiaTV, sp.SoLuongTon, sp.MaLoaiSanPham
                // lstspDTO.Add(spDTO);
            }
            else
            {
                spDTO = null;
            }
            return(spDTO);
        }
Example #15
0
    public static DataTable LayThongTinSanPham(SanPhamDTO spDTO)
    {
        string sQuery = "";

        if (spDTO.LoaiSP == 0 && spDTO.NSX != null && spDTO.Key == null && spDTO.GiaLon == -1)
        {
            sQuery = "select * from SanPham where NSX ='" + spDTO.NSX + "' and Active = 1 order by NgayNhapHang DESC";
        }
        if (spDTO.LoaiSP != 0 && spDTO.NSX == null && spDTO.Key == null && spDTO.GiaLon == -1)
        {
            sQuery = "select * from SanPham where LoaiSP =" + spDTO.LoaiSP + " and Active = 1 order by NgayNhapHang DESC";
        }
        if (spDTO.LoaiSP != 0 && spDTO.NSX != null && spDTO.Key == null && spDTO.GiaLon == -1)
        {
            sQuery = "select * from SanPham where LoaiSP =" + spDTO.LoaiSP + " and NSX ='" + spDTO.NSX + "' and Active = 1 order by NgayNhapHang DESC";
        }
        if (spDTO.LoaiSP == 0 && spDTO.NSX == null && spDTO.Key != null && spDTO.GiaLon == -1)
        {
            sQuery = "select * from SanPham where TenSP like '%" + spDTO.Key + "%' or NSX like '%"
                     + spDTO.Key + "%' or DonGia like '%" + spDTO.Key + "%' and Active = 1 order by NgayNhapHang DESC";
        }
        if (spDTO.LoaiSP == 0 && spDTO.NSX == null && spDTO.Key == null && spDTO.GiaLon == -1)
        {
            sQuery = "select * from SanPham where Active = 1 ORDER BY NgayNhapHang DESC";
        }
        if (spDTO.GiaNho >= 0 && spDTO.GiaNho > 0)
        {
            sQuery = "select * from SanPham where DonGia >=" + spDTO.GiaNho + " and Active = 1  and DonGia <=" + spDTO.GiaLon;
        }
        OleDbConnection con = DataProvider.TaoKetNoi();
        DataTable       dt  = DataProvider.LayDataTable(sQuery, con);

        DataProvider.DongKetNoi(con);
        return(dt);
    }
Example #16
0
        public List <SanPhamDTO> TKTHEOGIAten(string ma, string giatu, string giaden)
        {
            List <SanPhamDTO> lsdto   = new List <SanPhamDTO>();
            string            truyvan = "SELECT * FROM SAN_PHAM SAN_PHAM WHERE TENSP LIKE N'%" + ma + "%' AND GIA >= " + giatu + " AND GIA <= " + giaden + "";
            SqlConnection     con     = DataProvider.TaoKetNoi();
            SqlDataReader     sr      = DataProvider.TruyVanDuLieu(truyvan, con);

            while (sr.Read())
            {
                SanPhamDTO dto = new SanPhamDTO();
                dto.MaSP          = sr["MaSP"].ToString();
                dto.TenSP         = sr["TenSP"].ToString();
                dto.DoTuoi        = sr["DoTuoi"].ToString();
                dto.MoTa          = sr["MoTa"].ToString();
                dto.Gia           = decimal.Parse(sr["Gia"].ToString());
                dto.SoLuongTonKho = int.Parse(sr["SoLuongTonKho"].ToString());
                dto.HinhAnh       = sr["HinhAnh"].ToString();
                dto.MaLoaiSP      = sr["MaLoaiSP"].ToString();
                dto.MaNSX         = sr["MaNSX"].ToString();
                dto.TinhTrang     = int.Parse(sr["TinhTrang"].ToString());
                lsdto.Add(dto);
            }
            sr.Close();
            con.Close();
            return(lsdto);
        }
Example #17
0
        public static List <SanPhamDTO> LaySPTheoTuKhoa(string tukhoa)
        {
            SqlDataReader     reader = DataProvider.TruyVanSPTheoTuKhoa("LaySPTheoTuKhoa", tukhoa);
            List <SanPhamDTO> lsp    = new List <SanPhamDTO>();

            try
            {
                while (reader.Read())
                {
                    SanPhamDTO sp = new SanPhamDTO();
                    sp.MaSP       = reader.GetString(0);
                    sp.TenSP      = reader.GetString(1);
                    sp.TenLoaiSP  = reader.GetString(3);
                    sp.TenDanhMuc = reader.GetString(2);
                    sp.XuatXu     = reader.GetString(4);
                    sp.DonViTinh  = reader.GetString(5);
                    sp.GiaBan     = (int)reader.GetDecimal(6);
                    sp.SoLuong    = reader.GetInt32(7);
                    lsp.Add(sp);
                }
                reader.Close();
            }
            catch
            {
            }

            return(lsp);
        }
Example #18
0
        public List <SanPhamDTO> LayDSSanPhamTheoLoai(string maLoai)
        {
            List <SanPhamDTO> lsdto   = new List <SanPhamDTO>();
            string            truyvan = "SELECT * FROM SAN_PHAM WHERE MaLoaiSP = '" + maLoai + "' ";

            SqlParameter[] p = new SqlParameter[1];
            p[0] = new SqlParameter("@maLoai", maLoai);
            SqlConnection con = DataProvider.TaoKetNoi();
            SqlDataReader sr  = DataProvider.TruyVanDuLieu(truyvan, con);

            while (sr.Read())
            {
                SanPhamDTO dto = new SanPhamDTO();
                dto.MaSP          = sr["MaSP"].ToString();
                dto.TenSP         = sr["TenSP"].ToString();
                dto.DoTuoi        = sr["DoTuoi"].ToString();
                dto.MoTa          = sr["MoTa"].ToString();
                dto.Gia           = decimal.Parse(sr["Gia"].ToString());
                dto.SoLuongTonKho = int.Parse(sr["SoLuongTonKho"].ToString());
                dto.HinhAnh       = sr["HinhAnh"].ToString();
                dto.MaLoaiSP      = sr["MaLoaiSP"].ToString();
                dto.MaNSX         = sr["MaNSX"].ToString();
                if (maLoai == dto.MaLoaiSP)
                {
                    lsdto.Add(dto);
                }
            }
            sr.Close();
            con.Close();
            return(lsdto);
        }
Example #19
0
        //Status=0 Load_Default(), thanhphanNhap và DataGripView khi status = 0
        private void Load_Create()
        {
            Load_Default();

            //lamlai thanh phan nhap
            txtMaThanhVien.Clear();
            txtTenKhachHang.Clear();
            txtDiaChi.Clear();
            txtTenKhachHang.ReadOnly = false;
            txtDiaChi.ReadOnly       = false;

            //Load Datagripview
            int stt = 1;
            List <SanPhamDTO> listSanPhamDTO = SanPhamBUS.SelectSanPhamAll();

            if (listSanPhamDTO != null)
            {
                dataGridView_XuatHang.Rows.Clear();
                SanPhamDTO sanPhamDTO = new SanPhamDTO();
                for (int i = 0; i < listSanPhamDTO.Count; i++)
                {
                    sanPhamDTO = listSanPhamDTO[i];
                    dataGridView_XuatHang.Rows.Add(stt, sanPhamDTO.MaSanPham, sanPhamDTO.TenSanPham, sanPhamDTO.CV, sanPhamDTO.DonGia, sanPhamDTO.SoLuongTon, 0, 0);
                    stt++;
                }
            }
            btnTao.Enabled = false;
        }
Example #20
0
        public List <SanPhamDTO> LayDSSanPhamTheoNSX(string mansx)
        {
            List <SanPhamDTO> lsdto   = new List <SanPhamDTO>();
            string            truyvan = "SELECT * FROM SAN_PHAM WHERE MaNSX like N'%" + mansx + "%' ";
            SqlConnection     con     = DataProvider.TaoKetNoi();
            SqlDataReader     sr      = DataProvider.TruyVanDuLieu(truyvan, con);

            while (sr.Read())
            {
                SanPhamDTO dto = new SanPhamDTO();
                dto.MaSP          = sr["MaSP"].ToString();
                dto.TenSP         = sr["TenSP"].ToString();
                dto.DoTuoi        = sr["DoTuoi"].ToString();
                dto.MoTa          = sr["MoTa"].ToString();
                dto.Gia           = decimal.Parse(sr["Gia"].ToString());
                dto.SoLuongTonKho = int.Parse(sr["SoLuongTonKho"].ToString());
                dto.HinhAnh       = sr["HinhAnh"].ToString();
                dto.MaLoaiSP      = sr["MaLoaiSP"].ToString();
                dto.MaNSX         = sr["MaNSX"].ToString();
                dto.TinhTrang     = int.Parse(sr["TinhTrang"].ToString());
                lsdto.Add(dto);
            }
            sr.Close();
            con.Close();
            return(lsdto);
        }
Example #21
0
        private void lsvNhapSP_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lsvNhapSP.SelectedItems.Count > 0)
            {
                dgvDanhSachSP.AutoGenerateColumns = false;
                ListViewItem lviChon = lsvNhapSP.SelectedItems[0];
                chon = lsdto.Find(o => o.TenSP == lviChon.SubItems[1].Text);
                ChiTietHDNhapDTO ct = lscthdb.Find(o => o.MaSP == chon.MaSP);
                if (ct != null) //Đã tồn tại
                {
                    ct.SoLuong += 1;
                }
                else
                {
                    ct         = new ChiTietHDNhapDTO();
                    ct.MaSP    = chon.MaSP.ToString();
                    ct.TenSP   = chon.TenSP.ToString();
                    ct.SoLuong = 1;
                    ct.DonGia  = chon.Gia * ct.SoLuong;
                    lscthdb.Add(ct);
                }
                txtTongTien.Text = lscthdb.Sum(o => o.ThanhTien).ToString();
                txtTongSL.Text   = lscthdb.Sum(o => o.SoLuong).ToString();


                dgvDanhSachSP.DataSource = null;
                dgvDanhSachSP.DataSource = lscthdb;
            }
            else
            {
                chon = null;
            }
            BindingChiTiet();
        }
Example #22
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            SanPhamDTO sp = new SanPhamDTO();

            sp.Ten    = txtTen.Text;
            sp.MoTa   = txtMota.Text;
            sp.Gia    = Convert.ToInt32(txtGia.Text);
            sp.HSD    = txtHSD.Text;
            sp.LoaiSP = Convert.ToInt32(cbLoaiSP.SelectedValue);
            sp.NCC    = Convert.ToInt32(cbNCC.SelectedValue);
            sp.Hinh   = "";
            sp.TThai  = 1;
            if (radAn.Checked)
            {
                sp.TThai = 0;
            }
            int id = SanPhamBUS.themSanPham(sp);

            if (openFileDialog1.Tag != null)
            {
                string filePath = (string)openFileDialog1.Tag;
                string img      = id + Path.GetExtension(filePath);
                File.Copy(filePath, "images\\" + img, true);
                SanPhamBUS.capNhatAnhSP(id, img);
            }
            MessageBox.Show("Thêm sản phẩm thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.Close();
        }
Example #23
0
        public List <SanPhamDTO> GetSanPhamDAO(string sql)
        {
            List <SanPhamDTO> list = new List <SanPhamDTO>();
            int    categoryid, Price, userid;
            string id, name, des, img;

            try
            {
                SqlDataReader dr = cls.ExcuteReader(sql);;

                while (dr.Read())
                {
                    id         = dr.GetInt32(0).ToString();
                    name       = dr.GetString(1);
                    categoryid = dr.GetInt32(2);
                    des        = dr.GetString(3);
                    Price      = dr.GetInt32(4);
                    // img = dr.GetString(5);
                    userid = dr.GetInt32(6);

                    SanPhamDTO sp = new SanPhamDTO(id, name, categoryid, des, Price, userid);
                    list.Add(sp);
                }
                return(list);
            }

            catch (SqlException ex)
            {
                return(null);

                throw ex;
            }
        }
        public bool UpdateSanPham(SanPhamDTO dto)
        {
            var oldSanPham = _context.SanPhams
                             .Include(sp => sp.DanhMuc)
                             .FirstOrDefault(sp => sp.Id.Equals(dto.MaSanPham));

            if (oldSanPham == null)
            {
                throw new KeyNotFoundException(dto.MaSanPham);
            }

            oldSanPham.TenSanPham = dto.TenSanPham;
            oldSanPham.SoLuong    = dto.SoLuong;
            oldSanPham.DonGia     = dto.DonGia;
            oldSanPham.XuatXu     = dto.XuatXu;
            oldSanPham.DanhMucId  = dto.DanhMuc.MaDM;

            try
            {
                _context.SaveChanges();
            }
            catch (Exception ex)
            {
                throw new ArgumentException(ex.InnerException == null ? ex.Message : ex.InnerException.Message);
            }

            return(true);
        }
Example #25
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                SanPhamDTO sp = SanPhamBUS.LaySanPhamTheoMaSp(Request.QueryString["qqq"]);
                lblTenSP.Text          = sp.TenSP;
                imgAnhMinhHoa.ImageUrl = "images/" + sp.AnhMinhHoa;
                lblThongTin.Text       = sp.ThongTin;
                lblMaSP.Text           = sp.MaSP;
                lblGia.Text            = sp.GiaTien.ToString();
                lblMaSP.Visible        = false;


                DropDownList_size.DataSource     = SanPhamBUS.LaySanPhamTheoTheoSise(Request.QueryString["qqq"]);
                DropDownList_size.DataTextField  = "sizenumber";
                DropDownList_size.DataValueField = "SoLuongTonKho";
                DropDownList_size.DataBind();

                lblSLTK.Text = DropDownList_size.Items[0].Value.ToString();

                rpt_LoaiGiay.DataSource = LoaiSanPhamBUS.LayDSLoaiSanPham();
                rpt_LoaiGiay.DataBind();

                rpt_SizeGiay.DataSource = SizeGiayBUS.LayDSSize();
                rpt_SizeGiay.DataBind();

                rpt_spcungloai.DataSource = SanPhamBUS.LaySanPhamCungLoaiTrongTrangChiTiet(sp.MaLoaiSP);
                rpt_spcungloai.DataBind();
            }
        }
Example #26
0
 public HttpResponseMessage GetById([FromUri] int id)
 {
     try
     {
         SanPham entity = db.SanPhams.SingleOrDefault(x => x.MaSP == id);
         if (entity == null)
         {
             return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Not Found"));
         }
         else
         {
             SanPhamDTO sp = new SanPhamDTO();
             sp.MaSP        = entity.MaSP;
             sp.TenSP       = entity.TenSP;
             sp.DonGia      = entity.DonGia;
             sp.NgayCapNhat = entity.NgayCapNhat;
             sp.CauHinh     = entity.CauHinh;
             sp.MoTa        = entity.MoTa;
             sp.HinhAnh     = entity.HinhAnh;
             sp.SoLuongTon  = entity.SoLuongTon;
             sp.LuotXem     = entity.LuotXem;
             sp.Moi         = entity.Moi;
             sp.MaNCC       = entity.MaNCC;
             sp.MaLoaiSP    = entity.MaLoaiSP;
             sp.DaXoa       = entity.DaXoa;
             sp.LoaiSP      = entity.LoaiSP.TenLoaiSP;
             sp.NhaCC       = entity.NhaCungCap.TenNCC;
             return(Request.CreateResponse(HttpStatusCode.OK, sp));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
Example #27
0
        private void btnThemSP_Click(object sender, EventArgs e)
        {
            if (txtTenSP.Text != "" && txtDoTuoi.Text != "" && rtxtMoTa.Text != "" && txtGia.Text != "" && txtSL.Text != "" && picHinh.Image != null)
            {
                luuDuLieu();

                if (bus.ThemSP(chon))
                {
                    if (chon.HinhAnh != null)
                    {
                        picHinh.Image.Save(chon.HinhAnh);
                    }
                    LoadDSSP();
                    MessageBox.Show("Thêm thành công ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("Thêm thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    chon = null;
                }
            }
            else
            {
                MessageBox.Show("Làm ơn, Nhập đầy đủ thông tin", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Example #28
0
 public HttpResponseMessage Create(SanPhamDTO sp)
 {
     try
     {
         SanPham entity = new SanPham();
         entity.TenSP       = sp.TenSP;
         entity.DonGia      = sp.DonGia;
         entity.NgayCapNhat = sp.NgayCapNhat;
         entity.CauHinh     = sp.CauHinh;
         entity.MoTa        = sp.MoTa;
         entity.SoLuongTon  = sp.SoLuongTon;
         entity.LuotXem     = sp.LuotXem;
         entity.Moi         = sp.Moi;
         entity.MaNCC       = sp.MaNCC;
         entity.MaLoaiSP    = sp.MaLoaiSP;
         entity.DaXoa       = sp.DaXoa;
         db.SanPhams.Add(entity);
         db.SaveChanges();
         return(Request.CreateResponse(HttpStatusCode.OK, entity));
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex));
     }
 }
Example #29
0
        public IHttpActionResult PutSanPham(SanPhamDTO sanPham)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Not a valid data"));
            }
            using (QuanLyCoffeeDbContext entities = new QuanLyCoffeeDbContext())
            {
                var sanpham = entities.SanPhams.Where(s => s.SanPhamID == sanPham.SanPhamID)
                              .FirstOrDefault <SanPham>();
                if (sanpham != null)
                {
                    sanpham.TenSP           = sanPham.TenSP;
                    sanpham.MoTa            = sanPham.MoTa;
                    sanpham.LinkImage       = sanPham.LinkImage;
                    sanpham.Gia             = sanPham.Gia;
                    sanpham.LoaiSP.LoaiSPID = sanPham.LoaiSPID;

                    entities.SaveChanges();
                }
                else
                {
                    return(NotFound());
                }
            }
            return(Ok());
        }
        public List <SanPhamDTO> LayDSSP()
        {
            List <SanPhamDTO> SanPhams = new List <SanPhamDTO>();// Tao List

            con.Ketnoi();
            String        Query  = "SELECT sp.MaSanPham, sp.TenSanPham, sp.LoaiSanPham, sp.GiaGoc, sp.GiaBan, sp.SoLuongTon, sp.BaoHanh, sp.KhuyenMai,sp.MaNCC, sp.XuatXu, pn.NgayNhap FROM SanPham sp, PhieuNhap pn WHERE sp.MaNCC = pn.MaNCC";
            SqlDataReader reader = con.getdata(Query);

            while (reader.Read())
            {
                SanPhamDTO SP = new SanPhamDTO();
                SP.MaSP    = reader.GetString(0);
                SP.TenSP   = reader.GetString(1);
                SP.LoaiSP  = reader.GetString(2);
                SP.GiaGoc  = Math.Round(reader.GetDecimal(3));
                SP.GiaBan  = Math.Round(reader.GetDecimal(4));
                SP.SLT     = reader.GetInt32(5);
                SP.BaoHanh = reader.GetDateTime(6);
                SP.KM      = reader.GetInt32(7);
                SP.MaNCC   = reader.GetString(8);
                //SP.TrangThai = reader.GetInt32(9);
                SP.XuatXu   = reader.GetString(9);
                SP.NgayNhap = reader.GetDateTime(10);
                SanPhams.Add(SP);
            }
            con.Ngatketnoi();
            return(SanPhams);
        }