Razor Pages - ADO.NET: Stellar Water Point
Razor Pages - ADO.NET: Stellar Water Point
Introduction
Like many techniques available in the .NET Framework, Razor Pages is an approach to creating a Web-based application using existing HTML and CSS languages, and combining C# code to it. Still, Razor Pages adds its own syntax to HTML. ADO.NET is a technique to perform database operations using the .NET Framework. ADO.NET is not the only way to perform database operations but ADO.NET presents many advantages. For example, ADO.NET can be used in various types of applications, including console applications, Windows Forms, and of courses various types of Web-based applications. Another advantage of ADO.NET is that it can be used with almost any type of database that is supported in Microsoft Windows; these include Oracle, Microsoft Access, MySQL, etc.
In this exercise, we are going to create a Razor Pages application that uses a Microsoft SQL Server database. The database will be (manually) created in Microsoft SQL Server (we will create our database using SQL Server Management Studio 20). In case you don't know, Microsoft SQL Server is completely free. You can download Microsoft SQL Server 2022 Developer edition (or SQL Server 2022 Express) and SQL Server Management Studio 20 freely from the Microsoft web sites.
Practical Learning: Introducing the Application
html {
font-size: 14px;
}
@media (min-width: 768px) {
html {
font-size: 16px;
}
}
.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
}
html {
position: relative;
min-height: 100%;
}
body {
margin-bottom: 60px;
}
.bordered { border: 1px solid black; }
.encloser { margin: auto;
width: 400px; }
.encloser-large { margin: auto;
width: 600px; }
.enclosing { margin: auto;
width: 500px; }
.mb-3 { margin-bottom: 5rem !important;
background-color: #800000 !important;
font-family: Garamond, Georgia, Cambria, 'Times New Roman', Times, serif; }
.text-light { font-weight: bold; }
.stellar { font-weight: bold;
text-decoration: none;
color: maroon;
font-family: Garamond, Georgia, Cambria, 'Times New Roman', Times, serif; }
a.stellar:focus { color: red; }
a.stellar:hover { color: navy;
text-decoration: underline; }
.navbar-light .navbar-brand {
font-weight: bold;
color: #FFD800; }
.navbar-light .navbar-brand:hover, .navbar-light .navbar-brand:focus {
font-weight: bold;
color: #FFFFFF; }
.nav-link .text-light:focus {
font-weight: bold;
color: #FFD800; }
.nav-link .text-light:hover {
font-weight: bold;
color: #FFFFFF; }
.common-font {
font-family: Garamond, Georgia, Cambria, 'Times New Roman', Times, serif
}
A Database for an Application
Our application will use a database. You must create that database. You can do it in the SQL Server Management Studio or you can do it in the application as a local database. When setting up the database, we will create tables for water meters, customers, and water bills.
Practical Learning: Preparing a Database
USE master GO -- Drop the database if it already exists IF EXISTS ( SELECT name FROM sys.databases WHERE name = N'StellarWaterPoint1' ) DROP DATABASE StellarWaterPoint1; GO CREATE DATABASE StellarWaterPoint1; GO USE StellarWaterPoint1; GO
CREATE TABLE WaterMeters ( WaterMeterId INT IDENTITY(1, 1), MeterNumber NVARCHAR(10) NOT NULL, Make NVARCHAR(25) NOT NULL, Model NVARCHAR(15) NOT NULL, MeterSize NVARCHAR(15) NOT NULL, CONSTRAINT PK_WaterMeters PRIMARY KEY(WaterMeterId) ); GO CREATE TABLE Customers ( CustomerId INT IDENTITY(1, 1), AccountNumber NVARCHAR(15) NOT NULL, MeterNumber NVARCHAR(10), FirstName NVARCHAR(18), LastName NVARCHAR(18) NOT NULL, [Address] NVARCHAR(150), City NVARCHAR(25), County NVARCHAR(35), [State] NVARCHAR(35) NOT NULL, ZIPCode NVARCHAR(12), CONSTRAINT PK_Customers PRIMARY KEY(CustomerId) ); GO CREATE TABLE WaterBills ( WaterBillId INT IDENTITY(1, 1), BillNumber INT NOT NULL, AccountNumber NVARCHAR(15) NOT NULL, MeterReadingStartDate NVARCHAR(50) NOT NULL, MeterReadingEndDate NVARCHAR(50) NOT NULL, BillingDays INT NOT NULL, CounterReadingStart NVARCHAR(15), CounterReadingEnd NVARCHAR(15), Consumption NVARCHAR(15), TotalGallons NVARCHAR(15), FirstTierConsumption NVARCHAR(15), SecondTierConsumption NVARCHAR(15), LastTierConsumption NVARCHAR(15), WaterCharges NVARCHAR(15), SewerCharges NVARCHAR(15), EnvironmentCharges NVARCHAR(15), TotalCharges NVARCHAR(15), LocalTaxes NVARCHAR(15), StateTaxes NVARCHAR(15), PaymentDueDate NVARCHAR(50), AmountDue NVARCHAR(15), LatePaymentDueDate NVARCHAR(50), LateAmountDue NVARCHAR(15), CONSTRAINT PK_WaterBills PRIMARY KEY(WaterBillId) ); GO
Water Meters
A water meter is an electro-mechanical device that is installed at a cusomer's location to measure how much water a constume is consuming. For our application, we will use one form in a webpage to create water meter records, another webpage to allow a user to review the record of a water meter, another webpage to allow the use to make one or more changes about the information of a water recor, and one wepage to allow a user to delete the record of a water meter.
Practical Learning: Creating Water Meter Records
using System.ComponentModel.DataAnnotations; namespace StellarWaterPoint5.Models { public class WaterMeter { [Display(Name = "Water Meter Id")] public int WaterMeterId { get; set; } [Display(Name = "Meter #")] public string? MeterNumber { get; set; } public string? Make { get; set; } public string? Model { get; set; } [Display(Name = "Meter Size")] public string? MeterSize { get; set; } } }
using System.Data.SqlClient; using Microsoft.AspNetCore.Mvc; using StellarWaterPoint1.Models; using Microsoft.AspNetCore.Mvc.RazorPages; namespace StellarWaterPoint1.Pages.WaterMeters { public class CreateModel : PageModel { public void OnGet() { } [BindProperty] public WaterMeter WaterMeter { get; set; } = default!; public async Task<IActionResult> OnPostAsync() { using (SqlConnection scWaterDistribution = new SqlConnection("Data Source=(local);" + "Initial Catalog='StellarWaterPoint1';" + "Integrated Security=True;")) { SqlCommand cmdWaterMeters = new SqlCommand("INSERT INTO WaterMeters(MeterNumber, Make, Model, MeterSize) " + "VALUES(N'" + WaterMeter!.MeterNumber + "', N'" + WaterMeter.Make + "', N'" + WaterMeter.Model + "', N'" + WaterMeter.MeterSize + "');", scWaterDistribution); scWaterDistribution.Open(); cmdWaterMeters.ExecuteNonQuery(); } await Task.CompletedTask; return RedirectToPage("Index"); } } }
@page @model StellarWaterPoint1.Pages.WaterMeters.CreateModel @{ } <h1 class="common-font fw-bold text-center">Water Meter Setup</h1> <hr /> <form method="post" class="common-font encloser"> <div asp-validation-summary="ModelOnly" class="text-danger"></div> <div class="row mb-2"> <label asp-for="WaterMeter.MeterNumber" class="col-form-label col-sm-3 fw-bold"></label> <div class="col-sm-9"> <input class="form-control" asp-for="WaterMeter.MeterNumber"> <span asp-validation-for="WaterMeter.MeterNumber" class="text-danger"></span> </div> </div> <div class="row mb-2"> <label asp-for="WaterMeter.Make" class="fw-bold col-sm-3 col-form-label"></label> <div class="col-sm-9"> <input asp-for="WaterMeter.Make" class="form-control"> <span asp-validation-for="WaterMeter.Make" class="text-danger"></span> </div> </div> <div class="row mb-2"> <label asp-for="WaterMeter.Model" class="fw-bold col-sm-3 col-form-label"></label> <div class="col-sm-9"> <input asp-for="WaterMeter.Model" class="form-control"> <span asp-validation-for="WaterMeter.Model" class="text-danger"></span> </div> </div> <div class="row mb-2"> <label asp-for="WaterMeter.MeterSize" class="fw-bold col-sm-3 col-form-label"></label> <div class="col-sm-9"> <input asp-for="WaterMeter.MeterSize" class="form-control"> <span asp-validation-for="WaterMeter.MeterSize" class="text-danger"></span> </div> </div> <hr /> <div class="row mb-2"> <div class="col-sm-5 col-form-label"> <a asp-page="Index">Water Meters</a> </div> <div class="col-md-7"> <input type="submit" value="Save Water Meter" class="btn btn-primary" /> </div> </div> </form> <hr /> <p class="text-center"> <a asp-page="./Details" class="stellar">View a Water Meter Details</a> :: <a asp-page="./Edit" class="stellar">Edit a Water Meter</a> :: <a asp-page="./Delete" class="stellar">Delete a Water Meter</a> </p>
@page @using System.Data @using System.Data.SqlClient @model StellarWaterPoint1.Pages.WaterMeters.DetailsModel @{ bool bMeterFound = false; string? strMake = string.Empty; string? strModel = string.Empty; string? strMessage = string.Empty; string? strMeterSize = string.Empty; string? strMeterNumber = string.Empty; if (Request.HasFormContentType) { DataSet dsWaterMeters = new("WaterMetersSet"); strMeterNumber = Request.Form["txtMeterNumber"]; using (SqlConnection scWaterDistribution = new SqlConnection("Data Source=(local);" + "Initial Catalog='StellarWaterPoint1';" + "Integrated Security=True;")) { SqlCommand cmdWaterMeters = new SqlCommand("SELECT Make, Model, MeterSize " + "FROM WaterMeters " + "WHERE MeterNumber = N'" + strMeterNumber + "';", scWaterDistribution); scWaterDistribution.Open(); SqlDataAdapter sdaWaterMeters = new SqlDataAdapter(cmdWaterMeters); sdaWaterMeters.Fill(dsWaterMeters); foreach (DataRow drWaterMeter in dsWaterMeters.Tables[0].Rows!) { bMeterFound = true; strMake = drWaterMeter[0].ToString(); strModel = drWaterMeter[1].ToString(); strMeterSize = drWaterMeter[2].ToString(); break; } } if (bMeterFound == false) { strMessage = "There is no water meter with that number in our system."; } } } <h1 class="common-font fw-bold text-center">Water Meter Details</h1> <hr /> <form method="post" class="common-font encloser"> <div asp-validation-summary="ModelOnly" class="text-danger"></div> <div class="row mb-2"> <label for="txtMeterNumber" class="col-form-label col-sm-3 fw-bold">Meter #</label> <div class="col-sm-4"> <input class="form-control" name="txtMeterNumber" value="@strMeterNumber" /> </div> <div class="col-md-4"> <input type="submit" name="btnFindWaterMeter" value="Find Water Meter" class="btn btn-primary" /> </div> </div> <div class="row mb-2"> <label for="txtMake" class="fw-bold col-sm-3 col-form-label">Make</label> <div class="col-sm-9"> <input name="txtMake" class="form-control" value="@strMake" /> </div> </div> <div class="row mb-2"> <label for="txtModel" class="fw-bold col-sm-3 col-form-label">Model</label> <div class="col-sm-9"> <input name="txtModel" class="form-control" value="@strModel" /> </div> </div> <div class="row mb-2"> <label for="txtMeterSize" class="fw-bold col-sm-3 col-form-label">Meter Size</label> <div class="col-sm-9"> <input name="txtMeterSize" class="form-control" value="@strMeterSize" /> </div> </div> <hr /> <div class="row mb-2"> <div class="col-sm-5 col-form-label"> <a asp-page="Index">Water Meters</a> </div> <div class="col-md-7"> <p>@strMessage</p> </div> </div> </form> <hr /> <p class="text-center"> <a asp-page="./Create" class="stellar">Create Water Meter</a> :: <a asp-page="./Edit" class="stellar">Edit a Water Meter</a> :: <a asp-page="./Delete" class="stellar">Delete a Water Meter</a> </p>
@page @using System.Data; @using System.Data.SqlClient; @model StellarWaterPoint1.Pages.WaterMeters.EditModel @{ ViewData["Title"] = "Water Meter Setup"; bool bMeterFound = false; string? strMake = string.Empty; string? strModel = string.Empty; string? strMessage = string.Empty; string? strMeterSize = string.Empty; string? strMeterNumber = string.Empty; if (Request.HasFormContentType) { DataSet dsWaterMeters = new("WaterMetersSet"); strMeterNumber = Request.Form["txtMeterNumber"]; if (Request.Form["btnFindWaterMeter"] == "Find Water Meter") { using (SqlConnection scWaterDistribution = new SqlConnection("Data Source=(local);" + "Initial Catalog='StellarWaterPoint1';" + "Integrated Security=True;")) { SqlCommand cmdWaterMeters = new SqlCommand("SELECT Make, Model, MeterSize " + "FROM WaterMeters " + "WHERE MeterNumber = N'" + strMeterNumber + "';", scWaterDistribution); scWaterDistribution.Open(); SqlDataAdapter sdaWaterMeters = new SqlDataAdapter(cmdWaterMeters); sdaWaterMeters.Fill(dsWaterMeters); foreach (DataRow drWaterMeter in dsWaterMeters.Tables[0].Rows!) { bMeterFound = true; strMake = drWaterMeter[0].ToString(); strModel = drWaterMeter[1].ToString(); strMeterSize = drWaterMeter[2].ToString(); break; } } if (bMeterFound == false) { strMessage = "There is no water meter with that number in our system."; } } if (Request.Form["btnUpdateWaterMeter"] == "Update Water Meter") { using (SqlConnection scWaterDistribution = new SqlConnection("Data Source=(local);" + "Initial Catalog='StellarWaterPoint1';" + "Integrated Security=True;")) { strMeterNumber = Request.Form["txtMeterNumber"]; strMake = Request.Form["txtMake"]; strModel = Request.Form["txtModel"]; strMeterSize = Request.Form["txtMeterSize"]; SqlCommand cmdWaterMeters = new SqlCommand("UPDATE WaterMeters SET Make = N'" + strMake + "' WHERE MeterNumber = N'" + strMeterNumber + "';" + "UPDATE WaterMeters SET Model = N'" + strModel + "' WHERE MeterNumber = N'" + strMeterNumber + "';" + "UPDATE WaterMeters SET MeterSize = N'" + strMeterSize + "' WHERE MeterNumber = N'" + strMeterNumber + "';", scWaterDistribution); scWaterDistribution.Open(); cmdWaterMeters.ExecuteNonQuery(); } Response.Redirect("Index"); } } } <h1 class="common-font fw-bold text-center">Water Meter Setup</h1> <hr /> <form method="post" class="common-font encloser"> <div asp-validation-summary="ModelOnly" class="text-danger"></div> <div class="row mb-2"> <label for="txtMeterNumber" class="col-form-label col-sm-3 fw-bold">Meter #</label> <div class="col-sm-4"> <input class="form-control" name="txtMeterNumber" value="@strMeterNumber" /> </div> <div class="col-md-4"> <input type="submit" name="btnFindWaterMeter" value="Find Water Meter" class="btn btn-primary" /> </div> </div> <div class="row mb-2"> <label for="txtMake" class="fw-bold col-sm-3 col-form-label">Make</label> <div class="col-sm-9"> <input name="txtMake" class="form-control" value="@strMake" /> </div> </div> <div class="row mb-2"> <label for="txtModel" class="fw-bold col-sm-3 col-form-label">Model</label> <div class="col-sm-9"> <input name="txtModel" class="form-control" value="@strModel" /> </div> </div> <div class="row mb-2"> <label for="txtMeterSize" class="fw-bold col-sm-3 col-form-label">Meter Size</label> <div class="col-sm-9"> <input name="txtMeterSize" class="form-control" value="@strMeterSize" /> </div> </div> <hr /> <div class="row mb-2"> <div class="col-sm-5 col-form-label"> <a asp-page="Index">Water Meters</a> </div> <div class="col-md-7"> <input type="submit" name="btnUpdateWaterMeter" value="Update Water Meter" class="btn btn-primary" /> </div> </div> <hr /> <div class="row mb-2"> <div class="col-sm-5 col-form-label"> </div> <div class="col-md-7"> <p>@strMessage</p> </div> </div> </form> <hr /> <p class="text-center"> <a asp-page="./Create" class="stellar">Create Water Meter</a> :: <a asp-page="./Details" class="stellar">View Water Meter Details</a> :: <a asp-page="./Delete" class="stellar">Delete a Water Meter</a> </p>
@page @using System.Data; @using System.Data.SqlClient; @model StellarWaterPoint1.Pages.WaterMeters.DeleteModel @{ ViewData["Title"] = "Water Meter Setup"; bool bMeterFound = false; string? strMake = string.Empty; string? strModel = string.Empty; string? strMessage = string.Empty; string? strMeterSize = string.Empty; string? strMeterNumber = string.Empty; if (Request.HasFormContentType) { DataSet dsWaterMeters = new("WaterMetersSet"); strMeterNumber = Request.Form["txtMeterNumber"]; if (Request.Form["btnFindWaterMeter"] == "Find Water Meter") { using (SqlConnection scWaterDistribution = new SqlConnection("Data Source=(local);" + "Initial Catalog='StellarWaterPoint1';" + "Integrated Security=True;")) { SqlCommand cmdWaterMeters = new SqlCommand("SELECT Make, Model, MeterSize " + "FROM WaterMeters " + "WHERE MeterNumber = N'" + strMeterNumber + "';", scWaterDistribution); scWaterDistribution.Open(); SqlDataAdapter sdaWaterMeters = new SqlDataAdapter(cmdWaterMeters); sdaWaterMeters.Fill(dsWaterMeters); foreach (DataRow drWaterMeter in dsWaterMeters.Tables[0].Rows!) { bMeterFound = true; strMake = drWaterMeter[0].ToString(); strModel = drWaterMeter[1].ToString(); strMeterSize = drWaterMeter[2].ToString(); break; } } if (bMeterFound == false) { strMessage = "There is no water meter with that number in our system."; } } if (Request.Form["btnDeleteWaterMeter"] == "Delete Water Meter") { using (SqlConnection scWaterDistribution = new SqlConnection("Data Source=(local);" + "Initial Catalog='StellarWaterPoint1';" + "Integrated Security=True;")) { strMeterNumber = Request.Form["txtMeterNumber"]; strMake = Request.Form["txtMake"]; strModel = Request.Form["txtModel"]; strMeterSize = Request.Form["txtMeterSize"]; SqlCommand cmdWaterMeters = new SqlCommand("DELETE FROM WaterMeters WHERE MeterNumber = N'" + strMeterNumber + "';", scWaterDistribution); scWaterDistribution.Open(); cmdWaterMeters.ExecuteNonQuery(); } Response.Redirect("Index"); } } } <h1 class="common-font fw-bold text-center">Water Meter Deletion</h1> <hr /> <form method="post" class="common-font encloser"> <div asp-validation-summary="ModelOnly" class="text-danger"></div> <div class="row mb-2"> <label for="txtMeterNumber" class="col-form-label col-sm-3 fw-bold">Meter #</label> <div class="col-sm-4"> <input class="form-control" name="txtMeterNumber" value="@strMeterNumber" /> </div> <div class="col-md-4"> <input type="submit" name="btnFindWaterMeter" value="Find Water Meter" class="btn btn-primary" /> </div> </div> <div class="row mb-2"> <label for="txtMake" class="fw-bold col-sm-3 col-form-label">Make</label> <div class="col-sm-9"> <input name="txtMake" class="form-control" value="@strMake" /> </div> </div> <div class="row mb-2"> <label for="txtModel" class="fw-bold col-sm-3 col-form-label">Model</label> <div class="col-sm-9"> <input name="txtModel" class="form-control" value="@strModel" /> </div> </div> <div class="row mb-2"> <label for="txtMeterSize" class="fw-bold col-sm-3 col-form-label">Meter Size</label> <div class="col-sm-9"> <input name="txtMeterSize" class="form-control" value="@strMeterSize" /> </div> </div> <hr /> <div class="row mb-2"> <div class="col-sm-5 col-form-label"> <a asp-page="Index">Water Meters</a> </div> <div class="col-md-7"> <input type="submit" name="btnDeleteWaterMeter" value="Delete Water Meter" class="btn btn-primary" /> </div> </div> <hr /> <div class="row mb-2"> <div class="col-sm-5 col-form-label"> </div> <div class="col-md-7"> <p>@strMessage</p> </div> </div> </form> <hr /> <p class="text-center"> <a asp-page="./Create" class="stellar">Create Water Meter</a> :: <a asp-page="./Edit" class="stellar">Edit a Water Meter</a> :: <a asp-page="./Delete" class="stellar">Delete a Water Meter</a> </p>
using Microsoft.AspNetCore.Mvc.RazorPages; using System.Data; using System.Data.SqlClient; namespace StellarWaterPoint1.Pages.WaterMeters { public class IndexModel : PageModel { public DataSet dsWaterMeters = new("WaterMetersSet"); public void OnGet() { using (SqlConnection scWaterDistribution = new SqlConnection("Data Source=(local);" + "Initial Catalog='StellarWaterPoint1';" + "Integrated Security=True;")) { SqlCommand cmdWaterMeters = new SqlCommand("SELECT WaterMeterId, " + " MeterNumber, " + " Make, " + " Model, " + " MeterSize " + "FROM WaterMeters; ", scWaterDistribution); scWaterDistribution.Open(); SqlDataAdapter sdaWaterMeters = new SqlDataAdapter(cmdWaterMeters); sdaWaterMeters.Fill(dsWaterMeters); } } } }
@page @using System.Data @model StellarWaterPoint1.Pages.WaterMeters.IndexModel @{ } <h1 class="common-font fw-bold text-center">Water Meters</h1> <hr /> <table class="table common-font"> <tr class="fw-bold"> <td>Meter Id</td> <td>Meter #</td> <td>Make</td> <td>Model</td> <td>Meter Size</td> </tr> @foreach (DataRow drWaterMeter in Model.dsWaterMeters.Tables[0].Rows!) { <tr> <td>@drWaterMeter[0].ToString()</td> <td>@drWaterMeter[1].ToString()</td> <td>@drWaterMeter[2].ToString()</td> <td>@drWaterMeter[3].ToString()</td> <td>@drWaterMeter[4].ToString()</td> </tr> } </table> <hr /> <p class="text-center"> <a asp-page="Create" class="stellar">Set Up a Water Meter</a> :: <a asp-page="Edit" class="stellar">Edit a Water Meter</a> :: <a asp-page="Details" class="stellar">View a Water Meter</a> :: <a asp-page="Delete" class="stellar">Delete a Water Meter</a> </p>
Customers
A customer is an entity (person, business, organization, etc) that consumes the services of a company, such as a water distribution company. In our application, we will create the types of webpages we created for water meters.
Practical Learning: Creating Customers Records
@page @using System.Data; @using System.Data.SqlClient; @model StellarWaterPoint1.Pages.Customers.CreateModel @{ ViewData["Title"] = "Customer"; bool bMeterFound = false; string? strCity = string.Empty; string? strState = string.Empty; string? strCounty = string.Empty; string? strAddress = string.Empty; string? strZIPCode = string.Empty; string? strMessage = string.Empty; string? strLastName = string.Empty; string? strFirstName = string.Empty; string? strMeterNumber = string.Empty; string? strMeterDetails = string.Empty; string? strAccountNumber = string.Empty; if (Request.HasFormContentType) { DataSet dsWaterMeters = new("WaterMetersSet"); strMeterNumber = Request.Form["txtMeterNumber"]; strAccountNumber = Request.Form["txtAccountNumber"]; strMeterNumber = Request.Form["txtMeterNumber"]; strFirstName = Request.Form["txtFirstName"]; strLastName = Request.Form["txtLastName"]; strAddress = Request.Form["txtAddress"]; strCity = Request.Form["txtCity"]; strCounty = Request.Form["txtCounty"]; strState = Request.Form["txtState"]; strZIPCode = Request.Form["txtZIPCode"]; if (Request.Form["btnFindWaterMeter"] == "Find Water Meter") { using (SqlConnection scWaterDistribution = new SqlConnection("Data Source=(local);" + "Initial Catalog='StellarWaterPoint1';" + "Integrated Security=True;")) { SqlCommand cmdWaterMeters = new SqlCommand("SELECT Make, Model, MeterSize " + "FROM WaterMeters " + "WHERE MeterNumber = N'" + strMeterNumber + "';", scWaterDistribution); scWaterDistribution.Open(); SqlDataAdapter sdaWaterMeters = new SqlDataAdapter(cmdWaterMeters); sdaWaterMeters.Fill(dsWaterMeters); foreach (DataRow drWaterMeter in dsWaterMeters.Tables[0].Rows!) { bMeterFound = true; strMeterDetails = drWaterMeter[0].ToString() + " " + drWaterMeter[1].ToString() + " (Meter Size: " + drWaterMeter[2].ToString() + ")"; break; } } if (bMeterFound == false) { strMessage = "There is no water meter with that number in our system."; } } if (Request.Form["btnSaveCustomer"] == "Save Customer Account") { using (SqlConnection scWaterDistribution = new SqlConnection("Data Source=(local);" + "Initial Catalog='StellarWaterPoint1';" + "Integrated Security=True;")) { strAccountNumber = Request.Form["txtAccountNumber"]; strMeterNumber = Request.Form["txtMeterNumber"]; strFirstName = Request.Form["txtFirstName"]; strLastName = Request.Form["txtLastName"]; strAddress = Request.Form["txtAddress"]; strCity = Request.Form["txtCity"]; strCounty = Request.Form["txtCounty"]; strState = Request.Form["txtState"]; strZIPCode = Request.Form["txtZIPCode"]; SqlCommand cmdWaterMeters = new SqlCommand("INSERT INTO Customers(AccountNumber, MeterNumber, " + " FirstName, LastName, Address, " + " City, County, State, ZIPCode) " + "VALUES(N'" + strAccountNumber + "', N'" + strMeterNumber + "', N'" + strFirstName + "', N'" + strLastName + "', N'" + strAddress + "', N'" + strCity + "', N'" + strCounty + "', N'" + strState + "', N'" + strZIPCode + "');", scWaterDistribution); scWaterDistribution.Open(); cmdWaterMeters.ExecuteNonQuery(); } Response.Redirect("Index"); } } } <h1 class="common-font fw-bold text-center">Create Customer Account</h1> <hr /> <form method="post" class="common-font encloser"> <div class="row mb-2"> <label for="txtAccountNumber" class="col-form-label col-md-3 fw-bold">Account #</label> <div class="col-md-9"> <input name="txtAccountNumber" class="form-control" value="@strAccountNumber" /> </div> </div> <div class="row mb-2"> <label for="txtMeterNumber" class="col-form-label col-md-3 fw-bold">Meter #</label> <div class="col-md-4"> <input name="txtMeterNumber" class="form-control" value="@strMeterNumber" /> </div> <div class="col-md-4"> <input type="submit" name="btnFindWaterMeter" value="Find Water Meter" class="btn btn-primary" /> </div> </div> <div class="row mb-2"> <label for="txtMeterDetails" class="col-form-label col-md-3 fw-bold">Meter Details</label> <div class="col-md-9"> <input name="txtMeterDetails" class="form-control" value="@strMeterDetails" /> </div> </div> <div class="row mb-2"> <label for="txtFirstName" class="col-form-label col-md-3 fw-bold">First Name</label> <div class="col-md-9"> <input name="txtFirstName" class="form-control" value="@strFirstName" /> </div> </div> <div class="row mb-2"> <label for="txtLastName" class="col-form-label col-md-3 fw-bold">Last Name</label> <div class="col-md-9"> <input name="txtLastName" class="form-control" value="@strLastName" /> </div> </div> <div class="row mb-2"> <label for="txtAddress" class="col-form-label col-md-3 fw-bold">Address</label> <div class="col-md-9"> <input name="txtAddress" class="form-control" value="@strAddress" /> </div> </div> <div class="row mb-2"> <label for="txtCity" class="col-form-label col-md-3 fw-bold">City</label> <div class="col-md-9"> <input name="txtCity" class="form-control" value="@strCity" /> </div> </div> <div class="row mb-2"> <label for="txtCounty" class="col-form-label col-md-3 fw-bold">County</label> <div class="col-md-9"> <input name="txtCounty" class="form-control" value="@strCounty" /> </div> </div> <div class="row mb-2"> <label for="txtState" class="col-form-label col-md-3 fw-bold">State</label> <div class="col-md-9"> <input name="txtState" class="form-control" value="@strState" /> </div> </div> <div class="row mb-2"> <label for="txtZIPCode" class="col-form-label col-md-3 fw-bold">ZIP-Code</label> <div class="col-md-9"> <input name="txtZIPCode" class="form-control" value="@strZIPCode" /> </div> </div> <hr /> <div class="row mb-2"> <div class="col-md-5 col-form-label"> <a asp-page="Index">Customers Accounts</a> </div> <div class="col-md-7"> <input type="submit" name="btnSaveCustomer" value="Save Customer Account" class="btn btn-primary" /> </div> </div> </form> <hr /> <p class="text-center"> <a asp-page="./Details" class="stellar">Review a Customer's Account</a> :: <a asp-page="./Edit" class="stellar">Edit/Update a Customer's Account</a> :: <a asp-page="./Delete" class="stellar">Delete a Customer's Account</a> </p>
@page @using System.Data; @using System.Data.SqlClient; @model StellarWaterPoint1.Pages.Customers.DetailsModel @{ ViewData["Title"] = "Customer"; bool bCustomerFound = false; string? strCity = string.Empty; string? strState = string.Empty; string? strCounty = string.Empty; string? strAddress = string.Empty; string? strZIPCode = string.Empty; string? strMessage = string.Empty; string? strLastName = string.Empty; string? strFirstName = string.Empty; string? strCustomerId = string.Empty; string? strMeterNumber = string.Empty; string? strMeterDetails = string.Empty; string? strAccountNumber = string.Empty; if (Request.HasFormContentType) { DataSet dsWaterMeters = new("WaterMetersSet"); DataSet dsCustomers = new("CustomersSet"); strAccountNumber = Request.Form["txtAccountNumber"]; using (SqlConnection scWaterDistribution = new SqlConnection("Data Source=(local);" + "Initial Catalog='StellarWaterPoint1';" + "Integrated Security=True;")) { SqlCommand cmdCustomers = new SqlCommand("SELECT CustomerId, " + " MeterNumber, " + " FirstName, " + " LastName, " + " Address, " + " City, " + " County, " + " State, " + " ZIPCode " + "FROM Customers " + "WHERE AccountNumber = N'" + strAccountNumber + "';", scWaterDistribution); scWaterDistribution.Open(); SqlDataAdapter sdaCustomers = new SqlDataAdapter(cmdCustomers); sdaCustomers.Fill(dsCustomers); foreach (DataRow drCustomer in dsCustomers.Tables[0].Rows!) { bCustomerFound = true; strCustomerId = drCustomer[0].ToString(); strMeterNumber = drCustomer[1].ToString(); strFirstName = drCustomer[2].ToString(); strLastName = drCustomer[3].ToString(); strAddress = drCustomer[4].ToString(); strCity = drCustomer[5].ToString(); strCounty = drCustomer[6].ToString(); strState = drCustomer[7].ToString(); strZIPCode = drCustomer[8].ToString(); break; } } if (bCustomerFound == false) { strMessage = "There is no customer account with that number in our system."; } else { using (SqlConnection scWaterDistribution = new SqlConnection("Data Source=(local);" + "Initial Catalog='StellarWaterPoint1';" + "Integrated Security=True;")) { SqlCommand cmdWaterMeters = new SqlCommand("SELECT Make, Model, MeterSize " + "FROM WaterMeters " + "WHERE MeterNumber = N'" + strMeterNumber + "';", scWaterDistribution); scWaterDistribution.Open(); SqlDataAdapter sdaWaterMeters = new SqlDataAdapter(cmdWaterMeters); sdaWaterMeters.Fill(dsWaterMeters); foreach (DataRow drWaterMeter in dsWaterMeters.Tables[0].Rows!) { bCustomerFound = true; strMeterDetails = drWaterMeter[0].ToString() + " " + drWaterMeter[1].ToString() + " (Meter Size: " + drWaterMeter[2].ToString() + ")"; break; } } } } } <h1 class="common-font fw-bold text-center">View Customer Account</h1> <hr /> <form method="post" class="common-font encloser"> <div class="row mb-2"> <label for="txtAccountNumber" class="col-form-label col-md-3 fw-bold">Account #</label> <div class="col-md-4 text-center"> <input name="txtAccountNumber" class="form-control" value="@strAccountNumber" /> </div> <div class="col-md-4"> <input type="submit" name="btnFindCustomerAccount" value="Find Customer Account" class="btn btn-primary" /> </div> </div> <div class="row mb-2"> <label for="txtMeterDetails" class="col-form-label col-md-3 fw-bold">Meter Details</label> <div class="col-md-9"> <input name="txtMeterDetails" class="form-control" value="@strMeterDetails" /> </div> </div> <div class="row mb-2"> <label for="txtFirstName" class="col-form-label col-md-3 fw-bold">First Name</label> <div class="col-md-9"> <input name="txtFirstName" class="form-control" value="@strFirstName" /> </div> </div> <div class="row mb-2"> <label for="txtLastName" class="col-form-label col-md-3 fw-bold">Last Name</label> <div class="col-md-9"> <input name="txtLastName" class="form-control" value="@strLastName" /> </div> </div> <div class="row mb-2"> <label for="txtAddress" class="col-form-label col-md-3 fw-bold">Address</label> <div class="col-md-9"> <input name="txtAddress" class="form-control" value="@strAddress" /> </div> </div> <div class="row mb-2"> <label for="txtCity" class="col-form-label col-md-3 fw-bold">City</label> <div class="col-md-9"> <input name="txtCity" class="form-control" value="@strCity" /> </div> </div> <div class="row mb-2"> <label for="txtCounty" class="col-form-label col-md-3 fw-bold">County</label> <div class="col-md-9"> <input name="txtCounty" class="form-control" value="@strCounty" /> </div> </div> <div class="row mb-2"> <label for="txtState" class="col-form-label col-md-3 fw-bold">State</label> <div class="col-md-9"> <input name="txtState" class="form-control" value="@strState" /> </div> </div> <div class="row mb-2"> <label for="txtZIPCode" class="col-form-label col-md-3 fw-bold">ZIP-Code</label> <div class="col-md-9"> <input name="txtZIPCode" class="form-control" value="@strZIPCode" /> </div> </div> <hr /> <div class="row mb-2"> <div class="col-md-5 col-form-label"> </div> <div class="col-md-7"> <a asp-page="Index">Customers Accounts</a> </div> </div> </form> <hr /> <p class="text-center"> <a asp-page="./Create" class="stellar">Create a New Customer's Account</a> :: <a asp-page="./Edit" class="stellar">Edit/Update a Customer's Account</a> :: <a asp-page="./Delete" class="stellar">Delete a Customer's Account</a> </p>
@page @using System.Data; @using System.Data.SqlClient; @model StellarWaterPoint1.Pages.Customers.EditModel @{ ViewData["Title"] = "Update Customer Account"; bool bMeterFound = false; bool bCustomerFound = false; string? strCity = string.Empty; string? strState = string.Empty; string? strCounty = string.Empty; string? strAddress = string.Empty; string? strZIPCode = string.Empty; string? strMessage = string.Empty; string? strLastName = string.Empty; string? strFirstName = string.Empty; string? strMeterNumber = string.Empty; string? strMeterDetails = string.Empty; string? strAccountNumber = string.Empty; if (Request.HasFormContentType) { DataSet dsCustomers = new("CustomersSet"); DataSet dsWaterMeters = new("WaterMetersSet"); strMeterNumber = Request.Form["txtMeterNumber"]; strAccountNumber = Request.Form["txtAccountNumber"]; strMeterNumber = Request.Form["txtMeterNumber"]; strFirstName = Request.Form["txtFirstName"]; strLastName = Request.Form["txtLastName"]; strAddress = Request.Form["txtAddress"]; strCity = Request.Form["txtCity"]; strCounty = Request.Form["txtCounty"]; strState = Request.Form["txtState"]; strZIPCode = Request.Form["txtZIPCode"]; strAccountNumber = Request.Form["txtAccountNumber"]; if (Request.Form["btnFindCustomerAccount"] == "Find Customer Account") { using (SqlConnection scWaterDistribution = new SqlConnection("Data Source=(local);" + "Initial Catalog='StellarWaterPoint1';" + "Integrated Security=True;")) { SqlCommand cmdCustomers = new SqlCommand("SELECT MeterNumber, " + " FirstName, " + " LastName, " + " Address, " + " City, " + " County, " + " State, " + " ZIPCode " + "FROM Customers " + "WHERE AccountNumber = N'" + strAccountNumber + "';", scWaterDistribution); scWaterDistribution.Open(); SqlDataAdapter sdaCustomers = new SqlDataAdapter(cmdCustomers); sdaCustomers.Fill(dsCustomers); foreach (DataRow drCustomer in dsCustomers.Tables[0].Rows!) { bCustomerFound = true; strMeterNumber = drCustomer[0].ToString(); strFirstName = drCustomer[1].ToString(); strLastName = drCustomer[2].ToString(); strAddress = drCustomer[3].ToString(); strCity = drCustomer[4].ToString(); strCounty = drCustomer[5].ToString(); strState = drCustomer[6].ToString(); strZIPCode = drCustomer[7].ToString(); break; } } if(bCustomerFound == false) { strMessage = "There is no customer account with that number in our system."; } else { using (SqlConnection scWaterDistribution = new SqlConnection("Data Source=(local);" + "Initial Catalog='StellarWaterPoint1';" + "Integrated Security=True;")) { SqlCommand cmdWaterMeters = new SqlCommand("SELECT Make, Model, MeterSize " + "FROM WaterMeters " + "WHERE MeterNumber = N'" + strMeterNumber + "';", scWaterDistribution); scWaterDistribution.Open(); SqlDataAdapter sdaWaterMeters = new SqlDataAdapter(cmdWaterMeters); sdaWaterMeters.Fill(dsWaterMeters); foreach (DataRow drWaterMeter in dsWaterMeters.Tables[0].Rows!) { bCustomerFound = true; strMeterDetails = drWaterMeter[0].ToString() + " " + drWaterMeter[1].ToString() + " (Meter Size: " + drWaterMeter[2].ToString() + ")"; break; } } } } if (Request.Form["btnFindWaterMeter"] == "Find Water Meter") { strMeterNumber = Request.Form["txtMeterNumber"]; using (SqlConnection scWaterDistribution = new SqlConnection("Data Source=(local);" + "Initial Catalog='StellarWaterPoint1';" + "Integrated Security=True;")) { SqlCommand cmdWaterMeters = new SqlCommand("SELECT Make, Model, MeterSize " + "FROM WaterMeters " + "WHERE MeterNumber = N'" + strMeterNumber + "';", scWaterDistribution); scWaterDistribution.Open(); SqlDataAdapter sdaWaterMeters = new SqlDataAdapter(cmdWaterMeters); sdaWaterMeters.Fill(dsWaterMeters); foreach (DataRow drWaterMeter in dsWaterMeters.Tables[0].Rows!) { bMeterFound = true; strMeterDetails = drWaterMeter[0].ToString() + " " + drWaterMeter[1].ToString() + " (Meter Size: " + drWaterMeter[2].ToString() + ")"; break; } } if (bMeterFound == false) { strMessage = "There is no water meter with that number in our system."; } } if (Request.Form["btnUpdateCustomerAccount"] == "Update Customer Account") { using (SqlConnection scWaterDistribution = new SqlConnection("Data Source=(local);" + "Initial Catalog='StellarWaterPoint1';" + "Integrated Security=True;")) { strAccountNumber = Request.Form["txtAccountNumber"]; strMeterNumber = Request.Form["txtMeterNumber"]; strFirstName = Request.Form["txtFirstName"]; strLastName = Request.Form["txtLastName"]; strAddress = Request.Form["txtAddress"]; strCity = Request.Form["txtCity"]; strCounty = Request.Form["txtCounty"]; strState = Request.Form["txtState"]; strZIPCode = Request.Form["txtZIPCode"]; SqlCommand cmdWaterMeters = new SqlCommand("UPDATE Customers SET MeterNumber = N'" + strMeterNumber + "' WHERE AccountNumber = N'" + strAccountNumber + "';" + "UPDATE Customers SET FirstName = N'" + strFirstName + "' WHERE AccountNumber = N'" + strAccountNumber + "';" + "UPDATE Customers SET LastName = N'" + strLastName + "' WHERE AccountNumber = N'" + strAccountNumber + "';" + "UPDATE Customers SET Address = N'" + strAddress + "' WHERE AccountNumber = N'" + strAccountNumber + "';" + "UPDATE Customers SET City = N'" + strCity + "' WHERE AccountNumber = N'" + strAccountNumber + "';" + "UPDATE Customers SET County = N'" + strCounty + "' WHERE AccountNumber = N'" + strAccountNumber + "';" + "UPDATE Customers SET State = N'" + strState + "' WHERE AccountNumber = N'" + strAccountNumber + "';" + "UPDATE Customers SET ZIPCode = N'" + strZIPCode + "' WHERE AccountNumber = N'" + strAccountNumber + "';", scWaterDistribution); scWaterDistribution.Open(); cmdWaterMeters.ExecuteNonQuery(); } Response.Redirect("Index"); } } } <h1 class="common-font fw-bold text-center">Edit/Update Customer Account</h1> <hr /> <form method="post" class="common-font encloser"> <div class="row mb-2"> <label for="txtAccountNumber" class="col-form-label col-md-3 fw-bold">Account #</label> <div class="col-md-4 text-center"> <input name="txtAccountNumber" class="form-control" value="@strAccountNumber" /> </div> <div class="col-md-4"> <input type="submit" name="btnFindCustomerAccount" value="Find Customer Account" class="btn btn-primary" /> </div> </div> <div class="row mb-2"> <label for="txtMeterNumber" class="col-form-label col-md-3 fw-bold">Meter #</label> <div class="col-md-4"> <input name="txtMeterNumber" class="form-control" value="@strMeterNumber" /> </div> <div class="col-md-4"> <input type="submit" name="btnFindWaterMeter" value="Find Water Meter" class="btn btn-primary" /> </div> </div> <div class="row mb-2"> <label for="txtMeterDetails" class="col-form-label col-md-3 fw-bold">Meter Details</label> <div class="col-md-9"> <input name="txtMeterDetails" class="form-control" value="@strMeterDetails" /> </div> </div> <div class="row mb-2"> <label for="txtFirstName" class="col-form-label col-md-3 fw-bold">First Name</label> <div class="col-md-9"> <input name="txtFirstName" class="form-control" value="@strFirstName" /> </div> </div> <div class="row mb-2"> <label for="txtLastName" class="col-form-label col-md-3 fw-bold">Last Name</label> <div class="col-md-9"> <input name="txtLastName" class="form-control" value="@strLastName" /> </div> </div> <div class="row mb-2"> <label for="txtAddress" class="col-form-label col-md-3 fw-bold">Address</label> <div class="col-md-9"> <input name="txtAddress" class="form-control" value="@strAddress" /> </div> </div> <div class="row mb-2"> <label for="txtCity" class="col-form-label col-md-3 fw-bold">City</label> <div class="col-md-9"> <input name="txtCity" class="form-control" value="@strCity" /> </div> </div> <div class="row mb-2"> <label for="txtCounty" class="col-form-label col-md-3 fw-bold">County</label> <div class="col-md-9"> <input name="txtCounty" class="form-control" value="@strCounty" /> </div> </div> <div class="row mb-2"> <label for="txtState" class="col-form-label col-md-3 fw-bold">State</label> <div class="col-md-9"> <input name="txtState" class="form-control" value="@strState" /> </div> </div> <div class="row mb-2"> <label for="txtZIPCode" class="col-form-label col-md-3 fw-bold">ZIP-Code</label> <div class="col-md-9"> <input name="txtZIPCode" class="form-control" value="@strZIPCode" /> </div> </div> <hr /> <div class="row mb-2"> <div class="col-md-5 col-form-label"> <a asp-page="Index">Customers Accounts</a> </div> <div class="col-md-7"> <input type="submit" name="btnUpdateCustomerAccount" value="Update Customer Account" class="btn btn-primary" /> </div> </div> </form> <hr /> <p class="text-center"> <a asp-page="./Details" class="stellar">Review a Customer's Account</a> :: <a asp-page="./Edit" class="stellar">Edit/Update a Customer's Account</a> :: <a asp-page="./Delete" class="stellar">Delete a Customer's Account</a> </p>
@page @using System.Data; @using System.Data.SqlClient; @model StellarWaterPoint1.Pages.Customers.DeleteModel @{ ViewData["Title"] = "Customer Deletion"; bool bCustomerFound = false; string? strCity = string.Empty; string? strState = string.Empty; string? strCounty = string.Empty; string? strAddress = string.Empty; string? strZIPCode = string.Empty; string? strMessage = string.Empty; string? strLastName = string.Empty; string? strFirstName = string.Empty; string? strMeterNumber = string.Empty; string? strMeterDetails = string.Empty; string? strAccountNumber = string.Empty; if (Request.HasFormContentType) { DataSet dsWaterMeters = new("WaterMetersSet"); DataSet dsCustomers = new("CustomersSet"); strMeterNumber = Request.Form["txtMeterNumber"]; strAccountNumber = Request.Form["txtAccountNumber"]; strMeterNumber = Request.Form["txtMeterNumber"]; strFirstName = Request.Form["txtFirstName"]; strLastName = Request.Form["txtLastName"]; strAddress = Request.Form["txtAddress"]; strCity = Request.Form["txtCity"]; strCounty = Request.Form["txtCounty"]; strState = Request.Form["txtState"]; strZIPCode = Request.Form["txtZIPCode"]; strAccountNumber = Request.Form["txtAccountNumber"]; if (Request.Form["btnFindCustomerAccount"] == "Find Customer Account") { using (SqlConnection scWaterDistribution = new SqlConnection("Data Source=(local);" + "Initial Catalog='StellarWaterPoint1';" + "Integrated Security=True;")) { SqlCommand cmdCustomers = new SqlCommand("SELECT MeterNumber, " + " FirstName, " + " LastName, " + " Address, " + " City, " + " County, " + " State, " + " ZIPCode " + "FROM Customers " + "WHERE AccountNumber = N'" + strAccountNumber + "';", scWaterDistribution); scWaterDistribution.Open(); SqlDataAdapter sdaCustomers = new SqlDataAdapter(cmdCustomers); sdaCustomers.Fill(dsCustomers); foreach (DataRow drCustomer in dsCustomers.Tables[0].Rows!) { bCustomerFound = true; strMeterNumber = drCustomer[0].ToString(); strFirstName = drCustomer[1].ToString(); strLastName = drCustomer[2].ToString(); strAddress = drCustomer[3].ToString(); strCity = drCustomer[4].ToString(); strCounty = drCustomer[5].ToString(); strState = drCustomer[6].ToString(); strZIPCode = drCustomer[7].ToString(); break; } } if (bCustomerFound == false) { strMessage = "There is no customer account with that number in our system."; } else { using (SqlConnection scWaterDistribution = new SqlConnection("Data Source=(local);" + "Initial Catalog='StellarWaterPoint1';" + "Integrated Security=True;")) { SqlCommand cmdWaterMeters = new SqlCommand("SELECT Make, Model, MeterSize " + "FROM WaterMeters " + "WHERE MeterNumber = N'" + strMeterNumber + "';", scWaterDistribution); scWaterDistribution.Open(); SqlDataAdapter sdaWaterMeters = new SqlDataAdapter(cmdWaterMeters); sdaWaterMeters.Fill(dsWaterMeters); foreach (DataRow drWaterMeter in dsWaterMeters.Tables[0].Rows!) { bCustomerFound = true; strMeterDetails = drWaterMeter[0].ToString() + " " + drWaterMeter[1].ToString() + " (Meter Size: " + drWaterMeter[2].ToString() + ")"; break; } } } } if (Request.Form["btnDeleteCustomerAccount"] == "Delete Customer Account") { using (SqlConnection scWaterDistribution = new SqlConnection("Data Source=(local);" + "Initial Catalog='StellarWaterPoint1';" + "Integrated Security=True;")) { /* strAccountNumber = Request.Form["txtAccountNumber"]; strMeterNumber = Request.Form["txtMeterNumber"]; strFirstName = Request.Form["txtFirstName"]; strLastName = Request.Form["txtLastName"]; strAddress = Request.Form["txtAddress"]; strCity = Request.Form["txtCity"]; strCounty = Request.Form["txtCounty"]; strState = Request.Form["txtState"]; strZIPCode = Request.Form["txtZIPCode"]; */ SqlCommand cmdWaterMeters = new SqlCommand("DELETE Customers WHERE AccountNumber = N'" + strAccountNumber + "';", scWaterDistribution); scWaterDistribution.Open(); cmdWaterMeters.ExecuteNonQuery(); } Response.Redirect("Index"); } } } <h1 class="common-font fw-bold text-center">Delete Customer Account</h1> <hr /> <form method="post" class="common-font encloser"> <div class="row mb-2"> <label for="txtAccountNumber" class="col-form-label col-md-3 fw-bold">Account #</label> <div class="col-md-4 text-center"> <input name="txtAccountNumber" class="form-control" value="@strAccountNumber" /> </div> <div class="col-md-4"> <input type="submit" name="btnFindCustomerAccount" value="Find Customer Account" class="btn btn-primary" /> </div> </div> <div class="row mb-2"> <label for="txtMeterDetails" class="col-form-label col-md-3 fw-bold">Meter Details</label> <div class="col-md-9"> <input name="txtMeterDetails" class="form-control" value="@strMeterDetails" /> </div> </div> <div class="row mb-2"> <label for="txtFirstName" class="col-form-label col-md-3 fw-bold">First Name</label> <div class="col-md-9"> <input name="txtFirstName" class="form-control" value="@strFirstName" /> </div> </div> <div class="row mb-2"> <label for="txtLastName" class="col-form-label col-md-3 fw-bold">Last Name</label> <div class="col-md-9"> <input name="txtLastName" class="form-control" value="@strLastName" /> </div> </div> <div class="row mb-2"> <label for="txtAddress" class="col-form-label col-md-3 fw-bold">Address</label> <div class="col-md-9"> <input name="txtAddress" class="form-control" value="@strAddress" /> </div> </div> <div class="row mb-2"> <label for="txtCity" class="col-form-label col-md-3 fw-bold">City</label> <div class="col-md-9"> <input name="txtCity" class="form-control" value="@strCity" /> </div> </div> <div class="row mb-2"> <label for="txtCounty" class="col-form-label col-md-3 fw-bold">County</label> <div class="col-md-9"> <input name="txtCounty" class="form-control" value="@strCounty" /> </div> </div> <div class="row mb-2"> <label for="txtState" class="col-form-label col-md-3 fw-bold">State</label> <div class="col-md-9"> <input name="txtState" class="form-control" value="@strState" /> </div> </div> <div class="row mb-2"> <label for="txtZIPCode" class="col-form-label col-md-3 fw-bold">ZIP-Code</label> <div class="col-md-9"> <input name="txtZIPCode" class="form-control" value="@strZIPCode" /> </div> </div> <hr /> <div class="row mb-2"> <div class="col-md-5 col-form-label"> <a asp-page="Index">Customers Accounts</a> </div> <div class="col-md-7"> <input type="submit" name="btnDeleteCustomerAccount" value="Delete Customer Account" class="btn btn-primary" /> </div> </div> </form> <hr /> <p class="text-center"> <a asp-page="./Details" class="stellar">Review a Customer's Account</a> :: <a asp-page="./Edit" class="stellar">Edit/Update a Customer's Account</a> :: <a asp-page="./Delete" class="stellar">Delete a Customer's Account</a> </p>
using Microsoft.AspNetCore.Mvc.RazorPages; using System.Data; using System.Data.SqlClient; namespace StellarWaterPoint1.Pages.Customers { public class IndexModel : PageModel { public DataSet dsCustomers = new DataSet("CustomersSet"); public void OnGet() { using (SqlConnection scWaterDistribution = new SqlConnection("Data Source=(local);" + "Initial Catalog='StellarWaterPoint1';" + "Integrated Security=True;")) { SqlCommand cmdCustomers = new SqlCommand("SELECT CustomerId, " + " AccountNumber, " + " MeterNumber, " + " FirstName, " + " LastName, " + " Address, " + " City, " + " County, " + " State, " + " ZIPCode " + "FROM Customers; ", scWaterDistribution); scWaterDistribution.Open(); SqlDataAdapter sdaCustomers = new SqlDataAdapter(cmdCustomers); sdaCustomers.Fill(dsCustomers); } } } }
@page @using System.Data @model StellarWaterPoint1.Pages.Customers.IndexModel @{ } <h1 class="common-font fw-bold text-center">Customers Accounts</h1> <hr /> <table class="table common-font"> <tr class="fw-bold"> <td>Customer Id</td> <td>Meter #</td> <td>Account #</td> <td>First Name</td> <td>Last Name</td> <td>Address</td> <td>City</td> <td>County</td> <td>State</td> <td>ZIP-Code</td> </tr> @foreach (DataRow drCustomer in Model.dsCustomers.Tables[0].Rows!) { <tr> <td>@drCustomer[0].ToString()</td> <td>@drCustomer[1].ToString()</td> <td>@drCustomer[2].ToString()</td> <td>@drCustomer[3].ToString()</td> <td>@drCustomer[4].ToString()</td> <td>@drCustomer[5].ToString()</td> <td>@drCustomer[6].ToString()</td> <td>@drCustomer[7].ToString()</td> <td>@drCustomer[8].ToString()</td> <td>@drCustomer[9].ToString()</td> </tr> } </table> <hr /> <p class="text-center"> <a asp-page="Create" class="stellar">Create Customer Account</a> :: <a asp-page="Edit" class="stellar">Edit Customer Account</a> :: <a asp-page="Details" class="stellar">View Customer Account</a> :: <a asp-page="Delete" class="stellar">Delete a Customer Account</a> </p>
Water Bills
A water bill is a summery of the amount of water a customer has consumed, the amount to pay for that consumption, and the dates related to that bill. For our application, we will create a webpage that contains a form to create a water bill. We will create a webpage that contains a form that allows an employee to review a water bill. We will create a webpage that contains a form that allows an employee to review and edit or update a water bill. We will create a webpage that contains a form that allows an employee to delete a water bill.
Practical Learning: Creating Water Bills
@page @using System.Data; @using System.Data.SqlClient; @model StellarWaterPoint61.Pages.WaterBills.CreateModel @{ ViewData["Title"] = "Water Bill Processing"; bool bCustomerFound = false; string? strMessage = string.Empty; string? strMeterNumber = string.Empty; string? strMeterDetails = string.Empty; string? strCity = string.Empty; string? strState = string.Empty; string? strCounty = string.Empty; string? strZIPCode = string.Empty; string? strAddress = string.Empty; string? strBillNumber = string.Empty; string? strBillingDays = string.Empty; string? strCustomerName = string.Empty; string? strAccountNumber = string.Empty; string? strCounterReadingEnd = string.Empty; string? strCounterReadingStart = string.Empty; string? strMeterReadingEndDate = string.Empty; string? strMeterReadingStartDate = string.Empty; string? strTotalCCF = string.Empty; string? strTotalGallons = string.Empty; string? strFirstTierConsumption = string.Empty; string? strSecondTierConsumption = string.Empty; string? strLastTierConsumption = string.Empty; string? strWaterCharges = string.Empty; string? strSewerCharges = string.Empty; string? strEnvironmentCharges = string.Empty; string? strTotalCharges = string.Empty; string? strLocalTaxes = string.Empty; string? strStateTaxes = string.Empty; string? strPaymentDueDate = string.Empty; string? strAmountDue = string.Empty; string? strLatePaymentDueDate = string.Empty; string? strLateAmountDue = string.Empty; if (Request.HasFormContentType) { DataSet dsCustomers = new("CustomersSet"); DataSet dsWaterBills = new("WaterBillsSet"); DataSet dsWaterMeters = new("WaterMetersSet"); strAccountNumber = Request.Form["txtAccountNumber"]; strMeterNumber = Request.Form["txtMeterNumber"]; strAccountNumber = Request.Form["txtAccountNumber"]; strMeterNumber = Request.Form["txtMeterNumber"]; strCustomerName = Request.Form["txtCustomerName"]; strAddress = Request.Form["txtAddress"]; strCity = Request.Form["txtCity"]; strCounty = Request.Form["txtCounty"]; strState = Request.Form["txtState"]; strZIPCode = Request.Form["txtZIPCode"]; strMeterReadingStartDate = Request.Form["txtMeterReadingStartDate"]; strMeterReadingEndDate = Request.Form["txtMeterReadingEndDate"]; strCounterReadingStart = Request.Form["txtCounterReadingStart"]; strCounterReadingEnd = Request.Form["txtCounterReadingEnd"]; strBillingDays = Request.Form["txtBillingDays"]; strTotalCCF = Request.Form["txtTotalCCF"]; strTotalGallons = Request.Form["txtTotalGallons"]; strFirstTierConsumption = Request.Form["txtFirstTierConsumption"]; strSecondTierConsumption = Request.Form["txtSecondTierConsumption"]; strLastTierConsumption = Request.Form["txtLastTierConsumption"]; strWaterCharges = Request.Form["txtWaterCharges"]; strSewerCharges = Request.Form["txtSewerCharges"]; strEnvironmentCharges = Request.Form["txtEnvironmentCharges"]; strTotalCharges = Request.Form["txtTotalCharges"]; strLocalTaxes = Request.Form["txtLocalTaxes"]; strStateTaxes = Request.Form["txtStateTaxes"]; strPaymentDueDate = Request.Form["txtPaymentDueDate"]; strAmountDue = Request.Form["txtAmountDue"]; strLatePaymentDueDate = Request.Form["txtLatePaymentDueDate"]; strLateAmountDue = Request.Form["txtLateAmountDue"]; if (Request.Form["btnFindCustomerAccount"] == "Find Customer Account") { strBillNumber = Request.Form["txtBillNumber"]; strMeterNumber = Request.Form["txtMeterNumber"]; strMeterDetails = Request.Form["txtMeterDetails"]; strPaymentDueDate = Request.Form["txtPaymentDueDate"]; strAmountDue = Request.Form["txtAmountDue"]; strLatePaymentDueDate = Request.Form["txtLatePaymentDueDate"]; strLateAmountDue = Request.Form["txtLateAmountDue"]; using (SqlConnection scWaterDistribution = new SqlConnection("Data Source=(local);" + "Initial Catalog='StellarWaterPoint1';" + "Integrated Security=True;")) { SqlCommand cmdCustomers = new SqlCommand("SELECT MeterNumber, " + " FirstName, " + " LastName, " + " Address, " + " City, " + " County, " + " State, " + " ZIPCode " + "FROM Customers " + "WHERE AccountNumber = N'" + strAccountNumber + "';", scWaterDistribution); scWaterDistribution.Open(); SqlDataAdapter sdaCustomers = new SqlDataAdapter(cmdCustomers); sdaCustomers.Fill(dsCustomers); foreach (DataRow drCustomer in dsCustomers.Tables[0].Rows!) { bCustomerFound = true; strMeterNumber = drCustomer[0].ToString(); strCustomerName = drCustomer[1].ToString() + " " + drCustomer[2].ToString(); strAddress = drCustomer[3].ToString(); strCity = drCustomer[4].ToString(); strCounty = drCustomer[5].ToString(); strState = drCustomer[6].ToString(); strZIPCode = drCustomer[7].ToString(); break; } } if (bCustomerFound == false) { strMessage = "There is no customer account with that number in our system."; } else { using (SqlConnection scWaterDistribution = new SqlConnection("Data Source=(local);" + "Initial Catalog='StellarWaterPoint1';" + "Integrated Security=True;")) { SqlCommand cmdWaterMeters = new SqlCommand("SELECT Make, Model, MeterSize " + "FROM WaterMeters " + "WHERE MeterNumber = N'" + strMeterNumber + "';", scWaterDistribution); scWaterDistribution.Open(); SqlDataAdapter sdaWaterMeters = new SqlDataAdapter(cmdWaterMeters); sdaWaterMeters.Fill(dsWaterMeters); foreach (DataRow drWaterMeter in dsWaterMeters.Tables[0].Rows!) { strMeterDetails = drWaterMeter[0].ToString() + " " + drWaterMeter[1].ToString() + " (Meter Size: " + drWaterMeter[2].ToString() + ")"; break; } } } if (Request.Form["btnFindWaterMeter"] == "Find Water Meter") { strMeterNumber = Request.Form["txtMeterNumber"]; using (SqlConnection scWaterDistribution = new SqlConnection("Data Source=(local);" + "Initial Catalog='StellarWaterPoint1';" + "Integrated Security=True;")) { SqlCommand cmdWaterMeters = new SqlCommand("SELECT Make, Model, MeterSize " + "FROM WaterMeters " + "WHERE MeterNumber = N'" + strMeterNumber + "';", scWaterDistribution); scWaterDistribution.Open(); SqlDataAdapter sdaWaterMeters = new SqlDataAdapter(cmdWaterMeters); sdaWaterMeters.Fill(dsWaterMeters); foreach (DataRow drWaterMeter in dsWaterMeters.Tables[0].Rows!) { strMeterDetails = drWaterMeter[0].ToString() + " " + drWaterMeter[1].ToString() + " (Meter Size: " + drWaterMeter[2].ToString() + ")"; break; } } } } if (Request.Form["btnEvaluateWaterBill"] == "Evaluate Water Bill") { strBillNumber = Request.Form["txtBillNumber"]; strMeterNumber = Request.Form["txtMeterNumber"]; strCustomerName = Request.Form["txtCustomerName"]; strAddress = Request.Form["txtAddress"]; strCity = Request.Form["txtCity"]; strCounty = Request.Form["txtCounty"]; strState = Request.Form["txtState"]; strZIPCode = Request.Form["txtZIPCode"]; strMeterDetails = Request.Form["txtMeterDetails"]; strMeterReadingStartDate = Request.Form["txtMeterReadingStartDate"]; strMeterReadingEndDate = Request.Form["txtMeterReadingEndDate"]; strCounterReadingStart = Request.Form["txtCounterReadingStart"]; strCounterReadingEnd = Request.Form["txtCounterReadingEnd"]; strPaymentDueDate = Request.Form["txtPaymentDueDate"]; strAmountDue = Request.Form["txtAmountDue"]; strLatePaymentDueDate = Request.Form["txtLatePaymentDueDate"]; strLateAmountDue = Request.Form["txtLateAmountDue"]; TimeSpan tsDays = DateTime.Parse(strMeterReadingEndDate!) - DateTime.Parse(strMeterReadingStartDate!); strBillingDays = tsDays.Days.ToString(); string strCounterStart = Request.Form["txtCounterReadingStart"]!; string strCounterEnd = Request.Form["txtCounterReadingEnd"]!; double counterStart = double.Parse(strCounterStart); double counterEnd = double.Parse(strCounterEnd); double consumption = counterEnd - counterStart; double gallons = consumption * 748.05; double firstTier = gallons * (48.00 / 10000.00); double secondTier = gallons * (32.00 / 10000.00); double lastTier = gallons * (20.00 / 10000.00); double waterCharges = firstTier + secondTier + lastTier; double sewerCharges = waterCharges * 28.65 / 100; double envCharges = waterCharges * 0.22184; double totalCharges = waterCharges + sewerCharges + envCharges; double localTaxes = totalCharges * 0.06148; double stateTaxes = totalCharges * 0.01374; double amtDue = totalCharges + localTaxes + stateTaxes; TimeSpan tsPaymentDueDate = new TimeSpan(15, 0, 0, 0); strMeterReadingStartDate = Request.Form["txtMeterReadingStartDate"]; strMeterReadingEndDate = Request.Form["txtMeterReadingEndDate"]; DateTime dtPmtDueDate = DateTime.Parse(strMeterReadingEndDate!) + tsPaymentDueDate; TimeSpan tsLatePaymentDueDate = new TimeSpan(30, 0, 0, 0); DateTime dtLatePmtDueDate = DateTime.Parse(strMeterReadingEndDate!) + tsLatePaymentDueDate; strTotalCCF = consumption.ToString(); strTotalGallons = gallons.ToString("F"); strFirstTierConsumption = firstTier.ToString("F"); strSecondTierConsumption = secondTier.ToString("F"); strLastTierConsumption = lastTier.ToString("F"); strWaterCharges = waterCharges.ToString("F"); strSewerCharges = sewerCharges.ToString("F"); strEnvironmentCharges = envCharges.ToString("F"); strTotalCharges = totalCharges.ToString("F"); strLocalTaxes = localTaxes.ToString("F"); strStateTaxes = stateTaxes.ToString("F"); strAmountDue = amtDue.ToString("F"); strPaymentDueDate = dtPmtDueDate.ToLongDateString(); strLateAmountDue = (amtDue + 8.95).ToString("F"); strLatePaymentDueDate = dtLatePmtDueDate.ToLongDateString(); } if (Request.Form["btnSaveWaterBill"] == "Save Water Bill") { using (SqlConnection scWaterDistribution = new SqlConnection("Data Source=(local);" + "Initial Catalog='StellarWaterPoint1';" + "Integrated Security=True;")) { strAccountNumber = Request.Form["txtAccountNumber"]; strBillNumber = Request.Form["txtBillNumber"]; strMeterReadingStartDate = Request.Form["txtMeterReadingStartDate"]; strMeterReadingEndDate = Request.Form["txtMeterReadingEndDate"]; strBillingDays = Request.Form["txtBillingDays"]; strCounterReadingStart = Request.Form["txtCounterReadingStart"]; strCounterReadingEnd = Request.Form["txtCounterReadingEnd"]; strTotalCCF = Request.Form["txtTotalCCF"]; strTotalGallons = Request.Form["txtTotalGallons"]; strFirstTierConsumption = Request.Form["txtFirstTierConsumption"]; strSecondTierConsumption = Request.Form["txtSecondTierConsumption"]; strLastTierConsumption = Request.Form["txtLastTierConsumption"]; strWaterCharges = Request.Form["txtWaterCharges"]; strSewerCharges = Request.Form["txtSewerCharges"]; strEnvironmentCharges = Request.Form["txtEnvironmentCharges"]; strTotalCharges = Request.Form["txtTotalCharges"]; strLocalTaxes = Request.Form["txtLocalTaxes"]; strStateTaxes = Request.Form["txtStateTaxes"]; strPaymentDueDate = Request.Form["txtPaymentDueDate"]; strAmountDue = Request.Form["txtAmountDue"]; strLatePaymentDueDate = Request.Form["txtLatePaymentDueDate"]; strLateAmountDue = Request.Form["txtLateAmountDue"]; SqlCommand cmdWaterMeters = new SqlCommand("INSERT INTO WaterBills(AccountNumber, " + " BillNumber, " + " MeterReadingStartDate, " + " MeterReadingEndDate, " + " BillingDays, " + " CounterReadingStart, " + " CounterReadingEnd, " + " Consumption, " + " TotalGallons, " + " FirstTierConsumption, " + " SecondTierConsumption, " + " LastTierConsumption, " + " WaterCharges, " + " SewerCharges, " + " EnvironmentCharges, " + " TotalCharges, " + " LocalTaxes, " + " StateTaxes, " + " PaymentDueDate, " + " AmountDue, " + " LatePaymentDueDate, " + " LateAmountDue) " + " VALUES(N'" + strAccountNumber + "'," + " N'" + strBillNumber + "'," + " N'" + strMeterReadingStartDate + "'," + " N'" + strMeterReadingEndDate + "'," + " N'" + strBillingDays + "'," + " N'" + strCounterReadingStart + "'," + " N'" + strCounterReadingEnd + "'," + " N'" + strTotalCCF + "'," + " N'" + strTotalGallons + "'," + " N'" + strFirstTierConsumption + "'," + " N'" + strSecondTierConsumption + "'," + " N'" + strLastTierConsumption + "'," + " N'" + strWaterCharges + "'," + " N'" + strSewerCharges + "'," + " N'" + strEnvironmentCharges + "'," + " N'" + strTotalCharges + "'," + " N'" + strLocalTaxes + "'," + " N'" + strStateTaxes + "'," + " N'" + strPaymentDueDate + "'," + " N'" + strAmountDue + "'," + " N'" + strLatePaymentDueDate + "'," + " N'" + strLateAmountDue + "');", scWaterDistribution); scWaterDistribution.Open(); cmdWaterMeters.ExecuteNonQuery(); } Response.Redirect("Index"); } } } <h1 class="common-font fw-bold text-center">Water Bill Processing</h1> <hr /> <form method="post" class="common-font"> <div class="encloser-large"> <div class="row mb-2"> <label for="txtBillNumber" class="col-form-label col-md-4 fw-bold">Bill Number</label> <div class="col-md-3"> <input name="txtBillNumber" class="form-control" value="@strBillNumber" /> </div> </div> <hr /> <h3 class="fw-bold">Customer Information</h3> <hr /> <div class="row mb-2"> <label for="txtAccountNumber" class="col-form-label col-md-4 fw-bold">Account #</label> <div class="col-md-3"> <input name="txtAccountNumber" class="form-control" value="@strAccountNumber" /> </div> <div class="col-md-4"> <input type="submit" name="btnFindCustomerAccount" value="Find Customer Account" class="btn btn-primary" /> </div> </div> <div class="row mb-2"> <label for="txtCustomerName" class="col-form-label col-md-4 fw-bold">Customer Name</label> <div class="col-md-8"> <input name="txtCustomerName" class="form-control" value="@strCustomerName" /> </div> </div> <div class="row mb-2"> <label for="txtAddress" class="col-form-label col-md-4 fw-bold">Address</label> <div class="col-md-8"> <input name="txtAddress" class="form-control" value="@strAddress" /> </div> </div> <hr /> <div class="row mb-2"> <label for="txtCity" class="col-form-label col-md-4 fw-bold"></label> <div class="col-md-2"> <input name="txtCity" class="form-control" value="@strCity" /> </div> <div class="col-md-2"> <input name="txtCounty" class="form-control" value="@strCounty" /> </div> <div class="col-md-2"> <input name="txtState" class="form-control" value="@strState" /> </div> <div class="col-md-2"> <input name="txtZIPCode" class="form-control" value="@strZIPCode" /> </div> </div> <hr /> <div class="row mb-2"> <label for="txtMeterDetails" class="col-form-label col-md-4 fw-bold">Meter Details</label> <div class="col-md-8"> <input name="txtMeterDetails" class="form-control" value="@strMeterDetails" /> </div> </div> <hr /> <h3 class="fw-bold">Meter/Counter Reading</h3> <hr /> <div class="row mb-2"> <label for="txtMeterReadingStartDate" class="col-form-label col-md-4 fw-bold">Meter Reading Start Date</label> <div class="col-md-6"> <input name="txtMeterReadingStartDate" class="form-control" type="date" value="@strMeterReadingStartDate" /> </div> </div> <div class="row mb-2"> <label for="txtMeterReadingEndDate" class="col-form-label col-md-4 fw-bold">Meter Reading End Date</label> <div class="col-md-6"> <input name="txtMeterReadingEndDate" class="form-control" type="date" value="@strMeterReadingEndDate" /> </div> </div> <hr /> <div class="row mb-2"> <label for="txtCounterReadingStart" class="col-form-label col-md-4 fw-bold">Counter Reading Start</label> <div class="col-md-4"> <input name="txtCounterReadingStart" class="form-control" type="number" value="@strCounterReadingStart" /> </div> </div> <div class="row mb-2"> <label for="txtCounterReadingEnd" class="col-form-label col-md-4 fw-bold">Counter Reading End</label> <div class="col-md-4"> <input name="txtCounterReadingEnd" class="form-control" type="number" value="@strCounterReadingEnd" /> </div> </div> <hr /> <div class="row mb-2"> <div class="col-md-4 col-form-label"> </div> <div class="col-md-7"> <input type="submit" name="btnEvaluateWaterBill" value="Evaluate Water Bill" class="btn btn-primary" /> </div> </div> <hr /> <div class="row mb-2"> <label for="txtBillingDays" class="col-form-label col-md-4 fw-bold">Billing Days</label> <div class="col-md-4"> <input name="txtBillingDays" class="form-control" value="@strBillingDays" /> </div> </div> <div class="row mb-2"> <label for="txtTotalGallons" class="col-form-label col-md-4 fw-bold">Total Gallons</label> <div class="col-md-4"> <input name="txtTotalGallons" class="form-control" value="@strTotalGallons" /> </div> </div> <hr /> <h3 class="fw-bold">Consumption</h3> <hr /> <div class="row mb-2"> <label for="txtTotalCCF" class="col-form-label col-md-4 fw-bold">Total CCF</label> <div class="col-md-4"> <input name="txtTotalCCF" class="form-control" value="@strTotalCCF" /> </div> </div> <div class="row mb-2"> <label for="txtFirstTierConsumption" class="col-form-label col-md-4 fw-bold">First Tier Consumption</label> <div class="col-md-4"> <input name="txtFirstTierConsumption" class="form-control" value="@strFirstTierConsumption" /> </div> </div> <div class="row mb-2"> <label for="txtSecondTierConsumption" class="col-form-label col-md-4 fw-bold">Second Tier Consumption</label> <div class="col-md-4"> <input name="txtSecondTierConsumption" class="form-control" value="@strSecondTierConsumption" /> </div> </div> <div class="row mb-2"> <label for="txtLastTierConsumption" class="col-form-label col-md-4 fw-bold">Last Tier Consumption</label> <div class="col-md-4"> <input name="txtLastTierConsumption" class="form-control" value="@strLastTierConsumption" /> </div> </div> <hr /> <h3 class="fw-bold">Bill Charges</h3> <hr /> <div class="row mb-2"> <label for="txtWaterCharges" class="col-form-label col-md-4 fw-bold">Water Charges</label> <div class="col-md-4"> <input name="txtWaterCharges" class="form-control" value="@strWaterCharges" /> </div> </div> <div class="row mb-2"> <label for="txtSewerCharges" class="col-form-label col-md-4 fw-bold">Sewer Charges</label> <div class="col-md-4"> <input name="txtSewerCharges" class="form-control" value="@strSewerCharges" /> </div> </div> <div class="row mb-2"> <label for="txtEnvironmentCharges" class="col-form-label col-md-4 fw-bold">Environment Charges</label> <div class="col-md-4"> <input name="txtEnvironmentCharges" class="form-control" value="@strEnvironmentCharges" /> </div> </div> <div class="row mb-2"> <label for="txtTotalCharges" class="col-form-label col-md-4 fw-bold">Total Charges</label> <div class="col-md-4"> <input name="txtTotalCharges" class="form-control" value="@strTotalCharges" /> </div> </div> <hr /> <h3 class="fw-bold">Taxes</h3> <hr /> <div class="row mb-2"> <label for="txtLocalTaxes" class="col-form-label col-md-4 fw-bold">Local Taxes</label> <div class="col-md-4"> <input name="txtLocalTaxes" class="form-control" value="@strLocalTaxes" /> </div> </div> <div class="row mb-2"> <label for="txtStateTaxes" class="col-form-label col-md-4 fw-bold">State Taxes</label> <div class="col-md-4"> <input name="txtStateTaxes" class="form-control" value="@strStateTaxes" /> </div> </div> <hr /> <h3 class="fw-bold">Payment Details</h3> <hr /> <div class="row mb-2"> <label for="txtAmountDue" class="col-form-label col-md-4 fw-bold">Amount Due</label> <div class="col-md-4"> <input name="txtAmountDue" class="form-control" value="@strAmountDue" /> </div> </div> <div class="row mb-2"> <label for="txtPaymentDueDate" class="col-form-label col-md-4 fw-bold">Payment Due Date</label> <div class="col-md-6"> <input name="txtPaymentDueDate" class="form-control" value="@strPaymentDueDate" /> </div> </div> <div class="row mb-2"> <label for="txtLateAmountDue" class="col-form-label col-md-4 fw-bold">Late Amount Due</label> <div class="col-md-4"> <input name="txtLateAmountDue" class="form-control" value="@strLateAmountDue" /> </div> </div> <div class="row mb-2"> <label for="txtLatePaymentDueDate" class="col-form-label col-md-4 fw-bold">Late Payment Due Date</label> <div class="col-md-6"> <input name="txtLatePaymentDueDate" class="form-control" value="@strLatePaymentDueDate" /> </div> </div> <hr /> <div class="row mb-2"> <div class="col-md-5 col-form-label"> <a asp-page="Index">Stellar Water Point Home</a> </div> <div class="col-md-7"> <input type="submit" name="btnSaveWaterBill" value="Save Water Bill" class="btn btn-primary" /> </div> </div> </div> <p>@strMessage</p> </form> <hr /> <p class="text-center"> <a asp-page="./Details" class="stellar">Review a Water Bill</a> :: <a asp-page="./Edit" class="stellar">Edit/Update a Water Bill</a> :: <a asp-page="./Delete" class="stellar">Delete a Water Bill</a> </p>
@page @using System.Data; @using System.Data.SqlClient; @model StellarWaterPoint61.Pages.WaterBills.DetailsModel @{ ViewData["Title"] = "Water Bill Details"; bool bWaterBillFound = false; string? strMessage = string.Empty; string? strMeterNumber = string.Empty; string? strMeterDetails = string.Empty; string? strCity = string.Empty; string? strState = string.Empty; string? strCounty = string.Empty; string? strZIPCode = string.Empty; string? strAddress = string.Empty; string? strWaterBillId = string.Empty; string? strBillNumber = string.Empty; string? strBillingDays = string.Empty; string? strCustomerName = string.Empty; string? strAccountNumber = string.Empty; string? strCounterReadingEnd = string.Empty; string? strCounterReadingStart = string.Empty; string? strMeterReadingEndDate = string.Empty; string? strMeterReadingStartDate = string.Empty; string? strTotalCCF = string.Empty; string? strTotalGallons = string.Empty; string? strFirstTierConsumption = string.Empty; string? strSecondTierConsumption = string.Empty; string? strLastTierConsumption = string.Empty; string? strWaterCharges = string.Empty; string? strSewerCharges = string.Empty; string? strEnvironmentCharges = string.Empty; string? strTotalCharges = string.Empty; string? strLocalTaxes = string.Empty; string? strStateTaxes = string.Empty; string? strPaymentDueDate = string.Empty; string? strAmountDue = string.Empty; string? strLatePaymentDueDate = string.Empty; string? strLateAmountDue = string.Empty; if (Request.HasFormContentType) { DataSet dsCustomers = new("CustomersSet"); DataSet dsWaterBills = new("WaterBillsSet"); DataSet dsWaterMeters = new("WaterMetersSet"); strBillNumber = Request.Form["txtBillNumber"]; if (Request.Form["btnFindWaterBill"] == "Find Water Bill") { if (!string.IsNullOrEmpty(strBillNumber)) { using (SqlConnection scWaterDistribution = new SqlConnection("Data Source=(local);" + "Initial Catalog='StellarWaterPoint1';" + "Integrated Security=True;")) { SqlCommand cmdWaterBills = new SqlCommand("SELECT AccountNumber, " + " MeterReadingStartDate, " + " MeterReadingEndDate, " + " BillingDays, " + " CounterReadingStart, " + " CounterReadingEnd, " + " Consumption, " + " TotalGallons, " + " FirstTierConsumption, " + " SecondTierConsumption, " + " LastTierConsumption, " + " WaterCharges, " + " SewerCharges, " + " EnvironmentCharges, " + " TotalCharges, " + " LocalTaxes, " + " StateTaxes, " + " PaymentDueDate, " + " AmountDue, " + " LatePaymentDueDate, " + " LateAmountDue " + "FROM WaterBills " + "WHERE BillNumber = N'" + strBillNumber + "';", scWaterDistribution); scWaterDistribution.Open(); SqlDataAdapter sdaWaterBills = new SqlDataAdapter(cmdWaterBills); sdaWaterBills.Fill(dsWaterBills); foreach (DataRow drWaterBill in dsWaterBills.Tables[0].Rows!) { bWaterBillFound = true; strAccountNumber = drWaterBill[ 0].ToString(); strMeterReadingStartDate = drWaterBill[ 1].ToString(); strMeterReadingEndDate = drWaterBill[ 2].ToString(); strBillingDays = drWaterBill[ 3].ToString(); strCounterReadingStart = drWaterBill[ 4].ToString(); strCounterReadingEnd = drWaterBill[ 5].ToString(); strTotalCCF = drWaterBill[ 6].ToString(); strTotalGallons = drWaterBill[ 7].ToString(); strFirstTierConsumption = drWaterBill[ 8].ToString(); strSecondTierConsumption = drWaterBill[ 9].ToString(); strLastTierConsumption = drWaterBill[10].ToString(); strWaterCharges = drWaterBill[11].ToString(); strSewerCharges = drWaterBill[12].ToString(); strEnvironmentCharges = drWaterBill[13].ToString(); strTotalCharges = drWaterBill[14].ToString(); strLocalTaxes = drWaterBill[15].ToString(); strStateTaxes = drWaterBill[16].ToString(); strPaymentDueDate = drWaterBill[17].ToString(); strAmountDue = drWaterBill[18].ToString(); strLatePaymentDueDate = drWaterBill[19].ToString(); strLateAmountDue = drWaterBill[20].ToString(); break; } } using (SqlConnection scWaterDistribution = new SqlConnection("Data Source=(local);" + "Initial Catalog='StellarWaterPoint1';" + "Integrated Security=True;")) { SqlCommand cmdCustomers = new SqlCommand("SELECT MeterNumber, " + " FirstName, " + " LastName, " + " Address, " + " City, " + " County, " + " State, " + " ZIPCode " + "FROM Customers " + "WHERE AccountNumber = N'" + strAccountNumber + "';", scWaterDistribution); scWaterDistribution.Open(); SqlDataAdapter sdaCustomers = new SqlDataAdapter(cmdCustomers); sdaCustomers.Fill(dsCustomers); foreach (DataRow drCustomer in dsCustomers.Tables[0].Rows!) { strMeterNumber = drCustomer[0].ToString(); strCustomerName = drCustomer[1].ToString() + " " + drCustomer[2].ToString(); strAddress = drCustomer[3].ToString(); strCity = drCustomer[4].ToString(); strCounty = drCustomer[5].ToString(); strState = drCustomer[6].ToString(); strZIPCode = drCustomer[7].ToString(); break; } } using (SqlConnection scWaterDistribution = new SqlConnection("Data Source=(local);" + "Initial Catalog='StellarWaterPoint1';" + "Integrated Security=True;")) { SqlCommand cmdWaterMeters = new SqlCommand("SELECT Make, Model, MeterSize " + "FROM WaterMeters " + "WHERE MeterNumber = N'" + strMeterNumber + "';", scWaterDistribution); scWaterDistribution.Open(); SqlDataAdapter sdaWaterMeters = new SqlDataAdapter(cmdWaterMeters); sdaWaterMeters.Fill(dsWaterMeters); foreach (DataRow drWaterMeter in dsWaterMeters.Tables[0].Rows!) { strMeterDetails = drWaterMeter[0].ToString() + " " + drWaterMeter[1].ToString() + " (Meter Size: " + drWaterMeter[2].ToString() + ")"; break; } } } if (bWaterBillFound == false) { strMessage = "There is no water bill with that number in our system."; } } } } <h1 class="common-font fw-bold text-center">Water Bill Details</h1> <hr /> <form method="post" class="common-font"> <div class="encloser-large"> <div class="row mb-2"> <label for="txtBillNumber" class="col-form-label col-md-4 fw-bold">Bill Number</label> <div class="col-md-3"> <input name="txtBillNumber" class="form-control" value="@strBillNumber" /> </div> <div class="col-md-4"> <input type="submit" name="btnFindWaterBill" value="Find Water Bill" class="btn btn-primary" /> </div> </div> <hr /> <h3 class="fw-bold">Customer Information</h3> <hr /> <div class="row mb-2"> <label for="txtAccountNumber" class="col-form-label col-md-4 fw-bold">Account #</label> <div class="col-md-3"> <input name="txtAccountNumber" class="form-control" value="@strAccountNumber" /> </div> </div> <div class="row mb-2"> <label for="txtCustomerName" class="col-form-label col-md-4 fw-bold">Customer Name</label> <div class="col-md-8"> <input name="txtCustomerName" class="form-control" value="@strCustomerName" /> </div> </div> <div class="row mb-2"> <label for="txtAddress" class="col-form-label col-md-4 fw-bold">Address</label> <div class="col-md-8"> <input name="txtAddress" class="form-control" value="@strAddress" /> </div> </div> <hr /> <div class="row mb-2"> <label for="txtCity" class="col-form-label col-md-4 fw-bold"></label> <div class="col-md-2"> <input name="txtCity" class="form-control" value="@strCity" /> </div> <div class="col-md-2"> <input name="txtCounty" class="form-control" value="@strCounty" /> </div> <div class="col-md-2"> <input name="txtState" class="form-control" value="@strState" /> </div> <div class="col-md-2"> <input name="txtZIPCode" class="form-control" value="@strZIPCode" /> </div> </div> <hr /> <div class="row mb-2"> <label for="txtMeterDetails" class="col-form-label col-md-4 fw-bold">Meter Details</label> <div class="col-md-8"> <input name="txtMeterDetails" class="form-control" value="@strMeterDetails" /> </div> </div> <hr /> <h3 class="fw-bold">Meter/Counter Reading</h3> <hr /> <div class="row mb-2"> <label for="txtMeterReadingStartDate" class="col-form-label col-md-4 fw-bold">Meter Reading Start Date</label> <div class="col-md-6"> <input name="txtMeterReadingStartDate" class="form-control" type="date" value="@strMeterReadingStartDate" /> </div> </div> <div class="row mb-2"> <label for="txtMeterReadingEndDate" class="col-form-label col-md-4 fw-bold">Meter Reading End Date</label> <div class="col-md-6"> <input name="txtMeterReadingEndDate" class="form-control" type="date" value="@strMeterReadingEndDate" /> </div> </div> <hr /> <div class="row mb-2"> <label for="txtCounterReadingStart" class="col-form-label col-md-4 fw-bold">Counter Reading Start</label> <div class="col-md-4"> <input name="txtCounterReadingStart" class="form-control" type="number" value="@strCounterReadingStart" /> </div> </div> <div class="row mb-2"> <label for="txtCounterReadingEnd" class="col-form-label col-md-4 fw-bold">Counter Reading End</label> <div class="col-md-4"> <input name="txtCounterReadingEnd" class="form-control" type="number" value="@strCounterReadingEnd" /> </div> </div> <hr /> <div class="row mb-2"> <div class="col-md-4 col-form-label"> </div> <div class="col-md-7"> <input type="submit" name="btnEvaluateWaterBill" value="Evaluate Water Bill" class="btn btn-primary" /> </div> </div> <hr /> <div class="row mb-2"> <label for="txtBillingDays" class="col-form-label col-md-4 fw-bold">Billing Days</label> <div class="col-md-4"> <input name="txtBillingDays" class="form-control" value="@strBillingDays" /> </div> </div> <div class="row mb-2"> <label for="txtTotalGallons" class="col-form-label col-md-4 fw-bold">Total Gallons</label> <div class="col-md-4"> <input name="txtTotalGallons" class="form-control" value="@strTotalGallons" /> </div> </div> <hr /> <h3 class="fw-bold">Consumption</h3> <hr /> <div class="row mb-2"> <label for="txtTotalCCF" class="col-form-label col-md-4 fw-bold">Total CCF</label> <div class="col-md-4"> <input name="txtTotalCCF" class="form-control" value="@strTotalCCF" /> </div> </div> <div class="row mb-2"> <label for="txtFirstTierConsumption" class="col-form-label col-md-4 fw-bold">First Tier Consumption</label> <div class="col-md-4"> <input name="txtFirstTierConsumption" class="form-control" value="@strFirstTierConsumption" /> </div> </div> <div class="row mb-2"> <label for="txtSecondTierConsumption" class="col-form-label col-md-4 fw-bold">Second Tier Consumption</label> <div class="col-md-4"> <input name="txtSecondTierConsumption" class="form-control" value="@strSecondTierConsumption" /> </div> </div> <div class="row mb-2"> <label for="txtLastTierConsumption" class="col-form-label col-md-4 fw-bold">Last Tier Consumption</label> <div class="col-md-4"> <input name="txtLastTierConsumption" class="form-control" value="@strLastTierConsumption" /> </div> </div> <hr /> <h3 class="fw-bold">Bill Charges</h3> <hr /> <div class="row mb-2"> <label for="txtWaterCharges" class="col-form-label col-md-4 fw-bold">Water Charges</label> <div class="col-md-4"> <input name="txtWaterCharges" class="form-control" value="@strWaterCharges" /> </div> </div> <div class="row mb-2"> <label for="txtSewerCharges" class="col-form-label col-md-4 fw-bold">Sewer Charges</label> <div class="col-md-4"> <input name="txtSewerCharges" class="form-control" value="@strSewerCharges" /> </div> </div> <div class="row mb-2"> <label for="txtEnvironmentCharges" class="col-form-label col-md-4 fw-bold">Environment Charges</label> <div class="col-md-4"> <input name="txtEnvironmentCharges" class="form-control" value="@strEnvironmentCharges" /> </div> </div> <div class="row mb-2"> <label for="txtTotalCharges" class="col-form-label col-md-4 fw-bold">Total Charges</label> <div class="col-md-4"> <input name="txtTotalCharges" class="form-control" value="@strTotalCharges" /> </div> </div> <hr /> <h3 class="fw-bold">Taxes</h3> <hr /> <div class="row mb-2"> <label for="txtLocalTaxes" class="col-form-label col-md-4 fw-bold">Local Taxes</label> <div class="col-md-4"> <input name="txtLocalTaxes" class="form-control" value="@strLocalTaxes" /> </div> </div> <div class="row mb-2"> <label for="txtStateTaxes" class="col-form-label col-md-4 fw-bold">State Taxes</label> <div class="col-md-4"> <input name="txtStateTaxes" class="form-control" value="@strStateTaxes" /> </div> </div> <hr /> <h3 class="fw-bold">Payment Details</h3> <hr /> <div class="row mb-2"> <label for="txtAmountDue" class="col-form-label col-md-4 fw-bold">Amount Due</label> <div class="col-md-4"> <input name="txtAmountDue" class="form-control" value="@strAmountDue" /> </div> </div> <div class="row mb-2"> <label for="txtPaymentDueDate" class="col-form-label col-md-4 fw-bold">Payment Due Date</label> <div class="col-md-6"> <input name="txtPaymentDueDate" class="form-control" value="@strPaymentDueDate" /> </div> </div> <div class="row mb-2"> <label for="txtLateAmountDue" class="col-form-label col-md-4 fw-bold">Late Amount Due</label> <div class="col-md-4"> <input name="txtLateAmountDue" class="form-control" value="@strLateAmountDue" /> </div> </div> <div class="row mb-2"> <label for="txtLatePaymentDueDate" class="col-form-label col-md-4 fw-bold">Late Payment Due Date</label> <div class="col-md-6"> <input name="txtLatePaymentDueDate" class="form-control" value="@strLatePaymentDueDate" /> </div> </div> <hr /> <div class="row mb-2"> <div class="col-md-5 col-form-label"> </div> <div class="col-md-7"> <a asp-page="Index">Water Bills</a> </div> </div> </div> <p>@strMessage</p> </form> <hr /> <p class="text-center"> <a asp-page="./Create" class="stellar">Prepare a Water Bill</a> :: <a asp-page="./Edit" class="stellar">Edit/Update a Water Bill</a> :: <a asp-page="./Delete" class="stellar">Delete a Water Bill</a> </p>
@page @using System.Data; @using System.Data.SqlClient; @model StellarWaterPoint61.Pages.WaterBills.EditModel @{ ViewData["Title"] = "Water Bill Processing"; bool bCustomerFound = false; bool bWaterBillFound = false; string? strMessage = string.Empty; string? strBillNumber = string.Empty; string? strCity = string.Empty; string? strState = string.Empty; string? strCounty = string.Empty; string? strZIPCode = string.Empty; string? strAddress = string.Empty; string? strCustomerName = string.Empty; string? strAccountNumber = string.Empty; string? strMeterNumber = string.Empty; string? strMeterDetails = string.Empty; string? strTotalCCF = string.Empty; string? strAmountDue = string.Empty; string? strLocalTaxes = string.Empty; string? strStateTaxes = string.Empty; string? strBillingDays = string.Empty; string? strSewerCharges = string.Empty; string? strWaterCharges = string.Empty; string? strTotalGallons = string.Empty; string? strTotalCharges = string.Empty; string? strLateAmountDue = string.Empty; string? strPaymentDueDate = string.Empty; string? strCounterReadingEnd = string.Empty; string? strEnvironmentCharges = string.Empty; string? strLatePaymentDueDate = string.Empty; string? strLastTierConsumption = string.Empty; string? strCounterReadingStart = string.Empty; string? strMeterReadingEndDate = string.Empty; string? strFirstTierConsumption = string.Empty; string? strMeterReadingStartDate = string.Empty; string? strSecondTierConsumption = string.Empty; if(Request.HasFormContentType) { DataSet dsCustomers = new("CustomersSet"); DataSet dsWaterBills = new("WaterBillsSet"); DataSet dsWaterMeters = new("WaterMetersSet"); strAccountNumber = Request.Form["txtAccountNumber"]; strMeterNumber = Request.Form["txtMeterNumber"]; strAccountNumber = Request.Form["txtAccountNumber"]; strMeterNumber = Request.Form["txtMeterNumber"]; strCustomerName = Request.Form["txtCustomerName"]; strAddress = Request.Form["txtAddress"]; strCity = Request.Form["txtCity"]; strCounty = Request.Form["txtCounty"]; strState = Request.Form["txtState"]; strZIPCode = Request.Form["txtZIPCode"]; strMeterReadingStartDate = Request.Form["txtMeterReadingStartDate"]; strMeterReadingEndDate = Request.Form["txtMeterReadingEndDate"]; strCounterReadingStart = Request.Form["txtCounterReadingStart"]; strCounterReadingEnd = Request.Form["txtCounterReadingEnd"]; strBillingDays = Request.Form["txtBillingDays"]; strTotalCCF = Request.Form["txtTotalCCF"]; strTotalGallons = Request.Form["txtTotalGallons"]; strFirstTierConsumption = Request.Form["txtFirstTierConsumption"]; strSecondTierConsumption = Request.Form["txtSecondTierConsumption"]; strLastTierConsumption = Request.Form["txtLastTierConsumption"]; strWaterCharges = Request.Form["txtWaterCharges"]; strSewerCharges = Request.Form["txtSewerCharges"]; strEnvironmentCharges = Request.Form["txtEnvironmentCharges"]; strTotalCharges = Request.Form["txtTotalCharges"]; strLocalTaxes = Request.Form["txtLocalTaxes"]; strStateTaxes = Request.Form["txtStateTaxes"]; strPaymentDueDate = Request.Form["txtPaymentDueDate"]; strAmountDue = Request.Form["txtAmountDue"]; strLatePaymentDueDate = Request.Form["txtLatePaymentDueDate"]; strLateAmountDue = Request.Form["txtLateAmountDue"]; strBillNumber = Request.Form["txtBillNumber"]; if (Request.Form["btnFindWaterBill"] == "Find Water Bill") { if (!string.IsNullOrEmpty(strBillNumber)) { using (SqlConnection scWaterDistribution = new SqlConnection("Data Source=(local);" + "Initial Catalog='StellarWaterPoint1';" + "Integrated Security=True;")) { SqlCommand cmdWaterBills = new SqlCommand("SELECT AccountNumber, " + " MeterReadingStartDate, " + " MeterReadingEndDate, " + " BillingDays, " + " CounterReadingStart, " + " CounterReadingEnd, " + " Consumption, " + " TotalGallons, " + " FirstTierConsumption, " + " SecondTierConsumption, " + " LastTierConsumption, " + " WaterCharges, " + " SewerCharges, " + " EnvironmentCharges, " + " TotalCharges, " + " LocalTaxes, " + " StateTaxes, " + " PaymentDueDate, " + " AmountDue, " + " LatePaymentDueDate, " + " LateAmountDue " + "FROM WaterBills " + "WHERE BillNumber = N'" + strBillNumber + "';", scWaterDistribution); scWaterDistribution.Open(); SqlDataAdapter sdaWaterBills = new SqlDataAdapter(cmdWaterBills); sdaWaterBills.Fill(dsWaterBills); if (dsWaterBills.Tables[0].Rows.Count > 0) { bWaterBillFound = true; } foreach (DataRow drWaterBill in dsWaterBills.Tables[0].Rows!) { strAccountNumber = drWaterBill[0].ToString(); strMeterReadingStartDate = drWaterBill[1].ToString(); strMeterReadingEndDate = drWaterBill[2].ToString(); strBillingDays = drWaterBill[3].ToString(); strCounterReadingStart = drWaterBill[4].ToString(); strCounterReadingEnd = drWaterBill[5].ToString(); strTotalCCF = drWaterBill[6].ToString(); strTotalGallons = drWaterBill[7].ToString(); strFirstTierConsumption = drWaterBill[8].ToString(); strSecondTierConsumption = drWaterBill[9].ToString(); strLastTierConsumption = drWaterBill[10].ToString(); strWaterCharges = drWaterBill[11].ToString(); strSewerCharges = drWaterBill[12].ToString(); strEnvironmentCharges = drWaterBill[13].ToString(); strTotalCharges = drWaterBill[14].ToString(); strLocalTaxes = drWaterBill[15].ToString(); strStateTaxes = drWaterBill[16].ToString(); strPaymentDueDate = drWaterBill[17].ToString(); strAmountDue = drWaterBill[18].ToString(); strLatePaymentDueDate = drWaterBill[19].ToString(); strLateAmountDue = drWaterBill[20].ToString(); break; } } using (SqlConnection scWaterDistribution = new SqlConnection("Data Source=(local);" + "Initial Catalog='StellarWaterPoint1';" + "Integrated Security=True;")) { SqlCommand cmdCustomers = new SqlCommand("SELECT MeterNumber, " + " FirstName, " + " LastName, " + " Address, " + " City, " + " County, " + " State, " + " ZIPCode " + "FROM Customers " + "WHERE AccountNumber = N'" + strAccountNumber + "';", scWaterDistribution); scWaterDistribution.Open(); SqlDataAdapter sdaCustomers = new SqlDataAdapter(cmdCustomers); sdaCustomers.Fill(dsCustomers); foreach (DataRow drCustomer in dsCustomers.Tables[0].Rows!) { bCustomerFound = true; strMeterNumber = drCustomer[0].ToString(); strCustomerName = drCustomer[1].ToString() + " " + drCustomer[2].ToString(); strAddress = drCustomer[3].ToString(); strCity = drCustomer[4].ToString(); strCounty = drCustomer[5].ToString(); strState = drCustomer[6].ToString(); strZIPCode = drCustomer[7].ToString(); break; } } using (SqlConnection scWaterDistribution = new SqlConnection("Data Source=(local);" + "Initial Catalog='StellarWaterPoint1';" + "Integrated Security=True;")) { SqlCommand cmdWaterMeters = new SqlCommand("SELECT Make, Model, MeterSize " + "FROM WaterMeters " + "WHERE MeterNumber = N'" + strMeterNumber + "';", scWaterDistribution); scWaterDistribution.Open(); SqlDataAdapter sdaWaterMeters = new SqlDataAdapter(cmdWaterMeters); sdaWaterMeters.Fill(dsWaterMeters); foreach (DataRow drWaterMeter in dsWaterMeters.Tables[0].Rows!) { strMeterDetails = drWaterMeter[0].ToString() + " " + drWaterMeter[1].ToString() + " (Meter Size: " + drWaterMeter[2].ToString() + ")"; break; } } } } if (Request.Form["btnFindCustomerAccount"] == "Find Customer Account") { strBillNumber = Request.Form["txtBillNumber"]; strMeterNumber = Request.Form["txtMeterNumber"]; strMeterDetails = Request.Form["txtMeterDetails"]; strPaymentDueDate = Request.Form["txtPaymentDueDate"]; strAmountDue = Request.Form["txtAmountDue"]; strLatePaymentDueDate = Request.Form["txtLatePaymentDueDate"]; strLateAmountDue = Request.Form["txtLateAmountDue"]; using (SqlConnection scWaterDistribution = new SqlConnection("Data Source=(local);" + "Initial Catalog='StellarWaterPoint1';" + "Integrated Security=True;")) { SqlCommand cmdCustomers = new SqlCommand("SELECT MeterNumber, " + " FirstName, " + " LastName, " + " Address, " + " City, " + " County, " + " State, " + " ZIPCode " + "FROM Customers " + "WHERE AccountNumber = N'" + strAccountNumber + "';", scWaterDistribution); scWaterDistribution.Open(); SqlDataAdapter sdaCustomers = new SqlDataAdapter(cmdCustomers); sdaCustomers.Fill(dsCustomers); foreach (DataRow drCustomer in dsCustomers.Tables[0].Rows!) { bCustomerFound = true; strMeterNumber = drCustomer[0].ToString(); strCustomerName = drCustomer[1].ToString() + " " + drCustomer[2].ToString(); strAddress = drCustomer[3].ToString(); strCity = drCustomer[4].ToString(); strCounty = drCustomer[5].ToString(); strState = drCustomer[6].ToString(); strZIPCode = drCustomer[7].ToString(); break; } } if (bCustomerFound == false) { strMessage = "There is no customer account with that number in our system."; } else { using (SqlConnection scWaterDistribution = new SqlConnection("Data Source=(local);" + "Initial Catalog='StellarWaterPoint1';" + "Integrated Security=True;")) { SqlCommand cmdWaterMeters = new SqlCommand("SELECT Make, Model, MeterSize " + "FROM WaterMeters " + "WHERE MeterNumber = N'" + strMeterNumber + "';", scWaterDistribution); scWaterDistribution.Open(); SqlDataAdapter sdaWaterMeters = new SqlDataAdapter(cmdWaterMeters); sdaWaterMeters.Fill(dsWaterMeters); foreach (DataRow drWaterMeter in dsWaterMeters.Tables[0].Rows!) { strMeterDetails = drWaterMeter[0].ToString() + " " + drWaterMeter[1].ToString() + " (Meter Size: " + drWaterMeter[2].ToString() + ")"; break; } } } } if (Request.Form["btnEvaluateWaterBill"] == "Evaluate Water Bill") { strBillNumber = Request.Form["txtBillNumber"]; strMeterNumber = Request.Form["txtMeterNumber"]; strMeterDetails = Request.Form["txtMeterDetails"]; strCustomerName = Request.Form["txtCustomerName"]; strAddress = Request.Form["txtAddress"]; strCity = Request.Form["txtCity"]; strCounty = Request.Form["txtCounty"]; strState = Request.Form["txtState"]; strZIPCode = Request.Form["txtZIPCode"]; strMeterReadingStartDate = Request.Form["txtMeterReadingStartDate"]; strMeterReadingEndDate = Request.Form["txtMeterReadingEndDate"]; strCounterReadingStart = Request.Form["txtCounterReadingStart"]; strCounterReadingEnd = Request.Form["txtCounterReadingEnd"]; strPaymentDueDate = Request.Form["txtPaymentDueDate"]; strAmountDue = Request.Form["txtAmountDue"]; strLatePaymentDueDate = Request.Form["txtLatePaymentDueDate"]; strLateAmountDue = Request.Form["txtLateAmountDue"]; TimeSpan tsDays = DateTime.Parse(strMeterReadingEndDate!) - DateTime.Parse(strMeterReadingStartDate!); strBillingDays = tsDays.Days.ToString(); string strCounterStart = Request.Form["txtCounterReadingStart"]!; string strCounterEnd = Request.Form["txtCounterReadingEnd"]!; double counterStart = double.Parse(strCounterStart); double counterEnd = double.Parse(strCounterEnd); double consumption = counterEnd - counterStart; double gallons = consumption * 748.05; double firstTier = gallons * (48.00 / 10000.00); double secondTier = gallons * (32.00 / 10000.00); double lastTier = gallons * (20.00 / 10000.00); double waterCharges = firstTier + secondTier + lastTier; double sewerCharges = waterCharges * 28.65 / 100; double envCharges = waterCharges * 0.22184; double totalCharges = waterCharges + sewerCharges + envCharges; double localTaxes = totalCharges * 0.06148; double stateTaxes = totalCharges * 0.01374; double amtDue = totalCharges + localTaxes + stateTaxes; TimeSpan tsPaymentDueDate = new TimeSpan(15, 0, 0, 0); strMeterReadingStartDate = Request.Form["txtMeterReadingStartDate"]; strMeterReadingEndDate = Request.Form["txtMeterReadingEndDate"]; DateTime dtPmtDueDate = DateTime.Parse(strMeterReadingEndDate!) + tsPaymentDueDate; TimeSpan tsLatePaymentDueDate = new TimeSpan(30, 0, 0, 0); DateTime dtLatePmtDueDate = DateTime.Parse(strMeterReadingEndDate!) + tsLatePaymentDueDate; strTotalCCF = consumption.ToString(); strTotalGallons = gallons.ToString("F"); strFirstTierConsumption = firstTier.ToString("F"); strSecondTierConsumption = secondTier.ToString("F"); strLastTierConsumption = lastTier.ToString("F"); strWaterCharges = waterCharges.ToString("F"); strSewerCharges = sewerCharges.ToString("F"); strEnvironmentCharges = envCharges.ToString("F"); strTotalCharges = totalCharges.ToString("F"); strLocalTaxes = localTaxes.ToString("F"); strStateTaxes = stateTaxes.ToString("F"); strAmountDue = amtDue.ToString("F"); strPaymentDueDate = dtPmtDueDate.ToLongDateString(); strLateAmountDue = (amtDue + 8.95).ToString("F"); strLatePaymentDueDate = dtLatePmtDueDate.ToLongDateString(); } if (Request.Form["btnUpdateWaterBill"] == "Update Water Bill") { using (SqlConnection scWaterDistribution = new SqlConnection("Data Source=(local);" + "Initial Catalog='StellarWaterPoint1';" + "Integrated Security=True;")) { strAccountNumber = Request.Form["txtAccountNumber"]; strBillNumber = Request.Form["txtBillNumber"]; strMeterReadingStartDate = Request.Form["txtMeterReadingStartDate"]; strMeterReadingEndDate = Request.Form["txtMeterReadingEndDate"]; strBillingDays = Request.Form["txtBillingDays"]; strCounterReadingStart = Request.Form["txtCounterReadingStart"]; strCounterReadingEnd = Request.Form["txtCounterReadingEnd"]; strTotalCCF = Request.Form["txtTotalCCF"]; strTotalGallons = Request.Form["txtTotalGallons"]; strFirstTierConsumption = Request.Form["txtFirstTierConsumption"]; strSecondTierConsumption = Request.Form["txtSecondTierConsumption"]; strLastTierConsumption = Request.Form["txtLastTierConsumption"]; strWaterCharges = Request.Form["txtWaterCharges"]; strSewerCharges = Request.Form["txtSewerCharges"]; strEnvironmentCharges = Request.Form["txtEnvironmentCharges"]; strTotalCharges = Request.Form["txtTotalCharges"]; strLocalTaxes = Request.Form["txtLocalTaxes"]; strStateTaxes = Request.Form["txtStateTaxes"]; strPaymentDueDate = Request.Form["txtPaymentDueDate"]; strAmountDue = Request.Form["txtAmountDue"]; strLatePaymentDueDate = Request.Form["txtLatePaymentDueDate"]; strLateAmountDue = Request.Form["txtLateAmountDue"]; SqlCommand cmdWaterMeters = new SqlCommand("UPDATE WaterBills SET AccountNumber = N'" + strAccountNumber + "' WHERE BillNumber = N'" + strBillNumber + "';" + "UPDATE WaterBills SET MeterReadingStartDate = N'" + strMeterReadingStartDate + "' WHERE BillNumber = N'" + strBillNumber + "';" + "UPDATE WaterBills SET MeterReadingEndDate = N'" + strMeterReadingEndDate + "' WHERE BillNumber = N'" + strBillNumber + "';" + "UPDATE WaterBills SET BillingDays = N'" + strBillingDays + "' WHERE BillNumber = N'" + strBillNumber + "';" + "UPDATE WaterBills SET CounterReadingStart = N'" + strCounterReadingStart + "' WHERE BillNumber = N'" + strBillNumber + "';" + "UPDATE WaterBills SET CounterReadingEnd = N'" + strCounterReadingEnd + "' WHERE BillNumber = N'" + strBillNumber + "';" + "UPDATE WaterBills SET Consumption = N'" + strTotalCCF + "' WHERE BillNumber = N'" + strBillNumber + "';" + "UPDATE WaterBills SET TotalGallons = N'" + strTotalGallons + "' WHERE BillNumber = N'" + strBillNumber + "';" + "UPDATE WaterBills SET FirstTierConsumption = N'" + strFirstTierConsumption + "' WHERE BillNumber = N'" + strBillNumber + "';" + "UPDATE WaterBills SET SecondTierConsumption = N'" + strSecondTierConsumption + "' WHERE BillNumber = N'" + strBillNumber + "';" + "UPDATE WaterBills SET LastTierConsumption = N'" + strLastTierConsumption + "' WHERE BillNumber = N'" + strBillNumber + "';" + "UPDATE WaterBills SET WaterCharges = N'" + strWaterCharges + "' WHERE BillNumber = N'" + strBillNumber + "';" + "UPDATE WaterBills SET SewerCharges = N'" + strSewerCharges + "' WHERE BillNumber = N'" + strBillNumber + "';" + "UPDATE WaterBills SET EnvironmentCharges = N'" + strEnvironmentCharges + "' WHERE BillNumber = N'" + strBillNumber + "';" + "UPDATE WaterBills SET TotalCharges = N'" + strTotalCharges + "' WHERE BillNumber = N'" + strBillNumber + "';" + "UPDATE WaterBills SET LocalTaxes = N'" + strLocalTaxes + "' WHERE BillNumber = N'" + strBillNumber + "';" + "UPDATE WaterBills SET StateTaxes = N'" + strStateTaxes + "' WHERE BillNumber = N'" + strBillNumber + "';" + "UPDATE WaterBills SET PaymentDueDate = N'" + strPaymentDueDate + "' WHERE BillNumber = N'" + strBillNumber + "';" + "UPDATE WaterBills SET AmountDue = N'" + strAmountDue + "' WHERE BillNumber = N'" + strBillNumber + "';" + "UPDATE WaterBills SET LatePaymentDueDate = N'" + strLatePaymentDueDate + "' WHERE BillNumber = N'" + strBillNumber + "';" + "UPDATE WaterBills SET LateAmountDue = N'" + strLateAmountDue + "' WHERE BillNumber = N'" + strBillNumber + "';", scWaterDistribution); scWaterDistribution.Open(); cmdWaterMeters.ExecuteNonQuery(); } Response.Redirect("Index"); } } } <h1 class="common-font fw-bold text-center">Edit/Update a Water Bill</h1> <hr /> <form method="post" class="common-font"> <div class="encloser-large"> <div class="row mb-2"> <label for="txtBillNumber" class="col-form-label col-md-4 fw-bold">Bill Number</label> <div class="col-md-3"> <input name="txtBillNumber" class="form-control" value="@strBillNumber" /> </div> <div class="col-md-4"> <input type="submit" name="btnFindWaterBill" value="Find Water Bill" class="btn btn-primary" /> </div> </div> <hr /> <h3 class="fw-bold">Customer Information</h3> <hr /> <div class="row mb-2"> <label for="txtAccountNumber" class="col-form-label col-md-4 fw-bold">Account #</label> <div class="col-md-3"> <input name="txtAccountNumber" class="form-control" value="@strAccountNumber" /> </div> <div class="col-md-4"> <input type="submit" name="btnFindCustomerAccount" value="Find Customer Account" class="btn btn-primary" /> </div> </div> <div class="row mb-2"> <label for="txtCustomerName" class="col-form-label col-md-4 fw-bold">Customer Name</label> <div class="col-md-8"> <input name="txtCustomerName" class="form-control" value="@strCustomerName" /> </div> </div> <div class="row mb-2"> <label for="txtAddress" class="col-form-label col-md-4 fw-bold">Address</label> <div class="col-md-8"> <input name="txtAddress" class="form-control" value="@strAddress" /> </div> </div> <hr /> <div class="row mb-2"> <label for="txtCity" class="col-form-label col-md-4 fw-bold"></label> <div class="col-md-2"> <input name="txtCity" class="form-control" value="@strCity" /> </div> <div class="col-md-2"> <input name="txtCounty" class="form-control" value="@strCounty" /> </div> <div class="col-md-2"> <input name="txtState" class="form-control" value="@strState" /> </div> <div class="col-md-2"> <input name="txtZIPCode" class="form-control" value="@strZIPCode" /> </div> </div> <hr /> <div class="row mb-2"> <label for="txtMeterDetails" class="col-form-label col-md-4 fw-bold">Meter Details</label> <div class="col-md-8"> <input name="txtMeterDetails" class="form-control" value="@strMeterDetails" /> </div> </div> <hr /> <h3 class="fw-bold">Meter/Counter Reading</h3> <hr /> <div class="row mb-2"> <label for="txtMeterReadingStartDate" class="col-form-label col-md-4 fw-bold">Meter Reading Start Date</label> <div class="col-md-6"> <input name="txtMeterReadingStartDate" class="form-control" type="date" value="@strMeterReadingStartDate" /> </div> </div> <div class="row mb-2"> <label for="txtMeterReadingEndDate" class="col-form-label col-md-4 fw-bold">Meter Reading End Date</label> <div class="col-md-6"> <input name="txtMeterReadingEndDate" class="form-control" type="date" value="@strMeterReadingEndDate" /> </div> </div> <hr /> <div class="row mb-2"> <label for="txtCounterReadingStart" class="col-form-label col-md-4 fw-bold">Counter Reading Start</label> <div class="col-md-4"> <input name="txtCounterReadingStart" class="form-control" type="number" value="@strCounterReadingStart" /> </div> </div> <div class="row mb-2"> <label for="txtCounterReadingEnd" class="col-form-label col-md-4 fw-bold">Counter Reading End</label> <div class="col-md-4"> <input name="txtCounterReadingEnd" class="form-control" type="number" value="@strCounterReadingEnd" /> </div> </div> <hr /> <div class="row mb-2"> <div class="col-md-4 col-form-label"> </div> <div class="col-md-7"> <input type="submit" name="btnEvaluateWaterBill" value="Evaluate Water Bill" class="btn btn-primary" /> </div> </div> <hr /> <div class="row mb-2"> <label for="txtBillingDays" class="col-form-label col-md-4 fw-bold">Billing Days</label> <div class="col-md-4"> <input name="txtBillingDays" class="form-control" value="@strBillingDays" /> </div> </div> <div class="row mb-2"> <label for="txtTotalGallons" class="col-form-label col-md-4 fw-bold">Total Gallons</label> <div class="col-md-4"> <input name="txtTotalGallons" class="form-control" value="@strTotalGallons" /> </div> </div> <hr /> <h3 class="fw-bold">Consumption</h3> <hr /> <div class="row mb-2"> <label for="txtTotalCCF" class="col-form-label col-md-4 fw-bold">Total CCF</label> <div class="col-md-4"> <input name="txtTotalCCF" class="form-control" value="@strTotalCCF" /> </div> </div> <div class="row mb-2"> <label for="txtFirstTierConsumption" class="col-form-label col-md-4 fw-bold">First Tier Consumption</label> <div class="col-md-4"> <input name="txtFirstTierConsumption" class="form-control" value="@strFirstTierConsumption" /> </div> </div> <div class="row mb-2"> <label for="txtSecondTierConsumption" class="col-form-label col-md-4 fw-bold">Second Tier Consumption</label> <div class="col-md-4"> <input name="txtSecondTierConsumption" class="form-control" value="@strSecondTierConsumption" /> </div> </div> <div class="row mb-2"> <label for="txtLastTierConsumption" class="col-form-label col-md-4 fw-bold">Last Tier Consumption</label> <div class="col-md-4"> <input name="txtLastTierConsumption" class="form-control" value="@strLastTierConsumption" /> </div> </div> <hr /> <h3 class="fw-bold">Bill Charges</h3> <hr /> <div class="row mb-2"> <label for="txtWaterCharges" class="col-form-label col-md-4 fw-bold">Water Charges</label> <div class="col-md-4"> <input name="txtWaterCharges" class="form-control" value="@strWaterCharges" /> </div> </div> <div class="row mb-2"> <label for="txtSewerCharges" class="col-form-label col-md-4 fw-bold">Sewer Charges</label> <div class="col-md-4"> <input name="txtSewerCharges" class="form-control" value="@strSewerCharges" /> </div> </div> <div class="row mb-2"> <label for="txtEnvironmentCharges" class="col-form-label col-md-4 fw-bold">Environment Charges</label> <div class="col-md-4"> <input name="txtEnvironmentCharges" class="form-control" value="@strEnvironmentCharges" /> </div> </div> <div class="row mb-2"> <label for="txtTotalCharges" class="col-form-label col-md-4 fw-bold">Total Charges</label> <div class="col-md-4"> <input name="txtTotalCharges" class="form-control" value="@strTotalCharges" /> </div> </div> <hr /> <h3 class="fw-bold">Taxes</h3> <hr /> <div class="row mb-2"> <label for="txtLocalTaxes" class="col-form-label col-md-4 fw-bold">Local Taxes</label> <div class="col-md-4"> <input name="txtLocalTaxes" class="form-control" value="@strLocalTaxes" /> </div> </div> <div class="row mb-2"> <label for="txtStateTaxes" class="col-form-label col-md-4 fw-bold">State Taxes</label> <div class="col-md-4"> <input name="txtStateTaxes" class="form-control" value="@strStateTaxes" /> </div> </div> <hr /> <h3 class="fw-bold">Payment Details</h3> <hr /> <div class="row mb-2"> <label for="txtAmountDue" class="col-form-label col-md-4 fw-bold">Amount Due</label> <div class="col-md-4"> <input name="txtAmountDue" class="form-control" value="@strAmountDue" /> </div> </div> <div class="row mb-2"> <label for="txtPaymentDueDate" class="col-form-label col-md-4 fw-bold">Payment Due Date</label> <div class="col-md-6"> <input name="txtPaymentDueDate" class="form-control" value="@strPaymentDueDate" /> </div> </div> <div class="row mb-2"> <label for="txtLateAmountDue" class="col-form-label col-md-4 fw-bold">Late Amount Due</label> <div class="col-md-4"> <input name="txtLateAmountDue" class="form-control" value="@strLateAmountDue" /> </div> </div> <div class="row mb-2"> <label for="txtLatePaymentDueDate" class="col-form-label col-md-4 fw-bold">Late Payment Due Date</label> <div class="col-md-6"> <input name="txtLatePaymentDueDate" class="form-control" value="@strLatePaymentDueDate" /> </div> </div> <hr /> <div class="row mb-2"> <div class="col-md-5 col-form-label"> <a asp-page="Index">Stellar Water Point Home</a> </div> <div class="col-md-7"> <input type="submit" name="btnUpdateWaterBill" value="Update Water Bill" class="btn btn-primary" /> </div> </div> </div> <p>@strMessage</p> </form> <hr /> <p class="text-center"> <a asp-page="./Create" class="stellar">Prepare a New Water Bill</a> :: <a asp-page="./Details" class="stellar">Review an Existing Water Bill</a> :: <a asp-page="./Delete" class="stellar">Delete an Existing Water Bill</a> </p>
@page @using System.Data; @using System.Data.SqlClient; @model StellarWaterPoint61.Pages.WaterBills.DeleteModel @{ ViewData["Title"] = "Water Bill Deletion"; bool bWaterBillFound = false; string? strMessage = string.Empty; string? strMeterNumber = string.Empty; string? strMeterDetails = string.Empty; string? strCity = string.Empty; string? strState = string.Empty; string? strCounty = string.Empty; string? strZIPCode = string.Empty; string? strAddress = string.Empty; string? strBillNumber = string.Empty; string? strBillingDays = string.Empty; string? strCustomerName = string.Empty; string? strAccountNumber = string.Empty; string? strCounterReadingEnd = string.Empty; string? strCounterReadingStart = string.Empty; string? strMeterReadingEndDate = string.Empty; string? strMeterReadingStartDate = string.Empty; string? strTotalCCF = string.Empty; string? strTotalGallons = string.Empty; string? strFirstTierConsumption = string.Empty; string? strSecondTierConsumption = string.Empty; string? strLastTierConsumption = string.Empty; string? strWaterCharges = string.Empty; string? strSewerCharges = string.Empty; string? strEnvironmentCharges = string.Empty; string? strTotalCharges = string.Empty; string? strLocalTaxes = string.Empty; string? strStateTaxes = string.Empty; string? strPaymentDueDate = string.Empty; string? strAmountDue = string.Empty; string? strLatePaymentDueDate = string.Empty; string? strLateAmountDue = string.Empty; if (Request.HasFormContentType) { DataSet dsCustomers = new("CustomersSet"); DataSet dsWaterBills = new("WaterBillsSet"); DataSet dsWaterMeters = new("WaterMetersSet"); /* strAccountNumber = Request.Form["txtAccountNumber"]; strMeterNumber = Request.Form["txtMeterNumber"]; strAccountNumber = Request.Form["txtAccountNumber"]; strMeterNumber = Request.Form["txtMeterNumber"]; strCustomerName = Request.Form["txtCustomerName"]; strAddress = Request.Form["txtAddress"]; strCity = Request.Form["txtCity"]; strCounty = Request.Form["txtCounty"]; strState = Request.Form["txtState"]; strZIPCode = Request.Form["txtZIPCode"]; strMeterReadingStartDate = Request.Form["txtMeterReadingStartDate"]; strMeterReadingEndDate = Request.Form["txtMeterReadingEndDate"]; strCounterReadingStart = Request.Form["txtCounterReadingStart"]; strCounterReadingEnd = Request.Form["txtCounterReadingEnd"]; strBillingDays = Request.Form["txtBillingDays"]; strTotalCCF = Request.Form["txtTotalCCF"]; strTotalGallons = Request.Form["txtTotalGallons"]; strFirstTierConsumption = Request.Form["txtFirstTierConsumption"]; strSecondTierConsumption = Request.Form["txtSecondTierConsumption"]; strLastTierConsumption = Request.Form["txtLastTierConsumption"]; strWaterCharges = Request.Form["txtWaterCharges"]; strSewerCharges = Request.Form["txtSewerCharges"]; strEnvironmentCharges = Request.Form["txtEnvironmentCharges"]; strTotalCharges = Request.Form["txtTotalCharges"]; strLocalTaxes = Request.Form["txtLocalTaxes"]; strStateTaxes = Request.Form["txtStateTaxes"]; strPaymentDueDate = Request.Form["txtPaymentDueDate"]; strAmountDue = Request.Form["txtAmountDue"]; strLatePaymentDueDate = Request.Form["txtLatePaymentDueDate"]; strLateAmountDue = Request.Form["txtLateAmountDue"]; */ strBillNumber = Request.Form["txtBillNumber"]; if (Request.Form["btnFindWaterBill"] == "Find Water Bill") { if (!string.IsNullOrEmpty(strBillNumber)) { using (SqlConnection scWaterDistribution = new SqlConnection("Data Source=(local);" + "Initial Catalog='StellarWaterPoint1';" + "Integrated Security=True;")) { SqlCommand cmdWaterBills = new SqlCommand("SELECT AccountNumber, " + " MeterReadingStartDate, " + " MeterReadingEndDate, " + " BillingDays, " + " CounterReadingStart, " + " CounterReadingEnd, " + " Consumption, " + " TotalGallons, " + " FirstTierConsumption, " + " SecondTierConsumption, " + " LastTierConsumption, " + " WaterCharges, " + " SewerCharges, " + " EnvironmentCharges, " + " TotalCharges, " + " LocalTaxes, " + " StateTaxes, " + " PaymentDueDate, " + " AmountDue, " + " LatePaymentDueDate, " + " LateAmountDue " + "FROM WaterBills " + "WHERE BillNumber = N'" + strBillNumber + "';", scWaterDistribution); scWaterDistribution.Open(); SqlDataAdapter sdaWaterBills = new SqlDataAdapter(cmdWaterBills); sdaWaterBills.Fill(dsWaterBills); if (dsWaterBills.Tables[0].Rows.Count > 0) { bWaterBillFound = true; } foreach (DataRow drWaterBill in dsWaterBills.Tables[0].Rows!) { strAccountNumber = drWaterBill[0].ToString(); strMeterReadingStartDate = drWaterBill[1].ToString(); strMeterReadingEndDate = drWaterBill[2].ToString(); strBillingDays = drWaterBill[3].ToString(); strCounterReadingStart = drWaterBill[4].ToString(); strCounterReadingEnd = drWaterBill[5].ToString(); strTotalCCF = drWaterBill[6].ToString(); strTotalGallons = drWaterBill[7].ToString(); strFirstTierConsumption = drWaterBill[8].ToString(); strSecondTierConsumption = drWaterBill[9].ToString(); strLastTierConsumption = drWaterBill[10].ToString(); strWaterCharges = drWaterBill[11].ToString(); strSewerCharges = drWaterBill[12].ToString(); strEnvironmentCharges = drWaterBill[13].ToString(); strTotalCharges = drWaterBill[14].ToString(); strLocalTaxes = drWaterBill[15].ToString(); strStateTaxes = drWaterBill[16].ToString(); strPaymentDueDate = drWaterBill[17].ToString(); strAmountDue = drWaterBill[18].ToString(); strLatePaymentDueDate = drWaterBill[19].ToString(); strLateAmountDue = drWaterBill[20].ToString(); break; } } using (SqlConnection scWaterDistribution = new SqlConnection("Data Source=(local);" + "Initial Catalog='StellarWaterPoint1';" + "Integrated Security=True;")) { SqlCommand cmdCustomers = new SqlCommand("SELECT MeterNumber, " + " FirstName, " + " LastName, " + " Address, " + " City, " + " County, " + " State, " + " ZIPCode " + "FROM Customers " + "WHERE AccountNumber = N'" + strAccountNumber + "';", scWaterDistribution); scWaterDistribution.Open(); SqlDataAdapter sdaCustomers = new SqlDataAdapter(cmdCustomers); sdaCustomers.Fill(dsCustomers); foreach (DataRow drCustomer in dsCustomers.Tables[0].Rows!) { strMeterNumber = drCustomer[0].ToString(); strCustomerName = drCustomer[1].ToString() + " " + drCustomer[2].ToString(); strAddress = drCustomer[3].ToString(); strCity = drCustomer[4].ToString(); strCounty = drCustomer[5].ToString(); strState = drCustomer[6].ToString(); strZIPCode = drCustomer[7].ToString(); break; } } using (SqlConnection scWaterDistribution = new SqlConnection("Data Source=(local);" + "Initial Catalog='StellarWaterPoint1';" + "Integrated Security=True;")) { SqlCommand cmdWaterMeters = new SqlCommand("SELECT Make, Model, MeterSize " + "FROM WaterMeters " + "WHERE MeterNumber = N'" + strMeterNumber + "';", scWaterDistribution); scWaterDistribution.Open(); SqlDataAdapter sdaWaterMeters = new SqlDataAdapter(cmdWaterMeters); sdaWaterMeters.Fill(dsWaterMeters); foreach (DataRow drWaterMeter in dsWaterMeters.Tables[0].Rows!) { strMeterDetails = drWaterMeter[0].ToString() + " " + drWaterMeter[1].ToString() + " (Meter Size: " + drWaterMeter[2].ToString() + ")"; break; } } } } if (Request.Form["btnDeleteWaterBill"] == "Delete Water Bill") { using (SqlConnection scWaterDistribution = new SqlConnection("Data Source=(local);" + "Initial Catalog='StellarWaterPoint1';" + "Integrated Security=True;")) { SqlCommand cmdWaterMeters = new SqlCommand("DELETE WaterBills WHERE BillNumber = N'" + strBillNumber + "';", scWaterDistribution); scWaterDistribution.Open(); cmdWaterMeters.ExecuteNonQuery(); } Response.Redirect("Index"); } } } <h1 class="common-font fw-bold text-center">Water Bill Deletion</h1> <hr /> <form method="post" class="common-font"> <div class="encloser-large"> <div class="row mb-2"> <label for="txtBillNumber" class="col-form-label col-md-4 fw-bold">Bill Number</label> <div class="col-md-3"> <input name="txtBillNumber" class="form-control" value="@strBillNumber" /> </div> <div class="col-md-4"> <input type="submit" name="btnFindWaterBill" value="Find Water Bill" class="btn btn-primary" /> </div> </div> <hr /> <h3 class="fw-bold">Customer Information</h3> <hr /> <div class="row mb-2"> <label for="txtAccountNumber" class="col-form-label col-md-4 fw-bold">Account #</label> <div class="col-md-3"> <input name="txtAccountNumber" class="form-control" value="@strAccountNumber" /> </div> </div> <div class="row mb-2"> <label for="txtCustomerName" class="col-form-label col-md-4 fw-bold">Customer Name</label> <div class="col-md-8"> <input name="txtCustomerName" class="form-control" value="@strCustomerName" /> </div> </div> <div class="row mb-2"> <label for="txtAddress" class="col-form-label col-md-4 fw-bold">Address</label> <div class="col-md-8"> <input name="txtAddress" class="form-control" value="@strAddress" /> </div> </div> <hr /> <div class="row mb-2"> <label for="txtCity" class="col-form-label col-md-4 fw-bold"></label> <div class="col-md-2"> <input name="txtCity" class="form-control" value="@strCity" /> </div> <div class="col-md-2"> <input name="txtCounty" class="form-control" value="@strCounty" /> </div> <div class="col-md-2"> <input name="txtState" class="form-control" value="@strState" /> </div> <div class="col-md-2"> <input name="txtZIPCode" class="form-control" value="@strZIPCode" /> </div> </div> <hr /> <div class="row mb-2"> <label for="txtMeterDetails" class="col-form-label col-md-4 fw-bold">Meter Details</label> <div class="col-md-8"> <input name="txtMeterDetails" class="form-control" value="@strMeterDetails" /> </div> </div> <hr /> <h3 class="fw-bold">Meter/Counter Reading</h3> <hr /> <div class="row mb-2"> <label for="txtMeterReadingStartDate" class="col-form-label col-md-4 fw-bold">Meter Reading Start Date</label> <div class="col-md-6"> <input name="txtMeterReadingStartDate" class="form-control" type="date" value="@strMeterReadingStartDate" /> </div> </div> <div class="row mb-2"> <label for="txtMeterReadingEndDate" class="col-form-label col-md-4 fw-bold">Meter Reading End Date</label> <div class="col-md-6"> <input name="txtMeterReadingEndDate" class="form-control" type="date" value="@strMeterReadingEndDate" /> </div> </div> <hr /> <div class="row mb-2"> <label for="txtCounterReadingStart" class="col-form-label col-md-4 fw-bold">Counter Reading Start</label> <div class="col-md-4"> <input name="txtCounterReadingStart" class="form-control" type="number" value="@strCounterReadingStart" /> </div> </div> <div class="row mb-2"> <label for="txtCounterReadingEnd" class="col-form-label col-md-4 fw-bold">Counter Reading End</label> <div class="col-md-4"> <input name="txtCounterReadingEnd" class="form-control" type="number" value="@strCounterReadingEnd" /> </div> </div> <hr /> <div class="row mb-2"> <label for="txtBillingDays" class="col-form-label col-md-4 fw-bold">Billing Days</label> <div class="col-md-4"> <input name="txtBillingDays" class="form-control" value="@strBillingDays" /> </div> </div> <div class="row mb-2"> <label for="txtTotalGallons" class="col-form-label col-md-4 fw-bold">Total Gallons</label> <div class="col-md-4"> <input name="txtTotalGallons" class="form-control" value="@strTotalGallons" /> </div> </div> <hr /> <h3 class="fw-bold">Consumption</h3> <hr /> <div class="row mb-2"> <label for="txtTotalCCF" class="col-form-label col-md-4 fw-bold">Total CCF</label> <div class="col-md-4"> <input name="txtTotalCCF" class="form-control" value="@strTotalCCF" /> </div> </div> <div class="row mb-2"> <label for="txtFirstTierConsumption" class="col-form-label col-md-4 fw-bold">First Tier Consumption</label> <div class="col-md-4"> <input name="txtFirstTierConsumption" class="form-control" value="@strFirstTierConsumption" /> </div> </div> <div class="row mb-2"> <label for="txtSecondTierConsumption" class="col-form-label col-md-4 fw-bold">Second Tier Consumption</label> <div class="col-md-4"> <input name="txtSecondTierConsumption" class="form-control" value="@strSecondTierConsumption" /> </div> </div> <div class="row mb-2"> <label for="txtLastTierConsumption" class="col-form-label col-md-4 fw-bold">Last Tier Consumption</label> <div class="col-md-4"> <input name="txtLastTierConsumption" class="form-control" value="@strLastTierConsumption" /> </div> </div> <hr /> <h3 class="fw-bold">Bill Charges</h3> <hr /> <div class="row mb-2"> <label for="txtWaterCharges" class="col-form-label col-md-4 fw-bold">Water Charges</label> <div class="col-md-4"> <input name="txtWaterCharges" class="form-control" value="@strWaterCharges" /> </div> </div> <div class="row mb-2"> <label for="txtSewerCharges" class="col-form-label col-md-4 fw-bold">Sewer Charges</label> <div class="col-md-4"> <input name="txtSewerCharges" class="form-control" value="@strSewerCharges" /> </div> </div> <div class="row mb-2"> <label for="txtEnvironmentCharges" class="col-form-label col-md-4 fw-bold">Environment Charges</label> <div class="col-md-4"> <input name="txtEnvironmentCharges" class="form-control" value="@strEnvironmentCharges" /> </div> </div> <div class="row mb-2"> <label for="txtTotalCharges" class="col-form-label col-md-4 fw-bold">Total Charges</label> <div class="col-md-4"> <input name="txtTotalCharges" class="form-control" value="@strTotalCharges" /> </div> </div> <hr /> <h3 class="fw-bold">Taxes</h3> <hr /> <div class="row mb-2"> <label for="txtLocalTaxes" class="col-form-label col-md-4 fw-bold">Local Taxes</label> <div class="col-md-4"> <input name="txtLocalTaxes" class="form-control" value="@strLocalTaxes" /> </div> </div> <div class="row mb-2"> <label for="txtStateTaxes" class="col-form-label col-md-4 fw-bold">State Taxes</label> <div class="col-md-4"> <input name="txtStateTaxes" class="form-control" value="@strStateTaxes" /> </div> </div> <hr /> <h3 class="fw-bold">Payment Details</h3> <hr /> <div class="row mb-2"> <label for="txtAmountDue" class="col-form-label col-md-4 fw-bold">Amount Due</label> <div class="col-md-4"> <input name="txtAmountDue" class="form-control" value="@strAmountDue" /> </div> </div> <div class="row mb-2"> <label for="txtPaymentDueDate" class="col-form-label col-md-4 fw-bold">Payment Due Date</label> <div class="col-md-6"> <input name="txtPaymentDueDate" class="form-control" value="@strPaymentDueDate" /> </div> </div> <div class="row mb-2"> <label for="txtLateAmountDue" class="col-form-label col-md-4 fw-bold">Late Amount Due</label> <div class="col-md-4"> <input name="txtLateAmountDue" class="form-control" value="@strLateAmountDue" /> </div> </div> <div class="row mb-2"> <label for="txtLatePaymentDueDate" class="col-form-label col-md-4 fw-bold">Late Payment Due Date</label> <div class="col-md-6"> <input name="txtLatePaymentDueDate" class="form-control" value="@strLatePaymentDueDate" /> </div> </div> <hr /> <div class="row mb-2"> <div class="col-md-5 col-form-label"> <a asp-page="Index">Stellar Water Point Home</a> </div> <div class="col-md-7"> <input type="submit" name="btnDeleteWaterBill" value="Delete Water Bill" class="btn btn-primary" /> </div> </div> </div> <p>@strMessage</p> </form> <hr /> <p class="text-center"> <a asp-page="./Create" class="stellar">Prepare a New Water Bill</a> :: <a asp-page="./Details" class="stellar">Review an Existing Water Bill</a> :: <a asp-page="./Edit" class="stellar">Edit/Update an Existing Water Bill</a> </p>
@page @model StellarWaterPoint4.Pages.WaterBills.IndexModel @{ } <p class="text-center"> <a asp-page="./Create" class="stellar">Water Bill Processing</a> :: <a asp-page="./Details" class="stellar">Review a Water Bill</a> :: <a asp-page="./Edit">Edit/Update a Water Bill</a> :: <a asp-page="./Delete" class="stellar">Delete a Water Bill</a> </p>
Finalizing and Testing the Application
After creating the webpages and webforms that are necessary for the application, we can put the final touches and test it with some values.
Practical Learning: Finalizing and Testing the Application
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>@ViewData["Title"] - Stellar Water Point</title> <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" /> <link rel="stylesheet" href="~/css/site.css" asp-append-version="true" /> <link rel="stylesheet" href="~/StellarWaterPoint30.styles.css" asp-append-version="true" /> </head> <body> <header> <nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3"> <div class="container"> <a class="navbar-brand" asp-area="" asp-page="/Index">Stellar Water Point</a> <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="navbar-collapse collapse d-sm-inline-flex justify-content-between"> <ul class="navbar-nav flex-grow-1"> <li class="nav-item"> <a class="nav-link text-light" asp-area="" asp-page="/WaterBills/Index">Water Bills</a> </li> <li class="nav-item"> <a class="nav-link text-light" asp-area="" asp-page="/Customers/Index">Customers</a> </li> <li class="nav-item"> <a class="nav-link text-light" asp-area="" asp-page="/WaterMeters/Index">Water Meters</a> </li> <li class="nav-item"> <a class="nav-link text-light" asp-area="" asp-page="/Privacy">Privacy</a> </li> </ul> </div> </div> </nav> </header> <div class="container"> <main role="main" class="pb-3"> @RenderBody() </main> </div> <footer class="border-top footer text-muted"> <div class="container"> <p class="common-font text-center">© 2025 - Stellar Water Point - <a asp-area="" asp-page="/Privacy">Privacy</a></p> </div> </footer> <script src="~/lib/jquery/dist/jquery.min.js"></script> <script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script> <script src="~/js/site.js" asp-append-version="true"></script> @await RenderSectionAsync("Scripts", required: false) </body> </html>
@page
@model IndexModel
@{
ViewData["Title"] = "Home page";
}
<main class="common-font">
<div class="text-center">
<h1 class="display-4 fw-bold">Stellar Water Point</h1>
<p class="lead text-muted">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>
</div>
<div class="py-5 bg-light">
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="card mb-4 box-shadow">
<img class="bordered" 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>
</div>
<div class="col-md-4">
<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 each of our customers who holds an account with us, all for good service.</p>
</div>
</div>
</div>
<div class="col-md-4">
<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>
</div>
<div class="col-md-4">
<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>
</div>
<div class="col-md-4">
<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>
</div>
<div class="col-md-4">
<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>
</div>
</div>
</div>
</div>
</main>
Meter # | Make | Model | Meter Size |
392-44-572 | Constance Technologies | TG-4822 | 5/8 Inches |
938-75-869 | Stanford Trend | 266G | 1 1/2 Inches |
588-29-663 | Estellano | NCF-226 | 3/4 Inches |
186-92-805 | Lansome | 2800 | 1 1/2 Inches |
799-28-461 | Kensa Sons | K-584-L | 3/4 Inches |
386-48-057 | Estellano | NCF-226 | 3/4 Inches |
837-06-836 | Lansome | 7400 | 5/8 Inches |
207-94-835 | Constance Technologies | TG-6220 | 5/8 Inches |
592-84-957 | Kensa Sons | D-497-H | 3/4 Inches |
374-06-284 | Raynes Energica | i2022 | 3/4 Inches |
186-99-757 | Kensa Sons | M-686-G | 1 1/2 Inches |
630-07-055 | Lansome | 2800 | 3/4 Inches |
827-50-248 | Standard Trend | 428T | 3/4 Inches |
470-68-850 | Estellano | WRT-482 | 3/4 Inches |
649-33-505 | Constance Technologies | BD-7000 | 5/8 Inches |
306-82-497 | Lansome | 9000 | 3/4 Inches |
Account # | Meter # | First Name | Last Name | Address | City | County | State | ZIP-Code |
9279-570-8394 | 799-28-461 | Thomas | Stones | 10252 Broward Ave #D4 | Frederick | Frederick | MD | 21703-6628 |
2068-258-9486 | 186-92-805 | Ericka | Dellaney | 4819 East Munk Street | Whitehall | Fulton | PA | 17340-2277 |
4820-375-2842 | 392-44-572 | Akhil | Koumari | 748 Red Hills Rd | Roanoke | VA | 24012-9726 | |
6003-386-3955 | 374-06-284 | Mandiakandara | Marmoudi | 539 Avalon Court | Greenwood | Sussex | DE | 19950-2288 |
9249-379-6848 | 588-29-663 | Richard | Eghert | 8280 Sligo North Way | Albright | Preston | WV | 26519-4626 |
7518-302-6895 | 207-94-835 | Grace | Brenner | 4299 Peachtree Court | Rockville | Montgomery | MD | 20853-1512 |
3028-502-9418 | 186-99-757 | Spencer | Kershaw | 338C Grayson Street | Gatchellville | York | PA | 17352-3808 |
5293-957-3395 | 386-48-057 | Kelly | Davids | 10484 Greenway Avenue | Mt Storm | Grant | WV | 26739-6242 |
2038-413-9680 | 938-75-869 | Amidou | Gomah | 2075 Rose Hills Avenue | Washington | DC | 20004-1818 | |
7028-405-9381 | 306-82-497 | Jonathan | Simmings | 613 Meadowhill Road | Alonzaville | Shenandoah | VA | 22664-2662 |
5938-074-5293 | 592-84-957 | Marie | Rath | 582G Dunhill Avenue | Lanham | Prince Georges | MD | 20706-4422 |
1827-395-0203 | 470-68-850 | Sathyavanthara | Khooni | 10331 Chryswell Road | Washington | DC | 20008-5050 | |
8027-304-6829 | 837-06-836 | Anthony | Clarcksons | 904 Augusta Drive | Blackbird | New Castle | DE | 19734-2606 |
6699-396-2905 | 649-33-505 | Spencer | Reuter | 2850 Burnsweak Avenue | Silver Spring | Montgomery | MD | 20910-7272 |
7080-583-5947 | 827-50-248 | Sandra | Moffat | 663 Sherry Wood East Street | Shimpstown | Franklin | PA | 17236-1116 |
Water Bill # | Account # | Meter Reading Start Date | Meter Reading End Date | Counter Reading Start | Counter Reading End |
847384 | 3028-502-9418 | 10/03/2024 | 01/06/2025 | 16 | 21 |
330820 | 7028-405-9381 | 10/03/2024 | 01/03/2025 | 9749 | 9906 |
468550 | 7518-302-6895 | 10/05/2024 | 01/09/2025 | 96 | 114 |
148274 | 9249-379-6848 | 10/05/2024 | 01/10/2025 | 260504 | 260555 |
326384 | 2068-258-9486 | 10/08/2024 | 01/10/2025 | 104837 | 104851 |
936497 | 5293-957-3395 | 10/11/2024 | 01/10/2025 | 350 | 356 |
682416 | 4820-375-2842 | 10/18/2024 | 01/20/2025 | 109992 | 109998 |
203804 | 8027-304-6829 | 10/22/2024 | 1/23/2025 | 9953 | 9979 |
149739 | 6003-386-3955 | 10/22/2024 | 1/18/2025 | 98 | 99 |
|
|||
Home | Copyright © 2017-2025, FunctionX | Saturday 09 November 2024, 11:19 | Home |
|