using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using ZXDT.DBUtility;

namespace ZXDT.CallCenter.DAL
{
    /// <summary>
    /// 数据访问类:T_Call_MeetingInfo
    /// </summary>
    public partial class T_Call_MeetingInfo
    {
        public T_Call_MeetingInfo()
        { }
        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int F_MeetingId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from T_Call_MeetingInfo");
            strSql.Append(" where F_MeetingId=@F_MeetingId");
            SqlParameter[] parameters = {
					new SqlParameter("@F_MeetingId", SqlDbType.Int,4)
			};
            parameters[0].Value = F_MeetingId;

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


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(ZXDT.CallCenter.Model.T_Call_MeetingInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into T_Call_MeetingInfo(");
            strSql.Append("F_Title,F_Code,F_Remark,F_Count,F_SJCount,F_CreateTime,F_StartTime,F_EndTime,F_CreateId,F_CreateName,F_Phone,F_State,F_Ext1,F_Ext2,F_Ext3,F_Int1,F_Time1)");
            strSql.Append(" values (");
            strSql.Append("@F_Title,@F_Code,@F_Remark,@F_Count,@F_SJCount,@F_CreateTime,@F_StartTime,@F_EndTime,@F_CreateId,@F_CreateName,@F_Phone,@F_State,@F_Ext1,@F_Ext2,@F_Ext3,@F_Int1,@F_Time1)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@F_Title", SqlDbType.NVarChar,500),
					new SqlParameter("@F_Code", SqlDbType.NVarChar,50),
					new SqlParameter("@F_Remark", SqlDbType.Text),
					new SqlParameter("@F_Count", SqlDbType.Int,4),
					new SqlParameter("@F_SJCount", SqlDbType.Int,4),
					new SqlParameter("@F_CreateTime", SqlDbType.DateTime),
					new SqlParameter("@F_StartTime", SqlDbType.DateTime),
					new SqlParameter("@F_EndTime", SqlDbType.DateTime),
					new SqlParameter("@F_CreateId", SqlDbType.Int,4),
					new SqlParameter("@F_CreateName", SqlDbType.NVarChar,50),
					new SqlParameter("@F_Phone", SqlDbType.NVarChar,50),
					new SqlParameter("@F_State", SqlDbType.Int,4),
					new SqlParameter("@F_Ext1", SqlDbType.NVarChar,50),
					new SqlParameter("@F_Ext2", SqlDbType.NVarChar,500),
					new SqlParameter("@F_Ext3", SqlDbType.NVarChar,50),
					new SqlParameter("@F_Int1", SqlDbType.Int,4),
					new SqlParameter("@F_Time1", SqlDbType.DateTime)};
            parameters[0].Value = model.F_Title;
            parameters[1].Value = model.F_Code;
            parameters[2].Value = model.F_Remark;
            parameters[3].Value = model.F_Count;
            parameters[4].Value = model.F_SJCount;
            parameters[5].Value = model.F_CreateTime;
            parameters[6].Value = model.F_StartTime;
            parameters[7].Value = model.F_EndTime;
            parameters[8].Value = model.F_CreateId;
            parameters[9].Value = model.F_CreateName;
            parameters[10].Value = model.F_Phone;
            parameters[11].Value = model.F_State;
            parameters[12].Value = model.F_Ext1;
            parameters[13].Value = model.F_Ext2;
            parameters[14].Value = model.F_Ext3;
            parameters[15].Value = model.F_Int1;
            parameters[16].Value = model.F_Time1;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(ZXDT.CallCenter.Model.T_Call_MeetingInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Call_MeetingInfo set ");
            strSql.Append("F_Title=@F_Title,");
            strSql.Append("F_Code=@F_Code,");
            strSql.Append("F_Remark=@F_Remark,");
            strSql.Append("F_Count=@F_Count,");
            strSql.Append("F_SJCount=@F_SJCount,");
            strSql.Append("F_CreateTime=@F_CreateTime,");
            strSql.Append("F_StartTime=@F_StartTime,");
            strSql.Append("F_EndTime=@F_EndTime,");
            strSql.Append("F_CreateId=@F_CreateId,");
            strSql.Append("F_CreateName=@F_CreateName,");
            strSql.Append("F_Phone=@F_Phone,");
            strSql.Append("F_State=@F_State,");
            strSql.Append("F_Ext1=@F_Ext1,");
            strSql.Append("F_Ext2=@F_Ext2,");
            strSql.Append("F_Ext3=@F_Ext3,");
            strSql.Append("F_Int1=@F_Int1,");
            strSql.Append("F_Time1=@F_Time1");
            strSql.Append(" where F_MeetingId=@F_MeetingId");
            SqlParameter[] parameters = {
					new SqlParameter("@F_Title", SqlDbType.NVarChar,500),
					new SqlParameter("@F_Code", SqlDbType.NVarChar,50),
					new SqlParameter("@F_Remark", SqlDbType.Text),
					new SqlParameter("@F_Count", SqlDbType.Int,4),
					new SqlParameter("@F_SJCount", SqlDbType.Int,4),
					new SqlParameter("@F_CreateTime", SqlDbType.DateTime),
					new SqlParameter("@F_StartTime", SqlDbType.DateTime),
					new SqlParameter("@F_EndTime", SqlDbType.DateTime),
					new SqlParameter("@F_CreateId", SqlDbType.Int,4),
					new SqlParameter("@F_CreateName", SqlDbType.NVarChar,50),
					new SqlParameter("@F_Phone", SqlDbType.NVarChar,50),
					new SqlParameter("@F_State", SqlDbType.Int,4),
					new SqlParameter("@F_Ext1", SqlDbType.NVarChar,50),
					new SqlParameter("@F_Ext2", SqlDbType.NVarChar,500),
					new SqlParameter("@F_Ext3", SqlDbType.NVarChar,50),
					new SqlParameter("@F_Int1", SqlDbType.Int,4),
					new SqlParameter("@F_Time1", SqlDbType.DateTime),
					new SqlParameter("@F_MeetingId", SqlDbType.Int,4)};
            parameters[0].Value = model.F_Title;
            parameters[1].Value = model.F_Code;
            parameters[2].Value = model.F_Remark;
            parameters[3].Value = model.F_Count;
            parameters[4].Value = model.F_SJCount;
            parameters[5].Value = model.F_CreateTime;
            parameters[6].Value = model.F_StartTime;
            parameters[7].Value = model.F_EndTime;
            parameters[8].Value = model.F_CreateId;
            parameters[9].Value = model.F_CreateName;
            parameters[10].Value = model.F_Phone;
            parameters[11].Value = model.F_State;
            parameters[12].Value = model.F_Ext1;
            parameters[13].Value = model.F_Ext2;
            parameters[14].Value = model.F_Ext3;
            parameters[15].Value = model.F_Int1;
            parameters[16].Value = model.F_Time1;
            parameters[17].Value = model.F_MeetingId;

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

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool UpdateCreate(ZXDT.CallCenter.Model.T_Call_MeetingInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Call_MeetingInfo set ");
            strSql.Append("F_StartTime=@F_StartTime,");
            strSql.Append("F_State=@F_State");
            strSql.Append(" where F_MeetingId=@F_MeetingId");
            SqlParameter[] parameters = {
					new SqlParameter("@F_StartTime", SqlDbType.DateTime),
					new SqlParameter("@F_State", SqlDbType.Int,4),
					new SqlParameter("@F_MeetingId", SqlDbType.Int,4)};
            parameters[0].Value = model.F_StartTime;
            parameters[1].Value = model.F_State;
            parameters[2].Value = model.F_MeetingId;

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

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool UpdateDelete(ZXDT.CallCenter.Model.T_Call_MeetingInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Call_MeetingInfo set ");
            strSql.Append("F_EndTime=@F_EndTime,");
            strSql.Append("F_State=@F_State");
            strSql.Append(" where F_MeetingId=@F_MeetingId");
            SqlParameter[] parameters = {
					new SqlParameter("@F_EndTime", SqlDbType.DateTime),
					new SqlParameter("@F_State", SqlDbType.Int,4),
					new SqlParameter("@F_MeetingId", SqlDbType.Int,4)};
            parameters[0].Value = model.F_EndTime;
            parameters[1].Value = model.F_State;
            parameters[2].Value = model.F_MeetingId;

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

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool UpdateCount(int F_MeetingId,int count)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Call_MeetingInfo set ");
            if (count > 0)
            {
                strSql.Append("F_Count=F_Count+1");
            }
            else
            {
                strSql.Append("F_Count=F_Count-1");
            }
            strSql.Append(" where F_MeetingId=@F_MeetingId");
            SqlParameter[] parameters = {
					new SqlParameter("@F_MeetingId", SqlDbType.Int,4)};
            parameters[0].Value = F_MeetingId;

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

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

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

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


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ZXDT.CallCenter.Model.T_Call_MeetingInfo GetModel(int F_MeetingId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 F_MeetingId,F_Title,F_Code,F_Remark,F_Count,F_SJCount,F_CreateTime,F_StartTime,F_EndTime,F_CreateId,F_CreateName,F_Phone,F_State,F_Ext1,F_Ext2,F_Ext3,F_Int1,F_Time1 from T_Call_MeetingInfo ");
            strSql.Append(" where F_MeetingId=@F_MeetingId");
            SqlParameter[] parameters = {
					new SqlParameter("@F_MeetingId", SqlDbType.Int,4)
			};
            parameters[0].Value = F_MeetingId;

            ZXDT.CallCenter.Model.T_Call_MeetingInfo model = new ZXDT.CallCenter.Model.T_Call_MeetingInfo();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["F_MeetingId"] != null && ds.Tables[0].Rows[0]["F_MeetingId"].ToString() != "")
                {
                    model.F_MeetingId = int.Parse(ds.Tables[0].Rows[0]["F_MeetingId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_Title"] != null && ds.Tables[0].Rows[0]["F_Title"].ToString() != "")
                {
                    model.F_Title = ds.Tables[0].Rows[0]["F_Title"].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_Remark"] != null && ds.Tables[0].Rows[0]["F_Remark"].ToString() != "")
                {
                    model.F_Remark = ds.Tables[0].Rows[0]["F_Remark"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_Count"] != null && ds.Tables[0].Rows[0]["F_Count"].ToString() != "")
                {
                    model.F_Count = int.Parse(ds.Tables[0].Rows[0]["F_Count"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_SJCount"] != null && ds.Tables[0].Rows[0]["F_SJCount"].ToString() != "")
                {
                    model.F_SJCount = int.Parse(ds.Tables[0].Rows[0]["F_SJCount"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_CreateTime"] != null && ds.Tables[0].Rows[0]["F_CreateTime"].ToString() != "")
                {
                    model.F_CreateTime = DateTime.Parse(ds.Tables[0].Rows[0]["F_CreateTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_StartTime"] != null && ds.Tables[0].Rows[0]["F_StartTime"].ToString() != "")
                {
                    model.F_StartTime = DateTime.Parse(ds.Tables[0].Rows[0]["F_StartTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_EndTime"] != null && ds.Tables[0].Rows[0]["F_EndTime"].ToString() != "")
                {
                    model.F_EndTime = DateTime.Parse(ds.Tables[0].Rows[0]["F_EndTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_CreateId"] != null && ds.Tables[0].Rows[0]["F_CreateId"].ToString() != "")
                {
                    model.F_CreateId = int.Parse(ds.Tables[0].Rows[0]["F_CreateId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_CreateName"] != null && ds.Tables[0].Rows[0]["F_CreateName"].ToString() != "")
                {
                    model.F_CreateName = ds.Tables[0].Rows[0]["F_CreateName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_Phone"] != null && ds.Tables[0].Rows[0]["F_Phone"].ToString() != "")
                {
                    model.F_Phone = ds.Tables[0].Rows[0]["F_Phone"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_State"] != null && ds.Tables[0].Rows[0]["F_State"].ToString() != "")
                {
                    model.F_State = int.Parse(ds.Tables[0].Rows[0]["F_State"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_Ext1"] != null && ds.Tables[0].Rows[0]["F_Ext1"].ToString() != "")
                {
                    model.F_Ext1 = ds.Tables[0].Rows[0]["F_Ext1"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_Ext2"] != null && ds.Tables[0].Rows[0]["F_Ext2"].ToString() != "")
                {
                    model.F_Ext2 = ds.Tables[0].Rows[0]["F_Ext2"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_Ext3"] != null && ds.Tables[0].Rows[0]["F_Ext3"].ToString() != "")
                {
                    model.F_Ext3 = ds.Tables[0].Rows[0]["F_Ext3"].ToString();
                }
                if (ds.Tables[0].Rows[0]["F_Int1"] != null && ds.Tables[0].Rows[0]["F_Int1"].ToString() != "")
                {
                    model.F_Int1 = int.Parse(ds.Tables[0].Rows[0]["F_Int1"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_Time1"] != null && ds.Tables[0].Rows[0]["F_Time1"].ToString() != "")
                {
                    model.F_Time1 = DateTime.Parse(ds.Tables[0].Rows[0]["F_Time1"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select F_MeetingId,F_Title,F_Code,F_Remark,F_Count,F_SJCount,F_CreateTime,F_StartTime,F_EndTime,F_CreateId,F_CreateName,F_Phone,F_State,F_Ext1,F_Ext2,F_Ext3,F_Int1,F_Time1 ");
            strSql.Append(" FROM T_Call_MeetingInfo ");
            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_MeetingId,F_Title,F_Code,F_Remark,F_Count,F_SJCount,F_CreateTime,F_StartTime,F_EndTime,F_CreateId,F_CreateName,F_Phone,F_State,F_Ext1,F_Ext2,F_Ext3,F_Int1,F_Time1 ");
            strSql.Append(" FROM T_Call_MeetingInfo ");
            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_Call_MeetingInfo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.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.F_MeetingId desc");
            }
            strSql.Append(")AS Row, T.*  from T_Call_MeetingInfo 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 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_Call_MeetingInfo";
            parameters[1].Value = "F_MeetingId";
            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
    }
}

