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

149 lines
5.2 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 HeightmapSQL : ConnectionSQL, IHeightmapSQL
{
/// <summary>
/// Method to get club member by Id
/// </summary>
/// <param name="id">member id</param>
/// <returns>Data row</returns>
public DataRow GetHeightmapByProjectId(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 GetHeightmapByProjectName(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(HeightmapModel heightmapModel)
{
string connectionString = this.ConnectionString;
using (SqlConnection sqlCon = new SqlConnection(connectionString))
{
using (SqlCommand comm = new SqlCommand())
{
string cmdString = Scripts.SqlUpdateHeightMap;
comm.Connection = sqlCon;
comm.CommandText = cmdString;
comm.Parameters.AddWithValue("@Id", heightmapModel.Id);
comm.Parameters.AddWithValue("@ProjectName", heightmapModel.ProjectName);
comm.Parameters.AddWithValue("@HighLevelBrightness", heightmapModel.HighLevelBrightness);
comm.Parameters.AddWithValue("@LowLevelBrightness", heightmapModel.LowLevelBrightness);
comm.Parameters.AddWithValue("@NSlices", heightmapModel.NSlices);
comm.Parameters.AddWithValue("@MaxSlices", heightmapModel.MaxSlices);
comm.Parameters.AddWithValue("@Repeats", heightmapModel.Repeats);
comm.Parameters.AddWithValue("@NSlicesTexture", heightmapModel.NSlicesTexture);
comm.Parameters.AddWithValue("@BorderSize", heightmapModel.BorderSize);
comm.Parameters.AddWithValue("@PictureWidth", heightmapModel.PictureWidth);
try
{
sqlCon.Open();
comm.ExecuteNonQuery();
}
catch (SqlException e)
{
// do something with the exception
// don't hide it
}
}
}
return true;
}
}
}