|
|
|
|
using DevExpress.Office.Utils;
|
|
|
|
|
using DevExpress.Utils.Drawing.Helpers;
|
|
|
|
|
using DevExpress.XtraGauges.Core.Model;
|
|
|
|
|
using ICSharpCode.Core;
|
|
|
|
|
using Mesnac.Action.Base;
|
|
|
|
|
using Mesnac.Action.ChemicalWeighing.Entity;
|
|
|
|
|
using Mesnac.Codd.Session;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Data.SqlClient;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace Mesnac.Action.ChemicalWeighing.Warehouse
|
|
|
|
|
{
|
|
|
|
|
public class ImportAction : ChemicalWeighingAction, IAction
|
|
|
|
|
{
|
|
|
|
|
private string caption = StringParser.Parse(ResourceService.GetString("Mesnac_Dialog_Caption")); //提示
|
|
|
|
|
private DbMCControl _clientGridControl = null;
|
|
|
|
|
private RuntimeParameter _runtime;
|
|
|
|
|
public static event EventHandler OnSubRefresh;
|
|
|
|
|
public void Run(RuntimeParameter runtime)
|
|
|
|
|
{
|
|
|
|
|
base.RunIni(runtime);
|
|
|
|
|
this._runtime = runtime;
|
|
|
|
|
|
|
|
|
|
DbMCControl clientGridControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "Hw_WareHouse").FirstOrDefault();
|
|
|
|
|
if (clientGridControl == null || !(clientGridControl.BaseControl is DataGridView))
|
|
|
|
|
{
|
|
|
|
|
ICSharpCode.Core.LoggingService<ModifyAction>.Error("{投料管理—添加物料}缺少管理控件...");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
this._clientGridControl = clientGridControl;
|
|
|
|
|
DataGridView gridView = this._clientGridControl.BaseControl as DataGridView;
|
|
|
|
|
if (gridView.SelectedRows.Count != 1)
|
|
|
|
|
{
|
|
|
|
|
string msg1_1 = StringParser.Parse("请选择一行要釜信息");
|
|
|
|
|
MessageBox.Show(msg1_1, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
|
|
this._runtime.IsReturn = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//string msg = "导入操作会覆盖当前所有信息!是否继续?"; //导入操作会覆盖当前所有信息!是否继续?
|
|
|
|
|
//if (MessageBox.Show(msg, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
|
|
|
|
|
//{
|
|
|
|
|
// return;
|
|
|
|
|
//}
|
|
|
|
|
base.RunIni(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("PId") || !ds.Tables[0].Columns.Contains("ProductName") ||
|
|
|
|
|
!ds.Tables[0].Columns.Contains("Material_Code") || !ds.Tables[0].Columns.Contains("MaterialName") ||
|
|
|
|
|
!ds.Tables[0].Columns.Contains("MaterialType") || !ds.Tables[0].Columns.Contains("SetWeight") ||
|
|
|
|
|
!ds.Tables[0].Columns.Contains("SetError") || !ds.Tables[0].Columns.Contains("Difference") ||
|
|
|
|
|
!ds.Tables[0].Columns.Contains("Fixed") || !ds.Tables[0].Columns.Contains("FixedRatio") ||
|
|
|
|
|
!ds.Tables[0].Columns.Contains("Recipe"))
|
|
|
|
|
{
|
|
|
|
|
string msg4 = "导入的Excel表格式不正确!请检查后重试!"; //导入的Excel表格式不正确!请检查后重试!
|
|
|
|
|
MessageBox.Show(msg4);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var selectId = gridView.SelectedRows[0].Cells["ID"].Value.ToString();
|
|
|
|
|
if (string.IsNullOrEmpty(selectId))
|
|
|
|
|
{
|
|
|
|
|
string msg4 = "请选择反应釜!"; //导入的Excel表格式不正确!请检查后重试!
|
|
|
|
|
MessageBox.Show(msg4);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
int Id = int.Parse(selectId);
|
|
|
|
|
|
|
|
|
|
if (ds != null && ds.Tables.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
//List<Hw_WareHouseSubView> list= DataTableHelper.DataTableToList(ds.Tables[0]);
|
|
|
|
|
// if (list.Count==0)
|
|
|
|
|
// {
|
|
|
|
|
// string msg2 = "未查询到计划,或者检查计划是否正确!";
|
|
|
|
|
// MessageBox.Show(String.Format(msg2), Mesnac.Basic.LanguageHelper.WarnCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
|
|
|
// }
|
|
|
|
|
DataTable dt = ds.Tables[0];
|
|
|
|
|
RjHelper.DownRjPlan(dt);
|
|
|
|
|
RjHelper.DownZBPlan(dt);
|
|
|
|
|
XLHelper.DownXlPlan(dt);
|
|
|
|
|
|
|
|
|
|
string msg2 = "任务下发完成!";
|
|
|
|
|
MessageBox.Show(String.Format(msg2), Mesnac.Basic.LanguageHelper.WarnCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (OnSubRefresh != null)
|
|
|
|
|
{
|
|
|
|
|
OnSubRefresh(this._runtime.BaseControl.MCRoot, System.EventArgs.Empty);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
string msg3 = "从Excel导入物料数据失败:{0}!"; //从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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//刷新DataGridView数据
|
|
|
|
|
DbMCControl dgPmtAlarmInfo = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "Pmt_Alarm").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 = table;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|