using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
namespace cadre_mgmt_system
{
public class DataAccess
{
private SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DGMConnCms"].ConnectionString.ToString());
public DataSet Read(string StoredProcedure, SqlParameter[] param = null)
{
SqlCommand sqlCommand = new SqlCommand(StoredProcedure, conn);
sqlCommand.CommandType = CommandType.StoredProcedure;
if (param != null)
{
sqlCommand.Parameters.AddRange(Enumerable.ToArray<SqlParameter>((IEnumerable<SqlParameter>)param));
}
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand);
DataSet dataSet = new DataSet();
conn.Open();
sqlDataAdapter.Fill(dataSet);
conn.Close();
return dataSet;
}
public DataSet Decrypt(DataSet ds)
{
DataSet dataSet = new DataSet();
dataSet = ds.Clone();
dataSet.Clear();
foreach (DataTable table in ds.Tables)
{
DataTable dataTable2 = table.Clone();
dataTable2.Clear();
foreach (DataRow row in table.Rows)
{
DataRow dataRow2 = dataTable2.NewRow();
foreach (DataColumn column in table.Columns)
{
dataRow2[column.ColumnName] = row[column.ColumnName];
}
dataTable2.Rows.Add(dataRow2);
}
dataSet.Tables.Add(dataTable2);
}
return dataSet;
}
public DataSet Read(string Query)
{
SqlCommand selectCommand = new SqlCommand(Query, conn);
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(selectCommand);
DataSet dataSet = new DataSet();
conn.Open();
sqlDataAdapter.Fill(dataSet);
conn.Close();
return dataSet;
}
public bool Write(string StoredProcedure, SqlParameter[] param = null)
{
try
{
new UserLogs().InsertLog(StoredProcedure, param);
}
catch
{
}
SqlCommand sqlCommand = new SqlCommand(StoredProcedure, conn);
sqlCommand.CommandType = CommandType.StoredProcedure;
if (param != null)
{
sqlCommand.Parameters.AddRange(Enumerable.ToArray<SqlParameter>((IEnumerable<SqlParameter>)param));
}
conn.Open();
int num = sqlCommand.ExecuteNonQuery();
conn.Close();
if (num == 1)
{
return true;
}
return false;
}
public bool WriteLogs(string StoredProcedure, SqlParameter[] param = null)
{
SqlCommand sqlCommand = new SqlCommand(StoredProcedure, conn);
sqlCommand.CommandType = CommandType.StoredProcedure;
if (param != null)
{
sqlCommand.Parameters.AddRange(Enumerable.ToArray<SqlParameter>((IEnumerable<SqlParameter>)param));
}
conn.Open();
int num = sqlCommand.ExecuteNonQuery();
conn.Close();
if (num == 1)
{
return true;
}
return false;
}
}
}
No comments:
Post a Comment