Exemple #1
0
        public ActionResult Product(int?pid)
        {
            if (pid == null)
            {
                pid = 1;
            }

            DB.DB       mydb = new DB.DB();
            DB.IProduct ip   = new DB.Impl_Product(mydb.Connection);
            Dictionary <string, object> dp = ip.GetSingleProduct(pid.Value);

            if (dp == null || (int)dp["proState"] == 0)
            {
                RedirectToAction("Product");
            }

            Models.ProductInfo pi = new Models.ProductInfo();
            pi.ID     = (int)dp["proID"];
            pi.Name   = dp["proName"].ToString();
            pi.PTName = dp["PTName"].ToString();
            pi.Note   = dp["proNote"].ToString();
            pi.Price  = Convert.ToInt32(dp["proPrice"]);
            pi.Stock  = Convert.ToInt32(dp["proStock"]);
            pi.Pic    = dp["proPic"].ToString();

            ViewData["proTypes"] = Session["proTypes"];

            return(View(pi));
        }
 public ActionResult AddProduct(Models.ProductInfo product)
 {
     DB.DB       mydb = new DB.DB("SQLAdmin", "admin1234");
     DB.IProduct ip   = new DB.Impl_Product(mydb.Connection);
     ip.AddNewProduct(product.Name, product.PTID, product.Price, product.Note, product.Stock, product.State, product.Pic);
     return(RedirectToAction("ManageProduct"));
 }
        public ActionResult ManageProduct()
        {
            #region 列出商品
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            DB.DB       mydb             = new DB.DB();
            DB.IProduct ip = new DB.Impl_Product(mydb.Connection);
            DataTable   tt = ip.GetProducts();
            if (tt != null)
            {
                foreach (DataRow r in tt.Rows)
                {
                    sb.Append("<tr>");
                    sb.Append(string.Format("<td align=\"center\"><a style=\"text-decoration:underline\" href=\"/Admin/Product?pid={0}\">{1}</a></td>", r["proID"].ToString(), r["proID"].ToString()));
                    sb.Append(string.Format("<td align=\"center\">{0}</td>", r["proName"].ToString()));
                    sb.Append(string.Format("<td align=\"center\">{0}</td>", r["PTID"].ToString()));
                    sb.Append(string.Format("<td align=\"center\">{0}</td>", r["proPrice"].ToString()));
                    sb.Append(string.Format("<td align=\"center\">{0}</td>", r["proStock"].ToString()));
                    sb.Append(string.Format("<td align=\"center\">{0}</td>", r["proState"].ToString()));
                    sb.Append(string.Format("<td align=\"center\">{0}</td>", r["proPic"].ToString()));
                    sb.Append(string.Format("<td>{0}</td>", r["proNote"].ToString()));
                    sb.Append("</tr>");
                }
            }
            ViewData["products"] = sb.ToString();
            #endregion

            return(View());
        }
        public ActionResult AddToCart(int?pid)
        {
            if (pid == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            HashSet <Models.CartItem> myCart = null;

            if (Session["Cart"] == null)
            {
                myCart = new HashSet <Models.CartItem>();
            }
            else
            {
                myCart = Session["Cart"] as HashSet <Models.CartItem>;
            }

            Models.CartItem ci = new Models.CartItem();
            ci.ID = pid.Value;

            if (myCart.Contains(ci))
            {
                return(RedirectToAction("Index"));
            }

            DB.DB       mydb = new DB.DB();
            DB.IProduct ip   = new DB.Impl_Product(mydb.Connection);
            Dictionary <string, object> pp = ip.GetSingleProduct(pid.Value);

            if (pp == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            ci.ID       = Convert.ToInt32(pp["proID"]);
            ci.Name     = pp["proName"].ToString();
            ci.Stock    = Convert.ToInt32(pp["proStock"]);
            ci.Quantity = 1;
            ci.Price    = Convert.ToInt32(pp["proPrice"]);
            myCart.Add(ci);
            Session["Cart"] = myCart;
            return(RedirectToAction("Index"));
        }
Exemple #5
0
        public ActionResult ProductType(int?type, int?page)
        {
            if (page == null)
            {
                page = 1;
            }
            if (type == null)
            {
                type = 0;
            }

            DB.DB       mydb = new DB.DB("SQLAdmin", "admin1234");
            DB.IProduct ip   = new DB.Impl_Product(mydb.Connection);
            DataTable   tt   = ip.GetProductListByType(type.Value);

            if (tt == null)
            {
                tt = new DataTable();
            }
            int count = tt.Rows.Count;

            int totalPage = 1;

            if (count > 5)
            {
                totalPage = (int)Math.Ceiling(count / 5.0);
            }

            if (page > totalPage)
            {
                return(RedirectToAction("ProductType", new { type }));
            }

            List <Models.ProductInfo> ps = new List <Models.ProductInfo>();

            foreach (DataRow r in tt.Rows)
            {
                int countID = Convert.ToInt32(r["countID"]);
                if (countID <= 5 * (page.Value - 1) || countID > 5 * page.Value)
                {
                    continue;
                }

                Models.ProductInfo pi = new Models.ProductInfo();
                pi.ID     = (int)r["proID"];
                pi.Name   = r["proName"].ToString();
                pi.Note   = r["proNote"].ToString();
                pi.PTName = r["PTName"].ToString();
                pi.Price  = Convert.ToInt32(r["proPrice"]);
                pi.Stock  = Convert.ToInt32(r["proStock"]);
                pi.Pic    = r["proPic"].ToString();
                ps.Add(pi);
            }


            //頁碼
            System.Text.StringBuilder sb2 = new System.Text.StringBuilder();
            for (int i = 1; i <= totalPage; i++)
            {
                if (i == page.Value)
                {
                    sb2.Append(i).Append("&nbsp;&nbsp;");
                }
                else
                {
                    sb2.Append(string.Format("<a style=\"text-decoration:underline\" href='{0}'>{1}</a>&nbsp;&nbsp;", Url.Action("ProductType", new { type, page = i }), i));
                }
            }
            ViewData["PageLink"] = sb2.ToString();
            ViewData["proTypes"] = Session["proTypes"];

            return(View(ps));
        }
Exemple #6
0
        // GET: Home
        public ActionResult Index()
        {
            #region 光顧數量
            //記錄光顧數量
            string path = Server.MapPath("~/App_Data/VisitCount.txt");
            string text = System.IO.File.ReadAllText(path);
            int    nn   = int.Parse(text) + 1;
            System.IO.File.WriteAllText(path, nn.ToString());

            //印出光顧數量
            System.Text.StringBuilder sb1 = new System.Text.StringBuilder();
            for (int i = 1; i <= 5 - nn.ToString().Length; i++)
            {
                sb1.Append("<img src='/images/number/0.gif' />");
            }
            for (int i = 0; i < nn.ToString().Length; i++)
            {
                sb1.Append(string.Format("<img src='/images/number/{0}.gif' />", nn.ToString().Substring(i, 1)));
            }

            ViewData["VisitNum"] = sb1.ToString();
            #endregion

            #region 列出商品
            DB.DB       mydb = new DB.DB();
            DB.IProduct ip   = new DB.Impl_Product(mydb.Connection);
            DataTable   tt   = ip.GetProductList();

            List <Models.ProductInfo> ps = new List <Models.ProductInfo>();
            if (tt != null)
            {
                foreach (DataRow r in tt.Rows)
                {
                    Models.ProductInfo pi = new Models.ProductInfo();
                    pi.ID     = (int)r["proID"];
                    pi.Name   = r["proName"].ToString();
                    pi.PTName = r["PTName"].ToString();
                    pi.Pic    = r["proPic"].ToString();
                    ps.Add(pi);
                }
            }
            #endregion

            #region 列出分類
            if (Session["proTypes"] == null)
            {
                System.Text.StringBuilder sb2 = new System.Text.StringBuilder();
                sb2.Append("<table>");
                DB.DB       mydb2 = new DB.DB();
                DB.IProduct ip2   = new DB.Impl_Product(mydb2.Connection);
                DataTable   tt2   = ip2.GetProductType();
                if (tt2 != null)
                {
                    foreach (DataRow r in tt2.Rows)
                    {
                        sb2.Append(string.Format("<tr><td><a style=\"text-align:center\" href=\"/Home/ProductType?type={0}\">", r["PTID"].ToString()));
                        sb2.Append(string.Format("<img src='/images/shop/{0}' />", r["PTPic"].ToString()));
                        sb2.Append("</a></td></tr>");
                    }
                }
                sb2.Append("</table>");
                Session["proTypes"] = sb2.ToString();
            }
            ViewData["proTypes"] = Session["proTypes"];
            #endregion

            return(View(ps));
        }