连接mysql数据库,当改变金蝶数据时,修改mysql数据库数据

栏目:云星空知识作者:金蝶来源:金蝶云社区发布:2024-09-16浏览:1

连接mysql数据库,当改变金蝶数据时,修改mysql数据库数据

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

            }


        }

    }



}


连接mysql数据库,当改变金蝶数据时,修改mysql数据库数据

using Kingdee.BOS.App.Data;using Kingdee.BOS.Core;using Kingdee.BOS.Core.DynamicForm;using Kingdee.BOS.Core.DynamicForm.PlugIn...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息