S_CMN_023.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. /*******************************************************************************
  2. * Copyright(c) 2012 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:S_CMN_023.cs
  5. * 2.功能描述:窑炉信息控件查询界面
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 王鑫 2015/09/10 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. public partial class S_CMN_023 : FormBase
  23. {
  24. #region 成员变量
  25. // 单例模式
  26. private static S_CMN_023 _instance;
  27. // 最后选择行
  28. private int _selecedRow;
  29. #endregion
  30. #region 属性
  31. /// <summary>
  32. /// 选择的数据
  33. /// </summary>
  34. public DataTable SelTable { get; set; }
  35. /// <summary>
  36. /// 传入的窑炉编码
  37. /// </summary>
  38. public string SetKilnCode { get; set; }
  39. #endregion
  40. #region 单例模式
  41. /// <summary>
  42. /// 单例模式,防止重复创建窗体
  43. /// </summary>
  44. public static S_CMN_023 Instance
  45. {
  46. get
  47. {
  48. if (_instance == null)
  49. {
  50. _instance = new S_CMN_023();
  51. }
  52. return _instance;
  53. }
  54. }
  55. #endregion
  56. #region 构造函数
  57. public S_CMN_023()
  58. {
  59. InitializeComponent();
  60. this.Text ="窑炉选择";
  61. this.btnSearch.Text = ButtonText.BTN_SEARCH;
  62. //this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
  63. this.btnOK.Text = ButtonText.BTN_OK;
  64. this.btnClose.Text = ButtonText.BTN_CANCEL;
  65. this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
  66. }
  67. #endregion
  68. #region 事件
  69. /// <summary>
  70. /// 窗体加载事件
  71. /// </summary>
  72. /// <param name="sender"></param>
  73. /// <param name="e"></param>
  74. private void FrmUser_Load(object sender, EventArgs e)
  75. {
  76. try
  77. {
  78. // 设置表格不自动创建列
  79. this.dgvKiln.AutoGenerateColumns = false;
  80. this.dgvKiln.Columns["Sel"].ReadOnly = false;
  81. this.txtKilnCode.Text = this.SetKilnCode;
  82. this.btnSearch_Click(null, null);
  83. }
  84. catch (Exception ex)
  85. {
  86. // 对异常进行共通处理
  87. ExceptionManager.HandleEventException(this.ToString(),
  88. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  89. }
  90. }
  91. /// <summary>
  92. /// 释放成员变量
  93. /// </summary>
  94. /// <param name="sender"></param>
  95. /// <param name="e"></param>
  96. private void FrmOrganization_FormClosed(object sender, FormClosedEventArgs e)
  97. {
  98. _instance = null;
  99. }
  100. /// <summary>
  101. /// 搜索按钮事件
  102. /// </summary>
  103. /// <param name="sender"></param>
  104. /// <param name="e"></param>
  105. private void btnSearch_Click(object sender, EventArgs e)
  106. {
  107. try
  108. {
  109. // 根据页面设定用户实体值
  110. //this.GetUserEntityFromLayout();
  111. // 记录当前选中行
  112. int selectRowIndex = this._selecedRow;
  113. // 异步处理
  114. this.btnSearch.Enabled = false;
  115. //this.btnClearCondition.Enabled = false;
  116. DataSet userDataSet = (DataSet)DoAsync(new BaseAsyncMethod(this.SearchKilnData));
  117. this.btnSearch.Enabled = true;
  118. if (userDataSet != null)
  119. {
  120. string sql = null;
  121. if (!string.IsNullOrWhiteSpace(this.txtKilnCode.Text))
  122. {
  123. sql = " kilncode like '%" + this.txtKilnCode.Text.Trim() + "%' ";
  124. }
  125. if (!string.IsNullOrWhiteSpace(this.txtKilnName.Text))
  126. {
  127. if (sql != null)
  128. {
  129. sql += " and ";
  130. }
  131. sql += " kilnname like '%" + this.txtKilnName.Text.Trim() + "%' ";
  132. }
  133. userDataSet.Tables[0].DefaultView.RowFilter = sql;
  134. base.DataSource = (DataSet)userDataSet;
  135. if (this.DataSource != null && this.DataSource.Tables.Count > Constant.INT_IS_ZERO)
  136. {
  137. this.dgvKiln.DataSource = this.DataSource.Tables[0];
  138. if (this.DataSource.Tables[0].DefaultView.Count <= Constant.INT_IS_ZERO)
  139. {
  140. // 提示未查找到数据
  141. MessageBox.Show(Messages.MSG_CMN_I002, this.Text,
  142. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  143. }
  144. else
  145. {
  146. //if (selectRowIndex >= Constant.INT_IS_ZERO)
  147. //{
  148. // if (selectRowIndex >= userDataSet.Tables[0].Rows.Count)
  149. // {
  150. // this.dgvKiln.Rows[this.dgvKiln.Rows.Count - 1].Selected = true;
  151. // this.dgvKiln.CurrentCell = this.dgvKiln.Rows[this.dgvKiln.Rows.Count - 1].Cells["kilnCode"];
  152. // }
  153. // else
  154. // {
  155. // this.dgvKiln.Rows[selectRowIndex].Selected = true;
  156. // this.dgvKiln.CurrentCell = this.dgvKiln.Rows[selectRowIndex].Cells["kilnCode"];
  157. // }
  158. //}
  159. }
  160. }
  161. }
  162. this.dgvKiln.IsSetInputColumnsColor = true;
  163. }
  164. catch (Exception ex)
  165. {
  166. this.btnSearch.Enabled = true;
  167. // 对异常进行共通处理
  168. ExceptionManager.HandleEventException(this.ToString(),
  169. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  170. }
  171. }
  172. /// <summary>
  173. /// 选中行发生改变时 有效停用相互切换
  174. /// </summary>
  175. /// <param name="sender"></param>
  176. /// <param name="e"></param>
  177. private void dgvUser_CellEnter(object sender, DataGridViewCellEventArgs e)
  178. {
  179. if (dgvKiln.Rows.Count > Constant.INT_IS_ZERO)
  180. {
  181. this._selecedRow = this.dgvKiln.CurrentCell.RowIndex;
  182. }
  183. }
  184. /// <summary>
  185. /// 窗体关闭事件
  186. /// </summary>
  187. /// <param name="sender"></param>
  188. /// <param name="e"></param>
  189. private void F_MST_0203_FormClosed(object sender, FormClosedEventArgs e)
  190. {
  191. _instance = null;
  192. }
  193. /// <summary>
  194. /// 自动适应列宽事件
  195. /// </summary>
  196. /// <param name="sender"></param>
  197. /// <param name="e"></param>
  198. private void tsbtnAdaptive_Click(object sender, EventArgs e)
  199. {
  200. this.dgvKiln.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
  201. }
  202. /// <summary>
  203. /// 全选
  204. /// </summary>
  205. /// <param name="sender"></param>
  206. /// <param name="e"></param>
  207. private void chkChooseAll_CheckedChanged(object sender, EventArgs e)
  208. {
  209. try
  210. {
  211. for (int i = 0; i < this.dgvKiln.Rows.Count; i++)
  212. {
  213. this.dgvKiln.Rows[i].Cells["Sel"].Value = this.chkChooseAll.Checked;
  214. }
  215. }
  216. catch (Exception ex)
  217. {
  218. // 对异常进行共通处理
  219. ExceptionManager.HandleEventException(this.ToString(),
  220. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  221. }
  222. }
  223. /// <summary>
  224. /// 确定
  225. /// </summary>
  226. /// <param name="sender"></param>
  227. /// <param name="e"></param>
  228. private void btnOK_Click(object sender, EventArgs e)
  229. {
  230. try
  231. {
  232. this.Commit();
  233. }
  234. catch (Exception ex)
  235. {
  236. // 对异常进行共通处理
  237. ExceptionManager.HandleEventException(this.ToString(),
  238. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  239. }
  240. }
  241. /// <summary>
  242. /// 关闭窗体
  243. /// </summary>
  244. /// <param name="sender"></param>
  245. /// <param name="e"></param>
  246. private void btnClose_Click(object sender, EventArgs e)
  247. {
  248. this.Close();
  249. }
  250. #endregion
  251. #region 私有方法
  252. /// <summary>
  253. /// 点击确定或者回车键时调用
  254. /// </summary>
  255. private void Commit()
  256. {
  257. try
  258. {
  259. DataTable invDt = (DataTable)this.dgvKiln.DataSource;
  260. if (invDt == null || invDt.Rows.Count == Constant.INT_IS_ZERO)
  261. {
  262. MessageBox.Show(string.Format(Messages.MSG_CMN_W007,
  263. "没有选择数据"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  264. return;
  265. }
  266. invDt.AcceptChanges();
  267. invDt = invDt.Copy();
  268. string filter = "Sel = 1";
  269. invDt.DefaultView.RowFilter = filter;
  270. invDt = invDt.DefaultView.ToTable();
  271. // 如果选中了数据就关闭窗体,反之则不关
  272. if (invDt.Rows.Count > Constant.INT_IS_ZERO)
  273. {
  274. SelTable = invDt;
  275. this.DialogResult = DialogResult.OK;
  276. this.Close();
  277. }
  278. else
  279. {
  280. MessageBox.Show(string.Format(Messages.MSG_CMN_W007,
  281. "没有选择数据"),this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
  282. }
  283. }
  284. catch (Exception ex)
  285. {
  286. throw ex;
  287. }
  288. }
  289. /// <summary>
  290. /// 获取窑炉列表
  291. /// </summary>
  292. /// <returns></returns>
  293. private DataSet SearchKilnData()
  294. {
  295. try
  296. {
  297. return SystemModuleProxy.Service.GetKilnData(1);
  298. }
  299. catch (Exception ex)
  300. {
  301. throw ex;
  302. }
  303. }
  304. #endregion
  305. private void btnClearCondition_Click(object sender, EventArgs e)
  306. {
  307. this.txtKilnCode.Clear();
  308. this.txtKilnName.Clear();
  309. }
  310. }
  311. }