//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 ProjectSQL : ConnectionSQL, IProjectSQL { /// /// 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); return dataTable; } /// /// Method to get all club members /// /// Data table public DataTable GetAllProjectsForGridView() { DataTable dataTable = new DataTable(); string connectionString = this.ConnectionString; SqlConnection sqlCon = new SqlConnection(connectionString); sqlCon.Open(); //string commandString = "SELECT * FROM ProjectSettings"; string commandString = Scripts.SqlGetAllProjectsForGridView; SqlCommand sqlCmd = new SqlCommand(commandString, sqlCon); //SqlDataReader dr = sqlCmd.ExecuteReader(); SqlDataAdapter sd = new SqlDataAdapter(); sd.SelectCommand = sqlCmd; sd.Fill(dataTable); return dataTable; } /// /// 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 } // 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 } // Get the datarow from the table dataRow = dataTable.Rows.Count > 0 ? dataTable.Rows[0] : null; } } return dataRow; } /// /// Method to add new member /// /// club member model /// true or false public bool AddProject(ProjectModel project) { string connectionString = this.ConnectionString; //DateTime dateTimeVariable = //some DateTime value, e.g. DateTime.Now; //SqlCommand cmd = new SqlCommand("INSERT INTO () VALUES (@value)", connection); //cmd.Parameters.AddWithValue("@value", dateTimeVariable); //cmd.ExecuteNonQuery(); 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("@Author", project.Author); comm.Parameters.AddWithValue("@Created", project.CreatedDate); comm.Parameters.AddWithValue("@LastUpdated", project.UpdatedDate); comm.Parameters.AddWithValue("@HomeDir", project.HomeDir); try { sqlCon.Open(); comm.ExecuteNonQuery(); } catch(SqlException e) { // do something with the exception // don't hide it } } } 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("@Author", project.Author); comm.Parameters.AddWithValue("@LastUpdated", project.UpdatedDate); comm.Parameters.AddWithValue("@HomeDir", project.HomeDir); try { sqlCon.Open(); comm.ExecuteNonQuery(); } catch (SqlException e) { // do something with the exception // don't hide it } } } return true; } /// /// Method to update project /// /// project /// true / false public bool UpdateProjectIniGen(ProjectModel project) { string connectionString = this.ConnectionString; using (SqlConnection sqlCon = new SqlConnection(connectionString)) { using (SqlCommand comm = new SqlCommand()) { string cmdString = Scripts.SqlUpdateProjectIniGen; comm.Connection = sqlCon; comm.CommandText = cmdString; comm.Parameters.AddWithValue("@Id", project.Id); comm.Parameters.AddWithValue("@LastUpdated", project.UpdatedDate); comm.Parameters.AddWithValue("@FrameWidth", project.FrameWidth); comm.Parameters.AddWithValue("@FrameHeight", project.FrameHeight); comm.Parameters.AddWithValue("@ResW", project.ResW); comm.Parameters.AddWithValue("@ResH", project.ResH); comm.Parameters.AddWithValue("@ObjName", project.ObjName); comm.Parameters.AddWithValue("@ObjW", project.ObjWidth); comm.Parameters.AddWithValue("@ObjH", project.ObjHeight); comm.Parameters.AddWithValue("@NRows", project.NRows); comm.Parameters.AddWithValue("@NCols", project.NCols); comm.Parameters.AddWithValue("@CoX", project.CoX); comm.Parameters.AddWithValue("@CoY", project.CoY); try { sqlCon.Open(); comm.ExecuteNonQuery(); } catch (SqlException e) { // do something with the exception // don't hide it } } } 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 } } } return true; } } }