๐ŸŽฏ .NET 8 ยท Windows Forms ยท SQL Server

MobileShop

A desktop retail application for selling mobile phones โ€” featuring product browsing, shopping cart, checkout, user authentication, and an admin dashboard backed by SQL Server.

10+
Source Files
5
DB Tables
30+
SQL Queries
2
User Roles

Technology Stack

Core technologies powering the application

๐ŸชŸ

Windows Forms

Classic desktop UI framework

โšก

.NET 8

Target: net8.0-windows

๐Ÿ—„๏ธ

SQL Server Express

Local .\SQLEXPRESS instance

๐Ÿ”Œ

System.Data.SqlClient

ADO.NET data access

๐ŸŽจ

GDI+ Imaging

Product image rendering

๐Ÿ”

Session Management

Static Session holder class

System Architecture

How the pieces connect โ€” from UI forms to the database

PRESENTATION (WinForms) BUSINESS / LOGIC DATA (SQL Server) Form1 Main / Products LoginForm Auth CheckoutForm Orders AdminForm Management DetailsForm Product Info RegisterForm Sign-up Session (Static) UserId ยท UserName ยท Role SqlClient ยท ADO.NET SQL Queries MobileShop DB

Project Files

Every source file and what it does

๐Ÿ“„ Program.cs entry

Application entry point. Launches the main form.

  • Application.Run(new Form1())
๐Ÿ“„ Session.cs utility

Static session holder shared across forms.

  • UserId (int)
  • UserName (string)
  • Role (string)
๐Ÿ–ผ๏ธ Form1.cs form

Main UI โ€” product listing, search, sort, cart grid.

  • LoadProducts(search, sort)
  • Add_Click โ†’ Cart insert/update
  • RefreshCartSummary()
  • RefreshCartGrid()
๐Ÿ” LoginForm.cs form

Email + password authentication.

  • Validates against Users table
  • Populates Session on success
  • Links to Register / Forgot
๐Ÿ“ RegisterForm.cs form

New user registration with role 'Customer'.

  • Name, Email, Phone, Password
  • INSERT INTO Users
๐Ÿ”‘ ForgotPasswordForm.cs form

Multi-step password recovery flow.

  • Verify email โ†’ Verify phone
  • Update password
๐Ÿ“ฑ ProductDetailsForm.cs form

Single product detail view with specs.

  • Fetches by Id
  • Add to cart (mirrors Form1)
๐Ÿ’ณ CheckoutForm.cs form

Order placement โ€” COD or bKash online.

  • Creates Order record
  • Writes OrderItems
  • Decrements stock
  • Clears cart
โš™๏ธ AdminForm.cs form

Admin dashboard for products & orders.

  • CRUD products
  • View orders
  • Image upload support
โœ… OrderSuccessForm.cs form

Confirmation screen after placing an order.

๐Ÿ“‹ *.Designer.cs generated

Auto-generated UI control definitions for each form.

Database Schema

Inferred ER diagram from SQL usage in code

๐Ÿ‘ค Users ๐Ÿ”‘ Id (int) PK Name (nvarchar) Email (nvarchar) Phone (nvarchar) โš  Password (plaintext!) Role (Customer/Admin) ๐Ÿ“ฑ Products ๐Ÿ”‘ Id (int) PK Name (nvarchar) Brand (nvarchar) Model (nvarchar) Price (decimal) Discount (decimal?) Stock (int) ImagePath / Specs ๐Ÿ›’ Cart ๐Ÿ”‘ Id (int) PK ๐Ÿ”— UserId (FK โ†’ Users) ๐Ÿ”— ProductId (FK โ†’ Products) Quantity (int) ๐Ÿ“ฆ Orders ๐Ÿ”‘ Id (int) PK ๐Ÿ”— UserId (FK) CustomerName / Phone Address (nvarchar) TotalAmount (decimal) PaymentMethod TransactionId ๐Ÿงพ OrderItems ๐Ÿ”‘ Id (int) PK ๐Ÿ”— OrderId (FK) ๐Ÿ”— ProductId (FK) Quantity (int) Price (decimal) 1 : N 1 : N 1 : N 1 : N 1 : N

User Flows

Step-by-step journeys through the application

๐Ÿ” Login Flow

1
Enter email + password
2
SELECT * FROM Users WHERE Email=@email AND Password=@pass
3
Set Session.UserId / UserName / Role
4
Redirect to Form1 (main screen)

๐Ÿ›’ Add to Cart

1
Click "Add" on a product
2
Check login (Session.UserId)
3
SELECT Quantity FROM Cart WHERE UserId=@uid AND ProductId=@pid
4
If exists โ†’ UPDATE Quantity+1 ยท Else โ†’ INSERT
5
Refresh cart summary + grid

๐Ÿ’ณ Checkout Flow

1
Review cart + enter address
2
Select COD or bKash
3
INSERT INTO Orders (OUTPUT INSERTED.Id)
4
For each cart item โ†’ INSERT OrderItems
5
UPDATE Products SET Stock = Stock - qty
6
DELETE FROM Cart WHERE UserId=@uid
7
Show OrderSuccessForm

โš™๏ธ Admin Product CRUD

1
Open AdminForm (Role = 'Admin')
2
Load products + orders
3
INSERT / UPDATE / DELETE Products
4
Browse image files locally
5
Parse discount strings (% suffix)

SQL Queries by File

Every query extracted from source code, grouped by file

-- Load products with optional search/sort SELECT Id, Name, Price, Discount, ImagePath FROM Products [WHERE Name LIKE @s] [ORDER BY ...]
SELECT Quantity FROM Cart WHERE UserId = @uid AND ProductId = @pid
UPDATE Cart SET Quantity = Quantity + 1 WHERE UserId = @uid AND ProductId = @pid
INSERT INTO Cart (UserId, ProductId, Quantity) VALUES (@uid, @pid, 1)
-- Cart total with discount applied SELECT SUM(p.Price * (1 - ISNULL(p.Discount,0)/100.0) * c.Quantity) FROM Cart c JOIN Products p ON c.ProductId = p.Id WHERE c.UserId = @uid
SELECT SUM(Quantity) FROM Cart WHERE UserId = @uid
SELECT p.Id AS ProductId, p.Name, c.Quantity, (p.Price * (1 - ISNULL(p.Discount,0)/100.0)) AS Price, (...) AS Total FROM Cart c JOIN Products p ON c.ProductId = p.Id WHERE c.UserId = @uid
SELECT * FROM Users WHERE Email = @email AND Password = @pass
INSERT INTO Users (Name, Email, Phone, Password, Role) VALUES (@name, @email, @phone, @pass, 'Customer')
-- Step 1: verify email exists SELECT * FROM Users WHERE Email = @email
-- Step 2: verify phone matches SELECT * FROM Users WHERE Email = @email AND Phone = @phone
-- Step 3: update password UPDATE Users SET Password = @pass WHERE Email = @email
SELECT * FROM Products WHERE Id = @id
SELECT Quantity FROM Cart WHERE UserId = @uid AND ProductId = @pid
INSERT INTO Cart (UserId, ProductId, Quantity) VALUES (@uid, @pid, 1)
UPDATE Cart SET Quantity = Quantity + 1 WHERE UserId = @uid AND ProductId = @pid
SELECT Name, Phone FROM Users WHERE Id = @id
SELECT p.Id, p.Name, c.Quantity, (p.Price * (1 - ISNULL(p.Discount,0)/100.0)) AS Price, (...) AS Total FROM Cart c JOIN Products p ON c.ProductId = p.Id WHERE c.UserId = @uid
-- โš ๏ธ Uses string concatenation (security risk) INSERT INTO Orders (UserId, CustomerName, Phone, Address, TotalAmount, PaymentMethod, TransactionId) OUTPUT INSERTED.Id VALUES (...)
SELECT ProductId, Quantity FROM Cart WHERE UserId = {Session.UserId}
INSERT INTO OrderItems (OrderId, ProductId, Quantity, Price) VALUES (orderId, pid, qty, (SELECT Price * (1 - ISNULL(Discount, 0) / 100.0) FROM Products WHERE Id = pid))
UPDATE Products SET Stock = Stock - qty WHERE Id = pid
DELETE FROM Cart WHERE UserId = {Session.UserId}
SELECT * FROM Products
SELECT * FROM Orders
INSERT INTO Products (Name, Brand, Model, Price, Discount, Stock, ImagePath, Specifications) VALUES (@...)
UPDATE Products SET ... WHERE Id = @id
DELETE FROM Products WHERE Id = @id

Security & Maintenance Notes

Issues identified during code review

๐Ÿ”ด Plaintext Passwords

Passwords are stored and compared as raw strings in the Users table. Use bcrypt/Argon2 with per-user salt.

๐Ÿ”ด SQL Injection in CheckoutForm

Queries orderQ, cartQ, itemQ, stockQ, delQ are built via string concatenation. Replace with SqlParameter.

๐ŸŸก Missing Input Validation

Discount parsing supports '%' suffix but other inputs (email format, phone length) aren't consistently validated.

๐ŸŸก Connection String Hardcoded

The connection string is duplicated across files. Move to appsettings.json or ConfigurationManager.

๐Ÿ”ต Good: using/Dispose Pattern

Most code correctly uses using blocks for SqlConnection and SqlCommand.

๐Ÿ”ต Good: Parameterized Queries (mostly)

Form1, LoginForm, RegisterForm, and AdminForm use parameters correctly โ€” only CheckoutForm needs fixing.