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
{
///
/// Method to get club member by Id
///
/// member id
/// Data row
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;
}
///
/// Method to get project by name
///
/// project name
/// Data row
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;
}
///
/// Method to get all club members
///
/// Data table
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;
}
///
/// Method to get all club members
///
/// Data table
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;
}
///
/// Method to get all club members
///
/// Data table
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;
}
///
/// Method to add new member
///
/// club member model
/// true or false
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;
}
///
/// Method to get all club members
///
/// Data table
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;
}
///
/// Method to update project
///
/// project
/// true / false
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;
}
///
/// Method to update project
///
/// project
/// true / false
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;
}
///
/// Method to update project
///
/// project
/// true / false
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;
}
///
/// Method to delete a club member
///
/// member id
/// true / false
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;
}
///
/// Method to delete a club member
///
/// member id
/// true / false
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;
}
///
/// Method to delete a club member
///
/// member id
/// true / false
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;
}
}
}