Example #1
0
        private void loginButton_Click(object sender, EventArgs e)
        {
            //@ or //(double slash)
            LinqLoginDataContext query = new LinqLoginDataContext(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=D:\Study\Sem 8\OOP2 (C#)\Final\Project\FinalTermProject\FinalTermProject\Admindata.mdf;Integrated Security=True;Connect Timeout=30");
            {
                var x = from login in query.Logins
                        where login.Username == textBox_username.Text && login.Password == textBox_pass.Text
                        select login;

                if (x.Any())
                {
                    Home h1 = new Home();
                    this.Hide();
                    h1.Show();
                }
                else
                {
                    labelMessage.Visible = true;
                    labelMessage.Text    = "Invalid Username/Password. Try again.";

                    //delete this
                    //Home h1 = new Home();
                    //this.Hide();
                    //h1.Show();
                }
            }
        }
        private void button_Verify_Update_Click(object sender, EventArgs e)//UPDATE Password Button (ADMIN SECTION)
        {
            if (textBox_New_Pass.Text != "")
            {
                try
                {
                    LinqLoginDataContext lq = new LinqLoginDataContext(strCon);

                    var x = from a in lq.Logins
                            where a.Password == textBox_Old_Pass.Text
                            select a;

                    x.First().Password = textBox_New_Pass.Text;

                    lq.SubmitChanges();
                    dataGrid_Admin_List.DataSource = x.ToList();

                    MessageBox.Show("Success!");
                }
                catch
                {
                    MessageBox.Show("Wrong Password! Try again.");
                }
            }
            else
            {
                MessageBox.Show("Please insert a new password");
            }
        }
        private void button4_Click(object sender, EventArgs e)//ADD Admin
        {
            if (textBox2.Text != "" && textBox3.Text != "")
            {
                if (textBox3.Text.Length >= 4)
                {
                    LinqLoginDataContext lq = new LinqLoginDataContext(strCon);
                    Login lg = new Login
                    {
                        Username = textBox2.Text,
                        Password = textBox3.Text
                    };

                    MessageBox.Show("Admin added successfully!");
                    lq.Logins.InsertOnSubmit(lg);
                    lq.SubmitChanges();
                    // UpdateGridView();
                }
                else
                {
                    MessageBox.Show("Password must have minimum 4 characters!");
                }
            }
            else
            {
                MessageBox.Show("(Error!) Input username & password!");
            }
        }
        private void button_Verify_Update_Click(object sender, EventArgs e)//UPDATE Password Button (ADMIN SECTION)
        {
            if (textBox_New_Pass.Text != "")
            {
                try
                {
                    LinqLoginDataContext lq = new LinqLoginDataContext(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=D:\Study\Sem 8\OOP2 (C#)\Final\Project\FinalTermProject v2.0\FinalTermProject\FinalTermProject\Admindata.mdf;Integrated Security=True;Connect Timeout=30");

                    var x = from a in lq.Logins
                            where a.Password == textBox_Old_Pass.Text
                            select a;

                    x.First().Password = textBox_New_Pass.Text;

                    lq.SubmitChanges();
                    dataGrid_Admin_List.DataSource = x.ToList();

                    MessageBox.Show("Success!");
                }
                catch
                {
                    MessageBox.Show("Wrong Password! Try again.");
                }
            }
            else
            {
                MessageBox.Show("Please insert a new password");
            }
        }
        private void button4_Click(object sender, EventArgs e)//ADD Admin
        {
            if (textBox2.Text != "" && textBox3.Text != "")
            {
                if (textBox3.Text.Length >= 4)
                {
                    LinqLoginDataContext lq = new LinqLoginDataContext(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=D:\Study\Sem 8\OOP2 (C#)\Final\Project\FinalTermProject v2.0\FinalTermProject\FinalTermProject\Admindata.mdf;Integrated Security=True;Connect Timeout=30");
                    Login lg = new Login
                    {
                        Username = textBox2.Text,
                        Password = textBox3.Text
                    };

                    MessageBox.Show("Admin added successfully!");
                    lq.Logins.InsertOnSubmit(lg);
                    lq.SubmitChanges();
                    // UpdateGridView();
                }
                else
                {
                    MessageBox.Show("Password must have minimum 4 characters!");
                }
            }
            else
            {
                MessageBox.Show("(Error!) Input username & password!");
            }
        }
        private void LoginButton_Click(object sender, EventArgs e)
        {
            //@ or //(double slash)
            var strCon = ConfigurationManager.ConnectionStrings["FinalTermProject.Properties.Settings.ConnectionString"].ToString();
            LinqLoginDataContext query = new LinqLoginDataContext(strCon);
            {
                var x = from login in query.Logins
                        where login.Username == textBox_username.Text && login.Password == textBox_pass.Text
                        select login;

                if (x.Any())
                {
                    Home h1 = new Home();
                    this.Hide();
                    h1.Show();
                }
                else
                {
                    labelMessage.Visible = true;
                    labelMessage.Text    = "Invalid Username/Password. Try again.";

                    //delete this
                    //Home h1 = new Home();
                    //this.Hide();
                    //h1.Show();
                }
            }
        }
        private void panel_Admin_Paint(object sender, PaintEventArgs e)//Admin list
        {
            LinqLoginDataContext lq = new LinqLoginDataContext(strCon);
            var y = from g in lq.Logins
                    select new
            {
                Name = g.Username
            };

            dataGrid_Admin_List.DataSource = y.ToList();
        }
        private void panel_Admin_Paint(object sender, PaintEventArgs e)//Admin list
        {
            LinqLoginDataContext lq = new LinqLoginDataContext(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=D:\Study\Sem 8\OOP2 (C#)\Final\Project\FinalTermProject v2.0\FinalTermProject\FinalTermProject\Admindata.mdf;Integrated Security=True;Connect Timeout=30");
            var y = from g in lq.Logins
                    select new
            {
                Name = g.Username
            };

            dataGrid_Admin_List.DataSource = y.ToList();
        }
        private void button5_Click(object sender, EventArgs e)//REMOVE Admin
        {
            LinqLoginDataContext lq = new LinqLoginDataContext(strCon);

            if (textBox4.Text != "")
            {
                var x = from a in lq.Logins
                        where a.Username.Equals(textBox4.Text)
                        select a;

                //Lamda Expression
                foreach (Login l in x)
                {
                    lq.Logins.DeleteOnSubmit(l);
                }

                lq.SubmitChanges();
                dataGrid_Admin_List.DataSource = lq;
            }
            else
            {
                MessageBox.Show("Input an Admin name!");
            }
        }
        private void button5_Click(object sender, EventArgs e)//REMOVE Admin
        {
            LinqLoginDataContext lq = new LinqLoginDataContext(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=D:\Study\Sem 8\OOP2 (C#)\Final\Project\FinalTermProject v2.0\FinalTermProject\FinalTermProject\Admindata.mdf;Integrated Security=True;Connect Timeout=30");

            if (textBox4.Text != "")
            {
                var x = from a in lq.Logins
                        where a.Username.Equals(textBox4.Text)
                        select a;

                //Lamda Expression
                foreach (Login l in x)
                {
                    lq.Logins.DeleteOnSubmit(l);
                }

                lq.SubmitChanges();
                dataGrid_Admin_List.DataSource = lq;
            }
            else
            {
                MessageBox.Show("Input an Admin name!");
            }
        }