F_RPT_08011401.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*******************************************************************************
  2. * Copyright(c) 2016 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_RPT_08011401.cs
  5. * 2.功能描述:导出
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 陈晓野 2018/11/16 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Data;
  12. using System.IO;
  13. using System.Reflection;
  14. using System.Windows.Forms;
  15. using Dongke.IBOSS.PRD.Basics.BaseControls;
  16. using Dongke.IBOSS.PRD.Client.CommonModule;
  17. using Dongke.IBOSS.PRD.WCF.DataModels;
  18. using Dongke.IBOSS.PRD.WCF.Proxys;
  19. namespace Dongke.IBOSS.PRD.Client.SAPDataModule
  20. {
  21. public partial class F_RPT_08011401 : FormBase
  22. {
  23. public F_RPT_08011401()
  24. {
  25. InitializeComponent();
  26. this.dtpCreateTimeBegin.Value = DateTime.Now.Date.AddDays(-1);
  27. this.dtpCreateTimeEnd.Value = DateTime.Now.Date;
  28. }
  29. /// <summary>
  30. /// 画面加载
  31. /// </summary>
  32. /// <param name="sender"></param>
  33. /// <param name="e"></param>
  34. private void F_RPT_08011401_Load_1(object sender, EventArgs e)
  35. {
  36. try
  37. {
  38. DataTable dtCheckType = new DataTable();
  39. dtCheckType.Columns.Add("Flag", typeof(string));
  40. dtCheckType.Columns.Add("FlagName", typeof(string));
  41. DataRow newRow = dtCheckType.NewRow();
  42. dtCheckType.Rows.Add(newRow);
  43. newRow = dtCheckType.NewRow();
  44. newRow["Flag"] = "1";
  45. newRow["FlagName"] = "型式检验";
  46. dtCheckType.Rows.Add(newRow);
  47. newRow = dtCheckType.NewRow();
  48. newRow["Flag"] = "2";
  49. newRow["FlagName"] = "非型式检验";
  50. dtCheckType.Rows.Add(newRow);
  51. newRow = dtCheckType.NewRow();
  52. newRow["Flag"] = "3";
  53. newRow["FlagName"] = "首件检验";
  54. dtCheckType.Rows.Add(newRow);
  55. this.cmbCheckType.DisplayMember = "FlagName";
  56. this.cmbCheckType.ValueMember = "Flag";
  57. this.cmbCheckType.DataSource = dtCheckType;
  58. }
  59. catch (Exception ex)
  60. {
  61. // 对异常进行共通处理
  62. ExceptionManager.HandleEventException(ToString(),
  63. MethodBase.GetCurrentMethod().Name, Text, ex);
  64. }
  65. }
  66. /// <summary>
  67. /// 同步
  68. /// </summary>
  69. /// <param name="sender"></param>
  70. /// <param name="e"></param>
  71. private void btnSave_Click(object sender, EventArgs e)
  72. {
  73. try
  74. {
  75. if (string.IsNullOrWhiteSpace(this.cmbCheckType.SelectedValue.ToString()))
  76. {
  77. MessageBox.Show("请选择检验类型", this.Text,
  78. MessageBoxButtons.OK, MessageBoxIcon.Information);
  79. return;
  80. }
  81. if (string.IsNullOrWhiteSpace(this.txtFilePath.Text.ToString()))
  82. {
  83. MessageBox.Show("请选择导出路径", this.Text,
  84. MessageBoxButtons.OK, MessageBoxIcon.Information);
  85. return;
  86. }
  87. string createtimeBegin = this.dtpCreateTimeBegin.Value.ToString("yyyy-MM-dd");
  88. string createtimeEnd = this.dtpCreateTimeEnd.Value.ToString("yyyy-MM-dd");
  89. DialogResult dr = MessageBox.Show("是否导出【" + createtimeBegin + "】至【" + createtimeEnd+ "】的数据。",
  90. this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
  91. if (dr != DialogResult.Yes)
  92. {
  93. return;
  94. }
  95. string directory = Path.GetDirectoryName(this.txtFilePath.Text); // 获取目录
  96. string fileName = Path.GetFileName(this.txtFilePath.Text); // 获取文件名(含扩展名)
  97. ClientRequestEntity cre = new ClientRequestEntity();
  98. cre.NameSpace = "F_RPT_080114";
  99. cre.Name = "ExportData";
  100. cre.Properties["CheckType"] = this.cmbCheckType.SelectedValue;
  101. cre.Properties["CreatetimeBegin"] = createtimeBegin;
  102. cre.Properties["CreatetimeEnd"] = createtimeEnd;
  103. cre.Properties["FilePath"] = directory;
  104. cre.Properties["FileName"] = fileName;
  105. ServiceResultEntity sre = (ServiceResultEntity)DoAsync(() =>
  106. {
  107. return PCModuleProxyNew.Service.HandleRequest(cre);
  108. });
  109. if (sre.Message == "无数据")
  110. {
  111. MessageBox.Show("该范围内无数据", this.Text,
  112. MessageBoxButtons.OK, MessageBoxIcon.Information);
  113. return;
  114. }
  115. // 将Base64字符串转换为字节数组
  116. byte[] fileBytes = Convert.FromBase64String(sre.Message);
  117. // 保存到用户选择的路径
  118. File.WriteAllBytes(this.txtFilePath.Text, fileBytes);
  119. // 然后打开导出完成的窗口,显示文件路径
  120. MinimalExportForm f = new MinimalExportForm(this.txtFilePath.Text);
  121. DialogResult dialogResult = f.ShowDialog();
  122. }
  123. catch (Exception ex)
  124. {
  125. // 对异常进行共通处理
  126. ExceptionManager.HandleEventException(this.ToString(),
  127. MethodBase.GetCurrentMethod().Name, this.Text, ex);
  128. }
  129. }
  130. private void tsbtnchooesfile_Click(object sender, EventArgs e)
  131. {
  132. // 弹出保存对话框
  133. using (SaveFileDialog saveDialog = new SaveFileDialog())
  134. {
  135. saveDialog.Filter = "Excel文件 (*.xlsx)|*.xlsx";
  136. saveDialog.FileName = $"QC检验数据_{DateTime.Now:yyyyMMdd_HHmmss}.xlsx";
  137. // 如果有现有路径,使用它
  138. if (!string.IsNullOrEmpty(txtFilePath.Text))
  139. {
  140. string dir = Path.GetDirectoryName(txtFilePath.Text);
  141. if (Directory.Exists(dir))
  142. {
  143. saveDialog.InitialDirectory = dir;
  144. }
  145. }
  146. else
  147. {
  148. saveDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
  149. }
  150. if (saveDialog.ShowDialog() == DialogResult.OK)
  151. {
  152. // 将选择的路径写入文本框
  153. txtFilePath.Text = saveDialog.FileName;
  154. }
  155. }
  156. }
  157. }
  158. }