using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using System.Data;
using Dapper;
using PushPlatform.Data;

namespace PushPlatform.Data.DaoAchieve
{
    sealed partial class PushTagDaoAchieve
    {
        
        
        
        
        #region Dao
        public int Save(PushTag entity)
        {
            using(IDbConnection connection = new MySqlConnection(PushPlatformContext.connString))
            {
                var result = connection.Execute("Insert into push_tag values (@Id,@PushSys_ProId,@TagName,@TagDesc,@Is_Deleted,@Create_User,@Create_Time,@Update_User,@Update_Time)",
                                   entity);
                return result;
            }
        }
        
        public int Save(List<PushTag> entityList)
        {
            using(IDbConnection connection = new MySqlConnection(PushPlatformContext.connString))
            {
                var result = connection.Execute("Insert into push_tag values (@Id,@PushSys_ProId,@TagName,@TagDesc,@Is_Deleted,@Create_User,@Create_Time,@Update_User,@Update_Time)",
                                   entityList);
                return result;
            }
        }
        
        
        public int Delete(string id)
        {
            using(IDbConnection connection = new MySqlConnection(PushPlatformContext.connString))
            {
                var result = connection.Execute("delete from push_tag where Id=@id",
                                   new { id = id });
                return result;
            }
        }
        
        public int Update(PushTag entity)
        {
            using(IDbConnection connection = new MySqlConnection(PushPlatformContext.connString))
            {
                var result = connection.Execute("update push_tag set PushSys_ProId=@PushSys_ProId,TagName=@TagName,TagDesc=@TagDesc,Is_Deleted=@Is_Deleted,Create_User=@Create_User,Create_Time=@Create_Time,Update_User=@Update_User,Update_Time=@Update_Time where Id=@id",
                                   entity);
                return result;
            }
        }
        
        public int Update(List<PushTag> entityList)
        {
            using(IDbConnection connection = new MySqlConnection(PushPlatformContext.connString))
            {
                var result = connection.Execute("update push_tag set PushSys_ProId=@PushSys_ProId,TagName=@TagName,TagDesc=@TagDesc,Is_Deleted=@Is_Deleted,Create_User=@Create_User,Create_Time=@Create_Time,Update_User=@Update_User,Update_Time=@Update_Time where Id=@id",
                                   entityList);
                return result;
            }
        }
        
        public int SaveOrUpdate(IList<PushTag> entityList)
        {
            if (entityList == null || entityList.Count == 0)
                return 0;
            List<PushTag> saveList = new List<PushTag>();
            List<PushTag> updateList = new List<PushTag>();
            foreach(var entity in entityList)
            {
                if(entity.IsEdit)
                {
                    updateList.Add(entity);
                }
                else
                {
                    saveList.Add(entity);
                }
            }
            int save = 0;
            int update = 0;
            using(IDbConnection connection = new MySqlConnection(PushPlatformContext.connString))
            {
		connection.Open();
                IDbTransaction transaction = connection.BeginTransaction();
                try
                {
                    if (updateList.Count > 0)
                    {
                        update = connection.Execute("update push_tag set PushSys_ProId=@PushSys_ProId,TagName=@TagName,TagDesc=@TagDesc,Is_Deleted=@Is_Deleted,Create_User=@Create_User,Create_Time=@Create_Time,Update_User=@Update_User,Update_Time=@Update_Time where Id=@id",
                                       updateList, transaction, null, null);
                    }
                    if (saveList.Count > 0)
                    {
                        save = connection.Execute("Insert into push_tag values (@Id,@PushSys_ProId,@TagName,@TagDesc,@Is_Deleted,@Create_User,@Create_Time,@Update_User,@Update_Time)",
                                       saveList, transaction, null, null);
                    }
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw new Exception(ex.Message);
                }
                return save + update;
            }
        }
        
        public int SaveOrUpdateWithTran(IList<PushTag> entityList, IDbConnection connection, IDbTransaction transaction)
        {
            if (entityList == null || entityList.Count == 0)
                return 0;
            List<PushTag> saveList = new List<PushTag>();
            List<PushTag> updateList = new List<PushTag>();
            foreach(var entity in entityList)
            {
                if(entity.IsEdit)
                {
                    updateList.Add(entity);
                }
                else
                {
                    saveList.Add(entity);
                }
            }
            int save = 0;
            int update = 0;
            if (updateList.Count > 0)
            {
                update = connection.Execute("update push_tag set PushSys_ProId=@PushSys_ProId,TagName=@TagName,TagDesc=@TagDesc,Is_Deleted=@Is_Deleted,Create_User=@Create_User,Create_Time=@Create_Time,Update_User=@Update_User,Update_Time=@Update_Time where Id=@id",
                               updateList, transaction, null, null);
            }
            if (saveList.Count > 0)
            {
                save = connection.Execute("Insert into push_tag values (@Id,@PushSys_ProId,@TagName,@TagDesc,@Is_Deleted,@Create_User,@Create_Time,@Update_User,@Update_Time)",
                               saveList, transaction, null, null);
            }
            return save + update;
        }
        
        public PushTag Get(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return null;
            }
            using(IDbConnection connection = new MySqlConnection(PushPlatformContext.connString))
            {
                var query = connection.Query<PushTag>("select * from push_tag where Id=@id", new { id = id });
                if (query.Count() > 0)
                    return query.FirstOrDefault();
                return null;
            }
        }
        
        public int GetCount(PushPlatform.Data.Criteria.CriteriaPushTag mycriteria)
        {
            if(mycriteria.UsePage && (mycriteria.PageIndex <= 0 || mycriteria.PageSize < 1))
            {
                mycriteria.PageTotal = 0;
                return 0;
            }
            using(IDbConnection connection = new MySqlConnection(PushPlatformContext.connString))
            {
                if (mycriteria.UserWhere)
                {
                    if (mycriteria.WhereValue != null)
                    {
                        return connection.Query<int>("select count(1) from push_tag " + mycriteria.Where, mycriteria.WhereValue).FirstOrDefault();
                    }
                    else
                    {
                        return connection.Query<int>("select count(1) from push_tag " + mycriteria.Where).FirstOrDefault();
                    }
                }
                else
                {
                    return connection.Query<int>("select count(1) from push_tag " + CreatAutoQuery(mycriteria)).FirstOrDefault(); 
                }
            }
        }
        
        public List<PushTag> Fetch(PushPlatform.Data.Criteria.CriteriaPushTag mycriteria)
        {
            if(mycriteria.UsePage && (mycriteria.PageIndex <= 0 || mycriteria.PageSize < 1))
            {
                mycriteria.PageTotal = 0;
                return new List<PushTag>();
            }
            string orderby = "";
            foreach(var order in mycriteria.OrderList)
            {
                if(orderby=="")
                {
                    orderby = " order by ";
                }
                orderby += order+",";
            }
            if(orderby.Length>0)
            {
                orderby = orderby.Substring(0, orderby.Length - 1);
                if(!mycriteria.IsAsc)
                {
                    orderby += " desc ";
                }
            }
            int pageStart = (mycriteria.PageIndex - 1) * mycriteria.PageSize;
            using(IDbConnection connection = new MySqlConnection(PushPlatformContext.connString))
            {
                if (mycriteria.UserWhere)
                {
                    if(mycriteria.UsePage)
                    {
                        if (mycriteria.WhereValue != null)
                        {
                            mycriteria.PageTotal = connection.Query<int>("select count(1) from push_tag " + mycriteria.Where + orderby, mycriteria.WhereValue).FirstOrDefault();
                            var query = connection.Query<PushTag>("select * from push_tag " + mycriteria.Where + orderby + " LIMIT " + pageStart.ToString() + "," + mycriteria.PageSize, mycriteria.WhereValue);
                            return query.ToList();
                        }
                        else
                        {
                            mycriteria.PageTotal = connection.Query<int>("select count(1) from push_tag " + mycriteria.Where + orderby).FirstOrDefault();
                            var query = connection.Query<PushTag>("select * from push_tag " + mycriteria.Where + orderby + " LIMIT " + pageStart.ToString() + "," + mycriteria.PageSize);
                            return query.ToList();
                        }
                    }
                    else
                    {
                        if (mycriteria.WhereValue != null)
                        {
                            var query = connection.Query<PushTag>("select * from push_tag " + mycriteria.Where + orderby, mycriteria.WhereValue);
                            return query.ToList();
                        }
                        else
                        {
                            var query = connection.Query<PushTag>("select * from push_tag " + mycriteria.Where + orderby);
                            return query.ToList();
                        }
                    }
                }
                else
                {
                    if (mycriteria.UsePage)
                    {
                        string whereStr=CreatAutoQuery(mycriteria);
                        mycriteria.PageTotal = connection.Query<int>("select count(1) from push_tag " + whereStr).FirstOrDefault();
                        string queryStr = "select * from push_tag ";
                        queryStr += whereStr + orderby;
                        queryStr += " LIMIT " + pageStart.ToString() + "," + mycriteria.PageSize;
                        var query = connection.Query<PushTag>(queryStr);
                        return query.ToList();
                    }
                    else
                    {
                        string queryStr = "select * from push_tag ";
                        queryStr += CreatAutoQuery(mycriteria) + orderby;
                        var query = connection.Query<PushTag>(queryStr);
                        return query.ToList();
                    }  
                }
            }
        }
        #endregion
        
        #region method
        private string CreatAutoQuery(Criteria.CriteriaPushTag mycriteria)
        {
            string where = "";
            
            if (!string.IsNullOrEmpty(mycriteria.LikeId))
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += " Id like '%" + mycriteria.LikeId + "%'";
            }
            if (mycriteria.InId.Count>0)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                string instr = "";
                foreach(var str in mycriteria.InId)
                {
                    instr += "'"+str+"',";
                }
                instr = instr.Substring(0,instr.Length-1);
                where += " Id in (" + instr + ")";
            }
            if (mycriteria.NotId.Count>0)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                string instr = "";
                foreach(var str in mycriteria.NotId)
                {
                    instr += "'"+str+"',";
                }
                instr = instr.Substring(0,instr.Length-1);
                where += "Id not in (" + instr + ")";
            }
            if (mycriteria.OrEqId.Count>0)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                string instr = "";
                foreach(var str in mycriteria.OrEqId)
                {
                    if(instr=="")
                    {instr="(";}
                    instr += "Id='"+str+"' or ";
                }
                instr = instr.Substring(0,instr.Length-4);
                instr+=")";
                where += instr;
            }
            if (mycriteria.OrLikeId.Count>0)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                string instr = "";
                foreach(var str in mycriteria.OrLikeId)
                {
                    if(instr=="")
                    {instr="(";}
                    instr += "Id like '%"+str+"%' or ";
                }
                instr = instr.Substring(0,instr.Length-4);
                instr+=")";
                where += instr;
            }
            if (!string.IsNullOrEmpty(mycriteria.EqId))
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += "Id ='" + mycriteria.EqId + "'";
            }
            if (!string.IsNullOrEmpty(mycriteria.NeId))
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += "Id <>'" + mycriteria.NeId + "'";
            }
            if (mycriteria.NullId)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += " Id is null"; 
            }
            if (mycriteria.NotNullId)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += " Id is not null";
            }
            if (!string.IsNullOrEmpty(mycriteria.LikePushsysProid))
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += " PushSys_ProId like '%" + mycriteria.LikePushsysProid + "%'";
            }
            if (mycriteria.InPushsysProid.Count>0)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                string instr = "";
                foreach(var str in mycriteria.InPushsysProid)
                {
                    instr += "'"+str+"',";
                }
                instr = instr.Substring(0,instr.Length-1);
                where += " PushSys_ProId in (" + instr + ")";
            }
            if (mycriteria.NotPushsysProid.Count>0)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                string instr = "";
                foreach(var str in mycriteria.NotPushsysProid)
                {
                    instr += "'"+str+"',";
                }
                instr = instr.Substring(0,instr.Length-1);
                where += "PushSys_ProId not in (" + instr + ")";
            }
            if (mycriteria.OrEqPushsysProid.Count>0)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                string instr = "";
                foreach(var str in mycriteria.OrEqPushsysProid)
                {
                    if(instr=="")
                    {instr="(";}
                    instr += "PushSys_ProId='"+str+"' or ";
                }
                instr = instr.Substring(0,instr.Length-4);
                instr+=")";
                where += instr;
            }
            if (mycriteria.OrLikePushsysProid.Count>0)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                string instr = "";
                foreach(var str in mycriteria.OrLikePushsysProid)
                {
                    if(instr=="")
                    {instr="(";}
                    instr += "PushSys_ProId like '%"+str+"%' or ";
                }
                instr = instr.Substring(0,instr.Length-4);
                instr+=")";
                where += instr;
            }
            if (!string.IsNullOrEmpty(mycriteria.EqPushsysProid))
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += "PushSys_ProId ='" + mycriteria.EqPushsysProid + "'";
            }
            if (!string.IsNullOrEmpty(mycriteria.NePushsysProid))
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += "PushSys_ProId <>'" + mycriteria.NePushsysProid + "'";
            }
            if (mycriteria.NullPushsysProid)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += " PushSys_ProId is null"; 
            }
            if (mycriteria.NotNullPushsysProid)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += " PushSys_ProId is not null";
            }
            if (!string.IsNullOrEmpty(mycriteria.LikeTagname))
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += " TagName like '%" + mycriteria.LikeTagname + "%'";
            }
            if (mycriteria.InTagname.Count>0)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                string instr = "";
                foreach(var str in mycriteria.InTagname)
                {
                    instr += "'"+str+"',";
                }
                instr = instr.Substring(0,instr.Length-1);
                where += " TagName in (" + instr + ")";
            }
            if (mycriteria.NotTagname.Count>0)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                string instr = "";
                foreach(var str in mycriteria.NotTagname)
                {
                    instr += "'"+str+"',";
                }
                instr = instr.Substring(0,instr.Length-1);
                where += "TagName not in (" + instr + ")";
            }
            if (mycriteria.OrEqTagname.Count>0)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                string instr = "";
                foreach(var str in mycriteria.OrEqTagname)
                {
                    if(instr=="")
                    {instr="(";}
                    instr += "TagName='"+str+"' or ";
                }
                instr = instr.Substring(0,instr.Length-4);
                instr+=")";
                where += instr;
            }
            if (mycriteria.OrLikeTagname.Count>0)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                string instr = "";
                foreach(var str in mycriteria.OrLikeTagname)
                {
                    if(instr=="")
                    {instr="(";}
                    instr += "TagName like '%"+str+"%' or ";
                }
                instr = instr.Substring(0,instr.Length-4);
                instr+=")";
                where += instr;
            }
            if (!string.IsNullOrEmpty(mycriteria.EqTagname))
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += "TagName ='" + mycriteria.EqTagname + "'";
            }
            if (!string.IsNullOrEmpty(mycriteria.NeTagname))
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += "TagName <>'" + mycriteria.NeTagname + "'";
            }
            if (mycriteria.NullTagname)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += " TagName is null"; 
            }
            if (mycriteria.NotNullTagname)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += " TagName is not null";
            }
            if (!string.IsNullOrEmpty(mycriteria.LikeTagdesc))
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += " TagDesc like '%" + mycriteria.LikeTagdesc + "%'";
            }
            if (mycriteria.InTagdesc.Count>0)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                string instr = "";
                foreach(var str in mycriteria.InTagdesc)
                {
                    instr += "'"+str+"',";
                }
                instr = instr.Substring(0,instr.Length-1);
                where += " TagDesc in (" + instr + ")";
            }
            if (mycriteria.NotTagdesc.Count>0)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                string instr = "";
                foreach(var str in mycriteria.NotTagdesc)
                {
                    instr += "'"+str+"',";
                }
                instr = instr.Substring(0,instr.Length-1);
                where += "TagDesc not in (" + instr + ")";
            }
            if (mycriteria.OrEqTagdesc.Count>0)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                string instr = "";
                foreach(var str in mycriteria.OrEqTagdesc)
                {
                    if(instr=="")
                    {instr="(";}
                    instr += "TagDesc='"+str+"' or ";
                }
                instr = instr.Substring(0,instr.Length-4);
                instr+=")";
                where += instr;
            }
            if (mycriteria.OrLikeTagdesc.Count>0)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                string instr = "";
                foreach(var str in mycriteria.OrLikeTagdesc)
                {
                    if(instr=="")
                    {instr="(";}
                    instr += "TagDesc like '%"+str+"%' or ";
                }
                instr = instr.Substring(0,instr.Length-4);
                instr+=")";
                where += instr;
            }
            if (!string.IsNullOrEmpty(mycriteria.EqTagdesc))
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += "TagDesc ='" + mycriteria.EqTagdesc + "'";
            }
            if (!string.IsNullOrEmpty(mycriteria.NeTagdesc))
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += "TagDesc <>'" + mycriteria.NeTagdesc + "'";
            }
            if (mycriteria.NullTagdesc)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += " TagDesc is null"; 
            }
            if (mycriteria.NotNullTagdesc)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += " TagDesc is not null";
            }
            if (mycriteria.EqIsDeleted!=null)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += "Is_Deleted =" + mycriteria.EqIsDeleted;
            }
            if (mycriteria.NeIsDeleted!=null)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += "Is_Deleted <>" + mycriteria.NeIsDeleted;
            }
            if (mycriteria.LeIsDeleted!=null)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += "Is_Deleted <=" + mycriteria.LeIsDeleted;
            }
            if (mycriteria.GeIsDeleted!=null)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += "Is_Deleted >=" + mycriteria.GeIsDeleted;
            }
            if (mycriteria.LtIsDeleted!=null)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += "Is_Deleted <" + mycriteria.LtIsDeleted;
            }
            if (mycriteria.GtIsDeleted!=null)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += "Is_Deleted >" + mycriteria.GtIsDeleted;
            }
            if (mycriteria.NullIsDeleted)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += " Is_Deleted is null"; 
            }
            if (mycriteria.NotNullIsDeleted)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += " Is_Deleted is not null";
            }
            if (!string.IsNullOrEmpty(mycriteria.LikeCreateUser))
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += " Create_User like '%" + mycriteria.LikeCreateUser + "%'";
            }
            if (mycriteria.InCreateUser.Count>0)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                string instr = "";
                foreach(var str in mycriteria.InCreateUser)
                {
                    instr += "'"+str+"',";
                }
                instr = instr.Substring(0,instr.Length-1);
                where += " Create_User in (" + instr + ")";
            }
            if (mycriteria.NotCreateUser.Count>0)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                string instr = "";
                foreach(var str in mycriteria.NotCreateUser)
                {
                    instr += "'"+str+"',";
                }
                instr = instr.Substring(0,instr.Length-1);
                where += "Create_User not in (" + instr + ")";
            }
            if (mycriteria.OrEqCreateUser.Count>0)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                string instr = "";
                foreach(var str in mycriteria.OrEqCreateUser)
                {
                    if(instr=="")
                    {instr="(";}
                    instr += "Create_User='"+str+"' or ";
                }
                instr = instr.Substring(0,instr.Length-4);
                instr+=")";
                where += instr;
            }
            if (mycriteria.OrLikeCreateUser.Count>0)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                string instr = "";
                foreach(var str in mycriteria.OrLikeCreateUser)
                {
                    if(instr=="")
                    {instr="(";}
                    instr += "Create_User like '%"+str+"%' or ";
                }
                instr = instr.Substring(0,instr.Length-4);
                instr+=")";
                where += instr;
            }
            if (!string.IsNullOrEmpty(mycriteria.EqCreateUser))
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += "Create_User ='" + mycriteria.EqCreateUser + "'";
            }
            if (!string.IsNullOrEmpty(mycriteria.NeCreateUser))
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += "Create_User <>'" + mycriteria.NeCreateUser + "'";
            }
            if (mycriteria.NullCreateUser)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += " Create_User is null"; 
            }
            if (mycriteria.NotNullCreateUser)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += " Create_User is not null";
            }
            if (mycriteria.EqCreateTime!=null)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += "Create_Time =" + mycriteria.EqCreateTime;
            }
            if (mycriteria.NeCreateTime!=null)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += "Create_Time <>" + mycriteria.NeCreateTime;
            }
            if (mycriteria.LeCreateTime!=null)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += "Create_Time <='" + mycriteria.LeCreateTime + "'";
            }
            if (mycriteria.GeCreateTime!=null)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += "Create_Time >='" + mycriteria.GeCreateTime + "'";
            }
            if (mycriteria.LtCreateTime!=null)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += "Create_Time <'" + mycriteria.LtCreateTime + "'";
            }
            if (mycriteria.GtCreateTime!=null)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += "Create_Time >'" + mycriteria.GtCreateTime + "'";
            }
            if (mycriteria.NullCreateTime)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += " Create_Time is null"; 
            }
            if (mycriteria.NotNullCreateTime)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += " Create_Time is not null";
            }
            if (!string.IsNullOrEmpty(mycriteria.LikeUpdateUser))
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += " Update_User like '%" + mycriteria.LikeUpdateUser + "%'";
            }
            if (mycriteria.InUpdateUser.Count>0)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                string instr = "";
                foreach(var str in mycriteria.InUpdateUser)
                {
                    instr += "'"+str+"',";
                }
                instr = instr.Substring(0,instr.Length-1);
                where += " Update_User in (" + instr + ")";
            }
            if (mycriteria.NotUpdateUser.Count>0)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                string instr = "";
                foreach(var str in mycriteria.NotUpdateUser)
                {
                    instr += "'"+str+"',";
                }
                instr = instr.Substring(0,instr.Length-1);
                where += "Update_User not in (" + instr + ")";
            }
            if (mycriteria.OrEqUpdateUser.Count>0)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                string instr = "";
                foreach(var str in mycriteria.OrEqUpdateUser)
                {
                    if(instr=="")
                    {instr="(";}
                    instr += "Update_User='"+str+"' or ";
                }
                instr = instr.Substring(0,instr.Length-4);
                instr+=")";
                where += instr;
            }
            if (mycriteria.OrLikeUpdateUser.Count>0)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                string instr = "";
                foreach(var str in mycriteria.OrLikeUpdateUser)
                {
                    if(instr=="")
                    {instr="(";}
                    instr += "Update_User like '%"+str+"%' or ";
                }
                instr = instr.Substring(0,instr.Length-4);
                instr+=")";
                where += instr;
            }
            if (!string.IsNullOrEmpty(mycriteria.EqUpdateUser))
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += "Update_User ='" + mycriteria.EqUpdateUser + "'";
            }
            if (!string.IsNullOrEmpty(mycriteria.NeUpdateUser))
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += "Update_User <>'" + mycriteria.NeUpdateUser + "'";
            }
            if (mycriteria.NullUpdateUser)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += " Update_User is null"; 
            }
            if (mycriteria.NotNullUpdateUser)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += " Update_User is not null";
            }
            if (mycriteria.EqUpdateTime!=null)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += "Update_Time =" + mycriteria.EqUpdateTime;
            }
            if (mycriteria.NeUpdateTime!=null)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += "Update_Time <>" + mycriteria.NeUpdateTime;
            }
            if (mycriteria.LeUpdateTime!=null)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += "Update_Time <='" + mycriteria.LeUpdateTime + "'";
            }
            if (mycriteria.GeUpdateTime!=null)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += "Update_Time >='" + mycriteria.GeUpdateTime + "'";
            }
            if (mycriteria.LtUpdateTime!=null)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += "Update_Time <" + mycriteria.LtUpdateTime;
            }
            if (mycriteria.GtUpdateTime!=null)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += "Update_Time >" + mycriteria.GtUpdateTime;
            }
            if (mycriteria.NullUpdateTime)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += " Update_Time is null"; 
            }
            if (mycriteria.NotNullUpdateTime)
            {
                if(where==""){ where += "where "; } else if(mycriteria.UseOr) {where += " or ";} else { where += " and "; }
                where += " Update_Time is not null";
            }
            
            return where;
        }
        
        #endregion
        
        
        
        
    }
}
