S_CMN_005.cs 11 KB

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