Answer to Question #5641 in C# for Sophie

Question #5641
Create a form that accepts an arrival and departure date for a reservation from the user. The form should allow the user to select a room type from a list (single, double, king and suite) and then calculate the number of nights and the total price for the reservation.
1
Expert's answer
2011-12-16T08:34:02-0500
Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace ReservationForm
{
static class Program
{
& /// <summary>
& /// The main entry point for the application.
& /// </summary>
& [STAThread]
& static void Main()
& {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
& }
}
}

Form1.Designer.cs

namespace ReservationForm
{
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.label4 = new System.Windows.Forms.Label();
this.NumberOfNigthslabel = new System.Windows.Forms.Label();
this.TotalPricelabel = new System.Windows.Forms.Label();
this.ArrivaldateTimePicker = new System.Windows.Forms.DateTimePicker();
this.DeparturedateTimePicker = new System.Windows.Forms.DateTimePicker();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.SinglecheckBox = new System.Windows.Forms.CheckBox();
this.DoublecheckBox = new System.Windows.Forms.CheckBox();
this.KingcheckBox = new System.Windows.Forms.CheckBox();
this.label5 = new System.Windows.Forms.Label();
this.DoublePricelabel = new System.Windows.Forms.Label();
this.KingPricelabel = new System.Windows.Forms.Label();
this.SinglePricelabel = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label6 = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(415, 50);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(87, 13);
this.label4.TabIndex = 16;
this.label4.Text = "Number of nigths";
//
// NumberOfNigthslabel
//
this.NumberOfNigthslabel.AutoSize = true;
this.NumberOfNigthslabel.Location = new System.Drawing.Point(451, 74);
this.NumberOfNigthslabel.Name = "NumberOfNigthslabel";
this.NumberOfNigthslabel.Size = new System.Drawing.Size(0, 13);
this.NumberOfNigthslabel.TabIndex = 17;
//
// TotalPricelabel
//
this.TotalPricelabel.AutoSize = true;
this.TotalPricelabel.Location = new System.Drawing.Point(528, 74);
this.TotalPricelabel.Name = "TotalPricelabel";
this.TotalPricelabel.Size = new System.Drawing.Size(0, 13);
this.TotalPricelabel.TabIndex = 18;
//
// ArrivaldateTimePicker
//
this.ArrivaldateTimePicker.Location = new System.Drawing.Point(191, 27);
this.ArrivaldateTimePicker.Name = "ArrivaldateTimePicker";
this.ArrivaldateTimePicker.Size = new System.Drawing.Size(141, 20);
this.ArrivaldateTimePicker.TabIndex = 0;
this.ArrivaldateTimePicker.ValueChanged += new System.EventHandler(this.ArrivaldateTimePicker_ValueChanged);
//
// DeparturedateTimePicker
//
this.DeparturedateTimePicker.Location = new System.Drawing.Point(191, 67);
this.DeparturedateTimePicker.Name = "DeparturedateTimePicker";
this.DeparturedateTimePicker.Size = new System.Drawing.Size(141, 20);
this.DeparturedateTimePicker.TabIndex = 1;
this.DeparturedateTimePicker.ValueChanged += new System.EventHandler(this.DeparturedateTimePicker_ValueChanged);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(21, 33);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(95, 13);
this.label1.TabIndex = 4;
this.label1.Text = "Select arrival date ";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(21, 73);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(109, 13);
this.label2.TabIndex = 5;
this.label2.Text = "Select departure date";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(21, 160);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(86, 13);
this.label3.TabIndex = 6;
this.label3.Text = "Select room type";
//
// SinglecheckBox
//
this.SinglecheckBox.AutoSize = true;
this.SinglecheckBox.Location = new System.Drawing.Point(191, 137);
this.SinglecheckBox.Name = "SinglecheckBox";
this.SinglecheckBox.Size = new System.Drawing.Size(55, 17);
this.SinglecheckBox.TabIndex = 7;
this.SinglecheckBox.Text = "Single";
this.SinglecheckBox.UseVisualStyleBackColor = true;
this.SinglecheckBox.CheckedChanged += new System.EventHandler(this.SinglecheckBox_CheckedChanged);
//
// DoublecheckBox
//
this.DoublecheckBox.AutoSize = true;
this.DoublecheckBox.Location = new System.Drawing.Point(191, 160);
this.DoublecheckBox.Name = "DoublecheckBox";
this.DoublecheckBox.Size = new System.Drawing.Size(60, 17);
this.DoublecheckBox.TabIndex = 8;
this.DoublecheckBox.Text = "Double";
this.DoublecheckBox.UseVisualStyleBackColor = true;
this.DoublecheckBox.CheckedChanged += new System.EventHandler(this.DoublecheckBox_CheckedChanged);
//
// KingcheckBox
//
this.KingcheckBox.AutoSize = true;
this.KingcheckBox.Location = new System.Drawing.Point(191, 183);
this.KingcheckBox.Name = "KingcheckBox";
this.KingcheckBox.Size = new System.Drawing.Size(47, 17);
this.KingcheckBox.TabIndex = 9;
this.KingcheckBox.Text = "King";
this.KingcheckBox.UseVisualStyleBackColor = true;
this.KingcheckBox.CheckedChanged += new System.EventHandler(this.KingcheckBox_CheckedChanged);
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(246, 107);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(75, 13);
this.label5.TabIndex = 12;
this.label5.Text = "Price per nigth";
//
// DoublePricelabel
//
this.DoublePricelabel.AutoSize = true;
this.DoublePricelabel.Location = new System.Drawing.Point(275, 161);
this.DoublePricelabel.Name = "DoublePricelabel";
this.DoublePricelabel.Size = new System.Drawing.Size(0, 13);
this.DoublePricelabel.TabIndex = 13;
//
// KingPricelabel
//
this.KingPricelabel.AutoSize = true;
this.KingPricelabel.Location = new System.Drawing.Point(275, 184);
this.KingPricelabel.Name = "KingPricelabel";
this.KingPricelabel.Size = new System.Drawing.Size(0, 13);
this.KingPricelabel.TabIndex = 14;
//
// SinglePricelabel
//
this.SinglePricelabel.AutoSize = true;
this.SinglePricelabel.Location = new System.Drawing.Point(275, 138);
this.SinglePricelabel.Name = "SinglePricelabel";
this.SinglePricelabel.Size = new System.Drawing.Size(0, 13);
this.SinglePricelabel.TabIndex = 15;
//
// groupBox1
//
this.groupBox1.Controls.Add(this.SinglePricelabel);
this.groupBox1.Controls.Add(this.KingPricelabel);
this.groupBox1.Controls.Add(this.DoublePricelabel);
this.groupBox1.Controls.Add(this.label5);
this.groupBox1.Controls.Add(this.KingcheckBox);
this.groupBox1.Controls.Add(this.DoublecheckBox);
this.groupBox1.Controls.Add(this.SinglecheckBox);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.DeparturedateTimePicker);
this.groupBox1.Controls.Add(this.ArrivaldateTimePicker);
this.groupBox1.Location = new System.Drawing.Point(24, 23);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(365, 244);
this.groupBox1.TabIndex = 19;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "groupBox1";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(508, 50);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(58, 13);
this.label6.TabIndex = 20;
this.label6.Text = "Total Price";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(606, 307);
this.Controls.Add(this.label6);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.TotalPricelabel);
this.Controls.Add(this.NumberOfNigthslabel);
this.Controls.Add(this.label4);
this.Name = "Form1";
this.Text = "Form1";
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();

& }

& #endregion

& private System.Windows.Forms.Label label4;
& private System.Windows.Forms.Label NumberOfNigthslabel;
& private System.Windows.Forms.Label TotalPricelabel;
& private System.Windows.Forms.DateTimePicker ArrivaldateTimePicker;
& private System.Windows.Forms.DateTimePicker DeparturedateTimePicker;
& private System.Windows.Forms.Label label1;
& private System.Windows.Forms.Label label2;
& private System.Windows.Forms.Label label3;
& private System.Windows.Forms.CheckBox SinglecheckBox;
& private System.Windows.Forms.CheckBox DoublecheckBox;
& private System.Windows.Forms.CheckBox KingcheckBox;
& private System.Windows.Forms.Label label5;
& private System.Windows.Forms.Label DoublePricelabel;
& private System.Windows.Forms.Label KingPricelabel;
& private System.Windows.Forms.Label SinglePricelabel;
& private System.Windows.Forms.GroupBox groupBox1;
& private System.Windows.Forms.Label label6;
}
}


AssemblyInfo.cs
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ReservationForm")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ReservationForm")]
[assembly: AssemblyCopyright("Copyright ©& 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components.& If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("792b898b-a09e-4b63-9ae8-32a099c055d2")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS