Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
140 views

LAB & Class Assignment Programming Advance

The document outlines a series of programming assignments for a C# Programming Language Advance course, including tasks to save and retrieve data from text files, implement SQL commands like CREATE, ALTER and DROP, perform data manipulation with INSERT, UPDATE, DELETE, and work with classes and static methods. Lab assignments provide code examples and queries to complete the objectives for each topic.

Uploaded by

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

LAB & Class Assignment Programming Advance

The document outlines a series of programming assignments for a C# Programming Language Advance course, including tasks to save and retrieve data from text files, implement SQL commands like CREATE, ALTER and DROP, perform data manipulation with INSERT, UPDATE, DELETE, and work with classes and static methods. Lab assignments provide code examples and queries to complete the objectives for each topic.

Uploaded by

Junaid Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Syed Abul Fatha Foazul Kabeer Madani

UNIVERSITY OF KARACHI
Department of Computer Science
Course – Programming Languages Advance
Teacher – Ms. Saima Ashraf
Lab Teacher – Mr. Aziz
MCS – PROGRAMME-2018 (2nd Semester)

Assignments

1|Pa ge
MCS-Previous-2018
C# Programming Language Advance Assignment Objectives
# DATE OBJECTIVE SIGNATURE

1 21 Aug 18 Save and Retrieve Data using Text File

2 28 Aug 18 Implementation of DDL commands of SQL with suitable examples [CREATE, ALTER, DROP]

3 28 Aug 18 Implementation of DML commands of SQL with suitable examples [Insert INTO table, Update
table, Delete Table]

4 07 Sep 18 Class

5 25 Sep 18 Notepad with the function of New & Open only

LAB Assignment #-01


Save and Retrieve Data using Text File
CODE
namespace AppSample

2|Pa ge
{
public partial class Form1 : Form
{
private DataText conDB;
public Form1()
{
InitializeComponent();
conDB = new DataText();
conDB.Path = "d:/abc.txt"; // dont use '\'!!
fillCombo();
}
private void fillCombo()
{
this.combo.Items.Clear();
int temp = conDB.Entries();
if (temp > 0)
{
temp--;
for (int i = 0; i <= temp; i++)
{
string name = "";
conDB.ReadEntrie(i, ref name);
if (name == "")
{
name = "<empty>";
}
this.combo.Items.Add("ID: " + i + " - " + name);
}
combo.SelectedIndex = 0;
}
}
private void button7_Click(object sender, EventArgs e)
{
int temp = conDB.Entries();
MessageBox.Show(temp.ToString());
}

private void button6_Click(object sender, EventArgs e)


{
conDB.InsertEntrie(txtName.Text,txtLastName.Text,txtPhone.Text,txtMail.Text,txtWeb.Text);
txtID.Text = Convert.ToString(conDB.Entries()-1);
fillCombo();
}

private void read(int id)


{
txtID.Text = id.ToString();
string str_name = "", str_lastname = "", str_phone = "", str_mail = "", str_web = "";

bool result = conDB.ReadEntrie(id, ref str_name, ref str_lastname, ref str_phone, ref str_mail, ref str_web);
txtName.Text = str_name;
txtLastName.Text = str_lastname;
txtPhone.Text = str_phone;
txtMail.Text = str_mail;
txtWeb.Text = str_web;
if (!result) { MessageBox.Show("Invalid record"); }
}
private void button5_Click(object sender, EventArgs e)
{
dgv.Rows.Clear();
dgv.Refresh();
string Path = @"d:/abc.txt"; // dont use '\'!!
string[] lines = File.ReadAllLines(Path);
foreach (var line in lines)
{
string[] value = line.Split(';');
dgv.Rows.Add(value);
}

private void button4_Click(object sender, EventArgs e)


{
string str_name = "", str_lastname = "", str_phone = "", str_mail = "", str_web = "";
str_name =txtName.Text ;
str_lastname =txtLastName.Text;
str_phone =txtPhone.Text;
str_mail =txtMail.Text;
str_web =txtWeb.Text;
int id = Convert.ToInt32(txtID.Text);
conDB.UpdateEntrie(id, str_name, str_lastname, str_phone, str_mail, str_web);
fillCombo();
}

private void button1_Click(object sender, EventArgs e)


{
int id = Convert.ToInt32(txtID.Text);
conDB.DeleteEntrie(id);
read(0);
fillCombo();
}

private void combo_SelectedIndexChanged(object sender, EventArgs e)


{
txtID.Text = combo.SelectedIndex.ToString();
read(Convert.ToInt32(txtID.Text));
}

private void Form1_Load(object sender, EventArgs e)


{
string Path = @"d:/abc.txt"; // dont use '\'!!
string[] lines = File.ReadAllLines(Path);
foreach (var line in lines)
{
string[] value = line.Split(';');
dgv.Rows.Add(value);
}
}

3|Pa ge
}
}

OUTPUT

4|Pa ge
LAB Assignment #-02
Implementation of DDL commands of SQL with suitable examples [CREATE, ALTER, DROP]

QUIRES
--1(a). Create Database
Create database AEI

--1(b). Creating Table


Create table Employee
(
Emp_ID INT,
Name VARCHAR(20),
Age INT,
Address CHAR(25),
Salary DECIMAL(18,2)
PRIMARY KEY(Emp_ID)
);

--Show all records from table.


Select * From Employee

--2(a). Alter
Alter Table Employee
Add Designation CHAR(20)

--2(b). Alter..Modify
Alter Table Employee
Alter Column Designation Varchar(100)

--2(c) Alter..DROP
Alter Table Employee
Drop Column Designation

--3 Drop
Drop Database AEI

5|Pa ge
Output

LAB PRACTICE ASSIGNMENT:


1. Create a table EMPLOYEE with following schema:
(Emp_no, E_name, E_address, E_ph_no, Dept_no, Dept_name,Job_id , Salary)
Create table Employee
(Emp_no INT NOT NULL, E_name VARCHAR(20), E_address CHAR(25), E_ph_no VARCHAR(50), Dept_no INT NOT
Null, Dept_name VARCHAR(20), Job_id INT NOT Null, Salary DECIMAL(18,2), PRIMARY KEY(Emp_no));
2. Add a new column; HIREDATE to the existing relation.
Alter Table Employee
Add HIREDATE date
3. Change the data type of JOB_ID from int to small int .
Alter Table Employee
Alter Column Job_id smallint
4. Modify the column width of the job field of emp table

6|Pa ge
LAB Assignment #-03
Implementation of DML commands of SQL with suitable examples [Insert INTO table,
Update table, Delete Table]

QUERIES:
INSERT INTO:

SQL SELECT Statement:

7|Pa ge
UPDATE-SET-WHERE:

DELETE FROM:

TRUNCATE:

LAB PRACTICE ASSIGNMENT:


Create a table EMPLOYEE with following schema:
(Emp_no, E_name, E_address, E_ph_no, Dept_no, Dept_name,Job_id , Salary)
Create table Employee

8|Pa ge
(Emp_no INT NOT NULL, E_name VARCHAR(20), E_address CHAR(25), E_ph_no VARCHAR(50), Dept_no INT NOT
Null, Dept_name VARCHAR(20), Job_id INT NOT Null, Salary DECIMAL(18,2), PRIMARY KEY(Emp_no));
Write SQL queries for following question:
1. Insert aleast 5 rows in the table.
INSERT INTO employee
VALUES(1,'Ahsan','PECHS','0333558978',1003,'Marketing',5004,55000)
INSERT INTO employee
VALUES(2,'Raheel','Nazimabad','0333558978',1002,'Production',5002,55000)
INSERT INTO employee
VALUES(3,'Fatha','DHA','0333558978',1001,'IT',5001,55000)
INSERT INTO employee
VALUES(4,'Rameez','Malir','0333558978',1004,'Account',5003,45000)
INSERT INTO employee
VALUES(6,'Arsalan','Gulshan','0333558978',1003,'Sales',5005,35000))
2. Display all the information of EMP table.
Select * from employee
3. Display the record of each employee who works in department “IT”.
Select * from employee where Dept_name='IT'
4. Update the city of Emp_no-12 with current city as Nagpur.
update Employee Set E_Address='Nagpur' where emp_no='3'
5. Display the details of Employee who works in department MECH.
SELECT first_name, last_name, employee_id, job_id FROM employees WHERE department_id = (SELECT
department_id FROM departments WHERE location_id = (SELECT location_id
FROM locations WHERE city ='Toronto'));
6. Delete the email_id of employee James.
update Employee Set Email_ID=' ' where e_name='James'
7. Display the complete record of employees working in SALES Department.
Select * from employee where Dept_name='IT'

9|Pa ge
LAB Assignment #-04
class Program
{
static void Main(string[] args)
{
UseStatic.show(2);
UseStatic.show(45);
UseStatic saad = new UseStatic();
saad.k();
}

}
class UseStatic
{
static int a = 3;
static int b;

static void show(int x)


{
( );
Console.WriteLine("x = " + x);
Console.WriteLine("a = " + a);
Console.WriteLine("b = " + b);

}
static{
Console.WriteLine("Static block initialized");
b=a*14;
}

void k()
{
Console.WriteLine("K constracotr ");

}
}

10 | P a g e
LAB Assignment #-05
Notepad with the function of New & Open only
namespace NotepadXPDemo
{
public partial class Notepad : Form
{
private string currFileName;
public Notepad()
{
InitializeComponent();
}

private void aboutNotepadXpToolStripMenuItem_Click(object sender, EventArgs e)


{
MessageBox.Show("All right reseved with the Author", "About Notepad XP", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}

private void newToolStripMenuItem_Click(object sender, EventArgs e)


{
MainRichTextBox.Clear();
this.Text = Path.GetFileName(currFileName) + " Untitled.txt- Notepad XP";
}

private void exitApplicationToolStripMenuItem_Click(object sender, EventArgs e)


{
Application.Exit();
}

private void openToolStripMenuItem_Click(object sender, EventArgs e)


{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "TexFiles (*.txt)|*.txt|Rich Text Format (*.rtf)|*.rtf";

DialogResult result = openFileDialog.ShowDialog();

if(result== DialogResult.OK)
{
if(Path.GetExtension(openFileDialog.FileName) == ".txt")
MainRichTextBox.LoadFile(openFileDialog.FileName, RichTextBoxStreamType.PlainText);

if (Path.GetExtension(openFileDialog.FileName) == ".rtf")
MainRichTextBox.LoadFile(openFileDialog.FileName, RichTextBoxStreamType.RichText);
this.Text = Path.GetFileName(openFileDialog.FileName) + " - Notepad XP";
}

private void Notepad_Load(object sender, EventArgs e)


{
currFileName = "";
}
}
}
OUTPUT

11 | P a g e
12 | P a g e
LAB Assignment #-06
Notepad with the help of Tool Strip function for New & Open & Save

private void toolStripButton1_Click(object sender, EventArgs e)


{
NewFileMenu();
}

private void toolStripButton2_Click(object sender, EventArgs e)


{
OpenFileMenu();
}

private void toolStripButton3_Click(object sender, EventArgs e)


{
SaveFileMenu();
}

13 | P a g e
LAB Assignment #-07
Data grid view export in excel

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

private void button1_Click(object sender, EventArgs e)


{
// creating Excel Application
Microsoft.Office.Interop.Excel._Application app = new
Microsoft.Office.Interop.Excel.Application();
// creating new WorkBook within Excel application
Microsoft.Office.Interop.Excel._Workbook workbook = app.Workbooks.Add(Type.Missing);
// creating new Excelsheet in workbook
Microsoft.Office.Interop.Excel._Worksheet worksheet = null;
// see the excel sheet behind the program
app.Visible = true;
// get the reference of first sheet. By default its name is Sheet1.
// store its reference to worksheet
worksheet = workbook.Sheets["Sheet1"];
worksheet = workbook.ActiveSheet;
// changing the name of active sheet
worksheet.Name = "Exported from gridview";
// storing header part in Excel
for (int i = 1; i < dataGridView1.Columns.Count + 1; i++)
{
worksheet.Cells[1, i] = dataGridView1.Columns[i - 1].HeaderText;
}
// storing Each row and column value to excel sheet
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
for (int j = 0; j < dataGridView1.Columns.Count; j++)
{
worksheet.Cells[i + 2, j + 1] = dataGridView1.Rows[i].Cells[j].Value.ToString();
}
}
// save the application

14 | P a g e
workbook.SaveAs("c:\\output.xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
// Exit from the application
app.Quit();
}
}
}

15 | P a g e
LAB Assignment #-08
Using of Interface
Output
namespace interface1
{
public interface ITransactions
{
// interface members
void showTransaction();
double getAmount();
}
public class Transaction : ITransactions
{
private string tCode;
private string date;
private double amount;

public Transaction()
{
tCode = " ";
date = " ";
amount = 0.0;
}
public Transaction(string c, string d, double a)
{
tCode = c;
date = d;
amount = a;
}
public double getAmount()
{
return amount;
}
public void showTransaction()
{
Console.WriteLine("Transaction: {0}", tCode);
Console.WriteLine("Date: {0}", date);
Console.WriteLine("Amount: {0}", getAmount());
}
}
class Program
{
static void Main(string[] args)
{
Transaction t1 = new Transaction("001", "8/10/2012", 78900.00);
Transaction t2 = new Transaction("002", "9/10/2012", 451900.00);

t1.showTransaction();
t2.showTransaction();
Console.ReadKey();
}
}
}

16 | P a g e
LAB Assignment #-08
Using of String
// Comparing b/w two string
string str1 = "This is test";
string str2 = "This is text";

if (String.Compare(str1, str2) == 0)
{
Console.WriteLine(str1 + " and " + str2 + " are equal.");
}
else
{
Console.WriteLine(str1 + " and " + str2 + " are not equal.");
Console.ReadKey();

// String Contains String


string str = "This is test";

if (str.Contains("test"))
{
Console.WriteLine("The sequence 'test' was found.");
}
Console.ReadKey();

// Getting a Substring
string str = "Last night I dreamt of San Pedro";
Console.WriteLine(str);
string substr = str.Substring(23);
Console.WriteLine(substr);

//Joining Strings
string[] starray = new string[]{"Down the way nights are dark",
"And the sun shines daily on the mountain top",
"I took a trip on a sailing ship",
"And when I reached Jamaica",
"I made a stop"};

17 | P a g e
string str = String.Join("\n", starray);
Console.WriteLine(str);

18 | P a g e

You might also like