private void DGV_courses_CurrentCellDirtyStateChanged(object sender, EventArgs e) { if (DGV_courses.CurrentCell.ColumnIndex == 6 && DGV_courses.IsCurrentCellDirty) { DGV_courses.CommitEdit(DataGridViewDataErrorContexts.Commit); } }
private void ParseCredit() { HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(Index.creditsDoc); var query = from table in doc.DocumentNode.SelectNodes("//table") from row in table.SelectNodes("tr") from cell in row.SelectNodes("th|td") select new { Table = table.Id, CellText = cell.InnerText }; Regex regexCourse = new Regex("(B|J|K|M|X)[A-Z0-9]{3}"); int identity = 0, col = 0, line = 0, length = 0; string[] courses = new string[8]; foreach (var cell in query) { Match match = regexCourse.Match(Convert.ToString(cell.CellText)); if (match.Success) { length++; } } Regex regexCourses = new Regex("(A|Z|N){1}"); int i = 0; int tmp = 0; foreach (var cell in query) { tmp++; if (cell.CellText.Contains("Všechny skupiny volitelných předmětů")) { endTable = tmp; } Match match = regexCourses.Match(Convert.ToString(cell.CellText)); if (match.Success && cell.CellText.Length == 1) { col = 0; line = identity++; } if ((identity != 0) && (col < 8) && (line < length)) { courses[col++] = Convert.ToString(cell.CellText); if (col == 8) { if (courseList.Find(x => x.Acronym.Contains(courses[1])) != null) { continue; } courseList.Add(new Courses { Status = courses[0], Acronym = courses[1], Name = courses[2], Credits = Regex.Match(courses[3], @"\d+").Value, Semester = courses[4], Compulsory = courses[5], Enroll = courses[0].Contains("A") || courses[0].Contains("Z") || courses[0].Contains("U") //|| courses[5].Contains("P") } ); if (chb_readTable.Checked && i < readedValue.Count) { courseList.Last().Enroll = readedValue.ElementAt(i); } i++; if (courseList.Last().Compulsory == "P") { compulsory.min += Convert.ToInt16(courseList.Last().Credits); switch (courseList.Last().Status) { case "A": compulsory.passed += Convert.ToInt16(courseList.Last().Credits); break; } } } } } DGV_courses.DataSource = courseList; DGV_courses.AutoResizeColumns(); DGV_courses.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; DGV_courses.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; DGV_courses.Columns[0].HeaderText = "Status"; DGV_courses.Columns[1].HeaderText = "Acronym"; DGV_courses.Columns[2].HeaderText = "Name"; DGV_courses.Columns[3].HeaderText = "Credits"; DGV_courses.Columns[4].HeaderText = "Semester"; DGV_courses.Columns[5].HeaderText = "Compulsory"; DGV_courses.Columns[6].HeaderText = "Enroll"; foreach (DataGridViewColumn dc in DGV_courses.Columns) { dc.ReadOnly = !dc.Index.Equals(6); } foreach (DataGridViewRow row in DGV_courses.Rows) { DataGridViewCheckBoxCell chk = (DataGridViewCheckBoxCell)row.Cells["Enroll"]; chk.TrueValue = true; chk.FalseValue = false; if (chk.Value == null) { chk.Value = chk.FalseValue; } } /*for(int i = 0; i < DGV_courses.Columns.Count - 1; i++) * { * DGV_courses.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; * } * DGV_courses.Columns[DGV_courses.Columns.Count - 1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; * * for(int i = 0; i < DGV_courses.Columns.Count; i++) * { * int colw = DGV_courses.Columns[i].Width; * DGV_courses.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.None; * DGV_courses.Columns[i].Width = colw; * }*/ DGV_courses.SuspendLayout(); int controlBorderWidth = (DGV_courses.BorderStyle == BorderStyle.None) ? 0 : 2; DGV_courses.Width = DGV_courses.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) + DGV_courses.RowHeadersWidth + controlBorderWidth; //DGV_courses.Left = (ClientSize.Width - DGV_courses.Width) / 2; DGV_courses.ResumeLayout(); for (int idx = endTable; idx < query.Count(); idx++) { if (query.ElementAt(idx).CellText.ToString() == "VO" && query.ElementAt(idx + 1).CellText.ToString() == "Volitelný oborový") { specialized.min = Convert.ToInt16(query.ElementAt(idx + 2).CellText.ToString()); specialized.passed = Convert.ToInt16(query.ElementAt(idx + 3).CellText.ToString()); //specialized.reg = Convert.ToInt16(query.ElementAt(idx + 4).CellText.ToString()); } if (query.ElementAt(idx).CellText.ToString() == "VM" && query.ElementAt(idx + 1).CellText.ToString() == "Volitelný mimooborový") { interdisciplinary.min = Convert.ToInt16(query.ElementAt(idx + 2).CellText.ToString()); interdisciplinary.passed = Convert.ToInt16(query.ElementAt(idx + 3).CellText.ToString()); //interdisciplinary.reg = Convert.ToInt16(query.ElementAt(idx + 4).CellText.ToString()); } if (query.ElementAt(idx).CellText.ToString() == "VV" && query.ElementAt(idx + 1).CellText.ToString() == "Volitelný všeobecný") { knowledge.min = Convert.ToInt16(query.ElementAt(idx + 2).CellText.ToString()); knowledge.passed = Convert.ToInt16(query.ElementAt(idx + 3).CellText.ToString()); //knowledge.reg = Convert.ToInt16(query.ElementAt(idx + 4).CellText.ToString()); } if (query.ElementAt(idx).CellText.ToString() == "TN" && query.ElementAt(idx + 1).CellText.ToString() == "Teoretická nadstavba") { theoretical.min = Convert.ToInt16(query.ElementAt(idx + 2).CellText.ToString()); theoretical.passed = Convert.ToInt16(query.ElementAt(idx + 3).CellText.ToString()); //theoretical.reg = Convert.ToInt16(query.ElementAt(idx + 4).CellText.ToString()); } if (query.ElementAt(idx).CellText.ToString() == "Splnění minimálního počtu kreditů") { total.min = Convert.ToInt16(query.ElementAt(idx + 1).CellText.ToString()); total.passed = Convert.ToInt16(query.ElementAt(idx + 2).CellText.ToString()); //total.reg = Convert.ToInt16(query.ElementAt(idx + 3).CellText.ToString()); } } CountCredits(); }