using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using CallCenterApi.DB;
namespace CallCenterApi.DAL
{
    /// <summary>
    /// 数据访问类:T_Wiki_Functions
    /// </summary>
    public partial class T_Wiki_Functions
    {
        public T_Wiki_Functions()
        { }
        #region  BasicMethod
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int F_Id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from T_Wiki_Functions with(nolock)");
            strSql.Append(" where F_Id=@F_Id");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_Id", SqlDbType.Int,4)
            };
            parameters[0].Value = F_Id;

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


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(CallCenterApi.Model.T_Wiki_Functions model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into T_Wiki_Functions(");
            strSql.Append("F_FaBuDanWei,F_FaBuRen,F_HangYe,F_DiQu,F_ShengXiaoShiJian,F_ShiXiaoShiJian,F_FaBuShiJian,F_Key,F_FaWenWenHao,F_FaWenDanWei,F_BiaoShiBianMa,F_ZhiNengBuMen,F_File,F_WenJianMingCheng,F_WenJianNeiRong,F_DianJiLiang,F_CreateUser,F_CreateTime,F_IsDelete,F_DeleteUser,F_DeleteTime)");
            strSql.Append(" values (");
            strSql.Append("@F_FaBuDanWei,@F_FaBuRen,@F_HangYe,@F_DiQu,@F_ShengXiaoShiJian,@F_ShiXiaoShiJian,@F_FaBuShiJian,@F_Key,@F_FaWenWenHao,@F_FaWenDanWei,@F_BiaoShiBianMa,@F_ZhiNengBuMen,@F_File,@F_WenJianMingCheng,@F_WenJianNeiRong,@F_DianJiLiang,@F_CreateUser,@F_CreateTime,@F_IsDelete,@F_DeleteUser,@F_DeleteTime)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_FaBuDanWei", SqlDbType.NVarChar,255),
                    new SqlParameter("@F_FaBuRen", SqlDbType.NVarChar,50),
                    new SqlParameter("@F_HangYe", SqlDbType.NVarChar,50),
                    new SqlParameter("@F_DiQu", SqlDbType.NVarChar,50),
                    new SqlParameter("@F_ShengXiaoShiJian", SqlDbType.DateTime),
                    new SqlParameter("@F_ShiXiaoShiJian", SqlDbType.DateTime),
                    new SqlParameter("@F_FaBuShiJian", SqlDbType.DateTime),
                    new SqlParameter("@F_Key", SqlDbType.Int,4),
                    new SqlParameter("@F_FaWenWenHao", SqlDbType.VarChar,50),
                    new SqlParameter("@F_FaWenDanWei", SqlDbType.NVarChar,255),
                    new SqlParameter("@F_BiaoShiBianMa", SqlDbType.VarChar,50),
                    new SqlParameter("@F_ZhiNengBuMen", SqlDbType.NVarChar,255),
                    new SqlParameter("@F_File", SqlDbType.VarChar,500),
                    new SqlParameter("@F_WenJianMingCheng", SqlDbType.NVarChar,255),
                    new SqlParameter("@F_WenJianNeiRong", SqlDbType.NVarChar,-1),
                    new SqlParameter("@F_DianJiLiang", SqlDbType.BigInt,8),
                    new SqlParameter("@F_CreateUser", SqlDbType.VarChar,50),
                    new SqlParameter("@F_CreateTime", SqlDbType.DateTime),
                    new SqlParameter("@F_IsDelete", SqlDbType.Int,4),
                    new SqlParameter("@F_DeleteUser", SqlDbType.VarChar,50),
                    new SqlParameter("@F_DeleteTime", SqlDbType.DateTime)};
            parameters[0].Value = model.F_FaBuDanWei;
            parameters[1].Value = model.F_FaBuRen;
            parameters[2].Value = model.F_HangYe;
            parameters[3].Value = model.F_DiQu;
            parameters[4].Value = model.F_ShengXiaoShiJian;
            parameters[5].Value = model.F_ShiXiaoShiJian;
            parameters[6].Value = model.F_FaBuShiJian;
            parameters[7].Value = model.F_Key;
            parameters[8].Value = model.F_FaWenWenHao;
            parameters[9].Value = model.F_FaWenDanWei;
            parameters[10].Value = model.F_BiaoShiBianMa;
            parameters[11].Value = model.F_ZhiNengBuMen;
            parameters[12].Value = model.F_File;
            parameters[13].Value = model.F_WenJianMingCheng;
            parameters[14].Value = model.F_WenJianNeiRong;
            parameters[15].Value = model.F_DianJiLiang;
            parameters[16].Value = model.F_CreateUser;
            parameters[17].Value = model.F_CreateTime;
            parameters[18].Value = model.F_IsDelete;
            parameters[19].Value = model.F_DeleteUser;
            parameters[20].Value = model.F_DeleteTime;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(CallCenterApi.Model.T_Wiki_Functions model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Wiki_Functions set ");
            strSql.Append("F_FaBuDanWei=@F_FaBuDanWei,");
            strSql.Append("F_FaBuRen=@F_FaBuRen,");
            strSql.Append("F_HangYe=@F_HangYe,");
            strSql.Append("F_DiQu=@F_DiQu,");
            strSql.Append("F_ShengXiaoShiJian=@F_ShengXiaoShiJian,");
            strSql.Append("F_ShiXiaoShiJian=@F_ShiXiaoShiJian,");
            strSql.Append("F_FaBuShiJian=@F_FaBuShiJian,");
            strSql.Append("F_Key=@F_Key,");
            strSql.Append("F_FaWenWenHao=@F_FaWenWenHao,");
            strSql.Append("F_FaWenDanWei=@F_FaWenDanWei,");
            strSql.Append("F_BiaoShiBianMa=@F_BiaoShiBianMa,");
            strSql.Append("F_ZhiNengBuMen=@F_ZhiNengBuMen,");
            strSql.Append("F_File=@F_File,");
            strSql.Append("F_WenJianMingCheng=@F_WenJianMingCheng,");
            strSql.Append("F_WenJianNeiRong=@F_WenJianNeiRong,");
            strSql.Append("F_DianJiLiang=@F_DianJiLiang,");
            strSql.Append("F_CreateUser=@F_CreateUser,");
            strSql.Append("F_CreateTime=@F_CreateTime,");
            strSql.Append("F_IsDelete=@F_IsDelete,");
            strSql.Append("F_DeleteUser=@F_DeleteUser,");
            strSql.Append("F_DeleteTime=@F_DeleteTime");
            strSql.Append(" where F_Id=@F_Id");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_FaBuDanWei", SqlDbType.NVarChar,255),
                    new SqlParameter("@F_FaBuRen", SqlDbType.NVarChar,50),
                    new SqlParameter("@F_HangYe", SqlDbType.NVarChar,50),
                    new SqlParameter("@F_DiQu", SqlDbType.NVarChar,50),
                    new SqlParameter("@F_ShengXiaoShiJian", SqlDbType.DateTime),
                    new SqlParameter("@F_ShiXiaoShiJian", SqlDbType.DateTime),
                    new SqlParameter("@F_FaBuShiJian", SqlDbType.DateTime),
                    new SqlParameter("@F_Key", SqlDbType.Int,4),
                    new SqlParameter("@F_FaWenWenHao", SqlDbType.VarChar,50),
                    new SqlParameter("@F_FaWenDanWei", SqlDbType.NVarChar,255),
                    new SqlParameter("@F_BiaoShiBianMa", SqlDbType.VarChar,50),
                    new SqlParameter("@F_ZhiNengBuMen", SqlDbType.NVarChar,255),
                    new SqlParameter("@F_File", SqlDbType.VarChar,500),
                    new SqlParameter("@F_WenJianMingCheng", SqlDbType.NVarChar,255),
                    new SqlParameter("@F_WenJianNeiRong", SqlDbType.NVarChar,-1),
                    new SqlParameter("@F_DianJiLiang", SqlDbType.BigInt,8),
                    new SqlParameter("@F_CreateUser", SqlDbType.VarChar,50),
                    new SqlParameter("@F_CreateTime", SqlDbType.DateTime),
                    new SqlParameter("@F_IsDelete", SqlDbType.Int,4),
                    new SqlParameter("@F_DeleteUser", SqlDbType.VarChar,50),
                    new SqlParameter("@F_DeleteTime", SqlDbType.DateTime),
                    new SqlParameter("@F_Id", SqlDbType.Int,4)};
            parameters[0].Value = model.F_FaBuDanWei;
            parameters[1].Value = model.F_FaBuRen;
            parameters[2].Value = model.F_HangYe;
            parameters[3].Value = model.F_DiQu;
            parameters[4].Value = model.F_ShengXiaoShiJian;
            parameters[5].Value = model.F_ShiXiaoShiJian;
            parameters[6].Value = model.F_FaBuShiJian;
            parameters[7].Value = model.F_Key;
            parameters[8].Value = model.F_FaWenWenHao;
            parameters[9].Value = model.F_FaWenDanWei;
            parameters[10].Value = model.F_BiaoShiBianMa;
            parameters[11].Value = model.F_ZhiNengBuMen;
            parameters[12].Value = model.F_File;
            parameters[13].Value = model.F_WenJianMingCheng;
            parameters[14].Value = model.F_WenJianNeiRong;
            parameters[15].Value = model.F_DianJiLiang;
            parameters[16].Value = model.F_CreateUser;
            parameters[17].Value = model.F_CreateTime;
            parameters[18].Value = model.F_IsDelete;
            parameters[19].Value = model.F_DeleteUser;
            parameters[20].Value = model.F_DeleteTime;
            parameters[21].Value = model.F_Id;

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

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int F_Id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from T_Wiki_Functions ");
            strSql.Append(" where F_Id=@F_Id");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_Id", SqlDbType.Int,4)
            };
            parameters[0].Value = F_Id;

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


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public CallCenterApi.Model.T_Wiki_Functions GetModel(int F_Id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 F_Id,F_FaBuDanWei,F_FaBuRen,F_HangYe,F_DiQu,F_ShengXiaoShiJian,F_ShiXiaoShiJian,F_FaBuShiJian,F_Key,F_FaWenWenHao,F_FaWenDanWei,F_BiaoShiBianMa,F_ZhiNengBuMen,F_File,F_WenJianMingCheng,F_WenJianNeiRong,F_DianJiLiang,F_CreateUser,F_CreateTime,F_IsDelete,F_DeleteUser,F_DeleteTime from T_Wiki_Functions with(nolock)");
            strSql.Append(" where F_Id=@F_Id");
            SqlParameter[] parameters = {
                    new SqlParameter("@F_Id", SqlDbType.Int,4)
            };
            parameters[0].Value = F_Id;

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


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public CallCenterApi.Model.T_Wiki_Functions DataRowToModel(DataRow row)
        {
            CallCenterApi.Model.T_Wiki_Functions model = new CallCenterApi.Model.T_Wiki_Functions();
            if (row != null)
            {
                if (row["F_Id"] != null && row["F_Id"].ToString() != "")
                {
                    model.F_Id = int.Parse(row["F_Id"].ToString());
                }
                if (row["F_FaBuDanWei"] != null)
                {
                    model.F_FaBuDanWei = row["F_FaBuDanWei"].ToString();
                }
                if (row["F_FaBuRen"] != null)
                {
                    model.F_FaBuRen = row["F_FaBuRen"].ToString();
                }
                if (row["F_HangYe"] != null)
                {
                    model.F_HangYe = row["F_HangYe"].ToString();
                }
                if (row["F_DiQu"] != null)
                {
                    model.F_DiQu = row["F_DiQu"].ToString();
                }
                if (row["F_ShengXiaoShiJian"] != null && row["F_ShengXiaoShiJian"].ToString() != "")
                {
                    model.F_ShengXiaoShiJian = DateTime.Parse(row["F_ShengXiaoShiJian"].ToString());
                }
                if (row["F_ShiXiaoShiJian"] != null && row["F_ShiXiaoShiJian"].ToString() != "")
                {
                    model.F_ShiXiaoShiJian = DateTime.Parse(row["F_ShiXiaoShiJian"].ToString());
                }
                if (row["F_FaBuShiJian"] != null && row["F_FaBuShiJian"].ToString() != "")
                {
                    model.F_FaBuShiJian = DateTime.Parse(row["F_FaBuShiJian"].ToString());
                }
                if (row["F_Key"] != null && row["F_Key"].ToString() != "")
                {
                    model.F_Key = int.Parse(row["F_Key"].ToString());
                }
                if (row["F_FaWenWenHao"] != null)
                {
                    model.F_FaWenWenHao = row["F_FaWenWenHao"].ToString();
                }
                if (row["F_FaWenDanWei"] != null)
                {
                    model.F_FaWenDanWei = row["F_FaWenDanWei"].ToString();
                }
                if (row["F_BiaoShiBianMa"] != null)
                {
                    model.F_BiaoShiBianMa = row["F_BiaoShiBianMa"].ToString();
                }
                if (row["F_ZhiNengBuMen"] != null)
                {
                    model.F_ZhiNengBuMen = row["F_ZhiNengBuMen"].ToString();
                }
                if (row["F_File"] != null)
                {
                    model.F_File = row["F_File"].ToString();
                }
                if (row["F_WenJianMingCheng"] != null)
                {
                    model.F_WenJianMingCheng = row["F_WenJianMingCheng"].ToString();
                }
                if (row["F_WenJianNeiRong"] != null)
                {
                    model.F_WenJianNeiRong = row["F_WenJianNeiRong"].ToString();
                }
                if (row["F_DianJiLiang"] != null && row["F_DianJiLiang"].ToString() != "")
                {
                    model.F_DianJiLiang = long.Parse(row["F_DianJiLiang"].ToString());
                }
                if (row["F_CreateUser"] != null)
                {
                    model.F_CreateUser = row["F_CreateUser"].ToString();
                }
                if (row["F_CreateTime"] != null && row["F_CreateTime"].ToString() != "")
                {
                    model.F_CreateTime = DateTime.Parse(row["F_CreateTime"].ToString());
                }
                if (row["F_IsDelete"] != null && row["F_IsDelete"].ToString() != "")
                {
                    model.F_IsDelete = int.Parse(row["F_IsDelete"].ToString());
                }
                if (row["F_DeleteUser"] != null)
                {
                    model.F_DeleteUser = row["F_DeleteUser"].ToString();
                }
                if (row["F_DeleteTime"] != null && row["F_DeleteTime"].ToString() != "")
                {
                    model.F_DeleteTime = DateTime.Parse(row["F_DeleteTime"].ToString());
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select F_Id,F_FaBuDanWei,F_FaBuRen,F_HangYe,F_DiQu,F_ShengXiaoShiJian,F_ShiXiaoShiJian,F_FaBuShiJian,F_Key,F_FaWenWenHao,F_FaWenDanWei,F_BiaoShiBianMa,F_ZhiNengBuMen,F_File,F_WenJianMingCheng,F_WenJianNeiRong,F_DianJiLiang,F_CreateUser,F_CreateTime,F_IsDelete,F_DeleteUser,F_DeleteTime ");
            strSql.Append(" FROM T_Wiki_Functions with(nolock)");
            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_Id,F_FaBuDanWei,F_FaBuRen,F_HangYe,F_DiQu,F_ShengXiaoShiJian,F_ShiXiaoShiJian,F_FaBuShiJian,F_Key,F_FaWenWenHao,F_FaWenDanWei,F_BiaoShiBianMa,F_ZhiNengBuMen,F_File,F_WenJianMingCheng,F_WenJianNeiRong,F_DianJiLiang,F_CreateUser,F_CreateTime,F_IsDelete,F_DeleteUser,F_DeleteTime ");
            strSql.Append(" FROM T_Wiki_Functions with(nolock)");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM T_Wiki_Functions with(nolock)");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }

        #endregion  BasicMethod
    }
}
