C#代写:CSIS1175 Grocery Application

实现一个带界面的Grocery应用程序,支持csv文件的数据读写。

Grocery

Requirement

Create the C# project with your FirstInitialLastInitial_Assign2 - There should be NO SPACES in your PROJECT NAME. You must use upper and lower cases for the project name. (e.g., If your name is John Smith, then your project must be called JS_Assign2).

At the beginning of your source code, you must again enter your section #, your name and student id as a comment.

Zip up your entire program from the top folder and submit it via Blackboard before the due date. Do not rename the folder. You will be responsible for accurately compressing the entire project folder (along with solution files) and submitting it on blackboard. Late submission will not be accepted. The name of your zip file must be the same as your project name. If you do not follow the above instructions, including the file name and subject line, you will get marks deducted.

Note: Sharing your code, and looking at another student’s code will constitute to cheating. In case of cheating both the student that copies and the student that shared or allowed the copying would get Zero and will reported to administration.

Task

In this assignment, you are required to implement the local grocery application in C#. Grocery Data (see given csv file, localgrocery.csv) contains ItemName, ItemCode, UnitPrice, StartingQty (starting quantity count for each item), QtyMinRestck (minimum quantity needed for restocking the item), QtySold, QtyRStcked.

Class Definition

You must use a Grocery class to maintain a grocery item with Properties: ItemName, ItemCode, StartingQty, QtyMinForRestock, QtySold, QtyRestocked. You will use two additional computed read-only properties: i. QuantityOnHand, which is computed as the Starting Quantity - Quantity Sold + Restocked Quantity, and ii. Total Sales for each item based on QtySold multiplied by UnitPrice. These two additional properties of TotalSales and QtyHand will be read-only properties, and cannot be directly set at any point. They will be updated to reflect the correct amount whenever you try to get these properties.
You will use a list of Grocery Items class objects to maintain all grocery items in the list (input file). Feel free to create additional fields or class methods as needed.

Form Design

Design the App with the following design features (see figure for sample). Your form should contain:

  1. A grocery listbox that will display ItemCode, ItemName, StartingQty, QtyMinRestck, QtySold, QtyRStcked, UnitPrice, QtyHand and Sales. Set the listbox font to Consolas (or any other monospaced font).
  2. Below the list box, you will have a set of controls in three group boxes for loading data, updating data, saving data. On the left, you have the Load Grocery Button in the Load Data GroupBox. The Update Data group box contains one set (of label, TextBox and Button) for incrementing Qty Sold, and another set (of label, TextBox and Button) for incrementing Qty Restocked. Finally, there is a Delete Selected Item Button. The Save Data group box contains three buttons one each to Save Grocery Data, Save Sales Report and Save Restock Needs Report.
  3. Below all these controls, add a status label that will display status information as various user events are handled. You can set the AutoSize property of the label to false (so that the label can be resized). You can set the BackColor property (background color) to any color at the Web tab. You can set the TextAlign Property to Center. You can also set the border style to Fixed 3D (to give it an embossed look).
  4. Any other form layout or arrangement is fine as long as all this information is there in a clear format.

Event Handlers

  1. Load Grocery Data: When the Load Grocery button is clicked, grocery records will be read from a text file (localgrocery.csv) from the default folder, and the lines read from the file is tokenized into field values, parsed (as needed) and then loaded onto the listbox and the list of class objects. In addition to all the field values in the input file, the listbox should, also display columns for QtyHand and Sales. Do some background research to see how String.Format() or PadRight() method can be used to format the listbox contents such that all values in a column are aligned. Make sure your listbox has monospaced font. Finally, update the status label to indicate how many grocery items were loaded into the list.

Note that each item in listbox should always correspond to each item in the List of grocery items except for the extra header line at the top in the listbox but not in the List of Grocery Items. Every ith item in the listbox will thus correspond to (i-1)the item in the list of Grocery objects.

  1. Update Sold Qty For Selected Item: When this button is clicked, and if no item or if the headerline is selected from the listbox, you should display an error message in the status label indicating that “Please selected a grocery item to increment sold qty”. If a grocery item is selected from the listbox, then TryParse the sold Qty from the QtySold TextBox. If the TryParse fails or if the Qty Sold from TextBox input is less than or equal to 0 or if QtySold from TextBox is greater than Qty on Hand, then output relevant error messages in the status label. If the parse succeeds, and if the Qty Sold from the TextBox is greater than 0 and if Qty Sold from TextBox is lesser than Qty on Hand for that item, then increment the QtySold field by that amount given for the corresponding grocery item from the list. Qty on Hand should also reflect this change. Display a message in the status label saying “Sold Qty has been increased for the item with item code ABC”. See sample below.

  2. Update Restocked Qty For Selected Item Button: When this button is clicked, and if no item or if the headerline is selected from the listbox, you should display an error message in the status label indicating that “Please selected a grocery item to increment restocked qty”. If a grocery item is selected from the listbox, then TryParse the Qty Restocked from the TextBox. If the TryParse fails or if the Qty Restocked from TextBox input is less than or equal to 0, then output relevant error messages in the status label. If the parse succeeds, and if the Qty Restocked from the TextBox is greater than 0, then increment the QtyRestocked field by that amount given for the corresponding grocery item from the list. Qty on Hand needs to reflect this change. Display a message in the status label saying “Incremented Restocked Qty for item with item code ABC”. See sample below.

  3. Delete Selected Item Button: When this button is clicked, and if no item or if the headerline is selected from the listbox, you should display an error message in the status label indicating that “Please selected a grocery item to delete”. If a grocery item is selected from the listbox, then delete this grocery item from the listbox (and from the list of grocery item objects). Also, clear the output label if necessary. Display a message in the status label indicating “Deleted Item with item code ABC”. See sample with Deleted item Shampoo (1st item in the original list).

  4. Save Grocery Data (updatedgrocery.csv): When the user clicks on this button, for those items that are still in the list box (and the list of grocery objects), write the ItemCode, ItemName, StartingQty, QtyMinForRestock, QtySold, QtyRestocked, UnitPrice onto a comma-separated text file in the default folder location using file name updatedgrocery.csv. The comma separated text file will have each column separated by a comma. The file should have a header row at the top that gives the name of each field. Finally, the status label should display log messages indicating how many grocery items were written to the file (see sample).

  5. Save Sales Report (grocerysales.csv): When the user clicks on this button, for those items that are still in the list box (and the list of grocery objects) and have QtySold greater than 0, write the ItemCode, ItemName QtySold, UnitPrice and Sales onto a comma-separated text file in the default folder location using the name grocerysales.csv. The comma separated text file will have each column separated by a comma. The file should have a header row at the top that gives the name of each field. Finally, the status label should display log messages indicating how many sale items were written to the sales report file (see sample).

  6. Save Restock Needs Report (groceryrestocks.csv): When the user clicks on this button, for those items that are still in the list box (and the list of grocery objects) and have QtyHand lesser than QtyMinForRestock, write the ItemCode, ItemName, QtyMinForRestock, QtyHand onto a comma-separated text file in the default folder location using the file name groceryrestocks.csv. The comma separated text file will have each column separated by a comma. The file should have a header row at the top that gives the name of each field. Finally, the status label should display log messages indicating how many restock needed items were written to the restock needs report file (see sample).