Exemple #1
0
        private void registrasiButton_Click(object sender, EventArgs e)
        {
            String username   = registrasiusernameText.Text;
            String password   = registrasipasswordText.Text;
            String verifikasi = registrasiverifikasiText.Text;

            if (username.Length < 5 || username.Length > 15)
            {
                MessageBox.Show("Panjang username harus 5 - 15 karakter");
                return;
            }
            if (password.Length < 5 || password.Length > 15)
            {
                MessageBox.Show("Panjang password harus 5 - 15 karakter");
                return;
            }
            if (!containCharacterOnly(username))
            {
                MessageBox.Show("Username hanya boleh terdiri dari huruf alphabet besar/kecil");
                return;
            }
            //using (var conn = new SqlConnection(GlobalVariable.builder))
            //{
            //    conn.Open();
            //    String query = "SELECT * FROM UserData WHERE username = @username";
            //    using (var cmd = new SqlCommand(query,conn))
            //    {
            //        cmd.Parameters.AddWithValue("@username",username);
            //        if (cmd.ExecuteScalar() != null)
            //        {
            //            MessageBox.Show("Username Telah Ada");
            //            return;
            //        }
            //    }
            //    conn.Close();
            //}
            using (var conn = new SQLiteConnection(GlobalVariable.builder))
            {
                conn.Open();
                String query = "SELECT * FROM UserData WHERE username = @username";
                using (var cmd = new SQLiteCommand(query, conn))
                {
                    cmd.Parameters.AddWithValue("@username", username);
                    if (cmd.ExecuteScalar() != null)
                    {
                        MessageBox.Show("Username Telah Ada");
                        return;
                    }
                }
                conn.Close();
            }
            if (password != verifikasi)
            {
                MessageBox.Show("Password dan Verifikasi Password berbeda");
                return;
            }
            //using (var conn = new SqlConnection(GlobalVariable.builder))
            //{
            //    conn.Open();
            //    int maxID;
            //    String query = "SELECT COALESCE(MAX(userID),0) FROM UserData;";
            //    using (SqlCommand cmd = new SqlCommand(query,conn))
            //    {
            //        maxID = (int)cmd.ExecuteScalar();
            //    }
            //    query = "INSERT UserData(userID,username,password) VALUES (@userID,@username,PWDENCRYPT(@password));";
            //    using (SqlCommand cmd = new SqlCommand(query,conn))
            //    {
            //        cmd.Parameters.AddWithValue("@userID", maxID + 1);
            //        cmd.Parameters.AddWithValue("@username", username);
            //        cmd.Parameters.AddWithValue("@password", password);
            //        cmd.ExecuteNonQuery();
            //    }
            //    query = "INSERT UserROle(userID,roleID) VALUES (@userID,@roleID)";
            //    using (SqlCommand cmd = new SqlCommand(query, conn))
            //    {
            //        cmd.Parameters.AddWithValue("@userID", maxID + 1);
            //        cmd.Parameters.Add("@roleID", SqlDbType.VarChar);
            //        if (checkBox1.Checked)
            //        {
            //            cmd.Parameters["@roleID"].Value = "PRO1";
            //            cmd.ExecuteNonQuery();
            //        }
            //        if (checkBox2.Checked)
            //        {
            //            cmd.Parameters["@roleID"].Value = "PRO2";
            //            cmd.ExecuteNonQuery();
            //        }
            //        if (checkBox4.Checked)
            //        {
            //            cmd.Parameters["@roleID"].Value = "ORD1";
            //            cmd.ExecuteNonQuery();
            //        }
            //        if (checkBox3.Checked)
            //        {
            //            cmd.Parameters["@roleID"].Value = "ORD2";
            //            cmd.ExecuteNonQuery();
            //        }
            //        if (checkBox6.Checked)
            //        {
            //            cmd.Parameters["@roleID"].Value = "INV1";
            //            cmd.ExecuteNonQuery();
            //        }
            //        if (checkBox5.Checked)
            //        {
            //            cmd.Parameters["@roleID"].Value = "INV2";
            //            cmd.ExecuteNonQuery();
            //        }
            //        if (checkBox8.Checked)
            //        {
            //            cmd.Parameters["@roleID"].Value = "REC1";
            //            cmd.ExecuteNonQuery();
            //        }
            //        if (checkBox7.Checked)
            //        {
            //            cmd.Parameters["@roleID"].Value = "REC2";
            //            cmd.ExecuteNonQuery();
            //        }
            //        if (checkBox10.Checked)
            //        {
            //            cmd.Parameters["@roleID"].Value = "STO1";
            //            cmd.ExecuteNonQuery();
            //        }
            //        if (checkBox9.Checked)
            //        {
            //            cmd.Parameters["@roleID"].Value = "STO2";
            //            cmd.ExecuteNonQuery();
            //        }
            //        if (checkBox12.Checked)
            //        {
            //            cmd.Parameters["@roleID"].Value = "PUR1";
            //            cmd.ExecuteNonQuery();
            //        }
            //        if (checkBox11.Checked)
            //        {
            //            cmd.Parameters["@roleID"].Value = "PUR2";
            //            cmd.ExecuteNonQuery();
            //        }
            //        if (checkBox14.Checked)
            //        {
            //            cmd.Parameters["@roleID"].Value = "CUS1";
            //            cmd.ExecuteNonQuery();
            //        }
            //        if (checkBox13.Checked)
            //        {
            //            cmd.Parameters["@roleID"].Value = "CUS2";
            //            cmd.ExecuteNonQuery();
            //        }
            //        if (checkBox15.Checked)
            //        {
            //            cmd.Parameters["@roleID"].Value = "USR";
            //            cmd.ExecuteNonQuery();
            //        }
            //        if (checkBox16.Checked)
            //        {
            //            cmd.Parameters["@roleID"].Value = "PUR3";
            //            cmd.ExecuteNonQuery();
            //        }
            //        if (checkBox17.Checked)
            //        {
            //            cmd.Parameters["@roleID"].Value = "STO3";
            //            cmd.ExecuteNonQuery();
            //        }
            //        if (checkBox18.Checked)
            //        {
            //            cmd.Parameters["@roleID"].Value = "CUS3";
            //            cmd.ExecuteNonQuery();
            //        }
            //    }
            //    conn.Close();
            //}
            using (var conn = new SQLiteConnection(GlobalVariable.builder))
            {
                conn.Open();
                int    maxID;
                String query = "SELECT COALESCE(MAX(userID),0) FROM UserData;";
                using (var cmd = new SQLiteCommand(query, conn))
                {
                    maxID = Convert.ToInt32(cmd.ExecuteScalar());
                }
                query = "INSERT INTO UserData(userID,username,password) VALUES (@userID,@username,@password);";
                using (var cmd = new SQLiteCommand(query, conn))
                {
                    cmd.Parameters.AddWithValue("@userID", maxID + 1);
                    cmd.Parameters.AddWithValue("@username", username);
                    cmd.Parameters.AddWithValue("@password", GlobalVariable.Hash(password));
                    cmd.ExecuteNonQuery();
                }
                query = "INSERT INTO UserRole(userID,roleID) VALUES (@userID,@roleID)";
                using (var cmd = new SQLiteCommand(query, conn))
                {
                    cmd.Parameters.AddWithValue("@userID", maxID + 1);
                    cmd.Parameters.Add("@roleID", DbType.String);
                    if (checkBox1.Checked)
                    {
                        cmd.Parameters["@roleID"].Value = "PRO1";
                        cmd.ExecuteNonQuery();
                    }
                    if (checkBox2.Checked)
                    {
                        cmd.Parameters["@roleID"].Value = "PRO2";
                        cmd.ExecuteNonQuery();
                    }
                    if (checkBox4.Checked)
                    {
                        cmd.Parameters["@roleID"].Value = "ORD1";
                        cmd.ExecuteNonQuery();
                    }
                    if (checkBox3.Checked)
                    {
                        cmd.Parameters["@roleID"].Value = "ORD2";
                        cmd.ExecuteNonQuery();
                    }
                    if (checkBox6.Checked)
                    {
                        cmd.Parameters["@roleID"].Value = "INV1";
                        cmd.ExecuteNonQuery();
                    }
                    if (checkBox5.Checked)
                    {
                        cmd.Parameters["@roleID"].Value = "INV2";
                        cmd.ExecuteNonQuery();
                    }
                    if (checkBox8.Checked)
                    {
                        cmd.Parameters["@roleID"].Value = "REC1";
                        cmd.ExecuteNonQuery();
                    }
                    if (checkBox7.Checked)
                    {
                        cmd.Parameters["@roleID"].Value = "REC2";
                        cmd.ExecuteNonQuery();
                    }
                    if (checkBox10.Checked)
                    {
                        cmd.Parameters["@roleID"].Value = "STO1";
                        cmd.ExecuteNonQuery();
                    }
                    if (checkBox9.Checked)
                    {
                        cmd.Parameters["@roleID"].Value = "STO2";
                        cmd.ExecuteNonQuery();
                    }
                    if (checkBox12.Checked)
                    {
                        cmd.Parameters["@roleID"].Value = "PUR1";
                        cmd.ExecuteNonQuery();
                    }
                    if (checkBox11.Checked)
                    {
                        cmd.Parameters["@roleID"].Value = "PUR2";
                        cmd.ExecuteNonQuery();
                    }
                    if (checkBox14.Checked)
                    {
                        cmd.Parameters["@roleID"].Value = "CUS1";
                        cmd.ExecuteNonQuery();
                    }
                    if (checkBox13.Checked)
                    {
                        cmd.Parameters["@roleID"].Value = "CUS2";
                        cmd.ExecuteNonQuery();
                    }
                    if (checkBox15.Checked)
                    {
                        cmd.Parameters["@roleID"].Value = "USR";
                        cmd.ExecuteNonQuery();
                    }
                    if (checkBox16.Checked)
                    {
                        cmd.Parameters["@roleID"].Value = "PUR3";
                        cmd.ExecuteNonQuery();
                    }
                    if (checkBox17.Checked)
                    {
                        cmd.Parameters["@roleID"].Value = "STO3";
                        cmd.ExecuteNonQuery();
                    }
                    if (checkBox18.Checked)
                    {
                        cmd.Parameters["@roleID"].Value = "CUS3";
                        cmd.ExecuteNonQuery();
                    }
                }
                conn.Close();
            }
            MessageBox.Show("Akun Berhasil Ditambahkan");
        }
Exemple #2
0
        private void changeButton_Click(object sender, EventArgs e)
        {
            String username    = changeusernameText.Text;
            String password    = changepasswordText.Text;
            String newpassword = changenewpasswordText.Text;
            String verifikasi  = changeverifiasiText.Text;

            //using (sqlconnection conn = new sqlconnection(globalvariable.builder))
            //{
            //    conn.open();
            //    string query = "select * from userdata where username = @username and pwdcompare(@password,password) = 1";
            //    using (sqlcommand cmd = new sqlcommand(query, conn))
            //    {
            //        cmd.parameters.addwithvalue("@username", username);
            //        cmd.parameters.addwithvalue("@password", password);
            //        if (cmd.executescalar() == null)
            //        {
            //            messagebox.show("username dengan password tidak sesuai");
            //            return;
            //        }
            //    }
            //    if (newpassword.length < 5 || newpassword.length > 15)
            //    {
            //        conn.close();
            //        messagebox.show("panjang password baru harus 5 - 15 karakter");
            //        return;
            //    }
            //    if (newpassword != verifikasi)
            //    {
            //        conn.close();
            //        messagebox.show("password baru dan verifikasi password berbeda");
            //        return;
            //    }
            //    query = "update userdata set password = pwdencrypt(@password) where username = @username;";
            //    using (sqlcommand cmd = new sqlcommand(query, conn))
            //    {
            //        cmd.parameters.addwithvalue("@username", username);
            //        cmd.parameters.addwithvalue("@password", newpassword);
            //        cmd.executenonquery();
            //    }
            //    conn.close();
            //}
            using (var conn = new SQLiteConnection(GlobalVariable.builder))
            {
                conn.Open();
                String query = "SELECT * FROM UserData WHERE username = @username AND password = @password";
                using (var cmd = new SQLiteCommand(query, conn))
                {
                    cmd.Parameters.AddWithValue("@username", username);
                    cmd.Parameters.AddWithValue("@password", GlobalVariable.Hash(password));
                    if (cmd.ExecuteScalar() == null)
                    {
                        MessageBox.Show("Username dengan Password tidak sesuai");
                        return;
                    }
                }
                if (newpassword.Length < 5 || newpassword.Length > 15)
                {
                    conn.Close();
                    MessageBox.Show("Panjang password baru harus 5 - 15 karakter");
                    return;
                }
                if (newpassword != verifikasi)
                {
                    conn.Close();
                    MessageBox.Show("Password baru dan Verifikasi Password berbeda");
                    return;
                }
                query = "UPDATE UserData SET password = @password WHERE username = @username;";
                using (var cmd = new SQLiteCommand(query, conn))
                {
                    cmd.Parameters.AddWithValue("@username", username);
                    cmd.Parameters.AddWithValue("@password", GlobalVariable.Hash(newpassword));
                    cmd.ExecuteNonQuery();
                }
                conn.Close();
            }
            MessageBox.Show("Password Akun Berhasil Diubah");
            changepasswordText.Text = changenewpasswordText.Text = changeverifiasiText.Text = "";
        }
Exemple #3
0
        private void loginButton_Click(object sender, EventArgs e)
        {
            ////if (radioButton2.Checked)
            ////{
            ////    GlobalVariable.builder = @"Data Source=(LocalDB)\MSSQLLocalDB;
            ////                AttachDbFilename=" + textBox1.Text+ @";
            ////                Integrated Security=True";
            ////} else
            ////{
            ////    GlobalVariable.builder = @"Data Source=(LocalDB)\MSSQLLocalDB;
            ////                AttachDbFilename=|DataDirectory|bordirDatabase.mdf;
            ////                ;Integrated Security=True";
            ////}
            ////String username = usernameText.Text, password = passwordText.Text;
            ////bool success = false;
            ////using (var conn = new SqlConnection(GlobalVariable.builder))
            ////{
            ////    conn.Open();
            ////    String query = "SELECT * FROM UserData WHERE username = @username AND PWDCOMPARE(@password,password) = 1;";
            ////    using (var cmd = new SqlCommand(query, conn))
            ////    {
            ////        cmd.Parameters.AddWithValue("@username",username);
            ////        cmd.Parameters.AddWithValue("@password", password);
            ////        using (SqlDataReader reader = cmd.ExecuteReader())
            ////            while (reader.Read())
            ////            {
            ////                GlobalVariable.loginUserId = Convert.ToInt32(reader["userID"]);
            ////                GlobalVariable.loginUsername = reader["username"].ToString();
            ////                success = true;
            ////            }
            ////    }
            ////    conn.Close();
            ////}
            ////if (success)
            ////{
            ////    if (radioButton2.Checked)
            ////        Properties.Settings.Default["DatabaseDirectory"] = textBox1.Text;
            ////    else
            ////        Properties.Settings.Default["DatabaseDirectory"] = "|DataDirectory|bordirDatabase.mdf";
            ////    Properties.Settings.Default.Save();
            ////    openForm(new MenuForm());
            ////}
            ////else
            ////    MessageBox.Show("Login Failed");
            if (radioButton2.Checked)
            {
                GlobalVariable.builder = @"Data Source=" + textBox1.Text + "; Version = 3";
            }
            else
            {
                GlobalVariable.builder = @"Data Source=|DataDirectory|bordirDatabase.sqlite3; Version = 3;";
            }
            ////string mdfbuilder = @"Data Source=(LocalDB)\MSSQLLocalDB;
            ////            AttachDbFilename=D:\BORDIRDATABASE.MDF;
            ////            Integrated Security=True";
            ////using (var conn = new SqlConnection(mdfbuilder))
            ////{
            ////    conn.Open();
            ////    String query = "SELECT * FROM Customer";
            ////    using (var cmd = new SqlCommand(query, conn))
            ////    {
            ////        using (var reader = cmd.ExecuteReader())
            ////        {
            ////            while (reader.Read())
            ////            {
            ////                int customerID = Convert.ToInt32(reader["customerID"]);
            ////                String nameCustomer = reader["nameCustomer"].ToString();
            ////                String address = reader["address"].ToString();
            ////                String fax = reader["fax"].ToString();
            ////                String isCustomer = reader["customer"].ToString();
            ////                String isSupplier = reader["supplier"].ToString();
            ////                using (var conn2 = new SQLiteConnection(GlobalVariable.builder))
            ////                {
            ////                    conn2.Open();
            ////                    //masukkan data
            ////                    String query2 = "INSERT INTO Customer (customerID,nameCustomer,address,fax,customer,supplier) VALUES (@customerID,@nameCustomer,@address,@fax,@customer,@supplier);";
            ////                    using (var cmd2 = new SQLiteCommand(query2, conn2))
            ////                    {
            ////                        cmd2.Parameters.AddWithValue("@customerID", customerID);
            ////                        cmd2.Parameters.AddWithValue("@nameCustomer", nameCustomer);
            ////                        cmd2.Parameters.AddWithValue("@address", address);
            ////                        cmd2.Parameters.AddWithValue("@fax", fax);
            ////                        cmd2.Parameters.AddWithValue("@customer", isCustomer);
            ////                        cmd2.Parameters.AddWithValue("@supplier", isSupplier);
            ////                        cmd2.ExecuteNonQuery();
            ////                    }
            ////                    conn2.Close();
            ////                }
            ////            }
            ////        }
            ////    }
            ////    query = "SELECT * FROM CustomerContactPerson";
            ////    using (var cmd = new SqlCommand(query, conn))
            ////    {
            ////        using (var reader = cmd.ExecuteReader())
            ////        {
            ////            while (reader.Read())
            ////            {
            ////                int customerID = Convert.ToInt32(reader["customerID"]);
            ////                String name = reader["name"].ToString();
            ////                String hp = reader["hp"].ToString();
            ////                String ext = reader["ext"].ToString();
            ////                using (var conn2 = new SQLiteConnection(GlobalVariable.builder))
            ////                {
            ////                    conn2.Open();
            ////                    //masukkan data
            ////                    String query2 = "INSERT INTO CustomerContactPerson (customerID,name,hp,ext) VALUES (@customerID,@name,@hp,@ext);";
            ////                    using (var cmd2 = new SQLiteCommand(query2, conn2))
            ////                    {
            ////                        cmd2.Parameters.AddWithValue("@customerID", customerID);
            ////                        cmd2.Parameters.AddWithValue("@name", name);
            ////                        cmd2.Parameters.AddWithValue("@hp", hp);
            ////                        cmd2.Parameters.AddWithValue("@ext", ext);
            ////                        cmd2.ExecuteNonQuery();
            ////                    }
            ////                    conn2.Close();
            ////                }
            ////            }
            ////        }
            ////    }
            ////    query = "SELECT * FROM CustomerTelephone";
            ////    using (var cmd = new SqlCommand(query, conn))
            ////    {
            ////        using (var reader = cmd.ExecuteReader())
            ////        {
            ////            while (reader.Read())
            ////            {
            ////                int customerID = Convert.ToInt32(reader["customerID"]);
            ////                String telephone = reader["telephone"].ToString();
            ////                using (var conn2 = new SQLiteConnection(GlobalVariable.builder))
            ////                {
            ////                    conn2.Open();
            ////                    //masukkan data
            ////                    String query2 = "INSERT INTO CustomerTelephone (customerID,telephone) VALUES (@customerID,@telephone);";
            ////                    using (var cmd2 = new SQLiteCommand(query2, conn2))
            ////                    {
            ////                        cmd2.Parameters.AddWithValue("@customerID", customerID);
            ////                        cmd2.Parameters.AddWithValue("@telephone", telephone);
            ////                        cmd2.ExecuteNonQuery();
            ////                    }
            ////                    conn2.Close();
            ////                }
            ////            }
            ////        }
            ////    }
            ////    conn.Close();
            ////}
            String username = usernameText.Text, password = passwordText.Text;
            bool   success = false;

            using (SQLiteConnection conn = new SQLiteConnection(GlobalVariable.builder))
            {
                conn.Open();
                String query = "SELECT * FROM UserData WHERE username = @username AND password = @password;";
                using (SQLiteCommand cmd = new SQLiteCommand(query, conn))
                {
                    cmd.Parameters.AddWithValue("@username", username);
                    cmd.Parameters.AddWithValue("@password", GlobalVariable.Hash(password));
                    using (SQLiteDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            GlobalVariable.loginUserId   = Convert.ToInt32(reader["userID"]);
                            GlobalVariable.loginUsername = reader["username"].ToString();
                            success = true;
                        }
                    }
                }
                conn.Close();
            }
            if (success)
            {
                if (radioButton2.Checked)
                {
                    Properties.Settings.Default["DatabaseDirectory2"] = textBox1.Text;
                }
                else
                {
                    Properties.Settings.Default["DatabaseDirectory2"] = "|DataDirectory|bordirDatabase.sqlite3";
                }
                Properties.Settings.Default.Save();
                openForm(new MenuForm());
                passwordText.Text = "";
            }
            else
            {
                MessageBox.Show("Login Failed");
            }
        }