コード例 #1
0
 private void ToDownload_Click(object sender, EventArgs e)
 {
     if (path != "")
     {
         try
         {
             string[] DataFile  = File.ReadAllLines(path);
             string   TestName  = DataFile[0].Trim();
             string   TestTimer = DataFile[DataFile.Length - 1].Trim();
             methods.AddToBD("INSERT INTO tests (`testname`, `testtimer`) VALUES (@testname, @testtimer)", TestName, TestTimer);
             string TestID = methods.GetValue("SELECT id FROM `tests` WHERE testname = '" + TestName + "'");
             for (int i = 1; i < DataFile.Length - 3; i += 3)
             {
                 methods.AddToBD("INSERT INTO questions (`question_name`, `parent_test`) VALUES (@question_name, @parent_test)", DataFile[i], TestID);
                 string QuestionID = methods.GetValue("SELECT id FROM questions WHERE question_name = '" + DataFile[i] + "'");
                 AddAnswersToBD(DataFile[i + 1].Trim().Split('|').ToList(), QuestionID, DataFile[i + 2]);
             }
             DeleteStudents.SetMessaage(label2, "Тест создан!", Color.Green);
         }
         catch
         {
             DeleteStudents.SetMessaage(label2, "Ошибка!", Color.Red);
         }
     }
     else
     {
         DeleteStudents.SetMessaage(label2, "Выберите файл!", Color.Red);
     }
 }
コード例 #2
0
        private void registration_Click(object sender, EventArgs e)
        {
            DB method = new DB();

            if (RichBox.Text != "")
            {
                List <string> RichBoxData = ListFormation();
                // RichBoxData[0] - userclass;
                // RichboxData[2 * n] - username, where  1 <= n <= RichBoxData.Count - 2;
                // RichboxData[2 * n + 1] - password, where 0 <= n <= RichBoxData.Count - 1.
                try
                {
                    for (int i = 1; i < RichBoxData.Count - 1; i += 2)
                    {
                        method.AddToBD("INSERT INTO students (`username`, `password`, `userclass`) VALUES (@username, @password, @userclass)",
                                       RichBoxData[i], RichBoxData[i + 1], RichBoxData[0].Trim());
                    }
                    DeleteStudents.SetMessaage(label1, "Успешно зарегестрированы!", Color.Green);
                }
                catch
                {
                    DeleteStudents.SetMessaage(label1, "Ошибка!", Color.Red);
                }
            }
        }