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.Alarm.PmtAlarm { /// /// 添加报警参数业务 /// public class InsertAction : ChemicalWeighingAction, IAction { public void Run(RuntimeParameter runtime) { base.RunIni(runtime); //必须调用 ICSharpCode.Core.LoggingService.Debug("报警参数-添加..."); FrmInsert frmInsert = new FrmInsert(); DialogResult result = frmInsert.ShowDialog(); if (result == DialogResult.OK) { string alarmPLC = frmInsert.AlarmPLC; string alarmBlock = frmInsert.AlarmBlock; string alarm_Alias = frmInsert.Alarm_Alias; string alarmCnInfo = frmInsert.Alarm_Cn_Info; string strSql = @"insert into Pmt_Alarm(Equip_Code, Alarm_PLC, Alarm_Block, Alarm_Alias, Alarm_Cn_Info) values (@EquipCode, @AlarmPLC, @AlarmBlock, @Alarm_Alias, @Alarm_Cn_Info)"; 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("@Alarm_Alias", alarm_Alias); dbHelper.AddParameter("@Alarm_Cn_Info", alarmCnInfo); dbHelper.ExecuteNonQuery(); //清空报警缓存 Cache.CacheHelper.ClearAlarmInfo(); //刷新DataGridView数据 DbMCControl dgPmtAlarmInfo = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "Pmt_Alarm").FirstOrDefault(); if (dgPmtAlarmInfo == null || !(dgPmtAlarmInfo.BaseControl is DataGridView)) { ICSharpCode.Core.LoggingService.Warn("报警参数-添加-缺少报警参数DataGridView控件..."); runtime.IsReturn = false; return; } string sql = "select * from Pmt_Alarm"; DataTable table = dbHelper.GetDataTableBySql(sql); dgPmtAlarmInfo.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 } } } }