Advertisement
monaliza86

Untitled

Jan 26th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.28 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace Reservations
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.         }
  19.  
  20.         //public bool IsValidData()
  21.         //{
  22.  
  23.         //}
  24.  
  25.         public bool IsPresent(TextBox textBox, string name)
  26.         {
  27.             if (textBox.Text == "")
  28.             {
  29.                 MessageBox.Show(name + " is a required field.", "Entry Error");
  30.                 textBox.Focus();
  31.                 return false;
  32.             }
  33.             return true;
  34.         }
  35.  
  36.         //public bool IsDateTime(TextBox textBox, string name)
  37.         //{
  38.  
  39.         //}
  40.  
  41.         //public bool IsWithinRange(TextBox textBox, string name,
  42.         //    DateTime min, DateTime max)
  43.         //{
  44.  
  45.         //}
  46.  
  47.         private void btnExit_Click(object sender, EventArgs e)
  48.         {
  49.             this.Close();
  50.         }
  51.  
  52.         private void btnCalculate_Click(object sender, EventArgs e)
  53.         {
  54.             double weekendprice_perNight=0, price_perNight=0;
  55.             double total=0;
  56.             double average;
  57.  
  58.            
  59.             DateTime arrivalDate = DateTime.Today;
  60.             DateTime.TryParse(txtArrivalDate.Text, out arrivalDate);
  61.             DateTime departureDate = DateTime.Today;
  62.             DateTime.TryParse(txtDepartureDate.Text, out departureDate);
  63.             TimeSpan totalTime = departureDate.Subtract(arrivalDate);
  64.             int totalNights = totalTime.Days;
  65.             txtNights.Text += totalNights;
  66.  
  67.            
  68.  
  69.             DayOfWeek dayOfWeek = arrivalDate.DayOfWeek ;
  70.  
  71.             int counter = 0;
  72.             for(counter=1; counter <= 7; counter++)
  73.             {
  74.                 if (dayOfWeek == DayOfWeek.Friday || dayOfWeek == DayOfWeek.Saturday)
  75.                 {
  76.                     weekendprice_perNight = 150;
  77.                 }
  78.                 else
  79.                 {
  80.                     price_perNight = 120;
  81.                    
  82.                 }
  83.                 total = (price_perNight * totalNights) + weekendprice_perNight;
  84.                 txtTotalPrice.Text = total.ToString("c");
  85.                 average = total / totalNights;
  86.                 txtAvgPrice.Text = average.ToString("c");
  87.             }
  88.            
  89.            
  90.  
  91.  
  92.  
  93.  
  94.         }
  95.  
  96.         private void Form1_Load(object sender, EventArgs e)
  97.         {
  98.  
  99.  
  100.             DateTime currentDate = DateTime.Today;
  101.             DateTime depDate = currentDate.AddDays(3);
  102.             txtArrivalDate.Text = currentDate.ToShortDateString();
  103.             txtDepartureDate.Text = depDate.ToShortDateString();
  104.  
  105.             //DateTime dateTime = new DateTime(2016, 1, 29);
  106.             //DateTime departureTime = dateTime.AddDays(3);
  107.             //string shortDate = dateTime.ToShortDateString();
  108.             //shortDate = shortDate.Replace("-", "/");
  109.             //string shortDepDate = departureTime.ToShortDateString();
  110.             //shortDepDate = shortDepDate.Replace("-", "/");
  111.             //txtArrivalDate.Text = shortDate;
  112.             //txtDepartureDate.Text = shortDepDate;
  113.  
  114.  
  115.  
  116.         }
  117.     }
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement