Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C#:I need someone to help me with this problem. If you can\'t finish it all that

ID: 3905428 • Letter: C

Question

C#:I need someone to help me with this problem. If you can't finish it all that's fine. I will take it as long as it has most of the functionality of the assignment.

For today's lab you will be creating a basic inventory system. The inventory system will be for a DVD store. You will have to create a DVD class that has fields to hold a title (string), a price (decimal), and a rating (float).

Your program will connect to the database, that you either set-up in the Database class or by following the directions above, and select 20 DVD’s from the dvd table. The data that is returned from the database will have to be converted into DVD objects that should be placed into a List of DVD’s that will serve as the inventory. The program requires a second list to serve as a shopping cart for the user.

The user will be presented with a menu with the following options: View inventory - displays all of the DVD’s in the store’s inventory. View shopping cart - displays all of the DVD’s in the user’s shopping cart. Add DVD to shopping cart - present the user with a list of DVD’s in the inventory and allow her/him to select one to add to the shopping cart (this removes it from the inventory). Remove DVD from shopping cart - present the user with a list of DVD’s in the shopping cart and allow her/him to select one to remove from the shopping cart (this adds the DVD back into the inventory). Exit - exit the program.

Use the following guidelines to complete this application:

Classes/Variables

DVD class created

Requires the following fields:

.Title of type string

Price of type decimal

Rating of type float

Should override ToString() to display the DVD’s Title, Price, and Rating.

list of DVD’s called inventory at the top of main

list of DVD’s called shoppingCart below the inventory list

Database

I can do this step. Do not worry about doing file I/O(Use file I/O to read in the server’s ip address Because this will be helpful in VFW the file should be:

c:/VFW/connection.txt

the only thing in the file should be the ip address of the server (ex. “192.168.1.1”).)

Connects to the database

(For this query, you can just fill it in with words that seem correct. I can replace it with the real words.)Executes a query to get the info for 20 DVD’s from the dvd table. The following information must be a part of the query

DVD_Title

Price

publicRating

Query results converted to DVD objects and placed in the inventory list.

Menu

The following menu functionality should be implemented:

View inventory - list all of the DVD’s in the store’s inventory

View shopping cart - list all of the DVD’s in the shopping cart

Add DVD to cart - user input used to select a DVD to remove from the inventory and add that same DVD object to the shopping cart.

Remove DVD from cart - user input used to select a DVD to remove from the shopping cart and add that same DVD object to the inventory.

Exit - allow the user to quit the program.

The program will continue to run until the user chooses to exit.

Input Validation

All input must be validated

The user must not be able to crash your program

The user should be able to make selections on the main menu by number 1/2/3 or by typing out the option (ex. “view inventory”).

All string comparisons should be case insensitive.

Extra Information

Go back through your code and check for the following:

All variables and methods are named appropriately.

Any information being output to the user should be clear and concise.

The user should be clearly informed of what is occurring throughout the application. When values change or objects are instantiated information about this occurrence should be displayed.

Make sure nothing accesses an object that doesn’t exist.

Explanation / Answer

using System;

using System.Collections.Generic;

using System.Linq;
using System.Text.RegularExpressions;

namespace DVDProgram
{
public class Program
{
List<DVD> cartList=new List<DVD>();
public static void Main(string[] args)
{
Program program=new Program();
Console.WriteLine("1. Show Inventory List");
Console.WriteLine("2. Show Cart List");
Console.WriteLine("3. Add to cart");
Console.WriteLine("4. Remove from cart");
char option=Console.Read();
switch(option){
case '1':program.getInventoryList();
break;
case '2':program.getCartList();
break;
case '3': Console.WriteLine("Enter title of DVD to add");
string title=Console.ReadLine();
program.addDVDToCart(title);
break;
case '4': Console.WriteLine("Enter title of DVD to remove");
string removeTitle=Console.ReadLine();
program.RemoveFromCart(removeTitle);
break;
}
}
public List<DVD> getInventoryList(){
List<DVD> inventoryList=new List<DVD>();
var con = ConfigurationManager.ConnectionStrings["Yourconnection"].ToString();
using (SqlConnection myConnection = new SqlConnection(con))
{
string oString = "Select DVD_Title,Price,publicRating from DVD LIMIT 20";
SqlCommand oCmd = new SqlCommand(oString, myConnection);
  
myConnection.Open();
using (SqlDataReader oReader = oCmd.ExecuteReader())
{
while (oReader.Read())
{
DVD dvd=new DVD();
dvd.title = oReader["DVD_Title"].ToString();
dvd.price = double.Parse(oReader["Price"].ToString());
dvd.rating = float.Parse(oReader["publicRating"].ToString());
inventoryList.Add(dvd);
}

myConnection.Close();
}
}
return inventoryList;

}
public List<DVD> getCartList(){
return cartList;
}
public void addDVDToCart(String title){
var con = ConfigurationManager.ConnectionStrings["Yourconnection"].ToString();
using (SqlConnection myConnection = new SqlConnection(con))
{
string oString = "Select DVD_Title,Price,publicRating from DVD where DVD_Title=@title";
SqlCommand oCmd = new SqlCommand(oString, myConnection);
oCmd.Parameters.AddWithValue("@title", title);
myConnection.Open();
using (SqlDataReader oReader = oCmd.ExecuteReader())
{
while (oReader.Read())
{
DVD dvd=new DVD();
dvd.title = oReader["DVD_Title"].ToString();
dvd.price = double.Parse(oReader["Price"].ToString());
dvd.rating = float.Parse(oReader["publicRating"].ToString());
cartList.Add(dvd);
}

myConnection.Close();
}
}
using (SqlConnection myConnection = new SqlConnection(con))
{
myConnection.Open();
SqlCommand command = new SqlCommand("DELETE FROM DVD where DVD_Title =@title", myConnection);
command.Parameters.AddWithValue("@title", title);
command.ExecuteNonQuery();
  
myConnection.Close();
}
}
public void RemoveFromCart(String title){
DVD dvdObj=new DVD();
foreach(var dvd in cartList)
{
if(dvd.title.ToLowerCase() == title.ToLowerCase())
{
dvdObj.title=dvd.title;
dvdObj.price=dvd.price;
dvdObj.rating=dvd.rating;
cartList.Remove(dvd);
}
  
}
var con = ConfigurationManager.ConnectionStrings["Yourconnection"].ToString();
using (SqlConnection myConnection = new SqlConnection(con))
{
myConnection.Open();
SqlCommand command = new SqlCommand("INSERT INTO DVD(DVD_Title,Price,publicRating) values(@title,@price,@rating)",

myConnection);
command.Parameters.AddWithValue("@title", dvdObj.title);
command.Parameters.AddWithValue("@price", dvdObj.price);
command.Parameters.AddWithValue("@rating", dvdObj.rating);
command.ExecuteNonQuery();
  
myConnection.Close();
}
}
}
}
class DVD{
private String title { get; set; };
private double price { get; set; };
private float rating { get; set; };
private List<DVD> inventoryList{ get; set; };
private List<DVD> shoppingCart { get; set; };
}