using System; using System.Windows.Forms; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Data.DataAccess { using System.Data; using System.Data.SqlClient; using Data.Sql; using Data.DataModel; class LayerSQL : ConnectionSQL, ILayerSQL { /// /// Method to get club member by Id /// /// member id /// Data row public DataRow GetLayerById(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.sqlGetLayerById; 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 GetLayerByNameTechnology(string name, string technology) { DataTable dataTable = new DataTable(); DataRow dataRow; string connectionString = this.ConnectionString; using (SqlConnection sqlCon = new SqlConnection(connectionString)) { using (SqlCommand comm = new SqlCommand()) { string cmdString = Scripts.sqlGetLayerByNameTechnology; comm.Connection = sqlCon; comm.CommandText = cmdString; comm.Parameters.AddWithValue("@LayerName", name); comm.Parameters.AddWithValue("@Technology", technology); 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 GetLayerByName(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.sqlGetLayerByName; comm.Connection = sqlCon; comm.CommandText = cmdString; comm.Parameters.AddWithValue("@LayerName", 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 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 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(); return cnt; } /// /// Method to add new member /// /// club member model /// true or false public bool AddLayer(LayerModel layer) { string connectionString = this.ConnectionString; using (SqlConnection sqlCon = new SqlConnection(connectionString)) { using (SqlCommand comm = new SqlCommand()) { string cmdString = Scripts.SqlInsertLayer; comm.Connection = sqlCon; comm.CommandText = cmdString; comm.Parameters.AddWithValue("@LayerName", layer.LayerName); comm.Parameters.AddWithValue("@Order", layer.Order); comm.Parameters.AddWithValue("@TechnologyName", layer.TechnologyName); comm.Parameters.AddWithValue("@OpticalSchema", layer.OpticalSchema); comm.Parameters.AddWithValue("@ProjectId", layer.ProjectId); comm.Parameters.AddWithValue("@LayerLeft", layer.LayerLeft); comm.Parameters.AddWithValue("@LayerTop", layer.LayerTop); comm.Parameters.AddWithValue("@LayerWidth", layer.LayerWidth); comm.Parameters.AddWithValue("@LayerHeight", layer.LayerHeight); comm.Parameters.AddWithValue("@ArcWidth", layer.ArcWidth); comm.Parameters.AddWithValue("@RadiusMax", layer.RadiusMax); comm.Parameters.AddWithValue("@Step", layer.Step); comm.Parameters.AddWithValue("@SourceFilePath", layer.SourceFilePath); comm.Parameters.AddWithValue("@AnglesFilePath", layer.AnglesFilePath); 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 returns last created project Id /// /// Project Id public DataRow GetLastLayer() { DataTable dataTable = new DataTable(); DataRow dataRow; string connectionString = this.ConnectionString; using (SqlConnection sqlCon = new SqlConnection(connectionString)) { using (SqlCommand comm = new SqlCommand()) { string cmdString = Scripts.SqlGetLastLayer; 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 layer /// /// layer /// true / false public bool UpdateLayer(LayerModel layer) { string connectionString = this.ConnectionString; using (SqlConnection sqlCon = new SqlConnection(connectionString)) { using (SqlCommand comm = new SqlCommand()) { string cmdString = Scripts.SqlUpdateLayer; comm.Connection = sqlCon; comm.CommandText = cmdString; comm.Parameters.AddWithValue("@Id", layer.Id); comm.Parameters.AddWithValue("@Order", layer.Order); comm.Parameters.AddWithValue("@LayerName", layer.LayerName); comm.Parameters.AddWithValue("@TechnologyName", layer.TechnologyName); comm.Parameters.AddWithValue("@OpticalSchema", layer.OpticalSchema); comm.Parameters.AddWithValue("@ProjectId", layer.ProjectId); comm.Parameters.AddWithValue("@ArcWidth", layer.ArcWidth); comm.Parameters.AddWithValue("@LayerLeft", layer.LayerLeft); comm.Parameters.AddWithValue("@LayerTop", layer.LayerTop); comm.Parameters.AddWithValue("@LayerWidth", layer.LayerWidth); comm.Parameters.AddWithValue("@LayerHeight", layer.LayerHeight); comm.Parameters.AddWithValue("@RadiusMax", layer.RadiusMax); comm.Parameters.AddWithValue("@Step", layer.Step); comm.Parameters.AddWithValue("@SourceFilePath", layer.SourceFilePath); comm.Parameters.AddWithValue("@AnglesFilePath", layer.AnglesFilePath); try { sqlCon.Open(); comm.ExecuteNonQuery(); } catch (SqlException e) { MessageBox.Show( e.Message, "Exception!", //Resources.System_Error_Message_Title, MessageBoxButtons.OK, MessageBoxIcon.Error); // do something with the exception // don't hide it } } } return true; } /// /// Method to update layer /// /// layer /// true / false public bool DeleteLayer(LayerModel layer) { string connectionString = this.ConnectionString; using (SqlConnection sqlCon = new SqlConnection(connectionString)) { using (SqlCommand comm = new SqlCommand()) { string cmdString = Scripts.SqlDeleteLayer; comm.Connection = sqlCon; comm.CommandText = cmdString; comm.Parameters.AddWithValue("@Id", layer.Id); try { sqlCon.Open(); comm.ExecuteNonQuery(); } catch (SqlException e) { MessageBox.Show( e.Message, "Exception!", //Resources.System_Error_Message_Title, MessageBoxButtons.OK, MessageBoxIcon.Error); // do something with the exception // don't hide it } } } return true; } /// /// Service method to get project by Id /// /// project id /// Data row public DataRow GetColorProfileByLayerId(int layerId) { DataTable dataTable = new DataTable(); DataRow dataRow; string connectionString = this.ConnectionString; using (SqlConnection sqlCon = new SqlConnection(connectionString)) { using (SqlCommand comm = new SqlCommand()) { string cmdString = Scripts.SqlGetLayerColorProfiles; comm.Connection = sqlCon; comm.CommandText = cmdString; comm.Parameters.AddWithValue("@LayerId", layerId); 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 layer /// /// layer /// true / false public bool DeleteColorProfile(LayerModel layer) { string connectionString = this.ConnectionString; using (SqlConnection sqlCon = new SqlConnection(connectionString)) { using (SqlCommand comm = new SqlCommand()) { string cmdString = Scripts.SqlDeleteColorProfileByLayerId; comm.Connection = sqlCon; comm.CommandText = cmdString; comm.Parameters.AddWithValue("@LayerId", layer.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; } } }