| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760 |
- /*******************************************************************************
- * Copyright(c) 2014 dongke All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:dkOrganizationSearchBox.cs
- * 2.功能描述:组织结构选择控件
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 陈冰 2014/08/29 1.00 新建
- * 王鑫 2014/09/13 1.00 修改(添加一个当前用户组织机构属性)
- *******************************************************************************/
- using System;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Windows.Forms;
- using Dongke.IBOSS.PRD.Basics.BaseControls;
- using Dongke.IBOSS.PRD.WCF.Proxys;
- using Dongke.IBOSS.PRD.Client.DataModels;
- using Dongke.IBOSS.PRD.Basics.BaseResources;
- namespace Dongke.IBOSS.PRD.Client.Controls
- {
- /// <summary>
- /// 组织结构选择控件
- /// </summary>
- public partial class dkOrganizationSearchBox : UserControl
- {
- #region 成员变量
- private S_CMN_001 _frmOrganization;
- private Label lblOrganization; // 项目名称标签
- private TextBox txtOrganization; // 输入文本框
- private Button btnSearch; // 查询按钮
- private bool _isEnabled = true; // 控件是否可用
- private DataTable _dataSource = null; // 数据源
- private int? _organizationID; // 组织机构ID
- private string _organizationIDS; //id集
- private string _organizationCode; // 组织机构Code
- private string _organizationName; // 组织机构名称
- private bool _isOnlyDisplayEnd; // 只显示末端组织结构标识
- private bool _isMustInput; // 控件是否是必须输入项目
- private bool _IsOnlyShowValid = true; // 是否只显示有效数据
- private string _currentuserorganizationCode; // 当前用户组织机构用于过滤
- #endregion
- #region 构造函数
- public dkOrganizationSearchBox()
- {
- InitializeComponent();
- this.IsOnlyDisplayEnd = false;
- this.ReadOnly = true;
- }
- #endregion
- #region 属性
- /// <summary>
- /// 是否只显示有效数据
- /// </summary>
- [Description("设置控件是否只显示有效数据。")]
- [DefaultValue(true)]
- public bool IsOnlyShowValid
- {
- get
- {
- return _IsOnlyShowValid;
- }
- set
- {
- _IsOnlyShowValid = value;
- }
- }
- /// <summary>
- /// 获取或者设定控件是否是必须输入项目
- /// </summary>
- [DefaultValue("False")]
- [Description("获取或者设定控件是否是必须输入项目。")]
- public bool IsMustInput
- {
- get
- {
- return _isMustInput;
- }
- set
- {
- _isMustInput = value;
- // 项目为必须输入项时,需要修改字体颜色
- if (_isMustInput)
- {
- this.lblOrganization.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(155)))), ((int)(((byte)(39)))), ((int)(((byte)(39)))));
- }
- else
- {
- this.lblOrganization.ForeColor = System.Drawing.SystemColors.ControlText;
- }
- }
- }
- [DefaultValue("组织机构")]
- [Description("获取或者设定Lable标签字符。")]
- public string Title
- {
- get
- {
- return this.lblOrganization.Text;
- }
- set
- {
- this.lblOrganization.Text = value;
- AdjustControl();
- }
- }
- /// <summary>
- /// 获取和设置是否只显示末端组织机构。
- /// </summary>
- [DefaultValue(true)]
- [Description("获取和设置是否只显示末端组织机构。")]
- public bool IsOnlyDisplayEnd
- {
- get
- {
- return _isOnlyDisplayEnd;
- }
- set
- {
- _isOnlyDisplayEnd = value;
- }
- }
- [DefaultValue(false)]
- public bool IsDeleteSelf
- {
- get;
- set;
- }
- /// <summary>
- /// 获取或者设定控件的数据源。
- /// </summary>
- [Description("获取或者设定控件的数据源。")]
- public DataTable DataSource
- {
- get
- {
- return _dataSource;
- }
- set
- {
- DataTable dataSource = SetFilter(value);
- _dataSource = dataSource;
- // 如果数据源有值,需要过滤范围权限
- if (_dataSource != null && _dataSource.Rows.Count > 0)
- {
- string filter = string.Empty;
- // 只显示叶节点部门
- if (IsOnlyDisplayEnd)
- {
- for (int i = _dataSource.Rows.Count - 1; i >= 0; i--)
- {
- filter = "LEN(OrganizationCode) > 3 AND OrganizationCode LIKE '" + _dataSource.Rows[i]["OrganizationCode"] + "%'";
- _dataSource.DefaultView.RowFilter = filter;
- DataTable table = _dataSource.DefaultView.ToTable();
- // 说明有下级种类
- if (table.Rows.Count > 1)
- {
- _dataSource.Rows.RemoveAt(i);
- }
- }
- }
- // 是否是结算部门
- if (IsAccountOrganization)
- {
- filter = "LEN(OrganizationCode) = 6";
- _dataSource.DefaultView.RowFilter = filter;
- _dataSource = _dataSource.DefaultView.ToTable();
- }
- }
- }
- }
- /// <summary>
- /// 获取或者设定控件的尺寸大小。
- /// </summary>
- [Description("获取或者设定控件的尺寸大小。")]
- public new Size Size
- {
- get
- {
- return base.Size;
- }
- set
- {
- base.Size = value;
- AdjustControl();
- }
- }
- /// <summary>
- /// 获取或者设定控件的文本框的文本字符串。
- /// </summary>
- [Description("获取或者设定控件的文本框的文本字符串。")]
- public override string Text
- {
- get
- {
- return this.txtOrganization.Text;
- }
- set
- {
- this.txtOrganization.Text = value;
- }
- }
- /// <summary>
- /// 获取或者设定控件的文本框的背景颜色。
- /// </summary>
- [Description("获取或者设定控件的文本框的背景颜色。")]
- public Color TxtOrganizationBackColor
- {
- get
- {
- return this.txtOrganization.BackColor;
- }
- set
- {
- this.txtOrganization.BackColor = value;
- }
- }
- /// <summary>
- /// 获取或者设定控件的组织机构ID。
- /// </summary>
- [Description("获取或者设定控件的组织机构ID。")]
- [DefaultValue(null)]
- public int? OrganizationID
- {
- get
- {
- return _organizationID;
- }
- set
- {
- this._organizationID = null;
- this._organizationCode = string.Empty;
- this._organizationName = string.Empty;
- this.Text = string.Empty;
- if (value != null)
- {
- // 当数据源为null时,查询数据源
- if (DataSource == null)
- {
- // 查询数据源
- DataSource = SystemModuleProxy.Service.GetOrganizationData(1, _isOnlyDisplayEnd ? 1 : 0);
- // 过滤数据
- SetFilter(DataSource);
- }
- if (value != null && value != 0 && this.DataSource != null)
- {
- DataTable organizationTable = this.DataSource.Copy();
- DataRow[] dataRows = organizationTable.Select("OrganizationID = " + value);
- if (dataRows.Length == 1)
- {
- this._organizationID = value;
- this._organizationCode = dataRows[0]["OrganizationCode"] as string;
- this._organizationName = dataRows[0]["OrganizationName"] as string;
- this.Text = dataRows[0]["OrganizationName"] as string;
- }
- }
- }
- }
- }
- /// <summary>
- /// 获取或者设定控件的组织机构id集
- /// </summary>
- [Description("获取或者设定控件的组织机构id集。")]
- public string OrganizationIDS
- {
- get
- {
- return _organizationIDS;
- }
- set
- {
- _organizationIDS = value;
- }
- }
- /// <summary>
- /// 获取或者设定控件的组织机构Code
- /// </summary>
- [Description("获取或者设定控件的组织机构Code。")]
- public string OrganizationCode
- {
- get
- {
- return _organizationCode;
- }
- set
- {
- _organizationCode = value;
- }
- }
- /// <summary>
- /// 获取或者设定控件的当前用户组织机构Code
- /// </summary>
- [Description("获取或者设定控件的当前用户组织机构Code。")]
- public string CurrentUserOrganizationCode
- {
- get
- {
- return _currentuserorganizationCode;
- }
- set
- {
- _currentuserorganizationCode = value;
- }
- }
- /// <summary>
- /// 获取或者设定控件的组织机构名称
- /// </summary>
- [Description("获取或者设定控件的组织机构名称。")]
- public string OrganizationName
- {
- get
- {
- return _organizationName;
- }
- set
- {
- _organizationName = value;
- }
- }
- /// <summary>
- /// 获取或者设定控件是否可用。
- /// </summary>
- [System.ComponentModel.DefaultValue(null)]
- [Description("获取或者设定控件是否可用。")]
- public new bool Enabled
- {
- get
- {
- return _isEnabled;
- }
- set
- {
- _isEnabled = value;
- this.txtOrganization.Enabled = _isEnabled;
- //this.btnSearch.Enabled = _isEnabled;
- this.TabStop = _isEnabled;
- }
- }
- /// <summary>
- /// 获取或者设定控件是否只读。
- /// </summary>
- [System.ComponentModel.DefaultValue(null)]
- [Description("获取或者设定控件是否只读。")]
- public bool ReadOnly
- {
- set
- {
- this.txtOrganization.ReadOnly = value;
- }
- }
- /// <summary>
- /// 范围权限
- /// </summary>
- public byte PurviewType
- {
- get;
- set;
- }
- /// <summary>
- /// 控件是否是核算部门。
- /// </summary>
- [System.ComponentModel.DefaultValue(false)]
- [Description("控件是否是核算部门。")]
- public bool IsAccountOrganization
- {
- get;
- set;
- }
- /// <summary>
- /// 控件部门操作权限。
- /// </summary>
- [System.ComponentModel.DefaultValue(false)]
- [Description("控件部门操作权限。")]
- public bool PurviewOperateFlag
- {
- get;
- set;
- }
- /// <summary>
- /// 控件部门查看权限。
- /// </summary>
- [System.ComponentModel.DefaultValue(false)]
- [Description("控件部门查看权限。")]
- public bool PurviewViewFlag
- {
- get;
- set;
- }
- /// <summary>
- /// 多选。
- /// </summary>
- [System.ComponentModel.DefaultValue(false)]
- [Description("多选。")]
- public bool SelectMore
- {
- get;
- set;
- }
- #endregion
- #region 定义委托事件
- public delegate void TextBoxChangedHandle(object sender, TextChangeEventArgs e);
- public event TextBoxChangedHandle OrganizationValueChanged;
- #endregion
- #region 控件事件
- [Description("控件光标点击按钮事件。")]
- public new event EventHandler Click
- {
- add
- {
- this.btnSearch.Click += value;
- }
- remove
- {
- this.btnSearch.Click -= value;
- }
- }
- /// <summary>
- /// 控件尺寸大小改变事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void dkOrganizationSearchBox_SizeChanged(object sender, System.EventArgs e)
- {
- AdjustControl();
- }
- /// <summary>
- /// 查询按钮按下事件
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnSearch_Click(object sender, System.EventArgs e)
- {
- // 如果属性是不可用,是不能进行点击事件的
- if (!Enabled)
- {
- return;
- }
- // 当数据源为null时,查询数据源
- if (DataSource == null)
- {
- // 查询数据源
- DataSource = SystemModuleProxy.Service.GetOrganizationData(1, _isOnlyDisplayEnd ? 1 : 0);
- }
- // 释放窗体资源
- if (null != _frmOrganization)
- {
- _frmOrganization.Dispose();
- _frmOrganization = null;
- }
- // 打开查询窗体
- //判断是否多选
- if (this.SelectMore)
- {
- _frmOrganization = new S_CMN_001(1);
- }
- else
- {
- _frmOrganization = new S_CMN_001(this.txtOrganization.Text);
- }
- DataTable organizationTable = this.DataSource.Copy();
- if (CurrentUserOrganizationCode == string.Empty)
- _frmOrganization.DataSource = this.DataSource;
- else
- {
- organizationTable.DefaultView.RowFilter = string.Format(" OrganizationCode LIKE '{0}%'", CurrentUserOrganizationCode);
- _frmOrganization.DataSource = organizationTable.DefaultView.ToTable();
- }
- DialogResult dialogResult = _frmOrganization.ShowDialog();
- // 查询窗体返回值给控件赋值
- if (dialogResult.Equals(DialogResult.OK))
- {
- if (this.SelectMore)
- {
- _organizationCode = string.Empty;
- _organizationName = string.Empty;
- _organizationIDS = string.Empty;
- if (_frmOrganization.OrganizationRow != null || _frmOrganization.dataDT.Rows.Count > 0)
- {
- for (int i = 0; i < _frmOrganization.dataDT.Rows.Count; i++)
- {
- if (_frmOrganization.dataDT.Rows[i]["sel"].ToString().Equals("1"))
- {
- if (string.IsNullOrEmpty(_organizationCode))
- {
- _organizationCode = _frmOrganization.dataDT.Rows[i]["OrganizationCode"].ToString();
- _organizationName = _frmOrganization.dataDT.Rows[i]["OrganizationName"].ToString();
- _organizationIDS = _frmOrganization.dataDT.Rows[i]["OrganizationID"].ToString();
- }
- else
- {
- _organizationCode += "," + _frmOrganization.dataDT.Rows[i]["OrganizationCode"].ToString();
- _organizationName += "," + _frmOrganization.dataDT.Rows[i]["OrganizationName"].ToString();
- _organizationIDS += "," + _frmOrganization.dataDT.Rows[i]["OrganizationID"].ToString();
- }
- }
- }
- this.Text = _organizationName;
- }
- }
- else
- {
- if (_frmOrganization.OrganizationRow != null)
- {
- _organizationID = Convert.ToInt32(_frmOrganization.OrganizationRow["OrganizationID"]);
- _organizationCode = _frmOrganization.OrganizationRow["OrganizationCode"].ToString();
- _organizationName = _frmOrganization.OrganizationRow["OrganizationName"].ToString();
- //this.Text = _frmOrganization.OrganizationRow["OrganizationName"].ToString();
- this.Text = _frmOrganization.OrganizationRow["OrganizationCode"].ToString() + "→"
- + _frmOrganization.OrganizationRow["OrganizationFullName"].ToString();
- }
- }
- }
- }
- /// <summary>
- /// 清除控件的值
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void txtOrganization_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Delete)
- {
- ClearControl();
- }
- }
- private void txtOrganization_TextChanged(object sender, EventArgs e)
- {
- if (OrganizationValueChanged != null)
- {
- OrganizationValueChanged(this, new TextChangeEventArgs(this.txtOrganization.Text));
- }
- }
- public class TextChangeEventArgs : EventArgs
- {
- public TextChangeEventArgs(string message)
- {
- }
- }
- #endregion
- #region 私有方法/函数
- /// <summary>
- /// 初始化控件界面控件内容
- /// </summary>
- private void InitializeComponent()
- {
- this.lblOrganization = new System.Windows.Forms.Label();
- this.txtOrganization = new System.Windows.Forms.TextBox();
- this.btnSearch = new System.Windows.Forms.Button();
- this.SuspendLayout();
- //
- // lblOrganization
- //
- this.lblOrganization.AutoSize = true;
- this.lblOrganization.BackColor = System.Drawing.Color.Transparent;
- //this.lblOrganization.Image = global::Dongke.IBOSS.Framework.Controls.Properties.Resources.bg;
- this.lblOrganization.Location = new System.Drawing.Point(3, 4);
- this.lblOrganization.Name = "lblOrganization";
- this.lblOrganization.Size = new System.Drawing.Size(53, 12);
- this.lblOrganization.TabIndex = 0;
- this.lblOrganization.Text = "组织机构";
- //
- // txtOrganization
- //
- this.txtOrganization.Font = new System.Drawing.Font("宋体", 9F);
- this.txtOrganization.Location = new System.Drawing.Point(62, 0);
- this.txtOrganization.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
- this.txtOrganization.Name = "txtOrganization";
- this.txtOrganization.ReadOnly = true;
- this.txtOrganization.Size = new System.Drawing.Size(155, 21);
- this.txtOrganization.TabIndex = 1;
- this.txtOrganization.TextChanged += new System.EventHandler(this.txtOrganization_TextChanged);
- this.txtOrganization.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtOrganization_KeyDown);
- //
- // btnSearch
- //
- this.btnSearch.Image = global::Dongke.IBOSS.PRD.Client.Controls.Properties.Resources.searchButton;
- this.btnSearch.Location = new System.Drawing.Point(223, 0);
- this.btnSearch.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
- this.btnSearch.Name = "btnSearch";
- this.btnSearch.Size = new System.Drawing.Size(21, 21);
- this.btnSearch.TabIndex = 2;
- this.btnSearch.UseVisualStyleBackColor = true;
- this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
- //
- // dkOrganizationSearchBox
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.BackColor = System.Drawing.Color.Transparent;
- this.Controls.Add(this.btnSearch);
- this.Controls.Add(this.txtOrganization);
- this.Controls.Add(this.lblOrganization);
- this.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
- this.Name = "dkOrganizationSearchBox";
- this.Size = new System.Drawing.Size(245, 21);
- this.SizeChanged += new System.EventHandler(this.dkOrganizationSearchBox_SizeChanged);
- this.ResumeLayout(false);
- this.PerformLayout();
- }
- /// <summary>
- /// 根据控件的尺寸变化,改变控件内部控件的尺寸大小
- /// </summary>
- protected void AdjustControl()
- {
- // 取得按钮控件的宽度和高度
- int buttonWidth = (this.btnSearch.Visible) ? this.btnSearch.Width : 0;
- this.Height = this.btnSearch.Height;
- // 设置控件的尺寸和位置。
- this.txtOrganization.Location = new System.Drawing.Point(this.lblOrganization.Width +
- ControlsConst.CONTROLSPACE, (this.Height - this.txtOrganization.Height) / 2);
- this.txtOrganization.Size = new System.Drawing.Size(this.Width - this.btnSearch.Width -
- (this.lblOrganization.Width + ControlsConst.CONTROLSPACE * 2), this.Height);
- this.btnSearch.Location =
- new System.Drawing.Point(this.Width - this.btnSearch.Width,
- (this.Height - this.btnSearch.Height) / 2);
- // 设置标签的尺寸和位置。
- this.lblOrganization.Location =
- new System.Drawing.Point(0, (this.Height - this.lblOrganization.Height) / 2);
- this.lblOrganization.Size = new System.Drawing.Size(this.lblOrganization.Width, this.lblOrganization.Height);
- }
- /// <summary>
- /// 清空控件的值
- /// </summary>
- /// <param name="dataSource"></param>
- /// <returns></returns>
- public void ClearControl()
- {
- this.txtOrganization.Text = "";
- this._organizationID = null;
- this._organizationCode = string.Empty;
- this._organizationName = string.Empty;
- this._organizationIDS = string.Empty;
- }
- /// <summary>
- /// 过滤数据源
- /// </summary>
- /// <param name="dataSource"></param>
- /// <returns></returns>
- protected DataTable SetFilter(DataTable dataSource)
- {
- if (dataSource is DataTable)
- {
- #region 过滤部门操作权限
- if (PurviewOperateFlag)
- {
- if (LogInUserInfo.CurrentUser.CurrentUserEntity.UserRangeRightData != null)
- {
- string rowFilter = "0";
- foreach (DataRow row in LogInUserInfo.CurrentUser.CurrentUserEntity.UserRangeRightData.Rows)
- {
- // 操作部门类型
- if (int.Parse(row["PurviewType"].ToString()) == Constant.PurviewType.OperateOrganization.GetHashCode())
- {
- if ("-1" == row["PurviewID"].ToString())
- {
- rowFilter = "";
- break;
- }
- rowFilter += "," + row["PurviewID"].ToString();
- }
- }
- if (rowFilter != "")
- {
- dataSource.DefaultView.RowFilter = "OrganizationID IN (" + rowFilter + ")";
- dataSource = dataSource.DefaultView.ToTable();
- }
- }
- }
- #endregion
- #region 过滤部门查看权限
- if (PurviewViewFlag)
- {
- if (LogInUserInfo.CurrentUser.CurrentUserEntity.UserRangeRightData != null)
- {
- string rowFilter = "0";
- foreach (DataRow row in LogInUserInfo.CurrentUser.CurrentUserEntity.UserRangeRightData.Rows)
- {
- // 查看部门类型
- if (int.Parse(row["PurviewType"].ToString()) == Constant.PurviewType.ViewOrganization.GetHashCode())
- {
- if ("-1" == row["PurviewID"].ToString())
- {
- rowFilter = "";
- break;
- }
- rowFilter += "," + row["PurviewID"].ToString();
- }
- }
- if (rowFilter != "")
- {
- dataSource.DefaultView.RowFilter = "OrganizationID IN (" + rowFilter + ")";
- dataSource = dataSource.DefaultView.ToTable();
- }
- }
- }
- #endregion
- }
- return dataSource;
- }
- #endregion
- }
- }
|