You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
121 lines
5.2 KiB
C#
121 lines
5.2 KiB
C#
using DevExpress.Utils.Drawing.Helpers;
|
|
using ICSharpCode.Core;
|
|
using Mesnac.Action.Base;
|
|
using Mesnac.Action.ChemicalWeighing.Entity.Report;
|
|
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Mesnac.Action.ChemicalWeighing.Report.DryMixer
|
|
{
|
|
/// <summary>
|
|
/// 干混机报表导出事件
|
|
/// </summary>
|
|
public class ExportAction : ChemicalWeighingAction, Base.IAction
|
|
{
|
|
private Control _clientGridControl = null; //报表明细DGV
|
|
private DbMCControl _dgvDryMixer = null; //报表数据DGV
|
|
|
|
public void Run(RuntimeParameter runtime)
|
|
{
|
|
base.RunIni(runtime); //必须要调用的
|
|
ICSharpCode.Core.LoggingService<ExportAction>.Debug("干混机报表-导出...");
|
|
|
|
this._dgvDryMixer = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "Report_DryMixer").FirstOrDefault();
|
|
DataGridView _DryMixerGridView = this._dgvDryMixer.BaseControl as DataGridView;
|
|
|
|
if (_DryMixerGridView != null)
|
|
{
|
|
DryMixerDos dryMixerDos = new DryMixerDos();
|
|
dryMixerDos.eqNo = ParseToInt(_DryMixerGridView.SelectedRows[0].Cells["eqNo"].Value.ToString());
|
|
dryMixerDos.dos = ParseToInt(_DryMixerGridView.SelectedRows[0].Cells["dos"].Value.ToString());
|
|
dryMixerDos.batch = ParseToInt(_DryMixerGridView.SelectedRows[0].Cells["batch"].Value.ToString());
|
|
dryMixerDos.matCode = ParseToInt(_DryMixerGridView.SelectedRows[0].Cells["matCode"].Value.ToString());
|
|
dryMixerDos.setValue = Convert.ToDouble(_DryMixerGridView.SelectedRows[0].Cells["setValue"].Value);
|
|
dryMixerDos.setToler = Convert.ToDouble(_DryMixerGridView.SelectedRows[0].Cells["setToler"].Value);
|
|
dryMixerDos.actValue = Convert.ToDouble(_DryMixerGridView.SelectedRows[0].Cells["actValue"].Value);
|
|
dryMixerDos.actToLer = Convert.ToDouble(_DryMixerGridView.SelectedRows[0].Cells["actToLer"].Value);
|
|
dryMixerDos.recordTime = _DryMixerGridView.SelectedRows[0].Cells["recordTime"].Value.ToString();
|
|
|
|
SaveFileDialog sfd = new SaveFileDialog();
|
|
sfd.Filter = "xls files(*.xls)|*.xls";
|
|
sfd.FileName = String.Format("干混机报表_{0:yyyyMMdd}", DateTime.Now);
|
|
sfd.AddExtension = true;
|
|
DialogResult result = sfd.ShowDialog();
|
|
|
|
if (result == DialogResult.OK)
|
|
{
|
|
this._clientGridControl = GetAllControls().Where(x => x.Name.Contains("MultiColHeaderDgv")).FirstOrDefault();
|
|
|
|
if (_clientGridControl == null)
|
|
{
|
|
ICSharpCode.Core.LoggingService<ExportAction>.Warn("{生产报表} 缺少缺少称量名细MultiColHeaderDgv控件...");
|
|
runtime.IsReturn = false;
|
|
return;
|
|
}
|
|
|
|
Mesnac.Controls.Default.MultiColHeaderDgv clientGrid = (this._clientGridControl as Mesnac.Controls.Default.MultiColHeaderDgv);
|
|
System.Data.DataTable dt = clientGrid.DataSource as System.Data.DataTable;
|
|
|
|
string fileName = sfd.FileName;
|
|
if (!String.IsNullOrEmpty(fileName))
|
|
{
|
|
try
|
|
{
|
|
//写入Excle
|
|
DataTabletoExcel(fileName, dt, dryMixerDos);
|
|
string msg1 = "干混机报表导出成功"; //导出生产报表数据至Excel成功!
|
|
ICSharpCode.Core.LoggingService<ExportAction>.Info(msg1);
|
|
MessageBox.Show(msg1, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string msg1 = $"干混机报表导出异常:{ex.Message}";
|
|
ICSharpCode.Core.LoggingService<ExportAction>.Error(msg1);
|
|
MessageBox.Show(msg1, Mesnac.Basic.LanguageHelper.WarnCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 写入到Excel文件
|
|
/// </summary>
|
|
/// <param name="strFileName"></param>
|
|
/// <param name="tmpDataTable"></param>
|
|
/// <param name="dryMixerDos"></param>
|
|
public void DataTabletoExcel(string strFileName, System.Data.DataTable tmpDataTable, DryMixerDos dryMixerDos)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// 字符串转Int
|
|
/// </summary>
|
|
/// <param name="str"></param>
|
|
/// <returns></returns>
|
|
private int ParseToInt(string str)
|
|
{
|
|
int returnInt = 0;
|
|
if (str == null || str.Trim().Length < 1)
|
|
{
|
|
return returnInt;
|
|
}
|
|
if (int.TryParse(str, out returnInt))
|
|
{
|
|
return returnInt;
|
|
}
|
|
else
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
}
|