Esempio n. 1
0
        private void SaveChanges_Click(object sender, EventArgs e)
        {
            List <Control> controlsList = new List <Control>();

            controlsList.Add(new Control());
            controlsList.Add(new Control());


            foreach (Control ctrl in VisibleTheory.Controls)
            {
                if (ctrl is Scintilla)
                {
                    controlsList[0] = ctrl;
                }
                else if (ctrl is TextBox)
                {
                    controlsList[1] = ctrl;
                }
                else
                {
                    continue;
                }
            }

            if (UpdateState)
            {
                using (ForumContainer container = new ForumContainer())
                {
                    foreach (var control in controlsList)
                    {
                        if (control is Scintilla)
                        {
                            Scintilla sc = (Scintilla)control;

                            if (sc.Text.Length == 0)
                            {
                                MessageBox.Show("Вы добавили элемент \"Код\", но не ввели никаких данных.");
                                return;
                            }

                            byte[] result = Encoding.UTF8.GetBytes(sc.Text);
                            var    code   = container.CodeSet.First(x => x.CodeId == updateCodeId);

                            code.CodeFileName   = sc.Name + getIdObject();
                            code.BinaryFileData = result;
                            container.SaveChanges();

                            CodeId = code.CodeId;
                        }
                        else if (control is TextBox)
                        {
                            TextBox         tb        = (TextBox)control;
                            TheoryLessonSet lessonSet = new TheoryLessonSet()
                            {
                                CodeId     = CodeId == -1 ? 1011 : CodeId,
                                TheoryText = tb.Text
                            };

                            TheoryControl.TheoryLessonSet = lessonSet;
                            Close();
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
            }
            else
            {
                using (ForumContainer container = new ForumContainer())
                {
                    foreach (var control in controlsList)
                    {
                        if (control is Scintilla)
                        {
                            Scintilla sc = (Scintilla)control;

                            if (sc.Text.Length == 0)
                            {
                                MessageBox.Show("Вы добавили элемент \"Код\", но не ввели никаких данных.");
                                return;
                            }

                            byte[] result = Encoding.UTF8.GetBytes(sc.Text);

                            CodeSet code = new CodeSet()
                            {
                                CodeFileName   = sc.Name + getIdObject(),
                                BinaryFileData = result
                            };

                            container.CodeSet.Add(code);
                            container.SaveChanges();
                            CodeId = code.CodeId;
                        }
                        else if (control is TextBox)
                        {
                            TextBox         tb        = (TextBox)control;
                            TheoryLessonSet lessonSet = new TheoryLessonSet()
                            {
                                CodeId     = CodeId == -1 ? 1011 : CodeId,
                                TheoryText = tb.Text
                            };

                            TheoryControl.TheoryLessonSet = lessonSet;
                            Close();
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        private void AddTrainingToDb_Click(object sender, EventArgs e)
        {
            SaveTraining saveTraining = new SaveTraining();

            saveTraining.ShowDialog();

            if (saveTraining.TrainingName == "")
            {
                return;
            }

            using (ForumContainer container = new ForumContainer())
            {
                TrainingSet training = new TrainingSet()
                {
                    AuthorId           = MainForm.Client.AccountId,
                    TrainingName       = saveTraining.TrainingName,
                    TrainingDescrition = saveTraining.TrainingDescription,
                    LanguageId         = Language.LanguageId
                };

                container.TrainingSet.Add(training);
                container.SaveChanges();

                foreach (var Lesson in TestTrainingPanel.Controls)
                {
                    var       CurrentLesson = (LessonControl)Lesson;
                    LessonSet lesson        = new LessonSet()
                    {
                        TrainingId = training.TrainingId,
                        Color      = ColorTranslator.ToOle(CurrentLesson.ControlColor),
                        Picture    = ImageToByteArray(CurrentLesson.Picture),
                        LessonName = CurrentLesson.LessName,
                        LessonText = "??",
                        Position   = CurrentLesson.Position,
                        Shape      = 0,
                    };
                    container.LessonSet.Add(lesson);
                    container.SaveChanges();

                    foreach (var theory in CurrentLesson.Theories)
                    {
                        TheoryLessonSet theoryLesson = new TheoryLessonSet()
                        {
                            LessonId   = lesson.LessonId,
                            Position   = theory.Position,
                            TheoryId   = theory.TheoryLessonSet.TheoryId,
                            TheoryText = theory.TheoryLessonSet.TheoryText,
                            CodeId     = theory.TheoryLessonSet.CodeId
                        };

                        container.TheoryLessonSet.Add(theoryLesson);
                        container.SaveChanges();
                    }

                    foreach (var quest in CurrentLesson.Questions)
                    {
                        QuestionListLessonSet questionListLesson = new QuestionListLessonSet()
                        {
                            LessonId   = lesson.LessonId,
                            Position   = quest.Position,
                            QuestionId = quest.QuestionSet.QuestionId
                        };

                        container.QuestionListLessonSet.Add(questionListLesson);
                        container.SaveChanges();
                    }
                }
            }
        }