WebCache.cs 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260
  1. using BizCom;
  2. using NPOI.SS.Formula.Functions;
  3. using SQLData;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Data.SqlClient;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Web;
  11. using System.Web.Caching;
  12. using System.Web.UI.WebControls;
  13. using Utils;
  14. namespace SiteCore
  15. {
  16. public class WebCache
  17. {
  18. #region 缓存方法
  19. /// <summary>
  20. /// 添加缓存
  21. /// </summary>
  22. /// <param name="cKey"></param>
  23. /// <param name="cValue"></param>
  24. public static void AddCache(string cKey, object cValue)
  25. {
  26. AddCacheTime(cKey, cValue, 180);
  27. }
  28. public static void AddCacheWithTime(string cKey, object cValue, double hour)
  29. {
  30. if (HttpContext.Current.Cache[cKey] == null && cValue != null)//HttpContext.Current.Cache.Remove(cKey);
  31. HttpContext.Current.Cache.Add(cKey, cValue, null, DateTime.Now.AddHours(hour), TimeSpan.Zero, CacheItemPriority.Normal, null);
  32. }
  33. /// <summary>
  34. /// 添加缓存
  35. /// </summary>
  36. /// <param name="cKey"></param>
  37. /// <param name="cValue"></param>
  38. public static void AddCacheTime(string cKey, object cValue, double cTime)
  39. {
  40. if (HttpRuntime.Cache[cKey] == null && cValue != null)//HttpRuntime.Cache.Remove(cKey);
  41. HttpRuntime.Cache.Add(cKey, cValue, null, DateTime.Now.AddMinutes(cTime), TimeSpan.Zero, CacheItemPriority.Normal, null);
  42. }
  43. /// <summary>
  44. /// 获取缓存
  45. /// </summary>
  46. /// <param name="cKey"></param>
  47. /// <returns></returns>
  48. public static object GetCache(string cKey)
  49. {
  50. return HttpRuntime.Cache[cKey];
  51. }
  52. public static void RemoveCache(string cKey)
  53. {
  54. CommonHelper.RemoveCache(cKey);
  55. }
  56. public static void AddRunCacheTime(string cKey, object cValue, double cTime)
  57. {
  58. if (HttpRuntime.Cache[cKey] == null && cValue != null)//HttpRuntime.Cache.Remove(cKey);
  59. HttpRuntime.Cache.Add(cKey, cValue, null, DateTime.Now.AddMinutes(cTime), TimeSpan.Zero, CacheItemPriority.Normal, null);
  60. }
  61. public static object GetRunCache(string cKey)
  62. {
  63. return HttpRuntime.Cache[cKey];
  64. }
  65. public static void RemoveRunCache(string cKey)
  66. {
  67. if (HttpRuntime.Cache[cKey] != null)
  68. HttpRuntime.Cache.Remove(cKey);
  69. }
  70. #endregion
  71. #region 获取字典表datatable
  72. /// <summary>
  73. /// 获取字典数据
  74. /// </summary>
  75. /// <param name="dicType"></param>
  76. /// <returns></returns>
  77. public static DataTable GetDicData(DicType dicType)
  78. {
  79. return GetDicData(dicType, "");
  80. }
  81. /// <summary>
  82. /// 获取字典数据
  83. /// </summary>
  84. /// <param name="dicType"></param>
  85. /// <param name="sWhere">条件</param>
  86. /// <returns></returns>
  87. public static DataTable GetDicData(DicType dicType, string sWhere)
  88. {
  89. string dicClass = "Dic" + dicType.ToString();
  90. DicSysBase DicSysBase = (DicSysBase)WebHelper.GetReflectionObject(dicClass);
  91. return DicSysBase.GetDataTable(sWhere);
  92. }
  93. private static readonly object dicObj = new object();
  94. /// <summary>
  95. /// 获取带缓存的字典表数据
  96. /// </summary>
  97. /// <param name="dicType"></param>
  98. /// <param name="sWhere"></param>
  99. /// <param name="cacheId"></param>
  100. /// <returns></returns>
  101. public static DataTable GetCacheDicData(DicType dicType, string sWhere, string cacheId)
  102. {
  103. if (GetCache(cacheId) == null)
  104. {
  105. lock (dicObj)
  106. {
  107. if (GetCache(cacheId) == null)
  108. {
  109. string dicClass = "Dic" + dicType;
  110. DicSysBase DicSysBase = (DicSysBase)WebHelper.GetReflectionObject(dicClass);
  111. DataTable dt = DicSysBase.GetDataTable(sWhere);
  112. AddCache(dicClass, dt);
  113. return dt;
  114. }
  115. }
  116. }
  117. return (DataTable)GetCache(cacheId);
  118. }
  119. #endregion
  120. #region 转成DicItemList
  121. public static List<DicItem> GetDicItemList(string table)
  122. {
  123. return GetDicItemList(table, "", "Name", "ID");
  124. }
  125. public static List<DicItem> GetDicItemList(string table, string where)
  126. {
  127. return GetDicItemList(table, where, "Name", "ID");
  128. }
  129. public static List<DicItem> GetDicItemList(string table, string where, string key, string value)
  130. {
  131. List<DicItem> list = new List<DicItem>();
  132. DataTable dt = DicSysBase.GetTable(table, where);
  133. if (dt != null && dt.Rows.Count > 0)
  134. {
  135. bool hasParent = dt.Columns.Contains("ParentID");
  136. bool hasCode = dt.Columns.Contains("Code");
  137. bool hasLng = dt.Columns.Contains("Lng");
  138. bool hasLat = dt.Columns.Contains("Lat");
  139. bool hasMeal = table.IndexOf("industry", StringComparison.OrdinalIgnoreCase) != -1 ? true : false;
  140. bool hasMcount = dt.Columns.Contains("Mcount");
  141. foreach (DataRow row in dt.Rows)
  142. {
  143. DicItem item = new DicItem();
  144. item.Name = row[key].ToString();
  145. if (hasParent) item.ParentID = Convert.ToInt32(row["ParentID"]);
  146. if (hasCode) item.Code = row["Code"].ToString();
  147. if (hasLng) item.Lng = row["Lng"].ToString();
  148. if (hasLat) item.Lat = row["Lat"].ToString();
  149. if (hasMeal) item.IsTakeMeal = Convert.ToBoolean(row["IsTakeMeal"]);
  150. if (hasMcount) item.Mcount = Convert.ToInt32(row["Mcount"]);
  151. item.ID = Convert.ToInt32(row[value]);
  152. list.Add(item);
  153. }
  154. }
  155. return list;
  156. }
  157. public static List<DicItem> GetDicItemList(DataTable dt)
  158. {
  159. return GetDicItemList(dt, "Name", "ID");
  160. }
  161. public static List<DicItem> GetDicItemList(DataTable dt, string Name, string ID)
  162. {
  163. List<DicItem> list = new List<DicItem>();
  164. if (dt != null && dt.Rows.Count > 0)
  165. {
  166. foreach (DataRow row in dt.Rows)
  167. {
  168. DicItem item = new DicItem();
  169. item.Name = row[Name].ToString();
  170. item.ID = Convert.ToInt32(row[ID]);
  171. list.Add(item);
  172. }
  173. }
  174. return list;
  175. }
  176. #endregion
  177. #region 绑定字典表DropDownList
  178. /// <summary>
  179. /// 绑定DropDownList,插入默认
  180. /// </summary>
  181. /// <param name="sel"></param>
  182. /// <param name="dicType"></param>
  183. /// <param name="insertSel"></param>
  184. /// <param name="where">条件</param>
  185. public static void ddlBindDicData(DropDownList sel, DicType dicType, string insertSel, string where)
  186. {
  187. ddlBindDicData(sel, dicType, "Name", "ID", insertSel, where);
  188. }
  189. /// <summary>
  190. /// 绑定DropDownList,插入默认
  191. /// </summary>
  192. /// <param name="sel"></param>
  193. /// <param name="dicType"></param>
  194. /// <param name="name"></param>
  195. /// <param name="value"></param>
  196. /// <param name="insertSel"></param>
  197. /// <param name="where">条件</param>
  198. public static void ddlBindDicData(DropDownList sel, DicType dicType, string name, string value, string insertSel, string where)
  199. {
  200. sel.DataSource = GetDicData(dicType, where);
  201. sel.DataTextField = name;
  202. sel.DataValueField = value;
  203. sel.DataBind();
  204. if (insertSel != "")
  205. {
  206. sel.Items.Insert(0, new ListItem(insertSel, "0"));
  207. sel.SelectedIndex = 0;
  208. }
  209. }
  210. #endregion
  211. //private static readonly object siteAdv_Falg = new object();
  212. //public static DataTable GetSiteAdv(string cityCode)
  213. //{
  214. // string key = "siteAdv_" + cityCode;
  215. // if (GetCache(key) == null)
  216. // {
  217. // lock (siteAdv_Falg)
  218. // {
  219. // if (GetCache(key) == null)
  220. // {
  221. // DataTable dt=LcIndexAdv.SimpleQuery(getCurrentWhere(cityCode));
  222. // AddCache(key, dt);
  223. // return dt;
  224. // }
  225. // }
  226. // }
  227. // return GetCache(key) as DataTable;
  228. //}
  229. //商家分类
  230. private static readonly object TaskTypeCache_Flag = new object();
  231. private static List<DicItem> _taskType;
  232. public static List<DicItem> TaskType
  233. {
  234. get
  235. {
  236. if (_taskType == null)
  237. {
  238. if (GetCache("taskType") == null)
  239. {
  240. lock (TaskTypeCache_Flag)
  241. {
  242. if (GetCache("taskType") == null)
  243. {
  244. _taskType = GetDicItemList("S_TaskType");
  245. AddCache("taskType", _taskType);
  246. }
  247. }
  248. }
  249. else
  250. {
  251. _taskType = GetCache("taskType") as List<DicItem>;
  252. }
  253. }
  254. return _taskType;
  255. }
  256. }
  257. //商家分类
  258. private static readonly object ShopTypeCache_Flag = new object();
  259. private static List<DicItem> _shopType;
  260. public static List<DicItem> ShopType
  261. {
  262. get
  263. {
  264. if (_shopType == null)
  265. {
  266. if (GetCache("shopType") == null)
  267. {
  268. lock (ShopTypeCache_Flag)
  269. {
  270. if (GetCache("shopType") == null)
  271. {
  272. _shopType = GetDicItemList("S_ShopType");
  273. AddCache("shopType", _shopType);
  274. }
  275. }
  276. }
  277. else
  278. {
  279. _shopType = GetCache("shopType") as List<DicItem>;
  280. }
  281. }
  282. return _shopType;
  283. }
  284. }
  285. private static readonly object formIdCache_Flag = new object();
  286. private static DataTable _formTable = null;
  287. public static DataTable FormTable
  288. {
  289. get
  290. {
  291. if (_formTable == null)
  292. {
  293. if (GetCache("formTable") == null)
  294. {
  295. lock (formIdCache_Flag)
  296. {
  297. if (GetCache("formTable") == null)
  298. {
  299. string sql = "select userid,COUNT(0) as fc from dbo.S_WxFormId group by UserID";
  300. _formTable = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  301. AddCacheTime("formTable", _formTable, 480);
  302. }
  303. }
  304. }
  305. else
  306. {
  307. _formTable = GetCache("formTable") as DataTable;
  308. }
  309. }
  310. return _formTable;
  311. }
  312. }
  313. private static readonly object CopTypeCache_Flag = new object();
  314. private static List<DicItem> _copType = null;
  315. public static List<DicItem> CopType
  316. {
  317. get
  318. {
  319. if (_copType == null)
  320. {
  321. if (GetCache("copType") == null)
  322. {
  323. lock (CopTypeCache_Flag)
  324. {
  325. if (GetCache("copType") == null)
  326. {
  327. _copType = GetDicItemList("S_CopType");
  328. AddCache("copType", _shopType);
  329. }
  330. }
  331. }
  332. else
  333. {
  334. _copType = GetCache("copType") as List<DicItem>;
  335. }
  336. }
  337. return _copType;
  338. }
  339. }
  340. private static readonly object PrizeView_Flag = new object();
  341. private static DataView _prizeView = null;
  342. public static DataView GetPrizeView(string item, string date)
  343. {
  344. if (_prizeView == null)
  345. {
  346. if (GetCache("PrizeView") == null)
  347. {
  348. lock (PrizeView_Flag)
  349. {
  350. if (GetCache("PrizeView") == null)
  351. {
  352. string sql = string.Format("select * from s_prize where item='{0}' and datediff(d,termtime,'{1}')=0 ", item, date);
  353. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  354. //_prizeView = GetDicItemList("S_CopType");
  355. AddCacheTime("PrizeView", new DataView(dt), 5);
  356. //AddCache("PrizeView",new DataView(dt));
  357. }
  358. }
  359. }
  360. else
  361. {
  362. _prizeView = GetCache("PrizeView") as DataView;
  363. }
  364. }
  365. return _prizeView;
  366. }
  367. //商品分类
  368. private static readonly object GoodsTypeCache_Flag = new object();
  369. private static List<DicItem> _goodsType;
  370. public static List<DicItem> GoodsType
  371. {
  372. get
  373. {
  374. if (_goodsType == null)
  375. {
  376. if (GetCache("goodsType") == null)
  377. {
  378. lock (GoodsTypeCache_Flag)
  379. {
  380. if (GetCache("goodsType") == null)
  381. {
  382. _goodsType = GetDicItemList("S_GoodsType");
  383. AddCache("goodsType", _goodsType);
  384. }
  385. }
  386. }
  387. else
  388. {
  389. _goodsType = GetCache("goodsType") as List<DicItem>;
  390. }
  391. }
  392. return _goodsType;
  393. }
  394. }
  395. /// <summary>
  396. /// 根据ID获取商品分类
  397. /// </summary>
  398. /// <returns></returns>
  399. public static List<DicItem> GetGoodsType(string sIds)
  400. {
  401. int id = 0;
  402. string[] sArr = sIds.Split(',');
  403. if (!sIds.Equals("")) id = Convert.ToInt32(sArr[sArr.Length - 1]);
  404. return GoodsType.Where(t => t.ParentID == id || sArr.Contains(t.ID.ToString())).OrderBy(t => t.ID).ToList();
  405. }
  406. //行业
  407. public static List<DicItem> IndustryCache
  408. {
  409. get
  410. {
  411. return DicIndustryCache.Where(t => t.IsTakeMeal == false).ToList();
  412. }
  413. }
  414. public static List<DicItem> MealIndustryCache
  415. {
  416. get
  417. {
  418. return DicIndustryCache.Where(t => t.ParentID != 0 && t.IsTakeMeal).ToList();
  419. }
  420. }
  421. private static readonly object DicIndustryCache_Flag = new object();
  422. private static List<DicItem> _dicIndustryCache;
  423. public static List<DicItem> DicIndustryCache
  424. {
  425. get
  426. {
  427. if (_dicIndustryCache == null)
  428. {
  429. if (GetCache("dicIndustry") == null)
  430. {
  431. lock (DicIndustryCache_Flag)
  432. {
  433. if (GetCache("dicIndustry") == null)
  434. {
  435. _dicIndustryCache = GetDicItemList("LC_DicIndustry", "");
  436. AddCache("dicIndustry", _dicIndustryCache);
  437. }
  438. }
  439. }
  440. else
  441. {
  442. _dicIndustryCache = GetCache("dicIndustry") as List<DicItem>;
  443. }
  444. }
  445. return _dicIndustryCache;
  446. }
  447. }
  448. /// <summary>
  449. /// 根据ID获取行业
  450. /// </summary>
  451. /// <returns></returns>
  452. public static List<DicItem> GetIndustry(string sIds)
  453. {
  454. int id = 0;
  455. string[] sArr = sIds.Split(',');
  456. if (!sIds.Equals("")) id = Convert.ToInt32(sArr[sArr.Length - 1]);
  457. return IndustryCache.Where(t => t.ParentID == id || sArr.Contains(t.ID.ToString())).OrderBy(t => t.ID).ToList();
  458. }
  459. private static readonly object cityZoneFlag = new object();
  460. public static List<DicItem> GetCityZone(string code)
  461. {
  462. string key = "dicCityZone_" + code;
  463. if (GetCache(key) == null)
  464. {
  465. lock (cityZoneFlag)
  466. {
  467. if (GetCache(key) == null)
  468. {
  469. List<DicItem> list = GetDicItemList("LC_DicRegion",
  470. string.Format("Path like (select '%|'+convert(varchar,ID)+'|%' from Lc_Dicregion where Code='{0}')", code));
  471. AddCache(key, list);
  472. return list;
  473. }
  474. }
  475. }
  476. return GetCache(key) as List<DicItem>;
  477. }
  478. private static readonly object cityAreaFlag = new object();
  479. /// <summary>
  480. /// 获取所有区县
  481. /// </summary>
  482. /// <param name="code"></param>
  483. /// <returns></returns>
  484. public static List<DicItem> GetCityArea(string code)
  485. {
  486. string key = "dicCityArea_" + code;
  487. if (GetCache(key) == null)
  488. {
  489. lock (cityAreaFlag)
  490. {
  491. if (GetCache(key) == null)
  492. {
  493. List<DicItem> list = GetDicItemList("LC_DicRegion", "(Code like '" + code.Substring(0, 4) + "%' and Code<>'" + code + "') and IsDel=0", "Name", "Code");
  494. AddCache(key, list);
  495. return list;
  496. }
  497. }
  498. }
  499. return GetCache(key) as List<DicItem>;
  500. }
  501. private static readonly object recTasksFlag = new object();
  502. public static DataTable GetRecTasks()
  503. {
  504. string key = "recTasks";
  505. if (GetCache(key) == null)
  506. {
  507. lock (recTasksFlag)
  508. {
  509. if (GetCache(key) == null)
  510. {
  511. string sql = "SELECT TOP 6 id,fee,title,pubtime FROM s_task where State=1 and DATEDIFF(m,pubtime,GETDATE())=0 ORDER BY NEWID()";
  512. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  513. AddCacheTime(key, dt, 1);
  514. return dt;
  515. }
  516. }
  517. }
  518. return GetCache(key) as DataTable;
  519. }
  520. private static readonly object taskTypeTableFlag = new object();
  521. public static DataTable GetTaskTypeTable()
  522. {
  523. string key = "taskTypeKey";
  524. if (GetCache(key) == null)
  525. {
  526. lock (taskTypeTableFlag)
  527. {
  528. if (GetCache(key) == null)
  529. {
  530. string sql = "select id,name,sort from s_tasktype";
  531. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  532. AddCacheTime(key, dt, 12);
  533. return dt;
  534. }
  535. }
  536. }
  537. return GetCache(key) as DataTable;
  538. }
  539. private static readonly object appVerFlag = new object();
  540. public static DataTable GetAppVer()
  541. {
  542. string key = "appVerKey";
  543. if (GetCache(key) == null)
  544. {
  545. lock (appVerFlag)
  546. {
  547. if (GetCache(key) == null)
  548. {
  549. string sql = "select appname,appver,downfile from s_appver";
  550. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  551. AddCache(key, dt);
  552. return dt;
  553. }
  554. }
  555. }
  556. return GetCache(key) as DataTable;
  557. }
  558. private static readonly object appWeixinVer = new object();
  559. public static DataTable GeWeixinVer(string ps)
  560. {
  561. string key = "appWeixinVer" + ps;
  562. if (GetCache(key) == null)
  563. {
  564. lock (appWeixinVer)
  565. {
  566. if (GetCache(key) == null)
  567. {
  568. string sql = "select top " + ps + " * from s_weixinver order by pubtime desc";
  569. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  570. AddCache(key, dt);
  571. return dt;
  572. }
  573. }
  574. }
  575. return GetCache(key) as DataTable;
  576. }
  577. private static readonly object shopTypeTableFlag = new object();
  578. public static DataTable GetShopTypeTable()
  579. {
  580. string key = "shopTypeKey";
  581. if (GetCache(key) == null)
  582. {
  583. lock (shopTypeTableFlag)
  584. {
  585. if (GetCache(key) == null)
  586. {
  587. string sql = "select id,name,sort from s_shoptype";
  588. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  589. AddCacheTime(key, dt, 12);
  590. return dt;
  591. }
  592. }
  593. }
  594. return GetCache(key) as DataTable;
  595. }
  596. private static readonly object runRankFlag = new object();
  597. public static DataTable GetRunRank()
  598. {
  599. string key = "runRankFlag";
  600. if (GetCache(key) == null)
  601. {
  602. lock (runRankFlag)
  603. {
  604. if (GetCache(key) == null)
  605. {
  606. string sql = "select top 30 nickname,userpic,sex,SUM(step) as allstep from view_RunStep group by nickname,userpic,sex order by allstep desc";
  607. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  608. AddCacheTime(key, dt, 12);
  609. return dt;
  610. }
  611. }
  612. }
  613. return GetCache(key) as DataTable;
  614. }
  615. private static readonly object curRunRankFlag = new object();
  616. public static DataTable GetCurRunRank(int uid)
  617. {
  618. //string key = "curRunRankFlag";
  619. //if (GetCache(key) == null)
  620. //{
  621. // lock (curRunRankFlag)
  622. // {
  623. // if (GetCache(key) == null)
  624. // {
  625. // string sql = "select top 30 id,nickname,userpic,sex,step as allstep,(select COUNT(0) from S_RunStepLikes where StepID=view_RunStep.ID and UserID="+uid+") as cur,likes from view_RunStep where datediff(d,updatetime,GETDATE())=0 order by allstep desc";
  626. // DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  627. // //AddRunCacheTime(key, dt, 1);
  628. // return dt;
  629. // }
  630. // }
  631. //}
  632. //return GetRunCache(key) as DataTable;
  633. string sql = "select top 30 id,nickname,userpic,sex,step as allstep,(select COUNT(0) from S_RunStepLikes where StepID=view_RunStep.ID and UserID=" + uid + ") as cur,likes from view_RunStep where datediff(d,updatetime,GETDATE())=0 order by allstep desc";
  634. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  635. //AddRunCacheTime(key, dt, 1);
  636. return dt;
  637. }
  638. private static readonly object concealtypeFlag = new object();
  639. public static DataTable GetConcealType()
  640. {
  641. string key = "concealtype";
  642. if (GetCache(key) == null)
  643. {
  644. lock (concealtypeFlag)
  645. {
  646. if (GetCache(key) == null)
  647. {
  648. string sql = "select id,name from s_concealtype";
  649. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  650. AddCacheTime(key, dt, 12);
  651. return dt;
  652. }
  653. }
  654. }
  655. return GetCache(key) as DataTable;
  656. }
  657. private static readonly object ewuTypeTableFlag = new object();
  658. public static DataTable GetEwuTypeTable()
  659. {
  660. string key = "ewuTypeKey";
  661. if (GetCache(key) == null)
  662. {
  663. lock (ewuTypeTableFlag)
  664. {
  665. if (GetCache(key) == null)
  666. {
  667. string sql = "select id,name,sort from s_goodstype";
  668. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  669. AddCacheTime(key, dt, 12);
  670. return dt;
  671. }
  672. }
  673. }
  674. return GetCache(key) as DataTable;
  675. }
  676. private static readonly object copTypeTableFlag = new object();
  677. public static DataTable GetCopTypeTable()
  678. {
  679. string key = "copTypeKey";
  680. if (GetCache(key) == null)
  681. {
  682. lock (copTypeTableFlag)
  683. {
  684. if (GetCache(key) == null)
  685. {
  686. string sql = "select id,name,sort from s_coptype";
  687. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  688. AddCacheTime(key, dt, 12);
  689. return dt;
  690. }
  691. }
  692. }
  693. return GetCache(key) as DataTable;
  694. }
  695. //不能预约的
  696. private static string getNoOrderWhere(string stime, string etime)
  697. {
  698. List<string> lst = new List<string>();
  699. lst.Add(string.Format("not(DATEDIFF(MINUTE,'{1}',StartTime)>=0 or DATEDIFF(MINUTE, '{0}', EndTime)<=0)", stime, etime));//不能预约的,使用中的
  700. //lst.Add(string.Format("state<2"));//状态没有变化
  701. lst.Add(" not((state=0 and DATEDIFF(MINUTE,StartTime,GETDATE())>=15) or state>1)");//没有[过期结束的]
  702. //lst.Add("DATEDIFF(MINUTE, EndTime, GETDATE())<0");//未结束
  703. return string.Join(" and ", lst.ToArray());
  704. }
  705. private static readonly object indexMenuFlag = new object();
  706. public static DataTable GetIndexMenu(int r)
  707. {
  708. string key = "indexMenu";
  709. if (r == 44 || r == 3899 || r == 3900 || r == 3901) key = "indexMenu_r";
  710. else if (r == 40 || r == 3163 || r == 78 || r == 495 || r == 34) key = "indexMenu_m";
  711. if (GetCache(key) == null)
  712. {
  713. lock (indexMenuFlag)
  714. {
  715. if (GetCache(key) == null)
  716. {
  717. string sql = "select * from s_menu";
  718. if (r == 44 || r == 3899 || r == 3900 || r == 3901)
  719. {
  720. sql += " where tid not in(3,6,1) and isshow=1";
  721. }
  722. else if (r == 40 || r == 3163 || r == 78 || r == 495 || r == 34)
  723. {
  724. //sql += "";
  725. }
  726. else
  727. {
  728. sql += " where isshow=1";
  729. }
  730. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  731. AddCacheTime(key, dt, 120);
  732. return dt;
  733. }
  734. }
  735. }
  736. return GetCache(key) as DataTable;
  737. }
  738. private static readonly object labRoomFlag = new object();
  739. public static DataTable GetLabRoomTable()
  740. {
  741. string key = "labRoomKey";
  742. if (GetCache(key) == null)
  743. {
  744. lock (labRoomFlag)
  745. {
  746. if (GetCache(key) == null)
  747. {
  748. string ctime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  749. string etime = DateTime.Now.AddMinutes(30).ToString("yyyy-MM-dd HH:mm:ss");
  750. //string sql = "select id,name,sort from s_labroom where parentid=0 order by sort";
  751. StringBuilder sql = new StringBuilder();
  752. sql.Append("select id,name,opentime as ot,'' as opentime,'' as closetime,cols,rows,colfields,holdperson as hperson,sort,code,seatnum,0 as onum from s_labstudyroom where ismeeting=0 order by sort ;");//and state=0and state=0
  753. sql.Append("select * from s_labbreakoff where datediff(d,starttime,getdate())<=0 order by starttime asc;");
  754. sql.AppendFormat("select roomid,count(0) as cnum from view_laborder where {1} and datediff(d,starttime,'{0}')=0 group by roomid", ctime, getNoOrderWhere(ctime, etime));
  755. DataSet ds = DbHelper.DbConn.ExecuteDataset(sql.ToString());
  756. DataTable dt = ds.Tables[0];
  757. DataView bDv = new DataView(ds.Tables[1]);
  758. DataView orderDv = new DataView(ds.Tables[2]);
  759. int w = (int)DateTime.Now.DayOfWeek;
  760. if (w == 0) w = 7;
  761. string[] sArr = null;
  762. foreach (DataRow dr in dt.Rows)
  763. {
  764. if (dr["ot"].ToString() != "")
  765. {
  766. sArr = dr["ot"].ToString().Split('|');
  767. if (sArr.Length == 7)
  768. dr["opentime"] = sArr[getWeekDay(w - 1)] + "|" + sArr[getWeekDay(w)] + "|" + sArr[getWeekDay(w + 1)];
  769. }
  770. bDv.RowFilter = "roomid=" + dr["id"];
  771. if (bDv.Count > 0)
  772. {
  773. dr["closetime"] = bDv[0]["starttime"] + "|" + bDv[0]["endtime"];
  774. }
  775. orderDv.RowFilter = "roomid=" + dr["id"];
  776. if (orderDv.Count > 0)
  777. {
  778. dr["onum"] = orderDv[0]["cnum"];
  779. }
  780. }
  781. AddCacheTime(key, dt, 25);
  782. return dt;
  783. }
  784. }
  785. }
  786. return GetCache(key) as DataTable;
  787. }
  788. private static readonly object labDiscussFlag = new object();
  789. public static DataTable GetLabDiscussTable()
  790. {
  791. string key = "labDiscussKey";
  792. if (GetCache(key) == null)
  793. {
  794. lock (labDiscussFlag)
  795. {
  796. if (GetCache(key) == null)
  797. {
  798. //string sql = "select id,name,sort from s_labroom where parentid=0 order by sort";
  799. StringBuilder sql = new StringBuilder();
  800. sql.AppendFormat("select id,name,sort,hperson,facilities,opentime,'' as closetime,0 as cnum from s_labdiscuss order by name asc ;");
  801. sql.AppendFormat("select * from s_labbreakoff where discussid>0 and datediff(d,endtime,getdate())<=0 order by starttime asc;");
  802. DataSet ds = DbHelper.DbConn.ExecuteDataset(sql.ToString());
  803. DataTable dt = ds.Tables[0];
  804. DataView bDv = new DataView(ds.Tables[1]);
  805. List<string> lst = new List<string>();
  806. foreach (DataRow dr in dt.Rows)
  807. {
  808. lst = new List<string>();
  809. bDv.RowFilter = "discussid=" + dr["id"];
  810. if (bDv.Count > 0)
  811. {
  812. foreach (DataRowView bdrv in bDv)
  813. {
  814. lst.Add(bDv[0]["starttime"] + "|" + bDv[0]["endtime"]);
  815. }
  816. dr["closetime"] = String.Join(",", lst.ToArray());
  817. }
  818. }
  819. AddCacheTime(key, dt, 10);
  820. return dt;
  821. }
  822. }
  823. }
  824. return GetCache(key) as DataTable;
  825. }
  826. private static int getWeekDay(int w)
  827. {
  828. if (w == 7) w = 1;
  829. else if (w == 8) w = 2;
  830. return w;
  831. }
  832. private static readonly object recGoodsFlag = new object();
  833. public static DataTable GetRecGoods()
  834. {
  835. string key = "recGoods";
  836. if (GetCache(key) == null)
  837. {
  838. lock (recGoodsFlag)
  839. {
  840. if (GetCache(key) == null)
  841. {
  842. string sql = "SELECT TOP 6 * FROM s_goods where State=1 and DATEDIFF(m,GPublishTime,GETDATE())=0 ORDER BY NEWID()";
  843. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  844. AddCacheTime(key, dt, 1);
  845. return dt;
  846. }
  847. }
  848. }
  849. return GetCache(key) as DataTable;
  850. }
  851. private static readonly object recNewsFlag = new object();
  852. public static DataTable GetRecNews()
  853. {
  854. string key = "recNews";
  855. if (GetCache(key) == null)
  856. {
  857. lock (recNewsFlag)
  858. {
  859. if (GetCache(key) == null)
  860. {
  861. string sql = "SELECT TOP 6 id,title FROM s_news where newstypeid=2 order by addtime desc";
  862. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  863. AddCacheTime(key, dt, 1);
  864. return dt;
  865. }
  866. }
  867. }
  868. return GetCache(key) as DataTable;
  869. }
  870. private static readonly object lineNewsFlag = new object();
  871. public static DataTable GetLineNews()
  872. {
  873. string key = "lineNews";
  874. if (GetCache(key) == null)
  875. {
  876. lock (lineNewsFlag)
  877. {
  878. if (GetCache(key) == null)
  879. {
  880. string sql = "SELECT TOP 10 id,title FROM s_news order by addtime desc";
  881. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  882. AddCacheTime(key, dt, 1);
  883. return dt;
  884. }
  885. }
  886. }
  887. return GetCache(key) as DataTable;
  888. }
  889. private static readonly object assnFlag = new object();
  890. public static DataView GetAssn()
  891. {
  892. string key = "assn";
  893. if (GetCache(key) == null)
  894. {
  895. lock (lineNewsFlag)
  896. {
  897. if (GetCache(key) == null)
  898. {
  899. string sql = "select * FROM s_assn ";
  900. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  901. DataView dv = new DataView(dt);
  902. AddCache(key, dv);
  903. return dv;
  904. }
  905. }
  906. }
  907. return GetCache(key) as DataView;
  908. }
  909. private static readonly object lyxyUserFlag = new object();
  910. public static DataTable LyxyUserTable
  911. {
  912. get
  913. {
  914. string key = "lyxyuser";
  915. if (GetCache(key) == null)
  916. {
  917. lock (lyxyUserFlag)
  918. {
  919. if (GetCache(key) == null)
  920. {
  921. string sql = "select * FROM s_lyxyuser ";
  922. DataTable dt = SqlHelper.ExecuteDataSet(sql).Tables[0];
  923. AddCache(key, dt);
  924. return dt;
  925. }
  926. }
  927. }
  928. return GetCache(key) as DataTable;
  929. }
  930. }
  931. #region 获取表格数据
  932. /// <summary>
  933. /// 获取数据
  934. /// </summary>
  935. /// <param name="tableName">表名</param>
  936. /// <param name="dStruct">数据结构</param>
  937. /// <returns></returns>
  938. public static DataTable GetData(string tableName, DataStruct dStruct)
  939. {
  940. if (dStruct.isExport)
  941. {
  942. string where = CommonHelper.CombineWhere(dStruct.MainWhere, dStruct.SecondWhere);
  943. StringBuilder sql = new StringBuilder();
  944. if (dStruct.PageSize != 100000)
  945. {
  946. sql.AppendFormat("select top {0} {1} from {2}", dStruct.PageSize, dStruct.Fileds, tableName);
  947. }
  948. else
  949. {
  950. sql.AppendFormat("select {0} from {1}", dStruct.Fileds, tableName);
  951. }
  952. if (where.Length > 0) sql.AppendFormat(" where {0}", where);
  953. if (dStruct.Order.Length > 0) sql.AppendFormat(" order by {0}", dStruct.Order);
  954. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  955. return dt;
  956. /*int pageSize = 0;
  957. int pageIndex = 1;
  958. DataTable dt = new DataTable();
  959. StringBuilder sql = new StringBuilder();
  960. sql.AppendFormat("SELECT tid FROM CE_ErpTrade WITH ( NOLOCK ) ");
  961. if (where.Length > 0) sql.AppendFormat(" where {0}", where);
  962. DataTable dt_tid = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
  963. List<string> tids = new List<string>();
  964. foreach (DataRow item in dt_tid.Rows)
  965. {
  966. tids.Add("'" + item["tid"] + "'");
  967. if (pageSize == 1000)
  968. {
  969. DataTable dt_temp = DbHelper.DbConn.ExecuteDataset(string.Format("select * from view_orderlist where tid in ({0})", string.Join(",", tids))).Tables[0];
  970. if (pageIndex == 1)
  971. {
  972. dt = dt_temp.Clone();
  973. }
  974. else
  975. {
  976. dt.Merge(dt_temp);
  977. }
  978. pageIndex++;
  979. pageSize = 0;
  980. tids = new List<string>();
  981. }
  982. pageSize++;
  983. }
  984. if (tids.Count > 0)
  985. {
  986. DataTable dt_temp = DbHelper.DbConn.ExecuteDataset(string.Format("select * from view_orderlist where tid in ({0})", string.Join(",", tids))).Tables[0];
  987. if (pageIndex == 1)
  988. {
  989. dt = dt_temp.Clone();
  990. }
  991. else
  992. {
  993. dt.Merge(dt_temp);
  994. }
  995. }*/
  996. //if (dStruct.Order.Length > 0) sql.AppendFormat(" order by {0}", dStruct.Order);
  997. //if (where.Length > 0) sql = string.Format("select top {0} {1} from {2} where {3}", dStruct.PageSize, dStruct.Fileds, tableName, where);
  998. //else sql = string.Format("select top {0} {1} from {2} ", dStruct.PageSize, dStruct.Fileds, tableName);
  999. //return dt;
  1000. }
  1001. SqlParameter[] sqlParameter ={
  1002. new SqlParameter("@TableName", SqlDbType.VarChar,8000),
  1003. new SqlParameter("@Fields", SqlDbType.VarChar, 500),
  1004. new SqlParameter("@OrderBy", SqlDbType.VarChar, 500),
  1005. new SqlParameter("@Where", SqlDbType.VarChar, 8000),
  1006. new SqlParameter("@pageSize", SqlDbType.Int, 4),
  1007. new SqlParameter("@pageIndex", SqlDbType.Int, 4),
  1008. new SqlParameter("@totalRecord", SqlDbType.Int, 4)/*,
  1009. new SqlParameter("@totalPage", SqlDbType.Int, 4)*/
  1010. };
  1011. string key = dStruct.PrimaryKeys.Split(',')[0];
  1012. sqlParameter[0].Value = tableName;
  1013. sqlParameter[1].Value = dStruct.Fileds;
  1014. if (dStruct.Order != "")
  1015. sqlParameter[2].Value = dStruct.Order;
  1016. else
  1017. sqlParameter[2].Value = key + " Asc";
  1018. sqlParameter[3].Value = CommonHelper.CombineWhere(dStruct.MainWhere, dStruct.SecondWhere);
  1019. sqlParameter[4].Value = dStruct.PageSize;
  1020. sqlParameter[5].Value = dStruct.CurrentPage;
  1021. sqlParameter[6].Direction = ParameterDirection.ReturnValue;
  1022. try
  1023. {
  1024. DataTable tmpDt = DbHelper.DbConn.ExecuteDataset(CommandType.StoredProcedure, "sp_PageView", sqlParameter).Tables[0];
  1025. dStruct.TotalCount = (int)sqlParameter[6].Value;
  1026. dStruct.TotalPage = (int)Math.Ceiling((dStruct.TotalCount * 1.0 / dStruct.PageSize));
  1027. if (dStruct.TotalPage == 0 && dStruct.TotalCount > 0) dStruct.TotalPage = 1;
  1028. return tmpDt;
  1029. }
  1030. catch (Exception ex)
  1031. {
  1032. //SyLog.WriteLog(ex);
  1033. }
  1034. return null;
  1035. }
  1036. public static DataTable GetErpData(string tableName, DataStruct dStruct)
  1037. {
  1038. SqlParameter[] sqlParameter ={
  1039. new SqlParameter("@TableName", SqlDbType.VarChar,8000),
  1040. new SqlParameter("@Fields", SqlDbType.VarChar, 500),
  1041. new SqlParameter("@OrderBy", SqlDbType.VarChar, 500),
  1042. new SqlParameter("@Where", SqlDbType.VarChar, 8000),
  1043. new SqlParameter("@pageSize", SqlDbType.Int, 4),
  1044. new SqlParameter("@pageIndex", SqlDbType.Int, 4),
  1045. new SqlParameter("@totalRecord", SqlDbType.Int, 4)/*,
  1046. new SqlParameter("@totalPage", SqlDbType.Int, 4)*/
  1047. };
  1048. string key = dStruct.PrimaryKeys.Split(',')[0];
  1049. sqlParameter[0].Value = tableName;
  1050. sqlParameter[1].Value = dStruct.Fileds;
  1051. if (dStruct.Order != "")
  1052. sqlParameter[2].Value = dStruct.Order;
  1053. else
  1054. sqlParameter[2].Value = key + " Asc";
  1055. sqlParameter[3].Value = CommonHelper.CombineWhere(dStruct.MainWhere, dStruct.SecondWhere);
  1056. sqlParameter[4].Value = dStruct.PageSize;
  1057. sqlParameter[5].Value = dStruct.CurrentPage;
  1058. sqlParameter[6].Direction = ParameterDirection.ReturnValue;
  1059. try
  1060. {
  1061. DataTable tmpDt = ErpSqlHelper.ExecuteDataSet(CommandType.StoredProcedure, "sp_PageView", sqlParameter).Tables[0];
  1062. dStruct.TotalCount = (int)sqlParameter[6].Value;
  1063. dStruct.TotalPage = (int)Math.Ceiling((dStruct.TotalCount * 1.0 / dStruct.PageSize));
  1064. if (dStruct.TotalPage == 0 && dStruct.TotalCount > 0) dStruct.TotalPage = 1;
  1065. return tmpDt;
  1066. }
  1067. catch (Exception ex)
  1068. {
  1069. //SyLog.WriteLog(ex);
  1070. }
  1071. return null;
  1072. }
  1073. //获取所有数据
  1074. public static DataTable GetFullData(string sql, DataStruct dStruct)
  1075. {
  1076. string sWhere = CommonHelper.CombineWhere(dStruct.MainWhere, dStruct.SecondWhere);
  1077. if (sWhere != "") sWhere = " where " + sWhere;
  1078. sql = string.Format("select * from ({0}) as tb {1}", sql, sWhere);
  1079. return DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  1080. }
  1081. #endregion
  1082. private static object columnsObj = new object();
  1083. public static DataTable GetGridColumns()
  1084. {
  1085. if (GetCache("grid_columns") == null)
  1086. {
  1087. lock (columnsObj)
  1088. {
  1089. if (GetCache("grid_columns") == null)
  1090. {
  1091. string sql = "select * from ce_columns";
  1092. DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
  1093. //DataTable dt = CeErpUnit.SimpleQuery(0, "id,name,unittype", "", "");
  1094. AddCache("grid_columns", dt);
  1095. return dt;
  1096. }
  1097. }
  1098. }
  1099. return (DataTable)GetCache("grid_columns");
  1100. }
  1101. }
  1102. public enum AdvPositionEnum
  1103. {
  1104. IndexTop = 1,
  1105. IndexRecommend = 2,
  1106. IndexRight1 = 3,
  1107. IndexRight2 = 5,
  1108. IndexLeft1 = 6
  1109. }
  1110. public enum DicType
  1111. {
  1112. CouponType,
  1113. Industry,
  1114. Region,
  1115. ServiceType,
  1116. TradeType,
  1117. MemberType,
  1118. FriendType,
  1119. ProductType,
  1120. GoodsType,
  1121. CityArea
  1122. }
  1123. //字典表类
  1124. public class DicItem
  1125. {
  1126. public int ID { get; set; }
  1127. public string RegionID { get; set; }
  1128. public int ParentID { get; set; }
  1129. public string Code { get; set; }
  1130. public string Name { get; set; }
  1131. public string Lng { get; set; }
  1132. public string Lat { get; set; }
  1133. public bool IsTakeMeal { get; set; }
  1134. public int Mcount { get; set; }
  1135. public DicItem()
  1136. {
  1137. }
  1138. public DicItem(int _id, string _name)
  1139. {
  1140. ID = _id;
  1141. Name = _name;
  1142. }
  1143. public DicItem(int _id, int _parentid, string _name)
  1144. {
  1145. ID = _id;
  1146. ParentID = _parentid;
  1147. Name = _name;
  1148. }
  1149. }
  1150. public class CityItem
  1151. {
  1152. public string RegionName { get; set; }
  1153. public string RegionCode { get; set; }
  1154. public string Prev { get; set; }
  1155. public string LngLat { get; set; }
  1156. public string CityData { get; set; }
  1157. public string IsHot { get; set; }
  1158. public CityItem(string rName, object rCode, object prev, object ishot, object lngLat)
  1159. {
  1160. RegionName = rName;
  1161. RegionCode = rCode.ToString();
  1162. Prev = prev.ToString();
  1163. IsHot = ishot.ToString();
  1164. LngLat = lngLat.ToString();
  1165. }
  1166. }
  1167. }