private void btnAdd_Click(object sender, EventArgs e) { if (sbj == null) { sbj = new Subject(); } sbj.ID = txtSubjectId.Text; sbj.Name = txtNameSubject.Text; if (!this.newSubject && subjectController.UpdateSubject(sbj)) { MetroMessageBox.Show(this, "Cập nhật thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); success = true; this.Close(); return; } else { if (subjectController.AddSubject(sbj)) { MetroMessageBox.Show(this, "Thêm mới thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); success = true; this.Close(); return; } } MaterialSkin.Controls.MaterialMessageBox.Show("Cập nhật thất bại"); this.Close(); return; }
private void btnSave_Click(object sender, EventArgs e) { try { bool isvalidated = validatefields(); if (isvalidated) { Subject subject = new Subject(); subject.offeredyear = comboOfferedyear.SelectedItem.ToString(); subject.lecturehours = Convert.ToInt32(numericLhrs.Value); subject.offeredsemester = rdbSemester1.Checked ? 1 : 2; subject.tutorialhours = Convert.ToInt32(numericThrs.Value); subject.subjectname = txtSubjectname.Text; subject.labhours = Convert.ToInt32(numericLabhrs.Value); subject.subjectcode = txtSubjectcode.Text; subject.evoluationhours = Convert.ToInt32(numericEhrs.Value); string message = SubjectController.AddSubject(subject); MessageBox.Show(message); clear(); } else { MessageBox.Show("please fill in all fields!"); } } catch (NullReferenceException nre) { MessageBox.Show("please fill in all fields!"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void buttonAddSubject_Click(object sender, EventArgs e) { SubjectModel subject = new SubjectModel(this.textBoxSubjectName.Text, this.pictureBoxSubjectImage.Image); SubjectController controller = new SubjectController(); if (controller.AddSubject(subject)) { MessageBox.Show("New subject added"); } else { MessageBox.Show("An error has occured while executing the database operation"); } }
private void AddSubject_Button_Click(object sender, RoutedEventArgs e) { var subjectName = this.AddSubjectName_TextBox.Text; var subjectDate = this.AddSubject_Callendar.SelectedDate; var subjectTime = this.AddSubject_TimePicker.SelectedTime; var dateToSend = new DateTime(); try { var date = new DateTime(subjectDate.Value.Year, subjectDate.Value.Month, subjectDate.Value.Day, subjectTime.Value.Hour, subjectTime.Value.Minute, subjectTime.Value.Second); dateToSend = date; } catch (Exception) { MessageBox.Show("Prosze podac poprawne dane."); } Subjects subject = new Subjects() { subjectName = subjectName, subjectTime = dateToSend }; SubjectController controller = new SubjectController(); if (controller.SubjectValidation(subject)) { controller.AddSubject(subject); MessageBox.Show("Pomyślne dodanie przedmiotu."); AddSubjectName_TextBox.Text = ""; } DataGridController gridController = new DataGridController(TimeTable_DataGrid); gridController.SetDataSourceForSubjects(); }
private void btnAddSubject_Click(object sender, EventArgs e) { if (index != 0) { return; } if (SubjectController.CheckSubject(this.cbSubject.Text) == true) { return; } if (add == true) { Subject s = new Subject(); s.id = ID; s.subject = this.cbSubject.Text.Trim(); SubjectController.AddSubject(s); ID++; this.cbSubject.Items.Add(this.cbSubject.Text.Trim()); } this.btnAddSubject.Enabled = false; }