MissStrawberryPart1.zip ( 39.94k )
Number of downloads: 5Imports System.IO
vb
Public Class DataEntryStorage
Inherits System.Windows.Forms.Form
Public Class FruitType
Private code As String
Private name As String
Sub New(ByVal _code As String, ByVal _name As String)
code = _code
name = _name
End Sub
Public Property TypeCode()
Get
Return code
End Get
Set(ByVal Value)
code = Value
End Set
End Property
Public Property TypeName()
Get
Return name
End Get
Set(ByVal Value)
name = Value
End Set
End Property
End Class
Dim types(6) As FruitType
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
cboProductType.DataSource = New FruitType() {New FruitType("1", "Apples"), _
New FruitType("2", "Oranges"), _
New FruitType("3", "Bananas"), _
New FruitType("4", "Grapefruit"), _
New FruitType("5", "Peaches"), _
New FruitType("6", "Melons")}
cboProductType.DisplayMember = "TypeName"
cboProductType.ValueMember = "TypeCode"
cboCalculationMethod.DataSource = New String() {"1", "2"}
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
Friend WithEvents lblReferenceNum As System.Windows.Forms.Label
Friend WithEvents lblProductType As System.Windows.Forms.Label
Friend WithEvents lblWeight As System.Windows.Forms.Label
Friend WithEvents lblQuantity As System.Windows.Forms.Label
Friend WithEvents txtReferenceNum As System.Windows.Forms.TextBox
Friend WithEvents txtWeight As System.Windows.Forms.TextBox
Friend WithEvents txtQuantity As System.Windows.Forms.TextBox
Friend WithEvents cboCalculationMethod As System.Windows.Forms.ComboBox
Friend WithEvents txtBuyPrice As System.Windows.Forms.TextBox
Friend WithEvents txtSalePrice As System.Windows.Forms.TextBox
Friend WithEvents btnPurchase As System.Windows.Forms.Button
Friend WithEvents btnClose As System.Windows.Forms.Button
Friend WithEvents lblCalculationMethod As System.Windows.Forms.Label
Friend WithEvents lblSalePrice As System.Windows.Forms.Label
Friend WithEvents lblBuyPrice As System.Windows.Forms.Label
Friend WithEvents MenuItemPurchase As System.Windows.Forms.MenuItem
Friend WithEvents MenuItemClose As System.Windows.Forms.MenuItem
Private WithEvents cboProductType As System.Windows.Forms.ComboBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.MainMenu1 = New System.Windows.Forms.MainMenu
Me.MenuItem1 = New System.Windows.Forms.MenuItem
Me.MenuItemPurchase = New System.Windows.Forms.MenuItem
Me.MenuItemClose = New System.Windows.Forms.MenuItem
Me.lblReferenceNum = New System.Windows.Forms.Label
Me.lblProductType = New System.Windows.Forms.Label
Me.lblWeight = New System.Windows.Forms.Label
Me.lblQuantity = New System.Windows.Forms.Label
Me.lblCalculationMethod = New System.Windows.Forms.Label
Me.lblBuyPrice = New System.Windows.Forms.Label
Me.lblSalePrice = New System.Windows.Forms.Label
Me.txtReferenceNum = New System.Windows.Forms.TextBox
Me.cboProductType = New System.Windows.Forms.ComboBox
Me.txtWeight = New System.Windows.Forms.TextBox
Me.txtQuantity = New System.Windows.Forms.TextBox
Me.cboCalculationMethod = New System.Windows.Forms.ComboBox
Me.txtBuyPrice = New System.Windows.Forms.TextBox
Me.txtSalePrice = New System.Windows.Forms.TextBox
Me.btnPurchase = New System.Windows.Forms.Button
Me.btnClose = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'MainMenu1
'
Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1})
'
'MenuItem1
'
Me.MenuItem1.Index = 0
Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItemPurchase, Me.MenuItemClose})
Me.MenuItem1.Text = "File"
'
'MenuItemPurchase
'
Me.MenuItemPurchase.Index = 0
Me.MenuItemPurchase.Text = "Purchase"
'
'MenuItemClose
'
Me.MenuItemClose.Index = 1
Me.MenuItemClose.Text = "Close"
'
'lblReferenceNum
'
Me.lblReferenceNum.Location = New System.Drawing.Point(8, 24)
Me.lblReferenceNum.Name = "lblReferenceNum"
Me.lblReferenceNum.TabIndex = 0
Me.lblReferenceNum.Text = "Reference Number"
'
'lblProductType
'
Me.lblProductType.Location = New System.Drawing.Point(8, 56)
Me.lblProductType.Name = "lblProductType"
Me.lblProductType.TabIndex = 0
Me.lblProductType.Text = "Product Type"
'
'lblWeight
'
Me.lblWeight.Location = New System.Drawing.Point(8, 88)
Me.lblWeight.Name = "lblWeight"
Me.lblWeight.TabIndex = 0
Me.lblWeight.Text = "Weight"
'
'lblQuantity
'
Me.lblQuantity.Location = New System.Drawing.Point(8, 120)
Me.lblQuantity.Name = "lblQuantity"
Me.lblQuantity.TabIndex = 0
Me.lblQuantity.Text = "Quantity"
'
'lblCalculationMethod
'
Me.lblCalculationMethod.Location = New System.Drawing.Point(8, 152)
Me.lblCalculationMethod.Name = "lblCalculationMethod"
Me.lblCalculationMethod.Size = New System.Drawing.Size(104, 23)
Me.lblCalculationMethod.TabIndex = 0
Me.lblCalculationMethod.Text = "Calculation Method"
'
'lblBuyPrice
'
Me.lblBuyPrice.Location = New System.Drawing.Point(8, 184)
Me.lblBuyPrice.Name = "lblBuyPrice"
Me.lblBuyPrice.TabIndex = 0
Me.lblBuyPrice.Text = "Buy Price(Pence)"
'
'lblSalePrice
'
Me.lblSalePrice.Location = New System.Drawing.Point(8, 216)
Me.lblSalePrice.Name = "lblSalePrice"
Me.lblSalePrice.TabIndex = 0
Me.lblSalePrice.Text = "Sale Price(Pence)"
'
'txtReferenceNum
'
Me.txtReferenceNum.Location = New System.Drawing.Point(136, 24)
Me.txtReferenceNum.MaxLength = 6
Me.txtReferenceNum.Name = "txtReferenceNum"
Me.txtReferenceNum.Size = New System.Drawing.Size(120, 20)
Me.txtReferenceNum.TabIndex = 1
Me.txtReferenceNum.Text = ""
'
'cboProductType
'
Me.cboProductType.Location = New System.Drawing.Point(136, 56)
Me.cboProductType.Name = "cboProductType"
Me.cboProductType.Size = New System.Drawing.Size(121, 21)
Me.cboProductType.TabIndex = 2
Me.cboProductType.Text = "ComboBox1"
'
'txtWeight
'
Me.txtWeight.Location = New System.Drawing.Point(136, 88)
Me.txtWeight.MaxLength = 4
Me.txtWeight.Name = "txtWeight"
Me.txtWeight.Size = New System.Drawing.Size(120, 20)
Me.txtWeight.TabIndex = 1
Me.txtWeight.Text = ""
'
'txtQuantity
'
Me.txtQuantity.Location = New System.Drawing.Point(136, 120)
Me.txtQuantity.MaxLength = 4
Me.txtQuantity.Name = "txtQuantity"
Me.txtQuantity.Size = New System.Drawing.Size(120, 20)
Me.txtQuantity.TabIndex = 1
Me.txtQuantity.Text = ""
'
'cboCalculationMethod
'
Me.cboCalculationMethod.Location = New System.Drawing.Point(136, 152)
Me.cboCalculationMethod.Name = "cboCalculationMethod"
Me.cboCalculationMethod.Size = New System.Drawing.Size(121, 21)
Me.cboCalculationMethod.TabIndex = 2
Me.cboCalculationMethod.Text = "ComboBox1"
'
'txtBuyPrice
'
Me.txtBuyPrice.Location = New System.Drawing.Point(136, 184)
Me.txtBuyPrice.MaxLength = 4
Me.txtBuyPrice.Name = "txtBuyPrice"
Me.txtBuyPrice.Size = New System.Drawing.Size(120, 20)
Me.txtBuyPrice.TabIndex = 1
Me.txtBuyPrice.Text = ""
'
'txtSalePrice
'
Me.txtSalePrice.Location = New System.Drawing.Point(136, 216)
Me.txtSalePrice.MaxLength = 4
Me.txtSalePrice.Name = "txtSalePrice"
Me.txtSalePrice.Size = New System.Drawing.Size(120, 20)
Me.txtSalePrice.TabIndex = 1
Me.txtSalePrice.Text = ""
'
'btnPurchase
'
Me.btnPurchase.Location = New System.Drawing.Point(64, 248)
Me.btnPurchase.Name = "btnPurchase"
Me.btnPurchase.TabIndex = 3
Me.btnPurchase.Text = "Purchase"
'
'btnClose
'
Me.btnClose.Location = New System.Drawing.Point(160, 248)
Me.btnClose.Name = "btnClose"
Me.btnClose.TabIndex = 3
Me.btnClose.Text = "Close"
'
'DataEntryStorage
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(288, 281)
Me.Controls.Add(Me.btnPurchase)
Me.Controls.Add(Me.cboProductType)
Me.Controls.Add(Me.txtReferenceNum)
Me.Controls.Add(Me.lblReferenceNum)
Me.Controls.Add(Me.lblProductType)
Me.Controls.Add(Me.lblWeight)
Me.Controls.Add(Me.lblQuantity)
Me.Controls.Add(Me.lblCalculationMethod)
Me.Controls.Add(Me.lblBuyPrice)
Me.Controls.Add(Me.lblSalePrice)
Me.Controls.Add(Me.txtWeight)
Me.Controls.Add(Me.txtQuantity)
Me.Controls.Add(Me.cboCalculationMethod)
Me.Controls.Add(Me.txtBuyPrice)
Me.Controls.Add(Me.txtSalePrice)
Me.Controls.Add(Me.btnClose)
Me.Menu = Me.MainMenu1
Me.Name = "DataEntryStorage"
Me.Text = "Miss Strawberry"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
Me.Close()
End Sub
Private Sub btnPurchase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPurchase.Click
onPurchase()
End Sub
Private Sub WriteLine(ByVal line As String)
Dim writer As StreamWriter = _
New StreamWriter("C:\sales.txt", True)
writer.WriteLine(line)
writer.Close()
End Sub
Function getNumberString(ByVal number As Integer, ByVal length As Integer) As String
Dim str As String = number.ToString()
Dim difference As Integer = length - str.Length
Dim i As Integer
For i = 1 To difference
str = "0" & str
Next
Return str
End Function
Private Sub onPurchase()
Dim referenceNumber As Integer
Dim productType As Integer
Dim weight As Integer
Dim quantity As Integer
Dim calculationMethod As Integer
Dim buyPrice As Integer
Dim salePrice As Integer
Dim line As String = ""
Try
referenceNumber = Integer.Parse(txtReferenceNum.Text)
Catch ex As Exception
MessageBox.Show("Reference number be have an integer value", "Reference Number Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End Try
Try
weight = Integer.Parse(txtWeight.Text)
Catch ex As Exception
MessageBox.Show("Weight must be an integer value", "Weight Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End Try
Try
quantity = Integer.Parse(txtQuantity.Text)
Catch ex As Exception
MessageBox.Show("Quantity must be an integer value", "Quantity Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End Try
Try
buyPrice = Integer.Parse(txtBuyPrice.Text)
Catch ex As Exception
MessageBox.Show("Buy Price must be an integer value", "Buy Price Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End Try
Try
salePrice = Integer.Parse(txtSalePrice.Text)
Catch ex As Exception
MessageBox.Show("Sale Price must be an integer value", "Sale Price Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return
End Try
productType = Integer.Parse(cboProductType.SelectedValue.ToString())
calculationMethod = Integer.Parse(cboCalculationMethod.Text.ToString())
line = getNumberString(referenceNumber, 6) & productType.ToString() & getNumberString(weight, 4) & _
getNumberString(quantity, 4) & calculationMethod.ToString() & getNumberString(buyPrice, 4) & getNumberString(salePrice, 4)
WriteLine(line)
txtReferenceNum.Text = ""
txtWeight.Text = 1
txtQuantity.Text = ""
txtQuantity.Text = ""
cboCalculationMethod.Text = 1
txtBuyPrice.Text = ""
txtSalePrice.Text = ""
End Sub
Private Sub MenuItemPurchase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemPurchase.Click
onPurchase()
End Sub
Private Sub MenuItemClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemClose.Click
Me.Close()
End Sub
End Class
ATTENTION
THIS IS WHERE IT TROWS AN EXCEPTION
Private Sub WriteLine(ByVal line As String)
Dim writer As StreamWriter = _
New StreamWriter("C:\sales.txt", True)
Requirements
A small fruit shop needs a solution to store and retrieve sales information.
An application will be required to store details of the fruit sold on that day to a sales file. A second application will then read the sales file to produce a report. Please ensure that you have two different projects to complete this task, one to enter and save the information, and the other to retrieve it.
On part 1 of the Miss Strawberry project you will have a data entry form where the user will enter the sales details. When the user selects the purchase button, this information will be written to the data file (text file). Note: You can open and close the file in the Form_Load sub procedure - this will create a new file. Then when you open the file for writing the information (in your purchase button?s click method) you can open it in append mode which means that each record will be added to the file. For part 2 of the Miss Strawberry project you read the information from the text file and display it in a text/list box. Using a text/list box means that you do not need a second file.
Miss Strawberry Part 1 - Data Entry and Storage
All sales of fruit will be entered into the program and written to the sales file. The following information is to be stored within the file in the following format:
Field Required Format
Reference Number 6 Digits
Type Code 1 - 6
Weight in Kilos 4 Digits
Quantity 4 Digits
Calculation Method 1 or 2
Buying Price in 1/10 Pence 4 Digits
Selling Price in 1/10 Pence 4 Digits
Reference Number
This is a unique number which is given to each fruit e.g. 100033
Type Code
Miss Strawberry sells the following fruits in her shop.
Type Code Fruit
1 Apples
2 Oranges
3 Bananas
4 Grapefruit
5 Peaches
6 Melons
Weight in Kilos
This is for fruit which is sold by weight e.g. bananas, peaches.
Quantity
This is for fruit which is sold by quantity e.g. grapefruit, melons.
Calculation Method
This is must be entered by the user and is how the selling price will be calculated. This will be based on the type of fruit: e.g. bananas will use calculation method 1 as they are sold by weight whereas melons will use a calculation method of 2 as they are sold individually.
Buying Price in 1/10 pence
The buying price is the wholesale value i.e. the price that Miss Strawberry pays. This is entered in tenths(1/10) of a penny. e.g. £1.23 will be entered as 1230.
Buying Price in 1/10 pence
The selling price is the retail value i.e. the price that the customer pays. This is entered in tenths(1/10) of a penny. e.g. £1.23 will be entered as 1230.
The following screenshot shows the data entry form for the sales details:
The text file should be in this format:
100033100200000101400330
100033100200000101350320
100039100230000101500345
100040100230000101500325
100051100230000101300345
Miss Strawberry Part 2 - Sales Report
This separate project is required to produce a sales report within a form. To do this, the program will read the sales file and send the formatted data (i.e. split into fields) to the sales report. The sales report will contain each record (from the data file) plus the calculated buying value and sales value.
This is calculated as follows:
Calculation Method 1 Weight * Price
Calculation Method 2 Quantity * Price
Note: As sales and buying prices have been entered in tenths (1/10) of a penny, these will need to be divided by 1000 to give a value in pounds (£) and pence (p) e.g. 1230 will be £1.23.
Once all of the entries have been made, the information must be shown in a Sales Report to be viewed by Miss Strawberry. A possible format for the Sales Report is shown here:
In order to produce a correct solution you will need to make reference to the MSDN library for certain information. You may therefore find the following useful:
1. Using methods of the String class of the .NET Framework to access the fields in the records e.g. String.SubString, String.Split.
2. The Tab function can be used to align the columns in the report.
3. The Format function can be used to place zeros in numeric fields.
Mod edit: Please
Thanks, gabehabe