UserSession.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Data;
  5. using System.Web;
  6. using SysBaseLibs;
  7. using SysDataLibs.TableClass;
  8. namespace SysDataLibs
  9. {
  10. public class UserSession : IErrorMsg
  11. {
  12. public UserSession(Sys_Users_info poUsers, DBConnSql poConn)
  13. {
  14. _UserInfo = poUsers;
  15. _DBConn = poConn;
  16. }
  17. // Methods
  18. #region 权限菜单相关方法
  19. //private Dictionary<string, UIAndPower> _PowHas;
  20. private UIAndPowerList _powerList;
  21. public bool CheckPowerNoErrRedirect(PowerType poType)
  22. {
  23. UserSession loSession = WebLibs.GetUserSession();
  24. if (loSession != null)
  25. {
  26. ThreadLog.LogInfo(loSession.UserInfo.UserID + " --- " + WebLibs.CurPageName + " --- " + poType.ToString());
  27. }
  28. string pcUIID = UtilStr.UAndT(WebLibs.CurPageName);
  29. bool lbRetVal = false;
  30. if (this._powerList.ContainPageName(pcUIID))
  31. {
  32. UIAndPower power = this._powerList.getUIAndPowerByPageName(pcUIID);
  33. switch (poType)
  34. {
  35. case PowerType.IsBrowse:
  36. lbRetVal = power.IsBrowse;
  37. break;
  38. case PowerType.IsAdd:
  39. lbRetVal = power.IsAdd;
  40. break;
  41. case PowerType.IsUpdate:
  42. lbRetVal = power.IsUpdate;
  43. break;
  44. case PowerType.IsDelete:
  45. lbRetVal = power.IsDelete;
  46. break;
  47. case PowerType.IsAudit:
  48. lbRetVal = power.IsAudit;
  49. break;
  50. case PowerType.IsPrint:
  51. lbRetVal = power.IsPrint;
  52. break;
  53. }
  54. }
  55. return lbRetVal;
  56. }
  57. /// <summary>
  58. /// 权限检查
  59. /// </summary>
  60. /// <param name="poType">检查的类型</param>
  61. /// <returns></returns>
  62. public bool CheckPower(PowerType poType)
  63. {
  64. UserSession loSession = WebLibs.GetUserSession();
  65. if (loSession != null)
  66. {
  67. ThreadLog.LogInfo(loSession.UserInfo.UserID + " --- " + WebLibs.CurPageName + " --- " + poType.ToString());
  68. }
  69. string pcUIID = UtilStr.UAndT(WebLibs.CurPageName);
  70. bool lbRetVal = false;
  71. if (this._powerList.ContainPageName(pcUIID))
  72. {
  73. UIAndPower power = this._powerList.getUIAndPowerByPageName(pcUIID);
  74. switch (poType)
  75. {
  76. case PowerType.IsBrowse:
  77. lbRetVal = power.IsBrowse;
  78. if (!lbRetVal)
  79. WebLibs.NotPower(1);
  80. break;
  81. case PowerType.IsAdd:
  82. lbRetVal = power.IsAdd;
  83. if (!lbRetVal)
  84. WebLibs.NotPower(2);
  85. break;
  86. case PowerType.IsUpdate:
  87. lbRetVal = power.IsUpdate;
  88. if (!lbRetVal)
  89. WebLibs.NotPower(3);
  90. break;
  91. case PowerType.IsDelete:
  92. lbRetVal = power.IsDelete;
  93. if (!lbRetVal)
  94. WebLibs.NotPower(4);
  95. break;
  96. case PowerType.IsAudit:
  97. lbRetVal = power.IsAudit;
  98. if (!lbRetVal)
  99. WebLibs.NotPower(5);
  100. break;
  101. case PowerType.IsPrint:
  102. lbRetVal = power.IsPrint;
  103. //if (!lbRetVal)
  104. // WebLibs.NotPower(5);
  105. break;
  106. }
  107. }
  108. else
  109. {
  110. WebLibs.NotPower(7);
  111. }
  112. return lbRetVal;
  113. }
  114. /// <summary>
  115. /// 权限检查不跳转
  116. /// </summary>
  117. /// <param name="poType">检查的类型</param>
  118. /// <returns></returns>
  119. public bool CheckPowerNotRe(PowerType poType)
  120. {
  121. UserSession loSession = WebLibs.GetUserSession();
  122. if (loSession != null)
  123. {
  124. ThreadLog.LogInfo(loSession.UserInfo.UserID + " --- " + WebLibs.CurPageName + " --- " + poType.ToString());
  125. }
  126. string pcUIID = UtilStr.UAndT(WebLibs.CurPageName);
  127. bool lbRetVal = false;
  128. if (this._powerList.ContainPageName(pcUIID))
  129. {
  130. UIAndPower power = this._powerList.getUIAndPowerByPageName(pcUIID);
  131. switch (poType)
  132. {
  133. case PowerType.IsBrowse:
  134. lbRetVal = power.IsBrowse;
  135. break;
  136. case PowerType.IsAdd:
  137. lbRetVal = power.IsAdd;
  138. break;
  139. case PowerType.IsUpdate:
  140. lbRetVal = power.IsUpdate;
  141. break;
  142. case PowerType.IsDelete:
  143. lbRetVal = power.IsDelete;
  144. break;
  145. case PowerType.IsAudit:
  146. lbRetVal = power.IsAudit;
  147. break;
  148. case PowerType.IsPrint:
  149. lbRetVal = power.IsPrint;
  150. //if (!lbRetVal)
  151. // WebLibs.NotPower(5);
  152. break;
  153. }
  154. }
  155. else
  156. {
  157. //WebLibs.NotPower(7);
  158. }
  159. return lbRetVal;
  160. }
  161. /// <summary>
  162. ///
  163. /// </summary>
  164. /// <param name="poType"></param>
  165. /// <param name="msg"></param>
  166. /// <returns></returns>
  167. public bool CheckPowerMvc(PowerType poType,ref string msg)
  168. {
  169. UserSession loSession = WebLibs.GetUserSession();
  170. if (loSession != null)
  171. {
  172. ThreadLog.LogInfo(loSession.UserInfo.UserID + " --- " + WebLibs.CurPageName + " --- " + poType);
  173. }
  174. string pcUiid = UtilStr.UAndT(WebLibs.CurPageName);
  175. bool lbRetVal = false;
  176. if (_powerList.ContainPageName(pcUiid))
  177. {
  178. UIAndPower power = _powerList.getUIAndPowerByPageName(pcUiid);
  179. switch (poType)
  180. {
  181. case PowerType.IsBrowse:
  182. lbRetVal = power.IsBrowse;
  183. break;
  184. case PowerType.IsAdd:
  185. lbRetVal = power.IsAdd;
  186. break;
  187. case PowerType.IsUpdate:
  188. lbRetVal = power.IsUpdate;
  189. break;
  190. case PowerType.IsDelete:
  191. lbRetVal = power.IsDelete;
  192. break;
  193. case PowerType.IsAudit:
  194. lbRetVal = power.IsAudit;
  195. break;
  196. case PowerType.IsPrint:
  197. lbRetVal = power.IsPrint;
  198. break;
  199. }
  200. }
  201. if (!lbRetVal)
  202. NotPower(poType,ref msg);
  203. return lbRetVal;
  204. }
  205. public static void NotPower(PowerType poType,ref string msg)
  206. {
  207. if (msg == null) throw new ArgumentNullException(nameof(msg));
  208. msg = SysRebackDisplayInfo.Instance.GetDisplayValue("Oper_Auth_Error");
  209. switch (poType)
  210. {
  211. case PowerType.IsBrowse:
  212. msg = SysRebackDisplayInfo.Instance.GetDisplayValue("Oper_Auth_Browse");
  213. break;
  214. case PowerType.IsAdd:
  215. msg = SysRebackDisplayInfo.Instance.GetDisplayValue("Oper_Auth_Add");
  216. break;
  217. case PowerType.IsUpdate:
  218. msg = SysRebackDisplayInfo.Instance.GetDisplayValue("Oper_Auth_Edit");
  219. break;
  220. case PowerType.IsDelete:
  221. msg = SysRebackDisplayInfo.Instance.GetDisplayValue("Oper_Auth_Del");
  222. break;
  223. case PowerType.IsAudit:
  224. msg = SysRebackDisplayInfo.Instance.GetDisplayValue("Oper_Auth_Audit");
  225. break;
  226. case PowerType.IsPrint:
  227. msg = SysRebackDisplayInfo.Instance.GetDisplayValue("Oper_Auth_Print");
  228. break;
  229. }
  230. }
  231. public bool CheckPower()
  232. {
  233. string lcPageName = UtilStr.UAndT(WebLibs.CurPageName);
  234. bool lbRetVal = false;
  235. if (this._powerList.ContainPageName(lcPageName))
  236. {
  237. UIAndPower power = this._powerList.getUIAndPowerByPageName(lcPageName);
  238. if (power.IsBrowse && power.IsAdd && power.IsUpdate && power.IsDelete)
  239. {
  240. lbRetVal = true;
  241. }
  242. else
  243. WebLibs.NotPower(6);
  244. }
  245. else
  246. {
  247. WebLibs.NotPower(7);
  248. }
  249. return lbRetVal;
  250. }
  251. private void CreatePowHasDict(DataTable poDataTable)
  252. {
  253. if (this._powerList == null)
  254. this._powerList = new UIAndPowerList();
  255. else
  256. this._powerList.Clear();
  257. if (poDataTable!=null)
  258. {
  259. try
  260. {
  261. _powerList.SetData(poDataTable);
  262. }
  263. catch (Exception e)
  264. {
  265. ThreadLog.LogException(e);
  266. _ErrorMsg = e.Message;
  267. }
  268. }
  269. }
  270. public void refreshFunctions()
  271. {
  272. //string lcSql = "select * from " + Tn.v_UserHasAllFunctions_New + " where UserID='" + this._UserInfo.UserID + "' order by FunctionID ";
  273. string lcSql = "select * from v_UserHasAllFunctions_New where UserID='" + this._UserInfo.UserID + "' order by FunctionID ";
  274. rsQuery loQuery = DBConn.OpenQuery(lcSql);
  275. if (loQuery != null && loQuery.IsOpened && loQuery.RecCount > 0)
  276. {
  277. CreatePowHasDict(loQuery.CurrentTable);
  278. }
  279. else
  280. {
  281. _ErrorMsg = DBConn.ErrorMsg;
  282. ThreadLog.LogErr(_ErrorMsg);
  283. }
  284. }
  285. #endregion
  286. // Methods
  287. #region 市场相关的方法
  288. private void GetMarketListByUserID()
  289. {
  290. if (_UserInfo != null)
  291. {
  292. string lcSql = "select * from " + Tn.vwUserHasAllMarkets + " where " + vwUserHasAllMarkets_info.cUserID + "='" + _UserInfo.UserID + "'";
  293. rsQuery loQuery = _DBConn.OpenQuery(lcSql);
  294. if (loQuery != null && loQuery.IsOpened && loQuery.RecCount > 0)
  295. {
  296. loQuery.MoveFirst();
  297. _MarketIdList = "";
  298. for (int i = 0; i < loQuery.RecCount; i++)
  299. {
  300. string lcMarketId = loQuery.GetString(Markets_info.cMarketID);
  301. if (lcMarketId.Trim().Length > 0)
  302. {
  303. lcMarketId = "'" + lcMarketId + "'";
  304. _MarketIdList += (_MarketIdList == "" ? "" : ",") + lcMarketId;
  305. }
  306. loQuery.MoveNext();
  307. }
  308. }
  309. }
  310. }
  311. private void GetMarketInfobyMarketId()
  312. {
  313. if (IsMarketSysAccount)
  314. {
  315. _MarketInfo = new Markets_info(MarketId, _DBConn);
  316. }
  317. }
  318. #endregion
  319. List<string> _DenyList = null;
  320. private List<string> DenyList
  321. {
  322. get
  323. {
  324. if (_DenyList == null && !IsSystem)
  325. {
  326. string lcSql = " select * from " + Tn.v_UserDenyColumns + " where " + v_UserDenyColumns_info.cUserID + "='" + _UserInfo.UserID + "'";
  327. rsQuery loQuery = DBConn.OpenQuery(lcSql);
  328. if (loQuery != null && loQuery.IsOpened && loQuery.RecCount > 0)
  329. {
  330. _DenyList = new List<string>();
  331. loQuery.MoveFirst();
  332. for (int i = 0; i < loQuery.RecCount; i++)
  333. {
  334. string lcTCol = loQuery.GetString("TableId") + "." + loQuery.GetString("ColumnId");
  335. lcTCol = UtilStr.UAndT(lcTCol);
  336. _DenyList.Add(lcTCol);
  337. loQuery.MoveNext();
  338. }
  339. }
  340. }
  341. return _DenyList;
  342. }
  343. }
  344. public bool ColDeny(string pcTableId,string pcColumnId)
  345. {
  346. bool lbRetVal = false;
  347. if (DenyList != null)
  348. {
  349. string lcTCol = pcTableId + "." + pcColumnId;
  350. lcTCol = UtilStr.UAndT(lcTCol);
  351. lbRetVal = DenyList.Contains(lcTCol);
  352. }
  353. return lbRetVal;
  354. }
  355. #region 基础属性
  356. private string _ErrorMsg = "";
  357. public string ErrorMsg
  358. {
  359. get { return _ErrorMsg; }
  360. set { _ErrorMsg = value; }
  361. }
  362. public bool IsSystem
  363. {
  364. get { return UtilStr.StrToBool(_UserInfo.IsSystem); }
  365. }
  366. public bool IsAdvance
  367. {
  368. get { return UtilStr.StrToBool(_UserInfo.IsAdvance); }
  369. }
  370. private DBConnSql _DBConn = null;
  371. public DBConnSql DBConn
  372. {
  373. get
  374. {
  375. if (_DBConn == null)
  376. {
  377. _DBConn = new DBConnSql();
  378. //_DBConn.OnlyExec = false;
  379. _DBConn.OnDBConnectionError += new evDBConnectionError(loDbcon_OnDBConnectionError);
  380. _DBConn.OnDBConnectionAction += new evDBConnectionAction(loConn_OnDBConnectionAction);
  381. }
  382. if (!_DBConn.IsOpened)
  383. {
  384. _DBConn.Open();
  385. }
  386. return _DBConn;
  387. }
  388. }
  389. private Sys_Users_info _UserInfo = null;
  390. public Sys_Users_info UserInfo
  391. {
  392. get { return _UserInfo; }
  393. }
  394. private Farms_info _FarmsInfo = null;
  395. public Farms_info FarmsInfo
  396. {
  397. get {
  398. if (_FarmsInfo == null)
  399. _FarmsInfo = new Farms_info(UserInfo.FarmID, DBConn);
  400. return _FarmsInfo; }
  401. }
  402. GSSystem_info _UserBelongToSystem;
  403. public GSSystem_info BelongToSystem
  404. {
  405. get
  406. {
  407. if (_UserBelongToSystem == null)
  408. _UserBelongToSystem = new GSSystem_info(UserInfo.SystemID, DBConn);
  409. return _UserBelongToSystem;
  410. }
  411. }
  412. public string GetSysName
  413. {
  414. get
  415. {
  416. if (BelongToSystem != null)
  417. {
  418. return BelongToSystem.shortName;
  419. }
  420. return "";
  421. }
  422. }
  423. private Markets_info _MarketInfo = null;
  424. public Markets_info MarketInfo
  425. {
  426. get
  427. {
  428. if (IsMarketSysAccount && (MarketId.Trim().Length > 0))
  429. {
  430. if (_MarketInfo == null)
  431. GetMarketInfobyMarketId();
  432. return _MarketInfo;
  433. }
  434. return null;
  435. }
  436. }
  437. private string _MarketIdList = "";
  438. private string MarketIdList
  439. {
  440. get
  441. {
  442. if (_MarketIdList.Trim().Length == 0)
  443. GetMarketListByUserID();
  444. return _MarketIdList;
  445. }
  446. }
  447. /// <summary>
  448. /// 得到筛选相关市场数据的SQL 语句
  449. /// </summary>
  450. /// <param name="pbAddAnd">true 在前面添加 and ,否则不添加 </param>
  451. /// <returns></returns>
  452. public string MarketDataSql(bool pbAddAnd)
  453. {
  454. string lcRetVal = "";
  455. switch (AT)
  456. {
  457. case AcountType.System: // 如果是系统管理员用户 则 可以查看所有被监管者的数据
  458. lcRetVal = " 1=1 ";
  459. break;
  460. case AcountType.Advance:
  461. if (this.UserInfo.RegionID.Trim().Length > 0) // 如果是 高级用户 则看到其所在区域里的所有市场的数据
  462. {
  463. lcRetVal = Markets_info.cMarketID + " in ( " + Markets_info.GetAllMarketIDByRegionId(UserInfo.RegionID, this) + " )";
  464. }
  465. break;
  466. case AcountType.AdvanceMarket: // 市场的高级用户
  467. case AcountType.CommonMarket: // 市场普通用户
  468. case AcountType.Common: // 普通用户 只能看到 指定给该账户的 被监管者的数据 ,可以指定多个被监管对象的数据
  469. if (MarketIdList.Trim().Length > 0)
  470. {
  471. lcRetVal = Markets_info.cMarketID + " in ( " + MarketIdList + " )";
  472. }
  473. else
  474. {
  475. lcRetVal = " 1=2 ";
  476. }
  477. break;
  478. }
  479. if (lcRetVal.Length > 0 && pbAddAnd)
  480. lcRetVal = " AND " + lcRetVal;
  481. return lcRetVal;
  482. }
  483. /// <summary>
  484. /// 得到筛选相关市场数据的SQL 语句
  485. /// </summary>
  486. /// <param name="pbAddAnd">true 在前面添加 and ,否则不添加 </param>
  487. /// <returns></returns>
  488. public string GSSystemDataSql(bool pbAddAnd)
  489. {
  490. string lcRetVal = " 1=1 ";
  491. if (this.IsMarketSysAccount)
  492. {
  493. if (this.UserInfo.GSSystem.SystemID == "Industry")
  494. {
  495. lcRetVal = GSSystem_info.cSystemID + " = 'Industry' ";
  496. }
  497. else
  498. {
  499. lcRetVal = GSSystem_info.cSystemID + " <> 'Industry' ";
  500. }
  501. //
  502. }
  503. if (pbAddAnd)
  504. {
  505. lcRetVal = " AND " + lcRetVal;
  506. }
  507. return lcRetVal;
  508. }
  509. public string MarketId
  510. {
  511. get
  512. {
  513. if (IsMarketSysAccount)
  514. return MarketIdList.Replace("'", "");
  515. else
  516. return "";
  517. }
  518. }
  519. public bool IsMarketSysAccount
  520. {
  521. get { return _UserInfo.IsMarketSys; }
  522. }
  523. public AcountType AT
  524. {
  525. get
  526. {
  527. if (IsSystem) // 系统用户
  528. {
  529. return AcountType.System;
  530. }
  531. else if (IsAdvance && !IsMarketSysAccount) // 高级监管用户
  532. {
  533. return AcountType.Advance;
  534. }
  535. else if (IsAdvance && IsMarketSysAccount) // 高级被监管者用户
  536. {
  537. return AcountType.AdvanceMarket;
  538. }
  539. else if (!IsAdvance && !IsMarketSysAccount) // 普通监管者用户
  540. {
  541. return AcountType.Common;
  542. }
  543. else
  544. return AcountType.CommonMarket; // 普通被监管者用户
  545. }
  546. }
  547. #endregion
  548. // #region 获得菜单列表的方法
  549. // /// <summary>
  550. // /// 得到用户能查看的菜单所有列表的string型
  551. // /// </summary>
  552. // public string UserFunctionIdList
  553. // {
  554. // get
  555. // {
  556. // if (_PowerList != null)
  557. // {
  558. // return _PowerList.UserFunctionIdList;
  559. // }
  560. // else
  561. // return "''";
  562. // }
  563. // }
  564. // public string GetMenuData(MenuType poMType)
  565. // {
  566. // string lcRetVal = "";
  567. // string lcSql = "select FunctionID,FunctionName,URL,FatherID ,Depth,IsLeaf,Sort from " + Tn.Sys_Functions+ " where 1=1 ";
  568. // switch (poMType)
  569. // {
  570. // case MenuType.Back:
  571. // lcSql += " and IsBack='Y' ";
  572. // break;
  573. // case MenuType.Front:
  574. // lcSql += " and IsFront='Y' ";
  575. // break;
  576. // }
  577. // lcSql += " and FunctionID in ( " + _PowerList.UserFunctionIdList + " )";
  578. // lcSql += " order by sort asc ";
  579. // DataSet loDataSet = DBConn.OpenDataSet(lcSql);
  580. // if (loDataSet != null && loDataSet.Tables.Count > 0)
  581. // {
  582. // lcRetVal = loDataSet.GetXml();
  583. // if (UserInfo.SystemID == SysDataLibs.AppEnv.SysSetObj.GetString("SUPERMARKET"))
  584. // lcRetVal = lcRetVal.Replace("市场", "超市"); // 写死了,以后考虑处理掉
  585. // }
  586. // else
  587. // {
  588. // JSComm.ShowMessage(Sys_Info_Qry.GetMsgByMsgCode("1011007"));
  589. // System.Web.HttpContext.Current.Response.Write("<form id='Form2' method='post' action='../Default.aspx' target='_top' ></form><script>Form2.submit();</script>");
  590. // System.Web.HttpContext.Current.Response.End();
  591. // }
  592. // return lcRetVal;
  593. // }
  594. //#endregion
  595. #region 获得菜单列表的方法
  596. /// <summary>
  597. /// 得到用户能查看的菜单所有列表的string型
  598. /// </summary>
  599. public string UserFunctionIdList
  600. {
  601. get
  602. {
  603. if (_powerList != null)
  604. {
  605. return _powerList.UserFunctionIdList;
  606. }
  607. else
  608. return "";
  609. }
  610. }
  611. public string GetMenuTable(MenuType poMType)
  612. {
  613. string lcRetVal = "";
  614. string lcSql = " select FunctionID,FunctionName,URL,FatherID,Depth,IsLeaf,Sort from Sys_Functions_N where 1=1 ";
  615. switch (poMType)
  616. {
  617. case MenuType.Back:
  618. lcSql += " and IsBack='Y' ";
  619. break;
  620. case MenuType.Front:
  621. lcSql += " and IsFront='Y' ";
  622. break;
  623. }
  624. lcSql += " and FunctionID in ( " + UserFunctionIdList + " )";
  625. lcSql += " order by sort asc ";
  626. DataSet loDataSet = DBConn.OpenDataSet(lcSql);
  627. if (loDataSet != null && loDataSet.Tables.Count > 0)
  628. {
  629. lcRetVal = loDataSet.GetXml();
  630. }
  631. else
  632. {
  633. JSComm.ShowMessage("该用户尚未配置相关权限,请与有关人员联系!");
  634. System.Web.HttpContext.Current.Response.Write("<form id='Form2' method='post' action='../Default.aspx' target='_top' ></form><script>Form2.submit();</script>");
  635. System.Web.HttpContext.Current.Response.End();
  636. }
  637. return lcRetVal;
  638. }
  639. public DataTable GetMenuTableDate(MenuType poMType)
  640. {
  641. DataTable loRetVal = null;
  642. string lcSql = "select FunctionID,FunctionName,URL,FatherID ,Depth,IsLeaf,Sort from Sys_Functions_N where 1=1 ";
  643. switch (poMType)
  644. {
  645. case MenuType.Back:
  646. lcSql += " and IsBack='Y' ";
  647. break;
  648. case MenuType.Front:
  649. lcSql += " and IsFront='Y' ";
  650. break;
  651. }
  652. lcSql += " and FunctionID in ( " + _powerList.UserFunctionIdList + " )";
  653. lcSql += " order by sort asc ";
  654. loRetVal = DBConn.OpenDataTable(lcSql);
  655. return loRetVal;
  656. }
  657. public DataTable GetMenuDataTable(MenuType poMType)
  658. {
  659. DataTable loRetVal = null;
  660. string lcSql = "select FunctionID as id,FunctionName as name,URL,FatherID as parentId,Depth,IsLeaf,Sort from Sys_Functions where 1=1 ";
  661. switch (poMType)
  662. {
  663. case MenuType.Back:
  664. lcSql += " and IsBack='Y' ";
  665. break;
  666. case MenuType.Front:
  667. lcSql += " and IsFront='Y' ";
  668. break;
  669. }
  670. lcSql += " and FunctionID in ( " + UserFunctionIdList + " )";
  671. lcSql += " order by sort asc ";
  672. rsQuery loQuery = DBConn.OpenQuery(lcSql);
  673. if (loQuery != null && loQuery.RecCount > 0 && loQuery.IsOpened)
  674. {
  675. // lcRetVal = loDataSet.GetXml();
  676. loQuery.CurrentTable.Columns.Add("state", typeof(string));
  677. loQuery.MoveFirst();
  678. for (int i = 0; i < loQuery.RecCount; i++)
  679. {
  680. loQuery.SetField("state", loQuery.GetInt("Depth") >= 1&& loQuery.GetString("IsLeaf") == "N" ? "closed" : "open");
  681. loQuery.MoveNext();
  682. }
  683. loRetVal = loQuery.CurrentTable;
  684. }
  685. else
  686. {
  687. JSComm.ShowMessage("该用户尚未配置相关权限,请与有关人员联系!");
  688. System.Web.HttpContext.Current.Response.Write("<form id='Form2' method='post' action='../Default.aspx' target='_top' ></form><script>Form2.submit();</script>");
  689. System.Web.HttpContext.Current.Response.End();
  690. }
  691. return loRetVal;
  692. }
  693. #endregion
  694. public void Destroy()
  695. {
  696. if (_UserInfo != null)
  697. {
  698. _UserInfo = null;
  699. }
  700. if (_powerList!= null)
  701. {
  702. _powerList.Clear();
  703. _powerList = null;
  704. }
  705. if (_ObjSave != null)
  706. {
  707. _ObjSave.Clear();
  708. _ObjSave = null;
  709. }
  710. if (_DenyList != null)
  711. {
  712. _DenyList.Clear();
  713. _DenyList = null;
  714. }
  715. if (_DBConn != null)
  716. {
  717. _DBConn.Close();
  718. _DBConn = null;
  719. }
  720. }
  721. #region 静态用户登录方法
  722. public static bool UserLogin(string pcUserID, string pcPassWord, ref string pcErrorMsg)
  723. {
  724. bool lbRetVal = false;
  725. if (pcPassWord.Length > 0 && pcUserID.Length > 0)
  726. {
  727. pcPassWord = SysSecLibs.SysSecurity.Encrypt(pcPassWord);
  728. DBConnSql loConn = new DBConnSql();
  729. //loConn.OnlyExec = false;
  730. loConn.OnDBConnectionError += new evDBConnectionError(loDbcon_OnDBConnectionError);
  731. loConn.OnDBConnectionAction += new evDBConnectionAction(loConn_OnDBConnectionAction);
  732. if (loConn.Open())
  733. {
  734. string lcSql = "select * from " + Tn.Sys_Users + " where "
  735. + Sys_Users_info.cIsLock + "='N' and " + Sys_Users_info.cUserCode + "='" + pcUserID + "' ";// and "+ Users_info.cPassword + "='" + pcPassWord + "'";
  736. rsQuery loQuery = loConn.OpenQuery(lcSql);
  737. if (loQuery != null && loQuery.IsOpened && loQuery.RecCount == 1)
  738. {
  739. //检查用户是否已经被审核
  740. if (!loQuery.GetBool(Sys_Users_info.cIsAudit))
  741. {
  742. pcErrorMsg = "用户尚在审核中!";
  743. return false;
  744. }
  745. string lcPassword = loQuery.GetString(Sys_Users_info.cPassword);
  746. if (pcPassWord == lcPassword)
  747. {
  748. Sys_Users_info loUserInfo = new Sys_Users_info(loQuery.CurrentRow);
  749. if (!Utils.ObjToBool(loUserInfo.IsSystem))
  750. {
  751. if (!MyUtils.IsPerm)
  752. {
  753. System.Web.HttpContext.Current.Response.Redirect("LecenseShow.aspx", true);
  754. }
  755. }
  756. //if (loUserInfo.IsExpiry)
  757. //{
  758. // pcErrorMsg = "用户帐号已经过期,请与系统管理员联系!";
  759. // return false;
  760. //}
  761. UserSession loSession = new UserSession(loUserInfo, loConn);
  762. System.Web.HttpContext.Current.Session[Contants.UserInfoId] = loSession;
  763. lbRetVal = true;
  764. }
  765. else
  766. pcErrorMsg = "用户密码不正确!";
  767. }
  768. else
  769. pcErrorMsg = "用户名不存在或已经被锁定!";
  770. }
  771. else
  772. {
  773. pcErrorMsg = "错误信息:" + loConn.ErrorMsg;
  774. System.Web.HttpContext.Current.Response.Write("<form id='Form2' method='post' action='Default.aspx' target='_top' ></form><script>alert('数据库连接失败,请跟系统管理人员联系!'); Form2.submit();</script>");
  775. System.Web.HttpContext.Current.Response.End();
  776. }
  777. }
  778. return lbRetVal;
  779. }
  780. static void loConn_OnDBConnectionAction(string pcCommand, string pcMessage)
  781. {
  782. UserSession loSession = WebLibs.GetUserSession();
  783. if (loSession != null)
  784. {
  785. ThreadLog.LogInfo(loSession.UserInfo.UserID + " --- " + WebLibs.CurPageName);
  786. }
  787. ThreadLog.LogInfo("Command:" + pcCommand + "\r\n" + " Message:" + pcMessage);
  788. }
  789. private static void loDbcon_OnDBConnectionError(string pcCommand, string pcMessage, string pcErrorNumbers)
  790. {
  791. try
  792. {
  793. Sys_Log_info.LogMsg(LogType.ErrorMsg, pcCommand, pcMessage, pcErrorNumbers);
  794. UserSession loSession = WebLibs.GetUserSession();
  795. if (loSession != null)
  796. {
  797. ThreadLog.LogInfo(loSession.UserInfo.UserID + " --- " + WebLibs.CurPageName);
  798. }
  799. ThreadLog.LogErr("Command:" + pcCommand + "\r\n" + " Message:" + pcMessage + " ErrorNumbers:" + pcErrorNumbers);
  800. }
  801. catch (Exception err)
  802. {
  803. ThreadLog.LogException(err);
  804. }
  805. }
  806. #endregion
  807. #region 对象存储
  808. Dictionary<string, object> _ObjSave = null;
  809. public void SetObj(string pcKey, object pcValue)
  810. {
  811. if (_ObjSave == null)
  812. _ObjSave = new Dictionary<string, object>();
  813. if (_ObjSave.ContainsKey(pcKey))
  814. _ObjSave[pcKey] = pcValue;
  815. else
  816. _ObjSave.Add(pcKey, pcValue);
  817. }
  818. public object GetObj(string pcKey)
  819. {
  820. return GetObj(pcKey, true);
  821. }
  822. /// <summary>
  823. /// 得到对象
  824. /// </summary>
  825. /// <param name="pcKey">索引值</param>
  826. /// <param name="pbClear">是否情况该对象</param>
  827. /// <returns></returns>
  828. public object GetObj(string pcKey,bool pbClear)
  829. {
  830. object loRetVal = null;
  831. if (_ObjSave != null && _ObjSave.ContainsKey(pcKey))
  832. {
  833. loRetVal = _ObjSave[pcKey];
  834. if (pbClear)
  835. {
  836. // _ObjSave[pcKey] = null;
  837. _ObjSave.Remove(pcKey);
  838. }
  839. }
  840. return loRetVal;
  841. }
  842. /// <summary>
  843. /// 清空对象
  844. /// </summary>
  845. public void ClearObj()
  846. {
  847. if (_ObjSave != null)
  848. {
  849. _ObjSave.Clear();
  850. _ObjSave = null;
  851. }
  852. }
  853. #endregion 对象存储
  854. }
  855. public enum MenuType
  856. {
  857. /// <summary>
  858. /// 前台显示
  859. /// </summary>
  860. Front = 0,
  861. /// <summary>
  862. /// 后台显示
  863. /// </summary>
  864. Back = 1,
  865. /// <summary>
  866. /// 显示所有
  867. /// </summary>
  868. All = 2
  869. }
  870. public enum AcountType
  871. {
  872. /// <summary>
  873. /// 系统用户
  874. /// </summary>
  875. System = 0,
  876. /// <summary>
  877. /// 高级用户
  878. /// </summary>
  879. Advance = 1,
  880. /// <summary>
  881. /// 普通用户
  882. /// </summary>
  883. Common = 2,
  884. /// <summary>
  885. /// 高级市场用户
  886. /// </summary>
  887. AdvanceMarket = 3,
  888. /// <summary>
  889. /// 普通市场用户
  890. /// </summary>
  891. CommonMarket = 4
  892. }
  893. }