Home > Database > Mysql Tutorial > 我的c#代码生成器(生成SQL2005的和ACCESS的)

我的c#代码生成器(生成SQL2005的和ACCESS的)

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 15:11:02
Original
1327 people have browsed it

生成 内容 1.ACCESS 2.net2.0的泛型操作的 3.。net3.5-4.0的linq to entity 生成 的net2.0 代码 MODEL using System;using System.Collections.Generic;namespace ChineseCode.Bll{public class News{/// summary/// /// /summarypublic int NewsId{set;get;

 生成内容

1.ACCESS

2.net2.0的泛型操作的

3.。net3.5-4.0的linq to entity

 

生成的net2.0代码

MODEL

 
Copy after login

using System;
using System.Collections.Generic;
namespace ChineseCode.Bll
{
	public class News
	{
		/// <summary>
		/// 
		/// </summary>
		public int NewsId
		{
			set;
			get;
		}
		/// <summary>
		/// 
		/// </summary>
		public int UserID
		{
			set;
			get;
		}
		/// <summary>
		/// 
		/// </summary>
		public int TypeID
		{
			set;
			get;
		}
		/// <summary>
		/// 
		/// </summary>
		public string Author
		{
			set;
			get;
		}
		/// <summary>
		/// 
		/// </summary>
		public string Title
		{
			set;
			get;
		}
		/// <summary>
		/// 
		/// </summary>
		public string Excerpts
		{
			set;
			get;
		}
		/// <summary>
		/// 
		/// </summary>
		public string Body
		{
			set;
			get;
		}
		/// <summary>
		/// 
		/// </summary>
		public string Image
		{
			set;
			get;
		}
		/// <summary>
		/// 
		/// </summary>
		public int Views
		{
			set;
			get;
		}
		/// <summary>
		/// 
		/// </summary>
		public bool IsApprived
		{
			set;
			get;
		}
		/// <summary>
		/// 
		/// </summary>
		public bool CheckResult
		{
			set;
			get;
		}
		/// <summary>
		/// 
		/// </summary>
		public int DisplayOrder
		{
			set;
			get;
		}
		/// <summary>
		/// 
		/// </summary>
		public bool IsCommend
		{
			set;
			get;
		}
		/// <summary>
		/// 
		/// </summary>
		public string Sourse
		{
			set;
			get;
		}
		/// <summary>
		/// 
		/// </summary>
		public DateTime CreateDate
		{
			set;
			get;
		}
		/// <summary>
		/// 
		/// </summary>
		public string PostIP
		{
			set;
			get;
		}
		/// <summary>
		/// 
		/// </summary>
		public DateTime? UpdateDate
		{
			set;
			get;
		}
		/// <summary>
		///获取单个模型 
		/// </summary>
		private Users _Users;
		public Users Users
		{
			get
			{
				if (_Users == null)
				{
					_Users = UsersManager.GetModel(this.UserID);
					return _Users;
				}
				return _Users;
			}
		}

		/// <summary>
		///获取单个模型 
		/// </summary>
		private NewsType _NewsType;
		public NewsType NewsType
		{
			get
			{
				if (_NewsType == null)
				{
					_NewsType = NewsTypeManager.GetModel(this.TypeID);
					return _NewsType;
				}
				return _NewsType;
			}
		}

	}
}
Copy after login


BLL

<pre class="html" name="code">using System;
using System.Collections.Generic;
using System.Text;
using JrdLibrary;
using System.Data;
using System.Data.SqlClient;
namespace ChineseCode.Bll
{
	public class NewsManager
	{
	#region 获取实体方法
		/// <summary>
		/// 获取一个实体类
		/// </summary>
		public static News GetModel(SqlDataReader reader)
		{
			return SqlDataReaderExt.ReaderToModel<News>(reader);
		}

		/// <summary>
		/// 获取一个实体类集合
		/// </summary>
		public static List<News> GetList(SqlDataReader reader)
		{
			return SqlDataReaderExt.ReaderToList<News>(reader);
		}

#endregion

		/// <summary>
		/// 创建一个有默认值的Model
		/// </summary>
		public static News CreateModel()
		{
			News model = new News();
			model.Views = 0;
			model.IsApprived = true;
			model.CheckResult = true;
			model.DisplayOrder = 0;
			model.IsCommend = false;
			model.CreateDate = DateTime.Now;
			return model;
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public static int Insert(News model)
		{
			StringBuilder strSql = new StringBuilder();
			strSql.Append("insert into Jrd_News(");
			strSql.Append("UserID,TypeID,Author,Title,Excerpts,Body,Image,Views,IsApprived,CheckResult,DisplayOrder,IsCommend,Sourse,CreateDate,PostIP)");
			strSql.Append(" values (");
			strSql.Append("@UserID,@TypeID,@Author,@Title,@Excerpts,@Body,@Image,@Views,@IsApprived,@CheckResult,@DisplayOrder,@IsCommend,@Sourse,@CreateDate,@PostIP)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
			new SqlParameter("@UserID", SqlDbType.Int,4),
			new SqlParameter("@TypeID", SqlDbType.Int,4),
			new SqlParameter("@Author",SqlDbType.NVarChar,100),
			new SqlParameter("@Title",SqlDbType.NVarChar,400),
			new SqlParameter("@Excerpts",SqlDbType.NVarChar,1000),
			new SqlParameter("@Body",SqlDbType.NText),
			new SqlParameter("@Image",SqlDbType.VarChar,100),
			new SqlParameter("@Views", SqlDbType.Int,4),
			new SqlParameter("@IsApprived",SqlDbType.Bit,1),
			new SqlParameter("@CheckResult",SqlDbType.Bit,1),
			new SqlParameter("@DisplayOrder", SqlDbType.Int,4),
			new SqlParameter("@IsCommend",SqlDbType.Bit,1),
			new SqlParameter("@Sourse",SqlDbType.NVarChar,200),
			new SqlParameter("@CreateDate",SqlDbType.DateTime),
			new SqlParameter("@PostIP",SqlDbType.VarChar,20)
			};
			parameters[0].Value = model.UserID;
			parameters[1].Value = model.TypeID;
			parameters[2].Value = model.Author;
			parameters[3].Value = model.Title;
			parameters[4].Value = model.Excerpts;
			parameters[5].Value = model.Body;
			parameters[6].Value = model.Image;
			parameters[7].Value = model.Views;
			parameters[8].Value = model.IsApprived;
			parameters[9].Value = model.CheckResult;
			parameters[10].Value = model.DisplayOrder;
			parameters[11].Value = model.IsCommend;
			parameters[12].Value = model.Sourse;
			parameters[13].Value = model.CreateDate;
			parameters[14].Value = model.PostIP;
			object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}

		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public static bool Update(News model)
		{
			StringBuilder strSql = new StringBuilder();
			strSql.Append("update Jrd_News set ");
			strSql.Append("UserID=@userID,TypeID=@typeID,Author=@author,Title=@title,Excerpts=@excerpts,Body=@body,Image=@image,Views=@views,IsApprived=@isApprived,CheckResult=@checkResult,DisplayOrder=@displayOrder,IsCommend=@isCommend,Sourse=@sourse,PostIP=@postIP,UpdateDate=@updateDate ");
			strSql.Append(" where NewsId=@NewsId");
			SqlParameter[] parameters = {
			new SqlParameter("@UserID", SqlDbType.Int,4),
			new SqlParameter("@TypeID", SqlDbType.Int,4),
			new SqlParameter("@Author",SqlDbType.NVarChar,100),
			new SqlParameter("@Title",SqlDbType.NVarChar,400),
			new SqlParameter("@Excerpts",SqlDbType.NVarChar,1000),
			new SqlParameter("@Body",SqlDbType.NText),
			new SqlParameter("@Image",SqlDbType.VarChar,100),
			new SqlParameter("@Views", SqlDbType.Int,4),
			new SqlParameter("@IsApprived",SqlDbType.Bit,1),
			new SqlParameter("@CheckResult",SqlDbType.Bit,1),
			new SqlParameter("@DisplayOrder", SqlDbType.Int,4),
			new SqlParameter("@IsCommend",SqlDbType.Bit,1),
			new SqlParameter("@Sourse",SqlDbType.NVarChar,200),
			new SqlParameter("@PostIP",SqlDbType.VarChar,20),
			new SqlParameter("@UpdateDate",SqlDbType.DateTime),
			new SqlParameter("@NewsId", SqlDbType.Int,4)
			};
			parameters[0].Value = model.UserID;
			parameters[1].Value = model.TypeID;
			parameters[2].Value = model.Author;
			parameters[3].Value = model.Title;
			parameters[4].Value = model.Excerpts;
			parameters[5].Value = model.Body;
			parameters[6].Value = model.Image;
			parameters[7].Value = model.Views;
			parameters[8].Value = model.IsApprived;
			parameters[9].Value = model.CheckResult;
			parameters[10].Value = model.DisplayOrder;
			parameters[11].Value = model.IsCommend;
			parameters[12].Value = model.Sourse;
			parameters[13].Value = model.PostIP;
			parameters[14].Value = model.UpdateDate;
			parameters[15].Value = model.NewsId;
			int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
			if (rows > 0)
			{
				return true;
			}
				else
			{
			return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public static bool Delete(int newsId)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from Jrd_News ");
			strSql.Append(" where NewsId=@NewsId");
			SqlParameter[] parameters = {
				new SqlParameter("@NewsId", SqlDbType.Int,4)
			};
			parameters[0].Value = newsId;
			int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public static bool Exists(int newsId)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from Jrd_News");
			strSql.Append(" where NewsId=@NewsId");
			SqlParameter[] parameters = {
				new SqlParameter("@NewsId", SqlDbType.Int,4)
			};
			parameters[0].Value = newsId;
			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public static News GetModel(int newsId)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 NewsId,UserID,TypeID,Author,Title,Excerpts,Body,Image,Views,IsApprived,CheckResult,DisplayOrder,IsCommend,Sourse,CreateDate,PostIP from Jrd_News ");
			strSql.Append(" where NewsId=@NewsId");
			SqlParameter[] parameters = {
				new SqlParameter("@NewsId", SqlDbType.Int,4)
			};
			parameters[0].Value = newsId;
			return GetModel(DbHelperSQL.ExecuteReader(strSql.ToString(),parameters));
		}

		/// <summary>
		/// 获得全部数据
		/// </summary>
		public static List<News> GetAll()
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select NewsId,UserID,TypeID,Author,Title,Excerpts,Body,Image,Views,IsApprived,CheckResult,DisplayOrder,IsCommend,Sourse,CreateDate,PostIP ");
			strSql.Append(" FROM Jrd_News ");
			return GetList(DbHelperSQL.ExecuteReader(strSql.ToString(),null));
		}

		/// <summary>
		///根据UserID获取列表 
		/// </summary>
		public static List<News> GetNewsByUserID(string andStr,int userID, int PageSize,int PageCurrent,string FdOrder,  ref int totalCount)
		{
			SqlQuery query = new SqlQuery();
			query.Add("UserID", userID, QueryOperator.Equal);
			return GetPager(query.GetWhere + andStr, PageSize, PageCurrent, FdOrder, SortType.DESC, ref totalCount);
		}

		/// <summary>
		///根据TypeID获取列表 
		/// </summary>
		public static List<News> GetNewsByTypeID(string andStr,int typeID, int PageSize,int PageCurrent,string FdOrder,  ref int totalCount)
		{
			SqlQuery query = new SqlQuery();
			query.Add("TypeID", typeID, QueryOperator.Equal);
			return GetPager(query.GetWhere + andStr, PageSize, PageCurrent, FdOrder, SortType.DESC, ref totalCount);
		}

		/// <summary>
		/// 根据排序分页获取数据列表
		/// </summary>
		public static List<News> GetPagerByDisplayOrder(string strWhere, int PageSize, int PageCurrent,SortType sort, ref int RecordCount)
		{
			return GetPager(strWhere, PageSize, PageCurrent, "DisplayOrder" , sort, ref RecordCount);
		}

		/// <summary>
		/// 根据浏览分页获取数据列表
		/// </summary>
		public static List<News> GetPagerByViews(string strWhere, int PageSize, int PageCurrent, SortType sort, ref int RecordCount)
		{
			return GetPager(strWhere, PageSize, PageCurrent, "Views" , sort, ref RecordCount);
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public static List<News> GetPager(string strWhere, int PageSize, int PageCurrent, string FdOrder,SortType sort, ref int RecordCount)
		{
			string sqlStr="select cast(NewsId as int) as NewsId,UserID,TypeID,Author,Title,Excerpts,Body,Image,Views,IsApprived,CheckResult,DisplayOrder,IsCommend,Sourse,CreateDate,PostIP,UpdateDate from  Jrd_News ";
			if (string.IsNullOrEmpty(FdOrder) || FdOrder == "")
				FdOrder ="NewsId Desc";
			else
				FdOrder = FdOrder + " " + sort.ToString();
			return GetList(PagerBll.GetPagerReader(sqlStr + strWhere, PageSize, PageCurrent, "", FdOrder, ref RecordCount));
		}

	}
}
Copy after login

Copy after login



 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template