예제 #1
0
        private async void btn_Import_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog dialog = new OpenFileDialog()
            {
                Filter = "Excel Workbook|*.xlsx", ValidateNames = true
            })
            {
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    Enabled = false;
                    firebase_Connection fcon = new firebase_Connection();
                    SqlConnection       con  = new SqlConnection(connection_string);
                    string query             = "insert into vw_es_students (Full_Name,Student_No,College,Course,Status,Year,Password) " +
                                               " values (@param_fn,@param_sn,@param_cl,@param_cs,@param_s,@param_y,@param_p)";
                    string     truncate_query = "TRUNCATE TABLE vw_es_students";
                    SqlCommand cmd            = new SqlCommand(query, con);
                    SqlCommand truncate_cmd   = new SqlCommand(truncate_query, con);
                    string     path           = dialog.FileName;
                    Excel      excel          = new Excel(path, 1);
                    try
                    {
                        List <_App_User> results = excel.ReadCell();

                        //cleanup
                        GC.Collect();
                        GC.WaitForPendingFinalizers();
                        excel.cleanCOMobjects();

                        con.Open();
                        truncate_cmd.ExecuteNonQuery();
                        int max = excel._userCount * 4;
                        progressBar1.Maximum = max;
                        //drop queue_status and accounts first
                        await fcon.Controller_TruncateQueueStatus();

                        await fcon.Controller_DeleteAllAccounts();

                        foreach (_App_User b in results)
                        {
                            string password = Cryptography.Encrypt(b.password.ToString());

                            progressBar1.Increment(1);
                            //upload to the Firebase DB
                            try
                            {
                                await fcon.Controller_ImportUsers(b);

                                progressBar1.Increment(1);
                                await fcon.Controller_RegisterThisUser(b);

                                progressBar1.Increment(1);
                                await fcon.Controller_InsertQueueStatus(b.accountNumber);

                                progressBar1.Increment(1);

                                //upload to local db
                                cmd.Parameters.AddWithValue("@param_fn", b.lastName.ToUpper() + "," + b.firstName + " " + b.middleName);
                                cmd.Parameters.AddWithValue("@param_sn", b.accountNumber);
                                cmd.Parameters.AddWithValue("@param_cl", b.college);
                                cmd.Parameters.AddWithValue("@param_cs", b.course);
                                cmd.Parameters.AddWithValue("@param_s", b.status);
                                cmd.Parameters.AddWithValue("@param_y", b.year);
                                cmd.Parameters.AddWithValue("@param_p", password);
                                cmd.ExecuteNonQuery();
                                cmd.Parameters.Clear();
                            }
                            catch (FirebaseAuthException exd) {
                                Console.WriteLine(exd.Message);
                            }
                        }
                        con.Close();
                        progressBar1.Value = max;
                        MessageBox.Show("Import finished!", "Success!");
                        progressBar1.Value = 0;
                    }
                    catch (FormatException)
                    {
                        progressBar1.Value = 0;
                        MessageBox.Show("Make sure all the ID contains numbers only.", "Format error");
                    }
                    catch (FirebaseAuthException exd)
                    {
                        //progressBar1.Value = 0;
                        //MessageBox.Show("Make sure all of the Student_No contains no spaces and special characters. Error Code: "+exd.Reason,"Online Database error!");
                    }
                    catch (FirebaseException)
                    {
                        progressBar1.Value = 0;
                        MessageBox.Show("Please check your internet connection. Error Code:", "Connection error");
                    }
                    Enabled = true;
                }
            }
        }
예제 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            // Save changes
            // Check textBoxes length if OK

            Console.WriteLine("wat items");
            if (OkFieldLength())
            {
                SqlConnection con = new SqlConnection(connection_string);

                // Check if password is correct

                SqlCommand _check_cmd = new SqlCommand("SELECT Password FROM users WHERE status = @param_st", con);
                _check_cmd.Parameters.AddWithValue("@param_st", 0);
                SqlDataReader reader;
                string        Password = "";
                Console.WriteLine("Running items");
                try
                {
                    con.Open();
                    reader = _check_cmd.ExecuteReader();
                    if (reader.Read())
                    {
                        Password = (string)reader["Password"];
                    }
                    if (Cryptography.Decrypt(Password).Equals(textBox6.Text))
                    {
                        string     query = "update Users set ";
                        SqlCommand _cmd  = new SqlCommand();

                        _cmd.Connection = con;

                        if (!(string.IsNullOrEmpty(textBox4.Text)))
                        {
                            query += " Password = @param2";
                            _cmd.Parameters.AddWithValue("@param2", Cryptography.Encrypt(textBox4.Text.ToString()));
                        }


                        query += " where status = @param_st";
                        _cmd.Parameters.AddWithValue("@param_st", 0);
                        _cmd.CommandText = query;
                        _cmd.ExecuteNonQuery();

                        textBox4.Clear();
                        textBox6.Clear();

                        MessageBox.Show("Change Success", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("Please enter the valid credentials.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    con.Close();
                }
                catch (SqlException ex)
                {
                    MessageBox.Show("DB error! {0}", ex.Message);
                }
            }
        }