BigLitho/Large.Lito.Database/Make3_Treko3D/Data/DataAccess/ProjectSQL.cs

569 lines
21 KiB
C#

using System;
using System.Windows.Forms;
namespace Data.DataAccess
{
using System.Data;
using System.Data.SqlClient;
using Data.Sql;
using Data.DataModel;
class ProjectSQL : ConnectionSQL, IProjectSQL
{
/// <summary>
/// Method to get club member by Id
/// </summary>
/// <param name="id">member id</param>
/// <returns>Data row</returns>
public DataRow GetProjectById(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.sqlGetProjectById;
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
MessageBox.Show(
e.Message,
"Exception!",
//Resources.System_Error_Message_Title,
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
// 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 GetProjectByName(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.sqlGetProjectByName;
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
MessageBox.Show(
e.Message,
"Exception!",
//Resources.System_Error_Message_Title,
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
// Get the datarow from the table
dataRow = dataTable.Rows.Count > 0 ? dataTable.Rows[0] : null;
}
}
return dataRow;
}
/// <summary>
/// Method to get all club members
/// </summary>
/// <returns>Data table</returns>
public DataTable GetAllProjects()
{
DataTable dataTable = new DataTable();
string connectionString = this.ConnectionString;
SqlConnection sqlCon = new SqlConnection(connectionString);
sqlCon.Open();
//string commandString = "SELECT * FROM ProjectSettings";
string commandString = Scripts.SqlGetAllProjects;
SqlCommand sqlCmd = new SqlCommand(commandString, sqlCon);
//SqlDataReader dr = sqlCmd.ExecuteReader();
SqlDataAdapter sd = new SqlDataAdapter();
sd.SelectCommand = sqlCmd;
sd.Fill(dataTable);
sqlCon.Close();
sqlCon.Dispose();
sqlCmd.Dispose();
return dataTable;
}
/// <summary>
/// Method to get all club members
/// </summary>
/// <returns>Data table</returns>
public int GetCountOfLayers(int projectId)
{
string connectionString = this.ConnectionString;
SqlConnection sqlCon = new SqlConnection(connectionString);
sqlCon.Open();
//string commandString = "SELECT * FROM ProjectSettings";
string commandString = Scripts.SqlGetCountOfLayers;
SqlCommand sqlCmd = new SqlCommand(commandString, sqlCon);
sqlCmd.Parameters.AddWithValue("@ProjectId", projectId);
int cnt = (int)sqlCmd.ExecuteScalar();
sqlCon.Close();
sqlCon.Dispose();
sqlCmd.Dispose();
return cnt;
}
/// <summary>
/// Method to get all club members
/// </summary>
/// <returns>Data table</returns>
public DataTable GetProjectLayers(int projectId)
{
DataTable dataTable = new DataTable();
string connectionString = this.ConnectionString;
SqlConnection sqlCon = new SqlConnection(connectionString);
sqlCon.Open();
//string commandString = "SELECT * FROM ProjectSettings";
string commandString = Scripts.SqlGetProjectLayers;
SqlCommand sqlCmd = new SqlCommand(commandString, sqlCon);
sqlCmd.Parameters.AddWithValue("@ProjectId", projectId);
//SqlDataReader dr = sqlCmd.ExecuteReader();
SqlDataAdapter sd = new SqlDataAdapter();
sd.SelectCommand = sqlCmd;
sd.Fill(dataTable);
return dataTable;
}
/// <summary>
/// Method to add new member
/// </summary>
/// <param name="project">club member model</param>
/// <returns>true or false</returns>
public bool AddProject(ProjectModel project)
{
//int projectId;
string connectionString = this.ConnectionString;
using (SqlConnection sqlCon = new SqlConnection(connectionString))
{
using (SqlCommand comm = new SqlCommand())
{
string cmdString = Scripts.SqlInsertProject;
comm.Connection = sqlCon;
comm.CommandText = cmdString;
comm.Parameters.AddWithValue("@ProjectName", project.ProjectName);
comm.Parameters.AddWithValue("@OutPath", project.OutPath);
comm.Parameters.AddWithValue("@Created", project.CreatedDate);
comm.Parameters.AddWithValue("@LastUpdated", project.LastUpdatedDate);
comm.Parameters.AddWithValue("@HologramWidth", project.HologramWidth);
comm.Parameters.AddWithValue("@HologramHeight", project.HologramHeight);
comm.Parameters.AddWithValue("@FrameWidth", project.FrameWidth);
comm.Parameters.AddWithValue("@FrameHeight", project.FrameHeight);
comm.Parameters.AddWithValue("@FrameResolutionX", project.FrameResolutionX);
comm.Parameters.AddWithValue("@FrameResolutionY", project.FrameResolutionY);
comm.Parameters.AddWithValue("@GrayRangeHigh", project.GrayRangeHigh);
comm.Parameters.AddWithValue("@GrayRangeLow", project.GrayRangeLow);
try
{
sqlCon.Open();
comm.ExecuteNonQuery();
//projectId = (int)comm.ExecuteScalar();
}
catch (SqlException e)
{
// do something with the exception
// don't hide it
MessageBox.Show(
e.Message,
"Exception!",
//Resources.System_Error_Message_Title,
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
finally
{
sqlCon.Close();
//sqlCon.Dispose();
//comm.Dispose();
}
}
}
return true;
}
/// <summary>
/// Method to get all club members
/// </summary>
/// <returns>Data table</returns>
public DataRow GetLastProject()
{
DataTable dataTable = new DataTable();
DataRow dataRow;
string connectionString = this.ConnectionString;
using (SqlConnection sqlCon = new SqlConnection(connectionString))
{
using (SqlCommand comm = new SqlCommand())
{
string cmdString = Scripts.SqlGetLastProject;
comm.Connection = sqlCon;
comm.CommandText = cmdString;
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
MessageBox.Show(
e.Message,
"Exception!",
//Resources.System_Error_Message_Title,
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
// 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 UpdateProjectDefault(ProjectModel project)
{
string connectionString = this.ConnectionString;
using (SqlConnection sqlCon = new SqlConnection(connectionString))
{
using (SqlCommand comm = new SqlCommand())
{
string cmdString = Scripts.SqlUpdateProjectDefault;
comm.Connection = sqlCon;
comm.CommandText = cmdString;
comm.Parameters.AddWithValue("@Id", project.Id);
comm.Parameters.AddWithValue("@ProjectName", project.ProjectName);
comm.Parameters.AddWithValue("@OutPath", project.OutPath);
comm.Parameters.AddWithValue("@LastUpdated", project.LastUpdatedDate);
comm.Parameters.AddWithValue("@HologramWidth", project.HologramWidth);
comm.Parameters.AddWithValue("@HologramHeight", project.HologramHeight);
comm.Parameters.AddWithValue("@FrameWidth", project.FrameWidth);
comm.Parameters.AddWithValue("@FrameHeight", project.FrameHeight);
comm.Parameters.AddWithValue("@FrameResolutionX", project.FrameResolutionX);
comm.Parameters.AddWithValue("@FrameResolutionY", project.FrameResolutionY);
comm.Parameters.AddWithValue("@GrayRangeHigh", project.GrayRangeHigh);
comm.Parameters.AddWithValue("@GrayRangeLow", project.GrayRangeLow);
try
{
sqlCon.Open();
comm.ExecuteNonQuery();
}
catch (SqlException e)
{
// do something with the exception
// don't hide it
MessageBox.Show(
e.Message,
"Exception!",
//Resources.System_Error_Message_Title,
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
return true;
}
/// <summary>
/// Method to update project
/// </summary>
/// <param name="project">project</param>
/// <returns>true / false</returns>
public bool UpdateProject(ProjectModel project)
{
string connectionString = this.ConnectionString;
using (SqlConnection sqlCon = new SqlConnection(connectionString))
{
using (SqlCommand comm = new SqlCommand())
{
string cmdString = Scripts.SqlUpdateProject;
comm.Connection = sqlCon;
comm.CommandText = cmdString;
comm.Parameters.AddWithValue("@Id", project.Id);
comm.Parameters.AddWithValue("@ProjectName", project.ProjectName);
comm.Parameters.AddWithValue("@OutPath", project.OutPath);
comm.Parameters.AddWithValue("@LastUpdated", project.LastUpdatedDate);
comm.Parameters.AddWithValue("@HologramWidth", project.HologramWidth);
comm.Parameters.AddWithValue("@HologramHeight", project.HologramHeight);
comm.Parameters.AddWithValue("@FrameWidth", project.FrameWidth);
comm.Parameters.AddWithValue("@FrameHeight", project.FrameHeight);
comm.Parameters.AddWithValue("@FrameResolutionX", project.FrameResolutionX);
comm.Parameters.AddWithValue("@FrameResolutionY", project.FrameResolutionY);
comm.Parameters.AddWithValue("@GrayRangeHigh", project.GrayRangeHigh);
comm.Parameters.AddWithValue("@GrayRangeLow", project.GrayRangeLow);
try
{
sqlCon.Open();
comm.ExecuteNonQuery();
}
catch (SqlException e)
{
// do something with the exception
// don't hide it
MessageBox.Show(
e.Message,
"Exception!",
//Resources.System_Error_Message_Title,
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
return true;
}
/// <summary>
/// Method to update project
/// </summary>
/// <param name="project">project</param>
/// <returns>true / false</returns>
public bool UpdateProjectOutPath(int projectId, string outPath) //UpdateProject(project);
{
string connectionString = this.ConnectionString;
using (SqlConnection sqlCon = new SqlConnection(connectionString))
{
using (SqlCommand comm = new SqlCommand())
{
string cmdString = Scripts.SqlUpdateProjectOutPath;
comm.Connection = sqlCon;
comm.CommandText = cmdString;
comm.Parameters.AddWithValue("@Id", projectId);
comm.Parameters.AddWithValue("@OutPath", outPath);
try
{
sqlCon.Open();
comm.ExecuteNonQuery();
}
catch (SqlException e)
{
// do something with the exception
// don't hide it
MessageBox.Show(
e.Message,
"Exception!",
//Resources.System_Error_Message_Title,
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
return true;
}
/// <summary>
/// Method to delete a club member
/// </summary>
/// <param name="id">member id</param>
/// <returns>true / false</returns>
public bool DeleteProject(int id)
{
string connectionString = this.ConnectionString;
using (SqlConnection sqlCon = new SqlConnection(connectionString))
{
using (SqlCommand comm = new SqlCommand())
{
string cmdString = Scripts.SqlDeleteProject;
comm.Connection = sqlCon;
comm.CommandText = cmdString;
comm.Parameters.AddWithValue("@Id", id);
try
{
sqlCon.Open();
comm.ExecuteNonQuery();
}
catch (SqlException e)
{
// do something with the exception
// don't hide it
MessageBox.Show(
e.Message,
"Exception!",
//Resources.System_Error_Message_Title,
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
return true;
}
/// <summary>
/// Method to delete a club member
/// </summary>
/// <param name="id">member id</param>
/// <returns>true / false</returns>
public bool DeleteProjectLayers(int projectId)
{
string connectionString = this.ConnectionString;
using (SqlConnection sqlCon = new SqlConnection(connectionString))
{
using (SqlCommand comm = new SqlCommand())
{
string cmdString = Scripts.SqlDeleteProjectLayers;
comm.Connection = sqlCon;
comm.CommandText = cmdString;
comm.Parameters.AddWithValue("@ProjectId", projectId);
try
{
sqlCon.Open();
comm.ExecuteNonQuery();
}
catch (SqlException e)
{
// do something with the exception
// don't hide it
MessageBox.Show(
e.Message,
"Exception!",
//Resources.System_Error_Message_Title,
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
return true;
}
/// <summary>
/// Method to delete a club member
/// </summary>
/// <param name="id">member id</param>
/// <returns>true / false</returns>
public bool DeleteProjectColorProfiles(int projectId)
{
string connectionString = this.ConnectionString;
using (SqlConnection sqlCon = new SqlConnection(connectionString))
{
using (SqlCommand comm = new SqlCommand())
{
string cmdString = Scripts.SqlDeleteProjectColorProfiles;
comm.Connection = sqlCon;
comm.CommandText = cmdString;
comm.Parameters.AddWithValue("@ProjectId", projectId);
try
{
sqlCon.Open();
comm.ExecuteNonQuery();
}
catch (SqlException e)
{
// do something with the exception
// don't hide it
MessageBox.Show(
e.Message,
"Exception!",
//Resources.System_Error_Message_Title,
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
return true;
}
}
}