0% found this document useful (0 votes)
10 views9 pages

C# Login and Customer Management Code

The document contains code for a login and customer management system using C# and SQL Server. It includes functionalities for user login, customer registration, data retrieval, updating, and deletion. Additionally, it handles order details and calculates total amounts based on user input.

Uploaded by

gamebeast6525
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views9 pages

C# Login and Customer Management Code

The document contains code for a login and customer management system using C# and SQL Server. It includes functionalities for user login, customer registration, data retrieval, updating, and deletion. Additionally, it handles order details and calculates total amounts based on user input.

Uploaded by

gamebeast6525
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Login Form

private void btnLogin_Click(object sender, EventArgs e)


{
string username = [Link];
string password = [Link];

if (username == "admin" && password == "1234")


{
DialogResult result = [Link]("Login success!",
"Success", [Link], [Link]);

if (result == [Link])
{
Form3 f3 = new Form3();
[Link]();

[Link]();
}
}
else
{
[Link]("Login not success!", "Error",
[Link], [Link]);

}
}
}
}
private void btnView_Click(object sender, EventArgs e)
{
Form4 f4 = new Form4();
[Link]();
[Link]();
}

private void btnRegister_Click(object sender, EventArgs e)


{
Form1 f1 = new Form1();
[Link]();
[Link]();
}
private void button2_Click(object sender, EventArgs e)
{

Form2 f2 = new Form2();


[Link]();
[Link]();
}

private void btnExit_Click(object sender, EventArgs e)


{
[Link]();
}

Register Customer

SqlConnection con = new SqlConnection(@"Data


Source=LAPTOP-817VRUNI\SQLEXPRESS;Initial
Catalog=ABC;Integrated Security=True;");

public Form1()
{
InitializeComponent();
}
private void btnAdd_Click(object sender, EventArgs e)
{
string gender;
if ([Link])
gender = "Male";
else
gender = "Female";

string queryinsert = "insert into customers (Customer_ID,


Name, Country, Gender) values ('" + [Link] + "', '" +
[Link] + "','" + [Link] + "','" + gender + "')";
[Link]();
SqlCommand cmd = new SqlCommand(queryinsert, con);
[Link]();
[Link]();
[Link]();
[Link]();
[Link] = "";
[Link]("Customer Saved", "Furniture Shop",
[Link], [Link]);
[Link]();
SqlDataAdapter da = new SqlDataAdapter("SELECT *
FROM customers", con);
DataTable dt = new DataTable();
[Link](dt);
[Link] = dt;
[Link]();
}

private void label3_Click(object sender, EventArgs e)


{

private void Form1_Load(object sender, EventArgs e)


{
[Link]("India");
[Link]("Sri Lanka");
[Link]("Japan");
[Link]("China");
[Link]();
SqlDataAdapter da = new SqlDataAdapter("SELECT *
FROM customers", con);
DataTable dt = new DataTable();
[Link](dt);
[Link] = dt;
[Link]();

private void btnSearch_Click(object sender, EventArgs e)


{
string queryselect = "SELECT * FROM Customers WHERE
Customer_ID = '" + [Link] + "'";
SqlCommand cmd = new SqlCommand(queryselect, con);
[Link]();
SqlDataReader dr = [Link]();

if ([Link])
{
while ([Link]())
{
string id = dr["Customer_ID"].ToString();
string name = dr["Name"].ToString();
string gender =
dr["Gender"].ToString().Trim().ToLower();
string country = dr["Country"].ToString();

[Link] = id;
[Link] = name;

if (gender == "male")
{
[Link] = true;
}
else if (gender == "female")
{
[Link] = true;
}

[Link] = country;
}
}
else
{

[Link]("Customer not found. Please check


the Customer ID.",
"Search Result",
[Link],
[Link]);

// Optionally clear the fields


[Link]();
[Link] = "";
[Link] = false;
[Link] = false;
}

[Link]();

private void dataGridView1_CellContentClick(object sender,


DataGridViewCellEventArgs e)
{

}
private void LoadData()
{
SqlDataAdapter da = new SqlDataAdapter("SELECT *
FROM customers", con);
DataTable dt = new DataTable();
[Link](dt);
[Link] = dt;
}

private void btnUpdate_Click(object sender, EventArgs e)


{

string gender;
if ([Link])
gender = "Male";
else
gender = "Female";

[Link]();
string queryupdate = "update customers set Customer_ID
= '" + [Link] + "', Name = '" + [Link] + "', Gender = '"
+ gender + "', Country = '" + [Link] + "' where
Customer_ID = '" + [Link] + "'";
SqlCommand cmd = new SqlCommand(queryupdate,
con);
[Link]();
[Link]();
[Link]();
[Link]();
[Link] = "";
[Link]("Customer Saved", "Furniture Shop",
[Link], [Link]);
[Link]();
SqlDataAdapter da = new SqlDataAdapter("SELECT *
FROM customers", con);
DataTable dt = new DataTable();
[Link](dt);
[Link] = dt;
[Link]();
}

private void btnDelete_Click(object sender, EventArgs e)


{
DialogResult result = [Link](
"Are you sure you want to delete this customer?",
"Confirm Delete",
[Link],
[Link]
);

if (result == [Link])
{

[Link]();
string querydelete = "delete from customers where
Customer_ID = '" + [Link] + "'";
SqlCommand cmd = new SqlCommand(querydelete,
con);
[Link]();
[Link]();
[Link]();
[Link]();
[Link] = "";
[Link]("Customer Deleted Successfully!",
"Furniture Shop", [Link],
[Link]);
[Link]();
SqlDataAdapter da = new SqlDataAdapter("SELECT *
FROM customers", con);
DataTable dt = new DataTable();
[Link](dt);
[Link] = dt;
[Link]();

}
}

private void btnBack_Click(object sender, EventArgs e)


{
Form3 f3 = new Form3();
[Link]();
[Link]();
}

private void cmbCountry_SelectedIndexChanged(object


sender, EventArgs e)
{

}
}
}
Order Details
SqlConnection con = new SqlConnection(@"Data Source=LAPTOP-
817VRUNI\SQLEXPRESS;Initial Catalog=ABC;Integrated Security=True;");
{
try
{

[Link]();

string queryCustomer = "SELECT * FROM Customers WHERE


Customer_ID = '" + [Link] + "'";
SqlCommand cmdCustomer = new SqlCommand(queryCustomer,
con);
//[Link]("@CustomerID",
[Link]);

SqlDataReader drCustomer = [Link]();

if ([Link]())
{
[Link] = drCustomer["Name"].ToString();

[Link]();
}
else
{
[Link]("Customer not found.");
[Link]();

}
catch (Exception ex)
{
[Link]("Error: " + [Link], "Error",
[Link], [Link]);
}
finally
{
[Link]();
}
}
}

private void button1_Click(object sender, EventArgs e)


{

int quantity = [Link]([Link]);


int price = [Link]([Link]);
int total = quantity * price;
[Link] = [Link]();
}

private void btnAddOrder_Click(object sender, EventArgs e)


{
SqlConnection con = new SqlConnection(@"Data Source=LAPTOP-
817VRUNI\SQLEXPRESS;Initial Catalog=ABC;Integrated Security=True;");
string queryinsert = "insert into tblOrders (Order_Number, Description,
Orderdate, Quantity, UnitPrice, TotalAmount,Customer_ID) values ('" +
[Link] + "','" + [Link] + "','" +
[Link] + "','" + [Link] + "' , '" + [Link] +
"','" + [Link] + "','" + [Link] + "')";
[Link]();
SqlCommand cmd = new SqlCommand(queryinsert, con);
[Link]();
[Link]();
[Link]();
[Link]();
[Link]();
[Link]();
[Link]();
[Link]();
[Link]();

[Link]("Order saved successfully!");

private void btnBack_Click(object sender, EventArgs e)


{
Form3 f3 = new Form3();
[Link]();
[Link]();

You might also like