S_CMN_001.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. /*******************************************************************************
  2. * Copyright(c) 2012 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:S_CMN_001.cs
  5. * 2.功能描述:组织机构控件查询界面
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 陈冰 2014/08/30 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.ComponentModel;
  12. using System.Data;
  13. using System.Text;
  14. using System.Windows.Forms;
  15. using Dongke.IBOSS.PRD.Basics.BaseControls;
  16. using Dongke.IBOSS.PRD.Basics.BaseResources;
  17. using Dongke.IBOSS.PRD.Basics.Library;
  18. using Dongke.IBOSS.PRD.Client.CommonModule;
  19. namespace Dongke.IBOSS.PRD.Client.Controls
  20. {
  21. /// <summary>
  22. /// 组织机构控件查询界面
  23. /// </summary>
  24. public partial class S_CMN_001 : FormBase
  25. {
  26. #region 成员变量
  27. private DataTable _dataSource; // 画面的数据源
  28. private DataRow _organizationRow; // 返回组织机构的DataRow
  29. private DataTable _dataDT; //返回选择数据源
  30. #endregion
  31. #region 构造函数
  32. /// <summary>
  33. /// 构造函数
  34. /// </summary>
  35. public S_CMN_001()
  36. : this("")
  37. {
  38. }
  39. /// <summary>
  40. /// 重载的构造函数
  41. /// </summary>
  42. /// <param name="organizationName">组织结构名称</param>
  43. public S_CMN_001(string organizationName)
  44. {
  45. InitializeComponent();
  46. this.txtOrganizationName.Text = organizationName;
  47. // 按钮
  48. this.btnSearch.Text = ButtonText.BTN_SEARCH;
  49. this.btnOK.Text = ButtonText.BTN_OK;
  50. this.btnClose.Text = ButtonText.BTN_CANCEL;
  51. this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
  52. }
  53. /// <summary>
  54. /// 重载的构造函数
  55. /// </summary>
  56. /// <param name="organizationName">组织结构名称</param>
  57. public S_CMN_001(int flag)
  58. {
  59. InitializeComponent();
  60. if (flag == 1)
  61. {
  62. this.sel.Visible = true;
  63. }
  64. else
  65. {
  66. this.sel.Visible = false;
  67. }
  68. // 按钮
  69. this.btnSearch.Text = ButtonText.BTN_SEARCH;
  70. this.btnOK.Text = ButtonText.BTN_OK;
  71. this.btnClose.Text = ButtonText.BTN_CLOSE;
  72. this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
  73. }
  74. /// <summary>
  75. /// 重载的构造函数
  76. /// </summary>
  77. /// <param name="organizationName">组织结构名称</param>
  78. public S_CMN_001(int flag, string organizationName)
  79. {
  80. InitializeComponent();
  81. if (flag == 1)
  82. {
  83. this.sel.Visible = true;
  84. }
  85. else
  86. {
  87. this.sel.Visible = false;
  88. }
  89. this.txtOrganizationName.Text = organizationName;
  90. // 按钮
  91. this.btnSearch.Text = ButtonText.BTN_SEARCH;
  92. this.btnOK.Text = ButtonText.BTN_OK;
  93. this.btnClose.Text = ButtonText.BTN_CLOSE;
  94. this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
  95. }
  96. #endregion
  97. #region 属性
  98. /// <summary>
  99. /// 获取或者设定画面的数据源。
  100. /// </summary>
  101. [Description("获取或者设定画面的数据源。")]
  102. public new DataTable DataSource
  103. {
  104. get
  105. {
  106. return _dataSource;
  107. }
  108. set
  109. {
  110. _dataSource = value;
  111. }
  112. }
  113. /// <summary>
  114. /// 返回选择的组织行
  115. /// </summary>
  116. public DataRow OrganizationRow
  117. {
  118. get
  119. {
  120. return _organizationRow;
  121. }
  122. set
  123. {
  124. _organizationRow = value;
  125. }
  126. }
  127. /// <summary>
  128. /// 返回选择的组织多行
  129. /// </summary>
  130. public DataTable dataDT
  131. {
  132. get
  133. {
  134. return _dataDT;
  135. }
  136. set
  137. {
  138. _dataDT = value;
  139. }
  140. }
  141. #endregion
  142. #region 控件事件
  143. /// <summary>
  144. /// 窗体加载
  145. /// </summary>
  146. /// <param name="sender"></param>
  147. /// <param name="e"></param>
  148. private void S_CMN_003_Load(object sender, EventArgs e)
  149. {
  150. try
  151. {
  152. this.dgvOrganization.AutoGenerateColumns = false;
  153. if (!string.IsNullOrEmpty(this.txtOrganizationName.Text))
  154. {
  155. string[] subOrganization = this.txtOrganizationName.Text.Trim().Split('→');
  156. this.txtOrganizationCode.Text = subOrganization[0];
  157. this.txtOrganizationName.Text = subOrganization[subOrganization.Length - 1];
  158. Search();
  159. }
  160. }
  161. catch (Exception ex)
  162. {
  163. // 对异常进行共通处理
  164. ExceptionManager.HandleEventException(this.ToString(),
  165. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  166. }
  167. }
  168. /// <summary>
  169. /// 查询按钮按下事件
  170. /// </summary>
  171. /// <param name="sender"></param>
  172. /// <param name="e"></param>
  173. private void btnSearch_Click(object sender, System.EventArgs e)
  174. {
  175. try
  176. {
  177. Search();
  178. }
  179. catch (Exception ex)
  180. {
  181. // 对异常进行共通处理
  182. ExceptionManager.HandleEventException(this.ToString(),
  183. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  184. }
  185. }
  186. /// <summary>
  187. /// KeyDown事件
  188. /// </summary>
  189. /// <param name="sender"></param>
  190. /// <param name="e"></param>
  191. private void dgvOrganization_KeyDown(object sender, KeyEventArgs e)
  192. {
  193. try
  194. {
  195. // 拷贝单元格文本到剪切板
  196. if (e.KeyData == (Keys.Control | Keys.C))
  197. {
  198. if (dgvOrganization.CurrentRow != null
  199. && !string.IsNullOrEmpty(dgvOrganization.CurrentRow.Cells[dgvOrganization.CurrentCell.ColumnIndex].EditedFormattedValue + ""))
  200. {
  201. Clipboard.SetText(dgvOrganization.CurrentRow.Cells[dgvOrganization.CurrentCell.ColumnIndex].EditedFormattedValue + "");
  202. }
  203. }
  204. else if (e.KeyData == Keys.Enter)
  205. {
  206. Commit();
  207. }
  208. }
  209. catch (Exception ex)
  210. {
  211. // 对异常进行共通处理
  212. ExceptionManager.HandleEventException(this.ToString(),
  213. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  214. }
  215. }
  216. /// <summary>
  217. /// 确定按钮按下事件
  218. /// </summary>
  219. /// <param name="sender"></param>
  220. /// <param name="e"></param>
  221. private void btnOK_Click(object sender, System.EventArgs e)
  222. {
  223. try
  224. {
  225. Commit();
  226. }
  227. catch (Exception ex)
  228. {
  229. // 对异常进行共通处理
  230. ExceptionManager.HandleEventException(this.ToString(),
  231. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  232. }
  233. }
  234. /// <summary>
  235. /// 关闭按钮按下事件
  236. /// </summary>
  237. /// <param name="sender"></param>
  238. /// <param name="e"></param>
  239. private void btnClose_Click(object sender, System.EventArgs e)
  240. {
  241. this.DialogResult = DialogResult.Cancel;
  242. this.Close();
  243. }
  244. /// <summary>
  245. /// 双击DataGridView窗体,返回选中记录
  246. /// </summary>
  247. /// <param name="sender"></param>
  248. /// <param name="e"></param>
  249. private void dgvOrganization_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
  250. {
  251. try
  252. {
  253. // 判断是否是双击列头,如果是双击列头的话,不做任何操作
  254. if (-1 < e.RowIndex && -1 < e.ColumnIndex)
  255. {
  256. //判断有没有复选框,如果有不做任何操作
  257. if (!this.sel.Visible)
  258. {
  259. Commit();
  260. }
  261. }
  262. }
  263. catch (Exception ex)
  264. {
  265. // 对异常进行共通处理
  266. ExceptionManager.HandleEventException(this.ToString(),
  267. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  268. }
  269. }
  270. #endregion
  271. #region 私有方法/函数
  272. /// <summary>
  273. /// 查询方法
  274. /// </summary>
  275. private void Search()
  276. {
  277. // 清空之前的查询结果
  278. this.dgvOrganization.DataSource = null;
  279. // 根据查询条件查询数据源中的数据,并显示
  280. DataTable organizationTable = this.DataSource.Copy();
  281. organizationTable.DefaultView.RowFilter = GetFilterExpression();
  282. this.dgvOrganization.DataSource = organizationTable.DefaultView.ToTable();
  283. this.dgvOrganization.Focus();
  284. // 当没有查询结果时,提示无查询结构消息
  285. if (this.dgvOrganization.RowCount <= 0)
  286. {
  287. MessageBox.Show(ControlsTips.DK_SearchBox_NoResult,
  288. this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
  289. this.txtOrganizationCode.Focus();
  290. this.btnOK.Enabled = false;
  291. return;
  292. }
  293. this.btnOK.Enabled = true;
  294. }
  295. /// <summary>
  296. /// 提交时给取得的行赋值
  297. /// </summary>
  298. private void Commit()
  299. {
  300. if (this.sel.Visible)
  301. {
  302. if (this.dgvOrganization.CurrentCell != null)
  303. {
  304. this.dataDT = (DataTable)this.dgvOrganization.DataSource;
  305. this.DialogResult = DialogResult.OK;
  306. }
  307. }
  308. else
  309. {
  310. if (this.dgvOrganization.CurrentCell != null)
  311. {
  312. OrganizationRow = this.dgvOrganization.GetDataRow(this.dgvOrganization.CurrentCell.RowIndex);
  313. this.DialogResult = DialogResult.OK;
  314. this.Close();
  315. }
  316. }
  317. }
  318. /// <summary>
  319. /// 根据画面输入内容拼接过滤条件
  320. /// </summary>
  321. /// <returns></returns>
  322. private string GetFilterExpression()
  323. {
  324. StringBuilder strbFilterExpressions = new StringBuilder();
  325. strbFilterExpressions.Append("(1=1");
  326. if (!string.IsNullOrEmpty(this.txtOrganizationCode.Text))
  327. {
  328. // 组织机构编码条件
  329. strbFilterExpressions.Append(string.Format(" AND OrganizationCode LIKE '%{0}%'",
  330. Utility.SelectFilterLike(this.txtOrganizationCode.Text.Trim())));
  331. }
  332. if (!string.IsNullOrEmpty(this.txtOrganizationName.Text))
  333. {
  334. // 组织机构名称条件
  335. strbFilterExpressions.Append(string.Format(" AND OrganizationName LIKE '%{0}%'",
  336. Utility.SelectFilterLike(this.txtOrganizationName.Text.Trim())));
  337. }
  338. strbFilterExpressions.Append(")");
  339. return strbFilterExpressions.ToString();
  340. }
  341. #endregion
  342. private void btnClearCondition_Click(object sender, EventArgs e)
  343. {
  344. this.txtOrganizationCode.Clear();
  345. this.txtOrganizationName.Clear();
  346. }
  347. }
  348. }