S_CMN_027.cs 12 KB

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