|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Windows.Forms;
|
|
|
using System.Data;
|
|
|
using ICSharpCode.Core;
|
|
|
using Mesnac.Action.Base;
|
|
|
using Mesnac.Codd.Session;
|
|
|
|
|
|
namespace Mesnac.Action.ChemicalWeighing.Barrel
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 导入报警参数业务
|
|
|
/// </summary>
|
|
|
public class ImportAction: ChemicalWeighingAction, IAction
|
|
|
{
|
|
|
#region 事件定义
|
|
|
|
|
|
/// <summary>
|
|
|
/// 新增物料事件定义
|
|
|
/// </summary>
|
|
|
public static event EventHandler OnInsertBarrel;
|
|
|
|
|
|
#endregion
|
|
|
private RuntimeParameter _runtime;
|
|
|
|
|
|
private string caption = StringParser.Parse(ResourceService.GetString("Mesnac_Dialog_Caption")); //提示
|
|
|
public void Run(RuntimeParameter runtime)
|
|
|
{
|
|
|
string msg = "确定要导入料桶吗?";// StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_Alarm_PmtAlarm_ImportAction_msg")); //导入操作会覆盖当前所有报警信息!是否继续?
|
|
|
if (MessageBox.Show(msg, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
base.RunIni(runtime); //必须要调用的
|
|
|
this._runtime = runtime;
|
|
|
ICSharpCode.Core.LoggingService<ImportAction>.Debug("料桶参数-导入...");
|
|
|
|
|
|
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
if (dbHelper == null)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService<ImportAction>.Error("获取本地数据连接失败...");
|
|
|
return;
|
|
|
}
|
|
|
OpenFileDialog ofd = new OpenFileDialog();
|
|
|
ofd.Filter = "xls files(*.xls)|*.xls";
|
|
|
ofd.AddExtension = true;
|
|
|
DialogResult result = ofd.ShowDialog();
|
|
|
if (result == DialogResult.OK)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
string fileName = ofd.FileName;
|
|
|
if (!String.IsNullOrEmpty(fileName))
|
|
|
{
|
|
|
DataSet ds = Mesnac.Basic.DataToFileHandler.Instance.FromExcel(fileName);
|
|
|
//判断导入Excel表格式的合法性
|
|
|
if (!ds.Tables[0].Columns.Contains("BarrelName") ||
|
|
|
!ds.Tables[0].Columns.Contains("BarCode") )
|
|
|
{
|
|
|
string msg4 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_Alarm_PmtAlarm_ImportAction_msg4")); //导入的Excel表格式不正确!请检查后重试!
|
|
|
MessageBox.Show(msg4);
|
|
|
return;
|
|
|
}
|
|
|
//string del = "truncate table Pmt_Alarm";
|
|
|
//dbHelper.ClearParameter();
|
|
|
//dbHelper.CommandType = CommandType.Text;
|
|
|
//dbHelper.CommandText = del;
|
|
|
//dbHelper.ExecuteNonQuery();
|
|
|
//truncate table PmtAlarm
|
|
|
if (ds != null && ds.Tables.Count > 0)
|
|
|
{
|
|
|
string sqlstr = @"insert into Hw_Barrel(BarrelName, BarCode)VALUES(@BarrelName, @BarCode)";
|
|
|
foreach (DataRow row in ds.Tables[0].Rows)
|
|
|
{
|
|
|
dbHelper.ClearParameter();
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
dbHelper.CommandText = sqlstr;
|
|
|
dbHelper.AddParameter("@BarrelName", row["BarrelName"]);
|
|
|
dbHelper.AddParameter("@BarCode", row["BarCode"]);
|
|
|
dbHelper.ExecuteNonQuery();
|
|
|
}
|
|
|
string msg1 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_Alarm_PmtAlarm_ImportAction_msg1")); //从Excel导入报警参数数据完毕!
|
|
|
ICSharpCode.Core.LoggingService<ImportAction>.Info(msg1);
|
|
|
|
|
|
#region 记录操作日志
|
|
|
|
|
|
base.DBLog(msg1);
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
MessageBox.Show(msg1, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string msg2 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_Alarm_PmtAlarm_ImportAction_msg2")); //从Excel中导入报警参数数据失败:Excel中没有数据!
|
|
|
ICSharpCode.Core.LoggingService<ImportAction>.Warn(msg2);
|
|
|
|
|
|
#region 记录操作日志
|
|
|
|
|
|
base.DBLog(msg2);
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
MessageBox.Show(String.Format(msg2), Mesnac.Basic.LanguageHelper.WarnCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
string msg3 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_ChemicalWeighing_Alarm_PmtAlarm_ImportAction_msg3")); //从Excel导入报警参数数据失败:{0}!
|
|
|
msg3 = String.Format(msg3, ex.Message);
|
|
|
ICSharpCode.Core.LoggingService<ImportAction>.Error(msg3);
|
|
|
|
|
|
#region 记录操作日志
|
|
|
|
|
|
base.DBLog(msg3);
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
MessageBox.Show(msg3, Mesnac.Basic.LanguageHelper.WarnCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
|
}
|
|
|
#region 触发事件
|
|
|
|
|
|
if (OnInsertBarrel != null)
|
|
|
{
|
|
|
OnInsertBarrel(this._runtime.BaseControl.MCRoot, System.EventArgs.Empty);
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
//刷新DataGridView数据
|
|
|
//DbMCControl dgPmtAlarmInfo = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "Hw_Barrel").FirstOrDefault();
|
|
|
//if (dgPmtAlarmInfo == null || !(dgPmtAlarmInfo.BaseControl is DataGridView))
|
|
|
//{
|
|
|
// ICSharpCode.Core.LoggingService<ImportAction>.Warn("料桶导入-导入-缺少料桶参数DataGridView控件...");
|
|
|
// runtime.IsReturn = false;
|
|
|
// return;
|
|
|
//}
|
|
|
|
|
|
//DataTable table = dbHelper.GetDataTableBySql(dgPmtAlarmInfo.BaseControl.ActionDataSource);
|
|
|
//dgPmtAlarmInfo.BaseControl.BindDataSource = null;
|
|
|
//dgPmtAlarmInfo.BaseControl.BindDataSource = table;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|