/**  版本信息模板在安装目录下，可自行修改。
* customer.cs
*
* 功 能： N/A
* 类 名： customer
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2024-07-27 10:51:14   N/A    初版
*
* Copyright (c) 2012 Maticsoft Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：动软卓越（北京）科技有限公司　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;
using Maticsoft.DBUtility;//Please add references
namespace Jpsoft.DAL
{
	/// <summary>
	/// 数据访问类:customer
	/// </summary>
	public partial class Customer
	{
		public Customer()
		{}
		#region  BasicMethod

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string id_)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from base_customer");
			strSql.Append(" where id_=@id_ ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@id_", MySqlDbType.VarChar,36)			};
			parameters[0].Value = id_;

			return DbHelperMySQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(Jpsoft.Model.Customer model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into base_customer(");
			strSql.Append("id_,company_,name_,phone_,del_flag,create_by,create_time,update_by,update_time)");
			strSql.Append(" values (");
			strSql.Append("@id_,@company_,@name_,@phone_,@del_flag,@create_by,@create_time,@update_by,@update_time)");
			MySqlParameter[] parameters = {
					new MySqlParameter("@id_", MySqlDbType.VarChar,36),
					new MySqlParameter("@company_", MySqlDbType.VarChar,100),
					new MySqlParameter("@name_", MySqlDbType.VarChar,100),
					new MySqlParameter("@phone_", MySqlDbType.VarChar,100),
					new MySqlParameter("@del_flag", MySqlDbType.Bit),
					new MySqlParameter("@create_by", MySqlDbType.VarChar,36),
					new MySqlParameter("@create_time", MySqlDbType.Timestamp),
					new MySqlParameter("@update_by", MySqlDbType.VarChar,36),
					new MySqlParameter("@update_time", MySqlDbType.Timestamp)};
			parameters[0].Value = model.id_;
			parameters[1].Value = model.company_;
			parameters[2].Value = model.name_;
			parameters[3].Value = model.phone_;
			parameters[4].Value = model.del_flag;
			parameters[5].Value = model.create_by;
			parameters[6].Value = model.create_time;
			parameters[7].Value = model.update_by;
			parameters[8].Value = model.update_time;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Jpsoft.Model.Customer model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update base_customer set ");
			strSql.Append("company_=@company_,");
			strSql.Append("name_=@name_,");
			strSql.Append("phone_=@phone_,");
			strSql.Append("del_flag=@del_flag,");
			strSql.Append("create_by=@create_by,");
			strSql.Append("update_by=@update_by");
			strSql.Append(" where id_=@id_ ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@company_", MySqlDbType.VarChar,100),
					new MySqlParameter("@name_", MySqlDbType.VarChar,100),
					new MySqlParameter("@phone_", MySqlDbType.VarChar,100),
					new MySqlParameter("@del_flag", MySqlDbType.Bit),
					new MySqlParameter("@create_by", MySqlDbType.VarChar,36),
					new MySqlParameter("@update_by", MySqlDbType.VarChar,36),
					new MySqlParameter("@id_", MySqlDbType.VarChar,36)};
			parameters[0].Value = model.company_;
			parameters[1].Value = model.name_;
			parameters[2].Value = model.phone_;
			parameters[3].Value = model.del_flag;
			parameters[4].Value = model.create_by;
			parameters[5].Value = model.update_by;
			parameters[6].Value = model.id_;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string id_)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from base_customer ");
			strSql.Append(" where id_=@id_ ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@id_", MySqlDbType.VarChar,36)			};
			parameters[0].Value = id_;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string id_list )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from base_customer ");
			strSql.Append(" where id_ in ("+id_list + ")  ");
			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Jpsoft.Model.Customer GetModel(string id_)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select id_,company_,name_,phone_,del_flag,create_by,create_time,update_by,update_time from base_customer ");
			strSql.Append(" where id_=@id_ ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@id_", MySqlDbType.VarChar,36)			};
			parameters[0].Value = id_;

			Jpsoft.Model.Customer model=new Jpsoft.Model.Customer();
			DataSet ds=DbHelperMySQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Jpsoft.Model.Customer DataRowToModel(DataRow row)
		{
			Jpsoft.Model.Customer model=new Jpsoft.Model.Customer();
			if (row != null)
			{
				if(row["id_"]!=null)
				{
					model.id_=row["id_"].ToString();
				}
				if(row["company_"]!=null)
				{
					model.company_=row["company_"].ToString();
				}
				if(row["name_"]!=null)
				{
					model.name_=row["name_"].ToString();
				}
				if(row["phone_"]!=null)
				{
					model.phone_=row["phone_"].ToString();
				}
				if(row["del_flag"]!=null && row["del_flag"].ToString()!="")
				{
					if((row["del_flag"].ToString()=="1")||(row["del_flag"].ToString().ToLower()=="true"))
					{
						model.del_flag=true;
					}
					else
					{
						model.del_flag=false;
					}
				}
				if(row["create_by"]!=null)
				{
					model.create_by=row["create_by"].ToString();
				}
				if(row["create_time"]!=null && row["create_time"].ToString()!="")
				{
					model.create_time=DateTime.Parse(row["create_time"].ToString());
				}
				if(row["update_by"]!=null)
				{
					model.update_by=row["update_by"].ToString();
				}
				if(row["update_time"]!=null && row["update_time"].ToString()!="")
				{
					model.update_time=DateTime.Parse(row["update_time"].ToString());
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select id_,company_,name_,phone_,del_flag,create_by,create_time,update_by,update_time ");
			strSql.Append(" FROM base_customer ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM base_customer ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperMySQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.id_ desc");
			}
			strSql.Append(")AS Row, T.*  from base_customer T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			MySqlParameter[] parameters = {
					new MySqlParameter("@tblName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@fldName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@PageSize", MySqlDbType.Int32),
					new MySqlParameter("@PageIndex", MySqlDbType.Int32),
					new MySqlParameter("@IsReCount", MySqlDbType.Bit),
					new MySqlParameter("@OrderType", MySqlDbType.Bit),
					new MySqlParameter("@strWhere", MySqlDbType.VarChar,1000),
					};
			parameters[0].Value = "base_customer";
			parameters[1].Value = "id_";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperMySQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

