private void cmbSubjects_SelectedIndexChanged(object sender, EventArgs e) { string gradeText = ""; string subjectText = ""; if (!string.IsNullOrEmpty(cmbGrades.Text) && !string.IsNullOrEmpty(cmbSubjects.Text)) { LessonPlannerRepository lessonPlannerRepository = new LessonPlannerRepository(); long maxMainTopic = lessonPlannerRepository.GetMaxMainTopic(Convert.ToInt64(cmbGrades.SelectedValue), Convert.ToInt64(cmbSubjects.SelectedValue)) + 1; string maxmainTopic = maxMainTopic < 10 ? "0" + maxMainTopic : maxMainTopic.ToString(); gradeText = cmbGrades.Text; subjectText = cmbSubjects.Text; string mainTopicNumber = gradeText + subjectText.Substring(0, 1) + maxmainTopic; txtMainTopic.Text = mainTopicNumber; btnAddSubTopic.Enabled = true; //MainTopicNumberGlobal = txtMainTopic.Text; } else { txtMainTopic.Text = ""; } if (pnlSubTopic.Visible) { SetSubTopicValues(); } }
private void BindGridViewViewSubTopicsByMainTopicID(long mainTopicID) { LessonPlannerRepository lessonPlannerRepository = new LessonPlannerRepository(); List <SubTopicModel> subTopicModels = new List <SubTopicModel>(); DataTable dataTable = new DataTable(); try { dataTable = lessonPlannerRepository.GetAllSubTopicByMainTopicID(mainTopicID); subTopicModels = TranslateDataTableToSubTopicsModel(dataTable); } catch (Exception ex) { MessageBox.Show("Network error...Please try again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { dataTable.Clear(); dataTable = null; dataGridViewViewSubTopics.DataSource = subTopicModels; } if (subTopicModels != null && subTopicModels.Count() > 0) { AddGridButtons(); } }
private void btnSave_Click(object sender, EventArgs e) { LessonPlanner lessonPlanner = new LessonPlanner(); if (lblSubTopicID.Text == "0") //ADD { SubTopicModel subTopicModel = new SubTopicModel(); subTopicModel.MainTopicID = _mainTopicID; subTopicModel.MainTopicNumber = txtMainTopic.Text; subTopicModel.SubTopicNumber = txtSubTopicNo.Text; subTopicModel.SubTopicTitle = txtTitleSubTopic.Text; subTopicModel.Material = txtMaterial.Text; subTopicModel.CreatedOn = DateTime.Now; subTopicModel.CreatedBy = 1; subTopicModel.ModifiedOn = DateTime.Now; subTopicModel.ModifiedBy = 1; LessonPlanner.subTopicModelsListGlobal.Add(subTopicModel); if (LessonPlanner.subTopicModelsListGlobal != null && LessonPlanner.subTopicModelsListGlobal.Count() > 0) { LessonPlanner lesson = (LessonPlanner)Application.OpenForms["LessonPlanner"]; if (lesson != null) { //int subTopicMaterialAdded = LessonPlanner.subTopicModelsListGlobal.Where(x => !string.IsNullOrEmpty(x.Material)).Count(); //if (subTopicMaterialAdded > 0) //{ //} lesson.txtMaterial.Text = ""; } } } else //EDIT { SubTopicModel subTopicModel = new SubTopicModel(); //subTopicModel.MainTopicID = Convert.ToInt64(); subTopicModel.SubTopicID = Convert.ToInt64(lblSubTopicID.Text); subTopicModel.MainTopicNumber = txtMainTopic.Text; subTopicModel.SubTopicNumber = txtSubTopicNo.Text; subTopicModel.SubTopicTitle = txtTitleSubTopic.Text; subTopicModel.Material = txtMaterial.Text; subTopicModel.ModifiedOn = DateTime.Now; subTopicModel.ModifiedBy = 1; LessonPlannerRepository lessonPlannerRepository = new LessonPlannerRepository(); long result = lessonPlannerRepository.EditSubTopic(subTopicModel); if (result > 0) { ShowStatus(true, "ADD"); } //SaveToDB } this.Close(); }
private void BindGridViewLessonPlannerByGradeIDAndSubjectID(long gradeID, long subjecID) { LessonPlannerRepository lessonPlannerRepository = new LessonPlannerRepository(); List <LessonPlannerModel> lessonPlannerModels = lessonPlannerRepository.GetAllLessonPlannersByGradeIDandSubjectID(gradeID, subjecID); dataGridViewLessonPlanner.DataSource = lessonPlannerModels; if (lessonPlannerModels != null && lessonPlannerModels.Count() > 0) { AddGridButtons(); } }
private void dataGridViewViewSubTopics_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex == dataGridViewViewSubTopics.NewRowIndex || e.RowIndex < 0) { return; } if (e.ColumnIndex == dataGridViewViewSubTopics.Columns["Edit"].Index) { var data = (SubTopicModel)dataGridViewViewSubTopics.Rows[e.RowIndex].DataBoundItem; SubTopic subTopic = new SubTopic(data); subTopic.lblSubTopicID.Text = Convert.ToString(data.SubTopicID); subTopic.txtMainTopic.Text = data.MainTopicNumber; subTopic.txtSubTopicNo.Text = data.SubTopicNumber; subTopic.txtTitleSubTopic.Text = data.SubTopicTitle; subTopic.txtMaterial.Text = data.Material; subTopic.Show(); this.Close(); } else if (e.ColumnIndex == dataGridViewViewSubTopics.Columns["Quizzes"].Index) { long subTopicID = Convert.ToInt64(dataGridViewViewSubTopics.Rows[e.RowIndex].Cells["SubTopicID"].Value); if (subTopicID > 0) { SubTopicQuizMakerIndex quizMakerIndex = new SubTopicQuizMakerIndex(Convert.ToInt64(subTopicID)); quizMakerIndex.Show(); } } else if (e.ColumnIndex == dataGridViewViewSubTopics.Columns["Delete"].Index) { long rowCount = 0; long subTopicID = Convert.ToInt64(dataGridViewViewSubTopics.Rows[e.RowIndex].Cells["SubTopicID"].Value); LessonPlannerRepository lessonPlannerRepository = new LessonPlannerRepository(); rowCount = lessonPlannerRepository.DeleteSubTopic(subTopicID); if (rowCount > 0) { ShowStatus(true, "DELETE"); dataGridViewViewSubTopics.DataSource = null; dataGridViewViewSubTopics.Rows.Clear(); dataGridViewViewSubTopics.Columns.Clear(); BindGridViewViewSubTopicsByMainTopicID(_mainTopicID); } } }
private void dataGridViewMovies_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == dataGridViewMovies.Columns["Delete"].Index) { int rowCount = 0; long gameID = Convert.ToInt64(dataGridViewMovies.Rows[e.RowIndex].Cells["MovieID"].Value); LessonPlannerRepository lessonPlannerRepository = new LessonPlannerRepository(); rowCount = lessonPlannerRepository.DeleteMovieByID(gameID); if (rowCount > 0) { ShowStatus(true, "DELETE"); BindGridViewMovies(); } } }
private void BindGridViewBooks() { LessonPlannerRepository lessonPlannerRepository = new LessonPlannerRepository(); List <BooksModel> booksModels = new List <BooksModel>(); DataTable dataTable = new DataTable(); try { dataTable = lessonPlannerRepository.GetAllBooks(); booksModels = TranslateDataTableToBooksModel(dataTable); } catch (Exception ex) { MessageBox.Show("Network error...Please try again!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { dataTable.Clear(); dataTable = null; dataGridViewBooks.DataSource = booksModels; } }
private void btnSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(cmbGrades.Text)) { MessageBox.Show("Grade can't be blank!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (string.IsNullOrEmpty(cmbSubjects.Text)) { MessageBox.Show("Subject can't be blank!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (string.IsNullOrEmpty(txtTitleMainTopic.Text)) { MessageBox.Show("Title main topic can't be blank!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if ((subTopicModelsListGlobal == null || subTopicModelsListGlobal.Count == 0) && txtMaterial.Text == string.Empty) { MessageBox.Show("Main topic's material can't be blank!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { LessonPlannerModel lessonPlannerModel = new LessonPlannerModel(); lessonPlannerModel.LessonPlannerID = Convert.ToInt32(lblLessonPlannerID.Text); lessonPlannerModel.MainTopicID = Convert.ToInt32(lblMainTopicID.Text); lessonPlannerModel.GradeID = Convert.ToInt64(cmbGrades.SelectedValue); lessonPlannerModel.SubjectID = Convert.ToInt64(cmbSubjects.SelectedValue); lessonPlannerModel.MainTopicNumber = txtMainTopic.Text; lessonPlannerModel.TitleMainTopic = txtTitleMainTopic.Text; lessonPlannerModel.Introduction = txtIntroduction.Text; lessonPlannerModel.Objectives = txtObjectives.Text; lessonPlannerModel.Material = txtMaterial.Text; lessonPlannerModel.CreatedOn = DateTime.Now; lessonPlannerModel.CreatedBy = 1; // It will be added from users lessonPlannerModel.ModifiedOn = DateTime.Now; lessonPlannerModel.ModifiedBy = 1; // It will be added from users lessonPlannerModel.subTopicModels = subTopicModelsListGlobal; lessonPlannerModel.gamesModels = gamesModelsListGlobal; lessonPlannerModel.moviesModels = moviesModelsListGlobal; lessonPlannerModel.documentariesModels = documentariesModelsListGlobal; lessonPlannerModel.booksModels = booksModelsListGlobal; try { LessonPlannerRepository lessonPlannerRepository = new LessonPlannerRepository(); long result = lessonPlannerRepository.SaveUpdateLessonPlanner(lessonPlannerModel); if (result > 0) { ShowStatus(true, "ADD"); } else { ShowStatus(false, string.Empty); } lessonPlannerModel.subTopicModels = new List <SubTopicModel>(); lessonPlannerModel.gamesModels = new List <GamesModel>(); lessonPlannerModel.moviesModels = new List <MoviesModel>(); lessonPlannerModel.documentariesModels = new List <DocumentariesModel>(); lessonPlannerModel.booksModels = new List <BooksModel>(); subTopicModelsListGlobal = new List <SubTopicModel>(); gamesModelsListGlobal = new List <GamesModel>(); moviesModelsListGlobal = new List <MoviesModel>(); documentariesModelsListGlobal = new List <DocumentariesModel>(); booksModelsListGlobal = new List <BooksModel>(); } catch (Exception ex) { ShowStatus(false, string.Empty); } clearSubTopicFields(); } }