/**  版本信息模板在安装目录下，可自行修改。
* account.cs
*
* 功 能： N/A
* 类 名： account
*
* 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>
	/// 数据访问类:account
	/// </summary>
	public partial class Account
	{
		public Account()
		{}
		#region  BasicMethod

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string id_)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from base_account");
			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.Account model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into base_account(");
			strSql.Append("id_,customer_id,work_id,type_,plan_number,actual_amount,cloth_amount,roll_amount,total_amount,del_flag,create_by,create_time,update_by,update_time)");
			strSql.Append(" values (");
			strSql.Append("@id_,@customer_id,@work_id,@type_,@plan_number,@actual_amount,@cloth_amount,@roll_amount,@total_amount,@del_flag,@create_by,@create_time,@update_by,@update_time)");
			MySqlParameter[] parameters = {
					new MySqlParameter("@id_", MySqlDbType.VarChar,36),
					new MySqlParameter("@customer_id", MySqlDbType.VarChar,36),
					new MySqlParameter("@work_id", MySqlDbType.VarChar,36),
					new MySqlParameter("@type_", MySqlDbType.Int32,1),
					new MySqlParameter("@plan_number", MySqlDbType.VarChar,255),
					new MySqlParameter("@actual_amount", MySqlDbType.Decimal,10),
					new MySqlParameter("@cloth_amount", MySqlDbType.Decimal,10),
					new MySqlParameter("@roll_amount", MySqlDbType.Decimal,10),
					new MySqlParameter("@total_amount", MySqlDbType.Decimal,10),
					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.customer_id;
			parameters[2].Value = model.work_id;
			parameters[3].Value = model.type_;
			parameters[4].Value = model.plan_number;
			parameters[5].Value = model.actual_amount;
			parameters[6].Value = model.cloth_amount;
			parameters[7].Value = model.roll_amount;
			parameters[8].Value = model.total_amount;
			parameters[9].Value = model.del_flag;
			parameters[10].Value = model.create_by;
			parameters[11].Value = model.create_time;
			parameters[12].Value = model.update_by;
			parameters[13].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.Account model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update base_account set ");
			strSql.Append("customer_id=@customer_id,");
			strSql.Append("work_id=@work_id,");
			strSql.Append("type_=@type_,");
			strSql.Append("plan_number=@plan_number,");
			strSql.Append("actual_amount=@actual_amount,");
			strSql.Append("cloth_amount=@cloth_amount,");
			strSql.Append("roll_amount=@roll_amount,");
			strSql.Append("total_amount=@total_amount,");
			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("@customer_id", MySqlDbType.VarChar,36),
					new MySqlParameter("@work_id", MySqlDbType.VarChar,36),
					new MySqlParameter("@type_", MySqlDbType.Int32,1),
					new MySqlParameter("@plan_number", MySqlDbType.VarChar,255),
					new MySqlParameter("@actual_amount", MySqlDbType.Decimal,10),
					new MySqlParameter("@cloth_amount", MySqlDbType.Decimal,10),
					new MySqlParameter("@roll_amount", MySqlDbType.Decimal,10),
					new MySqlParameter("@total_amount", MySqlDbType.Decimal,10),
					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.customer_id;
			parameters[1].Value = model.work_id;
			parameters[2].Value = model.type_;
			parameters[3].Value = model.plan_number;
			parameters[4].Value = model.actual_amount;
			parameters[5].Value = model.cloth_amount;
			parameters[6].Value = model.roll_amount;
			parameters[7].Value = model.total_amount;
			parameters[8].Value = model.del_flag;
			parameters[9].Value = model.create_by;
			parameters[10].Value = model.update_by;
			parameters[11].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_account ");
			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_account ");
			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.Account GetModel(string id_)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select id_,customer_id,work_id,type_,plan_number,actual_amount,cloth_amount,roll_amount,total_amount,del_flag,create_by,create_time,update_by,update_time from base_account ");
			strSql.Append(" where id_=@id_ ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@id_", MySqlDbType.VarChar,36)			};
			parameters[0].Value = id_;

			Jpsoft.Model.Account model=new Jpsoft.Model.Account();
			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.Account DataRowToModel(DataRow row)
		{
			Jpsoft.Model.Account model=new Jpsoft.Model.Account();
			if (row != null)
			{
				if(row["id_"]!=null)
				{
					model.id_=row["id_"].ToString();
				}
				if(row["customer_id"]!=null)
				{
					model.customer_id=row["customer_id"].ToString();
				}
				if(row["work_id"]!=null)
				{
					model.work_id=row["work_id"].ToString();
				}
				if(row["type_"]!=null && row["type_"].ToString()!="")
				{
					model.type_=int.Parse(row["type_"].ToString());
				}
				if(row["plan_number"]!=null)
				{
					model.plan_number=row["plan_number"].ToString();
				}
				if(row["actual_amount"]!=null && row["actual_amount"].ToString()!="")
				{
					model.actual_amount=decimal.Parse(row["actual_amount"].ToString());
				}
				if(row["cloth_amount"]!=null && row["cloth_amount"].ToString()!="")
				{
					model.cloth_amount=decimal.Parse(row["cloth_amount"].ToString());
				}
				if(row["roll_amount"]!=null && row["roll_amount"].ToString()!="")
				{
					model.roll_amount=decimal.Parse(row["roll_amount"].ToString());
				}
				if(row["total_amount"]!=null && row["total_amount"].ToString()!="")
				{
					model.total_amount=decimal.Parse(row["total_amount"].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_,customer_id,work_id,type_,plan_number,actual_amount,cloth_amount,roll_amount,total_amount,del_flag,create_by,create_time,update_by,update_time ");
			strSql.Append(" FROM base_account ");
			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_account ");
			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_account 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_account";
			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
	}
}

