using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.List;
using Kingdee.BOS.Core.List.PlugIn;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using System.Data;
namespace Kingdee.Ghhx.delsfk
{
/// <summary>
/// 【服务插件】BeforeExecuteOperationTransaction
/// </summary>
[Description("删除简单生成入库单改变挪调单入库单号为空"), HotUpdate]
public class Class1 : AbstractOperationServicePlugIn
{
private string connectionString = "server=localhost;user=root;password=123456;database=test;charset=utf8;";
public override void BeforeExecuteOperationTransaction(BeforeExecuteOperationTransaction e)
{
base.BeforeExecuteOperationTransaction(e);
foreach (ExtendedDataEntity extended in e.SelectedRows)
{
DynamicObject dy = extended.DataEntity;
var tableName = "";
DynamicObject xmbm = dy["SRCCOSTID"] as DynamicObject;
if (xmbm["Number"].Equals("CI003"))
{
tableName = "ms_fbhtyfk";
}
else if (xmbm["Number"].Equals("CI004"))
{
tableName = "ms_jdkfk";
}
else if (xmbm["Number"].Equals("CI005"))
{
tableName = "ms_jskfk";
}
else
{
}
var sql = string.Format("UPDATE {0} \n" +
"SET jdfkd = CASE \n" +
" WHEN jdfkd = '{1}' THEN null\n" +
" WHEN jdfkd LIKE '%,{1},%' OR jdfkd LIKE '{1},%' OR jdfkd LIKE '%,{1}' THEN \n" +
" TRIM(BOTH ',' FROM REPLACE(REPLACE(jdfkd, ',{1},', ','), '{1}', '')) \n" +
" WHEN jdfkd = '{1}' || TRIM(BOTH ',' FROM SUBSTRING_INDEX(jdfkd, ',', -1)) THEN \n" +
" TRIM(BOTH ',' FROM SUBSTRING_INDEX(jdfkd, ',', -1)) \n" +
" ELSE \n" +
" jdfkd \n" +
"END\n" +
"WHERE jdfkd like '%{1}%';", tableName, dy["BillNo"]);
e.CancelMessage = "" + sql + dy["BillNo"];
Do(sql);
}
}
private void Do(string sql)
{
var ds = new DataSet();
using (var con = new MySqlConnection(connectionString))
{
con.Open();
var cmd = new MySqlCommand(sql, con);
var rval = cmd.ExecuteNonQuery();
con.Close();
}
}
}
}
您的鼓励与嘉奖将成为创作者们前进的动力,如果觉得本文还不错,可以给予作者创作打赏哦!
请选择打赏金币数 *