Introduction

.

.

Practical LearningPractical Learning: Introducing the Application

  1. Start Microsoft Visual Studio
  2. In the Visual Studio 2026 dialog box, click Create a New Project
  3. In the Create a New Project dialog box, click ASP.NET Core Web App (Razor Pages)
  4. Change the project Name to StellarWaterPoint1.
    Accept or change the project Location
  5. Click Next
  6. In the Additional Information dialog box, in the Framework combo box, select the highest .NET version.
    Click Create
  7. In the Solution Explorer, click the name of the project -> New -> New Folder
  8. Type Models as the name of the new folder
  9. In the Solution Explorer, right-click wwwroot -> Add -> New Folder
  10. Type Images as the name of the new folder and press Enter
  11. Add the following photos to the Images folder:
    Stellar Water Point - Water Bills Stellar Water Point - Customers Accounts
    Stellar Water Point - Water Meters Stellar Water Point - Community Services
    Stellar Water Point - Legal Affairs Stellar Water Point - Employees Portal
  12. In the Solution Explore, expand wwwroot, then expand css and double-click site.css
  13. Press Enter
  14. Add the following formats:
    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;   }
    
    
    .btn        { color: white; }
    .btn-maroon {
            --bs-btn-color: #000;
            --bs-btn-bg: #760c0c;
            --bs-btn-border-color: #ffc107;
            --bs-btn-hover-color: #800000;
            --bs-btn-hover-bg: #ffca2c;
            --bs-btn-hover-border-color: #ffc720;
            --bs-btn-focus-shadow-rgb: 217, 164, 6;
            --bs-btn-active-color: #000;
            --bs-btn-active-bg: #ffcd39;
            --bs-btn-active-border-color: #ffc720;
            --bs-btn-active-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125);
            --bs-btn-disabled-color: #000;
            --bs-btn-disabled-bg: #ffc107;
            --bs-btn-disabled-border-color: #ffc107;
    }
    .common-font {
        font-family: Garamond, Georgia, Cambria, 'Times New Roman', Times, serif
    }
  15. In the Solution Explorer, expand Pages and expand Shared
  16. In the Solution Explorer, under Pages and under Shared, click _Layout.cshtml to access it
  17. Change the document as follows:
    <!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="~/StellarWaterPoint5.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">&copy; 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>
  18. In the Solution Explorer, scroll down completly and double-click the last Index.cshtml
  19. Change the document as follows:
    @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>
  20. To execute the application, on the main menu, click Debug -> Start Without Debugging:

    Stellar Water Point - New Customer Account

  21. Return to your programming environment

Water Meters

Introduction

.

Practical LearningPractical Learning: Introducing Water Meters

  1. In the Solution Explorer, right-click Pages -> Add -> New Folder
  2. Type WaterMeters and press Enter

Displaying Water Meters

Practical LearningPractical Learning: Displaying Water Meters

  1. In the Solution Explorer, under Pages, right-click WaterMeters -> Add -> Razor Page...
  2. In the middle list of the Add New Scaffolded Item dialog box, make sure Razor Page - Empty is selected.
    Click Add
  3. In the middle list of the Add New Item dialog box, make sure Razor Page - Empty is selected.
    Accept the file name as Index.cshtml
    Click Add
  4. In the Solution Explorer, under WaterMeters and under Index.cshtml, double-click Index.cshtml.cs
  5. Change the document as follows:
    using Microsoft.AspNetCore.Mvc.RazorPages;
    using System.Data;
    using Microsoft.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='StellarWaterPoint101';" +
                                                                             "Integrated Security=True;" +
                                                                             "TrustServerCertificate=True;"))
                {
                    SqlCommand cmdWaterMeters = new SqlCommand("SELECT WaterMeterId, " +
                                                               "       MeterNumber,  " +
                                                               "       Make,         " +
                                                               "       Model,        " +
                                                               "       MeterSize     " +
                                                               "FROM   WaterMeters;  ",
                                                               scWaterDistribution);
    
                    scWaterDistribution.Open();
    
                    SqlDataAdapter sdaWaterMeters = new SqlDataAdapter(cmdWaterMeters);
    
                    sdaWaterMeters.Fill(dsWaterMeters);
                }
            }
        }
    }
  6. In the Solution Explorer, under WaterMeters, double-click Index.cshtml
  7. Change the document as follows:
    @page
    @using System.Data
    @model StellarWaterPoint5.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="Details" class="stellar">View a 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>
  8. To execute the application, on the main menu, click Debug -> Start Without Debugging

    Stellar Water Point

  9. In the top bar, click the Water Meters link:

    Stellar Water Point - Water Meters

  10. Return to your programming environoment

A Water Meter Record

Practical LearningPractical Learning: Creating a Water Meter Record

  1. In the Solution Explorer, right-click Models -> Add -> Class...
  2. Type WaterMeter as the name of the class
  3. Click Add
  4. Change the document as follows:
    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; }
        }
    }
  5. >In the Solution Explorer, expand Pages, right-click WaterMeters -> Add -> Razor Page...
  6. In the middle section of the Add New Scaffolder Item dialog box, make sure Razor Page - Empty is selected

    Add New Scaffolded Item

  7. Click Add
  8. In the Add New Item dialog box, make sure Razor Page - Empty is selected.
    Change the file Name to Create
  9. Click Add
  10. In the Solution Explorer, below WaterMeters, and below Create.cshtml, double-click Create.cshtml.cs to open the file
  11. Change the document as follows:
    using Microsoft.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='StellarWaterPoint101';" +
                                                                             "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");
            }
        }
    }
  12. In the Solution Explorer, under Pages and under WaterMeters, double-click Create.cshtml
  13. Change the document as follows:
    @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-maroon" />
            </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>
  14. To execute the application, on the main menu, click Debug -> Start Without Debugging

    Stellar Water Point

  15. In the top bar, click the Water Meters link:

    Stellar Water Point - Water Meters

  16. Click the Set Up a Water Meter link:

    Stellar Water Point - New Water Meter

  17. Enter the value for each of the following records and click Save Water Meter for each:

    Meter # Make Model Meter Size
    392-494-572 Constance Technologies TG-4822 5/8 Inches
    938-705-869 Stan Wood 66-G 1 Inch
    588-279-663 Estellano NCF-226 3/4 Inches

    Stellar Water Point - Water Meters

  18. Return to your programming environment

Water Meter Details

.

Practical LearningPractical Learning: Viewing a Water Meter Details

  1. In the Solution Explorer, under Pages, right-click WaterMeters -> Add -> Razor Page...
  2. In the Add New Scaffolded Item dialog box, make sure Razor Page - Empty is selected and click Add
  3. In the middle list of the Add New Item dialog box, make sure Razor Page - Empty is selected.
    Change the file Name to Details
  4. Click Add
  5. In the Solution Explorer, under WaterMeters, double-click Details.cshtml and change the document as follows:
    @page
    @using System.Data
    @using Microsoft.Data.SqlClient
    @model StellarWaterPoint5.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='StellarWaterPoint101';" +
                                                                         "Integrated Security=True;" +
                                                                         "TrustServerCertificate=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-maroon" />
            </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>
  6. To execute the application, on the main menu, click Debug -> Start Without Debugging

    Stellar Water Point

  7. Click the Water Meters link:

    Stellar Water Point - View Water Meter

  8. On the Water Meters webpage, click the View a Water Meter link:

    Stellar Water Point - View Water Meter

  9. In the Meter # text, type 392-494-572
  10. Click the Find Water Meter button:

    Stellar Water Point - View Water Meter

  11. Return to your programming environment

Updating a Water Meter Details

One of the routine operations performed on a database is to change the details of a record. To support this operation for a water meter, we will create a form that can be used to update the information of a water meter.

Practical LearningPractical Learning: Updating a Water Meter

  1. In the Solution Explorer, under Pages, right-click WaterMeters -> Add -> Razor Page...
  2. In the Add New Scaffolded Item dialog box, make sure Razor Page - Empty is selected.
    Click Add
  3. In the middle list of the Add New Item dialog box, make sure Razor Page - Empty is slected.
    Change the file Name to Edit
  4. Click Add
  5. Change the Edit.cshtml document as follows:
    @page
    @using System.Data;
    @using Microsoft.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='StellarWaterPoint101';" +
                                                                             "Integrated Security=True;" +
                                                                             "TrustServerCertificate=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='StellarWaterPoint101';" +
                                                                             "Integrated Security=True;" +
                                                                             "TrustServerCertificate=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-maroon" />
            </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-maroon" />
            </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>
  6. To execute the application, on the main menu, click Debug -> Start Without Debugging:

    Stellar Water Point

  7. On the Central form, click the Water Meters button:

    Stellar Water Point - View Water Meter

  8. Click the Edit Water Meter button:

    Stellar Water Point - Water Meter Editor

  9. In the Meter # text, type 938-705-869
  10. Click the Find button

    Stellar Water Point - Water Meter Editor

  11. Change the values as follows:
    Make: Stanford Trend
    Model: 266G
    Meter Size: 1 1/2 Inches

    Stellar Water Point - New Water Meter

  12. Click the Update button:

    Stellar Water Point - Water Meters

  13. Return to your programming environment

Removing a Water Meter from the Database

If a water meter has become useless and you want to make sure it is no more available for customer use, you can delete its record. To assist the user, we will create a form for that operation.

Practical LearningPractical Learning: Deleting a Water Meter Record

  1. In the Solution Explorer, under Pages, right-click WaterMeters -> Add -> Razor Page...
  2. In the Add New Scaffolded Item dialog box, make sure Razor Page - Empty is selected.
    Click Add
  3. In the Add New Item dialog box, make sure Razor Page - Empty is selected.
    Change the file Name to Delete
  4. Click Add
  5. Change the document as follows:
    @page
    @using System.Data;
    @using Microsoft.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='StellarWaterPoint101';" +
                                                                             "Integrated Security=True;" +
                                                                             "TrustServerCertificate=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='StellarWaterPoint101';" +
                                                                             "Integrated Security=True;" +
                                                                             "TrustServerCertificate=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-maroon" />
            </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-maroon" />
            </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>
  6. To execute the application, on the main menu, click Debug -> Start Without Debugging:

    Stellar Water Point - Water Meters

  7. Click the Water Meters link:

    Stellar Water Point - Water Meters

  8. Click the Delete Water Meter link:

    Stellar Water Point - Water Meter Deletion

  9. In the Meter # text, type 588-279-663
  10. Click the Find button:

    Stellar Water Point - Water Meter Deletion

  11. Click the Delete button:

    Stellar Water Point - Water Meter Deletion

  12. Return to your programming environment.
    Here is the SQL code to delete the WaterMeters table, create the table anew, and add records to it:
    USE StellarWaterPoint1;
    GO
    DROP TABLE WaterMeters;
    GO
    CREATE TABLE WaterMeters
    (
    	WaterMeterId int identity(1, 1),
    	MeterNumber  nvarchar(15) not null,
    	Make         nvarchar(25) null,
    	Model        nvarchar(15) not null,
    	MeterSize    nvarchar(15),
    	CONSTRAINT   PK_WaterMeters PRIMARY KEY(WaterMeterId)
    );
    GO
    INSERT INTO WaterMeters(MeterNumber, Make, Model, MeterSize)
    VALUES(N'392-494-572', N'Constance Technologies', N'TG-4822',  N'5/8 Inches'  ),
          (N'938-725-869', N'Stanford Trend',         N'266G',     N'1 1/2 Inches'),
          (N'588-279-663', N'Estellano',              N'NCF-226',  N'4 Inches'    ),
          (N'186-962-805', N'Lansome',                N'2800',     N'1 1/2 Inches'),
          (N'379-386-979', N'Planetra',               N'P-2020',   N'4 Inches'    ),
          (N'580-742-825', N'Kensa Sons',             N'KS2000A',  N'1 3/4 Inches'),
          (N'849-351-444', N'Raynes Energica',        N'a1088',    N'2 Inches'    ),
          (N'208-428-308', N'Constance Technologies', N'808D',     N'3/4 Inches'  ),
          (N'738-588-249', N'Warrington',             N'W4242',    N'5/8 Inches'  ),
          (N'496-813-794', N'Estellano',              N'NCF-226',  N'3/4 Inches'  ),
          (N'862-715-006', N'Warrington',             N'W-4040',   N'1/2 Inch'    ),
          (N'649-358-184', N'Raynes Energica',        N'b1700',    N'1 1/2 Inches'),
          (N'928-317-924', N'Gongola',                N'GN1000',   N'2 Inch'      ),
          (N'595-753-147', N'Grass Grill',            N'CRC-1000', N'1 Inch'      ),
          (N'799-528-461', N'Kensa Sons',             N'K-584-L',  N'3/4 Inches'  ),
          (N'386-468-057', N'Estellano',              N'NCF-226',  N'3/4 Inches'  ),
          (N'938-275-294', N'Constance Technologies', N'TT-8822',  N'4 Inches'    ),
          (N'288-427-585', N'Planetra',               N'P-2020',   N'1/2 Inch'    ),
          (N'394-835-297', N'Raynes Energica',        N'i2022',    N'3/4 Inches'  ),
          (N'847-252-246', N'Master Stream',          N'2000-MS',  N'1 1/2 Inches'),
          (N'349-725-848', N'Planetra',               N'P-8000',   N'4 Inches'    ),
          (N'713-942-058', N'Master Stream',          N'3366-MS',  N'3/4 Inches'  ),
          (N'747-581-379', N'Warrington',             N'W4242',    N'5/8 Inches'  ),
          (N'582-755-263', N'Kensa Sons',             N'KS2000A',  N'1 Inch'      ),
          (N'827-260-758', N'Raynes Energica',        N'a1088',    N'1-1/4 Inch'  ),
          (N'837-806-836', N'Lansome',                N'7400',     N'5/8 Inches'  ),
          (N'207-964-835', N'Constance Technologies', N'TG-6220',  N'5/8 Inches'  ),
          (N'296-837-495', N'Raynes Energica',        N'QG505',    N'4 Inches'    ),
          (N'468-359-486', N'Grass Grill',            N'KLP-8822', N'1-1/4 Inch'  ),
          (N'931-486-003', N'Planetra',               N'P-2020',   N'1/2 Inch'    ),
          (N'483-770-648', N'Warren',                 N'WWW',      N'0.1 Inches'  ),
          (N'592-824-957', N'Kensa Sons',             N'D-497-H',  N'3/4 Inches'  ),
          (N'293-835-704', N'Gongola',                N'GOL1000',  N'1/2 Inch'    ),
          (N'739-777-749', N'Warrington',             N'W2200W',   N'3/4 Inches'  ),
          (N'374-886-284', N'Raynes Energica',        N'i2022',    N'3/4 Inches'  ),
          (N'186-959-757', N'Kensa Sons',             N'M-686-G',  N'1 1/2 Inches'),
          (N'594-827-359', N'Planetra',               N'P-8000',   N'1 Inch'      ),
          (N'394-739-242', N'Master Stream',          N'9393-TT',  N'5/8 Inches'  ),
          (N'529-283-752', N'Constance Technologies', N'404T',     N'3/4 Inches'  ),
          (N'295-770-695', N'Warrington',             N'W-2286',   N'1-1/4 Inch'  ),
          (N'739-749-737', N'Kensa Sons',             N'KS2000A',  N'1 Inch'      ),
          (N'947-528-317', N'Gondola',                N'GDL-5000', N'1 Inch'      ),
          (N'630-207-055', N'Lansome',                N'2800',     N'3/4 Inches'  ),
          (N'827-508-248', N'Standard Trend',         N'428T',     N'3/4 Inches'  ),
          (N'293-924-869', N'Grass Grill',            N'CRC-2020', N'1/2 Inch'    ),
          (N'928-247-580', N'Gondola',                N'GOL2000',  N'0.34 Inch'   ),
          (N'682-537-380', N'Planetra',               N'P-2020',   N'1-1/4 Inch'  ),
          (N'470-628-850', N'Estellano',              N'WRT-482',  N'3/4 Inches'  ),
          (N'649-373-505', N'Constance Technologies', N'BD-7000',  N'5/8 Inches'  ),
          (N'306-842-497', N'Lansome',                N'9000',     N'3/4 Inches'  );
    GO

Customers

Introduction

Practical LearningPractical Learning: Introducing Customers

  1. To create a folder, in the Solution Explorer, right-click Pages -> Add -> New Folder
  2. Type Customers as the name of the folder

Customers Accounts

Practical LearningPractical Learning: Displaying Customers Accounts

  1. In the Solution Explorer, under Pages, right-click Customers -> Add -> Razor Page...
  2. In the Add New Scaffolded Item dialog box, make sure Razor Page - Empty is selected.
    Click Add
  3. In the middle list of the Add New Item dialog box, make sure Razor Page - Empty is selected.
    Accept the file Name as Index.cshtml.
    Click Add
  4. In the Solution Explorer, under Pages, under Customers, and under Index.cshtml, double-click Index.cshtml.cs
  5. Change the document as follows:
    using System.Data;
    using Microsoft.Data.SqlClient;
    using Microsoft.AspNetCore.Mvc.RazorPages;
    
    namespace StellarWaterPoint5.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='StellarWaterPoint101';" +
                                                                             "Integrated Security=True;" +
                                                                             "TrustServerCertificate=True;"))
                {
                    SqlCommand cmdCustomers = new SqlCommand("SELECT ALL * FROM CustomersAccounts ORDER BY CustId;",
                                                             scWaterDistribution);
    
                    scWaterDistribution.Open();
    
                    SqlDataAdapter sdaCustomers = new SqlDataAdapter(cmdCustomers);
    
                    sdaCustomers.Fill(dsCustomers);
                }
            }
        }
    }
  6. In the Solution Explorer, under Pages and under Customers, double-click Index.cshtml
  7. Change the document as follows:
    @page
    @using System.Data
    @model StellarWaterPoint5.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 class="text-center">Customer Id</td>
                <td class="text-center">Account #</td>
                <td>Account Name</td>
                <td>Water Meter</td>
                <td>Account Type</td>
                <td>Address</td>
                <td>City</td>
                <td>County</td>
                <td class="text-center">State</td>
                <td class="text-center">ZIP-Code</td>
            </tr>
            @foreach (DataRow drCustomer in Model.dsCustomers.Tables[0].Rows!)
            {
                <tr>
                    <td class="text-center">@drCustomer[0].ToString()</td>
                    <td class="text-center">@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 class="text-center">@drCustomer[8].ToString()</td>
                    <td class="text-center">@drCustomer[9].ToString()</td>
                </tr>
            }
        </table>
    
        <hr />
    
        <p class="text-center">
            <a asp-page="Create"  class="stellar">Create Customer Account</a> ::
            <a asp-page="Details" class="stellar">View Customer Account</a> ::
            <a asp-page="Edit"    class="stellar">Edit Customer Account</a> ::
            <a asp-page="Delete"  class="stellar">Delete a Customer Account</a>
        </p>
    }
  8. To execute the application, on the main menu, click Debug -> Start Without Debugging

    Stellar Water Point

  9. In the top bar, click the Customers link:

    Stellar Water Point - Water Meters

  10. Return to your programming environoment

A Customer Account

Practical LearningPractical Learning: Creating a Water Meter Record

  1. In the Solution Explorer, under Pages, right-click Customers -> Add -> Razor Page...
  2. In the Add New Scaffolded Item dialog box, make sure Razor Page - Empty is selected.
    Click Add
  3. In the middle list of the Add New Item dialog box, make sure Razor Page - Empty is selected.
    Change the file Name to Create
  4. Press Enter
  5. Change the document as follows: *
    @page
    @using System.Data;
    @using Microsoft.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? strAccountName   = string.Empty;
        string? strMeterNumber   = string.Empty;
        string? strAccountType   = 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='StellarWaterPoint101';" +
                                                                             "Integrated Security=True;" +
                                                                             "TrustServerCertificate=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='StellarWaterPoint101';" +
                                                                             "Integrated Security=True;" +
                                                                             "TrustServerCertificate=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-maroon" />
            </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-maroon" />
            </div>
        </div>
    </form>
    
    <hr />
    
    <p class="text-center">
        <a asp-page="./Details" class="stellar">Review a Customer&#039;s Account</a> ::
        <a asp-page="./Edit" class="stellar">Edit/Update a Customer&#039;s Account</a> ::
        <a asp-page="./Delete" class="stellar">Delete a Customer&#039;s Account</a>
    </p>
  6. To execute the application, on the main menu, click Debug -> Start Without Debugging:

    Stellar Water Point - New Customer Account

  7. On the Water Distribution form, click the Customers button:

    Stellar Water Point - Customers Accounts

  8. On the Central form of the customers, click the Create Customer Account button:

    Stellar Water Point - Customers Accounts

  9. In the account # text box, type 9279-570-8394
  10. In the meter # text box, type 799-528-461
  11. Click the Find water meter button
  12. Enter the other values as follows:
    Account #:    9279-570-8394
    Account Name: Thomas Stones
    Meter #:      799-528-461
    Account Type: RES - Residential Household
    Address:      10252 Broward Ave #D4
    City:         Frederick
    County:       Frederick
    State:        MD
    ZIP-Code:     21703-4422

    Stellar Water Point - New Customer Account

  13. Click Save Customer Account
  14. In the same way, create the following two records:

    Account # Account Name Meter # Account Type Address City County State ZIP-Code
    4086-938-4783 Hernola Dough 594-827-359 UUO - Unidentified or Unclassified Type of Organization 10 10 Hexagonal Drv Winston Yoke Penn 11402-4411
    7080-583-5947 Sunny Yard 827-508-248 WAT - Water Intensive Business(Laudromat, Hair Salon, Restaurant, etc 663 Sherry Wood East Street Shimpstown Franklin PA 17236-2626

    Stellar Water Point - Customers

  15. Close the forms and return to your programming environment

A Review of a Customer's Account

Practical LearningPractical Learning: Reviewing a Water Meter Record

  1. In the Solution Explorer, under Pages, right-click Customers -> Add -> Razor Page...
  2. In the Add New Scaffolded Item dialog box, make sure Razor Page - Empty is selected.
    Click Add
  3. In the middle list of the Add New Item dialog box, make sure Razor Page - Empty is selected.
    Change the file Name to Details
  4. Press Enter
  5. Change the Details.cshtml document as follows:
    @page
    @using System.Data;
    @using Microsoft.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='StellarWaterPoint101';" +
                                                                         "Integrated Security=True;" +
                                                                         "TrustServerCertificate=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='StellarWaterPoint101';" +
                                                                             "Integrated Security=True;" +
                                                                             "TrustServerCertificate=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-maroon" />
            </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&#039;s Account</a> ::
        <a asp-page="./Edit" class="stellar">Edit/Update a Customer&#039;s Account</a> ::
        <a asp-page="./Delete" class="stellar">Delete a Customer&#039;s Account</a>
    </p>
  6. To execute the application, on the main menu, click Debug -> Start Without Debugging

    Stellar Water Point

  7. On the Water Distribution form, click the Customers button:

    Stellar Water Point - Customers

  8. On the Central form of customers, click the View Customer Account button:

    Stellar Water Point - View Water Meter

  9. In the Account # text box, type 4086-938-4783
  10. Click the Find Customer Account button:

    Stellar Water Point - View Water Meter

  11. Close the Details form
  12. Close the forms and return to your programming environment

Updating a Customer's Account

Some time to time, a piece of information changes about a customer's account. When that happens, a user must update such an account. To assist the users in performing such an operation, we will create a form.

Practical LearningPractical Learning: Updating a Water Meter

  1. In the Solution Explorer, under Pages, right-click Customers -> Add -> Razor Page...
  2. In the Add New Scaffolded Item dialog box, make sure Razor Page - Empty is selected.
    Click Add
  3. In the middle list of the Add New Item dialog box, make sure Razor Page - Empty is selected.
    Change the file Name to Edit
  4. Click Add
  5. Change the document as follows:
    @page
    @using System.Data;
    @using Microsoft.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='StellarWaterPoint101';" +
                                                                             "Integrated Security=True;" +
                                                                             "TrustServerCertificate=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='StellarWaterPoint101';" +
                                                                                 "Integrated Security=True;" +
                                                                                 "TrustServerCertificate=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='StellarWaterPoint101';" +
                                                                             "Integrated Security=True;" +
                                                                             "TrustServerCertificate=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='StellarWaterPoint101';" +
                                                                             "Integrated Security=True;" +
                                                                             "TrustServerCertificate=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 AccountName = N'" + txtAccountName.Text + "' WHERE AccountNumber = N'" + mtbAccountNumber.Text + "';" +
                                                               "UPDATE Customers SET MeterNumber = N'" + mtbMeterNumber.Text + "' WHERE AccountNumber = N'" + mtbAccountNumber.Text + "';" +
                                                               "UPDATE Customers SET AccountType = N'" + strAccountType      + "' WHERE AccountNumber = N'" + mtbAccountNumber.Text + "';" +
                                                               "UPDATE Customers SET [Address]   = N'" + txtAddress.Text     + "' WHERE AccountNumber = N'" + mtbAccountNumber.Text + "';" +
                                                               "UPDATE Customers SET City        = N'" + txtCity.Text        + "' WHERE AccountNumber = N'" + mtbAccountNumber.Text + "';" +
                                                               "UPDATE Customers SET County      = N'" + txtCounty.Text      + "' WHERE AccountNumber = N'" + mtbAccountNumber.Text + "';" +
                                                               "UPDATE Customers SET [State]     = N'" + txtState.Text       + "' WHERE AccountNumber = N'" + mtbAccountNumber.Text + "';" +
                                                               "UPDATE Customers SET ZIPCode     = N'" + mtbZIPCode.Text     + "' WHERE AccountNumber = N'" + mtbAccountNumber.Text + "';",
                                                               scStellarWaterPoint);
    
                    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-maroon" />
            </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-maroon" />
            </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-maroon" />
            </div>
        </div>
    </form>
    
    <hr />
    
    <p class="text-center">
        <a asp-page="./Details" class="stellar">Review a Customer&#039;s Account</a> ::
        <a asp-page="./Edit" class="stellar">Edit/Update a Customer&#039;s Account</a> ::
        <a asp-page="./Delete" class="stellar">Delete a Customer&#039;s Account</a>
    </p>
  6. To execute the application, on the main menu, click Debug -> Start Without Debugging

    Stellar Water Point

  7. On the main form of the application, click the Customers button:

    Stellar Water Point - Customers

  8. Click the Edit Customer Account button:

    Stellar Water Point - Water Meter Editor

  9. In the Account # text, type 4086-938-4783
  10. Click the Find Customer Account button

    Stellar Water Point - Water Meter Editor

  11. Change the values as follows:
    Account Name: Bernotte Doughnuts
    Meter #:      580-742-825 and click Find Water Meter
    Account Type: BUS	- General Business
    Address:      10103 Hexagon Drive
    City:         Winterstown
    County:       York
    State:        PA
    ZIP-Code:     17402-8828

    Stellar Water Point - New Water Meter

  12. Click the Update Customer Account button:

    Stellar Water Point - Water Meters

  13. Close the forms and return to your programming environment

Deleting a Customer's Account

If a customer's account is not necessary anymore, the user can remove that account. To assist the user with this operation, we will create a form with necessary buttons.

Practical LearningPractical Learning: Deleting a Customer Account

  1. In the Solution Explorer, under Pages, right-click Customers -> Add -> Razor Page...
  2. In the Add New Scaffolded Item dialog box, make sure Razor Page - Empty is selected.
    Click Add
  3. In the middle list of the Add New Item dialog box, make sure Razor Page - Empty is selected.
    Change the file Name to Delete
  4. Press Enter
  5. Change the document as follows:
    @page
    @using System.Data;
    @using Microsoft.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='StellarWaterPoint101';" +
                                                                             "Integrated Security=True;" +
                                                                             "TrustServerCertificate=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='StellarWaterPoint101';" +
                                                                                 "Integrated Security=True;" +
                                                                                 "TrustServerCertificate=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='StellarWaterPoint101';" +
                                                                             "Integrated Security=True;" +
                                                                             "TrustServerCertificate=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-maroon" />
            </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-maroon" />
            </div>
        </div>
    </form>
    
    <hr />
    
    <p class="text-center">
        <a asp-page="./Details" class="stellar">Review a Customer&#039;s Account</a> ::
        <a asp-page="./Edit" class="stellar">Edit/Update a Customer&#039;s Account</a> ::
        <a asp-page="./Delete" class="stellar">Delete a Customer&#039;s Account</a>
    </p>
  6. To execute the application, on the main menu, click Debug -> Start Without Debugging:

    Stellar Water Point - Water Meters

  7. On the Central form, click the Customers button:

    Stellar Water Point - Customers

  8. On the Central form of the customers, click the Delete Customer Account button:

    Stellar Water Point - Customer Account Deletion

  9. In the Account # text box, type 7080-583-5947
  10. Click the Find Customer Account button:

    Stellar Water Point - Customer Account Deletion

  11. Click the Delete Customer Account button
  12. Read the text on the message box.
    On the message box, click Yes

    Stellar Water Point - Customers

  13. Close the forms and return to your programming environment
  14. From the Windows Explorer, open the Customers.xml file
  15. Replace the content of the file with the provided file
  16. Save the file
  17. Return to your programming environment

Water Bills

Introduction

.

Practical LearningPractical Learning: Preparing Bills

  1. In the Solution Explorer, right-click Pages -> Add -> New Folder
  2. Type WaterBills as the name of the folder

A List of Water Bills

Practical LearningPractical Learning: Viewing Water Bills

  1. In the Solution Explorer, under Pages, right-click WaterBills -> Add -> Razor Page...
  2. In the Add New Scaffolded Item dialog box, make sure Razor Page - Empty is selected.
    Click Add
  3. In the middle list of the Add New Item dialog box, make sure Razor Page - Empty is selected.
    Accept the suggested file Name as Index.cshtml .
    Click Add
  4. Change the document follows:
    @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>

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 LearningPractical Learning: Creating Water Bills

  1. In the Solution Explorer, right-click Pages -> Add -> New Folder
  2. Type WaterBills as the name of the new folder, and press Enter
  3. In the Solution Explorer, under Pages, right-click WaterBills -> Add -> Razor Page...
  4. In the Add New Scaffolded Item dialog box, make sure Razor Page - Empty is selected.
    Click Add
  5. In the middle list of the Add New Item dialog box, make sure Razor Page - Empty is selected.
    Change the file Name to Create
  6. Click Add
  7. Change the Create.cshtml document as follows:
    @page
    @using System.Data;
    @using Microsoft.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='StellarWaterPoint101';" +
                                                                             "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='StellarWaterPoint101';" +
                                                                                 "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='StellarWaterPoint101';" +
                                                                                 "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='StellarWaterPoint101';" +
                                                                             "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-maroon" />
                </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-maroon" />
                </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-maroon" />
                </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>
  8. In the Solution Explorer, under Pages, right-click WaterBills -> Add -> Razor Page...
  9. In the Add New Scaffolded Item dialog box, make sure Razor Page - Empty is selected.
    Click Add
  10. In the middle list of the Add New Item dialog box, make sure Razor Page - Empty is selected.
    Change the file Name to Details
  11. Click Add
  12. Change the document as follows:
    @page
    @using System.Data;
    @using Microsoft.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='StellarWaterPoint101';" +
                                                                                 "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='StellarWaterPoint101';" +
                                                                                 "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='StellarWaterPoint101';" +
                                                                                 "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-maroon" />
                </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-maroon" />
                </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>
  13. In the Solution Explorer, under Pages, right-click WaterBills -> Add -> Razor Page...
  14. In the Add New Scaffolded Item dialog box, make sure Razor Page - Empty is selected.
    Click Add
  15. In the middle list of the Add New Item dialog box, make sure Razor Page - Empty is selected.
    Change the file Name to Edit
  16. Click Add
  17. Change the document as follows:
    @page
    @using System.Data;
    @using Microsoft.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='StellarWaterPoint101';" +
                                                                                 "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='StellarWaterPoint101';" +
                                                                                 "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='StellarWaterPoint101';" +
                                                                                 "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='StellarWaterPoint101';" +
                                                                             "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='StellarWaterPoint101';" +
                                                                                 "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='StellarWaterPoint101';" +
                                                                             "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-maroon" />
                </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-maroon" />
                </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-maroon" />
                </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-maroon" />
                </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>
  18. In the Solution Explorer, under Pages, right-click WaterBills -> Add -> Razor Page...
  19. In the Add New Scaffolded Item dialog box, make sure Razor Page - Empty is selected.
    Click Add
  20. In the middle list of the Add New Item dialog box, make sure Razor Page - Empty is selected.
    Change the file Name to Delete
  21. Click Add
  22. Change the document as follows:
    @page
    @using System.Data;
    @using Microsoft.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='StellarWaterPoint101';" +
                                                                                 "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='StellarWaterPoint101';" +
                                                                                 "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='StellarWaterPoint101';" +
                                                                                 "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='StellarWaterPoint101';" +
                                                                             "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-maroon" />
                </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-maroon" />
                </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>

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 LearningPractical Learning: Finalizing and Testing the Application

  1. To execute, on the main menu, click Debug and click Start Without Debugging:

  2. In the top bar, click the Water Meters link

    Water Meters

  3. Click the Create Water Meter link

    Water Meters

  4. Create each of the following records, and save after each record:
     
    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
  5. Click the Customers link
  6. Click the Create Customer Account link

    Water Meters

  7. Create the following records:
    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
  8. Click the Water Bills link
  9. Click Water Bill Processing:

    Water Bill Processiing

    Water Bill Processiing

    Water Bill Processiing

  10. Create and save some records as follows:
    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
  11. Close the browser and return to your programming environment
  12. Close your programming environment

Home Copyright © 2017-2025, FunctionX Saturday 09 November 2024, 11:19 Home