Вы находитесь на странице: 1из 38

LAB TASK # 01:

Question # 01:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ReverseArray
{
class Program
{
static void Main(string[] args)
{
int[] array = { 22, 50, 11, 2, 49 };
foreach (int a in array)
{
Console.WriteLine(a);
}
Array.Reverse(array);
Console.WriteLine("Reversed Array : ");
foreach (int value in array)
{
Console.WriteLine(value);
}
Console.ReadLine();
}
}
}

Page 1 of 38
LAB TASK # 01:
Question # 02:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ReverseArray
{
class Program
{
static void Main(string[] args)
{

string[] bookname = new string[3];


string[] authorname = new string[3];
string[] publishername = new string[3];
int i, j = 0;
string search;

for (i = 0; i < 3; i++)


{
Console.Write("\n\nEnter book names: ");
bookname[i] = Console.ReadLine();

}
for (i = 0; i < 3; i++)
{
Console.Write("\n\nEnter author names: ");
authorname[i] = Console.ReadLine();

}
for (i = 0; i < 3; i++)
{
Console.Write("\n\nEnter publisher name:\t");
publishername[i] = Console.ReadLine();

Console.Write("\n\nEnter the name of the publisher/ author/ book to find :");


search = Console.ReadLine();

for (i = 0; i < 3; i++)


{
if (bookname[i] == search || publishername[i] == search|| authorname[i] == search )
{
Console.WriteLine( search," Name found !!");

j++;
}
}
if(j == 0)
Page 2 of 38
{
Console.WriteLine("Not Found!!!");
}
Console.ReadLine();
}
}

Page 3 of 38
LAB TASK # 02:
Class.txt:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsApplication5
{
class Product
{

public string p1()


{
string rate = "15";
return rate;
}
public double p2()
{
double rate = 25;
return rate;
}
public double p3()
{
double rate = 30;
return rate;
}
public string p4()
{
string rate = "50";
return rate;
}
public double p5()
{
double rate = 60;
return rate;
}
public double p6()
{
double rate = 18;
return rate;
}
public double p7()
{
double rate = 20;
return rate;
}
public double p8()
{
double rate = 36;
return rate;
}
public double p9()
{
Page 4 of 38
double rate = 22;
return rate;
}
}
}
Source Code:
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;
using WindowsFormsApplication5;
using System.IO;

namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Product p = new Product();

List<String> list = new List<string>();


List<int> sum = new List<int>();
int count = 0;
int total;

private void Form1_Load(object sender, EventArgs e)


{
total = sum.Sum();
listView.Items.Add("S.No\t Product\t Price");
list.Add("S.No\t Product\t Price");
txttotal.Text = "Total = ";

private void button1_Click(object sender, EventArgs e)


{
p.ToString();
int rate = 15;
count++;
listView.Items.Add(count.ToString()+" Prod "+rate);

list.Add(count.ToString() + " Prod " + rate);

sum.Add(rate);
Page 5 of 38
total = sum.Sum();

if (total == null)
{
txttotal.Text = Convert.ToString(total);
}
else
{
txttotal.Text = "Total = \t\t"+Convert.ToString(total)+" Rs";
}

private void listView_SelectedIndexChanged(object sender, EventArgs e)


{

private void btnp2_Click(object sender, EventArgs e)


{
p.ToString();
int rate = 15;
count++;
listView.Items.Add(count.ToString() + " Prod " + rate);
list.Add(count.ToString() + " Prod " + rate);
sum.Add(rate);
total = sum.Sum();
if (total == null)
{
txttotal.Text = Convert.ToString(total);
}
else
{
txttotal.Text = "Total = \t\t" + Convert.ToString(total) + " Rs";
}

private void btnp3_Click(object sender, EventArgs e)


{
p.ToString();
int rate = 25;
count++;
listView.Items.Add(count.ToString() + " Prod " + rate);
list.Add(count.ToString() + " Prod " + rate);
sum.Add(rate);
total = sum.Sum();
if (total == null)
{
txttotal.Text = Convert.ToString(total);
}
else
{
txttotal.Text = "Total = \t\t" + Convert.ToString(total) + " Rs";
}

Page 6 of 38
}

private void btnp4_Click(object sender, EventArgs e)


{
p.ToString();
int rate = 30;
count++;
listView.Items.Add(count.ToString() + " Prod " + rate);
list.Add(count.ToString() + " Prod " + rate);
sum.Add(rate);
total = sum.Sum();
if (total == null)
{
txttotal.Text = Convert.ToString(total);
}
else
{
txttotal.Text = "Total = \t\t" + Convert.ToString(total) + " Rs";
}
}

private void btnp5_Click(object sender, EventArgs e)


{
p.ToString();
int rate = 50;
count++;
listView.Items.Add(count.ToString() + " Prod " + rate);
list.Add(count.ToString() + " Prod " + rate);
sum.Add(rate);
total = sum.Sum();
if (total == null)
{
txttotal.Text = Convert.ToString(total);
}
else
{
txttotal.Text = "Total = \t\t" + Convert.ToString(total) + " Rs";
}
}

private void btnp6_Click(object sender, EventArgs e)


{
p.ToString();
int rate = 60;
count++;
listView.Items.Add(count.ToString() + " Prod " + rate);
list.Add(count.ToString() + " Prod " + rate);
sum.Add(rate);
total = sum.Sum();
if (total == null)
{
txttotal.Text = Convert.ToString(total);
}
else
{

Page 7 of 38
txttotal.Text = "Total = \t\t" + Convert.ToString(total) + " Rs";
}
}

private void btnp7_Click(object sender, EventArgs e)


{
p.ToString();
int rate = 18;
count++;
listView.Items.Add(count.ToString() + " Prod " + rate);
list.Add(count.ToString() + " Prod " + rate);
sum.Add(rate);
total = sum.Sum();
if (total == null)
{
txttotal.Text = Convert.ToString(total);
}
else
{
txttotal.Text = "Total = \t\t" + Convert.ToString(total) + " Rs";
}
}

private void btnp8_Click(object sender, EventArgs e)


{
p.ToString();
int rate = 15;
count++;
listView.Items.Add(count.ToString() + " Prod " + rate);
list.Add(count.ToString() + " Prod " + rate);
sum.Add(rate);
total = sum.Sum();
if (total == null)
{
txttotal.Text = Convert.ToString(total);
}
else
{
txttotal.Text = "Total = \t\t" + Convert.ToString(total) + " Rs";
}
}

private void btnp9_Click(object sender, EventArgs e)


{
p.ToString();
int rate = 15;
count++;
listView.Items.Add(count.ToString() + " Prod " + rate);
list.Add(count.ToString() + " Prod " + rate);
sum.Add(rate);
total = sum.Sum();
if (total == null)
{
txttotal.Text = Convert.ToString(total);
}

Page 8 of 38
else
{
txttotal.Text = "Total = \t\t" + Convert.ToString(total) + " Rs";
}
}

private void btnremove_Click(object sender, EventArgs e)


{
if (count == 0)
{
MessageBox.Show("List is empty");
}
else
{

sum.RemoveAt(count - 1);
list.RemoveAt(count - 1);
listView.Items.RemoveAt(count-1);
count--;

total = sum.Sum();

txttotal.Text = "Total = \t\t" + Convert.ToString(total) + " Rs";

}
}

private void button11_Click(object sender, EventArgs e)


{
String path = Directory.GetCurrentDirectory()+"\\Bill.txt";
if (File.Exists(path))
{
File.Delete(path);
}

list.Add("Total = \t\t" + Convert.ToString(total));


File.AppendAllLines(path, list);

}
}
}

Page 9 of 38
Page 10 of 38
Page 11 of 38
LAB TASK # 03:
Library.txt:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsApplication5
{
class Product
{

public int p1()


{
int rate = 15;
return rate;
}
public int p2()
{
int rate = 25;
return rate;
}
public int p3()
{
int rate = 30;
return rate;
}
public int p4()
{
int rate = 50;
return rate;
}
public int p5()
{
int rate = 60;
return rate;
}
public int p6()
{
int rate = 18;
return rate;
}
public int p7()
{
int rate = 20;
return rate;
}
public int p8()
{
int rate = 36;
return rate;
}
public int p9()
{
Page 12 of 38
int rate = 22;
return rate;
}
}
}
sourceCode.txt:
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;
using WindowsFormsApplication5;
using System.IO;

namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Product p = new Product();

List<String> list = new List<string>();


List<int> sum = new List<int>();
int count = 1;
int total;
int bill = 0;

private void Form1_Load(object sender, EventArgs e)


{
total = sum.Sum();
listView.Items.Add("S.No\t Product\t Price");
list.Add("S.No\t Product\t Price");
txttotal.Text = "Total = ";

private void button1_Click(object sender, EventArgs e)


{
p.ToString();
int rate = p.p1();

count++;
listView.Items.Add(Convert.ToString(count - 1) + " Prod " + rate);

list.Add(Convert.ToString(count - 1) + " Prod " + rate);

sum.Add(rate);
Page 13 of 38
total = sum.Sum();

if (total == null)
{
txttotal.Text = Convert.ToString(total);
}
else
{
txttotal.Text = "Total = \t\t" + Convert.ToString(total) + " Rs";
}

private void listView_SelectedIndexChanged(object sender, EventArgs e)


{

private void btnp2_Click(object sender, EventArgs e)


{
p.ToString();
int rate = p.p2();
count++;
listView.Items.Add(Convert.ToString(count - 1) + " Prod " + rate);
list.Add(Convert.ToString(count - 1) + " Prod " + rate);
sum.Add(rate);
total = sum.Sum();
if (total == null)
{
txttotal.Text = Convert.ToString(total);
}
else
{
txttotal.Text = "Total = \t\t" + Convert.ToString(total) + " Rs";
}

private void btnp3_Click(object sender, EventArgs e)


{
p.ToString();
int rate = p.p3();
count++;
listView.Items.Add(Convert.ToString(count - 1) + " Prod " + rate);
list.Add(Convert.ToString(count - 1) + " Prod " + rate);
sum.Add(rate);
total = sum.Sum();
if (total == null)
{
txttotal.Text = Convert.ToString(total);
}
else
{
txttotal.Text = "Total = \t\t" + Convert.ToString(total) + " Rs";
}

Page 14 of 38
}

private void btnp4_Click(object sender, EventArgs e)


{
p.ToString();
int rate = p.p4();
count++;
listView.Items.Add(Convert.ToString(count - 1) + " Prod " + rate);
list.Add(Convert.ToString(count - 1) + " Prod " + rate);
sum.Add(rate);
total = sum.Sum();
if (total == null)
{
txttotal.Text = Convert.ToString(total);
}
else
{
txttotal.Text = "Total = \t\t" + Convert.ToString(total) + " Rs";
}
}

private void btnp5_Click(object sender, EventArgs e)


{
p.ToString();
int rate = p.p5();
count++;
listView.Items.Add(Convert.ToString(count - 1) + " Prod " + rate);
list.Add(Convert.ToString(count - 1) + " Prod " + rate);
sum.Add(rate);
total = sum.Sum();
if (total == null)
{
txttotal.Text = Convert.ToString(total);
}
else
{
txttotal.Text = "Total = \t\t" + Convert.ToString(total) + " Rs";
}
}

private void btnp6_Click(object sender, EventArgs e)


{
p.ToString();
int rate = p.p6();
count++;
listView.Items.Add(Convert.ToString(count - 1) + " Prod " + rate);
list.Add(Convert.ToString(count - 1) + " Prod " + rate);
sum.Add(rate);
total = sum.Sum();
if (total == null)
{
txttotal.Text = Convert.ToString(total);
}
else
{

Page 15 of 38
txttotal.Text = "Total = \t\t" + Convert.ToString(total) + " Rs";
}
}

private void btnp7_Click(object sender, EventArgs e)


{
p.ToString();
int rate = p.p7();
count++;
listView.Items.Add(Convert.ToString(count - 1) + " Prod " + rate);
list.Add(Convert.ToString(count - 1) + " Prod " + rate);
sum.Add(rate);
total = sum.Sum();
if (total == null)
{
txttotal.Text = Convert.ToString(total);
}
else
{
txttotal.Text = "Total = \t\t" + Convert.ToString(total) + " Rs";
}
}

private void btnp8_Click(object sender, EventArgs e)


{
p.ToString();
int rate = p.p8();
count++;
listView.Items.Add(Convert.ToString(count - 1) + " Prod " + rate);
list.Add(Convert.ToString(count - 1) + " Prod " + rate);
sum.Add(rate);
total = sum.Sum();
if (total == null)
{
txttotal.Text = Convert.ToString(total);
}
else
{
txttotal.Text = "Total = \t\t" + Convert.ToString(total) + " Rs";
}
}

private void btnp9_Click(object sender, EventArgs e)


{
p.ToString();
int rate = p.p9();
count++;
listView.Items.Add(Convert.ToString(count - 1) + " Prod " + rate);
list.Add(Convert.ToString(count - 1) + " Prod " + rate);
sum.Add(rate);
total = sum.Sum();
if (total == null)
{
txttotal.Text = Convert.ToString(total);
}

Page 16 of 38
else
{
txttotal.Text = "Total = \t\t" + Convert.ToString(total) + " Rs";
}
}

private void btnremove_Click(object sender, EventArgs e)


{
if (count == 1)
{
MessageBox.Show("List is empty");
}
else
{

list.RemoveAt(1);
sum.Reverse();
sum.RemoveAt(0);
listView.Items.RemoveAt(count - 1);
count--;

total = sum.Sum();

txttotal.Text = "Total = \t\t" + Convert.ToString(total) + " Rs";

}
}

private void button11_Click(object sender, EventArgs e)


{

String path = Directory.GetCurrentDirectory() + "\\Bill.txt";


if (File.Exists(path))
{
String last = File.ReadLines(path).Last();
string[] word = last.Split();
bill = Convert.ToInt32(word[0]);

}
StreamWriter writer = new StreamWriter(path, append: true);

bill++;

writer.WriteLine("Bill No# \t\t Amount# \t\t Date#");


writer.WriteLine(bill + " \t\t"+ Convert.ToString(total) +"\t\t"+string.Format("{0:dd-MMM-yyyy hh:mm:ss tt}",
DateTime.Now));

MessageBox.Show("Bill Generated");
writer.Close();

Page 17 of 38
}
}

Page 18 of 38
Page 19 of 38
LAB TASK # 04:
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

}
double hours, sal;

private void Form1_Load(object sender, EventArgs e)


{

private void button1_Click(object sender, EventArgs e)

{
if (hours <= 8 && hours >= 21)
{

try
{

sal = hours * 150;

}
catch (FormatException ex)
{
MessageBox.Show("Not Possible");
}

}
}
}
}

Page 20 of 38
Page 21 of 38
LAB TASK # 05:
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;
using System.IO;

namespace Lab_task_5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

datagrid.DataSource = table;
table.Columns.Add("ID", typeof(int));
table.Columns.Add("Roll_No", typeof(string));
table.Columns.Add("Name", typeof(string));
table.Columns.Add("Address", typeof(string));
table.Columns.Add("Math", typeof(double));
table.Columns.Add("English", typeof(double));
table.Columns.Add("Urdu", typeof(double));
table.Columns.Add("islamiate", typeof(double));
table.Columns.Add("Pst", typeof(double));
table.Columns.Add("Total", typeof(double));
table.Columns.Add("Percentage", typeof(double));

String path = Directory.GetCurrentDirectory() + "\\Student_Data.txt";

DataTable table = new DataTable();

double Percentage, Total;


int counter=0;
List<string> list = new List<string>();
string path = Directory.GetCurrentDirectory()+"//Student_Data.txt";

private void label7_Click(object sender, EventArgs e)


{

private void label11_Click(object sender, EventArgs e)

Page 22 of 38
{

private void button1_Click(object sender, EventArgs e)


{
try
{

Total = Convert.ToDouble(txtEnglish.Text) + Convert.ToDouble(txtIslamiate.Text) +


Convert.ToDouble(txtMaths.Text) + Convert.ToDouble(txtPST.Text) + Convert.ToDouble(txtUrdu.Text);
Percentage = (Total / 500) * 100;
txtPercentage.Text = Percentage.ToString();
txtTotal.Text = Total.ToString();
counter++;
table.Rows.Add(counter, txtRoll.Text, txtName.Text, textAddress.Text, txtMaths.Text, txtEnglish.Text,
txtUrdu.Text, txtIslamiate.Text, txtPST.Text, Total, Percentage);

list.Add(counter + " " + txtRoll.Text + " " + txtName.Text + " " + datagrid.Text
+" " + txtMaths.Text + " " + txtEnglish.Text + " " + txtUrdu.Text + " "+
txtIslamiate.Text + " " + txtPST.Text + " " + txtTotal.Text + " " + txtPercentage.Text);

}catch(Exception ex)
{
MessageBox.Show(ex.Message,"Exception Error",MessageBoxButtons.OKCancel,MessageBoxIcon.Exclamation);
}

private void button3_Click(object sender, EventArgs e)


{
txtRoll.Text = txtName.Text = txtEnglish.Text = textAddress.Text = txtIslamiate.Text = txtMaths.Text =
txtPercentage.Text = txtUrdu.Text = txtPST.Text = txtTotal.Text = "";
table.Rows.Clear();
}

private void btnSearch_Click(object sender, EventArgs e)


{
if (txtSearchName.Text != null)
{

}
}

private void txtSearchName_TextChanged(object sender, EventArgs e)


{
try
{
(datagrid.DataSource as DataTable).DefaultView.RowFilter = string.Format("Name LIKE '%{0}%'",
txtSearchName.Text);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Exception Error", MessageBoxButtons.OKCancel,
MessageBoxIcon.Exclamation);

}
}
Page 23 of 38
private void txtSearchRoll_TextChanged(object sender, EventArgs e)
{
try
{

(datagrid.DataSource as DataTable).DefaultView.RowFilter = string.Format("Roll_No LIKE '%{0}%'",


txtSearchRoll.Text);
}catch(Exception ex)
{
MessageBox.Show(ex.Message, "Exception Error", MessageBoxButtons.OKCancel,
MessageBoxIcon.Exclamation);

private void button4_Click(object sender, EventArgs e)


{
try
{

if (list.Count >= 30)


{

if (File.Exists(path) == true)
{
File.AppendAllLines(path, list);
}
else
{
MessageBox.Show("File Not Exist", "Exception Error", MessageBoxButtons.OKCancel,
MessageBoxIcon.Exclamation);

}else
{
MessageBox.Show("List is Less Than 30", "Exception Error", MessageBoxButtons.OKCancel,
MessageBoxIcon.Exclamation);

}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Exception Error", MessageBoxButtons.OKCancel,
MessageBoxIcon.Exclamation);

}
}

private void btnLoad_Click(object sender, EventArgs e)


{

File.ReadAllLines(path);

StreamReader oStreamReader = new StreamReader(path);

string[] oStreamDataValues = null;


Page 24 of 38
int row = 0;

while (!oStreamReader.EndOfStream)
{

string oStreamRowData = oStreamReader.ReadLine().Trim();

if (oStreamRowData.Length > 0)
{

oStreamDataValues = oStreamRowData.Split(',');

for (int c = 0; c < 35; c++)


{

datagrid[c, row].Value = oStreamDataValues[c];

else
{
MessageBox.Show("There is no text file to read from!");

}
row++;

}
}

private void Form1_Load(object sender, EventArgs e)


{

private void button2_Click(object sender, EventArgs e)


{
txtRoll.Text = txtName.Text = textAddress.Text= txtEnglish.Text = txtIslamiate.Text = txtMaths.Text =
txtPercentage.Text = txtUrdu.Text = txtPST.Text = txtTotal.Text = "";

}
}
}

Page 25 of 38
Page 26 of 38
Page 27 of 38
Page 28 of 38
LAB TASK # 06:
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;
using System.IO;
using Microsoft.VisualBasic;
using Microsoft.VisualBasic.FileIO;

namespace Lab_task_5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

datagrid.DataSource = table;
table.Columns.Add("ID", typeof(string));
table.Columns.Add("Roll_No", typeof(string));
table.Columns.Add("Name", typeof(string));
table.Columns.Add("Address", typeof(string));
table.Columns.Add("Math", typeof(double));
table.Columns.Add("English", typeof(double));
table.Columns.Add("Urdu", typeof(double));
table.Columns.Add("islamiate", typeof(double));
table.Columns.Add("Pst", typeof(double));
table.Columns.Add("Total", typeof(double));
table.Columns.Add("Percentage", typeof(double));

String path = Directory.GetCurrentDirectory() + "\\Student_Data.txt"


}

DataTable table = new DataTable();

double Percentage, Total;


int counter=0;
List<string> list = new List<string>();
string path = Directory.GetCurrentDirectory()+"//Student_Data.txt";
private void label7_Click(object sender, EventArgs e)
{

private void label11_Click(object sender, EventArgs e)


{

private void button1_Click(object sender, EventArgs e)


{
try
{

Page 29 of 38
Total = Convert.ToDouble(txtEnglish.Text) + Convert.ToDouble(txtIslamiate.Text) +
Convert.ToDouble(txtMaths.Text) + Convert.ToDouble(txtPST.Text) + Convert.ToDouble(txtUrdu.Text);
Percentage = (Total / 500) * 100;
txtPercentage.Text = Percentage.ToString();
txtTotal.Text = Total.ToString();
counter++;
table.Rows.Add(counter, txtRoll.Text, txtName.Text, textAddress.Text, txtMaths.Text, txtEnglish.Text,
txtUrdu.Text, txtIslamiate.Text, txtPST.Text, Total, Percentage);

list.Add(counter + " " + txtRoll.Text + " " + txtName.Text + " " + datagrid.Text
+" " + txtMaths.Text + " " + txtEnglish.Text + " " + txtUrdu.Text + " "+
txtIslamiate.Text + " " + txtPST.Text + " " + txtTotal.Text + " "+
txtPercentage.Text+",");

}catch(Exception ex)
{
MessageBox.Show(ex.Message,"Exception Error",MessageBoxButtons.OKCancel,MessageBoxIcon.Exclamation);
}

private void button3_Click(object sender, EventArgs e)


{
txtRoll.Text = txtName.Text = txtEnglish.Text = textAddress.Text = txtIslamiate.Text = txtMaths.Text =
txtPercentage.Text = txtUrdu.Text = txtPST.Text = txtTotal.Text = "";
table.Rows.Clear();
}

private void btnSearch_Click(object sender, EventArgs e)


{
if (txtSearchName.Text != null)
{

}
}

private void txtSearchName_TextChanged(object sender, EventArgs e)


{
try
{
(datagrid.DataSource as DataTable).DefaultView.RowFilter = string.Format("Name LIKE '%{0}%'",
txtSearchName.Text);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Exception Error", MessageBoxButtons.OKCancel,
MessageBoxIcon.Exclamation);

}
}

private void txtSearchRoll_TextChanged(object sender, EventArgs e)


{
try
{

(datagrid.DataSource as DataTable).DefaultView.RowFilter = string.Format("Roll_No LIKE '%{0}%'",


txtSearchRoll.Text);
Page 30 of 38
}catch(Exception ex)
{
MessageBox.Show(ex.Message, "Exception Error", MessageBoxButtons.OKCancel,
MessageBoxIcon.Exclamation);

private void button4_Click(object sender, EventArgs e)


{
try
{

if (list.Count >= 30)


{

if (File.Exists(path) == true)
{
File.AppendAllLines(path, list);
}
else
{
MessageBox.Show("File Not Exist", "Exception Error", MessageBoxButtons.OKCancel,
MessageBoxIcon.Exclamation);

}else
{
MessageBox.Show("List is Less Than 30", "Exception Error", MessageBoxButtons.OKCancel,
MessageBoxIcon.Exclamation);

}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Exception Error", MessageBoxButtons.OKCancel,
MessageBoxIcon.Exclamation);

}
}

private void btnLoad_Click(object sender, EventArgs e)


{
try
{

StreamReader reader = new StreamReader(path);

int row = 0;
string line;
while ((line = reader.ReadLine()) != null)
{
string[] columns = line.Split(',');
table.Rows.Add();

for (int i = 0; i < columns.Length; i++)


{
for (int j = 0;j<row;j++)
Page 31 of 38
{
datagrid[i, row].Value = columns[i];

}
row++;
datagrid.DataSource = table;
}

/* var contents = reader.ReadToEnd().Split(new string[] {","},StringSplitOptions.None);

foreach (string gotya in contents)


{
table.Rows.Add(contents[0]);
datagrid.DataSource = gotya;
}
datagrid.DataSource = table;
reader.Close();
*/
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

private void Form1_Load(object sender, EventArgs e)


{

private void button2_Click(object sender, EventArgs e)


{
txtRoll.Text = txtName.Text = textAddress.Text= txtEnglish.Text = txtIslamiate.Text = txtMaths.Text =
txtPercentage.Text = txtUrdu.Text = txtPST.Text = txtTotal.Text = "";

}
}

Page 32 of 38
Power Point Slide:

Page 33 of 38
Lab Task # 07:-
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;
using System.Data.SqlClient;

namespace lab_task_7
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string ApplForDesci, Gender;
bool Success = false;
private void Form1_Load(object sender, EventArgs e)
{
LoadAllRecordIntoDataGridView();
}
void Insert()
{
try
{

string connstring = "Data Source=ITLAB03PC02;User ID=sa;Password=iunc123";


using (SqlConnection conn = new SqlConnection(connstring))
{
using (SqlCommand cmd = new SqlCommand("INSERT INTO STUDENT
(Name,Gender,Pre_Quali,Address,ApplForDesci,StudentID) VALUES
(@Name,@Gender,@Pre_Quali,@Address,@ApplForDesci,@StudentID)", conn))
{
conn.Open();
if (radioBBA.Checked)
{
ApplForDesci = "BBA";
}
else if (radioBSCS.Checked)
{
ApplForDesci = "BSCS";
}
else if (radioBSMS.Checked)
{
ApplForDesci = "BSMS";
}
else if (radioMSCS.Checked)
{
ApplForDesci = "MSCS";
}
else if (radioMBA.Checked)
{
ApplForDesci = "MBA";
}

Page 34 of 38
if (radioMale.Checked)
{
Gender = "Male";
}
else if (radioFemale.Checked)
{
Gender = "Female";
}
cmd.Parameters.AddWithValue("@Name", txtName.Text);
cmd.Parameters.AddWithValue("@Gender", Gender);
cmd.Parameters.AddWithValue("@Pre_Quali", txtPre.Text);
cmd.Parameters.AddWithValue("@Address", txtAddress.Text);
cmd.Parameters.AddWithValue("@ApplForDesci", ApplForDesci);
cmd.Parameters.AddWithValue("@StudentID", txtID.Text);
cmd.ExecuteNonQuery();

}
using (SqlCommand cmd = new SqlCommand("INSERT INTO stRecord
(CourseName,Grade,TeacherName,SemesterName,StudentID) VALUES
(@CourseName,@Grade,@TeacherName,@SemesterName,@StudentID)", conn))
{
cmd.Parameters.AddWithValue("@CourseName", txtCourse.Text);
cmd.Parameters.AddWithValue("@Grade", txtGrade.Text);
cmd.Parameters.AddWithValue("@TeacherName", txtTeacher.Text);
cmd.Parameters.AddWithValue("@SemesterName", txtSemester.Text);
cmd.Parameters.AddWithValue("@StudentID", txtID.Text);
cmd.ExecuteNonQuery();
conn.Close();
}
MessageBox.Show("Data Inserted Successfully", "Success", MessageBoxButtons.OK,
MessageBoxIcon.Information);
Success = true;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtID.Clear();
}
}

private void LoadAllRecordIntoDataGridView()


{
dataGridView1.DataSource = GetAllRecords();
}

private DataTable GetAllRecords()


{
DataTable dtRecords = new DataTable();

string connstring = "Data Source=ITLAB03PC02;User ID=sa;Password=iunc123";


using (SqlConnection conn = new SqlConnection(connstring))
{
using (SqlCommand cmd = new SqlCommand("SELECT
s.StudentID,s.Name,s.Pre_Quali,s.Address,s.ApplforDesci,r.CourseName,r.Grade,r.TeacherName,r.SemesterName FROM
STUDENT s LEFT JOIN stRecord r ON r.StudentID = s.StudentID ", conn))
Page 35 of 38
{
conn.Open();

SqlDataReader reader = cmd.ExecuteReader();

dtRecords.Load(reader);
dtRecords.Columns[4].ColumnName = "Apply For Descipline";
dtRecords.Columns[2].ColumnName = "Previous Qualification";
}

return dtRecords;

private void btnSave_Click(object sender, EventArgs e)


{
Insert();
LoadAllRecordIntoDataGridView();
if (Success)
{
Clear();
}

private void Clear()


{
txtID.Clear();
txtGrade.Clear();
txtCourse.Clear();
txtAddress.Clear();
txtName.Clear();
txtPre.Clear();
txtSemester.Clear();
txtTeacher.Clear();
ApplForDesci = "";
Gender = "";
}
}
}

Page 36 of 38
Lab Task 8:-
Power Point Slide:-

Page 37 of 38
Page 38 of 38

Вам также может понравиться