Example #1
0
 private void btnCapNhatLoai_Click(object sender, EventArgs e)
 {
     try
     {
         if (txtMaLoai.Text == "")
         {
             MessageBox.Show("Bạn chưa chọn loại sản phẩm nào", "Thông Báo");
         }
         else if (txtTenLoai.Text == "")
         {
             MessageBox.Show("Bạn chưa cập nhật tên loại sản phẩm", "Thông Báo");
         }
         else
         {
             LoaiSP temp = new LoaiSP();
             temp.MaLoaiSP  = Convert.ToInt32(txtMaLoai.Text);
             temp.TenLoaiSP = txtTenLoai.Text;
             UpdateLoaiSP(temp);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Thông Báo");
     }
 }
        private void frmsuaLoaiSP_Load(object sender, EventArgs e)
        {
            LoaiSP kh = (LoaiSP)this.Tag;

            txtmaloai.Text  = kh.Maloai;
            txttenloai.Text = kh.Tenloai;
        }
Example #3
0
 private void btnLuu_Click(object sender, EventArgs e)
 {
     if (Them)
     {
         try
         {
             LoaiSP sp = new LoaiSP();
             sp.MaLSP = txtMa.Text; sp.TenLSP = txtTenLoai.Text;
             LoaiSPBUS.ThemLSP(sp);
             LoadData();
             // Thông báo
             MessageBox.Show("Đã thêm xong!");
         }
         catch
         {
             MessageBox.Show("Mã loại sản phẩm tồn tai. Nhập Mã loại sản phẩm khác !");
             txtMa.ResetText();
             txtTenLoai.ResetText();
             txtMa.Focus();
         }
     }
     else
     {
         LoaiSP sp = new LoaiSP();
         sp.MaLSP = txtMa.Text; sp.TenLSP = txtTenLoai.Text;
         LoaiSPBUS.SuaLSP(sp);
         LoadData();
         // Thông báo
         MessageBox.Show("Đã sửa xong!");
     }
 }
Example #4
0
        public async Task <IActionResult> PutLoaiSP(int id, [FromBody] LoaiSP loaiSP)
        {
            if (id != loaiSP.MaLoai)
            {
                return(BadRequest());
            }

            _context.Entry(loaiSP).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LoaiSPExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #5
0
        public async Task <ActionResult <LoaiSP> > PostLoaiSP(LoaiSP loaiSP)
        {
            _context.LoaiSP.Add(loaiSP);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetLoaiSP", new { id = loaiSP.MaLoai }, loaiSP));
        }
Example #6
0
 public LoaiSP CreateCategory([FromBody] LoaiSP model)
 {
     model.maloai        = Guid.NewGuid().ToString();
     model.parent_maloai = "10";
     _CategoryBusiness.Create(model);
     return(model);
 }
Example #7
0
        public int updateLoaiSP(LoaiSP loaiSP)
        {
            var roweffect = _dbConnection.Execute($"Update LoaiSP SET tenloai = N'{loaiSP.tenloai}'," +
                                                  $" active = '{loaiSP.active}' where maloai = '{loaiSP.maloai}'", commandType: CommandType.Text);

            return(roweffect);
        }
        public ActionResult Create([Bind(Include = "MaSP,TenSP,Maloai,SL,Gia,Mota,Hinh_anh")] SanPham sanPham, HttpPostedFileBase img)
        {
            if (ModelState.IsValid)
            {
                LoaiSP sp = new LoaiSP();
                try
                {
                    if (img != null)
                    {
                        string fileName = System.IO.Path.GetFileName(img.FileName);
                        string filePath = "~/IMG SANPHAM/" + fileName;
                        img.SaveAs(Server.MapPath(filePath));
                        db.SanPhams.Add(new SanPham
                        {
                            TenSP    = sanPham.TenSP,
                            Mota     = sanPham.Mota,
                            SL       = sanPham.SL,
                            Gia      = sanPham.Gia,
                            Maloai   = sanPham.Maloai,
                            Hinh_anh = fileName
                        });
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                    ViewBag.FileStatus = "File uploaded successfully.";
                }
                catch (Exception)
                {
                }
            }

            ViewBag.Maloai = new SelectList(db.LoaiSPs, "MaLoai", "TenLoai", sanPham.Maloai);

            return(View(sanPham));
        }
Example #9
0
        private List <LoaiSP> GetLoaiHang()
        {
            List <LoaiSP> CaList           = new List <LoaiSP>();
            string        connectionString = Configuration["ConnectionStrings:DefaultConnection"];

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                using (SqlCommand command = new SqlCommand("LayDSLoaiHang", connection))
                {
                    command.CommandType = System.Data.CommandType.StoredProcedure;

                    if (connection.State == ConnectionState.Open)
                    {
                        connection.Close();
                    }

                    SqlDataAdapter da = new SqlDataAdapter(command);
                    DataSet        ds = new DataSet();
                    da.Fill(ds);
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        LoaiSP ca = new LoaiSP();
                        ca.TenLoai = ds.Tables[0].Rows[i]["tenloai"].ToString();
                        ca.MaLoai  = Convert.ToInt32(ds.Tables[0].Rows[i]["maloai"]);
                        CaList.Add(ca);
                    }
                }
            }
            return(CaList);
        }
        private void btnsuabtnsua_Click(object sender, EventArgs e)
        {
            // Tạo kết nối đến CSDL
            SqlConnection con = Database.GetConnection();

            // Tạo lệnh để thực hiện lấy dữ liệu
            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = con;
            cmd.CommandText = "update LoaiSanPham set Maloai = @MaloaiMoi, Tenloai = @Tenloai Where Maloai = @MaloaiCu";
            cmd.Parameters.Add("@MaloaiMoi", SqlDbType.VarChar, 15).Value = txtmaloai.Text;
            cmd.Parameters.Add("@Tenloai", SqlDbType.NVarChar, 50).Value  = txttenloai.Text;


            LoaiSP kh = (LoaiSP)this.Tag;

            cmd.Parameters.Add("@MaloaiCu", SqlDbType.VarChar, 15).Value = kh.Maloai;

            // Thực hiện lệnh.
            cmd.ExecuteNonQuery();

            MessageBox.Show("Đã Sửa mới khách hàng thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);

            frmLoaiSanPham frm = (frmLoaiSanPham)kh.ParentForm;

            frm.LayDSLoaiSP();
            this.Close();
        }
Example #11
0
 private void btnXoa_Click(object sender, EventArgs e)
 {
     try
     {
         if (txtMaSP.Text == "")
         {
             MessageBox.Show("Bạn chưa chọn sản phẩm nào", "Thông Báo");
         }
         else
         {
             SanPham temp = new SanPham();
             temp.MaSP  = Convert.ToInt32(txtMaSP.Text);
             temp.TenSP = txtTenSP.Text;
             temp.Gia   = Convert.ToInt32(txtGiaBan.Text);
             PhongVuContextDB context     = new PhongVuContextDB();
             List <LoaiSP>    listLoaiSPs = context.LoaiSPs.ToList();
             LoaiSP           s           = listLoaiSPs.FirstOrDefault(p => p.TenLoaiSP == cboLoaiSP.Text);
             temp.MaLoaiSP = s.MaLoaiSP;
             temp.Mota     = txtMoTa.Text;
             temp.img      = "aaaa";
             DeleteSanPham(temp);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Thông Báo");
     }
 }
        public async Task <IActionResult> Edit(int id, [Bind("MaLoai,TenLoai,TrangThai")] LoaiSP loaiSP)
        {
            if (id != loaiSP.MaLoai)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(loaiSP);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LoaiSPExists(loaiSP.MaLoai))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View("Index"));
        }
Example #13
0
        public ActionResult Edit(LoaiSP l)
        {
            LoaiSP lsp = db.LoaiSPs.SingleOrDefault(n => n.MaLoai == l.MaLoai);

            lsp.TenLoai = l.TenLoai;
            db.SubmitChanges();
            return(RedirectToAction("QLloaiSp"));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            LoaiSP loaiSP = db.LoaiSPs.Find(id);

            loaiSP.Xoa = true;
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #15
0
        public ActionResult DeleteConfirmed(string id)
        {
            LoaiSP loaiSP = db.LoaiSP.Find(id);

            db.LoaiSP.Remove(loaiSP);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult createLoaiSP(FormCollection frmCreate, LoaiSP a)
        {
            a.TenLoai = frmCreate["TenLoai"];
            a.MaLoai  = Convert.ToInt32(frmCreate["MaLoai"]);

            db.LoaiSPs.Add(a);
            db.SaveChanges();
            return(RedirectToAction("CreateLoaiSP", "AdminCRUD"));
        }
Example #17
0
 public ActionResult Themloai(LoaiSP l)
 {
     if (ModelState.IsValid)
     {
         db.LoaiSPs.InsertOnSubmit(l);
         db.SubmitChanges();
     }
     return(RedirectToAction("QLLoai"));
 }
Example #18
0
        // GET: Admin/LoaiSP/Edit/5
        public ActionResult Edit(int id)
        {
            var lsp = LoaiSPBUS.LoadLoaiSP(id);
            var n   = new LoaiSP();

            n.idLoai  = lsp.idLoai;
            n.TenLoai = lsp.TenLoai;
            return(View(n));
        }
    protected void gvSp_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int    index  = e.RowIndex; //lấy số thứ tự tự động đang đc update
        string str2   = gvSp.DataKeys[index].Value.ToString();
        LoaiSP loaisp = new LoaiSP();
        int    kq     = loaisp._Delete(int.Parse(str2));

        gvSp.EditIndex = -1;
        getAll();
    }
        private bool idHasExist(string id)
        {
            LoaiSP temp = db.LoaiSPs.Find(id);

            if (temp == null)
            {
                return(false);
            }
            return(true);
        }
Example #21
0
        public ActionResult themLoai(FormCollection form)
        {
            LoaiSP loai = new LoaiSP();

            loai.tenLoai = form["tenLoai"];
            data.LoaiSPs.InsertOnSubmit(loai);
            data.SubmitChanges();
            ViewBag.ok = true;
            return(View());
        }
Example #22
0
        public bool Update(LoaiSP entity)
        {
            var LoaiSanPham = db.LoaiSPs.Find(entity.MaLoaiSP);

            LoaiSanPham.TenLoai = entity.TenLoai;
            LoaiSanPham.MoTa    = entity.MoTa;

            db.SaveChanges();
            return(true);
        }
        public IActionResult Post([FromBody] LoaiSP loaiSp)
        {
            var roweffect = _loaiSPService.addLoaiSP(loaiSp);

            if (roweffect == 400)
            {
                return(Created("Thông báo", "Mã loại sản phẩm đã tồn tại"));
            }
            return(Ok(roweffect));
        }
Example #24
0
        private void btnLoaiSP_Click(object sender, EventArgs e)
        {
            frmLoaiSP LoaiSP = null;

            if (LoaiSP == null || LoaiSP.IsDisposed)
            {
                LoaiSP = new frmLoaiSP();
            }
            LoaiSP.ShowDialog();
        }
Example #25
0
        public bool KiemTraTonTai(int mahd)
        {
            LoaiSP loai = LoaiSPDAC.Instance.DocThongTin(mahd);

            if (loai == null)
            {
                return(true);//Chưa tồn tại
            }
            return(false);
        }
 public ActionResult Edit([Bind(Include = "LoaiSPId,TenLoai")] LoaiSP loaiSP)
 {
     if (ModelState.IsValid)
     {
         db.Entry(loaiSP).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(loaiSP));
 }
        public async Task <IActionResult> Create([Bind("MaLoai,TenLoai,TrangThai")] LoaiSP loaiSP)
        {
            if (ModelState.IsValid)
            {
                _context.Add(loaiSP);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View("Index"));
        }
        public ActionResult ThemLoaiSP([Bind(Include = "TenLoai")] LoaiSP loai)
        {
            CategoryModel spm = new CategoryModel();

            if (ModelState.IsValid && spm.KiemTraTen(loai.TenLoai))
            {
                string maloai = spm.ThemLoaiSP(loai);
                return(View("Index"));
            }
            return(View("Index", loai));
        }
        public ActionResult EditLoaiSP([Bind(Include = "MaLoai,TenLoai")] LoaiSP loai)
        {
            CategoryModel spm = new CategoryModel();

            if (ModelState.IsValid)
            {
                spm.EditLoaiSP(loai);
                return(RedirectToAction("Index"));
            }
            return(View(loai));
        }
Example #30
0
        public ActionResult Create([Bind(Include = "MaLoaiSP,TenLoaiSP,GhiChuLoaiSP")] LoaiSP loaiSP)
        {
            if (ModelState.IsValid)
            {
                db.LoaiSP.Add(loaiSP);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(loaiSP));
        }