Пример #1
0
        private void HomeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            VisitorHome VHF = new VisitorHome(Guest);

            VHF.Show();
            this.Close();
        }
Пример #2
0
        private void Button1_Click(object sender, EventArgs e)
        {
            if (radioButton1.Checked == true)
            {
                connection.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Users.mdb;";
                connection.Open();
                // Create a command object, give it a connection object, give it a query to update our database
                OleDbCommand command = new OleDbCommand();
                command.Connection  = connection;
                command.CommandText = "SELECT * FROM guest ;";
                // Now simply execute it!
                OleDbDataAdapter da = new OleDbDataAdapter(command);
                DataSet          dt = new DataSet();
                da.Fill(dt);
                try
                {
                    visitor vistr = new visitor();
                    vistr.Username = dt.Tables[0].Rows[0]["Username"].ToString();
                    vistr.Visits   = dt.Tables[0].Rows[0]["Visits"].ToString();
                    vistr.orderId  = "VON" + vistr.Visits.ToString();

                    int visitcount = Convert.ToInt32(vistr.Visits);

                    // Create a command object, give it a connection object, give it a query to update our database
                    OleDbCommand command2 = new OleDbCommand();
                    command2.Connection = connection;
                    visitcount++;
                    command2.CommandText = "UPDATE guest SET Visits=" + visitcount + " WHERE Username='******';";
                    // Now simply execute it!
                    command2.ExecuteNonQuery();
                    connection.Close();
                    globalusername = vistr.Username;
                    VisitorHome VHF = new VisitorHome(vistr);
                    VHF.Show();
                    this.Hide();
                }
                catch
                {
                    System.Windows.Forms.MessageBox.Show("Login failed! User or Guest are not found!");
                    connection.Close();
                }
            }
            else if (radioButton2.Checked == true)
            {
                connection.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Users.mdb;";
                connection.Open();
                // Create a command object, give it a connection object, give it a query to update our database
                OleDbCommand command = new OleDbCommand();
                command.Connection  = connection;
                command.CommandText = "SELECT * FROM users WHERE Username='******';";
                // Now simply execute it!
                OleDbDataAdapter da = new OleDbDataAdapter(command);
                DataSet          dt = new DataSet();
                da.Fill(dt);
                try
                {
                    user usr = new user();
                    usr.Username = dt.Tables[0].Rows[0]["Username"].ToString();
                    usr.Password = dt.Tables[0].Rows[0]["Password"].ToString();
                    usr.Visits   = dt.Tables[0].Rows[0]["Visits"].ToString();
                    usr.ID       = Convert.ToInt32(dt.Tables[0].Rows[0]["UserID"]);
                    int visitcount = Convert.ToInt32(usr.Visits);
                    connection.Close();
                    if (usr.Password == PswdBox.Text)
                    {
                        connection.Open();
                        // Create a command object, give it a connection object, give it a query to update our database
                        OleDbCommand command2 = new OleDbCommand();
                        command2.Connection = connection;
                        visitcount++;
                        command2.CommandText = "UPDATE users SET Visits=" + visitcount + " WHERE UserID=" + usr.ID + ";";
                        // Now simply execute it!
                        command2.ExecuteNonQuery();
                        connection.Close();
                        globalusername = usr.Username;
                        Home HF = new Home(usr);
                        HF.Show();
                        this.Hide();
                    }
                    else
                    {
                        System.Windows.Forms.MessageBox.Show("Wrong Password ! Try again.");
                    }
                }
                catch
                {
                    System.Windows.Forms.MessageBox.Show("Wrong Username! Try again.");
                    connection.Close();
                }
            }
        }