public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/html"; string html; //TODO:Check The ID is Vaild or Not int id = 0; try { id = Convert.ToInt32(context.Request["id"]); DataTable table = MySqlHelper.ExecuteDataTable("select products.*, productcategory.Name as 'CName' " + "from products join productcategory " + "on products.CategoryID=productcategory.ID " + "where products.ID=@id ", new MySql.Data.MySqlClient.MySqlParameter("@id", id)); if (table.Rows.Count != 1) { throw new FormatException(); } else { html = NVRender.ReanderHtml("view.html", new { title = "产品详细", product = table.Rows[0] }); } } catch (FormatException) { html = NVRender.ReanderHtml("view.html", new { title = "产品不存在", miss = "miss" }); } context.Response.Write(html); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/html"; string html = NVRender.ReanderHtml("index.html", new { title = "" }); context.Response.Write(html); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/html"; DataTable table, ctable; string html = ""; string name, msg, cid, imagename, path; int id; HttpPostedFile image; switch (context.Request["action"]) { case "edit": id = Convert.ToInt32(context.Request["id"]); table = MySqlHelper.ExecuteDataTable("select * from products where id=@id", new MySql.Data.MySqlClient.MySqlParameter("@id", id)); ctable = MySqlHelper.ExecuteDataTable("select * from productcategory"); if (table.Rows.Count != 1) { html = "Error! You have make a worng request!"; } else { html = NVRender.ReanderHtml("/admin/productedit.html", new { title = "edit product", baseaction = "edit", product = table.Rows[0], category = ctable.Rows }); } break; case "editlaunch": #region editlaunch id = Convert.ToInt32(context.Request["productid"]); name = context.Request["productname"]; msg = context.Request["productmsg"]; cid = context.Request["productcategoryid"]; image = context.Request.Files["productimage"]; if (image.FileName != "") { imagename = DateTime.Now.ToString("yyyymmddhhmmssffff") + Path.GetExtension(image.FileName); path = context.Server.MapPath("~/uploadfile/"); image.SaveAs(path + imagename); MySqlHelper.ExecuteNonQuery(@"update products set Name=@name,Msg=@msg,ImagePath=@image,CategoryID=@cid where ID=@id", new MySql.Data.MySqlClient.MySqlParameter("@id", id), new MySql.Data.MySqlClient.MySqlParameter("@name", name), new MySql.Data.MySqlClient.MySqlParameter("@msg", msg), new MySql.Data.MySqlClient.MySqlParameter("@image", "uploadfile/" + imagename), new MySql.Data.MySqlClient.MySqlParameter("@cid", Convert.ToInt32(cid))); } else { MySqlHelper.ExecuteNonQuery(@"update products set Name=@name,Msg=@msg,CategoryID=@cid where ID=@id", new MySql.Data.MySqlClient.MySqlParameter("@id", id), new MySql.Data.MySqlClient.MySqlParameter("@name", name), new MySql.Data.MySqlClient.MySqlParameter("@msg", msg), new MySql.Data.MySqlClient.MySqlParameter("@cid", Convert.ToInt32(cid))); } context.Response.Redirect("ProductAdmin.ashx"); #endregion break; case "add": ctable = MySqlHelper.ExecuteDataTable("select * from productcategory"); html = NVRender.ReanderHtml("/admin/productedit.html", new { title = "add product", baseaction = "add", category = ctable.Rows, product = new { Name = "", Msg = "", CategoryID = "" } }); break; case "addlaunch": #region addlaunch name = context.Request["productname"]; msg = context.Request["productmsg"]; cid = context.Request["productcategoryid"]; image = context.Request.Files["productimage"]; imagename = DateTime.Now.ToString("yyyymmddhhmmssffff") + Path.GetExtension(image.FileName); path = context.Server.MapPath("~/uploadfile/"); image.SaveAs(path + imagename); MySqlHelper.ExecuteNonQuery(@"insert into products (Name,Msg,ImagePath,CategoryID) values (@name,@msg,@image,@cid)", new MySql.Data.MySqlClient.MySqlParameter("@name", name), new MySql.Data.MySqlClient.MySqlParameter("@msg", msg), new MySql.Data.MySqlClient.MySqlParameter("@image", "uploadfile/" + imagename), new MySql.Data.MySqlClient.MySqlParameter("@cid", Convert.ToInt32(cid))); context.Response.Redirect("ProductAdmin.ashx"); #endregion addlaunch break; case "delete": id = Convert.ToInt32(context.Request["id"]); table = MySqlHelper.ExecuteDataTable("select * from products where ID=@id", new MySql.Data.MySqlClient.MySqlParameter("@id", id)); if (table.Rows.Count != 1) { html = "Error! You have make a worng request!"; } else { MySqlHelper.ExecuteNonQuery("delete from products where ID=@id", new MySql.Data.MySqlClient.MySqlParameter("@id", id)); context.Response.Redirect("ProductAdmin.ashx"); } break; default: string snum = context.Request["page"]; int pagenum; if (string.IsNullOrEmpty(snum)) { pagenum = 1; } else { pagenum = Convert.ToInt32(snum); } int pagecount = Convert.ToInt32(MySqlHelper.ExecuteScalar("select count(*) from products")); pagecount = (int)Math.Ceiling(pagecount / 10.0); int[] array = new int[pagecount]; for (int i = 0; i != pagecount; ++i) { array[i] = i + 1; } table = MySqlHelper.ExecuteDataTable("select products.*, productcategory.Name as 'CName' " + " from products join productcategory " + "on products.CategoryID=productcategory.ID " + "order by products.ID limit @pagenum,10 ", new MySql.Data.MySqlClient.MySqlParameter("@pagenum", (pagenum - 1) * 10)); html = NVRender.ReanderHtml("/admin/productslist.html", new { rows = table.Rows, title = "list", array = array, prevpage = pagenum - 1, nextpage = pagenum + 1, currentpage = pagenum, maxpage = pagecount }); break; } context.Response.Write(html); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/html"; string html; string category = context.Request["category"]; string limit = ""; int listlength = 12; DataTable table; if (!string.IsNullOrEmpty(category)) { int cid = Convert.ToInt32(MySqlHelper.ExecuteScalar("select ID from productcategory " + "where Name=@name", new MySql.Data.MySqlClient.MySqlParameter("@name", category))); if (cid != 0) { limit = " where products.CategoryID = " + cid; } else { category = ""; } } else { category = ""; } string snum = context.Request["page"]; int pagenum; if (string.IsNullOrEmpty(snum)) { pagenum = 1; } else { pagenum = Convert.ToInt32(snum); } int productnum = Convert.ToInt32(MySqlHelper.ExecuteScalar("select count(*) from products " + limit)); int pagecount = (int)Math.Ceiling(productnum / (listlength * 1.0)); if (pagenum > pagecount) { pagenum = 1; } int starter = (pagenum - 1) / 10 * 10; int[] array = new int[pagecount - starter > 10 ? 10 : pagecount - starter]; array[0] = starter + 1; for (int i = 1; i != array.Length; ++i) { array[i] = array[i - 1] + 1; } table = MySqlHelper.ExecuteDataTable("select products.*, productcategory.Name as 'CName' " + " from products join productcategory " + " on products.CategoryID=productcategory.ID " + limit + " order by products.ID limit @pagenum,@listlength ", new MySql.Data.MySqlClient.MySqlParameter("@pagenum", (pagenum - 1) * listlength), new MySql.Data.MySqlClient.MySqlParameter("@listlength", listlength)); html = NVRender.ReanderHtml("products.html", new { title = "产品展示", rows = table.Rows, array = array, currentpage = pagenum, maxpage = pagecount, productnum = productnum, category = category }); context.Response.Write(html); }