bind() public method

public bind ( string fields ) : void
fields string
return void
示例#1
0
        private void btnSaveChanges_Click(object sender, EventArgs e)
        {
            btnSaveChanges.Focus();
            bool tagsdel = false;

            Utilities.runInThread(() =>
            {
                if (string.IsNullOrEmpty(txtAddQ.Text.Trim()) == true || string.IsNullOrEmpty(txtAddTags.Text.Trim()) == true || (dgvAnswerlist.Rows.Count < 2))
                {
                    Utilities.notifyThem(ntfEdit, "You must fill some info about your question first.", NotificationBox.Type.Error);
                }
                else
                {
                    List <Answer> Answers = new List <Answer>();
                    for (int a = 0; a < dgvAnswerlist.Rows.Count - 1; a++)
                    {
                        bool correct;
                        if (dgvAnswerlist.Rows[a].Cells[1].Value == null)
                        {
                            correct = false;
                        }
                        else
                        {
                            correct = bool.Parse(dgvAnswerlist.Rows[a].Cells[1].Value.ToString());
                        }
                        Answers.Add(new Answer(dgvAnswerlist.Rows[a].Cells[0].Value.ToString().TrimEnd().TrimStart(), correct));
                    }


                    DB TempDB = Utilities.AsyncDB(true);
                    TempDB.bind(new string[] { "Question", txtAddQ.Text.TrimEnd().TrimStart(), "Answers", JsonConvert.SerializeObject(Answers).ToString(), "Dlevel", difficultyLvl.Value.ToString(), "Prive", (switchPrivate.isOn ? 1 : 0).ToString(), "UID", Globals.logUser.id.ToString() });

                    string qid = TempDB.single("UPDATE questions SET question = @Question, answers = @Answers, dlevel = @Dlevel, prive = @Prive, uid = @UID WHERE id=" + _quest.id + ";");

                    int qAddTag   = 0;
                    string[] tags = txtAddTags.Text.TrimEnd(',').Split(',');
                    foreach (string tag in tags)
                    {
                        if (!string.IsNullOrEmpty(tag))
                        {
                            if (tagsdel == true)
                            {
                                TempDB.bind(new string[] { "TAG", tag.ToLower(), "QID", _quest.id.ToString() });
                                qAddTag += TempDB.nQuery("INSERT INTO tags (nametag, qid) VALUES (@TAG, @QID)");
                            }
                            else
                            {
                                TempDB.nQuery("DELETE FROM tags WHERE qid = " + _quest.id);
                                TempDB.bind(new string[] { "TAG", tag.ToLower(), "QID", _quest.id.ToString() });
                                qAddTag += TempDB.nQuery("INSERT INTO tags (nametag, qid) VALUES (@TAG, @QID)");
                                tagsdel  = true;
                            }
                        }
                    }
                    Utilities.notifyThem(ntfEdit, "Successfully Saved.", NotificationBox.Type.Success);
                    Functionality.RefreshMyQuestions();
                    change = false;
                }
            }).Start();
        }
示例#2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtAddQ.Text.Trim()) == true || string.IsNullOrEmpty(txtAddTags.Text.Trim()) == true || (dgvAnswerlist.Rows.Count < 1))
            {
                Utilities.notifyThem(ntfAdd, "You must fill some info about your question first", NotificationBox.Type.Error);
            }
            else
            {
                List <Answer> Answers = new List <Answer>();
                for (int i = 0; i < dgvAnswerlist.Rows.Count; i++)
                {
                    Answers.Add(new Answer(dgvAnswerlist.Rows[i].Cells[0].Value.ToString().TrimEnd().TrimStart(), bool.Parse(dgvAnswerlist.Rows[i].Cells[1].Value.ToString())));
                }
                Utilities.runInThread(() =>
                {
                    DB TempDB = Utilities.AsyncDB(true);
                    TempDB.bind(new string[] { "Question", txtAddQ.Text.TrimEnd().TrimStart(), "Answers", JsonConvert.SerializeObject(Answers).ToString(), "Dlevel", difficultyLvl.Value.ToString(), "Prive", (switchPrivate.isOn ? 1 : 0).ToString(), "UID", Globals.logUser.id.ToString() });
                    string qid = TempDB.single("INSERT INTO questions (question, answers, dlevel, prive, uid) VALUES (@Question, @Answers, @Dlevel, @Prive, @UID); select last_insert_id();");

                    int qAddTag   = 0;
                    string[] tags = txtAddTags.Text.TrimEnd(',').Split(',');
                    foreach (string tag in tags)
                    {
                        if (!string.IsNullOrEmpty(tag))
                        {
                            TempDB.bind(new string[] { "TAG", tag.ToLower(), "QID", qid });
                            qAddTag += TempDB.nQuery("INSERT INTO tags (nametag, qid) VALUES (@TAG, @QID)");
                        }
                    }

                    if (string.IsNullOrEmpty(qid) == false && qAddTag > 0)
                    {
                        Utilities.notifyThem(ntfAdd, "Successfull Added Question !", NotificationBox.Type.Success);
                        Functionality.RefreshMyQuestions();
                        Utilities.clearText(txtAddQ, txtAddTags, txtAnswer);
                        Utilities.InvokeMe(dgvAnswerlist, () =>
                        {
                            dgvAnswerlist.Rows.Clear();
                            dgvAnswerlist.Refresh();
                        });
                        Utilities.InvokeMe(difficultyLvl, () =>
                        {
                            difficultyLvl.Value = 1;
                        });
                        Utilities.InvokeMe(switchPrivate, () =>
                        {
                            switchPrivate.isOn = false;
                        });
                        Utilities.InvokeMe(switchCorrectAnswer, () =>
                        {
                            switchCorrectAnswer.isOn = true;
                        });

                        Functionality.LoadTags(autocompleteMenu1);
                    }
                }).Start();
            }
        }
示例#3
0
        private void newRandomPassword(String user, int length)
        {
            if (Globals.Connected)
            {
                String password = createPassword(length);

                Utilities.runInThread(() =>
                {
                    DB changePassDB = Utilities.AsyncDB();
                    changePassDB.bind(new string[] { "usern", user, "pass1", Utilities.MD5Hash(password) });

                    int qreg = changePassDB.nQuery("UPDATE users SET pass=@pass1 where user=@usern");

                    if (qreg > 0)
                    {
                        Utilities.notifyThem(ntfForgot, "Successfully Generated", NotificationBox.Type.Success);
                        Utilities.InvokeMe(txtPassPassword, () =>
                        {
                            txtPassPassword.Text = password;
                        });
                    }
                    else
                    {
                        Utilities.notifyThem(ntfForgot, "Failed to Generate", NotificationBox.Type.Error);
                    }
                }).Start();
            }
        }
示例#4
0
        private bool securityCodeCheck(String username, String securityCodeCompare)
        {
            bool   checkPass = false;
            Thread t         = Utilities.runInThread(() =>
            {
                DB TempLogUser = Utilities.AsyncDB();
                TempLogUser.bind(new string[] { "user", username });
                DataTable dt = TempLogUser.query("select securitycode from users where user=@user");
                if (dt.Rows.Count == 1)
                {
                    String securityCode = dt.Rows[0][0].ToString();
                    if (securityCode.Equals(securityCodeCompare))
                    {
                        checkPass = true;
                    }
                    else
                    {
                        checkPass = false;
                    }
                }
                else
                {
                    checkPass = false;
                }
            });

            t.Start();
            t.Join();

            return(checkPass);
        }
示例#5
0
        private void btnChangeSecurity_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtspassword.Text) == true || string.IsNullOrEmpty(txtncode.Text.Trim()) == true)
            {
                Utilities.notifyThem(ntfC, "All fields are necessary", NotificationBox.Type.Error);
            }
            else if (!Globals.logUser.pass.Equals(Utilities.MD5Hash(txtspassword.Text)))
            {
                Utilities.notifyThem(ntfC, "Wrong Password", NotificationBox.Type.Error);
            }
            else if (txtncode.Text.Length < 4)
            {
                Utilities.notifyThem(ntfC, "Security code must be at least 4 characters", NotificationBox.Type.Warning);
            }
            else if (Validation.IsValidSecurityCode(txtncode.Text))
            {
                Utilities.notifyThem(ntfC, "Security code must contain\na-z, A-Z, 0-9 characters", NotificationBox.Type.Warning);
            }
            else
            {
                Utilities.runInThread(() =>
                {
                    String HashSecur = Utilities.MD5Hash(txtncode.Text.Trim());

                    DB TempDB = Utilities.AsyncDB();
                    TempDB.bind(new string[] { "Code", HashSecur });
                    TempDB.nQuery("UPDATE users SET securitycode=@Code WHERE id=" + Globals.logUser.id);
                    Globals.logUser.scode = HashSecur;
                    Utilities.clearText(txtspassword, txtncode);
                }).Start();
                Utilities.notifyThem(ntfC, "Security Code Changed", NotificationBox.Type.Success);
            }
        }
示例#6
0
 private void btnChangeEmail_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(txtepassword.Text) == true || string.IsNullOrEmpty(txtnemail.Text.Trim()) == true)
     {
         Utilities.notifyThem(ntfE, "All fields are necessary", NotificationBox.Type.Error);
     }
     else if (!Globals.logUser.pass.Equals(Utilities.MD5Hash(txtepassword.Text)))
     {
         Utilities.notifyThem(ntfE, "Wrong Password", NotificationBox.Type.Error);
     }
     else if (!Validation.IsValidEmail(txtnemail.Text))
     {
         Utilities.notifyThem(ntfE, "Email is not valid", NotificationBox.Type.Error);
     }
     else if (Validation.EmailAvailibility(txtnemail.Text))
     {
         Utilities.notifyThem(ntfE, "Email already exists", NotificationBox.Type.Warning);
     }
     else
     {
         Utilities.runInThread(() =>
         {
             DB TempDB = Utilities.AsyncDB();
             TempDB.bind(new string[] { "Email", txtnemail.Text.Trim() });
             TempDB.nQuery("UPDATE users SET email=@Email WHERE id=" + Globals.logUser.id);
             Globals.logUser.email = txtnemail.Text;
             Utilities.clearText(txtepassword, txtnemail);
         }).Start();
         Utilities.notifyThem(ntfE, "Email Changed", NotificationBox.Type.Success);
     }
 }
示例#7
0
        private void btnChangePassword_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtopassword.Text) == true || string.IsNullOrEmpty(txtnpassword.Text) == true || string.IsNullOrEmpty(txtrnpassword.Text))
            {
                Utilities.notifyThem(ntfP, "All fields are necessary", NotificationBox.Type.Error);
            }
            else if (!txtnpassword.Text.Equals(txtrnpassword.Text))
            {
                Utilities.notifyThem(ntfP, "Different new Password fields", NotificationBox.Type.Error);
            }
            else if (!Globals.logUser.pass.Equals(Utilities.MD5Hash(txtopassword.Text)))
            {
                Utilities.notifyThem(ntfP, "Wrong old Password", NotificationBox.Type.Error);
            }
            else
            {
                Utilities.runInThread(() =>
                {
                    String HashPass = Utilities.MD5Hash(txtnpassword.Text);

                    DB TempDB = Utilities.AsyncDB();
                    TempDB.bind(new string[] { "Pass", HashPass });
                    TempDB.nQuery("UPDATE users SET pass=@Pass WHERE id=" + Globals.logUser.id);
                    Globals.logUser.pass = HashPass;
                    Utilities.clearText(txtopassword, txtnpassword, txtrnpassword);
                }).Start();
                Utilities.notifyThem(ntfP, "Password Changed", NotificationBox.Type.Success);
            }
        }
示例#8
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (Globals.Connected)
            {
                txtLUser.Text = txtLUser.Text.Trim();
                if (string.IsNullOrEmpty(txtLUser.Text) || string.IsNullOrEmpty(txtLPass.Text))
                {
                    Utilities.notifyThem(ntfBox1, "Empty username or password!", NotificationBox.Type.Warning);
                }
                else
                {
                    Utilities.runInThread(() => {
                        String HashPass = Utilities.MD5Hash(txtLPass.Text);

                        DB TempLogUser = Utilities.AsyncDB();
                        TempLogUser.bind(new string[] { "user", txtLUser.Text, "pass", HashPass });
                        DataTable dt = TempLogUser.query("select * from users where user = @user and pass = @pass");
                        if (dt.Rows.Count == 1)
                        {
                            if (ckbLRemember.Checked)
                            {
                                Settings.save("StoredAccount", ckbLRemember.Checked.ToString(), txtLUser.Text, txtLPass.Text);
                            }
                            else
                            {
                                Settings.delete("StoredAccount");
                            }

                            //Load Tags
                            Functionality.LoadTags();

                            int id          = int.Parse(dt.Rows[0][0].ToString());
                            string user     = dt.Rows[0][1].ToString();
                            string pass     = dt.Rows[0][2].ToString();
                            string mail     = dt.Rows[0][3].ToString();
                            string scode    = dt.Rows[0][4].ToString();
                            Globals.logUser = new User(id, user, pass, mail, scode);

                            Utilities.InvokeMe(this, () =>
                            {
                                ntfBox1.Visible = false;
                                this.Hide();
                                Globals.formMain.Show();
                            });
                        }
                        else
                        {
                            Utilities.notifyThem(ntfBox1, "Username or Password were incorrect", NotificationBox.Type.Error);
                        }
                    }).Start();
                }
            }
            else
            {
                Utilities.notifyThem(ntfBox1, "Not connected to DB!", NotificationBox.Type.Warning);
            }
        }
示例#9
0
        private void btnRegister_Click(object sender, EventArgs e)
        {
            Utilities.runInThread(() =>
            {
                if (Globals.Connected)
                {
                    if (String.IsNullOrEmpty(txtRUser.Text.Trim()) || String.IsNullOrEmpty(txtRPass.Text) || String.IsNullOrEmpty(txtRrepeatPass.Text) || String.IsNullOrEmpty(txtREmail.Text.Trim()) || String.IsNullOrEmpty(txtRSecurityCode.Text.Trim()))
                    {
                        Utilities.notifyThem(ntfBox2, "All fields are necessary.", NotificationBox.Type.Warning);
                    }
                    else if (txtRPass.Text != txtRrepeatPass.Text)
                    {
                        Utilities.notifyThem(ntfBox2, "Passwords don't match.", NotificationBox.Type.Warning);
                    }
                    else if (!Validation.IsValidEmail(txtREmail.Text))
                    {
                        Utilities.notifyThem(ntfBox2, "Email is not valid.", NotificationBox.Type.Warning);
                    }
                    else if (Validation.EmailAvailibility(txtREmail.Text))
                    {
                        Utilities.notifyThem(ntfBox2, "Email is already exists.", NotificationBox.Type.Warning);
                    }
                    else if (txtRSecurityCode.Text.Length < 4)
                    {
                        Utilities.notifyThem(ntfBox2, "Security code must be at least 4 characters.", NotificationBox.Type.Warning);
                    }
                    else if (Validation.IsValidSecurityCode(txtRSecurityCode.Text))
                    {
                        Utilities.notifyThem(ntfBox2, "Security code must contain\na-z, A-Z, 0-9 characters", NotificationBox.Type.Warning);
                    }
                    else if (Validation.UsernameAvailibility(txtRUser.Text))
                    {
                        Utilities.notifyThem(ntfBox2, "Username is not available.", NotificationBox.Type.Warning);
                    }
                    else
                    {
                        String HashPass  = Utilities.MD5Hash(txtRPass.Text);
                        String HashSecur = Utilities.MD5Hash(txtRSecurityCode.Text);

                        DB tDB = Utilities.AsyncDB();
                        tDB.bind(new string[] { "usern", txtRUser.Text, "pass1", HashPass, "email1", txtREmail.Text, "securcode", HashSecur });

                        int qreg = tDB.nQuery("INSERT INTO users (user, pass, email,securitycode) VALUES (@usern, @pass1, @email1, @securcode)");


                        if (qreg > 0)
                        {
                            Utilities.notifyThem(ntfBox2, "Successfull Registration.", NotificationBox.Type.Success);
                        }
                    }
                }
                else
                {
                    Utilities.notifyThem(ntfBox2, "Not connected to DB!", NotificationBox.Type.Warning);
                }
            }).Start();
        }
示例#10
0
        public static bool EmailAvailibility(String str)
        {
            DB tDB = Utilities.AsyncDB();

            tDB.bind(new string[] { "Email", str });

            String Q      = tDB.single("SELECT COUNT(*) FROM users WHERE email = @Email");
            int    result = Int32.Parse(Q);

            if (result >= 1)
            {
                invalid = true;
            }
            else
            {
                invalid = false;
            }

            return(invalid);
        }