private void PopulateListItems() { containerFlowPanel.Controls.Clear(); if (ExamPaper == null || ExamPaper.GetPapers.Count == 0) { containerFlowPanel.Controls.Add(emptyListLabel); emptyListLabel.Visible = true; return; } for (int i = 0; i < ExamPaper.GetPapers.Count; i++) { PaperDataListItem paperDataListItem = PaperDataListItem.Create(ExamPaper.GetPapers[i]); paperDataListItem.OnControlButtonPressedEvent += PaperDataListItem_OnControlButtonPressedEvent; containerFlowPanel.Controls.Add(paperDataListItem); paperDataListItem.Size = new Size(containerFlowPanel.Width, 48); } }
private async void finishPaperBtn_Click(object sender, EventArgs e) { int paperCode = (int)paperCodeField.IntegerValue; if (paperCodeField.Text == "") { Messages.ShowError("Paper code cannot be empty"); return; } else if (!isEditingPaper && GeneralManager.GetExamPapers != null && GeneralManager.GetExamPapers.GetPapers.Exists(x => x.Code == paperCode)) { Messages.ShowError("Paper code already exists"); return; } string paperTitle = paperTitleField.Text; if (paperTitleField.Text == "") { Messages.ShowError("Paper title cannot be empty"); return; } else if (!isEditingPaper && GeneralManager.GetExamPapers != null && GeneralManager.GetExamPapers.GetPapers.Exists(x => x.Title == paperTitle)) { Messages.ShowError("Paper with that title already exists"); return; } PaperDirection paperDirection = (PaperDirection)paperDirectionField.SelectedValue; int totalFields = (int)paperFieldsCountField.IntegerValue; int totalOptions = (int)paperOptionsCountField.IntegerValue; if (paperFieldsCountField.Text == "") { Messages.ShowError("Paper fields cannot be empty"); return; } if (paperOptionsCountField.Text == "") { Messages.ShowError("Paper options cannot be empty"); return; } else if (totalOptions < 2) { Messages.ShowError("There must atleast be more than one option per field."); return; } Paper newPaper = new Paper(paperCode, paperTitle, totalFields, totalOptions, paperDirection); if (!isEditingPaper) { GeneralManager.GetExamPapers.GetPapers.Add(newPaper); PaperDataListItem paperDataListItem = PaperDataListItem.Create(newPaper); containerFlowPanel.Controls.Add(paperDataListItem); emptyListLabel.Visible = false; } else { var oldCode = paperToEdit.Code; paperToEdit.Reset(newPaper); isEditingPaper = false; for (int i = 0; i < containerFlowPanel.Controls.Count; i++) { PaperDataListItem paperDataListItem = (PaperDataListItem)containerFlowPanel.Controls[i]; if (paperDataListItem.PaperCode == oldCode) { paperDataListItem.PaperCode = paperCode; paperDataListItem.PaperTitle = paperTitle; } } } papersListTable.Visible = true; paperConfigurationPanel.Visible = false; papersListTable.Dock = DockStyle.Fill; await LSTM.SavePapers(GeneralManager.GetExamPapers); }