예제 #1
0
        private void BookSlotButton_Click(object sender, EventArgs e)
        {
            string id = UserIDForBookSlot.Text;
            //string time = TimeForStay.Text;
            string slot = SlotNumber.Text;

            //string time = Clock.Text;
            string time = DateTime.Now.ToString("MM/dd/yyyy h:mm tt");

            Boolean   flag       = false;
            Boolean   flag2      = false;
            Boolean   flag1      = false;
            ArrayList carlist    = new ArrayList();
            ArrayList carhistory = new ArrayList();

            String query1 = "select *  from carlist where ID = '" + id + "';";

            Connection.Open();
            Command = new SqlCommand(query1, Connection);
            SqlDataReader result1 = Command.ExecuteReader();

            try
            {
                while (result1.Read())
                {
                    string idd = result1["ID"].ToString();
                    flag = true;
                }
            }catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex);
            }

            Connection.Close();

            String query4 = "select *  from carlist where SlotNumber = '" + slot + "';";

            Connection.Open();
            Command4 = new SqlCommand(query4, Connection);
            SqlDataReader result4 = Command4.ExecuteReader();

            try
            {
                while (result4.Read())
                {
                    string s = result4["SlotNumber"].ToString();
                    flag1 = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex);
            }
            Connection.Close();
            String query2 = "select * from member where id ='" + id + "';";

            Connection.Open();
            Command1 = new SqlCommand(query2, Connection);
            SqlDataReader result2 = Command1.ExecuteReader();


            Boolean empty = string.IsNullOrEmpty(id);

            if (empty)
            {
                var w = new Form()
                {
                    Size = new Size(0, 0)
                };
                Task.Delay(TimeSpan.FromSeconds(2))
                .ContinueWith((t) => w.Close(), TaskScheduler.FromCurrentSynchronizationContext());
                MessageBox.Show(w, "Plase enter User ID");
            }
            else if (flag1)
            {
                var w = new Form()
                {
                    Size = new Size(0, 0)
                };
                Task.Delay(TimeSpan.FromSeconds(2))
                .ContinueWith((t) => w.Close(), TaskScheduler.FromCurrentSynchronizationContext());
                MessageBox.Show(w, "Slot not available");
                Connection.Close();
            }
            else if (flag)
            {
                var w = new Form()
                {
                    Size = new Size(0, 0)
                };
                Task.Delay(TimeSpan.FromSeconds(2))
                .ContinueWith((t) => w.Close(), TaskScheduler.FromCurrentSynchronizationContext());
                MessageBox.Show(w, "Car already available in the park");
                Connection.Close();
            }
            else
            {
                try
                {
                    while (result2.Read())
                    {
                        VName    = result2["Name"].ToString();
                        ID       = result2["ID"].ToString();
                        Email    = result2["EmailAddress"].ToString();
                        CarID    = result2["CarID"].ToString();
                        CarName  = result2["CarName"].ToString();
                        CarModel = result2["CarModel"].ToString();
                        CarColor = result2["CarColor"].ToString();

                        flag2 = true;

                        carlist.Add(slot);
                        carlist.Add(VName);
                        carlist.Add(ID);
                        carlist.Add(CarID);
                        carlist.Add(CarName);
                        carlist.Add(CarModel);
                        carlist.Add(CarColor);
                        carlist.Add(time);
                        //carlist.Add(DateTime.Now.ToString());

                        carhistory.Add(slot);
                        carhistory.Add(VName);
                        carhistory.Add(ID);
                        carhistory.Add(Email);
                        carhistory.Add(CarID);
                        carhistory.Add(CarName);
                        carhistory.Add(CarModel);
                        carhistory.Add(CarColor);
                        carhistory.Add(time);

                        for (int i = 0; i < textbox.Count; i++)
                        {
                            if (textbox[i].Text == slot)
                            {
                                textbox[i].BackColor = Color.FromArgb(231, 76, 6);
                                break;
                            }
                        }
                    }

                    if (!flag2)
                    {
                        var w = new Form()
                        {
                            Size = new Size(0, 0)
                        };
                        Task.Delay(TimeSpan.FromSeconds(2))
                        .ContinueWith((t) => w.Close(), TaskScheduler.FromCurrentSynchronizationContext());
                        MessageBox.Show(w, "No such type member  available");
                        Connection.Close();
                    }
                    else
                    {
                        database.InsertCarIntoPark(carlist);

                        database.CarEnterHistory(carhistory);
                        // MessageBox.Show("Vehicle Added to slot");
                        ParkingDetailsWindow pw = new ParkingDetailsWindow(CarID, CarName, CarModel, CarColor, slot);
                        pw.Show();
                    }
                    Connection.Close();
                }
                catch (Exception exx)
                {
                    MessageBox.Show("Error: " + exx);
                }
            }
        }
예제 #2
0
        public void BookSlotByScanning(string id)
        {
            // MessageBox.Show("Welcome");
            UserIDFromScan.Text = "";
            string userid = id;

            //MessageBox.Show(userid);
            for (int i = 0; i < textbox.Count; i++)
            {
                if (textbox[i].BackColor == Color.FromArgb(128, 255, 128))
                {
                    slot = textbox[i].Text;
                    break;
                }
            }
            string    time       = Clock.Text;
            Boolean   flag       = false;
            Boolean   flag2      = false;
            ArrayList carlist    = new ArrayList();
            ArrayList carhistory = new ArrayList();

            String query1 = "select *  from carlist where ID = '" + userid + "';";

            Connection.Open();
            Command1 = new SqlCommand(query1, Connection);
            SqlDataReader result1 = Command1.ExecuteReader();

            try
            {
                while (result1.Read())
                {
                    string idd = result1["ID"].ToString();
                    flag = true;
                }
                Connection.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex);
            }



            String query2 = "select * from member where ID ='" + userid + "';";

            Connection.Open();
            Command2 = new SqlCommand(query2, Connection);
            SqlDataReader result2 = Command2.ExecuteReader();



            Boolean empty = string.IsNullOrEmpty(userid);

            if (empty)
            {
                var w = new Form()
                {
                    Size = new Size(0, 0)
                };
                Task.Delay(TimeSpan.FromSeconds(2))
                .ContinueWith((t) => w.Close(), TaskScheduler.FromCurrentSynchronizationContext());
                MessageBox.Show(w, "No such type User is available");
            }
            else
            {
                try
                {
                    while (result2.Read())
                    {
                        Name     = result2["Name"].ToString();
                        ID       = result2["ID"].ToString();
                        Email    = result2["EmailAddress"].ToString();
                        CarID    = result2["CarID"].ToString();
                        CarName  = result2["CarName"].ToString();
                        CarModel = result2["CarModel"].ToString();
                        CarColor = result2["CarColor"].ToString();

                        flag2 = true;

                        carlist.Add(slot);
                        carlist.Add(Name);
                        carlist.Add(ID);
                        carlist.Add(CarID);
                        carlist.Add(CarName);
                        carlist.Add(CarModel);
                        carlist.Add(CarColor);
                        carlist.Add(time);

                        carhistory.Add(slot);
                        carhistory.Add(Name);
                        carhistory.Add(ID);
                        carhistory.Add(Email);
                        carhistory.Add(CarID);
                        carhistory.Add(CarName);
                        carhistory.Add(CarModel);
                        carhistory.Add(CarColor);
                        carhistory.Add(time);

                        /*for (int i = 0; i < textbox.Count; i++)
                         * {
                         *  if (textbox[i].Text == slot)
                         *  {
                         *      textbox[i].BackColor = Color.FromArgb(231, 76, 6);
                         *      break;
                         *  }
                         * }*/
                    }
                    Connection.Close();
                }
                catch (Exception exx)
                {
                    MessageBox.Show("Adding Error" + exx);
                }

                if (flag)
                {
                    string query3 = "delete from carlist where ID = '" + userid + "'; ";

                    try
                    {
                        Connection.Open();
                        Command3 = new SqlCommand(query3, Connection);
                        Command3.ExecuteNonQuery();



                        //ParkingSlotButton.Select();

                        PakingSlot c = new PakingSlot();
                        if (!Window.Controls.Contains(c))
                        {
                            Window.Controls.Add(c);
                            c.Dock = DockStyle.Fill;
                            c.BringToFront();
                        }
                        else
                        {
                            //Window.Controls.Add(c);
                            //c.Dock = DockStyle.Fill;
                            c.BringToFront();
                        }
                        var w = new Form()
                        {
                            Size = new Size(0, 0)
                        };
                        Task.Delay(TimeSpan.FromSeconds(1))
                        .ContinueWith((t) => w.Close(), TaskScheduler.FromCurrentSynchronizationContext());
                        for (int i = 0; i < 153; i++)
                        {
                            if (textbox[i].Text == slot)
                            {
                                textbox[i].BackColor = Color.FromArgb(128, 255, 128);
                                break;
                            }
                        }
                        MessageBox.Show(w, "Vehicle Removed");
                        Connection.Close();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Removing Error: " + ex);
                        Console.WriteLine("Error: " + ex);
                    }
                }
                else if (!flag2)
                {
                    var w = new Form()
                    {
                        Size = new Size(0, 0)
                    };
                    Task.Delay(TimeSpan.FromSeconds(2))
                    .ContinueWith((t) => w.Close(), TaskScheduler.FromCurrentSynchronizationContext());
                    MessageBox.Show(w, "No such type member  available");
                    //Connection.Close();
                }
                else
                {
                    database.InsertCarIntoPark(carlist);

                    database.CarEnterHistory(carhistory);
                    for (int i = 0; i < textbox.Count; i++)
                    {
                        if (textbox[i].Text == slot)
                        {
                            textbox[i].BackColor = Color.FromArgb(231, 76, 6);
                            break;
                        }
                    }
                    var w = new Form()
                    {
                        Size = new Size(0, 0)
                    };
                    Task.Delay(TimeSpan.FromSeconds(1))
                    .ContinueWith((t) => w.Close(), TaskScheduler.FromCurrentSynchronizationContext());
                    MessageBox.Show(w, "Vehicle Added to slot");
                    ParkingDetailsWindow pw = new ParkingDetailsWindow(CarID, CarName, CarModel, CarColor, slot);
                    pw.Show();

                    PakingSlot c = new PakingSlot();


                    if (!Window.Controls.Contains(c))
                    {
                        Window.Controls.Add(c);
                        c.Dock = DockStyle.Fill;
                        c.BringToFront();
                    }
                    else
                    {
                        c.BringToFront();
                    }
                }
            }
        }