连接mysql数据库,当改变金蝶数据时,修改mysql数据库数据原创
金蝶云社区-隋唐宋元明清
隋唐宋元明清
0人赞赏了该文章 150次浏览 未经作者许可,禁止转载编辑于2024年05月14日 16:59:15

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();

            }


        }

    }



}


图标赞 0
0人点赞
还没有人点赞,快来当第一个点赞的人吧!
图标打赏
0人打赏
还没有人打赏,快来当第一个打赏的人吧!