private void btnLuu_Click(object sender, EventArgs e)
 {
     if (txtTenKho.Text.Trim() == string.Empty)
     {
         MessageBox.Show("Nhập tên kho");
         txtTenKho.Focus();
         return;
     }
     else
     {
         KHOHANG k = new KHOHANG();
         k.MAKHO     = txtMaKho.Text.Trim();
         k.TENKHO    = txtTenKho.Text;
         k.DIACHIKHO = txtDiaChiKho.Text;
         k.MOTA      = txtMoTa.Text;
         if (kho.ThemKho(k))
         {
             dataGridViewKho.DataSource = kho.LoadKho();
             btnLuu.Enabled             = false;
             btnThem.PerformClick();
         }
         else
         {
             MessageBox.Show("Thêm Kho thất bại");
         }
     }
 }
Exemple #2
0
        public void updateSanPham_saukhiThemCTPX(string masp, int soluong)
        {
            KHOHANG sp = qlch.KHOHANGs.Where(d => d.MASP == masp).FirstOrDefault();

            sp.SOLUONG = soluong;
            qlch.SubmitChanges();
        }
Exemple #3
0
        public async Task <IHttpActionResult> Delete(string id)
        {
            var     result   = new TransferObj <bool>();
            KHOHANG instance = await _service.Repository.FindAsync(id);

            if (instance == null)
            {
                return(NotFound());
            }
            try
            {
                _service.Delete(instance.ID);
                int del = await _service.UnitOfWork.SaveAsync();

                if (del > 0)
                {
                    result.Data    = true;
                    result.Status  = true;
                    result.Message = "Xóa thành công bản ghi";
                }
                else
                {
                    result.Data    = false;
                    result.Status  = false;
                    result.Message = "Thao tác không thành công";
                }
            }
            catch (Exception e)
            {
                result.Data    = false;
                result.Status  = false;
                result.Message = e.Message;
            }
            return(Ok(result));
        }
Exemple #4
0
            public List <BuildQuery.IQueryFilter> GetFilters()
            {
                var result = new List <IQueryFilter>();
                var refObj = new KHOHANG();

                if (!string.IsNullOrEmpty(this.MAKHO))
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.TENKHO),
                        Value    = this.MAKHO,
                        Method   = FilterMethod.Like
                    });
                }
                if (!string.IsNullOrEmpty(this.TENKHO))
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.TENKHO),
                        Value    = this.TENKHO,
                        Method   = FilterMethod.Like
                    });
                }
                if (!string.IsNullOrEmpty(this.DIENGIAI))
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.DIENGIAI),
                        Value    = this.DIENGIAI,
                        Method   = FilterMethod.Like
                    });
                }
                return(result);
            }
Exemple #5
0
        public ActionResult DeleteConfirmed(string id)
        {
            KHOHANG kHOHANG = db.KHOHANGs.Find(id);

            db.KHOHANGs.Remove(kHOHANG);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemple #6
0
        public ActionResult ThanhToan(FormCollection col)
        {
            var name = col["firstname"];

            var    diachi    = col["address"];
            var    dienthoai = col["phone"];
            HOADON hd        = new HOADON();
            Muser  user      = Session["UserDN"] as Muser;

            hd.MAHD           = "HD";
            hd.NGAYLAP        = DateTime.Today;
            hd.TENKHACHHANG   = name;
            hd.DIACHIGIAOHANG = diachi;
            hd.SDTGIAOHANG    = dienthoai;
            hd.MAKHACHHANG    = user.MaKH;
            var chietkhau = 0.0;
            var msp       = "";

            if (Session["Giamgia"] != null)
            {
                chietkhau    = double.Parse(dulieu.MAGIAMGIAs.FirstOrDefault(m => m.MAGIAMGIA1 == Session["Giamgia"]).TILEGIAM);
                msp          = dulieu.MAGIAMGIAs.FirstOrDefault(m => m.MAGIAMGIA1 == Session["Giamgia"]).MASP;
                hd.CHIETKHAU = chietkhau / 10.0 * (double)dulieu.SANPHAMs.FirstOrDefault(s => s.MASP == msp).GIA;
            }
            hd.THANHTIEN = (decimal?)TongTien();
            dulieu.HOADONs.InsertOnSubmit(hd);
            dulieu.SubmitChanges();
            ViewBag.TongTien = TongTien();
            List <HOADON>  mahh       = dulieu.HOADONs.Where(h => h.MAKHACHHANG == user.MaKH && h.TENKHACHHANG == name && h.NGAYLAP == DateTime.Today).ToList();
            HOADON         mah        = mahh.Last();
            string         mahd       = mah.MAHD;
            List <GioHang> lstGioHang = LayGioHang();

            foreach (GioHang i in lstGioHang)
            {
                KHOHANG       kh = dulieu.KHOHANGs.FirstOrDefault(c => c.MASP == i.MaSP);
                CHITIETHOADON ct = dulieu.CHITIETHOADONs.FirstOrDefault(c => c.MAHD == mahd && c.MASP == i.MaSP);
                if (ct == null)
                {
                    ct          = new CHITIETHOADON();
                    ct.MAHD     = mahd;
                    ct.MASP     = i.MaSP;
                    ct.SOLUONG  = i.Soluong;
                    ct.DONGIA   = (decimal?)i.DonGia;
                    ct.TONGTIEN = (decimal?)i.ThanhTien;
                    dulieu.CHITIETHOADONs.InsertOnSubmit(ct);
                }
                else
                {
                    ct.SOLUONG  = i.Soluong + ct.SOLUONG;
                    ct.TONGTIEN = (decimal?)i.ThanhTien + ct.TONGTIEN;
                }
                kh.SOLUONG = kh.SOLUONG - ct.SOLUONG;
                dulieu.SubmitChanges();
            }

            return(View(hd));
        }
Exemple #7
0
 public ActionResult Edit([Bind(Include = "Makho,Tenkho,Diachi,Thukho")] KHOHANG kHOHANG)
 {
     if (ModelState.IsValid)
     {
         db.Entry(kHOHANG).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(kHOHANG));
 }
Exemple #8
0
        public ActionResult Create([Bind(Include = "Makho,Tenkho,Diachi,Thukho")] KHOHANG kHOHANG)
        {
            if (ModelState.IsValid)
            {
                db.KHOHANGs.Add(kHOHANG);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(kHOHANG));
        }
Exemple #9
0
 public bool XoaKho(string ma)
 {
     try
     {
         KHOHANG p = qlkho.KHOHANGs.Where(t => t.MAKHO == ma).FirstOrDefault();
         qlkho.KHOHANGs.DeleteOnSubmit(p);
         qlkho.SubmitChanges();
         return(true);
     }
     catch { return(false); }
 }
Exemple #10
0
 public bool ThemKho(KHOHANG kho)
 {
     try
     {
         qlkho.KHOHANGs.InsertOnSubmit(kho);
         qlkho.SubmitChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemple #11
0
        // GET: KHOHANGs/Delete/5
        public ActionResult Delete(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            KHOHANG kHOHANG = db.KHOHANGs.Find(id);

            if (kHOHANG == null)
            {
                return(HttpNotFound());
            }
            return(View(kHOHANG));
        }
Exemple #12
0
        public async Task <IHttpActionResult> Put(string id, KHOHANG instance)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != instance.ID)
            {
                return(BadRequest());
            }
            var result = new TransferObj <KHOHANG>();

            if (id != instance.ID)
            {
                result.Status  = false;
                result.Message = "Mã ID không hợp lệ";
                return(Ok(result));
            }
            try
            {
                var item = _service.Update(instance);
                int upd  = await _service.UnitOfWork.SaveAsync();

                if (upd > 0)
                {
                    result.Status  = true;
                    result.Data    = item;
                    result.Message = "Cập nhật thành công";
                }
                else
                {
                    result.Status  = false;
                    result.Data    = null;
                    result.Message = "Thao tác không thành công";
                }
            }
            catch (Exception e)
            {
                result.Data    = null;
                result.Status  = false;
                result.Message = e.Message;
            }
            return(Ok(result));
        }
Exemple #13
0
        //cập nhật sl sản phẩm
        public ActionResult UpdateSL(String ma, Boolean update)
        {
            GioHang gioGioHang = LayGioHang().FirstOrDefault(f => f.MaSP == ma);
            KHOHANG sp         = dulieu.KHOHANGs.FirstOrDefault(c => c.MASP == ma);

            if (update == true && sp.SOLUONG > gioGioHang.Soluong)
            {
                gioGioHang.Soluong++;
            }
            else if (sp.SOLUONG == gioGioHang.Soluong)
            {
                gioGioHang.Soluong = gioGioHang.Soluong;
            }
            else /*if (gioGioHang.Soluong-1 > 0) */
            {
                gioGioHang.Soluong--;
            }
            return(RedirectToAction("Giohang"));
        }