Question: Can s ome one help me finish my code about C# class ProductDB { // Get the connection string from an external file public static

Can sCan some one help me finish my code about C# class ProductDB{ // Get the connection string from an external file public staticome one help me finish my code about C#

class ProductDB {

// Get the connection string from an external file public static string ConnectionString() { return File.ReadAllText(@"..\..\DBConnStr.txt", Encoding.UTF8); }

// Get a connection to DB public static OleDbConnection GetConnection() { // Declare a connection and initialze to null OleDbConnection conn = null;

// Declare string and call method to get connection string from file string connStr = File.ReadAllText(@"..\..\DBConnStr.txt", Encoding.UTF8); conn = new OleDbConnection(connStr);

// Show connection string in message box // MessageBox.Show(connStr); // For debugging

// Instantiate connection

// Return connection return conn; }

// Get a list of all Products from DB public static List GetProducts() { // Declare a List of Product and initialize to null pointer List pl = null; using (ProductsDB = new ProductDB()) { List products = db.Products.where(x => x.ProductTypeID == ProductTypeId).toList() return products; } // Declare and get connection

// Declare a string to contain the sql statement string sqlStr = "";

// Show sql string in message box MessageBox.Show(sqlStr); // For debugging

// Declare and instantiate a command

// Read all Products from DB in try-catch block // Try // Instantiate List of Product // Open connection // Execute the command reader // Loop to get all records and copy to List of Product // Instantiate Product with constructor, passing data from reader // Add Product to List of Product // Catch // Catch exception // MessageBox.Show("Exception: " + ex.ToString()); // Set List of Product to null pointer // Finally // If connection not null close it // Return Products List return pl; }

The first task is to complete the Product hierarchy, which only has two simple classes. The Product class contains an int ID, ring Type, st Name and double Price. Write these as auto-implemented ring properties to decrease coding. Product has two constructors: one that accepts a fields (copies all fields from parameters to class fields) and another that accepts a Product (copies the data from the parameter Product to this Product). The Hoagie class inherits the Product class and has three Boolean fields to record lettuce, tomato or onion on a Hoagie Product. Again, write as auto-implemented properties There are also two constructors: one that accepts all Product and Hoagie fields (passes Product fields to Product and copies the Hoagie fields to this Hoagie) a another that accepts a Product and the Hoagie fields (The Product parameter is passed to the Product constructor that accepts a Product and copies the Hoagie fields to this Hoagie). The class diagrams are below properties ID Properties Name Price Lettuce Type Tomato Methods Methods Product (-1 overload Hoagie 1 overload) Task 1: Write Product hierarchy 1. Write Product class as described above a. Write the auto-implemented properties b. Write the constructors 2. Write Hoagie class as described above a. Write the auto-implemented properties b. Write the constructors 3. Declare Product List (name it pl) and Product (name it p) identifiers at top of frmMain 4. Check for and fix any errors indicated by .Net

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!