WebCache.cs 45 KB

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