コード例 #1
0
        private void ParkingSlotButton_Click(object sender, EventArgs e)
        {
            PakingSlot c = new PakingSlot();

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

            /* if (!Window.Controls.Contains(PakingSlot.Instance))
             * {
             *   Window.Controls.Add(PakingSlot.Instance);
             *   PakingSlot.Instance.Dock = DockStyle.Fill;
             *   PakingSlot.Instance.BringToFront();
             * }
             * else
             * {
             *   PakingSlot.Instance.BringToFront();
             * }*/
        }
コード例 #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();
                    }
                }
            }
        }