Ejemplo n.º 1
0
        protected void Btn_Create_Click(object sender, EventArgs e)
        {
            try
            {
                // 圖檔儲存
                string fileName = "";
                if (FileUpload1.HasFile)
                {
                    FileUpload1.SaveAs(Server.MapPath("Images") + "/" + FileUpload1.FileName);
                    fileName = FileUpload1.FileName;
                }

                // 新增紀錄
                dbProductEntities db      = new dbProductEntities();
                tProduct          product = new tProduct();
                product.fId    = txtId.Text;
                product.fName  = txtName.Text;
                product.fPrice = decimal.Parse(txtPrice.Text);
                product.fImg   = fileName;
                db.tProduct.Add(product);
                db.SaveChanges();

                // 轉向 Index.aspx
                Response.Redirect("Index.aspx");
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message;
            }
        }
Ejemplo n.º 2
0
        public ActionResult Index(string account, string pwd)
        {
            var db     = new dbProductEntities();
            var member = db.會員.FirstOrDefault(x => x.帳號 == account && x.密碼 == pwd);

            if (member != null)
            {
                FormsAuthentication.RedirectFromLoginPage(member.帳號, true);
                return(RedirectToAction("Index", "Category"));
            }

            ViewBag.IsLogin = true;
            return(View());
        }
Ejemplo n.º 3
0
        public ActionResult Index(string UId, string UPwd)
        {
            dbProductEntities dbProduct = new dbProductEntities();

            var member = dbProduct.會員.Where(m => m.帳號 == UId && m.密碼 == UPwd).FirstOrDefault();

            if (member != null)
            {
                FormsAuthentication.RedirectFromLoginPage(UId, true);
                return(RedirectToAction("Index", "Category"));
            }
            //登入失敗: 紀錄沒有登入, 並導回登入頁
            ViewBag.IsLogin = false;
            return(View());
        }