初始化项目...
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
CitySunlight/bin/
|
||||||
|
CitySunlight/obj/
|
||||||
|
packages/
|
22
CitySunlight.sln
Normal file
@ -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
|
BIN
CitySunlight.v12.suo
Normal file
22
CitySunlight/Account/LogOut.aspx
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="LogOut.aspx.cs" Inherits="CitySunlight.Account.LogOut" %>
|
||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
|
<head runat="server">
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||||
|
<title></title>
|
||||||
|
<link rel="stylesheet" href="../CssStyle/CityStyle.css" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<form id="logoutform" runat="server">
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
正在退出登录...
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
21
CitySunlight/Account/LogOut.aspx.cs
Normal file
@ -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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
24
CitySunlight/Account/LogOut.aspx.designer.cs
generated
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <自动生成>
|
||||||
|
// 此代码由工具生成。
|
||||||
|
//
|
||||||
|
// 对此文件的更改可能会导致不正确的行为,并且如果
|
||||||
|
// 重新生成代码,这些更改将会丢失。
|
||||||
|
// </自动生成>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace CitySunlight.Account {
|
||||||
|
|
||||||
|
|
||||||
|
public partial class LogOut {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// logoutform 控件。
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// 自动生成的字段。
|
||||||
|
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
|
||||||
|
/// </remarks>
|
||||||
|
protected global::System.Web.UI.HtmlControls.HtmlForm logoutform;
|
||||||
|
}
|
||||||
|
}
|
40
CitySunlight/Account/Login.aspx
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
<%@ Page Language="C#" MasterPageFile="~/Basic.Master" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="CitySunlight.Default" ValidateRequest="false" %>
|
||||||
|
|
||||||
|
<asp:Content ID="body" ContentPlaceHolderID="body" runat="server">
|
||||||
|
<form id="loginform" runat="server">
|
||||||
|
<table align="center" id="tb">
|
||||||
|
<tr>
|
||||||
|
<td colspan="2" id="head">
|
||||||
|
<h1>都市阳光销售平台</h1>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2" align="center">
|
||||||
|
<span style="color:red"><%= msg %></span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<label>用 户 名:</label></td>
|
||||||
|
<td>
|
||||||
|
<input type="text" id="UserNameTx" name="UserNameTx" />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<label>密 码:</label></td>
|
||||||
|
<td>
|
||||||
|
<input type="password" id="PassWordTx" name="PassWordTx" />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td align="center">
|
||||||
|
<asp:Button runat="server" ID="register" Text="注册" Width="70" OnClick="register_Click" UseSubmitBehavior="False" />
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<asp:Button runat="server" ID="login" Text="登录" OnClick="login_Click" />
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</form>
|
||||||
|
</asp:Content>
|
64
CitySunlight/Account/Login.aspx.cs
Normal file
@ -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("<script>alert('登录成功,欢迎回来" + username + "!')</script>");
|
||||||
|
Response.Redirect("../Main.aspx");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
msg = "账号密码错误,还可以尝试" + (4 - UserManager.GetTimes(username)) + "次..!";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void register_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Response.Redirect("./Register.aspx");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
42
CitySunlight/Account/Login.aspx.designer.cs
generated
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <自动生成>
|
||||||
|
// 此代码由工具生成。
|
||||||
|
//
|
||||||
|
// 对此文件的更改可能会导致不正确的行为,并且如果
|
||||||
|
// 重新生成代码,这些更改将会丢失。
|
||||||
|
// </自动生成>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace CitySunlight {
|
||||||
|
|
||||||
|
|
||||||
|
public partial class Default {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// loginform 控件。
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// 自动生成的字段。
|
||||||
|
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
|
||||||
|
/// </remarks>
|
||||||
|
protected global::System.Web.UI.HtmlControls.HtmlForm loginform;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// register 控件。
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// 自动生成的字段。
|
||||||
|
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
|
||||||
|
/// </remarks>
|
||||||
|
protected global::System.Web.UI.WebControls.Button register;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// login 控件。
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// 自动生成的字段。
|
||||||
|
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
|
||||||
|
/// </remarks>
|
||||||
|
protected global::System.Web.UI.WebControls.Button login;
|
||||||
|
}
|
||||||
|
}
|
44
CitySunlight/Account/Register.aspx
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<%@ Page Language="C#" MasterPageFile="~/Basic.Master" AutoEventWireup="true" CodeBehind="Register.aspx.cs" Inherits="CitySunlight.register" %>
|
||||||
|
|
||||||
|
<asp:Content ID="body" ContentPlaceHolderID="body" runat="server">
|
||||||
|
<form id="registerform" runat="server">
|
||||||
|
<table id="tb" align="center">
|
||||||
|
<tr>
|
||||||
|
<td colspan="2" id="head">
|
||||||
|
<h1>都市阳光注册系统</h1>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2" align="center">
|
||||||
|
<span style="color: red"><%= msg %></span>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<label>用 户 名: </label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input name="usernameTx" type="text" />
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<label>密 码: </label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input name="passwordTx" type="password" />
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<label>确认密码: </label>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<input name="confirmTx" type="password" />
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td colspan="2" align="center">
|
||||||
|
<asp:Button runat="server" Text="注册" ID="submit" OnClick="submit_Click" />
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</form>
|
||||||
|
</asp:Content>
|
||||||
|
|
56
CitySunlight/Account/Register.aspx.cs
Normal file
@ -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("<scrip>alert('1')</scrip>");
|
||||||
|
Session["username"] = username;
|
||||||
|
Response.Redirect("../Main.aspx");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
msg = "注册失败,请联系管理员!";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
33
CitySunlight/Account/Register.aspx.designer.cs
generated
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <自动生成>
|
||||||
|
// 此代码由工具生成。
|
||||||
|
//
|
||||||
|
// 对此文件的更改可能会导致不正确的行为,并且如果
|
||||||
|
// 重新生成代码,这些更改将会丢失。
|
||||||
|
// </自动生成>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace CitySunlight {
|
||||||
|
|
||||||
|
|
||||||
|
public partial class register {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// registerform 控件。
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// 自动生成的字段。
|
||||||
|
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
|
||||||
|
/// </remarks>
|
||||||
|
protected global::System.Web.UI.HtmlControls.HtmlForm registerform;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// submit 控件。
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// 自动生成的字段。
|
||||||
|
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
|
||||||
|
/// </remarks>
|
||||||
|
protected global::System.Web.UI.WebControls.Button submit;
|
||||||
|
}
|
||||||
|
}
|
70
CitySunlight/Account/UserManager.cs
Normal file
@ -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<String, int> trytimes = new Dictionary<string, int>();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
12
CitySunlight/Admin.aspx
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<%@ Page Language="C#" MasterPageFile="~/Basic.Master" AutoEventWireup="true" CodeBehind="Admin.aspx.cs" Inherits="CitySunlight.Admin" %>
|
||||||
|
|
||||||
|
<asp:Content ID="body" ContentPlaceHolderID="body" runat="server">
|
||||||
|
<form id="formmain" runat="server">
|
||||||
|
<table align="center">
|
||||||
|
<%= GetProductInfo() %>
|
||||||
|
</table>
|
||||||
|
</form>
|
||||||
|
</asp:Content>
|
||||||
|
|
||||||
|
|
||||||
|
|
76
CitySunlight/Admin.aspx.cs
Normal file
@ -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 "<tr><td>数据库中未找到产品</td></tr>";
|
||||||
|
else
|
||||||
|
html += String.Format("<tr>{0}</tr>",
|
||||||
|
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("<img src=\"/Picture/{0}\"alt=\"\" width=\"64\" height=\"64\"/>", url);
|
||||||
|
String price = ProductManager.GetProductInfo(item, ProductManager.Info.Price);
|
||||||
|
String amount = ProductManager.GetProductInfo(item, ProductManager.Info.Amount);
|
||||||
|
String edit = "<a href=\"/Product/ProductEdit.aspx?id=" + id + "&type=edit\" >编辑</a>";
|
||||||
|
String classname = ProductClassManager.getClassName(int.Parse(ProductManager.GetProductInfo(item, ProductManager.Info.Class)));
|
||||||
|
String delete = "<a href=\"/Product/ProductEdit.aspx?id=" + id + "&type=delete\" >删除</a>";
|
||||||
|
html += "<tr>";
|
||||||
|
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 += "</tr>";
|
||||||
|
}
|
||||||
|
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(" <a href=\"/Admin.aspx?pages={0}\">{1}</a> ", i, i);
|
||||||
|
allpage += page;
|
||||||
|
}
|
||||||
|
html += String.Format("<tr><td colspan=\"6\" align=\"right\"></td><td colspan=\"2\">{0} 共{1}页</td></tr>", allpage, totalpages);
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
24
CitySunlight/Admin.aspx.designer.cs
generated
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <自动生成>
|
||||||
|
// 此代码由工具生成。
|
||||||
|
//
|
||||||
|
// 对此文件的更改可能会导致不正确的行为,并且如果
|
||||||
|
// 重新生成代码,这些更改将会丢失。
|
||||||
|
// </自动生成>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace CitySunlight {
|
||||||
|
|
||||||
|
|
||||||
|
public partial class Admin {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// formmain 控件。
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// 自动生成的字段。
|
||||||
|
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
|
||||||
|
/// </remarks>
|
||||||
|
protected global::System.Web.UI.HtmlControls.HtmlForm formmain;
|
||||||
|
}
|
||||||
|
}
|
25
CitySunlight/Basic.Master
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Basic.Master.cs" Inherits="CitySunlight.Basic" %>
|
||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
|
<head runat="server">
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||||
|
<asp:ContentPlaceHolder ID="head" runat="server">
|
||||||
|
</asp:ContentPlaceHolder>
|
||||||
|
<link rel="stylesheet" href="/CssStyle/CityStyle.css" />
|
||||||
|
<title>都市阳光销售系统</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<table align="center">
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<a href="/Main.aspx">
|
||||||
|
<img src="/Picture/head.jpg" alt="主页图片" /></a></td>
|
||||||
|
<td><%= GetLoginInfo() %></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<asp:ContentPlaceHolder ID="body" runat="server">
|
||||||
|
</asp:ContentPlaceHolder>
|
||||||
|
</body>
|
||||||
|
</html>
|
33
CitySunlight/Basic.Master.cs
Normal file
@ -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 = "<a href=\"/Account/Login.aspx\" >登录</a>";
|
||||||
|
else
|
||||||
|
{
|
||||||
|
html = String.Format("欢迎您 {0} ", Session["username"].ToString());
|
||||||
|
html += "<a href=\"/Account/LogOut.aspx\" > 注销</a>";
|
||||||
|
html += " ";
|
||||||
|
html += "<a href=\"/Product/ProductEdit.aspx?type=create\" >发布</a>";
|
||||||
|
html += " ";
|
||||||
|
html += "<a href=\"/Admin.aspx\" >管理</a>";
|
||||||
|
}
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
33
CitySunlight/Basic.Master.designer.cs
generated
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <自动生成>
|
||||||
|
// 此代码由工具生成。
|
||||||
|
//
|
||||||
|
// 对此文件的更改可能会导致不正确的行为,并且如果
|
||||||
|
// 重新生成代码,这些更改将会丢失。
|
||||||
|
// </自动生成>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace CitySunlight {
|
||||||
|
|
||||||
|
|
||||||
|
public partial class Basic {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// head 控件。
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// 自动生成的字段。
|
||||||
|
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
|
||||||
|
/// </remarks>
|
||||||
|
protected global::System.Web.UI.WebControls.ContentPlaceHolder head;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// body 控件。
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// 自动生成的字段。
|
||||||
|
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
|
||||||
|
/// </remarks>
|
||||||
|
protected global::System.Web.UI.WebControls.ContentPlaceHolder body;
|
||||||
|
}
|
||||||
|
}
|
195
CitySunlight/CitySunlight.csproj
Normal file
@ -0,0 +1,195 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProductVersion>
|
||||||
|
</ProductVersion>
|
||||||
|
<SchemaVersion>2.0</SchemaVersion>
|
||||||
|
<ProjectGuid>{5CD44C0E-DD9E-45F4-9884-B50E7A42CCD4}</ProjectGuid>
|
||||||
|
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
|
||||||
|
<OutputType>Library</OutputType>
|
||||||
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
|
<RootNamespace>CitySunlight</RootNamespace>
|
||||||
|
<AssemblyName>CitySunlight</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||||
|
<UseIISExpress>true</UseIISExpress>
|
||||||
|
<IISExpressSSLPort />
|
||||||
|
<IISExpressAnonymousAuthentication />
|
||||||
|
<IISExpressWindowsAuthentication />
|
||||||
|
<IISExpressUseClassicPipelineMode />
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="EntityFramework">
|
||||||
|
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="EntityFramework.SqlServer">
|
||||||
|
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="Microsoft.CSharp" />
|
||||||
|
<Reference Include="System.Web.DynamicData" />
|
||||||
|
<Reference Include="System.Web.Entity" />
|
||||||
|
<Reference Include="System.Web.ApplicationServices" />
|
||||||
|
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
|
<Reference Include="System.Web.Extensions" />
|
||||||
|
<Reference Include="System.Xml.Linq" />
|
||||||
|
<Reference Include="System.Drawing" />
|
||||||
|
<Reference Include="System.Web" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
<Reference Include="System.Configuration" />
|
||||||
|
<Reference Include="System.Web.Services" />
|
||||||
|
<Reference Include="System.EnterpriseServices" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="Account\LogOut.aspx" />
|
||||||
|
<Content Include="CssStyle\CityStyle.css" />
|
||||||
|
<Content Include="Account\Login.aspx" />
|
||||||
|
<Content Include="Admin.aspx" />
|
||||||
|
<Content Include="Main.aspx" />
|
||||||
|
<Content Include="Account\Register.aspx" />
|
||||||
|
<Content Include="Picture\1_jtb.jpg" />
|
||||||
|
<Content Include="Picture\empty.jpg" />
|
||||||
|
<Content Include="Picture\main.jpg" />
|
||||||
|
<Content Include="Product\ProductClassEdit.aspx" />
|
||||||
|
<Content Include="Product\ProductEdit.aspx" />
|
||||||
|
<Content Include="Product\ProductShow.aspx" />
|
||||||
|
<Content Include="Web.config" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="Account\LogOut.aspx.cs">
|
||||||
|
<DependentUpon>LogOut.aspx</DependentUpon>
|
||||||
|
<SubType>ASPXCodeBehind</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Account\LogOut.aspx.designer.cs">
|
||||||
|
<DependentUpon>LogOut.aspx</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="HttpUtils.cs" />
|
||||||
|
<Compile Include="Admin.aspx.cs">
|
||||||
|
<DependentUpon>Admin.aspx</DependentUpon>
|
||||||
|
<SubType>ASPXCodeBehind</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Admin.aspx.designer.cs">
|
||||||
|
<DependentUpon>Admin.aspx</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Product\ProductClassManager.cs" />
|
||||||
|
<Compile Include="Product\ProductClassEdit.aspx.cs">
|
||||||
|
<DependentUpon>ProductClassEdit.aspx</DependentUpon>
|
||||||
|
<SubType>ASPXCodeBehind</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Product\ProductClassEdit.aspx.designer.cs">
|
||||||
|
<DependentUpon>ProductClassEdit.aspx</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Product\ProductEdit.aspx.cs">
|
||||||
|
<DependentUpon>ProductEdit.aspx</DependentUpon>
|
||||||
|
<SubType>ASPXCodeBehind</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Product\ProductEdit.aspx.designer.cs">
|
||||||
|
<DependentUpon>ProductEdit.aspx</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Product\ProductManager.cs" />
|
||||||
|
<Compile Include="Main.aspx.cs">
|
||||||
|
<DependentUpon>Main.aspx</DependentUpon>
|
||||||
|
<SubType>ASPXCodeBehind</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Main.aspx.designer.cs">
|
||||||
|
<DependentUpon>Main.aspx</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Account\Register.aspx.cs">
|
||||||
|
<DependentUpon>Register.aspx</DependentUpon>
|
||||||
|
<SubType>ASPXCodeBehind</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Account\Register.aspx.designer.cs">
|
||||||
|
<DependentUpon>Register.aspx</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Basic.Master.cs">
|
||||||
|
<DependentUpon>Basic.Master</DependentUpon>
|
||||||
|
<SubType>ASPXCodeBehind</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Basic.Master.designer.cs">
|
||||||
|
<DependentUpon>Basic.Master</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Product\ProductShow.aspx.cs">
|
||||||
|
<DependentUpon>ProductShow.aspx</DependentUpon>
|
||||||
|
<SubType>ASPXCodeBehind</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Product\ProductShow.aspx.designer.cs">
|
||||||
|
<DependentUpon>ProductShow.aspx</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="SqlHelper.cs" />
|
||||||
|
<Compile Include="Account\UserManager.cs" />
|
||||||
|
<Compile Include="Account\Login.aspx.cs">
|
||||||
|
<DependentUpon>Login.aspx</DependentUpon>
|
||||||
|
<SubType>ASPXCodeBehind</SubType>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Account\Login.aspx.designer.cs">
|
||||||
|
<DependentUpon>Login.aspx</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="Utils.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="packages.config" />
|
||||||
|
<Content Include="Basic.Master" />
|
||||||
|
<None Include="Web.Debug.config">
|
||||||
|
<DependentUpon>Web.config</DependentUpon>
|
||||||
|
</None>
|
||||||
|
<None Include="Web.Release.config">
|
||||||
|
<DependentUpon>Web.config</DependentUpon>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup />
|
||||||
|
<PropertyGroup>
|
||||||
|
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||||
|
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
|
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||||
|
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />
|
||||||
|
<ProjectExtensions>
|
||||||
|
<VisualStudio>
|
||||||
|
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
|
||||||
|
<WebProjectProperties>
|
||||||
|
<UseIIS>True</UseIIS>
|
||||||
|
<AutoAssignPort>True</AutoAssignPort>
|
||||||
|
<DevelopmentServerPort>1815</DevelopmentServerPort>
|
||||||
|
<DevelopmentServerVPath>/</DevelopmentServerVPath>
|
||||||
|
<IISUrl>http://localhost:1815/</IISUrl>
|
||||||
|
<NTLMAuthentication>False</NTLMAuthentication>
|
||||||
|
<UseCustomServer>False</UseCustomServer>
|
||||||
|
<CustomServerUrl>
|
||||||
|
</CustomServerUrl>
|
||||||
|
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
|
||||||
|
</WebProjectProperties>
|
||||||
|
</FlavorProperties>
|
||||||
|
</VisualStudio>
|
||||||
|
</ProjectExtensions>
|
||||||
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
Other similar extension points exist, see Microsoft.Common.targets.
|
||||||
|
<Target Name="BeforeBuild">
|
||||||
|
</Target>
|
||||||
|
<Target Name="AfterBuild">
|
||||||
|
</Target>
|
||||||
|
-->
|
||||||
|
</Project>
|
30
CitySunlight/CitySunlight.csproj.user
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<ProjectView>ShowAllFiles</ProjectView>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ProjectExtensions>
|
||||||
|
<VisualStudio>
|
||||||
|
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
|
||||||
|
<WebProjectProperties>
|
||||||
|
<StartPageUrl>Main.aspx</StartPageUrl>
|
||||||
|
<StartAction>SpecificPage</StartAction>
|
||||||
|
<AspNetDebugging>True</AspNetDebugging>
|
||||||
|
<SilverlightDebugging>False</SilverlightDebugging>
|
||||||
|
<NativeDebugging>False</NativeDebugging>
|
||||||
|
<SQLDebugging>False</SQLDebugging>
|
||||||
|
<ExternalProgram>
|
||||||
|
</ExternalProgram>
|
||||||
|
<StartExternalURL>
|
||||||
|
</StartExternalURL>
|
||||||
|
<StartCmdLineArguments>
|
||||||
|
</StartCmdLineArguments>
|
||||||
|
<StartWorkingDirectory>
|
||||||
|
</StartWorkingDirectory>
|
||||||
|
<EnableENC>True</EnableENC>
|
||||||
|
<AlwaysStartWebServerOnDebug>True</AlwaysStartWebServerOnDebug>
|
||||||
|
</WebProjectProperties>
|
||||||
|
</FlavorProperties>
|
||||||
|
</VisualStudio>
|
||||||
|
</ProjectExtensions>
|
||||||
|
</Project>
|
53
CitySunlight/CssStyle/CityStyle.css
Normal file
@ -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;
|
||||||
|
}
|
71
CitySunlight/HttpUtils.cs
Normal file
@ -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 "<td></td>";
|
||||||
|
}
|
||||||
|
public static String addTd(String s)
|
||||||
|
{
|
||||||
|
return String.Format("<td align=\"center\">{0}</td>", s);
|
||||||
|
}
|
||||||
|
public static String addTd(String s, int col, int row)
|
||||||
|
{
|
||||||
|
String td = "<td align=\"center\"";
|
||||||
|
td += col != 0 ? String.Format(" colspan=\"{0}\"", col) : "";
|
||||||
|
td += row != 0 ? String.Format(" rowspan=\"{0}\"", row) : "";
|
||||||
|
return String.Format(td + " >{0}</td>", 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
23
CitySunlight/Main.aspx
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<%@ Page Language="C#" MasterPageFile="~/Basic.Master" AutoEventWireup="true" CodeBehind="Main.aspx.cs" Inherits="CitySunlight.Main" %>
|
||||||
|
<%@ Import Namespace="CitySunlight" %>
|
||||||
|
<asp:Content ID="body" ContentPlaceHolderID="body" runat="server">
|
||||||
|
<form id="formmain" runat="server">
|
||||||
|
<table align="center">
|
||||||
|
<tr>
|
||||||
|
<td></td>
|
||||||
|
<td align="center"><span>商品名称: </span></td>
|
||||||
|
<td colspan="2" align="center">
|
||||||
|
<input name="search" type="text" value="<%= search %>" /></td>
|
||||||
|
<td>产品分类: </td>
|
||||||
|
<td><%= classoption %></td>
|
||||||
|
<td>
|
||||||
|
<asp:Button ID="searchB" runat="server" Text="搜索" OnClick="searchB_Click" /></td>
|
||||||
|
<td> </td>
|
||||||
|
</tr>
|
||||||
|
<%= GetProductInfo() %>
|
||||||
|
</table>
|
||||||
|
</form>
|
||||||
|
</asp:Content>
|
||||||
|
|
||||||
|
|
||||||
|
|
82
CitySunlight/Main.aspx.cs
Normal file
@ -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 "<tr><td style=\"color:red\" colspan=\"8\" align=\"center\">数据库中未找到产品</td></tr>";
|
||||||
|
else
|
||||||
|
html += String.Format("<tr>{0}</tr>",
|
||||||
|
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("<img src=\"../Picture/{0}\"alt=\"\" width=\"64\" height=\"64\"/>", 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("<tr>{0}</tr>",
|
||||||
|
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(" <a href=\"/Main.aspx?search={0}&classid={1}&pages={2}\">{3}</a> ", search, classid, i, i);
|
||||||
|
allpage += page;
|
||||||
|
}
|
||||||
|
html += String.Format("<tr><td colspan=\"6\" align=\"right\"></td><td colspan=\"2\">{0} 共{1}页</td></tr>", 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
33
CitySunlight/Main.aspx.designer.cs
generated
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <自动生成>
|
||||||
|
// 此代码由工具生成。
|
||||||
|
//
|
||||||
|
// 对此文件的更改可能会导致不正确的行为,并且如果
|
||||||
|
// 重新生成代码,这些更改将会丢失。
|
||||||
|
// </自动生成>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace CitySunlight {
|
||||||
|
|
||||||
|
|
||||||
|
public partial class Main {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// formmain 控件。
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// 自动生成的字段。
|
||||||
|
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
|
||||||
|
/// </remarks>
|
||||||
|
protected global::System.Web.UI.HtmlControls.HtmlForm formmain;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// searchB 控件。
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// 自动生成的字段。
|
||||||
|
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
|
||||||
|
/// </remarks>
|
||||||
|
protected global::System.Web.UI.WebControls.Button searchB;
|
||||||
|
}
|
||||||
|
}
|
BIN
CitySunlight/Picture/1434620915053_jtb.jpg
Normal file
After Width: | Height: | Size: 44 KiB |
BIN
CitySunlight/Picture/1434621663737_jtb.jpg
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
CitySunlight/Picture/1434623685494_hww.jpg
Normal file
After Width: | Height: | Size: 149 KiB |
BIN
CitySunlight/Picture/1434625802607_jtb.jpg
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
CitySunlight/Picture/1434625867729_jtb.jpg
Normal file
After Width: | Height: | Size: 149 KiB |
BIN
CitySunlight/Picture/1434626190135_jtb.jpg
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
CitySunlight/Picture/1434679594791_jtb.jpg
Normal file
After Width: | Height: | Size: 237 KiB |
BIN
CitySunlight/Picture/1434679618304_jtb.jpg
Normal file
After Width: | Height: | Size: 218 KiB |
BIN
CitySunlight/Picture/1434679648856_jtb.jpg
Normal file
After Width: | Height: | Size: 159 KiB |
BIN
CitySunlight/Picture/1434687922392_jtb.jpg
Normal file
After Width: | Height: | Size: 149 KiB |
BIN
CitySunlight/Picture/1434692042542_hww.jpg
Normal file
After Width: | Height: | Size: 120 KiB |
BIN
CitySunlight/Picture/1434692073846_hww.jpg
Normal file
After Width: | Height: | Size: 186 KiB |
BIN
CitySunlight/Picture/1_jtb.jpg
Normal file
After Width: | Height: | Size: 255 KiB |
BIN
CitySunlight/Picture/4_jtb.jpg
Normal file
After Width: | Height: | Size: 177 KiB |
BIN
CitySunlight/Picture/empty.jpg
Normal file
After Width: | Height: | Size: 1.7 KiB |
BIN
CitySunlight/Picture/head.jpg
Normal file
After Width: | Height: | Size: 25 KiB |
BIN
CitySunlight/Picture/main.jpg
Normal file
After Width: | Height: | Size: 44 KiB |
74
CitySunlight/Product/ProductClassEdit.aspx
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
<%@ Page Language="C#" MasterPageFile="~/Basic.Master" AutoEventWireup="true" CodeBehind="ProductClassEdit.aspx.cs" Inherits="CitySunlight.ProductClassEdit" %>
|
||||||
|
|
||||||
|
<asp:Content ContentPlaceHolderID="body" ID="body" runat="server">
|
||||||
|
<form id="productclasseditform" runat="server">
|
||||||
|
<table align="center">
|
||||||
|
<tr>
|
||||||
|
<td colspan="2" align="center">
|
||||||
|
<h3>自定义分类管理</h3>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<!-- 消息提示 -->
|
||||||
|
<tr>
|
||||||
|
<td colspan="2" align="center">
|
||||||
|
<%= msg %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<!-- 添加分类 -->
|
||||||
|
<tr>
|
||||||
|
<td align="center" colspan="2">
|
||||||
|
<h4>添加分类</h4>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td align="center">
|
||||||
|
<a>新增类名: </a>
|
||||||
|
<input type="text" name="customclass" />
|
||||||
|
</td>
|
||||||
|
<td rowspan="2">
|
||||||
|
<asp:Button runat="server" ID="add" Text="添加" Width="45px" OnClick="add_Click" /></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td align="center">
|
||||||
|
<a>上级分类: </a>
|
||||||
|
<%= GetOption("addclassfather") %>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<!-- 删除分类 -->
|
||||||
|
<tr>
|
||||||
|
<td align="center" colspan="2">
|
||||||
|
<h4>删除分类</h4>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td align="center">
|
||||||
|
<a>当前分类: </a>
|
||||||
|
<%= GetOption("deleteclass") %>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<asp:Button runat="server" ID="remove" Text="删除" Width="45px" OnClick="remove_Click" /></td>
|
||||||
|
</tr>
|
||||||
|
<!-- 修改分类 -->
|
||||||
|
<tr>
|
||||||
|
<td align="center" colspan="2">
|
||||||
|
<h4>修改分类</h4>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td align="center">
|
||||||
|
<a>选择分类: </a>
|
||||||
|
<%= GetOption("editclassid") %>
|
||||||
|
</td>
|
||||||
|
<td rowspan="2">
|
||||||
|
<asp:Button runat="server" ID="Edit" Text="修改" Width="45px" OnClick="edit_Click" /></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td align="center">
|
||||||
|
<a>修改类名: </a>
|
||||||
|
<input type="text" name="editclassname" />
|
||||||
|
</td>
|
||||||
|
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</form>
|
||||||
|
</asp:Content>
|
75
CitySunlight/Product/ProductClassEdit.aspx.cs
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
51
CitySunlight/Product/ProductClassEdit.aspx.designer.cs
generated
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <自动生成>
|
||||||
|
// 此代码由工具生成。
|
||||||
|
//
|
||||||
|
// 对此文件的更改可能会导致不正确的行为,并且如果
|
||||||
|
// 重新生成代码,这些更改将会丢失。
|
||||||
|
// </自动生成>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace CitySunlight {
|
||||||
|
|
||||||
|
|
||||||
|
public partial class ProductClassEdit {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// productclasseditform 控件。
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// 自动生成的字段。
|
||||||
|
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
|
||||||
|
/// </remarks>
|
||||||
|
protected global::System.Web.UI.HtmlControls.HtmlForm productclasseditform;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// add 控件。
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// 自动生成的字段。
|
||||||
|
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
|
||||||
|
/// </remarks>
|
||||||
|
protected global::System.Web.UI.WebControls.Button add;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// remove 控件。
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// 自动生成的字段。
|
||||||
|
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
|
||||||
|
/// </remarks>
|
||||||
|
protected global::System.Web.UI.WebControls.Button remove;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Edit 控件。
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// 自动生成的字段。
|
||||||
|
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
|
||||||
|
/// </remarks>
|
||||||
|
protected global::System.Web.UI.WebControls.Button Edit;
|
||||||
|
}
|
||||||
|
}
|
84
CitySunlight/Product/ProductClassManager.cs
Normal file
@ -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 = "<select style=\"width: 120px\" Name=\"" + name + "\">";
|
||||||
|
html += "<option value=\"0\">请选择分类</option>";
|
||||||
|
DataTable option = sql.ExecuteDataTable("select * from " + tbname, CommandType.Text);
|
||||||
|
foreach (DataRow item in option.Rows)
|
||||||
|
{
|
||||||
|
String nid = item["Nid"].ToString();
|
||||||
|
String classname = item["ProClassName"].ToString();
|
||||||
|
html += String.Format("<option value=\"{0}\"{1}>{2}</option>", nid, df == nid ? " selected=\"selected\"" : "", classname);
|
||||||
|
}
|
||||||
|
html += "</select>";
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
19
CitySunlight/Product/ProductEdit.aspx
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<%@ Page Language="C#" MasterPageFile="~/Basic.Master" AutoEventWireup="true" CodeBehind="ProductEdit.aspx.cs" Inherits="CitySunlight.Product.ProductEdit" %>
|
||||||
|
|
||||||
|
<asp:Content runat="server" ID="body" ContentPlaceHolderID="body">
|
||||||
|
<form id="productedit" runat="server" enctype="multipart/form-data">
|
||||||
|
<table align="center">
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<span style="color: red"><%= msg %></span>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<%= CreateEditForm() %>
|
||||||
|
<table align="center">
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<asp:Button ID="submit" runat="server" Text="提交" OnClick="submit_Click" /></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</form>
|
||||||
|
</asp:Content>
|
256
CitySunlight/Product/ProductEdit.aspx.cs
Normal file
@ -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("<img src=\"../Picture/{0}\"alt=\"\" width=\"64\" height=\"64\"/>", 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("<img src=\"../Picture/{0}\"alt=\"\" width=\"64\" height=\"64\"/>", 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 "<h1>你没有修改此商品的权限!</h1>";
|
||||||
|
|
||||||
|
}
|
||||||
|
String html = "";
|
||||||
|
html += "<table align=\"center\">";
|
||||||
|
html += "<tr>" + addTdc("<h1>商品编辑</h1>", 3) + "</tr>";
|
||||||
|
html += "<tr>" + addTd("商品名称") + addTdc(addText("Name", name), 2) + addTd("<input type=\"hidden\" name=\"iid\" value=\"" + id + "\"/>") + "</tr>";
|
||||||
|
html += "<tr>" + addTd("商品分类") + addTd(ProductClassManager.getOptionString("Class", classid)) + addTd(addA("编辑", "ProductClassEdit.aspx")) + "</tr>";
|
||||||
|
html += "<tr>" + addTdr("商品图片", 2) + addTdc(picurl, 2) + "</tr>";
|
||||||
|
html += "<tr>" + addTdc(addFile("Picture"), 2) + "</tr>";
|
||||||
|
html += "<tr>" + addTd("商品价格") + addTdc(addText("Price", price), 2) + "</tr>";
|
||||||
|
html += "<tr>" + addTd("库存数量") + addTdc(addText("Amount", amount), 2) + "</tr>";
|
||||||
|
html += "</table>";
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
protected String addA(String Text, String Url)
|
||||||
|
{
|
||||||
|
return String.Format("<a href=\"{0}\">{1}</a>", Url, Text);
|
||||||
|
}
|
||||||
|
protected String addTd(String value)
|
||||||
|
{
|
||||||
|
return String.Format("<td align=\"center\">{0}</td>", value);
|
||||||
|
}
|
||||||
|
protected String addTdc(String value, int colspan)
|
||||||
|
{
|
||||||
|
return String.Format("<td colspan=\"{0}\" align=\"center\">{1}</td>", colspan, value);
|
||||||
|
}
|
||||||
|
protected String addTdr(String value, int rowspan)
|
||||||
|
{
|
||||||
|
return String.Format("<td rowspan=\"{0}\" align=\"center\">{1}</td>", rowspan, value);
|
||||||
|
}
|
||||||
|
protected String addText(String name, String value)
|
||||||
|
{
|
||||||
|
return String.Format("<input type=\"text\" name=\"{0}\" value=\"{1}\" />", name, value);
|
||||||
|
}
|
||||||
|
protected String addImg(String picname)
|
||||||
|
{
|
||||||
|
return String.Format("<img alt=\"\" src=\"../Picture/{0}\" />", picname);
|
||||||
|
}
|
||||||
|
protected String addFile(String name)
|
||||||
|
{
|
||||||
|
return String.Format("<input type=\"file\" name=\"{0}\" style=\"width:150px\" value=\"请选择文件...\" />", 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("<scrip>windows.history.go(-1);</scrip>");
|
||||||
|
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("<scrip>windows.history.go(-1);</scrip>");
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 验证是否指定的图片格式
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="str"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
33
CitySunlight/Product/ProductEdit.aspx.designer.cs
generated
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <自动生成>
|
||||||
|
// 此代码由工具生成。
|
||||||
|
//
|
||||||
|
// 对此文件的更改可能会导致不正确的行为,并且如果
|
||||||
|
// 重新生成代码,这些更改将会丢失。
|
||||||
|
// </自动生成>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace CitySunlight.Product {
|
||||||
|
|
||||||
|
|
||||||
|
public partial class ProductEdit {
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// productedit 控件。
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// 自动生成的字段。
|
||||||
|
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
|
||||||
|
/// </remarks>
|
||||||
|
protected global::System.Web.UI.HtmlControls.HtmlForm productedit;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// submit 控件。
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// 自动生成的字段。
|
||||||
|
/// 若要进行修改,请将字段声明从设计器文件移到代码隐藏文件。
|
||||||
|
/// </remarks>
|
||||||
|
protected global::System.Web.UI.WebControls.Button submit;
|
||||||
|
}
|
||||||
|
}
|
231
CitySunlight/Product/ProductManager.cs
Normal file
@ -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
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 根据信息查询产品
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="it">查询类型</param>
|
||||||
|
/// <param name="value">查询值</param>
|
||||||
|
/// <returns>查询到的数据表</returns>
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 估计产品信息查询产品
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="username">用户名</param>
|
||||||
|
/// <param name="itemname">产品名</param>
|
||||||
|
/// <param name="ClassId">产品类</param>
|
||||||
|
/// <param name="price">价格</param>
|
||||||
|
/// <param name="amount">库存</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 根据产品信息查询产品并分页
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="username">用户名</param>
|
||||||
|
/// <param name="itemname">产品名</param>
|
||||||
|
/// <param name="ClassId">产品类</param>
|
||||||
|
/// <param name="price">价格</param>
|
||||||
|
/// <param name="amount">库存</param>
|
||||||
|
/// <param name="Index">第几页</param>
|
||||||
|
/// <param name="Size">每页大小</param>
|
||||||
|
/// <returns>数据表</returns>
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 获得所有产品的数据表
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>DataTable 数据表</returns>
|
||||||
|
public static DataTable GetAllProduct()
|
||||||
|
{
|
||||||
|
return sql.ExecuteDataTable("select * from " + tbname, CommandType.Text);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 获取指定ID产品的数据行
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Id"></param>
|
||||||
|
/// <returns>DataRow 数据行</returns>
|
||||||
|
public static DataRow GetProductById(int Id)
|
||||||
|
{
|
||||||
|
return sql.ExecuteDataTable("select * from " + tbname + " where Id='" + Id + "'", CommandType.Text).Rows[0];
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 获取第几页,几个产品
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Index">第几页</param>
|
||||||
|
/// <param name="Size">每页大小</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 通过用户名获取用户所有产品信息(数据库部分)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="username"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static DataTable GetUserProduct(String username)
|
||||||
|
{
|
||||||
|
return sql.ExecuteDataTable("select * from " + tbname + " where UserName='" + username + "'", CommandType.Text);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 通过ID获取产品指定信息(数据库部分)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Id"></param>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
/// <returns>String 指定数据的字符串格式</returns>
|
||||||
|
public static String GetProductInfoById(int Id, String type)
|
||||||
|
{
|
||||||
|
return sql.ExecuteDataTable("select " + type + " from " + tbname + " where Id='" + Id + "'", CommandType.Text).Rows[0][0].ToString();
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 通过ID编辑产品信息(数据库部分)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Id"></param>
|
||||||
|
/// <param name="type"></param>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <returns>bool 是否成功</returns>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 添加产品信息(数据库部分)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="username"></param>
|
||||||
|
/// <param name="itemname"></param>
|
||||||
|
/// <param name="ClassId"></param>
|
||||||
|
/// <param name="picurl"></param>
|
||||||
|
/// <param name="price"></param>
|
||||||
|
/// <param name="amount"></param>
|
||||||
|
/// <returns>bool 是否成功</returns>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 更新产品信息(数据库部分)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="username"></param>
|
||||||
|
/// <param name="itemname"></param>
|
||||||
|
/// <param name="ClassId"></param>
|
||||||
|
/// <param name="picurl"></param>
|
||||||
|
/// <param name="price"></param>
|
||||||
|
/// <param name="amount"></param>
|
||||||
|
/// <returns>bool 是否成功</returns>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 删除产品信息(数据库部分)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <returns>bool 是否成功</returns>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 判断商品ID是否存在
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Id"></param>
|
||||||
|
/// <returns>bool 是否存在</returns>
|
||||||
|
public static bool isExist(int Id)
|
||||||
|
{
|
||||||
|
return sql.ExecuteDataTable("select * from " + tbname + " where Id='" + Id + "'", CommandType.Text).Rows.Count > 0;
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// DataRow转换成商品信息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="Product"></param>
|
||||||
|
/// <param name="it"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 通过商品ID创建产品展示连接
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id"></param>
|
||||||
|
/// <param name="name"></param>
|
||||||
|
/// <returns>String 商品链接</returns>
|
||||||
|
public static String NameToUrl(int id, String name)
|
||||||
|
{
|
||||||
|
return String.Format("<a href=\"/Product/ProductShow.aspx?id={0}\">{1}</a>", id, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
5
CitySunlight/Product/ProductShow.aspx
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<%@ Page Language="C#" MasterPageFile="~/Basic.Master" AutoEventWireup="true" CodeBehind="ProductShow.aspx.cs" Inherits="CitySunlight.Product.ProductShow" %>
|
||||||
|
|
||||||
|
<asp:Content ContentPlaceHolderID="body" runat="server" ID="body">
|
||||||
|
<%= ShowProduct() %>
|
||||||
|
</asp:Content>
|
63
CitySunlight/Product/ProductShow.aspx.cs
Normal file
@ -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 = "<span style=\"color:red\">当前ID的产品不存在或已被删除!</span>";
|
||||||
|
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("<img src=\"../Picture/{0}\"alt=\"\" width=\"256\" height=\"256\"/>", 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 = "<a href=\"/Product/ProductEdit.aspx?id=" + id + "&type=edit\" >编辑</a>";
|
||||||
|
String classname = ProductClassManager.getClassName(int.Parse(ProductManager.GetProductInfo(id, ProductManager.Info.Class)));
|
||||||
|
html += "<table align=\"center\">";
|
||||||
|
html += "<tr>";
|
||||||
|
html += HttpUtils.addTd(picurl, 3, 3);
|
||||||
|
html += HttpUtils.addTd(String.Format("名称: {0}", name));
|
||||||
|
html += user == username ? HttpUtils.addTd(edit) : "";
|
||||||
|
html += "<tr>";
|
||||||
|
html += HttpUtils.addTd(String.Format("分类: {0}", classname));
|
||||||
|
html += "</tr><tr>";
|
||||||
|
html += HttpUtils.addTd(String.Format("库存: {0}", amount));
|
||||||
|
html += "</tr><tr>";
|
||||||
|
html += HttpUtils.addTd();
|
||||||
|
html += HttpUtils.addTd(String.Format("价格: {0}", price));
|
||||||
|
html += HttpUtils.addTd();
|
||||||
|
html += HttpUtils.addTd("<a href=\"#\">购买</a>");
|
||||||
|
html += "</tr>";
|
||||||
|
html += "</table>";
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
15
CitySunlight/Product/ProductShow.aspx.designer.cs
generated
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <自动生成>
|
||||||
|
// 此代码由工具生成。
|
||||||
|
//
|
||||||
|
// 对此文件的更改可能会导致不正确的行为,并且如果
|
||||||
|
// 重新生成代码,这些更改将会丢失。
|
||||||
|
// </自动生成>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace CitySunlight.Product {
|
||||||
|
|
||||||
|
|
||||||
|
public partial class ProductShow {
|
||||||
|
}
|
||||||
|
}
|
35
CitySunlight/Properties/AssemblyInfo.cs
Normal file
@ -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")]
|
248
CitySunlight/SqlHelper.cs
Normal file
@ -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
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 数据库访问通用类
|
||||||
|
/// </summary>
|
||||||
|
public class SqlHelper
|
||||||
|
{
|
||||||
|
private string connectionString;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设定数据库访问字符串
|
||||||
|
/// </summary>
|
||||||
|
public string ConnectionString
|
||||||
|
{
|
||||||
|
|
||||||
|
set { connectionString = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 构造函数
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="connectionString">数据库访问字符串</param>
|
||||||
|
public SqlHelper(string connectionString)
|
||||||
|
{
|
||||||
|
this.connectionString = connectionString;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 执行一个查询,并返回查询结果
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sql">要执行的sql语句</param>
|
||||||
|
/// <param name="commandType">要执行的查询语句的类型,如存储过程或者sql文本命令</param>
|
||||||
|
/// <returns>返回查询结果集</returns>
|
||||||
|
public DataTable ExecuteDataTable(string sql, CommandType commandType)
|
||||||
|
{
|
||||||
|
return ExecuteDataTable(sql, commandType, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 执行一个查询,并返回结果集
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sql">要执行的sql文本命令</param>
|
||||||
|
/// <returns>返回查询的结果集</returns>
|
||||||
|
public DataTable ExecuteDataTable(string sql)
|
||||||
|
{
|
||||||
|
return ExecuteDataTable(sql, CommandType.Text, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 执行一个查询,并返回查询结果
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sql">要执行的sql语句</param>
|
||||||
|
/// <param name="commandtype">要执行查询语句的类型,如存储过程或者sql文本命令</param>
|
||||||
|
/// <param name="parameters">Transact-SQL语句或者存储过程参数数组</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 返回一个SqlDataReader对象的实例
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sql">要执行的SQl查询命令</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public SqlDataReader ExecuteReader(string sql)
|
||||||
|
{
|
||||||
|
return ExecuteReader(sql, CommandType.Text, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sql">要执行的sql语句</param>
|
||||||
|
/// <param name="commandType">要执行查询语句的类型,如存储过程或者SQl文本命令</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public SqlDataReader ExecuteReader(string sql, CommandType commandType)
|
||||||
|
{
|
||||||
|
return ExecuteReader(sql, commandType, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 返回一个sqldatareader对象的实例
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sql"></param>
|
||||||
|
/// <param name="commandType"></param>
|
||||||
|
/// <param name="parameters"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 执行一个查询,返回结果集的首行首列。忽略其他行,其他列
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sql">要执行的SQl命令</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Object ExecuteScalar(string sql)
|
||||||
|
{
|
||||||
|
return ExecuteScalar(sql, CommandType.Text, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sql"></param>
|
||||||
|
/// <param name="commandType"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public Object ExecuteScalar(string sql, CommandType commandType)
|
||||||
|
{
|
||||||
|
return ExecuteScalar(sql, commandType, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sql"></param>
|
||||||
|
/// <param name="commandType">参数类型</param>
|
||||||
|
/// <param name="parameters"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 对数据库进行增删改的操作
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sql">要执行的sql命令</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int ExecuteNonQuery(string sql)
|
||||||
|
{
|
||||||
|
return ExecuteNonQuery(sql, CommandType.Text, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 数据库进行增删改的操作
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sql">对数据库进行操作的sql命令</param>
|
||||||
|
/// <param name="commandType">要执行查询语句的类型,如存储过程或者sql文本命令</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public int ExecuteNonQuery(string sql, CommandType commandType)
|
||||||
|
{
|
||||||
|
return ExecuteNonQuery(sql, commandType, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 对数据库进行增删改的操作
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sql">要执行的sql语句</param>
|
||||||
|
/// <param name="commandType">要执行的查询语句类型,如存储过程或者sql文本命令</param>
|
||||||
|
/// <param name="parameters">Transact-SQL语句或者存储过程的参数数组</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 返回当前连接的数据库中所有用户创建的数据库
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public DataTable GetTables()
|
||||||
|
{
|
||||||
|
DataTable table = null;
|
||||||
|
using (SqlConnection con = new SqlConnection(connectionString))
|
||||||
|
{
|
||||||
|
con.Open();
|
||||||
|
table = con.GetSchema("Tables");
|
||||||
|
|
||||||
|
}
|
||||||
|
return table;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
109
CitySunlight/Utils.cs
Normal file
@ -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<ItemInfo> ToItemInfoList(this DataTable t, string pFieldValue, string pFieldText)
|
||||||
|
{
|
||||||
|
IList<ItemInfo> list = new List<ItemInfo>();
|
||||||
|
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<ItemInfo> pInfolist, string pControlName, string pEditValue, string pFirstValue, string pFirstText)
|
||||||
|
{
|
||||||
|
StringBuilder sbStr = new StringBuilder();
|
||||||
|
sbStr.Append("<select id=\"" + pControlName + "\" name=\"" + pControlName + "\">");
|
||||||
|
if (pFirstText.Length > 0)
|
||||||
|
{
|
||||||
|
sbStr.Append("<option value=\"");
|
||||||
|
sbStr.Append(pFirstValue);
|
||||||
|
sbStr.Append("\"");
|
||||||
|
|
||||||
|
if (pFirstValue == pEditValue)
|
||||||
|
{
|
||||||
|
sbStr.Append(" selected=\"selected\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
sbStr.Append(">");
|
||||||
|
|
||||||
|
sbStr.Append(pFirstText);
|
||||||
|
sbStr.Append("</option>");
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (ItemInfo info in pInfolist)
|
||||||
|
{
|
||||||
|
sbStr.Append("<option value=\"");
|
||||||
|
sbStr.Append(info.id);
|
||||||
|
sbStr.Append("\"");
|
||||||
|
if (pEditValue == info.id)
|
||||||
|
{
|
||||||
|
sbStr.Append(" selected=\"selected\"");
|
||||||
|
}
|
||||||
|
sbStr.Append(">");
|
||||||
|
sbStr.Append(info.name);
|
||||||
|
sbStr.Append("</option>");
|
||||||
|
}
|
||||||
|
sbStr.Append("<lect>");
|
||||||
|
return sbStr.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class ItemInfo
|
||||||
|
{
|
||||||
|
public string id;
|
||||||
|
public string name = string.Empty;
|
||||||
|
public string detail;
|
||||||
|
|
||||||
|
public ItemInfo() { }
|
||||||
|
public ItemInfo(string pId, string pName)
|
||||||
|
{
|
||||||
|
this.id = pId;
|
||||||
|
this.name = pName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemInfo(string pId, string pName, string pDetail)
|
||||||
|
{
|
||||||
|
this.id = pId;
|
||||||
|
this.name = pName;
|
||||||
|
this.detail = pDetail;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemInfo Create(string pName)
|
||||||
|
{
|
||||||
|
return new ItemInfo(pName, pName, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemInfo Create(string pId, string pName)
|
||||||
|
{
|
||||||
|
return new ItemInfo(pId, pName, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemInfo Create(string pId, string pName, string pDetail)
|
||||||
|
{
|
||||||
|
return new ItemInfo(pId, pName, pDetail);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
31
CitySunlight/Web.Debug.config
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<!-- 有关使用 web.config 转换的详细信息,请访问 http://go.microsoft.com/fwlink/?LinkId=125889 -->
|
||||||
|
|
||||||
|
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
|
||||||
|
<!--
|
||||||
|
在下例中,“SetAttributes”转换将更改
|
||||||
|
“connectionString”的值,以仅在“Match”定位器
|
||||||
|
找到值为“MyDB”的特性“name”时使用“ReleaseSQLServer”。
|
||||||
|
|
||||||
|
<connectionStrings>
|
||||||
|
<add name="MyDB"
|
||||||
|
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
|
||||||
|
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
|
||||||
|
</connectionStrings>
|
||||||
|
-->
|
||||||
|
<system.web>
|
||||||
|
<!--
|
||||||
|
|
||||||
|
在下例中,“Replace”转换将替换
|
||||||
|
web.config 文件的整个 <customErrors> 节。
|
||||||
|
请注意,由于
|
||||||
|
在 <system.web> 节点下仅有一个 customErrors 节,因此不需要使用“xdt:Locator”特性。
|
||||||
|
|
||||||
|
<customErrors defaultRedirect="GenericError.htm"
|
||||||
|
mode="RemoteOnly" xdt:Transform="Replace">
|
||||||
|
<error statusCode="500" redirect="InternalError.htm"/>
|
||||||
|
</customErrors>
|
||||||
|
-->
|
||||||
|
</system.web>
|
||||||
|
</configuration>
|
32
CitySunlight/Web.Release.config
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<!-- 有关使用 web.config 转换的详细信息,请访问 http://go.microsoft.com/fwlink/?LinkId=125889 -->
|
||||||
|
|
||||||
|
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
|
||||||
|
<!--
|
||||||
|
在下例中,“SetAttributes”转换将更改
|
||||||
|
“connectionString”的值,以仅在“Match”定位器
|
||||||
|
找到值为“MyDB”的特性“name”时使用“ReleaseSQLServer”。
|
||||||
|
|
||||||
|
<connectionStrings>
|
||||||
|
<add name="MyDB"
|
||||||
|
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
|
||||||
|
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
|
||||||
|
</connectionStrings>
|
||||||
|
-->
|
||||||
|
<system.web>
|
||||||
|
<compilation xdt:Transform="RemoveAttributes(debug)" />
|
||||||
|
<!--
|
||||||
|
|
||||||
|
在下例中,“Replace”转换将替换
|
||||||
|
web.config 文件的整个 <customErrors> 节。
|
||||||
|
请注意,由于
|
||||||
|
在 <system.web> 节点下仅有一个 customErrors 节,因此不需要使用“xdt:Locator”特性。
|
||||||
|
|
||||||
|
<customErrors defaultRedirect="GenericError.htm"
|
||||||
|
mode="RemoteOnly" xdt:Transform="Replace">
|
||||||
|
<error statusCode="500" redirect="InternalError.htm"/>
|
||||||
|
</customErrors>
|
||||||
|
-->
|
||||||
|
</system.web>
|
||||||
|
</configuration>
|
25
CitySunlight/Web.config
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
有关如何配置 ASP.NET 应用程序的详细信息,请访问
|
||||||
|
http://go.microsoft.com/fwlink/?LinkId=169433
|
||||||
|
-->
|
||||||
|
<configuration>
|
||||||
|
<configSections>
|
||||||
|
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
|
||||||
|
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
|
||||||
|
</configSections>
|
||||||
|
<system.web>
|
||||||
|
<compilation debug="true" targetFramework="4.5" />
|
||||||
|
<httpRuntime targetFramework="4.5" />
|
||||||
|
</system.web>
|
||||||
|
<entityFramework>
|
||||||
|
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
|
||||||
|
<parameters>
|
||||||
|
<parameter value="v11.0" />
|
||||||
|
</parameters>
|
||||||
|
</defaultConnectionFactory>
|
||||||
|
<providers>
|
||||||
|
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
|
||||||
|
</providers>
|
||||||
|
</entityFramework>
|
||||||
|
</configuration>
|
4
CitySunlight/packages.config
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<packages>
|
||||||
|
<package id="EntityFramework" version="6.1.3" targetFramework="net45" />
|
||||||
|
</packages>
|