⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 converter.cs

📁 可以实现任意数据库之间的数据互导,可以实现任意数据库之间的数据互导
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.Collections;


namespace SqlserverXml
{
    public class Converter:LC_XMLControl.IThransProtocol
    {

        #region IThransProtocol 成员

        private SqlConnection _sourceconnection;
        private OleDbConnection _desconnection;
        private int _dtype;
        private int _stype;
        private string _spliter;
        private int _curnum;
        public void createDesContentction(string constr)
        {
            
        }
        
        public void createSourceContenction(string constr)
        {
            _sourceconnection = null;
            if (_sourceconnection != null) _sourceconnection.Close();
            string[] temp = constr.Split('#');
            string cstr = "";
            int k=0;
            if (temp.Length > 0)
            {
                for (int i = 0; i < temp.Length; i++)
                {
                    if (temp[i].Trim().ToString() != "")
                    {

                        temp[k++] = temp[i];
                    }
                }
            }
            cstr = "database=" + temp[1] + ";server=" + temp[0] + ";uid=" + temp[2] + ";pwd=" + temp[3];
            try
            {
                _sourceconnection = new SqlConnection(cstr);
                _sourceconnection.Open();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message.ToString());
            }
        }
        private ArrayList _allres;
        public ArrayList allres
        {
            get
            {
                return _allres;
            }
            set
            {
                _allres = (ArrayList)value;
            }
        }
        private ArrayList _errorres;
        public ArrayList errorres
        {
            get
            {
                return _errorres;
            }
            set
            {
                _errorres = (ArrayList)value;
            }
        }
        public object desconnection
        {
            get
            {
                return _desconnection;   
            }
            set
            {
                _desconnection = (OleDbConnection)value;
            }
        }

        public int dtype
        {
            get
            {
                return _dtype;
            }
            set
            {
                _dtype = value;
            }
        }

        public System.Collections.ArrayList getAllDesField(string table)
        {
            return null;
        }

        public System.Collections.ArrayList getAllDesTable()
        {
            return null;
        }

        public System.Collections.ArrayList getAllSourceField(string table)
        {
            ArrayList altemp = new ArrayList();
            SqlCommand cmd = new SqlCommand("select * from syscolumns where id=object_id('" + table + "')");
            cmd.Connection = _sourceconnection;
            SqlDataReader sdr = cmd.ExecuteReader();
            if (sdr.HasRows)
            {
                while (sdr.Read())
                {
                    altemp.Add(sdr["name"].ToString());
                }
            }
            sdr.Close();
            return altemp;
        }

        public ArrayList getAllSourceTable()
        {
            ArrayList altemp = new ArrayList();
            SqlCommand cmd=new SqlCommand("select * from sysobjects where xtype='U'");
            cmd.Connection=_sourceconnection;
            SqlDataReader sdr=cmd.ExecuteReader();
            if(sdr.HasRows)
            {
                while(sdr.Read())
                {
                    altemp.Add(sdr["name"].ToString());
                }
            }
            sdr.Close();
            return altemp;
        }

        public DataTable sourceToXml(string source,ArrayList allfield)
        {

            string temp = "";
            for (int i = 0; i < allfield.Count; i++)
            {
                temp += allfield[i].ToString() + ",";
            }
            temp = temp.Substring(0,temp.Length-1);
            SqlCommand cmd = new SqlCommand("select "+temp+" from "+source);
            cmd.Connection = _sourceconnection;
            DataTable dt = new DataTable();
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            sda.Fill(dt);
            return dt;
        }

        public object sourceconnection
        {
            get
            {
                return _sourceconnection;
            }
            set
            {
                _sourceconnection = (SqlConnection)value;
            }
        }

        public string spliter
        {
            get
            {
                return _spliter;
            }
            set
            {
                _spliter = value;
            }
        }

        public int stype
        {
            get
            {
                return _stype;
            }
            set
            {
                _stype = value;
            }
        }

        public void xmlToDes(string des, ArrayList rows, ArrayList fields)
        {

        }

  

      

        public void closeDesConnection()
        {
            
        }

        public void closeSourceConnection()
        {
            
        }
      #endregion

        #region IThransProtocol 成员


        public int cursum
        {
            get
            {
                return _curnum;
            }
            set
            {
                _curnum = value;
            }
        }

        #endregion

        #region IThransProtocol 成员

        private string _info;
        public string info
        {
            get
            {
                return _info;
            }
            set
            {
                _info = value; ;
            }
        }

        #endregion

        #region IThransProtocol 成员

        private ArrayList _msg;
        public ArrayList msg
        {
            get
            {
                return _msg ;
            }
            set
            {
                _msg=value;
            }
        }

        #endregion
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -