F_SAP_HEGII_0101.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. /*******************************************************************************
  2. * Copyright(c) 2016 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_SAP_HEGII_0101.cs
  5. * 2.功能描述:成品交接SAP同步
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 陈晓野 2018/11/13 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Data;
  13. using System.Reflection;
  14. using System.Windows.Forms;
  15. using Dongke.IBOSS.PRD.Basics.BaseResources;
  16. using Dongke.IBOSS.PRD.Client.CommonModule;
  17. using Dongke.IBOSS.PRD.Client.Controls;
  18. using Dongke.IBOSS.PRD.Client.DataModels;
  19. using Dongke.IBOSS.PRD.WCF.DataModels;
  20. using Dongke.IBOSS.PRD.WCF.Proxys;
  21. namespace Dongke.IBOSS.PRD.Client.SAPDataModule
  22. {
  23. /// <summary>
  24. /// 成品SAP同步
  25. /// </summary>
  26. public partial class F_SAP_HEGII_0101 : DKDockPanelBase
  27. {
  28. #region 成员变量
  29. private static F_SAP_HEGII_0101 _instance = null;
  30. private DateTime? _lastDate = null;
  31. //private bool _canSyn = false;
  32. private DateTime? _synDate = null;
  33. #endregion
  34. #region 单例模式
  35. /// <summary>
  36. /// 单例模式,防止重复创建窗体
  37. /// </summary>
  38. public static F_SAP_HEGII_0101 Instance
  39. {
  40. get
  41. {
  42. if (_instance == null)
  43. {
  44. _instance = new F_SAP_HEGII_0101();
  45. }
  46. return _instance;
  47. }
  48. }
  49. #endregion
  50. #region 构造函数
  51. /// <summary>
  52. /// 成品SAP同步
  53. /// </summary>
  54. public F_SAP_HEGII_0101()
  55. {
  56. InitializeComponent();
  57. this.Text = "成品SAP同步";
  58. this.tsbtnAdaptive.Text = ButtonText.TSBTN_ADAPTIVE;
  59. this.tsbtnClose.Text = ButtonText.TSBTN_CLOSE;
  60. this.dgvSum.AutoGenerateColumns = false;
  61. }
  62. #endregion
  63. #region 控件事件
  64. /// <summary>
  65. /// 关闭
  66. /// </summary>
  67. /// <param name="sender"></param>
  68. /// <param name="e"></param>
  69. private void F_SAP_HEGII_0101_FormClosed(object sender, FormClosedEventArgs e)
  70. {
  71. _instance = null;
  72. }
  73. /// <summary>
  74. /// 画面加载
  75. /// </summary>
  76. /// <param name="sender"></param>
  77. /// <param name="e"></param>
  78. private void F_SAP_HEGII_0101_Load(object sender, System.EventArgs e)
  79. {
  80. try
  81. {
  82. // 加载权限
  83. FormPermissionManager.FormPermissionControl(this.Name, this,
  84. LogInUserInfo.CurrentUser.CurrentUserEntity.UserRightData,
  85. LogInUserInfo.CurrentUser.CurrentUserEntity.FunctionData);
  86. GetlastDate();
  87. if (_lastDate.HasValue)
  88. {
  89. this.dtpDate.Value = _lastDate.Value.AddDays(1);
  90. }
  91. else
  92. {
  93. this.dtpDate.Value = DateTime.Now.Date;
  94. }
  95. }
  96. catch (Exception ex)
  97. {
  98. // 对异常进行共通处理
  99. ExceptionManager.HandleEventException(this.ToString(),
  100. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  101. }
  102. }
  103. /// <summary>
  104. /// 查询
  105. /// </summary>
  106. /// <param name="sender"></param>
  107. /// <param name="e"></param>
  108. private void tsbtnSearch_Click(object sender, EventArgs e)
  109. {
  110. try
  111. {
  112. this.dgvSum.DataSource = null;
  113. this.QueryDataFromOther();
  114. }
  115. catch (Exception ex)
  116. {
  117. // 对异常进行共通处理
  118. ExceptionManager.HandleEventException(this.ToString(),
  119. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  120. }
  121. }
  122. /// <summary>
  123. /// 清除条件
  124. /// </summary>
  125. /// <param name="sender"></param>
  126. /// <param name="e"></param>
  127. private void tsbtnClearCondition_Click(object sender, EventArgs e)
  128. {
  129. if (_lastDate.HasValue)
  130. {
  131. this.dtpDate.Value = _lastDate.Value.AddDays(1);
  132. }
  133. else
  134. {
  135. this.dtpDate.Value = DateTime.Now.Date;
  136. }
  137. }
  138. /// <summary>
  139. /// 自适应列宽
  140. /// </summary>
  141. /// <param name="sender"></param>
  142. /// <param name="e"></param>
  143. private void tsbtnAdaptive_Click(object sender, EventArgs e)
  144. {
  145. this.dgvSum.AutoResizeColumns();
  146. }
  147. /// <summary>
  148. /// 关闭画面
  149. /// </summary>
  150. /// <param name="sender"></param>
  151. /// <param name="e"></param>
  152. private void tsbtnClose_Click(object sender, EventArgs e)
  153. {
  154. this.Close();
  155. }
  156. /// <summary>
  157. /// SAP同步
  158. /// </summary>
  159. /// <param name="sender"></param>
  160. /// <param name="e"></param>
  161. private void tsbtnSyn_Click(object sender, EventArgs e)
  162. {
  163. if (this._synDate == null)
  164. {
  165. return;
  166. }
  167. try
  168. {
  169. DataTable data = this.dgvSum.DataSource as DataTable;
  170. //if (data.Rows.Count == 0)
  171. //{
  172. // return;
  173. //}
  174. //DateTime dateTime = Convert.ToDateTime(data.Rows[0]["createtime"]);
  175. //TimeSpan dts = DateTime.Now - dateTime;
  176. //if (dts.TotalMinutes > 30)
  177. //{
  178. // MessageBox.Show("数据查询后时间较长,请刷新数据后再进行同步。",
  179. // this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  180. // return;
  181. //}
  182. DialogResult dr = MessageBox.Show("是否同步【"+ this._synDate.Value.ToString("yyyyMMdd") + "】的成品交接数据。",
  183. this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
  184. if (dr != DialogResult.Yes)
  185. {
  186. return;
  187. }
  188. this.dtpDate.Value = this._synDate;
  189. //GetlastDate();
  190. TimeSpan ts = DateTime.Now - this._synDate.Value;
  191. if (ts.TotalHours < 24)
  192. {
  193. dr = MessageBox.Show("确认今天成品交接已结束,可以同步今天的成品交接数据。",
  194. this.Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
  195. if (dr != DialogResult.OK)
  196. {
  197. return;
  198. }
  199. }
  200. //DataTable data = this.dgvSum.DataSource as DataTable;
  201. ClientRequestEntity cre = new ClientRequestEntity();
  202. cre.NameSpace = "Hegii";
  203. cre.Name = "SetWorkData60";
  204. cre.Request = this.dtpDate.Value.Value;
  205. if (data.DataSet == null)
  206. {
  207. cre.Data = new DataSet();
  208. cre.Data.Tables.Add(data);
  209. }
  210. else
  211. {
  212. cre.Data = data.DataSet;
  213. }
  214. ServiceResultEntity sre = DoAsync<ServiceResultEntity>(() =>
  215. {
  216. return SAPDataModuleProxy.Service.DoRequest(cre);
  217. }
  218. );
  219. if (sre.Status == Constant.ServiceResultStatus.Other)
  220. {
  221. this._synDate = null;
  222. this.tsbtnSyn.Enabled = false;
  223. MessageBox.Show(sre.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  224. return;
  225. }
  226. if (sre.Status == Constant.ServiceResultStatus.Success)
  227. {
  228. string ztype = sre.Result + "";
  229. if (ztype == "S")
  230. {
  231. this._synDate = null;
  232. this.tsbtnSyn.Enabled = false;
  233. MessageBox.Show("数据同步成功。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  234. }
  235. else if (ztype == "W")
  236. {
  237. MessageBox.Show("部分数据同步失败,详情请查询成品交接数据同步日志。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  238. }
  239. else
  240. {
  241. MessageBox.Show("数据同步失败,详情请查询成品交接数据同步日志。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  242. }
  243. }
  244. else
  245. {
  246. MessageBox.Show("数据同步失败。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
  247. }
  248. }
  249. catch (Exception ex)
  250. {
  251. // 对异常进行共通处理
  252. ExceptionManager.HandleEventException(this.ToString(),
  253. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  254. }
  255. }
  256. #endregion
  257. #region 私有方法
  258. /// <summary>
  259. /// 查询数据
  260. /// </summary>
  261. private void QueryDataFromOther()
  262. {
  263. this._synDate = null;
  264. this.tsbtnSyn.Enabled = false;
  265. if (this.dtpDate.Value == null)
  266. {
  267. return;
  268. }
  269. try
  270. {
  271. this.tsrToolStrip1.Focus();
  272. ClientRequestEntity cre = new ClientRequestEntity();
  273. cre.NameSpace = "Hegii";
  274. cre.Name = "GetWorkData60";
  275. cre.Request = this.dtpDate.Value.Value;
  276. ServiceResultEntity sre = DoAsync<ServiceResultEntity>(() =>
  277. {
  278. return SAPDataModuleProxy.Service.DoRequest(cre);
  279. }
  280. );
  281. if (sre.Status == Constant.ServiceResultStatus.Success)
  282. {
  283. // 查询成功
  284. this.dgvSum.DataSource = sre.Data.Tables[0];
  285. int r = Convert.ToInt32(sre.Result);
  286. if (r == 0)
  287. {
  288. this._synDate = this.dtpDate.Value.Value;
  289. this.tsbtnSyn.Enabled = true;
  290. }
  291. }
  292. }
  293. catch (Exception ex)
  294. {
  295. throw ex;
  296. }
  297. }
  298. private void GetlastDate()
  299. {
  300. ClientRequestEntity cre = new ClientRequestEntity();
  301. cre.NameSpace = "Hegii";
  302. cre.Name = "GetLastDateByCode";
  303. cre.Request = "60";
  304. ServiceResultEntity sre = SAPDataModuleProxy.Service.DoRequest(cre);
  305. string lastDate = sre.Result + "";
  306. if (!string.IsNullOrEmpty(lastDate))
  307. {
  308. _lastDate = DateTime.ParseExact(lastDate, "yyyyMMdd", null);
  309. }
  310. }
  311. #endregion
  312. }
  313. }