Browse Source

上传文件至 'App.code/DAL'

master
童毓泽 3 years ago
parent
commit
6a1d6c506f
20 changed files with 6099 additions and 0 deletions
  1. +291
    -0
      App.code/DAL/about.cs
  2. +665
    -0
      App.code/DAL/address.cs
  3. +263
    -0
      App.code/DAL/albums.cs
  4. +282
    -0
      App.code/DAL/attribute.cs
  5. +300
    -0
      App.code/DAL/attribute_value.cs
  6. +258
    -0
      App.code/DAL/bed_class.cs
  7. +268
    -0
      App.code/DAL/bianliang.cs
  8. +291
    -0
      App.code/DAL/channel.cs
  9. +294
    -0
      App.code/DAL/comment.cs
  10. +295
    -0
      App.code/DAL/coupon.cs
  11. +259
    -0
      App.code/DAL/couponuser.cs
  12. +256
    -0
      App.code/DAL/databackup.cs
  13. +177
    -0
      App.code/DAL/followproduct.cs
  14. +373
    -0
      App.code/DAL/freight.cs
  15. +201
    -0
      App.code/DAL/link.cs
  16. +388
    -0
      App.code/DAL/manager.cs
  17. +225
    -0
      App.code/DAL/manager_log.cs
  18. +322
    -0
      App.code/DAL/manager_role.cs
  19. +384
    -0
      App.code/DAL/nav.cs
  20. +307
    -0
      App.code/DAL/news.cs

+ 291
- 0
App.code/DAL/about.cs View File

@ -0,0 +1,291 @@
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
namespace Basic.DAL
{
/// <summary>
/// 最终内容
/// </summary>
public partial class about
{
/// <summary>
/// 增加一条数据
/// </summary>
public int Add(Basic.Model.about model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into tb_about(");
strSql.Append("class_id,parent_id,guid,title,url,path,fujian,seo_title,seo_keywords,seo_description,content,paixu,hits,status,user_id,add_time)");
strSql.Append(" values (");
strSql.Append("@class_id,@parent_id,@guid,@title,@url,@path,@fujian,@seo_title,@seo_keywords,@seo_description,@content,@paixu,@hits,@status,@user_id,@add_time)");
strSql.Append(";select @@IDENTITY");
SqlParameter[] parameters = {
new SqlParameter("@class_id", SqlDbType.Int,10),
new SqlParameter("@parent_id", SqlDbType.Int,10),
new SqlParameter("@guid", SqlDbType.NVarChar,50),
new SqlParameter("@title", SqlDbType.NVarChar,100),
new SqlParameter("@url", SqlDbType.NVarChar,255),
new SqlParameter("@path", SqlDbType.NVarChar,255),
new SqlParameter("@fujian", SqlDbType.NVarChar,255),
new SqlParameter("@seo_title", SqlDbType.NVarChar,255),
new SqlParameter("@seo_keywords", SqlDbType.NVarChar,255),
new SqlParameter("@seo_description", SqlDbType.NVarChar,255),
new SqlParameter("@content", SqlDbType.NText,1073741823),
new SqlParameter("@paixu", SqlDbType.Int,10),
new SqlParameter("@hits", SqlDbType.Int,10),
new SqlParameter("@status", SqlDbType.Int,10),
new SqlParameter("@user_id", SqlDbType.Int,10),
new SqlParameter("@add_time", SqlDbType.DateTime,23)};
parameters[0].Value = model.class_id;
parameters[1].Value = model.parent_id;
parameters[2].Value = model.guid;
parameters[3].Value = model.title;
parameters[4].Value = model.url;
parameters[5].Value = model.path;
parameters[6].Value = model.fujian;
parameters[7].Value = model.seo_title;
parameters[8].Value = model.seo_keywords;
parameters[9].Value = model.seo_description;
parameters[10].Value = model.content;
parameters[11].Value = model.paixu;
parameters[12].Value = model.hits;
parameters[13].Value = model.status;
parameters[14].Value = model.user_id;
parameters[15].Value = model.add_time;
object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
if (obj == null)
{
return 0;
}
else
{
return Convert.ToInt32(obj);
}
}
/// <summary>
/// 更新一条数据
/// </summary>
public bool Update(Basic.Model.about model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update tb_about set ");
strSql.Append("class_id=@class_id,");
strSql.Append("parent_id=@parent_id,");
strSql.Append("guid=@guid,");
strSql.Append("title=@title,");
strSql.Append("url=@url,");
strSql.Append("path=@path,");
strSql.Append("fujian=@fujian,");
strSql.Append("seo_title=@seo_title,");
strSql.Append("seo_keywords=@seo_keywords,");
strSql.Append("seo_description=@seo_description,");
strSql.Append("content=@content,");
strSql.Append("paixu=@paixu,");
strSql.Append("hits=@hits,");
strSql.Append("status=@status,");
strSql.Append("user_id=@user_id,");
strSql.Append("add_time=@add_time");
strSql.Append(" where class_id=@class_id");
SqlParameter[] parameters = {
new SqlParameter("@class_id", SqlDbType.Int,10),
new SqlParameter("@parent_id", SqlDbType.Int,10),
new SqlParameter("@guid", SqlDbType.NVarChar,50),
new SqlParameter("@title", SqlDbType.NVarChar,100),
new SqlParameter("@url", SqlDbType.NVarChar,255),
new SqlParameter("@path", SqlDbType.NVarChar,255),
new SqlParameter("@fujian", SqlDbType.NVarChar,255),
new SqlParameter("@seo_title", SqlDbType.NVarChar,255),
new SqlParameter("@seo_keywords", SqlDbType.NVarChar,255),
new SqlParameter("@seo_description", SqlDbType.NVarChar,255),
new SqlParameter("@content", SqlDbType.NText,1073741823),
new SqlParameter("@paixu", SqlDbType.Int,10),
new SqlParameter("@hits", SqlDbType.Int,10),
new SqlParameter("@status", SqlDbType.Int,10),
new SqlParameter("@user_id", SqlDbType.Int,10),
new SqlParameter("@add_time", SqlDbType.DateTime,23),
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = model.class_id;
parameters[1].Value = model.parent_id;
parameters[2].Value = model.guid;
parameters[3].Value = model.title;
parameters[4].Value = model.url;
parameters[5].Value = model.path;
parameters[6].Value = model.fujian;
parameters[7].Value = model.seo_title;
parameters[8].Value = model.seo_keywords;
parameters[9].Value = model.seo_description;
parameters[10].Value = model.content;
parameters[11].Value = model.paixu;
parameters[12].Value = model.hits;
parameters[13].Value = model.status;
parameters[14].Value = model.user_id;
parameters[15].Value = model.add_time;
parameters[16].Value = model.id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 删除一条数据
/// </summary>
public bool Delete(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from tb_about");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public Basic.Model.about GetModel(int class_id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select top 1 id,class_id,parent_id,guid,title,url,path,fujian,seo_title,seo_keywords,seo_description,content,paixu,hits,status,user_id,add_time from tb_about");
strSql.Append(" where class_id=@class_id");
SqlParameter[] parameters = {
new SqlParameter("@class_id", SqlDbType.Int,4)};
parameters[0].Value = class_id;
Basic.Model.about model = new Basic.Model.about();
DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["id"].ToString()))
{
model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["class_id"].ToString()))
{
model.class_id = int.Parse(ds.Tables[0].Rows[0]["class_id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["parent_id"].ToString()))
{
model.parent_id = int.Parse(ds.Tables[0].Rows[0]["parent_id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["guid"].ToString()))
{
model.guid = ds.Tables[0].Rows[0]["guid"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["title"].ToString()))
{
model.title = ds.Tables[0].Rows[0]["title"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["url"].ToString()))
{
model.url = ds.Tables[0].Rows[0]["url"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["path"].ToString()))
{
model.path = ds.Tables[0].Rows[0]["path"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["fujian"].ToString()))
{
model.fujian = ds.Tables[0].Rows[0]["fujian"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["seo_title"].ToString()))
{
model.seo_title = ds.Tables[0].Rows[0]["seo_title"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["seo_keywords"].ToString()))
{
model.seo_keywords = ds.Tables[0].Rows[0]["seo_keywords"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["seo_description"].ToString()))
{
model.seo_description = ds.Tables[0].Rows[0]["seo_description"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["content"].ToString()))
{
model.content = ds.Tables[0].Rows[0]["content"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["paixu"].ToString()))
{
model.paixu = int.Parse(ds.Tables[0].Rows[0]["paixu"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["hits"].ToString()))
{
model.hits = int.Parse(ds.Tables[0].Rows[0]["hits"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["status"].ToString()))
{
model.status = int.Parse(ds.Tables[0].Rows[0]["status"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["user_id"].ToString()))
{
model.user_id = int.Parse(ds.Tables[0].Rows[0]["user_id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["add_time"].ToString()))
{
model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString());
}
return model;
}
else
{
return null;
}
}
/// <summary>
/// 获得前几行数据
/// </summary>
public DataSet GetList(int Top, string strWhere, string filedOrder)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select ");
if (Top > 0)
{
strSql.Append(" top " + Top.ToString());
}
strSql.Append("id,class_id,parent_id,guid,title,url,path,fujian,seo_title,seo_keywords,seo_description,content,paixu,hits,status,user_id,add_time");
strSql.Append(" from tb_about");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
strSql.Append(" order by " + filedOrder);
return DbHelperSQL.Query(strSql.ToString());
}
/// <summary>
/// 是否存在该记录
/// </summary>
public bool Exists(int class_id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(1) from tb_about");
strSql.Append(" where class_id=@class_id");
SqlParameter[] parameters = {
new SqlParameter("@class_id", SqlDbType.Int,4)};
parameters[0].Value = class_id;
return DbHelperSQL.Exists(strSql.ToString(), parameters);
}
}
}

+ 665
- 0
App.code/DAL/address.cs View File

@ -0,0 +1,665 @@
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
namespace Basic.DAL
{
/// <summary>
/// 数据访问层address
/// </summary>
public partial class address
{
/// <summary>
/// 增加一条数据
/// </summary>
public int Add(Basic.Model.address model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into tb_address(");
strSql.Append("user_id,name,sheng,shi,xian,ssx,xaddress,mobile,phone,email,status,dname,dxaddress,dmobile)");
strSql.Append(" values (");
strSql.Append("@user_id,@name,@sheng,@shi,@xian,@ssx,@xaddress,@mobile,@phone,@email,@status,@dname,@dxaddress,@dmobile)");
strSql.Append(";select @@IDENTITY");
SqlParameter[] parameters = {
new SqlParameter("@user_id", SqlDbType.Int,10),
new SqlParameter("@name", SqlDbType.NVarChar,50),
new SqlParameter("@sheng", SqlDbType.NVarChar,50),
new SqlParameter("@shi", SqlDbType.NVarChar,50),
new SqlParameter("@xian", SqlDbType.NVarChar,50),
new SqlParameter("@ssx", SqlDbType.NVarChar,255),
new SqlParameter("@xaddress", SqlDbType.NVarChar,255),
new SqlParameter("@mobile", SqlDbType.NVarChar,50),
new SqlParameter("@phone", SqlDbType.NVarChar,50),
new SqlParameter("@email", SqlDbType.NVarChar,100),
new SqlParameter("@status", SqlDbType.Int,10),
new SqlParameter("@dname", SqlDbType.NVarChar,50),
new SqlParameter("@dxaddress", SqlDbType.NVarChar,255),
new SqlParameter("@dmobile", SqlDbType.NVarChar,50)};
parameters[0].Value = model.user_id;
parameters[1].Value = model.name;
parameters[2].Value = model.sheng;
parameters[3].Value = model.shi;
parameters[4].Value = model.xian;
parameters[5].Value = model.ssx;
parameters[6].Value = model.xaddress;
parameters[7].Value = model.mobile;
parameters[8].Value = model.phone;
parameters[9].Value = model.email;
parameters[10].Value = model.status;
parameters[11].Value = model.dname;
parameters[12].Value = model.dxaddress;
parameters[13].Value = model.dmobile;
object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
if (obj == null)
{
return 0;
}
else
{
return Convert.ToInt32(obj);
}
}
/// <summary>
/// 更新一条数据
/// </summary>
public bool Update(Basic.Model.address model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update tb_address set ");
strSql.Append("user_id=@user_id,");
strSql.Append("name=@name,");
strSql.Append("sheng=@sheng,");
strSql.Append("shi=@shi,");
strSql.Append("xian=@xian,");
strSql.Append("ssx=@ssx,");
strSql.Append("xaddress=@xaddress,");
strSql.Append("mobile=@mobile,");
strSql.Append("phone=@phone,");
strSql.Append("email=@email,");
strSql.Append("status=@status,");
strSql.Append("dname=@dname,");
strSql.Append("dxaddress=@dxaddress,");
strSql.Append("dmobile=@dmobile");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@user_id", SqlDbType.Int,10),
new SqlParameter("@name", SqlDbType.NVarChar,50),
new SqlParameter("@sheng", SqlDbType.NVarChar,50),
new SqlParameter("@shi", SqlDbType.NVarChar,50),
new SqlParameter("@xian", SqlDbType.NVarChar,50),
new SqlParameter("@ssx", SqlDbType.NVarChar,255),
new SqlParameter("@xaddress", SqlDbType.NVarChar,255),
new SqlParameter("@mobile", SqlDbType.NVarChar,50),
new SqlParameter("@phone", SqlDbType.NVarChar,50),
new SqlParameter("@email", SqlDbType.NVarChar,100),
new SqlParameter("@status", SqlDbType.Int,10),
new SqlParameter("@dname", SqlDbType.NVarChar,50),
new SqlParameter("@dxaddress", SqlDbType.NVarChar,255),
new SqlParameter("@dmobile", SqlDbType.NVarChar,50),
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = model.user_id;
parameters[1].Value = model.name;
parameters[2].Value = model.sheng;
parameters[3].Value = model.shi;
parameters[4].Value = model.xian;
parameters[5].Value = model.ssx;
parameters[6].Value = model.xaddress;
parameters[7].Value = model.mobile;
parameters[8].Value = model.phone;
parameters[9].Value = model.email;
parameters[10].Value = model.status;
parameters[11].Value = model.dname;
parameters[12].Value = model.dxaddress;
parameters[13].Value = model.dmobile;
parameters[14].Value = model.id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 删除一条数据
/// </summary>
public bool Delete(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from tb_address");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public Basic.Model.address GetModel(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select top 1 id,user_id,name,sheng,shi,xian,ssx,xaddress,mobile,phone,email,status,dname,dxaddress,dmobile from tb_address");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
Basic.Model.address model = new Basic.Model.address();
DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["id"].ToString()))
{
model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["user_id"].ToString()))
{
model.user_id = int.Parse(ds.Tables[0].Rows[0]["user_id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["name"].ToString()))
{
model.name = ds.Tables[0].Rows[0]["name"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["sheng"].ToString()))
{
model.sheng = ds.Tables[0].Rows[0]["sheng"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["shi"].ToString()))
{
model.shi = ds.Tables[0].Rows[0]["shi"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["xian"].ToString()))
{
model.xian = ds.Tables[0].Rows[0]["xian"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["ssx"].ToString()))
{
model.ssx = ds.Tables[0].Rows[0]["ssx"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["xaddress"].ToString()))
{
model.xaddress = ds.Tables[0].Rows[0]["xaddress"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["mobile"].ToString()))
{
model.mobile = ds.Tables[0].Rows[0]["mobile"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["phone"].ToString()))
{
model.phone = ds.Tables[0].Rows[0]["phone"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["email"].ToString()))
{
model.email = ds.Tables[0].Rows[0]["email"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["status"].ToString()))
{
model.status = int.Parse(ds.Tables[0].Rows[0]["status"].ToString());
}
//订货人
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["dname"].ToString()))
{
model.dname = ds.Tables[0].Rows[0]["dname"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["dxaddress"].ToString()))
{
model.dxaddress = ds.Tables[0].Rows[0]["dxaddress"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["dmobile"].ToString()))
{
model.dmobile = ds.Tables[0].Rows[0]["dmobile"].ToString();
}
return model;
}
else
{
return null;
}
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public Basic.Model.address GetModel(string strUserName)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select top 1 id,user_id,name,sheng,shi,xian,ssx,xaddress,mobile,phone,email,status,dname,dxaddress,dmobile from tb_address");
strSql.Append(" where user_id=(select top 1 id from tb_user where name=@name) and status=1 order by id desc");
SqlParameter[] parameters = {
new SqlParameter("@name", SqlDbType.VarChar,50)};
parameters[0].Value = strUserName;
Basic.Model.address model = new Basic.Model.address();
DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["id"].ToString()))
{
model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["user_id"].ToString()))
{
model.user_id = int.Parse(ds.Tables[0].Rows[0]["user_id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["name"].ToString()))
{
model.name = ds.Tables[0].Rows[0]["name"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["sheng"].ToString()))
{
model.sheng = ds.Tables[0].Rows[0]["sheng"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["shi"].ToString()))
{
model.shi = ds.Tables[0].Rows[0]["shi"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["xian"].ToString()))
{
model.xian = ds.Tables[0].Rows[0]["xian"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["ssx"].ToString()))
{
model.ssx = ds.Tables[0].Rows[0]["ssx"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["xaddress"].ToString()))
{
model.xaddress = ds.Tables[0].Rows[0]["xaddress"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["mobile"].ToString()))
{
model.mobile = ds.Tables[0].Rows[0]["mobile"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["phone"].ToString()))
{
model.phone = ds.Tables[0].Rows[0]["phone"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["email"].ToString()))
{
model.email = ds.Tables[0].Rows[0]["email"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["status"].ToString()))
{
model.status = int.Parse(ds.Tables[0].Rows[0]["status"].ToString());
}
//订货人
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["dname"].ToString()))
{
model.dname = ds.Tables[0].Rows[0]["dname"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["dxaddress"].ToString()))
{
model.dxaddress = ds.Tables[0].Rows[0]["dxaddress"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["dmobile"].ToString()))
{
model.dmobile = ds.Tables[0].Rows[0]["dmobile"].ToString();
}
return model;
}
else
{
return null;
}
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public Basic.Model.address GetModelByUserId(int user_id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select top 1 id,user_id,name,sheng,shi,xian,ssx,xaddress,mobile,phone,email,status,dname,dxaddress,dmobile from tb_address");
strSql.Append(" where user_id=@user_id order by status desc,id desc");
SqlParameter[] parameters = {
new SqlParameter("@user_id", SqlDbType.Int,4)};
parameters[0].Value = user_id;
Basic.Model.address model = new Basic.Model.address();
DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["id"].ToString()))
{
model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["user_id"].ToString()))
{
model.user_id = int.Parse(ds.Tables[0].Rows[0]["user_id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["name"].ToString()))
{
model.name = ds.Tables[0].Rows[0]["name"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["sheng"].ToString()))
{
model.sheng = ds.Tables[0].Rows[0]["sheng"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["shi"].ToString()))
{
model.shi = ds.Tables[0].Rows[0]["shi"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["xian"].ToString()))
{
model.xian = ds.Tables[0].Rows[0]["xian"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["ssx"].ToString()))
{
model.ssx = ds.Tables[0].Rows[0]["ssx"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["xaddress"].ToString()))
{
model.xaddress = ds.Tables[0].Rows[0]["xaddress"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["mobile"].ToString()))
{
model.mobile = ds.Tables[0].Rows[0]["mobile"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["phone"].ToString()))
{
model.phone = ds.Tables[0].Rows[0]["phone"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["email"].ToString()))
{
model.email = ds.Tables[0].Rows[0]["email"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["status"].ToString()))
{
model.status = int.Parse(ds.Tables[0].Rows[0]["status"].ToString());
}
//订货人
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["dname"].ToString()))
{
model.dname = ds.Tables[0].Rows[0]["dname"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["dxaddress"].ToString()))
{
model.dxaddress = ds.Tables[0].Rows[0]["dxaddress"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["dmobile"].ToString()))
{
model.dmobile = ds.Tables[0].Rows[0]["dmobile"].ToString();
}
return model;
}
else
{
return null;
}
}
/// <summary>
/// 获得前几行数据
/// </summary>
public DataSet GetList(int Top, string strWhere, string filedOrder)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select ");
if (Top > 0)
{
strSql.Append(" top " + Top.ToString());
}
strSql.Append("id,user_id,name,sheng,shi,xian,ssx,xaddress,mobile,phone,email,status,dname,dxaddress,dmobile");
strSql.Append(" from tb_address");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
strSql.Append(" order by " + filedOrder);
return DbHelperSQL.Query(strSql.ToString());
}
/// <summary>
/// 是否存在该记录
/// </summary>
public bool Exists(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(1) from tb_address");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
return DbHelperSQL.Exists(strSql.ToString(), parameters);
}
/// <summary>
/// 修改一列数据
/// </summary>
public void UpdateField(int id, string strValue)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update tb_address set " + strValue);
strSql.Append(" where id=" + id);
DbHelperSQL.ExecuteSql(strSql.ToString());
}
//后添加的======================================================================================================================================
/// <summary>
/// 修改默认地址
/// </summary>
public void UpdateStatus(int id, int _UserID)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update tb_address set status=0");
strSql.Append(" where user_id=" + _UserID);
strSql.Append(" update tb_address set status=1");
strSql.Append(" where id=" + id);
DbHelperSQL.ExecuteSql(strSql.ToString());
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public Basic.Model.address GetModel(int id, int user_id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select top 1 id,user_id,name,sheng,shi,xian,ssx,xaddress,mobile,phone,email,status,dname,dxaddress,dmobile from tb_address");
strSql.Append(" where id=@id and user_id=@user_id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4),
new SqlParameter("@user_id", SqlDbType.Int,4)};
parameters[0].Value = id;
parameters[1].Value = user_id;
Basic.Model.address model = new Basic.Model.address();
DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["id"].ToString()))
{
model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["user_id"].ToString()))
{
model.user_id = int.Parse(ds.Tables[0].Rows[0]["user_id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["name"].ToString()))
{
model.name = ds.Tables[0].Rows[0]["name"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["sheng"].ToString()))
{
model.sheng = ds.Tables[0].Rows[0]["sheng"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["shi"].ToString()))
{
model.shi = ds.Tables[0].Rows[0]["shi"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["xian"].ToString()))
{
model.xian = ds.Tables[0].Rows[0]["xian"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["ssx"].ToString()))
{
model.ssx = ds.Tables[0].Rows[0]["ssx"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["xaddress"].ToString()))
{
model.xaddress = ds.Tables[0].Rows[0]["xaddress"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["mobile"].ToString()))
{
model.mobile = ds.Tables[0].Rows[0]["mobile"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["phone"].ToString()))
{
model.phone = ds.Tables[0].Rows[0]["phone"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["email"].ToString()))
{
model.email = ds.Tables[0].Rows[0]["email"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["status"].ToString()))
{
model.status = int.Parse(ds.Tables[0].Rows[0]["status"].ToString());
}
//订货人
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["dname"].ToString()))
{
model.dname = ds.Tables[0].Rows[0]["dname"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["dxaddress"].ToString()))
{
model.dxaddress = ds.Tables[0].Rows[0]["dxaddress"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["dmobile"].ToString()))
{
model.dmobile = ds.Tables[0].Rows[0]["dmobile"].ToString();
}
return model;
}
else
{
return null;
}
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public Basic.Model.address GetModel(int user_id, string status)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select top 1 id,user_id,name,sheng,shi,xian,ssx,xaddress,mobile,phone,email,status,dname,dxaddress,dmobile from tb_address");
strSql.Append(" where status=@status and user_id=@user_id");
SqlParameter[] parameters = {
new SqlParameter("@status", SqlDbType.Int,4),
new SqlParameter("@user_id", SqlDbType.Int,4)};
parameters[0].Value = status;
parameters[1].Value = user_id;
Basic.Model.address model = new Basic.Model.address();
DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["id"].ToString()))
{
model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["user_id"].ToString()))
{
model.user_id = int.Parse(ds.Tables[0].Rows[0]["user_id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["name"].ToString()))
{
model.name = ds.Tables[0].Rows[0]["name"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["sheng"].ToString()))
{
model.sheng = ds.Tables[0].Rows[0]["sheng"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["shi"].ToString()))
{
model.shi = ds.Tables[0].Rows[0]["shi"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["xian"].ToString()))
{
model.xian = ds.Tables[0].Rows[0]["xian"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["ssx"].ToString()))
{
model.ssx = ds.Tables[0].Rows[0]["ssx"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["xaddress"].ToString()))
{
model.xaddress = ds.Tables[0].Rows[0]["xaddress"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["mobile"].ToString()))
{
model.mobile = ds.Tables[0].Rows[0]["mobile"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["phone"].ToString()))
{
model.phone = ds.Tables[0].Rows[0]["phone"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["email"].ToString()))
{
model.email = ds.Tables[0].Rows[0]["email"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["status"].ToString()))
{
model.status = int.Parse(ds.Tables[0].Rows[0]["status"].ToString());
}
//订货人
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["dname"].ToString()))
{
model.dname = ds.Tables[0].Rows[0]["dname"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["dxaddress"].ToString()))
{
model.dxaddress = ds.Tables[0].Rows[0]["dxaddress"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["dmobile"].ToString()))
{
model.dmobile = ds.Tables[0].Rows[0]["dmobile"].ToString();
}
return model;
}
else
{
return null;
}
}
/// <summary>
/// 删除一条数据
/// </summary>
public bool Delete(int id, int user_id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from tb_address");
strSql.Append(" where id=@id and user_id=@user_id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4),
new SqlParameter("@user_id", SqlDbType.Int,4)};
parameters[0].Value = id;
parameters[1].Value = user_id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
}
}

+ 263
- 0
App.code/DAL/albums.cs View File

@ -0,0 +1,263 @@
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using System.Collections.Generic;
namespace Basic.DAL
{
/// <summary>
/// 相册
/// </summary>
public partial class albums
{
/// <summary>
/// 增加一条数据
/// </summary>
public int Add(Basic.Model.albums model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into tb_albums(");
strSql.Append("paixu,guid,big_img,small_img,remark)");
strSql.Append(" values (");
strSql.Append("@paixu,@guid,@big_img,@small_img,@remark)");
strSql.Append(";select @@IDENTITY");
SqlParameter[] parameters = {
new SqlParameter("@paixu", SqlDbType.Int,10),
new SqlParameter("@guid", SqlDbType.NVarChar,50),
new SqlParameter("@big_img", SqlDbType.NVarChar,255),
new SqlParameter("@small_img", SqlDbType.NVarChar,255),
new SqlParameter("@remark", SqlDbType.NVarChar,500)};
parameters[0].Value = model.paixu;
parameters[1].Value = model.guid;
parameters[2].Value = model.big_img;
parameters[3].Value = model.small_img;
parameters[4].Value = model.remark;
object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
if (obj == null)
{
return 0;
}
else
{
return Convert.ToInt32(obj);
}
}
/// <summary>
/// 更新一条数据
/// </summary>
public bool Update(Basic.Model.albums model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update tb_albums set ");
strSql.Append("paixu=@paixu,");
strSql.Append("guid=@guid,");
strSql.Append("big_img=@big_img,");
strSql.Append("small_img=@small_img,");
strSql.Append("remark=@remark");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@paixu", SqlDbType.Int,10),
new SqlParameter("@guid", SqlDbType.NVarChar,50),
new SqlParameter("@big_img", SqlDbType.NVarChar,255),
new SqlParameter("@small_img", SqlDbType.NVarChar,255),
new SqlParameter("@remark", SqlDbType.NVarChar,500),
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = model.paixu;
parameters[1].Value = model.guid;
parameters[2].Value = model.big_img;
parameters[3].Value = model.small_img;
parameters[4].Value = model.remark;
parameters[5].Value = model.id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 删除一条数据
/// </summary>
public bool Delete(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from tb_albums");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public Basic.Model.albums GetModel(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select top 1 id,paixu,guid,big_img,small_img,remark from tb_albums");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
Basic.Model.albums model = new Basic.Model.albums();
DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["id"].ToString()))
{
model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["paixu"].ToString()))
{
model.paixu = int.Parse(ds.Tables[0].Rows[0]["paixu"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["guid"].ToString()))
{
model.guid = ds.Tables[0].Rows[0]["guid"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["big_img"].ToString()))
{
model.big_img = ds.Tables[0].Rows[0]["big_img"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["small_img"].ToString()))
{
model.small_img = ds.Tables[0].Rows[0]["small_img"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["remark"].ToString()))
{
model.remark = ds.Tables[0].Rows[0]["remark"].ToString();
}
return model;
}
else
{
return null;
}
}
/// <summary>
/// 获得数据列表
/// </summary>
public List<Basic.Model.albums> GetList(string _guid)
{
List<Basic.Model.albums> modelList = new List<Basic.Model.albums>();
StringBuilder strSql = new StringBuilder();
strSql.Append("select * ");
strSql.Append(" from tb_albums ");
strSql.Append(" where guid='" + _guid + "'");
DataTable dt = DbHelperSQL.Query(strSql.ToString()).Tables[0];
int rowsCount = dt.Rows.Count;
if (rowsCount > 0)
{
Basic.Model.albums model;
for (int n = 0; n < rowsCount; n++)
{
model = new Basic.Model.albums();
if (dt.Rows[n]["id"] != null && dt.Rows[n]["id"].ToString() != "")
{
model.id = int.Parse(dt.Rows[n]["id"].ToString());
}
if (dt.Rows[n]["paixu"] != null && dt.Rows[n]["paixu"].ToString() != "")
{
model.paixu = int.Parse(dt.Rows[n]["paixu"].ToString());
}
if (dt.Rows[n]["guid"] != null && dt.Rows[n]["guid"].ToString() != "")
{
model.guid = dt.Rows[n]["guid"].ToString();
}
if (dt.Rows[n]["big_img"] != null && dt.Rows[n]["big_img"].ToString() != "")
{
model.big_img = dt.Rows[n]["big_img"].ToString();
}
if (dt.Rows[n]["small_img"] != null && dt.Rows[n]["small_img"].ToString() != "")
{
model.small_img = dt.Rows[n]["small_img"].ToString();
}
if (dt.Rows[n]["remark"] != null && dt.Rows[n]["remark"].ToString() != "")
{
model.remark = dt.Rows[n]["remark"].ToString();
}
modelList.Add(model);
}
}
return modelList;
}
/// <summary>
/// 查找不存在的图片并删除已删除的图片及数据
/// </summary>
public void DeleteList(List<Basic.Model.albums> models, string _guid)
{
StringBuilder idList = new StringBuilder();
if (models != null)
{
foreach (Basic.Model.albums modelt in models)
{
if (modelt.id > 0)
{
idList.Append(modelt.id + ",");
}
}
}
string id_list = Basic.Tools.Utils.DelLastChar(idList.ToString(), ",");
StringBuilder strSql = new StringBuilder();
strSql.Append("select id,big_img,small_img from tb_albums where guid='" + _guid + "'");
if (!string.IsNullOrEmpty(id_list))
{
strSql.Append(" and id not in(" + id_list + ")");
}
Basic.BasicPage bp = new BasicPage();
DataSet ds = bp.SelectDataBase("tb_albums", strSql.ToString());
foreach (DataRow dr in ds.Tables[0].Rows)
{
bool result = Delete(int.Parse(dr["id"].ToString()));//删除数据
if (result)
{
Basic.Tools.Utils.DeleteFile("../.." + dr["big_img"].ToString()); //删除原图
Basic.Tools.Utils.DeleteFile("../.." + dr["small_img"].ToString()); //删除缩略图
}
}
}
/// <summary>
/// 删除数据和图片
/// </summary>
public void Delete(string _guid)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select id,big_img,small_img from tb_albums where guid='" + _guid + "'");
Basic.BasicPage bp = new BasicPage();
DataSet ds = bp.SelectDataBase("tb_albums", strSql.ToString());
foreach (DataRow dr in ds.Tables[0].Rows)
{
bool result = Delete(int.Parse(dr["id"].ToString()));//删除数据
if (result)
{
Basic.Tools.Utils.DeleteFile("../../" + dr["big_img"].ToString()); //删除原图
Basic.Tools.Utils.DeleteFile("../../" + dr["small_img"].ToString()); //删除缩略图
}
}
}
}
}

+ 282
- 0
App.code/DAL/attribute.cs View File

@ -0,0 +1,282 @@
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
namespace Basic.DAL
{
/// <summary>
/// 属性列别
/// </summary>
public partial class attribute
{
/// <summary>
/// 增加一条数据
/// </summary>
public int Add(Basic.Model.attribute model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into tb_attribute(");
strSql.Append("class_id,title,guid,parent_id,class_list,class_layer,paixu,url,path,content)");
strSql.Append(" values (");
strSql.Append("@class_id,@title,@guid,@parent_id,@class_list,@class_layer,@paixu,@url,@path,@content)");
strSql.Append(";select @@IDENTITY");
SqlParameter[] parameters = {
new SqlParameter("@class_id", SqlDbType.Int,10),
new SqlParameter("@title", SqlDbType.NVarChar,100),
new SqlParameter("@guid", SqlDbType.NVarChar,50),
new SqlParameter("@parent_id", SqlDbType.Int,10),
new SqlParameter("@class_list", SqlDbType.NVarChar,500),
new SqlParameter("@class_layer", SqlDbType.Int,10),
new SqlParameter("@paixu", SqlDbType.Int,10),
new SqlParameter("@url", SqlDbType.NVarChar,255),
new SqlParameter("@path", SqlDbType.NVarChar,255),
new SqlParameter("@content", SqlDbType.NVarChar,500)};
parameters[0].Value = model.class_id;
parameters[1].Value = model.title;
parameters[2].Value = model.guid;
parameters[3].Value = model.parent_id;
parameters[4].Value = model.class_list;
parameters[5].Value = model.class_layer;
parameters[6].Value = model.paixu;
parameters[7].Value = model.url;
parameters[8].Value = model.path;
parameters[9].Value = model.content;
object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
if (obj == null)
{
return 0;
}
else
{
return Convert.ToInt32(obj);
}
}
/// <summary>
/// 更新一条数据
/// </summary>
public bool Update(Basic.Model.attribute model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update tb_attribute set ");
strSql.Append("class_id=@class_id,");
strSql.Append("title=@title,");
strSql.Append("guid=@guid,");
strSql.Append("parent_id=@parent_id,");
strSql.Append("class_list=@class_list,");
strSql.Append("class_layer=@class_layer,");
strSql.Append("paixu=@paixu,");
strSql.Append("url=@url,");
strSql.Append("path=@path,");
strSql.Append("content=@content");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@class_id", SqlDbType.Int,10),
new SqlParameter("@title", SqlDbType.NVarChar,100),
new SqlParameter("@guid", SqlDbType.NVarChar,50),
new SqlParameter("@parent_id", SqlDbType.Int,10),
new SqlParameter("@class_list", SqlDbType.NVarChar,500),
new SqlParameter("@class_layer", SqlDbType.Int,10),
new SqlParameter("@paixu", SqlDbType.Int,10),
new SqlParameter("@url", SqlDbType.NVarChar,255),
new SqlParameter("@path", SqlDbType.NVarChar,255),
new SqlParameter("@content", SqlDbType.NVarChar,500),
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = model.class_id;
parameters[1].Value = model.title;
parameters[2].Value = model.guid;
parameters[3].Value = model.parent_id;
parameters[4].Value = model.class_list;
parameters[5].Value = model.class_layer;
parameters[6].Value = model.paixu;
parameters[7].Value = model.url;
parameters[8].Value = model.path;
parameters[9].Value = model.content;
parameters[10].Value = model.id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 删除一条数据
/// </summary>
public bool Delete(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from tb_attribute");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public Basic.Model.attribute GetModel(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select top 1 id,class_id,title,guid,parent_id,class_list,class_layer,paixu,url,path,content from tb_attribute");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
Basic.Model.attribute model = new Basic.Model.attribute();
DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["id"].ToString()))
{
model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["class_id"].ToString()))
{
model.class_id = int.Parse(ds.Tables[0].Rows[0]["class_id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["title"].ToString()))
{
model.title = ds.Tables[0].Rows[0]["title"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["guid"].ToString()))
{
model.guid = ds.Tables[0].Rows[0]["guid"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["parent_id"].ToString()))
{
model.parent_id = int.Parse(ds.Tables[0].Rows[0]["parent_id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["class_list"].ToString()))
{
model.class_list = ds.Tables[0].Rows[0]["class_list"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["class_layer"].ToString()))
{
model.class_layer = int.Parse(ds.Tables[0].Rows[0]["class_layer"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["paixu"].ToString()))
{
model.paixu = int.Parse(ds.Tables[0].Rows[0]["paixu"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["url"].ToString()))
{
model.url = ds.Tables[0].Rows[0]["url"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["path"].ToString()))
{
model.path = ds.Tables[0].Rows[0]["path"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["content"].ToString()))
{
model.content = ds.Tables[0].Rows[0]["content"].ToString();
}
return model;
}
else
{
return null;
}
}
/// <summary>
/// 取得所有类别列表
/// </summary>
/// <param name="parent_id">父ID</param>
/// <param name="class_id">分类ID</param>
/// <returns></returns>
public DataTable GetList(int parent_id, int class_id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select * from tb_attribute");
strSql.Append(" where class_id=" + class_id + " order by paixu desc,id asc");
DataSet ds = DbHelperSQL.Query(strSql.ToString());
DataTable oldData = ds.Tables[0] as DataTable;
if (oldData == null)
{
return null;
}
//复制结构
DataTable newData = oldData.Clone();
//调用迭代组合成DAGATABLE
GetChilds(oldData, newData, parent_id, class_id);
return newData;
}
/// <summary>
/// 从内存中取得所有下级类别列表(自身迭代)
/// </summary>
private void GetChilds(DataTable oldData, DataTable newData, int parent_id, int pro_class_id)
{
DataRow[] dr = oldData.Select("parent_id=" + parent_id);
for (int i = 0; i < dr.Length; i++)
{
//添加一行数据
DataRow row = newData.NewRow();
row["id"] = int.Parse(dr[i]["id"].ToString());
row["class_id"] = int.Parse(dr[i]["class_id"].ToString());
row["title"] = dr[i]["title"].ToString();
row["guid"] = dr[i]["guid"].ToString();
row["parent_id"] = int.Parse(dr[i]["parent_id"].ToString());
row["class_list"] = dr[i]["class_list"].ToString();
row["class_layer"] = int.Parse(dr[i]["class_layer"].ToString());
row["paixu"] = int.Parse(dr[i]["paixu"].ToString());
row["url"] = dr[i]["url"].ToString();
row["path"] = dr[i]["path"].ToString();
row["content"] = dr[i]["content"].ToString();
newData.Rows.Add(row);
//调用自身迭代
this.GetChilds(oldData, newData, int.Parse(dr[i]["id"].ToString()), pro_class_id);
}
}
/// <summary>
/// 修改一列数据
/// </summary>
public void UpdateField(int id, string strValue)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update tb_attribute set " + strValue);
strSql.Append(" where id=" + id);
DbHelperSQL.ExecuteSql(strSql.ToString());
}
/// <summary>
/// 获得前几行数据
/// </summary>
public DataSet GetList(int Top, string strWhere, string filedOrder)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select ");
if (Top > 0)
{
strSql.Append(" top " + Top.ToString());
}
strSql.Append("id,class_id,title,guid,parent_id,class_list,class_layer,paixu,url,path,content");
strSql.Append(" from tb_attribute");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
strSql.Append(" order by " + filedOrder);
return DbHelperSQL.Query(strSql.ToString());
}
}
}

+ 300
- 0
App.code/DAL/attribute_value.cs View File

@ -0,0 +1,300 @@
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
namespace Basic.DAL
{
/// <summary>
/// 属性值
/// </summary>
public partial class attribute_value
{
/// <summary>
/// 增加一条数据
/// </summary>
public int Add(Basic.Model.attribute_value model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into tb_attribute_value(");
strSql.Append("class_id,parent_id,guid,title,path,content,paixu,status)");
strSql.Append(" values (");
strSql.Append("@class_id,@parent_id,@guid,@title,@path,@content,@paixu,@status)");
strSql.Append(";select @@IDENTITY");
SqlParameter[] parameters = {
new SqlParameter("@class_id", SqlDbType.Int,10),
new SqlParameter("@parent_id", SqlDbType.Int,10),
new SqlParameter("@guid", SqlDbType.NVarChar,50),
new SqlParameter("@title", SqlDbType.NVarChar,100),
new SqlParameter("@path", SqlDbType.NVarChar,255),
new SqlParameter("@content", SqlDbType.NVarChar,255),
new SqlParameter("@paixu", SqlDbType.Int,10),
new SqlParameter("@status", SqlDbType.Int,10)};
parameters[0].Value = model.class_id;
parameters[1].Value = model.parent_id;
parameters[2].Value = model.guid;
parameters[3].Value = model.title;
parameters[4].Value = model.path;
parameters[5].Value = model.content;
parameters[6].Value = model.paixu;
parameters[7].Value = model.status;
object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
if (obj == null)
{
return 0;
}
else
{
return Convert.ToInt32(obj);
}
}
/// <summary>
/// 更新一条数据
/// </summary>
public bool Update(Basic.Model.attribute_value model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update tb_attribute_value set ");
strSql.Append("class_id=@class_id,");
strSql.Append("parent_id=@parent_id,");
strSql.Append("guid=@guid,");
strSql.Append("title=@title,");
strSql.Append("path=@path,");
strSql.Append("content=@content,");
strSql.Append("paixu=@paixu,");
strSql.Append("status=@status");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@class_id", SqlDbType.Int,10),
new SqlParameter("@parent_id", SqlDbType.Int,10),
new SqlParameter("@guid", SqlDbType.NVarChar,50),
new SqlParameter("@title", SqlDbType.NVarChar,100),
new SqlParameter("@path", SqlDbType.NVarChar,255),
new SqlParameter("@content", SqlDbType.NVarChar,255),
new SqlParameter("@paixu", SqlDbType.Int,10),
new SqlParameter("@status", SqlDbType.Int,10),
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = model.class_id;
parameters[1].Value = model.parent_id;
parameters[2].Value = model.guid;
parameters[3].Value = model.title;
parameters[4].Value = model.path;
parameters[5].Value = model.content;
parameters[6].Value = model.paixu;
parameters[7].Value = model.status;
parameters[8].Value = model.id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 删除一条数据
/// </summary>
public bool Delete(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from tb_attribute_value");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 删除一条数据
/// </summary>
public bool DeleteByClassId(int class_id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from tb_attribute_value");
strSql.Append(" where class_id=@class_id");
SqlParameter[] parameters = {
new SqlParameter("@class_id", SqlDbType.Int,4)};
parameters[0].Value = class_id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public Basic.Model.attribute_value GetModel(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select top 1 id,class_id,parent_id,guid,title,path,content,paixu,status from tb_attribute_value");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
Basic.Model.attribute_value model = new Basic.Model.attribute_value();
DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["id"].ToString()))
{
model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["class_id"].ToString()))
{
model.class_id = int.Parse(ds.Tables[0].Rows[0]["class_id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["parent_id"].ToString()))
{
model.parent_id = int.Parse(ds.Tables[0].Rows[0]["parent_id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["guid"].ToString()))
{
model.guid = ds.Tables[0].Rows[0]["guid"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["title"].ToString()))
{
model.title = ds.Tables[0].Rows[0]["title"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["path"].ToString()))
{
model.path = ds.Tables[0].Rows[0]["path"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["content"].ToString()))
{
model.content = ds.Tables[0].Rows[0]["content"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["paixu"].ToString()))
{
model.paixu = int.Parse(ds.Tables[0].Rows[0]["paixu"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["status"].ToString()))
{
model.status = int.Parse(ds.Tables[0].Rows[0]["status"].ToString());
}
return model;
}
else
{
return null;
}
}
/// <summary>
/// 是否存在该记录
/// </summary>
public bool Exists(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(1) from tb_attribute_value");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
return DbHelperSQL.Exists(strSql.ToString(), parameters);
}
/// <summary>
/// 获得查询分页数据
/// </summary>
public DataSet GetList(string _strWhere, string _orderby, int _pageSize, int _page, out int recordCount)
{
BasicPage bp = new BasicPage();
StringBuilder str_Sql = new StringBuilder();
str_Sql.Append("select top " + _pageSize + " * from tb_attribute_value");
str_Sql.Append(" where ");
str_Sql.Append(_strWhere);
str_Sql.Append(" and id not in ");
str_Sql.Append(" ( ");
str_Sql.Append(" select top " + (_page - 1) * _pageSize + " id from tb_attribute_value ");
str_Sql.Append(" where ");
str_Sql.Append(_strWhere);
str_Sql.Append(" order by ");
str_Sql.Append(_orderby);
str_Sql.Append(" ) ");
str_Sql.Append(" order by ");
str_Sql.Append(_orderby);
DataSet dst = bp.SelectDataBase("tb_attribute_value", str_Sql.ToString());
//
recordCount = totlePage(showTotal(_strWhere), _pageSize);
return dst;
}
//总页数
public int totlePage(int Total, int PageSize)
{
if (Total % PageSize == 0)
{
return Total / PageSize;
}
else
{
return Total / PageSize + 1;
}
}
//总条数
protected int showTotal(string strSql)
{
BasicPage bp = new BasicPage();
int intTotal = 0;
SqlDataReader myread = bp.getRead("select count(id) as CountId from tb_attribute_value where " + strSql);
if (myread.Read())
{
intTotal = Convert.ToInt32(myread["CountId"].ToString());
}
myread.Close();
return intTotal;
}
/// <summary>
/// 修改一列数据
/// </summary>
public void UpdateField(int id, string strValue)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update tb_attribute_value set " + strValue);
strSql.Append(" where id=" + id);
DbHelperSQL.ExecuteSql(strSql.ToString());
}
/// <summary>
/// 获得前几行数据
/// </summary>
public DataSet GetList(int Top, string strWhere, string filedOrder)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select ");
if (Top > 0)
{
strSql.Append(" top " + Top.ToString());
}
strSql.Append("id,class_id,parent_id,guid,title,path,content,paixu,status");
strSql.Append(" from tb_attribute_value");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
strSql.Append(" order by " + filedOrder);
return DbHelperSQL.Query(strSql.ToString());
}
}
}

+ 258
- 0
App.code/DAL/bed_class.cs View File

@ -0,0 +1,258 @@
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
namespace Basic.DAL
{
/// <summary>
/// 数据访问层bed_class
/// </summary>
public partial class bed_class
{
#region 原始的
/// <summary>
/// 增加一条数据
/// </summary>
public int Add(Basic.Model.bed_class model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into tb_bed_class(");
strSql.Append("paixu,title,state,yongliao,gongfei)");
strSql.Append(" values (");
strSql.Append("@paixu,@title,@state,@yongliao,@gongfei)");
strSql.Append(";select @@IDENTITY");
SqlParameter[] parameters = {
new SqlParameter("@paixu", SqlDbType.Int,10),
new SqlParameter("@title", SqlDbType.NVarChar,255),
new SqlParameter("@state", SqlDbType.Int,10),
new SqlParameter("@yongliao", SqlDbType.Decimal,18),
new SqlParameter("@gongfei", SqlDbType.Decimal,18)};
parameters[0].Value = model.paixu;
parameters[1].Value = model.title;
parameters[2].Value = model.state;
parameters[3].Value = model.yongliao;
parameters[4].Value = model.gongfei;
object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
if (obj == null)
{
return 0;
}
else
{
return Convert.ToInt32(obj);
}
}
/// <summary>
/// 更新一条数据
/// </summary>
public bool Update(Basic.Model.bed_class model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update tb_bed_class set ");
strSql.Append("paixu=@paixu,");
strSql.Append("title=@title,");
strSql.Append("state=@state,");
strSql.Append("yongliao=@yongliao,");
strSql.Append("gongfei=@gongfei");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@paixu", SqlDbType.Int,10),
new SqlParameter("@title", SqlDbType.NVarChar,255),
new SqlParameter("@state", SqlDbType.Int,10),
new SqlParameter("@yongliao", SqlDbType.Decimal,18),
new SqlParameter("@gongfei", SqlDbType.Decimal,18),
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = model.paixu;
parameters[1].Value = model.title;
parameters[2].Value = model.state;
parameters[3].Value = model.yongliao;
parameters[4].Value = model.gongfei;
parameters[5].Value = model.id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 删除一条数据
/// </summary>
public bool Delete(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from tb_bed_class");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public Basic.Model.bed_class GetModel(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select top 1 id,paixu,title,state,yongliao,gongfei from tb_bed_class");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
Basic.Model.bed_class model = new Basic.Model.bed_class();
DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["id"].ToString()))
{
model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["paixu"].ToString()))
{
model.paixu = int.Parse(ds.Tables[0].Rows[0]["paixu"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["title"].ToString()))
{
model.title = ds.Tables[0].Rows[0]["title"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["state"].ToString()))
{
model.state = int.Parse(ds.Tables[0].Rows[0]["state"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["yongliao"].ToString()))
{
model.yongliao = decimal.Parse(ds.Tables[0].Rows[0]["yongliao"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["gongfei"].ToString()))
{
model.gongfei = decimal.Parse(ds.Tables[0].Rows[0]["gongfei"].ToString());
}
return model;
}
else
{
return null;
}
}
/// <summary>
/// 获得前几行数据
/// </summary>
public DataSet GetList(int Top, string strWhere, string filedOrder)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select ");
if (Top > 0)
{
strSql.Append(" top " + Top.ToString());
}
strSql.Append("id,paixu,title,state,yongliao,gongfei");
strSql.Append(" from tb_bed_class");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
strSql.Append(" order by " + filedOrder);
return DbHelperSQL.Query(strSql.ToString());
}
/// <summary>
/// 是否存在该记录
/// </summary>
public bool Exists(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(1) from tb_bed_class");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
return DbHelperSQL.Exists(strSql.ToString(), parameters);
}
#endregion
//后加的==============================================================================================================================
/// <summary>
/// 获得查询分页数据
/// </summary>
public DataSet GetList(string _strWhere, string _orderby, int _pageSize, int _page, out int recordCount)
{
BasicPage bp = new BasicPage();
StringBuilder str_Sql = new StringBuilder();
str_Sql.Append("select top " + _pageSize + " * from tb_bed_class");
str_Sql.Append(" where ");
str_Sql.Append(_strWhere);
str_Sql.Append(" and id not in ");
str_Sql.Append(" ( ");
str_Sql.Append(" select top " + (_page - 1) * _pageSize + " id from tb_bed_class ");
str_Sql.Append(" where ");
str_Sql.Append(_strWhere);
str_Sql.Append(" order by ");
str_Sql.Append(_orderby);
str_Sql.Append(" ) ");
str_Sql.Append(" order by ");
str_Sql.Append(_orderby);
DataSet dst = bp.SelectDataBase("tb_bed_class", str_Sql.ToString());
//
recordCount = totlePage(showTotal(_strWhere), _pageSize);
return dst;
}
//总页数
public int totlePage(int Total, int PageSize)
{
if (Total % PageSize == 0)
{
return Total / PageSize;
}
else
{
return Total / PageSize + 1;
}
}
//总条数
protected int showTotal(string strSql)
{
BasicPage bp = new BasicPage();
int intTotal = 0;
SqlDataReader myread = bp.getRead("select count(id) as CountId from tb_bed_class where " + strSql);
if (myread.Read())
{
intTotal = Convert.ToInt32(myread["CountId"].ToString());
}
myread.Close();
return intTotal;
}
/// <summary>
/// 修改一列数据
/// </summary>
public void UpdateField(int id, string strValue)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update tb_bed_class set " + strValue);
strSql.Append(" where id=" + id);
DbHelperSQL.ExecuteSql(strSql.ToString());
}
}
}

+ 268
- 0
App.code/DAL/bianliang.cs View File

@ -0,0 +1,268 @@
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
namespace Basic.DAL
{
/// <summary>
/// 数据访问层
/// </summary>
public partial class bianliang
{
#region 此代码由工具生成
/// <summary>
/// 增加一条数据
/// </summary>
public int Add(Basic.Model.bianliang model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into tb_bianliang(");
strSql.Append("paixu,keyid,zhi,beizhu,status,add_time)");
strSql.Append(" values (");
strSql.Append("@paixu,@keyid,@zhi,@beizhu,@status,@add_time)");
strSql.Append(";select @@IDENTITY");
SqlParameter[] parameters = {
new SqlParameter("@paixu", SqlDbType.Int,10),
new SqlParameter("@keyid", SqlDbType.NVarChar,255),
new SqlParameter("@zhi", SqlDbType.NText,1073741823),
new SqlParameter("@beizhu", SqlDbType.NText,1073741823),
new SqlParameter("@status", SqlDbType.Int,10),
new SqlParameter("@add_time", SqlDbType.DateTime,23)};
parameters[0].Value = model.paixu;
parameters[1].Value = model.keyid;
parameters[2].Value = model.zhi;
parameters[3].Value = model.beizhu;
parameters[4].Value = model.status;
parameters[5].Value = model.add_time;
object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
if (obj == null)
{
return 0;
}
else
{
return Convert.ToInt32(obj);
}
}
/// <summary>
/// 更新一条数据
/// </summary>
public bool Update(Basic.Model.bianliang model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update tb_bianliang set ");
strSql.Append("paixu=@paixu,");
strSql.Append("keyid=@keyid,");
strSql.Append("zhi=@zhi,");
strSql.Append("beizhu=@beizhu,");
strSql.Append("status=@status,");
strSql.Append("add_time=@add_time");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@paixu", SqlDbType.Int,10),
new SqlParameter("@keyid", SqlDbType.NVarChar,255),
new SqlParameter("@zhi", SqlDbType.NText,1073741823),
new SqlParameter("@beizhu", SqlDbType.NText,1073741823),
new SqlParameter("@status", SqlDbType.Int,10),
new SqlParameter("@add_time", SqlDbType.DateTime,23),
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = model.paixu;
parameters[1].Value = model.keyid;
parameters[2].Value = model.zhi;
parameters[3].Value = model.beizhu;
parameters[4].Value = model.status;
parameters[5].Value = model.add_time;
parameters[6].Value = model.id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 删除一条数据
/// </summary>
public bool Delete(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from tb_bianliang");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public Basic.Model.bianliang GetModel(int id)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("select top 1 id,paixu,keyid,zhi,beizhu,status,add_time from tb_bianliang");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
Basic.Model.bianliang model = new Basic.Model.bianliang();
DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["id"].ToString()))
{
model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["paixu"].ToString()))
{
model.paixu = int.Parse(ds.Tables[0].Rows[0]["paixu"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["keyid"].ToString()))
{
model.keyid = ds.Tables[0].Rows[0]["keyid"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["zhi"].ToString()))
{
model.zhi = ds.Tables[0].Rows[0]["zhi"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["beizhu"].ToString()))
{
model.beizhu = ds.Tables[0].Rows[0]["beizhu"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["status"].ToString()))
{
model.status = int.Parse(ds.Tables[0].Rows[0]["status"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["add_time"].ToString()))
{
model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString());
}
return model;
}
else
{
return null;
}
}
/// <summary>
/// 获得前几行数据
/// </summary>
public DataSet GetList(int Top, string strWhere, string filedOrder)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select ");
if (Top > 0)
{
strSql.Append(" top " + Top.ToString());
}
strSql.Append("id,paixu,keyid,zhi,beizhu,status,add_time");
strSql.Append(" from tb_bianliang");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
strSql.Append(" order by " + filedOrder);
return DbHelperSQL.Query(strSql.ToString());
}
/// <summary>
/// 获得查询分页数据
/// </summary>
public DataSet GetList(string _strWhere, string _orderby, int _pageSize, int _page, out int recordCount)
{
BasicPage bp = new BasicPage();
StringBuilder str_Sql = new StringBuilder();
str_Sql.Append("select top " + _pageSize + " id,paixu,keyid,zhi,beizhu,status,add_time from tb_bianliang");
str_Sql.Append(" where ");
str_Sql.Append(_strWhere);
str_Sql.Append(" and id not in ");
str_Sql.Append(" ( ");
str_Sql.Append(" select top " + (_page - 1) * _pageSize + " id from tb_bianliang ");
str_Sql.Append(" where ");
str_Sql.Append(_strWhere);
str_Sql.Append(" order by ");
str_Sql.Append(_orderby);
str_Sql.Append(" ) ");
str_Sql.Append(" order by ");
str_Sql.Append(_orderby);
DataSet dst = bp.SelectDataBase("tb_bianliang", str_Sql.ToString());
//
recordCount = totlePage(showTotal(_strWhere), _pageSize);
return dst;
}
//总页数
public int totlePage(int Total, int PageSize)
{
if (Total % PageSize == 0)
{
return Total / PageSize;
}
else
{
return Total / PageSize + 1;
}
}
//总条数
protected int showTotal(string strSql)
{
BasicPage bp = new BasicPage();
int intTotal = 0;
SqlDataReader myread = bp.getRead("select count(id) as CountId from tb_bianliang where " + strSql);
if (myread.Read())
{
intTotal = Convert.ToInt32(myread["CountId"].ToString());
}
myread.Close();
return intTotal;
}
/// <summary>
/// 是否存在该记录
/// </summary>
public bool Exists(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(1) from tb_bianliang");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
return DbHelperSQL.Exists(strSql.ToString(), parameters);
}
/// <summary>
/// 修改一列数据
/// </summary>
public void UpdateField(int id, string strValue)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update tb_bianliang set " + strValue);
strSql.Append(" where id=" + id);
DbHelperSQL.ExecuteSql(strSql.ToString());
}
#endregion
}
}

+ 291
- 0
App.code/DAL/channel.cs View File

@ -0,0 +1,291 @@
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
namespace Basic.DAL
{
/// <summary>
/// 频道
/// </summary>
public partial class channel
{
/// <summary>
/// 增加一条数据
/// </summary>
public int Add(Basic.Model.channel model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into tb_channel(");
strSql.Append("class_id,title,guid,parent_id,class_list,class_layer,paixu,url,path,content,seo_title,seo_keywords,seo_description)");
strSql.Append(" values (");
strSql.Append("@class_id,@title,@guid,@parent_id,@class_list,@class_layer,@paixu,@url,@path,@content,@seo_title,@seo_keywords,@seo_description)");
strSql.Append(";select @@IDENTITY");
SqlParameter[] parameters = {
new SqlParameter("@class_id", SqlDbType.Int,10),
new SqlParameter("@title", SqlDbType.NVarChar,100),
new SqlParameter("@guid", SqlDbType.NVarChar,50),
new SqlParameter("@parent_id", SqlDbType.Int,10),
new SqlParameter("@class_list", SqlDbType.NVarChar,500),
new SqlParameter("@class_layer", SqlDbType.Int,10),
new SqlParameter("@paixu", SqlDbType.Int,10),
new SqlParameter("@url", SqlDbType.NVarChar,255),
new SqlParameter("@path", SqlDbType.NVarChar,255),
new SqlParameter("@content", SqlDbType.NText,1073741823),
new SqlParameter("@seo_title", SqlDbType.NVarChar,255),
new SqlParameter("@seo_keywords", SqlDbType.NVarChar,255),
new SqlParameter("@seo_description", SqlDbType.NVarChar,255)};
parameters[0].Value = model.class_id;
parameters[1].Value = model.title;
parameters[2].Value = model.guid;
parameters[3].Value = model.parent_id;
parameters[4].Value = model.class_list;
parameters[5].Value = model.class_layer;
parameters[6].Value = model.paixu;
parameters[7].Value = model.url;
parameters[8].Value = model.path;
parameters[9].Value = model.content;
parameters[10].Value = model.seo_title;
parameters[11].Value = model.seo_keywords;
parameters[12].Value = model.seo_description;
object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
if (obj == null)
{
return 0;
}
else
{
return Convert.ToInt32(obj);
}
}
/// <summary>
/// 更新一条数据
/// </summary>
public bool Update(Basic.Model.channel model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update tb_channel set ");
strSql.Append("class_id=@class_id,");
strSql.Append("title=@title,");
strSql.Append("guid=@guid,");
strSql.Append("parent_id=@parent_id,");
strSql.Append("class_list=@class_list,");
strSql.Append("class_layer=@class_layer,");
strSql.Append("paixu=@paixu,");
strSql.Append("url=@url,");
strSql.Append("path=@path,");
strSql.Append("content=@content,");
strSql.Append("seo_title=@seo_title,");
strSql.Append("seo_keywords=@seo_keywords,");
strSql.Append("seo_description=@seo_description");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@class_id", SqlDbType.Int,10),
new SqlParameter("@title", SqlDbType.NVarChar,100),
new SqlParameter("@guid", SqlDbType.NVarChar,50),
new SqlParameter("@parent_id", SqlDbType.Int,10),
new SqlParameter("@class_list", SqlDbType.NVarChar,500),
new SqlParameter("@class_layer", SqlDbType.Int,10),
new SqlParameter("@paixu", SqlDbType.Int,10),
new SqlParameter("@url", SqlDbType.NVarChar,255),
new SqlParameter("@path", SqlDbType.NVarChar,255),
new SqlParameter("@content", SqlDbType.NText,1073741823),
new SqlParameter("@seo_title", SqlDbType.NVarChar,255),
new SqlParameter("@seo_keywords", SqlDbType.NVarChar,255),
new SqlParameter("@seo_description", SqlDbType.NVarChar,255),
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = model.class_id;
parameters[1].Value = model.title;
parameters[2].Value = model.guid;
parameters[3].Value = model.parent_id;
parameters[4].Value = model.class_list;
parameters[5].Value = model.class_layer;
parameters[6].Value = model.paixu;
parameters[7].Value = model.url;
parameters[8].Value = model.path;
parameters[9].Value = model.content;
parameters[10].Value = model.seo_title;
parameters[11].Value = model.seo_keywords;
parameters[12].Value = model.seo_description;
parameters[13].Value = model.id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 删除一条数据
/// </summary>
public bool Delete(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from tb_channel");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public Basic.Model.channel GetModel(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select top 1 id,class_id,title,guid,parent_id,class_list,class_layer,paixu,url,path,content,seo_title,seo_keywords,seo_description from tb_channel");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
Basic.Model.channel model = new Basic.Model.channel();
DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["id"].ToString()))
{
model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["class_id"].ToString()))
{
model.class_id = int.Parse(ds.Tables[0].Rows[0]["class_id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["title"].ToString()))
{
model.title = ds.Tables[0].Rows[0]["title"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["guid"].ToString()))
{
model.guid = ds.Tables[0].Rows[0]["guid"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["parent_id"].ToString()))
{
model.parent_id = int.Parse(ds.Tables[0].Rows[0]["parent_id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["class_list"].ToString()))
{
model.class_list = ds.Tables[0].Rows[0]["class_list"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["class_layer"].ToString()))
{
model.class_layer = int.Parse(ds.Tables[0].Rows[0]["class_layer"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["paixu"].ToString()))
{
model.paixu = int.Parse(ds.Tables[0].Rows[0]["paixu"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["url"].ToString()))
{
model.url = ds.Tables[0].Rows[0]["url"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["path"].ToString()))
{
model.path = ds.Tables[0].Rows[0]["path"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["content"].ToString()))
{
model.content = ds.Tables[0].Rows[0]["content"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["seo_title"].ToString()))
{
model.seo_title = ds.Tables[0].Rows[0]["seo_title"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["seo_keywords"].ToString()))
{
model.seo_keywords = ds.Tables[0].Rows[0]["seo_keywords"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["seo_description"].ToString()))
{
model.seo_description = ds.Tables[0].Rows[0]["seo_description"].ToString();
}
return model;
}
else
{
return null;
}
}
/// <summary>
/// 取得所有类别列表
/// </summary>
/// <param name="parent_id">父ID</param>
/// <param name="class_id">分类ID</param>
/// <returns></returns>
public DataTable GetList(int parent_id, int class_id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select * from tb_channel");
strSql.Append(" where class_id=" + class_id + " order by paixu desc,id asc");
DataSet ds = DbHelperSQL.Query(strSql.ToString());
DataTable oldData = ds.Tables[0] as DataTable;
if (oldData == null)
{
return null;
}
//复制结构
DataTable newData = oldData.Clone();
//调用迭代组合成DAGATABLE
GetChilds(oldData, newData, parent_id, class_id);
return newData;
}
/// <summary>
/// 从内存中取得所有下级类别列表(自身迭代)
/// </summary>
private void GetChilds(DataTable oldData, DataTable newData, int parent_id, int channel_id)
{
DataRow[] dr = oldData.Select("parent_id=" + parent_id);
for (int i = 0; i < dr.Length; i++)
{
//添加一行数据
DataRow row = newData.NewRow();
row["id"] = int.Parse(dr[i]["id"].ToString());
row["class_id"] = int.Parse(dr[i]["class_id"].ToString());
row["title"] = dr[i]["title"].ToString();
row["guid"] = dr[i]["guid"].ToString();
row["parent_id"] = int.Parse(dr[i]["parent_id"].ToString());
row["class_list"] = dr[i]["class_list"].ToString();
row["class_layer"] = int.Parse(dr[i]["class_layer"].ToString());
row["paixu"] = int.Parse(dr[i]["paixu"].ToString());
row["url"] = dr[i]["url"].ToString();
row["path"] = dr[i]["path"].ToString();
row["content"] = dr[i]["content"].ToString();
row["seo_title"] = dr[i]["seo_title"].ToString();
row["seo_keywords"] = dr[i]["seo_keywords"].ToString();
row["seo_description"] = dr[i]["seo_description"].ToString();
newData.Rows.Add(row);
//调用自身迭代
this.GetChilds(oldData, newData, int.Parse(dr[i]["id"].ToString()), channel_id);
}
}
/// <summary>
/// 修改一列数据
/// </summary>
public void UpdateField(int id, string strValue)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update tb_channel set " + strValue);
strSql.Append(" where id=" + id);
DbHelperSQL.ExecuteSql(strSql.ToString());
}
}
}

+ 294
- 0
App.code/DAL/comment.cs View File

@ -0,0 +1,294 @@
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
namespace Basic.DAL
{
/// <summary>
/// 数据访问层comment
/// </summary>
public partial class comment
{
#region 原始的
/// <summary>
/// 增加一条数据
/// </summary>
public int Add(Basic.Model.comment model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into tb_comment(");
strSql.Append("name,user_id,product_id,attribute_id,product_name,product_path,content,review,status,add_time)");
strSql.Append(" values (");
strSql.Append("@name,@user_id,@product_id,@attribute_id,@product_name,@product_path,@content,@review,@status,@add_time)");
strSql.Append(";select @@IDENTITY");
SqlParameter[] parameters = {
new SqlParameter("@name", SqlDbType.NVarChar,50),
new SqlParameter("@user_id", SqlDbType.Int,10),
new SqlParameter("@product_id", SqlDbType.Int,10),
new SqlParameter("@attribute_id", SqlDbType.NVarChar,255),
new SqlParameter("@product_name", SqlDbType.NVarChar,255),
new SqlParameter("@product_path", SqlDbType.NVarChar,255),
new SqlParameter("@content", SqlDbType.NVarChar,255),
new SqlParameter("@review", SqlDbType.NVarChar,255),
new SqlParameter("@status", SqlDbType.Int,10),
new SqlParameter("@add_time", SqlDbType.DateTime,23)};
parameters[0].Value = model.name;
parameters[1].Value = model.user_id;
parameters[2].Value = model.product_id;
parameters[3].Value = model.attribute_id;
parameters[4].Value = model.product_name;
parameters[5].Value = model.product_path;
parameters[6].Value = model.content;
parameters[7].Value = model.review;
parameters[8].Value = model.status;
parameters[9].Value = model.add_time;
object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
if (obj == null)
{
return 0;
}
else
{
return Convert.ToInt32(obj);
}
}
/// <summary>
/// 更新一条数据
/// </summary>
public bool Update(Basic.Model.comment model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update tb_comment set ");
strSql.Append("name=@name,");
strSql.Append("user_id=@user_id,");
strSql.Append("product_id=@product_id,");
strSql.Append("attribute_id=@attribute_id,");
strSql.Append("product_name=@product_name,");
strSql.Append("product_path=@product_path,");
strSql.Append("content=@content,");
strSql.Append("review=@review,");
strSql.Append("status=@status,");
strSql.Append("add_time=@add_time");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@name", SqlDbType.NVarChar,50),
new SqlParameter("@user_id", SqlDbType.Int,10),
new SqlParameter("@product_id", SqlDbType.Int,10),
new SqlParameter("@attribute_id", SqlDbType.NVarChar,255),
new SqlParameter("@product_name", SqlDbType.NVarChar,255),
new SqlParameter("@product_path", SqlDbType.NVarChar,255),
new SqlParameter("@content", SqlDbType.NVarChar,255),
new SqlParameter("@review", SqlDbType.NVarChar,255),
new SqlParameter("@status", SqlDbType.Int,10),
new SqlParameter("@add_time", SqlDbType.DateTime,23),
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = model.name;
parameters[1].Value = model.user_id;
parameters[2].Value = model.product_id;
parameters[3].Value = model.attribute_id;
parameters[4].Value = model.product_name;
parameters[5].Value = model.product_path;
parameters[6].Value = model.content;
parameters[7].Value = model.review;
parameters[8].Value = model.status;
parameters[9].Value = model.add_time;
parameters[10].Value = model.id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 删除一条数据
/// </summary>
public bool Delete(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from tb_comment");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public Basic.Model.comment GetModel(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select top 1 id,name,user_id,product_id,attribute_id,product_name,product_path,content,review,status,add_time from tb_comment");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
Basic.Model.comment model = new Basic.Model.comment();
DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["id"].ToString()))
{
model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["name"].ToString()))
{
model.name = ds.Tables[0].Rows[0]["name"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["user_id"].ToString()))
{
model.user_id = int.Parse(ds.Tables[0].Rows[0]["user_id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["product_id"].ToString()))
{
model.product_id = int.Parse(ds.Tables[0].Rows[0]["product_id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["attribute_id"].ToString()))
{
model.attribute_id = ds.Tables[0].Rows[0]["attribute_id"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["product_name"].ToString()))
{
model.product_name = ds.Tables[0].Rows[0]["product_name"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["product_path"].ToString()))
{
model.product_path = ds.Tables[0].Rows[0]["product_path"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["content"].ToString()))
{
model.content = ds.Tables[0].Rows[0]["content"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["review"].ToString()))
{
model.review = ds.Tables[0].Rows[0]["review"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["status"].ToString()))
{
model.status = int.Parse(ds.Tables[0].Rows[0]["status"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["add_time"].ToString()))
{
model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString());
}
return model;
}
else
{
return null;
}
}
/// <summary>
/// 获得前几行数据
/// </summary>
public DataSet GetList(int Top, string strWhere, string filedOrder)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select ");
if (Top > 0)
{
strSql.Append(" top " + Top.ToString());
}
strSql.Append("id,name,user_id,product_id,attribute_id,product_name,product_path,content,review,status,add_time");
strSql.Append(" from tb_comment");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
strSql.Append(" order by " + filedOrder);
return DbHelperSQL.Query(strSql.ToString());
}
/// <summary>
/// 是否存在该记录
/// </summary>
public bool Exists(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(1) from tb_comment");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
return DbHelperSQL.Exists(strSql.ToString(), parameters);
}
#endregion
//=======================================================================================================后加的
/// <summary>
/// 获得查询分页数据
/// </summary>
public DataSet GetList(string _strWhere, string _orderby, int _pageSize, int _page, out int recordCount)
{
BasicPage bp = new BasicPage();
StringBuilder str_Sql = new StringBuilder();
str_Sql.Append("select top " + _pageSize + " * from tb_comment");
str_Sql.Append(" where ");
str_Sql.Append(_strWhere);
str_Sql.Append(" and id not in ");
str_Sql.Append(" ( ");
str_Sql.Append(" select top " + (_page - 1) * _pageSize + " id from tb_comment ");
str_Sql.Append(" where ");
str_Sql.Append(_strWhere);
str_Sql.Append(" order by ");
str_Sql.Append(_orderby);
str_Sql.Append(" ) ");
str_Sql.Append(" order by ");
str_Sql.Append(_orderby);
DataSet dst = bp.SelectDataBase("tb_comment", str_Sql.ToString());
//
recordCount = totlePage(showTotal(_strWhere), _pageSize);
return dst;
}
//总页数
public int totlePage(int Total, int PageSize)
{
if (Total % PageSize == 0)
{
return Total / PageSize;
}
else
{
return Total / PageSize + 1;
}
}
//总条数
protected int showTotal(string strSql)
{
BasicPage bp = new BasicPage();
int intTotal = 0;
SqlDataReader myread = bp.getRead("select count(id) as CountId from tb_comment where " + strSql);
if (myread.Read())
{
intTotal = Convert.ToInt32(myread["CountId"].ToString());
}
myread.Close();
return intTotal;
}
}
}

+ 295
- 0
App.code/DAL/coupon.cs View File

@ -0,0 +1,295 @@
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
namespace Basic.DAL
{
/// <summary>
/// 数据访问层
/// </summary>
public partial class coupon
{
#region 此代码由工具生成
/// <summary>
/// 增加一条数据
/// </summary>
public int Add(Basic.Model.coupon model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into tb_coupon(");
strSql.Append("paixu,name,start_time,end_time,number,purchase_amount,coupon_amount,status,add_time)");
strSql.Append(" values (");
strSql.Append("@paixu,@name,@start_time,@end_time,@number,@purchase_amount,@coupon_amount,@status,@add_time)");
strSql.Append(";select @@IDENTITY");
SqlParameter[] parameters = {
new SqlParameter("@paixu", SqlDbType.Int,10),
new SqlParameter("@name", SqlDbType.NVarChar,255),
new SqlParameter("@start_time", SqlDbType.DateTime,23),
new SqlParameter("@end_time", SqlDbType.DateTime,23),
new SqlParameter("@number", SqlDbType.Int,10),
new SqlParameter("@purchase_amount", SqlDbType.Decimal,18),
new SqlParameter("@coupon_amount", SqlDbType.Decimal,18),
new SqlParameter("@status", SqlDbType.Int,10),
new SqlParameter("@add_time", SqlDbType.DateTime,23)};
parameters[0].Value = model.paixu;
parameters[1].Value = model.name;
parameters[2].Value = model.start_time;
parameters[3].Value = model.end_time;
parameters[4].Value = model.number;
parameters[5].Value = model.purchase_amount;
parameters[6].Value = model.coupon_amount;
parameters[7].Value = model.status;
parameters[8].Value = model.add_time;
object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
if (obj == null)
{
return 0;
}
else
{
return Convert.ToInt32(obj);
}
}
/// <summary>
/// 更新一条数据
/// </summary>
public bool Update(Basic.Model.coupon model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update tb_coupon set ");
strSql.Append("paixu=@paixu,");
strSql.Append("name=@name,");
strSql.Append("start_time=@start_time,");
strSql.Append("end_time=@end_time,");
strSql.Append("number=@number,");
strSql.Append("purchase_amount=@purchase_amount,");
strSql.Append("coupon_amount=@coupon_amount,");
strSql.Append("status=@status,");
strSql.Append("add_time=@add_time");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@paixu", SqlDbType.Int,10),
new SqlParameter("@name", SqlDbType.NVarChar,255),
new SqlParameter("@start_time", SqlDbType.DateTime,23),
new SqlParameter("@end_time", SqlDbType.DateTime,23),
new SqlParameter("@number", SqlDbType.Int,10),
new SqlParameter("@purchase_amount", SqlDbType.Decimal,18),
new SqlParameter("@coupon_amount", SqlDbType.Decimal,18),
new SqlParameter("@status", SqlDbType.Int,10),
new SqlParameter("@add_time", SqlDbType.DateTime,23),
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = model.paixu;
parameters[1].Value = model.name;
parameters[2].Value = model.start_time;
parameters[3].Value = model.end_time;
parameters[4].Value = model.number;
parameters[5].Value = model.purchase_amount;
parameters[6].Value = model.coupon_amount;
parameters[7].Value = model.status;
parameters[8].Value = model.add_time;
parameters[9].Value = model.id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 删除一条数据
/// </summary>
public bool Delete(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from tb_coupon");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public Basic.Model.coupon GetModel(int id)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("select top 1 id,paixu,name,start_time,end_time,number,purchase_amount,coupon_amount,status,add_time from tb_coupon");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
Basic.Model.coupon model = new Basic.Model.coupon();
DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["id"].ToString()))
{
model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["paixu"].ToString()))
{
model.paixu = int.Parse(ds.Tables[0].Rows[0]["paixu"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["name"].ToString()))
{
model.name = ds.Tables[0].Rows[0]["name"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["start_time"].ToString()))
{
model.start_time = DateTime.Parse(ds.Tables[0].Rows[0]["start_time"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["end_time"].ToString()))
{
model.end_time = DateTime.Parse(ds.Tables[0].Rows[0]["end_time"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["number"].ToString()))
{
model.number = int.Parse(ds.Tables[0].Rows[0]["number"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["purchase_amount"].ToString()))
{
model.purchase_amount = decimal.Parse(ds.Tables[0].Rows[0]["purchase_amount"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["coupon_amount"].ToString()))
{
model.coupon_amount = decimal.Parse(ds.Tables[0].Rows[0]["coupon_amount"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["status"].ToString()))
{
model.status = int.Parse(ds.Tables[0].Rows[0]["status"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["add_time"].ToString()))
{
model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString());
}
return model;
}
else
{
return null;
}
}
/// <summary>
/// 获得前几行数据
/// </summary>
public DataSet GetList(int Top, string strWhere, string filedOrder)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select ");
if (Top > 0)
{
strSql.Append(" top " + Top.ToString());
}
strSql.Append("id,paixu,name,start_time,end_time,number,purchase_amount,coupon_amount,status,add_time");
strSql.Append(" from tb_coupon");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
strSql.Append(" order by " + filedOrder);
return DbHelperSQL.Query(strSql.ToString());
}
/// <summary>
/// 获得查询分页数据
/// </summary>
public DataSet GetList(string _strWhere, string _orderby, int _pageSize, int _page, out int recordCount)
{
BasicPage bp = new BasicPage();
StringBuilder str_Sql = new StringBuilder();
str_Sql.Append("select top " + _pageSize + " id,paixu,name,start_time,end_time,number,purchase_amount,coupon_amount,status,add_time from tb_coupon");
str_Sql.Append(" where ");
str_Sql.Append(_strWhere);
str_Sql.Append(" and id not in ");
str_Sql.Append(" ( ");
str_Sql.Append(" select top " + (_page - 1) * _pageSize + " id from tb_coupon ");
str_Sql.Append(" where ");
str_Sql.Append(_strWhere);
str_Sql.Append(" order by ");
str_Sql.Append(_orderby);
str_Sql.Append(" ) ");
str_Sql.Append(" order by ");
str_Sql.Append(_orderby);
DataSet dst = bp.SelectDataBase("tb_coupon", str_Sql.ToString());
//
recordCount = totlePage(showTotal(_strWhere), _pageSize);
return dst;
}
//总页数
public int totlePage(int Total, int PageSize)
{
if (Total % PageSize == 0)
{
return Total / PageSize;
}
else
{
return Total / PageSize + 1;
}
}
//总条数
protected int showTotal(string strSql)
{
BasicPage bp = new BasicPage();
int intTotal = 0;
SqlDataReader myread = bp.getRead("select count(id) as CountId from tb_coupon where " + strSql);
if (myread.Read())
{
intTotal = Convert.ToInt32(myread["CountId"].ToString());
}
myread.Close();
return intTotal;
}
/// <summary>
/// 是否存在该记录
/// </summary>
public bool Exists(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(1) from tb_coupon");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
return DbHelperSQL.Exists(strSql.ToString(), parameters);
}
/// <summary>
/// 修改一列数据
/// </summary>
public void UpdateField(int id, string strValue)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update tb_coupon set " + strValue);
strSql.Append(" where id=" + id);
DbHelperSQL.ExecuteSql(strSql.ToString());
}
#endregion
}
}

+ 259
- 0
App.code/DAL/couponuser.cs View File

@ -0,0 +1,259 @@
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
namespace Basic.DAL
{
/// <summary>
/// 数据访问层
/// </summary>
public partial class couponuser
{
#region 此代码由工具生成
/// <summary>
/// 增加一条数据
/// </summary>
public int Add(Basic.Model.couponuser model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into tb_couponuser(");
strSql.Append("paixu,couponid,name,couponstatus,add_time)");
strSql.Append(" values (");
strSql.Append("@paixu,@couponid,@name,@couponstatus,@add_time)");
strSql.Append(";select @@IDENTITY");
SqlParameter[] parameters = {
new SqlParameter("@paixu", SqlDbType.Int,10),
new SqlParameter("@couponid", SqlDbType.Int,10),
new SqlParameter("@name", SqlDbType.NVarChar,255),
new SqlParameter("@couponstatus", SqlDbType.Int,10),
new SqlParameter("@add_time", SqlDbType.DateTime,23)};
parameters[0].Value = model.paixu;
parameters[1].Value = model.couponid;
parameters[2].Value = model.name;
parameters[3].Value = model.couponstatus;
parameters[4].Value = model.add_time;
object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
if (obj == null)
{
return 0;
}
else
{
return Convert.ToInt32(obj);
}
}
/// <summary>
/// 更新一条数据
/// </summary>
public bool Update(Basic.Model.couponuser model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update tb_couponuser set ");
strSql.Append("paixu=@paixu,");
strSql.Append("couponid=@couponid,");
strSql.Append("name=@name,");
strSql.Append("couponstatus=@couponstatus,");
strSql.Append("add_time=@add_time");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@paixu", SqlDbType.Int,10),
new SqlParameter("@couponid", SqlDbType.Int,10),
new SqlParameter("@name", SqlDbType.NVarChar,255),
new SqlParameter("@couponstatus", SqlDbType.Int,10),
new SqlParameter("@add_time", SqlDbType.DateTime,23),
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = model.paixu;
parameters[1].Value = model.couponid;
parameters[2].Value = model.name;
parameters[3].Value = model.couponstatus;
parameters[4].Value = model.add_time;
parameters[5].Value = model.id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 删除一条数据
/// </summary>
public bool Delete(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from tb_couponuser");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public Basic.Model.couponuser GetModel(int id)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("select top 1 id,paixu,couponid,name,couponstatus,add_time from tb_couponuser");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
Basic.Model.couponuser model = new Basic.Model.couponuser();
DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["id"].ToString()))
{
model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["paixu"].ToString()))
{
model.paixu = int.Parse(ds.Tables[0].Rows[0]["paixu"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["couponid"].ToString()))
{
model.couponid = int.Parse(ds.Tables[0].Rows[0]["couponid"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["name"].ToString()))
{
model.name = ds.Tables[0].Rows[0]["name"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["couponstatus"].ToString()))
{
model.couponstatus = int.Parse(ds.Tables[0].Rows[0]["couponstatus"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["add_time"].ToString()))
{
model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString());
}
return model;
}
else
{
return null;
}
}
/// <summary>
/// 获得前几行数据
/// </summary>
public DataSet GetList(int Top, string strWhere, string filedOrder)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select ");
if (Top > 0)
{
strSql.Append(" top " + Top.ToString());
}
strSql.Append("id,paixu,couponid,name,couponstatus,add_time");
strSql.Append(" from tb_couponuser");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
strSql.Append(" order by " + filedOrder);
return DbHelperSQL.Query(strSql.ToString());
}
/// <summary>
/// 获得查询分页数据
/// </summary>
public DataSet GetList(string _strWhere, string _orderby, int _pageSize, int _page, out int recordCount)
{
BasicPage bp = new BasicPage();
StringBuilder str_Sql = new StringBuilder();
str_Sql.Append("select top " + _pageSize + " id,paixu,couponid,name,couponstatus,add_time from tb_couponuser");
str_Sql.Append(" where ");
str_Sql.Append(_strWhere);
str_Sql.Append(" and id not in ");
str_Sql.Append(" ( ");
str_Sql.Append(" select top " + (_page - 1) * _pageSize + " id from tb_couponuser ");
str_Sql.Append(" where ");
str_Sql.Append(_strWhere);
str_Sql.Append(" order by ");
str_Sql.Append(_orderby);
str_Sql.Append(" ) ");
str_Sql.Append(" order by ");
str_Sql.Append(_orderby);
DataSet dst = bp.SelectDataBase("tb_couponuser", str_Sql.ToString());
//
recordCount = totlePage(showTotal(_strWhere), _pageSize);
return dst;
}
//总页数
public int totlePage(int Total, int PageSize)
{
if (Total % PageSize == 0)
{
return Total / PageSize;
}
else
{
return Total / PageSize + 1;
}
}
//总条数
protected int showTotal(string strSql)
{
BasicPage bp = new BasicPage();
int intTotal = 0;
SqlDataReader myread = bp.getRead("select count(id) as CountId from tb_couponuser where " + strSql);
if (myread.Read())
{
intTotal = Convert.ToInt32(myread["CountId"].ToString());
}
myread.Close();
return intTotal;
}
/// <summary>
/// 是否存在该记录
/// </summary>
public bool Exists(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(1) from tb_couponuser");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
return DbHelperSQL.Exists(strSql.ToString(), parameters);
}
/// <summary>
/// 修改一列数据
/// </summary>
public void UpdateField(int id, string strValue)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update tb_couponuser set " + strValue);
strSql.Append(" where id=" + id);
DbHelperSQL.ExecuteSql(strSql.ToString());
}
#endregion
}
}

+ 256
- 0
App.code/DAL/databackup.cs View File

@ -0,0 +1,256 @@
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
namespace Basic.DAL
{
/// <summary>
/// 数据访问层databackup
/// </summary>
public partial class databackup
{
/// <summary>
/// 增加一条数据
/// </summary>
public int Add(Basic.Model.databackup model)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("insert into tb_databackup(");
strSql.Append("title,paixu,storage,user_name,add_time)");
strSql.Append(" values (");
strSql.Append("@title,@paixu,@storage,@user_name,@add_time)");
strSql.Append(";select @@IDENTITY");
SqlParameter[] parameters = {
new SqlParameter("@title", SqlDbType.NVarChar,100),
new SqlParameter("@paixu", SqlDbType.Int,10),
new SqlParameter("@storage", SqlDbType.NVarChar,100),
new SqlParameter("@user_name", SqlDbType.NVarChar,100),
new SqlParameter("@add_time", SqlDbType.DateTime,23)};
parameters[0].Value = model.title;
parameters[1].Value = model.paixu;
parameters[2].Value = model.storage;
parameters[3].Value = model.user_name;
parameters[4].Value = model.add_time;
object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
if (obj == null)
{
return 0;
}
else
{
return Convert.ToInt32(obj);
}
}
/// <summary>
/// 更新一条数据
/// </summary>
public bool Update(Basic.Model.databackup model)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("update tb_databackup set ");
strSql.Append("title=@title,");
strSql.Append("paixu=@paixu,");
strSql.Append("storage=@storage,");
strSql.Append("user_name=@user_name,");
strSql.Append("add_time=@add_time");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@title", SqlDbType.NVarChar,100),
new SqlParameter("@paixu", SqlDbType.Int,10),
new SqlParameter("@storage", SqlDbType.NVarChar,100),
new SqlParameter("@user_name", SqlDbType.NVarChar,100),
new SqlParameter("@add_time", SqlDbType.DateTime,23),
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = model.title;
parameters[1].Value = model.paixu;
parameters[2].Value = model.storage;
parameters[3].Value = model.user_name;
parameters[4].Value = model.add_time;
parameters[5].Value = model.id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 删除一条数据
/// </summary>
public bool Delete(int id)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("delete from tb_databackup");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public Basic.Model.databackup GetModel(int id)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("select top 1 id,title,paixu,storage,user_name,add_time from tb_databackup");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
Basic.Model.databackup model = new Basic.Model.databackup();
DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["id"].ToString()))
{
model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["title"].ToString()))
{
model.title = ds.Tables[0].Rows[0]["title"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["paixu"].ToString()))
{
model.paixu = int.Parse(ds.Tables[0].Rows[0]["paixu"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["storage"].ToString()))
{
model.storage = ds.Tables[0].Rows[0]["storage"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["user_name"].ToString()))
{
model.user_name = ds.Tables[0].Rows[0]["user_name"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["add_time"].ToString()))
{
model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString());
}
return model;
}
else
{
return null;
}
}
/// <summary>
/// 获得前几行数据
/// </summary>
public DataSet GetList(int Top, string strWhere, string filedOrder)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("select ");
if (Top > 0)
{
strSql.Append(" top " + Top.ToString());
}
strSql.Append("id,title,paixu,storage,user_name,add_time");
strSql.Append(" from tb_databackup");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
strSql.Append(" order by " + filedOrder);
return DbHelperSQL.Query(strSql.ToString());
}
/// <summary>
/// 是否存在该记录
/// </summary>
public bool Exists(int id)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("select count(1) from tb_databackup");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
return DbHelperSQL.Exists(strSql.ToString(), parameters);
}
//后加的============================================================================================================
/// <summary>
/// 获得查询分页数据
/// </summary>
public DataSet GetList(string _strWhere, string _orderby, int _pageSize, int _page, out int recordCount)
{
BasicPage bp = new BasicPage();
StringBuilder str_Sql = new StringBuilder();
str_Sql.Append("select top " + _pageSize + " * from tb_databackup");
str_Sql.Append(" where ");
str_Sql.Append(_strWhere);
str_Sql.Append(" and id not in ");
str_Sql.Append(" ( ");
str_Sql.Append(" select top " + (_page - 1) * _pageSize + " id from tb_databackup ");
str_Sql.Append(" where ");
str_Sql.Append(_strWhere);
str_Sql.Append(" order by ");
str_Sql.Append(_orderby);
str_Sql.Append(" ) ");
str_Sql.Append(" order by ");
str_Sql.Append(_orderby);
DataSet dst = bp.SelectDataBase("tb_databackup", str_Sql.ToString());
//
recordCount = totlePage(showTotal(_strWhere), _pageSize);
return dst;
}
//总页数
public int totlePage(int Total, int PageSize)
{
if (Total % PageSize == 0)
{
return Total / PageSize;
}
else
{
return Total / PageSize + 1;
}
}
//总条数
protected int showTotal(string strSql)
{
BasicPage bp = new BasicPage();
int intTotal = 0;
SqlDataReader myread = bp.getRead("select count(id) as CountId from tb_databackup where " + strSql);
if (myread.Read())
{
intTotal = Convert.ToInt32(myread["CountId"].ToString());
}
myread.Close();
return intTotal;
}
/// <summary>
/// 修改一列数据
/// </summary>
public void UpdateField(int id, string strValue)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update tb_databackup set " + strValue);
strSql.Append(" where id=" + id);
DbHelperSQL.ExecuteSql(strSql.ToString());
}
}
}

+ 177
- 0
App.code/DAL/followproduct.cs View File

@ -0,0 +1,177 @@
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
namespace Basic.DAL
{
/// <summary>
/// 数据访问层
/// </summary>
public partial class followproduct
{
#region 此代码由工具生成
/// <summary>
/// 增加一条数据
/// </summary>
public int Add(Basic.Model.followproduct model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into tb_followproduct(");
strSql.Append("product_id,add_time,openid)");
strSql.Append(" values (");
strSql.Append("@product_id,@add_time,@openid)");
strSql.Append(";select @@IDENTITY");
SqlParameter[] parameters =
{
new SqlParameter("@product_id", SqlDbType.Int,10),
new SqlParameter("@add_time", SqlDbType.DateTime,23),
new SqlParameter("@openid", SqlDbType.NVarChar,255)
};
parameters[0].Value = model.product_id;
parameters[1].Value = model.add_time;
parameters[2].Value = model.openid;
object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
if (obj == null)
{
return 0;
}
else
{
return Convert.ToInt32(obj);
}
}
/// <summary>
/// 删除一条数据
/// </summary>
public bool Delete(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from tb_followproduct");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 获得前几行数据
/// </summary>
public DataSet GetList(int Top, string strWhere, string filedOrder)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select ");
if (Top > 0)
{
strSql.Append(" top " + Top.ToString());
}
strSql.Append("product_id,add_time,openid from tb_followproduct");
strSql.Append(" from tb_followproduct");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
strSql.Append(" order by " + filedOrder);
return DbHelperSQL.Query(strSql.ToString());
}
/// <summary>
/// 获得查询分页数据
/// </summary>
public DataSet GetList(string _strWhere, string _orderby, int _pageSize, int _page, out int recordCount)
{
BasicPage bp = new BasicPage();
StringBuilder str_Sql = new StringBuilder();
str_Sql.Append("select top " + _pageSize + " product_id,add_time,openid from tb_followproduct");
str_Sql.Append(" where ");
str_Sql.Append(_strWhere);
str_Sql.Append(" and id not in ");
str_Sql.Append(" ( ");
str_Sql.Append(" select top " + (_page - 1) * _pageSize + " id from tb_followproduct ");
str_Sql.Append(" where ");
str_Sql.Append(_strWhere);
str_Sql.Append(" order by ");
str_Sql.Append(_orderby);
str_Sql.Append(" ) ");
str_Sql.Append(" order by ");
str_Sql.Append(_orderby);
DataSet dst = bp.SelectDataBase("tb_followproduct", str_Sql.ToString());
//
recordCount = totlePage(showTotal(_strWhere), _pageSize);
return dst;
}
//总页数
public int totlePage(int Total, int PageSize)
{
if (Total % PageSize == 0)
{
return Total / PageSize;
}
else
{
return Total / PageSize + 1;
}
}
//总条数
public int showTotal(string strSql)
{
BasicPage bp = new BasicPage();
int intTotal = 0;
SqlDataReader myread = bp.getRead("select count(id) as CountId from tb_shopcart where " + strSql);
if (myread.Read())
{
intTotal = Convert.ToInt32(myread["CountId"].ToString());
}
myread.Close();
return intTotal;
}
/// <summary>
/// 是否存在该记录
/// </summary>
public bool Exists(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(1) from tb_followproduct");
strSql.Append(" where product_id=@product_id");
SqlParameter[] parameters =
{
new SqlParameter("@product_id", SqlDbType.Int,10)
};
parameters[0].Value = id;
return DbHelperSQL.Exists(strSql.ToString(), parameters);
}
/// <summary>
/// 修改一列数据
/// </summary>
public void UpdateField(int id, string strValue)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update tb_followproduct set " + strValue);
strSql.Append(" where id=" + id);
DbHelperSQL.ExecuteSql(strSql.ToString());
}
#endregion
}
}

+ 373
- 0
App.code/DAL/freight.cs View File

@ -0,0 +1,373 @@
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
namespace Basic.DAL
{
/// <summary>
/// 数据访问层
/// </summary>
public partial class freight
{
#region 此代码由工具生成
/// <summary>
/// 增加一条数据
/// </summary>
public int Add(Basic.Model.freight model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into tb_freight(");
strSql.Append("title,gudingyf,yuanmian,yuanjifei,jianmian,jianjifei,content,paixu,state,add_time)");
strSql.Append(" values (");
strSql.Append("@title,@gudingyf,@yuanmian,@yuanjifei,@jianmian,@jianjifei,@content,@paixu,@state,@add_time)");
strSql.Append(";select @@IDENTITY");
SqlParameter[] parameters = {
new SqlParameter("@title", SqlDbType.NVarChar,100),
new SqlParameter("@gudingyf", SqlDbType.NVarChar,255),
new SqlParameter("@yuanmian", SqlDbType.NVarChar,255),
new SqlParameter("@yuanjifei", SqlDbType.NVarChar,255),
new SqlParameter("@jianmian", SqlDbType.NVarChar,255),
new SqlParameter("@jianjifei", SqlDbType.NVarChar,255),
new SqlParameter("@content", SqlDbType.NVarChar,255),
new SqlParameter("@paixu", SqlDbType.Int,10),
new SqlParameter("@state", SqlDbType.Int,10),
new SqlParameter("@add_time", SqlDbType.DateTime,23)};
parameters[0].Value = model.title;
parameters[1].Value = model.gudingyf;
parameters[2].Value = model.yuanmian;
parameters[3].Value = model.yuanjifei;
parameters[4].Value = model.jianmian;
parameters[5].Value = model.jianjifei;
parameters[6].Value = model.content;
parameters[7].Value = model.paixu;
parameters[8].Value = model.state;
parameters[9].Value = model.add_time;
object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
if (obj == null)
{
return 0;
}
else
{
return Convert.ToInt32(obj);
}
}
/// <summary>
/// 更新一条数据
/// </summary>
public bool Update(Basic.Model.freight model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update tb_freight set ");
strSql.Append("title=@title,");
strSql.Append("gudingyf=@gudingyf,");
strSql.Append("yuanmian=@yuanmian,");
strSql.Append("yuanjifei=@yuanjifei,");
strSql.Append("jianmian=@jianmian,");
strSql.Append("jianjifei=@jianjifei,");
strSql.Append("content=@content,");
strSql.Append("paixu=@paixu,");
strSql.Append("state=@state,");
strSql.Append("add_time=@add_time");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@title", SqlDbType.NVarChar,100),
new SqlParameter("@gudingyf", SqlDbType.NVarChar,255),
new SqlParameter("@yuanmian", SqlDbType.NVarChar,255),
new SqlParameter("@yuanjifei", SqlDbType.NVarChar,255),
new SqlParameter("@jianmian", SqlDbType.NVarChar,255),
new SqlParameter("@jianjifei", SqlDbType.NVarChar,255),
new SqlParameter("@content", SqlDbType.NVarChar,255),
new SqlParameter("@paixu", SqlDbType.Int,10),
new SqlParameter("@state", SqlDbType.Int,10),
new SqlParameter("@add_time", SqlDbType.DateTime,23),
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = model.title;
parameters[1].Value = model.gudingyf;
parameters[2].Value = model.yuanmian;
parameters[3].Value = model.yuanjifei;
parameters[4].Value = model.jianmian;
parameters[5].Value = model.jianjifei;
parameters[6].Value = model.content;
parameters[7].Value = model.paixu;
parameters[8].Value = model.state;
parameters[9].Value = model.add_time;
parameters[10].Value = model.id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 删除一条数据
/// </summary>
public bool Delete(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from tb_freight");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public Basic.Model.freight GetModel(int id)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("select top 1 id,title,gudingyf,yuanmian,yuanjifei,jianmian,jianjifei,content,paixu,state,add_time from tb_freight");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
Basic.Model.freight model = new Basic.Model.freight();
DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["id"].ToString()))
{
model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["title"].ToString()))
{
model.title = ds.Tables[0].Rows[0]["title"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["gudingyf"].ToString()))
{
model.gudingyf = ds.Tables[0].Rows[0]["gudingyf"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["yuanmian"].ToString()))
{
model.yuanmian = ds.Tables[0].Rows[0]["yuanmian"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["yuanjifei"].ToString()))
{
model.yuanjifei = ds.Tables[0].Rows[0]["yuanjifei"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["jianmian"].ToString()))
{
model.jianmian = ds.Tables[0].Rows[0]["jianmian"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["jianjifei"].ToString()))
{
model.jianjifei = ds.Tables[0].Rows[0]["jianjifei"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["content"].ToString()))
{
model.content = ds.Tables[0].Rows[0]["content"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["paixu"].ToString()))
{
model.paixu = int.Parse(ds.Tables[0].Rows[0]["paixu"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["state"].ToString()))
{
model.state = int.Parse(ds.Tables[0].Rows[0]["state"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["add_time"].ToString()))
{
model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString());
}
return model;
}
else
{
return null;
}
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public Basic.Model.freight GetModelByState()
{
StringBuilder strSql=new StringBuilder();
strSql.Append("select top 1 id,title,gudingyf,yuanmian,yuanjifei,jianmian,jianjifei,content,paixu,state,add_time from tb_freight");
strSql.Append(" where state=@state");
SqlParameter[] parameters =
{
new SqlParameter("@state", SqlDbType.Int,4)};
parameters[0].Value = 0;
Basic.Model.freight model = new Basic.Model.freight();
DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["id"].ToString()))
{
model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["title"].ToString()))
{
model.title = ds.Tables[0].Rows[0]["title"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["gudingyf"].ToString()))
{
model.gudingyf = ds.Tables[0].Rows[0]["gudingyf"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["yuanmian"].ToString()))
{
model.yuanmian = ds.Tables[0].Rows[0]["yuanmian"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["yuanjifei"].ToString()))
{
model.yuanjifei = ds.Tables[0].Rows[0]["yuanjifei"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["jianmian"].ToString()))
{
model.jianmian = ds.Tables[0].Rows[0]["jianmian"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["jianjifei"].ToString()))
{
model.jianjifei = ds.Tables[0].Rows[0]["jianjifei"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["content"].ToString()))
{
model.content = ds.Tables[0].Rows[0]["content"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["paixu"].ToString()))
{
model.paixu = int.Parse(ds.Tables[0].Rows[0]["paixu"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["state"].ToString()))
{
model.state = int.Parse(ds.Tables[0].Rows[0]["state"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["add_time"].ToString()))
{
model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString());
}
return model;
}
else
{
return null;
}
}
/// <summary>
/// 获得前几行数据
/// </summary>
public DataSet GetList(int Top, string strWhere, string filedOrder)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select ");
if (Top > 0)
{
strSql.Append(" top " + Top.ToString());
}
strSql.Append("id,title,gudingyf,yuanmian,yuanjifei,jianmian,jianjifei,content,paixu,state,add_time");
strSql.Append(" from tb_freight");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
strSql.Append(" order by " + filedOrder);
return DbHelperSQL.Query(strSql.ToString());
}
/// <summary>
/// 获得查询分页数据
/// </summary>
public DataSet GetList(string _strWhere, string _orderby, int _pageSize, int _page, out int recordCount)
{
BasicPage bp = new BasicPage();
StringBuilder str_Sql = new StringBuilder();
str_Sql.Append("select top " + _pageSize + " id,title,gudingyf,yuanmian,yuanjifei,jianmian,jianjifei,content,paixu,state,add_time from tb_freight");
str_Sql.Append(" where ");
str_Sql.Append(_strWhere);
str_Sql.Append(" and id not in ");
str_Sql.Append(" ( ");
str_Sql.Append(" select top " + (_page - 1) * _pageSize + " id from tb_freight ");
str_Sql.Append(" where ");
str_Sql.Append(_strWhere);
str_Sql.Append(" order by ");
str_Sql.Append(_orderby);
str_Sql.Append(" ) ");
str_Sql.Append(" order by ");
str_Sql.Append(_orderby);
DataSet dst = bp.SelectDataBase("tb_freight", str_Sql.ToString());
//
recordCount = totlePage(showTotal(_strWhere), _pageSize);
return dst;
}
//总页数
public int totlePage(int Total, int PageSize)
{
if (Total % PageSize == 0)
{
return Total / PageSize;
}
else
{
return Total / PageSize + 1;
}
}
//总条数
protected int showTotal(string strSql)
{
BasicPage bp = new BasicPage();
int intTotal = 0;
SqlDataReader myread = bp.getRead("select count(id) as CountId from tb_freight where " + strSql);
if (myread.Read())
{
intTotal = Convert.ToInt32(myread["CountId"].ToString());
}
myread.Close();
return intTotal;
}
/// <summary>
/// 是否存在该记录
/// </summary>
public bool Exists(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(1) from tb_freight");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
return DbHelperSQL.Exists(strSql.ToString(), parameters);
}
/// <summary>
/// 修改一列数据
/// </summary>
public void UpdateField(int id, string strValue)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update tb_freight set " + strValue);
strSql.Append(" where id=" + id);
DbHelperSQL.ExecuteSql(strSql.ToString());
}
#endregion
}
}

+ 201
- 0
App.code/DAL/link.cs View File

@ -0,0 +1,201 @@
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
namespace Basic.DAL
{
/// <summary>
/// 友情链接
/// </summary>
public partial class link
{
/// <summary>
/// 增加一条数据
/// </summary>
public int Add(Basic.Model.link model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into tb_link(");
strSql.Append("paixu,title,class_id,path,url,target,state,remark,add_time)");
strSql.Append(" values (");
strSql.Append("@paixu,@title,@class_id,@path,@url,@target,@state,@remark,@add_time)");
strSql.Append(";select @@IDENTITY");
SqlParameter[] parameters = {
new SqlParameter("@paixu", SqlDbType.Int,10),
new SqlParameter("@title", SqlDbType.NVarChar,255),
new SqlParameter("@class_id", SqlDbType.Int,10),
new SqlParameter("@path", SqlDbType.NVarChar,255),
new SqlParameter("@url", SqlDbType.NVarChar,255),
new SqlParameter("@target", SqlDbType.Int,10),
new SqlParameter("@state", SqlDbType.Int,10),
new SqlParameter("@remark", SqlDbType.NVarChar,500),
new SqlParameter("@add_time", SqlDbType.DateTime,23)};
parameters[0].Value = model.paixu;
parameters[1].Value = model.title;
parameters[2].Value = model.class_id;
parameters[3].Value = model.path;
parameters[4].Value = model.url;
parameters[5].Value = model.target;
parameters[6].Value = model.state;
parameters[7].Value = model.remark;
parameters[8].Value = model.add_time;
object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
if (obj == null)
{
return 0;
}
else
{
return Convert.ToInt32(obj);
}
}
/// <summary>
/// 更新一条数据
/// </summary>
public bool Update(Basic.Model.link model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update tb_link set ");
strSql.Append("paixu=@paixu,");
strSql.Append("title=@title,");
strSql.Append("class_id=@class_id,");
strSql.Append("path=@path,");
strSql.Append("url=@url,");
strSql.Append("target=@target,");
strSql.Append("state=@state,");
strSql.Append("remark=@remark,");
strSql.Append("add_time=@add_time");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@paixu", SqlDbType.Int,10),
new SqlParameter("@title", SqlDbType.NVarChar,255),
new SqlParameter("@class_id", SqlDbType.Int,10),
new SqlParameter("@path", SqlDbType.NVarChar,255),
new SqlParameter("@url", SqlDbType.NVarChar,255),
new SqlParameter("@target", SqlDbType.Int,10),
new SqlParameter("@state", SqlDbType.Int,10),
new SqlParameter("@remark", SqlDbType.NVarChar,500),
new SqlParameter("@add_time", SqlDbType.DateTime,23),
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = model.paixu;
parameters[1].Value = model.title;
parameters[2].Value = model.class_id;
parameters[3].Value = model.path;
parameters[4].Value = model.url;
parameters[5].Value = model.target;
parameters[6].Value = model.state;
parameters[7].Value = model.remark;
parameters[8].Value = model.add_time;
parameters[9].Value = model.id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 删除一条数据
/// </summary>
public bool Delete(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from tb_link");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public Basic.Model.link GetModel(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select top 1 id,paixu,title,class_id,path,url,target,state,remark,add_time from tb_link");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
Basic.Model.link model = new Basic.Model.link();
DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["id"].ToString()))
{
model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["paixu"].ToString()))
{
model.paixu = int.Parse(ds.Tables[0].Rows[0]["paixu"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["title"].ToString()))
{
model.title = ds.Tables[0].Rows[0]["title"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["class_id"].ToString()))
{
model.class_id = int.Parse(ds.Tables[0].Rows[0]["class_id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["path"].ToString()))
{
model.path = ds.Tables[0].Rows[0]["path"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["url"].ToString()))
{
model.url = ds.Tables[0].Rows[0]["url"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["target"].ToString()))
{
model.target = int.Parse(ds.Tables[0].Rows[0]["target"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["state"].ToString()))
{
model.state = int.Parse(ds.Tables[0].Rows[0]["state"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["remark"].ToString()))
{
model.remark = ds.Tables[0].Rows[0]["remark"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["add_time"].ToString()))
{
model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString());
}
return model;
}
else
{
return null;
}
}
/// <summary>
/// 修改一列数据
/// </summary>
public void UpdateField(int id, string strValue)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update tb_link set " + strValue);
strSql.Append(" where id=" + id);
DbHelperSQL.ExecuteSql(strSql.ToString());
}
}
}

+ 388
- 0
App.code/DAL/manager.cs View File

@ -0,0 +1,388 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Data.SqlClient;
/// <summary>
/// 管理员
/// </summary>
namespace Basic.DAL
{
public class manager
{
/// <summary>
/// 获得查询分页数据
/// </summary>
public DataSet GetList(int pageSize, int pageIndex, string strWhere, string filedOrder, out int recordCount)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select * from tb_manager");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
recordCount = Convert.ToInt32(DbHelperSQL.GetSingle(PagingHelper.CreateCountingSql(strSql.ToString())));
return DbHelperSQL.Query(PagingHelper.CreatePagingSql(recordCount, pageSize, pageIndex, strSql.ToString(), filedOrder));
}
/// <summary>
/// 增加一条数据
/// </summary>
public int Add(Model.manager model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into tb_manager(");
strSql.Append("role_id,role_type,shop_id,user_name,user_pwd,real_name,telephone,email,is_lock,add_time)");
strSql.Append(" values (");
strSql.Append("@role_id,@role_type,@shop_id,@user_name,@user_pwd,@real_name,@telephone,@email,@is_lock,@add_time)");
strSql.Append(";select @@IDENTITY");
SqlParameter[] parameters = {
new SqlParameter("@role_id", SqlDbType.Int,10),
new SqlParameter("@role_type", SqlDbType.Int,10),
new SqlParameter("@shop_id", SqlDbType.Int,10),
new SqlParameter("@user_name", SqlDbType.NVarChar,100),
new SqlParameter("@user_pwd", SqlDbType.NVarChar,100),
new SqlParameter("@real_name", SqlDbType.NVarChar,50),
new SqlParameter("@telephone", SqlDbType.NVarChar,30),
new SqlParameter("@email", SqlDbType.NVarChar,30),
new SqlParameter("@is_lock", SqlDbType.Int,10),
new SqlParameter("@add_time", SqlDbType.DateTime,23)};
parameters[0].Value = model.role_id;
parameters[1].Value = model.role_type;
parameters[2].Value = model.shop_id;
parameters[3].Value = model.user_name;
parameters[4].Value = model.user_pwd;
parameters[5].Value = model.real_name;
parameters[6].Value = model.telephone;
parameters[7].Value = model.email;
parameters[8].Value = model.is_lock;
parameters[9].Value = model.add_time;
object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
if (obj == null)
{
return 0;
}
else
{
return Convert.ToInt32(obj);
}
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public Model.manager GetModel(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select top 1 id,role_id,role_type,shop_id,user_name,user_pwd,real_name,telephone,email,is_lock,add_time from tb_manager");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
Model.manager model = new Model.manager();
DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["id"].ToString()))
{
model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["role_id"].ToString()))
{
model.role_id = int.Parse(ds.Tables[0].Rows[0]["role_id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["role_type"].ToString()))
{
model.role_type = int.Parse(ds.Tables[0].Rows[0]["role_type"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["shop_id"].ToString()))
{
model.shop_id = int.Parse(ds.Tables[0].Rows[0]["shop_id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["user_name"].ToString()))
{
model.user_name = ds.Tables[0].Rows[0]["user_name"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["user_pwd"].ToString()))
{
model.user_pwd = ds.Tables[0].Rows[0]["user_pwd"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["real_name"].ToString()))
{
model.real_name = ds.Tables[0].Rows[0]["real_name"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["telephone"].ToString()))
{
model.telephone = ds.Tables[0].Rows[0]["telephone"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["email"].ToString()))
{
model.email = ds.Tables[0].Rows[0]["email"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["is_lock"].ToString()))
{
model.is_lock = int.Parse(ds.Tables[0].Rows[0]["is_lock"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["add_time"].ToString()))
{
model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString());
}
return model;
}
else
{
return null;
}
}
/// <summary>
/// 是否存在该记录
/// </summary>
public bool Exists(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(1) from tb_manager");
strSql.Append(" where id=@id ");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
return DbHelperSQL.Exists(strSql.ToString(), parameters);
}
/// <summary>
/// 更新一条数据
/// </summary>
public bool Update(Model.manager model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update tb_manager set ");
strSql.Append("role_id=@role_id,");
strSql.Append("role_type=@role_type,");
strSql.Append("shop_id=@shop_id,");
strSql.Append("user_name=@user_name,");
strSql.Append("user_pwd=@user_pwd,");
strSql.Append("real_name=@real_name,");
strSql.Append("telephone=@telephone,");
strSql.Append("email=@email,");
strSql.Append("is_lock=@is_lock,");
strSql.Append("add_time=@add_time");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@role_id", SqlDbType.Int,10),
new SqlParameter("@role_type", SqlDbType.Int,10),
new SqlParameter("@shop_id", SqlDbType.Int,10),
new SqlParameter("@user_name", SqlDbType.NVarChar,100),
new SqlParameter("@user_pwd", SqlDbType.NVarChar,100),
new SqlParameter("@real_name", SqlDbType.NVarChar,50),
new SqlParameter("@telephone", SqlDbType.NVarChar,30),
new SqlParameter("@email", SqlDbType.NVarChar,30),
new SqlParameter("@is_lock", SqlDbType.Int,10),
new SqlParameter("@add_time", SqlDbType.DateTime,23),
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = model.role_id;
parameters[1].Value = model.role_type;
parameters[2].Value = model.shop_id;
parameters[3].Value = model.user_name;
parameters[4].Value = model.user_pwd;
parameters[5].Value = model.real_name;
parameters[6].Value = model.telephone;
parameters[7].Value = model.email;
parameters[8].Value = model.is_lock;
parameters[9].Value = model.add_time;
parameters[10].Value = model.id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 删除一条数据
/// </summary>
public bool Delete(int id)
{
List<CommandInfo> sqllist = new List<CommandInfo>();
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from tb_manager_log ");
strSql.Append(" where user_id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
CommandInfo cmd = new CommandInfo(strSql.ToString(), parameters);
sqllist.Add(cmd);
StringBuilder strSql1 = new StringBuilder();
strSql1.Append("delete from tb_manager ");
strSql1.Append(" where id=@id");
SqlParameter[] parameters1 = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters1[0].Value = id;
cmd = new CommandInfo(strSql1.ToString(), parameters1);
sqllist.Add(cmd);
int rowsAffected = DbHelperSQL.ExecuteSqlTran(sqllist);
if (rowsAffected > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 根据用户名密码返回一个实体
/// </summary>
public Model.manager GetModel(string user_name, string user_pwd)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select id from tb_manager");
strSql.Append(" where user_name=@user_name and user_pwd=@user_pwd and is_lock=0");
SqlParameter[] parameters = {
new SqlParameter("@user_name", SqlDbType.NVarChar,100),
new SqlParameter("@user_pwd", SqlDbType.NVarChar,100)};
parameters[0].Value = user_name;
parameters[1].Value = user_pwd;
object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
if (obj != null)
{
return GetModel(Convert.ToInt32(obj));
}
return null;
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public Model.manager GetModel(string username)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select top 1 id,role_id,role_type,shop_id,user_name,user_pwd,real_name,telephone,email,is_lock,add_time from tb_manager");
strSql.Append(" where user_name=@user_name");
SqlParameter[] parameters = {
new SqlParameter("@user_name", SqlDbType.NVarChar,255)};
parameters[0].Value = username;
Model.manager model = new Model.manager();
DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["id"].ToString()))
{
model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["role_id"].ToString()))
{
model.role_id = int.Parse(ds.Tables[0].Rows[0]["role_id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["role_type"].ToString()))
{
model.role_type = int.Parse(ds.Tables[0].Rows[0]["role_type"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["shop_id"].ToString()))
{
model.shop_id = int.Parse(ds.Tables[0].Rows[0]["shop_id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["user_name"].ToString()))
{
model.user_name = ds.Tables[0].Rows[0]["user_name"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["user_pwd"].ToString()))
{
model.user_pwd = ds.Tables[0].Rows[0]["user_pwd"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["real_name"].ToString()))
{
model.real_name = ds.Tables[0].Rows[0]["real_name"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["telephone"].ToString()))
{
model.telephone = ds.Tables[0].Rows[0]["telephone"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["email"].ToString()))
{
model.email = ds.Tables[0].Rows[0]["email"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["is_lock"].ToString()))
{
model.is_lock = int.Parse(ds.Tables[0].Rows[0]["is_lock"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["add_time"].ToString()))
{
model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString());
}
return model;
}
else
{
return null;
}
}
#region
/// <summary>
/// 获得查询分页数据
/// </summary>
public DataSet GetList(string _strWhere, string _orderby, int _pageSize, int _page, out int recordCount)
{
BasicPage bp = new BasicPage();
StringBuilder str_Sql = new StringBuilder();
str_Sql.Append("select top " + _pageSize + " id,user_name,role_id,real_name,shop_id,telephone,email,add_time,is_lock from tb_manager");
str_Sql.Append(" where ");
str_Sql.Append(_strWhere);
str_Sql.Append(" and id not in ");
str_Sql.Append(" ( ");
str_Sql.Append(" select top " + (_page - 1) * _pageSize + " id from tb_manager ");
str_Sql.Append(" where ");
str_Sql.Append(_strWhere);
str_Sql.Append(" order by ");
str_Sql.Append(_orderby);
str_Sql.Append(" ) ");
str_Sql.Append(" order by ");
str_Sql.Append(_orderby);
DataSet dst = bp.SelectDataBase("tb_manager", str_Sql.ToString());
//
recordCount = totlePage(showTotal(_strWhere), _pageSize);
return dst;
}
//总页数
public int totlePage(int Total, int PageSize)
{
if (Total % PageSize == 0)
{
return Total / PageSize;
}
else
{
return Total / PageSize + 1;
}
}
//总条数
protected int showTotal(string strSql)
{
BasicPage bp = new BasicPage();
int intTotal = 0;
SqlDataReader myread = bp.getRead("select count(id) as CountId from tb_manager where " + strSql);
if (myread.Read())
{
intTotal = Convert.ToInt32(myread["CountId"].ToString());
}
myread.Close();
return intTotal;
}
#endregion
}
}

+ 225
- 0
App.code/DAL/manager_log.cs View File

@ -0,0 +1,225 @@
using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Text;
/// <summary>
/// 登录日志
/// </summary>
namespace Basic.DAL
{
public class manager_log
{
/// <summary>
/// 增加一条数据
/// </summary>
public int Add(Model.manager_log model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into tb_manager_log(");
strSql.Append("user_id,user_name,action_type,note,login_ip,login_time)");
strSql.Append(" values (");
strSql.Append("@user_id,@user_name,@action_type,@note,@login_ip,@login_time)");
strSql.Append(";select @@IDENTITY");
SqlParameter user_id = new SqlParameter("@user_id", model.user_id);
SqlParameter user_name = new SqlParameter("@user_name", model.user_name);
SqlParameter action_type = new SqlParameter("@action_type", model.action_type);
SqlParameter note = new SqlParameter("@note", model.note);
SqlParameter login_ip = new SqlParameter("@login_ip", model.login_ip);
SqlParameter login_time = new SqlParameter("@login_time", model.login_time);
SqlParameter[] parameters = new SqlParameter[6]
{
user_id,user_name,action_type,note,login_ip,login_time
};
object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
if (obj == null)
{
return 0;
}
else
{
return Convert.ToInt32(obj);
}
}
/// <summary>
/// 获得查询分页数据
/// </summary>
public DataSet GetList(int pageSize, int pageIndex, string strWhere, string filedOrder, out int recordCount)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select * FROM tb_manager_log");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
recordCount = Convert.ToInt32(DbHelperSQL.GetSingle(PagingHelper.CreateCountingSql(strSql.ToString())));
return DbHelperSQL.Query(PagingHelper.CreatePagingSql(recordCount, pageSize, pageIndex, strSql.ToString(), filedOrder));
}
/// <summary>
/// 删除一条数据
/// </summary>
public bool Delete(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from tb_manager_log ");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 根据用户名返回上一次登录记录
/// </summary>
public Model.manager_log GetModel(string user_name, int top_num, string action_type)
{
int rows = GetCount("user_name='" + user_name + "'");
if (top_num == 1)
{
rows = 2;
}
if (rows > 1)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select top 1 id from (select top " + top_num + " id from tb_manager_log where user_name=@user_name and action_type=@action_type order by id desc) as T ");
strSql.Append(" order by id asc");
SqlParameter[] parameters = {
new SqlParameter("@user_name", SqlDbType.NVarChar,100),
new SqlParameter("@action_type", SqlDbType.NVarChar,100)};
parameters[0].Value = user_name;
parameters[1].Value = action_type;
object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
if (obj != null)
{
return GetModel(Convert.ToInt32(obj));
}
}
return null;
}
/// <summary>
/// 返回数据数
/// </summary>
public int GetCount(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(*) as H ");
strSql.Append(" from tb_manager_log ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
return Convert.ToInt32(DbHelperSQL.GetSingle(strSql.ToString()));
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public Model.manager_log GetModel(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select top 1 id,user_id,user_name,action_type,note,login_ip,login_time from tb_manager_log ");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
Model.manager_log model = new Model.manager_log();
DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows[0]["id"].ToString() != "")
{
model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
}
if (ds.Tables[0].Rows[0]["user_id"].ToString() != "")
{
model.user_id = int.Parse(ds.Tables[0].Rows[0]["user_id"].ToString());
}
model.user_name = ds.Tables[0].Rows[0]["user_name"].ToString();
model.action_type = ds.Tables[0].Rows[0]["action_type"].ToString();
model.note = ds.Tables[0].Rows[0]["note"].ToString();
model.login_ip = ds.Tables[0].Rows[0]["login_ip"].ToString();
if (ds.Tables[0].Rows[0]["login_time"].ToString() != "")
{
model.login_time = DateTime.Parse(ds.Tables[0].Rows[0]["login_time"].ToString());
}
return model;
}
else
{
return null;
}
}
/// <summary>
/// 获得查询分页数据
/// </summary>
public DataSet GetList(string _strWhere, string _orderby, int _pageSize, int _page, out int recordCount)
{
BasicPage bp = new BasicPage();
StringBuilder str_Sql = new StringBuilder();
str_Sql.Append("select top " + _pageSize + " id,user_name,note,login_ip,login_time from tb_manager_log");
str_Sql.Append(" where ");
str_Sql.Append(_strWhere);
str_Sql.Append(" and id not in ");
str_Sql.Append(" ( ");
str_Sql.Append(" select top " + (_page - 1) * _pageSize + " id from tb_manager_log ");
str_Sql.Append(" where ");
str_Sql.Append(_strWhere);
str_Sql.Append(" order by ");
str_Sql.Append(_orderby);
str_Sql.Append(" ) ");
str_Sql.Append(" order by ");
str_Sql.Append(_orderby);
DataSet dst = bp.SelectDataBase("tb_manager_log", str_Sql.ToString());
//
recordCount = totlePage(showTotal(_strWhere), _pageSize);
return dst;
}
//总页数
public int totlePage(int Total, int PageSize)
{
if (Total % PageSize == 0)
{
return Total / PageSize;
}
else
{
return Total / PageSize + 1;
}
}
//总条数
protected int showTotal(string strSql)
{
BasicPage bp = new BasicPage();
int intTotal = 0;
SqlDataReader myread = bp.getRead("select count(id) as CountId from tb_manager_log where " + strSql);
if (myread.Read())
{
intTotal = Convert.ToInt32(myread["CountId"].ToString());
}
myread.Close();
return intTotal;
}
}
}

+ 322
- 0
App.code/DAL/manager_role.cs View File

@ -0,0 +1,322 @@
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Web;
using System.Data;
using System.Text;
/// <summary>
/// 管理员 角色
/// </summary>
namespace Basic.DAL
{
public class manager_role
{
/// <summary>
/// 获得数据列表
/// </summary>
public DataSet GetList(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select id,role_name,role_type ");
strSql.Append(" from tb_manager_role ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
return DbHelperSQL.Query(strSql.ToString());
}
/// <summary>
/// 增加一条数据,及其子表数据
/// </summary>
public int Add(Model.manager_role model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into tb_manager_role(");
strSql.Append("role_name,role_type)");
strSql.Append(" values (");
strSql.Append("@role_name,@role_type)");
strSql.Append(";set @ReturnValue= @@IDENTITY");
SqlParameter[] parameters = {
new SqlParameter("@role_name", SqlDbType.NVarChar,100),
new SqlParameter("@role_type", SqlDbType.TinyInt,1),
new SqlParameter("@ReturnValue",SqlDbType.Int)};
parameters[0].Value = model.role_name;
parameters[1].Value = model.role_type;
parameters[2].Direction = ParameterDirection.Output;
List<CommandInfo> sqllist = new List<CommandInfo>();
CommandInfo cmd = new CommandInfo(strSql.ToString(), parameters);
sqllist.Add(cmd);
StringBuilder strSql2;
foreach (Model.manager_role_value models in model.manager_role_values)
{
strSql2 = new StringBuilder();
strSql2.Append("insert into tb_manager_role_value(");
strSql2.Append("role_id,channel_name,channel_id,action_type)");
strSql2.Append(" values (");
strSql2.Append("@role_id,@channel_name,@channel_id,@action_type)");
SqlParameter[] parameters2 = {
new SqlParameter("@role_id", SqlDbType.Int,4),
new SqlParameter("@channel_name", SqlDbType.NVarChar,255),
new SqlParameter("@channel_id", SqlDbType.Int,4),
new SqlParameter("@action_type", SqlDbType.NVarChar,100)};
parameters2[0].Direction = ParameterDirection.InputOutput;
parameters2[1].Value = models.channel_name;
parameters2[2].Value = models.channel_id;
parameters2[3].Value = models.action_type;
cmd = new CommandInfo(strSql2.ToString(), parameters2);
sqllist.Add(cmd);
}
DbHelperSQL.ExecuteSqlTranWithIndentity(sqllist);
return (int)parameters[2].Value;
}
/// <summary>
/// 是否存在该记录
/// </summary>
public bool Exists(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(1) from tb_manager_role");
strSql.Append(" where id=@id ");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
return DbHelperSQL.Exists(strSql.ToString(), parameters);
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public Model.manager_role GetModel(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select id,role_name,role_type from tb_manager_role ");
strSql.Append(" where id=@id ");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
Model.manager_role model = new Model.manager_role();
DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
#region 父表信息
if (ds.Tables[0].Rows[0]["id"].ToString() != "")
{
model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
}
model.role_name = ds.Tables[0].Rows[0]["role_name"].ToString();
if (ds.Tables[0].Rows[0]["role_type"].ToString() != "")
{
model.role_type = int.Parse(ds.Tables[0].Rows[0]["role_type"].ToString());
}
#endregion 父表信息end
#region 子表信息
StringBuilder strSql2 = new StringBuilder();
strSql2.Append("select id,role_id,channel_name,channel_id,action_type from tb_manager_role_value ");
strSql2.Append(" where role_id=@role_id ");
SqlParameter[] parameters2 = {
new SqlParameter("@role_id", SqlDbType.Int,4)};
parameters2[0].Value = id;
DataSet ds2 = DbHelperSQL.Query(strSql2.ToString(), parameters2);
if (ds2.Tables[0].Rows.Count > 0)
{
#region 子表字段信息
int i = ds2.Tables[0].Rows.Count;
List<Model.manager_role_value> models = new List<Model.manager_role_value>();
Model.manager_role_value modelt;
for (int n = 0; n < i; n++)
{
modelt = new Model.manager_role_value();
if (ds2.Tables[0].Rows[n]["id"].ToString() != "")
{
modelt.id = int.Parse(ds2.Tables[0].Rows[n]["id"].ToString());
}
if (ds2.Tables[0].Rows[n]["role_id"].ToString() != "")
{
modelt.role_id = int.Parse(ds2.Tables[0].Rows[n]["role_id"].ToString());
}
modelt.channel_name = ds2.Tables[0].Rows[n]["channel_name"].ToString();
if (ds2.Tables[0].Rows[n]["channel_id"].ToString() != "")
{
modelt.channel_id = int.Parse(ds2.Tables[0].Rows[n]["channel_id"].ToString());
}
modelt.action_type = ds2.Tables[0].Rows[n]["action_type"].ToString();
models.Add(modelt);
}
model.manager_role_values = models;
#endregion 子表字段信息end
}
#endregion 子表信息end
return model;
}
else
{
return null;
}
}
/// <summary>
/// 更新一条数据及其子表
/// </summary>
public bool Update(Model.manager_role model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update tb_manager_role set ");
strSql.Append("role_name=@role_name,");
strSql.Append("role_type=@role_type");
strSql.Append(" where id=@id ");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4),
new SqlParameter("@role_name", SqlDbType.NVarChar,100),
new SqlParameter("@role_type", SqlDbType.TinyInt,1)};
parameters[0].Value = model.id;
parameters[1].Value = model.role_name;
parameters[2].Value = model.role_type;
List<CommandInfo> sqllist = new List<CommandInfo>();
CommandInfo cmd = new CommandInfo(strSql.ToString(), parameters);
sqllist.Add(cmd);
//删除权限
StringBuilder strSql2 = new StringBuilder();
strSql2.Append("delete from tb_manager_role_value where role_id=@role_id ");
StringBuilder idList = new StringBuilder();
if (model.manager_role_values != null)
{
foreach (Model.manager_role_value models in model.manager_role_values)
{
if (models.id > 0)
{
idList.Append(models.id + ",");
}
}
string id_list = Basic.Tools.Utils.DelLastChar(idList.ToString(), ",");
if (!string.IsNullOrEmpty(id_list))
{
strSql2.Append(" and id not in(" + id_list + ")");
}
}
SqlParameter[] parameters2 = {
new SqlParameter("@role_id", SqlDbType.Int,4)};
parameters2[0].Value = model.id;
cmd = new CommandInfo(strSql2.ToString(), parameters2);
sqllist.Add(cmd);
//添加权限
if (model.manager_role_values != null)
{
StringBuilder strSql3;
foreach (Model.manager_role_value models in model.manager_role_values)
{
strSql3 = new StringBuilder();
if (models.id == 0)
{
strSql3.Append("insert into tb_manager_role_value(");
strSql3.Append("role_id,channel_name,channel_id,action_type)");
strSql3.Append(" values (");
strSql3.Append("@role_id,@channel_name,@channel_id,@action_type)");
SqlParameter[] parameters3 = {
new SqlParameter("@role_id", SqlDbType.Int,4),
new SqlParameter("@channel_name", SqlDbType.NVarChar,255),
new SqlParameter("@channel_id", SqlDbType.Int,4),
new SqlParameter("@action_type", SqlDbType.NVarChar,100)};
parameters3[0].Value = model.id;
parameters3[1].Value = models.channel_name;
parameters3[2].Value = models.channel_id;
parameters3[3].Value = models.action_type;
cmd = new CommandInfo(strSql3.ToString(), parameters3);
sqllist.Add(cmd);
}
}
}
int rowsAffected = DbHelperSQL.ExecuteSqlTran(sqllist);
if (rowsAffected > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 返回角色名称
/// </summary>
public string GetTitle(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select top 1 role_name from tb_manager_role");
strSql.Append(" where id=" + id);
string title = Convert.ToString(DbHelperSQL.GetSingle(strSql.ToString()));
if (string.IsNullOrEmpty(title))
{
return "";
}
return title;
}
/// <summary>
/// 删除一条数据,及子表所有相关数据
/// </summary>
public bool Delete(int id)
{
List<CommandInfo> sqllist = new List<CommandInfo>();
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from tb_manager_role ");
strSql.Append(" where id=@id ");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
CommandInfo cmd = new CommandInfo(strSql.ToString(), parameters);
sqllist.Add(cmd);
StringBuilder strSql2 = new StringBuilder();
strSql2.Append("delete from tb_manager_role_value ");
strSql2.Append(" where role_id=@role_id ");
SqlParameter[] parameters2 = {
new SqlParameter("@role_id", SqlDbType.Int,4)};
parameters2[0].Value = id;
cmd = new CommandInfo(strSql2.ToString(), parameters2);
sqllist.Add(cmd);
int rowsAffected = DbHelperSQL.ExecuteSqlTran(sqllist);
if (rowsAffected > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 获取Role_Type
/// </summary>
/// <param name="id"></param>
public int GetRole_Type(int id)
{
int intRole_Type = 0;
BasicPage bp = new BasicPage();
SqlDataReader myread = bp.getRead("select * from tb_manager_role where id=" + id);
if (myread.Read())
{
intRole_Type = int.Parse(myread["role_type"].ToString());
}
myread.Close();
return intRole_Type;
}
}
}

+ 384
- 0
App.code/DAL/nav.cs View File

@ -0,0 +1,384 @@
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
namespace Basic.DAL
{
/// <summary>
/// 数据访问层nav
/// </summary>
public partial class nav
{
/// <summary>
/// 增加一条数据
/// </summary>
public int Add(Basic.Model.nav model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into tb_nav(");
strSql.Append("paixu,title,class_id,parent_id,class_list,class_layer,path,url,target,state,remark,seo_title,seo_keywords,seo_description,add_time)");
strSql.Append(" values (");
strSql.Append("@paixu,@title,@class_id,@parent_id,@class_list,@class_layer,@path,@url,@target,@state,@remark,@seo_title,@seo_keywords,@seo_description,@add_time)");
strSql.Append(";select @@IDENTITY");
SqlParameter[] parameters = {
new SqlParameter("@paixu", SqlDbType.Int,10),
new SqlParameter("@title", SqlDbType.NVarChar,255),
new SqlParameter("@class_id", SqlDbType.Int,10),
new SqlParameter("@parent_id", SqlDbType.Int,10),
new SqlParameter("@class_list", SqlDbType.NVarChar,500),
new SqlParameter("@class_layer", SqlDbType.Int,10),
new SqlParameter("@path", SqlDbType.NVarChar,255),
new SqlParameter("@url", SqlDbType.NVarChar,255),
new SqlParameter("@target", SqlDbType.Int,10),
new SqlParameter("@state", SqlDbType.Int,10),
new SqlParameter("@remark", SqlDbType.NVarChar,500),
new SqlParameter("@seo_title", SqlDbType.NVarChar,255),
new SqlParameter("@seo_keywords", SqlDbType.NVarChar,255),
new SqlParameter("@seo_description", SqlDbType.NVarChar,255),
new SqlParameter("@add_time", SqlDbType.DateTime,23)};
parameters[0].Value = model.paixu;
parameters[1].Value = model.title;
parameters[2].Value = model.class_id;
parameters[3].Value = model.parent_id;
parameters[4].Value = model.class_list;
parameters[5].Value = model.class_layer;
parameters[6].Value = model.path;
parameters[7].Value = model.url;
parameters[8].Value = model.target;
parameters[9].Value = model.state;
parameters[10].Value = model.remark;
parameters[11].Value = model.seo_title;
parameters[12].Value = model.seo_keywords;
parameters[13].Value = model.seo_description;
parameters[14].Value = model.add_time;
object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
if (obj == null)
{
return 0;
}
else
{
return Convert.ToInt32(obj);
}
}
/// <summary>
/// 更新一条数据
/// </summary>
public bool Update(Basic.Model.nav model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update tb_nav set ");
strSql.Append("paixu=@paixu,");
strSql.Append("title=@title,");
strSql.Append("class_id=@class_id,");
strSql.Append("parent_id=@parent_id,");
strSql.Append("class_list=@class_list,");
strSql.Append("class_layer=@class_layer,");
strSql.Append("path=@path,");
strSql.Append("url=@url,");
strSql.Append("target=@target,");
strSql.Append("state=@state,");
strSql.Append("remark=@remark,");
strSql.Append("seo_title=@seo_title,");
strSql.Append("seo_keywords=@seo_keywords,");
strSql.Append("seo_description=@seo_description,");
strSql.Append("add_time=@add_time");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@paixu", SqlDbType.Int,10),
new SqlParameter("@title", SqlDbType.NVarChar,255),
new SqlParameter("@class_id", SqlDbType.Int,10),
new SqlParameter("@parent_id", SqlDbType.Int,10),
new SqlParameter("@class_list", SqlDbType.NVarChar,500),
new SqlParameter("@class_layer", SqlDbType.Int,10),
new SqlParameter("@path", SqlDbType.NVarChar,255),
new SqlParameter("@url", SqlDbType.NVarChar,255),
new SqlParameter("@target", SqlDbType.Int,10),
new SqlParameter("@state", SqlDbType.Int,10),
new SqlParameter("@remark", SqlDbType.NVarChar,500),
new SqlParameter("@seo_title", SqlDbType.NVarChar,255),
new SqlParameter("@seo_keywords", SqlDbType.NVarChar,255),
new SqlParameter("@seo_description", SqlDbType.NVarChar,255),
new SqlParameter("@add_time", SqlDbType.DateTime,23),
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = model.paixu;
parameters[1].Value = model.title;
parameters[2].Value = model.class_id;
parameters[3].Value = model.parent_id;
parameters[4].Value = model.class_list;
parameters[5].Value = model.class_layer;
parameters[6].Value = model.path;
parameters[7].Value = model.url;
parameters[8].Value = model.target;
parameters[9].Value = model.state;
parameters[10].Value = model.remark;
parameters[11].Value = model.seo_title;
parameters[12].Value = model.seo_keywords;
parameters[13].Value = model.seo_description;
parameters[14].Value = model.add_time;
parameters[15].Value = model.id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 删除一条数据
/// </summary>
public bool Delete(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from tb_nav");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public Basic.Model.nav GetModel(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select top 1 id,paixu,title,class_id,parent_id,class_list,class_layer,path,url,target,state,remark,seo_title,seo_keywords,seo_description,add_time from tb_nav");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
Basic.Model.nav model = new Basic.Model.nav();
DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["id"].ToString()))
{
model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["paixu"].ToString()))
{
model.paixu = int.Parse(ds.Tables[0].Rows[0]["paixu"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["title"].ToString()))
{
model.title = ds.Tables[0].Rows[0]["title"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["class_id"].ToString()))
{
model.class_id = int.Parse(ds.Tables[0].Rows[0]["class_id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["parent_id"].ToString()))
{
model.parent_id = int.Parse(ds.Tables[0].Rows[0]["parent_id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["class_list"].ToString()))
{
model.class_list = ds.Tables[0].Rows[0]["class_list"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["class_layer"].ToString()))
{
model.class_layer = int.Parse(ds.Tables[0].Rows[0]["class_layer"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["path"].ToString()))
{
model.path = ds.Tables[0].Rows[0]["path"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["url"].ToString()))
{
model.url = ds.Tables[0].Rows[0]["url"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["target"].ToString()))
{
model.target = int.Parse(ds.Tables[0].Rows[0]["target"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["state"].ToString()))
{
model.state = int.Parse(ds.Tables[0].Rows[0]["state"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["remark"].ToString()))
{
model.remark = ds.Tables[0].Rows[0]["remark"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["seo_title"].ToString()))
{
model.seo_title = ds.Tables[0].Rows[0]["seo_title"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["seo_keywords"].ToString()))
{
model.seo_keywords = ds.Tables[0].Rows[0]["seo_keywords"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["seo_description"].ToString()))
{
model.seo_description = ds.Tables[0].Rows[0]["seo_description"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["add_time"].ToString()))
{
model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString());
}
return model;
}
else
{
return null;
}
}
/// <summary>
/// 获得前几行数据
/// </summary>
public DataSet GetList(int Top, string strWhere, string filedOrder)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select ");
if (Top > 0)
{
strSql.Append(" top " + Top.ToString());
}
strSql.Append("id,paixu,title,class_id,parent_id,class_list,class_layer,path,url,target,state,remark,seo_title,seo_keywords,seo_description,add_time");
strSql.Append(" from tb_nav");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
strSql.Append(" order by " + filedOrder);
return DbHelperSQL.Query(strSql.ToString());
}
/// <summary>
/// 是否存在该记录
/// </summary>
public bool Exists(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(1) from tb_nav");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
return DbHelperSQL.Exists(strSql.ToString(), parameters);
}
/// <summary>
/// 修改一列数据
/// </summary>
public void UpdateField(int id, string strValue)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update tb_nav set " + strValue);
strSql.Append(" where id=" + id);
DbHelperSQL.ExecuteSql(strSql.ToString());
}
/// <summary>
/// 取得所有类别列表
/// </summary>
/// <param name="parent_id">父ID</param>
/// <param name="class_id">分类ID</param>
/// <returns></returns>
public DataTable GetList(int parent_id, int class_id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select * from tb_nav");
if (class_id > 0)
{
strSql.Append(" where class_id=" + class_id);
}
strSql.Append(" order by paixu desc,id asc");
DataSet ds = DbHelperSQL.Query(strSql.ToString());
DataTable oldData = ds.Tables[0] as DataTable;
if (oldData == null)
{
return null;
}
//复制结构
DataTable newData = oldData.Clone();
//调用迭代组合成DAGATABLE
GetChilds(oldData, newData, parent_id, class_id);
return newData;
}
/// <summary>
/// 从内存中取得所有下级类别列表(自身迭代)
/// </summary>
private void GetChilds(DataTable oldData, DataTable newData, int parent_id, int channel_id)
{
DataRow[] dr = oldData.Select("parent_id=" + parent_id);
for (int i = 0; i < dr.Length; i++)
{
//添加一行数据
DataRow row = newData.NewRow();
row["id"] = int.Parse(dr[i]["id"].ToString());
row["paixu"] = int.Parse(dr[i]["paixu"].ToString());
row["title"] = dr[i]["title"].ToString();
row["class_id"] = int.Parse(dr[i]["class_id"].ToString());
row["parent_id"] = int.Parse(dr[i]["parent_id"].ToString());
row["class_layer"] = int.Parse(dr[i]["class_layer"].ToString());
row["class_list"] = dr[i]["class_list"].ToString();
row["path"] = dr[i]["path"].ToString();
row["url"] = dr[i]["url"].ToString();
row["target"] = int.Parse(dr[i]["target"].ToString());
row["state"] = int.Parse(dr[i]["state"].ToString());
row["remark"] = dr[i]["remark"].ToString();
row["seo_title"] = dr[i]["seo_title"].ToString();
row["seo_keywords"] = dr[i]["seo_keywords"].ToString();
row["seo_description"] = dr[i]["seo_description"].ToString();
row["add_time"] = DateTime.Parse(dr[i]["add_time"].ToString());
newData.Rows.Add(row);
//调用自身迭代
this.GetChilds(oldData, newData, int.Parse(dr[i]["id"].ToString()), channel_id);
}
}
/// <summary>
/// 返回第一个class_id
/// </summary>
public int GetClass_Id()
{
int class_id = 0;
BasicPage bp = new BasicPage();
SqlDataReader myread = bp.getRead("select top 1 class_id from tb_nav");
if (myread.Read())
{
class_id = int.Parse(myread[0].ToString());
}
myread.Close();
return class_id;
}
/// <summary>
/// 返回导航链接
/// </summary>
//public string GetNav(int _id)
//{
// int class_id = 0;
// BasicPage bp = new BasicPage();
// SqlDataReader myread = bp.getRead("select top 1 class_id from tb_nav");
// if (myread.Read())
// {
// class_id = int.Parse(myread[0].ToString());
// }
// myread.Close();
// return class_id;
//}
}
}

+ 307
- 0
App.code/DAL/news.cs View File

@ -0,0 +1,307 @@
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
namespace Basic.DAL
{
/// <summary>
/// 新闻
/// </summary>
public partial class news
{
/// <summary>
/// 增加一条数据
/// </summary>
public int Add(Basic.Model.news model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into tb_news(");
strSql.Append("class_id,parent_id,guid,title,url,path,seo_title,seo_keywords,seo_description,content,paixu,hits,status,user_id,add_time)");
strSql.Append(" values (");
strSql.Append("@class_id,@parent_id,@guid,@title,@url,@path,@seo_title,@seo_keywords,@seo_description,@content,@paixu,@hits,@status,@user_id,@add_time)");
strSql.Append(";select @@IDENTITY");
SqlParameter[] parameters = {
new SqlParameter("@class_id", SqlDbType.Int,10),
new SqlParameter("@parent_id", SqlDbType.Int,10),
new SqlParameter("@guid", SqlDbType.NVarChar,50),
new SqlParameter("@title", SqlDbType.NVarChar,100),
new SqlParameter("@url", SqlDbType.NVarChar,255),
new SqlParameter("@path", SqlDbType.NVarChar,255),
new SqlParameter("@seo_title", SqlDbType.NVarChar,255),
new SqlParameter("@seo_keywords", SqlDbType.NVarChar,255),
new SqlParameter("@seo_description", SqlDbType.NVarChar,255),
new SqlParameter("@content", SqlDbType.NText,1073741823),
new SqlParameter("@paixu", SqlDbType.Int,10),
new SqlParameter("@hits", SqlDbType.Int,10),
new SqlParameter("@status", SqlDbType.Int,10),
new SqlParameter("@user_id", SqlDbType.Int,10),
new SqlParameter("@add_time", SqlDbType.DateTime,23)};
parameters[0].Value = model.class_id;
parameters[1].Value = model.parent_id;
parameters[2].Value = model.guid;
parameters[3].Value = model.title;
parameters[4].Value = model.url;
parameters[5].Value = model.path;
parameters[6].Value = model.seo_title;
parameters[7].Value = model.seo_keywords;
parameters[8].Value = model.seo_description;
parameters[9].Value = model.content;
parameters[10].Value = model.paixu;
parameters[11].Value = model.hits;
parameters[12].Value = model.status;
parameters[13].Value = model.user_id;
parameters[14].Value = model.add_time;
object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
if (obj == null)
{
return 0;
}
else
{
return Convert.ToInt32(obj);
}
}
/// <summary>
/// 更新一条数据
/// </summary>
public bool Update(Basic.Model.news model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update tb_news set ");
strSql.Append("class_id=@class_id,");
strSql.Append("parent_id=@parent_id,");
strSql.Append("guid=@guid,");
strSql.Append("title=@title,");
strSql.Append("url=@url,");
strSql.Append("path=@path,");
strSql.Append("seo_title=@seo_title,");
strSql.Append("seo_keywords=@seo_keywords,");
strSql.Append("seo_description=@seo_description,");
strSql.Append("content=@content,");
strSql.Append("paixu=@paixu,");
strSql.Append("hits=@hits,");
strSql.Append("status=@status,");
strSql.Append("user_id=@user_id,");
strSql.Append("add_time=@add_time");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@class_id", SqlDbType.Int,10),
new SqlParameter("@parent_id", SqlDbType.Int,10),
new SqlParameter("@guid", SqlDbType.NVarChar,50),
new SqlParameter("@title", SqlDbType.NVarChar,100),
new SqlParameter("@url", SqlDbType.NVarChar,255),
new SqlParameter("@path", SqlDbType.NVarChar,255),
new SqlParameter("@seo_title", SqlDbType.NVarChar,255),
new SqlParameter("@seo_keywords", SqlDbType.NVarChar,255),
new SqlParameter("@seo_description", SqlDbType.NVarChar,255),
new SqlParameter("@content", SqlDbType.NText,1073741823),
new SqlParameter("@paixu", SqlDbType.Int,10),
new SqlParameter("@hits", SqlDbType.Int,10),
new SqlParameter("@status", SqlDbType.Int,10),
new SqlParameter("@user_id", SqlDbType.Int,10),
new SqlParameter("@add_time", SqlDbType.DateTime,23),
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = model.class_id;
parameters[1].Value = model.parent_id;
parameters[2].Value = model.guid;
parameters[3].Value = model.title;
parameters[4].Value = model.url;
parameters[5].Value = model.path;
parameters[6].Value = model.seo_title;
parameters[7].Value = model.seo_keywords;
parameters[8].Value = model.seo_description;
parameters[9].Value = model.content;
parameters[10].Value = model.paixu;
parameters[11].Value = model.hits;
parameters[12].Value = model.status;
parameters[13].Value = model.user_id;
parameters[14].Value = model.add_time;
parameters[15].Value = model.id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 删除一条数据
/// </summary>
public bool Delete(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from tb_news");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public Basic.Model.news GetModel(int id)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select top 1 id,class_id,parent_id,guid,title,url,path,seo_title,seo_keywords,seo_description,content,paixu,hits,status,user_id,add_time from tb_news");
strSql.Append(" where id=@id");
SqlParameter[] parameters = {
new SqlParameter("@id", SqlDbType.Int,4)};
parameters[0].Value = id;
Basic.Model.news model = new Basic.Model.news();
DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["id"].ToString()))
{
model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["class_id"].ToString()))
{
model.class_id = int.Parse(ds.Tables[0].Rows[0]["class_id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["parent_id"].ToString()))
{
model.parent_id = int.Parse(ds.Tables[0].Rows[0]["parent_id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["guid"].ToString()))
{
model.guid = ds.Tables[0].Rows[0]["guid"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["title"].ToString()))
{
model.title = ds.Tables[0].Rows[0]["title"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["url"].ToString()))
{
model.url = ds.Tables[0].Rows[0]["url"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["path"].ToString()))
{
model.path = ds.Tables[0].Rows[0]["path"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["seo_title"].ToString()))
{
model.seo_title = ds.Tables[0].Rows[0]["seo_title"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["seo_keywords"].ToString()))
{
model.seo_keywords = ds.Tables[0].Rows[0]["seo_keywords"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["seo_description"].ToString()))
{
model.seo_description = ds.Tables[0].Rows[0]["seo_description"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["content"].ToString()))
{
model.content = ds.Tables[0].Rows[0]["content"].ToString();
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["paixu"].ToString()))
{
model.paixu = int.Parse(ds.Tables[0].Rows[0]["paixu"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["hits"].ToString()))
{
model.hits = int.Parse(ds.Tables[0].Rows[0]["hits"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["status"].ToString()))
{
model.status = int.Parse(ds.Tables[0].Rows[0]["status"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["user_id"].ToString()))
{
model.user_id = int.Parse(ds.Tables[0].Rows[0]["user_id"].ToString());
}
if (!string.IsNullOrEmpty(ds.Tables[0].Rows[0]["add_time"].ToString()))
{
model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString());
}
return model;
}
else
{
return null;
}
}
/// <summary>
/// 获得查询分页数据
/// </summary>
public DataSet GetList(string _strWhere, string _orderby, int _pageSize, int _page, out int recordCount)
{
BasicPage bp = new BasicPage();
StringBuilder str_Sql = new StringBuilder();
str_Sql.Append("select top " + _pageSize + " * from tb_news");
str_Sql.Append(" where ");
str_Sql.Append(_strWhere);
str_Sql.Append(" and id not in ");
str_Sql.Append(" ( ");
str_Sql.Append(" select top " + (_page - 1) * _pageSize + " id from tb_news ");
str_Sql.Append(" where ");
str_Sql.Append(_strWhere);
str_Sql.Append(" order by ");
str_Sql.Append(_orderby);
str_Sql.Append(" ) ");
str_Sql.Append(" order by ");
str_Sql.Append(_orderby);
DataSet dst = bp.SelectDataBase("tb_news", str_Sql.ToString());
//
recordCount = totlePage(showTotal(_strWhere), _pageSize);
return dst;
}
//总页数
public int totlePage(int Total, int PageSize)
{
if (Total % PageSize == 0)
{
return Total / PageSize;
}
else
{
return Total / PageSize + 1;
}
}
//总条数
protected int showTotal(string strSql)
{
BasicPage bp = new BasicPage();
int intTotal = 0;
SqlDataReader myread = bp.getRead("select count(id) as CountId from tb_news where " + strSql);
if (myread.Read())
{
intTotal = Convert.ToInt32(myread["CountId"].ToString());
}
myread.Close();
return intTotal;
}
/// <summary>
/// 修改一列数据
/// </summary>
public void UpdateField(int id, string strValue)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update tb_news set " + strValue);
strSql.Append(" where id=" + id);
DbHelperSQL.ExecuteSql(strSql.ToString());
}
}
}

Loading…
Cancel
Save