S_CMN_021.cs 10 KB

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