Exemplo n.º 1
0
 private void btnThemTK_Click(object sender, EventArgs e)
 {
     try
     {
         if (validate.CheckTextBoxisEmpty(txtTaiKhoan) && validate.CheckTextBoxisEmpty(txtMatKhau))
         {
             QuanLyBanHangEntities db = new QuanLyBanHangEntities();
             TaiKhoan tk = new TaiKhoan();
             tk.TaiKhoan1 = txtTaiKhoan.Text.Trim();
             tk.MatKhau   = txtMatKhau.Text.Trim();
             tk.NgayTao   = DateTime.Now;
             if (checkBoxAdmin.Checked)
             {
                 tk.AdminYN = "Y";
             }
             else
             {
                 tk.AdminYN = "N";
             }
             db.TaiKhoans.Add(tk);
             db.SaveChanges();
             loadDatatoGrid();
             MessageBox.Show("Bạn đã thêm tài khoản thành công", "Thông báo", MessageBoxButtons.OK);
         }
     }
     catch (Exception v_e)
     {
         MessageBox.Show("Lỗi :" + v_e);
     }
 }
Exemplo n.º 2
0
        public ActionResult Create([FromBody] products product)
        {
            try
            {
                using (QuanLyBanHangEntities context = new QuanLyBanHangEntities())
                {
                    context.products.Add(product);
                    context.SaveChanges(); //id tự sinh
                }

                object result = new
                {
                    Code          = 201,
                    Message       = "Đã tạo product thành công!",
                    CreatedObject = product
                };
                return(Json(result));
            }
            catch (Exception ex)
            {
                object result = new
                {
                    Code    = 500,
                    Message = "Đã có lỗi xảy ra" + ex.Message
                };
                return(Json(result));
            }
        }
Exemplo n.º 3
0
        public string XuLyDangNhap(string email, string password)
        {
            // Tìm trong database ông nào có email và password giống với dữ liệu người dùng gởi
            using (QuanLyBanHangEntities context = new QuanLyBanHangEntities())
            {
                // Viết LINQ để tìm trong table `employees`, ai có `email` => username, `password` giống
                // object `context` => tương đương database
                // thuộc tính trong `context.
                // Ví dụ: context.employees => table employees trong database
                // Ví dụ: context.products => table products trong database
                // ...

                // Viết theo style METHOD()
                var objEmployeeLogin = context.employees
                                       .Where(p => p.email == email && p.password == password)
                                       .FirstOrDefault();

                // Viết theo style LINQ
                //var objEmployeeLogin2 = (from p in context.employees
                //                         where p.email == email && p.password == password
                //                         select p
                //                        ).FirstOrDefault();

                if (objEmployeeLogin == null) // Tìm không thấy dòng hợp lệ
                {
                    return("Không hợp lệ!");
                }
                else
                {
                    return(String.Format("Xin chào anh {0} {1}", objEmployeeLogin.last_name, objEmployeeLogin.first_name));
                }
            }
        }
Exemplo n.º 4
0
 public frm_BanHang()
 {
     InitializeComponent();
     funcBH      = new Func_BanHang();
     db          = new QuanLyBanHangEntities();
     lstCTHoaDon = new Dictionary <long, CTHOADON>();
 }
        public string XuLyDangNhap(string email, string password)
        {
            //Tìm trong DB username và password giống với dữ liệu mà người dùng gửi đến
            using (QuanLyBanHangEntities context = new QuanLyBanHangEntities())
            {
                /*Viết LinQ để tìm trong table 'employees', ai có email và password tương đương
                 * obj 'context' tương đương DB
                 * Thuộc tính trong 'context.'
                 * Ví dụ: context.employees => table employees trong DB
                 * ...
                 */

                // Viết theo style METHOD
                var objEmployeeLogin = context.employees.Where(p => p.email == email && p.password == password).FirstOrDefault();

                // Viết theo LinQ
                if (objEmployeeLogin == null)
                {
                    return("Không hợp lệ!");
                }
                else
                {
                    return(String.Format("Xin chào anh {0} {1}", objEmployeeLogin.last_name, objEmployeeLogin.first_name));
                }
            }
        }
Exemplo n.º 6
0
        public ActionResult Delete(int id)
        {
            try
            {
                using (QuanLyBanHangEntities context = new QuanLyBanHangEntities())
                {
                    products products = context.products.Find(id);
                    context.products.Remove(products);
                    context.SaveChanges();
                }

                object result = new
                {
                    Code    = 200,
                    Message = "Đã xoá product thành công!"
                };
                return(Json(result));
            }
            catch (Exception ex)
            {
                object result = new
                {
                    Code    = 500,
                    Message = "Đã có lỗi xảy ra" + ex.Message
                };
                return(Json(result));
            }
        }
Exemplo n.º 7
0
        public string XuLyDangNhap(string email, string password)
        {
            // Search in database ( username and password )
            using (QuanLyBanHangEntities context = new QuanLyBanHangEntities())
            {
                //Viet theo style method
                var objEmployeeLogin = context.employees.Where(p => p.email == email && p.password == password).FirstOrDefault();

                //Viết theo style LINQ
                //var objEmployeeLogin = (from p in context.employees
                //                        where p.email == email && p.password == password
                //                          select p
                //                          ).FirstorDefault();


                if (objEmployeeLogin == null)
                {
                    return("Không hợp lệ");
                }
                else
                {
                    return(String.Format("Xin chao anh {0} {1}", objEmployeeLogin.last_name, objEmployeeLogin.first_name));
                }
            }
        }
Exemplo n.º 8
0
        public static bool IsLogged()
        {
            var flag = HttpContext.Current.Session["isLogin"];

            if (flag == null || (int)flag == 0)
            {
                //Kiểm tra thêm trong cookie
                //nếu có cookie dùng thông tin trong cookie
                //để tái tạo lại session
                if (HttpContext.Current.Request.Cookies["userID"] != null)
                {
                    int userIdCookie = Convert.ToInt32(HttpContext.Current.Request.Cookies["userID"].Value);
                    using (QuanLyBanHangEntities _db = new QuanLyBanHangEntities())
                    {
                        var user = _db.Users
                                   .Where(u => u.f_ID == userIdCookie)
                                   .FirstOrDefault();
                        HttpContext.Current.Session["isLoggin"] = 1;
                        HttpContext.Current.Session["user"]     = user;
                        HttpContext.Current.Response.Cookies["userId"].Expires = DateTime.Now.AddDays(-1);
                    }
                    return(true);
                }
                return(false);
            }
            return(true);
        }
Exemplo n.º 9
0
 private void btnDangNhap_Click(object sender, EventArgs e)
 {
     try
     {
         if (validate.CheckTextBoxisEmpty(txtTaiKhoan, "Bạn phải nhập tên tài khoản") &&
             validate.CheckTextBoxisEmpty(txtMatKhau, "Bạn phải nhập mật khẩu"))
         {
             QuanLyBanHangEntities db = new QuanLyBanHangEntities();
             TaiKhoan user            = db.TaiKhoans.FirstOrDefault(x => x.TaiKhoan1 == txtTaiKhoan.Text &&
                                                                    x.MatKhau == txtMatKhau.Text);
             if (user != null)
             {
                 MsgUtil.userID = user.ID;
                 if (user.AdminYN.Trim() == "Y")
                 {
                     MsgUtil.isAdmin = true;
                 }
                 else
                 {
                     MsgUtil.isAdmin = false;
                 }
                 this.Close();
             }
             else
             {
                 MessageBox.Show("Tên tài khoản hoặc mật khẩu không đúng", "Thông báo", MessageBoxButtons.OK);
             }
         }
     }
     catch (Exception v_e)
     {
         MessageBox.Show("Lỗi :" + v_e);
     }
 }
Exemplo n.º 10
0
 private void btnThem_Click(object sender, EventArgs e)
 {
     try
     {
         QuanLyBanHangEntities db = new QuanLyBanHangEntities();
         if (validate.CheckTextBoxisEmpty(txtMaHDX) &&
             checkExistMaHDX(db))
         {
             HoaDonXuat hdx = new HoaDonXuat();
             hdx.IDTK     = MsgUtil.userID;
             hdx.MaHDX    = txtMaHDX.Text.Trim();
             hdx.NgayXuat = dtNgayXuat.Value;
             if (txtKhachHang.Text.Length > 0)
             {
                 hdx.TenKhachHang = txtKhachHang.Text.Trim();
             }
             if (txtDienThoai.Text.Length > 0)
             {
                 hdx.DienThoai = txtDienThoai.Text.Trim();
             }
             db.HoaDonXuats.Add(hdx);
             db.SaveChanges();
             loadDatatoGrid();
             MsgUtil.MessageThemSuccess();
         }
     }
     catch (Exception v_e)
     {
         MsgUtil.MessageThongBao("Lỗi " + v_e);
     }
 }
Exemplo n.º 11
0
 private void frmChiTietHDX_Load(object sender, EventArgs e)
 {
     // TODO: This line of code loads data into the 'quanLyBanHangDataSet.ViewChiTietHDX' table. You can move, or remove it, as needed.
     this.viewChiTietHDXTableAdapter.Fill(this.quanLyBanHangDataSet.ViewChiTietHDX);
     db = new QuanLyBanHangEntities();
     loadcboSP();
     loadDatatoGrid();
 }
Exemplo n.º 12
0
        private bool checkExistMaHDN(QuanLyBanHangEntities db)
        {
            HoaDonNhap dhn = db.HoaDonNhaps.FirstOrDefault(x => x.MaHDN == txtMaHDN.Text.Trim());

            if (dhn == null)
            {
                return(true);
            }
            MsgUtil.MessageThongBao("Mã đơn hóa đơn đã tồn tại!");
            return(false);
        }
Exemplo n.º 13
0
        public bool AddCity(string cityID, string cityName, ref string err)
        {
            QuanLyBanHangEntities qLBH = new QuanLyBanHangEntities();
            ThanhPho city = new ThanhPho();

            city.ThanhPho1   = cityID.Trim();
            city.TenThanhPho = cityName.Trim();
            qLBH.ThanhPhoes.Add(city);
            qLBH.SaveChanges();
            return(true);
        }
Exemplo n.º 14
0
        public bool RemoveCity(string cityID, ref string err)
        {
            QuanLyBanHangEntities qLBH = new QuanLyBanHangEntities();

            ThanhPho tp = new ThanhPho();

            tp.ThanhPho1 = cityID;
            qLBH.ThanhPhoes.Attach(tp);
            qLBH.ThanhPhoes.Remove(tp);
            qLBH.SaveChanges();
            return(true);
        }
        public ActionResult Edit(int id, [FromBody] products product)
        {
            try
            {
                using (QuanLyBanHangEntities context = new QuanLyBanHangEntities())
                {
                    products productEdited = context.products.Find(id);
                    if (!String.IsNullOrEmpty(product.category))
                    {
                        productEdited.category = product.category;
                    }
                    if (!String.IsNullOrEmpty(product.description))
                    {
                        productEdited.description = product.description;
                    }
                    productEdited.discontinued = product.discontinued;
                    productEdited.image        = product.image;
                    if (product.list_price > 0)
                    {
                        productEdited.list_price = product.list_price;
                    }
                    productEdited.minimum_reorder_quantity = product.minimum_reorder_quantity;
                    productEdited.order_details            = product.order_details;
                    productEdited.product_code             = product.product_code;
                    productEdited.product_name             = product.product_name;
                    productEdited.quantity_per_unit        = product.quantity_per_unit;
                    productEdited.reorder_level            = product.reorder_level;
                    productEdited.standard_cost            = product.standard_cost;
                    productEdited.target_level             = product.target_level;
                    context.SaveChanges();
                }

                object result = new
                {
                    Code    = 200,
                    Message = "Đã hiệu chỉnh product thành công!"
                };

                return(Json(result));
            }
            catch (Exception ex)
            {
                object result = new
                {
                    Code    = 500,
                    Message = "Đã có lỗi xảy ra" + ex.Message
                };

                return(Json(result));
            }
        }
Exemplo n.º 16
0
        public ActionResult ProductDetail(int idProduct)
        {
            products product = null;

            //Lay du lieu san pham
            using (QuanLyBanHangEntities context = new QuanLyBanHangEntities())
            {
                product = context.products.Where(p => p.id == idProduct).FirstOrDefault();
            }
            // Truyen du lieu tu controller sang view
            ViewBag.SanPham = product;

            return(View());
        }
Exemplo n.º 17
0
        public bool UpdateCity(string cityID, string cityName, ref string err)
        {
            QuanLyBanHangEntities qLBH = new QuanLyBanHangEntities();
            var TP = (from tp in qLBH.ThanhPhoes
                      where tp.ThanhPho1 == cityID
                      select tp).SingleOrDefault();

            if (TP != null)
            {
                TP.TenThanhPho = cityName;
                qLBH.SaveChanges();
            }
            return(true);
        }
        // GET
        public ActionResult ProductDetail(int idProduct)
        {
            products product = null;

            //Lấy dữ liệu sản phẩm bởi idProduct
            using (QuanLyBanHangEntities context = new QuanLyBanHangEntities())
            {
                product = context.products.Where(p => p.id == idProduct).FirstOrDefault();
            }

            // Truyền dữ liệu từ Controller sang View
            ViewBag.SanPham = product;
            return(View());
        }
        public ActionResult Index()
        {
            ViewBag.Title = "Kết quả thanh toán";
            int    result    = int.Parse(TempData["result"].ToString());
            long   MaDonHang = long.Parse(TempData["MaDonHang"].ToString());
            string status;

            if (result == 0)
            {
                status             = "Giao dịch thành công. Vui lòng kiểm tra email của bạn.";
                Session["GioHang"] = null;
                QuanLyBanHangEntities db  = new QuanLyBanHangEntities();
                DonDatHang            ddh = db.DonDatHangs.Where((p) => p.MaDDHString == MaDonHang).FirstOrDefault();

                if (ddh != null)
                {
                    string        MaTraCuu = string.Format("{0}-{1}", ddh.MaDDHString, ddh.MaDDH);
                    Core.MyQRCode qr       = new Core.MyQRCode(5, 4, 3);
                    // Tao image
                    Image img = qr.getImageFromString(MaTraCuu, false);

                    // Convert byte[] to Base64 String
                    ImageConverter imageConverter = new ImageConverter();
                    byte[]         imageByte      = (byte[])imageConverter.ConvertTo(img, typeof(byte[]));
                    // string base64String = Convert.ToBase64String(imageByte);
                    MemoryStream logo = new MemoryStream(imageByte);
                    // Send email
                    // string body = string.Format("<p>Chào bạn,<br/>ĐƠN HÀNG CỦA BẠN ĐÃ ĐẶT THÀNH CÔNG.<br/>Vui lòng đưa mã QR code này tới quầy vé để nhận vé.</p><br/><img src=\"data:image/png;base64, {0}\">", base64String);
                    string         body    = "<p>Chào bạn,<br/>ĐƠN HÀNG CỦA BẠN ĐÃ ĐẶT THÀNH CÔNG.<br/>Vui lòng đưa mã QR code này tới quầy vé để nhận vé.</p><br/><br/><img src=cid:imagepath>";
                    AlternateView  imgView = AlternateView.CreateAlternateViewFromString(body, null, "text/html");
                    LinkedResource lr      = new LinkedResource(logo);
                    lr.ContentId = "imagepath";
                    imgView.LinkedResources.Add(lr);

                    new QuanLyDonHangController().GuiEmail("Xác nhận đơn hàng", lr.ContentId, ddh.KhachHang.Email, imgView);
                }
            }
            else if (result == 1)
            {
                Session["GioHang"] = null;
                status             = "Giao dịch đang đợi.";
            }
            else
            {
                status = "Giao dịch không thành công.";
                return(RedirectToAction("XemGioHang"));
            }
            ViewBag.status = status;
            return(View());
        }
        public ActionResult SanPham()
        {
            List <products> lstProduct = new List <products>();

            // Lấy dữ liệu danh sách sản phẩm
            using (QuanLyBanHangEntities context = new QuanLyBanHangEntities())
            {
                lstProduct = context.products.ToList();// SELECT * FROM products
            }

            // Truyền dữ liệu từ Controller -> View thông qua Viewbag
            ViewBag.DanhSachSanPham = lstProduct;
            return(View());
        }
Exemplo n.º 21
0
        public ActionResult Index()
        {
            List <products> lstProduct = new List <products>();

            using (QuanLyBanHangEntities context = new QuanLyBanHangEntities())
            {
                lstProduct = context.products.ToList();
            }
            // Truyền dữ liệu từ controller => View thông qua viewBag
            //Tên View mới DanhSachSanPham
            ViewBag.DanhSachSanPham = lstProduct;

            return(View());
        }
Exemplo n.º 22
0
        public DataTable GetCities()
        {
            QuanLyBanHangEntities quanLyBanHangEntities = new QuanLyBanHangEntities();

            var tps = from p in quanLyBanHangEntities.ThanhPhoes
                      select p;
            DataTable data = new DataTable();

            data.Columns.Add("Mã thành phố");
            data.Columns.Add("Tên thành phố");
            foreach (var p in tps)
            {
                data.Rows.Add(p.ThanhPho1, p.TenThanhPho);
            }
            return(data);
        }
Exemplo n.º 23
0
 private void btnThem_Click(object sender, EventArgs e)
 {
     try
     {
         if (validate_data())
         {
             QuanLyBanHangEntities db   = new QuanLyBanHangEntities();
             NhaCungCap            vNCC = new NhaCungCap();
             if (checkMaNCCExist(db, true))
             {
                 vNCC.MaNCC = txtMaNCC.Text.Trim();
             }
             else
             {
                 MsgUtil.MessageThongBao("Mã nhà cung cấp đã tồn tại");
                 txtMaNCC.Focus();
                 return;
             }
             vNCC.TenNCC = txtTenNCC.Text.Trim();
             if (txtEmail.Text.Length > 0)
             {
                 vNCC.Email = txtEmail.Text.Trim();
             }
             if (txtDienThoai.Text.Length > 0)
             {
                 vNCC.DienThoai = txtDienThoai.Text.Trim();
             }
             if (txtDiaChi.Text.Length > 0)
             {
                 vNCC.DiaChi = txtDiaChi.Text.Trim();
             }
             if (txtFax.Text.Length > 0)
             {
                 vNCC.Fax = txtFax.Text.Trim();
             }
             db.NhaCungCaps.Add(vNCC);
             db.SaveChanges();
             loadDatatoGridView();
             MsgUtil.MessageThemSuccess();
         }
     }
     catch (Exception v_e)
     {
         MessageBox.Show("Lỗi :" + v_e);
     }
 }
Exemplo n.º 24
0
 private void btnCapNhat_Click(object sender, EventArgs e)
 {
     try
     {
         if (mIsRowSelected)
         {
             QuanLyBanHangEntities db   = new QuanLyBanHangEntities();
             NhaCungCap            vNCC = db.NhaCungCaps.FirstOrDefault(x => x.ID == mID);
             if (checkMaNCCExist(db, false))
             {
                 vNCC.MaNCC = txtMaNCC.Text.Trim();
             }
             else
             {
                 MsgUtil.MessageThongBao("Mã nhà cung cấp đã tồn tại");
                 txtMaNCC.Focus();
                 return;
             }
             vNCC.TenNCC = txtTenNCC.Text.Trim();
             if (txtEmail.Text.Length > 0)
             {
                 vNCC.Email = txtEmail.Text.Trim();
             }
             if (txtDienThoai.Text.Length > 0)
             {
                 vNCC.DienThoai = txtDienThoai.Text.Trim();
             }
             if (txtDiaChi.Text.Length > 0)
             {
                 vNCC.DiaChi = txtDiaChi.Text.Trim();
             }
             if (txtFax.Text.Length > 0)
             {
                 vNCC.Fax = txtFax.Text.Trim();
             }
             db.SaveChanges();
             loadDatatoGridView();
             MsgUtil.MessageCapNhatSuccess();
         }
     }
     catch (Exception v_e)
     {
         MessageBox.Show("Lỗi :" + v_e);
     }
 }
Exemplo n.º 25
0
 private void btnXoa_Click(object sender, EventArgs e)
 {
     try
     {
         if (isRowSelected)
         {
             QuanLyBanHangEntities db       = new QuanLyBanHangEntities();
             LoaiSanPham           v_loaiSP = db.LoaiSanPhams.FirstOrDefault(x => x.ID == IDLoaiSP);
             db.LoaiSanPhams.Remove(v_loaiSP);
             db.SaveChanges();
             loadDatatoGridView();
             MsgUtil.MessageXoaSuccess();
         }
     }
     catch (Exception v_e)
     {
         MessageBox.Show("Lỗi :" + v_e);
     }
 }
Exemplo n.º 26
0
 private void btnXoa_Click(object sender, EventArgs e)
 {
     try
     {
         if (mIsRowSelected)
         {
             QuanLyBanHangEntities db    = new QuanLyBanHangEntities();
             NhaCungCap            v_NCC = db.NhaCungCaps.FirstOrDefault(x => x.ID == mID);
             db.NhaCungCaps.Remove(v_NCC);
             db.SaveChanges();
             loadDatatoGridView();
             MsgUtil.MessageXoaSuccess();
         }
     }
     catch (Exception v_e)
     {
         MessageBox.Show("Lỗi :" + v_e);
     }
 }
Exemplo n.º 27
0
        private bool checkMaLoaiExist(QuanLyBanHangEntities db, Boolean isInsert)
        {
            LoaiSanPham loaiSP;

            if (isInsert)
            {
                loaiSP = db.LoaiSanPhams.FirstOrDefault(x => x.MaLoai == txtMaLoai.Text.Trim());
            }
            else
            {
                loaiSP = db.LoaiSanPhams.FirstOrDefault(x => x.MaLoai == txtMaLoai.Text.Trim() && x.ID != IDLoaiSP);
            }
            if (loaiSP == null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 28
0
        private bool checkMaSPExist(QuanLyBanHangEntities db, bool isInsert)
        {
            SanPham NCC;

            if (isInsert)
            {
                NCC = db.SanPhams.FirstOrDefault(x => x.MaSP == txtMaSP.Text.Trim());
            }
            else
            {
                NCC = db.SanPhams.FirstOrDefault(x => x.MaSP == txtMaSP.Text.Trim() && x.MaSP != mMaSP);
            }
            if (NCC == null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 29
0
        // http://domain.com/api/products
        public System.Web.Mvc.ActionResult GetProducts()
        {
            dynamic lstProduct = null;

            // Lấy dữ liệu danh sách Sản phẩm
            // Entity Framework
            using (QuanLyBanHangEntities context = new QuanLyBanHangEntities())
            {
                lstProduct = (from p in context.products
                              select new
                {
                    p.id,
                    p.product_code,
                    p.product_name,
                    p.standard_cost,
                    p.list_price
                }).ToList();
            }

            return(Json(lstProduct, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 30
0
        private bool checkMaNCCExist(QuanLyBanHangEntities db, bool isInsert)
        {
            NhaCungCap NCC;

            if (isInsert)
            {
                NCC = db.NhaCungCaps.FirstOrDefault(x => x.MaNCC == txtMaNCC.Text.Trim());
            }
            else
            {
                NCC = db.NhaCungCaps.FirstOrDefault(x => x.MaNCC == txtMaNCC.Text.Trim() && x.ID != mID);
            }
            if (NCC == null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }