You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
3.2 KiB
C#
93 lines
3.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using Mesnac.Codd.Session;
|
|
|
|
namespace Mesnac.Action.ChemicalWeighing.LjMaterial
|
|
{
|
|
public class DBHelp
|
|
{
|
|
|
|
|
|
protected static IDictionary<string, object> GetDefault()
|
|
{
|
|
return new Dictionary<string, object>();
|
|
}
|
|
|
|
public static DataTable GetTable(string sql)
|
|
{
|
|
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
if (dbHelper == null)
|
|
{
|
|
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
|
|
}
|
|
dbHelper.ClearParameter();
|
|
dbHelper.CommandType = CommandType.Text;
|
|
string strSql = sql;
|
|
dbHelper.CommandText = strSql;
|
|
DataTable table = dbHelper.ToDataTable();
|
|
return table;
|
|
}
|
|
public static object GetOne(string sql)
|
|
{
|
|
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
if (dbHelper == null)
|
|
{
|
|
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
|
|
}
|
|
dbHelper.ClearParameter();
|
|
dbHelper.CommandType = CommandType.Text;
|
|
string strSql = sql;
|
|
dbHelper.CommandText = strSql;
|
|
DataTable table = dbHelper.ToDataTable();
|
|
return table.Rows[0][0];
|
|
}
|
|
|
|
|
|
|
|
public static DataTable GetTable(string sql, IDictionary<string, object> dic)
|
|
{
|
|
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
if (dbHelper == null)
|
|
{
|
|
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
|
|
}
|
|
dbHelper.ClearParameter();
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
|
string insertUserSql = sql;
|
|
dbHelper.CommandText = insertUserSql;
|
|
foreach (var keyValuePair in dic)
|
|
{
|
|
dbHelper.AddParameter(keyValuePair.Key,keyValuePair.Value);
|
|
}
|
|
DataTable table = dbHelper.ToDataTable();
|
|
return table;
|
|
}
|
|
|
|
public static void ExecuteNonQuery(string sql)
|
|
{
|
|
ExecuteNonQuery(sql,new Dictionary<string, object>());
|
|
}
|
|
public static void ExecuteNonQuery(string sql, IDictionary<string, object> dic)
|
|
{
|
|
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
if (dbHelper == null)
|
|
{
|
|
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
|
|
}
|
|
dbHelper.ClearParameter();
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
|
string insertUserSql = sql;
|
|
dbHelper.CommandText = insertUserSql;
|
|
foreach (var keyValuePair in dic)
|
|
{
|
|
dbHelper.AddParameter(keyValuePair.Key,keyValuePair.Value);
|
|
}
|
|
|
|
dbHelper.ExecuteNonQuery();
|
|
}
|
|
|
|
}
|
|
} |