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

namespace HySoft.BaseCallCenter.DAL
{
    //T_Fax_SendFaxTask
    public partial class T_Fax_SendFaxTask
    {

        public bool Exists(int FaxID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from T_Fax_SendFaxTask");
            strSql.Append(" where ");
            strSql.Append(" FaxID = @FaxID  ");
            SqlParameter[] parameters = {
					new SqlParameter("@FaxID", SqlDbType.Int,4)
			};
            parameters[0].Value = FaxID;

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



        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.T_Fax_SendFaxTask model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into T_Fax_SendFaxTask(");
            strSql.Append("SendTime,LastSentTime,CurSentCount,MaxSendCount,Info,FileState,State,F_UserID,F_CustomerID,F_Name,TelNum,WebFilePath,FileName,FilePath,TifFilePath,FileSize,FileType,Remark,CommitTime");
            strSql.Append(") values (");
            strSql.Append("@SendTime,@LastSentTime,@CurSentCount,@MaxSendCount,@Info,@FileState,@State,@F_UserID,@F_CustomerID,@F_Name,@TelNum,@WebFilePath,@FileName,@FilePath,@TifFilePath,@FileSize,@FileType,@Remark,@CommitTime");
            strSql.Append(") ");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
			            new SqlParameter("@SendTime", SqlDbType.DateTime) ,            
                        new SqlParameter("@LastSentTime", SqlDbType.DateTime) ,            
                        new SqlParameter("@CurSentCount", SqlDbType.Int,4) ,            
                        new SqlParameter("@MaxSendCount", SqlDbType.Int,4) ,            
                        new SqlParameter("@Info", SqlDbType.VarChar,200) ,            
                        new SqlParameter("@FileState", SqlDbType.Int,4) ,            
                        new SqlParameter("@State", SqlDbType.Int,4) ,            
                        new SqlParameter("@F_UserID", SqlDbType.Int,4) ,            
                        new SqlParameter("@F_CustomerID", SqlDbType.Int,4) ,            
                        new SqlParameter("@F_Name", SqlDbType.NVarChar,50) ,            
                        new SqlParameter("@TelNum", SqlDbType.VarChar,20) ,            
                        new SqlParameter("@WebFilePath", SqlDbType.VarChar,200) ,            
                        new SqlParameter("@FileName", SqlDbType.VarChar,50) ,            
                        new SqlParameter("@FilePath", SqlDbType.VarChar,200) ,            
                        new SqlParameter("@TifFilePath", SqlDbType.VarChar,200) ,            
                        new SqlParameter("@FileSize", SqlDbType.Int,4) ,            
                        new SqlParameter("@FileType", SqlDbType.VarChar,20) ,            
                        new SqlParameter("@Remark", SqlDbType.VarChar,200) ,            
                        new SqlParameter("@CommitTime", SqlDbType.DateTime)             
              
            };

            parameters[0].Value = model.SendTime;
            parameters[1].Value = model.LastSentTime;
            parameters[2].Value = model.CurSentCount;
            parameters[3].Value = model.MaxSendCount;
            parameters[4].Value = model.Info;
            parameters[5].Value = model.FileState;
            parameters[6].Value = model.State;
            parameters[7].Value = model.F_UserID;
            parameters[8].Value = model.F_CustomerID;
            parameters[9].Value = model.F_Name;
            parameters[10].Value = model.TelNum;
            parameters[11].Value = model.WebFilePath;
            parameters[12].Value = model.FileName;
            parameters[13].Value = model.FilePath;
            parameters[14].Value = model.TifFilePath;
            parameters[15].Value = model.FileSize;
            parameters[16].Value = model.FileType;
            parameters[17].Value = model.Remark;
            parameters[18].Value = model.CommitTime;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {

                return Convert.ToInt32(obj);

            }

        }


        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.T_Fax_SendFaxTask model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Fax_SendFaxTask set ");

            strSql.Append(" SendTime = @SendTime , ");
            strSql.Append(" LastSentTime = @LastSentTime , ");
            strSql.Append(" CurSentCount = @CurSentCount , ");
            strSql.Append(" MaxSendCount = @MaxSendCount , ");
            strSql.Append(" Info = @Info , ");
            strSql.Append(" FileState = @FileState , ");
            strSql.Append(" State = @State , ");
            strSql.Append(" F_UserID = @F_UserID , ");
            strSql.Append(" F_CustomerID = @F_CustomerID , ");
            strSql.Append(" F_Name = @F_Name , ");
            strSql.Append(" TelNum = @TelNum , ");
            strSql.Append(" WebFilePath = @WebFilePath , ");
            strSql.Append(" FileName = @FileName , ");
            strSql.Append(" FilePath = @FilePath , ");
            strSql.Append(" TifFilePath = @TifFilePath , ");
            strSql.Append(" FileSize = @FileSize , ");
            strSql.Append(" FileType = @FileType , ");
            strSql.Append(" Remark = @Remark , ");
            strSql.Append(" CommitTime = @CommitTime  ");
            strSql.Append(" where FaxID=@FaxID ");

            SqlParameter[] parameters = {
			            new SqlParameter("@FaxID", SqlDbType.Int,4) ,            
                        new SqlParameter("@SendTime", SqlDbType.DateTime) ,            
                        new SqlParameter("@LastSentTime", SqlDbType.DateTime) ,            
                        new SqlParameter("@CurSentCount", SqlDbType.Int,4) ,            
                        new SqlParameter("@MaxSendCount", SqlDbType.Int,4) ,            
                        new SqlParameter("@Info", SqlDbType.VarChar,200) ,            
                        new SqlParameter("@FileState", SqlDbType.Int,4) ,            
                        new SqlParameter("@State", SqlDbType.Int,4) ,            
                        new SqlParameter("@F_UserID", SqlDbType.Int,4) ,            
                        new SqlParameter("@F_CustomerID", SqlDbType.Int,4) ,            
                        new SqlParameter("@F_Name", SqlDbType.NVarChar,50) ,            
                        new SqlParameter("@TelNum", SqlDbType.VarChar,20) ,            
                        new SqlParameter("@WebFilePath", SqlDbType.VarChar,200) ,            
                        new SqlParameter("@FileName", SqlDbType.VarChar,50) ,            
                        new SqlParameter("@FilePath", SqlDbType.VarChar,200) ,            
                        new SqlParameter("@TifFilePath", SqlDbType.VarChar,200) ,            
                        new SqlParameter("@FileSize", SqlDbType.Int,4) ,            
                        new SqlParameter("@FileType", SqlDbType.VarChar,20) ,            
                        new SqlParameter("@Remark", SqlDbType.VarChar,200) ,            
                        new SqlParameter("@CommitTime", SqlDbType.DateTime)             
              
            };

            parameters[0].Value = model.FaxID;
            parameters[1].Value = model.SendTime;
            parameters[2].Value = model.LastSentTime;
            parameters[3].Value = model.CurSentCount;
            parameters[4].Value = model.MaxSendCount;
            parameters[5].Value = model.Info;
            parameters[6].Value = model.FileState;
            parameters[7].Value = model.State;
            parameters[8].Value = model.F_UserID;
            parameters[9].Value = model.F_CustomerID;
            parameters[10].Value = model.F_Name;
            parameters[11].Value = model.TelNum;
            parameters[12].Value = model.WebFilePath;
            parameters[13].Value = model.FileName;
            parameters[14].Value = model.FilePath;
            parameters[15].Value = model.TifFilePath;
            parameters[16].Value = model.FileSize;
            parameters[17].Value = model.FileType;
            parameters[18].Value = model.Remark;
            parameters[19].Value = model.CommitTime;
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public int UpdateWebFilePath(Model.T_Fax_SendFaxTask model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Fax_SendFaxTask set ");
            strSql.Append("WebFilePath=@WebFilePath");
            strSql.Append(" where FaxID=@FaxID ");
            SqlParameter[] parameters = {
					new SqlParameter("@FaxID", SqlDbType.Int,4),
					new SqlParameter("@WebFilePath", SqlDbType.VarChar,200)};
            parameters[0].Value = model.FaxID;
            parameters[1].Value = model.WebFilePath;

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

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

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


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

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


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

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select FaxID, SendTime, LastSentTime, CurSentCount, MaxSendCount, Info, FileState, State, F_UserID, F_CustomerID, F_Name, TelNum, WebFilePath, FileName, FilePath, TifFilePath, FileSize, FileType, Remark, CommitTime  ");
            strSql.Append("  from T_Fax_SendFaxTask ");
            strSql.Append(" where FaxID=@FaxID");
            SqlParameter[] parameters = {
					new SqlParameter("@FaxID", SqlDbType.Int,4)
			};
            parameters[0].Value = FaxID;


            Model.T_Fax_SendFaxTask model = new Model.T_Fax_SendFaxTask();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["FaxID"].ToString() != "")
                {
                    model.FaxID = int.Parse(ds.Tables[0].Rows[0]["FaxID"].ToString());
                }
                if (ds.Tables[0].Rows[0]["SendTime"].ToString() != "")
                {
                    model.SendTime = DateTime.Parse(ds.Tables[0].Rows[0]["SendTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["LastSentTime"].ToString() != "")
                {
                    model.LastSentTime = DateTime.Parse(ds.Tables[0].Rows[0]["LastSentTime"].ToString());
                }
                if (ds.Tables[0].Rows[0]["CurSentCount"].ToString() != "")
                {
                    model.CurSentCount = int.Parse(ds.Tables[0].Rows[0]["CurSentCount"].ToString());
                }
                if (ds.Tables[0].Rows[0]["MaxSendCount"].ToString() != "")
                {
                    model.MaxSendCount = int.Parse(ds.Tables[0].Rows[0]["MaxSendCount"].ToString());
                }
                model.Info = ds.Tables[0].Rows[0]["Info"].ToString();
                if (ds.Tables[0].Rows[0]["FileState"].ToString() != "")
                {
                    model.FileState = int.Parse(ds.Tables[0].Rows[0]["FileState"].ToString());
                }
                if (ds.Tables[0].Rows[0]["State"].ToString() != "")
                {
                    model.State = int.Parse(ds.Tables[0].Rows[0]["State"].ToString());
                }
                if (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_CustomerID"].ToString() != "")
                {
                    model.F_CustomerID = int.Parse(ds.Tables[0].Rows[0]["F_CustomerID"].ToString());
                }
                model.F_Name = ds.Tables[0].Rows[0]["F_Name"].ToString();
                model.TelNum = ds.Tables[0].Rows[0]["TelNum"].ToString();
                model.WebFilePath = ds.Tables[0].Rows[0]["WebFilePath"].ToString();
                model.FileName = ds.Tables[0].Rows[0]["FileName"].ToString();
                model.FilePath = ds.Tables[0].Rows[0]["FilePath"].ToString();
                model.TifFilePath = ds.Tables[0].Rows[0]["TifFilePath"].ToString();
                if (ds.Tables[0].Rows[0]["FileSize"].ToString() != "")
                {
                    model.FileSize = int.Parse(ds.Tables[0].Rows[0]["FileSize"].ToString());
                }
                model.FileType = ds.Tables[0].Rows[0]["FileType"].ToString();
                model.Remark = ds.Tables[0].Rows[0]["Remark"].ToString();
                if (ds.Tables[0].Rows[0]["CommitTime"].ToString() != "")
                {
                    model.CommitTime = DateTime.Parse(ds.Tables[0].Rows[0]["CommitTime"].ToString());
                }

                return model;
            }
            else
            {
                return null;
            }
        }


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


    }
}
