notifyThem() public static method

public static notifyThem ( NotificationBox ntfbox, string msg, NotificationBox ntype ) : void
ntfbox NotificationBox
msg string
ntype NotificationBox
return void
Example #1
0
        private void btnPrint_Click(object sender, EventArgs e)
        {
            List <Question> myTest = new List <Question>();

            if (string.IsNullOrWhiteSpace(txtTestTitle.Text))
            {
                Utilities.notifyThem(ntfTest, "No title found", NotificationBox.Type.Warning);
            }
            else if (dgvMyTest.Rows.Count < 1)
            {
                Utilities.notifyThem(ntfTest, "No Questions Found", NotificationBox.Type.Warning);
            }
            else
            {
                foreach (DataGridViewRow row in dgvMyTest.Rows)
                {
                    myTest.Add(Utilities.dgvRowIntoQuestion(row));
                }

                PrintTest.Initialize();
                PrintTest.SetTest(txtTestTitle.Text, datePicker.Value.ToShortDateString(), myTest, checkBoxAnsweredTest.Checked);
                Globals.formPrint.Document = PrintTest.Document;
                Globals.formPrint.ShowDialog();
            }
        }
Example #2
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();
        }
Example #3
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);
     }
 }
Example #4
0
 private void btnconnect_Click(object sender, EventArgs e)
 {
     Utilities.runInThread(() => {
         Globals.ConnectionStr(txtSHost.Text, txtSUser.Text, txtSPass.Text, txtSDatabase.Text);
         if (Utilities.AsyncDB().Connected())
         {
             Globals.Connected = true;
         }
         else
         {
             Globals.Connected = false;
         }
         if (Globals.Connected)
         {
             if (checkBoxRemember.Checked)
             {
                 Settings.save("StoredSettings", checkBoxRemember.Checked.ToString(), checkBoxAutoConnect.Checked.ToString(), txtSHost.Text, txtSUser.Text, txtSPass.Text, txtSDatabase.Text);
             }
             else
             {
                 Settings.delete("StoredSettings");
             }
             Utilities.InvokeMe(btnconnect, () =>
             {
                 btnconnect.Text = "Reconnect";
             });
             Utilities.notifyThem(ntfBox3, "Successfully Connected", NotificationBox.Type.Success);
         }
         else
         {
             Utilities.notifyThem(ntfBox3, "Could not connect to the Database", NotificationBox.Type.Error);
         }
     }).Start();
 }
Example #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);
            }
        }
Example #6
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);
            }
        }
Example #7
0
        private void btnPassGenerate_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtPassUser.Text))
            {
                Utilities.notifyThem(ntfForgot, "Empty username", NotificationBox.Type.Error);
                return;
            }
            else if (string.IsNullOrEmpty(txtPassCode.Text))
            {
                Utilities.notifyThem(ntfForgot, "Enter security code", NotificationBox.Type.Error);
                return;
            }
            String username            = txtPassUser.Text;
            String securityCodeCompare = Utilities.MD5Hash(txtPassCode.Text);
            String password            = txtPassPassword.Text;

            if (securityCodeCheck(username, securityCodeCompare))
            {
                newRandomPassword(username, 6);
            }
            else
            {
                Utilities.notifyThem(ntfForgot, "Wrong combination,try again", NotificationBox.Type.Error);
                return;
            }
        }
Example #8
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();
            }
        }
Example #9
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            List <Question> myTest = new List <Question>();

            if (string.IsNullOrWhiteSpace(txtTestTitle.Text))
            {
                Utilities.notifyThem(ntfTest, "No title found", NotificationBox.Type.Warning);
            }
            else if (dgvMyTest.Rows.Count < 1)
            {
                Utilities.notifyThem(ntfTest, "No Questions Found", NotificationBox.Type.Warning);
            }
            else
            {
                foreach (DataGridViewRow row in dgvMyTest.Rows)
                {
                    myTest.Add(Utilities.dgvRowIntoQuestion(row));
                }

                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Filter = "PDF file|*.pdf";
                sfd.Title  = "Save The Test into a PDF file";
                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    SavePDF.SetTest(txtTestTitle.Text, datePicker.Value.ToShortDateString(), myTest, checkBoxAnsweredTest.Checked, sfd.FileName);
                    SavePDF.SaveTest();
                    Utilities.notifyThem(ntfTest, "Successfully Saved", NotificationBox.Type.Success);
                }
            }
        }
Example #10
0
        private void btnAddTest_Click(object sender, EventArgs e)
        {
            btnAddTest.Focus();

            int AddedQ = 0;

            for (int i = 0; i < dgvMyQ.Rows.Count; i++)
            {
                int id = int.Parse(dgvMyQ.Rows[i].Cells[1].Value.ToString());
                if (bool.Parse(dgvMyQ.Rows[i].Cells[0].Value.ToString()) && !Globals.MyTestQids.Contains(id))
                {
                    AddedQ++;
                    string question = dgvMyQ.Rows[i].Cells[2].Value.ToString();
                    string answers  = dgvMyQ.Rows[i].Cells[3].Value.ToString();
                    int    dlevel   = int.Parse(dgvMyQ.Rows[i].Cells[4].Value.ToString());
                    dgvMyTest.Rows.Add("NONE", id, question, answers, dlevel, false);
                    Globals.MyTestQids.Add(id);
                }
            }
            if (AddedQ < 1)
            {
                Utilities.notifyThem(ntfMyQ, "No Questions added", NotificationBox.Type.Warning);
            }
            else
            {
                Utilities.notifyThem(ntfMyQ, AddedQ + " Questions Added to your Test", NotificationBox.Type.Success);
            }
        }
Example #11
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();
            }
        }
Example #12
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);
            }
        }
Example #13
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();
        }
Example #14
0
 private void btnAddAnswer_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(txtAnswer.Text.Trim()))
     {
         Utilities.notifyThem(ntfAdd, "Write your answer first", NotificationBox.Type.Warning);
     }
     else
     {
         dgvAnswerlist.Rows.Add(txtAnswer.Text.TrimEnd().TrimStart(), switchCorrectAnswer.isOn);
         txtAnswer.Text = "";
     }
 }
Example #15
0
        private void btnReset_Click(object sender, EventArgs e)
        {
            for (int i = (dgvAnswerlist.Rows.Count - 1); i >= 0; i--)
            {
                dgvAnswerlist.Rows.RemoveAt(i);
            }

            Utilities.clearText(txtAddQ, txtAddTags, txtAnswer);
            difficultyLvl.Value      = 1;
            switchPrivate.isOn       = false;
            switchCorrectAnswer.isOn = true;
            Utilities.notifyThem(ntfAdd, "Cleared Question info", NotificationBox.Type.Other);
        }
Example #16
0
        private void btnClear_Click(object sender, EventArgs e)
        {
            for (int i = (dgvFoundQ.Rows.Count - 1); i >= 0; i--)
            {
                dgvFoundQ.Rows.RemoveAt(i);
            }

            txtTags.Text       = "";
            switchAllTags.isOn = false;
            switchFindAll.isOn = true;
            numericMin.Value   = 1;
            numericMax.Value   = 5;
            Utilities.notifyThem(ntbfindQ, "Cleared Search result and settings", NotificationBox.Type.Other);
        }
Example #17
0
        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var msgbResult = MessageBox.Show("Are you sure that you want to\nPermanatly delete the highlighted Question ?", "Delete Question", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (msgbResult == DialogResult.Yes)
            {
                int sid = int.Parse(dgvMyQ.SelectedRows[0].Cells[1].Value.ToString());
                Utilities.runInThread(() =>
                {
                    Utilities.AsyncDB().nQuery("DELETE FROM questions WHERE id = " + sid);
                    Utilities.AsyncDB().nQuery("DELETE FROM tags WHERE qid = " + sid);
                }).Start();
                dgvMyQ.Rows.Remove(dgvMyQ.SelectedRows[0]);
                pnumQ.Text = dgvMyQ.Rows.Count.ToString();
                Utilities.notifyThem(ntfMyQ, "Successfully Deleted !", NotificationBox.Type.Success);
            }
        }
Example #18
0
        private void btnDeleteSelected_Click(object sender, EventArgs e)
        {
            btnDeleteSelected.Focus();
            string     idsForDelete = "";
            List <int> cids         = new List <int>();

            for (int i = 0; i < dgvMyQ.Rows.Count; i++)
            {
                if (bool.Parse(dgvMyQ.Rows[i].Cells[0].Value.ToString()))
                {
                    cids.Add(i);
                    idsForDelete += dgvMyQ.Rows[i].Cells[1].Value.ToString() + ",";
                }
            }
            if (cids.Count > 0)
            {
                var msgbResult = MessageBox.Show("Are you sure that you want to\nPermanatly delete the selected Questions ?", "Delete Question", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (msgbResult == DialogResult.Yes)
                {
                    for (int k = (cids.Count - 1); k >= 0; k--)
                    {
                        dgvMyQ.Rows.RemoveAt(int.Parse(cids[k].ToString()));
                    }
                    idsForDelete = idsForDelete.TrimEnd(',');
                    Utilities.runInThread(() =>
                    {
                        Utilities.AsyncDB().nQuery("DELETE FROM questions WHERE id IN (" + idsForDelete + ")");
                        Utilities.AsyncDB().nQuery("DELETE FROM tags WHERE qid IN (" + idsForDelete + ")");
                        Utilities.notifyThem(ntfMyQ, "Successfully Deleted " + cids.Count + " Questions !", NotificationBox.Type.Success);
                    }).Start();
                    pnumQ.Text = dgvMyQ.Rows.Count.ToString();
                }
            }
            else
            {
                Utilities.notifyThem(ntfMyQ, "You didn't select any questions", NotificationBox.Type.Warning);
            }
        }
Example #19
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtTags.Text))
            {
                Utilities.notifyThem(ntbfindQ, "You must add some tags first", NotificationBox.Type.Error);
            }
            else
            {
                Utilities.runInThread(() =>
                {
                    DB TempDB       = Utilities.AsyncDB(true);
                    string[] tags   = txtTags.Text.TrimEnd(',').Split(',');
                    string conQuery = "";
                    for (int i = 0; i < tags.Length; i++)
                    {
                        conQuery += "@" + i + ",";
                    }

                    string fromall = "";
                    if (switchFindAll.isOn)
                    {
                        fromall = "(prive = 0 and uid != " + Globals.logUser.id + ") or ";
                    }

                    DataTable dt = new DataTable();

                    TempDB.qBind(tags);
                    if (!switchAllTags.isOn)
                    {
                        dt = TempDB.query("select * from questions where (" + fromall + "uid = " + Globals.logUser.id + ") and dlevel >= " + numericMin.Value + " and dlevel <= " + numericMax.Value + " and id in(select distinct qid from tags where nametag in (" + conQuery.TrimEnd(',') + "));");
                    }
                    else
                    {
                        dt = TempDB.query("SELECT * FROM  `questions` WHERE (" + fromall + "uid = " + Globals.logUser.id + ") and dlevel >= " + numericMin.Value + " and dlevel <= " + numericMax.Value + " and id IN (SELECT qid FROM  `tags` WHERE nametag IN (SELECT nametag FROM tags WHERE nametag IN (" + conQuery.TrimEnd(',') + ")) GROUP BY qid HAVING COUNT( qid ) = " + tags.Length + ")");
                    }

                    for (int i = 0; i < dt.Columns.Count; i++)
                    {
                        dt.Columns[i].ReadOnly = true;
                    }

                    Utilities.InvokeMe(dgvFoundQ, () =>
                    {
                        dgvFoundQ.DataSource            = dt;
                        dgvFoundQ.Columns[0].Visible    = true;
                        dgvFoundQ.Columns[0].Width      = 50;
                        dgvFoundQ.Columns[1].Visible    = false;
                        dgvFoundQ.Columns[2].HeaderText = "Questions";
                        dgvFoundQ.Columns[2].SortMode   = DataGridViewColumnSortMode.NotSortable;
                        dgvFoundQ.Columns[2].Width      = 390;
                        dgvFoundQ.Columns[3].Visible    = false;
                        dgvFoundQ.Columns[4].HeaderText = "Difficulty";
                        dgvFoundQ.Columns[4].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                        dgvFoundQ.Columns[4].SortMode = DataGridViewColumnSortMode.NotSortable;
                        dgvFoundQ.Columns[4].Width    = 80;
                        dgvFoundQ.Columns[5].Visible  = false;
                        dgvFoundQ.Columns[6].Visible  = false;
                        for (int i = 0; i < dgvFoundQ.Rows.Count; i++)
                        {
                            dgvFoundQ.Rows[i].Cells[0].Value = "False";
                        }
                    });

                    if (dt.Rows.Count < 1)
                    {
                        DataTable da = new DataTable();
                        Utilities.InvokeMe(dgvFoundQ, () =>
                        {
                            dgvFoundQ.DataSource         = da;
                            dgvFoundQ.Columns[0].Visible = false;
                        });
                    }

                    Utilities.notifyThem(ntbfindQ, "Found " + dt.Rows.Count + " Questions", NotificationBox.Type.Notice);
                }).Start();
            }
        }