using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using HySoft.DBUtility;//Please add references
namespace HySoft.BaseCallCenter.DAL
{
	/// <summary>
	/// 数据访问类:T_Wo_WorkOrderButton
	/// </summary>
	public partial class T_Wo_WorkOrderButton
	{
		public T_Wo_WorkOrderButton()
		{}
		#region  Method



		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(HySoft.BaseCallCenter.Model.T_Wo_WorkOrderButton model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into T_Wo_WorkOrderButton(");
			strSql.Append("F_Name,F_Code,F_Des,F_Sort,F_Icon,F_DeleteFlag)");
			strSql.Append(" values (");
			strSql.Append("@F_Name,@F_Code,@F_Des,@F_Sort,@F_Icon,@F_DeleteFlag)");
            strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
				
					new SqlParameter("@F_Name", SqlDbType.NChar,10),
					new SqlParameter("@F_Code", SqlDbType.NChar,10),
					new SqlParameter("@F_Des", SqlDbType.NVarChar,100),
					new SqlParameter("@F_Sort", SqlDbType.Int,4),
					new SqlParameter("@F_Icon", SqlDbType.Int,4),
					new SqlParameter("@F_DeleteFlag", SqlDbType.Int,4)};

			parameters[0].Value = model.F_Name;
			parameters[1].Value = model.F_Code;
			parameters[2].Value = model.F_Des;
			parameters[3].Value = model.F_Sort;
			parameters[4].Value = model.F_Icon;
			parameters[5].Value = model.F_DeleteFlag;

            int res = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (res > 0)
            {
                return true;
            }
            else {
                return false;
            }
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(HySoft.BaseCallCenter.Model.T_Wo_WorkOrderButton model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update T_Wo_WorkOrderButton set ");
			strSql.Append("F_Name=@F_Name,");
			strSql.Append("F_Code=@F_Code,");
			strSql.Append("F_Des=@F_Des,");
			strSql.Append("F_Sort=@F_Sort,");
			strSql.Append("F_Icon=@F_Icon,");
			strSql.Append("F_DeleteFlag=@F_DeleteFlag");
            strSql.Append(" where F_ButtonId=@F_ButtonId");
			SqlParameter[] parameters = {
				
					new SqlParameter("@F_Name", SqlDbType.NChar,10),
					new SqlParameter("@F_Code", SqlDbType.NChar,10),
					new SqlParameter("@F_Des", SqlDbType.NVarChar,100),
					new SqlParameter("@F_Sort", SqlDbType.Int,4),
					new SqlParameter("@F_Icon", SqlDbType.Int,4),
					new SqlParameter("@F_DeleteFlag", SqlDbType.Int,4),
                    new SqlParameter("@F_ButtonId", SqlDbType.Int,4)};

			parameters[0].Value = model.F_Name;
			parameters[1].Value = model.F_Code;
			parameters[2].Value = model.F_Des;
			parameters[3].Value = model.F_Sort;
			parameters[4].Value = model.F_Icon;
			parameters[5].Value = model.F_DeleteFlag;
            parameters[6].Value = model.F_ButtonId;

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

		/// <summary>
		/// 删除一条数据
		/// </summary>
        public bool Delete(int F_ButtonId)
		{
			//该表无主键信息，请自定义主键/条件字段
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_Wo_WorkOrderButton ");
            strSql.Append(" where F_ButtonId=@F_ButtonId");
            SqlParameter[] parameters = {
					new SqlParameter("@F_ButtonId", SqlDbType.Int,4)
			};
            parameters[0].Value = F_ButtonId;
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string F_ButtonIdList)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from T_Wo_WorkOrderButton ");
            strSql.Append(" where F_ButtonId in (" + F_ButtonIdList + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
		/// <summary>
		/// 得到一个对象实体
		/// </summary>
        public HySoft.BaseCallCenter.Model.T_Wo_WorkOrderButton GetModel(int F_ButtonId)
		{
			//该表无主键信息，请自定义主键/条件字段
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 F_ButtonId,F_Name,F_Code,F_Des,F_Sort,F_Icon,F_DeleteFlag from T_Wo_WorkOrderButton ");
            strSql.Append(" where F_ButtonId=@F_ButtonId");
			SqlParameter[] parameters = {
new SqlParameter("@F_ButtonId", SqlDbType.Int,4)
};
            parameters[0].Value = F_ButtonId;

			HySoft.BaseCallCenter.Model.T_Wo_WorkOrderButton model=new HySoft.BaseCallCenter.Model.T_Wo_WorkOrderButton();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["F_ButtonId"]!=null && ds.Tables[0].Rows[0]["F_ButtonId"].ToString()!="")
				{
					model.F_ButtonId=int.Parse(ds.Tables[0].Rows[0]["F_ButtonId"].ToString());
				}
				if(ds.Tables[0].Rows[0]["F_Name"]!=null && ds.Tables[0].Rows[0]["F_Name"].ToString()!="")
				{
					model.F_Name=ds.Tables[0].Rows[0]["F_Name"].ToString();
				}
				if(ds.Tables[0].Rows[0]["F_Code"]!=null && ds.Tables[0].Rows[0]["F_Code"].ToString()!="")
				{
					model.F_Code=ds.Tables[0].Rows[0]["F_Code"].ToString();
				}
				if(ds.Tables[0].Rows[0]["F_Des"]!=null && ds.Tables[0].Rows[0]["F_Des"].ToString()!="")
				{
					model.F_Des=ds.Tables[0].Rows[0]["F_Des"].ToString();
				}
				if(ds.Tables[0].Rows[0]["F_Sort"]!=null && ds.Tables[0].Rows[0]["F_Sort"].ToString()!="")
				{
					model.F_Sort=int.Parse(ds.Tables[0].Rows[0]["F_Sort"].ToString());
				}
				if(ds.Tables[0].Rows[0]["F_Icon"]!=null && ds.Tables[0].Rows[0]["F_Icon"].ToString()!="")
				{
					model.F_Icon=int.Parse(ds.Tables[0].Rows[0]["F_Icon"].ToString());
				}
				if(ds.Tables[0].Rows[0]["F_DeleteFlag"]!=null && ds.Tables[0].Rows[0]["F_DeleteFlag"].ToString()!="")
				{
					model.F_DeleteFlag=int.Parse(ds.Tables[0].Rows[0]["F_DeleteFlag"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select F_ButtonId,F_Name,F_Code,F_Des,F_Sort,F_Icon,F_DeleteFlag ");
			strSql.Append(" FROM T_Wo_WorkOrderButton ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(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(" F_ButtonId,F_Name,F_Code,F_Des,F_Sort,F_Icon,F_DeleteFlag ");
			strSql.Append(" FROM T_Wo_WorkOrderButton ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

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

		#endregion  Method
	}
}

