|
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
/// <summary>
/// A class that contains the connection string
/// </summary>
public class CommonQueries
{
//A method that Gets all the cutomers from the database
public DataTable GetAllCustomers()
{
DataTable dt = new DataTable();
string sql = string.Empty;
try
{
sql = "SELECT * FROM Customers";
DAL dal = new DAL();
dt = dal.FetchData(sql);
return dt;
}
catch (System.Exception ex)
{
throw new Exception(ex.Message);
}
}
//A methods that gets all the orders per customer
//GetOrdersPerCustomer is a method with a reqiured parameter
public DataTable GetCustomerDetails(string cusid)
{
DataTable dt = new DataTable();
string sql = string.Empty;
try
{
sql = "SELECT * FROM Customers WHERE CustomerID =@id";
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@id", SqlDbType.NChar, 5);
param[0].Value = cusid;
DAL dal = new DAL();
dt = dal.FetchDataWithParam(sql, param);
return dt;
}
catch (System.Exception ex)
{
throw new Exception(ex.Message);
}
}
//A methods that Deletes the record per customer in the databae
//DeleteOrdersPerCustomer is a method with a reqiured parameter
public void DeleteCustomer(string cusid)
{
string sql = string.Empty;
try
{
sql = "DELETE FROM Customers WHERE WHERE CustomerID =@id";
SqlParameter[] param = new SqlParameter[2];
param[0] = new SqlParameter("@id", SqlDbType.NChar, 5);
param[0].Value = cusid;
DAL dal = new DAL();
dal.DeleteWithParam(sql, param);
}
catch (System.Exception ex)
{
throw new Exception(ex.Message);
}
}
//A methods that Inserts new cutomer to the database
//AddNewCustomer is a method with a reqiured parameter
public void AddNewCustomer(int id, string name, string address, string city)
{
string sql = string.Empty;
try
{
sql = " INSERT INTO Customers (CustomerID,ContactName,ContactAddress,City)VALUES (@account,@contact,@nick,@msg)";
SqlParameter[] param = new SqlParameter[4];
param[0] = new SqlParameter("@id", SqlDbType.NChar, 5);
param[1] = new SqlParameter("@name", SqlDbType.NVarChar, 30);
param[2] = new SqlParameter("@address", SqlDbType.NVarChar, 60);
param[3] = new SqlParameter("@city", SqlDbType.NVarChar, 15);
param[0].Value = id;
param[1].Value = name;
param[2].Value = address;
param[3].Value = city;
DAL dal = new DAL();
dal.InsertWithParam(sql, param);
}
catch (System.Exception ex)
{
throw new Exception(ex.Message);
}
}
}
|