Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7166725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:27:36+00:00 2026-05-28T14:27:36+00:00

I have a small web form that user will enter some patient data and

  • 0

I have a small web form that user will enter some patient data and it will get passed along to insurance hub. I just want to provide some basic validation e.g the social security number sb numerics, a legnth of 10, age sb numercial and maybe over a certain age number, etc. how can i do this, here in this code ?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
...


namespace PBM
{
    public partial class MainPage : UserControl
    {
        private DomainServicePBM _context = new DomainServicePBM();
        public MainPage()
        {
            InitializeComponent();
            this.ObjPatient = new Patient();
        }

        private void btnSearch_Click(object sender, RoutedEventArgs e)
        {
            dgPatient.ItemsSource = _context.Patients;
            _context.Load(_context.GetPatientsBySearchQuery(sTxtFirstName.Text.Trim(), sTxtLastName.Text.Trim(), sCombGender.SelectedIndex == 1 ? false: sCombGender.SelectedIndex == 2 ? true : new bool?()));

            PagedCollectionView itemListView = new PagedCollectionView(dgPatient.ItemsSource);
            dpPatient.Source = itemListView;
        }

        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            //_context = new DomainServicePBM();
            if (ObjPatient != null && ObjPatient.PatientID > 0)
            {
                Patient p = _context.Patients.Single(pat => pat.PatientID == this.ObjPatient.PatientID);
                p.FirstName = txtFirstName.Text.Trim();
                p.LastName = txtLastName.Text.Trim();
                p.MiddleName = txtMiddleName.Text.Trim();
                p.Gender = cmbGender.SelectedIndex == 0 ? false : true;
                p.DOB = ctrlDTDOB.SelectedDate;
                p.Age = Convert.ToInt32(txtAge.Text.Trim());
                p.MaterialStatus = cmbMaritalStatus.SelectedIndex == 0 ? (byte)MaritalStatus.Single :
                    cmbMaritalStatus.SelectedIndex == 1 ? (byte)MaritalStatus.Married : (byte)MaritalStatus.Divorced;
                p.SSN = txtSSN.Text.Trim();
                p.MedicalID = txtMedicalID.Text.Trim();
                p.Medicare = txtMedicare.Text.Trim();
                p.Race = txtRace.Text.Trim();
                p.AdmitFrom = ctrlDTAdmitFrom.SelectedDate;
            }
            else
            {
                _context.Patients.Add(new Patient
                {
                    FirstName = txtFirstName.Text.Trim(),
                    LastName = txtLastName.Text.Trim(),
                    MiddleName = txtMiddleName.Text.Trim(),
                    Gender = cmbGender.SelectedIndex == 0 ? false : true,
                    DOB = ctrlDTDOB.SelectedDate,
                    Age = Convert.ToInt32(txtAge.Text.Trim()),
                    MaterialStatus = cmbMaritalStatus.SelectedIndex == 0 ? (byte)MaritalStatus.Single :
                    cmbMaritalStatus.SelectedIndex == 1 ? (byte)MaritalStatus.Married : (byte)MaritalStatus.Divorced,
                    SSN = txtSSN.Text.Trim(),
                    MedicalID = txtMedicalID.Text.Trim(),
                    Medicare = txtMedicare.Text.Trim(),
                    Race = txtRace.Text.Trim(),
                    AdmitFrom = ctrlDTAdmitFrom.SelectedDate
                });
            }
            _context.SubmitChanges(
                (SubmitOperation so) =>
                {
                    if (so.HasError)
                    {
                        MessageBox.Show("Patient Info Not Saved.");
                    }
                    else
                    {
                        MessageBox.Show("Patient Info Saved Successfully.");
                        ResetControls();
                        this.ObjPatient = new Patient();
                    }
                }, null);


        }



        Patient ObjPatient { get; set; }

        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            this.ObjPatient = new Patient();
        }

        private void ResetControls()
        {
            txtFirstName.Text = txtLastName.Text = txtMiddleName.Text = txtMedicalID.Text = txtMedicare.Text = txtRace.Text = txtSSN.Text = txtAge.Text = string.Empty;
            cmbGender.SelectedIndex = cmbMaritalStatus.SelectedIndex = 0;
            ctrlDTAdmitFrom.SelectedDate = ctrlDTDOB.SelectedDate = DateTime.Now;
        }

        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            this.ObjPatient = dgPatient.SelectedItem as Patient;
            if (this.ObjPatient != null)
            {
                _context.Patients.Remove(this.ObjPatient);
                _context.SubmitChanges(
                    (SubmitOperation so) =>
                    {
                        if (so.HasError)
                        {
                            MessageBox.Show(so.Error.ToString());
                        }
                        else
                        {
                            MessageBox.Show("Patient Deleted Successfully.");
                        }

                    }, null);
            }
            else
            {
                MessageBox.Show("Please select patient first.");
            }
        }

        private void btnEdit_Click(object sender, RoutedEventArgs e)
        {
            this.ObjPatient = dgPatient.SelectedItem as Patient;
            if (ObjPatient != null)
            {
                txtFirstName.Text = ObjPatient.FirstName;
                txtLastName.Text = ObjPatient.LastName;
                txtMiddleName.Text = ObjPatient.MiddleName;
                cmbGender.SelectedIndex = ObjPatient.Gender == true ? 0 : 1;
                cmbMaritalStatus.SelectedIndex = ObjPatient.MaterialStatus == 1 ? 0 : ObjPatient.MaterialStatus == 2 ? 1 : 2;
                txtAge.Text = Convert.ToString(ObjPatient.Age);
                ctrlDTDOB.SelectedDate = ObjPatient.DOB;
                ctrlDTAdmitFrom.SelectedDate = Convert.ToDateTime(ObjPatient.AdmitFrom);
                txtMedicalID.Text = ObjPatient.MedicalID;
                txtMedicare.Text = ObjPatient.Medicare;
                txtRace.Text = ObjPatient.Race;
                txtSSN.Text = ObjPatient.SSN;
            }
        }

        private void dpPatient_PageIndexChanged(object sender, EventArgs e)
        {
            _context.Patients.Skip(dpPatient.PageIndex).Take(1);
        }

    }

    public enum MaritalStatus {
        Single=0,
        Married=1, 
        Divorced = 2
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:27:36+00:00Added an answer on May 28, 2026 at 2:27 pm

    I would take a look at the DataAnnations namespace. It provides attributes for defining all sorts of validations. You’ll need to apply these attributes to the properties that need validation. Then you’ll need a way to check if these attributes pass validation. This is typically done using reflection. Take a look at this answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small web form which will cause a PHP script to send
I have small web app that generate PDF files as a report. I'm trying
I have a web form used for importing data from a CSV file. It
I am just trying to write a small web page that can parse some
i have made a small web application with form.html output.jsp ServletOne.java In the form.html,users
I have a web form and I'm using PHP. I'm aware that forms can
I have a small web app I wrote that has a Dijit.layout.BorderContainer nested within
I have a ASP.Net web form that contains both text box fields and hidden
I'm writing a small web app that will receive and parse tab-delimited text files
I have a small web application with ASP.NET AJAX running well under the Cassini

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.