using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using CallCenterApi.DB;

namespace CallCenterApi.DAL
{
    /// <summary>
    /// 数据访问类:T_Wo_WorkOrder
    /// </summary>
    public partial class T_Wo_WorkOrder
    {
        public T_Wo_WorkOrder()
        { }
        #region  BasicMethod
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(long ID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from T_Wo_WorkOrder");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters = {
                    new SqlParameter("@ID", SqlDbType.BigInt)
            };
            parameters[0].Value = ID;

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

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string OrderID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from T_Wo_WorkOrder");
            strSql.Append(" where WorkOrderID=@ID");
            SqlParameter[] parameters = {
                    new SqlParameter("@ID", SqlDbType.BigInt)
            };
            parameters[0].Value = OrderID;

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

        /// <summary>
		/// 增加一条数据
		/// </summary>
		public long Add(CallCenterApi.Model.T_Wo_WorkOrder model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into T_Wo_WorkOrder(");
            strSql.Append("WorkOrderID,Type,TypeClass,Title,Detail,Files,ResponDept,ResponUser,CallID,CustomerID,Customer,CustomerTel,Province,City,County,Address,Source,Answer,State,LastDealUser,LastDealTime,IsReturn,LimitTime,IsReturnBak,ReturnBakTime,IsTimeOut,IsUserSend,IsAdminSend,CreateUser,CreateTime,IsDel,DelUser,DelTime,IsAudit,AuditState,AuditUser,AuditTime,AuditCont,AppointTime,clcontent,InfoType,InfoTypeID,ISReward,RewardAmount,RewardTime,UnitID,Unit,Inqtime,Inquser,Remark,WjID,InfoTypeDetail,InfoTypeDetailID,IsRestore)");
            strSql.Append(" values (");
            strSql.Append("@WorkOrderID,@Type,@TypeClass,@Title,@Detail,@Files,@ResponDept,@ResponUser,@CallID,@CustomerID,@Customer,@CustomerTel,@Province,@City,@County,@Address,@Source,@Answer,@State,@LastDealUser,@LastDealTime,@IsReturn,@LimitTime,@IsReturnBak,@ReturnBakTime,@IsTimeOut,@IsUserSend,@IsAdminSend,@CreateUser,@CreateTime,@IsDel,@DelUser,@DelTime,@IsAudit,@AuditState,@AuditUser,@AuditTime,@AuditCont,@AppointTime,@clcontent,@InfoType,@InfoTypeID,@ISReward,@RewardAmount,@RewardTime,@UnitID,@Unit,@Inqtime,@Inquser,@Remark,@WjID,@InfoTypeDetail,@InfoTypeDetailID,@IsRestore)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
                    new SqlParameter("@WorkOrderID", SqlDbType.VarChar,50),
                    new SqlParameter("@Type", SqlDbType.Int,4),
                    new SqlParameter("@TypeClass", SqlDbType.Int,4),
                    new SqlParameter("@Title", SqlDbType.NVarChar,200),
                    new SqlParameter("@Detail", SqlDbType.NVarChar,-1),
                    new SqlParameter("@Files", SqlDbType.VarChar,-1),
                    new SqlParameter("@ResponDept", SqlDbType.Int,4),
                    new SqlParameter("@ResponUser", SqlDbType.VarChar,50),
                    new SqlParameter("@CallID", SqlDbType.VarChar,50),
                    new SqlParameter("@CustomerID", SqlDbType.Int,4),
                    new SqlParameter("@Customer", SqlDbType.NVarChar,200),
                    new SqlParameter("@CustomerTel", SqlDbType.VarChar,20),
                    new SqlParameter("@Province", SqlDbType.VarChar,50),
                    new SqlParameter("@City", SqlDbType.VarChar,50),
                    new SqlParameter("@County", SqlDbType.VarChar,50),
                    new SqlParameter("@Address", SqlDbType.VarChar,200),
                    new SqlParameter("@Source", SqlDbType.VarChar,50),
                    new SqlParameter("@Answer", SqlDbType.NVarChar,-1),
                    new SqlParameter("@State", SqlDbType.Int,4),
                    new SqlParameter("@LastDealUser", SqlDbType.VarChar,50),
                    new SqlParameter("@LastDealTime", SqlDbType.DateTime),
                    new SqlParameter("@IsReturn", SqlDbType.Int,4),
                    new SqlParameter("@LimitTime", SqlDbType.Decimal,9),
                    new SqlParameter("@IsReturnBak", SqlDbType.Int,4),
                    new SqlParameter("@ReturnBakTime", SqlDbType.DateTime),
                    new SqlParameter("@IsTimeOut", SqlDbType.Int,4),
                    new SqlParameter("@IsUserSend", SqlDbType.Int,4),
                    new SqlParameter("@IsAdminSend", SqlDbType.Int,4),
                    new SqlParameter("@CreateUser", SqlDbType.VarChar,50),
                    new SqlParameter("@CreateTime", SqlDbType.DateTime),
                    new SqlParameter("@IsDel", SqlDbType.Int,4),
                    new SqlParameter("@DelUser", SqlDbType.VarChar,50),
                    new SqlParameter("@DelTime", SqlDbType.DateTime),
                    new SqlParameter("@IsAudit", SqlDbType.Int,4),
                    new SqlParameter("@AuditState", SqlDbType.Int,4),
                    new SqlParameter("@AuditUser", SqlDbType.VarChar,50),
                    new SqlParameter("@AuditTime", SqlDbType.DateTime),
                    new SqlParameter("@AuditCont", SqlDbType.NVarChar,-1),
                    new SqlParameter("@AppointTime", SqlDbType.DateTime),
                    new SqlParameter("@clcontent", SqlDbType.NText),
                    new SqlParameter("@InfoType", SqlDbType.NVarChar,500),
                    new SqlParameter("@InfoTypeID", SqlDbType.Int,4),
                    new SqlParameter("@ISReward", SqlDbType.Int,4),
                    new SqlParameter("@RewardAmount", SqlDbType.NVarChar,50),
                    new SqlParameter("@RewardTime", SqlDbType.NVarChar,50),
                    new SqlParameter("@UnitID", SqlDbType.Int,4),
                    new SqlParameter("@Unit", SqlDbType.NVarChar,90),
                    new SqlParameter("@Inqtime", SqlDbType.DateTime),
                    new SqlParameter("@Inquser", SqlDbType.NVarChar,90),
                    new SqlParameter("@Remark", SqlDbType.NVarChar,-1),
                    new SqlParameter("@WjID", SqlDbType.Int,4),

                     new SqlParameter("@InfoTypeDetail", SqlDbType.NVarChar,500),
                    new SqlParameter("@InfoTypeDetailID", SqlDbType.Int,4),
                     new SqlParameter("@IsRestore", SqlDbType.Int,4)

                    
            };
            parameters[0].Value = model.WorkOrderID;
            parameters[1].Value = model.Type;
            parameters[2].Value = model.TypeClass;
            parameters[3].Value = model.Title;
            parameters[4].Value = model.Detail;
            parameters[5].Value = model.Files;
            parameters[6].Value = model.ResponDept;
            parameters[7].Value = model.ResponUser;
            parameters[8].Value = model.CallID;
            parameters[9].Value = model.CustomerID;
            parameters[10].Value = model.Customer;
            parameters[11].Value = model.CustomerTel;
            parameters[12].Value = model.Province;
            parameters[13].Value = model.City;
            parameters[14].Value = model.County;
            parameters[15].Value = model.Address;
            parameters[16].Value = model.Source;
            parameters[17].Value = model.Answer;
            parameters[18].Value = model.State;
            parameters[19].Value = model.LastDealUser;
            parameters[20].Value = model.LastDealTime;
            parameters[21].Value = model.IsReturn;
            parameters[22].Value = model.LimitTime;
            parameters[23].Value = model.IsReturnBak;
            parameters[24].Value = model.ReturnBakTime;
            parameters[25].Value = model.IsTimeOut;
            parameters[26].Value = model.IsUserSend;
            parameters[27].Value = model.IsAdminSend;
            parameters[28].Value = model.CreateUser;
            parameters[29].Value = model.CreateTime;
            parameters[30].Value = model.IsDel;
            parameters[31].Value = model.DelUser;
            parameters[32].Value = model.DelTime;
            parameters[33].Value = model.IsAudit;
            parameters[34].Value = model.AuditState;
            parameters[35].Value = model.AuditUser;
            parameters[36].Value = model.AuditTime;
            parameters[37].Value = model.AuditCont;
            parameters[38].Value = model.AppointTime;
            parameters[39].Value = model.Clcontent;
            parameters[40].Value = model.InfoType;
            parameters[41].Value = model.InfoTypeID;
            parameters[42].Value = model.ISReward;
            parameters[43].Value = model.RewardAmount;
            parameters[44].Value = model.RewardTime;
            parameters[45].Value = model.UnitID;
            parameters[46].Value = model.Unit;
            parameters[47].Value = model.Inqtime;
            parameters[48].Value = model.Inquser;
            parameters[49].Value = model.Remark;
            parameters[50].Value = model.WjID;

            parameters[51].Value = model.InfoTypeDetail;
            parameters[52].Value = model.InfoTypeDetailID;
            parameters[53].Value = model.IsRestore;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt64(obj);
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(CallCenterApi.Model.T_Wo_WorkOrder model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Wo_WorkOrder set ");
            strSql.Append("WorkOrderID=@WorkOrderID,");
            strSql.Append("Type=@Type,");
            strSql.Append("TypeClass=@TypeClass,");
            strSql.Append("Title=@Title,");
            strSql.Append("Detail=@Detail,");
            strSql.Append("Files=@Files,");
            strSql.Append("ResponDept=@ResponDept,");
            strSql.Append("ResponUser=@ResponUser,");
            strSql.Append("CallID=@CallID,");
            strSql.Append("CustomerID=@CustomerID,");
            strSql.Append("Customer=@Customer,");
            strSql.Append("CustomerTel=@CustomerTel,");
            strSql.Append("Province=@Province,");
            strSql.Append("City=@City,");
            strSql.Append("County=@County,");
            strSql.Append("Address=@Address,");
            strSql.Append("Source=@Source,");
            strSql.Append("Answer=@Answer,");
            strSql.Append("State=@State,");
            strSql.Append("LastDealUser=@LastDealUser,");
            strSql.Append("LastDealTime=@LastDealTime,");
            strSql.Append("IsReturn=@IsReturn,");
            strSql.Append("LimitTime=@LimitTime,");
            strSql.Append("IsReturnBak=@IsReturnBak,");
            strSql.Append("ReturnBakTime=@ReturnBakTime,");
            strSql.Append("IsTimeOut=@IsTimeOut,");
            strSql.Append("IsUserSend=@IsUserSend,");
            strSql.Append("IsAdminSend=@IsAdminSend,");
            strSql.Append("CreateUser=@CreateUser,");
            strSql.Append("CreateTime=@CreateTime,");
            strSql.Append("IsDel=@IsDel,");
            strSql.Append("DelUser=@DelUser,");
            strSql.Append("DelTime=@DelTime,");
            strSql.Append("IsAudit=@IsAudit,");
            strSql.Append("AuditState=@AuditState,");
            strSql.Append("AuditUser=@AuditUser,");
            strSql.Append("AuditTime=@AuditTime,");
            strSql.Append("AuditCont=@AuditCont,");
            strSql.Append("AppointTime=@AppointTime,");
            strSql.Append("clcontent=@clcontent,");
            strSql.Append("InfoType=@InfoType,");
            strSql.Append("InfoTypeID=@InfoTypeID,");
            strSql.Append("ISReward=@ISReward,");
            strSql.Append("RewardAmount=@RewardAmount,");
            strSql.Append("RewardTime=@RewardTime,");
            strSql.Append("UnitID=@UnitID,");
            strSql.Append("Unit=@Unit,");
            strSql.Append("Inqtime=@Inqtime,");
            strSql.Append("Inquser=@Inquser,");
            strSql.Append("Remark=@Remark,");
            strSql.Append("WjID=@WjID,");
            strSql.Append("InfoTypeDetail=@InfoTypeDetail,");
            strSql.Append("InfoTypeDetailID=@InfoTypeDetailID,");
            strSql.Append("IsRestore=@IsRestore");
            
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters = {
                    new SqlParameter("@WorkOrderID", SqlDbType.VarChar,50),
                    new SqlParameter("@Type", SqlDbType.Int,4),
                    new SqlParameter("@TypeClass", SqlDbType.Int,4),
                    new SqlParameter("@Title", SqlDbType.NVarChar,200),
                    new SqlParameter("@Detail", SqlDbType.NVarChar,-1),
                    new SqlParameter("@Files", SqlDbType.VarChar,-1),
                    new SqlParameter("@ResponDept", SqlDbType.Int,4),
                    new SqlParameter("@ResponUser", SqlDbType.VarChar,50),
                    new SqlParameter("@CallID", SqlDbType.VarChar,50),
                    new SqlParameter("@CustomerID", SqlDbType.Int,4),
                    new SqlParameter("@Customer", SqlDbType.NVarChar,200),
                    new SqlParameter("@CustomerTel", SqlDbType.VarChar,20),
                    new SqlParameter("@Province", SqlDbType.VarChar,50),
                    new SqlParameter("@City", SqlDbType.VarChar,50),
                    new SqlParameter("@County", SqlDbType.VarChar,50),
                    new SqlParameter("@Address", SqlDbType.VarChar,200),
                    new SqlParameter("@Source", SqlDbType.VarChar,50),
                    new SqlParameter("@Answer", SqlDbType.NVarChar,-1),
                    new SqlParameter("@State", SqlDbType.Int,4),
                    new SqlParameter("@LastDealUser", SqlDbType.VarChar,50),
                    new SqlParameter("@LastDealTime", SqlDbType.DateTime),
                    new SqlParameter("@IsReturn", SqlDbType.Int,4),
                    new SqlParameter("@LimitTime", SqlDbType.Decimal,9),
                    new SqlParameter("@IsReturnBak", SqlDbType.Int,4),
                    new SqlParameter("@ReturnBakTime", SqlDbType.DateTime),
                    new SqlParameter("@IsTimeOut", SqlDbType.Int,4),
                    new SqlParameter("@IsUserSend", SqlDbType.Int,4),
                    new SqlParameter("@IsAdminSend", SqlDbType.Int,4),
                    new SqlParameter("@CreateUser", SqlDbType.VarChar,50),
                    new SqlParameter("@CreateTime", SqlDbType.DateTime),
                    new SqlParameter("@IsDel", SqlDbType.Int,4),
                    new SqlParameter("@DelUser", SqlDbType.VarChar,50),
                    new SqlParameter("@DelTime", SqlDbType.DateTime),
                    new SqlParameter("@IsAudit", SqlDbType.Int,4),
                    new SqlParameter("@AuditState", SqlDbType.Int,4),
                    new SqlParameter("@AuditUser", SqlDbType.VarChar,50),
                    new SqlParameter("@AuditTime", SqlDbType.DateTime),
                    new SqlParameter("@AuditCont", SqlDbType.NVarChar,-1),
                    new SqlParameter("@AppointTime", SqlDbType.DateTime),
                    new SqlParameter("@clcontent", SqlDbType.NText),
                    new SqlParameter("@InfoType", SqlDbType.NVarChar,500),
                    new SqlParameter("@InfoTypeID", SqlDbType.Int,4),
                    new SqlParameter("@ISReward", SqlDbType.Int,4),
                    new SqlParameter("@RewardAmount", SqlDbType.NVarChar,50),
                    new SqlParameter("@RewardTime", SqlDbType.NVarChar,50),
                    new SqlParameter("@UnitID", SqlDbType.Int,4),
                    new SqlParameter("@Unit", SqlDbType.NVarChar,90),
                    new SqlParameter("@Inqtime", SqlDbType.DateTime),
                    new SqlParameter("@Inquser", SqlDbType.NVarChar,90),
                    new SqlParameter("@Remark", SqlDbType.NVarChar,-1),
                    new SqlParameter("@WjID", SqlDbType.Int,4),

                     new SqlParameter("@InfoTypeDetail", SqlDbType.NVarChar,100),
                    new SqlParameter("@InfoTypeDetailID", SqlDbType.Int,4),
                    new SqlParameter("@IsRestore", SqlDbType.Int,4),

                    


                    new SqlParameter("@ID", SqlDbType.BigInt,8)};
            parameters[0].Value = model.WorkOrderID;
            parameters[1].Value = model.Type;
            parameters[2].Value = model.TypeClass;
            parameters[3].Value = model.Title;
            parameters[4].Value = model.Detail;
            parameters[5].Value = model.Files;
            parameters[6].Value = model.ResponDept;
            parameters[7].Value = model.ResponUser;
            parameters[8].Value = model.CallID;
            parameters[9].Value = model.CustomerID;
            parameters[10].Value = model.Customer;
            parameters[11].Value = model.CustomerTel;
            parameters[12].Value = model.Province;
            parameters[13].Value = model.City;
            parameters[14].Value = model.County;
            parameters[15].Value = model.Address;
            parameters[16].Value = model.Source;
            parameters[17].Value = model.Answer;
            parameters[18].Value = model.State;
            parameters[19].Value = model.LastDealUser;
            parameters[20].Value = model.LastDealTime;
            parameters[21].Value = model.IsReturn;
            parameters[22].Value = model.LimitTime;
            parameters[23].Value = model.IsReturnBak;
            parameters[24].Value = model.ReturnBakTime;
            parameters[25].Value = model.IsTimeOut;
            parameters[26].Value = model.IsUserSend;
            parameters[27].Value = model.IsAdminSend;
            parameters[28].Value = model.CreateUser;
            parameters[29].Value = model.CreateTime;
            parameters[30].Value = model.IsDel;
            parameters[31].Value = model.DelUser;
            parameters[32].Value = model.DelTime;
            parameters[33].Value = model.IsAudit;
            parameters[34].Value = model.AuditState;
            parameters[35].Value = model.AuditUser;
            parameters[36].Value = model.AuditTime;
            parameters[37].Value = model.AuditCont;
            parameters[38].Value = model.AppointTime;
            parameters[39].Value = model.Clcontent;
            parameters[40].Value = model.InfoType;
            parameters[41].Value = model.InfoTypeID;
            parameters[42].Value = model.ISReward;
            parameters[43].Value = model.RewardAmount;
            parameters[44].Value = model.RewardTime;
            parameters[45].Value = model.UnitID;
            parameters[46].Value = model.Unit;
            parameters[47].Value = model.Inqtime;
            parameters[48].Value = model.Inquser;
            parameters[49].Value = model.Remark;
            parameters[50].Value = model.WjID;
         
            parameters[51].Value = model.InfoTypeDetail;
            parameters[52].Value = model.InfoTypeDetailID;
            parameters[53].Value = model.IsRestore;
            parameters[54].Value = model.ID;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(long ID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from T_Wo_WorkOrder ");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters = {
                    new SqlParameter("@ID", SqlDbType.BigInt)
            };
            parameters[0].Value = ID;

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


        /// <summary>
		/// 得到一个对象实体
		/// </summary>
		public CallCenterApi.Model.T_Wo_WorkOrder GetModel(long ID)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 * from T_Wo_WorkOrder ");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters = {
                    new SqlParameter("@ID", SqlDbType.BigInt)
            };
            parameters[0].Value = ID;

            CallCenterApi.Model.T_Wo_WorkOrder model = new CallCenterApi.Model.T_Wo_WorkOrder();
            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_Wo_WorkOrder DataRowToModel(DataRow row)
        {
            CallCenterApi.Model.T_Wo_WorkOrder model = new CallCenterApi.Model.T_Wo_WorkOrder();
            if (row != null)
            {
                if (row["ID"] != null && row["ID"].ToString() != "")
                {
                    model.ID = long.Parse(row["ID"].ToString());
                }
                if (row["WorkOrderID"] != null)
                {
                    model.WorkOrderID = row["WorkOrderID"].ToString();
                }
                if (row["Type"] != null && row["Type"].ToString() != "")
                {
                    model.Type = int.Parse(row["Type"].ToString());
                }
                if (row["TypeClass"] != null && row["TypeClass"].ToString() != "")
                {
                    model.TypeClass = int.Parse(row["TypeClass"].ToString());
                }
                if (row["Title"] != null)
                {
                    model.Title = row["Title"].ToString();
                }
                if (row["Detail"] != null)
                {
                    model.Detail = row["Detail"].ToString();
                }
                if (row["Files"] != null)
                {
                    model.Files = row["Files"].ToString();
                }
                if (row["ResponDept"] != null && row["ResponDept"].ToString() != "")
                {
                    model.ResponDept = int.Parse(row["ResponDept"].ToString());
                }
                if (row["ResponUser"] != null)
                {
                    model.ResponUser = row["ResponUser"].ToString();
                }
                if (row["CallID"] != null)
                {
                    model.CallID = row["CallID"].ToString();
                }
                if (row["CustomerID"] != null && row["CustomerID"].ToString() != "")
                {
                    model.CustomerID = int.Parse(row["CustomerID"].ToString());
                }
                if (row["Customer"] != null)
                {
                    model.Customer = row["Customer"].ToString();
                }
                if (row["CustomerTel"] != null)
                {
                    model.CustomerTel = row["CustomerTel"].ToString();
                }
                if (row["Province"] != null)
                {
                    model.Province = row["Province"].ToString();
                }
                if (row["City"] != null)
                {
                    model.City = row["City"].ToString();
                }
                if (row["County"] != null)
                {
                    model.County = row["County"].ToString();
                }
                if (row["Address"] != null)
                {
                    model.Address = row["Address"].ToString();
                }
                if (row["Source"] != null)
                {
                    model.Source = row["Source"].ToString();
                }
                if (row["Answer"] != null)
                {
                    model.Answer = row["Answer"].ToString();
                }
                if (row["State"] != null && row["State"].ToString() != "")
                {
                    model.State = int.Parse(row["State"].ToString());
                }
                if (row["LastDealUser"] != null)
                {
                    model.LastDealUser = row["LastDealUser"].ToString();
                }
                if (row["LastDealTime"] != null && row["LastDealTime"].ToString() != "")
                {
                    model.LastDealTime = DateTime.Parse(row["LastDealTime"].ToString());
                }
                if (row["IsReturn"] != null && row["IsReturn"].ToString() != "")
                {
                    model.IsReturn = int.Parse(row["IsReturn"].ToString());
                }
                if (row["LimitTime"] != null && row["LimitTime"].ToString() != "")
                {
                    model.LimitTime = decimal.Parse(row["LimitTime"].ToString());
                }
                if (row["IsReturnBak"] != null && row["IsReturnBak"].ToString() != "")
                {
                    model.IsReturnBak = int.Parse(row["IsReturnBak"].ToString());
                }
                if (row["ReturnBakTime"] != null && row["ReturnBakTime"].ToString() != "")
                {
                    model.ReturnBakTime = DateTime.Parse(row["ReturnBakTime"].ToString());
                }
                if (row["IsTimeOut"] != null && row["IsTimeOut"].ToString() != "")
                {
                    model.IsTimeOut = int.Parse(row["IsTimeOut"].ToString());
                }
                if (row["IsUserSend"] != null && row["IsUserSend"].ToString() != "")
                {
                    model.IsUserSend = int.Parse(row["IsUserSend"].ToString());
                }
                if (row["IsAdminSend"] != null && row["IsAdminSend"].ToString() != "")
                {
                    model.IsAdminSend = int.Parse(row["IsAdminSend"].ToString());
                }
                if (row["CreateUser"] != null)
                {
                    model.CreateUser = row["CreateUser"].ToString();
                }
                if (row["CreateTime"] != null && row["CreateTime"].ToString() != "")
                {
                    model.CreateTime = DateTime.Parse(row["CreateTime"].ToString());
                }
                if (row["IsDel"] != null && row["IsDel"].ToString() != "")
                {
                    model.IsDel = int.Parse(row["IsDel"].ToString());
                }
                if (row["DelUser"] != null)
                {
                    model.DelUser = row["DelUser"].ToString();
                }
                if (row["DelTime"] != null && row["DelTime"].ToString() != "")
                {
                    model.DelTime = DateTime.Parse(row["DelTime"].ToString());
                }
                if (row["IsAudit"] != null && row["IsAudit"].ToString() != "")
                {
                    model.IsAudit = int.Parse(row["IsAudit"].ToString());
                }
                if (row["AuditState"] != null && row["AuditState"].ToString() != "")
                {
                    model.AuditState = int.Parse(row["AuditState"].ToString());
                }
                if (row["AuditUser"] != null)
                {
                    model.AuditUser = row["AuditUser"].ToString();
                }
                if (row["AuditTime"] != null && row["AuditTime"].ToString() != "")
                {
                    model.AuditTime = DateTime.Parse(row["AuditTime"].ToString());
                }
                if (row["AuditCont"] != null)
                {
                    model.AuditCont = row["AuditCont"].ToString();
                }
                if (row["AppointTime"] != null && row["AppointTime"].ToString() != "")
                {
                    model.AppointTime = DateTime.Parse(row["AppointTime"].ToString());
                }
                if (row["Clcontent"] != null)
                {
                    model.Clcontent = row["Clcontent"].ToString();
                }
                if (row["InfoType"] != null)
                {
                    model.InfoType = row["InfoType"].ToString();
                }
                if (row["InfoTypeID"] != null && row["InfoTypeID"].ToString() != "")
                {
                    model.InfoTypeID = int.Parse(row["InfoTypeID"].ToString());
                }
                if (row["ISReward"] != null && row["ISReward"].ToString() != "")
                {
                    model.ISReward = int.Parse(row["ISReward"].ToString());
                }
                if (row["RewardAmount"] != null)
                {
                    model.RewardAmount = row["RewardAmount"].ToString();
                }
                if (row["RewardTime"] != null)
                {
                    model.RewardTime = row["RewardTime"].ToString();
                }
                if (row["UnitID"] != null && row["UnitID"].ToString() != "")
                {
                    model.UnitID = int.Parse(row["UnitID"].ToString());
                }
                if (row["Unit"] != null)
                {
                    model.Unit = row["Unit"].ToString();
                }
                if (row["Inqtime"] != null && row["Inqtime"].ToString() != "")
                {
                    model.Inqtime = DateTime.Parse(row["Inqtime"].ToString());
                }
                if (row["Inquser"] != null)
                {
                    model.Inquser = row["Inquser"].ToString();
                }
                if (row["Remark"] != null)
                {
                    model.Remark = row["Remark"].ToString();
                }
                if (row["WjID"] != null && row["WjID"].ToString() != "")
                {
                    model.WjID = int.Parse(row["WjID"].ToString());
                }

                if (row["InfoTypeDetail"] != null)
                {
                    model.InfoTypeDetail = row["InfoTypeDetail"].ToString();
                }
                if (row["InfoTypeDetailID"] != null && row["InfoTypeDetailID"].ToString() != "")
                {
                    model.InfoTypeDetailID = int.Parse(row["InfoTypeDetailID"].ToString());
                }
                if (row["IsRestore"] != null && row["IsRestore"].ToString() != "")
                {
                    model.IsRestore = int.Parse(row["IsRestore"].ToString());
                }

                

            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM T_Wo_WorkOrder ");
            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_Wo_WorkOrder ");
            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_Wo_WorkOrder ");
            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.ID desc");
            }
            strSql.Append(")AS Row, T.*  from T_Wo_WorkOrder 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_Wo_WorkOrder";
			parameters[1].Value = "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  BasicMethod
        #region  ExtensionMethod

        /// <summary>
        /// 处理工单
        /// </summary>
        public int DealWorkOrder(string strorderid, int isend, string strcont, int jsbm, string jsgh, string clgh
            ,int isaudit, string infotype,int infotypeid,int unitid,string unit
            )
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@orderid", SqlDbType.VarChar, 50),
                    new SqlParameter("@isend", SqlDbType.Int),
                    new SqlParameter("@cont", SqlDbType.NVarChar,-1),
                    new SqlParameter("@jsbm", SqlDbType.Int),
                    new SqlParameter("@jsgh", SqlDbType.VarChar,-1),
                    new SqlParameter("@clgh", SqlDbType.VarChar,50),
                    new SqlParameter("@IsAudit", SqlDbType.Int),
                    new SqlParameter("@InfoTypeID", SqlDbType.Int),
                    new SqlParameter("@InfoType", SqlDbType.VarChar,50),
                    new SqlParameter("@UnitID", SqlDbType.Int),
                    new SqlParameter("@Unit", SqlDbType.VarChar,50)
                    };
            parameters[0].Value = strorderid;
            parameters[1].Value = isend;
            parameters[2].Value = strcont;
            parameters[3].Value = jsbm;
            parameters[4].Value = jsgh;
            parameters[5].Value = clgh;
            parameters[6].Value = isaudit;
            parameters[7].Value = infotypeid;
            parameters[8].Value = infotype;
            parameters[9].Value = unitid;
            parameters[10].Value = unit;
            int n = 0;
            return DbHelperSQL.RunProcedure("DealWorkOrder", parameters, out n);
        }

        /// <summary>
        /// 处理工单
        /// </summary>
        public int DealWorkOrder1(string strorderid, int isend
           , string customer, string custel, string inqtime, string inquser, string country, string address
           , string detail, string strcont, string answer, string remark
           , int jsbm, string jsgh, string clgh, string infotype, int infotypeid, int unitid, string unit
           )
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@orderid", SqlDbType.VarChar, 50),
                    new SqlParameter("@isend", SqlDbType.Int),
                    new SqlParameter("@Customer", SqlDbType.VarChar, 50),//姓 名
                    new SqlParameter("@CustomerTel", SqlDbType.VarChar, 50),//电 话
                    new SqlParameter("@country", SqlDbType.VarChar, 50),//县镇
                    new SqlParameter("@Address", SqlDbType.VarChar, 50),//住 址
                    new SqlParameter("@cont", SqlDbType.NVarChar,-1),//处理内容(问题处理情况)
                    new SqlParameter("@Answer", SqlDbType.NVarChar,-1),//回访反馈情况
                    new SqlParameter("@Detail", SqlDbType.NVarChar,-1),//反映问题(工单内容)
                    new SqlParameter("@Remark", SqlDbType.NVarChar,-1),//备注
                    new SqlParameter("@InqUser", SqlDbType.VarChar, 50),//调查员
                    new SqlParameter("@InqTime", SqlDbType.DateTime),//调查时间
                    new SqlParameter("@jsbm", SqlDbType.Int),
                    new SqlParameter("@jsgh", SqlDbType.VarChar,-1),
                    new SqlParameter("@clgh", SqlDbType.VarChar,50),
                    new SqlParameter("@InfoTypeID", SqlDbType.Int),
                    new SqlParameter("@InfoType", SqlDbType.VarChar,50),
                    new SqlParameter("@UnitID", SqlDbType.Int),
                    new SqlParameter("@Unit", SqlDbType.VarChar,50)
                    };
            parameters[0].Value = strorderid;
            parameters[1].Value = isend;
            parameters[2].Value = customer;
            parameters[3].Value = custel;
            parameters[4].Value = country;
            parameters[5].Value = address;
            parameters[6].Value = strcont;
            parameters[7].Value = answer;
            parameters[8].Value = detail;
            parameters[9].Value = remark;
            parameters[10].Value = inquser;
            parameters[11].Value = inqtime;
            parameters[12].Value = jsbm;
            parameters[13].Value = jsgh;
            parameters[14].Value = clgh;
            parameters[15].Value = infotypeid;
            parameters[16].Value = infotype;
            parameters[17].Value = unitid;
            parameters[18].Value = unit;
            int n = 0;
            return DbHelperSQL.RunProcedure("DealWorkOrder", parameters, out n);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool UpdateReward(long woid,int isreward,string amount,string time)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_Wo_WorkOrder set ");
            strSql.Append("ISReward=@ISReward,");
            strSql.Append("RewardAmount=@RewardAmount,");
            strSql.Append("RewardTime=@RewardTime");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters = {
                    new SqlParameter("@ISReward", SqlDbType.Int,4),
                    new SqlParameter("@RewardAmount", SqlDbType.NVarChar,50),
                    new SqlParameter("@RewardTime", SqlDbType.NVarChar,50),
                    new SqlParameter("@ID", SqlDbType.BigInt,8)};
            parameters[0].Value = isreward;
            parameters[1].Value = amount;
            parameters[2].Value = time;
            parameters[3].Value = woid;

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


