WinForms XML - Stellar Water Point
WinForms XML - Stellar Water Point
Application Setup
Introduction
Hi, for our exercise, we will create a text-based database Windows Forms application. We will use XML to store the records of our database.
Practical Learning: Introducing the Application
The Main Form of the Application
Our application will use a central form to access the other forms. We will use the default form for that purpose.
Practical Learning: Preparing the Central Form of the Application
Public Class WaterDistribution Private Sub Exercise_Load(sender As Object, e As EventArgs) Handles MyBase.Load Handles MyBase.Load Rem If the directory for the database doesn't yet exist, create it Directory.CreateDirectory("C:\Stellar Water Point1") End Sub End Class
Water Meters
Introduction
Our application will use forms to create water meter records, to view a record of a water meter, to edit or to delete the record of a water meter.
Practical Learning: Introducing Water Meters
Displaying Water Meters
To let the user see a list of the water meters in the database, we will use a form equipped with a list view.
Practical Learning: Displaying Water Meters
(Name) | Text | Width |
colWaterMeterId | Id | 40 |
colMeterNumber | Meter # | 150 |
colMake | Make | 300 |
colModel | Model | 150 |
colMeterSize | Meter Size | 150 |
Control | (Name) | Other Properties | |
ListView | ![]() |
LvwWaterMeters | FullRowSelect: True GridLines: True View: Details Anchor: Top, Bottom, Left, Right |
Imports System.IO Imports System.Xml Public Class Central Private Sub ShowWaterMeters() Dim xdWaterMeters As XmlDocument = New XmlDocument() Dim strFileWaterMeters As String = "C:\Stellar Water Point10\WaterMeters.xml" If File.Exists(strFileWaterMeters) Then Using fsWaterMeters As FileStream = New FileStream(strFileWaterMeters, FileMode.Open, FileAccess.Read, FileShare.Read) xdWaterMeters.Load(fsWaterMeters) Dim xnlWaterMeters As XmlNodeList = xdWaterMeters.DocumentElement.ChildNodes LvwWaterMeters.Items.Clear() For Each xnWaterMeter As XmlNode In xnlWaterMeters Dim lviWaterMeter As ListViewItem = New ListViewItem(xnWaterMeter.FirstChild.InnerText) lviWaterMeter.SubItems.Add(xnWaterMeter.FirstChild.NextSibling.InnerText) lviWaterMeter.SubItems.Add(xnWaterMeter.FirstChild.NextSibling.NextSibling.InnerText) lviWaterMeter.SubItems.Add(xnWaterMeter.FirstChild.NextSibling.NextSibling.NextSibling.InnerText) lviWaterMeter.SubItems.Add(xnWaterMeter.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling.InnerText) LvwWaterMeters.Items.Add(lviWaterMeter) Next End Using End If End Sub Private Sub Central_Load(sender As Object, e As EventArgs) Handles MyBase.Load ShowWaterMeters() End Sub End Class
Control | (Name) | Text | Font | |
Button | ![]() |
BtnWaterMeters | &Water Meters... | Times New Roman, 24pt, style=Bold |
Imports System.IO
Public Class WaterDistribution
Private Sub Exercise_Load(sender As Object, e As EventArgs) Handles MyBase.Load
REM If the directory for the database doesn't yet exist, create it
Directory.CreateDirectory("C:\Stellar Water Point10")
End Sub
Private Sub BtnWaterMeters_Click(sender As Object, e As EventArgs) Handles BtnWaterMeters.Click
Dim Central As Central = New Central()
Central.ShowDialog()
End Sub
End Class
A Water Meter Record
Our application will have a list of water meters. A record for each water meter must be created. To make this happen, we will equip the application with an appropriate form.
Practical Learning: Creating a Water Meter Record
Control | (Name) | Text | Other Properties | |
Label | ![]() |
&Meter #: | ||
MaskedTextBox | ![]() |
MtbMeterNumber | Masked: 000-000-000 | |
Label | ![]() |
M&ake: | ||
TextBox | ![]() |
TxtMake | Modifiers: Public | |
Label | ![]() |
M&odel: | ||
TextBox | ![]() |
TxtModel | Modifiers: Public | |
Label | ![]() |
Me&ter Size: | ||
TextBox | ![]() |
TxtMeterSize | Modifiers: Public | |
Button | ![]() |
BtnOK | &OK | DialogResult: OK |
Button | ![]() |
BtnCancel | &Cancel | DialogResult: Cancel |
FormBorderStyle: FixedDialog Text: Stellar Water Point - Water Meter Setup StartPosition: CenterScreen AcceptButton: BtnOK CancelButton: BtnCancel
Control | (Name) | Other Properties | |
ListView | ![]() |
LvwWaterMeters | FullRowSelect: True GridLines: True View: Details Anchor: Top, Bottom, Left, Right |
Button | ![]() |
BtnNewWaterMeter | &New Water Meter... Anchor: Bottom, Right |
Imports System.IO
Imports System.Xml
Public Class Central
Private Sub ShowWaterMeters()
REM Create a reference to the XML's DOM object
Dim xdWaterMeters As XmlDocument = New XmlDocument()
REM Indicate the file that holds a list of water meters
Dim strFileWaterMeters As String = "C:\Stellar Water Point10\WaterMeters.xml"
REM Check whether a file that holds a list of water meters exists
If File.Exists(strFileWaterMeters) Then
REM If that file exists, open it
Using fsWaterMeters As FileStream = New FileStream(strFileWaterMeters, FileMode.Open,
FileAccess.Read, FileShare.Read)
REM Get the list of water meters from the file and store
REM the records in the previously created DOM object.
xdWaterMeters.Load(fsWaterMeters)
REM If there is at least one record for the water meters,
REM create an XmlNodeList list and transmit it to
REM a collection that wille be used in the view page.
Dim xnlWaterMeters As XmlNodeList = xdWaterMeters.DocumentElement.ChildNodes
LvwWaterMeters.Items.Clear()
For Each xnWaterMeter As XmlNode In xnlWaterMeters
Dim lviWaterMeter As ListViewItem = New ListViewItem(xnWaterMeter.FirstChild.InnerText)
lviWaterMeter.SubItems.Add(xnWaterMeter.FirstChild.NextSibling.InnerText)
lviWaterMeter.SubItems.Add(xnWaterMeter.FirstChild.NextSibling.NextSibling.InnerText)
lviWaterMeter.SubItems.Add(xnWaterMeter.FirstChild.NextSibling.NextSibling.NextSibling.InnerText)
lviWaterMeter.SubItems.Add(xnWaterMeter.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling.InnerText)
LvwWaterMeters.Items.Add(lviWaterMeter)
Next
End Using
End If
End Sub
Private Sub Central_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ShowWaterMeters()
End Sub
Private Sub BtnNewWaterMeter_Click(sender As Object, e As EventArgs) Handles BtnNewWaterMeter.Click
Dim wm = New Create
Dim fiWaterMeters As FileInfo = Nothing
Dim xdWaterMeters = New XmlDocument
Dim strWaterMeters = "C:\Stellar Water Point10\WaterMeters.xml"
If wm.ShowDialog = DialogResult.OK Then
fiWaterMeters = New FileInfo(strWaterMeters)
If fiWaterMeters.Exists Then
Using fsWaterMeters = New FileStream(fiWaterMeters.FullName, FileMode.Open,
FileAccess.Read, FileShare.Read)
xdWaterMeters.Load(fsWaterMeters)
End Using
Else
Using fsWaterMeters = New FileStream(fiWaterMeters.FullName, FileMode.Create,
FileAccess.Write, FileShare.Write)
xdWaterMeters.LoadXml("<?xml version=""1.0"" encoding=""utf-8""?>" +
"<water-meters></water-meters>")
xdWaterMeters.Save(fsWaterMeters)
End Using
End If
End If
Using fsWaterMeters = New FileStream(fiWaterMeters.FullName, FileMode.OpenOrCreate,
FileAccess.ReadWrite, FileShare.ReadWrite)
Dim xeWaterMeter = xdWaterMeters.CreateElement("water-meter")
xeWaterMeter.InnerXml = "<water-meter-id>" + wm.TxtWaterMeterId.Text + "</water-meter-id>" +
"<meter-number>" + wm.MtbMeterNumber.Text + "</meter-number>" +
"<make>" + wm.TxtMake.Text + "</make>" +
"<model>" + wm.TxtModel.Text + "</model>" +
"<meter-size>" + wm.TxtMeterSize.Text + "</meter-size>"
xdWaterMeters.DocumentElement.AppendChild(xeWaterMeter)
xdWaterMeters.Save(fsWaterMeters)
End Using
ShowWaterMeters()
End Sub
End Class
Meter # | Make | Model | Meter Size |
392-494-572 | Constance Technologies | TG-4822 | 5/8 Inches |
938-705-869 | Stan Wood | 66-G | 1 Inch |
588-279-663 | Estellano | NCF-226 | 3/4 Inches |
Water Meter Details
Sometimes, a user may want to check the values of a water meter record. To support this, we will add an appropriate form to our application.
Practical Learning: Creating a Water Meter Record
Control | (Name) | Text | |
Button | ![]() |
BtnFindWateMeter | &Find Water Meter |
Button | ![]() |
BtnClose | &Close |
Imports System.IO
Imports System.Xml
Public Class Details
Private Sub BtnFindWateMeter_Click(sender As Object, e As EventArgs) Handles BtnFindWaterMeter.Click
If String.IsNullOrEmpty(MtbMeterNumber.Text) Then
MsgBox("You must type a meter number and then click the Find button.",
"Stellar Water Point", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information)
Exit Sub
End If
Dim xdWaterMeters As XmlDocument = New XmlDocument()
Dim strWaterMeters As String = "C:\Stellar Water Point10\WaterMeters.xml"
Dim fiWaterMeters As FileInfo = New FileInfo(strWaterMeters)
If fiWaterMeters.Exists Then
Using fsWaterMeters As FileStream = New FileStream(fiWaterMeters.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)
xdWaterMeters.Load(fsWaterMeters)
Dim xnlWaterMeters As XmlNodeList = xdWaterMeters.DocumentElement.SelectNodes("//meter-number[.='" + MtbMeterNumber.Text + "']")
For Each xnWaterMeter As XmlNode In xnlWaterMeters
TxtWaterMeterId.Text = xnWaterMeter.PreviousSibling.InnerText
TxtMake.Text = xnWaterMeter.NextSibling.InnerText
TxtModel.Text = xnWaterMeter.NextSibling.NextSibling.InnerText
TxtMeterSize.Text = xnWaterMeter.NextSibling.NextSibling.NextSibling.InnerText
Next
End Using
End If
End Sub
End Class
Imports System.IO
Imports System.Xml
Public Class Details
Private Sub BtnFindWateMeter_Click(sender As Object, e As EventArgs) Handles BtnFindWaterMeter.Click
REM If the user clicks the Find button,
REM make sure there Is a meter number in the top text box.
If String.IsNullOrEmpty(MtbMeterNumber.Text) Then
REM If the user didn't type a meter number,
REM display a message box to inform the user.
MsgBox("You must type a meter number and then click the Find button.",
"Stellar Water Point", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information)
REM If the user didn't type a meter number but clicked Find, don't do anything
Exit Sub
End If
REM We will need a reference to an XML Dom object as an XmlDocument variable
Dim xdWaterMeters As XmlDocument = New XmlDocument()
REM This is the name and path of the file that holds the records of water meters
Dim strWaterMeters As String = "C:\Stellar Water Point10\WaterMeters.xml"
REM We will process the file of water meters using a FileInfo object
Dim fiWaterMeters As FileInfo = New FileInfo(strWaterMeters)
REM We need to find out whether a file for water meters was previously created.
If fiWaterMeters.Exists Then
REM If that file exists, create a stream of it. Open that file with a read-only status
Using fsWaterMeters As FileStream = New FileStream(fiWaterMeters.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)
REM Get the list of water meter records and put those records in the XML Dom object created earlier.
xdWaterMeters.Load(fsWaterMeters)
REM Use XPath to locate the water meter that has
REM the same meter number as the one in the Meter # text box.
REM Store the water meter in an XmlNodeList variable.
Dim xnlWaterMeters As XmlNodeList = xdWaterMeters.DocumentElement.SelectNodes("//meter-number[.='" + MtbMeterNumber.Text + "']")
REM If there Is a water meter in the database with
REM the number that the user typed, locate that water meter
REM and display each of its values in the appropriate text box.
For Each xnWaterMeter As XmlNode In xnlWaterMeters
TxtWaterMeterId.Text = xnWaterMeter.PreviousSibling.InnerText
TxtMake.Text = xnWaterMeter.NextSibling.InnerText
TxtModel.Text = xnWaterMeter.NextSibling.NextSibling.InnerText
TxtMeterSize.Text = xnWaterMeter.NextSibling.NextSibling.NextSibling.InnerText
Next
End Using
End If
End Sub
Private Sub BtnClose_Click(sender As Object, e As EventArgs) Handles BtnClose.Click
Close()
End Sub
End Class
Control | (Name) | Other Properties | |
ListView | ![]() |
LvwWaterMeters | No Change |
Button | ![]() |
BtnNewWaterMeter | &New Water Meter... Anchor: Bottom, Right |
Button | ![]() |
BtnViewWaterMeter | &View Water Meter... Anchor: Bottom, Right |
Imports System.IO
Imports System.Xml
Public Class Central
Private Sub ShowWaterMeters()
. . .
End Sub
Private Sub Central_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ShowWaterMeters()
End Sub
Private Sub BtnNewWaterMeter_Click(sender As Object, e As EventArgs) Handles BtnNewWaterMeter.Click
. . .
End Sub
Private Sub BtnWaterMeterDetails_Click(sender As Object, e As EventArgs) Handles BtnWaterMeterDetails.Click
Dim waterMeterDetails As Details = New Details()
waterMeterDetails.Show()
End Sub
End Class
Updating a Water Meter Details
One of the routine operations performed on a database is to change the details of a record. To support this operation for a water meter, we will create a form that can be used to update the information of a water meter.
Practical Learning: Updating a Water Meter
Control | (Name) | Text | |
Button | ![]() |
BtnUpdateWateMeter | &Update Water Meter |
Imports System.IO
Imports System.Xml
Public Class Editor
Private Sub BtnFindWaterMeter_Click(sender As Object, e As EventArgs) Handles BtnFindWaterMeter.Click
If String.IsNullOrEmpty(MtbMeterNumber.Text) Then
MsgBox("You must type a meter number and then click the Find button.",
MsgBoxStyle.OkOnly Or MsgBoxStyle.Information,
"Stellar Water Point")
Exit Sub
End If
Dim xdWaterMeters As XmlDocument = New XmlDocument()
Dim strWaterMeters As String = "C:\Stellar Water Point10\WaterMeters.xml"
Dim fiWaterMeters As FileInfo = New FileInfo(strWaterMeters)
If fiWaterMeters.Exists Then
Using fsWaterMeters As FileStream = New FileStream(fiWaterMeters.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)
xdWaterMeters.Load(fsWaterMeters)
Dim xnlWaterMeters As XmlNodeList = xdWaterMeters.DocumentElement.SelectNodes("//meter-number[.='" + MtbMeterNumber.Text + "']")
For Each xnWaterMeter As XmlNode In xnlWaterMeters
TxtWaterMeterId.Text = xnWaterMeter.PreviousSibling.InnerText
TxtMake.Text = xnWaterMeter.NextSibling.InnerText
TxtModel.Text = xnWaterMeter.NextSibling.NextSibling.InnerText
TxtMeterSize.Text = xnWaterMeter.NextSibling.NextSibling.NextSibling.InnerText
Next
End Using
End If
End Sub
End Class
Imports System.IO
Imports System.Xml
Public Class Editor
Private Sub BtnFindWaterMeter_Click(sender As Object, e As EventArgs) Handles BtnFindWaterMeter.Click
. . .
End Sub
Private Sub BtnUpdateWateMeter_Click(sender As Object, e As EventArgs) Handles BtnUpdateWateMeter.Click
Dim xdWaterMeters As XmlDocument = New XmlDocument()
Dim strWaterMeters As String = "C:\Stellar Water Point10\WaterMeters.xml"
Dim fiWaterMeters As FileInfo = New FileInfo(strWaterMeters)
If fiWaterMeters.Exists Then
Using fsWaterMeters As FileStream = New FileStream(fiWaterMeters.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)
xdWaterMeters.Load(fsWaterMeters)
Dim xnlWaterMeters As XmlNodeList = xdWaterMeters.DocumentElement.SelectNodes("//meter-number[.='" + MtbMeterNumber.Text + "']")
For Each xnWaterMeter As XmlNode In xnlWaterMeters
xnWaterMeter.ParentNode.InnerXml = "<water-meter-id>" + TxtWaterMeterId.Text + "</water-meter-id>" +
"<meter-number>" + MtbMeterNumber.Text + "</meter-number>" +
"<make>" + TxtMake.Text + "</make>" +
"<model>" + TxtModel.Text + "</model>" +
"<meter-size>" + TxtMeterSize.Text + "</meter-size>"
Next
End Using
Using fsWaterMeters As FileStream = New FileStream(fiWaterMeters.FullName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)
xdWaterMeters.Save(fsWaterMeters)
End Using
End If
Close()
End Sub
End Class
import System.Xml namespace StellarWaterPoint1.WaterMeters public partial class Editor : Form public Editor() InitializeComponent() } private sub BtnFindWateMeter_Click(sender As Object, e As EventArgs) rem If the user clicks the Find button, rem make sure there is a meter number in the top text box. if string.IsNullOrEmpty(MtbMeterNumber.Text)) rem If the user didn't type a meter number, rem display a message box to inform the user. MsgBox("You must type a meter number and then click the Find button.", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, "Stellar Water Point") rem If the user didn't type a meter number but clicked Find, don't do anything Exit Sub end if rem We will need a reference to an XML Dom object as an XmlDocument variable dim xdWaterMeters as XmlDocument = new XmlDocument() rem This is the name and path of the file that holds the records of water meters dim strWaterMeters as string= "C:\Stellar Water Point1\WaterMeters.xml" rem We will process the file of water meters using a FileInfo object dim fiWaterMeters as FileInfo= new FileInfo(strWaterMeters) rem We need to find out whether a file for water meters was previously created. if fiWaterMeters.Exists) rem If that file exists, create a stream of it. Open that file with a read-only status using fsWaterMeters as FileStream= new FileStream(fiWaterMeters.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) rem Get the list of water meter records rem and put those records in the XML Dom object created earlier. xdWaterMeters.Load(fsWaterMeters) rem Use XPath to locate the water meter that has rem the same meter number as the one in the Meter # text box. rem Store the water meter in an XmlNodeList variable. dim xnlWaterMeters as XmlNodeList = xdWaterMeters.DocumentElement!.SelectNodes("//meter-number[.='" + MtbMeterNumber.Text + "']")!; rem If there is a water meter in the database with rem the number that the user typed, locate that water meter rem and display each of its values in the appropriate text box. for each xnWaterMeter as XmlNode in xnlWaterMeters) TxtMake.Text = xnWaterMeter.NextSibling.InnerText TxtModel.Text = xnWaterMeter.NextSibling.NextSibling.InnerText TxtMeterSize.Text = xnWaterMeter.NextSibling.NextSibling.NextSibling.InnerText next end using end if end sub private sub BtnUpdateWaterMeter_Click(sender As Object, e As EventArgs) rem We will need a reference to an XML Dom object as an XmlDocument variable dim xdWaterMeters as XmlDocument = new() rem This is the name and path of the file that holds the records of water meters dim strWaterMeters as string= "C:\Stellar Water Point1\WaterMeters.xml" rem We will process the file of water meters using a FileInfo object dim fiWaterMeters as FileInfo= new(strWaterMeters) rem We need to find out whether a file for water meters was previously created. if fiWaterMeters.Exists) rem If that file exists, create a stream of it. Open that file with a read-only status using fsWaterMeters as FileStream= new FileStream(fiWaterMeters.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) rem Get the list of water meter records rem and put those records in the XML Dom object created earlier. xdWaterMeters.Load(fsWaterMeters) rem Use XPath to locate the water meter that has rem the same meter number as the one in the Meter # text box. rem Store the water meter in an XmlNodeList variable. dim xnlWaterMeters as XmlNodeList = xdWaterMeters.DocumentElement!.SelectNodes("//meter-number[.='" + MtbMeterNumber.Text + "']")!; rem Check each record of the water meters. for each xnWaterMeter as XmlNode in xnlWaterMeters) rem If you find a record whose water meter is rem the same as the meter number that the user typed, rem change the values of the Make, the Model, rem and the Meter Size based on the values rem the user typed in the corresponding text boxes. xnWaterMeter.ParentNode!.InnerXml = "<meter-number>" + MtbMeterNumber.Text + "</meter-number>" + "<make>" + TxtMake.Text + "</make>" + "<model>" + TxtModel.Text + "</model>" + "<meter-size>" + TxtMeterSize.Text + "</meter-size>" next end using rem Now that a water meter has been changed/update rem (and the file of water meters has changed), save the new version of the file. using fsWaterMeters as FileStream= new FileStream(fiWaterMeters.FullName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)) xdWaterMeters.Save(fsWaterMeters) end using end if rem If the user has updated a record, we will assume that, rem in most cases (such as usually in real life), rem a user updates one record and moves to other activities. rem For this record, after the user has updated a record, rem we will clode the form. Close() end sub private sub BtnClose_Click(sender As Object, e As EventArgs) Close() end usb } }
Control | (Name) | Other Properties | |
ListView | ![]() |
LvwWaterMeters | FullRowSelect: True GridLines: True View: Details Anchor: Top, Bottom, Left, Right |
Button | ![]() |
BtnNewWaterMeter | &New Water Meter... Anchor: Bottom, Right |
Button | ![]() |
BtnViewWaterMeter | &View Water Meter... Anchor: Bottom, Right |
Button | ![]() |
BtnEditWaterMeter | &Edit Water Meter... Anchor: Bottom, Right |
import System.Xml namespace StellarWaterPoint1.WaterMeters public partial class Central : Form public Central() InitializeComponent() } private sub ShowWaterMeters() . . . } private sub Central_Load(sender As Object, e As EventArgs) Handles MyBase.Load rem When the open opens, make an attempt to display a list of water meters. ShowWaterMeters() } private sub BtnNewWaterMeter_Click(sender As Object, e As EventArgs) . . . } private sub BtnViewWaterMeter_Click(sender As Object, e As EventArgs) . . . } private sub BtnEditWaterMeter_Click(sender As Object, e As EventArgs) rem Get a reference to the dialog box that is used rem to update the details of a water meter. Editor editor = new() rem Display that dialog box editor.ShowDialog() rem After using the dialog box, make an attempt to display the list of water meters. ShowWaterMeters() } } }
Make: | Stanford Trend | Model: | 266G |
Meter Size: | 1 1/2 Inches |
Removing a Water Meter from the Database
If a water meter has become useless and you want to make sure it is no more available for customer use, you can delete its record. To assist the user, we will create a form for that operation.
Practical Learning: Deleting a Water Meter Record
Control | (Name) | Text | |
Button | ![]() |
BtnDeleteWateMeter | &Delete Water Meter |
import System.Xml namespace StellarWaterPoint1.WaterMeters public partial class Delete : Form public Delete() InitializeComponent() } private sub BtnFind_Click(sender As Object, e As EventArgs) dim xdWaterMeters as XmlDocument = new XmlDocument() dim strWaterMeters as string= "C:\Stellar Water Point1\WaterMeters.xml" dim fiWaterMeters as FileInfo= new FileInfo(strWaterMeters) if fiWaterMeters.Exists) using fsWaterMeters as FileStream= new FileStream(fiWaterMeters.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) xdWaterMeters.Load(fsWaterMeters) dim xnlWaterMeters as XmlNodeList = xdWaterMeters.DocumentElement!.SelectNodes("//meter-number[.='" + MtbMeterNumber.Text + "']")!; for each xnWaterMeter as XmlNode in xnlWaterMeters) TxtMake.Text = xnWaterMeter.NextSibling.InnerText TxtModel.Text = xnWaterMeter.NextSibling.NextSibling.InnerText TxtMeterSize.Text = xnWaterMeter.NextSibling.NextSibling.NextSibling.InnerText next end using end if end sub } }
import System.Xml namespace StellarWaterPoint1.WaterMeters public partial class Delete : Form public Delete() InitializeComponent() } . . . private sub BtnDeleteWaterMeter_Click(sender As Object, e As EventArgs) dim xdWaterMeters as XmlDocument = new XmlDocument() dim strWaterMeters as string= "C:\Stellar Water Point1\WaterMeters.xml" if string.IsNullOrEmpty(MtbMeterNumber.Text) MsgBox("You must type a water meter number if you want to delete one.", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, "Stellar Water Point") Exit Sub end if if File.Exists(strWaterMeters) = false MsgBox("There is no file for the water meters in the system.", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, "Stellar Water Point") Exit Sub end if xdWaterMeters.Load(strWaterMeters) dim xnlWaterMeters as XmlNodeList = xdWaterMeters.DocumentElement!.GetElementsByTagName("meter-number") for each xnWaterMeter as XmlNode in xnlWaterMeters) if xnWaterMeter.InnerText=MtbMeterNumber.Text) if MsgBox("Are you sure you want to delete this water meter record from the system?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, "Stellar Water Point") =MsgBoxResult.Yes) xdWaterMeters.DocumentElement.RemoveChild(xnWaterMeter.ParentNode!) Exit For end if end if next xdWaterMeters.Save(strWaterMeters) Close() end sub } }
import System.Xml namespace StellarWaterPoint1.WaterMeters public partial class Delete : Form public Delete() InitializeComponent() } private sub BtnFindWateMeter_Click(sender As Object, e As EventArgs) rem If the user clicks the Find button, rem make sure there is a meter number in the top text box. if string.IsNullOrEmpty(MtbMeterNumber.Text)) rem If the user didn't type a meter number, rem display a message box to inform the user. MsgBox("You must type a meter number and then click the Find button.", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, "Stellar Water Point") rem If the user didn't type a meter number but clicked Find, don't do anything Exit Sub } rem We will need a reference to an XML Dom object as an XmlDocument variable dim xdWaterMeters as XmlDocument = new XmlDocument() rem This is the name and path of the file that holds the records of water meters dim strWaterMeters as string= "C:\Stellar Water Point1\WaterMeters.xml" rem We will process the file of water meters using a FileInfo object dim fiWaterMeters as FileInfo= new FileInfo(strWaterMeters) rem We need to find out whether a file for water meters was previously created. if fiWaterMeters.Exists) rem If that file exists, create a stream of it. Open that file with a read-only status using fsWaterMeters as FileStream= new FileStream(fiWaterMeters.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) rem Get the list of water meter records rem and put those records in the XML Dom object created earlier. xdWaterMeters.Load(fsWaterMeters) rem Use XPath to locate the water meter that has rem the same meter number as the one in the Meter # text box. rem Store the water meter in an XmlNodeList variable. dim xnlWaterMeters as XmlNodeList = xdWaterMeters.DocumentElement!.SelectNodes("//meter-number[.='" + MtbMeterNumber.Text + "']")!; rem If there is a water meter in the database with rem the number that the user typed, locate that water meter rem and display each of its values in the appropriate text box. for each xnWaterMeter as XmlNode in xnlWaterMeters) TxtMake.Text = xnWaterMeter.NextSibling.InnerText TxtModel.Text = xnWaterMeter.NextSibling.NextSibling.InnerText TxtMeterSize.Text = xnWaterMeter.NextSibling.NextSibling.NextSibling.InnerText } } } } private sub BtnDeleteWaterMeter_Click(sender As Object, e As EventArgs) rem If the user clicks the Delete button, make sure that rem the right text box contains a meter number if string.IsNullOrEmpty(MtbMeterNumber.Text)) rem If the user didn't provide a meter number, display a message box ... MsgBox("You must type a water meter number if you want to delete one.", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, "Stellar Water Point") rem .. and stop the operation. Exit Sub } rem Create an XML Dom object dim xdWaterMeters as XmlDocument = new XmlDocument() rem Get the file that holds a list of water meters rem and assign that file to a string variable. dim strWaterMeters as string= "C:\Stellar Water Point1\WaterMeters.xml" rem If the user provided a meter number and clicked the Find button, rem check whether a file for water meters was previously created. if !File.Exists(strWaterMeters)) rem If a file for water meters was not created already, display a message box... MsgBox("There is no file for the water meters in the system.", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, "Stellar Water Point") rem .. and stop the operation. Exit Sub } rem Since a file of water meters exists, open it. rem Store the list of water meters in the XML Dom object that was previously created. xdWaterMeters.Load(strWaterMeters) rem From the list of XML elements, get a list of elements based one named meter-number. dim xnlWaterMeters as XmlNodeList = xdWaterMeters.DocumentElement!.GetElementsByTagName("meter-number") rem Visit each XML node from the list for each xnWaterMeter as XmlNode in xnlWaterMeters) rem When you get to an element, check whether its meter number is rem the same number the user had typed. if xnWaterMeter.InnerText=MtbMeterNumber.Text) rem If you find that meter number, enquire from rem the user if the water meter must be deleted. rem To get that information, display a message box with a Yes and a No buttons. if MsgBox("Are you sure you want to delete this water meter record from the system?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, "Stellar Water Point") =MsgBoxResult.Yes) rem If the user had clicked Yes, delete the water meter. xdWaterMeters.DocumentElement.RemoveChild(xnWaterMeter.ParentNode!) Exit For } } } rem Since the list of water meters has been changed, save its new version xdWaterMeters.Save(strWaterMeters) rem After the deletion operation, close the dialog box and rem return to the Central form of water meters. Close() } private sub BtnClose_Click(sender As Object, e As EventArgs) Close() } } }
Control | (Name) | Other Properties | |
ListView | ![]() |
LvwWaterMeters | FullRowSelect: True GridLines: True View: Details Anchor: Top, Bottom, Left, Right |
Button | ![]() |
BtnDeleteWateMeter | &Delete Water Meter... Anchor: Bottom, Right |
Button | ![]() |
BtnClose | &Close Anchor: Bottom, Right |
import System.Xml namespace StellarWaterPoint1.WaterMeters public partial class Central : Form public Central() InitializeComponent() } private sub ShowWaterMeters() rem Create an XML Dom reference dim xdWaterMeters as XmlDocument = new XmlDocument() rem Declare a string variable to have the file that holds a list of water meters dim strWaterMeters as string= "C:\Stellar Water Point1\WaterMeters.xml" rem Create a FileInfo object that holds a reference to the file of water meters dim fiWaterMeters as FileInfo= new FileInfo(strWaterMeters) rem If you are about to display a list of water meters, first empty the list view lvwWaterMeters.Items.Clear() rem Check whether a file for water meters was previously created. if fiWaterMeters.Exists) rem If such a file exists, create a Stream for it using fsWaterMeters as FileStream= new FileStream(fiWaterMeters.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) rem Store the stream of water meters into the XML Dom that was created earlier xdWaterMeters.Load(fsWaterMeters) rem Get a list of the water meter elements from the XML Dom object dim xnlWaterMeters as XmlNodeList = xdWaterMeters.DocumentElement!.ChildNodes; int i = 1; rem Check each water meter for each xnWaterMeter as XmlNode in xnlWaterMeters) rem Create a list view item to hold a record of a water meter dim lviWaterMeter as ListViewItem = new ListViewItem(i.ToString()) lviWaterMeter.SubItems.Add(xnWaterMeter.FirstChild!.InnerText) lviWaterMeter.SubItems.Add(xnWaterMeter.FirstChild.NextSibling!.InnerText) lviWaterMeter.SubItems.Add(xnWaterMeter.FirstChild.NextSibling.NextSibling!.InnerText) lviWaterMeter.SubItems.Add(xnWaterMeter.FirstChild.NextSibling.NextSibling.NextSibling!.InnerText) rem Pass the list view item to the list view object on the form lvwWaterMeters.Items.Add(lviWaterMeter) i++; } } } } private sub Central_Load(sender As Object, e As EventArgs) Handles MyBase.Load rem When the open opens, make an attempt to display a list of water meters. ShowWaterMeters() } private sub BtnNewWaterMeter_Click(sender As Object, e As EventArgs) rem Get a reference to the form used to add a water meter Create wm = new() rem Create a FileInfo object dim fiWaterMeters as FileInfo= nothing rem Create a file stream object FileStream? fsWaterMeters = nothing rem Create an XML Dom object dim xdWaterMeters as XmlDocument = new XmlDocument() rem Declare a string for a file to hold a list of water meters dim strWaterMeters as string= "C:\Stellar Water Point1\WaterMeters.xml" rem Display the form used to create a water meter. rem If the user finishes using that form and click the OK button... if wm.ShowDialog() =MsgBoxResult.OK) rem Store the file of water meters into the FileInfo object that was previously created. fiWaterMeters = new FileInfo(strWaterMeters) rem Find out whether a list of water meters was previously created rem and was stored in the string file declared above. if fiWaterMeters.Exists) rem If that file exists already, create a Stream object rem for it with a read-only status. using (fsWaterMeters = new FileStream(fiWaterMeters.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) rem Pass the list of water meters to the XML Dom object created earlier xdWaterMeters.Load(fsWaterMeters) end using else rem If a file for water meters was not previously created, create it now... using (fsWaterMeters = new FileStream(fiWaterMeters.FullName, FileMode.Create, FileAccess.Write, FileShare.Write)) rem and create the root XML element for it xdWaterMeters.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<water-meters></water-meters>") rem Make sure you save the new file xdWaterMeters.Save(fsWaterMeters) end using end if rem Now that the file exists, open it using (fsWaterMeters = new FileStream(fiWaterMeters.FullName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)) rem Start creating a new Water Meter XML element XmlElement xeWaterMeter = xdWaterMeters.CreateElement("water-meter") rem Use the values that the user had typed in the Create form. rem Use those values to create the child elements of the new water meter node. rem Assign the combination of child elements to the new water meter node. xeWaterMeter.InnerXml = "<meter-number>" + wm.MtbMeterNumber.Text + "</meter-number>" + "<make>" + wm.TxtMake.Text + "</make>" + "<model>" + wm.TxtModel.Text + "</model>" + "<meter-size>" + wm.TxtMeterSize.Text + "</meter-size>" rem Once the XML element is ready, add/append it to the XML Dom that was previously created. xdWaterMeters.DocumentElement!.AppendChild(xeWaterMeter) rem Once the new element has been created and add it to the file, save that file xdWaterMeters.Save(fsWaterMeters) end using end if rem Whenever the user has finished using the Create form, rem make an attempt to display the list of water meters. ShowWaterMeters() end sub private sub BtnViewWaterMeter_Click(sender As Object, e As EventArgs) rem Get a reference to the dialog box that is used rem to view information about a water meter. Details view = new() rem Display that dialog box view.ShowDialog() rem After using the dialog box, make an attempt to display the list of water meters. ShowWaterMeters() end sub private sub BtnEditWaterMeter_Click(sender As Object, e As EventArgs) rem Get a reference to the dialog box that is used rem to update the details of a water meter. Editor editor = new() rem Display that dialog box editor.ShowDialog() rem After using the dialog box, make an attempt to display the list of water meters. ShowWaterMeters() end sub private sub BtnDeleteWateMeter_Click(sender As Object, e As EventArgs) Delete del = new Delete() del.ShowDialog() ShowWaterMeters() end sub private sub BtnClose_Click(sender As Object, e As EventArgs) Close() end sub } }
Customers
Introduction
Customers are the entities that use the services of the bussiness whose application we are building. In this seciton, we will createthe forms that can assist a user with customers-based operations.
Customers Accounts
Our application will use a database that contains a list of customers. As seen with water meter records, some time to time, a user will want to view the customers records. To display a list of customers, we will create a form equipped with a list view.
Practical Learning: Displaying Customers Accounts
Control | (Name) | Other Properties | |
ListView | ![]() |
LvwCustomers | FullRowSelect: True GridLines: True View: Details Anchor: Top, Bottom, Left, Right |
(Name) | Text | TextAlign | Width |
colCustomerId | Id | 40 | |
colAccountNumber | Account # | Center | 150 |
colAccountName | Account Name | 200 | |
colMeterNumber | Meter # | Center | 100 |
colAccountType | Account Type | 200 | |
colAddress | Address | 250 | |
colCity | City | 125 | |
colCounty | County | 125 | |
colState | State | Center | |
colZIPCode | ZIP-Code | Center | 125 |
import System.Xml namespace StellarWaterPoint1.Customers public partial class Central : Form public Central() { InitializeComponent() } private sub ShowCustomers() { int i = 1; lvwCustomers.Items.Clear() XmlDocument xdCustomers = new XmlDocument() string? strCustomers = "C:\Stellar Water Point1\Customers.xml" FileInfo? fiCustomers = new FileInfo(strCustomers) if fiCustomers.Exists) { using fsCustomers as FileStream= new FileStream(fiCustomers.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { xdCustomers.Load(fsCustomers) XmlNodeList xnlCustomers = xdCustomers.DocumentElement!.ChildNodes; for each xnCustomer as XmlNode in xnlCustomers { dim lviCustomer as ListViewItem = new ListViewItem(i.ToString()) lviCustomer.SubItems.Add(xnCustomer.FirstChild!.InnerText) rem Account # lviCustomer.SubItems.Add(xnCustomer.FirstChild.NextSibling!.InnerText) rem Account Name lviCustomer.SubItems.Add(xnCustomer.FirstChild.NextSibling.NextSibling!.InnerText) rem Meter # lviCustomer.SubItems.Add(xnCustomer.FirstChild.NextSibling.NextSibling.NextSibling!.InnerText) rem Account Type lviCustomer.SubItems.Add(xnCustomer.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling!.InnerText) rem Address lviCustomer.SubItems.Add(xnCustomer.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.InnerText) rem City lviCustomer.SubItems.Add(xnCustomer.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.InnerText) rem County lviCustomer.SubItems.Add(xnCustomer.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.InnerText) rem State lviCustomer.SubItems.Add(xnCustomer.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.InnerText) rem ZIP-Code lvwCustomers.Items.Add(lviCustomer) i++; } } } } private sub Central_Load(sender As Object, e As EventArgs) Handles MyBase.Load { ShowCustomers() } } }
Control | (Name) | Text | Font | |
Button | ![]() |
BtnCustomers | &Customers... | Times New Roman, 24pt, style=Bold |
namespace StellarWaterPoint1
{
public partial class WaterDistribution : Form
{
public WaterDistribution()
{
InitializeComponent()
}
private sub WaterDistribution_Load(sender As Object, e As EventArgs) Handles MyBase.Load
{
rem If the directory for the database doesn't yet exist, create it
Directory.CreateDirectory("C:\Stellar Water Point")
}
private sub BtnCustomers_Click(sender As Object, e As EventArgs)
{
Customers.Central central = new Customers.Central()
central.ShowDialog()
}
private sub BtnWaterMeters_Click(sender As Object, e As EventArgs)
{
WaterMeters.Central central = new WaterMeters.Central()
central.ShowDialog()
}
}
}
A Customer's Account
As mentioned already, our application will use a database that contains a list of customers. This means that a customer must have an account. We will create a form to let the user create an account. Each customer account must have an associated water meter.
Practical Learning: Creating a Customer Account
Control | (Name) | Text | Other Properties | |
Label | ![]() |
&Account #: | ||
MaskedTextBox | ![]() |
MtbAccountNumber | Masked: 0000-000-0000 | |
Label | ![]() |
&Account Name: | ||
TextBox | ![]() |
TxtAccountName | ||
Label | ![]() |
&Meter #: | ||
MaskedTextBox | ![]() |
MtbMeterNumber | Masked: 000-000-000 | |
Button | ![]() |
BtnFindWaterMeter | &Find Water Meter | |
Label | ![]() |
Meter &Details: | ||
TextBox | ![]() |
TxtMeterDetails | Enabled: False | |
Label | ![]() |
&Account Type: | ||
ComboBox | ![]() |
cbxAccountsTypes | Items:
OTH - Other BUS - General Business RES - Residential Household SGO - Social/Government/Non - Profit Organization UUO - Unidentified or Unclassified Type of Organization WAT - Water Intensive Business(Laudromat, Hair Salon, Restaurant, etc |
|
Label | ![]() |
&Address: | ||
TextBox | ![]() |
TxtAddress | ||
Label | ![]() |
C&ity: | ||
TextBox | ![]() |
TxtCity | ||
Label | ![]() |
C&ounty: | ||
TextBox | ![]() |
TxtCounty | ||
Label | ![]() |
&State: | ||
TextBox | ![]() |
TxtState | ||
Label | ![]() |
&ZIP-Code: | ||
MaskedTextBox | ![]() |
MtbZIPCode | Masked: Zip-Code | |
Button | ![]() |
BtnSaveCustomerAccount | S&ave Customer Account | DialogResult: OK |
Button | ![]() |
BtnClose | &Close | DialogResult: Cancel |
FormBorderStyle: FixedDialog Text: Stellar Water Point - Customer Account Setup StartPosition: CenterScreen AcceptButton: BtnSaveCustomerAccount CancelButton: BtnClose MinimizeBox: False MaximizeBox: False
import System.Xml namespace StellarWaterPoint1.Customers { public partial class Create : Form { public Create() { InitializeComponent() } private sub BtnFindWaterMeter_Click(sender As Object, e As EventArgs) { rem Create an XML Dom object dim xdWaterMeters as XmlDocument = new XmlDocument() rem Declare a string variable and assign the file of water meters to it dim strWaterMeters as string= "C:\Stellar Water Point1\WaterMeters.xml" rem Create a FileInfo object to manage the file that has the water meters dim fiWaterMeters as FileInfo= new FileInfo(strWaterMeters) rem Find out whether a file for water meters exists already if fiWaterMeters.Exists) { rem If a file for water meters exists already, create a Stream object for it using fsWaterMeters as FileStream= new FileStream(fiWaterMeters.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { rem From the file of water meters, store the list of water meters rem in the XML Dom that was previously created. xdWaterMeters.Load(fsWaterMeters) rem Check the list of water meters. rem Find a water meter that has the same name as the meter number that the user typed. dim xnlWaterMeters as XmlNodeList = xdWaterMeters.DocumentElement!.SelectNodes("//meter-number[.='" + MtbMeterNumber.Text + "']")!; rem If such a water meter exists... for each xnWaterMeter as XmlNode in xnlWaterMeters) { rem ... store its details in the meter details text box. TxtMeterDetails.Text = xnWaterMeter.NextSibling!.InnerText + " " + xnWaterMeter.NextSibling.NextSibling!.InnerText + " (Meter Size: " + xnWaterMeter.NextSibling.NextSibling.NextSibling!.InnerText + ")" } } } } } }
Control | (Name) | Other Properties | |
ListView | ![]() |
LvwCustomers | |
Button | ![]() |
BtnCreateCustomerAccount | &Create Customer Account... Anchor: Bottom, Right |
import System.Xml namespace StellarWaterPoint1.Customers { public partial class Central : Form { public Central() { InitializeComponent() } private sub ShowCustomers() { int i = 1; lvwCustomers.Items.Clear() XmlDocument xdCustomers = new XmlDocument() string? strCustomers = "C:\Stellar Water Point1\Customers.xml" FileInfo? fiCustomers = new FileInfo(strCustomers) if fiCustomers.Exists) { using fsCustomers as FileStream= new FileStream(fiCustomers.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { xdCustomers.Load(fsCustomers) XmlNodeList xnlCustomers = xdCustomers.DocumentElement!.ChildNodes; for each xnCustomer as XmlNode in xnlCustomers { dim lviCustomer as ListViewItem = new ListViewItem(i.ToString()) lviCustomer.SubItems.Add(xnCustomer.FirstChild!.InnerText) rem Account # lviCustomer.SubItems.Add(xnCustomer.FirstChild.NextSibling!.InnerText) rem Account Name lviCustomer.SubItems.Add(xnCustomer.FirstChild.NextSibling.NextSibling!.InnerText) rem Meter # lviCustomer.SubItems.Add(xnCustomer.FirstChild.NextSibling.NextSibling.NextSibling!.InnerText) rem Account Type lviCustomer.SubItems.Add(xnCustomer.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling!.InnerText) rem Address lviCustomer.SubItems.Add(xnCustomer.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.InnerText) rem City lviCustomer.SubItems.Add(xnCustomer.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.InnerText) rem County lviCustomer.SubItems.Add(xnCustomer.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.InnerText) rem State lviCustomer.SubItems.Add(xnCustomer.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.InnerText) rem ZIP-Code lvwCustomers.Items.Add(lviCustomer) i++; } } } } private sub Central_Load(sender As Object, e As EventArgs) Handles MyBase.Load { rem When the form opens, try displaying the list of customers ShowCustomers() } private sub BtnCreateCustomerAccount_Click(sender As Object, e As EventArgs) { Create create = new Create() if create.ShowDialog() =MsgBoxResult.OK) { rem Make sure the user provides an account number for the new account. rem If not, don't create the account. if string.IsNullOrEmpty(create.MtbAccountNumber.Text)) { MsgBox("You must provide an account number for the new customer. " + "Otherwise, the account cannot be created.", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, "Stellar Water Point") Exit Sub } rem If the meter details text box is empty, it means the user didn't enter rem a meter number, in which case there is no water meter associated rem with the account. The account cannot be created. if string.IsNullOrEmpty(create.TxtMeterDetails.Text)) { MsgBox("You must enter a water meter to associate with a new customer's account.", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, "Stellar Water Point") Exit Sub } rem Create a FileInfo object that will be used to manage a file FileInfo? fiCustomers = nothing rem Start a Stream object that will be used to manage a file FileStream? fsCustomers = nothing rem Create an XML Dom XmlDocument xdCustomers = new XmlDocument() rem Declare a string variable for the file that contains a list of customers string? strCustomers = "C:\Stellar Water Point1\Customers.xml" rem Pass the file of customers to the FileInfo object that was started fiCustomers = new FileInfo(strCustomers) rem Find out whether that file was already created if fiCustomers.Exists) { rem If that file was already created, open it through rem the Stream object that was previously initiated. using (fsCustomers = new FileStream(fiCustomers.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { rem Pass the Stream object to the XML Dom that was previously created. xdCustomers.Load(fsCustomers) } } else { rem If the file of customers was not created already, start by rem initializing the Stream object that was previously initiated. using (fsCustomers = new FileStream(fiCustomers.FullName, FileMode.Create, FileAccess.Write, FileShare.Write)) { rem Create a root to start the XML file xdCustomers.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<customers></customers>") rem Once the file has been started, save it xdCustomers.Save(fsCustomers) } } rem Now that we have an XML file for customers, open it using (fsCustomers = new FileStream(fiCustomers.FullName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)) { rem We want to create an XML element to be added to the XML file. rem To start, create an XML element named "customer". XmlElement xeCustomer = xdCustomers.CreateElement("customer") rem Create/Format the child nodes of the "customer" element xeCustomer.InnerXml = "<account-number>" + create.MtbAccountNumber.Text + "</account-number>" + "<account-name>" + create.TxtAccountName.Text + "</account-name>" + "<meter-number>" + create.MtbMeterNumber.Text + "</meter-number>" + "<account-type>" + create.cbxAccountsTypes.Text + "</account-type>" + "<address>" + create.TxtAddress.Text + "</address>" + "<city>" + create.TxtCity.Text + "</city>" + "<county>" + create.TxtCounty.Text + "</county>" + "<state>" + create.TxtState.Text + "</state>" + "<zip-code>" + create.MtbZIPCode.Text + "</zip-code>" xdCustomers.DocumentElement!.AppendChild(xeCustomer) xdCustomers.Save(fsCustomers) } } ShowCustomers() } } }
Account #: 9279-570-8394 Account Name: Thomas Stones Meter #: 799-528-461 Account Type: RES - Residential Household Address: 10252 Broward Ave #D4 City: Frederick County: Frederick State: MD ZIP-Code: 21703-4422
Account # | Account Name | Meter # | Account Type | Address | City | County | State | ZIP-Code |
4086-938-4783 | Hernola Dough | 594-827-359 | UUO - Unidentified or Unclassified Type of Organization | 10 10 Hexagonal Drv | Winston | Yoke | Penn | 11402-4411 |
7080-583-5947 | Sunny Yard | 827-508-248 | WAT - Water Intensive Business(Laudromat, Hair Salon, Restaurant, etc | 663 Sherry Wood East Street | Shimpstown | Franklin | PA | 17236-2626 |
A Review of a Customer's Account
Some time to time, a user will want to review the details of a customer's account. We will create a form to assist the user with this.
Practical Learning: Creating a Water Meter Record
Control | (Name) | Text | Other Properties | |
Label | ![]() |
&Account #: | ||
MaskedTextBox | ![]() |
MtbAccountNumber | Masked: 0000-000-0000 | |
Button | ![]() |
BtnFindCustomerAccount | &Find Customer Account | |
Label | ![]() |
Account Name: | ||
TextBox | ![]() |
TxtAccountName | Enabled: False | |
Label | ![]() |
Meter #: | ||
TextBox | ![]() |
TxtMeterNumber | Enabled: False | |
Label | ![]() |
Meter Details: | ||
TextBox | ![]() |
TxtMeterDetails | Enabled: False | |
Label | ![]() |
Account Type: | ||
TextBox | ![]() |
TxtAccountType | Enabled: False | |
Label | ![]() |
Address: | ||
TextBox | ![]() |
TxtAddress | Enabled: False | |
Label | ![]() |
City: | ||
TextBox | ![]() |
TxtCity | Enabled: False | |
Label | ![]() |
County: | ||
TextBox | ![]() |
TxtCounty | Enabled: False | |
Label | ![]() |
State: | ||
TextBox | ![]() |
TxtState | Enabled: False | |
Label | ![]() |
ZIP-Code: | Enabled: False | |
TextBox | ![]() |
TxtZIPCode | Enabled: False | |
Button | ![]() |
BtnClose | &Close |
FormBorderStyle: FixedDialog Text: Stellar Water Point - Customer Account Setup StartPosition: CenterScreen MinimizeBox: False MaximizeBox: False
import System.Xml namespace StellarWaterPoint1.Customers { public partial class Details : Form { public Details() { InitializeComponent() } private sub BtnFindCustomerAccount_Click(sender As Object, e As EventArgs) { XmlDocument xdCustomers = new XmlDocument() string? strCustomers = "C:\Stellar Water Point1\Customers.xml" FileInfo? fiCustomers = new FileInfo(strCustomers) string strMeterNumber = string.Empty; if fiCustomers.Exists) { using fsCustomers as FileStream= new FileStream(fiCustomers.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { xdCustomers.Load(fsCustomers) XmlNodeList xnlCustomers = xdCustomers.DocumentElement!.SelectNodes("//account-number[.='" + MtbAccountNumber.Text + "']")!; for each xnCustomer as XmlNode in xnlCustomers { //MtbAccountNumber.Text = xnCustomer.NextSibling.InnerText rem Meter # TxtAccountName.Text = xnCustomer.NextSibling.InnerText rem Account Name TxtMeterNumber.Text = xnCustomer.NextSibling.NextSibling.InnerText rem Meter Number strMeterNumber = xnCustomer.NextSibling.NextSibling.InnerText rem Meter Number TxtAccountType.Text = xnCustomer.NextSibling.NextSibling.NextSibling.InnerText rem Account Type TxtAddress.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.InnerText rem Address TxtCity.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText rem City TxtCounty.Text = xnCustomer.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling.InnerText rem County TxtState.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText rem State TxtZIPCode.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText rem ZIP-Code } } } dim xdWaterMeters as XmlDocument = new XmlDocument() dim strWaterMeters as string= "C:\Stellar Water Point10\WaterMeters.xml" dim fiWaterMeters as FileInfo= new FileInfo(strWaterMeters) if fiWaterMeters.Exists) { using fsWaterMeters as FileStream= new FileStream(fiWaterMeters.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { xdWaterMeters.Load(fsWaterMeters) dim xnlWaterMeters as XmlNodeList = xdWaterMeters.DocumentElement!.SelectNodes("//meter-number[.='" + strMeterNumber + "']")!; for each xnWaterMeter as XmlNode in xnlWaterMeters) { TxtMeterDetails.Text = xnWaterMeter.NextSibling!.InnerText + " " + xnWaterMeter.NextSibling.NextSibling!.InnerText + " (Meter Size: " + xnWaterMeter.NextSibling.NextSibling.NextSibling!.InnerText + ")" } } } } } }
import System.Xml
namespace StellarWaterPoint1.Customers
{
public partial class Details : Form
{
public Details()
{
InitializeComponent()
}
private sub BtnFindCustomerAccount_Click(sender As Object, e As EventArgs)
{
rem Create an XML DOM object for the customers records
XmlDocument xdCustomers = new XmlDocument()
rem Declare a variable for a file that holds the list of customers
string? strCustomers = "C:\Stellar Water Point10\Customers.xml"
rem Create a FileInfo object for the customers
FileInfo? fiCustomers = new FileInfo(strCustomers)
rem We will need to know the water meter associated with this customer account
string strMeterNumber = string.Empty;
rem Check whether the file that holds a list of customers exists
if fiCustomers.Exists)
{
rem If that exists, open it and pass it to a FileStream object
using fsCustomers as FileStream= new FileStream(fiCustomers.FullName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
rem Get the list of customers and pass the records to the XML DOM object created earlier
xdCustomers.Load(fsCustomers)
rem Create an XmlNodeList list of customers using XPath
XmlNodeList xnlCustomers = xdCustomers.DocumentElement!.SelectNodes("//account-number[.='" + MtbAccountNumber.Text + "']")!;
rem Check each node of the XML record and display its values in each Windows control on the form
for each xnCustomer as XmlNode in xnlCustomers
{
//MtbAccountNumber.Text = xnCustomer.NextSibling.InnerText rem Meter #
TxtAccountName.Text = xnCustomer.NextSibling.InnerText rem Account Name
TxtMeterNumber.Text = xnCustomer.NextSibling.NextSibling.InnerText rem Meter Number
strMeterNumber = xnCustomer.NextSibling.NextSibling.InnerText rem Meter Number
TxtAccountType.Text = xnCustomer.NextSibling.NextSibling.NextSibling.InnerText rem Account Type
TxtAddress.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.InnerText rem Address
TxtCity.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText rem City
TxtCounty.Text = xnCustomer.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling.InnerText rem County
TxtState.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText rem State
TxtZIPCode.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText rem ZIP-Code
}
}
}
rem Create an XML DOM object for the water meters records
dim xdWaterMeters as XmlDocument = new XmlDocument()
rem Declare a variable for a file that holds the list of water meters
dim strWaterMeters as string= "C:\Stellar Water Point10\WaterMeters.xml"
rem Create a FileInfo object for the customers
dim fiWaterMeters as FileInfo= new FileInfo(strWaterMeters)
rem Check whether the file that holds a list of water meters exists
if fiWaterMeters.Exists)
{
rem Get the list of water meters and pass the records to the XML DOM object
using fsWaterMeters as FileStream= new FileStream(fiWaterMeters.FullName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
rem Get the list of water meters and pass the records to the XML DOM object
xdWaterMeters.Load(fsWaterMeters)
rem Create an XmlNodeList list of water meters using XPath
dim xnlWaterMeters as XmlNodeList = xdWaterMeters.DocumentElement!.SelectNodes("//meter-number[.='" + strMeterNumber + "']")!;
rem Check each node of the XML record
for each xnWaterMeter as XmlNode in xnlWaterMeters)
{
rem Get the values for the water meter.
rem Create a sentence and display it in the Meter Details text box.
TxtMeterDetails.Text = xnWaterMeter.NextSibling!.InnerText + " " +
xnWaterMeter.NextSibling.NextSibling!.InnerText + " (Meter Size: " +
xnWaterMeter.NextSibling.NextSibling.NextSibling!.InnerText + ")"
}
}
}
}
private sub BtnClose_Click(sender As Object, e As EventArgs)
{
Close()
}
}
}
Control | (Name) | Other Properties | |
Button | ![]() |
BtnViewCustomerAccount | &View Customer Account... Anchor: Bottom, Right |
import System.Xml namespace StellarWaterPoint1.Customers { public partial class Details : Form { public Details() { InitializeComponent() } private sub BtnFindCustomerAccount_Click(sender As Object, e As EventArgs) { XmlDocument xdCustomers = new XmlDocument() string? strCustomers = "C:\Stellar Water Point10\Customers.xml" FileInfo? fiCustomers = new FileInfo(strCustomers) string strMeterNumber = string.Empty; if fiCustomers.Exists) { using fsCustomers as FileStream= new FileStream(fiCustomers.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { xdCustomers.Load(fsCustomers) XmlNodeList xnlCustomers = xdCustomers.DocumentElement!.SelectNodes("//account-number[.='" + MtbAccountNumber.Text + "']")!; for each xnCustomer as XmlNode in xnlCustomers { //MtbAccountNumber.Text = xnCustomer.NextSibling.InnerText rem Meter # TxtAccountName.Text = xnCustomer.NextSibling.InnerText rem Account Name TxtMeterNumber.Text = xnCustomer.NextSibling.NextSibling.InnerText rem Meter Number strMeterNumber = xnCustomer.NextSibling.NextSibling.InnerText rem Meter Number TxtAccountType.Text = xnCustomer.NextSibling.NextSibling.NextSibling.InnerText rem Account Type TxtAddress.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.InnerText rem Address TxtCity.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText rem City TxtCounty.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling.InnerText rem County TxtState.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText rem State TxtZIPCode.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText rem ZIP-Code } } } dim xdWaterMeters as XmlDocument = new XmlDocument() dim strWaterMeters as string= "C:\Stellar Water Point10\WaterMeters.xml" dim fiWaterMeters as FileInfo= new FileInfo(strWaterMeters) if fiWaterMeters.Exists) { using fsWaterMeters as FileStream= new FileStream(fiWaterMeters.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { xdWaterMeters.Load(fsWaterMeters) dim xnlWaterMeters as XmlNodeList = xdWaterMeters.DocumentElement!.SelectNodes("//meter-number[.='" + strMeterNumber + "']")!; for each xnWaterMeter as XmlNode in xnlWaterMeters) { TxtMeterDetails.Text = xnWaterMeter.NextSibling!.InnerText + " " + xnWaterMeter.NextSibling.NextSibling!.InnerText + " (Meter Size: " + xnWaterMeter.NextSibling.NextSibling.NextSibling!.InnerText + ")" } } } } } }
Updating a Customer's Account
Some time to time, a piece of information changes about a customer's account. When that happens, a user must update such an account. To assist the users in performing such an operation, we will create a form.
Practical Learning: Updating a Water Meter
Control | (Name) | Text | Other Properties | |
Button | ![]() |
BtnFindCustomerAccount | &Find Customer Account | |
Button | ![]() |
BtnUpdateWateMeter | &Update Water Meter | DialogResult: OK |
Button | ![]() |
BtnClose | &Close | DialogResult: Cancel |
FormBorderStyle: FixedDialog Text: Stellar Water Point - Customer Account Editor StartPosition: CenterScreen AcceptButton: BtnUpdateWateMeter CancelButton: BtnClose MinimizeBox: False MaximizeBox: False
import System.Xml namespace StellarWaterPoint1.Customers { public partial class Editor : Form { public Editor() { InitializeComponent() } private sub BtnFindCustomerAccount_Click(sender As Object, e As EventArgs) { XmlDocument xdCustomers = new XmlDocument() string? strCustomers = "C:\Stellar Water Point10\Customers.xml" FileInfo? fiCustomers = new FileInfo(strCustomers) string strMeterNumber = string.Empty; if fiCustomers.Exists) { using fsCustomers as FileStream= new FileStream(fiCustomers.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { xdCustomers.Load(fsCustomers) XmlNodeList xnlCustomers = xdCustomers.DocumentElement!.SelectNodes("//account-number[.='" + MtbAccountNumber.Text + "']")!; for each xnCustomer as XmlNode in xnlCustomers { //MtbAccountNumber.Text = xnCustomer.NextSibling.InnerText rem Meter # TxtAccountName.Text = xnCustomer.NextSibling.InnerText rem Account Name MtbMeterNumber.Text = xnCustomer.NextSibling.NextSibling.InnerText rem Meter Number strMeterNumber = xnCustomer.NextSibling.NextSibling.InnerText rem Meter Number cbxAccountsTypes.Text = xnCustomer.NextSibling.NextSibling.NextSibling.InnerText rem Account Type TxtAddress.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.InnerText rem Address TxtCity.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText rem City TxtCounty.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling.InnerText rem County TxtState.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText rem State MtbZIPCode.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText rem ZIP-Code } } } dim xdWaterMeters as XmlDocument = new XmlDocument() dim strWaterMeters as string= "C:\Stellar Water Point10\WaterMeters.xml" dim fiWaterMeters as FileInfo= new FileInfo(strWaterMeters) if fiWaterMeters.Exists) { using fsWaterMeters as FileStream= new FileStream(fiWaterMeters.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { xdWaterMeters.Load(fsWaterMeters) dim xnlWaterMeters as XmlNodeList = xdWaterMeters.DocumentElement!.SelectNodes("//meter-number[.='" + strMeterNumber + "']")!; for each xnWaterMeter as XmlNode in xnlWaterMeters) { TxtMeterDetails.Text = xnWaterMeter.NextSibling!.InnerText + " " + xnWaterMeter.NextSibling.NextSibling!.InnerText + " (Meter Size: " + xnWaterMeter.NextSibling.NextSibling.NextSibling!.InnerText + ")" } } } } } }
import System.Xml
namespace StellarWaterPoint1.Customers
{
public partial class Editor : Form
{
public Editor()
{
InitializeComponent()
}
private sub BtnFindCustomerAccount_Click(sender As Object, e As EventArgs)
{
XmlDocument xdCustomers = new XmlDocument()
string? strCustomers = "C:\Stellar Water Point10\Customers.xml"
FileInfo? fiCustomers = new FileInfo(strCustomers)
string strMeterNumber = string.Empty;
if fiCustomers.Exists)
{
using fsCustomers as FileStream= new FileStream(fiCustomers.FullName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
xdCustomers.Load(fsCustomers)
XmlNodeList xnlCustomers = xdCustomers.DocumentElement!.SelectNodes("//account-number[.='" + MtbAccountNumber.Text + "']")!;
for each xnCustomer as XmlNode in xnlCustomers
rem MtbAccountNumber.Text = xnCustomer.NextSibling.InnerText
TxtAccountName.Text = xnCustomer.NextSibling.InnerText
MtbMeterNumber.Text = xnCustomer.NextSibling.NextSibling.InnerText
strMeterNumber = xnCustomer.NextSibling.NextSibling.InnerText
cbxAccountsTypes.Text = xnCustomer.NextSibling.NextSibling.NextSibling.InnerText
TxtAddress.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.InnerText
TxtCity.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText
TxtCounty.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling.InnerText
TxtState.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText
MtbZIPCode.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText
next
}
}
dim xdWaterMeters as XmlDocument = new XmlDocument()
dim strWaterMeters as string= "C:\Stellar Water Point10\WaterMeters.xml"
dim fiWaterMeters as FileInfo= new FileInfo(strWaterMeters)
if fiWaterMeters.Exists)
{
using fsWaterMeters as FileStream= new FileStream(fiWaterMeters.FullName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
xdWaterMeters.Load(fsWaterMeters)
dim xnlWaterMeters as XmlNodeList = xdWaterMeters.DocumentElement!.SelectNodes("//meter-number[.='" + strMeterNumber + "']")!;
for each xnWaterMeter as XmlNode in xnlWaterMeters)
{
TxtMeterDetails.Text = xnWaterMeter.NextSibling!.InnerText + " " +
xnWaterMeter.NextSibling.NextSibling!.InnerText + " (Meter Size: " +
xnWaterMeter.NextSibling.NextSibling.NextSibling!.InnerText + ")"
}
}
}
}
private sub BtnFindWateMeter_Click(sender As Object, e As EventArgs)
{
dim xdWaterMeters as XmlDocument = new XmlDocument()
dim strWaterMeters as string= "C:\Stellar Water Point10\WaterMeters.xml"
dim fiWaterMeters as FileInfo= new FileInfo(strWaterMeters)
if fiWaterMeters.Exists)
{
using fsWaterMeters as FileStream= new FileStream(fiWaterMeters.FullName, FileMode.Open,
FileAccess.Read, FileShare.Read))
{
xdWaterMeters.Load(fsWaterMeters)
dim xnlWaterMeters as XmlNodeList = xdWaterMeters.DocumentElement!.SelectNodes("//meter-number[.='" + MtbMeterNumber.Text + "']")!;
for each xnWaterMeter as XmlNode in xnlWaterMeters)
{
TxtMeterDetails.Text = xnWaterMeter.NextSibling!.InnerText + " " +
xnWaterMeter.NextSibling.NextSibling!.InnerText + " (Meter Size: " +
xnWaterMeter.NextSibling.NextSibling.NextSibling!.InnerText + ")"
}
}
}
}
}
}
Control | (Name) | Text | Other Properties | |
ListView | ![]() |
LvwCustomers | No Change | |
Button | ![]() |
BtnNewCustomerAccount | No Change | |
Button | ![]() |
BtnViewCustomerAccount | No Change | |
Button | ![]() |
BtnEditCustomerAccount | &Edit Water Meter... | Anchor: Bottom, Right |
import System.Xml
namespace StellarWaterPoint1.Customers
{
public partial class Central : Form
{
public Central()
{
InitializeComponent()
}
private sub ShowCustomers()
{
. . .
}
private sub Central_Load(sender As Object, e As EventArgs) Handles MyBase.Load
{
ShowCustomers()
}
private sub BtnCreateCustomerAccount_Click(sender As Object, e As EventArgs)
{
. . .
}
private sub ViewCustomerAccount_Click(sender As Object, e As EventArgs)
{
Details det = new Details()
det.ShowDialog()
}
private sub BtnEditCustomerAccount_Click(sender As Object, e As EventArgs)
{
Editor editor = new()
XmlDocument xdCustomers = new XmlDocument()
string? strCustomers = "C:\Stellar Water Point10\Customers.xml"
if editor.ShowDialog() =MsgBoxResult.OK
xdCustomers.Load(strCustomers)
XmlNodeList xnlCustomers = xdCustomers.DocumentElement!.GetElementsByTagName("account-number")
for each xnCustomer as XmlNode in xnlCustomers
if xnCustomer.InnerText.Contains(editor.MtbAccountNumber.Text)
xnCustomer.ParentNode!.InnerXml = "<account-number>" + editor.MtbAccountNumber.Text + "</account-number>" +
"<account-name>" + editor.TxtAccountName.Text + "</account-name>" +
"<meter-number>" + editor.MtbMeterNumber.Text + "</meter-number>" +
"<account-type>" + editor.cbxAccountsTypes.Text + "</account-type>" +
"<address>" + editor.TxtAddress.Text + "</address>" +
"<city>" + editor.TxtCity.Text + "</city>" +
"<county>" + editor.TxtCounty.Text + "</county>" +
"<state>" + editor.TxtState.Text + "</state>" +
"<zip-code>" + editor.MtbZIPCode.Text + "</zip-code>"
xdCustomers.Save(strCustomers)
Exit For
end if
next
end if
ShowCustomers()
}
}
}
Account Name: Bernotte's Doughnuts Meter #: 580-742-825 and click Find Water Meter Account Type: BUS - General Business Address: 10103 Hexagon Drive City: Winterstown County: York State: PA ZIP-Code: 17402-8828
Deleting a Customer's Account
If a customer's account is not necessary anymore, the user can remove that account. To assist the user with this operation, we will create a form with necessary buttons.
Practical Learning: Deleting a Customer Account
Control | (Name) | Text | Othe Properties | |
Button | ![]() |
BtnDeleteCustomerAccount | &Delete Water Meter | DialogResult: OK |
Button | ![]() |
BtnClose | &Close | DialogResult: Cancel |
FormBorderStyle: FixedDialog Text: Stellar Water Point - Customer Account Deletion StartPosition: CenterScreen AcceptButton: BtnDeleteCustomerAccount CancelButton: BtnClose MinimizeBox: False MaximizeBox: False
import System.Xml namespace StellarWaterPoint1.Customers { public partial class Delete : Form { public Delete() { InitializeComponent() } private sub BtnFindCustomerAccount_Click(sender As Object, e As EventArgs) { rem Create an XML DOM object for the customers records XmlDocument xdCustomers = new XmlDocument() rem Declare a variable for a file that holds the list of customers string? strCustomers = "C:\Stellar Water Point10\Customers.xml" rem Create a FileInfo object for the customers FileInfo? fiCustomers = new FileInfo(strCustomers) rem We will need to know the water meter associated with this customer account string strMeterNumber = string.Empty; rem Check whether the file that holds a list of customers exists if fiCustomers.Exists rem If that exists, open it and pass it to a FileStream object using fsCustomers as FileStream= new FileStream(fiCustomers.FullName, FileMode.Open, FileAccess.Read, FileShare.Read) rem Get the list of customers and pass the records to the XML DOM object created earlier xdCustomers.Load(fsCustomers) rem Create an XmlNodeList list of customers using XPath XmlNodeList xnlCustomers = xdCustomers.DocumentElement!.SelectNodes("//account-number[.='" + MtbAccountNumber.Text + "']")!; rem Check each node of the XML record and display its values in each Windows control on the form for each xnCustomer as XmlNode in xnlCustomers rem MtbAccountNumber.Text = xnCustomer.NextSibling.InnerText TxtAccountName.Text = xnCustomer.NextSibling.InnerText TxtMeterNumber.Text = xnCustomer.NextSibling.NextSibling.InnerText strMeterNumber = xnCustomer.NextSibling.NextSibling.InnerText TxtAccountType.Text = xnCustomer.NextSibling.NextSibling.NextSibling.InnerText TxtAddress.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.InnerText TxtCity.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText TxtCounty.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling.InnerText TxtState.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtZIPCode.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText next end using end if rem Create an XML DOM object for the water meters records dim xdWaterMeters as XmlDocument = new XmlDocument() rem Declare a variable for a file that holds the list of water meters dim strWaterMeters as string= "C:\Stellar Water Point10\WaterMeters.xml" rem Create a FileInfo object for the customers dim fiWaterMeters as FileInfo= new FileInfo(strWaterMeters) rem Check whether the file that holds a list of water meters exists if fiWaterMeters.Exists rem Get the list of water meters and pass the records to the XML DOM object using fsWaterMeters as FileStream= new FileStream(fiWaterMeters.FullName, FileMode.Open, FileAccess.Read, FileShare.Read) rem Get the list of water meters and pass the records to the XML DOM object xdWaterMeters.Load(fsWaterMeters) rem Create an XmlNodeList list of water meters using XPath dim xnlWaterMeters as XmlNodeList = xdWaterMeters.DocumentElement!.SelectNodes("//meter-number[.='" + strMeterNumber + "']")!; rem Check each node of the XML record for each xnWaterMeter as XmlNode in xnlWaterMeters) rem Get the values for the water meter. rem Create a sentence and display it in the Meter Details text box. TxtMeterDetails.Text = xnWaterMeter.NextSibling!.InnerText + " " + xnWaterMeter.NextSibling.NextSibling!.InnerText + " (Meter Size: " + xnWaterMeter.NextSibling.NextSibling.NextSibling!.InnerText + ")" next end using end if } } }
Control | (Name) | Other Properties | |
ListView | ![]() |
LvwCustomers | |
Button | ![]() |
BtnDeleteCustomerAcount | &Delete Customer Acount... Anchor: Bottom, Right |
Button | ![]() |
BtnClose | &Close Anchor: Bottom, Right |
import System.Xml namespace StellarWaterPoint1.Customers { public partial class Central : Form { public Central() { InitializeComponent() } private sub ShowCustomers() { int i = 1; lvwCustomers.Items.Clear() XmlDocument xdCustomers = new XmlDocument() string? strCustomers = "C:\Stellar Water Point10\Customers.xml" FileInfo? fiCustomers = new FileInfo(strCustomers) if fiCustomers.Exists using fsCustomers as FileStream= new FileStream(fiCustomers.FullName, FileMode.Open, FileAccess.Read, FileShare.Read) xdCustomers.Load(fsCustomers) XmlNodeList xnlCustomers = xdCustomers.DocumentElement!.ChildNodes; for each xnCustomer as XmlNode in xnlCustomers dim lviCustomer as ListViewItem = new ListViewItem(CStr(i)) lviCustomer.SubItems.Add(xnCustomer.FirstChild!.InnerText) rem Account # lviCustomer.SubItems.Add(xnCustomer.FirstChild.NextSibling!.InnerText) rem Account Name lviCustomer.SubItems.Add(xnCustomer.FirstChild.NextSibling.NextSibling!.InnerText) rem Meter # lviCustomer.SubItems.Add(xnCustomer.FirstChild.NextSibling.NextSibling.NextSibling!.InnerText) rem Account Type lviCustomer.SubItems.Add(xnCustomer.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling!.InnerText) rem Address lviCustomer.SubItems.Add(xnCustomer.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.InnerText) rem City lviCustomer.SubItems.Add(xnCustomer.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.InnerText) rem County lviCustomer.SubItems.Add(xnCustomer.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.InnerText) rem State lviCustomer.SubItems.Add(xnCustomer.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.InnerText) rem ZIP-Code lvwCustomers.Items.Add(lviCustomer) i = i + 1 next end using end if } private sub Central_Load(sender As Object, e As EventArgs) Handles MyBase.Load { ShowCustomers() } private sub BtnCreateCustomerAccount_Click(sender As Object, e As EventArgs) { Create create = new Create() if create.ShowDialog() =MsgBoxResult.OK rem Make sure the user provides an account number for the new account. rem If not, don't create the account. if string.IsNullOrEmpty(create.MtbAccountNumber.Text) MsgBox("You must provide an account number for the new customer. " + "Otherwise, the account cannot be created.", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, "Stellar Water Point") Exit Sub end if rem If the meter details text box is empty, it means the user didn't enter rem a meter number, in which case there is no water meter associated rem with the account. The account cannot be created. if string.IsNullOrEmpty(create.TxtMeterDetails.Text) MsgBox("You must enter a water meter to associate with a new customer's account.", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information, "Stellar Water Point") Exit Sub end if rem Create a FileInfo object that will be used to manage a file FileInfo? fiCustomers = nothing rem Start a Stream object that will be used to manage a file FileStream? fsCustomers = nothing rem Create an XML Dom XmlDocument xdCustomers = new XmlDocument() rem Declare a string variable for the file that contains a list of customers string? strCustomers = "C:\Stellar Water Point10\Customers.xml" rem Pass the file of customers to the FileInfo object that was started fiCustomers = new FileInfo(strCustomers) rem Find out whether that file was already created if fiCustomers.Exists rem If that file was already created, open it through rem the Stream object that was previously initiated. using (fsCustomers = new FileStream(fiCustomers.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) rem Pass the Stream object to the XML Dom that was previously created. xdCustomers.Load(fsCustomers) end using else rem If the file of customers was not created already, start by rem initializing the Stream object that was previously initiated. using (fsCustomers = new FileStream(fiCustomers.FullName, FileMode.Create, FileAccess.Write, FileShare.Write)) rem Create a root to start the XML file xdCustomers.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<customers></customers>") rem Once the file has been started, save it xdCustomers.Save(fsCustomers) end using end if rem Now that we have an XML file for customers, open it using (fsCustomers = new FileStream(fiCustomers.FullName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite) rem We want to create an XML element to be added to the XML file. rem To start, create an XML element named "customer". XmlElement xeCustomer = xdCustomers.CreateElement("customer") rem Create/Format the child nodes of the "customer" element xeCustomer.InnerXml = "<account-number>" + create.MtbAccountNumber.Text + "</account-number>" + "<account-name>" + create.TxtAccountName.Text + "</account-name>" + "<meter-number>" + create.MtbMeterNumber.Text + "</meter-number>" + "<account-type>" + create.cbxAccountsTypes.Text + "</account-type>" + "<address>" + create.TxtAddress.Text + "</address>" + "<city>" + create.TxtCity.Text + "</city>" + "<county>" + create.TxtCounty.Text + "</county>" + "<state>" + create.TxtState.Text + "</state>" + "<zip-code>" + create.MtbZIPCode.Text + "</zip-code>" xdCustomers.DocumentElement!.AppendChild(xeCustomer) xdCustomers.Save(fsCustomers) end using end if ShowCustomers() end sub private sub ViewCustomerAccount_Click(sender As Object, e As EventArgs) { Details det = new Details() det.ShowDialog() } private sub BtnEditWaterMeter_Click(sender As Object, e As EventArgs) { rem This is the form that will be used to update a customer record Editor editor = new() rem Create an XML DOM object XmlDocument xdCustomers = new XmlDocument() rem Prepare the path and name of the file that holds a list of customers string? strCustomers = "C:\Stellar Water Point10\Customers.xml" rem Display the Editor form. rem Find out if the user clicked the Update Customer Account button when closing the Editor dialog box. if editor.ShowDialog() =MsgBoxResult.OK rem Get the customers records and store them in the above XML DOM object xdCustomers.Load(strCustomers) rem Create an XmlNodeList list that reprensents the XML elements from the list of customers. rem Call the XML DOM's GetElementsByTagName() method. rem To use the account number elements as references, pass the name of the Account # element as argument. XmlNodeList xnlCustomers = xdCustomers.DocumentElement!.GetElementsByTagName("account-number") rem Visit each XML element of the list of customers for each xnCustomer as XmlNode in xnlCustomers rem When you get to an element, find out if the value of it Account Number is rem the same as the account number the user typed in the form. If that's the case, rem change the value of each node of that element, using the values from the form. if xnCustomer.InnerText.Contains(editor.MtbAccountNumber.Text)) xnCustomer.ParentNode!.InnerXml = "<account-number>" + editor.MtbAccountNumber.Text + "</account-number>" + "<account-name>" + editor.TxtAccountName.Text + "</account-name>" + "<meter-number>" + editor.MtbMeterNumber.Text + "</meter-number>" + "<account-type>" + editor.cbxAccountsTypes.Text + "</account-type>" + "<address>" + editor.TxtAddress.Text + "</address>" + "<city>" + editor.TxtCity.Text + "</city>" + "<county>" + editor.TxtCounty.Text + "</county>" + "<state>" + editor.TxtState.Text + "</state>" + "<zip-code>" + editor.MtbZIPCode.Text + "</zip-code>" rem After updating the elements, save the updated file xdCustomers.Save(strCustomers) rem After saving the file, stop searching Exit For end if next end if rem Now that the user has closed the Editor dialog box (and probably updated the XML file), rem redisplay the list of customers.*/ ShowCustomers() } private sub BtnDeleteCustomerAcount_Click(sender As Object, e As EventArgs) { rem Here is the dialog box that the user will use to locate and delete a customer account Delete delete = new() rem Create an XML DOM object XmlDocument xdCustomers = new XmlDocument() rem Specify the file that holds a database of customers string? strCustomers = "C:\Stellar Water Point10\Customers.xml" rem Open the Delete dialog box. rem Find out if the user clicked the Delete Customer Account button to close the Delete dialog box. if delete.ShowDialog() =MsgBoxResult.OK) { rem If there is no file for the list of customers, don't do nothing if !File.Exists(strCustomers)) { MsgBox("There is no file for the customers accounts in the system.", "Stellar Water Point", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information) Exit Sub } rem If the user didn't provide a valid account number, don't do nothing if string.IsNullOrEmpty(delete.MtbAccountNumber.Text)) { MsgBox("You must type an account number for the customer whose account you want to delete one.", "Stellar Water Point", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information) Exit Sub } rem Open the file of customers records and put those records in our XML DOM object xdCustomers.Load(strCustomers) rem Create an XmlNodeList list of the customers records. rem Use the Account Number node as reference. XmlNodeList xnlCustomers = xdCustomers.DocumentElement!.GetElementsByTagName("account-number") rem Check each customer record as an XML element for each xnCustomer as XmlNode in xnlCustomers { rem When you reach an element, find out whether its value is rem the same as the account number the user typed on the form. if xnCustomer.InnerText=delete.MtbAccountNumber.Text) { rem If you find a matching record, find whether the user really wants to delete the record. if MsgBox("Are you sure you want to remove this customer's account from the system?", "Stellar Water Point", MessageBoxButtons.YesNo, MessageBoxIcon.Question) =MsgBoxResult.Yes) { rem If the user really wants to delete the record, delete it... xdCustomers.DocumentElement.RemoveChild(xnCustomer.ParentNode!) rem and stop searching Exit For } } } rem After removing the record, save the new version of the file xdCustomers.Save(strCustomers) } rem Now that the user has closed the Delete dialog box (and probably deleted the XML file), rem redisplay the list of customers.*/ ShowCustomers() } private sub BtnClose_Click(sender As Object, e As EventArgs) { Close() } } }
Water Bills
Introduction
A water bill is a summary that indicates how much water a customer consumed and the value of that consumption. Our application will include the forms necessary to process water bills operations.
Practical Learning: Preparing Bills
A List of Water Bills
A water bill must contain as much information as possible. In our application, when displaying a list of water bills, we will show only select pieces of information.
Practical Learning: Viewing Water Bills
Control | (Name) | Text | Other Properties | |
ListView | ![]() |
LvwWaterBills | FullRowSelect: True GridLines: True View: Details Anchor: Top, Bottom, Left, Right |
|
Button | ![]() |
BtnCreateWaterBill | Close | &Create Water Bill... |
(Name) | Text | TextAlign | Width |
colWaterBillId | Id | 40 | |
colBillNumber | Bill # | Center | 80 |
colAccountNumber | Account # | Center | 150 |
colStartDate | Start Date | Center | 150 |
colEndDate | End Date | Center | 150 |
colBillingDays | Days | Center | |
colCounterStart | Counter Start | Right | 125 |
colCounterEnd | Counter End | Right | 125 |
colTotalHCF | Total HCF | Right | 100 |
colGallons | Gallons | Right | 80 |
colPaymentDueDate | Pmt Due Date | Center | 125 |
colAmountDue | Amt Due | Right | 90 |
import System.Xml namespace StellarWaterPoint1.WaterBills { public partial class Central : Form { public Central() { InitializeComponent() } private sub ShowWaterBills() { lvwWaterBills.Items.Clear() XmlDocument xdWaterBills = new XmlDocument() string? strWaterBills = "C:\Stellar Water Point10\WaterBills.xml" FileInfo? fiWaterBills = new FileInfo(strWaterBills) if fiWaterBills.Exists) { using (FileStream? fsWaterBills = new FileStream(fiWaterBills.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { xdWaterBills.Load(fsWaterBills) XmlNodeList xnlWaterBills = xdWaterBills.DocumentElement!.ChildNodes; int i = 1; foreach (XmlNode xnWaterBill in xnlWaterBills) { ListViewItem lviWaterBill = new ListViewItem(i.ToString()) lviWaterBill.SubItems.Add(xnWaterBill.FirstChild!.InnerText) lviWaterBill.SubItems.Add(xnWaterBill.FirstChild.NextSibling!.InnerText) lviWaterBill.SubItems.Add(xnWaterBill.FirstChild.NextSibling.NextSibling!.InnerText) lviWaterBill.SubItems.Add(xnWaterBill.FirstChild.NextSibling.NextSibling.NextSibling!.InnerText) lviWaterBill.SubItems.Add(xnWaterBill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling!.InnerText) lviWaterBill.SubItems.Add(xnWaterBill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.InnerText) lviWaterBill.SubItems.Add(xnWaterBill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.InnerText) lviWaterBill.SubItems.Add(xnWaterBill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.InnerText) lviWaterBill.SubItems.Add(xnWaterBill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.InnerText.ToString()) lviWaterBill.SubItems.Add(xnWaterBill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.InnerText) lviWaterBill.SubItems.Add(xnWaterBill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.InnerText) lvwWaterBills.Items.Add(lviWaterBill) i++; } } } } private sub Central_Load(sender As Object, e As EventArgs) Handles MyBase.Load { ShowWaterBills() } } }
import System.Xml
namespace StellarWaterPoint1.WaterBills
{
public partial class Central : Form
{
public Central()
{
InitializeComponent()
}
private sub ShowWaterBills()
{
lvwWaterBills.Items.Clear()
XmlDocument xdWaterBills = new XmlDocument()
string? strWaterBills = "C:\Stellar Water Point10\WaterBills.xml"
FileInfo? fiWaterBills = new FileInfo(strWaterBills)
if fiWaterBills.Exists)
{
using (FileStream? fsWaterBills = new FileStream(fiWaterBills.FullName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
xdWaterBills.Load(fsWaterBills)
XmlNodeList xnlWaterBills = xdWaterBills.DocumentElement!.ChildNodes;
int i = 1;
foreach (XmlNode xnWaterBill in xnlWaterBills)
{
ListViewItem lviWaterBill = new ListViewItem(i.ToString())
lviWaterBill.SubItems.Add(xnWaterBill.FirstChild!.InnerText) rem Water Bill #
lviWaterBill.SubItems.Add(xnWaterBill.FirstChild.NextSibling!.InnerText) rem Account Number
lviWaterBill.SubItems.Add(xnWaterBill.FirstChild.NextSibling.NextSibling!.InnerText) rem Meter Reading Start Date
lviWaterBill.SubItems.Add(xnWaterBill.FirstChild.NextSibling.NextSibling.NextSibling!.InnerText) rem Meter Reading End Date
lviWaterBill.SubItems.Add(xnWaterBill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling!.InnerText) rem Billing Days
lviWaterBill.SubItems.Add(xnWaterBill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.InnerText) rem Counter Reading Start
lviWaterBill.SubItems.Add(xnWaterBill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.InnerText) rem Counter Reading End
lviWaterBill.SubItems.Add(xnWaterBill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.InnerText) rem Total CCF
lviWaterBill.SubItems.Add(xnWaterBill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.InnerText.ToString()) rem Gallons
lviWaterBill.SubItems.Add(xnWaterBill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.InnerText) rem Payment Due Date
lviWaterBill.SubItems.Add(xnWaterBill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.InnerText) rem Amount Due
lvwWaterBills.Items.Add(lviWaterBill)
i++;
}
}
}
}
private sub Central_Load(sender As Object, e As EventArgs) Handles MyBase.Load
{
ShowWaterBills()
}
private sub BtnCreateWaterBill_Click(sender As Object, e As EventArgs)
{
Create create = new()
create.ShowDialog()
ShowWaterBills()
}
}
}
Control | (Name) | Text | Font | |
Button | ![]() |
BtnWaterBills | Water &Bills... | Times New Roman, 24pt, style=Bold |
Button | ![]() |
BtnClose | &Close | Times New Roman, 24pt, style=Bold |
namespace StellarWaterPoint1 { public partial class WaterDistribution : Form { public WaterDistribution() { InitializeComponent() } private sub WaterDistribution_Load(sender As Object, e As EventArgs) Handles MyBase.Load { rem If the directory for the database doesn't yet exist, create it Directory.CreateDirectory("C:\Stellar Water Point10") } private sub BtnWaterBills_Click(sender As Object, e As EventArgs) { WaterBills.Central central = new() central.Show() } private sub BtnCustomers_Click(sender As Object, e As EventArgs) { Customers.Central central = new Customers.Central() central.ShowDialog() } private sub BtnWaterMeters_Click(sender As Object, e As EventArgs) { WaterMeters.Central central = new WaterMeters.Central() central.ShowDialog() } private sub BtnClose_Click(sender As Object, e As EventArgs) { Close() } } }
A Water Bill
A water bill is a collection of information that includes the identification of the customer who consumed the water, the period during which water was consumed, how much water was consumed, how much that consumption is worth, etc. We will create a form hat a user can use to create and process a water bill.
Practical Learning: Processing a Water Bill
Control | (Name) | Text | Other Properties | |
Label | ![]() |
Water Bill #: | ||
TextBox | ![]() |
TxtBillNumber | ||
GroupBox | ![]() |
Customer Information | ||
Label | ![]() |
Account #: | ||
MaskedTextBox | ![]() |
MtbAccountNumber | Masked: 0000-000-0000 | |
Button | ![]() |
BtnFindCustomerAccount | Find Customer Account | |
Label | ![]() |
Customer Name: | ||
TextBox | ![]() |
TxtCustomerName | ||
Label | ![]() |
Address: | ||
TextBox | ![]() |
TxtAddress | ||
TextBox | ![]() |
TxtCity | ||
TextBox | ![]() |
TxtCounty | ||
TextBox | ![]() |
TxtState | ||
MaskedTextBox | ![]() |
MtbZIPCode | Masked: Zip-Code | |
Label | ![]() |
______________________________________________ | ||
Label | ![]() |
Meter Details: | ||
TextBox | ![]() |
TxtMeterDetails | Modifiers: Public | |
GroupBox | ![]() |
Meter Reading | ||
Label | ![]() |
Meter Reading Start Date: | ||
DateTimePicker | ![]() |
dtpMeterReadingStartDate | ||
Label | ![]() |
Meter Reading End Date: | ||
DateTimePicker | ![]() |
dtpMeterReadingEndDate | ||
Label | ![]() |
Counter Reading Start: | ||
TextBox | ![]() |
TxtCounterReadingStart | ||
Label | ![]() |
Counter Reading End: | ||
TextBox | ![]() |
TxtCounterReadingEnd | ||
Button | ![]() |
BtnEvaluateWaterBill | Evaluate Water Bill | |
GroupBox | ![]() |
Meter Result | ||
Label | ![]() |
Billing Days: | ||
TextBox | ![]() |
TxtBillingDays | TextAlign: Right | |
Label | ![]() |
Total Gallons: | ||
TextBox | ![]() |
TxtTotalGallons | TextAlign: Right | |
Label | ![]() |
Total CCF: | ||
TextBox | ![]() |
TxtTotalCCF | TextAlign: Right | |
Label | ![]() |
First Tier Consumption: | ||
TextBox | ![]() |
TxtFirstTierConsumption | TextAlign: Right | |
Label | ![]() |
Second Tier: | ||
TextBox | ![]() |
TxtSecondTierConsumption | TextAlign: Right | |
Label | ![]() |
Last Tier: | ||
TextBox | ![]() |
TxtLastTierConsumption | TextAlign: Right | |
GroupBox | ![]() |
Consumption Charges | ||
Label | ![]() |
Water Charges: | ||
TextBox | ![]() |
TxtWaterCharges | TextAlign: Right | |
Label | ![]() |
Sewer Charges: | ||
TextBox | ![]() |
TxtSewerCharges | TextAlign: Right | |
Label | ![]() |
Environment Charges: | ||
TextBox | ![]() |
TxtEnvironmentCharges | TextAlign: Right | |
Label | ![]() |
Total Charges: | ||
TextBox | ![]() |
TxtTotalCharges | TextAlign: Right | |
GroupBox | ![]() |
Taxes | ||
Label | ![]() |
Local Taxes: | ||
TextBox | ![]() |
TxtLocalTaxes | TextAlign: Right | |
Label | ![]() |
State Taxes: | ||
TextBox | ![]() |
TxtStateTaxes | TextAlign: Right | |
GroupBox | ![]() |
Water Bill Payment | ||
Label | ![]() |
Payment Due Date: | ||
DateTimePicker | ![]() |
dtpPaymentDueDate | ||
Label | ![]() |
Amount Due: | ||
TextBox | ![]() |
TxtAmountDue | TextAlign: Right | |
Label | ![]() |
Late Payment Due Date: | ||
DateTimePicker | ![]() |
dtpLatePaymentDueDate | ||
Label | ![]() |
Late Amount Due: | ||
TextBox | ![]() |
TxtLateAmountDue | TextAlign: Right | |
Button | ![]() |
BtnSaveWaterBill | Save Water Bill | |
Button | ![]() |
BtnClose | Close |
import System.Xml namespace StellarWaterPoint1.WaterBills { public partial class Create : Form { public Create() { InitializeComponent() } private sub BtnFindCustomerAccount_Click(sender As Object, e As EventArgs) { XmlDocument xdCustomers = new XmlDocument() string? strCustomers = "C:\Stellar Water Point10\Customers.xml" FileInfo? fiCustomers = new FileInfo(strCustomers) string strMeterNumber = string.Empty; if fiCustomers.Exists) { using fsCustomers as FileStream= new FileStream(fiCustomers.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { xdCustomers.Load(fsCustomers) XmlNodeList xnlCustomers = xdCustomers.DocumentElement!.SelectNodes("//account-number[.='" + MtbAccountNumber.Text + "']")!; for each xnCustomer as XmlNode in xnlCustomers { TxtAccountName.Text = xnCustomer.NextSibling.InnerText strMeterNumber = xnCustomer.NextSibling.NextSibling.InnerText TxtAccountType.Text = xnCustomer.NextSibling.NextSibling.NextSibling.InnerText TxtAddress.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.InnerText TxtCity.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText TxtCounty.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling.InnerText TxtState.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtZIPCode.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText } } } dim xdWaterMeters as XmlDocument = new XmlDocument() dim strWaterMeters as string= "C:\Stellar Water Point10\WaterMeters.xml" dim fiWaterMeters as FileInfo= new FileInfo(strWaterMeters) if fiWaterMeters.Exists) { using fsWaterMeters as FileStream= new FileStream(fiWaterMeters.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { xdWaterMeters.Load(fsWaterMeters) dim xnlWaterMeters as XmlNodeList = xdWaterMeters.DocumentElement!.SelectNodes("//meter-number[.='" + strMeterNumber + "']")!; for each xnWaterMeter as XmlNode in xnlWaterMeters) { TxtMeterDetails.Text = xnWaterMeter.NextSibling!.InnerText + " " + xnWaterMeter.NextSibling.NextSibling!.InnerText + " (Meter Size: " + xnWaterMeter.NextSibling.NextSibling.NextSibling!.InnerText + ")" } } } } } }
import System.Xml
namespace StellarWaterPoint1.WaterBills
{
public partial class Create : Form
{
public Create()
{
InitializeComponent()
}
private sub BtnFindCustomerAccount_Click(sender As Object, e As EventArgs)
{
. . .
}
private sub dtpMeterReadingEndDate_ValueChanged(sender As Object, e As EventArgs)
{
TimeSpan tsDays = dtpMeterReadingEndDate.Value - dtpMeterReadingStartDate.Value;
TxtBillingDays.Text = (tsDays.Days + 1).ToString()
}
}
}
import System.Xml namespace StellarWaterPoint1.WaterBills { public partial class Create : Form { public Create() { InitializeComponent() } private sub BtnFindCustomerAccount_Click(sender As Object, e As EventArgs) { . . . } private sub dtpMeterReadingEndDate_ValueChanged(sender As Object, e As EventArgs) { . . . } (double a, double b, double c) CalculateTiers(string acnt, double total) { (double tier1, double tier2, double tier3) results = (0.00, 0.00, 0.00) switch (acnt) { case "RES": results.tier1 = total * 41.50 / 10000.00; results.tier2 = total * 32.50 / 10000.00; results.tier3 = total * 26.00 / 10000.00; Exit For case "SGO": results.tier1 = total * 46 / 10000; results.tier2 = total * 50 / 10000; results.tier3 = total * 4 / 10000; Exit For case "BUS": results.tier1 = total * 45 / 10000; results.tier2 = total * 30 / 10000; results.tier3 = total * 25 / 10000; Exit For case "UUO": results.tier1 = total * 25 / 10000; results.tier2 = total * 35 / 10000; results.tier3 = total * 40 / 10000; Exit For case "WAT": results.tier1 = total * 50 / 10000; results.tier2 = total * 40 / 10000; results.tier3 = total * 10 / 10000; Exit For default: results.tier1 = total * (48.00 / 10000.00) results.tier2 = total * (32.00 / 10000.00) results.tier3 = total * (20.00 / 10000.00) Exit For } return results; } private double CalculateSewerCharges(string acnt, double total) { double result; if acnt="RES") { result = total * 6.826941 / 100; } else if acnt="SGO") { result = total * 4.162522 / 100; } else if acnt="BUS") { result = total * 8.3136 / 100; } else if acnt="UUO") { result = total * 10.6247 / 100; } else if acnt="WAT") { result = total * 12.0535 / 100; } else rem if acnt="OTH)" { result = total * 9.2065 / 100; } return result; } private double CalculateEnvironmentCharges(string acnt, double total) { double result; switch(acnt) { case "RES": result = total * 0.022724; Exit For case "SGO": result = total * 0.118242; Exit For case "BUS": result = total * 0.161369; Exit For case "UUO": result = total * 0.082477; Exit For case "WAT": result = total * 0.413574; Exit For default: result = total * 0.221842; Exit For } return result; } private double CalculateServiceCharges(string acnt, double total) { switch (acnt) { case "RES": return total * 0.145748; case "SGO": return total * 0.102246; case "BUS": return total * 0.242627; case "UUO": return total * 0.186692; case "WAT": return total * 0.412628; default: return total * 0.210248; } } private double CalculateLocalTaxes(string acnt, double total) => acnt switch { "RES" => total * 0.031574, "SGO" => total * 0.035026, "BUS" => total * 0.122517, "UUO" => total * 0.105737, "WAT" => total * 0.153248, _ => total * 0.125148 }; private double CalculateStateTaxes(string acnt, double total) => acnt switch { "RES" => total * 0.016724, "SGO" => total * 0.008779, "BUS" => total * 0.042448, "UUO" => total * 0.067958, "WAT" => total * 0.081622, _ => total * 0.013746 }; private DateTime SetPaymentDueDate(string acnt, DateTime date) TimeSpan tsPaymentDueDate = new TimeSpan(1, 0, 0, 0) if acnt="RES" tsPaymentDueDate = new TimeSpan(15, 0, 0, 0) } else if acnt="SGO") tsPaymentDueDate = new TimeSpan(20, 0, 0, 0) } else if acnt="BUS") tsPaymentDueDate = new TimeSpan(30, 0, 0, 0) } else if acnt="UUO") tsPaymentDueDate = new TimeSpan(15, 0, 0, 0) } else if acnt="WAT") tsPaymentDueDate = new TimeSpan(40, 0, 0, 0) } else tsPaymentDueDate = new TimeSpan(35, 0, 0, 0) } return date + tsPaymentDueDate; } private DateTime SetLatePaymentDueDate(string acnt, DateTime date) switch (acnt) case "RES": return date + new TimeSpan(30, 0, 0, 0) case "SGO": return date + new TimeSpan(40, 0, 0, 0) case "BUS": return date + new TimeSpan(50, 0, 0, 0) case "UUO": return date + new TimeSpan(60, 0, 0, 0) case "WAT": return date + new TimeSpan(65, 0, 0, 0) default: return date + new TimeSpan(45, 0, 0, 0) } } private double CalculateLateAmountDue(string acnt, double amt) => acnt switch "RES" => amt + 8.95, "SGO" => amt + (amt / 4.575), "BUS" => amt + (amt / 12.315), "UUO" => amt + (amt / 7.425), "WAT" => amt + (amt / 15.225), _ => amt + (amt / 6.735) }; private sub BtnEvaluateWaterBill_Click(sender As Object, e As EventArgs) double counterStart = 0, counterEnd = 0; try counterStart = double.Parse(TxtCounterReadingStart.Text) } catch (FormatException feCRStart) MsgBox("There was a problem with the value of the " + "Counter Reading Start. The error produced is: " + feCRStart.Message, "Stellar Water Point", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information) } try counterEnd = double.Parse(TxtCounterReadingEnd.Text) } catch (FormatException feCREnd) MsgBox("There was a problem with the value of the " + "Counter Reading End. The error produced is: " + feCREnd.Message, "Stellar Water Point", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information) } double consumption = counterEnd - counterStart; double gallons = consumption * 748.05; string strAccountType = TxtAccountType.Text[..3]; (double first, double second, double last) tiers = CalculateTiers(strAccountType, gallons) double waterCharges = tiers.first + tiers.second + tiers.last; double sewerCharges = CalculateSewerCharges(strAccountType, waterCharges) double envCharges = CalculateEnvironmentCharges(strAccountType, waterCharges) double srvCharges = CalculateServiceCharges(strAccountType, waterCharges) double totalCharges = waterCharges + sewerCharges + envCharges + srvCharges; double localTaxes = CalculateLocalTaxes(strAccountType, waterCharges) double stateTaxes = CalculateStateTaxes(strAccountType, waterCharges) double amtDue = totalCharges + localTaxes + stateTaxes; TxtTotalHCF.Text = consumption.ToString() TxtTotalGallons.Text = ((int)(Math.Ceiling(gallons))).ToString() TxtFirstTierConsumption.Text = tiers.first.ToString("F") TxtSecondTierConsumption.Text = tiers.second.ToString("F") TxtLastTierConsumption.Text = tiers.last.ToString("F") TxtWaterCharges.Text = waterCharges.ToString("F") TxtSewerCharges.Text = sewerCharges.ToString("F") TxtEnvironmentCharges.Text = envCharges.ToString("F") TxtServiceCharges.Text = srvCharges.ToString("F") TxtTotalCharges.Text = totalCharges.ToString("F") TxtLocalTaxes.Text = localTaxes.ToString("F") TxtStateTaxes.Text = stateTaxes.ToString("F") dtpPaymentDueDate.Value = SetPaymentDueDate(strAccountType, dtpMeterReadingEndDate.Value) TxtAmountDue.Text = amtDue.ToString("F") dtpLatePaymentDueDate.Value = SetLatePaymentDueDate(strAccountType, dtpMeterReadingEndDate.Value) TxtLateAmountDue.Text = CalculateLateAmountDue(strAccountType, amtDue).ToString("F") } } }
import System.Xml namespace StellarWaterPoint1.WaterBills public partial class Create : Form public Create() InitializeComponent() } private sub BtnFindCustomerAccount_Click(sender As Object, e As EventArgs) XmlDocument xdCustomers = new XmlDocument() string? strCustomers = "C:\Stellar Water Point10\Customers.xml" FileInfo? fiCustomers = new FileInfo(strCustomers) string strMeterNumber = string.Empty; if fiCustomers.Exists) using fsCustomers as FileStream= new FileStream(fiCustomers.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) xdCustomers.Load(fsCustomers) XmlNodeList xnlCustomers = xdCustomers.DocumentElement!.SelectNodes("//account-number[.='" + MtbAccountNumber.Text + "']")!; for each xnCustomer as XmlNode in xnlCustomers TxtAccountName.Text = xnCustomer.NextSibling.InnerText strMeterNumber = xnCustomer.NextSibling.NextSibling.InnerText TxtAccountType.Text = xnCustomer.NextSibling.NextSibling.NextSibling.InnerText TxtAddress.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.InnerText TxtCity.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText TxtCounty.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling.InnerText TxtState.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtZIPCode.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText } } } dim xdWaterMeters as XmlDocument = new XmlDocument() dim strWaterMeters as string= "C:\Stellar Water Point10\WaterMeters.xml" dim fiWaterMeters as FileInfo= new FileInfo(strWaterMeters) if fiWaterMeters.Exists) using fsWaterMeters as FileStream= new FileStream(fiWaterMeters.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) xdWaterMeters.Load(fsWaterMeters) dim xnlWaterMeters as XmlNodeList = xdWaterMeters.DocumentElement!.SelectNodes("//meter-number[.='" + strMeterNumber + "']")!; for each xnWaterMeter as XmlNode in xnlWaterMeters) TxtMeterDetails.Text = xnWaterMeter.NextSibling!.InnerText + " " + xnWaterMeter.NextSibling.NextSibling!.InnerText + " (Meter Size: " + xnWaterMeter.NextSibling.NextSibling.NextSibling!.InnerText + ")" } } } } private sub dtpMeterReadingEndDate_ValueChanged(sender As Object, e As EventArgs) TimeSpan tsDays = dtpMeterReadingEndDate.Value - dtpMeterReadingStartDate.Value; TxtBillingDays.Text = (tsDays.Days + 1).ToString() } (double a, double b, double c) CalculateTiers(string acnt, double total) (double tier1, double tier2, double tier3) results = (0.00, 0.00, 0.00) if acnt="RES") results.tier1 = total * 41.50 / 10000.00; results.tier2 = total * 32.50 / 10000.00; results.tier3 = total * 26.00 / 10000.00; } else if acnt="SGO") results.tier1 = total * 46 / 10000; results.tier2 = total * 50 / 10000; results.tier3 = total * 4 / 10000; } else if acnt="BUS") results.tier1 = total * 45 / 10000; results.tier2 = total * 30 / 10000; results.tier3 = total * 25 / 10000; } else if acnt="UUO") results.tier1 = total * 25 / 10000; results.tier2 = total * 35 / 10000; results.tier3 = total * 40 / 10000; } else if acnt="WAT") results.tier1 = total * 50 / 10000; results.tier2 = total * 40 / 10000; results.tier3 = total * 10 / 10000; } else results.tier1 = total * (48.00 / 10000.00) results.tier2 = total * (32.00 / 10000.00) results.tier3 = total * (20.00 / 10000.00) } return results; } private double CalculateSewerCharges(string acnt, double total) double result; if acnt="RES") result = total * 6.826941 / 100; } else if acnt="SGO") result = total * 4.162522 / 100; } else if acnt="BUS") result = total * 8.3136 / 100; } else if acnt="UUO") result = total * 10.6247 / 100; } else if acnt="WAT") result = total * 12.0535 / 100; } else rem if acnt="OTH)" result = total * 9.2065 / 100; } return result; } private double CalculateEnvironmentCharges(string acnt, double total) double result; switch(acnt) case "RES": result = total * 0.022724; Exit For case "SGO": result = total * 0.118242; Exit For case "BUS": result = total * 0.161369; Exit For case "UUO": result = total * 0.082477; Exit For case "WAT": result = total * 0.413574; Exit For default: result = total * 0.221842; Exit For } return result; } private double CalculateServiceCharges(string acnt, double total) switch (acnt) case "RES": return total * 0.145748; case "SGO": return total * 0.102246; case "BUS": return total * 0.242627; case "UUO": return total * 0.186692; case "WAT": return total * 0.412628; default: return total * 0.210248; } } private double CalculateLocalTaxes(string acnt, double total) => acnt switch "RES" => total * 0.031574, "SGO" => total * 0.035026, "BUS" => total * 0.122517, "UUO" => total * 0.105737, "WAT" => total * 0.153248, _ => total * 0.125148 }; private double CalculateStateTaxes(string acnt, double total) => acnt switch "RES" => total * 0.016724, "SGO" => total * 0.008779, "BUS" => total * 0.042448, "UUO" => total * 0.067958, "WAT" => total * 0.081622, _ => total * 0.013746 }; private DateTime SetPaymentDueDate(string acnt, DateTime date) TimeSpan tsPaymentDueDate = new TimeSpan(1, 0, 0, 0) if acnt="RES") tsPaymentDueDate = new TimeSpan(15, 0, 0, 0) } else if acnt="SGO") tsPaymentDueDate = new TimeSpan(20, 0, 0, 0) } else if acnt="BUS") { tsPaymentDueDate = new TimeSpan(30, 0, 0, 0) } else if acnt="UUO") { tsPaymentDueDate = new TimeSpan(15, 0, 0, 0) } else if acnt="WAT") { tsPaymentDueDate = new TimeSpan(40, 0, 0, 0) } else { tsPaymentDueDate = new TimeSpan(35, 0, 0, 0) } return date + tsPaymentDueDate; } private DateTime SetLatePaymentDueDate(string acnt, DateTime date) { switch (acnt) { case "RES": return date + new TimeSpan(30, 0, 0, 0) case "SGO": return date + new TimeSpan(40, 0, 0, 0) case "BUS": return date + new TimeSpan(50, 0, 0, 0) case "UUO": return date + new TimeSpan(60, 0, 0, 0) case "WAT": return date + new TimeSpan(65, 0, 0, 0) default: return date + new TimeSpan(45, 0, 0, 0) } } private double CalculateLateAmountDue(string acnt, double amt) => acnt switch { "RES" => amt + 8.95, "SGO" => amt + (amt / 4.575), "BUS" => amt + (amt / 12.315), "UUO" => amt + (amt / 7.425), "WAT" => amt + (amt / 15.225), _ => amt + (amt / 6.735) }; private sub BtnEvaluateWaterBill_Click(sender As Object, e As EventArgs) { double counterStart = 0, counterEnd = 0; try { counterStart = double.Parse(TxtCounterReadingStart.Text) } catch (FormatException feCRStart) { MsgBox("There was a problem with the value of the " + "Counter Reading Start. The error produced is: " + feCRStart.Message, "Stellar Water Point", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information) } try { counterEnd = double.Parse(TxtCounterReadingEnd.Text) } catch (FormatException feCREnd) { MsgBox("There was a problem with the value of the " + "Counter Reading End. The error produced is: " + feCREnd.Message, "Stellar Water Point", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information) } double consumption = counterEnd - counterStart; double gallons = consumption * 748.05; string strAccountType = TxtAccountType.Text[..3]; (double first, double second, double last) tiers = CalculateTiers(strAccountType, gallons) double waterCharges = tiers.first + tiers.second + tiers.last; double sewerCharges = CalculateSewerCharges(strAccountType, waterCharges) double envCharges = CalculateEnvironmentCharges(strAccountType, waterCharges) double srvCharges = CalculateServiceCharges(strAccountType, waterCharges) double totalCharges = waterCharges + sewerCharges + envCharges + srvCharges; double localTaxes = CalculateLocalTaxes(strAccountType, waterCharges) double stateTaxes = CalculateStateTaxes(strAccountType, waterCharges) double amtDue = totalCharges + localTaxes + stateTaxes; TxtTotalHCF.Text = consumption.ToString() TxtTotalGallons.Text = ((int)(Math.Ceiling(gallons))).ToString() TxtFirstTierConsumption.Text = tiers.first.ToString("F") TxtSecondTierConsumption.Text = tiers.second.ToString("F") TxtLastTierConsumption.Text = tiers.last.ToString("F") TxtWaterCharges.Text = waterCharges.ToString("F") TxtSewerCharges.Text = sewerCharges.ToString("F") TxtEnvironmentCharges.Text = envCharges.ToString("F") TxtServiceCharges.Text = srvCharges.ToString("F") TxtTotalCharges.Text = totalCharges.ToString("F") TxtLocalTaxes.Text = localTaxes.ToString("F") TxtStateTaxes.Text = stateTaxes.ToString("F") dtpPaymentDueDate.Value = SetPaymentDueDate(strAccountType, dtpMeterReadingEndDate.Value) TxtAmountDue.Text = amtDue.ToString("F") dtpLatePaymentDueDate.Value = SetLatePaymentDueDate(strAccountType, dtpMeterReadingEndDate.Value) TxtLateAmountDue.Text = CalculateLateAmountDue(strAccountType, amtDue).ToString("F") } private sub BtnSaveWaterBill_Click(sender As Object, e As EventArgs) { if string.IsNullOrEmpty(TxtBillNumber.Text)) { MsgBox("You must type a bill number." + "Otherwise, the account cannot be saved.", "Stellar Water Point", MessageBoxButtons.OK) Exit Sub } if string.IsNullOrEmpty(TxtCounterReadingStart.Text)) { MsgBox("You must enter the start value of the water bill counter." + "Otherwise, the account cannot be saved.", "Stellar Water Point", MessageBoxButtons.OK) Exit Sub } if string.IsNullOrEmpty(MtbAccountNumber.Text)) { MsgBox("You must type an account number of a customer." + "Otherwise, the account cannot be saved.", "Stellar Water Point", MessageBoxButtons.OK) Exit Sub } FileStream? fsWaterBills = nothing XmlDocument xdWaterBills = new XmlDocument() string strWaterBills = "C:\Stellar Water Point10\WaterBills.xml" FileInfo? fiWaterBills = new FileInfo(strWaterBills) if fiWaterBills.Exists) { using (fsWaterBills = new FileStream(fiWaterBills.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { xdWaterBills.Load(fsWaterBills) } } else { using (fsWaterBills = new FileStream(fiWaterBills.FullName, FileMode.Create, FileAccess.Write, FileShare.Write)) { xdWaterBills.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<water-bills></water-bills>") xdWaterBills.Save(fsWaterBills) } } using (fsWaterBills = new FileStream(fiWaterBills.FullName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)) { XmlElement xeWaterBill = xdWaterBills.CreateElement("water-bill") xeWaterBill.InnerXml = "<bill-number>" + TxtBillNumber.Text + "</bill-number>" + "<account-number>" + MtbAccountNumber.Text + "</account-number>" + "<meter-reading-start-date>" + dtpMeterReadingStartDate.Value.ToShortDateString() + "</meter-reading-start-date>" + "<meter-reading-end-date>" + dtpMeterReadingEndDate.Value.ToShortDateString() + "</meter-reading-end-date>" + "<billing-days>" + TxtBillingDays.Text + "</billing-days>" + "<counter-reading-start>" + TxtCounterReadingStart.Text + "</counter-reading-start>" + "<counter-reading-end>" + TxtCounterReadingEnd.Text + "</counter-reading-end>" + "<total-hcf>" + TxtTotalHCF.Text + "</total-hcf>" + "<total-gallons>" + TxtTotalGallons.Text + "</total-gallons>" + "<first-tier-consumption>" + TxtFirstTierConsumption.Text + "</first-tier-consumption>" + "<second-tier-consumption>" + TxtSecondTierConsumption.Text + "</second-tier-consumption>" + "<last-tier-consumption>" + TxtLastTierConsumption.Text + "</last-tier-consumption>" + "<water-charges>" + TxtWaterCharges.Text + "</water-charges>" + "<sewer-charges>" + TxtSewerCharges.Text + "</sewer-charges>" + "<environment-charges>" + TxtEnvironmentCharges.Text + "</environment-charges>" + "<service-charges>" + TxtEnvironmentCharges.Text + "</service-charges>" + "<total-charges>" + TxtTotalCharges.Text + "</total-charges>" + "<state-taxes>" + TxtStateTaxes.Text + "</state-taxes>" + "<local-taxes>" + TxtLocalTaxes.Text + "</local-taxes>" + "<payment-due-date>" + dtpPaymentDueDate.Value.ToShortDateString() + "</payment-due-date>" + "<amount-due>" + TxtAmountDue.Text + "</amount-due>" + "<late-payment-due-date>" + dtpLatePaymentDueDate.Value.ToShortDateString() + "</late-payment-due-date>" + "<late-amount-due>" + TxtLateAmountDue.Text + "</late-amount-due>" xdWaterBills.DocumentElement!.AppendChild(xeWaterBill) xdWaterBills.Save(fsWaterBills) } Close() } private sub BtnClose_Click(sender As Object, e As EventArgs) { Close() } } }
Control | (Name) | Text | Other Properties | |
ListView | ![]() |
LvwWaterBills | No Change | |
Button | ![]() |
BtnCreateWaterBill | Close | &Create Water Bill... |
private sub BtnProcessWaterBill_Click(sender As Object, e As EventArgs) { Create create = new() create.ShowDialog() ShowWaterBills() }
Water Bill # | Account # | Reading Start Date | Reading End Date | Counter Reading Start | Counter Reading End |
451474 | 2068-258-9486 | 01/11/2010 | 04/12/2010 | 103943 | 103956 |
923633 | 5293-957-3395 | 01/17/2010 | 08/18/2010 | 256945 | 256972 |
917829 | 9279-570-8394 | 02/15/2010 | 05/14/2010 | 5205 | 5222 |
202666 | 6986-829-3741 | 03/08/2010 | 06/06/2010 | 5679 | 5690 |
Details on a Wate Bill
Probably the simplest operation that a user can perform on a water bill to only view its details. To make this happen, we will create and provide a form.
Practical Learning: Creating a Water Meter Record
Control | (Name) | Text | Other Properties | |
Label | ![]() |
Water Bill #: | ||
TextBox | ![]() |
TxtBillNumber | ||
Button | ![]() |
BtnFindWaterBill | Find Water Bill | |
GroupBox | ![]() |
Customer Information | ||
Label | ![]() |
Account #: | ||
TextBox | ![]() |
TxtAccountNumber | Enabled: False | |
Label | ![]() |
Customer Name: | ||
TextBox | ![]() |
TxtCustomerName | Enabled: False | |
Label | ![]() |
Address: | ||
TextBox | ![]() |
TxtAddress | Enabled: False | |
TextBox | ![]() |
TxtCity | Enabled: False | |
TextBox | ![]() |
TxtCounty | Enabled: False | |
TextBox | ![]() |
TxtState | Enabled: False | |
TextBox | ![]() |
TxtZIPCode | Enabled: False | |
Label | ![]() |
_____________________________________ | ||
Label | ![]() |
Meter Details: | ||
TextBox | ![]() |
TxtMeterDetails | Enabled: False | |
GroupBox | ![]() |
Meter Reading | ||
Label | ![]() |
Meter Reading Start Date: | ||
TextBox | ![]() |
TxtMeterReadingStartDate | Enabled: False | |
Label | ![]() |
Meter Reading End Date: | ||
TextBox | ![]() |
TxtMeterReadingEndDate | Enabled: False | |
Label | ![]() |
Counter Reading Start: | ||
TextBox | ![]() |
TxtCounterReadingStart | Enabled: False | |
Label | ![]() |
Counter Reading End: | ||
TextBox | ![]() |
TxtCounterReadingEnd | Enabled: False | |
GroupBox | ![]() |
Meter Result | ||
Label | ![]() |
Billing Days: | ||
TextBox | ![]() |
TxtBillingDays | TextAlign: Right Enabled: False |
|
Label | ![]() |
Total Gallons: | ||
TextBox | ![]() |
TxtTotalGallons | TextAlign: Right Enabled: False |
|
Label | ![]() |
Total CCF: | ||
TextBox | ![]() |
TxtTotalHCF | TextAlign: Right Enabled: False |
|
Label | ![]() |
First Tier Consumption: | ||
TextBox | ![]() |
TxtFirstTierConsumption | TextAlign: Right Enabled: False |
|
Label | ![]() |
Second Tier: | ||
TextBox | ![]() |
TxtSecondTierConsumption | TextAlign: Right Enabled: False |
|
Label | ![]() |
Last Tier: | ||
TextBox | ![]() |
TxtLastTierConsumption | TextAlign: Right Enabled: False |
|
GroupBox | ![]() |
Consumption Charges | ||
Label | ![]() |
Water Charges: | ||
TextBox | ![]() |
TxtWaterCharges | TextAlign: Right Enabled: False |
|
Label | ![]() |
Sewer Charges: | ||
TextBox | ![]() |
TxtSewerCharges | TextAlign: Right Enabled: False |
|
Label | ![]() |
Environment Charges: | ||
TextBox | ![]() |
TxtEnvironmentCharges | TextAlign: Right Enabled: False |
|
Label | ![]() |
Total Charges: | ||
TextBox | ![]() |
TxtTotalCharges | TextAlign: Right Enabled: False |
|
GroupBox | ![]() |
Taxes | ||
Label | ![]() |
Local Taxes: | ||
TextBox | ![]() |
TxtLocalTaxes | TextAlign: Right Enabled: False |
|
Label | ![]() |
State Taxes: | ||
TextBox | ![]() |
TxtStateTaxes | TextAlign: Right Enabled: False |
|
GroupBox | ![]() |
Water Bill Payment | ||
Label | ![]() |
Payment Due Date: | ||
TextBox | ![]() |
TxtPaymentDueDate | Enabled: False | |
Label | ![]() |
Amount Due: | ||
TextBox | ![]() |
TxtAmountDue | TextAlign: Right Enabled: False |
|
Label | ![]() |
Late Payment Due Date: | ||
TextBox | ![]() |
TxtLatePaymentDueDate | Enabled: False | |
Label | ![]() |
Late Amount Due: | ||
TextBox | ![]() |
TxtLateAmountDue | TextAlign: Right Enabled: False |
|
Button | ![]() |
BtnClose | Close |
FormBorderStyle: FixedDialog Text: Stellar Water Point - Water Bill Details StartPosition: CenterScreen MinimizeBox: False MaximizeBox: False
import System.Xml namespace StellarWaterPoint1.WaterBills { public partial class Details : Form { public Details() { InitializeComponent() } private sub BtnFindWaterBill_Click(sender As Object, e As EventArgs) { rem If the user clicks the Find Water Meter button, * make sure there is an invoice number in the top text box. if string.IsNullOrEmpty(TxtBillNumber.Text)) { MsgBox("You must provide a water bill number and then click the Find Water Bill button.", "Stellar Water Point", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information) rem If the user didn't type a bill number but clicked Find Water Bill, don't do anything Exit Sub } XmlDocument xdWaterBills = new XmlDocument() string? strWaterBills = "C:\Stellar Water Point10\WaterBills.xml" FileInfo? fiWaterBills = new FileInfo(strWaterBills) if fiWaterBills.Exists) { using (FileStream? fsWaterBills = new FileStream(fiWaterBills.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { xdWaterBills.Load(fsWaterBills) rem Use XPath to locate the water bill that has * the same invoice number as the one in the Water Bill Number text box. * Store the water bill in an XmlNodeList variable. XmlNodeList xnlWaterBills = xdWaterBills.DocumentElement!.SelectNodes("//bill-number[.='" + TxtBillNumber.Text + "']")!; foreach (XmlNode xnWaterBill in xnlWaterBills) { TxtBillNumber.Text = xnWaterBill.FirstChild.InnerText TxtAccountNumber.Text = xnWaterBill.NextSibling.InnerText TxtMeterReadingStartDate.Text = DateTime.Parse(xnWaterBill.NextSibling.NextSibling!.InnerText).ToLongDateString() TxtMeterReadingEndDate.Text = DateTime.Parse(xnWaterBill.NextSibling.NextSibling.NextSibling!.InnerText).ToLongDateString() TxtBillingDays.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.InnerText TxtCounterReadingStart.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling.InnerText TxtCounterReadingEnd.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling.InnerText TxtTotalHCF.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtTotalGallons.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtFirstTierConsumption.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtSecondTierConsumption.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtLastTierConsumption.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtWaterCharges.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtSewerCharges.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtEnvironmentCharges.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtServiceCharges.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtTotalCharges.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtStateTaxes.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtLocalTaxes.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtPaymentDueDate.Text = DateTime.Parse(xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.InnerText).ToLongDateString() TxtAmountDue.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtLatePaymentDueDate.Text = DateTime.Parse(xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.InnerText).ToLongDateString() TxtLateAmountDue.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText } } } XmlDocument xdCustomers = new XmlDocument() rem Declare a variable for a file that holds the list of customers string? strCustomers = "C:\Stellar Water Point10\Customers.xml" rem Create a FileInfo object for the customers FileInfo? fiCustomers = new FileInfo(strCustomers) rem We will need to know the water meter associated with this customer account string strMeterNumber = string.Empty; rem Check whether the file that holds a list of customers exists if fiCustomers.Exists) { rem If that exists, open it and pass it to a FileStream object using fsCustomers as FileStream= new FileStream(fiCustomers.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { rem Get the list of customers and pass the records to the XML DOM object created earlier xdCustomers.Load(fsCustomers) rem Create an XmlNodeList list of customers using XPath XmlNodeList xnlCustomers = xdCustomers.DocumentElement!.SelectNodes("//account-number[.='" + TxtAccountNumber.Text + "']")!; rem Check each node of the XML record and display its values in each Windows control on the form for each xnCustomer as XmlNode in xnlCustomers { //MtbAccountNumber.Text = xnCustomer.NextSibling.InnerText rem Meter # TxtAccountName.Text = xnCustomer.NextSibling.InnerText rem Account Name strMeterNumber = xnCustomer.NextSibling.NextSibling.InnerText rem Meter Number TxtAccountType.Text = xnCustomer.NextSibling.NextSibling.NextSibling.InnerText rem Account Type TxtAddress.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.InnerText rem Address TxtCity.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText rem City TxtCounty.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling.InnerText rem County TxtState.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText rem State TxtZIPCode.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText rem ZIP-Code } } } rem Create an XML DOM object for the water meters records dim xdWaterMeters as XmlDocument = new XmlDocument() rem Declare a variable for a file that holds the list of water meters dim strWaterMeters as string= "C:\Stellar Water Point10\WaterMeters.xml" rem Create a FileInfo object for the customers dim fiWaterMeters as FileInfo= new FileInfo(strWaterMeters) rem Check whether the file that holds a list of water meters exists if fiWaterMeters.Exists) { rem Get the list of water meters and pass the records to the XML DOM object using fsWaterMeters as FileStream= new FileStream(fiWaterMeters.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { rem Get the list of water meters and pass the records to the XML DOM object xdWaterMeters.Load(fsWaterMeters) rem Create an XmlNodeList list of water meters using XPath dim xnlWaterMeters as XmlNodeList = xdWaterMeters.DocumentElement!.SelectNodes("//meter-number[.='" + strMeterNumber + "']")!; rem Check each node of the XML record for each xnWaterMeter as XmlNode in xnlWaterMeters) { rem Get the values for the water meter. * Create a sentence and display it in the Meter Details text box. TxtMeterDetails.Text = xnWaterMeter.NextSibling!.InnerText + " " + xnWaterMeter.NextSibling.NextSibling!.InnerText + " (Meter Size: " + xnWaterMeter.NextSibling.NextSibling.NextSibling!.InnerText + ")" } } } } private sub BtnClose_Click(sender As Object, e As EventArgs) { Close() } } }
Control | (Name) | Other Properties | |
Button | ![]() |
BtnViewWaterBill | &View Water Bill... Anchor: Bottom, Right |
import System.Xml
namespace StellarWaterPoint1.WaterBills
{
public partial class Central : Form
{
public Central()
{
InitializeComponent()
}
private sub ShowWaterBills()
{
. . .
}
private sub Central_Load(sender As Object, e As EventArgs) Handles MyBase.Load
{
ShowWaterBills()
}
private sub BtnCreateWaterBill_Click(sender As Object, e As EventArgs)
{
Create create = new()
create.ShowDialog()
ShowWaterBills()
}
private sub BtnViewWaterBill_Click(sender As Object, e As EventArgs)
{
Details details = new()
details.ShowDialog()
}
}
}
Water Bill Edition
Although it doesn't happen regularly, some information can change about an existing water bill. If that happens, the user must be able to update the water bill. For this reason, we will create and provide a form that supports that operation.
Practical Learning: Editing a Water Bill
Control | (Name) | Text | Other Properties | |
Label | ![]() |
Water Bill #: | ||
TextBox | ![]() |
TxtBillNumber | Modifiers: Public | |
Button | ![]() |
BtnFindWaterBill | &Find Water Bill | |
GroupBox | ![]() |
Customer Information | ||
Label | ![]() |
Account #: | ||
MaskedTextBox | ![]() |
MtbAccountNumber | Masked: 0000-000-0000 Modifiers: Public |
|
Button | ![]() |
BtnFindCustomerAccount | Find Customer Account | |
Label | ![]() |
Account Name: | ||
TextBox | ![]() |
TxtAccountName | Enabled: False | |
Label | ![]() |
Address: | ||
TextBox | ![]() |
TxtAddress | Enabled: False | |
TextBox | ![]() |
TxtCity | Enabled: False | |
TextBox | ![]() |
TxtCounty | Enabled: False | |
TextBox | ![]() |
TxtState | Enabled: False | |
TextBox | ![]() |
MtbZIPCode | Enabled: False | |
Label | ![]() |
______________________________________________ | ||
Label | ![]() |
Meter Details: | ||
TextBox | ![]() |
TxtMeterDetails | Modifiers: Public | |
GroupBox | ![]() |
Meter Reading | ||
Label | ![]() |
Meter Reading Start Date: | ||
DateTimePicker | ![]() |
dtpMeterReadingStartDate | Modifiers: Public | |
Label | ![]() |
Meter Reading End Date: | ||
DateTimePicker | ![]() |
dtpMeterReadingEndDate | Modifiers: Public | |
Label | ![]() |
Counter Reading Start: | ||
TextBox | ![]() |
TxtCounterReadingStart | Modifiers: Public | |
Label | ![]() |
Counter Reading End: | ||
TextBox | ![]() |
TxtCounterReadingEnd | Modifiers: Public | |
Button | ![]() |
BtnEvaluateWaterBill | Evaluate Water Bill | |
GroupBox | ![]() |
Meter Result | ||
Label | ![]() |
Billing Days: | ||
TextBox | ![]() |
TxtBillingDays | TextAlign: Right Modifiers: Public |
|
Label | ![]() |
Total Gallons: | ||
TextBox | ![]() |
TxtTotalGallons | TextAlign: Right Modifiers: Public |
|
Label | ![]() |
Total CCF: | ||
TextBox | ![]() |
TxtTotalCCF | TextAlign: Right Modifiers: Public |
|
Label | ![]() |
First Tier Consumption: | ||
TextBox | ![]() |
TxtFirstTierConsumption | TextAlign: Right Modifiers: Public |
|
Label | ![]() |
Second Tier: | ||
TextBox | ![]() |
TxtSecondTierConsumption | TextAlign: Right Modifiers: Public |
|
Label | ![]() |
Last Tier: | ||
TextBox | ![]() |
TxtLastTierConsumption | TextAlign: Right Modifiers: Public |
|
GroupBox | ![]() |
Consumption Charges | ||
Label | ![]() |
Water Charges: | ||
TextBox | ![]() |
TxtWaterCharges | TextAlign: Right Modifiers: Public |
|
Label | ![]() |
Sewer Charges: | ||
TextBox | ![]() |
TxtSewerCharges | TextAlign: Right Modifiers: Public |
|
Label | ![]() |
Environment Charges: | ||
TextBox | ![]() |
TxtEnvironmentCharges | TextAlign: Right Modifiers: Public |
|
Label | ![]() |
Total Charges: | ||
TextBox | ![]() |
TxtTotalCharges | TextAlign: Right Modifiers: Public |
|
GroupBox | ![]() |
Taxes | ||
Label | ![]() |
Local Taxes: | ||
TextBox | ![]() |
TxtLocalTaxes | TextAlign: Right Modifiers: Public |
|
Label | ![]() |
State Taxes: | ||
TextBox | ![]() |
TxtStateTaxes | TextAlign: Right Modifiers: Public |
|
GroupBox | ![]() |
Water Bill Payment | ||
Label | ![]() |
Payment Due Date: | ||
DateTimePicker | ![]() |
dtpPaymentDueDate | Modifiers: Public | |
Label | ![]() |
Amount Due: | ||
TextBox | ![]() |
TxtAmountDue | TextAlign: Right Modifiers: Public |
|
Label | ![]() |
Late Payment Due Date: | ||
DateTimePicker | ![]() |
dtpLatePaymentDueDate | Modifiers: Public | |
Label | ![]() |
Late Amount Due: | ||
TextBox | ![]() |
TxtLateAmountDue | TextAlign: Right Modifiers: Public |
|
Button | ![]() |
BtnUpdateWaterBill | Update Water Bill | DialogResult: OK |
Button | ![]() |
BtnClose | Close | DialogResult: Cancel |
FormBorderStyle: FixedDialog Text: Stellar Water Point - Water Bill Edition StartPosition: CenterScreen MinimizeBox: False MaximizeBox: False AcceptButton: BtnUpdateWaterBill CancelButton: BtnClose
import System.Xmlimport System.Xml { public partial class Editor : Form { public Editor() { InitializeComponent() } private sub BtnFindWaterBill_Click(sender As Object, e As EventArgs) { if string.IsNullOrEmpty(TxtBillNumber.Text)) { MsgBox("You must provide a water bill number and then click the Find Water Bill button.", "Stellar Water Point", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information) Exit Sub } XmlDocument xdWaterBills = new XmlDocument() string? strWaterBills = "C:\Stellar Water Point10\WaterBills.xml" FileInfo? fiWaterBills = new FileInfo(strWaterBills) if fiWaterBills.Exists) { using (FileStream? fsWaterBills = new FileStream(fiWaterBills.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { xdWaterBills.Load(fsWaterBills) XmlNodeList xnlWaterBills = xdWaterBills.DocumentElement!.SelectNodes("//bill-number[.='" + TxtBillNumber.Text + "']")!; foreach (XmlNode xnWaterBill in xnlWaterBills) { TxtBillNumber.Text = xnWaterBill.FirstChild.InnerText MtbAccountNumber.Text = xnWaterBill.NextSibling.InnerText dtpMeterReadingStartDate.Text = DateTime.Parse(xnWaterBill.NextSibling.NextSibling!.InnerText).ToLongDateString() dtpMeterReadingEndDate.Text = DateTime.Parse(xnWaterBill.NextSibling.NextSibling.NextSibling!.InnerText).ToLongDateString() TxtBillingDays.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.InnerText TxtCounterReadingStart.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling.InnerText TxtCounterReadingEnd.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling.InnerText TxtTotalHCF.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtTotalGallons.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtFirstTierConsumption.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtSecondTierConsumption.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtLastTierConsumption.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtWaterCharges.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtSewerCharges.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtEnvironmentCharges.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtServiceCharges.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtTotalCharges.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtStateTaxes.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtLocalTaxes.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText dtpPaymentDueDate.Text = DateTime.Parse(xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.InnerText).ToLongDateString() TxtAmountDue.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText dtpLatePaymentDueDate.Text = DateTime.Parse(xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.InnerText).ToLongDateString() TxtLateAmountDue.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText } } } XmlDocument xdCustomers = new XmlDocument() string? strCustomers = "C:\Stellar Water Point10\Customers.xml" FileInfo? fiCustomers = new FileInfo(strCustomers) string strMeterNumber = string.Empty; if fiCustomers.Exists) { using fsCustomers as FileStream= new FileStream(fiCustomers.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { xdCustomers.Load(fsCustomers) XmlNodeList xnlCustomers = xdCustomers.DocumentElement!.SelectNodes("//account-number[.='" + MtbAccountNumber.Text + "']")!; for each xnCustomer as XmlNode in xnlCustomers { TxtAccountName.Text = xnCustomer.NextSibling.InnerText rem Account Name strMeterNumber = xnCustomer.NextSibling.NextSibling.InnerText rem Meter Number TxtAccountType.Text = xnCustomer.NextSibling.NextSibling.NextSibling.InnerText rem Account Type TxtAddress.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.InnerText rem Address TxtCity.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText rem City TxtCounty.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling.InnerText rem County TxtState.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText rem State TxtZIPCode.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText rem ZIP-Code } } } dim xdWaterMeters as XmlDocument = new XmlDocument() dim strWaterMeters as string= "C:\Stellar Water Point10\WaterMeters.xml" dim fiWaterMeters as FileInfo= new FileInfo(strWaterMeters) if fiWaterMeters.Exists) { using fsWaterMeters as FileStream= new FileStream(fiWaterMeters.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { xdWaterMeters.Load(fsWaterMeters) dim xnlWaterMeters as XmlNodeList = xdWaterMeters.DocumentElement!.SelectNodes("//meter-number[.='" + strMeterNumber + "']")!; rem Check each node of the XML record for each xnWaterMeter as XmlNode in xnlWaterMeters) { TxtMeterDetails.Text = xnWaterMeter.NextSibling!.InnerText + " " + xnWaterMeter.NextSibling.NextSibling!.InnerText + " (Meter Size: " + xnWaterMeter.NextSibling.NextSibling.NextSibling!.InnerText + ")" } } } } } }
import System.Xml
namespace StellarWaterPoint1.WaterBills
{
public partial class Editor : Form
{
public Editor()
{
InitializeComponent()
}
private sub BtnFindWaterBill_Click(sender As Object, e As EventArgs)
{
. . .
}
private sub BtnFindCustomerAccount_Click(sender As Object, e As EventArgs)
{
XmlDocument xdCustomers = new XmlDocument()
string? strCustomers = "C:\Stellar Water Point10\Customers.xml"
FileInfo? fiCustomers = new FileInfo(strCustomers)
string strMeterNumber = string.Empty;
if fiCustomers.Exists)
{
using fsCustomers as FileStream= new FileStream(fiCustomers.FullName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
xdCustomers.Load(fsCustomers)
XmlNodeList xnlCustomers = xdCustomers.DocumentElement!.SelectNodes("//account-number[.='" + MtbAccountNumber.Text + "']")!;
for each xnCustomer as XmlNode in xnlCustomers
{
TxtAccountName.Text = xnCustomer.NextSibling.InnerText
strMeterNumber = xnCustomer.NextSibling.NextSibling.InnerText
TxtAccountType.Text = xnCustomer.NextSibling.NextSibling.NextSibling.InnerText
TxtAddress.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.InnerText
TxtCity.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText
TxtCounty.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling.InnerText
TxtState.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText
TxtZIPCode.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText
}
}
}
dim xdWaterMeters as XmlDocument = new XmlDocument()
dim strWaterMeters as string= "C:\Stellar Water Point10\WaterMeters.xml"
dim fiWaterMeters as FileInfo= new FileInfo(strWaterMeters)
if fiWaterMeters.Exists)
{
using fsWaterMeters as FileStream= new FileStream(fiWaterMeters.FullName, FileMode.Open, FileAccess.Read, FileShare.Read))
{
xdWaterMeters.Load(fsWaterMeters)
dim xnlWaterMeters as XmlNodeList = xdWaterMeters.DocumentElement!.SelectNodes("//meter-number[.='" + strMeterNumber + "']")!;
for each xnWaterMeter as XmlNode in xnlWaterMeters)
{
TxtMeterDetails.Text = xnWaterMeter.NextSibling!.InnerText + " " +
xnWaterMeter.NextSibling.NextSibling!.InnerText + " (Meter Size: " +
xnWaterMeter.NextSibling.NextSibling.NextSibling!.InnerText + ")"
}
}
}
}
}
}
import System.Xml
namespace StellarWaterPoint1.WaterBills
{
public partial class Editor : Form
{
public Editor()
{
InitializeComponent()
}
private sub BtnFindWaterBill_Click(sender As Object, e As EventArgs)
{
. . .
}
private sub BtnFindCustomerAccount_Click(sender As Object, e As EventArgs)
{
. . .
}
private sub dtpMeterReadingEndDate_ValueChanged(sender As Object, e As EventArgs)
{
TimeSpan tsDays = dtpMeterReadingEndDate.Value - dtpMeterReadingStartDate.Value;
TxtBillingDays.Text = (tsDays.Days + 1).ToString()
}
}
}
import System.Xml namespace StellarWaterPoint1.WaterBills { public partial class Editor : Form { public Editor() { InitializeComponent() } private sub BtnFindWaterBill_Click(sender As Object, e As EventArgs) { if string.IsNullOrEmpty(TxtBillNumber.Text)) { MsgBox("You must provide a water bill number and then click the Find Water Bill button.", "Stellar Water Point", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information) Exit Sub } XmlDocument xdWaterBills = new XmlDocument() string? strWaterBills = "C:\Stellar Water Point10\WaterBills.xml" FileInfo? fiWaterBills = new FileInfo(strWaterBills) if fiWaterBills.Exists) { using (FileStream? fsWaterBills = new FileStream(fiWaterBills.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { xdWaterBills.Load(fsWaterBills) XmlNodeList xnlWaterBills = xdWaterBills.DocumentElement!.SelectNodes("//bill-number[.='" + TxtBillNumber.Text + "']")!; foreach (XmlNode xnWaterBill in xnlWaterBills) { TxtBillNumber.Text = xnWaterBill.FirstChild.InnerText MtbAccountNumber.Text = xnWaterBill.NextSibling.InnerText dtpMeterReadingStartDate.Text = DateTime.Parse(xnWaterBill.NextSibling.NextSibling!.InnerText).ToLongDateString() dtpMeterReadingEndDate.Text = DateTime.Parse(xnWaterBill.NextSibling.NextSibling.NextSibling!.InnerText).ToLongDateString() TxtBillingDays.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.InnerText TxtCounterReadingStart.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling.InnerText TxtCounterReadingEnd.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling.InnerText TxtTotalHCF.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtTotalGallons.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtFirstTierConsumption.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtSecondTierConsumption.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtLastTierConsumption.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtWaterCharges.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtSewerCharges.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtEnvironmentCharges.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtServiceCharges.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtTotalCharges.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtStateTaxes.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtLocalTaxes.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText dtpPaymentDueDate.Text = DateTime.Parse(xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.InnerText).ToLongDateString() TxtAmountDue.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText dtpLatePaymentDueDate.Text = DateTime.Parse(xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.InnerText).ToLongDateString() TxtLateAmountDue.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText } } } XmlDocument xdCustomers = new XmlDocument() string? strCustomers = "C:\Stellar Water Point10\Customers.xml" FileInfo? fiCustomers = new FileInfo(strCustomers) string strMeterNumber = string.Empty; if fiCustomers.Exists) { using fsCustomers as FileStream= new FileStream(fiCustomers.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { xdCustomers.Load(fsCustomers) XmlNodeList xnlCustomers = xdCustomers.DocumentElement!.SelectNodes("//account-number[.='" + MtbAccountNumber.Text + "']")!; for each xnCustomer as XmlNode in xnlCustomers { TxtAccountName.Text = xnCustomer.NextSibling.InnerText rem Account Name strMeterNumber = xnCustomer.NextSibling.NextSibling.InnerText rem Meter Number TxtAccountType.Text = xnCustomer.NextSibling.NextSibling.NextSibling.InnerText rem Account Type TxtAddress.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.InnerText rem Address TxtCity.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText rem City TxtCounty.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling.InnerText rem County TxtState.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText rem State TxtZIPCode.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText rem ZIP-Code } } } dim xdWaterMeters as XmlDocument = new XmlDocument() dim strWaterMeters as string= "C:\Stellar Water Point10\WaterMeters.xml" dim fiWaterMeters as FileInfo= new FileInfo(strWaterMeters) if fiWaterMeters.Exists) { using fsWaterMeters as FileStream= new FileStream(fiWaterMeters.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { xdWaterMeters.Load(fsWaterMeters) dim xnlWaterMeters as XmlNodeList = xdWaterMeters.DocumentElement!.SelectNodes("//meter-number[.='" + strMeterNumber + "']")!; rem Check each node of the XML record for each xnWaterMeter as XmlNode in xnlWaterMeters) { TxtMeterDetails.Text = xnWaterMeter.NextSibling!.InnerText + " " + xnWaterMeter.NextSibling.NextSibling!.InnerText + " (Meter Size: " + xnWaterMeter.NextSibling.NextSibling.NextSibling!.InnerText + ")" } } } } private sub BtnFindCustomerAccount_Click(sender As Object, e As EventArgs) { XmlDocument xdCustomers = new XmlDocument() string? strCustomers = "C:\Stellar Water Point10\Customers.xml" FileInfo? fiCustomers = new FileInfo(strCustomers) string strMeterNumber = string.Empty; if fiCustomers.Exists) { using fsCustomers as FileStream= new FileStream(fiCustomers.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { xdCustomers.Load(fsCustomers) XmlNodeList xnlCustomers = xdCustomers.DocumentElement!.SelectNodes("//account-number[.='" + MtbAccountNumber.Text + "']")!; for each xnCustomer as XmlNode in xnlCustomers { TxtAccountName.Text = xnCustomer.NextSibling.InnerText strMeterNumber = xnCustomer.NextSibling.NextSibling.InnerText TxtAccountType.Text = xnCustomer.NextSibling.NextSibling.NextSibling.InnerText TxtAddress.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.InnerText TxtCity.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText TxtCounty.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling.InnerText TxtState.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtZIPCode.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText } } } dim xdWaterMeters as XmlDocument = new XmlDocument() dim strWaterMeters as string= "C:\Stellar Water Point10\WaterMeters.xml" dim fiWaterMeters as FileInfo= new FileInfo(strWaterMeters) if fiWaterMeters.Exists) { using fsWaterMeters as FileStream= new FileStream(fiWaterMeters.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { xdWaterMeters.Load(fsWaterMeters) dim xnlWaterMeters as XmlNodeList = xdWaterMeters.DocumentElement!.SelectNodes("//meter-number[.='" + strMeterNumber + "']")!; for each xnWaterMeter as XmlNode in xnlWaterMeters) { TxtMeterDetails.Text = xnWaterMeter.NextSibling!.InnerText + " " + xnWaterMeter.NextSibling.NextSibling!.InnerText + " (Meter Size: " + xnWaterMeter.NextSibling.NextSibling.NextSibling!.InnerText + ")" } } } } private sub dtpMeterReadingEndDate_ValueChanged(sender As Object, e As EventArgs) { TimeSpan tsDays = dtpMeterReadingEndDate.Value - dtpMeterReadingStartDate.Value; TxtBillingDays.Text = (tsDays.Days + 1).ToString() } (double a, double b, double c) CalculateTiers(string acnt, double total) { (double tier1, double tier2, double tier3) results = (0.00, 0.00, 0.00) if acnt="RES") { results.tier1 = total * 41.50 / 10000.00; results.tier2 = total * 32.50 / 10000.00; results.tier3 = total * 26.00 / 10000.00; } else if acnt="SGO") { results.tier1 = total * 46 / 10000; results.tier2 = total * 50 / 10000; results.tier3 = total * 4 / 10000; } else if acnt="BUS") { results.tier1 = total * 45 / 10000; results.tier2 = total * 30 / 10000; results.tier3 = total * 25 / 10000; } else if acnt="UUO") { results.tier1 = total * 25 / 10000; results.tier2 = total * 35 / 10000; results.tier3 = total * 40 / 10000; } else if acnt="WAT") { results.tier1 = total * 50 / 10000; results.tier2 = total * 40 / 10000; results.tier3 = total * 10 / 10000; } else if acnt="OTH") { results.tier1 = total * (48.00 / 10000.00) results.tier2 = total * (32.00 / 10000.00) results.tier3 = total * (20.00 / 10000.00) } return results; } private double CalculateSewerCharges(string acnt, double total) { double result; if acnt="RES") { result = total * 6.826941 / 100; } else if acnt="SGO") { result = total * 4.162522 / 100; } else if acnt="BUS") { result = total * 8.3136 / 100; } else if acnt="UUO") { result = total * 10.6247 / 100; } else if acnt="WAT") { result = total * 12.0535 / 100; } else rem OTH { result = total * 9.2065 / 100; } return result; } private double CalculateEnvironmentCharges(string acnt, double total) { double result; switch (acnt) { case "RES": result = total * 0.022724; Exit For case "SGO": result = total * 0.118242; Exit For case "BUS": result = total * 0.161369; Exit For case "UUO": result = total * 0.082477; Exit For case "WAT": result = total * 0.413574; Exit For default: result = total * 0.22184; Exit For } return result; } private double CalculateServiceCharges(string acnt, double total) { if acnt="RES") { return total * 0.145748; } else if acnt="SGO") { return total * 0.10224; } else if acnt="BUS") { return total * 0.242627; } else if acnt="UUO") { return total * 0.18669; } else if acnt="WAT") { return total * 0.412628; } else { return total * 0.210248; } } private double CalculateLocalTaxes(string acnt, double total) => acnt switch { "RES" => total * 0.031574, "SGO" => total * 0.035026, "BUS" => total * 0.122517, "UUO" => total * 0.105737, "WAT" => total * 0.153248, _ => total * 0.125148 }; private double CalculateStateTaxes(string acnt, double total) => acnt switch { "RES" => total * 0.016724, "SGO" => total * 0.008779, "BUS" => total * 0.042448, "UUO" => total * 0.067958, "WAT" => total * 0.081622, _ => total * 0.013746 }; private DateTime SetPaymentDueDate(string acnt, DateTime date) { TimeSpan tsPaymentDueDate = new TimeSpan(1, 0, 0, 0) if acnt="RES") { tsPaymentDueDate = new TimeSpan(15, 0, 0, 0) } else if acnt="SGO") { tsPaymentDueDate = new TimeSpan(20, 0, 0, 0) } else if acnt="BUS") { tsPaymentDueDate = new TimeSpan(30, 0, 0, 0) } else if acnt="UUO") { tsPaymentDueDate = new TimeSpan(15, 0, 0, 0) } else if acnt="WAT") { tsPaymentDueDate = new TimeSpan(40, 0, 0, 0) } else { tsPaymentDueDate = new TimeSpan(35, 0, 0, 0) } return date + tsPaymentDueDate; } private DateTime SetLatePaymentDueDate(string acnt, DateTime date) { TimeSpan tsLatePaymentDueDate = new TimeSpan(1, 0, 0, 0) if acnt="RES") { tsLatePaymentDueDate = new TimeSpan(30, 0, 0, 0) return date + tsLatePaymentDueDate; } else if acnt="SGO") { tsLatePaymentDueDate = new TimeSpan(40, 0, 0, 0) return date + tsLatePaymentDueDate; } else if acnt="BUS") { tsLatePaymentDueDate = new TimeSpan(50, 0, 0, 0) return date + tsLatePaymentDueDate; } else if acnt="UUO") { tsLatePaymentDueDate = new TimeSpan(60, 0, 0, 0) return date + tsLatePaymentDueDate; } else if acnt="WAT") { tsLatePaymentDueDate = new TimeSpan(65, 0, 0, 0) return date + tsLatePaymentDueDate; } else { tsLatePaymentDueDate = new TimeSpan(45, 0, 0, 0) return date + tsLatePaymentDueDate; } } private double CalculateLateAmountDue(string acnt, double amt) { double result; if acnt="RES") { result = amt + 8.95; } else if acnt="SGO") { result = amt + (amt / 4.575) } else if acnt="BUS") { result = amt + (amt / 12.315) } else if acnt="UUO") { result = amt + (amt / 7.425) } else if acnt="WAT") { result = amt + (amt / 15.225) } else { result = amt + (amt / 6.735) } return result; } private sub BtnEvaluateWaterBill_Click(sender As Object, e As EventArgs) { double counterStart = 0, counterEnd = 0; try { counterStart = double.Parse(TxtCounterReadingStart.Text) } catch (FormatException feCRStart) { MsgBox("There was a problem with the value of the " + "Counter Reading Start. The error produced is: " + feCRStart.Message, "Stellar Water Point", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information) } try { counterEnd = double.Parse(TxtCounterReadingEnd.Text) } catch (FormatException feCREnd) { MsgBox("There was a problem with the value of the " + "Counter Reading End. The error produced is: " + feCREnd.Message, "Stellar Water Point", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information) } double consumption = counterEnd - counterStart; double gallons = consumption * 748.05; string strAccountType = TxtAccountType.Text[..3]; (double first, double second, double last) tiers = CalculateTiers(strAccountType, gallons) double waterCharges = tiers.first + tiers.second + tiers.last; double sewerCharges = CalculateSewerCharges(strAccountType, waterCharges) double envCharges = CalculateEnvironmentCharges(strAccountType, waterCharges) double srvCharges = CalculateServiceCharges(strAccountType, waterCharges) double totalCharges = waterCharges + sewerCharges + envCharges + srvCharges; double localTaxes = CalculateLocalTaxes(strAccountType, waterCharges) double stateTaxes = CalculateStateTaxes(strAccountType, waterCharges) double amtDue = totalCharges + localTaxes + stateTaxes; TxtTotalHCF.Text = consumption.ToString() TxtTotalGallons.Text = gallons.ToString("F") TxtFirstTierConsumption.Text = tiers.first.ToString("F") TxtSecondTierConsumption.Text = tiers.second.ToString("F") TxtLastTierConsumption.Text = tiers.last.ToString("F") TxtWaterCharges.Text = waterCharges.ToString("F") TxtSewerCharges.Text = sewerCharges.ToString("F") TxtEnvironmentCharges.Text = envCharges.ToString("F") TxtServiceCharges.Text = srvCharges.ToString("F") TxtTotalCharges.Text = totalCharges.ToString("F") TxtLocalTaxes.Text = localTaxes.ToString("F") TxtStateTaxes.Text = stateTaxes.ToString("F") dtpPaymentDueDate.Value = SetPaymentDueDate(strAccountType, dtpMeterReadingEndDate.Value) TxtAmountDue.Text = amtDue.ToString("F") dtpLatePaymentDueDate.Value = SetLatePaymentDueDate(strAccountType, dtpMeterReadingEndDate.Value) TxtLateAmountDue.Text = CalculateLateAmountDue(strAccountType, amtDue).ToString("F") } } }
Control | (Name) | Text | Other Properties | |
ListView | ![]() |
LvwWaterBills | No Change | |
Button | ![]() |
BtnNewWaterBill | No Change | |
Button | ![]() |
BtnViewWaterBill | No Change | |
Button | ![]() |
BtnEditWaterBill | &Edit Water Bill... | Anchor: Bottom, Right |
import System.Xml
namespace StellarWaterPoint1.WaterBills
{
public partial class Central : Form
{
public Central()
{
InitializeComponent()
}
private sub ShowWaterBills()
{
. . .
}
private sub Central_Load(sender As Object, e As EventArgs) Handles MyBase.Load
{
ShowWaterBills()
}
private sub BtnCreateWaterBill_Click(sender As Object, e As EventArgs)
{
Create create = new()
create.ShowDialog()
ShowWaterBills()
}
private sub BtnViewWaterBill_Click(sender As Object, e As EventArgs)
{
Details details = new()
details.ShowDialog()
}
private sub BtnEditWaterBill_Click(sender As Object, e As EventArgs)
{
Editor editor = new()
if editor.ShowDialog() =MsgBoxResult.OK)
{
if string.IsNullOrEmpty(editor.TxtBillNumber.Text))
{
MsgBox("You must first type a bill number and then click the Find Water Bill button. " +
"You can then optionally change some values on the water bill and save it.",
"Stellar Water Point", MessageBoxButtons.OK)
Exit Sub
}
XmlDocument xdWaterBills = new XmlDocument()
string? strWaterBills = "C:\Stellar Water Point10\WaterBills.xml"
xdWaterBills.Load(strWaterBills)
XmlNodeList xnlWaterBills = xdWaterBills.DocumentElement!.GetElementsByTagName("bill-number")
foreach (XmlNode xnWaterBill in xnlWaterBills)
{
if xnWaterBill.InnerText.Contains(editor.TxtBillNumber.Text))
{
xnWaterBill.ParentNode!.InnerXml =
"<bill-number>" + editor.TxtBillNumber.Text + "</bill-number>" +
"<account-number>" + editor.MtbAccountNumber.Text + "</account-number>" +
"<meter-reading-start-date>" + editor.dtpMeterReadingStartDate.Value.ToShortDateString() + "</meter-reading-start-date>" +
"<meter-reading-end-date>" + editor.dtpMeterReadingEndDate.Value.ToShortDateString() + "</meter-reading-end-date>" +
"<billing-days>" + editor.TxtBillingDays.Text + "</billing-days>" +
"<counter-reading-start>" + editor.TxtCounterReadingStart.Text + "</counter-reading-start>" +
"<counter-reading-end>" + editor.TxtCounterReadingEnd.Text + "</counter-reading-end>" +
"<total-hcf>" + editor.TxtTotalHCF.Text + "</total-hcf>" +
"<total-gallons>" + editor.TxtTotalGallons.Text + "</total-gallons>" +
"<first-tier-consumption>" + editor.TxtFirstTierConsumption.Text + "</first-tier-consumption>" +
"<second-tier-consumption>" + editor.TxtSecondTierConsumption.Text + "</second-tier-consumption>" +
"<last-tier-consumption>" + editor.TxtLastTierConsumption.Text + "</last-tier-consumption>" +
"<water-charges>" + editor.TxtWaterCharges.Text + "</water-charges>" +
"<sewer-charges>" + editor.TxtSewerCharges.Text + "</sewer-charges>" +
"<environment-charges>" + editor.TxtEnvironmentCharges.Text + "</environment-charges>" +
"<service-charges>" + editor.TxtEnvironmentCharges.Text + "</service-charges>" +
"<total-charges>" + editor.TxtTotalCharges.Text + "</total-charges>" +
"<state-taxes>" + editor.TxtStateTaxes.Text + "</state-taxes>" +
"<local-taxes>" + editor.TxtLocalTaxes.Text + "</local-taxes>" +
"<payment-due-date>" + editor.dtpPaymentDueDate.Value.ToShortDateString() + "</payment-due-date>" +
"<amount-due>" + editor.TxtAmountDue.Text + "</amount-due>" +
"<late-payment-due-date>" + editor.dtpLatePaymentDueDate.Value.ToShortDateString() + "</late-payment-due-date>" +
"<late-amount-due>" + editor.TxtLateAmountDue.Text + "</late-amount-due>"
xdWaterBills.Save(strWaterBills)
Exit For
}
}
}
ShowWaterBills()
}
}
}
Account #: 9249-379-6848 and click Find Customer Account Meter Reading Start Date: 1/19/2010 Meter Reading End Date: 4/17/2010 Counter Reading Start: 256953 Counter Reading End: 256966
Deleting a Water Bill
If something is completely wrong about a water bill so much that such a water bill must be removed from the application, the water bill must be deleted. To assist the user with such an operation, we will create the necessary form.
Practical Learning: Deleting a Customer Account
Control | (Name) | Text | |
Button | ![]() |
BtnDeleteWaterBill | &Delete Water Bill |
FormBorderStyle: FixedDialog Text: Stellar Water Point - Water Bill Deletion StartPosition: CenterScreen MinimizeBox: False MaximizeBox: False ShowInTaskbar: False
import System.Xml namespace StellarWaterPoint1.WaterBills { public partial class Delete : Form { public Delete() { InitializeComponent() } private sub BtnFindWaterBill_Click(sender As Object, e As EventArgs) { rem If the user clicks the Find Water Meter button, * make sure there is an invoice number in the top text box. if string.IsNullOrEmpty(TxtBillNumber.Text)) { MsgBox("You must provide a water bill number and then click the Find Water Bill button.", "Stellar Water Point", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information) rem If the user didn't type a bill number but clicked Find Water Bill, don't do anything Exit Sub } XmlDocument xdWaterBills = new XmlDocument() string? strWaterBills = "C:\Stellar Water Point10\WaterBills.xml" FileInfo? fiWaterBills = new FileInfo(strWaterBills) if fiWaterBills.Exists) { using (FileStream? fsWaterBills = new FileStream(fiWaterBills.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { xdWaterBills.Load(fsWaterBills) rem Use XPath to locate the water bill that has * the same invoice number as the one in the Water Bill Number text box. * Store the water bill in an XmlNodeList variable. XmlNodeList xnlWaterBills = xdWaterBills.DocumentElement!.SelectNodes("//bill-number[.='" + TxtBillNumber.Text + "']")!; foreach (XmlNode xnWaterBill in xnlWaterBills) { TxtBillNumber.Text = xnWaterBill.FirstChild.InnerText TxtAccountNumber.Text = xnWaterBill.NextSibling.InnerText TxtMeterReadingStartDate.Text = DateTime.Parse(xnWaterBill.NextSibling.NextSibling!.InnerText).ToLongDateString() TxtMeterReadingEndDate.Text = DateTime.Parse(xnWaterBill.NextSibling.NextSibling.NextSibling!.InnerText).ToLongDateString() TxtBillingDays.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.InnerText TxtCounterReadingStart.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling.InnerText TxtCounterReadingEnd.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling.InnerText TxtTotalHCF.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtTotalGallons.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtFirstTierConsumption.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtSecondTierConsumption.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtLastTierConsumption.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtWaterCharges.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtSewerCharges.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtEnvironmentCharges.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtServiceCharges.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtTotalCharges.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtStateTaxes.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtLocalTaxes.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtPaymentDueDate.Text = DateTime.Parse(xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.InnerText).ToLongDateString() TxtAmountDue.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtLatePaymentDueDate.Text = DateTime.Parse(xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.InnerText).ToLongDateString() TxtLateAmountDue.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText } } } XmlDocument xdCustomers = new XmlDocument() rem Declare a variable for a file that holds the list of customers string? strCustomers = "C:\Stellar Water Point10\Customers.xml" rem Create a FileInfo object for the customers FileInfo? fiCustomers = new FileInfo(strCustomers) rem We will need to know the water meter associated with this customer account string strMeterNumber = string.Empty; rem Check whether the file that holds a list of customers exists if fiCustomers.Exists) { rem If that exists, open it and pass it to a FileStream object using fsCustomers as FileStream= new FileStream(fiCustomers.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { rem Get the list of customers and pass the records to the XML DOM object created earlier xdCustomers.Load(fsCustomers) rem Create an XmlNodeList list of customers using XPath XmlNodeList xnlCustomers = xdCustomers.DocumentElement!.SelectNodes("//account-number[.='" + TxtAccountNumber.Text + "']")!; rem Check each node of the XML record and display its values in each Windows control on the form for each xnCustomer as XmlNode in xnlCustomers { //MtbAccountNumber.Text = xnCustomer.NextSibling.InnerText rem Meter # TxtAccountName.Text = xnCustomer.NextSibling.InnerText rem Account Name strMeterNumber = xnCustomer.NextSibling.NextSibling.InnerText rem Meter Number TxtAccountType.Text = xnCustomer.NextSibling.NextSibling.NextSibling.InnerText rem Account Type TxtAddress.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.InnerText rem Address TxtCity.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText rem City TxtCounty.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling.InnerText rem County TxtState.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText rem State TxtZIPCode.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText rem ZIP-Code } } } rem Create an XML DOM object for the water meters records dim xdWaterMeters as XmlDocument = new XmlDocument() rem Declare a variable for a file that holds the list of water meters dim strWaterMeters as string= "C:\Stellar Water Point10\WaterMeters.xml" rem Create a FileInfo object for the customers dim fiWaterMeters as FileInfo= new FileInfo(strWaterMeters) rem Check whether the file that holds a list of water meters exists if fiWaterMeters.Exists) { rem Get the list of water meters and pass the records to the XML DOM object using fsWaterMeters as FileStream= new FileStream(fiWaterMeters.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { rem Get the list of water meters and pass the records to the XML DOM object xdWaterMeters.Load(fsWaterMeters) rem Create an XmlNodeList list of water meters using XPath dim xnlWaterMeters as XmlNodeList = xdWaterMeters.DocumentElement!.SelectNodes("//meter-number[.='" + strMeterNumber + "']")!; rem Check each node of the XML record for each xnWaterMeter as XmlNode in xnlWaterMeters) { rem Get the values for the water meter. * Create a sentence and display it in the Meter Details text box. TxtMeterDetails.Text = xnWaterMeter.NextSibling!.InnerText + " " + xnWaterMeter.NextSibling.NextSibling!.InnerText + " (Meter Size: " + xnWaterMeter.NextSibling.NextSibling.NextSibling!.InnerText + ")" } } } } } }
import System.Xml namespace StellarWaterPoint1.WaterBills { public partial class Delete : Form { public Delete() { InitializeComponent() } private sub BtnFindWaterBill_Click(sender As Object, e As EventArgs) { rem If the user clicks the Find Water Meter button, * make sure there is an invoice number in the top text box. if string.IsNullOrEmpty(TxtBillNumber.Text)) { MsgBox("You must provide a water bill number and then click the Find Water Bill button.", "Stellar Water Point", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information) rem If the user didn't type a bill number but clicked Find Water Bill, don't do anything Exit Sub } XmlDocument xdWaterBills = new XmlDocument() string? strWaterBills = "C:\Stellar Water Point10\WaterBills.xml" FileInfo? fiWaterBills = new FileInfo(strWaterBills) if fiWaterBills.Exists) { using (FileStream? fsWaterBills = new FileStream(fiWaterBills.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { xdWaterBills.Load(fsWaterBills) rem Use XPath to locate the water bill that has * the same invoice number as the one in the Water Bill Number text box. * Store the water bill in an XmlNodeList variable. XmlNodeList xnlWaterBills = xdWaterBills.DocumentElement!.SelectNodes("//bill-number[.='" + TxtBillNumber.Text + "']")!; foreach (XmlNode xnWaterBill in xnlWaterBills) { TxtBillNumber.Text = xnWaterBill.FirstChild.InnerText TxtAccountNumber.Text = xnWaterBill.NextSibling.InnerText TxtMeterReadingStartDate.Text = DateTime.Parse(xnWaterBill.NextSibling.NextSibling!.InnerText).ToLongDateString() TxtMeterReadingEndDate.Text = DateTime.Parse(xnWaterBill.NextSibling.NextSibling.NextSibling!.InnerText).ToLongDateString() TxtBillingDays.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.InnerText TxtCounterReadingStart.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling.InnerText TxtCounterReadingEnd.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling.InnerText TxtTotalHCF.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtTotalGallons.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtFirstTierConsumption.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtSecondTierConsumption.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtLastTierConsumption.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtWaterCharges.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtSewerCharges.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtEnvironmentCharges.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtServiceCharges.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtTotalCharges.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtStateTaxes.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtLocalTaxes.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtPaymentDueDate.Text = DateTime.Parse(xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.InnerText).ToLongDateString() TxtAmountDue.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText TxtLatePaymentDueDate.Text = DateTime.Parse(xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.InnerText).ToLongDateString() TxtLateAmountDue.Text = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText } } } XmlDocument xdCustomers = new XmlDocument() rem Declare a variable for a file that holds the list of customers string? strCustomers = "C:\Stellar Water Point10\Customers.xml" rem Create a FileInfo object for the customers FileInfo? fiCustomers = new FileInfo(strCustomers) rem We will need to know the water meter associated with this customer account string strMeterNumber = string.Empty; rem Check whether the file that holds a list of customers exists if fiCustomers.Exists) { rem If that exists, open it and pass it to a FileStream object using fsCustomers as FileStream= new FileStream(fiCustomers.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { rem Get the list of customers and pass the records to the XML DOM object created earlier xdCustomers.Load(fsCustomers) rem Create an XmlNodeList list of customers using XPath XmlNodeList xnlCustomers = xdCustomers.DocumentElement!.SelectNodes("//account-number[.='" + TxtAccountNumber.Text + "']")!; rem Check each node of the XML record and display its values in each Windows control on the form for each xnCustomer as XmlNode in xnlCustomers { //MtbAccountNumber.Text = xnCustomer.NextSibling.InnerText rem Meter # TxtAccountName.Text = xnCustomer.NextSibling.InnerText rem Account Name strMeterNumber = xnCustomer.NextSibling.NextSibling.InnerText rem Meter Number TxtAccountType.Text = xnCustomer.NextSibling.NextSibling.NextSibling.InnerText rem Account Type TxtAddress.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.InnerText rem Address TxtCity.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText rem City TxtCounty.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling.InnerText rem County TxtState.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText rem State TxtZIPCode.Text = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling.InnerText rem ZIP-Code } } } rem Create an XML DOM object for the water meters records dim xdWaterMeters as XmlDocument = new XmlDocument() rem Declare a variable for a file that holds the list of water meters dim strWaterMeters as string= "C:\Stellar Water Point10\WaterMeters.xml" rem Create a FileInfo object for the customers dim fiWaterMeters as FileInfo= new FileInfo(strWaterMeters) rem Check whether the file that holds a list of water meters exists if fiWaterMeters.Exists) { rem Get the list of water meters and pass the records to the XML DOM object using fsWaterMeters as FileStream= new FileStream(fiWaterMeters.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { rem Get the list of water meters and pass the records to the XML DOM object xdWaterMeters.Load(fsWaterMeters) rem Create an XmlNodeList list of water meters using XPath dim xnlWaterMeters as XmlNodeList = xdWaterMeters.DocumentElement!.SelectNodes("//meter-number[.='" + strMeterNumber + "']")!; rem Check each node of the XML record for each xnWaterMeter as XmlNode in xnlWaterMeters) { rem Get the values for the water meter. * Create a sentence and display it in the Meter Details text box. TxtMeterDetails.Text = xnWaterMeter.NextSibling!.InnerText + " " + xnWaterMeter.NextSibling.NextSibling!.InnerText + " (Meter Size: " + xnWaterMeter.NextSibling.NextSibling.NextSibling!.InnerText + ")" } } } } private sub BtnDeleteWaterBill_Click(sender As Object, e As EventArgs) { dim xdWaterMeters as XmlDocument = new XmlDocument() dim strWaterMeters as string= "C:\Stellar Water Point10\WaterBills.xml" if string.IsNullOrEmpty(TxtBillNumber.Text)) { MsgBox("You must provide a bill number for the water bill you want to delete.", "Stellar Water Point", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information) Exit Sub } if !File.Exists(strWaterMeters)) { MsgBox("There is no file for the water bills in the system.", "Stellar Water Point", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information) Exit Sub } xdWaterMeters.Load(strWaterMeters) dim xnlWaterMeters as XmlNodeList = xdWaterMeters.DocumentElement!.GetElementsByTagName("bill-number") for each xnWaterMeter as XmlNode in xnlWaterMeters) { if xnWaterMeter.InnerText=TxtBillNumber.Text) { if MsgBox("Are you sure you want to delete this water bill from the system?", "Stellar Water Point", MessageBoxButtons.YesNo, MessageBoxIcon.Question) =MsgBoxResult.Yes) { xdWaterMeters.DocumentElement.RemoveChild(xnWaterMeter.ParentNode!) Exit For } } } xdWaterMeters.Save(strWaterMeters) Close() } private sub BtnClose_Click(sender As Object, e As EventArgs) { Close() } } }
Control | (Name) | Text | Other Properties | |
ListView | ![]() |
LvwWaterBills | Anchor: Bottom, Top, Bottom, Left, Right | |
Button | ![]() |
BtnCreateWaterBill | &Create Water Bill... | Anchor: Bottom, Right |
Button | ![]() |
BtnViewWaterBill | &View Water Bill... | Anchor: Bottom, Right |
Button | ![]() |
BtnEditWaterBill | &Edit Water Bill... | Anchor: Bottom, Right |
Button | ![]() |
BtnDeleteWaterBill | &Delete Water Bill... | Anchor: Bottom, Right |
Button | ![]() |
BtnClose | &Close | Anchor: Bottom, Right |
import System.Xml namespace StellarWaterPoint1.WaterBills { public partial class Central : Form { public Central() { InitializeComponent() } private sub ShowWaterBills() { lvwWaterBills.Items.Clear() XmlDocument xdWaterBills = new XmlDocument() string? strWaterBills = "C:\Stellar Water Point10\WaterBills.xml" FileInfo? fiWaterBills = new FileInfo(strWaterBills) if fiWaterBills.Exists) { using (FileStream? fsWaterBills = new FileStream(fiWaterBills.FullName, FileMode.Open, FileAccess.Read, FileShare.Read)) { xdWaterBills.Load(fsWaterBills) XmlNodeList xnlWaterBills = xdWaterBills.DocumentElement!.ChildNodes; int i = 1; foreach (XmlNode xnWaterBill in xnlWaterBills) { ListViewItem lviWaterBill = new ListViewItem(i.ToString()) lviWaterBill.SubItems.Add(xnWaterBill.FirstChild!.InnerText) rem Water Bill # lviWaterBill.SubItems.Add(xnWaterBill.FirstChild.NextSibling!.InnerText) rem Account Number lviWaterBill.SubItems.Add(xnWaterBill.FirstChild.NextSibling.NextSibling!.InnerText) rem Meter Reading Start Date lviWaterBill.SubItems.Add(xnWaterBill.FirstChild.NextSibling.NextSibling.NextSibling!.InnerText) rem Meter Reading End Date lviWaterBill.SubItems.Add(xnWaterBill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling!.InnerText) rem Billing Days lviWaterBill.SubItems.Add(xnWaterBill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.InnerText) rem Counter Reading Start lviWaterBill.SubItems.Add(xnWaterBill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.InnerText) rem Counter Reading End lviWaterBill.SubItems.Add(xnWaterBill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.InnerText) rem Total HCF lviWaterBill.SubItems.Add(xnWaterBill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.InnerText) rem Gallons lviWaterBill.SubItems.Add(xnWaterBill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.InnerText) rem Payment Due Date lviWaterBill.SubItems.Add(xnWaterBill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.NextSibling!.InnerText) rem Amount Due lvwWaterBills.Items.Add(lviWaterBill) i++; } } } } private sub Central_Load(sender As Object, e As EventArgs) Handles MyBase.Load { ShowWaterBills() } private sub BtnCreateWaterBill_Click(sender As Object, e As EventArgs) { Create create = new() create.ShowDialog() ShowWaterBills() } private sub BtnViewWaterBill_Click(sender As Object, e As EventArgs) { Details details = new() details.ShowDialog() } private sub BtnEditWaterBill_Click(sender As Object, e As EventArgs) { Editor editor = new() if editor.ShowDialog() =MsgBoxResult.OK) { if string.IsNullOrEmpty(editor.TxtBillNumber.Text)) { MsgBox("You must first type a bill number and then click the Find Water Bill button. " + "You can then optionally change some values on the water bill and save it.", "Stellar Water Point", MessageBoxButtons.OK) Exit Sub } rem Create an XML DOM object XmlDocument xdWaterBills = new XmlDocument() rem Prepare the path and name of the file that holds a list of water bills string? strWaterBills = "C:\Stellar Water Point10\WaterBills.xml" rem Get the water bills records and store them in the above XML DOM object xdWaterBills.Load(strWaterBills) rem Create an XmlNodeList list that reprensents the XML elements from the list of water bills. * Call the XML DOM's GetElementsByTagName() method. * To use the bill number elements as reference, pass the water bill number element as argument. XmlNodeList xnlWaterBills = xdWaterBills.DocumentElement!.GetElementsByTagName("bill-number") rem Visit each XML element of the list of water bills foreach (XmlNode xnWaterBill in xnlWaterBills) { rem When you get to an element, find out if the value of its bill number is rem the same as the bill number the user typed in the form. If that's the case, rem change the value of each node of that element, using the values from the form. if xnWaterBill.InnerText.Contains(editor.TxtBillNumber.Text)) { xnWaterBill.ParentNode!.InnerXml = "<bill-number>" + editor.TxtBillNumber.Text + "</bill-number>" + "<account-number>" + editor.MtbAccountNumber.Text + "</account-number>" + "<meter-reading-start-date>" + editor.dtpMeterReadingStartDate.Value.ToShortDateString() + "</meter-reading-start-date>" + "<meter-reading-end-date>" + editor.dtpMeterReadingEndDate.Value.ToShortDateString() + "</meter-reading-end-date>" + "<billing-days>" + editor.TxtBillingDays.Text + "</billing-days>" + "<counter-reading-start>" + editor.TxtCounterReadingStart.Text + "</counter-reading-start>" + "<counter-reading-end>" + editor.TxtCounterReadingEnd.Text + "</counter-reading-end>" + "<total-hcf>" + editor.TxtTotalHCF.Text + "</total-hcf>" + "<total-gallons>" + editor.TxtTotalGallons.Text + "</total-gallons>" + "<first-tier-consumption>" + editor.TxtFirstTierConsumption.Text + "</first-tier-consumption>" + "<second-tier-consumption>" + editor.TxtSecondTierConsumption.Text + "</second-tier-consumption>" + "<last-tier-consumption>" + editor.TxtLastTierConsumption.Text + "</last-tier-consumption>" + "<water-charges>" + editor.TxtWaterCharges.Text + "</water-charges>" + "<sewer-charges>" + editor.TxtSewerCharges.Text + "</sewer-charges>" + "<environment-charges>" + editor.TxtEnvironmentCharges.Text + "</environment-charges>" + "<service-charges>" + editor.TxtEnvironmentCharges.Text + "</service-charges>" + "<total-charges>" + editor.TxtTotalCharges.Text + "</total-charges>" + "<state-taxes>" + editor.TxtStateTaxes.Text + "</state-taxes>" + "<local-taxes>" + editor.TxtLocalTaxes.Text + "</local-taxes>" + "<payment-due-date>" + editor.dtpPaymentDueDate.Value.ToShortDateString() + "</payment-due-date>" + "<amount-due>" + editor.TxtAmountDue.Text + "</amount-due>" + "<late-payment-due-date>" + editor.dtpLatePaymentDueDate.Value.ToShortDateString() + "</late-payment-due-date>" + "<late-amount-due>" + editor.TxtLateAmountDue.Text + "</late-amount-due>" rem After updating the elements, save the updated file xdWaterBills.Save(strWaterBills) rem After saving the file, stop searching Exit For } } } rem Now that the user has closed the Water Bill - Editor dialog box (and probably rem updated the XML file for water bills), (re-)display the list of water bills.*/ ShowWaterBills() } private sub BtnDeleteWaterBill_Click(sender As Object, e As EventArgs) { Delete delete = new() delete.ShowDialog() ShowWaterBills() } private sub BtnClose_Click(sender As Object, e As EventArgs) { Close() } } }
|
|||
Home | Copyright © 2010-2025, FunctionX | Sunday 30 March 2025, 13:50 | Home |
|