📄 converter.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data.OleDb;
using LC_XMLControl;
using System.Collections;
using System.Data;
using System.Windows.Forms;
using System.Threading;
namespace XmlToAccess
{
public class Converter : IThransProtocol
{
#region IThransProtocol 成员
private XmlManager _sourceconnection;
public string _info="";
private OleDbConnection _desconnection;
private int _dtype;
private int _stype;
private string _spliter;
private int _cursum;
public void createDesContentction(string constr)
{
string cstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + constr;
_desconnection = new OleDbConnection(cstr);
_desconnection.Open();
}
public void createSourceContenction(string constr)
{
}
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)
{
ArrayList altemp = new ArrayList();
DataTable dt = new DataTable();
dt = _desconnection.GetOleDbSchemaTable(OleDbSchemaGuid.Columns, new Object[] { null, null, table, null });
for (int i = 0; i < dt.Rows.Count; i++)
{
altemp.Add(dt.Rows[i].ItemArray[3].ToString());
}
return altemp;
}
public ArrayList getAllDesTable()
{
ArrayList altemp = new ArrayList();
DataTable dt=new DataTable();
dt=_desconnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new Object[] {null, null, null, "TABLE"}) ;
for (int i = 0; i < dt.Rows.Count; i++)
{
altemp.Add(dt.Rows[i].ItemArray[2].ToString());
}
return altemp;
}
public System.Collections.ArrayList getAllSourceField(string table)
{
return null;
}
public System.Collections.ArrayList getAllSourceTable()
{
return null;
}
public DataTable sourceToXml(string source, ArrayList allfield)
{
return null;
}
public object sourceconnection
{
get
{
return _sourceconnection;
}
set
{
_sourceconnection = (XmlManager)value;
}
}
public string spliter
{
get
{
return _spliter;
}
set
{
_spliter = value;
}
}
public int stype
{
get
{
return _stype;
}
set
{
_stype = value;
}
}
private ArrayList _msg;
public ArrayList msg
{
get
{
return _msg;
}
set
{
_msg = value;
}
}
private ArrayList _allres=new ArrayList();
public ArrayList allres
{
get
{
return _allres;
}
set
{
_allres = (ArrayList)value;
}
}
private ArrayList _errorres=new ArrayList();
public ArrayList errorres
{
get
{
return _errorres;
}
set
{
_errorres = (ArrayList)value;
}
}
public void xmlToDes(string des,ArrayList rows,ArrayList field)
{
_allres.Clear();
_errorres.Clear();
OleDbCommand ocmd = new OleDbCommand();
ocmd.Connection = _desconnection;
//[1] = "type=数字■id=1133|type=字符串■pwd=10124160|type=字符串■username=Hewitt|"
string temp;
string[] fields;
string str="";
string f=" ";
f = " (";
for(int i=0;i<field.Count;i++)
{
f+=field[i].ToString()+" , ";
}
f=f.Substring(0,f.Length-2);
f += ") ";
for (int i = 0; i < rows.Count; i++)
{
str = "insert into "+des + f +"values(";
temp = rows[i].ToString();
fields = temp.Split('|');
//
for (int k = 0; k < fields.Length; k++)
{
if (fields[k].Trim() != "")
{
str += getFieldValue(fields[k]) + ",";
}
}
str = str.Substring(0,str.Length-1);
str += ")";
try
{
_cursum = i + 1;
ocmd.CommandText = str;
ocmd.ExecuteNonQuery();
info = _cursum + " " + DateTime.Now.ToString() + " : " + str + "被成功执行!";
_allres.Add(info);
Thread.Sleep(100);
}
catch (Exception ee)
{
info = _cursum + " " + DateTime.Now.ToString() + " : " + "在执行" + str + "时候发生了 " + ee.Message.ToString();
_allres.Add(info);
_errorres.Add(info);
continue;
}
}
}
private string getFieldValue(string str)
{
string type = str.Substring(str.IndexOf('=')+1, str.IndexOf('■')-5);
string value=str.Substring(str.LastIndexOf('=')+1);
if (type == "字符串")
return "'" + value + "'";
return value;
}
public void closeDesConnection()
{
_desconnection.Close();
}
public void closeSourceConnection()
{
}
#endregion
#region IThransProtocol 成员
public int cursum
{
get
{
return _cursum;
}
set
{
_cursum = value;
}
}
#endregion
#region IThransProtocol 成员
public string info
{
get
{
return _info ;
}
set
{
_info = value ;
}
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -