using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Reflection;
using System.Text;
using RMYY_CallCenter_Api.DB;

namespace RMYY_CallCenter_Api.Dal
{
    public   class T_WowoRepair_Basedal
    {
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string T_Wowocodeid)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from T_WowoRepair_Base ");
            strSql.Append(" where T_Wowocodeid=@T_Wowocodeid");
            SqlParameter[] parameters = {
                    new SqlParameter("@T_Wowocodeid", SqlDbType.Int,4)
            };
            parameters[0].Value = T_Wowocodeid;

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

        #region 添加
        /// <summary>
        /// 增加一条报修工单数据
        /// </summary>
        public int Addrepair(RMYY_CallCenter_Api.Model.T_WowoRepair_Base model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into T_WowoRepair_Base(");
            strSql.Append("T_workercode,T_Wowocodetype,T_Wowocodecnnal,T_Wofrindpid,T_Wowocodestate,T_Wowocodecenter,T_Wocreaterepairman,T_Worepairman,T_Worepairmanphone,T_Worepairdate,T_Worepairyqid,T_Worepairdeptid,T_Worepairaddress,T_Woimageid,T_Wotousercode,T_Wotousertime,T_Wodealrepairman,T_Wodealdesmo,T_Wothbecause,T_Wodealtime)");
            strSql.Append(" values (");
            strSql.Append("@T_workercode,@T_Wowocodetype,@T_Wowocodecnnal,@T_Wofrindpid,@T_Wowocodestate,@T_Wowocodecenter,@T_Wocreaterepairman,@T_Worepairman,@T_Worepairmanphone,@T_Worepairdate,@T_Worepairyqid,@T_Worepairdeptid,@T_Worepairaddress,@T_Woimageid,@T_Wotousercode,@T_Wotousertime,@T_Wodealrepairman,@T_Wodealdesmo,@T_Wothbecause,@T_Wodealtime)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
                 new SqlParameter("@T_workercode", SqlDbType.NVarChar,100),
                    new SqlParameter("@T_Wowocodetype", SqlDbType.Int,4),
                     new SqlParameter("@T_Wowocodecnnal", SqlDbType.NVarChar,100),
                    new SqlParameter("@T_Wofrindpid", SqlDbType.Int,4),
                    new SqlParameter("@T_Wowocodestate", SqlDbType.Int,4),
                    new SqlParameter("@T_Wowocodecenter", SqlDbType.NVarChar,100),
                    new SqlParameter("@T_Wocreaterepairman", SqlDbType.NVarChar,100),
                    new SqlParameter("@T_Worepairman", SqlDbType.NVarChar,100),
                    new SqlParameter("@T_Worepairmanphone", SqlDbType.NVarChar,100),
                    new SqlParameter("@T_Worepairdate", SqlDbType.DateTime),
                    new SqlParameter("@T_Worepairyqid", SqlDbType.Int,4),
                    new SqlParameter("@T_Worepairdeptid", SqlDbType.Int,4),
                    new SqlParameter("@T_Worepairaddress", SqlDbType.NVarChar,100),
                    new SqlParameter("@T_Woimageid", SqlDbType.NVarChar, 100),
                    new SqlParameter("@T_Wotousercode", SqlDbType.NVarChar,100),
                    new SqlParameter("@T_Wotousertime", SqlDbType.DateTime),
                    new SqlParameter("@T_Wodealrepairman",SqlDbType.NVarChar,100),
                    new SqlParameter("@T_Wodealdesmo", SqlDbType.NVarChar,100),
                    new SqlParameter("@T_Wothbecause", SqlDbType.NVarChar,100),
                    new SqlParameter("@T_Wodealtime", SqlDbType.DateTime)};
            parameters[0].Value = model.T_workercode;
            parameters[1].Value = model.T_Wowocodetype;
            parameters[2].Value = model.T_Wowocodecnnal; 
            parameters[3].Value = model.T_Wofrindpid;
            parameters[4].Value = model.T_Wowocodestate;
            parameters[5].Value = model.T_Wowocodecenter;
            parameters[6].Value = model.T_Wocreaterepairman;
            parameters[7].Value = model.T_Worepairman;
            parameters[8].Value = model.T_Worepairmanphone;
            parameters[9].Value = model.T_Worepairdate;
            parameters[10].Value = model.T_Worepairyqid;
            parameters[11].Value = model.T_Worepairdeptid;
            parameters[12].Value = model.T_Worepairaddress;
            parameters[13].Value = model.T_Woimageid;
            parameters[14].Value = model.T_Wotousercode;
            parameters[15].Value = model.T_Wotousertime;
            parameters[16].Value = model.T_Wodealrepairman;
            parameters[17].Value = model.T_Wodealdesmo;
            parameters[18].Value = model.T_Wothbecause;
            parameters[19].Value = model.T_Wodealtime;

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

        /// <summary>
        /// 增加一条派单数据
        /// </summary>
        public int Addrepairsend(RMYY_CallCenter_Api.Model.T_Wowo_repair_send model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into T_Wowo_repair_send(");
            strSql.Append("T_Wowocodeid,T_Wocreaterepairman,T_Wousername,T_Wouserphone,T_Woreparicenter,T_Wocreatetime)");
            strSql.Append(" values (");
            strSql.Append("@T_Wowocodeid,@T_Wocreaterepairman,@T_Wousername,@T_Wouserphone,@T_Woreparicenter,@T_Wocreatetime)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
                    new SqlParameter("@T_Wowocodeid", SqlDbType.Int,4),
                    new SqlParameter("@T_Wocreaterepairman", SqlDbType.NVarChar,100),
                    new SqlParameter("@T_Wousername", SqlDbType.NVarChar,100),
                    new SqlParameter("@T_Wouserphone", SqlDbType.NVarChar,100),
                    new SqlParameter("@T_Woreparicenter", SqlDbType.NVarChar,100),
                    new SqlParameter("@T_Wocreatetime", SqlDbType.DateTime)};
            parameters[0].Value = model.T_Wowocodeid;
            parameters[1].Value = model.T_Wocreaterepairman;
            parameters[2].Value = model.T_Wousername;
            parameters[3].Value = model.T_Wouserphone;
            parameters[4].Value = model.T_Woreparicenter;
            parameters[5].Value = model.T_Wocreatetime;

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

        /// <summary>
        /// 增加一条工单流程数据
        /// </summary>
        public int Addrepairitems(RMYY_CallCenter_Api.Model.T_Wowo_repair_items model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into T_Wowo_repair_items(");
            strSql.Append("T_Wowocodeid,T_Woplaycenter,T_Wocreatetime)");
            strSql.Append(" values (");
            strSql.Append("@T_Wowocodeid,@T_Woplaycenter,@T_Wocreatetime)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
                    new SqlParameter("@T_Wowocodeid", SqlDbType.Int,4),
                    new SqlParameter("@T_Woplaycenter", SqlDbType.NVarChar,100),
                    new SqlParameter("@T_Wocreatetime", SqlDbType.DateTime)};
            parameters[0].Value = model.T_Wowocodeid;
            parameters[1].Value = model.T_Woplaycenter;
            parameters[2].Value = model.T_Wocreatetime;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 上传一张工单图片
        /// </summary>
        public int Addrepairimg(RMYY_CallCenter_Api.Model.T_Wowo_repair_img model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into T_Wowo_repair_img(");
            strSql.Append("T_Wofilename,T_Wofileurl)");
            strSql.Append(" values (");
            strSql.Append("@T_Wofilename,@T_Wofileurl)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
                    //new SqlParameter("@T_Wowocodeid", SqlDbType.Int,4),
                    new SqlParameter("@T_Wofilename",SqlDbType.NVarChar,100),
                    new SqlParameter("@T_Wofileurl", SqlDbType.NVarChar,100),};
            //parameters[0].Value = model.T_Wowocodeid;
            parameters[0].Value = model.T_Wofilename;
            parameters[1].Value = model.T_Wofileurl;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 获取图片信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public List<RMYY_CallCenter_Api.Model.T_Wowo_repair_img> Getrepairimg(string id)
        {
            List<RMYY_CallCenter_Api.Model.T_Wowo_repair_img> list =new List<Model.T_Wowo_repair_img>();
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * from T_Wowo_repair_img where T_Woimgid in ("+ id + ")");
            var ds= DbHelperSQL.Query(strSql.ToString());
            int a = 0;
            if (ds.Tables[0].Rows.Count > 0)
            {
                foreach (var item in ds.Tables[0].Rows)
                {
                    list.Add(DataRowToModeimg(ds.Tables[0].Rows[a]));
                    a++;
                }
                return list;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 评价
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Addrepairevaluate(RMYY_CallCenter_Api.Model.T_Wowo_repair_evaluate model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into T_Wowo_repair_evaluate(");
            strSql.Append("T_Wowocodeid,T_Woscore,T_Woevaluate,T_Wolabel,T_Wocreateuser,T_Wocreatetime)");
            strSql.Append(" values (");
            strSql.Append("@T_Wowocodeid,@T_Woscore,@T_Woevaluate,@T_Wolabel,@T_Wocreateuser,@T_Wocreatetime)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters = {
                    new SqlParameter("@T_Wowocodeid", SqlDbType.Int,4),
                    new SqlParameter("@T_Woscore", SqlDbType.Int,4),
                    new SqlParameter("@T_Woevaluate",SqlDbType.NVarChar,100),
                    new SqlParameter("@T_Wolabel", SqlDbType.NVarChar,100),
                    new SqlParameter("@T_Wocreateuser", SqlDbType.NVarChar,100),
                    new SqlParameter("@T_Wocreatetime", SqlDbType.DateTime)};
            parameters[0].Value = model.T_Wowocodeid;
            parameters[1].Value = model.T_Woscore;
            parameters[2].Value = model.T_Woevaluate;
            parameters[3].Value = model.T_Wolabel;
            parameters[4].Value = model.T_Wocreateuser;
            parameters[5].Value = model.T_Wocreatetime;
            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        #endregion
        #region 修改
        /// <summary>
        /// 更新一条报修工单数据
        /// </summary>
        public bool Updaterepair(RMYY_CallCenter_Api.Model.T_WowoRepair_Base model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_WowoRepair_Base set ");
            strSql.Append("T_Wowocodetype=@T_Wowocodetype,");
            strSql.Append("T_Wofrindpid=@T_Wofrindpid,");
            strSql.Append("T_Wowocodestate=@T_Wowocodestate,");
            strSql.Append("T_Wowocodecenter=@T_Wowocodecenter,");
            strSql.Append("T_Worepairman=@T_Worepairman,");
            strSql.Append("T_Worepairmanphone=@T_Worepairmanphone,");
            strSql.Append("T_Worepairdate=@T_Worepairdate,");
            strSql.Append("T_Worepairyqid=@T_Worepairyqid,");
            strSql.Append("T_Worepairdeptid=@T_Worepairdeptid,");
            strSql.Append("T_Worepairaddress=@T_Worepairaddress,");
            strSql.Append("T_Woimageid=@T_Woimageid,");
            strSql.Append("T_Wotousercode=@T_Wotousercode,");
            strSql.Append("T_Wotousertime=@T_Wotousertime,");
            strSql.Append("T_Wodealrepairman=@T_Wodealrepairman,");
            strSql.Append("T_Wodealdesmo=@T_Wodealdesmo,");
            strSql.Append("T_Wothbecause=@T_Wothbecause,"); 
            strSql.Append("T_Wodealtime=@T_Wodealtime");
            strSql.Append(" where T_Wowocodeid=@T_Wowocodeid");
            SqlParameter[] parameters = {
                    new SqlParameter("@T_Wowocodetype", SqlDbType.Int,4),
                    new SqlParameter("@T_Wofrindpid", SqlDbType.Int,4),
                    new SqlParameter("@T_Wowocodestate", SqlDbType.Int,4),
                    new SqlParameter("@T_Wowocodecenter", SqlDbType.NVarChar,500),
                    new SqlParameter("@T_Worepairman", SqlDbType.NVarChar,100),
                    new SqlParameter("@T_Worepairmanphone", SqlDbType.NVarChar,100),
                    new SqlParameter("@T_Worepairdate", SqlDbType.DateTime),
                    new SqlParameter("@T_Worepairyqid", SqlDbType.Int,4),
                    new SqlParameter("@T_Worepairdeptid", SqlDbType.Int,4),
                    new SqlParameter("@T_Worepairaddress", SqlDbType.NVarChar,100),
                    new SqlParameter("@T_Woimageid", SqlDbType.NVarChar,300),
                    new SqlParameter("@T_Wotousercode", SqlDbType.NVarChar,100),
                    new SqlParameter("@T_Wotousertime", SqlDbType.DateTime),
                    new SqlParameter("@T_Wodealrepairman", SqlDbType.NVarChar,100),
                    new SqlParameter("@T_Wodealdesmo", SqlDbType.NVarChar,100),
                    new SqlParameter("@T_Wothbecause", SqlDbType.NVarChar,100),
                    new SqlParameter("@T_Wodealtime", SqlDbType.DateTime),
                    new SqlParameter("@T_Wowocodeid", SqlDbType.Int,4)};
            parameters[0].Value = model.T_Wowocodetype;
            parameters[1].Value = model.T_Wofrindpid;
            parameters[2].Value = model.T_Wowocodestate;
            parameters[3].Value = model.T_Wowocodecenter;
            parameters[4].Value = model.T_Worepairman;
            parameters[5].Value = model.T_Worepairmanphone;
            parameters[6].Value = model.T_Worepairdate;
            parameters[7].Value = model.T_Worepairyqid;
            parameters[8].Value = model.T_Worepairdeptid;
            parameters[9].Value = model.T_Worepairaddress;
            parameters[10].Value = model.T_Woimageid;
            parameters[11].Value = model.T_Wotousercode;
            parameters[12].Value = model.T_Wotousertime;
            parameters[13].Value = model.T_Wodealrepairman;
            parameters[14].Value = model.T_Wodealdesmo;
            parameters[15].Value = model.T_Wothbecause; 
            parameters[16].Value = model.T_Wodealtime;
            parameters[17].Value = model.T_Wowocodeid;

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

        #endregion
        #region 删除
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Deleterepair(int T_Wowocodeid)
        {

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

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

        #endregion
        #region 查询
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public RMYY_CallCenter_Api.Model.T_WowoRepair_Base GetModel(int T_Wowocodeid)
        {

            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 T_Wowocodeid,T_Wowocodetype,T_Wowocodecnnal,T_Wowocodestate,T_Wowocodecenter,T_Worepairman,T_Worepairmanphone,T_Worepairdate,T_Worepairyqid,T_Worepairdeptid,T_Worepairaddress,T_Woimageid,T_Wotousercode,T_Wotousertime,T_Wodealrepairman,T_Wothbecause,T_Wodealtime,T_Woimageid,c.T_Woname,d.F_DeptName,e.F_UserName repairmanusername,h.F_Name T_Wowocodetypename from T_WowoRepair_Base  a ");
            //strSql.Append(" left join T_Wowo_repair_img b on a.T_Woimageid=b.T_Woimgid ");
            strSql.Append(" left join T_Wowo_repairyq c on a.T_Worepairyqid=c.T_Woid ");
            strSql.Append(" left join T_Sys_Department d on a.T_Worepairdeptid=d.F_DeptId ");
            strSql.Append(" left join T_Sys_UserAccount e on a.T_Worepairman=e.F_UserCode ");
            strSql.Append(" left join T_Sys_GongDan h on a.T_Wowocodetype=h.F_GDId ");
            strSql.Append(" where T_Wowocodeid=@T_Wowocodeid");
            SqlParameter[] parameters = {
                    new SqlParameter("@T_Wowocodeid", SqlDbType.Int,4)
            };
            parameters[0].Value = T_Wowocodeid;

            RMYY_CallCenter_Api.Model.T_WowoRepair_Base model = new RMYY_CallCenter_Api.Model.T_WowoRepair_Base();
            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 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.T_Wowocodeid desc");
            }
            strSql.Append(")AS Row, T.*  from T_WowoRepair_Base T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE 1=1" + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

        public DataSet GetListRepairlistall(string strwhere)
        {
            string tablename = "SELECT * FROM ";
            tablename += "(select a.*,b.T_Woname,c.F_DeptName,d.F_UserName createrepairmanusername,e.F_UserName repairmanusername,f.F_UserName  tousercodeusername,g.F_UserName dealrepairmanusername,h.F_Name T_Wowocodetypename from T_WowoRepair_Base a ";
            tablename += " left join T_Wowo_repairyq b on a.T_Worepairyqid=b.T_Woid";
            tablename += " left join T_Sys_Department c on a.T_Worepairdeptid=c.F_DeptId";
            tablename += " left join T_Sys_UserAccount d on a.T_Wocreaterepairman=d.F_UserCode";
            tablename += " left join T_Sys_UserAccount e on a.T_Worepairman=e.F_UserCode";
            tablename += " left join T_Sys_UserAccount f on a.T_Wotousercode=f.F_UserCode";
            tablename += " left join T_Sys_UserAccount g on a.T_Wodealrepairman=g.F_UserCode";
            tablename += " left join T_Sys_DictionaryValue h on a.T_Wowocodetype=h.F_DictionaryValueId ) T_WowoRepair_Base ";
            tablename += strwhere;
            return DbHelperSQL.Query(tablename.ToString());
        }
        /// <summary>
        /// 获取工单流程信息
        /// </summary>
        /// <param name="T_Wowocodeid"></param>
        /// <returns></returns>
        public DataSet Getworderitems(int T_Wowocodeid)
        {
           
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM  T_Wowo_repair_items ");
            strSql.Append(" where T_Wowocodeid=@T_Wowocodeid");
            SqlParameter[] parameters = {
                    new SqlParameter("@T_Wowocodeid", SqlDbType.Int,4)
            };
            parameters[0].Value = T_Wowocodeid;
            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 获取派单记录
        /// </summary>
        /// <param name="T_Wowocodeid"></param>
        /// <returns></returns>
        public DataSet Getwordersend(int T_Wowocodeid)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM  T_Wowo_repair_send ");
            strSql.Append(" where T_Wowocodeid=@T_Wowocodeid");
            SqlParameter[] parameters = {
                    new SqlParameter("@T_Wowocodeid", SqlDbType.Int,4)
            };
            parameters[0].Value = T_Wowocodeid;
            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 获取评价信息
        /// </summary>
        /// <param name="T_Wowocodeid"></param>
        /// <returns></returns>
        public DataSet Getworderevaluate(int T_Wowocodeid)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM  T_Wowo_repair_evaluate ");
            strSql.Append(" where T_Wowocodeid=@T_Wowocodeid");
            SqlParameter[] parameters = {
                    new SqlParameter("@T_Wowocodeid", SqlDbType.Int,4)
            };
            parameters[0].Value = T_Wowocodeid;
            return DbHelperSQL.Query(strSql.ToString(), parameters);
        }
        /// <summary>
        /// 获取维运报表数据信息
        /// </summary>
        /// <returns></returns>
        public DataSet GetZhwyworktable(string stime ,string etime ,int typeid,string key )
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select a.T_Worepairdate,a.T_Wotousercode,a.T_Wotousertime,a.T_Worepairman,a.T_Wocreaterepairman,a.T_Worepairdeptid,a.T_Wowocodeid,a.T_Wodealtime,a.T_Wodealdesmo,");
            strSql.Append("  b.F_DeptName T_Worepairdeptname ,");
            strSql.Append("  c.T_Woname T_Wowocodetypename,");
            strSql.Append(" (select F_DeptName from T_Sys_Department where F_DeptId=d.F_DeptId ) dealdeptname ,");
            strSql.Append(" (select F_UserName from T_Sys_UserAccount where F_UserCode = a.T_Wotousercode) tousercodeusername,");
            strSql.Append("  (select F_UserName from T_Sys_UserAccount where F_UserCode = a.T_Wocreaterepairman) createrepairmanusername,");
            strSql.Append("  e.T_Woscore,");
            strSql.Append("  f.F_Name T_Wowocodetypename ");
            strSql.Append("   from T_WowoRepair_Base a ");
            strSql.Append(" left join T_Sys_Department b on a.T_Worepairdeptid=b.F_DeptId");
            strSql.Append(" left join T_Wowo_repairyq c on a.T_Worepairyqid=c.T_Woid");
            strSql.Append(" left join T_Sys_UserAccount d on a.T_Wodealrepairman=d.F_UserCode");
            strSql.Append(" left join T_Wowo_repair_evaluate e on a.T_Wowocodeid=e.T_Wowocodeid");
            strSql.Append(" left join T_Sys_GongDan f on a.T_Wowocodetype = f.F_GDId"); 
            strSql.Append("  where 1=1");
            if (!string.IsNullOrEmpty(stime))
            {
                strSql.Append("  and a.T_Worepairdate >= '"+stime+"'");
            }
            if (!string.IsNullOrEmpty(etime))
            {
                strSql.Append("  and a.T_Worepairdate <= '" + etime + "'");
            }
            if (typeid  != 0)
            {
                strSql.Append("  and a.T_Worepairdeptid="+ typeid + "");
            }
            if (!string.IsNullOrEmpty(key))
            {
                strSql.Append("  and a.T_Wowocodecenter like '%"+key+ "%' or a.T_Wowocodeid like '%" + key + "%' ");
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
        /// <summary>
        /// 获取数量
        /// </summary>
        /// <returns></returns>
        public int getcount(string datable,string strWhere,string stime ,string etime)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(*) from   ");
            strSql.Append(datable);
            strSql.Append(" where 1=1");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" and " + strWhere);
            }
            ///咨询类查询
            if (datable == "T_Con_WorkOrder")
            {
                if (!string.IsNullOrEmpty(stime))
                {
                    strSql.Append("  and F_HandleTime >= '" + stime + "'");
                }
                if (!string.IsNullOrEmpty(etime))
                {
                    strSql.Append("  and F_HandleTime <= '" + etime + "'");
                }
            }
            else if (datable == "T_Dev_WorkOrder" || datable == "T_Acc_WorkOrder"||datable== "T_Dis_WorkOrder"||datable== "T_Hos_WorkOrder"||datable== "T_Mat_WorkOrder"||datable== "T_Car_WorkOrder")
            {
                if (!string.IsNullOrEmpty(stime))
                {
                    strSql.Append("  and F_FinishTime >= '" + stime + "'");
                }
                if (!string.IsNullOrEmpty(etime))
                {
                    strSql.Append("  and F_FinishTime <= '" + etime + "'");
                }
            }
            else if(datable == "T_WowoRepair_Base")
            {
                
                if (!string.IsNullOrEmpty(stime))
                {
                    strSql.Append("  and T_Wodealtime >= '" + stime + "'");
                }
                if (!string.IsNullOrEmpty(etime))
                {
                    strSql.Append("  and T_Wodealtime <= '" + etime + "'");
                }
            }
            var obj = DbHelperSQL.GetSingle(strSql.ToString());
            var getcount = Convert.ToInt32(obj.ToString());
            return getcount;
        }


        #endregion
        #region 得到一个对象实体
        /// <summary>
        /// 得到一个工单对象实体
        /// </summary>
        public RMYY_CallCenter_Api.Model.T_WowoRepair_Base DataRowToModel(DataRow row)
        {
            RMYY_CallCenter_Api.Model.T_WowoRepair_Base model = new RMYY_CallCenter_Api.Model.T_WowoRepair_Base();
            if (row != null)
            {
                #region 主表信息======================
                //利用反射获得属性的所有公共属性
                Type modelType = model.GetType();
                for (int i = 0; i < row.Table.Columns.Count; i++)
                {
                    PropertyInfo proInfo = modelType.GetProperty(row.Table.Columns[i].ColumnName);
                    if (proInfo != null && row[i] != DBNull.Value)
                    {
                        //用索引值设置属性值
                        proInfo.SetValue(model, row[i], null);
                    }
                }
                #endregion
            }
            return model;
        }
        /// <summary>
        /// 得到一个工单流程对象实体
        /// </summary>
        public RMYY_CallCenter_Api.Model.T_Wowo_repair_items DataRowToitemModel(DataRow row)
        {
            RMYY_CallCenter_Api.Model.T_Wowo_repair_items model = new RMYY_CallCenter_Api.Model.T_Wowo_repair_items();
            if (row != null)
            {
                #region 主表信息======================
                //利用反射获得属性的所有公共属性
                Type modelType = model.GetType();
                for (int i = 0; i < row.Table.Columns.Count; i++)
                {
                    PropertyInfo proInfo = modelType.GetProperty(row.Table.Columns[i].ColumnName);
                    if (proInfo != null && row[i] != DBNull.Value)
                    {
                        //用索引值设置属性值
                        proInfo.SetValue(model, row[i], null);
                    }
                }
                #endregion
            }
            return model;
        }
        /// <summary>
        /// 得到一个排单记录对象实体
        /// </summary>
        public RMYY_CallCenter_Api.Model.T_Wowo_repair_send DataRowTosendModel(DataRow row)
        {
            RMYY_CallCenter_Api.Model.T_Wowo_repair_send model = new RMYY_CallCenter_Api.Model.T_Wowo_repair_send();
            if (row != null)
            {
                #region 主表信息======================
                //利用反射获得属性的所有公共属性
                Type modelType = model.GetType();
                for (int i = 0; i < row.Table.Columns.Count; i++)
                {
                    PropertyInfo proInfo = modelType.GetProperty(row.Table.Columns[i].ColumnName);
                    if (proInfo != null && row[i] != DBNull.Value)
                    {
                        //用索引值设置属性值
                        proInfo.SetValue(model, row[i], null);
                    }
                }
                #endregion
            }
            return model;
        }
        /// <summary>
        /// 得到一个评价对象实体
        /// </summary>
        public RMYY_CallCenter_Api.Model.T_Wowo_repair_evaluate DataRowToevaluateModel(DataRow row)
        {
            RMYY_CallCenter_Api.Model.T_Wowo_repair_evaluate model = new RMYY_CallCenter_Api.Model.T_Wowo_repair_evaluate();
            if (row != null)
            {
                #region 主表信息======================
                //利用反射获得属性的所有公共属性
                Type modelType = model.GetType();
                for (int i = 0; i < row.Table.Columns.Count; i++)
                {
                    PropertyInfo proInfo = modelType.GetProperty(row.Table.Columns[i].ColumnName);
                    if (proInfo != null && row[i] != DBNull.Value)
                    {
                        //用索引值设置属性值
                        proInfo.SetValue(model, row[i], null);
                    }
                }
                #endregion
            }
            return model;
        }
        /// <summary>
        /// 得到一个工单对象实体
        /// </summary>
        public RMYY_CallCenter_Api.Model.T_Wowo_repair_img DataRowToModeimg(DataRow row)
        {
            RMYY_CallCenter_Api.Model.T_Wowo_repair_img model = new RMYY_CallCenter_Api.Model.T_Wowo_repair_img();
            if (row != null)
            {
                #region 主表信息======================
                //利用反射获得属性的所有公共属性
                Type modelType = model.GetType();
                for (int i = 0; i < row.Table.Columns.Count; i++)
                {
                    PropertyInfo proInfo = modelType.GetProperty(row.Table.Columns[i].ColumnName);
                    if (proInfo != null && row[i] != DBNull.Value)
                    {
                        //用索引值设置属性值
                        proInfo.SetValue(model, row[i], null);
                    }
                }
                #endregion
            }
            return model;
        }
        #endregion
    }
}
