commit 1af6f4fdc13f271f0697fd73e3e694c80737af3b Author: j502647092 Date: Fri Jun 19 14:09:07 2015 +0800 初始化项目... diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0852cbc --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +CitySunlight/bin/ +CitySunlight/obj/ +packages/ diff --git a/CitySunlight.sln b/CitySunlight.sln new file mode 100644 index 0000000..7fb3b3e --- /dev/null +++ b/CitySunlight.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.21005.1 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CitySunlight", "CitySunlight\CitySunlight.csproj", "{5CD44C0E-DD9E-45F4-9884-B50E7A42CCD4}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5CD44C0E-DD9E-45F4-9884-B50E7A42CCD4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5CD44C0E-DD9E-45F4-9884-B50E7A42CCD4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5CD44C0E-DD9E-45F4-9884-B50E7A42CCD4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5CD44C0E-DD9E-45F4-9884-B50E7A42CCD4}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/CitySunlight.v12.suo b/CitySunlight.v12.suo new file mode 100644 index 0000000..8c107b5 Binary files /dev/null and b/CitySunlight.v12.suo differ diff --git a/CitySunlight/Account/LogOut.aspx b/CitySunlight/Account/LogOut.aspx new file mode 100644 index 0000000..1ad7945 --- /dev/null +++ b/CitySunlight/Account/LogOut.aspx @@ -0,0 +1,22 @@ +<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="LogOut.aspx.cs" Inherits="CitySunlight.Account.LogOut" %> + + + + + + + + + + +
+ + + + +
+ 正在退出登录... +
+
+ + diff --git a/CitySunlight/Account/LogOut.aspx.cs b/CitySunlight/Account/LogOut.aspx.cs new file mode 100644 index 0000000..679cefa --- /dev/null +++ b/CitySunlight/Account/LogOut.aspx.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; + +namespace CitySunlight.Account +{ + public partial class LogOut : System.Web.UI.Page + { + protected void Page_Load(object sender, EventArgs e) + { + if (Session["username"] != null) + { + Session.Abandon(); + Response.Redirect("../Main.aspx"); + } + } + } +} \ No newline at end of file diff --git a/CitySunlight/Account/LogOut.aspx.designer.cs b/CitySunlight/Account/LogOut.aspx.designer.cs new file mode 100644 index 0000000..6d80be5 --- /dev/null +++ b/CitySunlight/Account/LogOut.aspx.designer.cs @@ -0,0 +1,24 @@ +//------------------------------------------------------------------------------ +// <自动生成> +// 此代码由工具生成。 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace CitySunlight.Account { + + + public partial class LogOut { + + /// + /// logoutform 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::System.Web.UI.HtmlControls.HtmlForm logoutform; + } +} diff --git a/CitySunlight/Account/Login.aspx b/CitySunlight/Account/Login.aspx new file mode 100644 index 0000000..7c52202 --- /dev/null +++ b/CitySunlight/Account/Login.aspx @@ -0,0 +1,40 @@ +<%@ Page Language="C#" MasterPageFile="~/Basic.Master" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="CitySunlight.Default" ValidateRequest="false" %> + + +
+ + + + + + + + + + + + + + + + + + + +
+ <%= msg %> +
+ + +
+ + +
+ + + +
+
+
diff --git a/CitySunlight/Account/Login.aspx.cs b/CitySunlight/Account/Login.aspx.cs new file mode 100644 index 0000000..b221cb4 --- /dev/null +++ b/CitySunlight/Account/Login.aspx.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Web; +using System.Web.ModelBinding; +using System.Web.UI; +using System.Web.UI.WebControls; + +namespace CitySunlight +{ + public partial class Default : System.Web.UI.Page + { + protected string msg; + protected void Page_Load(object sender, EventArgs e) + { + if (Session["username"] != null) + { + Response.Redirect("../Main.aspx"); + } + } + + protected void login_Click(object sender, EventArgs e) + { + //String username = UserNameTx.Value; + String password = HttpUtils.getElementsbyName("PassWordTx"); + String username = HttpUtils.getElementsbyName("UserNameTx"); + + if ((username.Length == 0) || (password.Length == 0)) + { + msg = "请填写完整的账号和密码!"; + return; + } + + if (!UserManager.isExist(username)) + { + msg = "当前用户不存在!"; + return; + } + + if (UserManager.GetTimes(username) > 2) + { + msg = "登录错误超过3次,已被锁定,请联系管理员!"; + return; + } + + if (UserManager.LoginUser(username, password)) + { + Session["username"] = username; + Response.Write(""); + Response.Redirect("../Main.aspx"); + } + else + { + msg = "账号密码错误,还可以尝试" + (4 - UserManager.GetTimes(username)) + "次..!"; + } + } + + protected void register_Click(object sender, EventArgs e) + { + Response.Redirect("./Register.aspx"); + } + } +} \ No newline at end of file diff --git a/CitySunlight/Account/Login.aspx.designer.cs b/CitySunlight/Account/Login.aspx.designer.cs new file mode 100644 index 0000000..735ef66 --- /dev/null +++ b/CitySunlight/Account/Login.aspx.designer.cs @@ -0,0 +1,42 @@ +//------------------------------------------------------------------------------ +// <自动生成> +// 此代码由工具生成。 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace CitySunlight { + + + public partial class Default { + + /// + /// loginform 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::System.Web.UI.HtmlControls.HtmlForm loginform; + + /// + /// register 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::System.Web.UI.WebControls.Button register; + + /// + /// login 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::System.Web.UI.WebControls.Button login; + } +} diff --git a/CitySunlight/Account/Register.aspx b/CitySunlight/Account/Register.aspx new file mode 100644 index 0000000..1751718 --- /dev/null +++ b/CitySunlight/Account/Register.aspx @@ -0,0 +1,44 @@ +<%@ Page Language="C#" MasterPageFile="~/Basic.Master" AutoEventWireup="true" CodeBehind="Register.aspx.cs" Inherits="CitySunlight.register" %> + + +
+ + + + + + + + + + + + + + + + + + +
+ <%= msg %> +
+ + + +
+ + + +
+ + + +
+ +
+
+
+ diff --git a/CitySunlight/Account/Register.aspx.cs b/CitySunlight/Account/Register.aspx.cs new file mode 100644 index 0000000..72ce740 --- /dev/null +++ b/CitySunlight/Account/Register.aspx.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.ModelBinding; +using System.Web.UI; +using System.Web.UI.WebControls; + +namespace CitySunlight +{ + public partial class register : System.Web.UI.Page + { + public String msg; + protected void Page_Load(object sender, EventArgs e) + { + + } + + protected void submit_Click(object sender, EventArgs e) + { + String username = HttpUtils.getElementsbyName("usernameTx"); + String password = HttpUtils.getElementsbyName("passwordTx"); + String confirm = HttpUtils.getElementsbyName("confirmTx"); + + if (username == "" || password == "" || confirm == "") + { + msg = "请填写完整的账号密码!"; + return; + } + + if (password != confirm) + { + msg = "两次输入的密密码不一致!"; + return; + } + + if (UserManager.isExist(username)) + { + msg = "当前用户名已存在,请换一个用户名!"; + return; + } + + if (UserManager.RegisterUser(username, password)) + { + Response.Redirect("alert('1')"); + Session["username"] = username; + Response.Redirect("../Main.aspx"); + } + else + { + msg = "注册失败,请联系管理员!"; + } + } + + } +} \ No newline at end of file diff --git a/CitySunlight/Account/Register.aspx.designer.cs b/CitySunlight/Account/Register.aspx.designer.cs new file mode 100644 index 0000000..af55973 --- /dev/null +++ b/CitySunlight/Account/Register.aspx.designer.cs @@ -0,0 +1,33 @@ +//------------------------------------------------------------------------------ +// <自动生成> +// 此代码由工具生成。 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace CitySunlight { + + + public partial class register { + + /// + /// registerform 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::System.Web.UI.HtmlControls.HtmlForm registerform; + + /// + /// submit 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::System.Web.UI.WebControls.Button submit; + } +} diff --git a/CitySunlight/Account/UserManager.cs b/CitySunlight/Account/UserManager.cs new file mode 100644 index 0000000..7df65e7 --- /dev/null +++ b/CitySunlight/Account/UserManager.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.ComponentModel.DataAnnotations; +using System.Data; +namespace CitySunlight +{ + public static class UserManager + { + private const String tbname = "tb_user"; + private static Dictionary trytimes = new Dictionary(); + private static SqlHelper sql = new SqlHelper("Data Source=.;Initial Catalog=myApplication;User ID=sa;Password=325325"); + + public static int ErrLogin(String username) + { + return UpdateTimes(username, true); + } + + public static int GetTimes(String username) + { + return UpdateTimes(username, false); + } + + private static int UpdateTimes(String username, bool add) + { + if (!trytimes.ContainsKey(username)) + { + trytimes.Add(username, add ? 1 : 0); + } + else + { + if (add) { trytimes[username] += 1; }; + } + return trytimes[username]; + } + + public static bool LoginUser(String username, String password) + { + DataTable dt = sql.ExecuteDataTable("select * from " + tbname + " where UserName='" + username + "' and PassWord='" + password + "'", CommandType.Text); + //return "select * from user where username='" + username + "' and password='" + password + "'"; + if (dt.Rows.Count > 0) + { + return true; + } + UpdateTimes(username, true); + return false; + } + + public static bool isExist(String username) + { + DataTable dt = sql.ExecuteDataTable("select * from " + tbname + " where UserName='" + username + "'", CommandType.Text); + if (dt.Rows.Count > 0) + { + return true; + } + return false; + } + + public static bool RegisterUser(String username, String password) + { + int insert = sql.ExecuteNonQuery("insert into " + tbname + "(UserName,PassWord) values('" + username + "','" + password + "')"); + if (insert > 0) + { + return true; + } + return false; + } + } +} \ No newline at end of file diff --git a/CitySunlight/Admin.aspx b/CitySunlight/Admin.aspx new file mode 100644 index 0000000..f8dd417 --- /dev/null +++ b/CitySunlight/Admin.aspx @@ -0,0 +1,12 @@ +<%@ Page Language="C#" MasterPageFile="~/Basic.Master" AutoEventWireup="true" CodeBehind="Admin.aspx.cs" Inherits="CitySunlight.Admin" %> + + +
+ + <%= GetProductInfo() %> +
+
+
+ + + diff --git a/CitySunlight/Admin.aspx.cs b/CitySunlight/Admin.aspx.cs new file mode 100644 index 0000000..6cd2308 --- /dev/null +++ b/CitySunlight/Admin.aspx.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; +using CitySunlight.Product; + +namespace CitySunlight +{ + public partial class Admin : System.Web.UI.Page + { + int pages = HttpUtils.getQueryString("pages").ToInt(); + public String user; + const int peritems = 5; + protected void Page_Load(object sender, EventArgs e) + { + if (Session["username"] == null) + { + Response.Redirect("/Account/Login.aspx"); + } + user = Session["username"].ToString(); + } + + public String GetProductInfo() + { + String html = ""; + DataTable items = ProductManager.SearchProduct(user, "", "", "", "", pages, peritems); + if (items.Rows.Count == 0) + return "数据库中未找到产品"; + else + html += String.Format("{0}", + HttpUtils.addTd("") + + HttpUtils.addTd("商品名称") + + HttpUtils.addTd("商品图片") + + HttpUtils.addTd("商品价格") + + HttpUtils.addTd("商品数量") + + HttpUtils.addTd("商品分类") + + HttpUtils.addTd("编辑") + + HttpUtils.addTd("删除")); + foreach (DataRow item in items.Rows) + { + int id = int.Parse(ProductManager.GetProductInfo(item, ProductManager.Info.ID)); + String name = ProductManager.GetProductInfo(item, ProductManager.Info.ItemName); + String url = ProductManager.GetProductInfo(item, ProductManager.Info.PicUrl); + String picurl = String.Format("", url); + String price = ProductManager.GetProductInfo(item, ProductManager.Info.Price); + String amount = ProductManager.GetProductInfo(item, ProductManager.Info.Amount); + String edit = "编辑"; + String classname = ProductClassManager.getClassName(int.Parse(ProductManager.GetProductInfo(item, ProductManager.Info.Class))); + String delete = "删除"; + html += ""; + html += HttpUtils.addTd(""); + html += HttpUtils.addTd(ProductManager.NameToUrl(id, name)); + html += HttpUtils.addTd(picurl); + html += HttpUtils.addTd(price); + html += HttpUtils.addTd(amount); + html += HttpUtils.addTd(classname); + html += HttpUtils.addTd(edit); + html += HttpUtils.addTd(delete); + html += ""; + } + decimal total = ProductManager.SearchProduct(user, "", "", "", "").Rows.Count / peritems; + int totalpages = (int)(Math.Ceiling(total)); + String allpage = ""; + for (int i = 1; i <= totalpages; i++) + { + String page = String.Format(" {1} ", i, i); + allpage += page; + } + html += String.Format("{0} 共{1}页", allpage, totalpages); + return html; + } + } +} \ No newline at end of file diff --git a/CitySunlight/Admin.aspx.designer.cs b/CitySunlight/Admin.aspx.designer.cs new file mode 100644 index 0000000..85b7b34 --- /dev/null +++ b/CitySunlight/Admin.aspx.designer.cs @@ -0,0 +1,24 @@ +//------------------------------------------------------------------------------ +// <自动生成> +// 此代码由工具生成。 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace CitySunlight { + + + public partial class Admin { + + /// + /// formmain 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::System.Web.UI.HtmlControls.HtmlForm formmain; + } +} diff --git a/CitySunlight/Basic.Master b/CitySunlight/Basic.Master new file mode 100644 index 0000000..3ee2645 --- /dev/null +++ b/CitySunlight/Basic.Master @@ -0,0 +1,25 @@ +<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Basic.Master.cs" Inherits="CitySunlight.Basic" %> + + + + + + + + + + 都市阳光销售系统 + + + + + + + +
+ + 主页图片<%= GetLoginInfo() %>
+ + + + diff --git a/CitySunlight/Basic.Master.cs b/CitySunlight/Basic.Master.cs new file mode 100644 index 0000000..4e5b5e5 --- /dev/null +++ b/CitySunlight/Basic.Master.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; + +namespace CitySunlight +{ + public partial class Basic : System.Web.UI.MasterPage + { + protected void Page_Load(object sender, EventArgs e) + { + + } + public String GetLoginInfo() + { + String html = ""; + if (Session["username"] == null) + html = "登录"; + else + { + html = String.Format("欢迎您 {0} ", Session["username"].ToString()); + html += " 注销"; + html += " "; + html += "发布"; + html += " "; + html += "管理"; + } + return html; + } + } +} \ No newline at end of file diff --git a/CitySunlight/Basic.Master.designer.cs b/CitySunlight/Basic.Master.designer.cs new file mode 100644 index 0000000..0edf744 --- /dev/null +++ b/CitySunlight/Basic.Master.designer.cs @@ -0,0 +1,33 @@ +//------------------------------------------------------------------------------ +// <自动生成> +// 此代码由工具生成。 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace CitySunlight { + + + public partial class Basic { + + /// + /// head 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::System.Web.UI.WebControls.ContentPlaceHolder head; + + /// + /// body 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::System.Web.UI.WebControls.ContentPlaceHolder body; + } +} diff --git a/CitySunlight/CitySunlight.csproj b/CitySunlight/CitySunlight.csproj new file mode 100644 index 0000000..26d0e4f --- /dev/null +++ b/CitySunlight/CitySunlight.csproj @@ -0,0 +1,195 @@ + + + + + Debug + AnyCPU + + + 2.0 + {5CD44C0E-DD9E-45F4-9884-B50E7A42CCD4} + {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} + Library + Properties + CitySunlight + CitySunlight + v4.5 + true + + + + + + + true + full + false + bin\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\ + TRACE + prompt + 4 + + + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll + + + ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + LogOut.aspx + ASPXCodeBehind + + + LogOut.aspx + + + + Admin.aspx + ASPXCodeBehind + + + Admin.aspx + + + + ProductClassEdit.aspx + ASPXCodeBehind + + + ProductClassEdit.aspx + + + ProductEdit.aspx + ASPXCodeBehind + + + ProductEdit.aspx + + + + Main.aspx + ASPXCodeBehind + + + Main.aspx + + + Register.aspx + ASPXCodeBehind + + + Register.aspx + + + Basic.Master + ASPXCodeBehind + + + Basic.Master + + + ProductShow.aspx + ASPXCodeBehind + + + ProductShow.aspx + + + + + Login.aspx + ASPXCodeBehind + + + Login.aspx + + + + + + + + + Web.config + + + Web.config + + + + + 10.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + + + + + True + True + 1815 + / + http://localhost:1815/ + False + False + + + False + + + + + + \ No newline at end of file diff --git a/CitySunlight/CitySunlight.csproj.user b/CitySunlight/CitySunlight.csproj.user new file mode 100644 index 0000000..9f3f3a5 --- /dev/null +++ b/CitySunlight/CitySunlight.csproj.user @@ -0,0 +1,30 @@ + + + + ShowAllFiles + + + + + + Main.aspx + SpecificPage + True + False + False + False + + + + + + + + + True + True + + + + + \ No newline at end of file diff --git a/CitySunlight/CssStyle/CityStyle.css b/CitySunlight/CssStyle/CityStyle.css new file mode 100644 index 0000000..08f7b8b --- /dev/null +++ b/CitySunlight/CssStyle/CityStyle.css @@ -0,0 +1,53 @@ +body { + align-content: center; +} + +table { + align-content: center; +} + +label { + width: 80px; + display: inline-block; + align-content: center; +} + +input { + margin-left: 0px; + margin-right: 2px; + margin-top: 2px; + margin-bottom: 2px; +} + +table td { + align-content: center; +} + +table tr { + align-content: center; +} + +#tb { + color: #333333; + border-width: 0px; + border-collapse: collapse; + background-color: #333333; +} + + #tb th { + border-width: 0px; + padding: 8px; + align-content: center; + background-color: #dedede; + } + + #tb td { + border-width: 0px; + padding: 8px; + align-content: center; + background-color: #ffffff; + } + +#errmsg { + align-content: center; +} diff --git a/CitySunlight/HttpUtils.cs b/CitySunlight/HttpUtils.cs new file mode 100644 index 0000000..7c6a327 --- /dev/null +++ b/CitySunlight/HttpUtils.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace CitySunlight +{ + public static class HttpUtils + { + public static String getElementsbyName(String tagName) + { + if (HttpContext.Current.Request.Form[tagName] != null) + return HttpContext.Current.Request.Form[tagName].ToString().Trim(); + else + return null; + } + public static String getQueryString(String tagName) + { + if (HttpContext.Current.Request.QueryString[tagName] != null) + return HttpContext.Current.Request.QueryString[tagName]; + else + return null; + } + + public static HttpPostedFile getFilebyName(String tagName) + { + HttpPostedFile file = HttpContext.Current.Request.Files[tagName]; + if (file != null && file.ContentLength > 0) + return file; + else + return null; + } + public static long currentTimeMillis() + { + return (long)((DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds); + } + public static String addTd() + { + return ""; + } + public static String addTd(String s) + { + return String.Format("{0}", s); + } + public static String addTd(String s, int col, int row) + { + String td = "{0}", s); + } + public static int ToInt(this string s) + { + int i; + if (!int.TryParse(s, out i)) + { + i = 0; + } + return i; + } + public static decimal Todecimal(this string s) + { + decimal i; + if (!decimal.TryParse(s, out i)) + { + i = 0; + } + return i; + } + } +} \ No newline at end of file diff --git a/CitySunlight/Main.aspx b/CitySunlight/Main.aspx new file mode 100644 index 0000000..2af5b86 --- /dev/null +++ b/CitySunlight/Main.aspx @@ -0,0 +1,23 @@ +<%@ Page Language="C#" MasterPageFile="~/Basic.Master" AutoEventWireup="true" CodeBehind="Main.aspx.cs" Inherits="CitySunlight.Main" %> +<%@ Import Namespace="CitySunlight" %> + +
+ + + + + + + + + + + <%= GetProductInfo() %> +
商品名称: + 产品分类: <%= classoption %> +  
+
+
+ + + diff --git a/CitySunlight/Main.aspx.cs b/CitySunlight/Main.aspx.cs new file mode 100644 index 0000000..584b571 --- /dev/null +++ b/CitySunlight/Main.aspx.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; +using CitySunlight.Product; + +namespace CitySunlight +{ + public partial class Main : System.Web.UI.Page + { + int pages = HttpUtils.getQueryString("pages").ToInt(); + public String classid = HttpUtils.getQueryString("classid"); + public String search = HttpUtils.getQueryString("search"); + public String classoption; + const int peritems = 5; + protected void Page_Load(object sender, EventArgs e) + { + classoption = ProductClassManager.getOptionString("classid", classid); + } + public String GetProductInfo() + { + String html = ""; + DataTable items = ProductManager.SearchProduct("", search, classid, "", "", pages, peritems); + if (items.Rows.Count == 0) + return "数据库中未找到产品"; + else + html += String.Format("{0}", + HttpUtils.addTd("") + + HttpUtils.addTd("商品名称") + + HttpUtils.addTd("商品图片") + + HttpUtils.addTd("商品价格") + + HttpUtils.addTd("商品数量") + + HttpUtils.addTd("商品分类") + + HttpUtils.addTd("所属卖家") + + HttpUtils.addTd("")); + + foreach (DataRow item in items.Rows) + { + int id = int.Parse(ProductManager.GetProductInfo(item, ProductManager.Info.ID)); + String name = ProductManager.GetProductInfo(item, ProductManager.Info.ItemName); + String url = ProductManager.GetProductInfo(item, ProductManager.Info.PicUrl); + String picurl = String.Format("", url); + String price = ProductManager.GetProductInfo(item, ProductManager.Info.Price); + String amount = ProductManager.GetProductInfo(item, ProductManager.Info.Amount); + String user = ProductManager.GetProductInfo(item, ProductManager.Info.UserName); + String classname = ProductClassManager.getClassName(int.Parse(ProductManager.GetProductInfo(item, ProductManager.Info.Class))); + + html += String.Format("{0}", + HttpUtils.addTd("") + + HttpUtils.addTd(ProductManager.NameToUrl(id, name)) + + HttpUtils.addTd(picurl) + + HttpUtils.addTd(price) + + HttpUtils.addTd(amount) + + HttpUtils.addTd(classname) + + HttpUtils.addTd(user) + + HttpUtils.addTd("")); + } + decimal total = ProductManager.SearchProduct("", search, classid, "", "").Rows.Count / peritems; + int totalpages = (int)(Math.Ceiling(total)); + String allpage = ""; + for (int i = 1; i <= totalpages; i++) + { + String page = String.Format(" {3} ", search, classid, i, i); + allpage += page; + } + html += String.Format("{0} 共{1}页", allpage, totalpages); + return html; + } + + protected void searchB_Click(object sender, EventArgs e) + { + String search = HttpUtils.getElementsbyName("search"); + String classid = HttpUtils.getElementsbyName("classid"); + String url = String.Format("/Main.aspx?search={0}&classid={1}&pages=1", search, classid == "0" ? "" : classid); + Response.Redirect(url); + } + + } +} \ No newline at end of file diff --git a/CitySunlight/Main.aspx.designer.cs b/CitySunlight/Main.aspx.designer.cs new file mode 100644 index 0000000..a0684a4 --- /dev/null +++ b/CitySunlight/Main.aspx.designer.cs @@ -0,0 +1,33 @@ +//------------------------------------------------------------------------------ +// <自动生成> +// 此代码由工具生成。 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace CitySunlight { + + + public partial class Main { + + /// + /// formmain 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::System.Web.UI.HtmlControls.HtmlForm formmain; + + /// + /// searchB 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::System.Web.UI.WebControls.Button searchB; + } +} diff --git a/CitySunlight/Picture/1434620915053_jtb.jpg b/CitySunlight/Picture/1434620915053_jtb.jpg new file mode 100644 index 0000000..86d18fb Binary files /dev/null and b/CitySunlight/Picture/1434620915053_jtb.jpg differ diff --git a/CitySunlight/Picture/1434621663737_jtb.jpg b/CitySunlight/Picture/1434621663737_jtb.jpg new file mode 100644 index 0000000..55d1381 Binary files /dev/null and b/CitySunlight/Picture/1434621663737_jtb.jpg differ diff --git a/CitySunlight/Picture/1434623685494_hww.jpg b/CitySunlight/Picture/1434623685494_hww.jpg new file mode 100644 index 0000000..acd2428 Binary files /dev/null and b/CitySunlight/Picture/1434623685494_hww.jpg differ diff --git a/CitySunlight/Picture/1434625802607_jtb.jpg b/CitySunlight/Picture/1434625802607_jtb.jpg new file mode 100644 index 0000000..55d1381 Binary files /dev/null and b/CitySunlight/Picture/1434625802607_jtb.jpg differ diff --git a/CitySunlight/Picture/1434625867729_jtb.jpg b/CitySunlight/Picture/1434625867729_jtb.jpg new file mode 100644 index 0000000..acd2428 Binary files /dev/null and b/CitySunlight/Picture/1434625867729_jtb.jpg differ diff --git a/CitySunlight/Picture/1434626190135_jtb.jpg b/CitySunlight/Picture/1434626190135_jtb.jpg new file mode 100644 index 0000000..55d1381 Binary files /dev/null and b/CitySunlight/Picture/1434626190135_jtb.jpg differ diff --git a/CitySunlight/Picture/1434679594791_jtb.jpg b/CitySunlight/Picture/1434679594791_jtb.jpg new file mode 100644 index 0000000..d59ab2a Binary files /dev/null and b/CitySunlight/Picture/1434679594791_jtb.jpg differ diff --git a/CitySunlight/Picture/1434679618304_jtb.jpg b/CitySunlight/Picture/1434679618304_jtb.jpg new file mode 100644 index 0000000..28f5678 Binary files /dev/null and b/CitySunlight/Picture/1434679618304_jtb.jpg differ diff --git a/CitySunlight/Picture/1434679648856_jtb.jpg b/CitySunlight/Picture/1434679648856_jtb.jpg new file mode 100644 index 0000000..3e130ef Binary files /dev/null and b/CitySunlight/Picture/1434679648856_jtb.jpg differ diff --git a/CitySunlight/Picture/1434687922392_jtb.jpg b/CitySunlight/Picture/1434687922392_jtb.jpg new file mode 100644 index 0000000..acd2428 Binary files /dev/null and b/CitySunlight/Picture/1434687922392_jtb.jpg differ diff --git a/CitySunlight/Picture/1434692042542_hww.jpg b/CitySunlight/Picture/1434692042542_hww.jpg new file mode 100644 index 0000000..ce412d4 Binary files /dev/null and b/CitySunlight/Picture/1434692042542_hww.jpg differ diff --git a/CitySunlight/Picture/1434692073846_hww.jpg b/CitySunlight/Picture/1434692073846_hww.jpg new file mode 100644 index 0000000..86d413d Binary files /dev/null and b/CitySunlight/Picture/1434692073846_hww.jpg differ diff --git a/CitySunlight/Picture/1_jtb.jpg b/CitySunlight/Picture/1_jtb.jpg new file mode 100644 index 0000000..df3e752 Binary files /dev/null and b/CitySunlight/Picture/1_jtb.jpg differ diff --git a/CitySunlight/Picture/4_jtb.jpg b/CitySunlight/Picture/4_jtb.jpg new file mode 100644 index 0000000..2017eb3 Binary files /dev/null and b/CitySunlight/Picture/4_jtb.jpg differ diff --git a/CitySunlight/Picture/empty.jpg b/CitySunlight/Picture/empty.jpg new file mode 100644 index 0000000..55d1381 Binary files /dev/null and b/CitySunlight/Picture/empty.jpg differ diff --git a/CitySunlight/Picture/head.jpg b/CitySunlight/Picture/head.jpg new file mode 100644 index 0000000..9823157 Binary files /dev/null and b/CitySunlight/Picture/head.jpg differ diff --git a/CitySunlight/Picture/main.jpg b/CitySunlight/Picture/main.jpg new file mode 100644 index 0000000..86d18fb Binary files /dev/null and b/CitySunlight/Picture/main.jpg differ diff --git a/CitySunlight/Product/ProductClassEdit.aspx b/CitySunlight/Product/ProductClassEdit.aspx new file mode 100644 index 0000000..c6ce041 --- /dev/null +++ b/CitySunlight/Product/ProductClassEdit.aspx @@ -0,0 +1,74 @@ +<%@ Page Language="C#" MasterPageFile="~/Basic.Master" AutoEventWireup="true" CodeBehind="ProductClassEdit.aspx.cs" Inherits="CitySunlight.ProductClassEdit" %> + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

自定义分类管理

+
+ <%= msg %> +
+

添加分类

+
+ 新增类名: + + +
+ 上级分类: + <%= GetOption("addclassfather") %> +
+

删除分类

+
+ 当前分类: + <%= GetOption("deleteclass") %> + +
+

修改分类

+
+ 选择分类: + <%= GetOption("editclassid") %> + +
+ 修改类名: + +
+
+
diff --git a/CitySunlight/Product/ProductClassEdit.aspx.cs b/CitySunlight/Product/ProductClassEdit.aspx.cs new file mode 100644 index 0000000..17f9da1 --- /dev/null +++ b/CitySunlight/Product/ProductClassEdit.aspx.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; + +namespace CitySunlight +{ + public partial class ProductClassEdit : System.Web.UI.Page + { + public String msg; + protected void Page_Load(object sender, EventArgs e) + { + + } + public String GetOption(String name) + { + return ProductClassManager.getOptionString(name); + } + + protected void add_Click(object sender, EventArgs e) + { + String cname = HttpUtils.getElementsbyName("customclass"); + int pid = int.Parse(HttpUtils.getElementsbyName("addclassfather")); + if (cname == "") + { + msg = "请输入分类的名称!"; + return; + } + if (ProductClassManager.isExist(cname)) + { + msg = "分类 [" + cname + "] 已存在!"; + return; + } + if (ProductClassManager.addclass(pid, cname)) + { + msg = "分类 [" + cname + "] 添加成功!"; + return; + } + } + protected void remove_Click(object sender, EventArgs e) + { + int id = int.Parse(HttpUtils.getElementsbyName("deleteclass")); + String cname = ProductClassManager.getClassName(id); + if (id == 0) + { + msg = "请选择需要删除的分类!"; + return; + } + if (ProductClassManager.removeclass(id)) + { + msg = "分类 [" + cname + "] 删除成功!"; + } + } + + protected void edit_Click(object sender, EventArgs e) + { + int id = int.Parse(HttpUtils.getElementsbyName("editclassid")); + String ocname = ProductClassManager.getClassName(id); + String cname = HttpUtils.getElementsbyName("editclassname"); + if (ProductClassManager.isExist(cname)) + { + msg = "修改失败 分类名称 [" + cname + "] 已存在!"; + return; + } + if (ProductClassManager.editclass(id, cname)) + { + msg = "修改成功 分类名称 [" + ocname + "] 已修改为 [" + cname + "]!"; + return; + } + } + } +} \ No newline at end of file diff --git a/CitySunlight/Product/ProductClassEdit.aspx.designer.cs b/CitySunlight/Product/ProductClassEdit.aspx.designer.cs new file mode 100644 index 0000000..e4455f3 --- /dev/null +++ b/CitySunlight/Product/ProductClassEdit.aspx.designer.cs @@ -0,0 +1,51 @@ +//------------------------------------------------------------------------------ +// <自动生成> +// 此代码由工具生成。 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace CitySunlight { + + + public partial class ProductClassEdit { + + /// + /// productclasseditform 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::System.Web.UI.HtmlControls.HtmlForm productclasseditform; + + /// + /// add 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::System.Web.UI.WebControls.Button add; + + /// + /// remove 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::System.Web.UI.WebControls.Button remove; + + /// + /// Edit 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::System.Web.UI.WebControls.Button Edit; + } +} diff --git a/CitySunlight/Product/ProductClassManager.cs b/CitySunlight/Product/ProductClassManager.cs new file mode 100644 index 0000000..54e04cb --- /dev/null +++ b/CitySunlight/Product/ProductClassManager.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Web; + +namespace CitySunlight +{ + public static class ProductClassManager + { + public static SqlHelper sql = new SqlHelper("Data Source=.;Initial Catalog=myApplication;Persist Security Info=True;User ID=sa;Password=325325"); + //分类表名 + public const String tbname = "tb_proclass"; + + //获得分类列表默认选择第一个 + public static String getOptionString(String name) + { + return getOptionString(name, "0"); + } + //获得分类列表 可以配置选项 + public static String getOptionString(String name, String df) + { + String html = ""; + return html; + } + //获得分类名称通过ID + public static String getClassName(int Nid) + { + DataTable dt = sql.ExecuteDataTable("select * from " + tbname + " where nid='" + Nid + "'", CommandType.Text); + if (dt.Rows.Count > 0) + return dt.Rows[0]["ProClassName"].ToString(); + else + return "分类已被删除"; + } + //判断分类是否存在 + public static bool isExist(String name) + { + return sql.ExecuteDataTable("select * from " + tbname + " where ProClassName='" + name + "'", CommandType.Text).Rows.Count > 0; + } + public static bool isExist(int nid) + { + return sql.ExecuteDataTable("select * from " + tbname + " where Nid='" + nid + "'", CommandType.Text).Rows.Count > 0; + } + //添加分类 + public static bool addclass(int Pid, String classname) + { + int j = sql.ExecuteNonQuery("insert into " + tbname + "(Pid,ProClassName) values('" + Pid + "','" + classname + "')", CommandType.Text); + if (j > 0) + return true; + return false; + } + //删除分类 + public static bool removeclass(int Nid) + { + if (Nid != 0) + { + int j = sql.ExecuteNonQuery("delete from " + tbname + " where Nid='" + Nid + "'", CommandType.Text); + if (j > 0) + return true; + } + return false; + } + //修改分类 + public static bool editclass(int Nid, String cname) + { + if (Nid != 0) + { + int j = sql.ExecuteNonQuery("update " + tbname + " set ProClassName='" + cname + "' where Nid='" + Nid + "'", CommandType.Text); + if (j > 0) + return true; + } + return false; + } + } +} \ No newline at end of file diff --git a/CitySunlight/Product/ProductEdit.aspx b/CitySunlight/Product/ProductEdit.aspx new file mode 100644 index 0000000..285f8d2 --- /dev/null +++ b/CitySunlight/Product/ProductEdit.aspx @@ -0,0 +1,19 @@ +<%@ Page Language="C#" MasterPageFile="~/Basic.Master" AutoEventWireup="true" CodeBehind="ProductEdit.aspx.cs" Inherits="CitySunlight.Product.ProductEdit" %> + + +
+ + + +
+ <%= msg %> +
+ <%= CreateEditForm() %> + + + + +
+
+
+
diff --git a/CitySunlight/Product/ProductEdit.aspx.cs b/CitySunlight/Product/ProductEdit.aspx.cs new file mode 100644 index 0000000..019aada --- /dev/null +++ b/CitySunlight/Product/ProductEdit.aspx.cs @@ -0,0 +1,256 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.IO; +using System.Linq; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; +using CitySunlight; + +namespace CitySunlight.Product +{ + public partial class ProductEdit : System.Web.UI.Page + { + public String msg; + public String username; + public String type; + protected void Page_Load(object sender, EventArgs e) + { + if (Session["username"] == null) + Response.Redirect("/Account/Login.aspx"); + else + username = Session["username"].ToString(); + type = HttpUtils.getQueryString("type"); + switch (type) + { + case "success": + msg = HttpUtils.getQueryString("msg"); + this.submit.Visible = false; + break; + case "delete": + if (isExist(HttpUtils.getQueryString("id").ToInt()) != 0) + { + msg = "你确定要删除这个产品?"; + this.submit.Text = "确定"; + } + break; + } + } + + public String CreateEditForm() + { + int id = HttpUtils.getQueryString("id").ToInt(); + switch (type) + { + case "edit": + if (isExist(id) != 0) + { + this.submit.Text = "修改"; + return GetEditForm(id); + } + return ""; + case "create": + this.submit.Text = "添加"; + return GetEditForm(id); + } + return ""; + } + public int isExist(int id) + { + if (id == 0 || !ProductManager.isExist(id)) + { + this.submit.Visible = false; + msg = "您所操作的产品不存在!"; + id = 0; + } + return id; + } + + protected String GetEditForm(int id) + { + String name = ""; + String url = "empty.jpg"; + String picurl = String.Format("", url); + String price = ""; + String amount = ""; + String classid = ""; + if (id != 0) + { + name = ProductManager.GetProductInfo(id, ProductManager.Info.ItemName); + url = ProductManager.GetProductInfo(id, ProductManager.Info.PicUrl); + picurl = String.Format("", url); + price = ProductManager.GetProductInfo(id, ProductManager.Info.Price); + amount = ProductManager.GetProductInfo(id, ProductManager.Info.Amount); + classid = ProductManager.GetProductInfo(id, ProductManager.Info.Class); + if (username != ProductManager.GetProductInfo(id, ProductManager.Info.UserName)) + return "

你没有修改此商品的权限!

"; + + } + String html = ""; + html += ""; + html += "" + addTdc("

商品编辑

", 3) + ""; + html += "" + addTd("商品名称") + addTdc(addText("Name", name), 2) + addTd("") + ""; + html += "" + addTd("商品分类") + addTd(ProductClassManager.getOptionString("Class", classid)) + addTd(addA("编辑", "ProductClassEdit.aspx")) + ""; + html += "" + addTdr("商品图片", 2) + addTdc(picurl, 2) + ""; + html += "" + addTdc(addFile("Picture"), 2) + ""; + html += "" + addTd("商品价格") + addTdc(addText("Price", price), 2) + ""; + html += "" + addTd("库存数量") + addTdc(addText("Amount", amount), 2) + ""; + html += "
"; + return html; + } + protected String addA(String Text, String Url) + { + return String.Format("{1}", Url, Text); + } + protected String addTd(String value) + { + return String.Format("{0}", value); + } + protected String addTdc(String value, int colspan) + { + return String.Format("{1}", colspan, value); + } + protected String addTdr(String value, int rowspan) + { + return String.Format("{1}", rowspan, value); + } + protected String addText(String name, String value) + { + return String.Format("", name, value); + } + protected String addImg(String picname) + { + return String.Format("\"\"", picname); + } + protected String addFile(String name) + { + return String.Format("", name); + } + protected void submit_Click(object sender, EventArgs e) + { + int id = HttpUtils.getQueryString("id").ToInt(); + String picurl = ""; + switch (type) + { + case "delete": + if (ProductManager.DeleteProduct(id)) + { + msg = "产品删除成功!"; + Response.Redirect("/Product/ProductEdit.aspx?type=success&msg=" + msg); + } + return; + case "edit": + if (id == 0) + { + msg = "您所操作的产品不存在!"; + return; + } + picurl = ProductManager.GetProductInfo(id, ProductManager.Info.PicUrl); + break; + } + String floder = "/Picture/"; + String user = Session["username"].ToString(); + String name = HttpUtils.getElementsbyName("Name"); + HttpPostedFile file = HttpUtils.getFilebyName("Picture"); + decimal price = HttpUtils.getElementsbyName("Price").Todecimal(); + int amount = HttpUtils.getElementsbyName("Amount").ToInt(); + int classid = int.Parse(HttpUtils.getElementsbyName("Class")); + //检查名称 + if (name.Length == 0) + { + msg = "请填写名称!"; + GoBack(); + return; + } + //检查价格 + if (price == 0) + { + msg = "请输入价格且必须为数字!"; + GoBack(); + return; + } + //检查库存 + if (amount == 0) + { + msg = "请输入库存且必须为数字!"; + GoBack(); + return; + } + //检查图片(图片文件为空,且不存在原有图片) + if (file == null && picurl == "") + { + msg = "请上传产品图片!"; + Response.Write("windows.history.go(-1);"); + return; + } + if (file != null) + { + String fileExtension = Path.GetExtension(file.FileName).ToLower(); + //验证上传文件是否图片格式 + if (!IsImage(fileExtension)) + { + msg = "请上传类型为 jpg | gif | bmp | png 图片!"; + GoBack(); + return; + } + //生成图片名称 + picurl = HttpUtils.currentTimeMillis() + "_" + user + fileExtension; + //转换为系统路径 + String filepath = Server.MapPath(floder + picurl); + //保存图片 + file.SaveAs(filepath); + } + bool upload = false; + switch (type) + { + case "edit": + upload = ProductManager.EditProduct(id, user, name, classid, picurl, price, amount); + break; + case "create": + upload = ProductManager.AddProduct(user, name, classid, picurl, price, amount); + break; + } + if (upload) + { + msg = "产品发布成功!"; + Response.Redirect("/Product/ProductEdit.aspx?type=success&msg=" + msg); + } + else + { + msg = "产品发布失败!"; + GoBack(); + } + + + } + + + public void GoBack() + { + Response.Write("windows.history.go(-1);"); + } + /// + /// 验证是否指定的图片格式 + /// + /// + /// + public bool IsImage(string str) + { + bool isimage = false; + string thestr = str.ToLower(); + //限定只能上传jpg和gif图片 + string[] allowExtension = { ".jpg", ".gif", ".bmp", ".png" }; + //对上传的文件的类型进行一个个匹对 + for (int i = 0; i < allowExtension.Length; i++) + { + if (thestr == allowExtension[i]) + { + isimage = true; + break; + } + } + return isimage; + } + } +} \ No newline at end of file diff --git a/CitySunlight/Product/ProductEdit.aspx.designer.cs b/CitySunlight/Product/ProductEdit.aspx.designer.cs new file mode 100644 index 0000000..353aa39 --- /dev/null +++ b/CitySunlight/Product/ProductEdit.aspx.designer.cs @@ -0,0 +1,33 @@ +//------------------------------------------------------------------------------ +// <自动生成> +// 此代码由工具生成。 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace CitySunlight.Product { + + + public partial class ProductEdit { + + /// + /// productedit 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::System.Web.UI.HtmlControls.HtmlForm productedit; + + /// + /// submit 控件。 + /// + /// + /// 自动生成的字段。 + /// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。 + /// + protected global::System.Web.UI.WebControls.Button submit; + } +} diff --git a/CitySunlight/Product/ProductManager.cs b/CitySunlight/Product/ProductManager.cs new file mode 100644 index 0000000..4dac51a --- /dev/null +++ b/CitySunlight/Product/ProductManager.cs @@ -0,0 +1,231 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Web; + +namespace CitySunlight.Product +{ + public static class ProductManager + { + private static SqlHelper sql = new SqlHelper("Data Source=.;Initial Catalog=myApplication;Persist Security Info=True;User ID=sa;Password=325325"); + const String tbname = "tb_product"; + public enum Info + { + ID, + UserName, + ItemName, + Class, + PicUrl, + Price, + Amount + } + /// + /// 根据信息查询产品 + /// + /// 查询类型 + /// 查询值 + /// 查询到的数据表 + public static DataTable SearchProduct(Info it, String value) + { + String cmd = String.Format("SELECT * FROM {0} WHERE {1} LIKE '%{2}%'", tbname, it.ToString(), value); + return sql.ExecuteDataTable(cmd, CommandType.Text); + } + /// + /// 估计产品信息查询产品 + /// + /// 用户名 + /// 产品名 + /// 产品类 + /// 价格 + /// 库存 + /// + public static DataTable SearchProduct(String username, String itemname, String ClassId, String price, String amount) + { + String cmd = "select * from {0} where "; + cmd += String.Format("{0} like '%{1}%'", Info.UserName.ToString(), username); + cmd += String.Format("and {0} like '%{1}%'", Info.ItemName.ToString(), itemname); + cmd += String.Format("and {0} like '%{1}%'", Info.Class.ToString(), ClassId); + cmd += String.Format("and {0} like '%{1}%'", Info.Price.ToString(), price); + cmd += String.Format("and {0} like '%{1}%'", Info.Amount.ToString(), amount); + String sqlcmd = String.Format(cmd, tbname, itemname, ClassId); + return sql.ExecuteDataTable(sqlcmd, CommandType.Text); + } + /// + /// 根据产品信息查询产品并分页 + /// + /// 用户名 + /// 产品名 + /// 产品类 + /// 价格 + /// 库存 + /// 第几页 + /// 每页大小 + /// 数据表 + public static DataTable SearchProduct(String username, String itemname, String ClassId, String price, String amount, int Index, int Size) + {//select * from (select *,row_number() over (order by Id asc) as number from {0} where {1} like '%{2}%') temp where temp.number between {3} and {4} + int start = ((Index == 0 ? 1 : Index) - 1) * Size + 1; + int end = start + Size - 1; + String cmd = "select * from (select *,row_number() over (order by Id asc) as number from {0} where {1}) temp where temp.number between {2} and {3}"; + String condition = String.Format("{0} like '%{1}%'", Info.UserName.ToString(), username); + condition += String.Format("and {0} like '%{1}%'", Info.ItemName.ToString(), itemname); + condition += String.Format("and {0} like '%{1}%'", Info.Class.ToString(), ClassId); + condition += String.Format("and {0} like '%{1}%'", Info.Price.ToString(), price); + condition += String.Format("and {0} like '%{1}%'", Info.Amount.ToString(), amount); + String sqlcmd = String.Format(cmd, tbname, condition, start, end); + return sql.ExecuteDataTable(sqlcmd, CommandType.Text); + } + /// + /// 获得所有产品的数据表 + /// + /// DataTable 数据表 + public static DataTable GetAllProduct() + { + return sql.ExecuteDataTable("select * from " + tbname, CommandType.Text); + } + /// + /// 获取指定ID产品的数据行 + /// + /// + /// DataRow 数据行 + public static DataRow GetProductById(int Id) + { + return sql.ExecuteDataTable("select * from " + tbname + " where Id='" + Id + "'", CommandType.Text).Rows[0]; + } + /// + /// 获取第几页,几个产品 + /// + /// 第几页 + /// 每页大小 + /// + public static DataTable GetSomeProduct(int Index, int Size) + { + int start = (Index - 1) * Size + 1; + int end = start + Size - 1; + String cmd = "select * from (select *,row_number() over (order by Id asc) as number from {0}) temp where temp.number between {1} and {2}"; + String sqlcmd = String.Format(cmd, tbname, start, end); + return sql.ExecuteDataTable(sqlcmd, CommandType.Text); + } + /// + /// 通过用户名获取用户所有产品信息(数据库部分) + /// + /// + /// + public static DataTable GetUserProduct(String username) + { + return sql.ExecuteDataTable("select * from " + tbname + " where UserName='" + username + "'", CommandType.Text); + } + /// + /// 通过ID获取产品指定信息(数据库部分) + /// + /// + /// + /// String 指定数据的字符串格式 + public static String GetProductInfoById(int Id, String type) + { + return sql.ExecuteDataTable("select " + type + " from " + tbname + " where Id='" + Id + "'", CommandType.Text).Rows[0][0].ToString(); + } + /// + /// 通过ID编辑产品信息(数据库部分) + /// + /// + /// + /// + /// bool 是否成功 + public static bool EditProductInfoById(int Id, String type, String value) + { + if (sql.ExecuteNonQuery("update " + tbname + " set " + type + "='" + value + "' where Id='" + Id + "'", CommandType.Text) > 0) + return true; + return false; + } + /// + /// 添加产品信息(数据库部分) + /// + /// + /// + /// + /// + /// + /// + /// bool 是否成功 + public static bool AddProduct(String username, String itemname, int ClassId, String picurl, decimal price, int amount) + { + String sqlcmd = "insert into tb_product(UserName,ItemName,Class,PicUrl,Price,Amount) values('{0}','{1}','{2}','{3}','{4}','{5}')"; + sqlcmd = String.Format(sqlcmd, username, itemname, ClassId, picurl, price, amount); + if (sql.ExecuteNonQuery(sqlcmd, CommandType.Text) > 0) + return true; + return false; + } + /// + /// 更新产品信息(数据库部分) + /// + /// + /// + /// + /// + /// + /// + /// + /// bool 是否成功 + public static bool EditProduct(int id, String username, String itemname, int ClassId, String picurl, decimal price, int amount) + { + String sqlcmd = "update tb_product set UserName='{0}',ItemName='{1}',Class='{2}',PicUrl='{3}',Price='{4}',Amount='{5}' where id='" + id + "'"; + sqlcmd = String.Format(sqlcmd, username, itemname, ClassId, picurl, price, amount); + if (sql.ExecuteNonQuery(sqlcmd, CommandType.Text) > 0) + return true; + return false; + } + /// + /// 删除产品信息(数据库部分) + /// + /// + /// bool 是否成功 + public static bool DeleteProduct(int id) + { + String sqlcmd = "delete from " + tbname + " where id='" + id + "'"; + if (sql.ExecuteNonQuery(sqlcmd, CommandType.Text) > 0) + return true; + return false; + } + /// + /// 判断商品ID是否存在 + /// + /// + /// bool 是否存在 + public static bool isExist(int Id) + { + return sql.ExecuteDataTable("select * from " + tbname + " where Id='" + Id + "'", CommandType.Text).Rows.Count > 0; + } + /// + /// DataRow转换成商品信息 + /// + /// + /// + /// + public static String GetProductInfo(DataRow Product, Info it) + { + return Product[it.ToString()].ToString(); + } + ////通过商品ID获取产品信息 + public static String GetProductInfo(int id, Info it) + { + return GetProductInfoById(id, it.ToString()); + } + ////通过商品ID编辑产品信息 + public static bool EditProductInfo(int id, Info it, String value) + { + return EditProductInfoById(id, it.ToString(), value); + } + /// + /// 通过商品ID创建产品展示连接 + /// + /// + /// + /// String 商品链接 + public static String NameToUrl(int id, String name) + { + return String.Format("{1}", id, name); + } + + } +} \ No newline at end of file diff --git a/CitySunlight/Product/ProductShow.aspx b/CitySunlight/Product/ProductShow.aspx new file mode 100644 index 0000000..a830754 --- /dev/null +++ b/CitySunlight/Product/ProductShow.aspx @@ -0,0 +1,5 @@ +<%@ Page Language="C#" MasterPageFile="~/Basic.Master" AutoEventWireup="true" CodeBehind="ProductShow.aspx.cs" Inherits="CitySunlight.Product.ProductShow" %> + + + <%= ShowProduct() %> + diff --git a/CitySunlight/Product/ProductShow.aspx.cs b/CitySunlight/Product/ProductShow.aspx.cs new file mode 100644 index 0000000..3bf8fda --- /dev/null +++ b/CitySunlight/Product/ProductShow.aspx.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; + +namespace CitySunlight.Product +{ + public partial class ProductShow : System.Web.UI.Page + { + public String type; + public String username; + protected void Page_Load(object sender, EventArgs e) + { + if (Session["username"] != null) + { + username = Session["username"].ToString(); + } + } + protected String ShowProduct() + { + String html = ""; + int id = HttpUtils.getQueryString("id").ToInt(); + if (ProductManager.isExist(id)) + html = GetProductInfo(id); + else + html = "当前ID的产品不存在或已被删除!"; + return html; + } + + private string GetProductInfo(int id) + { + String html = ""; + String name = ProductManager.GetProductInfo(id, ProductManager.Info.ItemName); + String url = ProductManager.GetProductInfo(id, ProductManager.Info.PicUrl); + String picurl = String.Format("", url); + String price = ProductManager.GetProductInfo(id, ProductManager.Info.Price); + String amount = ProductManager.GetProductInfo(id, ProductManager.Info.Amount); + String user = ProductManager.GetProductInfo(id, ProductManager.Info.UserName); + String edit = "编辑"; + String classname = ProductClassManager.getClassName(int.Parse(ProductManager.GetProductInfo(id, ProductManager.Info.Class))); + html += ""; + html += ""; + html += HttpUtils.addTd(picurl, 3, 3); + html += HttpUtils.addTd(String.Format("名称: {0}", name)); + html += user == username ? HttpUtils.addTd(edit) : ""; + html += ""; + html += HttpUtils.addTd(String.Format("分类: {0}", classname)); + html += ""; + html += HttpUtils.addTd(String.Format("库存: {0}", amount)); + html += ""; + html += HttpUtils.addTd(); + html += HttpUtils.addTd(String.Format("价格: {0}", price)); + html += HttpUtils.addTd(); + html += HttpUtils.addTd("购买"); + html += ""; + html += "
"; + return html; + } + + } +} \ No newline at end of file diff --git a/CitySunlight/Product/ProductShow.aspx.designer.cs b/CitySunlight/Product/ProductShow.aspx.designer.cs new file mode 100644 index 0000000..34a7461 --- /dev/null +++ b/CitySunlight/Product/ProductShow.aspx.designer.cs @@ -0,0 +1,15 @@ +//------------------------------------------------------------------------------ +// <自动生成> +// 此代码由工具生成。 +// +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 +// +//------------------------------------------------------------------------------ + +namespace CitySunlight.Product { + + + public partial class ProductShow { + } +} diff --git a/CitySunlight/Properties/AssemblyInfo.cs b/CitySunlight/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..de1fc3e --- /dev/null +++ b/CitySunlight/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 有关程序集的常规信息通过下列特性集 +// 控制。更改这些特性值可修改 +// 与程序集关联的信息。 +[assembly: AssemblyTitle("CitySunlight")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("CitySunlight")] +[assembly: AssemblyCopyright("版权所有(C) Microsoft 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// 将 ComVisible 设置为 false 会使此程序集中的类型 +// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的某个类型, +// 请针对该类型将 ComVisible 特性设置为 true。 +[assembly: ComVisible(false)] + +// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID +[assembly: Guid("20d38829-f770-4b17-af2f-e55b055eadaa")] + +// 程序集的版本信息由下列四个值组成: +// +// 主版本 +// 次版本 +// 内部版本号 +// 修订号 +// +// 可以指定所有这些值,也可以使用“修订号”和“内部版本号”的默认值, +// 方法是按如下所示使用“*”: +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/CitySunlight/SqlHelper.cs b/CitySunlight/SqlHelper.cs new file mode 100644 index 0000000..73deb71 --- /dev/null +++ b/CitySunlight/SqlHelper.cs @@ -0,0 +1,248 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Data.SqlClient; +using System.Linq; +using System.Web; + +namespace CitySunlight +{ + /// + /// 数据库访问通用类 + /// + public class SqlHelper + { + private string connectionString; + + /// + /// 设定数据库访问字符串 + /// + public string ConnectionString + { + + set { connectionString = value; } + } + + /// + /// 构造函数 + /// + /// 数据库访问字符串 + public SqlHelper(string connectionString) + { + this.connectionString = connectionString; + } + + /// + /// 执行一个查询,并返回查询结果 + /// + /// 要执行的sql语句 + /// 要执行的查询语句的类型,如存储过程或者sql文本命令 + /// 返回查询结果集 + public DataTable ExecuteDataTable(string sql, CommandType commandType) + { + return ExecuteDataTable(sql, commandType, null); + } + + /// + /// 执行一个查询,并返回结果集 + /// + /// 要执行的sql文本命令 + /// 返回查询的结果集 + public DataTable ExecuteDataTable(string sql) + { + return ExecuteDataTable(sql, CommandType.Text, null); + } + + + /// + /// 执行一个查询,并返回查询结果 + /// + /// 要执行的sql语句 + /// 要执行查询语句的类型,如存储过程或者sql文本命令 + /// Transact-SQL语句或者存储过程参数数组 + /// + public DataTable ExecuteDataTable(string sql, CommandType commandtype, SqlParameter[] parameters) + { + DataTable data = new DataTable(); //实例化datatable,用于装载查询结果集 + using (SqlConnection con = new SqlConnection(connectionString)) + { + using (SqlCommand cmd = new SqlCommand(sql, con)) + { + cmd.CommandType = commandtype;//设置command的commandType为指定的Commandtype + //如果同时传入了参数,则添加这些参数 + if (parameters != null) + { + foreach (SqlParameter parameter in parameters) + { + cmd.Parameters.Add(parameter); + } + } + + //通过包含查询sql的sqlcommand实例来实例化sqldataadapter + SqlDataAdapter adapter = new SqlDataAdapter(cmd); + adapter.Fill(data);//填充datatable + + } + } + return data; + } + + /// + /// 返回一个SqlDataReader对象的实例 + /// + /// 要执行的SQl查询命令 + /// + public SqlDataReader ExecuteReader(string sql) + { + return ExecuteReader(sql, CommandType.Text, null); + } + + /// + /// + /// + /// 要执行的sql语句 + /// 要执行查询语句的类型,如存储过程或者SQl文本命令 + /// + public SqlDataReader ExecuteReader(string sql, CommandType commandType) + { + return ExecuteReader(sql, commandType, null); + } + + /// + /// 返回一个sqldatareader对象的实例 + /// + /// + /// + /// + /// + public SqlDataReader ExecuteReader(string sql, CommandType commandType, SqlParameter[] parameters) + { + SqlConnection con = new SqlConnection(connectionString); + SqlCommand cmd = new SqlCommand(sql, con); + + if (parameters != null) + { + foreach (SqlParameter parameter in parameters) + { + cmd.Parameters.Add(parameters); + } + } + con.Open(); + //CommandBehavior.CloseConnection参数指示关闭reader对象时关闭与其关联的Connection对象 + return cmd.ExecuteReader(CommandBehavior.CloseConnection); + } + + /// + /// 执行一个查询,返回结果集的首行首列。忽略其他行,其他列 + /// + /// 要执行的SQl命令 + /// + public Object ExecuteScalar(string sql) + { + return ExecuteScalar(sql, CommandType.Text, null); + } + + /// + /// + /// + /// + /// + /// + public Object ExecuteScalar(string sql, CommandType commandType) + { + return ExecuteScalar(sql, commandType, null); + } + + + /// + /// + /// + /// + /// 参数类型 + /// + /// + public Object ExecuteScalar(string sql, CommandType commandType, SqlParameter[] parameters) + { + Object result = null; + SqlConnection con = new SqlConnection(connectionString); + SqlCommand cmd = new SqlCommand(sql, con); + cmd.CommandType = commandType; + if (parameters != null) + { + foreach (SqlParameter parapmeter in parameters) + { + cmd.Parameters.Add(parapmeter); + } + } + + con.Open(); + result = cmd.ExecuteScalar(); + con.Close(); + return result; + } + + /// + /// 对数据库进行增删改的操作 + /// + /// 要执行的sql命令 + /// + public int ExecuteNonQuery(string sql) + { + return ExecuteNonQuery(sql, CommandType.Text, null); + } + + /// + /// 数据库进行增删改的操作 + /// + /// 对数据库进行操作的sql命令 + /// 要执行查询语句的类型,如存储过程或者sql文本命令 + /// + public int ExecuteNonQuery(string sql, CommandType commandType) + { + return ExecuteNonQuery(sql, commandType, null); + } + + /// + /// 对数据库进行增删改的操作 + /// + /// 要执行的sql语句 + /// 要执行的查询语句类型,如存储过程或者sql文本命令 + /// Transact-SQL语句或者存储过程的参数数组 + /// + public int ExecuteNonQuery(string sql, CommandType commandType, SqlParameter[] parameters) + { + int count = 0; + SqlConnection con = new SqlConnection(connectionString); + SqlCommand cmd = new SqlCommand(sql, con); + cmd.CommandType = commandType; + if (parameters != null) + { + foreach (SqlParameter parameter in parameters) + { + cmd.Parameters.Add(parameter); + } + } + + con.Open(); + count = cmd.ExecuteNonQuery(); + con.Close(); + return count; + } + + /// + /// 返回当前连接的数据库中所有用户创建的数据库 + /// + /// + public DataTable GetTables() + { + DataTable table = null; + using (SqlConnection con = new SqlConnection(connectionString)) + { + con.Open(); + table = con.GetSchema("Tables"); + + } + return table; + } + } +} \ No newline at end of file diff --git a/CitySunlight/Utils.cs b/CitySunlight/Utils.cs new file mode 100644 index 0000000..59de9fd --- /dev/null +++ b/CitySunlight/Utils.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using System.Web; + +namespace CitySunlight +{ + + + + public static class Utils + { + public static IList ToItemInfoList(this DataTable t, string pFieldValue, string pFieldText) + { + IList list = new List(); + if (t == null) + { + return list; + } + + foreach (DataRow row in t.Rows) + { + list.Add(ItemInfo.Create(row[pFieldValue].ToString(), row[pFieldText].ToString())); + } + + return list; + } + + public static string GetSelect(IList pInfolist, string pControlName, string pEditValue, string pFirstValue, string pFirstText) + { + StringBuilder sbStr = new StringBuilder(); + sbStr.Append("