using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web; using HomeService.Models; using HomeService.Utility; using System.Text; using Microsoft.Practices.EnterpriseLibrary.Data; using HcUtility.Comm; using HomeService.DBHelper; namespace HomeService { public class HomeDBHelper { #region Inquery DataList public static void Main() { string gid = ""; string companyid = ""; string templetid = ""; string linkurl = ""; string sql = ""; List modInquire = new List(); modInquire = GetSQL(); //得到公司用户 List employee = new List(); employee = GetUserInfo(); foreach (Employee _emp in employee) { foreach (MsTempletStructure _templet in modInquire) { gid = _templet.GID; companyid = _templet.COMPANYID; templetid = _templet.TEMPLETID; linkurl = _templet.LINKURL; sql = _templet.SQL; sql = sql.Replace("\" + userid + \"", _emp.GID); sql = "select (" + sql + ") as result"; DataTable dt = SqlHelper.ExecuteSql(sql); CacheHelper.Set(gid + "|" + companyid + "|" + templetid, dt, DateTime.Now.AddSeconds(120)); } } } private static List GetSQL() { StringBuilder sql = new StringBuilder(); sql.AppendLine("select B.GID,B.COMPANYID,LINKURL,[SQL] from main_module as A "); sql.AppendLine("left join user_templet as B on A.USERTEMPLETID=B.TEMPLETID "); sql.AppendLine("where B.LINKURL != '' and B.LINKURL is not NULL and B.[SQL] != '' and B.[SQL] is not NULL "); return SetSQL(sql); } private static List SetSQL(StringBuilder sql) { var list = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, sql.ToString())) { while (reader.Read()) { MsTempletStructure data = new MsTempletStructure(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.COMPANYID = Convert.ToString(reader["COMPANYID"]); data.TEMPLETID = Convert.ToString(reader["TEMPLETID"]); data.LINKURL = Convert.ToString(reader["LINKURL"]); data.SQL = Convert.ToString(reader["SQL"]); #endregion list.Add(data); } reader.Close(); } return list; } private static List GetUserInfo() { DataTable dt = new DataTable(); StringBuilder sql = new StringBuilder(); sql.AppendLine("select GID from [user] "); return SetUserInfo(sql); } private static List SetUserInfo(StringBuilder sql) { var list = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, sql.ToString())) { while (reader.Read()) { Employee data = new Employee(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.USERNAME = Convert.ToString(reader["USERNAME"]); data.CODENAME = Convert.ToString(reader["CODENAME"]); data.PASSWORD = Convert.ToString(reader["PASSWORD"]); #endregion list.Add(data); } reader.Close(); } return list; } #endregion } }