Question

I need to write a function in C# that would validated user entry for Payment Code in the form.

The form is used to collect information about payments. User can enter ad many rows/entries as he/she wishes by clicking "Add another Payment" button on the buttom. There is a Payment Code field that needs to be validates. It's a drop down list, with many values but the user is eligible to select only two of them: Meal and Travel. Every row/entry must have a Payment Code of either Meal or Travel, if user selects any other value or leaves this field blank an error message will be issued. Every form must have both Payment Values (Meal and Travel) and any combination. If user entered only Meal payment coded, but no Travel, an error message should specify that Payment information for Travel is missing. The same as if user would miss a Meal Code. The form looks like this:

Payment Code Payment Date Amount Currency Trave 08.01.2018 1765.54 USD Travel Meal Utility Medical Add another Payment

Just to summarize the requirements. C# code must validate Payment Code field in every row(entry), to make sure that nothing else but both Travel and Meal are selected, and issue a query (error) message if the field is blank, something other then Travel or Meal is selected or if either Travel or Meal is missing. The error message must specify whether Travel or Meal is missing.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Output will be like

Form payment code Amount Utility Add another Payment Travel Meal is missing OK

Code will be like

using System;
using System.Windows.Forms;

namespace mEALtRAVELfORM
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();

comboBox1.Items.Add("Travel");
comboBox1.Items.Add("Meal");
comboBox1.Items.Add("Utility");
comboBox1.Items.Add("Medical");

comboBox2.Items.Add("Travel");
comboBox2.Items.Add("Meal");
comboBox2.Items.Add("Utility");
comboBox2.Items.Add("Medical");

}

private void button1_Click(object sender, EventArgs e)
{

  
if(comboBox1.Text !="Travel" && comboBox2.Text !="Travel" )

{
MessageBox.Show("Travel is missing");


}
else if (comboBox1.Text != "Meal" && comboBox2.Text != "Meal")
{

MessageBox.Show("Meal is missing");

}

else
{
MessageBox.Show("Successful");
}
  
}
}
}

Designer code will be like:

namespace mEALtRAVELfORM
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.textBox2 = new System.Windows.Forms.TextBox();
this.comboBox2 = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// comboBox1
//
this.comboBox1.FormattingEnabled = true;
this.comboBox1.Location = new System.Drawing.Point(41, 41);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(121, 21);
this.comboBox1.TabIndex = 0;
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(210, 42);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(51, 20);
this.textBox1.TabIndex = 1;
//
// button1
//
this.button1.Location = new System.Drawing.Point(339, 42);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(119, 100);
this.button1.TabIndex = 2;
this.button1.Text = "Add another Payment";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(210, 118);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(51, 20);
this.textBox2.TabIndex = 4;
//
// comboBox2
//
this.comboBox2.FormattingEnabled = true;
this.comboBox2.Location = new System.Drawing.Point(41, 117);
this.comboBox2.Name = "comboBox2";
this.comboBox2.Size = new System.Drawing.Size(121, 21);
this.comboBox2.TabIndex = 3;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(38, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(74, 13);
this.label1.TabIndex = 5;
this.label1.Text = "payment code";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(210, 9);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(43, 13);
this.label2.TabIndex = 6;
this.label2.Text = "Amount";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(470, 365);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.comboBox2);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.comboBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.ComboBox comboBox2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
}
}

Please rate it if the above solution helps you in any way or if you have any concerns comment it, I will help you through again.

Add a comment
Know the answer?
Add Answer to:
I need to write a function in C# that would validated user entry for Payment Code...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In this exercise, you’ll add code to a form that converts the value the user enters...

    In this exercise, you’ll add code to a form that converts the value the user enters based on the selected conversion type. The application should handle the following conversions: 1. Open the Conversions project. Display the code for the form, and notice the rectangular array whose rows contain the value to be displayed in the combo box, the text for the labels that identify the two text boxes, and the multiplier for the conversion as shown above. Note: An array...

  • I need html coding in notepad++ according to the requirments those are listed in the pictures....

    I need html coding in notepad++ according to the requirments those are listed in the pictures. The purpose of this assignment is to figure out the designing and development of HTML forms with CSS and interaction between users and forms by using the Javascript script language. Below Student Registration Form views some form inputs entered by users and shows in the form as a response. Resources: All posted class documents and lab practices will help to complete this assignment. Student...

  • need this in #c . You will now add server side validation code to the frmPersonnel...

    need this in #c . You will now add server side validation code to the frmPersonnel page. Currently, when the Submit button is pressed, the frmPersonnelVerified page is displayed. This is because the frmPersonnelVerified page is set as the Submit button's PostBackUrl property. Instead of having the page go directly to the frmPersonnelVerified page when the Submit button is pressed, we want to do some server side validation. If any of the validation rules fail, we will redisplay the frmPersonnel...

  • This is a matlab HW that I need the code for, if someone could help me figure this out it would b...

    This is a matlab HW that I need the code for, if someone could help me figure this out it would be appreciated. The value of t can be estimated from the following equation: in your script file, estimate the value of π for any number of terms. You must ask the user for the desired number of terms and calculate the absolute error/difference between your calculation and the built-in MATLAB value ofpi. Display your results with the following message...

  • NEED HELP with HTML with Javascript embedding for form validation project below. I have my code...

    NEED HELP with HTML with Javascript embedding for form validation project below. I have my code below but I'm stuck with validation. If anyone can fix it, I'd really appreciate. ****************************************************************************** CODE: <!DOCTYPE html> <!-- To change this license header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. --> <html> <head> <title>Nice</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script> var textFromTextArea; function getWords(){ var text =...

  • Project 10-1 Convert lengths In this assignment, you’ll add code to a form that converts the valu...

    Project 10-1 Convert lengths In this assignment, you’ll add code to a form that converts the value the user enters based on the selected conversion type. The application should handle the following conversions: From To Conversion Miles - Kilometers: 1 mile = 1.6093 kilometers Kilometers - Miles: 1 kilometer = 0.6214 miles Feet - Meters: 1 foot = 0.3048 meters Meters - Feet: 1 meter = 3.2808 feet Inches - Centimeters: 1 inch = 2.54 centimeters Centimeters - Inches: 1...

  • Python GPA calculator: Assume the user has a bunch of courses they took, and need to...

    Python GPA calculator: Assume the user has a bunch of courses they took, and need to calculate the overall GPA. We will need to get the grade and number of units for each course. It is not ideal to ask how many courses they took, as they have to manually count their courses. Programming is about automation and not manual work. We will create a textual menu that shows 3 choices. 1. Input class grade and number of units. 2....

  • **This is for the C Language. Trigonometric Calculator Specification You are required to write a program...

    **This is for the C Language. Trigonometric Calculator Specification You are required to write a program that calculates and displays values of the trigonometric functions sine, cosine, and tangent for user-supplied angular values. The basic program must comply with the following specification. 1. When the program is run, it is to display a short welcome message. TRIG: the trigonometric calculator 2. The program shall display a message prompting the user to enter input from the keyboard. Please input request (h-help,...

  • abe 2 Use the provided HTML for the following questions. You only need to write the...

    abe 2 Use the provided HTML for the following questions. You only need to write the JavaScript code for the following questions. No need to write a full JavaScript application. Ex. if I said "Set a myVar variable equal to 2" you would simply write myVar = 2; Please write your code in a separate file. The file MUST be named with the following format lastname_firstname.js. Use comments to divide the questions on the single JavaScript file. Example, for question...

  • All code will be in Java, and there will be TWO source code. I. Write the...

    All code will be in Java, and there will be TWO source code. I. Write the class  MailOrder to provide the following functions: At this point of the class, since we have not gone through object-oriented programming and method calling in detail yet, the basic requirement in this homework is process-oriented programming with all the code inside method processOrderof this class. Inside method processOrder, we still follow the principles of structured programming.   Set up one one-dimensional array for each field: product...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT