using Dongke.IBOSS.PRD.Basics.BaseControls; using Dongke.IBOSS.PRD.Basics.BaseResources; using Dongke.IBOSS.PRD.Client.CommonModule; using Dongke.IBOSS.PRD.Client.Controls; using Dongke.IBOSS.PRD.WCF.DataModels; using Dongke.IBOSS.PRD.WCF.Proxys; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Reflection; using System.Text; using System.Windows.Forms; namespace Dongke.IBOSS.PRD.Client.SAPDataModule.Hegii { public partial class F_SAP_HEGII_0110 : DKDockPanelBase { #region 成员变量 private static F_SAP_HEGII_0110 _instance = null; private static DataTable _CostCenterDt = null; #endregion #region 单例模式 /// /// 单例模式,防止重复创建窗体 /// public static F_SAP_HEGII_0110 Instance { get { if (_instance == null) { _instance = new F_SAP_HEGII_0110(); } return _instance; } } #endregion #region 构造函数 public F_SAP_HEGII_0110() { InitializeComponent(); } public F_SAP_HEGII_0110(DataTable dt) { InitializeComponent(); this.Text = "BPM成本中心设置 "; this.tsbtnAdaptive.Text = ButtonText.TSBTN_ADAPTIVE; _CostCenterDt = dt; this.dgvCenter.AutoGenerateColumns = false; } #endregion #region 事件 /// /// 查询事件 /// /// /// private void tsbtnSearch_Click(object sender, EventArgs e) { try { this.QueryDataFromOther(); this.tsbtnAdaptive_Click(null, null) ; } catch (Exception ex ) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 保存成本中心 /// /// /// private void btnSave_Click(object sender, EventArgs e) { try { tsrToolStrip1.Focus(); DataTable data = (DataTable)this.dgvCenter.DataSource; if (data == null || data.Rows.Count == 0) { return; } DataTable datacp = data.Copy(); datacp.DefaultView.RowFilter = "check1 =1 "; DataTable checkedDt = datacp.DefaultView.ToTable(); if (checkedDt.Rows.Count == 0) { DKMessageBox.ShowDialog(this, DKMessageCode.W_CMN_S_004, "未选择任何数据"); return; } else if (checkedDt.Rows.Count >1) { DKMessageBox.ShowDialog(this, DKMessageCode.W_CMN_S_004, "请选择一条数据"); return; } DialogResult dr = MessageBox.Show("是否对所选数据进行保存?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr != System.Windows.Forms.DialogResult.Yes) { return; } // 调用服务器端获取数据集 ClientRequestEntity cre = new ClientRequestEntity(); cre.NameSpace = "Hegii"; cre.Name = "SaveCostCenter"; cre.Properties["CostCenter"] = checkedDt.Rows[0]["COSTCENTER"]; cre.Properties["CostCenterName"] = checkedDt.Rows[0]["COSTCENTERNAME"]; DataTable costdt = _CostCenterDt.Copy(); DataSet ds = new DataSet(); ds.Tables.Add(costdt); cre.Data=ds; ServiceResultEntity sre = DoAsync(() => { return SAPDataModuleProxy.Service.DoRequest(cre); }); if (sre.Status == Constant.ServiceResultStatus.Success) { MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "成本中心", "保存"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = DialogResult.OK; } } catch (Exception ex) { // 对异常进行共通处理 ExceptionManager.HandleEventException(this.ToString(), MethodBase.GetCurrentMethod().Name, this.Text, ex); } } /// /// 窗体关闭 /// /// /// private void F_SAP_HEGII_0110_FormClosed(object sender, FormClosedEventArgs e) { _instance = null; } /// /// 清空条件 /// /// /// private void tsbtnClearCondition_Click(object sender, EventArgs e) { this.txtCostcenter.Clear(); this.txtCostcenterName.Clear(); } /// /// 自适应列宽 /// /// /// private void tsbtnAdaptive_Click(object sender, EventArgs e) { this.dgvCenter.AutoResizeColumns(); } /// /// 关闭 /// /// /// private void btnClose_Click(object sender, EventArgs e) { this.Close(); } #endregion #region 私有方法 private void QueryDataFromOther() { this.dgvCenter.DataSource = null; this.tsrToolStrip1.Focus(); ClientRequestEntity cre = new ClientRequestEntity(); cre.Properties["CostCenter"] = this.txtCostcenter.Text.Trim(); cre.Properties["CostcenterName"] = this.txtCostcenterName.Text.Trim(); cre.NameSpace = "Hegii"; cre.Name = "GetCostCenter"; ServiceResultEntity sre = DoAsync(() => { return SAPDataModuleProxy.Service.DoRequest(cre); }); if (sre.Status == Constant.ServiceResultStatus.Success) { // 查询成功 this.dgvCenter.DataSource = sre.Data.Tables[0]; if (this.dgvCenter.RowCount == 0) { DKMessageBox.ShowDialog(this, DKMessageCode.I_CMN_S_001); } } } #endregion } }