Professional Documents
Culture Documents
Prog 3
Prog 3
categoriesBLL.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AnyStore.BLL
{
class categoriesBLL
{
public int id { get; set; }
public string title { get; set; }
public string description { get; set; }
public DateTime added_date { get; set; }
public int added_by { get; set; }
}
}
DeaCustBLL.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AnyStore.BLL
{
class DeaCustBLL
{
public int id { get; set; }
public string type { get; set; }
public string name { get; set; }
public string email { get; set; }
public string contact { get; set; }
public string address { get; set; }
public DateTime added_date { get; set; }
public int added_by { get; set; }
}
}
loginBLL.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AnyStore.BLL
{
class loginBLL
{
public string username { get; set; }
public string password { get; set; }
public string user_type { get; set; }
}
}
productsBLL.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AnyStore.BLL
{
class productsBLL
{
//Getters and Setters for product module
public int id { get; set; }
public string name { get; set; }
public string category { get; set; }
public string description { get; set; }
public decimal rate { get; set; }
public decimal qty { get; set; }
public DateTime added_date { get; set; }
public int added_by { get; set; }
}
}
transactionDetailBLL.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AnyStore.BLL
{
class transactionDetailBLL
{
public int id { get; set; }
public int product_id { get; set; }
public decimal rate { get; set; }
public decimal qty { get; set; }
public decimal total { get; set; }
public int dea_cust_id { get; set; }
public DateTime added_date { get; set; }
public int added_by { get; set; }
}
}
transactionsBLL.cs
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AnyStore.BLL
{
class transactionsBLL
{
public int id { get; set; }
public string type { get; set; }
public int dea_cust_id { get; set; }
public decimal grandTotal { get; set; }
public DateTime transaction_date { get; set; }
public decimal tax { get; set; }
public decimal discount { get; set; }
public int added_by { get; set; }
public DataTable transactionDetails { get; set; }
}
}
userBLL.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AnyStore.BLL
{
class userBLL
{
public int id { get; set; }
public string first_name { get; set; }
public string last_name { get; set; }
public string email { get; set; }
public string username { get; set; }
public string password { get; set; }
public string contact { get; set; }
public string address { get; set; }
public string gender { get; set; }
public string user_type { get; set; }
public DateTime added_date { get; set; }
public int added_by { get; set; }
}
}
FOLDER DAL
categoriesDAL.cs
using AnyStore.BLL;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AnyStore.DAL
{
class categoriesDAL
{
/*Static String Method for Database Connection String*/
static string myconnstrng =
ConfigurationManager.ConnectionStrings["connstrng"].ConnectionString;
try
{
/*Writing SQL Query to get all the data from Database*/
string sql = "SELECT * FROM tbl_categories";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
return dt;
}
#endregion
#region Insert New Category
public bool Insert(categoriesBLL c)
{
/*Creating A BOolean Variable and set its default value to false */
bool isSucces = false;
/*Connectin to Database*/
SqlConnection conn = new SqlConnection(myconnstrng);
try
{
/*Writing Wuery to add new category*/
string sql = "INSERT INTO tbl_categories (title, description, added_date,
added_by) VALUES (@title, @description, @added_date, @added_by) ";
/*Creating SQL Command to pass values in our query*/
SqlCommand cmd = new SqlCommand(sql, conn);
//Passing Values through parameter
cmd.Parameters.AddWithValue("@title", c.title);
cmd.Parameters.AddWithValue("@description", c.description);
cmd.Parameters.AddWithValue("@added_date", c.added_date);
cmd.Parameters.AddWithValue("added_by", c.added_by);
//If the Query is executed successfully then its value will be greater than 0 else it
will be less than 0
if(rows > 0)
{
isSucces = true;
}
else
{
isSucces = false;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
return isSucces;
}
#endregion
#region Update Method
public bool Update(categoriesBLL c)
{
//Creating Boolean variable and set its default value to false
bool isSuccess = false;
try
{
//Query to Update Category
string sql = "UPDATE tbl_categories SET title=@title, description=@description,
added_date=@added_date, added_by=@added_by WHERE id=@id";
//Database Connecrtion
conn.Open();
//Create Int cariable to execute
int rows = cmd.ExecuteNonQuery();
//if the query is successsfully executed then value will be greater then zero
if(rows >0)
{
isSuccess = true;
}
else
{
isSuccess = false;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
return isSuccess;
}
#endregion
#region Delete Category Method
public bool Delete(categoriesBLL c)
{
//Create a Boolean variable and set its value to false
bool isSuccess = false;
SqlConnection conn = new SqlConnection(myconnstrng);
try
{
//SQL Query to delete databes
string sql = "DELETE tbl_categories WHERE id=@id";
//Open SqlConnestion
conn.Open();
if(rows > 0)
{
isSuccess = true;
}
else
{
isSuccess = false;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
return isSuccess;
}
#endregion
#region Method for Search Functionality
public DataTable Search(string keywords)
{
SqlConnection conn = new SqlConnection(myconnstrng);
//Creating Data Table to hold the data from database temporarily
DataTable dt = new DataTable();
try
{
//SQl query to search vcategories from database
string sql = "SELECT * FROM tbl_categories WHERE id LIKE '%" + keywords +
"%' OR title LIKE '%" + keywords + "%' OR description LIKE '%" + keywords + "%' ";
//Creatig SQL command to execute the Query
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
return dt;
}
#endregion
}
}
DeaCustDAL.cs
using AnyStore.BLL;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AnyStore.DAL
{
class DeaCustDAL
{
//Static String Method for db conn
static string myconnstrng =
ConfigurationManager.ConnectionStrings["connstrng"].ConnectionString;
try
{
string sql = "SELECT * FROM tbl_dea_cust";
return dt;
}
#endregion
#region Insert Method to Add details of Dealer or Customer
public bool Insert(DeaCustBLL dc)
{
SqlConnection conn = new SqlConnection(myconnstrng);
try
{
string sql = "INSERT INTO tbl_dea_cust (type, name, email, contact, address,
added_date, added_by) VALUES (@type, @name, @email, @contact, @address,
@added_date, @added_by)";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.AddWithValue("@type", dc.type);
cmd.Parameters.AddWithValue("@name", dc.name);
cmd.Parameters.AddWithValue("@email", dc.email);
cmd.Parameters.AddWithValue("contact", dc.contact);
cmd.Parameters.AddWithValue("@address", dc.address);
cmd.Parameters.AddWithValue("@added_date", dc.added_date);
cmd.Parameters.AddWithValue("@added_by", dc.added_by);
conn.Open();
if(rows>0)
{
isSuccess = true;
}
else
{
isSuccess = false;
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
return isSuccess;
}
#endregion
#region Update Method for Dealer and Customer Module
public bool Update(DeaCustBLL dc)
{
SqlConnection conn = new SqlConnection(myconnstrng);
bool isSuccess = false;
try
{
string sql = "UPDATE tbl_dea_cust SET type=@type, name=@name,
email=@email, address=@address, added_date=@added_date, added_by=@added_by
WHERE id=@id";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.AddWithValue("@type", dc.type);
cmd.Parameters.AddWithValue("@name", dc.name);
cmd.Parameters.AddWithValue("@email", dc.email);
cmd.Parameters.AddWithValue("@contact", dc.contact);
cmd.Parameters.AddWithValue("@address", dc.address);
cmd.Parameters.AddWithValue("@added_date", dc.added_date);
cmd.Parameters.AddWithValue("@added_by", dc.added_by);
cmd.Parameters.AddWithValue("@id", dc.id);
conn.Open();
return isSuccess;
}
#endregion
#region Delete Method for Dealer and Customer Module
public bool Delete(DeaCustBLL dc)
{
SqlConnection conn = new SqlConnection(myconnstrng);
try
{
string sql = "DELETE FROM tbl_dea_cust WHERE id=@id";
conn.Open();
int rows = cmd.ExecuteNonQuery();
if(rows > 0)
{
isSuccess = true;
}
else
{
isSuccess = false;
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
return isSuccess;
}
#endregion
#region Search Method fro Dealer and Customer Module
public DataTable Search(string keyword)
{
SqlConnection conn = new SqlConnection(myconnstrng);
try
{
string sql = "SELECT * FROM tbl_dea_cust WHERE id LIKE '%" + keyword +
"%' OR type LIKE '%" + keyword + "%' OR name LIKE '%" + keyword + "%' ";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
return dt;
}
#endregion
#region Method to Search Dealer or Customer for Transaction Module
public DeaCustBLL SearchDealerCustomerForTransaction(string keyword)
{
//Create an object for DeaCustBLL classs
DeaCustBLL dc = new DeaCustBLL();
//Create db conn
SqlConnection conn = new SqlConnection(myconnstrng);
try
{
string sql = "SELECT name, email, contact, address from tbl_dea_cust WHERE id
LIKE '%"+keyword+ "%' OR name LIKE '%" + keyword + "%' ";
if (dt.Rows.Count > 0)
{
dc.name = dt.Rows[0]["name"].ToString();
dc.email = dt.Rows[0]["email"].ToString();
dc.contact = dt.Rows[0]["contact"].ToString();
dc.address = dt.Rows[0]["address"].ToString();
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
return dc;
}
#endregion
#region Method to get ID Of The Dealer or Customer based on Name
public DeaCustBLL GetDeaCustIDFromName(string Name)
{
//first create an object of deacust BLL and return it
DeaCustBLL dc = new DeaCustBLL();
//sql conn
SqlConnection conn = new SqlConnection(myconnstrng);
DataTable dt = new DataTable();
try
{
string sql = "SELECT id FROM tbl_dea_cust WHERE name '" + Name + "' ";
SqlDataAdapter adapter = new SqlDataAdapter(sql, conn);
conn.Open();
if(dt.Rows.Count>0)
{
dc.id = int.Parse(dt.Rows[0]["id"].ToString());
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
return dc;
}
#endregion
}
}
loginDAL.cs
using AnyStore.BLL;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AnyStore.DAL
{
class loginDAL
{
/*Static string to Connect Database*/
static string myconstrng =
ConfigurationManager.ConnectionStrings["connstrng"].ConnectionString;
/*Connecting to Database*/
SqlConnection conn = new SqlConnection(myconstrng);
try
{
/*SQL Query to check login*/
string sql = "SELECT * FROM tbl_users WHERE username=@username AND
password=@password AND user_type=@user_type";
cmd.Parameters.AddWithValue("@username", loginBLL.username);
cmd.Parameters.AddWithValue("@password", loginBLL.password);
cmd.Parameters.AddWithValue("@user_type",loginBLL.user_type);
adapter.Fill(dt);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
return isSuccess;
}
}
}
productsDAL.cs
using AnyStore.BLL;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AnyStore.DAL
{
class productsDAL
{
//Creating STATI String Method for DB Connection
static string myconnstrng =
ConfigurationManager.ConnectionStrings["connstrng"].ConnectionString;
try
{
//Writing rhw Query to Select all the products from Database
String sql = "SELECT * FROM tbl_products";
adapter.Fill(dt);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
return dt;
}
#endregion
#region Method to Insert Product in database
public bool Insert(productsBLL p)
{
//Creating bool variable and set its default value to false
bool isSuccess = false;
SqlConnection conn = new SqlConnection(myconnstrng);
try
{
//SQL query to insert product into db
String sql = "INSERT INTO tbl_products(name, category, description, rate, qty,
added_date, added_by) VALUES (@name, @category, @description, @rate, @qty,
@added_date, @added_by)";
conn.Open();
if(rows >0)
{
isSuccess = true;
}
else
{
isSuccess = false;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
return isSuccess;
}
#endregion
#region Method to Update Product in Database
conn.Open();
if(rows > 0)
{
isSuccess = true;
}
else
{
isSuccess = false;
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
return isSuccess;
}
#endregion
#region Method to Delete Product from Database
try
{
String sql = "DELETE FROM tbl_products WHERE id=@id";
cmd.Parameters.AddWithValue("@id", p.id);
conn.Open();
int rows = cmd.ExecuteNonQuery();
if(rows > 0)
{
isSuccess = true;
}
else
{
isSuccess = false;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
return isSuccess;
}
#endregion
#region SEARCH Method for Product Module
public DataTable Search(string keywords)
{
SqlConnection conn = new SqlConnection(myconnstrng);
//Creating DataTable to hold value from db
DataTable dt = new DataTable();
try
{
string sql = "SELECT * FROM tbl_products WHERE id LIKE '%" + keywords +
"%' OR name LIKE '%" + keywords + "%' OR category LIKE '%" + keywords + "%'";
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
conn.Open();
adapter.Fill(dt);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
return dt;
}
#endregion
#region Method to Search Product in Transaction Module
public productsBLL GetProductsForTransaction(string keyword)
{
productsBLL p = new productsBLL();
SqlConnection conn = new SqlConnection(myconnstrng);
DataTable dt = new DataTable();
try
{
string sql = "SELECT name, rate, qty FROM tbl_products WHERE id LIKE '%" +
keyword + "%' OR name LIKE '%" + keyword + "%' ";
SqlDataAdapter adapter = new SqlDataAdapter(sql, conn);
conn.Open();
adapter.Fill(dt);
if(dt.Rows.Count>0)
{
p.name = dt.Rows[0]["name"].ToString();
p.rate = decimal.Parse(dt.Rows[0]["rate"].ToString());
p.qty = decimal.Parse(dt.Rows[0]["qty"].ToString());
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
return p;
}
#endregion
#region Method to Get ProductID based on Product Name
public productsBLL GetProductIDFromName(string ProductName)
{
//first create an object of deacust BLL and return it
productsBLL p = new productsBLL();
//sql conn
SqlConnection conn = new SqlConnection(myconnstrng);
DataTable dt = new DataTable();
try
{
string sql = "SELECT id FROM tbl_products WHERE name '" + ProductName + "'
";
SqlDataAdapter adapter = new SqlDataAdapter(sql, conn);
conn.Open();
if (dt.Rows.Count > 0)
{
p.id = int.Parse(dt.Rows[0]["id"].ToString());
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
return p;
}
#endregion
#region Method To Get Current Quantity from The Database Based on Product ID
public decimal GetProductQty(int ProductID)
{
SqlConnection conn = new SqlConnection(myconnstrng);
decimal qty = 0;
DataTable dt = new DataTable();
try
{
string sql = "SELECT qty FROM tbl_products WHERE id = " + ProductID;
if(dt.Rows.Count>0)
{
qty = decimal.Parse(dt.Rows[0]["qty"].ToString());
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
return qty;
}
#endregion
#region Method To Update Quantity
public bool UpdateQuantity(int ProductID, decimal Qty)
{
bool success = false;
SqlConnection conn = new SqlConnection(myconnstrng);
try
{
string sql = "UPDATE tbl_products SET qty=@qty WHERE id=@id";
return success;
}
#endregion
#region Method To Increase Product
public bool IncreaseProduct(int ProductID, decimal IncreaseQty)
{
bool success = false;
try
{
decimal currentQty = GetProductQty(ProductID);
#endregion
}
}
transactionDAL.cs
using AnyStore.BLL;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AnyStore.DAL
{
class transactionDAL
{
//Create a connection string var
static string myconnstrng =
ConfigurationManager.ConnectionStrings["connstrng"].ConnectionString;
cmd.Parameters.AddWithValue("@type", t.type);
cmd.Parameters.AddWithValue("@dea_cust_id", t.dea_cust_id);
cmd.Parameters.AddWithValue("@grandTotal", t.grandTotal);
cmd.Parameters.AddWithValue("@transaction_date", t.transaction_date);
cmd.Parameters.AddWithValue("@tax", t.tax);
cmd.Parameters.AddWithValue("@discount", t.discount);
cmd.Parameters.AddWithValue("@added_by", t.added_by);
conn.Open();
//If the Query is executed sucessfully then the value will not be null else it will be
null
if(o!=null)
{
transactionID = int.Parse(o.ToString());
isSuccess = true;
}
else
{
isSuccess = false;
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
return isSuccess;
}
#endregion
#region Method To Display All The Transaction
public DataTable DisplayAllTransactions()
{
SqlConnection conn = new SqlConnection(myconnstrng);
DataTable dt = new DataTable();
try
{
string sql = "SELECT * FROM tbl_transactions";
return dt;
}
#endregion
#region Method To Display Transaction Based On Transaction Type
public DataTable DisplayTransactionByType(string type)
{
SqlConnection conn = new SqlConnection(myconnstrng);
try
{
string sql = "SELECT * FROM tbl_transactions WHERE type ='" + type + "' ";
conn.Open();
adapter.Fill(dt);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
return dt;
}
#endregion
}
transactionDetailDAL.cs
using AnyStore.BLL;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AnyStore.DAL
{
class transactionDetailDAL
{
static string myconnstrng =
ConfigurationManager.ConnectionStrings["connstrng"].ConnectionString;
try
{
string sql = "INSERT INTO tbl_transaction_detail (product_id, rate, qty, total,
dea_cust_id, added_date, added_by) VALUES (@product_id, @rate, @qty, @total,
@dea_cust_id, @added_date, @added_by)";
cmd.Parameters.AddWithValue("@product_id", td.product_id);
cmd.Parameters.AddWithValue("@rate", td.rate);
cmd.Parameters.AddWithValue("@qty", td.qty);
cmd.Parameters.AddWithValue("@total", td.total);
cmd.Parameters.AddWithValue("@dea_cust_id", td.dea_cust_id);
cmd.Parameters.AddWithValue("@added_date", td.added_date);
cmd.Parameters.AddWithValue("@added_by", td.added_by);
conn.Open();
if(rows>0)
{
isSuccess = true;
}
else
{
isSuccess = false;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
return isSuccess;
}
#endregion
}
}
userDAL.cs
using AnyStore.BLL;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AnyStore.DAL
{
class userDAL
{
static string myconnstrng =
ConfigurationManager.ConnectionStrings["connstrng"].ConnectionString;
}
catch(Exception ex)
{
/*Throw Message if any error occurs*/
MessageBox.Show(ex.Message);
}
finally
{
/*closing connection*/
conn.Close();
}
/*return the value in datatable*/
return dt;
}
#endregion
#region Insert Data in Database
try
{
String sql = "INSERT INTO tbl_users (first_name, last_name, email, username,
password, contact, address, gender, user_type, added_date, added_by) VALUES
(@first_name, @last_name, @email, @username, @password, @contact, @address,
@gender, @user_type, @added_date, @added_by)";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.AddWithValue("@first_name", u.first_name);
cmd.Parameters.AddWithValue("@last_name", u.last_name);
cmd.Parameters.AddWithValue("@email", u.email);
cmd.Parameters.AddWithValue("@username", u.username);
cmd.Parameters.AddWithValue("@password", u.password);
cmd.Parameters.AddWithValue("@contact", u.contact);
cmd.Parameters.AddWithValue("@address", u.address);
cmd.Parameters.AddWithValue("@gender", u.gender);
cmd.Parameters.AddWithValue("@user_type", u.user_type);
cmd.Parameters.AddWithValue("@added_date", u.added_date);
cmd.Parameters.AddWithValue("@added_by", u.added_by);
conn.Open();
int rows = cmd.ExecuteNonQuery();
/*If the query is executed Successfully then the value to rows will be greater than 0
else it will be less than 0*/
if(rows > 0)
{
/*query successful*/
isSuccess = true;
}
else
{
/*Query failed*/
isSuccess = false;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
return isSuccess;
}
#endregion
#region Update data in Database
public bool Update(userBLL u)
{
bool isSuccess = false;
SqlConnection conn = new SqlConnection(myconnstrng);
try
{
string sql = "UPDATE tbl_users SET first_name=@first_name,
last_name=@last_name, email=@email, username=@username, password=@password,
contact=@contact, address=@address, gender=@gender, user_type=@user_type,
added_date=@added_date, added_by=@added_by WHERE id=@id";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.AddWithValue("@first_name", u.first_name);
cmd.Parameters.AddWithValue("@last_name", u.last_name);
cmd.Parameters.AddWithValue("@email", u.email);
cmd.Parameters.AddWithValue("@username", u.username);
cmd.Parameters.AddWithValue("@password", u.password);
cmd.Parameters.AddWithValue("@contact", u.contact);
cmd.Parameters.AddWithValue("@address", u.address);
cmd.Parameters.AddWithValue("@gender", u.gender);
cmd.Parameters.AddWithValue("@user_type", u.user_type);
cmd.Parameters.AddWithValue("@added_date", u.added_date);
cmd.Parameters.AddWithValue("@added_by", u.added_by);
cmd.Parameters.AddWithValue("@id", u.id);
conn.Open();
}
#endregion
#region Delete Data from Database
}
#endregion
#region Search User on Database usingKeywords
public DataTable Search(string keywords)
{
/* Static Method to connect Database */
SqlConnection conn = new SqlConnection(myconnstrng);
/*To hold the data from database*/
DataTable dt = new DataTable();
try
{
/*SQL Query to Get Data from database*/
String sql = "SELECT * FROM tbl_users WHERE id LIKE '%" +keywords+ "%'
OR first_name LIKE '%" +keywords+ "%' OR last_name LIKE '%"+keywords+"%' OR
username LIKE '%"+keywords+"%' ";
/*For exucuting Command*/
SqlCommand cmd = new SqlCommand(sql, conn);
/*Getting data from database*/
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
/*Database connection open*/
conn.Open();
/*fill data in our datatable*/
adapter.Fill(dt);
}
catch (Exception ex)
{
/*Throw Message if any error occurs*/
MessageBox.Show(ex.Message);
}
finally
{
/*closing connection*/
conn.Close();
}
/*return the value in datatable*/
return dt;
}
#endregion
#region Getting User ID from Username
public userBLL GetIDFromUsername (string username)
{
userBLL u = new userBLL();
SqlConnection conn = new SqlConnection(myconnstrng);
DataTable dt = new DataTable();
try
{
string sql="SELECT id FROM tbl_users WHERE username='"+ username + "'";
adapter.Fill(dt);
if(dt.Rows.Count>0)
{
u.id = int.Parse(dt.Rows[0]["id"].ToString());
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
return u;
}
#endregion
}
}
FOLDER UI FORME
frmAdminDashboard.cs
using AnyStore.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AnyStore
{
public partial class frmAdminDashboard : Form
{
public frmAdminDashboard()
{
InitializeComponent();
}
frmCategories.cs
using AnyStore.BLL;
using AnyStore.DAL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AnyStore.UI
{
public partial class frmCategories : Form
{
public frmCategories()
{
InitializeComponent();
}
//If the category is inserted successfully then the value of the success will be true else
it will be false
if(success == true)
{
//New category inserted
MessageBox.Show("New Category Inserted Successfully.");
Clear();
//Refresh data grid view
DataTable dt = dal.Select();
dgvCategories.DataSource = dt;
}
else
{
//failed
MessageBox.Show("Failed to Insert New Category.");
}
}
public void Clear()
{
txtCategoryID.Text = "";
txtTitle.Text = "";
txtDescription.Text = "";
txtSearch.Text = "";
}
}
else
{
MessageBox.Show("Failed to update category");
}
}
else
{
MessageBox.Show("Failed to delete category!");
}
}
else
{
DataTable dt = dal.Select();
dgvCategories.DataSource = dt;
}
}
}
}
frmDeaCust.cs
using AnyStore.BLL;
using AnyStore.DAL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AnyStore.UI
{
public partial class frmDeaCust : Form
{
public frmDeaCust()
{
InitializeComponent();
}
}
public void Clear()
{
txtDeaCustID.Text = "";
txtName.Text = "";
txtEmail.Text = "";
txtContact.Text = "";
txtAddress.Text = "";
txtSearch.Text = "";
txtDeaCustID.Text = dgvDeaCust.Rows[rowIndex].Cells[0].Value.ToString();
cmbDeaCust.Text = dgvDeaCust.Rows[rowIndex].Cells[1].Value.ToString();
txtName.Text = dgvDeaCust.Rows[rowIndex].Cells[2].Value.ToString();
txtEmail.Text = dgvDeaCust.Rows[rowIndex].Cells[3].Value.ToString();
txtContact.Text = dgvDeaCust.Rows[rowIndex].Cells[4].Value.ToString();
txtAddress.Text = dgvDeaCust.Rows[rowIndex].Cells[5].Value.ToString();
}
if (success == true)
{
MessageBox.Show("Product successfully deleted!");
Clear();
DataTable dt = dcDal.Select();
dgvDeaCust.DataSource = dt;
}
else
{
MessageBox.Show("Failed to Delete Product!");
}
}
if(keyword!=null)
{
DataTable dt = dcDal.Search(keyword);
dgvDeaCust.DataSource = dt;
}
else
{
DataTable dt = dcDal.Select();
dgvDeaCust.DataSource = dt;
}
}
//Getting the ID to Logged in user and passign its value in dealer or customer module
string loggedUsr = frmLogin.loggedIn;
userBLL usr = uDal.GetIDFromUsername(loggedUsr);
dc.added_by = usr.id;
if(success==true)
{
MessageBox.Show("Dealer or Customer Updated Successfully");
Clear();
DataTable dt = dcDal.Select();
dgvDeaCust.DataSource = dt;
}
else
{
MessageBox.Show("Failed to Update Dealer or Customer.");
}
}
}
}
frmLogin.cs
using AnyStore.BLL;
using AnyStore.DAL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AnyStore.UI
{
public partial class frmLogin : Form
{
public frmLogin()
{
InitializeComponent();
}
}
break;
case "User":
{
frmUserDashboard user = new frmUserDashboard();
user.Show();
this.Hide();
}
break;
default:
{
/*Display an error message*/
MessageBox.Show("Invlaid User Type.");
}
break;
}
}
else
{
MessageBox.Show("Login Failed. Try Again");
}
}
}
}
frmProducts.cs
using AnyStore.BLL;
using AnyStore.DAL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AnyStore.UI
{
public partial class frmProducts : Form
{
public frmProducts()
{
InitializeComponent();
}
p.added_by = usr.id;
}
else
{
MessageBox.Show("Failed to Add New Product");
}
}
public void Clear()
{
txtID.Text = "";
txtName.Text = "";
txtDescription.Text = "";
txtRate.Text = "";
txtSearch.Text = "";
}
p.id = int.Parse(txtID.Text);
p.name = txtName.Text;
p.category = cmbCategory.Text;
p.description = txtDescription.Text;
p.rate = decimal.Parse(txtRate.Text);
p.added_date = DateTime.Now;
p.added_by = usr.id;
if (success == true)
{
MessageBox.Show("Product successfully deleted!");
Clear();
DataTable dt = pdal.Select();
dgvProducts.DataSource = dt;
}
else
{
MessageBox.Show("Failed to Delete Product!");
}
}
if(keywords!=null)
{
//Search the products
DataTable dt = pdal.Search(keywords);
dgvProducts.DataSource = dt;
}
else
{
//Display all the products
DataTable dt = pdal.Select();
dgvProducts.DataSource = dt;
}
}
}
}
frmPurchaseAndSales.cs
using AnyStore.BLL;
using AnyStore.DAL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Transactions;
using System.Windows.Forms;
namespace AnyStore.UI
{
public partial class frmPurchaseAndSales : Form
{
public frmPurchaseAndSales()
{
InitializeComponent();
}
txtName.Text = dc.name;
txtEmail.Text = dc.email;
txtContact.Text = dc.contact;
txtAddress.Text = dc.address;
if(keyword=="")
{
txtProductName.Text = "";
txtInventory.Text = "";
txtRate.Text = "";
txtQty.Text = "";
return;
}
productsBLL p = pDAL.GetProductsForTransaction(keyword);
txtProductName.Text = p.name;
txtInventory.Text = p.qty.ToString();
txtRate.Text = p.rate.ToString();
}
//Show in dgv
dgvAddedProducts.DataSource = transactionDT;
//displax sub
txtSubTotal.Text = subTotal.ToString();
//clear tx6
txtSearchProduct.Text = "";
txtProductName.Text = "";
txtInventory.Text = "0.00";
txtRate.Text = "0.00";
txtQty.Text = "0.00";
}
}
if(value=="")
{
MessageBox.Show("Please Add Discount First");
}
else
{
//get the discount id decimal value
decimal subTotal = decimal.Parse(txtSubTotal.Text);
decimal discount = decimal.Parse(txtDiscount.Text);
txtGrandTotal.Text = grandTotal.ToString();
}
}
txtGrandTotal.Text = grandTotalWithVAT.ToString();
}
}
transaction.type = lblTop.Text;
//get the id of dealer or cuszomer
//lets get name of the d or c first
string deaCustName = txtName.Text;
DeaCustBLL dc = dcDAL.GetDeaCustIDFromName(deaCustName);
transaction.dea_cust_id = dc.id;
transaction.grandTotal = Math.Round(decimal.Parse(txtGrandTotal.Text),2);
transaction.transaction_date = DateTime.Now;
transaction.tax = decimal.Parse(txtVat.Text);
transaction.discount = decimal.Parse(txtDiscount.Text);
string username = frmLogin.loggedIn;
userBLL u = uDAL.GetIDFromUsername(username);
transaction.added_by = u.id;
transaction.transactionDetails = transactionDT;
transactionDetail.product_id = p.id;
transactionDetail.rate = decimal.Parse(transactionDT.Rows[i][1].ToString());
transactionDetail.qty = decimal.Parse(transactionDT.Rows[i][2].ToString());
transactionDetail.total = Math.Round(decimal.Parse(transactionDT.Rows[i]
[3].ToString()),2);
transactionDetail.dea_cust_id = dc.id;
transactionDetail.added_date = DateTime.Now;
transactionDetail.added_by = u.id;
if (success == true)
{
scope.Complete();
MessageBox.Show("Transaction Completed Successfully!");
dgvAddedProducts.DataSource = null;
dgvAddedProducts.Rows.Clear();
txtSearch.Text = "";
txtName.Text = "";
txtEmail.Text = "";
txtContact.Text = "";
txtAddress.Text = "";
txtSearchProduct.Text = "";
txtProductName.Text = "";
txtInventory.Text = "0";
txtRate.Text = "0";
txtQty.Text = "0";
txtSubTotal.Text = "0";
txtDiscount.Text = "0";
txtVat.Text = "0";
txtGrandTotal.Text = "0";
txtPaidAmount.Text = "0";
txtReturnAmount.Text = "0";
}
else
{
MessageBox.Show("Transaction Failed!");
}
}
}
}
frmTransactions.cs
using AnyStore.DAL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AnyStore.UI
{
public partial class frmTransactions : Form
{
public frmTransactions()
{
InitializeComponent();
}
DataTable dt = tdal.DisplayTransactionByType(type);
dgvTransactions.DataSource = dt;
}
frmUserDashboard.cs
using AnyStore.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AnyStore
{
public partial class frmUserDashboard : Form
{
public frmUserDashboard()
{
InitializeComponent();
}
//Set a public static method to specify whether the form is purchase or sales
public static string transactionType;
private void frmUserDashboard_FormClosed(object sender, FormClosedEventArgs e)
{
}
}
}
frmUsers.cs
using AnyStore.BLL;
using AnyStore.DAL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AnyStore.UI
{
public partial class frmUsers : Form
{
public frmUsers()
{
InitializeComponent();
}
u.first_name = txtFirstName.Text;
u.last_name = txtLastName.Text;
u.email = txtEmail.Text;
u.username = txtUsername.Text;
u.password = txtPassword.Text;
u.contact = txtContact.Text;
u.address = txtAddress.Text;
u.gender = cmbGender.Text;
u.user_type = cmbUserType.Text;
u.added_date = DateTime.Now;
}
DataTable dt = dal.Select();
dgvUsers.DataSource = dt;
}
private void clear()
{
txtUserID.Text = "";
txtFirstName.Text = "";
txtLastName.Text = "";
txtUsername.Text = "";
txtPassword.Text = "";
txtContact.Text = "";
txtAddress.Text = "";
txtEmail.Text = "";
cmbGender.Text = "";
cmbUserType.Text = "";
/*if data is updated successfully then the value of success will be true or false*/
if(success ==true)
{
MessageBox.Show("User successfully updated");
clear();
}
else
{
MessageBox.Show("Failed to update user");
}
/*Refreshing data grid view*/
DataTable dt = dal.Select();
dgvUsers.DataSource = dt;
DataTable dt = dal.Select();
dgvUsers.DataSource = dt;
}
Program.cs
using AnyStore.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AnyStore
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new frmLogin());
}
}
}