Example #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            bool user = false;

            //string line;
            //System.IO.StreamReader database = new System.IO.StreamReader("users.in");
            //while (!database.EndOfStream)
            {
                user = true;
                user currentUser = new user();
                //line=database.ReadLine();
                //string username = "";
                //int i = 0;
                //for(i=0;line[i]!=' ';i++)
                //{
                linqtoregdbDataContext db = new linqtoregdbDataContext();
                bool valid = false;

                var queryIsUsername = from usr in db.users
                                      select usr;

                List <string> allUsernames = new List <string>();
                foreach (var c in queryIsUsername)
                {
                    allUsernames.Add(c.username.ToLower());
                    if (c.username.ToLower() == maskedTextBox1.Text.ToLower())
                    {
                        User.username = c.username;
                        valid         = true;
                        currentUser   = c;
                    }
                }
                if (currentUser.password != Hasher.GetHash(maskedTextBox2.Text).ToString())
                {
                    MessageBox.Show("Invalid username/password combination!");
                }
                else
                {
                    //username += line[i];
                    //if (maskedTextBox1.Text.ToString().ToLower()[i] != char.ToLower(line[i]))
                    //{
                    //    user = false;
                    //    break;
                    //}
                    //}
                    //if (user)
                    //{
                    //    User.username = username;
                    //    i = 11;
                    //    user = false;
                    //    foreach (char c in maskedTextBox2.Text.ToString())
                    //    {
                    //        user = true;
                    //        if (c != line[i])
                    //        {
                    //            user = false;
                    //            break;
                    //        }
                    //        i++;
                    //    }
                    //    if (user)
                    //{
                    //i = 70;
                    //string status="";
                    //for(i=70;i<line.Length&&line[i]!='\n'&&line[i]!=' ';i++)
                    //    status+=line[i];
                    string name = "Welcome,\n";
                    name += currentUser.lastName + ", " + currentUser.firstName;
                    //for (i = 22; line[i] != ' '; i++)
                    //    name += line[i];
                    MessageBox.Show(name);
                    User.type = currentUser.usertype;
                    //if (User.type == "admin")
                    //{
                    //    AdminWindow adminScreen = new AdminWindow(this, User);
                    //    adminScreen.Show();
                    //}
                    //else if (User.type == "faculty")
                    //{
                    //    FacultyHome facultyScreen = new FacultyHome(User, this);
                    //    facultyScreen.Show();
                    //}
                    //else
                    //{
                    Home screen = new Home(this, User);
                    screen.Show();
                    //}
                    this.Hide();
                }
            }
            //if (maskedTextBox2.Text.ToString() == "pong")
            //{
            //    linqtoregdbDataContext db = new linqtoregdbDataContext();
            //    var queryUsername = from usr in db.users
            //                        where usr.username.ToLower()==maskedTextBox1.Text.ToLower()
            //                        select usr.username;
            //    if (queryUsername.Count() == 1)
            //    {
            //        PongForm pongWindow = new PongForm(this,queryUsername.First());
            //        pongWindow.Show();
            //        this.Hide();
            //    }
            //    /*MessageBox.Show("Welcome");
            //    Classes screen = new Classes(this);
            //    screen.Show();
            //    this.Hide();*/
            //}
            //database.Close();
            maskedTextBox2.Text = "";
            //maskedTextBox1.Text="";
        }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            bool keepGoing            = true;
            user usr                  = new user();
            linqtoregdbDataContext db = new linqtoregdbDataContext();

            string[] types = { "student", "faculty", "admin", "manager" };

            var queryGetUserID = from quser in db.users
                                 where quser.username == comboBox2.SelectedItem.ToString()
                                 select quser;

            if (comboBox1.SelectedIndex == -1)
            {
                MessageBox.Show("Please select a User Type.");
                keepGoing = false;
            }
            else
            {
                if ((string)comboBox1.SelectedItem == "Student")
                {
                    if (comboBox2.SelectedIndex == -1)
                    {
                        MessageBox.Show("Please select an advisor.");
                        keepGoing = false;
                    }
                    else
                    {
                        var advisorID = queryGetUserID.FirstOrDefault().userID;
                        usr = new user
                        {
                            username  = textBox1.Text,
                            password  = Hasher.GetHash(textBox2.Text).ToString(),
                            firstName = textBox3.Text,
                            lastName  = textBox5.Text,
                            usertype  = types[comboBox1.SelectedIndex],
                            advisor   = advisorID
                        };
                    }
                }
                else
                {
                    usr = new user
                    {
                        username  = textBox1.Text,
                        password  = Hasher.GetHash(textBox2.Text).ToString(),
                        firstName = textBox3.Text,
                        lastName  = textBox5.Text,
                        usertype  = types[comboBox1.SelectedIndex]
                    };
                }
                if (usr.username == "")
                {
                    keepGoing = false;
                    MessageBox.Show("Username cannot be blank.");
                }
                else if ((from usrs in db.users
                          where usrs.username == usr.username
                          select usrs).Any())
                {
                    keepGoing = false;
                    MessageBox.Show("Username already exists, please choose a different one.");
                }
                else if (usr.usertype == "manager")
                {
                    DialogResult drslt = MessageBox.Show("Are you certain you wish to create a new manager?", "Confirm User Creation", MessageBoxButtons.YesNo);
                    if (drslt == DialogResult.No)
                    {
                        keepGoing = false;
                    }
                }
                if (keepGoing)
                {
                    db.users.InsertOnSubmit(usr);
                    db.SubmitChanges();
                    MessageBox.Show("User added successfully!");
                    this.Close();
                }
            }
        }