| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- /*******************************************************************************
- * Copyright(c) 2016 DongkeSoft All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:F_RPT_08011401.cs
- * 2.功能描述:导出
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 陈晓野 2018/11/16 1.00 新建
- *******************************************************************************/
- using System;
- using System.Data;
- using System.IO;
- using System.Reflection;
- using System.Windows.Forms;
- using Dongke.IBOSS.PRD.Basics.BaseControls;
- using Dongke.IBOSS.PRD.Client.CommonModule;
- using Dongke.IBOSS.PRD.WCF.DataModels;
- using Dongke.IBOSS.PRD.WCF.Proxys;
- namespace Dongke.IBOSS.PRD.Client.SAPDataModule
- {
- public partial class F_RPT_08011401 : FormBase
- {
- public F_RPT_08011401()
- {
- InitializeComponent();
- this.dtpCreateTimeBegin.Value = DateTime.Now.Date.AddDays(-1);
- this.dtpCreateTimeEnd.Value = DateTime.Now.Date;
-
- }
- /// <summary>
- /// 画面加载
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void F_RPT_08011401_Load_1(object sender, EventArgs e)
- {
- try
- {
- DataTable dtCheckType = new DataTable();
- dtCheckType.Columns.Add("Flag", typeof(string));
- dtCheckType.Columns.Add("FlagName", typeof(string));
- DataRow newRow = dtCheckType.NewRow();
- dtCheckType.Rows.Add(newRow);
- newRow = dtCheckType.NewRow();
- newRow["Flag"] = "1";
- newRow["FlagName"] = "型式检验";
- dtCheckType.Rows.Add(newRow);
- newRow = dtCheckType.NewRow();
- newRow["Flag"] = "2";
- newRow["FlagName"] = "非型式检验";
- dtCheckType.Rows.Add(newRow);
- newRow = dtCheckType.NewRow();
- newRow["Flag"] = "3";
- newRow["FlagName"] = "首件检验";
- dtCheckType.Rows.Add(newRow);
- this.cmbCheckType.DisplayMember = "FlagName";
- this.cmbCheckType.ValueMember = "Flag";
- this.cmbCheckType.DataSource = dtCheckType;
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(ToString(),
- MethodBase.GetCurrentMethod().Name, Text, ex);
- }
- }
- /// <summary>
- /// 同步
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void btnSave_Click(object sender, EventArgs e)
- {
- try
- {
- if (string.IsNullOrWhiteSpace(this.cmbCheckType.SelectedValue.ToString()))
- {
- MessageBox.Show("请选择检验类型", this.Text,
- MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (string.IsNullOrWhiteSpace(this.txtFilePath.Text.ToString()))
- {
- MessageBox.Show("请选择导出路径", this.Text,
- MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- string createtimeBegin = this.dtpCreateTimeBegin.Value.ToString("yyyy-MM-dd");
- string createtimeEnd = this.dtpCreateTimeEnd.Value.ToString("yyyy-MM-dd");
- DialogResult dr = MessageBox.Show("是否导出【" + createtimeBegin + "】至【" + createtimeEnd+ "】的数据。",
- this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
- if (dr != DialogResult.Yes)
- {
- return;
- }
- string directory = Path.GetDirectoryName(this.txtFilePath.Text); // 获取目录
- string fileName = Path.GetFileName(this.txtFilePath.Text); // 获取文件名(含扩展名)
- ClientRequestEntity cre = new ClientRequestEntity();
- cre.NameSpace = "F_RPT_080114";
- cre.Name = "ExportData";
- cre.Properties["CheckType"] = this.cmbCheckType.SelectedValue;
- cre.Properties["CreatetimeBegin"] = createtimeBegin;
- cre.Properties["CreatetimeEnd"] = createtimeEnd;
- cre.Properties["FilePath"] = directory;
- cre.Properties["FileName"] = fileName;
- ServiceResultEntity sre = (ServiceResultEntity)DoAsync(() =>
- {
- return PCModuleProxyNew.Service.HandleRequest(cre);
- });
- if (sre.Message == "无数据")
- {
- MessageBox.Show("该范围内无数据", this.Text,
- MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- // 将Base64字符串转换为字节数组
- byte[] fileBytes = Convert.FromBase64String(sre.Message);
- // 保存到用户选择的路径
- File.WriteAllBytes(this.txtFilePath.Text, fileBytes);
- // 然后打开导出完成的窗口,显示文件路径
- MinimalExportForm f = new MinimalExportForm(this.txtFilePath.Text);
- DialogResult dialogResult = f.ShowDialog();
- }
- catch (Exception ex)
- {
- // 对异常进行共通处理
- ExceptionManager.HandleEventException(this.ToString(),
- MethodBase.GetCurrentMethod().Name, this.Text, ex);
- }
- }
- private void tsbtnchooesfile_Click(object sender, EventArgs e)
- {
- // 弹出保存对话框
- using (SaveFileDialog saveDialog = new SaveFileDialog())
- {
- saveDialog.Filter = "Excel文件 (*.xlsx)|*.xlsx";
- saveDialog.FileName = $"QC检验数据_{DateTime.Now:yyyyMMdd_HHmmss}.xlsx";
- // 如果有现有路径,使用它
- if (!string.IsNullOrEmpty(txtFilePath.Text))
- {
- string dir = Path.GetDirectoryName(txtFilePath.Text);
- if (Directory.Exists(dir))
- {
- saveDialog.InitialDirectory = dir;
- }
- }
- else
- {
- saveDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
- }
- if (saveDialog.ShowDialog() == DialogResult.OK)
- {
- // 将选择的路径写入文本框
- txtFilePath.Text = saveDialog.FileName;
- }
- }
- }
- }
- }
|