In: Computer Science
Your task is to create a book ordering form using VISUAL STUDIOS, with the code and screenshots
1. Boxes for first name, last name, address.
2. Radio buttons to select: hard cover, soft cover, ebook.
3. Drop down list to select the book (make up three or four book names).
4. Radio buttons to select credit card (at least Visa, Master Card, American Express).
5. Box to enter credit card numbers.
6. The credit card box MUST verify that numbers are entered only. It will display error information and make the user enter the information agaion.
7. All items will be checked to make sure the user entered something, or selected something. If something is missing an error message must be displayed.
Once the user clicks the submit button, the following happens:
A total price is determined by looking at the book selected, and the type of book selected.
If the book is hardback, the price is $50, softback $40, ebook $30.
Add 10% sales tax.
Display the book name, book type, and total cost back to the user. Also thank them for the order.
Make everything user friendly by including labels, and text to explain what to do and what to enter into boxes.
1. Open Visual studio
2.Open new project -> C# -> Windows Form App (.net framework)
3. Add text boxes and labels for firstname,lastname and address and name the tbxFirstName,tbxLastName and tbxAddr.
4. Add groupbox and add radiobuttons with rBtnHardCover, rBtnSoftCover and rBtnEbook, select checked true in single radio
5. Add Combobox with DropDownStyle to Dropdownlist and add book names in collection items.
6. Radio buttons for credit card same as cover- > visa,master and american express, select checked true in single radio
code for from cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace BookOrderForm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnSubmit_Click(object sender, EventArgs e)
{
if( string.IsNullOrEmpty( tbxFirstName.Text.Trim()))
{
MessageBox.Show("Please enter first name");
return;
}
if (string.IsNullOrEmpty(tbxLastName.Text.Trim()))
{
MessageBox.Show("Please enter last name");
return;
}
if (string.IsNullOrEmpty(tbxAddr.Text.Trim()))
{
MessageBox.Show("Please enter address");
return;
}
if (string.IsNullOrEmpty(tbxCardNo.Text.Trim()))
{
MessageBox.Show("Please enter card no");
return;
}
string booktype = rBtnEbook.Text;
Double Price = 30;
if(rBtnHardCover.Checked)
{
Price = 50;
booktype = rBtnHardCover.Text;
}
else if(rBtnSoftCover.Checked)
{
Price = 40;
booktype = rBtnSoftCover.Text;
}
double total = Price + Price * 10 / 100;
MessageBox.Show(@"Thanks for order."+Environment.NewLine+"Order
Details"+ Environment.NewLine+
"Book : " +cbxBookName.Text+ Environment.NewLine + "BookType : "+
booktype + Environment.NewLine + "Cost :
"+total.ToString("0.00")
);
}
private void Form1_Load(object sender, EventArgs e)
{
cbxBookName.SelectedIndex = 0;
}
private void tbxCardNo_KeyPress(object sender, KeyPressEventArgs
e)
{
if (!char.IsDigit(e.KeyChar) && e.KeyChar != 8)
e.Handled = true;
}
}
}
Designer:
namespace BookOrderForm
{
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.label1 = new System.Windows.Forms.Label();
this.tbxFirstName = new System.Windows.Forms.TextBox();
this.tbxLastName = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.tbxAddr = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.rBtnHardCover = new System.Windows.Forms.RadioButton();
this.rBtnSoftCover = new System.Windows.Forms.RadioButton();
this.rBtnEbook = new System.Windows.Forms.RadioButton();
this.cbxBookName = new System.Windows.Forms.ComboBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label4 = new System.Windows.Forms.Label();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.rBtnAE = new System.Windows.Forms.RadioButton();
this.rBtnVisa = new System.Windows.Forms.RadioButton();
this.rBtnMaster = new System.Windows.Forms.RadioButton();
this.tbxCardNo = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.btnSubmit = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(57, 27);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(63, 13);
this.label1.TabIndex = 0;
this.label1.Text = "FirstName : ";
//
// tbxFirstName
//
this.tbxFirstName.Location = new System.Drawing.Point(126,
24);
this.tbxFirstName.Name = "tbxFirstName";
this.tbxFirstName.Size = new System.Drawing.Size(149, 20);
this.tbxFirstName.TabIndex = 1;
//
// tbxLastName
//
this.tbxLastName.Location = new System.Drawing.Point(126,
50);
this.tbxLastName.Name = "tbxLastName";
this.tbxLastName.Size = new System.Drawing.Size(149, 20);
this.tbxLastName.TabIndex = 3;
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(57, 53);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(64, 13);
this.label2.TabIndex = 2;
this.label2.Text = "Last Name :";
//
// tbxAddr
//
this.tbxAddr.Location = new System.Drawing.Point(126, 76);
this.tbxAddr.Multiline = true;
this.tbxAddr.Name = "tbxAddr";
this.tbxAddr.Size = new System.Drawing.Size(149, 54);
this.tbxAddr.TabIndex = 5;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(57, 79);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(51, 13);
this.label3.TabIndex = 4;
this.label3.Text = "Address :";
//
// rBtnHardCover
//
this.rBtnHardCover.AutoSize = true;
this.rBtnHardCover.Checked = true;
this.rBtnHardCover.Location = new System.Drawing.Point(19,
19);
this.rBtnHardCover.Name = "rBtnHardCover";
this.rBtnHardCover.Size = new System.Drawing.Size(76, 17);
this.rBtnHardCover.TabIndex = 6;
this.rBtnHardCover.TabStop = true;
this.rBtnHardCover.Text = "hard cover";
this.rBtnHardCover.UseVisualStyleBackColor = true;
//
// rBtnSoftCover
//
this.rBtnSoftCover.AutoSize = true;
this.rBtnSoftCover.Location = new System.Drawing.Point(19,
42);
this.rBtnSoftCover.Name = "rBtnSoftCover";
this.rBtnSoftCover.Size = new System.Drawing.Size(72, 17);
this.rBtnSoftCover.TabIndex = 7;
this.rBtnSoftCover.TabStop = true;
this.rBtnSoftCover.Text = "soft cover";
this.rBtnSoftCover.UseVisualStyleBackColor = true;
//
// rBtnEbook
//
this.rBtnEbook.AutoSize = true;
this.rBtnEbook.Location = new System.Drawing.Point(19, 65);
this.rBtnEbook.Name = "rBtnEbook";
this.rBtnEbook.Size = new System.Drawing.Size(55, 17);
this.rBtnEbook.TabIndex = 8;
this.rBtnEbook.TabStop = true;
this.rBtnEbook.Text = "ebook";
this.rBtnEbook.UseVisualStyleBackColor = true;
//
// cbxBookName
//
this.cbxBookName.DropDownStyle =
System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cbxBookName.FormattingEnabled = true;
this.cbxBookName.Items.AddRange(new object[] {
"Book1",
"Book2",
"Book3"});
this.cbxBookName.Location = new System.Drawing.Point(126,
234);
this.cbxBookName.Name = "cbxBookName";
this.cbxBookName.Size = new System.Drawing.Size(149, 21);
this.cbxBookName.TabIndex = 9;
//
// groupBox1
//
this.groupBox1.Controls.Add(this.rBtnEbook);
this.groupBox1.Controls.Add(this.rBtnHardCover);
this.groupBox1.Controls.Add(this.rBtnSoftCover);
this.groupBox1.Location = new System.Drawing.Point(126, 136);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(149, 92);
this.groupBox1.TabIndex = 13;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Cover type";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(57, 237);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(66, 13);
this.label4.TabIndex = 14;
this.label4.Text = "Book Name:";
//
// groupBox2
//
this.groupBox2.Controls.Add(this.rBtnAE);
this.groupBox2.Controls.Add(this.rBtnVisa);
this.groupBox2.Controls.Add(this.rBtnMaster);
this.groupBox2.Location = new System.Drawing.Point(126, 261);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(149, 92);
this.groupBox2.TabIndex = 15;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "Select Credit Card";
//
// rBtnAE
//
this.rBtnAE.AutoSize = true;
this.rBtnAE.Location = new System.Drawing.Point(19, 65);
this.rBtnAE.Name = "rBtnAE";
this.rBtnAE.Size = new System.Drawing.Size(109, 17);
this.rBtnAE.TabIndex = 8;
this.rBtnAE.TabStop = true;
this.rBtnAE.Text = "American Express";
this.rBtnAE.UseVisualStyleBackColor = true;
//
// rBtnVisa
//
this.rBtnVisa.AutoSize = true;
this.rBtnVisa.Checked = true;
this.rBtnVisa.Location = new System.Drawing.Point(19, 19);
this.rBtnVisa.Name = "rBtnVisa";
this.rBtnVisa.Size = new System.Drawing.Size(45, 17);
this.rBtnVisa.TabIndex = 6;
this.rBtnVisa.TabStop = true;
this.rBtnVisa.Text = "Visa";
this.rBtnVisa.UseVisualStyleBackColor = true;
//
// rBtnMaster
//
this.rBtnMaster.AutoSize = true;
this.rBtnMaster.Location = new System.Drawing.Point(19, 42);
this.rBtnMaster.Name = "rBtnMaster";
this.rBtnMaster.Size = new System.Drawing.Size(82, 17);
this.rBtnMaster.TabIndex = 7;
this.rBtnMaster.TabStop = true;
this.rBtnMaster.Text = "Master Card";
this.rBtnMaster.UseVisualStyleBackColor = true;
//
// tbxCardNo
//
this.tbxCardNo.Location = new System.Drawing.Point(126, 359);
this.tbxCardNo.MaxLength = 16;
this.tbxCardNo.Name = "tbxCardNo";
this.tbxCardNo.Size = new System.Drawing.Size(149, 20);
this.tbxCardNo.TabIndex = 17;
this.tbxCardNo.KeyPress += new
System.Windows.Forms.KeyPressEventHandler(this.tbxCardNo_KeyPress);
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(57, 362);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(55, 13);
this.label5.TabIndex = 16;
this.label5.Text = "Card No : ";
//
// btnSubmit
//
this.btnSubmit.Location = new System.Drawing.Point(200, 401);
this.btnSubmit.Name = "btnSubmit";
this.btnSubmit.Size = new System.Drawing.Size(75, 23);
this.btnSubmit.TabIndex = 18;
this.btnSubmit.Text = "Submit";
this.btnSubmit.UseVisualStyleBackColor = true;
this.btnSubmit.Click += new
System.EventHandler(this.btnSubmit_Click);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(325, 450);
this.Controls.Add(this.btnSubmit);
this.Controls.Add(this.tbxCardNo);
this.Controls.Add(this.label5);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.label4);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.cbxBookName);
this.Controls.Add(this.tbxAddr);
this.Controls.Add(this.label3);
this.Controls.Add(this.tbxLastName);
this.Controls.Add(this.label2);
this.Controls.Add(this.tbxFirstName);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Book Order";
this.Load += new System.EventHandler(this.Form1_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox tbxFirstName;
private System.Windows.Forms.TextBox tbxLastName;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox tbxAddr;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.RadioButton rBtnHardCover;
private System.Windows.Forms.RadioButton rBtnSoftCover;
private System.Windows.Forms.RadioButton rBtnEbook;
private System.Windows.Forms.ComboBox cbxBookName;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.RadioButton rBtnAE;
private System.Windows.Forms.RadioButton rBtnVisa;
private System.Windows.Forms.RadioButton rBtnMaster;
private System.Windows.Forms.TextBox tbxCardNo;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Button btnSubmit;
}
}
form: