private void SendMessageButton_Click(object sender, EventArgs e) { if (selectedUser == null) { MessageBox.Show("Вы не выбрали получателя"); return; } ForumContainer Scontainer = new ForumContainer(); var converstation = new ConversationSet() { SenderId = Client.AccountId, RecipientId = selectedUser.AccountId, AccountSet_Recipient = Scontainer.AccountSet.SingleOrDefault(x => x.AccountId == selectedUser.AccountId), AccountSet_Sender = Scontainer.AccountSet.SingleOrDefault(x => x.AccountId == Client.AccountId) }; void handlerClickerChat(object SenderK, EventArgs args) { MessageSendForm messageForm = new MessageSendForm(Client, converstation.AccountSet_Recipient); messageForm.Show(); }; Scontainer.ConversationSet.Add(converstation); Scontainer.SaveChanges(); Chat.Chat newChat = new Chat.Chat(converstation.AccountSet_Recipient.Login, handlerClickerChat); // с кем беседа pmFlowLoyoutPanel.Controls.Add(newChat); if (Message.Text != string.Empty || Message.Text.Length < 5) { MessageSet message = new MessageSet() { Date = DateTime.Now, MessageText = Message.Text, ConversationId = converstation.ConversationId, SenderId = Client.AccountId }; Scontainer.MessageSet.Add(message); Scontainer.SaveChanges(); Message.Text = ""; // this code post query in server and get await } else { MessageBox.Show("Вы не ввели сообщение, либо оно слишком короткое!"); return; } Close(); }
private void LoadTheoryControl() { ClearPanels(); var isNowTheory = Theories.FirstOrDefault(x => x.Position == CurrentPosition); if (isNowTheory == null) { var isNowQuestion = Questions.FirstOrDefault(x => x.Position == CurrentPosition); if (isNowQuestion == null) { // Пользователь завершил урок. Возвращаем его на панель Training! // В бд отмечаем, что последний урок который он прошел, следующий по Position от этого LessonSet using (ForumContainer container = new ForumContainer()) { int NextPosition = Lesson.Position + 1; // Получаем следующий урок var nextLesson = container.LessonSet.FirstOrDefault(x => x.TrainingId == Lesson.TrainingId && x.Position == NextPosition); if (nextLesson == null) { var training = container.TrainingProgressSet.FirstOrDefault(x => x.TrainingId == Lesson.TrainingId); container.TrainingProgressSet.Remove(training); MessageBox.Show("Вы успешно прошли данное обучение!"); container.SaveChanges(); var tPlane = (Training)Parent; tPlane.Completed(); Dispose(); return; } // Обновляем строку в LessonProgress var nextProgress = container.TrainingProgressSet.FirstOrDefault(x => x.LessonId == Lesson.LessonId); nextProgress.LessonId = nextLesson.LessonId; container.SaveChanges(); } var TrainingPanel = (Training)Parent; TrainingPanel.UpdateTrainingPanel(); Dispose(); } else { LoadQuestion(); } } else { LoadTheory(); } }
private void StartTraining_Click(object sender, EventArgs e) { using (ForumContainer container = new ForumContainer()) { var client = container.AccountSet.FirstOrDefault(x => x.AccountId == MainForm.Client.AccountId); if (client.TrainingProgressSet.FirstOrDefault(x => x.TrainingId == Training.TrainingId) != null) { MessageBox.Show("Вы уже начали это обучение. Для того, чтобы продолжить изучение перейдите на главную"); return; } else { var FirstLesson = container.LessonSet.FirstOrDefault(x => x.TrainingId == Training.TrainingId && x.Position == 0); TrainingProgressSet progressSet = new TrainingProgressSet() { AccountId = MainForm.Client.AccountId, LessonId = FirstLesson.LessonId, TrainingId = Training.TrainingId }; container.TrainingProgressSet.Add(progressSet); container.SaveChanges(); } } }
private void MessageBox_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (MessageBox.Text != string.Empty || MessageBox.Text.Length < 5) { using (ForumContainer container = new ForumContainer()) { MessageSet message = new MessageSet() { Date = DateTime.Now, MessageText = MessageBox.Text, ConversationId = FormConversation.ConversationId, SenderId = Recipient.AccountId }; container.MessageSet.Add(message); container.SaveChanges(); AddNewMessageContainer(message); } MessageBox.Text = ""; var change = ContainerPMessage.VerticalScroll.Value + ContainerPMessage.VerticalScroll.SmallChange * 100; ContainerPMessage.AutoScrollPosition = new Point(0, change); // this code post query in server and get await } else { System.Windows.Forms.MessageBox.Show("Вы не ввели сообщение, либо оно слишком короткое!"); return; } } }
private void SaveAllChanges_Click(object sender, EventArgs e) { using (ForumContainer container = new ForumContainer()) { container.AccountSet.SingleOrDefault(x => x.AccountId == Account.AccountId).Email = EmailTextBox.Text.TrimEnd(); container.SaveChanges(); } }
/// <summary> /// /// </summary> /// <param name="message">Текст сообщения</param> /// <param name="AccountId1">Отправитель</param> /// <param name="AccountId2">Получатель</param> /// <returns></returns> public bool Send(string message, int AccountId1, int AccountId2) { using (ForumContainer container = new ForumContainer()) { ConversationSet conversation = container.ConversationSet.SingleOrDefault(x => (x.AccountSet_Recipient.AccountId == AccountId1 && x.AccountSet_Sender.AccountId == AccountId2) || (x.AccountSet_Recipient.AccountId == AccountId2 && x.AccountSet_Sender.AccountId == AccountId1) ); if (conversation == null) { ConversationSet newConversation = new ConversationSet() { RecipientId = AccountId2, SenderId = AccountId1 }; container.ConversationSet.Add(newConversation); container.SaveChanges(); FormConversation = newConversation; } else { FormConversation = conversation; // next code } } if (message != string.Empty || message.Length < 5) { using (ForumContainer container = new ForumContainer()) { MessageSet messageSet = new MessageSet() { Date = DateTime.Now, MessageText = message, ConversationId = FormConversation.ConversationId, SenderId = AccountId2 }; container.MessageSet.Add(messageSet); container.SaveChanges(); } // this code post query in server and get await return(true); } else { errorMessage = "Вы не ввели сообщение, либо оно слишком короткое!"; return(false); } }
private void CloseTheme_Click(object sender, EventArgs e) { using (ForumContainer container = new ForumContainer()) { container.ThemeSet.FirstOrDefault(x => x.ThemeId == Theme.ThemeId).Visible = false; container.SaveChanges(); MessageBox.Show("Тема была успешно скрыта"); ThemeRedactorSessionForm.UpdateForm(); Close(); } }
private void SaveTheme_Click(object sender, EventArgs e) { using (ForumContainer container = new ForumContainer()) { var ourtheme = container.ThemeSet.FirstOrDefault(x => x.ThemeId == Theme.ThemeId); ourtheme.ThemeName = ThemeName.Text; ourtheme.ThemeText = ThemeText.Text; container.SaveChanges(); MessageBox.Show("Тема была успешно сохранена"); ThemeRedactorSessionForm.UpdateForm(); Close(); } }
/// <summary> /// /// </summary> /// <param name="keyValuePairs">Значения тип вопроса</param> /// <param name="questionVariable">Ответы на вопросы</param> /// <param name="langId">Айди языка</param> /// <param name="typeId">Айди типа</param> /// <returns></returns> public bool NewQuestion(Dictionary <StringTypeQuestion, string> keyValuePairs, List <string> questionVariable, int LangId, int correctOtvet) { using (ForumContainer container = new ForumContainer()) { int langId = LangId; int questTypeId = Convert.ToInt32(keyValuePairs[StringTypeQuestion.QuestionType]); QuestionSet setQuest = new QuestionSet() { QuestionText = keyValuePairs[StringTypeQuestion.QuestionText], CorrectOption = correctOtvet, LanguageLanguageId = langId, QuestionTypeQuestionTypeId = questTypeId, AccountAccountId = 0, AccountSet = container.AccountSet.Single(x => x.Login == "admin"), QuestionTypeSet = container.QuestionTypeSet.Single(x => x.QuestionTypeId == questTypeId), LanguageSet = container.LanguageSet.Single(x => x.LanguageId == langId), }; container.QuestionSet.Add(setQuest); for (int i = 0; i < 4; i++) { AnswerSet secAnswer = new AnswerSet() { AnswerVarible = questionVariable[i], QuestionSet = setQuest }; container.AnswerSet.Add(secAnswer); container.SaveChanges(); } container.SaveChanges(); } return(true); }
private void SaveChanges_Click(object sender, EventArgs e) { if (OldPasswordTextBox.Text.TrimEnd() == Account.Password.TrimEnd()) { using (ForumContainer container = new ForumContainer()) { container.AccountSet.SingleOrDefault(x => x.AccountId == Account.AccountId).Password = NewPasswordTextBox.Text.TrimEnd(); container.SaveChanges(); } MessageBox.Show("Пароль был изменён."); return; } else { MessageBox.Show("Пароль не был изменён, потому что вы ввели неверный старый пароль. Повторите попытку."); return; } }
/// <summary> /// init = Получатель, send = Отправитель /// </summary> /// <param name="init">Получатель</param> /// <param name="send">Отправитель</param> private void GetMessages(AccountSet init, AccountSet send) { using (ForumContainer container = new ForumContainer()) { ConversationSet conversation = container.ConversationSet.SingleOrDefault(x => (x.AccountSet_Recipient.AccountId == init.AccountId && x.AccountSet_Sender.AccountId == send.AccountId) || (x.AccountSet_Recipient.AccountId == send.AccountId && x.AccountSet_Sender.AccountId == init.AccountId) ); if (conversation == null) { ConversationSet newConversation = new ConversationSet() { RecipientId = init.AccountId, SenderId = send.AccountId }; FormConversation = newConversation; container.ConversationSet.Add(newConversation); container.SaveChanges(); return; } else { FormConversation = conversation; var MessageList = container.MessageSet.Where(x => x.ConversationSet.ConversationId == FormConversation.ConversationId).ToList(); if (MessageList.Count > 0) { foreach (MessageSet message in MessageList) { AddNewMessageContainer(message); } } return; } } }
private void SendOnDatebaseButton_Click(object sender, EventArgs e) { if (ThemeName.Text == string.Empty) { MessageBox.Show("Имя темы не может быть пустым."); return; } if (ThemeText.Text.Length < 25) { MessageBox.Show("Текст темы не может быть менее, чем 25 символов."); return; } if (Author.AccountType == 0) { if (Author.Reputation < 25 || Author.Reputation == 0) { MessageBox.Show("Вы не можете отправлять заявки на темы. Вам не хватает репутации."); return; } } using (ForumContainer container = new ForumContainer()) { ThemeSet newTheme = new ThemeSet() { AuthorId = Author.AccountId, ThemeName = ThemeName.Text, ThemeText = ThemeText.Text, ThemePoints = 0, CreateDate = DateTime.Now, Visible = false }; container.ThemeSet.Add(newTheme); container.SaveChanges(); MessageBox.Show("Тема была успешно отправлена на редакцию"); } }
private void SaveChanges_Click(object sender, EventArgs e) { if (Controls.OfType <QuestionType0>().FirstOrDefault() == null) { return; } //if(QuestionSet.QuestionTypeQuestionTypeId == 0) var answerVariable0 = Controls.OfType <QuestionType0>().First(). Controls.OfType <TextBox>().ToList() .FirstOrDefault(x => x.Name == "textBox1"); var answerVariable1 = Controls.OfType <QuestionType0>().First(). Controls.OfType <TextBox>().ToList() .FirstOrDefault(x => x.Name == "textBox2"); var answerVariable2 = Controls.OfType <QuestionType0>().First(). Controls.OfType <TextBox>().ToList() .FirstOrDefault(x => x.Name == "textBox3"); var answerVariable3 = Controls.OfType <QuestionType0>().First(). Controls.OfType <TextBox>().ToList() .FirstOrDefault(x => x.Name == "textBox4"); using (ForumContainer container = new ForumContainer()) { var quest = container.QuestionSet.FirstOrDefault(x => x.QuestionId == QuestionSet.QuestionId); var answers = container.AnswerSet.Where(x => x.QuestionQuestionId == quest.QuestionId).ToList(); answers[0].AnswerVarible = answerVariable0.Text; answers[1].AnswerVarible = answerVariable1.Text; answers[2].AnswerVarible = answerVariable2.Text; answers[3].AnswerVarible = answerVariable3.Text; container.SaveChanges(); } }
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; } } } } }
private void RegistrationButton_Click(object sender, EventArgs e) { if (Login.Text == string.Empty) { MessageBox.Show("Вы оставили поле Логин пустым"); return; } if (EmailTextBox.Text == string.Empty) { MessageBox.Show("Вы оставили поле Почта пустым"); return; } if (TelephoneNumber.Text == string.Empty) { MessageBox.Show("Вы оставили поле Телефон пустым"); return; } if (Password.Text == string.Empty) { MessageBox.Show("Вы оставили поле Пароль пустым"); return; } if (UserName.Text == string.Empty) { MessageBox.Show("Вы оставили поле Имя пустым"); return; } using (ForumContainer container = new ForumContainer()) { if (container.AccountSet.SingleOrDefault(x => x.Login == Login.Text) != null) { MessageBox.Show("Данный логин уже занят. Выберите другой логин для входа на форум."); return; } if (container.AccountSet.SingleOrDefault(x => x.Email == EmailTextBox.Text) != null) { MessageBox.Show("Данный емайл уже занят. Выберите другой емайл."); return; } if (container.AccountSet.SingleOrDefault(x => x.PhoneNumber == TelephoneNumber.Text) != null) { MessageBox.Show("Данный телефонный номер уже занят. Выберите другой телефонный номер."); return; } if (Password.Text.Equals(RePassword.Text)) { AccountSet newAccount = new AccountSet() { Login = Login.Text, PhoneNumber = TelephoneNumber.Text, Email = EmailTextBox.Text, Password = HashPassword(Password.Text), Name = UserName.Text, UserName = UserName.Text, AccountType = 0, CreateDate = DateTime.Now, Points = 0, Reputation = 0 }; container.AccountSet.Add(newAccount); container.SaveChanges(); MessageBox.Show("Аккаунт был успешно создан!"); } else { MessageBox.Show("Повторите попытку. Вы ввели не одинаковый пароль."); return; } } }
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(); } } } }