public static void Create(string resultFile) { List<Egp> egps = presenterEGP.ReadEgpFromDb(); string conStr = mapViewer.GisProject.ExtraDataConnectionStr("Снимки"); //mapViewer // presenterEGP.SetSelectEgpMode(true); // mapViewer.DrawMap(); WordDocument doc = new WordDocument(); NumberFormatInfo nfi = new CultureInfo("en-US", false).NumberFormat; for (int i = 0; i < egps.Count; i++) { char[] splinChar = { '-' }; string[] km = egps[i].Name.Split(splinChar); double beginKm = 0; double endKm = 0; try { beginKm = Double.Parse(km[0], nfi); endKm = Double.Parse(km[1], nfi); } catch (Exception) { doc.CloseDocument(); doc.Close(); throw new Exception("Невозможно прочитать километры в таблице EGP"); } WordDocument tempDocument = new WordDocument(templateName, false); PictureSet pictureSet = new PictureSet(conStr); List<Picture> pictures = pictureSet.getPicturesAtIntervalOfMarks(((int)beginKm).ToString(), ((int)endKm).ToString()); DateTime pointTime = DateTime.Parse(egps[i].AppearanceTime); String longMin = egps[i].Start.Long.ToString(); String latMin = egps[i].Start.Lat.ToString(); String longMax = egps[i].End.Long.ToString(); String latMax = egps[i].End.Lat.ToString(); String reliefWidth = egps[i].MaxWidth.ToString(); String orientir = egps[i].Relief; String water = egps[i].Watering; String grass = egps[i].VegetationAbnormality; if (pictures != null) { tempDocument.ReplaceIncludePicture(1, new Uri(pictures[0].Session.Folder + "\\" + pictures[0].Name), 1); tempDocument.ReplaceVariables("DayPhoto", pictures[0].Session.Date.ToString()); tempDocument.ReplaceVariables("TimePhoto", pictures[0].Session.Date.TimeOfDay.ToString()); } else { tempDocument.ReplaceIncludePicture(1, new Uri("C:\\"), 1); tempDocument.ReplaceVariables("DayPhoto", "________"); tempDocument.ReplaceVariables("TimePhoto", "________"); } tempDocument.ReplaceVariables("PointNumber", i.ToString()); tempDocument.ReplaceVariables("description_date", pointTime.Date.ToString("dd.MM.yyyy")); tempDocument.ReplaceVariables("time", pointTime.ToString("hh:mm")); tempDocument.ReplaceVariables("KmMin-KmMax", beginKm + "-" + endKm); tempDocument.ReplaceVariables("point_position1", longMin + ";" + latMin); tempDocument.ReplaceVariables("point_position2", longMax + ";" + latMax); tempDocument.ReplaceVariables("PhotoName", pictures[0].Name); tempDocument.ReplaceVariables("PhotoISN", i.ToString()); tempDocument.ReplaceVariables("EGPType", egps[i].Category.ToString()); tempDocument.ReplaceVariables("MaxWidth", reliefWidth); tempDocument.ReplaceVariables("Length", ((int)((endKm - beginKm)) * 1000).ToString()); tempDocument.ReplaceVariables("Orientir", orientir); tempDocument.ReplaceVariables("Water", water); tempDocument.ReplaceVariables("Grass", grass); doc.AddDocument(tempDocument); tempDocument.CloseDocument(); tempDocument.Close(); tempDocument.Dispose(); } doc.Save(resultFile); doc.Close(); doc.Dispose(); }
static void WriteReport() { MapObjSet objSet = MifReader.ReadMifMid(@"C:\Users\Тинкс\Documents\Visual Studio 2010\Projects\Работа\geo_reports\Source\ареалы_май_2011_final.mif"); WordDocument doc = new WordDocument(); int i = 109; StreamWriter writer = new StreamWriter("C:/noPictures.txt"); List<MapEntity> sorted = new List<MapEntity>(); foreach (MapEntity me in objSet) { sorted.Add(me); } sorted.Sort(delegate(MapEntity me1, MapEntity me2) { string kmMin1 = me1.Semantics["ISN"].ToString(); string kmMin2 = me2.Semantics["ISN"].ToString(); return (Double.Parse(kmMin1)).CompareTo(Double.Parse(kmMin2)); }); foreach (MapEntity me in sorted) { /// MapEntity me - объект, содержит географию и семантику DPoint[] p = me.Points; // точки, которые описывают географию DataRow r = me.Semantics; // строка таблицы, содержит всю семантику string pointNumber = r["ISN"].ToString(); DateTime pointTime = DateTime.Parse( r["дата_время"].ToString()); string kmMin = r["KM_MIN"].ToString(); string kmMax = r["KM_MAX"].ToString(); string picturePath = r["PhotoISN"].ToString(); string longMin = r["Long_MIN"].ToString(); string latMin = r["Lat_MIN"].ToString(); string longMax = r["Long_MAX"].ToString(); string latMax = r["Lat_MAX"].ToString(); string PhotoName = r["Фотка"].ToString(); string egp = r["ЭГП"].ToString(); int egpType = Int32.Parse( r["Тип_ЭГП"].ToString()); string reliefWidth = r["макс_ширина"].ToString(); if (reliefWidth.Length == 0) reliefWidth = " "; // string reliefLength = r["протяженность"].ToString(); string orientir = r["напр_измен_границ"].ToString(); string water = r["обводнение"].ToString(); string grass = r["нарушен_растительности"].ToString(); if (!File.Exists((Path.Combine("L:\\Photo_ЭГП", picturePath + ".jpg")))) { // writer.WriteLine(picturePath + " " + PhotoName); continue; } if (egpType == 1 || egpType == 2 || egpType == 3 || egpType == 4 || egpType == 5 || egpType == 6 || egpType == 7 || egpType == 8 || egpType == 9 || egpType == 11 || egpType == 12 || egpType == 20 || egpType == 22 || egpType == 26 ) { WordDocument tempDocument = new WordDocument(@"C:\Users\Тинкс\Documents\Visual Studio 2010\Projects\Работа\geo_reports\Source\GeoReports\WordTemplates\Приложение Ж.dotx", false); tempDocument.ReplaceVariables("PointNumber", pointNumber); tempDocument.ReplaceVariables("description_date", pointTime.Date.ToString("dd.MM.yyyy")); tempDocument.ReplaceVariables("time", pointTime.ToString("hh:mm")); tempDocument.ReplaceVariables("KmMin-KmMax", kmMin + "-" + kmMax); tempDocument.ReplaceVariables("point_position1", longMin + ";" + latMin); tempDocument.ReplaceVariables("point_position2", longMax + ";" + latMax); tempDocument.ReplaceVariables("PhotoName", PhotoName); tempDocument.ReplaceVariables("PhotoISN", picturePath); tempDocument.ReplaceVariables("EGPType", egp); tempDocument.ReplaceVariables("MaxWidth", reliefWidth); tempDocument.ReplaceVariables("Length", ((int)((Double.Parse(kmMax) - Double.Parse(kmMin))*1000)).ToString()); tempDocument.ReplaceVariables("Orientir", orientir); tempDocument.ReplaceVariables("Water", water); tempDocument.ReplaceVariables("Grass", grass); if (Double.Parse(kmMax) < 200) { tempDocument.ReplaceVariables("Sorname", "Макарычева Л."); tempDocument.ReplaceVariables("Proff", "Инженер-исследователь"); } else if (Double.Parse(kmMax) < 450) { tempDocument.ReplaceVariables("Sorname", "Разумец М."); tempDocument.ReplaceVariables("Proff", "Инженер-исследователь"); } else if (Double.Parse(kmMax) < 960) { tempDocument.ReplaceVariables("Sorname", "Смирнова Л."); tempDocument.ReplaceVariables("Proff", "Инженер-исследователь"); } else if (Double.Parse(kmMax) < 1567) { tempDocument.ReplaceVariables("Sorname", "Разумец М."); tempDocument.ReplaceVariables("Proff", "Инженер-исследователь"); } else if (Double.Parse(kmMax) < 2300) { tempDocument.ReplaceVariables("Sorname", "Смирнова Л."); tempDocument.ReplaceVariables("Proff", "Инженер-исследователь"); } else { tempDocument.ReplaceVariables("Sorname", "Халилова Ю."); tempDocument.ReplaceVariables("Proff", "м.н.с."); } tempDocument.ReplaceIncludePicture(1, new Uri(Path.Combine("L:\\Photo_ЭГП", picturePath + ".jpg")), 1); doc.AddDocument(tempDocument); tempDocument.CloseDocument(); tempDocument.Close(); tempDocument.Dispose(); } } doc.Save("C:\\result.doc"); doc.Close(); doc.Dispose(); }