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.

77 lines
3.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;
using Mesnac.Action.Base;
using Mesnac.Codd.Session;
namespace Mesnac.Action.ChemicalWeighing.Solvent.Alarm
{
/// <summary>
/// 添加报警参数业务
/// </summary>
public class InsertAction : ChemicalWeighingAction, IAction
{
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime); //必须调用
ICSharpCode.Core.LoggingService<InsertAction>.Debug("报警参数-添加...");
FrmInsert frmInsert = new FrmInsert();
DialogResult result = frmInsert.ShowDialog();
if (result == DialogResult.OK)
{
string alarmPLC = frmInsert.AlarmPLC;
string alarmBlock = frmInsert.AlarmBlock;
int alarmAddress = frmInsert.AlarmAddress;
int alarmBit = frmInsert.AlarmBit;
//string alarmCode = frmInsert.AlarmCode;
string alarmName = frmInsert.AlarmName;
string alarmPosition = frmInsert.AlarmPosition;
string strSql = @"insert into Hw_Solvent_Alarm(Equip_Code, Alarm_PLC, Alarm_Block, Alarm_Word, Alarm_Bit, Alarm_Cn_Info, Alarm_Other_Info, Plc_Type)
values (@EquipCode, @AlarmPLC, @AlarmBlock, @AlarmAddress, @AlarmBit, @AlarmName, @AlarmPosition, @PlcType)";
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
dbHelper.ClearParameter();
dbHelper.CommandText = strSql;
dbHelper.CommandType = System.Data.CommandType.Text;
dbHelper.AddParameter("@EquipCode", "01");
dbHelper.AddParameter("@AlarmPLC", alarmPLC);
dbHelper.AddParameter("@AlarmBlock", alarmBlock);
dbHelper.AddParameter("@AlarmAddress", alarmAddress);
dbHelper.AddParameter("@AlarmBit", alarmBit);
//dbHelper.AddParameter("@AlarmCode", alarmCode);
dbHelper.AddParameter("@AlarmName", alarmName);
dbHelper.AddParameter("@AlarmPosition", alarmPosition);
//dbHelper.AddParameter("@SaveFlag", "1");
dbHelper.AddParameter("@PlcType", 4);
dbHelper.ExecuteNonQuery();
//清空报警缓存
Cache.CacheHelper.ClearAlarmInfo();
//刷新DataGridView数据
DbMCControl dgAlarmInfo = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "Hw_Solvent_Alarm").FirstOrDefault();
if (dgAlarmInfo == null || !(dgAlarmInfo.BaseControl is DataGridView))
{
ICSharpCode.Core.LoggingService<InsertAction>.Warn("报警参数-添加-缺少报警参数DataGridView控件...");
runtime.IsReturn = false;
return;
}
DataTable table = dbHelper.GetDataTableBySql(dgAlarmInfo.BaseControl.ActionDataSource);
dgAlarmInfo.BaseControl.BindDataSource = table;
#region 记录操作日志
//string logContent = String.Format("AlarmPLC={0}, AlarmBlock={1}, AlarmAddress={2}, AlarmBit={3}, AlarmCode={4}, AlarmName={5}", alarmPLC, alarmBlock, alarmAddress, alarmBit, alarmCode, alarmName);
//base.DBLog(logContent);
#endregion
}
}
}
}