using System; using System.Collections.Generic; using System.Linq; using System.Text; using Mesnac.Action.Base; using System.Windows.Forms; using Mesnac.Codd.Session; namespace Mesnac.Action.Feeding.Qingquan.Verification { /// /// 日罐更新验证类,防止更新记录是同类型罐号重复 /// public class SytJarUpdateValidateAction : FeedingAction, IAction { public void Run(RuntimeParameter runtime) { base.RunIni(runtime); DbMCControl objIDControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "[SytJar].[ObjID]").FirstOrDefault(); DbMCControl jarTypeControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "[SytJar].[JarType]").FirstOrDefault(); DbMCControl jarSerialControl = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "[SytJar].[JarSerial]").FirstOrDefault(); if (objIDControl == null) { ICSharpCode.Core.LoggingService.Warn("缺少ObjID控件!"); MessageBox.Show("缺少ObjID控件!", Language(1), MessageBoxButtons.OK, MessageBoxIcon.Information); runtime.IsReturn = true; return; } if (jarTypeControl == null) { ICSharpCode.Core.LoggingService.Warn("缺少罐类型输入控件!"); MessageBox.Show("缺少罐类型输入控件!", Language(1), MessageBoxButtons.OK, MessageBoxIcon.Information); runtime.IsReturn = true; return; } if (jarSerialControl == null) { ICSharpCode.Core.LoggingService.Warn("缺少罐号输入控件!"); MessageBox.Show("缺少罐号输入控件!", Language(1), MessageBoxButtons.OK, MessageBoxIcon.Information); runtime.IsReturn = true; return; } string objID = String.Empty; string jarType = String.Empty; string jarSerial = String.Empty; if (objIDControl.BaseControl.MCValue != null) { objID = objIDControl.BaseControl.MCValue.ToString(); } if (jarTypeControl.BaseControl.MCValue != null) { jarType = jarTypeControl.BaseControl.MCValue.ToString(); } if (jarSerialControl.BaseControl.MCValue != null) { jarSerial = jarSerialControl.BaseControl.MCValue.ToString(); } DbHelper dbHelper = base.NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); if (dbHelper == null) { ICSharpCode.Core.LoggingService.Warn("获取本地数据连接失败!"); MessageBox.Show("获取本地数据连接失败!", Language(1), MessageBoxButtons.OK, MessageBoxIcon.Information); runtime.IsReturn = true; return; } if (this.IsExists(dbHelper, jarType.Trim(), jarSerial.Trim(), objID.Trim())) { MessageBox.Show("修改失败:已存在此类型的罐号!", Language(1), MessageBoxButtons.OK, MessageBoxIcon.Information); runtime.IsReturn = true; return; } } /// /// 判断是否称量物料参数表中是否已存在此参数 /// /// 罐的类型 /// 罐号 /// 存在返回true,不存在返回false public bool IsExists(DbHelper dbHelper, string jarType, string jarSerial, string objID) { try { string strSql = "select COUNT(*) from SytJar where ObjID != @ObjID and JarType = @JarType and JarSerial = @JarSerial"; dbHelper.CommandType = System.Data.CommandType.Text; dbHelper.ClearParameter(); dbHelper.CommandText = strSql; dbHelper.AddParameter("@ObjID", objID); dbHelper.AddParameter("@JarType", jarType); dbHelper.AddParameter("@JarSerial", jarSerial); object result = dbHelper.ToScalar(); if (result != null && result != System.DBNull.Value) { int intResult = 0; if (int.TryParse(result.ToString(), out intResult)) { if (intResult > 0) { return true; } } } return false; } catch (Exception ex) { ICSharpCode.Core.LoggingService.Error("判断罐号重复出错:" + ex.Message); return false; } } } }