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_MeetingItems
    /// </summary>
    public partial class T_Call_MeetingItems
    {
        public T_Call_MeetingItems()
        { }
        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int F_MeetingItemId)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from T_Call_MeetingItems");
            strSql.Append(" where F_MeetingItemId=@F_MeetingItemId");
            SqlParameter[] parameters = {
					new SqlParameter("@F_MeetingItemId", SqlDbType.Int,4)
			};
            parameters[0].Value = F_MeetingItemId;

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


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(ZXDT.CallCenter.Model.T_Call_MeetingItems model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into T_Call_MeetingItems(");
            strSql.Append("F_MeetingId,F_Phone,F_Name,F_UserId,F_IsMain,F_State,F_InTime,F_OutTime,F_TiCount,F_JingCount,F_CreateTime,F_Remark,F_Int1,F_DateTime1)");
            strSql.Append(" values (");
            strSql.Append("@F_MeetingId,@F_Phone,@F_Name,@F_UserId,@F_IsMain,@F_State,@F_InTime,@F_OutTime,@F_TiCount,@F_JingCount,@F_CreateTime,@F_Remark,@F_Int1,@F_DateTime1)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
					new SqlParameter("@F_MeetingId", SqlDbType.Int,4),
					new SqlParameter("@F_Phone", SqlDbType.NVarChar,50),
					new SqlParameter("@F_Name", SqlDbType.NVarChar,50),
					new SqlParameter("@F_UserId", SqlDbType.Int,4),
					new SqlParameter("@F_IsMain", SqlDbType.SmallInt,2),
					new SqlParameter("@F_State", SqlDbType.SmallInt,2),
					new SqlParameter("@F_InTime", SqlDbType.DateTime),
					new SqlParameter("@F_OutTime", SqlDbType.DateTime),
					new SqlParameter("@F_TiCount", SqlDbType.Int,4),
					new SqlParameter("@F_JingCount", SqlDbType.Int,4),
					new SqlParameter("@F_CreateTime", SqlDbType.DateTime),
					new SqlParameter("@F_Remark", SqlDbType.NVarChar,500),
					new SqlParameter("@F_Int1", SqlDbType.Int,4),
					new SqlParameter("@F_DateTime1", SqlDbType.DateTime)};
            parameters[0].Value = model.F_MeetingId;
            parameters[1].Value = model.F_Phone;
            parameters[2].Value = model.F_Name;
            parameters[3].Value = model.F_UserId;
            parameters[4].Value = model.F_IsMain;
            parameters[5].Value = model.F_State;
            parameters[6].Value = model.F_InTime;
            parameters[7].Value = model.F_OutTime;
            parameters[8].Value = model.F_TiCount;
            parameters[9].Value = model.F_JingCount;
            parameters[10].Value = model.F_CreateTime;
            parameters[11].Value = model.F_Remark;
            parameters[12].Value = model.F_Int1;
            parameters[13].Value = model.F_DateTime1;

            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_MeetingItems model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Call_MeetingItems set ");
            strSql.Append("F_MeetingId=@F_MeetingId,");
            strSql.Append("F_Phone=@F_Phone,");
            strSql.Append("F_Name=@F_Name,");
            strSql.Append("F_UserId=@F_UserId,");
            strSql.Append("F_IsMain=@F_IsMain,");
            strSql.Append("F_State=@F_State,");
            strSql.Append("F_InTime=@F_InTime,");
            strSql.Append("F_OutTime=@F_OutTime,");
            strSql.Append("F_TiCount=@F_TiCount,");
            strSql.Append("F_JingCount=@F_JingCount,");
            strSql.Append("F_CreateTime=@F_CreateTime,");
            strSql.Append("F_Remark=@F_Remark,");
            strSql.Append("F_Int1=@F_Int1,");
            strSql.Append("F_DateTime1=@F_DateTime1");
            strSql.Append(" where F_MeetingItemId=@F_MeetingItemId");
            SqlParameter[] parameters = {
					new SqlParameter("@F_MeetingId", SqlDbType.Int,4),
					new SqlParameter("@F_Phone", SqlDbType.NVarChar,50),
					new SqlParameter("@F_Name", SqlDbType.NVarChar,50),
					new SqlParameter("@F_UserId", SqlDbType.Int,4),
					new SqlParameter("@F_IsMain", SqlDbType.SmallInt,2),
					new SqlParameter("@F_State", SqlDbType.SmallInt,2),
					new SqlParameter("@F_InTime", SqlDbType.DateTime),
					new SqlParameter("@F_OutTime", SqlDbType.DateTime),
					new SqlParameter("@F_TiCount", SqlDbType.Int,4),
					new SqlParameter("@F_JingCount", SqlDbType.Int,4),
					new SqlParameter("@F_CreateTime", SqlDbType.DateTime),
					new SqlParameter("@F_Remark", SqlDbType.NVarChar,500),
					new SqlParameter("@F_Int1", SqlDbType.Int,4),
					new SqlParameter("@F_DateTime1", SqlDbType.DateTime),
					new SqlParameter("@F_MeetingItemId", SqlDbType.Int,4)};
            parameters[0].Value = model.F_MeetingId;
            parameters[1].Value = model.F_Phone;
            parameters[2].Value = model.F_Name;
            parameters[3].Value = model.F_UserId;
            parameters[4].Value = model.F_IsMain;
            parameters[5].Value = model.F_State;
            parameters[6].Value = model.F_InTime;
            parameters[7].Value = model.F_OutTime;
            parameters[8].Value = model.F_TiCount;
            parameters[9].Value = model.F_JingCount;
            parameters[10].Value = model.F_CreateTime;
            parameters[11].Value = model.F_Remark;
            parameters[12].Value = model.F_Int1;
            parameters[13].Value = model.F_DateTime1;
            parameters[14].Value = model.F_MeetingItemId;

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

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

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

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool UpdateAddMemberByPhone(ZXDT.CallCenter.Model.T_Call_MeetingItems model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Call_MeetingItems set ");
            strSql.Append("F_State=@F_State,");
            strSql.Append("F_InTime=@F_InTime");
            strSql.Append(" where F_MeetingId=@F_MeetingId and F_Phone=@F_Phone ");
            SqlParameter[] parameters = {
					new SqlParameter("@F_State", SqlDbType.SmallInt,2),
					new SqlParameter("@F_InTime", SqlDbType.DateTime),
					new SqlParameter("@F_MeetingId", SqlDbType.Int,4),
					new SqlParameter("@F_Phone", SqlDbType.NVarChar,50)};
            parameters[0].Value = model.F_State;
            parameters[1].Value = model.F_InTime;
            parameters[2].Value = model.F_MeetingId;
            parameters[3].Value = model.F_Phone;

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

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool UpdateRemoveMemberByPhone(ZXDT.CallCenter.Model.T_Call_MeetingItems model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Call_MeetingItems set ");
            strSql.Append("F_State=@F_State,");
            strSql.Append("F_TiCount=F_TiCount+1,");
            strSql.Append("F_OutTime=@F_OutTime");
            strSql.Append(" where F_MeetingId=@F_MeetingId and F_Phone=@F_Phone ");
            SqlParameter[] parameters = {
					new SqlParameter("@F_State", SqlDbType.SmallInt,2),
					new SqlParameter("@F_OutTime", SqlDbType.DateTime),
					new SqlParameter("@F_MeetingId", SqlDbType.Int,4),
					new SqlParameter("@F_Phone", SqlDbType.NVarChar,50)};
            parameters[0].Value = model.F_State;
            parameters[1].Value = model.F_OutTime;
            parameters[2].Value = model.F_MeetingId;
            parameters[3].Value = model.F_Phone;

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

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool UpdateMuteMemberByPhone(ZXDT.CallCenter.Model.T_Call_MeetingItems model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Call_MeetingItems set ");
            strSql.Append("F_State=@F_State,");
            strSql.Append("F_JingCount=F_JingCount+1");
            strSql.Append(" where F_MeetingId=@F_MeetingId and F_Phone=@F_Phone ");
            SqlParameter[] parameters = {
					new SqlParameter("@F_State", SqlDbType.SmallInt,2),
					new SqlParameter("@F_MeetingId", SqlDbType.Int,4),
					new SqlParameter("@F_Phone", SqlDbType.NVarChar,50)};
            parameters[0].Value = model.F_State;
            parameters[1].Value = model.F_MeetingId;
            parameters[2].Value = model.F_Phone;

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

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

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


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

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

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


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

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 F_MeetingItemId,F_MeetingId,F_Phone,F_Name,F_UserId,F_IsMain,F_State,F_InTime,F_OutTime,F_TiCount,F_JingCount,F_CreateTime,F_Remark,F_Int1,F_DateTime1 from T_Call_MeetingItems ");
            strSql.Append(" where F_MeetingItemId=@F_MeetingItemId");
            SqlParameter[] parameters = {
					new SqlParameter("@F_MeetingItemId", SqlDbType.Int,4)
			};
            parameters[0].Value = F_MeetingItemId;

            ZXDT.CallCenter.Model.T_Call_MeetingItems model = new ZXDT.CallCenter.Model.T_Call_MeetingItems();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["F_MeetingItemId"] != null && ds.Tables[0].Rows[0]["F_MeetingItemId"].ToString() != "")
                {
                    model.F_MeetingItemId = int.Parse(ds.Tables[0].Rows[0]["F_MeetingItemId"].ToString());
                }
                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_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_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_UserId"] != null && ds.Tables[0].Rows[0]["F_UserId"].ToString() != "")
                {
                    model.F_UserId = int.Parse(ds.Tables[0].Rows[0]["F_UserId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_IsMain"] != null && ds.Tables[0].Rows[0]["F_IsMain"].ToString() != "")
                {
                    model.F_IsMain = int.Parse(ds.Tables[0].Rows[0]["F_IsMain"].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_InTime"] != null && ds.Tables[0].Rows[0]["F_InTime"].ToString() != "")
                {
                    model.F_InTime = DateTime.Parse(ds.Tables[0].Rows[0]["F_InTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_OutTime"] != null && ds.Tables[0].Rows[0]["F_OutTime"].ToString() != "")
                {
                    model.F_OutTime = DateTime.Parse(ds.Tables[0].Rows[0]["F_OutTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_TiCount"] != null && ds.Tables[0].Rows[0]["F_TiCount"].ToString() != "")
                {
                    model.F_TiCount = int.Parse(ds.Tables[0].Rows[0]["F_TiCount"].ToString());
                }
                if (ds.Tables[0].Rows[0]["F_JingCount"] != null && ds.Tables[0].Rows[0]["F_JingCount"].ToString() != "")
                {
                    model.F_JingCount = int.Parse(ds.Tables[0].Rows[0]["F_JingCount"].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_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_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_DateTime1"] != null && ds.Tables[0].Rows[0]["F_DateTime1"].ToString() != "")
                {
                    model.F_DateTime1 = DateTime.Parse(ds.Tables[0].Rows[0]["F_DateTime1"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select F_MeetingItemId,F_MeetingId,F_Phone,F_Name,F_UserId,F_IsMain,F_State,F_InTime,F_OutTime,F_TiCount,F_JingCount,F_CreateTime,F_Remark,F_Int1,F_DateTime1 ");
            strSql.Append(" FROM T_Call_MeetingItems ");
            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_MeetingItemId,F_MeetingId,F_Phone,F_Name,F_UserId,F_IsMain,F_State,F_InTime,F_OutTime,F_TiCount,F_JingCount,F_CreateTime,F_Remark,F_Int1,F_DateTime1 ");
            strSql.Append(" FROM T_Call_MeetingItems ");
            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_MeetingItems ");
            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_MeetingItemId desc");
            }
            strSql.Append(")AS Row, T.*  from T_Call_MeetingItems 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_MeetingItems";
            parameters[1].Value = "F_MeetingItemId";
            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
    }
}

