using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Big.Lito.Data.DataModel;
using Big.Lito.Data.Sql;
namespace Big.Lito.Data.DataAccess
{
using System.Data;
using System.Data.SqlClient;
class ProgressSQL : ConnectionSQL, IProgressSQL
{
///
/// Method to get all club members
///
/// Data table
public DataRow GetProgressById(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.sqlGetProgressById;
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 all club members
///
/// Data table
public DataRow GetProgressByName(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.sqlGetProgressByName;
comm.Connection = sqlCon;
comm.CommandText = cmdString;
comm.Parameters.AddWithValue("@ProgressName", 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 get all club members
///
/// Data table
public DataTable GetAllProgress()
{
DataTable dataTable = new DataTable();
return dataTable;
}
///
/// Method to create new member
///
/// club member model
/// true or false
public bool AddProgress(ProgressModel progress)
{
return true;
}
///
/// Method to update club member details
///
/// club member
///
public bool UpdateProgress(ProgressModel progress)
{
string connectionString = this.ConnectionString;
using (SqlConnection sqlCon = new SqlConnection(connectionString))
{
using (SqlCommand comm = new SqlCommand())
{
string cmdString = Scripts.SqlUpdateProgressByName;
comm.Connection = sqlCon;
comm.CommandText = cmdString;
comm.Parameters.AddWithValue("@name", progress.ProgressName);
comm.Parameters.AddWithValue("@start", progress.MinValue);
comm.Parameters.AddWithValue("@end", progress.MaxValue);
comm.Parameters.AddWithValue("@val", progress.CurValue);
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 DeleteProgress(int id)
{
string connectionString = this.ConnectionString;
using (SqlConnection sqlCon = new SqlConnection(connectionString))
{
using (SqlCommand comm = new SqlCommand())
{
string cmdString = Scripts.SqlDeleteProgress;
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;
}
}
}