dkOrganizationSearchBox.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  1. /*******************************************************************************
  2. * Copyright(c) 2014 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:dkOrganizationSearchBox.cs
  5. * 2.功能描述:组织结构选择控件
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 陈冰 2014/08/29 1.00 新建
  9. * 王鑫 2014/09/13 1.00 修改(添加一个当前用户组织机构属性)
  10. *******************************************************************************/
  11. using System;
  12. using System.ComponentModel;
  13. using System.Data;
  14. using System.Drawing;
  15. using System.Windows.Forms;
  16. using Dongke.IBOSS.PRD.Basics.BaseControls;
  17. using Dongke.IBOSS.PRD.WCF.Proxys;
  18. using Dongke.IBOSS.PRD.Client.DataModels;
  19. using Dongke.IBOSS.PRD.Basics.BaseResources;
  20. namespace Dongke.IBOSS.PRD.Client.Controls
  21. {
  22. /// <summary>
  23. /// 组织结构选择控件
  24. /// </summary>
  25. public partial class dkOrganizationSearchBox : UserControl
  26. {
  27. #region 成员变量
  28. private S_CMN_001 _frmOrganization;
  29. private Label lblOrganization; // 项目名称标签
  30. private TextBox txtOrganization; // 输入文本框
  31. private Button btnSearch; // 查询按钮
  32. private bool _isEnabled = true; // 控件是否可用
  33. private DataTable _dataSource = null; // 数据源
  34. private int? _organizationID; // 组织机构ID
  35. private string _organizationIDS; //id集
  36. private string _organizationCode; // 组织机构Code
  37. private string _organizationName; // 组织机构名称
  38. private bool _isOnlyDisplayEnd; // 只显示末端组织结构标识
  39. private bool _isMustInput; // 控件是否是必须输入项目
  40. private bool _IsOnlyShowValid = true; // 是否只显示有效数据
  41. private string _currentuserorganizationCode; // 当前用户组织机构用于过滤
  42. #endregion
  43. #region 构造函数
  44. public dkOrganizationSearchBox()
  45. {
  46. InitializeComponent();
  47. this.IsOnlyDisplayEnd = false;
  48. this.ReadOnly = true;
  49. }
  50. #endregion
  51. #region 属性
  52. /// <summary>
  53. /// 是否只显示有效数据
  54. /// </summary>
  55. [Description("设置控件是否只显示有效数据。")]
  56. [DefaultValue(true)]
  57. public bool IsOnlyShowValid
  58. {
  59. get
  60. {
  61. return _IsOnlyShowValid;
  62. }
  63. set
  64. {
  65. _IsOnlyShowValid = value;
  66. }
  67. }
  68. /// <summary>
  69. /// 获取或者设定控件是否是必须输入项目
  70. /// </summary>
  71. [DefaultValue("False")]
  72. [Description("获取或者设定控件是否是必须输入项目。")]
  73. public bool IsMustInput
  74. {
  75. get
  76. {
  77. return _isMustInput;
  78. }
  79. set
  80. {
  81. _isMustInput = value;
  82. // 项目为必须输入项时,需要修改字体颜色
  83. if (_isMustInput)
  84. {
  85. this.lblOrganization.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(155)))), ((int)(((byte)(39)))), ((int)(((byte)(39)))));
  86. }
  87. else
  88. {
  89. this.lblOrganization.ForeColor = System.Drawing.SystemColors.ControlText;
  90. }
  91. }
  92. }
  93. [DefaultValue("组织机构")]
  94. [Description("获取或者设定Lable标签字符。")]
  95. public string Title
  96. {
  97. get
  98. {
  99. return this.lblOrganization.Text;
  100. }
  101. set
  102. {
  103. this.lblOrganization.Text = value;
  104. AdjustControl();
  105. }
  106. }
  107. /// <summary>
  108. /// 获取和设置是否只显示末端组织机构。
  109. /// </summary>
  110. [DefaultValue(true)]
  111. [Description("获取和设置是否只显示末端组织机构。")]
  112. public bool IsOnlyDisplayEnd
  113. {
  114. get
  115. {
  116. return _isOnlyDisplayEnd;
  117. }
  118. set
  119. {
  120. _isOnlyDisplayEnd = value;
  121. }
  122. }
  123. [DefaultValue(false)]
  124. public bool IsDeleteSelf
  125. {
  126. get;
  127. set;
  128. }
  129. /// <summary>
  130. /// 获取或者设定控件的数据源。
  131. /// </summary>
  132. [Description("获取或者设定控件的数据源。")]
  133. public DataTable DataSource
  134. {
  135. get
  136. {
  137. return _dataSource;
  138. }
  139. set
  140. {
  141. DataTable dataSource = SetFilter(value);
  142. _dataSource = dataSource;
  143. // 如果数据源有值,需要过滤范围权限
  144. if (_dataSource != null && _dataSource.Rows.Count > 0)
  145. {
  146. string filter = string.Empty;
  147. // 只显示叶节点部门
  148. if (IsOnlyDisplayEnd)
  149. {
  150. for (int i = _dataSource.Rows.Count - 1; i >= 0; i--)
  151. {
  152. filter = "LEN(OrganizationCode) > 3 AND OrganizationCode LIKE '" + _dataSource.Rows[i]["OrganizationCode"] + "%'";
  153. _dataSource.DefaultView.RowFilter = filter;
  154. DataTable table = _dataSource.DefaultView.ToTable();
  155. // 说明有下级种类
  156. if (table.Rows.Count > 1)
  157. {
  158. _dataSource.Rows.RemoveAt(i);
  159. }
  160. }
  161. }
  162. // 是否是结算部门
  163. if (IsAccountOrganization)
  164. {
  165. filter = "LEN(OrganizationCode) = 6";
  166. _dataSource.DefaultView.RowFilter = filter;
  167. _dataSource = _dataSource.DefaultView.ToTable();
  168. }
  169. }
  170. }
  171. }
  172. /// <summary>
  173. /// 获取或者设定控件的尺寸大小。
  174. /// </summary>
  175. [Description("获取或者设定控件的尺寸大小。")]
  176. public new Size Size
  177. {
  178. get
  179. {
  180. return base.Size;
  181. }
  182. set
  183. {
  184. base.Size = value;
  185. AdjustControl();
  186. }
  187. }
  188. /// <summary>
  189. /// 获取或者设定控件的文本框的文本字符串。
  190. /// </summary>
  191. [Description("获取或者设定控件的文本框的文本字符串。")]
  192. public override string Text
  193. {
  194. get
  195. {
  196. return this.txtOrganization.Text;
  197. }
  198. set
  199. {
  200. this.txtOrganization.Text = value;
  201. }
  202. }
  203. /// <summary>
  204. /// 获取或者设定控件的文本框的背景颜色。
  205. /// </summary>
  206. [Description("获取或者设定控件的文本框的背景颜色。")]
  207. public Color TxtOrganizationBackColor
  208. {
  209. get
  210. {
  211. return this.txtOrganization.BackColor;
  212. }
  213. set
  214. {
  215. this.txtOrganization.BackColor = value;
  216. }
  217. }
  218. /// <summary>
  219. /// 获取或者设定控件的组织机构ID。
  220. /// </summary>
  221. [Description("获取或者设定控件的组织机构ID。")]
  222. [DefaultValue(null)]
  223. public int? OrganizationID
  224. {
  225. get
  226. {
  227. return _organizationID;
  228. }
  229. set
  230. {
  231. this._organizationID = null;
  232. this._organizationCode = string.Empty;
  233. this._organizationName = string.Empty;
  234. this.Text = string.Empty;
  235. if (value != null)
  236. {
  237. // 当数据源为null时,查询数据源
  238. if (DataSource == null)
  239. {
  240. // 查询数据源
  241. DataSource = SystemModuleProxy.Service.GetOrganizationData(1, _isOnlyDisplayEnd ? 1 : 0);
  242. // 过滤数据
  243. SetFilter(DataSource);
  244. }
  245. if (value != null && value != 0 && this.DataSource != null)
  246. {
  247. DataTable organizationTable = this.DataSource.Copy();
  248. DataRow[] dataRows = organizationTable.Select("OrganizationID = " + value);
  249. if (dataRows.Length == 1)
  250. {
  251. this._organizationID = value;
  252. this._organizationCode = dataRows[0]["OrganizationCode"] as string;
  253. this._organizationName = dataRows[0]["OrganizationName"] as string;
  254. this.Text = dataRows[0]["OrganizationName"] as string;
  255. }
  256. }
  257. }
  258. }
  259. }
  260. /// <summary>
  261. /// 获取或者设定控件的组织机构id集
  262. /// </summary>
  263. [Description("获取或者设定控件的组织机构id集。")]
  264. public string OrganizationIDS
  265. {
  266. get
  267. {
  268. return _organizationIDS;
  269. }
  270. set
  271. {
  272. _organizationIDS = value;
  273. }
  274. }
  275. /// <summary>
  276. /// 获取或者设定控件的组织机构Code
  277. /// </summary>
  278. [Description("获取或者设定控件的组织机构Code。")]
  279. public string OrganizationCode
  280. {
  281. get
  282. {
  283. return _organizationCode;
  284. }
  285. set
  286. {
  287. _organizationCode = value;
  288. }
  289. }
  290. /// <summary>
  291. /// 获取或者设定控件的当前用户组织机构Code
  292. /// </summary>
  293. [Description("获取或者设定控件的当前用户组织机构Code。")]
  294. public string CurrentUserOrganizationCode
  295. {
  296. get
  297. {
  298. return _currentuserorganizationCode;
  299. }
  300. set
  301. {
  302. _currentuserorganizationCode = value;
  303. }
  304. }
  305. /// <summary>
  306. /// 获取或者设定控件的组织机构名称
  307. /// </summary>
  308. [Description("获取或者设定控件的组织机构名称。")]
  309. public string OrganizationName
  310. {
  311. get
  312. {
  313. return _organizationName;
  314. }
  315. set
  316. {
  317. _organizationName = value;
  318. }
  319. }
  320. /// <summary>
  321. /// 获取或者设定控件是否可用。
  322. /// </summary>
  323. [System.ComponentModel.DefaultValue(null)]
  324. [Description("获取或者设定控件是否可用。")]
  325. public new bool Enabled
  326. {
  327. get
  328. {
  329. return _isEnabled;
  330. }
  331. set
  332. {
  333. _isEnabled = value;
  334. this.txtOrganization.Enabled = _isEnabled;
  335. //this.btnSearch.Enabled = _isEnabled;
  336. this.TabStop = _isEnabled;
  337. }
  338. }
  339. /// <summary>
  340. /// 获取或者设定控件是否只读。
  341. /// </summary>
  342. [System.ComponentModel.DefaultValue(null)]
  343. [Description("获取或者设定控件是否只读。")]
  344. public bool ReadOnly
  345. {
  346. set
  347. {
  348. this.txtOrganization.ReadOnly = value;
  349. }
  350. }
  351. /// <summary>
  352. /// 范围权限
  353. /// </summary>
  354. public byte PurviewType
  355. {
  356. get;
  357. set;
  358. }
  359. /// <summary>
  360. /// 控件是否是核算部门。
  361. /// </summary>
  362. [System.ComponentModel.DefaultValue(false)]
  363. [Description("控件是否是核算部门。")]
  364. public bool IsAccountOrganization
  365. {
  366. get;
  367. set;
  368. }
  369. /// <summary>
  370. /// 控件部门操作权限。
  371. /// </summary>
  372. [System.ComponentModel.DefaultValue(false)]
  373. [Description("控件部门操作权限。")]
  374. public bool PurviewOperateFlag
  375. {
  376. get;
  377. set;
  378. }
  379. /// <summary>
  380. /// 控件部门查看权限。
  381. /// </summary>
  382. [System.ComponentModel.DefaultValue(false)]
  383. [Description("控件部门查看权限。")]
  384. public bool PurviewViewFlag
  385. {
  386. get;
  387. set;
  388. }
  389. /// <summary>
  390. /// 多选。
  391. /// </summary>
  392. [System.ComponentModel.DefaultValue(false)]
  393. [Description("多选。")]
  394. public bool SelectMore
  395. {
  396. get;
  397. set;
  398. }
  399. #endregion
  400. #region 定义委托事件
  401. public delegate void TextBoxChangedHandle(object sender, TextChangeEventArgs e);
  402. public event TextBoxChangedHandle OrganizationValueChanged;
  403. #endregion
  404. #region 控件事件
  405. [Description("控件光标点击按钮事件。")]
  406. public new event EventHandler Click
  407. {
  408. add
  409. {
  410. this.btnSearch.Click += value;
  411. }
  412. remove
  413. {
  414. this.btnSearch.Click -= value;
  415. }
  416. }
  417. /// <summary>
  418. /// 控件尺寸大小改变事件
  419. /// </summary>
  420. /// <param name="sender"></param>
  421. /// <param name="e"></param>
  422. private void dkOrganizationSearchBox_SizeChanged(object sender, System.EventArgs e)
  423. {
  424. AdjustControl();
  425. }
  426. /// <summary>
  427. /// 查询按钮按下事件
  428. /// </summary>
  429. /// <param name="sender"></param>
  430. /// <param name="e"></param>
  431. private void btnSearch_Click(object sender, System.EventArgs e)
  432. {
  433. // 如果属性是不可用,是不能进行点击事件的
  434. if (!Enabled)
  435. {
  436. return;
  437. }
  438. // 当数据源为null时,查询数据源
  439. if (DataSource == null)
  440. {
  441. // 查询数据源
  442. DataSource = SystemModuleProxy.Service.GetOrganizationData(1, _isOnlyDisplayEnd ? 1 : 0);
  443. }
  444. // 释放窗体资源
  445. if (null != _frmOrganization)
  446. {
  447. _frmOrganization.Dispose();
  448. _frmOrganization = null;
  449. }
  450. // 打开查询窗体
  451. //判断是否多选
  452. if (this.SelectMore)
  453. {
  454. _frmOrganization = new S_CMN_001(1);
  455. }
  456. else
  457. {
  458. _frmOrganization = new S_CMN_001(this.txtOrganization.Text);
  459. }
  460. DataTable organizationTable = this.DataSource.Copy();
  461. if (CurrentUserOrganizationCode == string.Empty)
  462. _frmOrganization.DataSource = this.DataSource;
  463. else
  464. {
  465. organizationTable.DefaultView.RowFilter = string.Format(" OrganizationCode LIKE '{0}%'", CurrentUserOrganizationCode);
  466. _frmOrganization.DataSource = organizationTable.DefaultView.ToTable();
  467. }
  468. DialogResult dialogResult = _frmOrganization.ShowDialog();
  469. // 查询窗体返回值给控件赋值
  470. if (dialogResult.Equals(DialogResult.OK))
  471. {
  472. if (this.SelectMore)
  473. {
  474. _organizationCode = string.Empty;
  475. _organizationName = string.Empty;
  476. _organizationIDS = string.Empty;
  477. if (_frmOrganization.OrganizationRow != null || _frmOrganization.dataDT.Rows.Count > 0)
  478. {
  479. for (int i = 0; i < _frmOrganization.dataDT.Rows.Count; i++)
  480. {
  481. if (_frmOrganization.dataDT.Rows[i]["sel"].ToString().Equals("1"))
  482. {
  483. if (string.IsNullOrEmpty(_organizationCode))
  484. {
  485. _organizationCode = _frmOrganization.dataDT.Rows[i]["OrganizationCode"].ToString();
  486. _organizationName = _frmOrganization.dataDT.Rows[i]["OrganizationName"].ToString();
  487. _organizationIDS = _frmOrganization.dataDT.Rows[i]["OrganizationID"].ToString();
  488. }
  489. else
  490. {
  491. _organizationCode += "," + _frmOrganization.dataDT.Rows[i]["OrganizationCode"].ToString();
  492. _organizationName += "," + _frmOrganization.dataDT.Rows[i]["OrganizationName"].ToString();
  493. _organizationIDS += "," + _frmOrganization.dataDT.Rows[i]["OrganizationID"].ToString();
  494. }
  495. }
  496. }
  497. this.Text = _organizationName;
  498. }
  499. }
  500. else
  501. {
  502. if (_frmOrganization.OrganizationRow != null)
  503. {
  504. _organizationID = Convert.ToInt32(_frmOrganization.OrganizationRow["OrganizationID"]);
  505. _organizationCode = _frmOrganization.OrganizationRow["OrganizationCode"].ToString();
  506. _organizationName = _frmOrganization.OrganizationRow["OrganizationName"].ToString();
  507. //this.Text = _frmOrganization.OrganizationRow["OrganizationName"].ToString();
  508. this.Text = _frmOrganization.OrganizationRow["OrganizationCode"].ToString() + "→"
  509. + _frmOrganization.OrganizationRow["OrganizationFullName"].ToString();
  510. }
  511. }
  512. }
  513. }
  514. /// <summary>
  515. /// 清除控件的值
  516. /// </summary>
  517. /// <param name="sender"></param>
  518. /// <param name="e"></param>
  519. private void txtOrganization_KeyDown(object sender, KeyEventArgs e)
  520. {
  521. if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Delete)
  522. {
  523. ClearControl();
  524. }
  525. }
  526. private void txtOrganization_TextChanged(object sender, EventArgs e)
  527. {
  528. if (OrganizationValueChanged != null)
  529. {
  530. OrganizationValueChanged(this, new TextChangeEventArgs(this.txtOrganization.Text));
  531. }
  532. }
  533. public class TextChangeEventArgs : EventArgs
  534. {
  535. public TextChangeEventArgs(string message)
  536. {
  537. }
  538. }
  539. #endregion
  540. #region 私有方法/函数
  541. /// <summary>
  542. /// 初始化控件界面控件内容
  543. /// </summary>
  544. private void InitializeComponent()
  545. {
  546. this.lblOrganization = new System.Windows.Forms.Label();
  547. this.txtOrganization = new System.Windows.Forms.TextBox();
  548. this.btnSearch = new System.Windows.Forms.Button();
  549. this.SuspendLayout();
  550. //
  551. // lblOrganization
  552. //
  553. this.lblOrganization.AutoSize = true;
  554. this.lblOrganization.BackColor = System.Drawing.Color.Transparent;
  555. //this.lblOrganization.Image = global::Dongke.IBOSS.Framework.Controls.Properties.Resources.bg;
  556. this.lblOrganization.Location = new System.Drawing.Point(3, 4);
  557. this.lblOrganization.Name = "lblOrganization";
  558. this.lblOrganization.Size = new System.Drawing.Size(53, 12);
  559. this.lblOrganization.TabIndex = 0;
  560. this.lblOrganization.Text = "组织机构";
  561. //
  562. // txtOrganization
  563. //
  564. this.txtOrganization.Font = new System.Drawing.Font("宋体", 9F);
  565. this.txtOrganization.Location = new System.Drawing.Point(62, 0);
  566. this.txtOrganization.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
  567. this.txtOrganization.Name = "txtOrganization";
  568. this.txtOrganization.ReadOnly = true;
  569. this.txtOrganization.Size = new System.Drawing.Size(155, 21);
  570. this.txtOrganization.TabIndex = 1;
  571. this.txtOrganization.TextChanged += new System.EventHandler(this.txtOrganization_TextChanged);
  572. this.txtOrganization.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtOrganization_KeyDown);
  573. //
  574. // btnSearch
  575. //
  576. this.btnSearch.Image = global::Dongke.IBOSS.PRD.Client.Controls.Properties.Resources.searchButton;
  577. this.btnSearch.Location = new System.Drawing.Point(223, 0);
  578. this.btnSearch.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
  579. this.btnSearch.Name = "btnSearch";
  580. this.btnSearch.Size = new System.Drawing.Size(21, 21);
  581. this.btnSearch.TabIndex = 2;
  582. this.btnSearch.UseVisualStyleBackColor = true;
  583. this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
  584. //
  585. // dkOrganizationSearchBox
  586. //
  587. this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
  588. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  589. this.BackColor = System.Drawing.Color.Transparent;
  590. this.Controls.Add(this.btnSearch);
  591. this.Controls.Add(this.txtOrganization);
  592. this.Controls.Add(this.lblOrganization);
  593. this.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
  594. this.Name = "dkOrganizationSearchBox";
  595. this.Size = new System.Drawing.Size(245, 21);
  596. this.SizeChanged += new System.EventHandler(this.dkOrganizationSearchBox_SizeChanged);
  597. this.ResumeLayout(false);
  598. this.PerformLayout();
  599. }
  600. /// <summary>
  601. /// 根据控件的尺寸变化,改变控件内部控件的尺寸大小
  602. /// </summary>
  603. protected void AdjustControl()
  604. {
  605. // 取得按钮控件的宽度和高度
  606. int buttonWidth = (this.btnSearch.Visible) ? this.btnSearch.Width : 0;
  607. this.Height = this.btnSearch.Height;
  608. // 设置控件的尺寸和位置。
  609. this.txtOrganization.Location = new System.Drawing.Point(this.lblOrganization.Width +
  610. ControlsConst.CONTROLSPACE, (this.Height - this.txtOrganization.Height) / 2);
  611. this.txtOrganization.Size = new System.Drawing.Size(this.Width - this.btnSearch.Width -
  612. (this.lblOrganization.Width + ControlsConst.CONTROLSPACE * 2), this.Height);
  613. this.btnSearch.Location =
  614. new System.Drawing.Point(this.Width - this.btnSearch.Width,
  615. (this.Height - this.btnSearch.Height) / 2);
  616. // 设置标签的尺寸和位置。
  617. this.lblOrganization.Location =
  618. new System.Drawing.Point(0, (this.Height - this.lblOrganization.Height) / 2);
  619. this.lblOrganization.Size = new System.Drawing.Size(this.lblOrganization.Width, this.lblOrganization.Height);
  620. }
  621. /// <summary>
  622. /// 清空控件的值
  623. /// </summary>
  624. /// <param name="dataSource"></param>
  625. /// <returns></returns>
  626. public void ClearControl()
  627. {
  628. this.txtOrganization.Text = "";
  629. this._organizationID = null;
  630. this._organizationCode = string.Empty;
  631. this._organizationName = string.Empty;
  632. this._organizationIDS = string.Empty;
  633. }
  634. /// <summary>
  635. /// 过滤数据源
  636. /// </summary>
  637. /// <param name="dataSource"></param>
  638. /// <returns></returns>
  639. protected DataTable SetFilter(DataTable dataSource)
  640. {
  641. if (dataSource is DataTable)
  642. {
  643. #region 过滤部门操作权限
  644. if (PurviewOperateFlag)
  645. {
  646. if (LogInUserInfo.CurrentUser.CurrentUserEntity.UserRangeRightData != null)
  647. {
  648. string rowFilter = "0";
  649. foreach (DataRow row in LogInUserInfo.CurrentUser.CurrentUserEntity.UserRangeRightData.Rows)
  650. {
  651. // 操作部门类型
  652. if (int.Parse(row["PurviewType"].ToString()) == Constant.PurviewType.OperateOrganization.GetHashCode())
  653. {
  654. if ("-1" == row["PurviewID"].ToString())
  655. {
  656. rowFilter = "";
  657. break;
  658. }
  659. rowFilter += "," + row["PurviewID"].ToString();
  660. }
  661. }
  662. if (rowFilter != "")
  663. {
  664. dataSource.DefaultView.RowFilter = "OrganizationID IN (" + rowFilter + ")";
  665. dataSource = dataSource.DefaultView.ToTable();
  666. }
  667. }
  668. }
  669. #endregion
  670. #region 过滤部门查看权限
  671. if (PurviewViewFlag)
  672. {
  673. if (LogInUserInfo.CurrentUser.CurrentUserEntity.UserRangeRightData != null)
  674. {
  675. string rowFilter = "0";
  676. foreach (DataRow row in LogInUserInfo.CurrentUser.CurrentUserEntity.UserRangeRightData.Rows)
  677. {
  678. // 查看部门类型
  679. if (int.Parse(row["PurviewType"].ToString()) == Constant.PurviewType.ViewOrganization.GetHashCode())
  680. {
  681. if ("-1" == row["PurviewID"].ToString())
  682. {
  683. rowFilter = "";
  684. break;
  685. }
  686. rowFilter += "," + row["PurviewID"].ToString();
  687. }
  688. }
  689. if (rowFilter != "")
  690. {
  691. dataSource.DefaultView.RowFilter = "OrganizationID IN (" + rowFilter + ")";
  692. dataSource = dataSource.DefaultView.ToTable();
  693. }
  694. }
  695. }
  696. #endregion
  697. }
  698. return dataSource;
  699. }
  700. #endregion
  701. }
  702. }