public void Test28CellCourse() { CellCourse c1 = new CellCourse(); c1.ID = c1.ID; c1.code = c1.code; c1.originalName = c1.originalName; c1.name = c1.name; c1.c_hour = c1.c_hour; c1.section = c1.section; c1.venue = c1.venue; c1.timeFrom = c1.timeFrom; c1.timeTo = c1.timeTo; c1.semester = c1.semester; c1.day = c1.day; }
public bool generate(String pathPlusName, String path0) { bool labTime = false; // if 1 hour course lies under lab tab, then find correct time bool dateFound = false; Form1 frm = new Form1(); int num = 78; String day = ""; // to store course's day for (int i = 1; i <= rowCount; i++) { for (int j = 1; j <= colCount; j++) { try { // if this (x,y) cell is present && has some value inside it if (xlRange.Cells[i, j] != null && xlRange.Cells[i, j].Value2 != null) { String cellData = xlWorksheet.Cells[i, j].Value2.ToString(); // Console.WriteLine("(" + i + "," + j + ")" + cellData + "\t"); // if data is a number (date converted to a serial no. ) && (serial no length must be 5 to be date) if (dateFound == false && int.TryParse(cellData, out num) && (cellData).Length == 5) { // Console.WriteLine("(" + i + "," + j + ")" + cellData + "\t"); cellData = FromExcelSerialDate(Convert.ToInt32(cellData)); // Console.WriteLine("(" + i + "," + j + ")" + cellData + "\t"); cellData = dateChanger(cellData); //Console.WriteLine("(" + i + "," + j + ")" + cellData + "\t"); date = cellData; dateFound = true; continue; } else { // Console.WriteLine("(" + i + "," + j + ")" + cellData + "\t"); if (clearStrings(cellData).ToUpper() == "Venue".ToUpper()) // stores the location of Venue, for furthure loop work { venueCol = j; continue; } if (j == venueCol) // if venue column { continue; } // Store the day if (cellData == days[0] || cellData == days[1] || cellData == days[2] || cellData == days[3] || cellData == days[4] || cellData == days[5]) { day = cellData; frm.label3.Text = "Finding classes on " + day; labTime = false; // sets it to false at every new day start continue; } if (clearStrings(cellData).ToUpper() == "Labs".ToUpper()) { labTime = true; continue; } //<-----------------------------------------FINDING NAME-----------------------------------------------> // Console.WriteLine("1"); CellCourse temp = new CellCourse(); int returnedNo = isACourse(cellData); if (returnedNo == -1) // not a course (w.r.t our D.B) { continue; } else { temp.code = getCode(returnedNo); temp.originalName = getoriginalName(returnedNo); temp.name = getName(returnedNo); temp.section = getSection(returnedNo); temp.c_hour = getC_Hour(returnedNo); temp.semester = getSemester(returnedNo); // Console.WriteLine("(" + i + "," + j + ")" + cellData + "\t\t" + temp.name+"("+temp.section+")"); } // Console.WriteLine("2"); //<-----------------------------------------SETTING DAY------------------------------------------------> temp.day = day; // Console.WriteLine("3"); //<-----------------------------------------FINDING VENUE----------------------------------------------> if (isVenueInCell(cellData) == 1) { temp.venue = getVenue1(cellData); // ROOM } else if (isVenueInCell(cellData) == 2) { temp.venue = getVenue2(cellData); // R# } else { // Console.WriteLine(xlWorksheet.Cells[i, 2].Value2.ToString()); temp.venue = xlWorksheet.Cells[i, venueCol].Value2.ToString(); // Console.WriteLine("3b"); } // Console.WriteLine("4"); //<-----------------------------------------FINDING TIME-----------------------------------------------> if (timeInCell(cellData)) { String time = extractTime(cellData); time = removeAMsPMs(time); if (time.Contains("-")) { String[] arrTime = time.Split('-'); arrTime[0] = addZeros(arrTime[0]); // add missing zeros arrTime[1] = addZeros(arrTime[1]); temp.timeFrom = arrTime[0]; temp.timeTo = arrTime[1]; } else if (time.ToLower().Contains("to")) { String[] arrTime = time.ToLower().Split('t'); arrTime[1] = arrTime[1].Substring(1, arrTime[1].Length - 1); arrTime[0] = addZeros(arrTime[0]); arrTime[1] = addZeros(arrTime[1]); temp.timeFrom = arrTime[0]; temp.timeTo = arrTime[1]; } else { Console.WriteLine("\nTime Parsing Error in cell = " + cellData); } // Console.WriteLine(temp.timeFrom+"-"+temp.timeTo+"--->"+cellData); } else // time is in proper place (in top time row) { for (int c = i; c > 0; c--) { // finds the time and day missElse36: if (xlRange.Cells[c, j] != null && xlRange.Cells[c, j].Value2 != null && isTime(xlWorksheet.Cells[c, j].Value2.ToString())) { // if under lab tab, find suitable time String gj = cellData.ToUpper(); if (labTime && !gj.Contains("LAB")) {// difference should be 1 hour, as its a class, not a lab /* if (differenceIs1(xlWorksheet.Cells[c, j].Value2.ToString())) * { * * String gh = xlRange.Cells[c, j].Value2.ToString().Replace(" ", String.Empty); * String[] tu = gh.Split('-'); * temp.timeFrom = tu[0]; * temp.timeTo = tu[1]; * * break; * } */ c--; goto missElse36; } // display found time displays venue else { String gh = xlRange.Cells[c, j].Value2.ToString().Replace(" ", String.Empty); String[] tu = gh.Split('-'); temp.timeFrom = tu[0]; temp.timeTo = tu[1]; break; } } } } // Console.WriteLine("5"); dailyClasses.Add(temp); Console.Write("(" + i + "," + j + ")" + cellData + "\t\t" + temp.name + "(" + temp.section + ")"); Console.WriteLine("\t\t" + temp.originalName + "\t\t" + temp.venue + "\t\t" + temp.timeFrom + "-" + temp.timeTo + ", " + temp.day + ", " + temp.c_hour); } } // if } catch (Exception er) { Console.WriteLine(er); } } // for } // for try { // generate filenames to write data and errors String errorFile = path0; String writeFile = path0; for (int a = 0; a < pathPlusName.Length; a++) { if (pathPlusName[a] == '.') { break; } if (a >= path0.Length) { errorFile += pathPlusName[a]; writeFile += pathPlusName[a]; } } errorFile += "_error_log.txt"; writeFile += ".txt"; /* using (StreamWriter write1 = new StreamWriter(errorFile)) * { } * * frm.label3.Text = "Done Finding"; * * using (StreamWriter write = new StreamWriter(writeFile)) * { * for (int a = 0; a < dailyClasses.Count; a++) * { * String dumm = dailyClasses[a].timeFrom + "-" + dailyClasses[a].timeTo; * if (dumm.Length != 11) * { * using (StreamWriter write1 = new StreamWriter(errorFile, true)) * { * write1.Write((a + 1) + "," + dailyClasses[a].code + "," + dailyClasses[a].originalName + "," + dailyClasses[a].name + "," + dailyClasses[a].section + "," + dailyClasses[a].c_hour + ","); * write1.Write(dailyClasses[a].venue + "," + dailyClasses[a].timeFrom + "-" + dailyClasses[a].timeTo + "," + dailyClasses[a].day + "," + dailyClasses[a].semester + "\n"); * } * * } * write.Write((a + 1) + "," + dailyClasses[a].code + "," + dailyClasses[a].originalName + "," + dailyClasses[a].name + "," + dailyClasses[a].section + "," + dailyClasses[a].c_hour + ","); * write.Write(dailyClasses[a].venue + "," + dailyClasses[a].timeFrom + "-" + dailyClasses[a].timeTo + "," + dailyClasses[a].day + "," + dailyClasses[a].semester + "\n"); * } * } * */ close(); return(true); } catch (Exception er) { Console.WriteLine(er); close(); return(true); } }