// Inserts an empty result block at the position public void InsertResult(int pos) { MovableCasResult movableCasResult = new MovableCasResult(user, "", ""); movableCasResult.Attach(AddLockCheckButton(movableCasResult), 1, 100, 1, 1); movableCasResult.Attach(AddCommandButtons(movableCasResult), 100, 1, 1, 1); castextviews.Insert(pos, movableCasResult); Clear(); Redraw(); ShowAll(); }
// Inserts a result widget public void InsertResult(string answer, string facit) { MovableCasResult MovableCasResult = new MovableCasResult(user, answer, facit); MovableCasResult.Attach(AddLockCheckButton(MovableCasResult), 1, 100, 1, 1); MovableCasResult.Attach(AddCommandButtons(MovableCasResult), 100, 1, 1, 1); castextviews.Add(MovableCasResult); Clear(); Redraw(); ShowAll(); }
// Run when the button is pressed. Serializes the file, and saves it to the selected file public void SaveFile() { OperatingSystem os = Environment.OSVersion; PlatformID pid = os.Platform; List <MetaType> metaTypeList = new List <MetaType>(); // Saves each widget in a list, before serializing it all into a single string foreach (Widget w in textviews) { if (w is MovableCasCalcView) { MetaType metaType = new MetaType(); MovableCasCalcView calcView = (MovableCasCalcView)w; metaType.type = typeof(MovableCasCalcView); metaType.metastring = calcView.calcview.input.Text; metaType.locked = calcView.textview.locked; metaTypeList.Add(metaType); } else if (w is MovableCasCalcMulitlineView) { MetaType metaType = new MetaType(); MovableCasCalcMulitlineView calcview = (MovableCasCalcMulitlineView)w; metaType.type = typeof(MovableCasCalcMulitlineView); metaType.metastring = calcview.calcview.SerializeCasTextView(); metaType.locked = calcview.textview.locked; metaTypeList.Add(metaType); } else if (w.GetType() == typeof(MovableCasResult)) { MetaType metaType = new MetaType(); MovableCasResult result = (MovableCasResult)w; metaType.type = typeof(MovableCasResult); metaType.metastring = Export.Serialize(result.casresult.facitContainer); metaType.locked = result.casresult.correct; metaTypeList.Add(metaType); } else if (w.GetType() == typeof(MovableCasTextView)) { MetaType metaType = new MetaType(); MovableCasTextView textView = (MovableCasTextView)w; metaType.type = typeof(MovableCasTextView); metaType.metastring = textView.textview.SerializeCasTextView(); metaType.locked = textView.textview.locked; metaTypeList.Add(metaType); } } string s = ImEx.Export.Serialize(metaTypeList); switch (pid) { case PlatformID.Win32S: case PlatformID.Win32Windows: case PlatformID.WinCE: case PlatformID.Win32NT: // <- if one, this is the one we really need { var filechooser = new System.Windows.Forms.SaveFileDialog(); filechooser.InitialDirectory = "c:\\"; filechooser.Filter = "cas files (*.cas)|*.cas"; filechooser.FilterIndex = 2; filechooser.RestoreDirectory = true; if (filechooser.ShowDialog() == System.Windows.Forms.DialogResult.OK) { System.IO.File.WriteAllText(filechooser.FileName, s); } break; } case PlatformID.Unix: case PlatformID.MacOSX: { Object[] parameters = { "Cancel", ResponseType.Cancel, "Save", ResponseType.Accept }; FileChooserDialog filechooser = new FileChooserDialog("Save File...", null, FileChooserAction.Save, parameters); filechooser.Filter = new FileFilter(); filechooser.Filter.AddPattern("*.cas"); if (filechooser.Run() == (int)ResponseType.Accept) { if (filechooser.Filename.ToLower().EndsWith(".cas")) { System.IO.File.WriteAllText(filechooser.Filename, s); } else { System.IO.File.WriteAllText(filechooser.Filename + ".cas", s); } } filechooser.Destroy(); break; } default: { break; } } }
// Constructor for teacheraddfeedbackwindow public TeacherAddFeedbackWindow(User user, TextViewList textviews, string Filename) : base("Add Feedback") { this.user = user; this.textviews = textviews; this.Filename = Filename; SetSizeRequest(300, 300); Grid grid = new Grid(); Label labClass = new Label("Class:"); Entry entClass = new Entry(); entClass.Changed += (e, arg) => { className = entClass.Text; }; Button buttonCancel = new Button("Cancel"); buttonCancel.Clicked += delegate { Destroy(); }; Button buttonFeedback = new Button("Feedback"); buttonFeedback.Clicked += delegate { string feedbackString = String.Empty; List <MetaType> metaTypeList = new List <MetaType>(); // Packs the workspace into a single string for easy transfer foreach (Widget w in this.textviews) { if (w.GetType() == typeof(MovableCasCalcView)) { MetaType metaType = new MetaType(); MovableCasCalcView calcView = (MovableCasCalcView)w; metaType.type = typeof(MovableCasCalcView); metaType.metastring = calcView.calcview.input.Text; metaType.locked = calcView.textview.locked; metaTypeList.Add(metaType); } else if (w is MovableCasCalcMulitlineView) { MetaType metaType = new MetaType(); MovableCasCalcMulitlineView calcview = (MovableCasCalcMulitlineView)w; metaType.type = typeof(MovableCasCalcMulitlineView); metaType.metastring = calcview.calcview.SerializeCasTextView(); metaType.locked = calcview.textview.locked; metaTypeList.Add(metaType); } else if (w is MovableCasResult) { MetaType metaType = new MetaType(); MovableCasResult casres = (MovableCasResult)w; metaType.type = typeof(MovableCasResult); metaType.metastring = Export.Serialize(casres.casresult.facitContainer); metaType.locked = casres.textview.locked; metaTypeList.Add(metaType); } else if (w.GetType() == typeof(MovableCasTextView)) { MetaType metaType = new MetaType(); MovableCasTextView textView = (MovableCasTextView)w; metaType.type = typeof(MovableCasTextView); metaType.metastring = textView.textview.SerializeCasTextView(); metaType.locked = textView.textview.locked; metaTypeList.Add(metaType); } } if (metaTypeList.Count != 0 && string.IsNullOrEmpty(className) == false && string.IsNullOrEmpty(this.Filename) == false) { feedbackString = Export.Serialize(metaTypeList); } string[] StudentList = this.user.teacher.GetCompletedList(this.Filename, className); grid.Destroy(); grid = new Grid(); for (int i = 0; i < StudentList.Length / 2; i++) { int j = 2 * i; Button button = new Button(StudentList[j]); button.Clicked += delegate { this.user.teacher.AddFeedback(feedbackString, this.Filename, StudentList[j], className); MessageDialog ms = new MessageDialog(this, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Close, "Added feedback"); ms.Run(); ms.Destroy(); Destroy(); }; grid.Attach(button, 1, 1 + i, 1, 1); } Add(grid); ShowAll(); }; grid.Attach(labClass, 1, 1, 1, 1); grid.Attach(entClass, 2, 1, 1, 1); grid.Attach(buttonCancel, 1, 3, 1, 1); grid.Attach(buttonFeedback, 2, 3, 1, 1); Add(grid); ShowAll(); }
public StudentAddCompletedWindow(User user, TextViewList textviews, string Filename) : base("Upload Completed Assignment") { this.user = user; this.textviews = textviews; this.Filename = Filename; SetDefaultSize(300, 300); List <MetaType> metaTypeList = new List <MetaType>(); // Packs the file into a single string foreach (Widget w in this.textviews) { if (w is MovableCasCalcView) { MetaType metaType = new MetaType(); MovableCasCalcView calcView = (MovableCasCalcView)w; metaType.type = typeof(MovableCasCalcView); metaType.metastring = calcView.calcview.input.Text; metaType.locked = calcView.textview.locked; metaTypeList.Add(metaType); } else if (w is MovableCasCalcMulitlineView) { MetaType metaType = new MetaType(); MovableCasCalcMulitlineView calcview = (MovableCasCalcMulitlineView)w; metaType.type = typeof(MovableCasCalcMulitlineView); metaType.metastring = calcview.calcview.SerializeCasTextView(); metaType.locked = calcview.textview.locked; metaTypeList.Add(metaType); } else if (w is MovableCasResult) { MetaType metaType = new MetaType(); MovableCasResult casres = (MovableCasResult)w; metaType.type = typeof(MovableCasResult); metaType.metastring = Export.Serialize(casres.casresult.facitContainer); metaType.locked = casres.textview.locked; metaTypeList.Add(metaType); } else if (w.GetType() == typeof(MovableCasTextView)) { MetaType metaType = new MetaType(); MovableCasTextView textView = (MovableCasTextView)w; metaType.type = typeof(MovableCasTextView); metaType.metastring = textView.textview.SerializeCasTextView(); metaType.locked = textView.textview.locked; metaTypeList.Add(metaType); } } if (metaTypeList.Count != 0 && !string.IsNullOrEmpty(this.Filename)) { string serializedString = ImEx.Export.Serialize(metaTypeList); this.user.student.AddCompleted(serializedString, this.Filename); MessageDialog ms = new MessageDialog(this, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Close, "Upload Successful"); ms.Run(); ms.Destroy(); } else { MessageDialog ms = new MessageDialog(this, DialogFlags.DestroyWithParent, MessageType.Warning, ButtonsType.Close, "Upload failed"); ms.Run(); ms.Destroy(); } Destroy(); }
public TeacherAddAssignmentWindow(User user, TextViewList textviews) : base("Add Assignment") { this.user = user; this.textviews = textviews; SetSizeRequest(300, 300); Grid grid = new Grid(); Entry grad = new Entry(); grad.WidthRequest = 200; Label classLabel = new Label("Class:"); Entry name = new Entry(); name.WidthRequest = 200; Label nameLabel = new Label("File name:"); Label warningLabel = new Label(); Button uploadButton = new Button("Upload"); uploadButton.Clicked += delegate { List <MetaType> metaTypeList = new List <MetaType>(); // Packs the workspace into a single string for easy transfer foreach (Widget w in this.textviews) { if (w.GetType() == typeof(MovableCasCalcView)) { MetaType metaType = new MetaType(); MovableCasCalcView calcView = (MovableCasCalcView)w; metaType.type = typeof(MovableCasCalcView); metaType.metastring = calcView.calcview.input.Text; metaType.locked = calcView.textview.locked; metaTypeList.Add(metaType); } else if (w is MovableCasCalcMulitlineView) { MetaType metaType = new MetaType(); MovableCasCalcMulitlineView calcview = (MovableCasCalcMulitlineView)w; metaType.type = typeof(MovableCasCalcMulitlineView); metaType.metastring = calcview.calcview.SerializeCasTextView(); metaType.locked = calcview.textview.locked; metaTypeList.Add(metaType); } else if (w is MovableCasResult) { MetaType metaType = new MetaType(); MovableCasResult casres = (MovableCasResult)w; metaType.type = typeof(MovableCasResult); metaType.metastring = Export.Serialize(casres.casresult.facitContainer); metaType.locked = casres.textview.locked; metaTypeList.Add(metaType); } else if (w.GetType() == typeof(MovableCasTextView)) { MetaType metaType = new MetaType(); MovableCasTextView textView = (MovableCasTextView)w; metaType.type = typeof(MovableCasTextView); metaType.metastring = textView.textview.SerializeCasTextView(); metaType.locked = textView.textview.locked; metaTypeList.Add(metaType); } } // Sends the file, if there are anything to send if (metaTypeList.Count != 0 && !string.IsNullOrEmpty(name.Text) && !string.IsNullOrEmpty(grad.Text)) { string Assignment = Export.Serialize(metaTypeList); this.user.teacher.AddAssignment(Assignment, name.Text, grad.Text); MessageDialog ms = new MessageDialog(this, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Close, "Added assignment"); ms.Run(); ms.Destroy(); Destroy(); } else { warningLabel.Text = "Warning, upload invalid"; } }; Button cancelButton = new Button("Cancel"); cancelButton.Clicked += delegate { Destroy(); }; grid.Attach(nameLabel, 1, 1, 1, 1); grid.Attach(name, 2, 1, 1, 1); grid.Attach(classLabel, 1, 2, 1, 1); grid.Attach(grad, 2, 2, 1, 1); grid.Attach(warningLabel, 1, 3, 2, 1); grid.Attach(uploadButton, 2, 4, 1, 1); grid.Attach(cancelButton, 1, 4, 1, 1); Add(grid); ShowAll(); }