ASP.NET MVC/jQuery Application: Stellar Water Point
ASP.NET MVC/jQuery Application: Stellar Water Point
Starting the Project
Introduction
A water distribution company delivers water to homes and commercial buildings. In this exercise, we will create an application for a fictitious company that distributes and sells water. This version of the application creates and stores records in XML.
Practical Learning: Introducing XML Node Maintenance
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
/* Set padding to keep content from hitting the edges */
.body-content {
margin-top: 15px;
padding-left: 15px;
padding-right: 15px;
}
/* Override the default bootstrap behavior where horizontal description lists
will truncate terms that are too long to fit in the left column
*/
.dl-horizontal dt {
white-space: normal;
}
/* Set width on the form input elements since they're 100% wide by default */
input,
select,
textarea {
max-width: 280px;
}
.bordered { border: 1px solid black; }
.bg-dark { margin-bottom: 1rem !important;
background-color: #800000 !important;
font-family: Garamond, Georgia, Cambria, 'Times New Roman', Times, serif; }
.display-4 { line-height: 0.825; }
.encloser-small { margin: auto;
width: 400px; }
.encloser-medium { margin: auto;
width: 550px; }
.encloser-large { margin: auto;
width: 600px; }
.navbar-brand { font-weight: bold;
color: #FFD800; }
.navbar-brand:hover, .navbar-brand:focus {
font-weight: bold;
color: #FFFFFF; }
.nav-link { font-weight: bold;
color: yellow; }
.nav-link { font-weight: bold;
color: #FFFFFF; }
.stellar { font-weight: bold;
text-decoration: none;
color: navy;
font-family: Garamond, Georgia, Cambria, 'Times New Roman', Times, serif; }
a.stellar:focus { color: blue; }
a.stellar:hover { color: maroon;
text-decoration: underline; }
.btn-stellar { --bs-btn-color: #FFF;
--bs-btn-hover-color: #000;
--bs-btn-disabled-color: #000;
--bs-btn-bg: #800000;
--bs-btn-border-color: #800000;
--bs-btn-hover-bg: #E78A29;
--bs-btn-hover-border-color: #E78A29;
--bs-btn-active-color: #000000;
--bs-btn-active-bg: #5E0707;
--bs-btn-active-border-color: #E78A29;
--bs-btn-disabled-bg: #800000;
--bs-btn-disabled-border-color: #800000; }
.common-font { font-family: Garamond, Georgia, Cambria, 'Times New Roman', Times, serif; }Setting Up the Site
.
Practical Learning: Setting Up the Ŝite
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - Stellar Water Point</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
</head>
<body>
<nav class="common-font navbar navbar-expand-sm navbar-toggleable-sm navbar-dark bg-dark">
<div class="container">
@Html.ActionLink("Stellar Water Point", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
<button type="button" class="navbar-toggler" data-bs-toggle="collapse"
data-bs-target=".navbar-collapse" title="Toggle navigation" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1">
<li>@Html.ActionLink("Water Bills", "Index", "WaterBills", new { area = "" }, new { @class = "nav-link" })</li>
<li>@Html.ActionLink("Customers", "Index", "Customers", new { area = "" }, new { @class = "nav-link" })</li>
<li>@Html.ActionLink("Water Meters", "Index", "WaterMeters", new { area = "" }, new { @class = "nav-link" })</li>
<li>@Html.ActionLink("About", "About", "Home", new { area = "" }, new { @class = "nav-link" })</li>
<li>@Html.ActionLink("Contact", "Contact", "Home", new { area = "" }, new { @class = "nav-link" })</li>
</ul>
</div>
</div>
</nav>
<div class="container body-content">
@RenderBody()
<hr />
<footer>
<p class="common-font text-center">© 2011-@DateTime.Now.Year - Stellar Water Point</p>
</footer>
</div>
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
</body>
</html>@{
ViewBag.Title = "Home";
}
<main class="common-font">
<section class="row text-center" aria-labelledby="aspnetTitle">
<h1 id="title" class="display-4 fw-bold">Stellar Water Point</h1>
<p class="lead">Stellar Water Point is a community-based company that commercially distributes water to customers in need. Our water process is socially responsible and community oriented.</p>
</p>
</section>
<div class="row">
<section class="col-md-4" aria-labelledby="gettingStartedTitle">
<div class="card mb-4 box-shadow">
<img class="bordered card-img-top" src="../Images/WaterBills.png" alt="Water Bills">
<div class="card-body">
<h5><a class="nav-link text-dark fw-bold" href="/WaterBills/Index">Water Bills</a></h5>
<hr />
<p class="card-text">Water bills are processed in a timely and responsible manner, applying only the strictest, regular, and lawful rules.</p>
</div>
</div>
</section>
<section class="col-md-4" aria-labelledby="librariesTitle">
<div class="card mb-4 box-shadow">
<img class="bordered card-img-top" src="../Images/Customers.png" alt="Customers Accounts">
<div class="card-body">
<h5><a class="nav-link text-dark fw-bold" href="/Customers/Index">Customers Accounts</a></h5>
<hr />
<p class="card-text">Water bills are sent in a trimester-base to our customers who holds an account with us, all for good service.</p>
</div>
</div>
</section>
<section class="col-md-4" aria-labelledby="hostingTitle">
<div class="card mb-4 box-shadow">
<img class="bordered card-img-top" src="../Images/WaterMeter.png" alt="Water Meters">
<div class="card-body">
<h5><a class="nav-link text-dark fw-bold" href="/WaterMeters/Index">Water Meters</a></h5>
<hr />
<p class="card-text">We use industry standard water meters that are regularly government inspected for their accuracy and precision.</p>
</div>
</div>
</section>
</div>
<div class="row">
<section class="col-md-4" aria-labelledby="gettingStartedTitle">
<div class="card mb-4">
<img class="card-img-top bordered" src="../Images/Community.png" alt="Community Services">
<div class="card-body">
<h5><a class="nav-link text-dark fw-bold" href="/StellarWaterPoint">Community Services</a></h5>
<hr />
<p class="card-text">Stellar Water Point is a community-oriented company that works withn various local activities and authorities.</p>
</div>
</div>
</section>
<section class="col-md-4" aria-labelledby="librariesTitle">
<div class="card mb-4">
<img class="card-img-top bordered" src="../Images/LegalAffairs.png" alt="Legal Affairs">
<div class="card-body">
<h5><a class="nav-link text-dark fw-bold" href="/StellarWaterPoint">Legal Affairs</a></h5>
<hr />
<p class="card-text">Issues of regulations and government affairs are addressed here. This is available for employees, contractors, etc.</p>
</div>
</div>
</section>
<section class="col-md-4" aria-labelledby="hostingTitle">
<div class="card mb-4">
<img class="card-img-top bordered" src="../Images/Employees.png" alt="Employees Portal">
<div class="card-body">
<h5><a class="nav-link text-dark fw-bold" href="/StellarWaterPoint">Employees Portal</a></h5>
<hr />
<p class="card-text">This is a central area form employees to access the company resources such as time sheets, payroll, benefits, etc.</p>
</div>
</div>
</section>
</div>
</main>Water Meters
Introduction
Utility companies use a device that measure what their customers consume. For example a water utility company installs water meters in residences and commercial buildings to find out how much water has been used. In this section, we will create a view that allows an employee to keep track of water consumption.
Practical Learning: Introducing Water Meters

Getting a List of Water Meters
.
Practical Learning: Getting a List of Water Meters
using System.IO;
using System.Xml;
using System.Web.Mvc;
namespace StellarWaterPoint12.Controllers
{
public class WaterMetersController : Controller
{
// GET: WaterMeters
public ActionResult Index()
{
XmlDocument xdWaterMeters = new XmlDocument();
string strFileWaterMeters = Server.MapPath("/AppData/WaterMeters.xml");
if (System.IO.File.Exists(strFileWaterMeters))
{
using (FileStream fsWaterMeters = new FileStream(strFileWaterMeters, FileMode.Open,
FileAccess.Read, FileShare.Read))
{
xdWaterMeters.Load(fsWaterMeters);
}
if (xdWaterMeters.DocumentElement.ChildNodes.Count > 0)
{
ViewData["WaterMeters"] = xdWaterMeters.DocumentElement.ChildNodes;
}
else
{
ViewData["WaterMeters"] = null;
}
}
return View();
}
// GET: WaterMeters/Details/5
public ActionResult Details(int id)
{
return View();
}
. . .
}
}@{
ViewBag.Title = "Water Meters";
}
<h2 class="fw-bold common-font text-center">Water Meters</h2>
<hr />
<table class="table table-striped common-font">
<tr>
<th class="fw-bold text-center">Water Meter Id</th>
<th class="fw-bold">Meter #</th>
<th class="fw-bold">Make</th>
<th class="fw-bold">Model</th>
<th class="fw-bold">Meter Size</th>
<th>@Html.ActionLink("New Water Meter", "Create", new { area = "" }, new { @class = "stellar" })</th>
</tr>
@if (ViewBag.waterMeters != null)
{
foreach (System.Xml.XmlNode meter in ViewBag.WaterMeters as System.Xml.XmlNodeList)
{
<tr>
<td class="text-center">@meter.FirstChild.InnerText</td>
<td>@meter.FirstChild.NextSibling.InnerText</td>
<td>@meter.FirstChild.NextSibling.NextSibling.InnerText</td>
<td>@meter.FirstChild.NextSibling.NextSibling.NextSibling.InnerText</td>
<td>@meter.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling.InnerText</td>
<td>
@Html.ActionLink("Update", "Edit", new { id = @meter.FirstChild.InnerText }, new { @class = "stellar" }) ::
@Html.ActionLink("Review", "Details", new { id = @meter.FirstChild.InnerText }, new { @class = "stellar" }) ::
@Html.ActionLink("Remove", "Delete", new { id = @meter.FirstChild.InnerText }, new { @class = "stellar" })
</td>
</tr>
}
}
</table>Setting Up a Water Meter
.
Practical Learning: Setting Up a Water Meter
using System.IO;
using System.Xml;
using System.Web.Mvc;
namespace StellarWaterPoint12.Controllers
{
public class WaterMetersController : Controller
{
// GET: WaterMeters
public ActionResult Index()
{
XmlDocument xdWaterMeters = new XmlDocument();
string strFileWaterMeters = Server.MapPath("/AppData/WaterMeters.xml");
if (System.IO.File.Exists(strFileWaterMeters))
{
using (FileStream fsWaterMeters = new FileStream(strFileWaterMeters, FileMode.Open,
FileAccess.Read, FileShare.Read))
{
xdWaterMeters.Load(fsWaterMeters);
}
if (xdWaterMeters.DocumentElement.ChildNodes.Count > 0)
{
ViewData["WaterMeters"] = xdWaterMeters.DocumentElement.ChildNodes;
}
else
{
ViewData["WaterMeters"] = null;
}
}
return View();
}
// GET: WaterMeters/Details/5
public ActionResult Details(int id)
{
return View();
}
// GET: WaterMeters/Create
public ActionResult Create()
{
return View();
}
// POST: WaterMeters/Create
[HttpPost]
public ActionResult Create(FormCollection collection)
{
try
{
// TODO: Add insert logic here
XmlDocument xdWaterMeters = new XmlDocument();
string strFileWaterMeters = Server.MapPath("/AppData/WaterMeters.xml");
if (!string.IsNullOrEmpty(collection["txtMeterNumber"]))
{
if (System.IO.File.Exists(strFileWaterMeters))
{
using (FileStream fsWaterMeters = new FileStream(strFileWaterMeters, FileMode.OpenOrCreate,
FileAccess.ReadWrite, FileShare.ReadWrite))
{
xdWaterMeters.Load(fsWaterMeters);
}
}
else
{
xdWaterMeters.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<water-meters></water-meters>");
}
}
XmlElement xeWaterMeter = xdWaterMeters.CreateElement("water-meter");
string strWaterMeter = "<water-meter-id>" + collection["txtWaterMeterId"] + "</water-meter-id>" +
"<meter-number>" + collection["txtMeterNumber"] + "</meter-number>" +
"<make>" + collection["txtMake"] + "</make>" +
"<model>" + collection["txtModel"] + "</model>" +
"<meter-size>" + collection["txtMeterSize"] + "</meter-size>";
xeWaterMeter.InnerXml = strWaterMeter;
xdWaterMeters.DocumentElement.AppendChild(xeWaterMeter);
using (FileStream fsWaterMeters = new FileStream(strFileWaterMeters, FileMode.Create,
FileAccess.Write, FileShare.Write))
{
xdWaterMeters.Save(fsWaterMeters);
}
return RedirectToAction("Index");
}
catch
{
return View();
}
}
. . .
}
}
@{
ViewBag.Title = "Create Water Meter";
}
<h2 class="common-font fw-bold text-center">Create Water Meter</h2>
<hr />
@using (Html.BeginForm())
{
<div class="common-font encloser-small">
<div class="row mb-2">
@Html.Label("txtWaterMeterId", "Meter Meter Id:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtWaterMeterId", null, htmlAttributes: new { @class = "form-control" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtMeterNumber", "Meter #:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtMeterNumber", null, htmlAttributes: new { @class = "form-control" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtMake", "Make:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtMake", null, htmlAttributes: new { @class = "form-control" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtModel", "Model:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtModel", null, htmlAttributes: new { @class = "form-control" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtMeterSize", "Meter Size:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtMeterSize", null, htmlAttributes: new { @class = "form-control" })
</div>
</div>
<hr />
<div class="row mb-2">
<div class="col-md-5 col-form-label">
@Html.ActionLink("Water Meters", "Index", new { area = "" }, new { @class = "stellar" })
</div>
<div class="col-md-7">
<input type="submit" name="btnSaveWaterMeter" value="Save Water Meter" class="btn btn-stellar" />
</div>
</div>
</div>
}
<hr />
<p class="text-center">
@Html.ActionLink("View Water Meter", "Details", new { area = "" }, new { @class = "stellar" }) ::
@Html.ActionLink("Edit Water Meter", "Edit", new { area = "" }, new { @class = "stellar" }) ::
@Html.ActionLink("Delete Water Meter", "Delete", new { area = "" }, new { @class = "stellar" })
</p>| Water Meter Id | Meter # | Make | Model | Meter Size |
| 1 | 392-44-572 | Constant Tech | TG-4822 | 5-Inch |
| 2 | 938-75-869 | Stan Wood | 266G | Half Inch |
| 3 | 588-279-663 | Estellano | NCF-226 | 2 Inches |
Getting a Details of a Water Meter
.
Practical Learning: Getting a Details of a Water Meter
using System.IO;
using System.Xml;
using System.Web.Mvc;
namespace StellarWaterPoint12.Controllers
{
public class WaterMetersController : Controller
{
// GET: WaterMeters
public ActionResult Index()
{
XmlDocument xdWaterMeters = new XmlDocument();
string strFileWaterMeters = Server.MapPath("/AppData/WaterMeters.xml");
if (System.IO.File.Exists(strFileWaterMeters))
{
using (FileStream fsWaterMeters = new FileStream(strFileWaterMeters, FileMode.Open,
FileAccess.Read, FileShare.Read))
{
xdWaterMeters.Load(fsWaterMeters);
}
if (xdWaterMeters.DocumentElement.ChildNodes.Count > 0)
{
ViewData["WaterMeters"] = xdWaterMeters.DocumentElement.ChildNodes;
}
else
{
ViewData["WaterMeters"] = null;
}
}
return View();
}
// GET: WaterMeters/Details/5
public ActionResult Details(int id)
{
XmlDocument xdWaterMeters = new XmlDocument();
string strFileWaterMeters = Server.MapPath("/AppData/WaterMeters.xml");
if (System.IO.File.Exists(strFileWaterMeters))
{
using (FileStream fsWaterMeters = new FileStream(strFileWaterMeters, FileMode.Open,
FileAccess.Read, FileShare.Read))
{
xdWaterMeters.Load(fsWaterMeters);
XmlNodeList xnlWaterMeters = xdWaterMeters.GetElementsByTagName("water-meter-id");
foreach (XmlNode xnWaterMeter in xnlWaterMeters)
{
if (xnWaterMeter.InnerText == id.ToString())
{
ViewData["txtWaterMeterId"] = xnWaterMeter.InnerText;
ViewData["txtMeterNumber"] = xnWaterMeter.NextSibling.InnerText;
ViewData["txtMake"] = xnWaterMeter.NextSibling.NextSibling.InnerText;
ViewData["txtModel"] = xnWaterMeter.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["txtMeterSize"] = xnWaterMeter.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
}
}
}
}
return View();
}
// GET: WaterMeters/Create
public ActionResult Create()
{
return View();
}
// POST: WaterMeters/Create
[HttpPost]
public ActionResult Create(FormCollection collection)
{
try
{
// TODO: Add insert logic here
XmlDocument xdWaterMeters = new XmlDocument();
string strFileWaterMeters = Server.MapPath("/AppData/WaterMeters.xml");
if (!string.IsNullOrEmpty(collection["txtMeterNumber"]))
{
if (System.IO.File.Exists(strFileWaterMeters))
{
using (FileStream fsWaterMeters = new FileStream(strFileWaterMeters, FileMode.OpenOrCreate,
FileAccess.ReadWrite, FileShare.ReadWrite))
{
xdWaterMeters.Load(fsWaterMeters);
}
}
else
{
xdWaterMeters.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<water-meters></water-meters>");
}
}
XmlElement xeWaterMeter = xdWaterMeters.CreateElement("water-meter");
string strWaterMeter = "<water-meter-id>" + collection["txtWaterMeterId"] + "</water-meter-id>" +
"<meter-number>" + collection["txtMeterNumber"] + "</meter-number>" +
"<make>" + collection["txtMake"] + "</make>" +
"<model>" + collection["txtModel"] + "</model>" +
"<meter-size>" + collection["txtMeterSize"] + "</meter-size>";
xeWaterMeter.InnerXml = strWaterMeter;
xdWaterMeters.DocumentElement.AppendChild(xeWaterMeter);
using (FileStream fsWaterMeters = new FileStream(strFileWaterMeters, FileMode.Create,
FileAccess.Write, FileShare.Write))
{
xdWaterMeters.Save(fsWaterMeters);
}
return RedirectToAction("Index");
}
catch
{
return View();
}
}
. . .
}
}@{
ViewBag.Title = "Water Meter Details";
}
<h2 class="text-center fw-bold common-font">Water Meter Details</h2>
<hr />
<div class="encloser-small common-font">
<div class="row mb-2">
@Html.Label("txtWaterMeterId", "Meter Meter Id:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtWaterMeterId", ViewBag.WaterMeterId as string,
htmlAttributes: new { @class = "form-control", disabled = "disabled" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtMeterNumber", "Meter #:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtMeterNumber", ViewBag.MeterNumber as string,
htmlAttributes: new { @class = "form-control", disabled = "disabled" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtMake", "Make:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtMake", ViewBag.Make as string,
htmlAttributes: new { @class = "form-control", disabled = "disabled" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtModel", "Model:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtModel", ViewBag.Model as string,
htmlAttributes: new { @class = "form-control", disabled = "disabled" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtMeterSize", "Meter Size:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtMeterSize", ViewBag.MeterSize as string,
htmlAttributes: new { @class = "form-control", disabled = "disabled" })
</div>
</div>
</div>Updating a Water Meter
.
Practical Learning: Updating a Water Meter
using System.IO;
using System.Xml;
using System.Web.Mvc;
namespace StellarWaterPoint12.Controllers
{
public class WaterMetersController : Controller
{
// GET: WaterMeters
public ActionResult Index()
{
. . .
return View();
}
// GET: WaterMeters/Details/5
public ActionResult Details(int id)
{
. . .
return View();
}
// GET: WaterMeters/Create
public ActionResult Create()
{
return View();
}
// POST: WaterMeters/Create
[HttpPost]
public ActionResult Create(FormCollection collection)
{
try
{
// TODO: Add insert logic here
. . .
return RedirectToAction("Index");
}
catch
{
return View();
}
}
// GET: WaterMeters/Edit/5
public ActionResult Edit(int id)
{
XmlDocument xdWaterMeters = new XmlDocument();
string strFileWaterMeters = Server.MapPath("/AppData/WaterMeters.xml");
if (System.IO.File.Exists(strFileWaterMeters))
{
using (FileStream fsWaterMeters = new FileStream(strFileWaterMeters, FileMode.Open,
FileAccess.Read, FileShare.Read))
{
xdWaterMeters.Load(fsWaterMeters);
XmlNodeList xnlWaterMeters = xdWaterMeters.GetElementsByTagName("water-meter-id");
foreach (XmlNode xnWaterMeter in xnlWaterMeters)
{
if (xnWaterMeter.InnerText == id.ToString())
{
ViewData["txtWaterMeterId"] = xnWaterMeter.InnerText;
ViewData["txtMeterNumber"] = xnWaterMeter.NextSibling.InnerText;
ViewData["txtMake"] = xnWaterMeter.NextSibling.NextSibling.InnerText;
ViewData["txtModel"] = xnWaterMeter.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["txtMeterSize"] = xnWaterMeter.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
}
}
}
}
return View();
}
// POST: WaterMeters/Edit/5
[HttpPost]
public ActionResult Edit(int id, FormCollection collection)
{
try
{
// TODO: Add update logic here
XmlDocument xdWaterMeters = new XmlDocument();
string strFileWaterMeters = Server.MapPath("/AppData/WaterMeters.xml");
if (System.IO.File.Exists(strFileWaterMeters))
{
using (FileStream fsWaterMeters = new FileStream(strFileWaterMeters, FileMode.Open,
FileAccess.ReadWrite, FileShare.ReadWrite))
{
xdWaterMeters.Load(fsWaterMeters);
}
XmlNodeList xnlWaterMeters = xdWaterMeters.GetElementsByTagName("water-meter-id");
using (FileStream fsWaterMeters = new FileStream(strFileWaterMeters, FileMode.Truncate,
FileAccess.ReadWrite, FileShare.ReadWrite))
{
foreach (XmlNode xnWaterMeter in xnlWaterMeters)
{
if (xnWaterMeter.InnerText == id.ToString())
{
xnWaterMeter.ParentNode.InnerXml = "<water-meter-id>" + id + "</water-meter-id>" +
"<meter-number>" + collection["txtMeterNumber"] + "</meter-number>" +
"<make>" + collection["txtMake"] + "</make>" +
"<model>" + collection["txtModel"] + "</model>" +
"<meter-size>" + collection["txtMeterSize"] + "</meter-size>";
xdWaterMeters.Save(fsWaterMeters);
break;
}
}
}
}
return RedirectToAction("Index");
}
catch
{
return View();
}
}
// GET: WaterMeters/Delete/5
public ActionResult Delete(int id)
{
return View();
}
// POST: WaterMeters/Delete/5
[HttpPost]
public ActionResult Delete(int id, FormCollection collection)
{
try
{
// TODO: Add delete logic here
return RedirectToAction("Index");
}
catch
{
return View();
}
}
}
}@{
ViewBag.Title = "Edit Water Meter";
}
<h2 class="fw-bold common-font text-center">Edit/Update Water Meter</h2>
<hr />
@using (Html.BeginForm())
{
<div class="common-font encloser-small">
<div class="row mb-2">
@Html.Label("txtWaterMeterId", "Meter Meter Id:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtWaterMeterId", null, htmlAttributes: new { @class = "form-control", id = "wtrMdlId" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtMeterNumber", "Meter #:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtMeterNumber", ViewBag.MeterNumber as string,
htmlAttributes: new { @class = "form-control", id = "mtrNbr" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtMake", "Make:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtMake", ViewBag.Make as string,
htmlAttributes: new { @class = "form-control", id = "make" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtModel", "Model:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtModel", ViewBag.Model as string, htmlAttributes: new { @class = "form-control", id = "model" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtMeterSize", "Meter Size:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtMeterSize", ViewBag.MeterSize as string, htmlAttributes: new { @class = "form-control", id = "mtrSize" })
</div>
</div>
<hr />
<div class="row mb-2">
<label class="control-label col-md-5">
@Html.ActionLink("Water Meters", "Index", null, htmlAttributes: new { @class = "stellar" })
</label>
<div class="col-md-7">
<input type="submit" value="Update Water Meter" class="btn btn-stellar" />
</div>
</div>
</div>
}Meter #: 392-494-572 Make: Constance Technologies Meter Size: 5/8 Inches
Meter #: 938-725-869 Make: Stanford Trend Meter Size: 1 1/2 Inches
Deleting a Water Meter
.
Practical Learning: Removing a Water Meter
using System.IO;
using System.Xml;
using System.Web.Mvc;
w
namespace StellarWaterPoint1.Controllers
{
public class WaterMetersController : Controller
{
// GET: WaterMeters
public ActionResult Index()
{
// Create a reference to the XML's DOM object
XmlDocument xdWaterMeters = new XmlDocument();
// Indicate the file that holds a list of water meters
string strFileWaterMeters = Server.MapPath("/AppData/WaterMeters.xml");
// Check whether a file that holds a list of water meters exists
if (System.IO.File.Exists(strFileWaterMeters))
{
// If that file exists, open it
using (FileStream fsWaterMeters = new FileStream(strFileWaterMeters, FileMode.Open,
FileAccess.Read, FileShare.Read))
{
/* Get the list of water meters from the file and store
* the records in the previously created DOM object. */
xdWaterMeters.Load(fsWaterMeters);
}
// Check if there is at least one record in the file of water meters
if (xdWaterMeters.DocumentElement.ChildNodes.Count > 0)
{
/* If there is at least one record for the water meters,
* create an XmlNodeList list and transmit it to
* a ViewData collection that wille be used in the view page.*/
ViewData["WaterMeters"] = xdWaterMeters.DocumentElement.ChildNodes;
}
else
{
/* If there is no file or record for water meters,
* transmit a null list to the ViewData object.*/
ViewData["WaterMeters"] = null;
}
}
return View();
}
// GET: WaterMeters/Details/5
public ActionResult Details(int id)
{
// Create a reference to the XML's DOM object
XmlDocument xdWaterMeters = new XmlDocument();
// Indicate the file that holds a list of water meters
string strFileWaterMeters = Server.MapPath("/AppData/WaterMeters.xml");
// If there a file that holds a list of water meters
if (System.IO.File.Exists(strFileWaterMeters))
{
// If there is such a file, open it to get its records
using (FileStream fsWaterMeters = new FileStream(strFileWaterMeters, FileMode.Open,
FileAccess.Read, FileShare.Read))
{
// Get the records and load them in the created XML's DOM object
xdWaterMeters.Load(fsWaterMeters);
/* Using the water-meter-id element from the list of water meters,
* create a collection of nodes and store it in an XmlNodeList variable. */
XmlNodeList xnlWaterMeters = xdWaterMeters.GetElementsByTagName("water-meter-id");
// Check each record in the above XmlNodeList collection
foreach (XmlNode xnWaterMeter in xnlWaterMeters)
{
/* Find out if there is a record whose water-meter-id is the
* same as the number (id) that came from the form. */
if (xnWaterMeter.InnerText == id.ToString())
{
/* If you find such a record, get the value of each element
* and transmit it to a corresponding ViewData object. */
ViewData["txtWaterMeterId"] = xnWaterMeter.InnerText;
ViewData["txtMeterNumber"] = xnWaterMeter.NextSibling.InnerText;
ViewData["txtMake"] = xnWaterMeter.NextSibling.NextSibling.InnerText;
ViewData["txtModel"] = xnWaterMeter.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["txtMeterSize"] = xnWaterMeter.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
}
}
}
}
return View();
}
// GET: WaterMeters/Create
public ActionResult Create()
{
return View();
}
// POST: WaterMeters/Create
[HttpPost]
public ActionResult Create(FormCollection collection)
{
try
{
// TODO: Add insert logic here
// Create a reference to the XML's DOM
XmlDocument xdWaterMeters = new XmlDocument();
// Specify the file that would contain a list of water meters
string strFileWaterMeters = Server.MapPath("/AppData/WaterMeters.xml");
/* When the user clicks the Submit button on the Create webpage, check the
* content of the Meter Number text box.
* If the user typed a value in the Meter Number text box, ... */
if (!string.IsNullOrEmpty(collection["txtMeterNumber"]))
{
// If an XML file for water meters was created already, ...
if (System.IO.File.Exists(strFileWaterMeters))
{
// ... open it ...
using(FileStream fsWaterMeters = new FileStream(strFileWaterMeters, FileMode.OpenOrCreate,
FileAccess.ReadWrite, FileShare.ReadWrite))
{
// ... and put the records in the DOM
xdWaterMeters.Load(fsWaterMeters);
}
}
else
{
// If there is no XML file yet, create skeleton code for an XML document, ...
xdWaterMeters.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<water-meters></water-meters>");
}
}
// Get ready to create an XML element named water-meter
XmlElement xeWaterMeter = xdWaterMeters.CreateElement("water-meter");
// Create the markup of the XML water meter
string strWaterMeter = "<water-meter-id>" + collection["txtWaterMeterId"] + "</water-meter-id>" +
"<meter-number>" + collection["txtMeterNumber"] + "</meter-number>" +
"<make>" + collection["txtMake"] + "</make>" +
"<model>" + collection["txtModel"] + "</model>" +
"<meter-size>" + collection["txtMeterSize"] + "</meter-size>";
// Specify the markup of the new element
xeWaterMeter.InnerXml = strWaterMeter;
// Add the new node to the root
xdWaterMeters.DocumentElement.AppendChild(xeWaterMeter);
// Save the (new version of the) XML file
using(FileStream fsWaterMeters = new FileStream(strFileWaterMeters, FileMode.Create,
FileAccess.Write, FileShare.Write))
{
xdWaterMeters.Save(fsWaterMeters);
}
return RedirectToAction("Index");
}
catch
{
return View();
}
}
// GET: WaterMeters/Edit/5
public ActionResult Edit(int id)
{
// Create an XML DOM object
XmlDocument xdWaterMeters = new XmlDocument();
// Declare a string variable for the file that holds the records of water meters
string strFileWaterMeters = Server.MapPath("/AppData/WaterMeters.xml");
// Check the existence of the file that holds the records of water meters
if (System.IO.File.Exists(strFileWaterMeters))
{
// If that file exists, open it and store it in a FileStream object
using(FileStream fsWaterMeters = new FileStream(strFileWaterMeters, FileMode.Open,
FileAccess.Read, FileShare.Read))
{
// Put the water meters records in the previously created DOM object
xdWaterMeters.Load(fsWaterMeters);
/* Declare an XmlNodeList.
* Create a list of water meter records, using the water-meter-id element as reference. */
XmlNodeList xnlWaterMeters = xdWaterMeters.GetElementsByTagName("water-meter-id");
// Once a list of water meters has been created, check each of its records
foreach (XmlNode xnWaterMeter in xnlWaterMeters)
{
// Look for a record whose water-meter-id value is the same as the number that came from the Web form
if (xnWaterMeter.InnerText == id.ToString())
{
/* If you find such an element, get the value of each of its siblings
* and pass it to a text box that corresponds to the XML node.*/
ViewData["txtWaterMeterId"] = xnWaterMeter.InnerText;
ViewData["txtMeterNumber"] = xnWaterMeter.NextSibling.InnerText;
ViewData["txtMake"] = xnWaterMeter.NextSibling.NextSibling.InnerText;
ViewData["txtModel"] = xnWaterMeter.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["txtMeterSize"] = xnWaterMeter.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
}
}
}
}
return View();
}
// POST: WaterMeters/Edit/5
[HttpPost]
public ActionResult Edit(int id, FormCollection collection)
{
try
{
// TODO: Add update logic here
// Create an XML DOM object
XmlDocument xdWaterMeters = new XmlDocument();
// Get the file that holds the records of water meters and store its path in a string variable
string strFileWaterMeters = Server.MapPath("/AppData/WaterMeters.xml");
// Check the file that holds the records of water meters
if (System.IO.File.Exists(strFileWaterMeters))
{
// If that file exists, open it and store it in a FileStream object
using (FileStream fsWaterMeters = new FileStream(strFileWaterMeters, FileMode.Open,
FileAccess.ReadWrite, FileShare.ReadWrite))
{
// Store the records of water meters in the existing XML DOM object
xdWaterMeters.Load(fsWaterMeters);
}
// Create an XmlNodeList that will hold a list of water meters (from the file)
XmlNodeList xnlWaterMeters = xdWaterMeters.GetElementsByTagName("water-meter-id");
// Create a FileStream from the previously mentioned file of water meters
using (FileStream fsWaterMeters = new FileStream(strFileWaterMeters, FileMode.Truncate,
FileAccess.ReadWrite, FileShare.ReadWrite))
{
// Check each water meter record
foreach (XmlNode xnWaterMeter in xnlWaterMeters)
{
/* If you find a record whose water-meter-id has the same value
* as the value from the Water Meter Id from the Web form, ... */
if (xnWaterMeter.InnerText == id.ToString())
{
// Change each value of the elements of the current node
xnWaterMeter.ParentNode.InnerXml = "<water-meter-id>" + id + "</water-meter-id>" +
"<meter-number>" + collection["txtMeterNumber"] + "</meter-number>" +
"<make>" + collection["txtMake"] + "</make>" +
"<model>" + collection["txtModel"] + "</model>" +
"<meter-size>" + collection["txtMeterSize"] + "</meter-size>";
// Save the updated file
xdWaterMeters.Save(fsWaterMeters);
// Stop the operation (because it has been completed).
break;
}
}
}
}
// After this operation, go to the home page of the water meters
return RedirectToAction("Index");
}
catch
{
return View();
}
}
// GET: WaterMeters/Delete/5
public ActionResult Delete(int id)
{
// Create an XML DOM
XmlDocument xdWaterMeters = new XmlDocument();
// Get the path to the file that has the records of water meters
string strFileWaterMeters = Server.MapPath("/AppData/WaterMeters.xml");
// Check if that file exists
if (System.IO.File.Exists(strFileWaterMeters))
{
// If that file exists, open it and pass it to a FileStream object
using (FileStream fsWaterMeters = new FileStream(strFileWaterMeters, FileMode.Open,
FileAccess.Read, FileShare.Read))
{
// Get the records from the DOM object and store them into the DOM object
xdWaterMeters.Load(fsWaterMeters);
// Get the collection of water meter objects
XmlNodeList xnlWaterMeters = xdWaterMeters.GetElementsByTagName("water-meter-id");
// Scan the collection of water meters
foreach (XmlNode xnWaterMeter in xnlWaterMeters)
{
/* Try to match a record whose Id is the same as the Id
* of the record the user had clicked on the form*/
if (xnWaterMeter.InnerText == id.ToString())
{
/* If you find such a record, get the values of that record
* and pass them to the text boxes on the Web form.*/
ViewData["txtWaterMeterId"] = xnWaterMeter.InnerText;
ViewData["txtMeterNumber"] = xnWaterMeter.NextSibling.InnerText;
ViewData["txtMake"] = xnWaterMeter.NextSibling.NextSibling.InnerText;
ViewData["txtModel"] = xnWaterMeter.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["txtMeterSize"] = xnWaterMeter.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
}
}
}
}
return View();
}
// POST: WaterMeters/Delete/5
[HttpPost]
public ActionResult Delete(int id, FormCollection collection)
{
try
{
// TODO: Add delete logic here
XmlDocument xdWaterMeters = new XmlDocument();
string strFileWaterMeters = Server.MapPath("/AppData/WaterMeters.xml");
// Make sure an XML file for the water meters was previously created
if (System.IO.File.Exists(strFileWaterMeters))
{
// If such a file exists, open it and store it in a FileStream object
using (FileStream fsWaterMeters = new FileStream(strFileWaterMeters, FileMode.Open,
FileAccess.Read, FileShare.Read))
{
// Get the records and store them in an XML DOM object
xdWaterMeters.Load(fsWaterMeters);
}
// Get ready to change something on the file
using (FileStream fsWaterMeters = new FileStream(strFileWaterMeters, FileMode.Truncate,
FileAccess.Write, FileShare.Write))
{
// Get a collection of water meter nodes
XmlNodeList xnlWaterMeters = xdWaterMeters.GetElementsByTagName("water-meter-id");
// Check each node
foreach (XmlNode xnWaterMeter in xnlWaterMeters)
{
/* If you find a water meter record whose water-meter-id is
* the same as the id of the record the user clicked, ... */
if (xnWaterMeter.InnerText == id.ToString())
{
// ... ask its parent to delete that record
xdWaterMeters.DocumentElement.RemoveChild(xnWaterMeter.ParentNode);
// Now that the record has been deleted, save the XML file
xdWaterMeters.Save(fsWaterMeters);
// And stop checking the records
break;
}
}
}
}
// Return to the home page of the water meters
return RedirectToAction("Index");
}
catch
{
return View();
}
}
}
}@{
ViewBag.Title = "Delete Water Meter";
}
<h2 class="fw-bold common-font text-center">Delete Water Meter</h2>
<hr />
@using (Html.BeginForm())
{
<div class="encloser-small common-font">
<div class="row mb-2">
@Html.Label("txtWaterMeterId", "Meter Meter Id:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtWaterMeterId", ViewBag.WaterMeterId as string,
htmlAttributes: new { @class = "form-control", disabled = "disabled" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtMeterNumber", "Meter #:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtMeterNumber", ViewBag.MeterNumber as string,
htmlAttributes: new { @class = "form-control", disabled = "disabled" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtMake", "Make:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtMake", ViewBag.Make as string,
htmlAttributes: new { @class = "form-control", disabled = "disabled" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtModel", "Model:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtModel", ViewBag.Model as string,
htmlAttributes: new { @class = "form-control", disabled = "disabled" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtMeterSize", "Meter Size:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtMeterSize", ViewBag.MeterSize as string,
htmlAttributes: new { @class = "form-control", disabled = "disabled" })
</div>
</div>
</div>
<hr />
<div class="encloser-small">
<h3 class="common-font fw-bold text-center">Are you sure you want to remove this water meter from the system?</h3>
<div class="row mb-2">
<div class="col-md-4">
@Html.ActionLink("Water Meters", "Index", null, new { @class = "stellar" }) ::
</div>
<div class="col-md-8">
<input type="submit" value="Delete this Water Meter" class="btn btn-stellar" />
</div>
</div>
</div>
}Customers
Introduction
Customers are people and companies that consume a resource such as water. In this section, we will create object that can assist the employees in creating and managing customers accounts.
Practical Learning: Introducing Customers
Getting a List of Customers Records
.
Practical Learning: Getting a List of Customers Records
using System.IO;
using System.Xml;
using System.Web.Mvc;
namespace StellarWaterPoint12.Controllers
{
public class CustomersController : Controller
{
// GET: Customers
public ActionResult Index()
{
XmlDocument xdCustomers = new XmlDocument();
string strFileCustomers = Server.MapPath("/AppData/Customers.xml");
if (System.IO.File.Exists(strFileCustomers))
{
using (FileStream fsCustomers = new FileStream(strFileCustomers, FileMode.Open, FileAccess.Read, FileShare.Read))
{
xdCustomers.Load(fsCustomers);
}
ViewBag.Customers = xdCustomers.DocumentElement.ChildNodes.Count > 0 ? xdCustomers.DocumentElement.ChildNodes : null;
}
return View();
}
. . .
}
}@{
ViewBag.Title = "Customers Accounts";
}
<h2 class="fw-bold common-font text-center">Customers Accounts</h2>
<hr />
<table class="table table-striped common-font">
<tr>
<th class="fw-bold">Customer Id</th>
<th class="fw-bold">Account #</th>
<th class="fw-bold">Account Name</th>
<th class="fw-bold">Meter #</th>
<th class="fw-bold">Account Type</th>
<th class="fw-bold">Address</th>
<th class="fw-bold">City</th>
<th class="fw-bold">County</th>
<th class="fw-bold">State</th>
<th class="fw-bold">ZIP Code</th>
<th>@Html.ActionLink("Create Customer Account", "Create", null, htmlAttributes: new { @class = "stellar" })</th>
</tr>
@if (ViewBag.customers != null)
{
foreach (System.Xml.XmlNode client in ViewBag.Customers as System.Xml.XmlNodeList)
{
<tr>
<td class="text-center">@client.FirstChild.InnerText</td>
<td>@client.FirstChild.NextSibling.InnerText</td>
<td>@client.FirstChild.NextSibling.NextSibling.InnerText</td>
<td>@client.FirstChild.NextSibling.NextSibling.NextSibling.InnerText</td>
<td class="text-center">@client.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling.InnerText</td>
<td>@client.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText</td>
<td>@client.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText</td>
<td>@client.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText</td>
<td class="text-center">@client.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText</td>
<td>@client.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText</td>
<td>
@Html.ActionLink("Update", "Edit", new { id = @client.FirstChild.InnerText }) |
@Html.ActionLink("Review", "Details", new { id = @client.FirstChild.InnerText }) |
@Html.ActionLink("Remove", "Delete", new { id = @client.FirstChild.InnerText })
</td>
</tr>
}
}
</table>Creating a Customer Account
.
Practical Learning: Creating a Customer Account
using System.IO;
using System.Xml;
using System.Web.Mvc;
using System.Collections.Generic;
namespace StellarWaterPoint13.Controllers
{
public class CustomersController : Controller
{
. . .
// GET: Customers/Details/5
public ActionResult Details(int id)
{
return View();
}
// GET: Customers/Create
public ActionResult Create()
{
int customerId = 0;
XmlDocument xdCustomers = new XmlDocument();
string strFileCustomers = Server.MapPath("/AppData/Customers.xml");
if (System.IO.File.Exists(strFileCustomers))
{
using (FileStream fsCustomers = new FileStream(strFileCustomers, FileMode.Open,
FileAccess.Read, FileShare.Read))
{
xdCustomers.Load(fsCustomers);
XmlNodeList xnlCustomers = xdCustomers.GetElementsByTagName("customer-id");
foreach (XmlNode xnCustomer in xnlCustomers)
{
customerId = int.Parse(xnCustomer.InnerText);
}
}
}
ViewData["txtCustomerId"] = customerId + 1;
List<SelectListItem> acntsTypes = new List<SelectListItem>();
acntsTypes.Add(new SelectListItem() { Text = "OTH - Other", Value = "OTH" });
acntsTypes.Add(new SelectListItem() { Text = "BUS - General Business", Value = "BUS" });
acntsTypes.Add(new SelectListItem() { Text = "RES - Residential Household", Value = "RES" });
acntsTypes.Add(new SelectListItem() { Text = "SGO - Social Government/Non-Profit Organization", Value = "SGO" });
acntsTypes.Add(new SelectListItem() { Text = "UUO - Unidentified or Unclassified Type of Organization", Value = "UUO" });
acntsTypes.Add(new SelectListItem() { Text = "WAT - Water Intensive Business(Laudromat, Hair Salon, Restaurant, etc", Value = "WAT" });
ViewBag.cbxAccountsTypes = acntsTypes;
return View();
}
// POST: Customers/Create
[HttpPost]
public ActionResult Create(FormCollection collection)
{
try
{
// TODO: Add insert logic here
XmlDocument xdCustomers = new XmlDocument();
// Specify the file that would contain a list of customers
string strFileCustomers = Server.MapPath("/AppData/Customers.xml");
if (!string.IsNullOrEmpty(collection["txtAccountNumber"]))
{
// If an XML file for customers was created already, ...
if (System.IO.File.Exists(strFileCustomers))
{
// ... open it ...
using (FileStream fsCustomers = new FileStream(strFileCustomers, FileMode.OpenOrCreate,
FileAccess.ReadWrite, FileShare.ReadWrite))
{
// ... and put the records in the DOM
xdCustomers.Load(fsCustomers);
}
}
else
{
// If there is no XML file yet, create skeleton code for an XML document, ...
xdCustomers.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<customers></customers>");
}
}
// Get ready to create an XML element named water-meter
XmlElement xeCustomer = xdCustomers.CreateElement("customer");
// Create the markup of the XML water meter
string strCustomer = "<customer-id>" + collection["txtCustomerId"] + "</customer-id>" +
"<account-number>" + collection["txtAccountNumber"] + "</account-number>" +
"<account-name>" + collection["txtAccountName"] + "</account-name>" +
"<meter-number>" + collection["txtMeterNumber"] + "</meter-number>" +
"<account-type>" + collection["cbxAccountsTypes"] + "</account-type>" +
"<address>" + collection["txtAddress"] + "</address>" +
"<city>" + collection["txtCity"] + "</city>" +
"<county>" + collection["txtCounty"] + "</county>" +
"<state>" + collection["txtState"] + "</state>" +
"<zip-code>" + collection["txtZIPCode"] + "</zip-code>";
// Specify the markup of the new element
xeCustomer.InnerXml = strCustomer;
// Add the new node to the root
xdCustomers.DocumentElement.AppendChild(xeCustomer);
// Save the (new version of the) XML file
using (FileStream fsCustomers = new FileStream(strFileCustomers, FileMode.Create,
FileAccess.Write, FileShare.Write))
{
xdCustomers.Save(fsCustomers);
}
return RedirectToAction("Index");
}
catch
{
return View();
}
}
. . .
}
}@{
ViewBag.Title = "Create Customer";
}
<h2 class="common-font fw-bold text-center">Create Customer Account</h2>
<hr />
@using (Html.BeginForm())
{
<div class="common-font encloser-small">
<div class="row mb-2">
@Html.Label("txtCustomerId", "Customer Id:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtCustomerId", ViewBag.txtCustomerId as string, htmlAttributes: new { @class = "form-control" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtAccountNumber", "Account #:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtAccountNumber", null, htmlAttributes: new { @class = "form-control" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtAccountName", "Account Name:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtAccountName", null, htmlAttributes: new { @class = "form-control" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtMeterNumber", "Meter #:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtMeterNumber", null, htmlAttributes: new { @class = "form-control", id = "mtrNbr" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtMeterDetails", "Meter Details:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8"><input type="text" id="meterDetails" class="form-control" disabled /></div>
</div>
<div class="row mb-2">
@Html.Label("cbxAccountsTypes", "Account Type:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-sm-8">
@Html.DropDownList("cbxAccountsTypes", ViewBag.AccountsTypes as SelectList, htmlAttributes: new { @class = "form-control" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtAddress", "Address:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtAddress", null, htmlAttributes: new { @class = "form-control" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtCity", "City:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtCity", null, htmlAttributes: new { @class = "form-control" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtCounty", "County:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtCounty", null, htmlAttributes: new { @class = "form-control" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtState", "State:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtState", null, htmlAttributes: new { @class = "form-control" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtZIPCode", "ZIP-Code:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtZIPCode", null, htmlAttributes: new { @class = "form-control" })
</div>
</div>
<hr />
<div class="row mb-2">
<div class="col-md-5 col-form-label">
@Html.ActionLink("Customers", "Index", new { area = "" }, new { @class = "stellar" })
</div>
<div class="col-md-7">
<input type="submit" name="btnSaveCustomerAccount" value="Save Customer Account" class="btn btn-stellar" />
</div>
</div>
</div>
}
@Scripts.Render("~/bundles/jquery")
<script type="text/javascript">
$(document).ready(function () {
$("#mtrNbr").blur(function (event) {
var connection = {
url: "/AppData/WaterMeters.xml",
method: "GET",
dataType: "xml"
};
$.ajax(connection).
done(function (data) {
var waterMeters = $(data).find("water-meter");
waterMeters.each(function () {
if ($(this).find("meter-number").text() == $("#mtrNbr").val())
$("#meterDetails").val($(this).find("make").text() + " " + $(this).find("model").text() + " (" + $(this).find("meter-size").text() + ")");
});
});
}); // Lost Focus Event
}); // Document.Ready
</script>Customer Id: 1 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 |
| 8080-888-4444 | 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 |
Getting the Details of a Customer Account
.
Practical Learning: Getting a Details of a Customer Account
using System.IO;
using System.Xml;
using System.Web.Mvc;
using System.Collections.Generic;
namespace StellarWaterPoint13.Controllers
{
public class CustomersController : Controller
{
. . .
// GET: Customers/Details/5
public ActionResult Details(int id)
{
string strMeterNumber = string.Empty;
XmlDocument xdCustomers = new XmlDocument();
string strFileCustomers = Server.MapPath("/AppData/Customers.xml");
if (System.IO.File.Exists(strFileCustomers))
{
using (FileStream fsWaterMeters = new FileStream(strFileCustomers, FileMode.Open, FileAccess.Read, FileShare.Read))
{
xdCustomers.Load(fsWaterMeters);
XmlNodeList xnlCustomers = xdCustomers.GetElementsByTagName("customer-id");
foreach (XmlNode xnCustomer in xnlCustomers)
{
if (xnCustomer.InnerText == id.ToString())
{
ViewBag.CustomerId = xnCustomer.InnerText;
ViewBag.AccountNumber = xnCustomer.NextSibling.InnerText;
ViewBag.AccountName = xnCustomer.NextSibling.NextSibling.InnerText;
strMeterNumber = xnCustomer.NextSibling.NextSibling.NextSibling.InnerText;
string strActCode = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
string strAccountType = string.Empty;
if (strActCode == "BUS")
{
strAccountType = "BUS - General Business";
}
else if (strActCode == "RES")
{
strAccountType = "RES - Residential Household";
}
else if (strActCode == "SGO")
{
strAccountType = "SGO - Social/Government/Non - Profit Organization";
}
else if (strActCode == "UUO")
{
strAccountType = "UUO - Unidentified or Unclassified Type of Organization";
}
else if (strActCode == "WAT")
{
strAccountType = "WAT - Water Intensive Business(Laudromat, Hair Salon, Restaurant, etc";
}
else
{
strAccountType = "OTH - Other";
}
ViewBag.AccountType = strAccountType;
ViewBag.Address = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewBag.City = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewBag.County = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewBag.State = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewBag.ZIPCode = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
}
}
}
}
XmlDocument xdWaterMeters = new XmlDocument();
string strFileWaterMeters = Server.MapPath("/AppData/WaterMeters.xml");
if (System.IO.File.Exists(strFileWaterMeters))
{
using (FileStream fsWaterMeters = new FileStream(strFileWaterMeters, FileMode.Open,
FileAccess.Read, FileShare.Read))
{
xdWaterMeters.Load(fsWaterMeters);
XmlNodeList xnlWaterMeters = xdWaterMeters.GetElementsByTagName("meter-number");
foreach (XmlNode xnWaterMeter in xnlWaterMeters)
{
if (xnWaterMeter.InnerText == strMeterNumber)
{
ViewBag.MeterNumber = xnWaterMeter.PreviousSibling.InnerText + " - " + strMeterNumber;
ViewBag.MeterDetails = xnWaterMeter.NextSibling.InnerText + " " +
xnWaterMeter.NextSibling.NextSibling.InnerText +
" (" + xnWaterMeter.NextSibling.NextSibling.NextSibling.InnerText + ")";
break;
}
}
}
}
return View();
}
. . .
}
}
@{
ViewBag.Title = "Customer Details";
}
<h2 class="fw-bold common-font text-center">Customer Account Details</h2>
<hr />
<div class="encloser-small common-font">
<div class="row mb-2">
@Html.Label("txtCustomerId", "Customer Id:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtCustomerId", ViewBag.CustomerId as string,
htmlAttributes: new { @class = "form-control", disabled = "disabled" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtAccountNumber", "Account #:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtAccountNumber", ViewBag.AccountNumber as string,
htmlAttributes: new { @class = "form-control", disabled = "disabled" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtAccountName", "Account Name:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtAccountName", ViewBag.AccountName as string,
htmlAttributes: new { @class = "form-control", disabled = "disabled" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtMeterNumber", "Meter #:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtMeterNumber", ViewBag.MeterNumber as string,
htmlAttributes: new { @class = "form-control", disabled = "disabled" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtMeterDetails", "Meter Details:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtMeterDetails", ViewBag.MeterDetails as string,
htmlAttributes: new { @class = "form-control", disabled = "disabled" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtAccountType", "Account Type:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtAccountType", ViewBag.AccountType as string,
htmlAttributes: new { @class = "form-control", disabled = "disabled" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtAddress", "Address:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtAddress", ViewBag.Address as string,
htmlAttributes: new { @class = "form-control", disabled = "disabled" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtCity", "City:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtCity", ViewBag.City as string,
htmlAttributes: new { @class = "form-control", disabled = "disabled" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtCounty", "County:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtCounty", ViewBag.County as string,
htmlAttributes: new { @class = "form-control", disabled = "disabled" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtState", "State:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtState", ViewBag.State as string,
htmlAttributes: new { @class = "form-control", disabled = "disabled" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtZIPCode", "ZIP-Code", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtZIPCode", ViewBag.ZIPCode as string,
htmlAttributes: new { @class = "form-control", disabled = "disabled" })
</div>
</div>
</div>Updating a Customer Account
.
Practical Learning: Updating a Customer Account
using System.IO;
using System.Xml;
using System.Web.Mvc;
using System.Collections.Generic;
namespace StellarWaterPoint13.Controllers
{
public class CustomersController : Controller
{
. . .
// GET: Customers/Edit/5
public ActionResult Edit(int id)
{
XmlDocument xdCustomers = new XmlDocument();
string strFileCustomers = Server.MapPath("/AppData/Customers.xml");
string strMeterNumber = string.Empty;
if (System.IO.File.Exists(strFileCustomers))
{
using (FileStream fsWaterMeters = new FileStream(strFileCustomers, FileMode.Open,
FileAccess.Read, FileShare.Read))
{
xdCustomers.Load(fsWaterMeters);
XmlNodeList xnlCustomers = xdCustomers.GetElementsByTagName("customer-id");
foreach (XmlNode xnCustomer in xnlCustomers)
{
if (xnCustomer.InnerText == id.ToString())
{
ViewBag.CustomerId = xnCustomer.InnerText;
ViewBag.AccountNumber = xnCustomer.NextSibling.InnerText;
ViewBag.AccountName = xnCustomer.NextSibling.NextSibling.InnerText;
ViewBag.MeterNumber = xnCustomer.NextSibling.NextSibling.NextSibling.InnerText;
strMeterNumber = xnCustomer.NextSibling.NextSibling.NextSibling.InnerText;
string strActCode = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
string strAccountType = string.Empty;
List<SelectListItem> actTypes = new List<SelectListItem>();
if (strActCode == "OTH")
{
actTypes.Add(new SelectListItem() { Text = "OTH - Other", Value = "OTH", Selected = true });
}
else
{
actTypes.Add(new SelectListItem() { Text = "OTH - Other", Value = "OTH" });
}
if (strActCode == "BUS")
{
actTypes.Add(new SelectListItem() { Text = "BUS - General Business", Value = "BUS", Selected = true });
}
else
{
actTypes.Add(new SelectListItem() { Text = "BUS - General Business", Value = "BUS" });
}
if (strActCode == "RES")
{
actTypes.Add(new SelectListItem() { Text = "RES - Residential Household", Value = "RES", Selected = true });
}
else
{
actTypes.Add(new SelectListItem() { Text = "RES - Residential Household", Value = "RES" });
}
if (strActCode == "SGO")
{
actTypes.Add(new SelectListItem() { Text = "SGO - Social/Government/Non - Profit Organization", Value = "SGO", Selected = true });
}
else
{
actTypes.Add(new SelectListItem() { Text = "SGO - Social/Government/Non - Profit Organization", Value = "SGO" });
}
if (strActCode == "UUO")
{
actTypes.Add(new SelectListItem() { Text = "UUO - Unidentified or Unclassified Type of Organization", Value = "UUO", Selected = true });
}
else
{
actTypes.Add(new SelectListItem() { Text = "UUO - Unidentified or Unclassified Type of Organization", Value = "UUO" });
}
if (strActCode == "WAT")
{
actTypes.Add(new SelectListItem() { Text = "WAT - Water Intensive Business(Laudromat, Hair Salon, Restaurant, etc", Value = "WAT", Selected = true });
}
else
{
actTypes.Add(new SelectListItem() { Text = "WAT - Water Intensive Business(Laudromat, Hair Salon, Restaurant, etc", Value = "WAT" });
}
ViewBag.cbxAccountsTypes = actTypes;
ViewBag.Address = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewBag.City = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewBag.County = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewBag.State = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewBag.ZIPCode = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
}
}
}
}
return View();
}
// POST: Customers/Edit/5
[HttpPost]
public ActionResult Edit(int id, FormCollection collection)
{
try
{
// TODO: Add update logic here
XmlDocument xdCustomers = new XmlDocument();
string strFileCustomers = Server.MapPath("/AppData/Customers.xml");
XmlElement xeCustomer = xdCustomers.CreateElement("customer");
// Create the markup of a customer
string strCustomer = "<customer-id>" + id + "</customer-id>" +
"<account-number>" + collection["txtAccountNumber"] + "</account-number>" +
"<account-name>" + collection["txtAccountName"] + "</account-name>" +
"<meter-number>" + collection["txtMeterNumber"] + "</meter-number>" +
"<account-type>" + collection["cbxAccountsTypes"].Substring(0, 3) + "</account-type>" +
"<address>" + collection["txtAddress"] + "</address>" +
"<city>" + collection["txtCity"] + "</city>" +
"<county>" + collection["txtCounty"] + "</county>" +
"<state>" + collection["txtState"] + "</state>" +
"<zip-code>" + collection["txtZIPCode"] + "</zip-code>";
xeCustomer.InnerXml = strCustomer;
if (System.IO.File.Exists(strFileCustomers))
{
using (FileStream fsWaterMeters = new FileStream(strFileCustomers, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
{
xdCustomers.Load(fsWaterMeters);
}
using (FileStream fsCustomers = new FileStream(strFileCustomers, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
{
XmlNodeList xnlCustomers = xdCustomers.GetElementsByTagName("customer");
foreach (XmlNode xnCustomer in xnlCustomers)
{
if (xnCustomer.FirstChild.InnerText == id.ToString())
{
xnCustomer.ParentNode.ReplaceChild(xeCustomer, xnCustomer);
xdCustomers.Save(fsCustomers);
break;
}
}
}
}
return RedirectToAction("Index");
}
catch
{
return View();
}
}
. . .
}
}
@{
ViewBag.Title = "Edit Customer";
}
<h2 class="text-center common-font fw-bold">Edit/Update Customer Account</h2>
<hr />
@using (Html.BeginForm())
{
<div class="common-font encloser-small">
<div class="row mb-2">
@Html.Label("txtCustomerId", "Customer Id:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtCustomerId", ViewBag.CustomerId as string, htmlAttributes: new { @class = "form-control" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtAccountNumber", "Account #:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtAccountNumber", ViewBag.AccountNumber as string, htmlAttributes: new { @class = "form-control" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtAccountName", "Account Name:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtAccountName", ViewBag.AccountName as string, htmlAttributes: new { @class = "form-control" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtMeterNumber", "Meter #:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtMeterNumber", ViewBag.MeterNumber as string, htmlAttributes: new { @class = "form-control", id = "mtrNbr" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtMeterDetails", "Meter Details:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8"><input type="text" id="meterDetails" class="form-control" disabled /></div>
</div>
<div class="row mb-2">
@Html.Label("cbxAccountsTypes", "Account Type:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-sm-8">
@Html.DropDownList("cbxAccountsTypes", ViewBag.AccountsTypes as SelectList, htmlAttributes: new { @class = "form-control" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtAddress", "Address:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtAddress", ViewBag.Address as string, htmlAttributes: new { @class = "form-control" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtCity", "City:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtCity", ViewBag.City as string, htmlAttributes: new { @class = "form-control" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtCounty", "County:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtCounty", ViewBag.County as string, htmlAttributes: new { @class = "form-control" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtState", "State:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtState", ViewBag.State as string, htmlAttributes: new { @class = "form-control" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtZIPCode", "ZIP-Code:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtZIPCode", ViewBag.ZIPCode as string, htmlAttributes: new { @class = "form-control" })
</div>
</div>
<hr />
<div class="row mb-2">
<div class="col-md-5 col-form-label">
@Html.ActionLink("Customers", "Index", new { area = "" }, new { @class = "stellar" })
</div>
<div class="col-md-7">
<input type="submit" name="btnUpdateCustomerAccount" value="Update Customer Account" class="btn btn-stellar" />
</div>
</div>
</div>
}
@Scripts.Render("~/bundles/jquery")
<script type="text/javascript">
$(document).ready(function () {
var connection = {
url: "/AppData/WaterMeters.xml",
method: "GET",
dataType: "xml"
};
$.ajax(connection).
done(function (data) {
var waterMeters = $(data).find("water-meter");
waterMeters.each(function () {
if ($(this).find("meter-number").text() == $("#mtrNbr").val())
$("#meterDetails").val($(this).find("make").text() + " " + $(this).find("model").text() + " (" + $(this).find("meter-size").text() + ")");
});
});
$("#mtrNbr").blur(function (event) {
var connection = {
url: "/AppData/WaterMeters.xml",
method: "GET",
dataType: "xml"
};
$.ajax(connection).
done(function (data) {
var waterMeters = $(data).find("water-meter");
waterMeters.each(function () {
if ($(this).find("meter-number").text() == $("#mtrNbr").val())
$("#meterDetails").val($(this).find("make").text() + " " + $(this).find("model").text() + " (" + $(this).find("meter-size").text() + ")");
});
});
}); // Lost Focus Event
}); // Document.Ready
</script>| Customer Id | Account # | Account Name | Meter # | Account Type | Address | City | County | State | ZIP Code |
| 2 | 9279-570-8394 | Bernotte's Doughnuts | 799-528-461 | RES | 10252 Broward Avenue, Suite #D4 | Winterstown | York | MD | 21703-4422 |
Deleting a Customer Account
.
Practical Learning: Deleting a Customer Account
using System.IO;
using System.Xml;
using System.Web.Mvc;
using System.Collections.Generic;
namespace StellarWaterPoint13.Controllers
{
public class CustomersController : Controller
{
// GET: Customers
public ActionResult Index()
{
XmlDocument xdCustomers = new XmlDocument();
string strFileCustomers = Server.MapPath("/AppData/Customers.xml");
if (System.IO.File.Exists(strFileCustomers))
{
using (FileStream fsCustomers = new FileStream(strFileCustomers, FileMode.Open, FileAccess.Read, FileShare.Read))
{
xdCustomers.Load(fsCustomers);
}
ViewBag.Customers = xdCustomers.DocumentElement.ChildNodes.Count > 0 ? xdCustomers.DocumentElement.ChildNodes : null;
}
return View();
}
// GET: Customers/Details/5
public ActionResult Details(int id)
{
string strMeterNumber = string.Empty;
XmlDocument xdCustomers = new XmlDocument();
string strFileCustomers = Server.MapPath("/AppData/Customers.xml");
if (System.IO.File.Exists(strFileCustomers))
{
using (FileStream fsWaterMeters = new FileStream(strFileCustomers, FileMode.Open, FileAccess.Read, FileShare.Read))
{
xdCustomers.Load(fsWaterMeters);
XmlNodeList xnlCustomers = xdCustomers.GetElementsByTagName("customer-id");
foreach (XmlNode xnCustomer in xnlCustomers)
{
if (xnCustomer.InnerText == id.ToString())
{
ViewBag.CustomerId = xnCustomer.InnerText;
ViewBag.AccountNumber = xnCustomer.NextSibling.InnerText;
ViewBag.AccountName = xnCustomer.NextSibling.NextSibling.InnerText;
strMeterNumber = xnCustomer.NextSibling.NextSibling.NextSibling.InnerText;
string strActCode = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
string strAccountType = string.Empty;
if (strActCode == "BUS")
{
strAccountType = "BUS - General Business";
}
else if (strActCode == "RES")
{
strAccountType = "RES - Residential Household";
}
else if (strActCode == "SGO")
{
strAccountType = "SGO - Social/Government/Non - Profit Organization";
}
else if (strActCode == "UUO")
{
strAccountType = "UUO - Unidentified or Unclassified Type of Organization";
}
else if (strActCode == "WAT")
{
strAccountType = "WAT - Water Intensive Business(Laudromat, Hair Salon, Restaurant, etc";
}
else
{
strAccountType = "OTH - Other";
}
ViewBag.AccountType = strAccountType;
ViewBag.Address = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewBag.City = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewBag.County = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewBag.State = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewBag.ZIPCode = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
}
}
}
}
XmlDocument xdWaterMeters = new XmlDocument();
string strFileWaterMeters = Server.MapPath("/AppData/WaterMeters.xml");
if (System.IO.File.Exists(strFileWaterMeters))
{
using (FileStream fsWaterMeters = new FileStream(strFileWaterMeters, FileMode.Open,
FileAccess.Read, FileShare.Read))
{
xdWaterMeters.Load(fsWaterMeters);
XmlNodeList xnlWaterMeters = xdWaterMeters.GetElementsByTagName("meter-number");
foreach (XmlNode xnWaterMeter in xnlWaterMeters)
{
if (xnWaterMeter.InnerText == strMeterNumber)
{
ViewBag.MeterNumber = xnWaterMeter.PreviousSibling.InnerText + " - " + strMeterNumber;
ViewBag.MeterDetails = xnWaterMeter.NextSibling.InnerText + " " +
xnWaterMeter.NextSibling.NextSibling.InnerText +
" (" + xnWaterMeter.NextSibling.NextSibling.NextSibling.InnerText + ")";
break;
}
}
}
}
return View();
}
// GET: Customers/Create
public ActionResult Create()
{
int customerId = 0;
XmlDocument xdCustomers = new XmlDocument();
string strFileCustomers = Server.MapPath("/AppData/Customers.xml");
if (System.IO.File.Exists(strFileCustomers))
{
using (FileStream fsCustomers = new FileStream(strFileCustomers, FileMode.Open,
FileAccess.Read, FileShare.Read))
{
xdCustomers.Load(fsCustomers);
XmlNodeList xnlCustomers = xdCustomers.GetElementsByTagName("customer-id");
foreach (XmlNode xnCustomer in xnlCustomers)
{
customerId = int.Parse(xnCustomer.InnerText);
}
}
}
ViewData["txtCustomerId"] = customerId + 1;
List<SelectListItem> acntsTypes = new List<SelectListItem>();
acntsTypes.Add(new SelectListItem() { Text = "OTH - Other", Value = "OTH" });
acntsTypes.Add(new SelectListItem() { Text = "BUS - General Business", Value = "BUS" });
acntsTypes.Add(new SelectListItem() { Text = "RES - Residential Household", Value = "RES" });
acntsTypes.Add(new SelectListItem() { Text = "SGO - Social Government/Non-Profit Organization", Value = "SGO" });
acntsTypes.Add(new SelectListItem() { Text = "UUO - Unidentified or Unclassified Type of Organization", Value = "UUO" });
acntsTypes.Add(new SelectListItem() { Text = "WAT - Water Intensive Business(Laudromat, Hair Salon, Restaurant, etc", Value = "WAT" });
ViewBag.cbxAccountsTypes = acntsTypes;
return View();
}
// POST: Customers/Create
[HttpPost]
public ActionResult Create(FormCollection collection)
{
try
{
// TODO: Add insert logic here
XmlDocument xdCustomers = new XmlDocument();
// Specify the file that would contain a list of customers
string strFileCustomers = Server.MapPath("/AppData/Customers.xml");
if (!string.IsNullOrEmpty(collection["txtAccountNumber"]))
{
// If an XML file for customers was created already, ...
if (System.IO.File.Exists(strFileCustomers))
{
// ... open it ...
using (FileStream fsCustomers = new FileStream(strFileCustomers, FileMode.OpenOrCreate,
FileAccess.ReadWrite, FileShare.ReadWrite))
{
// ... and put the records in the DOM
xdCustomers.Load(fsCustomers);
}
}
else
{
// If there is no XML file yet, create skeleton code for an XML document, ...
xdCustomers.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<customers></customers>");
}
}
// Get ready to create an XML element named water-meter
XmlElement xeCustomer = xdCustomers.CreateElement("customer");
// Create the markup of the XML water meter
string strCustomer = "<customer-id>" + collection["txtCustomerId"] + "</customer-id>" +
"<account-number>" + collection["txtAccountNumber"] + "</account-number>" +
"<account-name>" + collection["txtAccountName"] + "</account-name>" +
"<meter-number>" + collection["txtMeterNumber"] + "</meter-number>" +
"<account-type>" + collection["cbxAccountsTypes"] + "</account-type>" +
"<address>" + collection["txtAddress"] + "</address>" +
"<city>" + collection["txtCity"] + "</city>" +
"<county>" + collection["txtCounty"] + "</county>" +
"<state>" + collection["txtState"] + "</state>" +
"<zip-code>" + collection["txtZIPCode"] + "</zip-code>";
// Specify the markup of the new element
xeCustomer.InnerXml = strCustomer;
// Add the new node to the root
xdCustomers.DocumentElement.AppendChild(xeCustomer);
// Save the (new version of the) XML file
using (FileStream fsCustomers = new FileStream(strFileCustomers, FileMode.Create,
FileAccess.Write, FileShare.Write))
{
xdCustomers.Save(fsCustomers);
}
return RedirectToAction("Index");
}
catch
{
return View();
}
}
// GET: Customers/Edit/5
public ActionResult Edit(int id)
{
XmlDocument xdCustomers = new XmlDocument();
string strFileCustomers = Server.MapPath("/AppData/Customers.xml");
string strMeterNumber = string.Empty;
if (System.IO.File.Exists(strFileCustomers))
{
using (FileStream fsWaterMeters = new FileStream(strFileCustomers, FileMode.Open,
FileAccess.Read, FileShare.Read))
{
xdCustomers.Load(fsWaterMeters);
XmlNodeList xnlCustomers = xdCustomers.GetElementsByTagName("customer-id");
foreach (XmlNode xnCustomer in xnlCustomers)
{
if (xnCustomer.InnerText == id.ToString())
{
ViewBag.CustomerId = xnCustomer.InnerText;
ViewBag.AccountNumber = xnCustomer.NextSibling.InnerText;
ViewBag.AccountName = xnCustomer.NextSibling.NextSibling.InnerText;
ViewBag.MeterNumber = xnCustomer.NextSibling.NextSibling.NextSibling.InnerText;
strMeterNumber = xnCustomer.NextSibling.NextSibling.NextSibling.InnerText;
string strActCode = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
string strAccountType = string.Empty;
List<SelectListItem> actTypes = new List<SelectListItem>();
if (strActCode == "OTH")
{
actTypes.Add(new SelectListItem() { Text = "OTH - Other", Value = "OTH", Selected = true });
}
else
{
actTypes.Add(new SelectListItem() { Text = "OTH - Other", Value = "OTH" });
}
if (strActCode == "BUS")
{
actTypes.Add(new SelectListItem() { Text = "BUS - General Business", Value = "BUS", Selected = true });
}
else
{
actTypes.Add(new SelectListItem() { Text = "BUS - General Business", Value = "BUS" });
}
if (strActCode == "RES")
{
actTypes.Add(new SelectListItem() { Text = "RES - Residential Household", Value = "RES", Selected = true });
}
else
{
actTypes.Add(new SelectListItem() { Text = "RES - Residential Household", Value = "RES" });
}
if (strActCode == "SGO")
{
actTypes.Add(new SelectListItem() { Text = "SGO - Social/Government/Non - Profit Organization", Value = "SGO", Selected = true });
}
else
{
actTypes.Add(new SelectListItem() { Text = "SGO - Social/Government/Non - Profit Organization", Value = "SGO" });
}
if (strActCode == "UUO")
{
actTypes.Add(new SelectListItem() { Text = "UUO - Unidentified or Unclassified Type of Organization", Value = "UUO", Selected = true });
}
else
{
actTypes.Add(new SelectListItem() { Text = "UUO - Unidentified or Unclassified Type of Organization", Value = "UUO" });
}
if (strActCode == "WAT")
{
actTypes.Add(new SelectListItem() { Text = "WAT - Water Intensive Business(Laudromat, Hair Salon, Restaurant, etc", Value = "WAT", Selected = true });
}
else
{
actTypes.Add(new SelectListItem() { Text = "WAT - Water Intensive Business(Laudromat, Hair Salon, Restaurant, etc", Value = "WAT" });
}
ViewBag.cbxAccountsTypes = actTypes;
ViewBag.Address = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewBag.City = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewBag.County = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewBag.State = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewBag.ZIPCode = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
}
}
}
}
return View();
}
// POST: Customers/Edit/5
[HttpPost]
public ActionResult Edit(int id, FormCollection collection)
{
try
{
// TODO: Add update logic here
XmlDocument xdCustomers = new XmlDocument();
string strFileCustomers = Server.MapPath("/AppData/Customers.xml");
XmlElement xeCustomer = xdCustomers.CreateElement("customer");
// Create the markup of a customer
string strCustomer = "<customer-id>" + id + "</customer-id>" +
"<account-number>" + collection["txtAccountNumber"] + "</account-number>" +
"<account-name>" + collection["txtAccountName"] + "</account-name>" +
"<meter-number>" + collection["txtMeterNumber"] + "</meter-number>" +
"<account-type>" + collection["cbxAccountsTypes"].Substring(0, 3) + "</account-type>" +
"<address>" + collection["txtAddress"] + "</address>" +
"<city>" + collection["txtCity"] + "</city>" +
"<county>" + collection["txtCounty"] + "</county>" +
"<state>" + collection["txtState"] + "</state>" +
"<zip-code>" + collection["txtZIPCode"] + "</zip-code>";
xeCustomer.InnerXml = strCustomer;
if (System.IO.File.Exists(strFileCustomers))
{
using (FileStream fsWaterMeters = new FileStream(strFileCustomers, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
{
xdCustomers.Load(fsWaterMeters);
}
using (FileStream fsCustomers = new FileStream(strFileCustomers, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
{
XmlNodeList xnlCustomers = xdCustomers.GetElementsByTagName("customer");
foreach (XmlNode xnCustomer in xnlCustomers)
{
if (xnCustomer.FirstChild.InnerText == id.ToString())
{
xnCustomer.ParentNode.ReplaceChild(xeCustomer, xnCustomer);
xdCustomers.Save(fsCustomers);
break;
}
}
}
}
return RedirectToAction("Index");
}
catch
{
return View();
}
}
// GET: Customers/Delete/5
public ActionResult Delete(int id)
{
string strMeterNumber = string.Empty;
XmlDocument xdCustomers = new XmlDocument();
string strFileCustomers = Server.MapPath("/AppData/Customers.xml");
if (System.IO.File.Exists(strFileCustomers))
{
using (FileStream fsCustomers = new FileStream(strFileCustomers, FileMode.Open, FileAccess.Read, FileShare.Read))
{
xdCustomers.Load(fsCustomers);
XmlNodeList xnlCustomers = xdCustomers.GetElementsByTagName("customer-id");
foreach (XmlNode xnCustomer in xnlCustomers)
{
if (xnCustomer.InnerText == id.ToString())
{
ViewBag.CustomerId = xnCustomer.InnerText;
ViewBag.AccountNumber = xnCustomer.NextSibling.InnerText;
ViewBag.AccountName = xnCustomer.NextSibling.NextSibling.InnerText;
ViewBag.MeterNumber = xnCustomer.NextSibling.NextSibling.NextSibling.InnerText;
strMeterNumber = xnCustomer.NextSibling.NextSibling.NextSibling.InnerText;
string strActCode = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
string strAccountType = string.Empty;
if (strActCode == "BUS")
{
strAccountType = "BUS - General Business";
}
else if (strActCode == "RES")
{
strAccountType = "RES - Residential Household";
}
else if (strActCode == "SGO")
{
strAccountType = "SGO - Social/Government/Non - Profit Organization";
}
else if (strActCode == "UUO")
{
strAccountType = "UUO - Unidentified or Unclassified Type of Organization";
}
else if (strActCode == "WAT")
{
strAccountType = "WAT - Water Intensive Business(Laudromat, Hair Salon, Restaurant, etc";
}
else
{
strAccountType = "OTH - Other";
}
ViewBag.AccountType = strAccountType;
ViewBag.Address = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewBag.City = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewBag.County = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewBag.State = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewBag.ZIPCode = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
}
}
}
}
XmlDocument xdWaterMeters = new XmlDocument();
string strFileWaterMeters = Server.MapPath("/AppData/WaterMeters.xml");
if (System.IO.File.Exists(strFileWaterMeters))
{
using (FileStream fsWaterMeters = new FileStream(strFileWaterMeters, FileMode.Open,
FileAccess.Read, FileShare.Read))
{
xdWaterMeters.Load(fsWaterMeters);
XmlNodeList xnlWaterMeters = xdWaterMeters.GetElementsByTagName("meter-number");
foreach (XmlNode xnWaterMeter in xnlWaterMeters)
{
if (xnWaterMeter.InnerText == strMeterNumber)
{
ViewBag.MeterDetails = xnWaterMeter.NextSibling.InnerText + " " +
xnWaterMeter.NextSibling.NextSibling.InnerText +
" (" + xnWaterMeter.NextSibling.NextSibling.NextSibling.InnerText + ")";
break;
}
}
}
}
return View();
}
// POST: Customers/Delete/5
[HttpPost]
public ActionResult Delete(int id, FormCollection collection)
{
try
{
// TODO: Add delete logic here
XmlDocument xdCustomers = new XmlDocument();
string strFileCustomers = Server.MapPath("/AppData/Customers.xml");
if (System.IO.File.Exists(strFileCustomers))
{
using (FileStream fsCustomers = new FileStream(strFileCustomers, FileMode.Open,
FileAccess.Read, FileShare.Read))
{
xdCustomers.Load(fsCustomers);
}
using (FileStream fsCustomers = new FileStream(strFileCustomers, FileMode.Truncate,
FileAccess.Write, FileShare.Write))
{
XmlNodeList xnlCustomers = xdCustomers.GetElementsByTagName("customer-id");
foreach (XmlNode xnCustomer in xnlCustomers)
{
if (xnCustomer.InnerText == id.ToString())
{
xdCustomers.DocumentElement.RemoveChild(xnCustomer.ParentNode);
xdCustomers.Save(fsCustomers);
break;
}
}
}
}
return RedirectToAction("Index");
}
catch
{
return View();
}
}
}
}@{
ViewBag.Title = "Delete Customer";
}
<h2 class="fw-bold common-font text-center">Delete Customer Account</h2>
<hr />
@using (Html.BeginForm())
{
<div class="encloser-small common-font">
<div class="row mb-2">
@Html.Label("txtCustomerId", "Customer Id:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtCustomerId", ViewBag.CustomerId as string,
htmlAttributes: new { @class = "form-control", disabled = "disabled" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtAccountNumber", "Account #:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtAccountNumber", ViewBag.AccountNumber as string,
htmlAttributes: new { @class = "form-control", disabled = "disabled" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtAccountName", "Account Name:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtAccountName", ViewBag.AccountName as string,
htmlAttributes: new { @class = "form-control", disabled = "disabled" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtMeterNumber", "Meter #:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtMeterNumber", ViewBag.MeterNumber as string,
htmlAttributes: new { @class = "form-control", disabled = "disabled" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtMeterDetails", "Meter Details:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtMeterDetails", ViewBag.MeterDetails as string,
htmlAttributes: new { @class = "form-control", disabled = "disabled" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtAccountType", "Account Type:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtAccountType", ViewBag.AccountType as string,
htmlAttributes: new { @class = "form-control", disabled = "disabled" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtAddress", "Address:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtAddress", ViewBag.Address as string,
htmlAttributes: new { @class = "form-control", disabled = "disabled" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtCity", "City:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtCity", ViewBag.City as string,
htmlAttributes: new { @class = "form-control", disabled = "disabled" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtCounty", "County:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtCounty", ViewBag.County as string,
htmlAttributes: new { @class = "form-control", disabled = "disabled" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtState", "State:", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtState", ViewBag.State as string,
htmlAttributes: new { @class = "form-control", disabled = "disabled" })
</div>
</div>
<div class="row mb-2">
@Html.Label("txtZIPCode", "ZIP-Code", htmlAttributes: new { @class = "col-form-label col-md-4 fw-bold" })
<div class="col-md-8">
@Html.TextBox("txtZIPCode", ViewBag.ZIPCode as string,
htmlAttributes: new { @class = "form-control", disabled = "disabled" })
</div>
</div>
</div>
<hr />
<div class="encloser-small">
<h3 class="common-font fw-bold text-center">Are you sure you want to close this customer's account?</h3>
<div class="row mb-2">
<div class="col-md-4">
@Html.ActionLink("Customers", "Index", null, new { @class = "stellar" })
</div>
<div class="col-md-8">
<input type="submit" name="btnDeleteCustomerAccount" value="Delete Customer's Account" class="btn btn-stellar" />
</div>
</div>
</div>
}Water Bills
Introduction
A water bill is a document that provides various pieces of information about a costumer consuming water and the amount to pay for it. In thissection, we will create objects that can assist the company in creating water bills.
Practical Learning: Introducing Water Bills
Creating a Water Bill
.
Practical Learning: Creating a Water Bill
// GET: WaterBills/Create
public ActionResult Create()
{
int water_bill_id = 0;
XmlDocument xdWaterBills = new XmlDocument();
string strFileWaterBills = Server.MapPath("/AppData/WaterBills.xml");
if (System.IO.File.Exists(strFileWaterBills))
{
using (FileStream fsWaterBills = new FileStream(strFileWaterBills, FileMode.Open, FileAccess.Read, FileShare.Read))
{
xdWaterBills.Load(fsWaterBills);
XmlNodeList xnlWaterBills = xdWaterBills.GetElementsByTagName("water-bill-id");
foreach (XmlNode xnWaterBill in xnlWaterBills)
{
water_bill_id = int.Parse(xnWaterBill.InnerText);
}
}
}
ViewData["WaterBillID"] = (water_bill_id + 1);
Random rndNumber = new Random();
ViewData["InvoiceNumber"] = rndNumber.Next(100001, 999999).ToString();
return View();
}
// POST: WaterBills/Create
[HttpPost]
public ActionResult Create(FormCollection collection)
{
try
{
// TODO: Add insert logic here
int bill_id = -1;
bool customerIsValid = false;
string meterNumber = string.Empty;
XmlDocument xdCustomers = new XmlDocument();
XmlDocument xdWaterBills = new XmlDocument();
string strFileCustomers = Server.MapPath("/AppData/Customers.xml");
string strFileWaterBills = Server.MapPath("/AppData/WaterBills.xml");
// Make sure the user provided an account number for the customer, ...
if (!string.IsNullOrEmpty(collection["AccountNumber"]))
{
// If the user provided an account number, find out if an XML file for customers was already created.
if (System.IO.File.Exists(strFileCustomers))
{
// If a file for customers exists, open it
using (FileStream fsCustomers = new FileStream(strFileCustomers, FileMode.Open,
FileAccess.Read,
FileShare.Read))
{
// Store the list of customers in an XML document
xdCustomers.Load(fsCustomers);
// Create a list of customers nodes that use the account number provided by the user
XmlNodeList xnlCustomers = xdCustomers.GetElementsByTagName("account-number");
// Visit each node of the list of elements
foreach (XmlNode xnCustomer in xnlCustomers)
{
// If you find a customer that is the same as the account number from the form, ...
if (xnCustomer.InnerText == collection["AccountNumber"])
{
// ... make a note
customerIsValid = true;
// and get the meter number used by that customer
meterNumber = xnCustomer.NextSibling.InnerText;
}
}
}
}
}
if (customerIsValid == true)
{
// It appears that the user provided a valid customer account number.
// If an XML file for water bills was previously created, ...
if (System.IO.File.Exists(strFileWaterBills))
{
// ... open it ...
using (FileStream fsWaterBills = new FileStream(strFileWaterBills, FileMode.OpenOrCreate,
FileAccess.ReadWrite,
FileShare.ReadWrite))
{
// ... and put the records in the DOM
xdWaterBills.Load(fsWaterBills);
XmlNodeList xnlWaterBills = xdWaterBills.GetElementsByTagName("water-bill-id");
foreach (XmlNode xnWaterBill in xnlWaterBills)
{
bill_id = int.Parse(xnWaterBill.InnerText);
}
}
}
else
{
// If there is no XML file yet for the customers, create skeleton code for an XML document
xdWaterBills.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<water-bills></water-bills>");
bill_id = 0;
}
// Get ready to create an XML element named water-bill
XmlElement xeWaterBill = xdWaterBills.CreateElement("invoice");
bill_id++;
// Create the markup of the XML water bill
xeWaterBill.InnerXml = "<water-bill-id>" + bill_id + "</water-bill-id>" +
"<invoice-number>" + collection["InvoiceNumber"] + "</invoice-number>" +
"<account-number>" + collection["AccountNumber"] + "</account-number>" +
"<meter-reading-start-date>" + collection["MeterReadingStartDate"] + "</meter-reading-start-date>" +
"<meter-reading-end-date>" + collection["MeterReadingEndDate"] + "</meter-reading-end-date>" +
"<billing-days>" + collection["BillingDays"] + "</billing-days>" +
"<counter-reading-start>" + collection["CounterReadingStart"] + "</counter-reading-start>" +
"<counter-reading-end>" + collection["CounterReadingEnd"] + "</counter-reading-end>" +
"<total-hcf>" + collection["TotalHCF"] + "</total-hcf>" +
"<total-gallons>" + collection["TotalGallons"] + "</total-gallons>" +
"<first-15-hcf>" + collection["First15HCF"] + "</first-15-hcf>" +
"<next-10-hcf>" + collection["Next10HCF"] + "</next-10-hcf>" +
"<remaining-hcf>" + collection["RemainingHCF"] + "</remaining-hcf>" +
"<sewer-charges>" + collection["SewerCharges"] + "</sewer-charges>" +
"<storm-charges>" + collection["StormCharges"] + "</storm-charges>" +
"<water-usage-charges>" + collection["WaterUsageCharges"] + "</water-usage-charges>" +
"<total-charges>" + collection["TotalCharges"] + "</total-charges>" +
"<local-taxes>" + collection["LocalTaxes"] + "</local-taxes>" +
"<state-taxes>" + collection["StateTaxes"] + "</state-taxes>" +
"<payment-due-date>" + collection["PaymentDueDate"] + "</payment-due-date>" +
"<amount-due>" + collection["AmountDue"] + "</amount-due>" +
"<late-payment-due-date>" + collection["LatePaymentDueDate"] + "</late-payment-due-date>" +
"<late-amount-due>" + collection["LateAmountDue"] + "</late-amount-due>";
// Add the new node to the root
xdWaterBills.DocumentElement.AppendChild(xeWaterBill);
// Save the (new version of the) XML file
using (FileStream fsWaterBills = new FileStream(strFileWaterBills, FileMode.Create, FileAccess.Write, FileShare.Write))
{
xdWaterBills.Save(fsWaterBills);
}
// We also want to update the counter value on the water meter with the new Counter Reading End value
XmlDocument xdWaterMeters = new XmlDocument();
string strFileWaterMeters = Server.MapPath("/AppData/WaterMeters.xml");
if (System.IO.File.Exists(strFileWaterMeters))
{
using (FileStream fsWaterMeters = new FileStream(strFileWaterMeters, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
{
xdWaterMeters.Load(fsWaterMeters);
}
XmlNodeList xnlWaterMeters = xdWaterMeters.GetElementsByTagName("meter-id");
using (FileStream fsWaterMeters = new FileStream(strFileWaterMeters, FileMode.Truncate, FileAccess.ReadWrite, FileShare.ReadWrite))
{
foreach (XmlNode xnWaterMeter in xnlWaterMeters)
{
if (xnWaterMeter.NextSibling.InnerText == meterNumber)
{
xnWaterMeter.ParentNode.InnerXml = "<meter-id>" + xnWaterMeter.InnerText + "</meter-id>" +
"<meter-number>" + meterNumber + "</meter-number>" +
"<make>" + xnWaterMeter.NextSibling.NextSibling.InnerText + "</make>" +
"<model>" + xnWaterMeter.NextSibling.NextSibling.NextSibling.InnerText + "</model>" +
"<meter-size>" + xnWaterMeter.NextSibling.NextSibling.NextSibling.NextSibling.InnerText + "</meter-size>" +
"<date-last-update>" + xnWaterMeter.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText + "</date-last-update>" +
"<counter-value>" + collection["CounterReadingEnd"] + "</counter-value>";
xdWaterMeters.Save(fsWaterMeters);
break;
}
}
}
}
}
return RedirectToAction("Index");
}
catch
{
return View();
}
}@{
ViewBag.Title = "Prepare Customer Water Bill";
}
<div class="push-down">
<h2>Prepare Customer Water Bill</h2>
</div>
<hr />
@using (Html.BeginForm())
{
<div class="form-horizontal">
<div class="form-group">
<label for="billNbr" class="control-label col-md-4 caption">Water Bill ID:</label>
<div class="col-md-8">
@Html.TextBox("WaterBillID", null,
htmlAttributes: new { @class = "form-control", id = "billNbr", disabled = "disabled" })
</div>
</div>
<div class="form-group">
<label for="invoiceNbr" class="control-label col-md-4 caption">Invoice #:</label>
<div class="col-md-8">
@Html.TextBox("InvoiceNumber", null,
htmlAttributes: new { @class = "form-control", id = "invoiceNbr" })
</div>
</div>
<div class="form-group">
<label for="acntNbr" class="control-label col-md-4 caption">Customer Account #:</label>
<div class="col-md-8">
@Html.TextBox("AccountNumber", null,
htmlAttributes: new { @class = "form-control", id = "acntNbr" })
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4 caption">Customer Name:</label>
<div class="col-md-8">
@Html.TextBox("CustomerName", null,
new { @class = "form-control", id = "custName", disabled = "disabled" })
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4 caption">Customer Address:</label>
<div class="col-md-8">
@Html.TextBox("CustomerAddress", null,
new { @class = "form-control", id = "adrs", disabled = "disabled" })
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4"> </label>
<div class="col-md-125">
@Html.TextBox("CustomerCity", null,
new { @class = "form-control", id = "city", disabled = "disabled" })
</div>
<div class="col-md-125">
@Html.TextBox("CustomerCounty", null,
new { @class = "form-control", id = "county", disabled = "disabled" })
</div>
<div class="col-md-125">
@Html.TextBox("CustomerState", null,
new { @class = "form-control", id = "state", disabled = "disabled" })
</div>
<div class="col-md-125">
@Html.TextBox("CustomerZIPCode", null,
new { @class = "form-control", id = "zip", disabled = "disabled" })
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4 caption">Meter Details:</label>
<div class="col-md-125">
@Html.TextBox("MeterNumber", null,
new { @class = "form-control", id = "mtrNbr", disabled = "disabled" })
</div>
<div class="col-md-6">
@Html.TextBox("MeterDetails", null,
htmlAttributes: new { @class = "form-control", id = "meterDetails", disabled = "disabled" })
</div>
</div>
<hr />
<div class="form-group">
<label for="mrsd" class="control-label col-md-4 caption">Meter Reading Start Date:</label>
<div class="col-md-2">
@Html.TextBox("MeterReadingStartDate", null,
htmlAttributes: new { @class = "form-control", id = "mrsd" })
</div>
<label for="mred" class="control-label col-md-125 caption">Meter Reading End Date:</label>
<div class="col-md-125">
@Html.TextBox("MeterReadingEndDate", null,
htmlAttributes: new { @class = "form-control", type = "date", id = "mred" })
</div>
<label for="days" class="control-label col-md-2 caption">Billing Days:</label>
<div class="col-md-1">
@Html.TextBox("BillingDays", null, htmlAttributes: new { @class = "form-control", id = "days" })
</div>
</div>
<div class="form-group">
<label for="crs" class="control-label col-md-4 caption">Counter Reading Start:</label>
<div class="col-md-2">
@Html.TextBox("CounterReadingStart", null, htmlAttributes: new { @class = "form-control", id = "crs" })
</div>
<label for="cre" class="control-label col-md-125 caption">Current Meter Reading:</label>
<div class="col-md-125">
@Html.TextBox("CounterReadingEnd", null, htmlAttributes: new { @class = "form-control", id = "cre" })
</div>
<label for="thcf" class="control-label col-md-2 caption">Total HCF:</label>
<div class="col-md-1">
@Html.TextBox("TotalHCF", null, htmlAttributes: new { @class = "form-control", id = "thcf" })
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4"> </label>
<div class="col-md-2"> </div>
<label class="control-label col-md-125"> </label>
<div class="col-md-125"> </div>
<label for="gallons" class="control-label col-md-2 caption">Total Gallons:</label>
<div class="col-md-1">
@Html.TextBox("TotalGallons", null, htmlAttributes: new { @class = "form-control", id = "gallons" })
</div>
</div>
<div class="form-group">
<label for="f15HCF" class="control-label col-md-4 caption">1st 15 HCF at $3.6121:</label>
<div class="col-md-2">
@Html.TextBox("First15HCF", null,
htmlAttributes: new { @class = "form-control", id = "f15HCF" })
</div>
<label for="next10HCF" class="control-label col-md-125 caption">Next 10 HCF at $3.9180:</label>
<div class="col-md-125">
@Html.TextBox("Next10HCF", null,
htmlAttributes: new { @class = "form-control", id = "next10HCF" })
</div>
<label for="remHCF" class="control-label col-md-2 caption">Remaining HCF at $4.2763:</label>
<div class="col-md-1">
@Html.TextBox("RemainingHCF", null, htmlAttributes: new { @class = "form-control", id = "remHCF" })
</div>
</div>
<div class="form-group">
<label for="sewerCharges" class="control-label col-md-4 caption">Sewer Charges:</label>
<div class="col-md-2">
@Html.TextBox("SewerCharges", null,
htmlAttributes: new { @class = "form-control", id = "sewerCharges" })
</div>
<label for="stormCharges" class="control-label col-md-125 caption">Storm Charges:</label>
<div class="col-md-125">
@Html.TextBox("StormCharges", null,
htmlAttributes: new { @class = "form-control", id = "stormCharges" })
</div>
<label for="wuc" class="control-label col-md-2 caption">Water Usage Charges:</label>
<div class="col-md-1">
@Html.TextBox("WaterUsageCharges", null, htmlAttributes: new { @class = "form-control", id = "wuc" })
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4"> </label>
<div class="col-md-2"> </div>
<label class="control-label col-md-125"> </label>
<div class="col-md-125"> </div>
<label for="totalCharges" class="control-label col-md-2 caption">Total Charges:</label>
<div class="col-md-1">
@Html.TextBox("TotalCharges", null, htmlAttributes: new { @class = "form-control", id = "totalCharges" })
</div>
</div>
<hr />
<div class="form-group">
<label class="control-label col-md-4"> </label>
<div class="col-md-125"> </div>
<label for="localTaxes" class="control-label col-md-125 caption">Local Taxes:</label>
<div class="col-md-125">
@Html.TextBox("LocalTaxes", null,
htmlAttributes: new { @class = "form-control", id = "localTaxes" })
</div>
<label for="stateTaxes" class="control-label col-md-125 caption">State Taxes:</label>
<div class="col-md-125">
@Html.TextBox("StateTaxes", null, htmlAttributes: new { @class = "form-control", id = "stateTaxes" })
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4"> </label>
<div class="col-md-125"> </div>
<label for="pdd" class="control-label col-md-125 caption">Payment Due Date:</label>
<div class="col-md-125">
@Html.TextBox("PaymentDueDate", null,
htmlAttributes: new { @class = "form-control", type = "date", id = "pdd" })
</div>
<label for="amtDue" class="control-label col-md-125 caption">Amount Due:</label>
<div class="col-md-125">
@Html.TextBox("AmountDue", null,
htmlAttributes: new { @class = "form-control", id = "amtDue" })
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4 caption"> </label>
<div class="col-md-125"> </div>
<label for="lpdd" class="control-label col-md-125 caption">Late Payment Due Date:</label>
<div class="col-md-125">
@Html.TextBox("LatePaymentDueDate", null,
htmlAttributes: new { @class = "form-control", id = "lpdd" })
</div>
<label for="lateAmtDue" class="control-label col-md-125 caption">Late Amount Due:</label>
<div class="col-md-125">
@Html.TextBox("LateAmountDue", null, htmlAttributes: new { @class = "form-control", id = "lateAmtDue" })
</div>
</div>
<div class="form-group text-center">
<label class="control-label col-md-5">
@Html.ActionLink("Water Bills", "Index", null, htmlAttributes: new { @class = "water-nav" })
</label>
<div class="col-md-7">
<input type="submit" value="Save Water Bill" class="btn btn-primary" />
</div>
</div>
</div>
}
@Scripts.Render("~/bundles/jquery")
<script type="text/javascript">
$(document).ready(function () {
$("#acntNbr").blur(function (event) {
var connection = {
method: "GET",
dataType: "xml",
url: "/WaterDistribution/Customers.xml"
};
$.ajax(connection).
done(function (data) {
var clients = $(data).find("customer");
clients.each(function () {
if ($(this).find("account-number").text() === $("#acntNbr").val()) {
$("#mtrNbr").val($(this).find("meter-number").text());
$("#custName").val($(this).find("first-name").text() + " " + $(this).find("last-name").text());
$("#adrs").val($(this).find("address").text());
$("#city").val($(this).find("city").text());
$("#county").val($(this).find("county").text());
$("#state").val($(this).find("state").text());
$("#zip").val($(this).find("zip-code").text());
}
});
});
connection = {
method: "GET",
dataType: "xml",
url: "/WaterDistribution/WaterMeters.xml"
};
$.ajax(connection).
done(function (data) {
var waterMeters = $(data).find("water-meter");
waterMeters.each(function () {
if ($(this).find("meter-number").text() === $("#mtrNbr").val()) {
$("#meterDetails").val($(this).find("make").text() + " " + $(this).find("model").text() + " (" + $(this).find("meter-size").text() + ")");
$("#mrsd").val($(this).find("date-last-update").text());
$("#crs").val($(this).find("counter-value").text());
}
});
});
connection = {
method: "GET",
dataType: "xml",
url: "/WaterDistribution/WaterBills.xml"
};
$.ajax(connection).
done(function (data) {
var invoices = $(data).find("invoice");
invoices.each(function () {
if ($(this).find("account-number").text() === $("#acntNbr").val()) {
$("#mrsd").val($(this).find("meter-reading-end-date").text());
$("#crs").val($(this).find("counter-reading-end").text());
}
});
});
}); // Account # Lost Focus
$("#mred").change(function (event) {
var meterReadingStartDate = Date.parse($("#mrsd").val());
var meterReadingEndDate = Date.parse($("#mred").val());
var days = (meterReadingEndDate - meterReadingStartDate) / 86400000;
$("#days").val(days.toFixed());
}); // Meter Reading End Date Lost Focus
$("#cre").focusout(function (event) {
var counterReadingStart = parseInt($("#crs").val());
var counterReadingEnd = parseInt($("#cre").val());
var totalHCF = counterReadingEnd - counterReadingStart;
var gallons = totalHCF * 748; // 748.05
var first15HCF = totalHCF * 3.612;
var next10HCF = 0, remainingHCF = 0;
if (totalHCF <= 15) {
first15HCF = totalHCF * 3.612;
next10HCF = 0;
remainingHCF = 0;
}
else if (totalHCF <= 25) {
first15HCF = 15 * 3.612;
next10HCF = (totalHCF - 15) * 3.918;
remainingHCF = 0;
}
else {
first15HCF = 15 * 3.612;
next10HCF = 10 * 3.918;
remainingHCF = (totalHCF - 25) * 2.2763;
}
var waterUsageCharges = first15HCF + next10HCF + remainingHCF;
var sewerCharges = waterUsageCharges * 0.252;
var stormCharges = waterUsageCharges * 0.0025;
var totalCharges = waterUsageCharges + sewerCharges + stormCharges;
var localTaxes = totalCharges * 0.0152;
var stateTaxes = totalCharges * 0.005;
var amountDue = totalCharges + localTaxes + stateTaxes;
$("#thcf").val(totalHCF.toFixed());
$("#gallons").val(gallons.toFixed());
$("#amtDue").val(amountDue.toFixed(2));
$("#f15HCF").val(first15HCF.toFixed(2));
$("#next10HCF").val(next10HCF.toFixed(2));
$("#remHCF").val(remainingHCF.toFixed(2));
$("#wuc").val(waterUsageCharges.toFixed(2));
$("#stateTaxes").val(stateTaxes.toFixed(2));
$("#localTaxes").val(localTaxes.toFixed(2));
$("#sewerCharges").val(sewerCharges.toFixed(2));
$("#stormCharges").val(stormCharges.toFixed(2));
$("#totalCharges").val(totalCharges.toFixed(2));
$("#lateAmtDue").val((amountDue + 8.95).toFixed(2));
}); // Counter Reading End Lost Focus
}); // Document.Ready
</script>Reviewing a Water Bill
.
Practical Learning: Reviewing a Water Bill
using System.Xml;
using System.Web.Mvc;
using System.Collections.Generic;
namespace StellarWaterPoint1.Controllers
{
public class WaterBillsController : Controller
{
// GET: WaterBills
public ActionResult Index()
{
XmlDocument xdWaterBills = new XmlDocument();
string strFileWaterBills = Server.MapPath("/AppData/WaterBills.xml");
if (System.IO.File.Exists(strFileWaterBills))
{
using (FileStream fsWaterBills = new FileStream(strFileWaterBills, FileMode.Open, FileAccess.Read, FileShare.Read))
{
xdWaterBills.Load(fsWaterBills);
}
if (xdWaterBills.DocumentElement.ChildNodes.Count > 0)
{
ViewData["Invoices"] = xdWaterBills.DocumentElement.ChildNodes;
}
else
{
ViewData["Invoices"] = null;
}
}
return View();
}
// GET: WaterBills/Details/5
public ActionResult Details(int id)
{
XmlDocument xdWaterBills = new XmlDocument();
string strFileWaterBills = Server.MapPath("/AppData/WaterBills.xml");
if (System.IO.File.Exists(strFileWaterBills))
{
using (FileStream fsWaterBills = new FileStream(strFileWaterBills, FileMode.Open, FileAccess.Read, FileShare.Read))
{
xdWaterBills.Load(fsWaterBills);
XmlNodeList xnlWaterBills = xdWaterBills.GetElementsByTagName("water-bill-id");
foreach (XmlNode xnWaterBill in xnlWaterBills)
{
if (xnWaterBill.InnerText == id.ToString())
{
ViewData["WaterBillID"] = xnWaterBill.InnerText;
ViewData["InvoiceNumber"] = xnWaterBill.NextSibling.InnerText;
ViewData["AccountNumber"] = xnWaterBill.NextSibling.NextSibling.InnerText;
ViewData["MeterReadingStartDate"] = xnWaterBill.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["MeterReadingEndDate"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["BillingDays"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["CounterReadingStart"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["CounterReadingEnd"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["TotalHCF"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["TotalGallons"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["First15HCF"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["Next10HCF"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["RemainingHCF"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["SewerCharges"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["StormCharges"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["WaterUsageCharges"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["TotalCharges"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["LocalTaxes"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["StateTaxes"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["PaymentDueDate"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["AmountDue"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["LatePaymentDueDate"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["LateAmountDue"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
}
}
}
}
return View();
}
// GET: WaterBills/Edit/5
public ActionResult Edit(int id)
{
XmlDocument xdWaterBills = new XmlDocument();
string strAccountNumber = string.Empty, strMeterNumber = string.Empty;
string strFileWaterBills = Server.MapPath("/AppData/WaterBills.xml");
if (System.IO.File.Exists(strFileWaterBills))
{
using (FileStream fsWaterBills = new FileStream(strFileWaterBills, FileMode.Open, FileAccess.Read, FileShare.Read))
{
xdWaterBills.Load(fsWaterBills);
XmlNodeList xnlWaterBills = xdWaterBills.GetElementsByTagName("water-bill-id");
foreach (XmlNode xnWaterBill in xnlWaterBills)
{
if (xnWaterBill.InnerText == id.ToString())
{
ViewData["WaterBillID"] = xnWaterBill.InnerText;
ViewData["InvoiceNumber"] = xnWaterBill.NextSibling.InnerText;
ViewData["AccountNumber"] = xnWaterBill.NextSibling.NextSibling.InnerText;
ViewData["MeterReadingStartDate"] = xnWaterBill.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["MeterReadingEndDate"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["BillingDays"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["CounterReadingStart"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["CounterReadingEnd"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["TotalHCF"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["TotalGallons"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["First15HCF"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["Next10HCF"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["RemainingHCF"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["SewerCharges"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["StormCharges"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["WaterUsageCharges"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["TotalCharges"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["LocalTaxes"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["StateTaxes"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["PaymentDueDate"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["AmountDue"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["LatePaymentDueDate"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["LateAmountDue"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
strAccountNumber = xnWaterBill.NextSibling.NextSibling.InnerText;
}
}
}
XmlDocument xdCustomers = new XmlDocument();
string strFileCustomers = Server.MapPath("/AppData/Customers.xml");
if (System.IO.File.Exists(strFileCustomers))
{
using (FileStream fsWaterMeters = new FileStream(strFileCustomers, FileMode.Open, FileAccess.Read, FileShare.Read))
{
xdCustomers.Load(fsWaterMeters);
XmlNodeList xnlCustomers = xdCustomers.GetElementsByTagName("account-number");
foreach (XmlNode xnCustomer in xnlCustomers)
{
if (xnCustomer.InnerText == strAccountNumber)
{
ViewData["AccountNumber"] = xnCustomer.InnerText;
ViewData["MeterNumber"] = xnCustomer.NextSibling.InnerText;
ViewData["CustomerName"] = xnCustomer.NextSibling.NextSibling.InnerText + " " +
xnCustomer.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["CustomerAddress"] = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["CustomerCity"] = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["CustomerCounty"] = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["CustomerState"] = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["CustomerZIPCode"] = xnCustomer.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
strMeterNumber = xnCustomer.NextSibling.InnerText;
}
}
}
}
XmlDocument xdWaterMeters = new XmlDocument();
string strFileWaterMeters = Server.MapPath("/AppData/WaterMeters.xml");
if (System.IO.File.Exists(strFileWaterMeters))
{
using (FileStream fsWaterMeters = new FileStream(strFileWaterMeters, FileMode.Open, FileAccess.Read, FileShare.Read))
{
xdWaterMeters.Load(fsWaterMeters);
XmlNodeList xnlWaterMeters = xdWaterMeters.GetElementsByTagName("meter-number");
foreach (XmlNode xnWaterMeter in xnlWaterMeters)
{
if (xnWaterMeter.InnerText == strMeterNumber)
{
ViewData["MeterDetails"] = xnWaterMeter.InnerText + " " +
xnWaterMeter.NextSibling.InnerText + " (" +
xnWaterMeter.NextSibling.NextSibling.NextSibling.InnerText + ")";
}
}
}
}
}
return View();
}
// POST: WaterBills/Edit/5
[HttpPost]
public ActionResult Edit(int id, FormCollection collection)
{
try
{
// TODO: Add update logic here
XmlDocument xdWaterBills = new XmlDocument();
string strFileWaterBills = Server.MapPath("/AppData/WaterBills.xml");
if (System.IO.File.Exists(strFileWaterBills))
{
using (FileStream fsWaterMeters = new FileStream(strFileWaterBills, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
{
xdWaterBills.Load(fsWaterMeters);
}
XmlNodeList xnlWaterBills = xdWaterBills.GetElementsByTagName("water-bill-id");
using (FileStream fsWaterBills = new FileStream(strFileWaterBills, FileMode.Truncate, FileAccess.ReadWrite, FileShare.ReadWrite))
{
foreach (XmlNode xnWaterBill in xnlWaterBills)
{
if (xnWaterBill.InnerText == id.ToString())
{
xnWaterBill.ParentNode.InnerXml = "<water-bill-id>" + id + "</water-bill-id>" +
"<invoice-number>" + collection["InvoiceNumber"] + "</invoice-number>" +
"<account-number>" + collection["AccountNumber"] + "</account-number>" +
"<meter-reading-start-date>" + collection["MeterReadingStartDate"] + "</meter-reading-start-date>" +
"<meter-reading-end-date>" + collection["MeterReadingEndDate"] + "</meter-reading-end-date>" +
"<billing-days>" + collection["BillingDays"] + "</billing-days>" +
"<counter-reading-start>" + collection["CounterReadingStart"] + "</counter-reading-start>" +
"<counter-reading-end>" + collection["CounterReadingEnd"] + "</counter-reading-end>" +
"<total-hcf>" + collection["TotalHCF"] + "</total-hcf>" +
"<total-gallons>" + collection["TotalGallons"] + "</total-gallons>" +
"<first-15-hcf>" + collection["First15HCF"] + "</first-15-hcf>" +
"<next-10-hcf>" + collection["Next10HCF"] + "</next-10-hcf>" +
"<remaining-hcf>" + collection["RemainingHCF"] + "</remaining-hcf>" +
"<sewer-charges>" + collection["SewerCharges"] + "</sewer-charges>" +
"<storm-charges>" + collection["StormCharges"] + "</storm-charges>" +
"<water-usage-charges>" + collection["WaterUsageCharges"] + "</water-usage-charges>" +
"<total-charges>" + collection["TotalCharges"] + "</total-charges>" +
"<local-taxes>" + collection["LocalTaxes"] + "</local-taxes>" +
"<state-taxes>" + collection["StateTaxes"] + "</state-taxes>" +
"<payment-due-date>" + collection["PaymentDueDate"] + "</payment-due-date>" +
"<amount-due>" + collection["AmountDue"] + "</amount-due>" +
"<late-payment-due-date>" + collection["LatePaymentDueDate"] + "</late-payment-due-date>" +
"<late-amount-due>" + collection["LateAmountDue"] + "</late-amount-due>";
xdWaterBills.Save(fsWaterBills);
break;
}
}
}
}
return RedirectToAction("Index");
}
catch
{
return View();
}
}
// GET: WaterBills/Delete/5
public ActionResult Delete(int id)
{
XmlDocument xdWaterBills = new XmlDocument();
string strAccountNumber = string.Empty, strMeterNumber = string.Empty;
string strFileWaterBills = Server.MapPath("/AppData/WaterBills.xml");
if (System.IO.File.Exists(strFileWaterBills))
{
using (FileStream fsWaterBills = new FileStream(strFileWaterBills, FileMode.Open, FileAccess.Read, FileShare.Read))
{
xdWaterBills.Load(fsWaterBills);
XmlNodeList xnlWaterBills = xdWaterBills.GetElementsByTagName("water-bill-id");
foreach (XmlNode xnWaterBill in xnlWaterBills)
{
if (xnWaterBill.InnerText == id.ToString())
{
ViewData["WaterBillID"] = xnWaterBill.InnerText;
ViewData["InvoiceNumber"] = xnWaterBill.NextSibling.InnerText;
ViewData["AccountNumber"] = xnWaterBill.NextSibling.NextSibling.InnerText;
ViewData["MeterReadingStartDate"] = xnWaterBill.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["MeterReadingEndDate"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["BillingDays"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["CounterReadingStart"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["CounterReadingEnd"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["TotalHCF"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["TotalGallons"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["First15HCF"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["Next10HCF"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["RemainingHCF"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["SewerCharges"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["StormCharges"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["WaterUsageCharges"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["TotalCharges"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["LocalTaxes"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["StateTaxes"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["PaymentDueDate"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["AmountDue"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["LatePaymentDueDate"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["LateAmountDue"] = xnWaterBill.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
strAccountNumber = xnWaterBill.NextSibling.NextSibling.InnerText;
}
}
}
}
return View();
}
// POST: WaterBills/Delete/5
[HttpPost]
public ActionResult Delete(int id, FormCollection collection)
{
try
{
// TODO: Add delete logic here
XmlDocument xdWaterBills = new XmlDocument();
string strFileWaterBills = Server.MapPath("/AppData/WaterBills.xml");
if (System.IO.File.Exists(strFileWaterBills))
{
using (FileStream fsWaterBills = new FileStream(strFileWaterBills, FileMode.Open, FileAccess.Read, FileShare.Read))
{
xdWaterBills.Load(fsWaterBills);
}
using (FileStream fsWaterBills = new FileStream(strFileWaterBills, FileMode.Truncate, FileAccess.Write, FileShare.Write))
{
XmlNodeList xnlWaterBills = xdWaterBills.GetElementsByTagName("invoice");
foreach (XmlNode xnWaterBill in xnlWaterBills)
{
if (xnWaterBill.FirstChild.InnerText == id.ToString())
{
xnWaterBill.ParentNode.RemoveChild(xnWaterBill);
xdWaterBills.Save(fsWaterBills);
break;
}
}
}
}
return RedirectToAction("Index");
}
catch
{
return View();
}
}
}
}
@{
ViewBag.Title = "Customers Water Bills";
}
<div class="push-down">
<h2 class="common-font bold text-center">Customers Water Bills</h2>
</div>
<hr />
<table class="table table-striped common-font">
<tr>
<th class="fw-bold text-center" colspan="2">Identification</th>
<th class="fw-bold text-center" colspan="4">Meter Reading</th>
<th class="fw-bold text-center" colspan="2">Counter Reading</th>
<th class="fw-bold text-center" colspan="5">HCF Summary</th>
<th class="fw-bold text-center" colspan="4">Charges</th>
<th class="fw-bold text-center" colspan="2">Taxes</th>
<th class="fw-bold text-center" colspan="4">Payment</th>
<th> </th>
</tr>
<tr>
<th class="fw-bold">Bill ID</th>
<th class="fw-bold">Invoice #</th>
<th class="fw-bold">Account #</th>
<th class="fw-bold">Start Date</th>
<th class="fw-bold">End Date</th>
<th class="fw-bold">Days</th>
<th class="fw-bold">Start</th>
<th class="fw-bold">End</th>
<th class="fw-bold">Total</th>
<th class="fw-bold">Gallons</th>
<th class="fw-bold">First 15</th>
<th class="fw-bold">Next 10</th>
<th class="fw-bold">Remaining</th>
<th class="fw-bold">Sewer</th>
<th class="fw-bold">Storm</th>
<th class="fw-bold">Water Usage</th>
<th class="fw-bold">Total</th>
<th class="fw-bold">Local</th>
<th class="fw-bold">State</th>
<th class="fw-bold">Due Date</th>
<th class="fw-bold">Amount</th>
<th class="fw-bold">Late Pmt</th>
<th class="fw-bold">Late Amt</th>
<th> </th>
</tr>
@if (ViewBag.Invoices != null)
{
foreach (System.Xml.XmlNode bill in ViewData["Invoices"] as System.Xml.XmlNodeList)
{
<tr>
<td class="text-center">@bill.FirstChild.InnerText</td>
<td>@bill.FirstChild.NextSibling.InnerText</td>
<td>@bill.FirstChild.NextSibling.NextSibling.InnerText</td>
<td>@bill.FirstChild.NextSibling.NextSibling.NextSibling.InnerText</td>
<td>@bill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling.InnerText</td>
<td>@bill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText</td>
<td>@bill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText</td>
<td>@bill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText</td>
<td>@bill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText</td>
<td>@bill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText</td>
<td>@bill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText</td>
<td>@bill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText</td>
<td>@bill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText</td>
<td>@bill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText</td>
<td>@bill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText</td>
<td>@bill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText</td>
<td>@bill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText</td>
<td>@bill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText</td>
<td>@bill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText</td>
<td>@bill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText</td>
<td>@bill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText</td>
<td>@bill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText</td>
<td>@bill.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText</td>
<td>
@Html.ActionLink("Update", "Edit", new { id = @bill.FirstChild.InnerText }) <span style="color: aquamarine">::</span>
@Html.ActionLink("Review", "Details", new { id = @bill.FirstChild.InnerText }) <span style="color: aquamarine">::</span>
@Html.ActionLink("Remove", "Delete", new { id = @bill.FirstChild.InnerText })
</td>
</tr>
}
}
</table>
<p class="text-center">@Html.ActionLink("New Water Bill", "Create", null, htmlAttributes: new { @class = "water-nav" })</p>@{
ViewBag.Title = "Water Bill Details";
}
<div class="push-down">
<h2>Water Bill Details</h2>
</div>
<hr />
<div class="containment">
<dl class="dl-horizontal common-font caption">
<dt class="fw-bold">Water Bill ID:</dt>
<dd>@ViewData["WaterBillID"]</dd>
<dt class="fw-bold">Invoice #:</dt>
<dd>@ViewData["InvoiceNumber"]</dd>
<dt class="fw-bold">Account #:</dt>
<dd>@ViewData["AccountNumber"]</dd>
<dt class="fw-bold">Meter Reading Start Date:</dt>
<dd>@ViewData["MeterReadingStartDate"]</dd>
<dt class="fw-bold">Meter Reading End Date:</dt>
<dd>@ViewData["MeterReadingEndDate"]</dd>
<dt class="fw-bold">Billing Days:</dt>
<dd>@ViewData["BillingDays"]</dd>
<dt class="fw-bold">Counter Reading Start:</dt>
<dd>@ViewData["CounterReadingStart"]</dd>
<dt class="fw-bold">Counter Reading End:</dt>
<dd>@ViewData["CounterReadingEnd"]</dd>
<dt class="fw-bold">Total HCF:</dt>
<dd>@ViewData["TotalHCF"]</dd>
<dt class="fw-bold">Total Gallons:</dt>
<dd>@ViewData["TotalGallons"]</dd>
<dt class="fw-bold">First 15 HCF:</dt>
<dd>@ViewData["First15HCF"]</dd>
<dt class="fw-bold">Next 10 HCF:</dt>
<dd>@ViewData["Next10HCF"]</dd>
<dt class="fw-bold">Remaining HCF:</dt>
<dd>@ViewData["RemainingHCF"]</dd>
<dt class="fw-bold">Sewer Charges:</dt>
<dd>@ViewData["SewerCharges"]</dd>
<dt class="fw-bold">Storm Charges:</dt>
<dd>@ViewData["StormCharges"]</dd>
<dt class="fw-bold">Water Usage Charges:</dt>
<dd>@ViewData["WaterUsageCharges"]</dd>
<dt class="fw-bold">Total Charges:</dt>
<dd>@ViewData["TotalCharges"]</dd>
<dt class="fw-bold">Local Taxes:</dt>
<dd>@ViewData["LocalTaxes"]</dd>
<dt class="fw-bold">State Taxes:</dt>
<dd>@ViewData["StateTaxes"]</dd>
<dt class="fw-bold">Payment Due Date:</dt>
<dd>@ViewData["PaymentDueDate"]</dd>
<dt class="fw-bold">Amount Due:</dt>
<dd>@ViewData["AmountDue"]</dd>
<dt class="fw-bold">Late Payment Due Date:</dt>
<dd>@ViewData["LatePaymentDueDate"]</dd>
<dt class="fw-bold">Late Amount Due:</dt>
<dd>@ViewData["LateAmountDue"]</dd>
</dl>
</div>
<p class="text-center">
@Html.ActionLink("Edit/Update Customer Water Bill", "Edit",
new { id = ViewData["WaterBillID"] }, htmlAttributes: new { @class = "water -nav" }) ::
@Html.ActionLink("Customers Water Bills", "Index",
null, new { @class = "water-nav" })
</p>@{
ViewBag.Title = "Edit/Update Water Bill";
}
<div class="push-down">
<h2>Edit/Update Water Bill</h2>
</div>
<hr />
@using (Html.BeginForm())
{
<div class="form-horizontal">
<div class="form-group">
<label for="billNbr" class="control-label col-md-4 caption">Water Bill ID:</label>
<div class="col-md-8">
@Html.TextBox("WaterBillID", null,
htmlAttributes: new { @class = "form-control", id = "billNbr", disabled = "disabled" })
</div>
</div>
<div class="form-group">
<label for="invoiceNbr" class="control-label col-md-4 caption">Invoice #:</label>
<div class="col-md-8">
@Html.TextBox("InvoiceNumber", null,
htmlAttributes: new { @class = "form-control", id = "invoiceNbr" })
</div>
</div>
<div class="form-group">
<label for="acntNbr" class="control-label col-md-4 caption">Customer Account #:</label>
<div class="col-md-8">
@Html.TextBox("AccountNumber", null,
htmlAttributes: new { @class = "form-control", id = "acntNbr" })
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4 caption">Customer Name:</label>
<div class="col-md-8">
@Html.TextBox("CustomerName", null,
new { @class = "form-control", id = "custName", disabled = "disabled" })
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4 caption">Customer Address:</label>
<div class="col-md-8">
@Html.TextBox("CustomerAddress", null,
new { @class = "form-control", id = "adrs", disabled = "disabled" })
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4"> </label>
<div class="col-md-125">
@Html.TextBox("CustomerCity", null,
new { @class = "form-control", id = "city", disabled = "disabled" })
</div>
<div class="col-md-125">
@Html.TextBox("CustomerCounty", null,
new { @class = "form-control", id = "county", disabled = "disabled" })
</div>
<div class="col-md-125">
@Html.TextBox("CustomerState", null,
new { @class = "form-control", id = "state", disabled = "disabled" })
</div>
<div class="col-md-125">
@Html.TextBox("CustomerZIPCode", null,
new { @class = "form-control", id = "zip", disabled = "disabled" })
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4 caption">Meter Details:</label>
<div class="col-md-125">
@Html.TextBox("MeterNumber", null,
new { @class = "form-control", id = "mtrNbr", disabled = "disabled" })
</div>
<div class="col-md-6">
@Html.TextBox("MeterDetails", null,
new { @class = "form-control", id = "meterDetails", disabled = "disabled" })
</div>
</div>
<hr />
<div class="form-group">
<label for="mrsd" class="control-label col-md-4 caption">Meter Reading Start Date:</label>
<div class="col-md-2">
@Html.TextBox("MeterReadingStartDate", null,
htmlAttributes: new { @class = "form-control", id = "mrsd" })
</div>
<label for="mred" class="control-label col-md-125 caption">Meter Reading End Date:</label>
<div class="col-md-125">
@Html.TextBox("MeterReadingEndDate", null,
htmlAttributes: new { @class = "form-control", type = "date", id = "mred" })
</div>
<label for="days" class="control-label col-md-2 caption">Billing Days:</label>
<div class="col-md-1">
@Html.TextBox("BillingDays", null, htmlAttributes: new { @class = "form-control", id = "days" })
</div>
</div>
<div class="form-group">
<label for="crs" class="control-label col-md-4 caption">Counter Reading Start:</label>
<div class="col-md-2">
@Html.TextBox("CounterReadingStart", null, htmlAttributes: new { @class = "form-control", id = "crs" })
</div>
<label for="cre" class="control-label col-md-125 caption">Current Meter Reading:</label>
<div class="col-md-125">
@Html.TextBox("CounterReadingEnd", null, htmlAttributes: new { @class = "form-control", id = "cre" })
</div>
<label for="thcf" class="control-label col-md-2 caption">Total HCF:</label>
<div class="col-md-1">
@Html.TextBox("TotalHCF", null, htmlAttributes: new { @class = "form-control", id = "thcf" })
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4"> </label>
<div class="col-md-2"> </div>
<label class="control-label col-md-125"> </label>
<div class="col-md-125"> </div>
<label for="gallons" class="control-label col-md-2 caption">Total Gallons:</label>
<div class="col-md-1">
@Html.TextBox("TotalGallons", null, htmlAttributes: new { @class = "form-control", id = "gallons" })
</div>
</div>
<div class="form-group">
<label for="f15HCF" class="control-label col-md-4 caption">1st 15 HCF at $3.6121:</label>
<div class="col-md-2">
@Html.TextBox("First15HCF", null,
htmlAttributes: new { @class = "form-control", id = "f15HCF" })
</div>
<label for="next10HCF" class="control-label col-md-125 caption">Next 10 HCF at $3.9180:</label>
<div class="col-md-125">
@Html.TextBox("Next10HCF", null,
htmlAttributes: new { @class = "form-control", id = "next10HCF" })
</div>
<label for="remHCF" class="control-label col-md-2 caption">Remaining HCF at $4.2763:</label>
<div class="col-md-1">
@Html.TextBox("RemainingHCF", null, htmlAttributes: new { @class = "form-control", id = "remHCF" })
</div>
</div>
<div class="form-group">
<label for="sewerCharges" class="control-label col-md-4 caption">Sewer Charges:</label>
<div class="col-md-2">
@Html.TextBox("SewerCharges", null,
htmlAttributes: new { @class = "form-control", id = "sewerCharges" })
</div>
<label for="stormCharges" class="control-label col-md-125 caption">Storm Charges:</label>
<div class="col-md-125">
@Html.TextBox("StormCharges", null,
htmlAttributes: new { @class = "form-control", id = "stormCharges" })
</div>
<label for="wuc" class="control-label col-md-2 caption">Water Usage Charges:</label>
<div class="col-md-1">
@Html.TextBox("WaterUsageCharges", null, htmlAttributes: new { @class = "form-control", id = "wuc" })
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4"> </label>
<div class="col-md-2"> </div>
<label class="control-label col-md-125"> </label>
<div class="col-md-125"> </div>
<label for="totalCharges" class="control-label col-md-2 caption">Total Charges:</label>
<div class="col-md-1">
@Html.TextBox("TotalCharges", null, htmlAttributes: new { @class = "form-control", id = "totalCharges" })
</div>
</div>
<hr />
<div class="form-group">
<label class="control-label col-md-4"> </label>
<div class="col-md-125"> </div>
<label for="localTaxes" class="control-label col-md-125 caption">Local Taxes:</label>
<div class="col-md-125">
@Html.TextBox("LocalTaxes", null,
htmlAttributes: new { @class = "form-control", id = "localTaxes" })
</div>
<label for="stateTaxes" class="control-label col-md-125 caption">State Taxes:</label>
<div class="col-md-125">
@Html.TextBox("StateTaxes", null, htmlAttributes: new { @class = "form-control", id = "stateTaxes" })
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4"> </label>
<div class="col-md-125"> </div>
<label for="pdd" class="control-label col-md-125 caption">Payment Due Date:</label>
<div class="col-md-125">
@Html.TextBox("PaymentDueDate", null,
htmlAttributes: new { @class = "form-control", type = "date", id = "pdd" })
</div>
<label for="amtDue" class="control-label col-md-125 caption">Amount Due:</label>
<div class="col-md-125">
@Html.TextBox("AmountDue", null,
htmlAttributes: new { @class = "form-control", id = "amtDue" })
</div>
</div>
<div class="form-group">
<label class="control-label col-md-4 caption"> </label>
<div class="col-md-125"> </div>
<label for="lpdd" class="control-label col-md-125 caption">Late Payment Due Date:</label>
<div class="col-md-125">
@Html.TextBox("LatePaymentDueDate", null,
htmlAttributes: new { @class = "form-control", id = "lpdd" })
</div>
<label for="lateAmtDue" class="control-label col-md-125 caption">Late Amount Due:</label>
<div class="col-md-125">
@Html.TextBox("LateAmountDue", null, htmlAttributes: new { @class = "form-control", id = "lateAmtDue" })
</div>
</div>
<div class="form-group text-center">
<label class="control-label col-md-5">
@Html.ActionLink("Water Bills", "Index", null, htmlAttributes: new { @class = "water-nav" })
</label>
<div class="col-md-7">
<input type="submit" value="Update Water Bill" class="btn btn-primary" />
</div>
</div>
</div>
}@{
ViewBag.Title = "Delete Water Bill";
}
<div class="push-down">
<h2>Cancel Water Bill</h2>
</div>
<hr />
<div class="containment">
<dl class="dl-horizontal common-font caption">
<dt class="fw-bold">Water Bill ID:</dt>
<dd>@ViewData["WaterBillID"]</dd>
<dt class="fw-bold">Invoice #:</dt>
<dd>@ViewData["InvoiceNumber"]</dd>
<dt class="fw-bold">Account #:</dt>
<dd>@ViewData["AccountNumber"]</dd>
<dt class="fw-bold">Meter Reading Start Date:</dt>
<dd>@ViewData["MeterReadingStartDate"]</dd>
<dt class="fw-bold">Meter Reading End Date:</dt>
<dd>@ViewData["MeterReadingEndDate"]</dd>
<dt class="fw-bold">Billing Days:</dt>
<dd>@ViewData["BillingDays"]</dd>
<dt class="fw-bold">Counter Reading Start:</dt>
<dd>@ViewData["CounterReadingStart"]</dd>
<dt class="fw-bold">Counter Reading End:</dt>
<dd>@ViewData["CounterReadingEnd"]</dd>
<dt class="fw-bold">Total HCF:</dt>
<dd>@ViewData["TotalHCF"]</dd>
<dt class="fw-bold">Total Gallons:</dt>
<dd>@ViewData["TotalGallons"]</dd>
<dt class="fw-bold">First 15 HCF:</dt>
<dd>@ViewData["First15HCF"]</dd>
<dt class="fw-bold">Next 10 HCF:</dt>
<dd>@ViewData["Next10HCF"]</dd>
<dt class="fw-bold">Remaining HCF:</dt>
<dd>@ViewData["RemainingHCF"]</dd>
<dt class="fw-bold">Sewer Charges:</dt>
<dd>@ViewData["SewerCharges"]</dd>
<dt class="fw-bold">Storm Charges:</dt>
<dd>@ViewData["StormCharges"]</dd>
<dt class="fw-bold">Water Usage Charges:</dt>
<dd>@ViewData["WaterUsageCharges"]</dd>
<dt class="fw-bold">Total Charges:</dt>
<dd>@ViewData["TotalCharges"]</dd>
<dt class="fw-bold">Local Taxes:</dt>
<dd>@ViewData["LocalTaxes"]</dd>
<dt class="fw-bold">State Taxes:</dt>
<dd>@ViewData["StateTaxes"]</dd>
<dt class="fw-bold">Payment Due Date:</dt>
<dd>@ViewData["PaymentDueDate"]</dd>
<dt class="fw-bold">Amount Due:</dt>
<dd>@ViewData["AmountDue"]</dd>
<dt class="fw-bold">Late Payment Due Date:</dt>
<dd>@ViewData["LatePaymentDueDate"]</dd>
<dt class="fw-bold">Late Amount Due:</dt>
<dd>@ViewData["LateAmountDue"]</dd>
</dl>
<h3 class="common-font caption">Are you sure you want to cancel this water bill (if you do, the bill will disappear from the system)?</h3>
@using (Html.BeginForm())
{
<div class="form-actions no-color">
<input type="submit" value="Cancel this Water Bill" class="btn btn-primary" /> |
@Html.ActionLink("Customers Water Bills", "Index", null, new { @class = "water-nav" })
</div>
}
</div>Payments
Bills payments are the means by which a company make smoney. Now, we will create the webpages necessary to create and manage payments.
Practical Learning: Making Payments
using System.Xml;
u
using System.Web.Mvc;
namespace StellarWaterPoint1.Controllers
{
public class PaymentsController : Controller
{
// GET: Payments
public ActionResult Index()
{
XmlDocument xdPayments = new XmlDocument();
string strFilePayments = Server.MapPath("/AppData/Payments.xml");
if (System.IO.File.Exists(strFilePayments))
{
using (FileStream fsPayments = new FileStream(strFilePayments, FileMode.Open, FileAccess.Read, FileShare.Read))
{
xdPayments.Load(fsPayments);
}
if (xdPayments.DocumentElement.ChildNodes.Count > 0)
{
ViewData["Payments"] = xdPayments.DocumentElement.ChildNodes;
}
else
{
ViewData["Payments"] = null;
}
}
return View();
}
// GET: Payments/Details/5
public ActionResult Details(int id)
{
XmlDocument xdPayments = new XmlDocument();
string strFilePayments = Server.MapPath("/AppData/Payments.xml");
if (System.IO.File.Exists(strFilePayments))
{
using (FileStream fsPayments = new FileStream(strFilePayments, FileMode.Open, FileAccess.Read, FileShare.Read))
{
xdPayments.Load(fsPayments);
XmlNodeList xnlPayments = xdPayments.GetElementsByTagName("payment-id");
foreach (XmlNode xnPayment in xnlPayments)
{
if (xnPayment.InnerText == id.ToString())
{
ViewData["PaymentID"] = xnPayment.InnerText;
ViewData["ReceiptNumber"] = xnPayment.NextSibling.InnerText;
ViewData["WaterBillID"] = xnPayment.NextSibling.NextSibling.InnerText;
ViewData["PaymentDate"] = xnPayment.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["PaymentAmount"] = xnPayment.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
}
}
}
}
return View();
}
// GET: Payments/Create
public ActionResult Create()
{
int payment_id = 0;
XmlDocument xdPayments = new XmlDocument();
string strFilePayments = Server.MapPath("/AppData/Payments.xml");
if (System.IO.File.Exists(strFilePayments))
{
using (FileStream fsPayments = new FileStream(strFilePayments, FileMode.Open, FileAccess.Read, FileShare.Read))
{
xdPayments.Load(fsPayments);
XmlNodeList xnlPayments = xdPayments.GetElementsByTagName("payment-id");
foreach (XmlNode xnPayment in xnlPayments)
{
payment_id = int.Parse(xnPayment.FirstChild.InnerText);
}
}
}
ViewData["PaymentID"] = (payment_id + 1);
Random rndNumber = new Random();
ViewData["ReceiptNumber"] = rndNumber.Next(100001, 999999).ToString();
return View();
}
// POST: Payments/Create
[HttpPost]
public ActionResult Create(FormCollection collection)
{
try
{
// TODO: Add insert logic here
// int pmtId = 0;
XmlDocument xdPayments = new XmlDocument();
string strFilePayments = Server.MapPath("/AppData/Payments.xml");
if (System.IO.File.Exists(strFilePayments))
{
using (FileStream fsPayments = new FileStream(strFilePayments, FileMode.Open, FileAccess.Read, FileShare.Read))
{
xdPayments.Load(fsPayments);
/* XmlNodeList xnlPayments = xdPayments.GetElementsByTagName("payment-id");
foreach (XmlNode xnPayment in xnlPayments)
{
pmtId = int.Parse(xnPayment.InnerText);
} */
}
}
else
{
xdPayments.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<payments></payments>");
// pmtId = 0;
}
// pmtId++;
XmlElement xePayment = xdPayments.CreateElement("payment");
xePayment.InnerXml = "<payment-id>" + collection["PaymentID"] + "</payment-id>" +
"<receipt-number>" + collection["ReceiptNumber"] + "</receipt-number>" +
"<water-bill-id>" + collection["WaterBillID"] + "</water-bill-id>" +
"<payment-date>" + collection["PaymentDate"] + "</payment-date>" +
"<payment-amount>" + collection["PaymentAmount"] + "</payment-amount>";
xdPayments.DocumentElement.AppendChild(xePayment);
using (FileStream fsPayments = new FileStream(strFilePayments, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
{
xdPayments.Save(fsPayments);
}
return RedirectToAction("Index");
}
catch
{
return View();
}
}
// GET: Payments/Edit/5
public ActionResult Edit(int id)
{
XmlDocument xdPayments = new XmlDocument();
string strFilePayments = Server.MapPath("/AppData/Payments.xml");
if (System.IO.File.Exists(strFilePayments))
{
using (FileStream fsPayments = new FileStream(strFilePayments, FileMode.Open, FileAccess.Read, FileShare.Read))
{
xdPayments.Load(fsPayments);
XmlNodeList xnlPayments = xdPayments.GetElementsByTagName("payment-id");
foreach (XmlNode xnPayment in xnlPayments)
{
if (xnPayment.InnerText == id.ToString())
{
ViewData["PaymentID"] = xnPayment.InnerText;
ViewData["ReceiptNumber"] = xnPayment.NextSibling.InnerText;
ViewData["WaterBillID"] = xnPayment.NextSibling.NextSibling.InnerText;
ViewData["PaymentDate"] = xnPayment.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["PaymentAmount"] = xnPayment.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
}
}
}
}
return View();
}
// POST: Payments/Edit/5
[HttpPost]
public ActionResult Edit(int id, FormCollection collection)
{
try
{
// TODO: Add update logic here
XmlDocument xdPayments = new XmlDocument();
string strFilePayments = Server.MapPath("/AppData/Payments.xml");
if (System.IO.File.Exists(strFilePayments))
{
using (FileStream fsPayments = new FileStream(strFilePayments, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
{
xdPayments.Load(fsPayments);
}
XmlNodeList xnlPayments = xdPayments.GetElementsByTagName("payment-id");
using (FileStream fsPayments = new FileStream(strFilePayments, FileMode.Truncate, FileAccess.ReadWrite, FileShare.ReadWrite))
{
foreach (XmlNode xnPayment in xnlPayments)
{
if (xnPayment.InnerText == id.ToString())
{
xnPayment.ParentNode.InnerXml = "<payment-id>" + id + "</payment-id>" +
"<receipt-number>" + collection["ReceiptNumber"] + "</receipt-number>" +
"<water-bill-id>" + collection["WaterBillID"] + "</water-bill-id>" +
"<payment-date>" + collection["PaymentDate"] + "</payment-date>" +
"<payment-amount>" + collection["PaymentAmount"] + "</payment-amount>";
xdPayments.Save(fsPayments);
break;
}
}
}
}
return RedirectToAction("Index");
}
catch
{
return View();
}
}
// GET: Payments/Delete/5
public ActionResult Delete(int id)
{
XmlDocument xdPayments = new XmlDocument();
string strFilePayments = Server.MapPath("/AppData/Payments.xml");
if (System.IO.File.Exists(strFilePayments))
{
using (FileStream fsPayments = new FileStream(strFilePayments, FileMode.Open, FileAccess.Read, FileShare.Read))
{
xdPayments.Load(fsPayments);
XmlNodeList xnlPayments = xdPayments.GetElementsByTagName("payment-id");
foreach (XmlNode xnPayment in xnlPayments)
{
if (xnPayment.InnerText == id.ToString())
{
ViewData["PaymentID"] = xnPayment.InnerText;
ViewData["ReceiptNumber"] = xnPayment.NextSibling.InnerText;
ViewData["WaterBillID"] = xnPayment.NextSibling.NextSibling.InnerText;
ViewData["PaymentDate"] = xnPayment.NextSibling.NextSibling.NextSibling.InnerText;
ViewData["PaymentAmount"] = xnPayment.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
}
}
}
}
return View();
}
// POST: Payments/Delete/5
[HttpPost]
public ActionResult Delete(int id, FormCollection collection)
{
try
{
// TODO: Add delete logic here
XmlDocument xdPayments = new XmlDocument();
string strFilePayments = Server.MapPath("/AppData/Payments.xml");
if (System.IO.File.Exists(strFilePayments))
{
using (FileStream fsPayments = new FileStream(strFilePayments, FileMode.Open, FileAccess.Read, FileShare.Read))
{
xdPayments.Load(fsPayments);
}
using (FileStream fsPayments = new FileStream(strFilePayments, FileMode.Truncate, FileAccess.Write, FileShare.Write))
{
XmlNodeList xnlPayments = xdPayments.GetElementsByTagName("payment");
foreach (XmlNode xnPayment in xnlPayments)
{
if (xnPayment.FirstChild.InnerText == id.ToString())
{
xnPayment.ParentNode.RemoveChild(xnPayment);
xdPayments.Save(fsPayments);
break;
}
}
}
}
return RedirectToAction("Index");
}
catch
{
return View();
}
}
}
}@{
ViewBag.Title = "Water Bills Payments";
}
<div class="push-down">
<h2 class="common-font bold text-center">Water Bills Payments</h2>
</div>
<hr />
<table class="table table-striped common-font">
<tr>
<th class="fw-bold">Payment ID</th>
<th class="fw-bold">Receipt #</th>
<th class="fw-bold">Water Bill ID</th>
<th class="fw-bold">Payment Date</th>
<th class="fw-bold">Payment Amount</th>
<th>@Html.ActionLink("New Bill Payment", "Create", null, htmlAttributes: new { @class = "water-nav" })</th>
</tr>
@if (ViewData["Payments"] != null)
{
foreach (System.Xml.XmlNode pmt in ViewData["Payments"] as System.Xml.XmlNodeList)
{
<tr>
<td class="text-center">@pmt.FirstChild.InnerText</td>
<td>@pmt.FirstChild.NextSibling.InnerText</td>
<td>@pmt.FirstChild.NextSibling.NextSibling.InnerText</td>
<td>@pmt.FirstChild.NextSibling.NextSibling.NextSibling.InnerText</td>
<td>@pmt.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling.InnerText</td>
<td>
@Html.ActionLink("Update", "Edit", new { id = pmt.FirstChild.InnerText }) <span style="color: aquamarine">::</span>
@Html.ActionLink("Review", "Details", new { id = pmt.FirstChild.InnerText }) <span style="color: aquamarine">::</span>
@Html.ActionLink("Remove", "Delete", new { id = pmt.FirstChild.InnerText })
</td>
</tr>
}
}
</table>@{
ViewBag.Title = "Water Bill Details";
}
<div class="push-down">
<h2>Water Bill Details</h2>
</div>
<hr />
<div class="containment">
<dl class="dl-horizontal common-font caption">
<dt class="fw-bold">Payment ID:</dt>
<dd>@ViewData["PaymentID"]</dd>
<dt>Receipt #:</dt>
<dd>@ViewData["ReceiptNumber"]</dd>
<dt>Water Bill ID:</dt>
<dd>@ViewData["WaterBillID"]</dd>
<dt>Payment Date:</dt>
<dd>@ViewData["PaymentDate"]</dd>
<dt>Payment Amount:</dt>
<dd>@ViewData["PaymentAmount"]</dd>
</dl>
</div>
<p class="text-center">
@Html.ActionLink("Edit/Update Bill Payment", "Edit",
new { id = ViewData["PaymentID"] }, htmlAttributes: new { @class = "water-nav" }) ::
@Html.ActionLink("Water Bill Payments", "Index",
null, new { @class = "water-nav" })
</p>
@{
ViewBag.Title = "Create Bill Payment";
}
<div class="push-down">
<h2>Make Water Bill Payment</h2>
</div>
<hr />
@using (Html.BeginForm())
{
<div class="form-horizontal">
<div class="form-group">
<label for="pmtId" class="control-label col-md-4 caption">Payment ID:</label>
<div class="col-md-8">
@Html.TextBox("PaymentID", null, htmlAttributes: new { @class = "form-control", id = "pmtId" })
</div>
</div>
<div class="form-group">
<label for="mtrNbr" class="control-label col-md-4 caption">Receipt #:</label>
<div class="col-md-8">
@Html.TextBox("ReceiptNumber", null, htmlAttributes: new { @class = "form-control", id = "mtrNbr" })
</div>
</div>
<div class="form-group">
<label for="billId" class="control-label col-md-4 caption">Water Bill ID:</label>
<div class="col-md-8">
@Html.TextBox("WaterBillID", null, htmlAttributes: new { @class = "form-control", id = "billId" })
</div>
</div>
<div class="form-group">
<label for="pmtDate" class="control-label col-md-4 caption">Payment Date:</label>
<div class="col-md-8">
@Html.TextBox("PaymentDate", null, htmlAttributes: new { @class = "form-control", id = "pmtDate" })
</div>
</div>
<div class="form-group">
<label for="pmtAmt" class="control-label col-md-4 caption">Payment Amount:</label>
<div class="col-md-8">
@Html.TextBox("PaymentAmount", null, htmlAttributes: new { @class = "form-control", id = "pmtAmt" })
</div>
</div>
<div class="form-group">
<label class="control-label col-md-5">
@Html.ActionLink("Bills Payments", "Index", null, htmlAttributes: new { @class = "water-nav" })
</label>
<div class="col-md-7">
<input type="submit" value="Create Bill Payment" class="btn btn-primary" />
</div>
</div>
</div>
}@{
ViewBag.Title = "Edit/Update Bill Payment";
}
<div class="push-down">
<h2>Edit/Update Bill Payment</h2>
</div>
<hr />
@using (Html.BeginForm())
{
<div class="form-horizontal">
<div class="form-group">
<label class="control-label col-md-4 caption">Payment ID:</label>
<div class="col-md-8">
@Html.TextBox("PaymentID", null,
htmlAttributes: new { @class = "form-control", disabled = "disabled" })
</div>
</div>
<div class="form-group">
<label for="recNbr" class="control-label col-md-4 caption">Receipt #:</label>
<div class="col-md-8">
@Html.TextBox("ReceiptNumber", null, htmlAttributes: new { @class = "form-control", id = "recNbr" })
</div>
</div>
<div class="form-group">
<label for="billNbr" class="control-label col-md-4 caption">Account #:</label>
<div class="col-md-8">
@Html.TextBox("WaterBillID", null, htmlAttributes: new { @class = "form-control", id = "billNbr" })
</div>
</div>
<div class="form-group">
<label for="pmtDate" class="control-label col-md-4 caption">Payment Date:</label>
<div class="col-md-8">
@Html.TextBox("PaymentDate", null,
htmlAttributes: new { @class = "form-control", type = "date", id = "pmtDate" })
</div>
</div>
<div class="form-group">
<label for="pmtAmt" class="control-label col-md-4 caption">Payment Amount:</label>
<div class="col-md-8">
@Html.TextBox("PaymentAmount", null, htmlAttributes: new { @class = "form-control", id = "pmtAmt" })
</div>
</div>
<div class="form-group">
<label class="control-label col-md-5">
@Html.ActionLink("Bills Payments", "Index", null, htmlAttributes: new { @class = "water-nav" })
</label>
<div class="col-md-7">
<input type="submit" value="Update this Payment" class="btn btn-primary" />
</div>
</div>
</div>
}@{
ViewBag.Title = "Delete Bill Payment";
}
<div class="push-down">
<h2>Delete Bill Payment</h2>
</div>
<hr />
<div class="containment">
<dl class="dl-horizontal common-font caption">
<dt>Payment ID:</dt>
<dd>@ViewData["PaymentID"]</dd>
<dt>Receipt #:</dt>
<dd>@ViewData["ReceiptNumber"]</dd>
<dt>Water Bill ID:</dt>
<dd>@ViewData["WaterBillID"]</dd>
<dt>Payment Date:</dt>
<dd>@ViewData["PaymentDate"]</dd>
<dt>Payment Amount:</dt>
<dd>@ViewData["PaymentAmount"]</dd>
</dl>
<h3 class="common-font caption">Are you sure you want to cancel this payment?</h3>
@using (Html.BeginForm())
{
<div class="form-actions no-color">
<input type="submit" value="Cancel this bill payment" class="btn btn-primary" /> |
@Html.ActionLink("Water Bills Payments", "Index", null, new { @class = "water-nav" })
</div>
}
</div>Finalizing the Application
Most of the time, it is a good idea to apply a common design to most webpages of a website. In ASP.NET, such a design is created as a layout view.
Practical Learning: Finalizing the Application
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - Water for a Shining Life</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
</head>
<body>
<div class="top-bar">
<div class="containment"><img src="~/Images/wsl1.png" alt="Water for a Shining Life" width="490" height="92" /></div>
</div>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
@Html.ActionLink("Home", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>@Html.ActionLink("Emergency Services", "Index", "Home")</li>
<li>@Html.ActionLink("Cummunity", "Index", "Home")</li>
<li>@Html.ActionLink("Environment", "Index", "Home")</li>
<li>@Html.ActionLink("Resources", "Index", "Home")</li>
<li>@Html.ActionLink("Projects", "Index", "Home")</li>
<li>@Html.ActionLink("Customer Service", "Index", "Home")</li>
<li>@Html.ActionLink("Employment", "Index", "Home")</li>
<li>@Html.ActionLink("Questions?", "Index", "Home")</li>
<li>@Html.ActionLink("About", "About", "Home")</li>
<li>@Html.ActionLink("Contact", "Contact", "Home")</li>
</ul>
</div>
</div>
</div>
<div class="container body-content">
@RenderBody()
<hr />
<footer>
<p class="copyright text-center common-font">© @DateTime.Now.Year - Water for a Shining Life</p>
</footer>
</div>
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
</body>
</html><div class="jumbotron">
<h2>.</h2>
<p class="lead">
Our water utility company provides energy, greatness, and warmth
for a everyday life, a shining life. We provide solutions to families, businesses,
and the community.
</p>
<p class="lead">
This is the employees portal section of the company. From here,
employees can register a new water meter, manage a customer account, or
create a water bill.
</p>
</div>
<div class="row">
<div class="col-md-3">
<h2>Water Meters</h2>
<p>
Our company uses the most accurate, sophisticated, and environment-friendly
water meters on the market.
</p>
<p>@Html.ActionLink("Water Meters", "Index", "WaterMeters", null, new { @class = "btn btn-primary" })</p>
</div>
<div class="col-md-3">
<h2>Customers</h2>
<p>
We supply water to individuals, families, small
businesses, as well as enterprises or government agencies.
</p>
<p>@Html.ActionLink("Customers", "Index", "Customers", null, new { @class = "btn btn-primary" })</p>
</div>
<div class="col-md-3">
<h2>Water Bills</h2>
<p>
Our water rates are very competitive nationwide. We use precise,
effective, and strict algorithms when calculating our bills.
</p>
<p>@Html.ActionLink("Bills/Invoices", "Index", "WaterBills", null, new { @class = "btn btn-primary" })</p>
</div>
<div class="col-md-3">
<h2>Payments</h2>
<p>
Our payment system is the simplest, the fairest, and the fastest. Our custiomer's service
is highly rated.
</p>
<p>@Html.ActionLink("Bills Payments", "Index", "Payments", null, new { @class = "btn btn-primary" })</p>
</div>
</div>Meter #: 283-58-958 Make: Constance Technologies Model: TR-6224 Date Last Udate: 04/22/2022
Payment Due Date: 08/27/2022 Late Payment Due Date: 09/13/2022
| Account # | Meter Reading End Date | Current Meter Reading | Payment Due Date | Late Payment Due Date |
| 4820-375-2842 | 07/31/2022 | 109998 | 08/28/2022 | 09/14/2022 |
| 2038-413-9680 | 7/30/2022 | 137975 | 8/27/2022 | 9/13/2022 |
| 9279-570-8394 | 08/07/2022 | 6275 | 08/04/2022 | 08/20/2022 |
| 7518-302-6895 | 11/07/2022 | 118 | 12/01/2022 | 12/15/2022 |
| 2038-413-9680 | 10/27/2022 | 138012 | 11/24/2022 | 12/10/2022 |
| Receipt # | Bill ID | Payment Date | Payment Amount |
| 625288 | 2 | 08/24/2022 | 145.75 |
| 836168 | 3 | 09/12/2022 | 198.36 |
| 886415 | 1 | 08/27/2022 | 93.34 |
| 724705 | 4 | 09/01/2022 | 41.31 |
| 141806 | 6 | 12/05/2022 | 163.40 |
| 706953 | 5 | 12/10/2022 | 27.44 |
|
|
|||
| Home | Copyright © 2005-2022, FunctionX | Friday 06 May 2022 | Home |
|
|
|||