Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

NAME: AHMAD RAMZAN

ARID-NO: 18-ARID-2843
using System;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace Contacts
{
public partial class ContactList : Form
{
int[] rates = new int[4];
int total_units = 0;

public ContactList()
{
InitializeComponent();
}

public string conString = @"Data Source= DESKTOP-1E9C7H3 ;Initial


Catalog=Talaldb;Integrated Security=True";

private void btn_Click(object sender, EventArgs e)


{
SqlConnection connection = new SqlConnection(conString);
connection.Open();

if (connection.State == System.Data.ConnectionState.Open)
{
string query = "SELECT u_name, u_cnic, c_units FROM Data_schema
where id = 1";
SqlCommand cmd = new SqlCommand(query, connection);
cmd.Connection = connection;

using (SqlDataReader sdr = cmd.ExecuteReader())


{
sdr.Read();
label1.Text = sdr["u_name"].ToString();
label2.Text = sdr["u_cnic"].ToString();
label3.Text = sdr["c_units"].ToString();
total_units = Convert.ToInt32(sdr["total_units"]);

MessageBox.Show("Details!");
}
}

private void button1_Click_1(object sender, EventArgs e)


{
if (total_units == 0)
{
MessageBox.Show("Click On Get Details First!");
}else
{

SqlConnection connection = new SqlConnection(conString);


connection.Open();

if (connection.State == System.Data.ConnectionState.Open)
{
string query = "SELECT [1_100_units], [101_300_units],
[301_500_units], [500_so_on_units] FROM calculation_schema";
SqlCommand cmd = new SqlCommand(query, connection);
cmd.Connection = connection;

using (SqlDataReader sdr = cmd.ExecuteReader())


{
sdr.Read();
rates[0] = Convert.ToInt32(sdr["1_100_units"]);
rates[1] = Convert.ToInt32(sdr["101_300_units"]);
rates[2] = Convert.ToInt32(sdr["301_500_units"]);
rates[3] = Convert.ToInt32(sdr["500_so_on_units"]);
}

if (total_units >= 0 && total_units <= 100)


result.Text = (rates[0] * total_units).ToString();
else if (total_units >= 101 && total_units <= 300)
result.Text = (rates[1] * total_units).ToString();
else if (total_units >= 300 && total_units <= 500)
result.Text = (rates[2] * total_units).ToString();
else
result.Text = (rates[3] * total_units).ToString();

MessageBox.Show("Total Bill!");
}
}
}

/* ----------------------------------------------------------------------- */

private void label1_Click(object sender, EventArgs e)


{

private void dataGridView1_CellContentClick(object sender,


DataGridViewCellEventArgs e)
{

private void pictureBox1_Click(object sender, EventArgs e)


{

private void test_Click(object sender, EventArgs e)


{
SqlConnection SqlCon = new SqlConnection(conString);
SqlCon.Open();
if (SqlCon.State == System.Data.ConnectionState.Open)
{
MessageBox.Show("Connection to db is successful!");
}
else
{
MessageBox.Show("UU");
}
SqlCon.Close();
}

private void panel1_Paint(object sender, PaintEventArgs e)


{

}
}

You might also like