626178a42e9a0 Visual Programming Final Paper
626178a42e9a0 Visual Programming Final Paper
To be filled by Student
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
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();
}
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;
Page 6 of 8
Asad a = new Asad();
dataGridView1.DataSource = a.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();
}
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; }
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