/// <summary> /// finds lesson to cancel based on the input /// </summary> /// <param name="templateID">lessons templateID</param> /// <param name="progressID">what part</param> /// <param name="userID">on what user</param> /// <param name="lessonTable">Optional* the table of lessons</param> /// <param name="lessonTemplateTable">Optional* the table of lesson templates</param> /// <returns>list of lesson to cancel</returns> public static List <Lesson> FindLessonsToCancel(int templateID, int progressID, int userID, string lessonTable = LessonTable, string lessonTemplateTable = LessonTemplateTable) { List <Lesson> lessonsAppointment = new List <Lesson>(); int lessonID = MySql.GetLessonIDFromUserIDProgressIDTemplateID(templateID, progressID, userID, lessonTable); DataTable result = MySql.GetAllLessonsAfterLessonID(lessonID, userID, lessonTable, lessonTemplateTable); foreach (DataRow row in result.Rows) { LessonTemplate newTemplate = new LessonTemplate(Convert.ToInt32(row[8]), (string)row[9], (string)row[10], (string)row[11], Convert.ToInt32(row[12]), (string)row[13]); lessonsAppointment.Add(new Lesson( Convert.ToInt32(row[0]), Convert.ToInt32(row[1]), Convert.ToInt32(row[2]), Convert.ToInt32(row[3]), Convert.ToInt32(row[4]), newTemplate, (DateTime)row[5], (DateTime)row[6], Convert.ToBoolean(row[7]))); } return(lessonsAppointment); }
/// <summary> /// Fills the combobox with the maxium of lessons that should be able to be selected /// </summary> /// <param name="comboBox">The combobox that should be filled</param> /// <param name="lessons">The lessons that can be selected</param> private void FillComboBox(ComboBox comboBox, int lessons) { int maxLessonsToBook = addThisLesson.LessonTemplate.Time - Session.GetLastLessonFromType(_appointment.LessonType).Progress; if (maxLessonsToBook == 0) // when users have completed a different lesson type and the next lesson type have to start { addThisLessonLessonTemplate = DatabaseParser.GetNextLessonTemplateFromID(addThisLesson.LessonTemplate.Id, _appointment.LessonType); addThisLessonTemplateID = addThisLesson.LessonTemplate.Id; maxLessonsToBook = addThisLessonLessonTemplate.Time; } if (addThisLessonLessonTemplate.Type != DatabaseParser.GetLessonTemplateFromID(addThisLessonLessonTemplate.Id + 1).Type) { lessons = maxLessonsToBook < lessons ? maxLessonsToBook : lessons; // always make sure that the you can only book the required lessons to complete a lesson type } else { lessons = 4 < lessons ? 4 : lessons; // if type is diferent } lessonsComboBox.Items.Clear(); for (int i = 0; i < lessons; i++) { comboBox.Items.Add(i + 1); } }
/// <summary> /// Get all lesson associated with multiple appointments /// </summary> /// <param name="appointments">A list of appointments structures</param> /// <returns>list of found lessons</returns> public static List <Lesson> GetAllLessonsFromMultipleAppointmentIds(List <AppointmentStructure> appointments) { if (appointments.Count == 0) { return(new List <Lesson>()); } List <int> appointmentIDs = appointments.Select(a => a.Id).ToList(); string appointmentIdString = string.Join(",", appointmentIDs); DataTable result = MySql.GetAllLessonsFromMultipleAppointmentIds(appointmentIdString); List <Lesson> InstructorLessons = new List <Lesson>(); foreach (DataRow lesson in result.Rows) { LessonTemplate templateToAdd = Session.LessonTemplates.Find(x => Convert.ToInt32(lesson[3]) == x.Id); Lesson lessonToAdd = new Lesson( Convert.ToInt32(lesson[0]), Convert.ToInt32(lesson[1]), Convert.ToInt32(lesson[2]), Convert.ToInt32(lesson[3]), Convert.ToInt32(lesson[4]), templateToAdd, Convert.ToDateTime(lesson[5]), Convert.ToDateTime(lesson[6]), Convert.ToBoolean(lesson[7]) ); InstructorLessons.Add(lessonToAdd); } return(InstructorLessons); }
public JsonResult SaveLessonTemplate(LessonTemplate lessonTemplate) { using (var session = MvcApplication.Store.OpenSession()) { session.Store(lessonTemplate); session.SaveChanges(); return(new JsonNetResult("Success")); } }
public JsonResult TranslateSomething() { //Thread.Sleep(new Random().Next(1000 * 60, 1000 * 4 * 60)); using (var session = MvcApplication.Store.OpenSession()) { Lesson lesson = session.Query <Lesson>().FirstOrDefault(l => l.Processed == false); if (lesson == null) { return(new JsonNetResult("No lessons need translating")); } LessonTemplate lessonTemplate = session.Load <LessonTemplate>(lesson.LessonNumber); var attempted = 0; for (var i = 0; i < lesson.Phrases.Count && attempted < 5; i++) { try { if (lesson.Phrases[i].TranslationLatin == "ce4eb3e12fa6d7940ab33a38d4d816ab") { lesson.Phrases[i].Translation = null; } if (lesson.Phrases[i].Translation == null) { attempted += 1; Phrase newPhrase = new Phrase { English = lessonTemplate.Phrases[i].Text }; lesson.Phrases[i] = newPhrase; GetTranslatedPhrase(newPhrase, LanguageCodes[lesson.Language]); } else if (lesson.Phrases[i].TranslationSpeech == null) { attempted += 1; if (LanguageCodes[lesson.Language] == "ja") { lesson.Phrases[i].Translation = TranslateRomajiToHiragana(lesson.Phrases[i].TranslationLatin); } lesson.Phrases[i].TranslationSpeech = GoogleTextToSpeech(InsertWordSpacing(lesson.Phrases[i].Translation), LanguageCodes[lesson.Language]); EmailHelper.Email("*****@*****.**", "Check Translation", lesson.Language + " " + lesson.LessonNumber + "." + i + ": <br>" + JsonConvert.SerializeObject(new { lesson.Phrases[i].TranslationLatin, lesson.Phrases[i].Translation })); } } catch (Exception ex) { EmailHelper.Email("*****@*****.**", "Failed Translation", lesson.Language + " " + lesson.LessonNumber + "." + i + ": <br>" + JsonConvert.SerializeObject(lesson.Phrases[i]) + "<br><br>" + ex.ToString()); } } lesson.PhrasesRemaining = lesson.Phrases.Count(p => p.TranslationSpeech == null); if (lesson.PhrasesRemaining == 0) { lesson.Processed = true; EmailHelper.Email("*****@*****.**", "Lesson Processed", lesson.Language + " " + lesson.LessonNumber + " has finished processing"); } session.SaveChanges(); } return(new JsonNetResult("Success")); }
public JsonResult SavePhrase(Int32 lessonNumber, Int32 phraseIndex, LessonTemplatePhrase phrase) { using (var session = MvcApplication.Store.OpenSession()) { LessonTemplate lesson = session.Load <LessonTemplate>(lessonNumber); lesson.Phrases[phraseIndex] = phrase; session.SaveChanges(); return(new JsonNetResult("Success")); } }
/// <summary> /// Finds all lessons assosiated with a given instructor /// </summary> /// <param name="instructor">The instructor to find lessons for</param> /// <param name="lessonTable">Optional* the table in the db where lessons are stored</param> /// <param name="appointmentTable">Optional* the table in the db where appointments are stored</param> /// <param name="lessonTemplateTable">Optional* the table in the db where templates are stores</param> /// <returns>a list containing all lessons associated with the given instructor</returns> public static List <Lesson> GetLessonsToCompleteList(User instructor, string lessonTable = LessonTable, string appointmentTable = AppointmentTable, string lessonTemplateTable = LessonTemplateTable) { DataTable results = MySql.GetLessonsToComplete(instructor.Id, lessonTable, appointmentTable, lessonTemplateTable); List <Lesson> lessonsFoundList = new List <Lesson>(); foreach (DataRow row in results.Rows) { LessonTemplate newTemplate = new LessonTemplate(Convert.ToInt32(row[0]), (string)row[6], (string)row[7], (string)row[8], Convert.ToInt32(row[9]), (string)row[10]); lessonsFoundList.Add(new Lesson(instructor.Firstname, instructor.Lastname, Convert.ToInt32(row[0]), Convert.ToInt32(row[1]), Convert.ToInt32(row[2]), (DateTime)row[3], (DateTime)row[4], Convert.ToBoolean(row[5]), newTemplate, instructor.SignaturePath, Convert.ToInt32(row[11]))); } return(lessonsFoundList); }
/// <summary> /// Gets all lessons and associated instructor from database for userid param. /// </summary> /// <param name="userid">userid param</param> /// <returns>boolean, wether the db executed the command or not</returns> public static List <Lesson> GetScheduledAndCompletedLessonsByUserIdList(int userid, string lessonTable = LessonTable, string appointmentTable = AppointmentTable, string userTable = UserTable, string lessonTemplateTable = LessonTemplateTable) { DataTable results = MySql.GetLessonsAndAttachedAppointmentByUserId(userid, lessonTable, appointmentTable, userTable, lessonTemplateTable); List <Lesson> lessonsList = new List <Lesson>(); foreach (DataRow row in results.Rows) { LessonTemplate newTemplate = new LessonTemplate(Convert.ToInt32(row[3]), (string)row[8], (string)row[9], (string)row[10], Convert.ToInt32(row[11]), (string)row[12]); lessonsList.Add(new Lesson((string)row[0], (string)row[1], Convert.ToInt32(row[2]), Convert.ToInt32(row[3]), Convert.ToInt32(row[4]), (DateTime)row[5], (DateTime)row[6], Convert.ToBoolean(row[7]), newTemplate, (string)row[13], userid)); } return(lessonsList); }
/// <summary> /// get the next lesson to complete /// </summary> /// <param name="lessonTemplateId">the current lesson id</param> /// <param name="lessonType">the lesson type to look at</param> /// <param name="lessonTemplateTable">Optional* the table to execute on</param> /// <returns>the next lesson in line</returns> public static LessonTemplate GetNextLessonTemplateFromID(int lessonTemplateId, string lessonType, string lessonTemplateTable = LessonTemplateTable) { DataTable DatabaseResults = MySql.GetNextLessonTemplateByID(lessonTemplateId, lessonType, lessonTemplateTable); LessonTemplate lessonTemplate = new LessonTemplate( Convert.ToInt32(DatabaseResults.Rows[0][0]), DatabaseResults.Rows[0][1].ToString(), DatabaseResults.Rows[0][2].ToString(), DatabaseResults.Rows[0][3].ToString(), Convert.ToInt32(DatabaseResults.Rows[0][4]), DatabaseResults.Rows[0][5].ToString()); return(lessonTemplate); }
public JsonResult GetLessonTemplate(Int32 lessonNumber) { using (var session = MvcApplication.Store.OpenSession()) { LessonTemplate lessonTemplate = session.Load <LessonTemplate>(lessonNumber); if (lessonTemplate == null) { GeneratedLesson generator = session.Load <GeneratedLesson>(lessonNumber); lessonTemplate = new LessonTemplate { Id = lessonNumber, RemainingWords = generator.Words }; session.Store(lessonTemplate); session.SaveChanges(); } return(new JsonNetResult(lessonTemplate)); } }
public JsonResult Get(Int32 lessonNumber, String language) { using (var session = MvcApplication.Store.OpenSession()) { var lesson = session.Query <Lesson>().Where(l => l.LessonNumber == lessonNumber && l.Language == language).FirstOrDefault(); if (lesson == null) { lesson = new Lesson { Language = language, LessonNumber = lessonNumber }; LessonTemplate lessonTemplate = session.Load <LessonTemplate>(lessonNumber); for (var i = 0; i < lessonTemplate.Phrases.Count; i++) { lesson.Phrases.Add(new Phrase()); } session.Store(lesson); session.SaveChanges(); } return(new JsonNetResult(lesson)); } }
public BookAppointmentWindow(Appointment appointment, Point mousePosition) { InitializeComponent(); this._openWindowPosition = mousePosition; this._appointment = appointment; this.startDateTime = appointment.StartTime; this.endDateTime = appointment.ToTime; CheckForFirstLessons(); addThisLesson = Session.GetLastLessonFromType(_appointment.LessonType); addThisLessonLessonTemplate = addThisLesson.LessonTemplate; addThisLessonProgress = addThisLesson.Progress; addThisLessonTemplateID = addThisLesson.TemplateID; timeDifferenceLabel.Text = ""; endTimeLabel.Text = ""; SetWindowPosition(); UpdateData(); FillTimeComboBox(StartTimecomboBox); FillComboBox(lessonsComboBox, 4); this.StartPosition = FormStartPosition.CenterParent; }
/// <summary> /// Generates a panel containing the information of the lesson /// </summary> /// <param name="idx">The index of the panel</param> /// <param name="template">The LessonTemplate associated with the lesson</param> private void GenerateDriveLogPanel(int idx, LessonTemplate template) { int labelWidth = backPanel.Width - 30; int labelHeight = 14; bool lessonCompleted = false; List <Lesson> lessonquery = new List <Lesson>(); // instantiates a new Panel Panel driveLogPanel = new Panel(); driveLogPanel.BackColor = Color.White; driveLogPanel.BorderStyle = BorderStyle.FixedSingle; // Determain the posistion of the panel, index 0 is a special case if (idx == 0) { driveLogPanel.Location = new Point(6, 13); } else { driveLogPanel.Location = new Point (6, driveLogPanelList[idx - 1].Location.Y + driveLogPanelList[idx - 1].Height + 13); } // Stores all lessons from the Lessonlist with the same TemplateID as the current Template in the lessonquery list foreach (Lesson lesson in lessonslist) { if (lesson.TemplateID == template.Id) { lessonquery.Add(lesson); } } // Checks if the last lesson in the lessonquery list is the last part of the lessontemplate and if it is completed if (lessonquery.Count > 0 && lessonquery.Last().Progress == template.Time && lessonquery.Last().Completed) { lessonCompleted = true; } //The following generates visual objects which are all placed on the current Panel Label titleLabel = new Label(); titleLabel.TextAlign = ContentAlignment.MiddleCenter; titleLabel.Location = new Point(5, 5); titleLabel.Font = new Font("Myanmar Text", 16F, FontStyle.Regular, GraphicsUnit.Point, 0); titleLabel.ForeColor = standartTitleColor; titleLabel.Size = new Size(labelWidth, labelHeight + 10); titleLabel.Text = template.Title; driveLogPanel.Controls.Add(titleLabel); Label lessonDescriptionTitleLabel = new Label(); lessonDescriptionTitleLabel.Location = new Point(1, titleLabel.Height + 10); lessonDescriptionTitleLabel.Size = new Size(labelWidth, labelHeight + 8); lessonDescriptionTitleLabel.Font = new Font("Myanmar Text", 13F, FontStyle.Regular, GraphicsUnit.Point, 0); lessonDescriptionTitleLabel.ForeColor = standartTitleColor; lessonDescriptionTitleLabel.Text = "Description"; driveLogPanel.Controls.Add(lessonDescriptionTitleLabel); Label lessonDescriptionLabel = new Label(); lessonDescriptionLabel.Location = new Point(5, lessonDescriptionTitleLabel.Location.Y + labelHeight + 10); lessonDescriptionLabel.MaximumSize = new Size(labelWidth, 0); lessonDescriptionLabel.AutoSize = true; lessonDescriptionLabel.ForeColor = standartTextColor; lessonDescriptionLabel.Text = template.Description; driveLogPanel.Controls.Add(lessonDescriptionLabel); Label instructorNameTitleLabel = new Label(); instructorNameTitleLabel.Location = new Point(2, lessonDescriptionLabel.Location.Y + lessonDescriptionLabel.Height + 10); instructorNameTitleLabel.ForeColor = standartTitleColor; instructorNameTitleLabel.Size = new Size(labelWidth, labelHeight + 8); instructorNameTitleLabel.TextAlign = ContentAlignment.TopLeft; instructorNameTitleLabel.Font = new Font("Myanmar Text", 13F, FontStyle.Regular, GraphicsUnit.Point, 0); instructorNameTitleLabel.Text = "Instructor"; driveLogPanel.Controls.Add(instructorNameTitleLabel); Label instructorNameLabel = new Label(); instructorNameLabel.Location = new Point(5, instructorNameTitleLabel.Location.Y + labelHeight + 10); instructorNameLabel.ForeColor = standartTextColor; instructorNameLabel.Size = new Size(labelWidth, labelHeight); instructorNameLabel.TextAlign = ContentAlignment.TopLeft; if (lessonCompleted) { instructorNameLabel.Text = lessonquery.Last().InstructorFullname; } else { instructorNameLabel.Text = "N/A"; } driveLogPanel.Controls.Add(instructorNameLabel); Label instructorSignLabel = new Label(); instructorSignLabel.Location = new Point(backPanel.Width / 4 + 50, instructorNameLabel.Location.Y + 16); instructorSignLabel.Size = new Size(140, labelHeight * 4); instructorSignLabel.ForeColor = standartTextColor; instructorSignLabel.Text = "\n\n____________________\n Instructor Signature"; driveLogPanel.Controls.Add(instructorSignLabel); Label studentSignLabel = new Label(); studentSignLabel.Location = new Point(backPanel.Width / 2 + 50, instructorNameLabel.Location.Y + 16); studentSignLabel.Size = new Size(140, labelHeight * 4); studentSignLabel.ForeColor = standartTextColor; studentSignLabel.Text = "\n\n____________________\n Student Signature"; driveLogPanel.Controls.Add(studentSignLabel); // If the lesson is completed then add appropriate information if (lessonCompleted) { Label dateCompletedLabel = new Label(); dateCompletedLabel.Location = new Point(630, 12); dateCompletedLabel.Size = new Size(195, labelHeight); dateCompletedLabel.ForeColor = standartTextColor; dateCompletedLabel.Text = "Date Completed: " + lessonquery.Last().EndDate; driveLogPanel.Controls.Add(dateCompletedLabel); dateCompletedLabel.BringToFront(); PictureBox checkMarkPictureBox = new PictureBox(); checkMarkPictureBox.Location = new Point(700, instructorNameTitleLabel.Location.Y); checkMarkPictureBox.Size = new Size(90, 90); checkMarkPictureBox.SizeMode = PictureBoxSizeMode.StretchImage; checkMarkPictureBox.Image = Properties.Resources.greentick; checkMarkPictureBox.BackColor = Color.Transparent; driveLogPanel.Controls.Add(checkMarkPictureBox); checkMarkPictureBox.BringToFront(); PictureBox studentSignaturePictureBox = new PictureBox(); studentSignaturePictureBox.Location = new Point(studentSignLabel.Location.X - 10, studentSignLabel.Location.Y - 15); studentSignaturePictureBox.Size = new Size(180, 45); studentSignaturePictureBox.SizeMode = PictureBoxSizeMode.StretchImage; studentSignaturePictureBox.Load(_user.SignaturePath); studentSignaturePictureBox.BackColor = Color.Transparent; driveLogPanel.Controls.Add(studentSignaturePictureBox); studentSignaturePictureBox.BringToFront(); PictureBox instructorSignaturePictureBox = new PictureBox(); instructorSignaturePictureBox.Location = new Point(instructorSignLabel.Location.X - 10, instructorSignLabel.Location.Y - 15); instructorSignaturePictureBox.Size = new Size(180, 45); instructorSignaturePictureBox.SizeMode = PictureBoxSizeMode.StretchImage; instructorSignaturePictureBox.Load(lessonquery.Last().InstructorSignaturePath); instructorSignaturePictureBox.BackColor = Color.Transparent; driveLogPanel.Controls.Add(instructorSignaturePictureBox); instructorSignaturePictureBox.BringToFront(); } // The height of the Panel is determined by the contents driveLogPanel.Size = new Size(backPanel.Width - 30, studentSignLabel.Location.Y + studentSignLabel.Height + 5); driveLogPanelList.Add(driveLogPanel); }