using System; using System.Collections.Generic; using System.Data; using Mesnac.Codd.Session; namespace Mesnac.Action.ChemicalWeighing.LjMaterial { public class DBHelp { protected static IDictionary GetDefault() { return new Dictionary(); } 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 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()); } public static void ExecuteNonQuery(string sql, IDictionary 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(); } } }