/*******************************************************************************
* Copyright(c) 2016 DongkeSoft All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:F_SAP_HEGII_0101.cs
* 2.功能描述:成品交接SAP同步
* 编辑履历:
* 作者 日期 版本 修改内容
* 陈晓野 2018/11/13 1.00 新建
*******************************************************************************/
using System;
using System.Collections.Generic;
using System.Data;
using System.Reflection;
using System.Windows.Forms;
using Dongke.IBOSS.PRD.Basics.BaseResources;
using Dongke.IBOSS.PRD.Client.CommonModule;
using Dongke.IBOSS.PRD.Client.Controls;
using Dongke.IBOSS.PRD.Client.DataModels;
using Dongke.IBOSS.PRD.WCF.DataModels;
using Dongke.IBOSS.PRD.WCF.Proxys;
namespace Dongke.IBOSS.PRD.Client.SAPDataModule
{
///
/// 成品SAP同步
///
public partial class F_SAP_HEGII_0101 : DKDockPanelBase
{
#region 成员变量
private static F_SAP_HEGII_0101 _instance = null;
private DateTime? _lastDate = null;
//private bool _canSyn = false;
private DateTime? _synDate = null;
#endregion
#region 单例模式
///
/// 单例模式,防止重复创建窗体
///
public static F_SAP_HEGII_0101 Instance
{
get
{
if (_instance == null)
{
_instance = new F_SAP_HEGII_0101();
}
return _instance;
}
}
#endregion
#region 构造函数
///
/// 成品SAP同步
///
public F_SAP_HEGII_0101()
{
InitializeComponent();
this.Text = "成品SAP同步";
this.tsbtnAdaptive.Text = ButtonText.TSBTN_ADAPTIVE;
this.tsbtnClose.Text = ButtonText.TSBTN_CLOSE;
this.dgvSum.AutoGenerateColumns = false;
}
#endregion
#region 控件事件
///
/// 关闭
///
///
///
private void F_SAP_HEGII_0101_FormClosed(object sender, FormClosedEventArgs e)
{
_instance = null;
}
///
/// 画面加载
///
///
///
private void F_SAP_HEGII_0101_Load(object sender, System.EventArgs e)
{
try
{
// 加载权限
FormPermissionManager.FormPermissionControl(this.Name, this,
LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData,
LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
GetlastDate();
if (_lastDate.HasValue)
{
this.dtpDate.Value = _lastDate.Value.AddDays(1);
}
else
{
this.dtpDate.Value = DateTime.Now.Date;
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 查询
///
///
///
private void tsbtnSearch_Click(object sender, EventArgs e)
{
try
{
this.dgvSum.DataSource = null;
this.QueryDataFromOther();
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
///
/// 清除条件
///
///
///
private void tsbtnClearCondition_Click(object sender, EventArgs e)
{
if (_lastDate.HasValue)
{
this.dtpDate.Value = _lastDate.Value.AddDays(1);
}
else
{
this.dtpDate.Value = DateTime.Now.Date;
}
}
///
/// 自适应列宽
///
///
///
private void tsbtnAdaptive_Click(object sender, EventArgs e)
{
this.dgvSum.AutoResizeColumns();
}
///
/// 关闭画面
///
///
///
private void tsbtnClose_Click(object sender, EventArgs e)
{
this.Close();
}
///
/// SAP同步
///
///
///
private void tsbtnSyn_Click(object sender, EventArgs e)
{
if (this._synDate == null)
{
return;
}
try
{
DataTable data = this.dgvSum.DataSource as DataTable;
//if (data.Rows.Count == 0)
//{
// return;
//}
//DateTime dateTime = Convert.ToDateTime(data.Rows[0]["createtime"]);
//TimeSpan dts = DateTime.Now - dateTime;
//if (dts.TotalMinutes > 30)
//{
// MessageBox.Show("数据查询后时间较长,请刷新数据后再进行同步。",
// this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
// return;
//}
DialogResult dr = MessageBox.Show("是否同步【"+ this._synDate.Value.ToString("yyyyMMdd") + "】的成品交接数据。",
this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
if (dr != DialogResult.Yes)
{
return;
}
this.dtpDate.Value = this._synDate;
//GetlastDate();
TimeSpan ts = DateTime.Now - this._synDate.Value;
if (ts.TotalHours < 24)
{
dr = MessageBox.Show("确认今天成品交接已结束,可以同步今天的成品交接数据。",
this.Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
if (dr != DialogResult.OK)
{
return;
}
}
//DataTable data = this.dgvSum.DataSource as DataTable;
ClientRequestEntity cre = new ClientRequestEntity();
cre.NameSpace = "Hegii";
cre.Name = "SetWorkData60";
cre.Request = this.dtpDate.Value.Value;
if (data.DataSet == null)
{
cre.Data = new DataSet();
cre.Data.Tables.Add(data);
}
else
{
cre.Data = data.DataSet;
}
ServiceResultEntity sre = DoAsync(() =>
{
return SAPDataModuleProxy.Service.DoRequest(cre);
}
);
if (sre.Status == Constant.ServiceResultStatus.Other)
{
this._synDate = null;
this.tsbtnSyn.Enabled = false;
MessageBox.Show(sre.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (sre.Status == Constant.ServiceResultStatus.Success)
{
string ztype = sre.Result + "";
if (ztype == "S")
{
this._synDate = null;
this.tsbtnSyn.Enabled = false;
MessageBox.Show("数据同步成功。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else if (ztype == "W")
{
MessageBox.Show("部分数据同步失败,详情请查询成品交接数据同步日志。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
MessageBox.Show("数据同步失败,详情请查询成品交接数据同步日志。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
else
{
MessageBox.Show("数据同步失败。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
catch (Exception ex)
{
// 对异常进行共通处理
ExceptionManager.HandleEventException(this.ToString(),
MethodBase.GetCurrentMethod().Name, this.Text, ex);
}
}
#endregion
#region 私有方法
///
/// 查询数据
///
private void QueryDataFromOther()
{
this._synDate = null;
this.tsbtnSyn.Enabled = false;
if (this.dtpDate.Value == null)
{
return;
}
try
{
this.tsrToolStrip1.Focus();
ClientRequestEntity cre = new ClientRequestEntity();
cre.NameSpace = "Hegii";
cre.Name = "GetWorkData60";
cre.Request = this.dtpDate.Value.Value;
ServiceResultEntity sre = DoAsync(() =>
{
return SAPDataModuleProxy.Service.DoRequest(cre);
}
);
if (sre.Status == Constant.ServiceResultStatus.Success)
{
// 查询成功
this.dgvSum.DataSource = sre.Data.Tables[0];
int r = Convert.ToInt32(sre.Result);
if (r == 0)
{
this._synDate = this.dtpDate.Value.Value;
this.tsbtnSyn.Enabled = true;
}
}
}
catch (Exception ex)
{
throw ex;
}
}
private void GetlastDate()
{
ClientRequestEntity cre = new ClientRequestEntity();
cre.NameSpace = "Hegii";
cre.Name = "GetLastDateByCode";
cre.Request = "60";
ServiceResultEntity sre = SAPDataModuleProxy.Service.DoRequest(cre);
string lastDate = sre.Result + "";
if (!string.IsNullOrEmpty(lastDate))
{
_lastDate = DateTime.ParseExact(lastDate, "yyyyMMdd", null);
}
}
#endregion
}
}