0% found this document useful (0 votes)
88 views8 pages

626178a42e9a0 Visual Programming Final Paper

The document describes a final exam for a Visual Programming course taken at Arid Agriculture University. It includes instructions for students to answer 10 questions related to creating a C# desktop application for managing inventory records and a cash register for a retail store. The application uses an Inventory class to store data and allows adding new inventory items to a database table, looking up items, and processing purchases by updating inventory quantities.

Uploaded by

Saim Ahmed
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)
88 views8 pages

626178a42e9a0 Visual Programming Final Paper

The document describes a final exam for a Visual Programming course taken at Arid Agriculture University. It includes instructions for students to answer 10 questions related to creating a C# desktop application for managing inventory records and a cash register for a retail store. The application uses an Inventory class to store data and allows adding new inventory items to a database table, looking up items, and processing purchases by updating inventory quantities.

Uploaded by

Saim Ahmed
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
You are on page 1/ 8

Pir Mehr Ali Shah

Arid Agriculture University, Rawalpindi


Office of the controller of Examinations
Final Exam / Spring 2021 (Paper Duration 12 hours)
To be filled by Teacher

Course No.: ……….CS-692…………….Course Title: ….…………Visual Programming………………….


Total Marks: ……….20…………………………Date of Exam: ……......8th July 2021……...........
Degree: ………………BSCS……………………. Semester: …………5th...………… Section: …………A….………………
Marks
Q. No. 1 2 3 4 5 6 7 8 9 10
Obtained/Total Marks
Marks
Obtained
X X X X X X X X X 0/20
Total Marks in Words:
Name of the teacher who taught the course: Mr. Bilal Mazhar
Signature of teacher / Examiner:

To be filled by Student

Registration No.: ……………………………………………….……… Name: ……………….………………………………………..

Answer the following questions in the specified area (add more lines/insert images if needed).
Instructions:
1. Read all questions carefully and write only relevant answer
2. Don't forget to write your name & roll number.
3. Write your all answers in given question paper. Avoid using any other file
4. Font Size should be 12 and Times new Roman
5. Upload your solution File after completing the questions.
6. Plagiarism in any question will lead to you zero marks in whole paper
7. Attach output screenshots/images only, any other screenshots/images will not be
acceptable

Q.No.1. [Marks 20]


Inventory Class
Create a C# desktop application that stores inventory records for a retail store. The
application should have an Inventory class with the following properties:
InvNumber: A string used to hold an inventory number. Each item in the inventory should
have a unique inventory number.
Description A string that holds a brief description of the item.
:
Cost: A decimal value that holds the amount that the retail store paid for the item.
Retail: A decimal value that holds the retail price for the item.
OnHand: An integer value that holds the number of items on hand. This value cannot be
less than 0.

Page 1 of 8
The application should store Inventory class objects data into database table. Create an input
form in the application that allows users to input new inventory items to be added to the
database table. The user should also be able to look up items by their inventory number.
When the application starts up, it should load the data from the table into the gridview. Be
sure to use exception handling.
Cash Register
Create an application that serves as a simple cash register for a retail store. Use the Inventory
class you created to store data about the items in the store’s inventory. When the application
starts up, it should load the entire store’s inventory from a table into a gridview of Inventory
form.
When a purchase is made, the cashier should select an item from a combobox. (If an item’s
OnHand property is set to zero, the item should not be available in the combobox.) The
item’s description, retail price, and number of units on hand should be displayed on the form
when selected. The cashier should enter the quantity being purchased, and the application
should display the sales tax and the total of the sale. (The quantity being purchased cannot
exceed the number of units on hand.) The quantity being purchased should be subtracted
from the item’s OnHand property..

Answer:
Coding screen shot

Page 2 of 8
Page 3 of 8
Output

Data
add

Search

Cash

Page 4 of 8
Now database is updated

Code form 1

Page 5 of 8
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

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

private void button1_Click(object sender, EventArgs e)


{

Asad a = new Asad();


a.inv = textBox1.Text;
a.des = textBox2.Text;
a.cos = textBox3.Text;
a.ret = textBox4.Text;
a.onh = textBox5.Text;
a.add();
MessageBox.Show("Data Added!");

private void button2_Click(object sender, EventArgs e)


{

int id = Convert.ToInt32(textBox6.Text);
SqlConnection connection = new SqlConnection("Data Source=Asad\\
SQLEXPRESS;Initial Catalog=Asad;Integrated Security=True");
string db = @"select * from item_record where id =" + id;
SqlCommand cmd = new SqlCommand(db, connection);
connection.Open();
SqlDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("isb", typeof(string));
dt.Columns.Add("des", typeof(string));
dt.Columns.Add("cost", typeof(string));
dt.Columns.Add("ret ", typeof(string));
dt.Columns.Add("onh", typeof(string));

while (dr.Read())
{
dt.Rows.Add(dr[0], dr[1], dr[2], dr[3], dr[4], dr[5]);
}

connection.Close();
dataGridView1.DataSource = dt;

private void Form1_Load(object sender, EventArgs e)


{

Page 6 of 8
Asad a = new Asad();

dataGridView1.DataSource = a.show();

private void button3_Click(object sender, EventArgs e)


{
Form2 fo = new Form2();
fo.Show();

}
}
}

Code form 2
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Asad_LAB
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
int id = Convert.ToInt32(comboBox1.Text);
int x = Convert.ToInt32(textBox1.Text);
SqlConnection connection = new SqlConnection("Data Source=Asad\\
SQLEXPRESS;Initial Catalog=Asad;Integrated Security=True");

string query = @"update item_record set onh='" + x + "' where id='" + id +


"'";
SqlCommand cmd = new SqlCommand(query, connection);
connection.Open();
cmd.ExecuteNonQuery();
connection.Close();
MessageBox.Show("Record Updated");
}
}
}

Class
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Asad_LAB

Page 7 of 8
{
class Asad
{
public string inv { get; set; }
public string des { get; set; }
public string cos { get; set; }
public string ret { get; set; }
public string onh { get; set; }

public void add()


{
SqlConnection connection = new SqlConnection("Data Source=HUSNAINTALIB\\
SQLEXPRESS;Initial Catalog=Asad;Integrated Security=True");
string db = @"insert into item_record(inv , des , cos , ret , onh)
values('" + inv + "','" + des + "','" + cos + "','" + ret + "','" +
onh + "')";
SqlCommand commandd = new SqlCommand(db, connection);
connection.Open();
commandd.ExecuteNonQuery();
connection.Close();
}

public DataTable show() {


SqlConnection connection = new SqlConnection("Data Source=Asad\\
SQLEXPRESS;Initial Catalog=Asad;Integrated Security=True");
string db = @"select * from item_record";
SqlCommand cmd = new SqlCommand(db, connection);
connection.Open();
SqlDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Columns.Add("ID", typeof(int));
dt.Columns.Add("isb", typeof(string));
dt.Columns.Add("des", typeof(string));
dt.Columns.Add("cost", typeof(string));
dt.Columns.Add("ret ", typeof(string));
dt.Columns.Add("onh", typeof(string));

while (dr.Read())
{
dt.Rows.Add(dr[0], dr[1], dr[2], dr[3], dr[4], dr[5]);
}

connection.Close();
return dt;
}
}

Page 8 of 8

You might also like