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.

94 lines
3.2 KiB
C#

1 year ago
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>();
}
1 year ago
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];
}
1 year ago
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);
1 year ago
}
DataTable table = dbHelper.ToDataTable();
return table;
}
public static void ExecuteNonQuery(string sql)
{
ExecuteNonQuery(sql, new Dictionary<string, object>());
1 year ago
}
1 year ago
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);
1 year ago
}
1 year ago
dbHelper.ExecuteNonQuery();
}
1 year ago
}
}