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.
lj_plc/Actions/Default/Mesnac.Action.Default/SynchroData/Delete.cs

93 lines
3.7 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using ICSharpCode.Core;
using Mesnac.Action.Base;
using Mesnac.Controls.Base;
using System.Windows.Forms;
using Mesnac.Codd.Session;
namespace Mesnac.Action.Default.SynchroData
{
public class Delete : DefaultAction, IAction
{
private string caption = StringParser.Parse(ResourceService.GetString("Mesnac_Dialog_Caption")); //提示
public void Run(RuntimeParameter runtime)
{
string msg1 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_Default_SynchroData_Delete_msg1")); //您确认要删除当前信息吗?
if (MessageBox.Show(msg1, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
{
return;
}
base.RunIni(runtime); //必须调用
#region 限定只对相同DataSource的数据表进行操作
string mcDataSourceID = String.Empty;
if (runtime.Sender is Mesnac.Controls.Base.IBaseControl)
{
mcDataSourceID = (runtime.Sender as Mesnac.Controls.Base.IBaseControl).MCDataSourceID;
}
#endregion
ShowMsg(String.Empty); //清除消息显示标签内容
foreach (DbMCSource dbsource in GetAllDbMCSources())
{
if (string.IsNullOrWhiteSpace(dbsource.DesignSource) ||
string.IsNullOrWhiteSpace(dbsource.DataTable.ToString()))
{
continue;
}
if (!String.IsNullOrEmpty(mcDataSourceID) && dbsource.MCDataSource.Site.Name != mcDataSourceID)
{
continue;
}
string source = dbsource.DesignSource;
string table = dbsource.DataTable;
DbHelper dbHelper = NewDbHelper(source);
if (dbHelper == null)
{
continue;
}
dbHelper.ClearParameter();
dbHelper.CommandType = CommandType.Text;
DbMCControlDesignKeyConfig config = new DbMCControlDesignKeyConfig();
List<DbMCControl> objidcontrols = GetDbMCControlByKey(config.ToString(new string[] { source, table, "GUID" }));
foreach (DbMCControl control in objidcontrols)
{
if (control.BaseControl.MCValue == null ||
string.IsNullOrWhiteSpace(control.BaseControl.MCValue.ToString()))
{
continue;
}
if ((base.DbOptionTypesIsModify(control.BaseControl)))
{
string guid = control.BaseControl.MCValue.ToString();
string sqlstr = "DELETE FROM [" + table + "] WHERE GUID='" + guid + "'";
if (dbHelper.DbSession.ProviderFactory.GetType().FullName.Contains("OracleClientFactory"))
{
sqlstr = "DELETE FROM " + table + " WHERE GUID='" + guid + "'";
}
dbHelper.ClearParameter();
dbHelper.CommandText = sqlstr;
dbHelper.ExecuteNonQuery();
string msg2 = StringParser.Parse(ResourceService.GetString("Mesnac_Action_Default_SynchroData_Delete_msg2")); //信息删除成功!
ShowMsg(msg2);
#region 记录操作日志
base.DBLog(msg2);
#endregion
}
}
}
}
}
}