F_SAP_HEGII_0110.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. using Dongke.IBOSS.PRD.Basics.BaseControls;
  2. using Dongke.IBOSS.PRD.Basics.BaseResources;
  3. using Dongke.IBOSS.PRD.Client.CommonModule;
  4. using Dongke.IBOSS.PRD.Client.Controls;
  5. using Dongke.IBOSS.PRD.WCF.DataModels;
  6. using Dongke.IBOSS.PRD.WCF.Proxys;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.ComponentModel;
  10. using System.Data;
  11. using System.Drawing;
  12. using System.Linq;
  13. using System.Reflection;
  14. using System.Text;
  15. using System.Windows.Forms;
  16. namespace Dongke.IBOSS.PRD.Client.SAPDataModule.Hegii
  17. {
  18. public partial class F_SAP_HEGII_0110 : DKDockPanelBase
  19. {
  20. #region 成员变量
  21. private static F_SAP_HEGII_0110 _instance = null;
  22. private static DataTable _CostCenterDt = null;
  23. #endregion
  24. #region 单例模式
  25. /// <summary>
  26. /// 单例模式,防止重复创建窗体
  27. /// </summary>
  28. public static F_SAP_HEGII_0110 Instance
  29. {
  30. get
  31. {
  32. if (_instance == null)
  33. {
  34. _instance = new F_SAP_HEGII_0110();
  35. }
  36. return _instance;
  37. }
  38. }
  39. #endregion
  40. #region 构造函数
  41. public F_SAP_HEGII_0110()
  42. {
  43. InitializeComponent();
  44. }
  45. public F_SAP_HEGII_0110(DataTable dt)
  46. {
  47. InitializeComponent();
  48. this.Text = "BPM成本中心设置 ";
  49. this.tsbtnAdaptive.Text = ButtonText.TSBTN_ADAPTIVE;
  50. _CostCenterDt = dt;
  51. this.dgvCenter.AutoGenerateColumns = false;
  52. }
  53. #endregion
  54. #region 事件
  55. /// <summary>
  56. /// 查询事件
  57. /// </summary>
  58. /// <param name="sender"></param>
  59. /// <param name="e"></param>
  60. private void tsbtnSearch_Click(object sender, EventArgs e)
  61. {
  62. try
  63. {
  64. this.QueryDataFromOther();
  65. this.tsbtnAdaptive_Click(null, null) ;
  66. }
  67. catch (Exception ex )
  68. {
  69. // 对异常进行共通处理
  70. ExceptionManager.HandleEventException(this.ToString(),
  71. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  72. }
  73. }
  74. /// <summary>
  75. /// 保存成本中心
  76. /// </summary>
  77. /// <param name="sender"></param>
  78. /// <param name="e"></param>
  79. private void btnSave_Click(object sender, EventArgs e)
  80. {
  81. try
  82. {
  83. tsrToolStrip1.Focus();
  84. DataTable data = (DataTable)this.dgvCenter.DataSource;
  85. if (data == null || data.Rows.Count == 0)
  86. {
  87. return;
  88. }
  89. DataTable datacp = data.Copy();
  90. datacp.DefaultView.RowFilter = "check1 =1 ";
  91. DataTable checkedDt = datacp.DefaultView.ToTable();
  92. if (checkedDt.Rows.Count == 0)
  93. {
  94. DKMessageBox.ShowDialog(this, DKMessageCode.W_CMN_S_004, "未选择任何数据");
  95. return;
  96. }
  97. else if (checkedDt.Rows.Count >1)
  98. {
  99. DKMessageBox.ShowDialog(this, DKMessageCode.W_CMN_S_004, "请选择一条数据");
  100. return;
  101. }
  102. DialogResult dr = MessageBox.Show("是否对所选数据进行保存?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  103. if (dr != System.Windows.Forms.DialogResult.Yes)
  104. {
  105. return;
  106. }
  107. // 调用服务器端获取数据集
  108. ClientRequestEntity cre = new ClientRequestEntity();
  109. cre.NameSpace = "Hegii";
  110. cre.Name = "SaveCostCenter";
  111. cre.Properties["CostCenter"] = checkedDt.Rows[0]["COSTCENTER"];
  112. cre.Properties["CostCenterName"] = checkedDt.Rows[0]["COSTCENTERNAME"];
  113. DataTable costdt = _CostCenterDt.Copy();
  114. DataSet ds = new DataSet();
  115. ds.Tables.Add(costdt);
  116. cre.Data=ds;
  117. ServiceResultEntity sre = DoAsync<ServiceResultEntity>(() =>
  118. {
  119. return SAPDataModuleProxy.Service.DoRequest(cre);
  120. });
  121. if (sre.Status == Constant.ServiceResultStatus.Success)
  122. {
  123. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "成本中心", "保存"),
  124. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  125. this.DialogResult = DialogResult.OK;
  126. }
  127. }
  128. catch (Exception ex)
  129. {
  130. // 对异常进行共通处理
  131. ExceptionManager.HandleEventException(this.ToString(),
  132. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  133. }
  134. }
  135. /// <summary>
  136. /// 窗体关闭
  137. /// </summary>
  138. /// <param name="sender"></param>
  139. /// <param name="e"></param>
  140. private void F_SAP_HEGII_0110_FormClosed(object sender, FormClosedEventArgs e)
  141. {
  142. _instance = null;
  143. }
  144. /// <summary>
  145. /// 清空条件
  146. /// </summary>
  147. /// <param name="sender"></param>
  148. /// <param name="e"></param>
  149. private void tsbtnClearCondition_Click(object sender, EventArgs e)
  150. {
  151. this.txtCostcenter.Clear();
  152. this.txtCostcenterName.Clear();
  153. }
  154. /// <summary>
  155. /// 自适应列宽
  156. /// </summary>
  157. /// <param name="sender"></param>
  158. /// <param name="e"></param>
  159. private void tsbtnAdaptive_Click(object sender, EventArgs e)
  160. {
  161. this.dgvCenter.AutoResizeColumns();
  162. }
  163. /// <summary>
  164. /// 关闭
  165. /// </summary>
  166. /// <param name="sender"></param>
  167. /// <param name="e"></param>
  168. private void btnClose_Click(object sender, EventArgs e)
  169. {
  170. this.Close();
  171. }
  172. #endregion
  173. #region 私有方法
  174. private void QueryDataFromOther()
  175. {
  176. this.dgvCenter.DataSource = null;
  177. this.tsrToolStrip1.Focus();
  178. ClientRequestEntity cre = new ClientRequestEntity();
  179. cre.Properties["CostCenter"] = this.txtCostcenter.Text.Trim();
  180. cre.Properties["CostcenterName"] = this.txtCostcenterName.Text.Trim();
  181. cre.NameSpace = "Hegii";
  182. cre.Name = "GetCostCenter";
  183. ServiceResultEntity sre = DoAsync<ServiceResultEntity>(() =>
  184. {
  185. return SAPDataModuleProxy.Service.DoRequest(cre);
  186. });
  187. if (sre.Status == Constant.ServiceResultStatus.Success)
  188. {
  189. // 查询成功
  190. this.dgvCenter.DataSource = sre.Data.Tables[0];
  191. if (this.dgvCenter.RowCount == 0)
  192. {
  193. DKMessageBox.ShowDialog(this, DKMessageCode.I_CMN_S_001);
  194. }
  195. }
  196. }
  197. #endregion
  198. }
  199. }