Programming for Everybody: c# tutorial for beginners - hotel management system project

c# tutorial for beginners - hotel management system project



 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;

using System.Data.SqlClient;

namespace Book__room

{

    public partial class Form3 : Form

    {

        public Form3()

        {

            InitializeComponent();

        }

        SqlConnection conn = new SqlConnection("Data Source=.;Initial catalog=hotel;Integrated Security=true");

        string strsql;

        SqlCommand cmd;

        private void button1_Click(object sender, EventArgs e)

        {

            strsql = "insert into table1(room,startdate,enddate)Values(@room1,@start1,@end1)";

            cmd = new SqlCommand(strsql, conn);

            cmd.Parameters.AddWithValue("room1", comboBox1.Text);

            cmd.Parameters.AddWithValue("start1", dateTimePicker1.Value.ToString());

            cmd.Parameters.AddWithValue("end1", dateTimePicker2.Value.ToString());

            conn.Open();

            cmd.ExecuteNonQuery();

            conn.Close();

            MessageBox.Show("The room reserved successfully");

        }


        private void button2_Click(object sender, EventArgs e)

        {

            conn.Open();

            strsql = "Select * from table1 Where room=@room1 " +

                "And ((@start1 >= startdate And @end1 <= enddate)" +

                "Or (@start1 <= startdate And @end1 >= enddate)" +

                "or (@start1 > startdate And @end1 > enddate And @start1<enddate)" +

                "or (@start1 < startdate And @end1 < enddate And @end1>startdate))";

            cmd = new SqlCommand(strsql, conn);

            cmd.Parameters.AddWithValue("room1", comboBox1.Text);

            cmd.Parameters.AddWithValue("start1", dateTimePicker1.Value.ToString());

            cmd.Parameters.AddWithValue("end1", dateTimePicker2.Value.ToString());

            SqlDataReader myreader = cmd.ExecuteReader();

            if (myreader.Read())

            {

                MessageBox.Show("The room reserved From: " + myreader.GetValue(2).ToString() + " To: " + myreader.GetValue(3).ToString());

            }

            else

            {

                MessageBox.Show("The room not reserved before");

            }

            conn.Close();

        }

    }

}


No comments:

Post a Comment