BigLitho/Large.Lito.Data/DataAccess/SystemSettingsSQL.cs

141 lines
4.6 KiB
C#

//using System.Data.SqlClient;
using Big.Lito.Data.DataModel;
using Big.Lito.Data.Sql;
namespace Big.Lito.Data.DataAccess
{
//using System;
using System.Data;
using System.Data.SqlClient;
public class SystemSettingsSQL : ConnectionSQL, ISystemSettingsSQL
{
/// <summary>
/// Method to get club member by Id
/// </summary>
/// <param name="id">member id</param>
/// <returns>Data row</returns>
public DataRow GetSystemSettingsByProjectId(int id)
{
DataTable dataTable = new DataTable();
DataRow dataRow;
string connectionString = this.ConnectionString;
using (SqlConnection sqlCon = new SqlConnection(connectionString))
{
using (SqlCommand comm = new SqlCommand())
{
string cmdString = Scripts.sqlGetHeightmapByProjectId;
comm.Connection = sqlCon;
comm.CommandText = cmdString;
comm.Parameters.AddWithValue("@Id", id);
try
{
SqlDataAdapter sd = new SqlDataAdapter();
sd.SelectCommand = comm;
sd.Fill(dataTable);
//sqlCon.Open();
//comm.ExecuteNonQuery();
}
catch (SqlException e)
{
// do something with the exception
// don't hide it
}
// Get the datarow from the table
dataRow = dataTable.Rows.Count > 0 ? dataTable.Rows[0] : null;
}
}
return dataRow;
}
/// <summary>
/// Method to get project by name
/// </summary>
/// <param name="name">project name</param>
/// <returns>Data row</returns>
public DataRow GetSystemSettingsByProjectName(string name)
{
DataTable dataTable = new DataTable();
DataRow dataRow;
string connectionString = this.ConnectionString;
using (SqlConnection sqlCon = new SqlConnection(connectionString))
{
using (SqlCommand comm = new SqlCommand())
{
string cmdString = Scripts.sqlGetHeightmapByProjectName;
comm.Connection = sqlCon;
comm.CommandText = cmdString;
comm.Parameters.AddWithValue("@ProjectName", name);
try
{
SqlDataAdapter sd = new SqlDataAdapter();
sd.SelectCommand = comm;
sd.Fill(dataTable);
//sqlCon.Open();
//comm.ExecuteNonQuery();
}
catch (SqlException e)
{
// do something with the exception
// don't hide it
}
// Get the datarow from the table
dataRow = dataTable.Rows.Count > 0 ? dataTable.Rows[0] : null;
}
}
return dataRow;
}
/// <summary>
/// Method to update project
/// </summary>
/// <param name="project">project</param>
/// <returns>true / false</returns>
public bool UpdateProject(SystemSettingsModel systemSettingsModel)
{
string connectionString = this.ConnectionString;
using (SqlConnection sqlCon = new SqlConnection(connectionString))
{
using (SqlCommand comm = new SqlCommand())
{
string cmdString = Scripts.SqlUpdateSystemSettings;
comm.Connection = sqlCon;
comm.CommandText = cmdString;
comm.Parameters.AddWithValue("@Id", systemSettingsModel.Id);
comm.Parameters.AddWithValue("@HomeDir", systemSettingsModel.HomeDir);
comm.Parameters.AddWithValue("@BlenderDir", systemSettingsModel.BlenderDir);
try
{
sqlCon.Open();
comm.ExecuteNonQuery();
}
catch (SqlException e)
{
// do something with the exception
// don't hide it
}
}
}
return true;
}
}
}