Example #1
0
        private void CreateAccount_Click(object sender, EventArgs e)
        {
            var query = "Select * from tblLogin Where username = '******'";
            var con   = new SqlDataAdapter(query, Cnst.SqlCon);
            var check = new DataTable();

            con.Fill(check);
            if (check.Rows.Count > 0)
            {
                MessageBox.Show("Vartotojas tokiu prisijungimo vardu jau yra");
            }
            else
            {
                DropList level         = comboBox1.SelectedItem as DropList;
                string   pass          = txtSignInPassword.Text.Trim();
                string   hashPass      = Cnst.ToMd5(pass);
                int      authorization = Convert.ToInt32(level.Value);
                if (c)
                {
                    Cnst.SqlCon.Open();
                    query = "INSERT INTO tblLogin (username, password, level) VALUES (@username, @password , @level)";
                    SqlCommand myCommand = new SqlCommand(query, Cnst.SqlCon);
                    myCommand.Parameters.AddWithValue("@username", txtSignInName.Text);
                    myCommand.Parameters.AddWithValue("@password", hashPass);
                    myCommand.Parameters.AddWithValue("@level", authorization);
                    myCommand.ExecuteNonQuery();
                    Cnst.SqlCon.Close();
                    Prisijungimas redirect = new Prisijungimas();
                    this.Hide();
                    redirect.Show();
                    MessageBox.Show("Priregistruota");
                }
            }
        }
        private void Keisti_Click(object sender, EventArgs e)
        {
            if (Cnst.alevel != 2)
            {
                if (txtOldName.Text.Length > 0 && txtOldPass.Text.Length > 0)
                {
                    var pass  = Cnst.ToMd5(txtOldPass.Text);
                    var query = "SELECT password from tblLogin where username = '******'";// AND SELECT password from tblLogin where username = '******'";
                    var sda   = new SqlDataAdapter(query, Cnst.SqlCon);
                    var dtbl  = new DataTable();
                    sda.Fill(dtbl);
                    var passCheck = dtbl.Rows[0][0].ToString();

                    if (passCheck == pass && Cnst.User == txtOldName.Text)
                    {
                        if (txtNewPass.Text.Length > 0 && txtNewName.Text.Length > 0)
                        {
                            Cnst.SqlCon.Open();
                            query = "UPDATE tblLogin SET password = '******' and username = '******' WHERE username = '******' ";
                            var myCommand = new SqlCommand(query, Cnst.SqlCon);
                            myCommand.ExecuteNonQuery();
                            Cnst.SqlCon.Close();
                            Cnst.User = txtNewName.Text;
                        }
                        else
                        {
                            Cnst.SqlCon.Open();
                            query = "UPDATE tblLogin SET password = '******' WHERE username = '******' ";
                            var myCommand = new SqlCommand(query, Cnst.SqlCon);
                            myCommand.ExecuteNonQuery();
                            Cnst.SqlCon.Close();
                        }
                        MessageBox.Show("Duomenys sėkmingai pakeisti");
                    }
                }
            }
            else
            {
                if (txtNewPass.Text.Length > 0 && txtNewName.Text.Length > 0)
                {
                    Cnst.SqlCon.Open();
                    var query     = "UPDATE tblLogin SET password = '******' and username = '******' WHERE username = '******' ";
                    var myCommand = new SqlCommand(query, Cnst.SqlCon);
                    myCommand.ExecuteNonQuery();
                    Cnst.SqlCon.Close();
                    Cnst.User = txtNewName.Text;
                    MessageBox.Show("Duomenys sėkmingai pakeisti");
                }
                else if (txtNewPass.Text.Length > 0)
                {
                    Cnst.SqlCon.Open();
                    var query     = "UPDATE tblLogin SET password = '******' WHERE username = '******' ";
                    var myCommand = new SqlCommand(query, Cnst.SqlCon);
                    myCommand.ExecuteNonQuery();
                    Cnst.SqlCon.Close();
                    MessageBox.Show("Duomenys sėkmingai pakeisti");
                }
            }
        }
Example #3
0
        private void Login_Click(object sender, EventArgs e)
        {
            var passMd5 = Cnst.ToMd5(txtPassword.Text.Trim()); // pass pakeistas i md5 hash
            var query   = "Select * from tblLogin Where username = '******' and password = '******'";
            var sda     = new SqlDataAdapter(query, Cnst.SqlCon);
            var dtbl    = new DataTable();

            sda.Fill(dtbl);
            if (dtbl.Rows.Count == 0)
            {
                MessageBox.Show("Check username and (or) password");
            }
            else
            {
                Cnst.User   = txtUserName.Text.Trim();
                Cnst.alevel = Int32.Parse(dtbl.Rows[0]["level"].ToString()); // authorization level
                switch (Cnst.alevel)
                {
                case 0:
                {
                    var redirect = new PardavejoMeniu();
                    Hide();
                    redirect.Show();
                    break;
                }

                case 1:
                {
                    var redirect = new SandelininkoMeniu();
                    Hide();
                    redirect.Show();
                    break;
                }

                case 2:
                {
                    var redirect = new AdministratoriausMeniu();
                    Hide();
                    redirect.Show();
                    break;
                }
                }
            }
        }
Example #4
0
        private void CreateAccount_Click(object sender, EventArgs e)
        {
            DropList level         = comboBox1.SelectedItem as DropList;
            string   pass          = txtSignInPassword.Text.Trim();
            string   hashPass      = Cnst.ToMd5(pass);
            int      authorization = Convert.ToInt32(level.Value);

            if (c)
            {
                Cnst.SqlCon.Open();
                string     query     = "INSERT INTO tblLogin (username, password, level) VALUES (@username, @password , @level)";
                SqlCommand myCommand = new SqlCommand(query, Cnst.SqlCon);
                myCommand.Parameters.AddWithValue("@username", txtSignInName.Text);
                myCommand.Parameters.AddWithValue("@password", hashPass);
                myCommand.Parameters.AddWithValue("@level", authorization);
                myCommand.ExecuteNonQuery();
                Cnst.SqlCon.Close();
                FormLogIn redirect = new FormLogIn();
                this.Hide();
                redirect.Show();
                MessageBox.Show("Priregistruota");
            }
        }
Example #5
0
 private void FormSignIn_FormClosing(object sender, FormClosingEventArgs e)
 {
     Cnst.ExitApp();
 }
Example #6
0
 private void FormAddItem_FormClosing(object sender, FormClosingEventArgs e)
 {
     Cnst.ExitApp();
 }
 private void Exit(object sender, FormClosingEventArgs e)
 {
     Cnst.ExitApp();
 }