S_CMN_019.cs 11 KB

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