Example #1
0
 public bool InsertOrUpdateMatHang(MATHANG[] mathangs)
 {
     try
     {
         using (QLDLEntities db = new QLDLEntities())
         {
             foreach (MATHANG mathang in mathangs)
             {
                 if (mathang.MAHANG == 0)
                 {
                     MATHANG item = new MATHANG()
                     {
                         TENHANG = mathang.TENHANG,
                         DONGIA  = mathang.DONGIA,
                         MADVT   = mathang.MADVT,
                     };
                     db.MATHANGs.Add(item);
                 }
                 else
                 {
                     MATHANG item = db.MATHANGs.FirstOrDefault(x => x.MAHANG == mathang.MAHANG);
                     item.TENHANG = mathang.TENHANG;
                     item.DONGIA  = mathang.DONGIA;
                     item.MADVT   = mathang.MADVT;
                 }
             }
             db.SaveChanges();
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Example #2
0
            public List <BuildQuery.IQueryFilter> GetFilters()
            {
                var result = new List <IQueryFilter>();
                var refObj = new MATHANG();

                if (!string.IsNullOrEmpty(this.MAHANG))
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.MAHANG),
                        Value    = this.MAHANG,
                        Method   = FilterMethod.Like
                    });
                }
                if (!string.IsNullOrEmpty(this.TENHANG))
                {
                    result.Add(new QueryFilterLinQ
                    {
                        Property = ClassHelper.GetProperty(() => refObj.TENHANG),
                        Value    = this.TENHANG,
                        Method   = FilterMethod.Like
                    });
                }
                return(result);
            }
Example #3
0
        public ActionResult Edit([Bind(Include = "MAMH,MALOAI,MANSX,TENMH,ANH,DONGIA,MAU,GIAMGIA,GHICHU,GIOITHIEUMH")] MATHANG mATHANG)
        {
            var    imgNV          = Request.Files["Avatar"];
            var    target         = db.MATHANGs.Find(mATHANG.MAMH);
            string postedFileName = System.IO.Path.GetFileName(imgNV.FileName);
            //Lu hình đại diện về Server
            var path = Server.MapPath("/Images/Products/" + postedFileName);

            if (postedFileName != null && !postedFileName.IsNullOrWhiteSpace())
            {
                imgNV.SaveAs(path);
            }
            else
            {
                postedFileName = db.MATHANGs.Find(mATHANG.MAMH).ANH;
            }
            if (ModelState.IsValid)
            {
                mATHANG.ANH = postedFileName;
                db.Entry(target).CurrentValues.SetValues(mATHANG);
                db.Entry(target).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index", "QuanTri"));
            }
            ViewBag.MALOAI = new SelectList(db.LOAIMATHANGs, "MALOAI", "TENLOAI", mATHANG.MALOAI);
            ViewBag.MANSX  = new SelectList(db.NHASANXUATs, "MANSX", "TENNSX", mATHANG.MANSX);
            return(View(mATHANG));
        }
Example #4
0
        private void UpdateDetail()
        {
            try
            {
                MATHANG ans = getMATHANGByID();

                if (ans.ID == 0)
                {
                    return;
                }

                cbxNhaSanXuat.EditValue = ans.NHASANXUATID;

                txtTenMATHANG.Text      = ans.TEN;
                txtGiaBan.Text          = ans.GIABAN.ToString();
                txtGiaSi.Text           = ans.GIASI.ToString();
                txtGiaShip.Text         = ans.GIASHIP.ToString();
                txtNamXuatBan.Text      = ans.NAMXUATBAN.ToString();
                txtTitleTacGia.Text     = cbxNhaSanXuat.Text;
                txtTitleTenMATHANG.Text = ans.TEN;


                imgAnh.Image = null;
                imgAnh.Image = Helper.byteArrayToImage(ans.ANH);
            }
            catch
            {
            }
        }
Example #5
0
 private void btnThem_Click(object sender, EventArgs e)
 {
     if (txtSoLuong.Text != "")
     {
         //lấy thông tin mat hang
         MATHANG mh = MatHangBUS.Instance.GetByID(cmbMaMatHang.Text);
         //thêm dòng vào datagriedview
         DataGridViewRow row = (DataGridViewRow)dgvPhieuXuatHang.Rows[0].Clone();
         row.Cells[0].Value = index.ToString();
         row.Cells[1].Value = cmbMaMatHang.Text;
         row.Cells[2].Value = lblTenMatHang.Text;
         row.Cells[3].Value = cmbDonViTinh.Text;
         row.Cells[4].Value = txtSoLuong.Text;
         row.Cells[5].Value = mh.DonGia;
         row.Cells[6].Value = (int.Parse(txtSoLuong.Text) * mh.DonGia).ToString();
         dgvPhieuXuatHang.Rows.Add(row);
         TongT += (int.Parse(txtSoLuong.Text) * (int)mh.DonGia);
         index++;
         lblTongTien.Text = TongT.ToString();
     }
     else
     {
         MessageBox.Show("Bạn Phải điền số lượng", "Thông báo");
     }
 }
Example #6
0
        private void btnThemHang_Click(object sender, EventArgs e)
        {
            string  mathangID = txtMatHang.Text;
            MATHANG mathang   = db.MATHANGs.Where(p => p.MaHang == mathangID).SingleOrDefault();

            if (mathang != null)
            {
                MessageBox.Show("Mã mặt hàng đã tồn tại");
                return;
            }
            if (mathang == null)
            {
                MATHANG p = new MATHANG()
                {
                    MaHang     = mathangID,
                    TenMatHang = txtTenHang.Text,
                    MaLoaiHang = cbMaLoaiHang.Text,
                    DonViTinh  = cbDonViTinh.Text,
                    DonGia     = double.Parse(txtDonGia.Text),
                    LoaiHang   = cbLoaiHang.Text,
                };
                db.MATHANGs.Add(p);
                db.SaveChanges();
                LoadDataMatHang();
                MessageBox.Show("Thêm mặt hàng thành công");
            }
        }
Example #7
0
 private void simpleButton1_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Duyệt phiếu nhập này?", "Duyệt", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
     {
         try
         {
             var dbEntry = db.PHIEUNHAPs.SingleOrDefault(x => x.MAPHIEUNHAP == txtMaPhieuNhap.Text);
             dbEntry.STATUS = 1;
             var Chitiet = db.CHITIETNHAPs.Where(x => x.PHIEUNHAPID == dbEntry.ID).ToList();
             foreach (var item in Chitiet)
             {
                 MATHANG mh = db.MATHANGs.Where(p => p.ID == item.MATHANGID).FirstOrDefault();
                 mh.SOLUONG += item.SOLUONG;
             }
             db.SaveChanges();
             MessageBox.Show("Duyệt thành công !", "Duyệt", MessageBoxButtons.OK, MessageBoxIcon.Information);
             LoadDgvDanhSachHoaDon();
             btn_Xoa.Enabled   = false;
             btn_Duyet.Enabled = false;
         }
         catch
         {
             MessageBox.Show("Có lỗi xảy ra ! Vui lòng thử lại", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
 }
Example #8
0
        private void TinhThanhTien()
        {
            MATHANG mh = Helper.db.MATHANGs.Where(p => p.ID == Helper.IDSanPham).First();
            Int64   gt = (Int64)txtSoLuong.Value * Helper.GiaSanPham(mh);

            txtThanhTien.Text = gt.ToString("N0");
        }
Example #9
0
        public ActionResult ThemNGK(MATHANG ngk, HttpPostedFileBase fileupload)
        {
            if (Session["Taikhoanadmin"] == null || Session["Taikhoanadmin"].ToString() == "")
            {
                return(RedirectToAction("Login", "Admin"));
            }
            ViewBag.MaLH = new SelectList(data.LOAINGKs.ToList().OrderBy(n => n.TenLH), "MaLH", "TenLH");
            if (fileupload == null)
            {
                ViewBag.Thongbao = "Vui lòng chọn ảnh bìa";
                return(View());
            }

            else
            {
                if (ModelState.IsValid)
                {
                    var fileName = Path.GetFileName(fileupload.FileName);
                    var path     = Path.Combine(Server.MapPath("~/Content/Hinhsp"), fileName);
                    if (System.IO.File.Exists(path))
                    {
                        ViewBag.Thongbao = "Hình ảnh đã tồn tại";
                        return(View());
                    }
                    else
                    {
                        fileupload.SaveAs(path);
                    }
                    ngk.HinhSP = fileName;
                    data.MATHANGs.InsertOnSubmit(ngk);
                    data.SubmitChanges();
                }
                return(RedirectToAction("NGK"));
            }
        }
Example #10
0
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            // 0: self                      : CTPX
            // 1: DanhSachChiTietPhieuXuat  : ObservableCollection<CTPX>
            // 2: MatHang                   : ObservableCollection<MATHANG>

            foreach (CTPX ct in (values[1] as ObservableCollection <CTPX>).ToArray())
            {
                MATHANG mh = (values[2] as ObservableCollection <MATHANG>)
                             .ToList().Find(x =>
                                            (
                                                x.MAHANG == ct.MAHANG &&
                                                (
                                                    values[0] == null ||
                                                    x.MAHANG != (values[0] as CTPX).MAHANG
                                                )
                                            )
                                            );
                if (mh != null)
                {
                    (values[2] as ObservableCollection <MATHANG>).Remove(mh);
                }
            }
            return(values[2]);
        }
Example #11
0
        public async Task <IHttpActionResult> Delete(string id)
        {
            var     result   = new TransferObj <bool>();
            MATHANG 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));
        }
        public void sua(form_mathang f)
        {
            string mamh        = "";
            int    donghientai = f.gv_mathang.FocusedRowHandle;

            if (donghientai != dongdachon)
            {
                mamh = f.gv_mathang.GetRowCellValue(donghientai, "MAMH").ToString();
                MATHANG tam = data.database().MATHANGs.SingleOrDefault(a => a.MAMH == mamh);
                if (tam != null)
                {
                    tam.TENMH     = f.gv_mathang.GetRowCellValue(donghientai, "TENMH").ToString();
                    tam.MALOAI    = f.gv_mathang.GetRowCellValue(donghientai, "MALOAI").ToString();
                    tam.NOISX     = f.gv_mathang.GetRowCellValue(donghientai, "NOISX").ToString();
                    tam.DVT       = f.gv_mathang.GetRowCellValue(donghientai, "DVT").ToString();
                    tam.GIABAN    = (double)f.gv_mathang.GetRowCellValue(donghientai, "GIABAN");
                    tam.GIAMUA    = (double)f.gv_mathang.GetRowCellValue(donghientai, "GIAMUA");
                    tam.KHUYENMAI = (double)f.gv_mathang.GetRowCellValue(donghientai, "KHUYENMAI");
                    tam.SLTON     = (int)f.gv_mathang.GetRowCellValue(donghientai, "SLTON");
                    data.database().SubmitChanges();
                    loaddulieu(f);
                    dongdachon = donghientai;
                }
            }
        }
Example #13
0
        public void BindingPhieuDHOnline()
        {
            LoadDatabase();
            MaPhieuDH = Global.Ins.PhieuDHXuLY.id;
            if (Global.Ins.PhieuDHXuLY == null)
            {
                return;
            }
            PHIEUDATHANG pdh = Global.Ins.PhieuDHXuLY;

            if (pdh.KHACHHANG != null)
            {
                SDT          = pdh.KHACHHANG.SDT;
                TenKhachHang = pdh.KHACHHANG.TenKH;
            }

            ObservableCollection <CT_PHIEUDATHANG> _listCTPDH = new ObservableCollection <CT_PHIEUDATHANG>(DataProvider.Ins.DB.CT_PHIEUDATHANG);

            foreach (var ctphdh in _listCTPDH)
            {
                if (ctphdh.MaPhieuDH == pdh.id)
                {
                    int            stt      = ListMatHang.Count + 1;
                    MATHANG        mh       = ctphdh.MATHANG;
                    string         dongia   = double.Parse(mh.DonGia.ToString()).ToString("0,000");
                    string         tongtien = double.Parse(ctphdh.TongTien.ToString()).ToString("0,000");
                    ListMatHangMua mhmua    = new ListMatHangMua(stt + "", mh.id, mh.TenMH, mh.DonVi, dongia, ctphdh.SLDat + "", tongtien);
                    ListMatHang.Add(mhmua);
                }
            }
            DiaChiNhan = pdh.DiaChiNhan;
            TinhTien();
        }
Example #14
0
        private bool Check()
        {
            if (txtSoLuong.Value == 0)
            {
                MessageBox.Show("Số lượng sản phẩm phải là số nguyên dương",
                                "Thông báo",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return(false);
            }


            /// check trong kho
            int sl = (int)txtSoLuong.Value;

            MATHANG mh = Helper.db.MATHANGs.Where(p => p.ID == Helper.IDSanPham).First();

            if (sl > mh.SOLUONG)
            {
                MessageBox.Show("Số lượng hàng trong kho không đủ",
                                "Thông báo",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return(false);
            }

            return(true);
        }
Example #15
0
        private void UpdateDetail()
        {
            try
            {
                MATHANG tg = getMATHANGByID();

                if (tg.ID == 0)
                {
                    return;
                }

                txtTenMatHang.Text = tg.TEN;
                txtDonViTinh.Text  = tg.DONVITINH;
                txtThanhPhan.Text  = tg.THANHPHAN;
                txtGiaBan.Text     = tg.GIABAN.ToString();

                txtTitleTen.Text       = tg.TEN;
                txtTitleDonViTinh.Text = tg.DONVITINH;

                imgAnh.Image = null;
                imgAnh.Image = Helper.byteArrayToImage(tg.ANH);
            }
            catch
            {
            }
        }
        private void btnThem_Click(object sender, EventArgs e)
        {
            try
            {
                MATHANG mh = new MATHANG();
                mh.TENMH     = txtTenMH.Text;
                mh.DONVITINH = txtDonViTinh.Text;
                mh.THANHPHAN = txtThanhPhan.Text;
                int sx = int.Parse(cbxNhaSanXuat.SelectedValue.ToString());

                mh.NHASANXUATID = sx;


                //  mh.MATHANGID = 100;

                db.MATHANGs.Add(mh);
                db.SaveChanges();

                MessageBox.Show("Thêm mặt hàng thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                LoadDgv();
            }
            catch
            {
            }
        }
Example #17
0
        private void btnSuaHang_Click(object sender, EventArgs e)
        {
            string  mathangID = txtMatHang.Text;
            MATHANG mathang   = db.MATHANGs.Where(p => p.MaHang == mathangID).SingleOrDefault();

            if (mathang == null)
            {
                MessageBox.Show("Mã mặt hàng không tồn tại");
                return;
            }
            if (mathang != null)
            {
                mathang.MaHang     = mathangID;
                mathang.TenMatHang = txtTenHang.Text;
                mathang.MaLoaiHang = cbMaLoaiHang.Text;
                mathang.LoaiHang   = cbLoaiHang.Text;
                mathang.DonGia     = double.Parse(txtDonGia.Text);
                mathang.DonViTinh  = cbDonViTinh.Text;

                //product.Product_CategoryID = categoryID;
                //product.Product_Name = cbProductName.SelectedValue.ToString();
                //product.Product_Price = int.Parse(txtPrice.Text);
                //product.Product_Status = cxActiveProduct.Checked;


                db.SaveChanges();
                LoadDataMatHang();
                MessageBox.Show("Cập nhật mặt hàng thành công");
            }
        }
Example #18
0
        public static int GiaSanPham(MATHANG a)
        {
            int ans = 0;

            ans = (int)a.GIABAN;

            return(ans);
        }
Example #19
0
        public ActionResult DeleteConfirmed(int id)
        {
            MATHANG mATHANG = db.MATHANG.Find(id);

            db.MATHANG.Remove(mATHANG);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #20
0
 private void CapNhat(ref MATHANG cu, MATHANG moi)
 {
     cu.TEN       = moi.TEN;
     cu.DONVITINH = moi.DONVITINH;
     cu.GIABAN    = moi.GIABAN;
     cu.THANHPHAN = moi.THANHPHAN;
     cu.ANH       = moi.ANH;
 }
Example #21
0
        public static string TenSanPham(MATHANG a)
        {
            string ans = "";

            ans = a.TEN;

            return(ans);
        }
Example #22
0
        private void btnXoa_Click(object sender, EventArgs e)
        {
            if (btnXoa.Text == "Xóa")
            {
                if (!CheckLuaChon())
                {
                    return;
                }

                SACH         cu = getSACHByID();
                DialogResult rs = MessageBox.Show("Bạn có chắc chắn xóa đầu sách " + cu.TEN + "?",
                                                  "Thông báo",
                                                  MessageBoxButtons.OKCancel,
                                                  MessageBoxIcon.Warning);

                if (rs == DialogResult.Cancel)
                {
                    return;
                }

                try
                {
                    MATHANG mh = db.MATHANGs.Where(p => p.LOAISP == 0 && p.SACHID == cu.ID).FirstOrDefault();
                    if (mh != null)
                    {
                        db.MATHANGs.Remove(mh);
                    }

                    db.SACHes.Remove(cu);
                    db.SaveChanges();
                    MessageBox.Show("Xóa thông tin đầu sách thành công",
                                    "Thông báo",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Xóa thông tin đầu sách thất bại\n" + ex.Message,
                                    "Thông báo",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
                LoadDgvSACH();

                return;
            }
            if (btnXoa.Text == "Hủy")
            {
                btnSua.Text  = "Sửa";
                btnThem.Text = "Thêm";
                btnXoa.Text  = "Xóa";

                LockControl();
                UpdateDetail();
                return;
            }
        }
Example #23
0
        public ActionResult DeleteProduct(string id)
        {
            MATHANG mh = db.MATHANGs.Find(id);

            db.MATHANGs.Remove(mh);
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Example #24
0
        public ActionResult ProductDetails(string id)
        {
            if (id == null)
            {
                return(HttpNotFound());
            }
            MATHANG mh = db.MATHANGs.Find(id);

            return(View(mh));
        }
 public ActionResult Edit([Bind(Include = "MaMH,TenMH,Makho")] MATHANG mATHANG)
 {
     if (ModelState.IsValid)
     {
         db.Entry(mATHANG).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(mATHANG));
 }
Example #26
0
        private void btnTra_Click(object sender, EventArgs e)
        {
            CHITIETHOADON a = getChiTietNhapByForm();

            if (a.ID == 0)
            {
                MessageBox.Show("Chưa có chi tiết hóa đơn nào được chọn",
                                "Thông báo",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            DialogResult rs = MessageBox.Show("Bạn có chắc chắn xóa chi tiết hóa đơn này?",
                                              "Thông báo",
                                              MessageBoxButtons.OKCancel,
                                              MessageBoxIcon.Warning);

            if (rs == DialogResult.Cancel)
            {
                return;
            }

            MATHANG mh = db.MATHANGs.Where(p => a.MATHANGID == p.ID).FirstOrDefault();

            mh.SOLUONG += a.SOLUONG;
            if (mh.SOLUONG < 0)
            {
                mh.SOLUONG = 0;
            }

            pn.TONGTIEN -= a.SOLUONG * a.DONGIA;
            db.CHITIETHOADONs.Remove(a);

            try
            {
                db.SaveChanges();
                MessageBox.Show("Xóa chi tiết hóa đơn thành công",
                                "Thông báo",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Xóa chi tiết hóa đơn thất bại\n" + ex.Message,
                                "Thông báo",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            finally
            {
                LoadDgvChiTietNhap();
            }
        }
Example #27
0
        private MATHANG getMatHangByForm()
        {
            MATHANG ans = new MATHANG();

            ans.MAMH      = txtMaMH.Text;
            ans.TEN       = txtTenMH.Text;
            ans.DONVITINH = txtDVT.Text;
            ans.GHICHU    = txtGhiChu.Text;

            return(ans);
        }
Example #28
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            if (btnThem.Text == "Thêm")
            {
                btnSua.Enabled = false;
                btnThem.Text   = "Lưu";
                btnXoa.Text    = "Hủy";

                ClearControl();
                UnlockControl();

                return;
            }

            if (btnThem.Text == "Lưu")
            {
                if (Check())
                {
                    btnThem.Text = "Thêm";
                    btnXoa.Text  = "Xóa";
                    LockControl();

                    SACH moi = getSACHByForm();
                    db.SACHes.Add(moi);


                    try
                    {
                        db.SaveChanges();

                        MATHANG mh = new MATHANG();
                        mh.LOAISP  = 0;
                        mh.SACHID  = moi.ID;
                        mh.SOLUONG = 0;
                        db.MATHANGs.Add(mh);
                        db.SaveChanges();

                        MessageBox.Show("Thêm thông tin đầu sách thành công",
                                        "Thông báo",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Thêm thông tin đầu sách thất bại\n" + ex.Message,
                                        "Thông báo",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }
                    LoadDgvSACH();
                }
                return;
            }
        }
Example #29
0
        public void Insert(string TenMatHang, int SoLuongTon, int DonGia)
        {
            string  MaMH = MatHangDAO.Instance.CreateCode();
            MATHANG mh   = new MATHANG();

            mh.TenMatHang = TenMatHang;
            mh.SoLuongTon = SoLuongTon;
            mh.DonGia     = DonGia;

            MatHangDAO.Instance.Insert(mh);
        }
Example #30
0
 public ActionResult Edit([Bind(Include = "MaMH,TenMH,UrlAnh,KieuDang,ChatLieu,MaNSX,GiaBan")] MATHANG mATHANG)
 {
     if (ModelState.IsValid)
     {
         db.Entry(mATHANG).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.MaNSX = new SelectList(db.NHASANXUAT, "MaNSX", "TenNSX", mATHANG.MaNSX);
     return(View(mATHANG));
 }