public void AddLesson(Lesson lesson) { lesson.Course.AddLesson(lesson); this.timetableLayoutPanel.SuspendLayout(); this.timetableLayoutPanel.Controls.Add(lesson.CellControl, lesson.CellX, lesson.CellY); this.timetableLayoutPanel.SetRowSpan(lesson.CellControl, lesson.RowSpan); this.timetableLayoutPanel.ResumeLayout(); }
static async Task Main(string[] args) { ClassFile classFile = new ClassFile(); string file = classFile.path; if (file != null) { using (var document = SpreadsheetDocument.Open(file, true)) { //create the object for workbook part WorkbookPart wbPart = document.WorkbookPart; //statement to get the count of the worksheet int worksheetcount = document.WorkbookPart.Workbook.Sheets.Count(); //statement to get the sheet object Sheet mysheet = (Sheet)document.WorkbookPart.Workbook.Sheets.ChildElements.GetItem(0); //statement to get the worksheet object by using the sheet id Worksheet Worksheet = ((WorksheetPart)wbPart.GetPartById(mysheet.Id)).Worksheet; //statement to get the sheetdata which contains the rows and cell in table IEnumerable <Row> Rows = Worksheet.GetFirstChild <SheetData>().Descendants <Row>(); //Loop through the Worksheet rows foreach (var row in Rows) { if (row.RowIndex.Value != 0) { //var qq = Program.GetSharedStringItemById(wbPart ,0); var lesson = new Lesson(); int idx = 1; int idy = 0; foreach (Cell cell in row.Descendants <Cell>()) { var val = Program.GetValue(document, cell); if (val == "Неделя") { break; } if (idx < 8) { if (idx == 1) { int x; Int32.TryParse(val, out x); lesson.numberOfWeek = x; } if (idx == 2) { lesson.dayOfWeek = val; } if (idx == 3) { int x; Int32.TryParse(val, out x); lesson.numbewrOfDayInWeek = x; } if (idx == 4) { int day, month, year; string[] z = val.Split(' '); Int32.TryParse(z[0], out day); if (z[2].Length == 4) { Int32.TryParse(z[2], out year); } else { Int32.TryParse(z[2].Substring(0, 3), out year); } switch (z[1]) { case "СЕНТЯБРЯ": month = 09; break; case "ОКТЯБРЯ": month = 10; break; case "НОЯБРЯ": month = 11; break; case "ДЕКАБРЯ": month = 12; break; case "ЯНВАРЯ": month = 1; break; case "ФЕВРАЛЯ": month = 2; break; case "МАРТ": month = 3; break; case "АПРЕЛЬ": month = 4; break; case "МАЙ": month = 5; break; case "ИЮНЬ": month = 6; break; case "ИЮЛЬ": month = 7; break; case "АВГУСТА": month = 8; break; default: month = 0; break; } DateTime dateTime = new DateTime(year, month, day); lesson.date = dateTime; } if (idx == 5) { int x; Int32.TryParse(val, out x); lesson.numberOfLessonInDay = x; } if (idx == 7) { int x; Int32.TryParse(val, out x); if (x != 4) { break; } } } else { idy++; if (idy == 1) { lesson.numberOfGroup = val; } if (idy == 2) { lesson.nameOfDiscipline = val; } if (idy == 3) { int x = 0; if (val != "" && val != "ОХРАНА" && val != "ПРАЗДНИК") { string[] z = val.Split(' '); lesson.typeOfLesson = z[0]; Int32.TryParse(z[z.Length - 1], out x); lesson.numberOfLesson = x; } } if (idy == 4) { lesson.Lectural = val; } if (idy == 5) { if (val != null) { lesson.auditore = val; } else { lesson.auditore = ""; } } if (idy == 7) { idy = 0; //await sendLessonToAPIAsync(lesson); if (lesson.numberOfGroup != "431А" && lesson.numberOfGroup != "431Б" && lesson.numberOfGroup != "441А" && lesson.numberOfGroup != "441Б" && lesson.numberOfGroup != "451А" && lesson.numberOfGroup != "451Б") { Console.WriteLine(lesson.ToString()); if (lesson.Lectural != "" && lesson.nameOfDiscipline != "") { try { await sendLessonToAPIAsync(lesson); } catch (Exception e) { Console.WriteLine(e.Message); } } } } } idx++; } } } } } }
//Metodi ei tarkista onko kursorin alla valittu kurssi. //Vain courseLstBoxissa valitulla kurssilla on väliä. private void coursesListBox_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { if (this.coursesListBox.Items.Count > 0 && this.coursesListBox.SelectedItem != null) { Lesson lesson = new Lesson(courseList[this.coursesListBox.SelectedIndex], this.timetableLayoutPanel); this.coursesListBox.DoDragDrop(lesson, DragDropEffects.Move); } } else if(e.Button == MouseButtons.Right) { this.coursesListBox.ContextMenuStrip.Show(this.coursesListBox.PointToScreen(new Point(e.X, e.Y))); } }