}
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
using System.Collections;
using System;
using System.Data;
using System.Data.Odbc;
using System.Data.OleDb;
using PPS.Tool.Event;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data.OracleClient;
namespace PPS.Tool.DataBass
{
public class SqlSvrData
{
private DataBaseHelper _helper;
public SqlSvrData()
{
Providers pro;
if(PPS.Properties.Settings.Default._svrDataBaseDBType.ToLower().Contains("sql"))
{
pro= Providers.SqlServer;
}else if(PPS.Properties.Settings.Default._svrDataBaseDBType.ToLower().Contains("odbc"))
{
pro= Providers.ODBC;
}else if(PPS.Properties.Settings.Default._svrDataBaseDBType.ToLower().Contains("oracle"))
{
pro= Providers.Oracle;
}
else if(PPS.Properties.Settings.Default._svrDataBaseDBType.ToLower().Contains("oledb"))
{
pro= Providers.OleDb;
}else{
pro= Providers.ConfigDefined;
}
_helper = new DataBaseHelper(PPS.Properties.Settings.Default._svrDataBaseConnetstring,pro);
}
public Boolean MyUpdatasql(string strsql)///跟新数据库
{
if (_helper.ExecuteNonQuery(strsql)==-1)
{
return false;
}
return true;
//Debug.Log(dtYourData.Rows[0]["work_1"].ToString());
}
public DataSet selectDataSet(string sql)
{
return _helper.ExecuteDataSet(sql);
}
public DataSet selectDataSet(string query, CommandType commandtype)
{
return _helper.ExecuteDataSet( query, commandtype);
}
public DataSet selectDataSet(string query, CommandType commandtype, List
{
return _helper.ExecuteDataSet(query, commandtype, _Paras);
}
//插入数据
public bool InsertRow(string tableName, List
PictureNode pictureNode)
{
try
{
string col = "";
string val = "";
if (PPS.Properties.Settings.Default._svrDataBaseDBType.ToLower().Contains("sql"))
{
foreach (Node node in arrayLiat)
{
if (node.NodeType.Contains("_count"))
{
col += node.NodeType + ",";
val = val + "" + node.NodeValue + ",";
}
else
{
col += node.NodeType + ",";
val = val + "'" + node.NodeValue + "',";
}
}
col = col.TrimEnd(',');
val = val.TrimEnd(',');
if (pictureNode.NodeType != "" && pictureNode.NodeValue.Length != 1)
{
col += ',' + pictureNode.NodeType;
val += ",@Image";
}
string sql = "insert into " + tableName + " (" + col + ") values" + "(" + val + ")";
if (pictureNode.NodeType != "" && pictureNode.NodeValue.Length != 1)
{
SqlParameter param = new SqlParameter("@Image", pictureNode.NodeValue);
_helper.Command.Parameters.Add(param);
}
_helper.Command.CommandText = sql;
}
else if (PPS.Properties.Settings.Default._svrDataBaseDBType.ToLower().Contains("odbc"))
{
if (pictureNode.NodeType != "" && pictureNode.NodeValue.Length != 1)
{
OdbcParameter[] param = new OdbcParameter[] { new OdbcParameter("@Image", pictureNode.NodeValue) };
_helper.Command.Parameters.Add(param);
}
}
else if (PPS.Properties.Settings.Default._svrDataBaseDBType.ToLower().Contains("oracle"))
{
OracleParameter[] param = new OracleParameter[] { new OracleParameter("@Image", pictureNode.NodeValue) };
_helper.Command.Parameters.Add(param);
}
else if (PPS.Properties.Settings.Default._svrDataBaseDBType.ToLower().Contains("oledb"))
{
foreach (Node node in arrayLiat)
{
if (node.NodeType.Contains("_date"))
{
col += node.NodeType + ",";
val = val + "#" + node.NodeValue + "#,";
}
else if (node.NodeType.Contains("_count"))
{
col += node.NodeType + ",";
val = val + "" + node.NodeValue + ",";
}
else
{
col += node.NodeType + ",";
val = val + "'" + node.NodeValue + "',";
}
}
col = col.TrimEnd(',');
val = val.TrimEnd(',');
if (pictureNode.NodeType != "" && pictureNode.NodeValue.Length != 1)
{
col += ',' + pictureNode.NodeType;
val += ",@Image";
}
string sql = "insert into " + tableName + " (" + col + ") values" + "(" + val + ")";
if (pictureNode.NodeType != "" && pictureNode.NodeValue.Length != 1)
{
OleDbParameter[] param = new OleDbParameter[] { new OleDbParameter("@Image", pictureNode.NodeValue) };
_helper.Command.Parameters.Add(param);
}
_helper.Command.CommandText = sql;
}
_helper.Command.Connection.Open();
if (_helper.Command.ExecuteNonQuery() != -1)
{ return true; }
else {
return false;
}
}
catch (Exception err)
{
Console.WriteLine(err.ToString());
return false;
}
finally
{
_helper.Command.Connection.Close();
GC.Collect();
}
}
//更新一行数据
public bool UpdateRow(string tableName, List
PictureNode pictureNode)
{
try
{
//2、打开连接
string sql = "";
Node KeyNode = new Node(((Node)arrayLiat[0]).NodeType, ((Node)arrayLiat[0]).NodeValue); ;
arrayLiat.RemoveAt(0);
if (PPS.Properties.Settings.Default._svrDataBaseDBType.ToLower().Contains("sql"))
{
foreach (Node node in arrayLiat)
{
if (node.NodeType.Contains("_count"))
{
sql += node.NodeType + "=" + node.NodeValue + ",";
}
else
{
sql += node.NodeType + "='" + node.NodeValue + "',";
}
}
sql = sql.TrimEnd(',');
if (pictureNode.NodeType != "" && pictureNode.NodeValue.Length != 1)
{
sql += "," + pictureNode.NodeType + "=@Image ";
}
if (KeyNode.NodeType.Contains("_count"))
{
}
else
{
KeyNode.NodeValue = "'" + KeyNode.NodeValue + "'";
}
string mysql = "update " + tableName + " set " + sql +
" where " + KeyNode.NodeType + " = " + KeyNode.NodeValue;
if (pictureNode.NodeType != "" && pictureNode.NodeValue.Length != 1)
{
SqlParameter param = new SqlParameter("@Image", pictureNode.NodeValue);
_helper.Command.Parameters.Add(param);
}
_helper.Command.CommandText = mysql;
}
else if (PPS.Properties.Settings.Default._svrDataBaseDBType.ToLower().Contains("odbc"))
{
if (pictureNode.NodeType != "" && pictureNode.NodeValue.Length != 1)
{
OdbcParameter[] param = new OdbcParameter[] { new OdbcParameter("@Image", pictureNode.NodeValue) };
_helper.Command.Parameters.Add(param);
}
}
else if (PPS.Properties.Settings.Default._svrDataBaseDBType.ToLower().Contains("oracle"))
{
OracleParameter[] param = new OracleParameter[] { new OracleParameter("@Image", pictureNode.NodeValue) };
_helper.Command.Parameters.Add(param);
}
else if (PPS.Properties.Settings.Default._svrDataBaseDBType.ToLower().Contains("oledb"))
{
foreach (Node node in arrayLiat)
{
if (node.NodeType.Contains("_date"))
{
sql += node.NodeType + "=#" + node.NodeValue + "#,";
}
else if (node.NodeType.Contains("_count"))
{
sql += node.NodeType + "=" + node.NodeValue + ",";
}
else
{
sql += node.NodeType + "='" + node.NodeValue + "',";
}
}
sql = sql.TrimEnd(',');
if (pictureNode.NodeType != "" && pictureNode.NodeValue.Length != 1)
{
sql += "," + pictureNode.NodeType + "=@Image ";
}
if (KeyNode.NodeType.Contains("_date"))
{
KeyNode.NodeValue = "#" + KeyNode.NodeValue + "#";
}
else if (KeyNode.NodeType.Contains("_count"))
{
}
else
{
KeyNode.NodeValue = "'" + KeyNode.NodeValue + "'";
}
string mysql = "update " + tableName + " set " + sql +
" where " + KeyNode.NodeType + " = " + KeyNode.NodeValue;
if (pictureNode.NodeType != "" && pictureNode.NodeValue.Length != 1)
{
OleDbParameter[] param = new OleDbParameter[] { new OleDbParameter("@Image", pictureNode.NodeValue) };
_helper.Command.Parameters.Add(param);
} _helper.Command.CommandText = mysql;
}
_helper.Command.Connection.Open();
if (_helper.Command.ExecuteNonQuery() != -1)
{ return true; }
else
{
return false;
}
}
catch (Exception err)
{
Console.WriteLine(err.ToString());
return false;
}
finally
{
_helper.Command.Connection.Close();
GC.Collect();
}
}
}
}