private void toolStripMenuItem1_Click(object sender, EventArgs e) { SaveFileDialog sf = new SaveFileDialog(); if (sf.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string path = sf.FileName.ToString(); OutPutFile outPutFile = new OutPutFile(); MrDataShow mrDataShow = new MrDataShow(); MRTableList mRTableList = new MRTableList(); DataTable dt2 = new DataTable(); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } foreach (TreeNode item in treeView1.Nodes) { foreach (TreeNode item2 in item.Nodes) { string name = item2.Text; mRTableList.tabletype = item.Text; mRTableList.tableName = item2.Text; dt2 = mrDataShow.GetTableData(mRTableList); dt2.TableName = item.Name + "-" + item2.Text; string str = outPutFile.SaveCSV(dt2, string.Format("{0}//{1}.csv", path, dt2.TableName)); } } MessageBox.Show("导出成功!", "提示"); } }
private void 导出结果ToolStripMenuItem_Click(object sender, EventArgs e) { SaveFileDialog sf = new SaveFileDialog(); sf.FileName = dt.TableName; if (sf.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (dt == null) { MessageBox.Show("请选中相应的表"); } else { string path = sf.FileName.ToString() + ".csv"; OutPutFile outPutFile = new OutPutFile(); string str = outPutFile.SaveCSV(dt, path); if (str != null) { MessageBox.Show(str, "提示"); } else { MessageBox.Show("导出成功!", "提示"); } } } }
private void btnExcel_Click(object sender, EventArgs e) { // ToExcel(grid); DataTable dt = (DataTable)grid.DataSource; OutPutFile outputfile = new OutPutFile(); SaveFileDialog sf = new SaveFileDialog(); if (sf.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (dt == null) { MessageBox.Show("请选中相应的表"); } else { string path = sf.FileName.ToString() + ".csv"; OutPutFile outPutFile = new OutPutFile(); string str = outPutFile.SaveCSV(dt, path); if (str != null) { MessageBox.Show(str, "提示"); } else { MessageBox.Show("导出成功!", "提示"); } } } }
private void 导出全部文件ToolStripMenuItem_Click(object sender, EventArgs e) { SaveFileDialog sf = new SaveFileDialog(); if (sf.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (SingletonPMData.pmAllMd == null || SingletonPMData.pmAllMd.Count == 0) { MessageBox.Show("全部表数据为空"); } else { string path = sf.FileName.ToString(); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } foreach (DataTable item in dbset.Tables) { OutPutFile outPutFile = new OutPutFile(); outPutFile.SaveCSV(item, string.Format("{0}//{1}.csv", path, item.TableName)); } } } MessageBox.Show("全部数据导出完成"); }
static void Main(string[] args) { try { TrafficLights TrafficLights = ReadInputFile(path + fileName); OutPutFile outPutFile = new OutPutFile(); outPutFile = ScheduleIntersection(TrafficLights); WriteOutputFile(outPutFile); } catch (Exception exc) { Console.WriteLine(exc.Message); } }
private static void WriteOutputFile(OutPutFile outPut) { string createText = outPut.NumIntersectionHasSchedule + Environment.NewLine; foreach (var op in outPut.intersectionSchedules) { createText += op.IntersectionID + Environment.NewLine + op.NumberncomingOfStreets + Environment.NewLine; foreach (var abc in op.orderNDurationGreenLights) { createText += abc.StreetName + " " + abc.GreenSeconds + Environment.NewLine; } } File.WriteAllText(path + fileName + "_Output.txt", createText); }
private static OutPutFile ScheduleIntersection(TrafficLights trafficLights) { OutPutFile outPutFile = new OutPutFile(); List <IntersectionSchedule> intersectionScheduleList = new List <IntersectionSchedule>(); int intersections = trafficLights.NumOfIntersection; int streets = trafficLights.NumOfStreets; int cars = trafficLights.NumOfCars; var UniqueIntersections = trafficLights.streets.Select(p => p.IntersectionEndStreet).Distinct().ToList(); for (int i = 0; i < UniqueIntersections.Count; i++) { bool intersectionNotUsed = false; int currentIntersection = UniqueIntersections[i]; var allcarPaths = trafficLights.carPaths; var allStreets = trafficLights.streets.Where(p => p.IntersectionEndStreet == currentIntersection).ToList(); IntersectionSchedule intersectionSchedule = new IntersectionSchedule(); intersectionSchedule.NumberncomingOfStreets = 0; intersectionSchedule.NumberncomingOfStreets = allStreets.Count; intersectionSchedule.IntersectionID = currentIntersection; foreach (var street in allStreets) { var beginStreet = allcarPaths.Where(p => p.StreetName.IndexOf(street.StreetName) == 0).ToList(); var endStreet = allcarPaths.Where(p => p.StreetName.IndexOf(street.StreetName) == p.StreetName.Count - 1).ToList(); if (beginStreet.Count == 0 && endStreet.Count == allStreets.Count) { intersectionNotUsed = true; } if (intersectionNotUsed) { intersectionSchedule = null; continue; } //for (int j = 0; j < cars; j++) //{ // var path = trafficLights.carPaths[j]; // var firstStreetName = path.StreetName[0]; var currentStreet = street;// trafficLights.streets.Where(p => p.StreetName == firstStreetName).FirstOrDefault(); //var intersectionStreets = trafficLights.streets.Where(p => p.IntersectionEndStreet == intersectionSchedule.IntersectionID).ToList(); // || p.IntersectionStartStreet == intersectionSchedule.IntersectionID //foreach (var istreet in intersectionStreets) { OrderNDurationGreenLight orderNDurationGreenLight = new OrderNDurationGreenLight(); orderNDurationGreenLight.StreetName = currentStreet.StreetName; //second + 1 for car passing int isStartofPath = 0; foreach (var carPath in allcarPaths) { if (carPath.StreetName[0] == currentStreet.StreetName) { isStartofPath = 1; } } //orderNDurationGreenLight.GreenSeconds = currentStreet.TimeStartEndStreet + isStartofPath; orderNDurationGreenLight.GreenSeconds = 1 + isStartofPath; intersectionSchedule.orderNDurationGreenLights.Add(orderNDurationGreenLight); } //} } if (intersectionSchedule != null) { intersectionSchedule.orderNDurationGreenLights = intersectionSchedule.orderNDurationGreenLights.OrderByDescending(p => p.GreenSeconds).ToList(); intersectionScheduleList.Add(intersectionSchedule); intersectionScheduleList = intersectionScheduleList.OrderByDescending(p => p.NumberncomingOfStreets).ToList(); decimal IntersectionPercentage = (decimal)intersectionScheduleList.Count / (decimal)UniqueIntersections.Count; Console.WriteLine(intersectionScheduleList.Count + " / " + UniqueIntersections.Count + " = " + IntersectionPercentage); } } outPutFile.intersectionSchedules = intersectionScheduleList; outPutFile.NumIntersectionHasSchedule = intersectionScheduleList.Count; return(outPutFile); }