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.

114 lines
4.9 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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
{
/// <summary>
/// 日罐更新验证类,防止更新记录是同类型罐号重复
/// </summary>
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;
}
}
/// <summary>
/// 判断是否称量物料参数表中是否已存在此参数
/// </summary>
/// <param name="jarType">罐的类型</param>
/// <param name="jarSerial">罐号</param>
/// <returns>存在返回true不存在返回false</returns>
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;
}
}
}
}