Form1.cs 258 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982
  1. using Aspose.Words;
  2. using Aspose.Words.Tables;
  3. using DAL;
  4. using Models;
  5. using Newtonsoft.Json.Linq;
  6. using OA2014.publicCode;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.ComponentModel;
  10. using System.Configuration;
  11. using System.Data;
  12. using System.Drawing;
  13. using System.IO;
  14. using System.Linq;
  15. using System.Security.Cryptography;
  16. using System.Text;
  17. using System.Text.RegularExpressions;
  18. using System.Threading.Tasks;
  19. using System.Web;
  20. using System.Web.UI.WebControls.WebParts;
  21. using System.Web.Util;
  22. using System.Windows.Forms;
  23. using System.Xml.Linq;
  24. namespace WinTools
  25. {
  26. public partial class OPTravelListOutput : Form
  27. {
  28. //团组信息DAL
  29. DelegationInfoService dis = new DelegationInfoService();
  30. //三字码DAL
  31. ThreeCodeServices tcs = new ThreeCodeServices();
  32. //航司缩写DAL
  33. AirCompanyServcies acs = new AirCompanyServcies();
  34. //车导地接DAL
  35. CarTouristGuideGroundReservationsService ctgs = new CarTouristGuideGroundReservationsService();
  36. //车导地接详情DAL
  37. CarTouristGuideGroundReservationsContentService ctgss = new CarTouristGuideGroundReservationsContentService();
  38. //公务
  39. OfficialActivitiesService oas = new OfficialActivitiesService();
  40. //酒店信息DAL
  41. HotelReservationsService htrs = new HotelReservationsService();
  42. //行程详情DAL
  43. TravelDetailsService tds = new TravelDetailsService();
  44. //行程单DAL
  45. TravelListService tls = new TravelListService();
  46. //谷歌地图接口结果DAL
  47. GoogleMapApiResultService gmrs = new GoogleMapApiResultService();
  48. string[] weekdays = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
  49. public OPTravelListOutput()
  50. {
  51. InitializeComponent();
  52. }
  53. private void Form1_Load(object sender, EventArgs e)
  54. {
  55. comb_Delegation.ValueMember = "Id";
  56. comb_Delegation.DisplayMember = "TeamName";
  57. comb_Delegation.DataSource = dis.GetAll();
  58. }
  59. private void btnOutput_Click(object sender, EventArgs e)
  60. {
  61. lblOutputResult.Text = "文件正在导出...";
  62. lblOutputResult.ForeColor = Color.Black;
  63. //数据源
  64. List<TravelList> _travelList = new List<TravelList>();
  65. int diid = (int)comb_Delegation.SelectedValue;
  66. DataTable dtBlack = PublicCode.GetTableByBlackCode(diid);
  67. DelegationInfo di = dis.GetDelegationInfoByID(diid);
  68. string CityStr1 = "";
  69. List<string> countriesList = new List<string>();
  70. List<string> cityList = new List<string>();
  71. string countriesIntroduction = "";
  72. string cityIntroduction = "";
  73. string timeDifference = "";
  74. string currExchangeRate = "";
  75. string txt_itemPrepare = "";
  76. string txt_specialReminder = "";
  77. string txt_cGPrecautions = "";
  78. string txt_yGCG = "";
  79. string txt_conduct = "";
  80. string txt_commonEnglish = "";
  81. if (dtBlack == null && (dtBlack.Rows[0]["Day"] == null || dtBlack.Rows[0]["Day"].ToString() == ""))
  82. {
  83. //提示
  84. //PublicCode.GetAlertMsg(this, GetType(), dt.Rows[dt.Rows.Count - 1]["Error"].ToString());
  85. }
  86. else
  87. {
  88. //创建三字码示例
  89. ThreeCode t = new ThreeCode();
  90. //城市缓存
  91. string city = "";
  92. //出访城市
  93. for (int i = 0; i < dtBlack.Rows.Count; i++)
  94. {
  95. if ((i + 1) < dtBlack.Rows.Count && dtBlack.Rows[i]["Three"].ToString() == dtBlack.Rows[i + 1]["Three"].ToString())
  96. {
  97. continue;
  98. }
  99. if (dtBlack.Rows.Count > 0 && (dtBlack.Rows[i]["Three"].ToString() != null && dtBlack.Rows[i]["Three"].ToString() != ""))
  100. {
  101. //出发城市
  102. string cityTemp = dtBlack.Rows[i]["Three"].ToString().Replace("/", string.Empty).Substring(0, 3);
  103. t = tcs.getByThree(cityTemp);
  104. if (t != null)
  105. {
  106. city = city + "/" + t.City;
  107. }
  108. else
  109. {
  110. city = city + "/【" + cityTemp + "未收录,请联系机票同事录入】";
  111. }
  112. if (i == dtBlack.Rows.Count - 1)
  113. {
  114. //抵达城市
  115. cityTemp = dtBlack.Rows[i]["Three"].ToString().Replace("/", string.Empty).Substring(3, 3);
  116. t = tcs.getByThree(cityTemp);
  117. if (t != null)
  118. {
  119. city = city + "/" + t.City;
  120. }
  121. else
  122. {
  123. city = city + "/【" + cityTemp + "未收录,请联系机票同事录入】";
  124. }
  125. }
  126. }
  127. }
  128. if (city != "" && city != null)
  129. {
  130. string[] cityStr2 = city.Split('/');
  131. string[] strs = cityStr2.Distinct().ToArray(); ;
  132. string str = "";
  133. foreach (var s in strs)
  134. {
  135. str += s + "/";
  136. }
  137. str = str.TrimStart('/');
  138. str = str.TrimEnd('/');
  139. //lblTourCity.Text = "去重前:" + city.TrimStart('/') + "\n 去重后:" + str;
  140. CityStr1 = city.TrimStart('/');
  141. }
  142. opitineraryService opitservice = new opitineraryService();
  143. //城市不为空
  144. if (!string.IsNullOrEmpty(city))
  145. {
  146. cityList = city.TrimStart('/').Split('/').ToList();
  147. if (cityList.Count > 1)
  148. {
  149. cityList.RemoveAt(0);
  150. }
  151. opitinerarydata cityData = opitservice.getDaFirstData(cityList[0]);
  152. cityIntroduction = cityData.Introduction;
  153. timeDifference = cityData.TimeDifference;
  154. currExchangeRate = cityData.CurrExchangeRate.ToString();
  155. }
  156. //国家不为空
  157. if (!string.IsNullOrEmpty(di.VisitCountry))
  158. {
  159. countriesList = di.VisitCountry.Split(' ').ToList();
  160. opitinerarydata Country = opitservice.getDaFirstData(countriesList[0]);
  161. countriesIntroduction = Country.Introduction == null ? "" : Country.Introduction;
  162. }
  163. //取出固定标语
  164. opitineraryfixed fixedData = opitservice.getFiFirstData();
  165. //if (!string.IsNullOrEmpty(fixedData.Tid.ToString()))
  166. //{
  167. //}
  168. txt_cGPrecautions = fixedData.CGPrecautions;
  169. txt_commonEnglish = fixedData.CommonEnglish;
  170. txt_conduct = fixedData.Conduct;
  171. txt_itemPrepare = fixedData.ItemPrepare;
  172. txt_specialReminder = fixedData.SpecialReminder;
  173. txt_yGCG = fixedData.YGCG;
  174. // 行程repeater
  175. if (tls.GetByDiid(diid).Count > 0)
  176. {
  177. _travelList = tls.GetByDiid(diid).Where(x => x.issel == 1).ToList();
  178. }
  179. else
  180. {
  181. //生成该时间段日期
  182. List<string> timeList = PublicCode.GetTimeListByDataTable(dtBlack);
  183. if (timeList != null)
  184. {
  185. string[] str = new string[timeList.Count];
  186. //rpData.DataSource = str;
  187. //rpData.DataBind();
  188. }
  189. }
  190. }
  191. //创建数据源Table
  192. DataTable dtSource = new DataTable();
  193. dtSource.Columns.Add("Days", typeof(string));
  194. dtSource.Columns.Add("Date", typeof(string));
  195. dtSource.Columns.Add("Week", typeof(string));
  196. dtSource.Columns.Add("Traffic", typeof(string));
  197. dtSource.Columns.Add("Trip", typeof(string));
  198. //获取数据,放到datatable
  199. foreach (var item in _travelList)
  200. {
  201. DataRow dr = dtSource.NewRow();
  202. dr["Days"] = item.Days;
  203. dr["Date"] = item.Date;
  204. dr["Week"] = item.WeekDay;
  205. dr["Traffic"] = item.Traffic_First
  206. + "\r\n"
  207. + item.Traffic_Second;
  208. if (item.Trip.Replace("(此地区为黄热病地区,请注意打疫苗)","").Length < 15)
  209. {
  210. item.Trip += @"
  211. 08:00 早餐于酒店;
  212. 09:00 公务活动;
  213. 10:30 公务活动;
  214. 12:00 午餐于当地餐厅;
  215. 14:00 公务活动;
  216. 16:00 公务活动;
  217. 18:00 晚餐于当地餐厅;
  218. 19:00 入住酒店休息;";
  219. }
  220. dr["Trip"] = item.Trip;
  221. dtSource.Rows.Add(dr);
  222. }
  223. //lblTeamName.Text = di.TourCode;
  224. //lblVisitDays.Text = di.VisitDays.ToString();
  225. //lblVisitDays2.Text = di.VisitDays.ToString();
  226. //lblPNumber.Text = di.VisitPNumber.ToString();
  227. //lblGroup.Text = di.TeamName.ToString();
  228. Dictionary<string, string> dic = new Dictionary<string, string>();
  229. dic.Add("Dele", di.TeamName.ToString() + PublicCode.GetNum(di.VisitDays.ToString()));
  230. dic.Add("City", CityStr1);
  231. dic.Add("Days", di.VisitDays.ToString());
  232. dic.Add("DeleCode", di.TourCode);
  233. dic.Add("Pnum", di.VisitPNumber.ToString());
  234. dic.Add("Pnum2", di.VisitPNumber.ToString());
  235. List<DeleClient> leader = new DeleClientService().GetByDiid(di.Id);
  236. if (leader != null && leader.Count > 0)
  237. {
  238. dic.Add("Leader", new DeleClientService().GetByDiid(di.Id)[0].LastName + new DeleClientService().GetByDiid(di.Id)[0].Name);
  239. }
  240. else
  241. {
  242. dic.Add("Leader", "");
  243. }
  244. dic.Add("Pnum3", di.VisitPNumber.ToString());
  245. int UserId = int.Parse(ConfigurationManager.AppSettings["OPId"]);
  246. dic.Add("OP", new UsersService().GetUsersByID(UserId).CnName);
  247. dic.Add("OPTel", new UsersService().GetUsersByID(UserId).Phone);
  248. //dic.Add("OP", "OP姓名");
  249. //dic.Add("OPTel", "OP手机号码");
  250. string countriesStr = "";
  251. countriesList.ForEach(s => countriesStr += s + "、");
  252. countriesStr = countriesStr.TrimEnd('、');
  253. string cityStr = "";
  254. cityList.ForEach(s => cityStr += s + "、");
  255. cityStr = cityStr.TrimEnd('、');
  256. //下方数据
  257. dic.Add("selCountries", countriesStr == null ? "" : countriesStr);
  258. dic.Add("selCity", cityStr == null ? "" : cityStr);
  259. dic.Add("countriesIntroduction", countriesIntroduction == null ? "" : countriesIntroduction);
  260. dic.Add("CityIntroduction", cityIntroduction == null ? "" : cityIntroduction);
  261. dic.Add("timeDifference", timeDifference == null ? "" : timeDifference);
  262. dic.Add("currExchangeRate", currExchangeRate == null ? "" : currExchangeRate);
  263. dic.Add("temperature", "");
  264. dic.Add("txt_itemPrepare", txt_itemPrepare == null ? "" : txt_itemPrepare);
  265. dic.Add("txt_specialReminder", txt_specialReminder == null ? "" : txt_specialReminder);
  266. dic.Add("txt_cGPrecautions", txt_cGPrecautions == null ? "" : txt_cGPrecautions);
  267. dic.Add("txt_yGCG", txt_yGCG == null ? "" : txt_yGCG);
  268. dic.Add("txt_conduct", txt_conduct == null ? "" : txt_conduct);
  269. dic.Add("txt_commonEnglish", txt_commonEnglish == null ? "" : txt_commonEnglish);
  270. //模板路径
  271. string tempPath = @"C:\日行程3.docx";
  272. //载入模板
  273. Document doc = null;
  274. DocumentBuilder builder = null;
  275. try
  276. {
  277. //载入模板
  278. doc = new Document(tempPath);
  279. builder = new DocumentBuilder(doc);
  280. }
  281. catch (Exception)
  282. {
  283. //载入模板
  284. doc = new Document(@"D:\日行程3.docx");
  285. builder = new DocumentBuilder(doc);
  286. }
  287. foreach (var key in dic.Keys)
  288. {
  289. Bookmark bookmark = doc.Range.Bookmarks[key];
  290. if (bookmark!=null)
  291. {
  292. builder.MoveToBookmark(key);
  293. builder.Write(dic[key]);
  294. }
  295. }
  296. //获取word里所有表格
  297. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  298. //获取所填表格的序数
  299. Aspose.Words.Tables.Table tableOne = allTables[0] as Aspose.Words.Tables.Table;
  300. try
  301. {
  302. //循环赋值
  303. for (int i = 0; i < dtSource.Rows.Count; i++)
  304. {
  305. builder.MoveToCell(0, i + 1, 0, 0);
  306. builder.Write(dtSource.Rows[i]["Days"].ToString());
  307. builder.MoveToCell(0, i + 1, 1, 0);
  308. builder.Write(dtSource.Rows[i]["Date"].ToString() + "\r\n" + dtSource.Rows[i]["Week"].ToString());
  309. builder.MoveToCell(0, i + 1, 2, 0);
  310. builder.Write(dtSource.Rows[i]["Traffic"].ToString());
  311. var trip = dtSource.Rows[i]["Trip"].ToString();
  312. builder.MoveToCell(0, i + 1, 3, 0);
  313. builder.Write(trip);
  314. var cell = (Aspose.Words.Tables.Cell)doc.GetChild(NodeType.Cell, ((i + 2) * 4) - 1, true);
  315. var paragraphs = cell.GetChildNodes(NodeType.Paragraph, true);
  316. // 获取特定索引的段落
  317. Paragraph paragraph = (Paragraph)paragraphs[0];
  318. Run run = paragraph.Runs[0];
  319. Aspose.Words.Font font = run.Font;
  320. font.Name = "黑体";
  321. //设置双休红色
  322. cell = (Aspose.Words.Tables.Cell)doc.GetChild(NodeType.Cell, ((i + 2) * 4) - 3, true);
  323. paragraphs = cell.GetChildNodes(NodeType.Paragraph, true);
  324. paragraph = (Paragraph)paragraphs[1];
  325. if (paragraph.GetText().Contains("星期六") || paragraph.GetText().Contains("星期日"))
  326. {
  327. run = paragraph.Runs[0];
  328. font = run.Font;
  329. font.Color = Color.Red;
  330. }
  331. }
  332. }
  333. catch (Exception ex)
  334. {
  335. }
  336. //删除多余行
  337. while (tableOne.Rows.Count > 1 + dtSource.Rows.Count)
  338. {
  339. tableOne.Rows.RemoveAt(1 + dtSource.Rows.Count);//(1+dtSource.Rows.Count + 1)-1
  340. }
  341. string savePath = ConfigurationManager.AppSettings["TravelListDocSavePath"];
  342. if (!Directory.Exists(savePath))
  343. {
  344. try
  345. {
  346. Directory.CreateDirectory(savePath);
  347. }
  348. catch
  349. {
  350. }
  351. }
  352. string strFileName = savePath + di.TeamName + "出访日程.docx";
  353. try
  354. {
  355. doc.Save(strFileName, Aspose.Words.SaveFormat.Doc);
  356. lblOutputResult.Text = "文件导出完成";
  357. lblOutputResult.ForeColor = Color.Green;
  358. System.Diagnostics.Process.Start("Explorer.exe", "/select," + strFileName);
  359. }
  360. catch (Exception)
  361. {
  362. lblOutputResult.Text = "请重试!";
  363. lblOutputResult.ForeColor = Color.Green;
  364. }
  365. //doc.Save(HttpUtility.UrlEncode(strFileName, Encoding.UTF8), Aspose.Words.SaveFormat.Doc, Aspose.Words.SaveType.OpenInWord, Response);
  366. }
  367. private void btnImport_Click(object sender, EventArgs e)
  368. {
  369. lblImport.Text = "";
  370. lblImport.Text = "正在导入数据";
  371. int comb_Diid = (int)comb_Delegation.SelectedValue;
  372. int UserId = int.Parse(ConfigurationManager.AppSettings["OPId"]);
  373. //下拉框团组对象实例
  374. DelegationInfo di = dis.GetDelegationInfoByID(comb_Diid);
  375. //获取机票黑屏代码信息,生成datatable表
  376. DataTable dt = PublicCode.GetTableByBlackCode(di.Id);
  377. //通过datatable表里的第一个字段的信息来判断是否有黑屏代码
  378. //没有则提示未录入
  379. if (dt.Rows[0]["Day"] == null || dt.Rows[0]["Day"].ToString() == "")
  380. {
  381. //PublicCode.GetAlertMsg(this, GetType(), dt.Rows[dt.Rows.Count - 1]["Error"].ToString());
  382. lblImport.Text = "黑屏代码未录入";
  383. }
  384. else//成功获取黑屏代码
  385. {
  386. //根据黑屏代码生成日期段
  387. List<string> timeList = PublicCode.GetTimeListByDataTable(dt);
  388. //本团车导地接信息
  389. List<CarTouristGuideGroundReservations> listctg = ctgs.GetCarTouristGuideGroundReservationsByDIID(di.Id);
  390. //本团酒店信息
  391. List<HotelReservations> listht = htrs.GetByDIId(di.Id);
  392. //本团行程单数据
  393. List<Models.TravelList> listTravel = tls.GetByDiid(di.Id);
  394. try
  395. {
  396. if (listTravel != null && listTravel.Count > 0)//若本团已存行程,则合并/更新;同时因为机票行程的变化或行程详情的变化,会导致行程更改
  397. {
  398. if (timeList.Count > listTravel.Count)//1.改版后黑屏代码天数>已存在行程的天数
  399. {
  400. //1.1替换日期和星期
  401. for (int i = 0; i < listTravel.Count; i++)
  402. {
  403. //日期转换星期
  404. string weekday = weekdays[(int)new DateTime(
  405. Convert.ToInt32(timeList[i].Split('-')[0]),
  406. Convert.ToInt32(timeList[i].Split('-')[1]),
  407. Convert.ToInt32(timeList[i].Split('-')[2])).DayOfWeek];
  408. // 日期去掉0
  409. string monthStr = "Unknown", dayStr = "Unknown";
  410. if (!string.IsNullOrEmpty(timeList[i]))
  411. {
  412. DateTime dateTime = new DateTime();
  413. bool convertResult = DateTime.TryParse(timeList[i], out dateTime);
  414. if (convertResult)
  415. {
  416. monthStr = dateTime.Month.ToString();
  417. dayStr = dateTime.Day.ToString();
  418. }
  419. }
  420. //日期
  421. listTravel[i].Date = monthStr + "月" + dayStr + "日";
  422. //listTravel[i].Date = timeList[i].Substring(5, 2) + "月" + timeList[i].Substring(8, 2) + "日";
  423. listTravel[i].WeekDay = weekday;
  424. listTravel[i].OPer = UserId;
  425. listTravel[i].OPdate = PublicCode.GetBeijingTime().ToString("yyyy-MM-dd HH:mm:ss");
  426. listTravel[i].Isdel = 0;
  427. tls.EditTravelList(listTravel[i]);
  428. }
  429. //1.2添加未有行程
  430. //航班号标识
  431. //string flightcode_Sign = "";
  432. //三字码标识
  433. //string citycode_Sign = "";
  434. #region 城市数据 20210823 贾文滔
  435. List<PublicCode.CityInDate> CityInDateList = PublicCode.GetCityByDataTable(dt);
  436. #endregion
  437. //生成行程
  438. for (int i = listTravel.Count; i < timeList.Count; i++)
  439. {
  440. //实、例化一个temp
  441. Models.TravelList tlTemp = new Models.TravelList();
  442. //团号
  443. tlTemp.Diid = di.Id;
  444. //天数序号
  445. tlTemp.Days = i + 1;
  446. //日期
  447. tlTemp.Date = timeList[i].Substring(5, 2) + "月" + timeList[i].Substring(8, 2) + "日";
  448. //日期转换星期
  449. string weekday = weekdays[(int)new DateTime(
  450. Convert.ToInt32(timeList[i].Split('-')[0]),
  451. Convert.ToInt32(timeList[i].Split('-')[1]),
  452. Convert.ToInt32(timeList[i].Split('-')[2])).DayOfWeek];
  453. tlTemp.WeekDay = weekday;
  454. //行程
  455. string trip = "";
  456. //历经城市
  457. string city = "";
  458. #region 机票数据
  459. //根据航班信息推出抵达机场的位置信息
  460. string AirPort = "";
  461. //根据航班时间前后推进入机场或离开机场的时间
  462. string GoAirportTime = "", leaveAirPortTime = "";
  463. //飞机标识
  464. bool airSign = false;
  465. //查询该日期下的航班信息
  466. //resultRows字段顺序为:航班号,起飞日期,三字码,起飞时刻,到达时刻,出发航站楼,到达航站楼,机型,飞行时间,整理后的起飞日期,整理后的到达日期
  467. DataRow[] resultRows = dt.Select("Day like '%" + timeList[i] + "%'");
  468. if (resultRows.Count() > 0)
  469. {
  470. //修改标识
  471. airSign = true;
  472. }
  473. //同一天只有一条数据走正常判定
  474. if (resultRows.Count() == 1)
  475. {
  476. #region 三字码
  477. string _citycode = resultRows[0]["Three"].ToString();
  478. //起飞城市三字码
  479. ThreeCode font_threecode = null;
  480. string font_citycode = _citycode.Replace("/", string.Empty).Substring(0, 3);
  481. //抵达城市
  482. string font_City = "";
  483. //起飞城市机场
  484. string font_Airport = "";
  485. //抵达城市三字码
  486. ThreeCode back_threecode = null;
  487. string end_citycode = _citycode.Replace("/", string.Empty).Substring(3, 3);
  488. //抵达城市机场
  489. string back_Airport = "";
  490. //抵达城市
  491. string back_City = "";
  492. font_threecode = tcs.getByThree(font_citycode);
  493. //验证是否存在三字码
  494. if (font_threecode == null)
  495. {
  496. city = city + "【此三字码" + font_citycode + "未收录,请机票同事录入】" + "一";
  497. font_Airport = "【此三字码" + font_citycode + "未收录,请机票同事录入】";
  498. font_City = "【此三字码" + font_citycode + "未收录,请机票同事录入】";
  499. }
  500. else
  501. {
  502. city = city + "/" + font_threecode.City;
  503. font_Airport = font_threecode.AirPort;
  504. font_City = font_threecode.City; ;
  505. }
  506. back_threecode = tcs.getByThree(end_citycode);
  507. if (back_threecode == null)
  508. {
  509. city = city + "【此三字码" + end_citycode + "未收录,请机票同事录入】" + "一";
  510. back_Airport = "【此三字码" + end_citycode + "未收录,请机票同事录入】";
  511. back_City = "【此三字码" + end_citycode + "未收录,请机票同事录入】";
  512. }
  513. else
  514. {
  515. city = city + "/" + back_threecode.City;
  516. //部分黄热病国家,需要提醒打疫苗
  517. string result = PublicCode.GetCountryInfo(back_threecode.Country);
  518. if (result.Contains("3"))
  519. {
  520. city += "(此地区为黄热病地区,请注意打疫苗)";
  521. }
  522. back_Airport = back_threecode.AirPort;
  523. back_City = back_threecode.City;
  524. //查询酒店路线要用
  525. AirPort = back_threecode.AirPort;
  526. }
  527. //行程里加入城市
  528. #endregion
  529. #region 信息准备
  530. trip = city.TrimStart('/');
  531. //起飞航站楼
  532. string _StartBuilding = resultRows[0]["StartBuilding"].ToString();
  533. //转机航站楼
  534. string _EndBuilding = resultRows[0]["EndBuilding"].ToString();
  535. //起飞时刻
  536. string _startTime = resultRows[0]["StartTime"].ToString();
  537. //飞行时刻
  538. string _flightTime = resultRows[0]["FlightTime"].ToString();
  539. _flightTime = _flightTime.Contains("H") ? _flightTime.Split('H')[0] + "小时" + _flightTime.Split('H')[1].Split('M')[0] + "分钟" : _flightTime.Split('M')[0] + "分钟";
  540. //到达时刻
  541. string _endTime = resultRows[0]["EndTime"].ToString();
  542. //航班号
  543. string _flightcode = resultRows[0]["Fliagtcode"].ToString();
  544. //航司
  545. AirCompany aircompany = acs.getByShortCode(_flightcode.Substring(0, 2));
  546. string _aircompany_Name = "";
  547. if (aircompany == null)
  548. {
  549. _aircompany_Name = "【此航司" + resultRows[0]["Fliagtcode"].ToString().Substring(0, 2) + "未收录,请机票同事录入】";
  550. }
  551. else
  552. {
  553. _aircompany_Name = aircompany.CnName;
  554. }
  555. //机型判断
  556. string airModel = resultRows[0]["AirModel"].ToString();
  557. airModel = PublicCode.GetLonger(airModel.Substring(0, 1)) + airModel;
  558. #endregion
  559. #region trip编辑
  560. //若本行抵达时间包含"+1",则本行为母版行,仅提示登机
  561. if (resultRows[0]["Sign"].ToString() == "0" && _endTime.Contains("+"))
  562. {
  563. //根据航班信息推算进入机场的时间
  564. int temp = Convert.ToInt32(_startTime.Substring(0, 2)) - 2;//一般提前提前两小时
  565. string result = PublicCode.GetCountryInfo(back_threecode.Country);//美国或者欧洲国家提前三小时
  566. if (result.Contains("2"))
  567. {
  568. temp = Convert.ToInt32(_startTime.Substring(0, 2)) - 3;//提前3小时
  569. }
  570. if (temp < 0)
  571. {
  572. temp = temp + 24;
  573. }
  574. GoAirportTime = temp < 10 ? "0" + temp.ToString() : temp.ToString();
  575. GoAirportTime = GoAirportTime + ":" + _startTime.Substring(2, _startTime.Length - 2);
  576. //第一天之后的行程可以加上“酒店出发到机场”的距离和时间
  577. if (i > 0)
  578. {
  579. #region 酒店
  580. foreach (HotelReservations h in listht)
  581. {
  582. if (Convert.ToDateTime(h.CheckInDate) < Convert.ToDateTime(timeList[i])
  583. && Convert.ToDateTime(h.CheckOutDate) > Convert.ToDateTime(timeList[i]))
  584. {
  585. //利用谷歌API计算路线
  586. if (AirPort != "")
  587. {
  588. GoogleMapApiResult g = gmrs.GetByDiidAddress(di.Id, h.HotelAddress, font_Airport);
  589. if (g != null)
  590. {
  591. //计算“酒店到机场”的时间
  592. string CheckoutHotelTime;
  593. //处理时间格式
  594. string hours = "", mins = "";
  595. if (g.Time.Contains("hour"))
  596. {
  597. g.Time = g.Time.Replace("hour", "h");
  598. }
  599. else if (g.Time.Contains("hours"))
  600. {
  601. g.Time = g.Time.Replace("hours", "h");
  602. }
  603. g.Time = g.Time.Replace("mins", "m");
  604. if (g.Time.Contains("h"))
  605. {
  606. hours = g.Time.Split('h')[0].Trim();
  607. }
  608. else if (!g.Time.Contains("h"))
  609. {
  610. mins = g.Time.Split('m')[0].Trim();
  611. }
  612. int hour = Convert.ToInt32(GoAirportTime.Substring(0, 2));
  613. int min = Convert.ToInt32(GoAirportTime.Substring(3, 2));
  614. min = min - Convert.ToInt32(mins);
  615. if (min < 0)
  616. {
  617. min = min + 60;
  618. hour = hour - 1;
  619. }
  620. if (hours != "")
  621. {
  622. hour = hour - Convert.ToInt32(hours);
  623. }
  624. if (hour < 0)
  625. {
  626. hour = hour + 24;
  627. }
  628. CheckoutHotelTime = hour < 10 ? "0" + hour.ToString() : hour.ToString();
  629. CheckoutHotelTime = CheckoutHotelTime + ":" + (min < 10 ? "0" + min.ToString() : min.ToString());
  630. trip = trip + "\r\n"
  631. + CheckoutHotelTime + " 乘车前往机场:(" + g.Distance + "," + g.Time + ")";
  632. }
  633. else
  634. {
  635. try
  636. {
  637. JObject Result = PublicCode.GetDirectionByGoogleApi(h.HotelAddress, font_Airport);
  638. //计算“抵达酒店办理入住手续”的时间
  639. string CheckoutHotelTime;
  640. //处理时间格式
  641. string Gtime = "", hours = "", mins = "";
  642. if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hour"))
  643. {
  644. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hour", "h");
  645. }
  646. else if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hours"))
  647. {
  648. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hours", "h");
  649. }
  650. Gtime = Gtime.Replace("mins", "m");
  651. if (!string.IsNullOrEmpty(Gtime) && Gtime.Contains("h"))
  652. {
  653. hours = Gtime.Split('h')[0].Trim();
  654. }
  655. else if (!string.IsNullOrEmpty(Gtime) && !Gtime.Contains("h"))
  656. {
  657. mins = Gtime.Split('m')[0].Trim();
  658. }
  659. int hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  660. int min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  661. min = min - Convert.ToInt32(mins);
  662. if (min < 0)
  663. {
  664. min = min + 60;
  665. hour = hour - 1;
  666. }
  667. if (hours != "")
  668. {
  669. hour = hour + Convert.ToInt32(hours);
  670. }
  671. if (hour < 0)
  672. {
  673. hour = hour + 24;
  674. }
  675. CheckoutHotelTime = hour < 10 ? "0" + hour.ToString() : hour.ToString();
  676. CheckoutHotelTime = CheckoutHotelTime + ":" + (min < 10 ? "0" + min.ToString() : min.ToString());
  677. trip = trip + "\r\n"
  678. + CheckoutHotelTime + " 乘车前往机场:(" + g.Distance + "," + g.Time + ")";
  679. GoogleMapApiResult gtemp = new GoogleMapApiResult();
  680. gtemp.Diid = di.Id;
  681. gtemp.Date = "";
  682. gtemp.Moment = "";
  683. gtemp.StartAddress = AirPort;
  684. gtemp.EndAddress = h.HotelAddress;
  685. gtemp.Time = Result["routes"][0]["legs"][0]["duration"]["text"].ToString();
  686. gtemp.Distance = Result["routes"][0]["legs"][0]["distance"]["text"].ToString();
  687. gmrs.Add(gtemp);
  688. }
  689. catch
  690. {
  691. trip = trip + "\r\n"
  692. + " 乘车前往机场:(谷歌接口异常,无法测算的路程时间)";
  693. }
  694. }
  695. }
  696. }
  697. }
  698. #endregion
  699. }
  700. //行程
  701. trip = trip
  702. + "\r\n" + GoAirportTime + " 抵达" + font_Airport + _StartBuilding + "航站楼,办理登机手续:"
  703. + "\r\n" + _startTime.Substring(0, 2) + ":" + _startTime.Substring(2, _startTime.Length - 2) + " 搭乘" + _aircompany_Name + "航空公司" + _flightcode + "航班,由" + font_City + "飞往" + back_City + ";"
  704. + "\r\n" + " (" + font_Airport + "/" + back_Airport + " 机型:" + airModel + " 飞行时间" + (_flightTime) + ");";
  705. //标记本行为母版行
  706. //flightcode_Sign = resultRows[0]["Fliagtcode"].ToString();
  707. //citycode_Sign = resultRows[0]["Three"].ToString();
  708. }
  709. //与前一行航班号,三字码相同且本行抵达时间不包含"+1",则本行是被生成的重复行,仅提示抵达
  710. else if (resultRows[0]["Sign"].ToString() == "1") /* && (!_endTime.Contains("+"))&&(_flightcode == flightcode_Sign)&&(_citycode == citycode_Sign)*/
  711. {
  712. //行程
  713. trip = trip
  714. + "\r\n" + _endTime.Substring(0, 2) + ":" + _endTime.Substring(2, _endTime.Length - 2) + " 抵达" + back_Airport + _EndBuilding + "航站楼,办理入境手续,之后前往提取行李";
  715. //根据航班信息推算离开机场的时间
  716. int temp = Convert.ToInt32(_endTime.Substring(0, 2)) + 1;
  717. leaveAirPortTime = temp < 10 ? "0" + temp.ToString() : temp.ToString();
  718. leaveAirPortTime = leaveAirPortTime + ":" + _endTime.Substring(2, _endTime.Length - 2);
  719. if (i == timeList.Count - 1)//如果本日是行程的最后一天,则提醒“行程圆满结束”
  720. {
  721. trip = trip + " ,圆满结束此次访问之行!";
  722. }
  723. else //如果本日不是行程的最后一天,正常提醒
  724. {
  725. //trip += pushTrip(leaveAirPortTime, back_Airport, city,out leaveAirPortTime);
  726. trip = trip + ";\r\n" + leaveAirPortTime + " 搭乘专车前往酒店,抵达后办理入住;";
  727. }
  728. //整理离开机场的时间 +10分钟为"乘车前往酒店"的时刻
  729. int hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  730. int min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  731. min = min + 10;
  732. if (min > 59)
  733. {
  734. min = min - 60;
  735. hour = hour + 1;
  736. }
  737. if (hour > 23)
  738. {
  739. hour = hour - 24;
  740. }
  741. leaveAirPortTime = hour < 10 ? "0" + hour.ToString() : hour.ToString();
  742. leaveAirPortTime = leaveAirPortTime + ":" + (min < 10 ? "0" + min.ToString() : min.ToString());
  743. }
  744. //正常提示
  745. else
  746. {
  747. //根据航班信息推算进入机场的时间
  748. int temp = Convert.ToInt32(_startTime.Substring(0, 2)) - 2;//一般提前提前2小时
  749. string result = PublicCode.GetCountryInfo(back_threecode.Country);//美国或者欧洲国家提前3小时
  750. if (result.Contains("2"))
  751. {
  752. temp = Convert.ToInt32(_startTime.Substring(0, 2)) - 3;//提前3小时
  753. }
  754. if (temp < 0)
  755. {
  756. temp = temp + 24;
  757. }
  758. GoAirportTime = temp < 10 ? "0" + temp.ToString() : temp.ToString();
  759. GoAirportTime = GoAirportTime + ":" + _startTime.Substring(2, _startTime.Length - 2);
  760. //根据航班信息推算离开机场的时间
  761. temp = Convert.ToInt32(_endTime.Substring(0, 2)) + 1;
  762. leaveAirPortTime = temp < 10 ? "0" + temp.ToString() : temp.ToString();
  763. leaveAirPortTime = leaveAirPortTime + ":" + _endTime.Substring(2, _endTime.Length - 2);
  764. //第一天之后的行程可以加上“酒店出发到机场”的距离和时间
  765. if (i > 0)
  766. {
  767. #region 酒店
  768. foreach (HotelReservations h in listht)
  769. {
  770. if (Convert.ToDateTime(h.CheckInDate) < Convert.ToDateTime(timeList[i])
  771. && Convert.ToDateTime(h.CheckOutDate) >= Convert.ToDateTime(timeList[i]))
  772. {
  773. //利用谷歌API计算路线
  774. if (AirPort != "")
  775. {
  776. GoogleMapApiResult g = gmrs.GetByDiidAddress(di.Id, h.HotelAddress, font_Airport);
  777. if (g != null)
  778. {
  779. //计算“酒店到机场”的时间
  780. string CheckoutHotelTime;
  781. //处理时间格式
  782. string hours = "0", mins = "0";
  783. if (g.Time.Contains("hour"))
  784. {
  785. g.Time = g.Time.Replace("hour", "h");
  786. }
  787. else if (g.Time.Contains("hours"))
  788. {
  789. g.Time = g.Time.Replace("hours", "h");
  790. }
  791. g.Time = g.Time.Replace("mins", "m");
  792. if (g.Time.Contains("h"))
  793. {
  794. hours = g.Time.Split('h')[0].Trim();
  795. }
  796. else if (!g.Time.Contains("h"))
  797. {
  798. mins = g.Time.Split('m')[0].Trim();
  799. }
  800. int _hour = Convert.ToInt32(GoAirportTime.Substring(0, 2));
  801. int _min = Convert.ToInt32(GoAirportTime.Substring(3, 2));
  802. _min = _min - Convert.ToInt32(mins);
  803. if (_min < 0)
  804. {
  805. _min = _min + 60;
  806. _hour = _hour - 1;
  807. }
  808. if (hours != "")
  809. {
  810. _hour = _hour - Convert.ToInt32(hours);
  811. }
  812. if (_hour < 0)
  813. {
  814. _hour = _hour + 24;
  815. }
  816. CheckoutHotelTime = _hour < 10 ? "0" + _hour.ToString() : _hour.ToString();
  817. CheckoutHotelTime = CheckoutHotelTime + ":" + (_min < 10 ? "0" + _min.ToString() : _min.ToString());
  818. trip = trip + "\r\n"
  819. + CheckoutHotelTime + " 乘车前往机场:(" + g.Distance + "," + g.Time + ")";
  820. }
  821. else
  822. {
  823. try
  824. {
  825. JObject Result = PublicCode.GetDirectionByGoogleApi(h.HotelAddress, font_Airport);
  826. //计算“抵达酒店办理入住手续”的时间
  827. string CheckoutHotelTime;
  828. //处理时间格式
  829. string Gtime = "", hours = "0", mins = "0";
  830. if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hour"))
  831. {
  832. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hour", "h");
  833. }
  834. else if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hours"))
  835. {
  836. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hours", "h");
  837. }
  838. Gtime = Gtime.Replace("mins", "m");
  839. if (!string.IsNullOrEmpty(Gtime) && Gtime.Contains("h"))
  840. {
  841. hours = Gtime.Split('h')[0].Trim();
  842. }
  843. else if (!string.IsNullOrEmpty(Gtime) && !Gtime.Contains("h"))
  844. {
  845. mins = Gtime.Split('m')[0].Trim();
  846. }
  847. int _hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  848. int _min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  849. _min = _min - Convert.ToInt32(mins);
  850. if (_min < 0)
  851. {
  852. _min = _min + 60;
  853. _hour = _hour - 1;
  854. }
  855. if (hours != "")
  856. {
  857. _hour = _hour + Convert.ToInt32(hours);
  858. }
  859. if (_hour < 0)
  860. {
  861. _hour = _hour + 24;
  862. }
  863. CheckoutHotelTime = _hour < 10 ? "0" + _hour.ToString() : _hour.ToString();
  864. CheckoutHotelTime = CheckoutHotelTime + ":" + (_min < 10 ? "0" + _min.ToString() : _min.ToString());
  865. trip = trip + "\r\n"
  866. + CheckoutHotelTime + " 乘车前往机场:(" + g.Distance + "," + g.Time + ")";
  867. GoogleMapApiResult gtemp = new GoogleMapApiResult();
  868. gtemp.Diid = di.Id;
  869. gtemp.Date = "";
  870. gtemp.Moment = "";
  871. gtemp.StartAddress = AirPort;
  872. gtemp.EndAddress = h.HotelAddress;
  873. gtemp.Time = Result["routes"][0]["legs"][0]["duration"]["text"].ToString();
  874. gtemp.Distance = Result["routes"][0]["legs"][0]["distance"]["text"].ToString();
  875. gmrs.Add(gtemp);
  876. }
  877. catch
  878. {
  879. trip = trip + "\r\n"
  880. + " 乘车前往机场:(谷歌接口异常,无法测算的路程时间)";
  881. }
  882. }
  883. }
  884. }
  885. }
  886. #endregion
  887. }
  888. trip = trip
  889. + "\r\n" + GoAirportTime + " 抵达" + font_Airport + _StartBuilding + "航站楼,办理登机手续:"
  890. + "\r\n" + _startTime.Substring(0, 2) + ":" + _startTime.Substring(2, _startTime.Length - 2) + " 搭乘" + _aircompany_Name + "航空公司" + _flightcode + "航班,由" + font_City + "飞往" + back_City + ";"
  891. + "\r\n" + " (" + font_Airport + "/" + back_Airport + " 机型:" + airModel + " 飞行时间" + (_flightTime) + ");"
  892. + "\r\n" + _endTime.Substring(0, 2) + ":" + _endTime.Substring(2, _endTime.Length - 2) + " 抵达" + back_Airport + _EndBuilding + "航站楼,办理入境手续,之后前往提取行李";
  893. if (i == timeList.Count - 1)//如果本日是行程的最后一天,先增加酒店到机场的距离时间,再在末尾提醒“行程圆满结束”
  894. {
  895. trip = trip + ",圆满结束此次访问之行!";
  896. }
  897. else //如果本日不是行程的最后一天,正常提醒
  898. {
  899. trip += pushTrip(leaveAirPortTime, back_Airport, city,out leaveAirPortTime);
  900. trip = trip + ";\r\n" + leaveAirPortTime + "搭乘专车前往酒店,抵达后办理入住;";
  901. }
  902. //整理离开机场的时间 +10分钟为"乘车前往酒店"的时刻
  903. int hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  904. int min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  905. min = min + 10;
  906. if (min > 59)
  907. {
  908. min = min - 60;
  909. hour = hour + 1;
  910. }
  911. if (hour > 23)
  912. {
  913. hour = hour - 24;
  914. }
  915. leaveAirPortTime = hour < 10 ? "0" + hour.ToString() : hour.ToString();
  916. leaveAirPortTime = leaveAirPortTime + ":" + (min < 10 ? "0" + min.ToString() : min.ToString());
  917. }
  918. #endregion
  919. }
  920. //同一天多条数据走分类讨论
  921. else
  922. {
  923. for (int n = 0; n < resultRows.Count(); n++)
  924. {
  925. city = "";
  926. #region 三字码
  927. string _citycode = resultRows[n]["Three"].ToString();
  928. //起飞城市三字码
  929. ThreeCode font_threecode = null;
  930. string font_citycode = _citycode.Replace("/", string.Empty).Substring(0, 3);
  931. //抵达城市
  932. string font_City = "";
  933. //起飞城市机场
  934. string font_Airport = "";
  935. //抵达城市三字码
  936. ThreeCode back_threecode = null;
  937. string end_citycode = _citycode.Replace("/", string.Empty).Substring(3, 3);
  938. //抵达城市机场
  939. string back_Airport = "";
  940. //抵达城市
  941. string back_City = "";
  942. font_threecode = tcs.getByThree(font_citycode);
  943. //验证是否存在三字码
  944. if (font_threecode == null)
  945. {
  946. city = city + "【此三字码" + font_citycode + "未收录,请机票同事录入】" + "一";
  947. font_Airport = "【此三字码" + font_citycode + "未收录,请机票同事录入】";
  948. font_City = "【此三字码" + font_citycode + "未收录,请机票同事录入】";
  949. }
  950. else
  951. {
  952. city = city + "/" + font_threecode.City;
  953. font_Airport = font_threecode.AirPort;
  954. font_City = font_threecode.City; ;
  955. }
  956. back_threecode = tcs.getByThree(end_citycode);
  957. if (back_threecode == null)
  958. {
  959. city = city + "【此三字码" + end_citycode + "未收录,请机票同事录入】" + "一";
  960. back_Airport = "【此三字码" + end_citycode + "未收录,请机票同事录入】";
  961. back_City = "【此三字码" + end_citycode + "未收录,请机票同事录入】";
  962. }
  963. else
  964. {
  965. city = city + "/" + back_threecode.City;
  966. //部分黄热病国家,需要提醒打疫苗
  967. string result = PublicCode.GetCountryInfo(back_threecode.Country);
  968. if (result.Contains("3"))
  969. {
  970. city += "(此地区为黄热病地区,请注意打疫苗)";
  971. }
  972. back_Airport = back_threecode.AirPort;
  973. back_City = back_threecode.City;
  974. //查询酒店路线要用
  975. AirPort = back_threecode.AirPort;
  976. }
  977. //行程里加入城市
  978. if (trip == "")
  979. {
  980. trip = city.TrimStart('/');
  981. }
  982. else
  983. {
  984. trip = trip + "\r\n"
  985. + city.TrimStart('/');
  986. }
  987. //起飞航站楼
  988. string _StartBuilding = resultRows[n]["StartBuilding"].ToString();
  989. //转机航站楼
  990. string _EndBuilding = resultRows[n]["EndBuilding"].ToString();
  991. //起飞时刻
  992. string _startTime = resultRows[n]["StartTime"].ToString();
  993. //飞行时刻
  994. string _flightTime = resultRows[n]["FlightTime"].ToString();
  995. _flightTime = _flightTime.Contains("H") ? _flightTime.Split('H')[0] + "小时" + _flightTime.Split('H')[1].Split('M')[0] + "分钟" : _flightTime.Split('M')[0] + "分钟";
  996. //到达时刻
  997. string _endTime = resultRows[n]["EndTime"].ToString();
  998. //航班号
  999. string _flightcode = resultRows[n]["Fliagtcode"].ToString();
  1000. //航司
  1001. AirCompany aircompany = acs.getByShortCode(_flightcode.Substring(0, 2));
  1002. string _aircompany_Name = "";
  1003. if (aircompany == null)
  1004. {
  1005. _aircompany_Name = "【此航司" + resultRows[n]["Fliagtcode"].ToString().Substring(0, 2) + "未收录,请机票同事录入】";
  1006. }
  1007. else
  1008. {
  1009. _aircompany_Name = aircompany.CnName;
  1010. }
  1011. //机型判断
  1012. string airModel = resultRows[n]["AirModel"].ToString();
  1013. airModel = PublicCode.GetLonger(airModel.Substring(0, 1)) + airModel;
  1014. #endregion
  1015. //Sign字段为标识,string类型,含义:0表示为原生黑屏代码、1表示“+1”新增的黑屏代码
  1016. //目前存在两种情况:同一天的多条数据标识为“0->0”或“1->0”
  1017. //如下示例
  1018. //Day ArrivedDate Sign
  1019. //10 10 0
  1020. //10 11 0
  1021. //11 11 1
  1022. //11 12 0
  1023. //12 12 1
  1024. if (n == 0)
  1025. {
  1026. //原生机票代码
  1027. if (resultRows[n]["Sign"].ToString() == "0")
  1028. {
  1029. #region trip编辑
  1030. //根据航班信息推算进入机场的时间
  1031. int temp = Convert.ToInt32(_startTime.Substring(0, 2)) - 2;//一般提前提前两小时
  1032. string result = PublicCode.GetCountryInfo(back_threecode.Country);//美国或者欧洲国家提前三小时
  1033. if (result.Contains("2"))
  1034. {
  1035. temp = Convert.ToInt32(_startTime.Substring(0, 2)) - 3;//提前3小时
  1036. }
  1037. if (temp < 0)
  1038. {
  1039. temp = temp + 24;
  1040. }
  1041. GoAirportTime = temp < 10 ? "0" + temp.ToString() : temp.ToString();
  1042. GoAirportTime = GoAirportTime + ":" + _startTime.Substring(2, _startTime.Length - 2);
  1043. //第一天之后的行程可以加上“酒店出发到机场”的距离和时间
  1044. if (i > 0)
  1045. {
  1046. #region 酒店
  1047. foreach (HotelReservations h in listht)
  1048. {
  1049. if (Convert.ToDateTime(h.CheckInDate) < Convert.ToDateTime(timeList[i])
  1050. && Convert.ToDateTime(h.CheckOutDate) >= Convert.ToDateTime(timeList[i]))
  1051. {
  1052. //利用谷歌API计算路线
  1053. if (AirPort != "")
  1054. {
  1055. GoogleMapApiResult g = gmrs.GetByDiidAddress(di.Id, h.HotelAddress, font_Airport);
  1056. if (g != null)
  1057. {
  1058. //计算“酒店到机场”的时间
  1059. string CheckoutHotelTime;
  1060. //处理时间格式
  1061. string hours = "0", mins = "0";
  1062. if (g.Time.Contains("hour"))
  1063. {
  1064. g.Time = g.Time.Replace("hour", "h");
  1065. }
  1066. else if (g.Time.Contains("hours"))
  1067. {
  1068. g.Time = g.Time.Replace("hours", "h");
  1069. }
  1070. g.Time = g.Time.Replace("mins", "m");
  1071. if (g.Time.Contains("h"))
  1072. {
  1073. hours = g.Time.Split('h')[0].Trim();
  1074. }
  1075. else if (!g.Time.Contains("h"))
  1076. {
  1077. mins = g.Time.Split('m')[0].Trim();
  1078. }
  1079. int _hour = Convert.ToInt32(GoAirportTime.Substring(0, 2));
  1080. int _min = Convert.ToInt32(GoAirportTime.Substring(3, 2));
  1081. _min = _min - Convert.ToInt32(mins);
  1082. if (_min < 0)
  1083. {
  1084. _min = _min + 60;
  1085. _hour = _hour - 1;
  1086. }
  1087. if (hours != "")
  1088. {
  1089. _hour = _hour - Convert.ToInt32(hours);
  1090. }
  1091. if (_hour < 0)
  1092. {
  1093. _hour = _hour + 24;
  1094. }
  1095. CheckoutHotelTime = _hour < 10 ? "0" + _hour.ToString() : _hour.ToString();
  1096. CheckoutHotelTime = CheckoutHotelTime + ":" + (_min < 10 ? "0" + _min.ToString() : _min.ToString());
  1097. trip = trip + "\r\n"
  1098. + CheckoutHotelTime + " 乘车前往机场:(" + g.Distance + "," + g.Time + ")";
  1099. }
  1100. else
  1101. {
  1102. try
  1103. {
  1104. JObject Result = PublicCode.GetDirectionByGoogleApi(h.HotelAddress, font_Airport);
  1105. //计算“抵达酒店办理入住手续”的时间
  1106. string CheckoutHotelTime;
  1107. //处理时间格式
  1108. string Gtime = "", hours = "0", mins = "0";
  1109. if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hour"))
  1110. {
  1111. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hour", "h");
  1112. }
  1113. else if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hours"))
  1114. {
  1115. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hours", "h");
  1116. }
  1117. Gtime = Gtime.Replace("mins", "m");
  1118. if (!string.IsNullOrEmpty(Gtime) && Gtime.Contains("h"))
  1119. {
  1120. hours = Gtime.Split('h')[0].Trim();
  1121. }
  1122. else if (!string.IsNullOrEmpty(Gtime) && !Gtime.Contains("h"))
  1123. {
  1124. mins = Gtime.Split('m')[0].Trim();
  1125. }
  1126. int _hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  1127. int _min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  1128. _min = _min - Convert.ToInt32(mins);
  1129. if (_min < 0)
  1130. {
  1131. _min = _min + 60;
  1132. _hour = _hour - 1;
  1133. }
  1134. if (hours != "")
  1135. {
  1136. _hour = _hour + Convert.ToInt32(hours);
  1137. }
  1138. if (_hour < 0)
  1139. {
  1140. _hour = _hour + 24;
  1141. }
  1142. CheckoutHotelTime = _hour < 10 ? "0" + _hour.ToString() : _hour.ToString();
  1143. CheckoutHotelTime = CheckoutHotelTime + ":" + (_min < 10 ? "0" + _min.ToString() : _min.ToString());
  1144. trip = trip + "\r\n"
  1145. + CheckoutHotelTime + " 乘车前往机场:(" + g.Distance + "," + g.Time + ")";
  1146. GoogleMapApiResult gtemp = new GoogleMapApiResult();
  1147. gtemp.Diid = di.Id;
  1148. gtemp.Date = "";
  1149. gtemp.Moment = "";
  1150. gtemp.StartAddress = AirPort;
  1151. gtemp.EndAddress = h.HotelAddress;
  1152. gtemp.Time = Result["routes"][0]["legs"][0]["duration"]["text"].ToString();
  1153. gtemp.Distance = Result["routes"][0]["legs"][0]["distance"]["text"].ToString();
  1154. gmrs.Add(gtemp);
  1155. }
  1156. catch
  1157. {
  1158. trip = trip + "\r\n"
  1159. + " 乘车前往机场:(谷歌接口异常,无法测算的路程时间)";
  1160. }
  1161. }
  1162. }
  1163. }
  1164. }
  1165. #endregion
  1166. }
  1167. trip = trip
  1168. + "\r\n" + GoAirportTime + " 抵达" + font_Airport + _StartBuilding + "航站楼,办理登机手续:"
  1169. + "\r\n" + _startTime.Substring(0, 2) + ":" + _startTime.Substring(2, _startTime.Length - 2) + " 搭乘" + _aircompany_Name + "航空公司" + _flightcode + "航班,由" + font_City + "飞往" + back_City + ";"
  1170. + "\r\n" + " (" + font_Airport + "/" + back_Airport + " 机型:" + airModel + " 飞行时间" + (_flightTime) + ");"
  1171. + "\r\n" + _endTime.Substring(0, 2) + ":" + _endTime.Substring(2, _endTime.Length - 2) + " 抵达" + back_Airport + _EndBuilding + "航站楼,提取行李;";
  1172. #endregion
  1173. }
  1174. //"+1"生成的机票代码
  1175. else if (resultRows[n]["Sign"].ToString() == "1")
  1176. {
  1177. #region trip编辑
  1178. //行程
  1179. trip = trip
  1180. + "\r\n" + _endTime.Substring(0, 2) + ":" + _endTime.Substring(2, _endTime.Length - 2) + " 抵达" + back_Airport + _EndBuilding + "航站楼,提取行李;";
  1181. #endregion
  1182. }
  1183. }
  1184. else if (n > 0)
  1185. {
  1186. //若前行是原生的,则本行判定为转机
  1187. if (resultRows[n - 1]["Sign"].ToString() == "0")
  1188. {
  1189. #region trip编辑
  1190. int temp = Convert.ToInt32(_startTime.Substring(0, 2)) - 1;//一般提前提前2小时
  1191. if (temp < 0)
  1192. {
  1193. temp = temp + 24;
  1194. }
  1195. GoAirportTime = temp < 10 ? "0" + temp.ToString() : temp.ToString();
  1196. GoAirportTime = GoAirportTime + ":" + _startTime.Substring(2, _startTime.Length - 2);
  1197. trip = trip
  1198. + "\r\n" + GoAirportTime + " 抵达" + font_Airport + _StartBuilding + "航站楼,办理登机手续:"
  1199. + "\r\n" + _startTime.Substring(0, 2) + ":" + _startTime.Substring(2, _startTime.Length - 2) + " 搭乘" + _aircompany_Name + "航空公司" + _flightcode + "航班,由" + font_City + "飞往" + back_City + ";"
  1200. + "\r\n" + " (" + font_Airport + "/" + back_Airport + " 机型:" + airModel + " 飞行时间" + (_flightTime) + ");"
  1201. + "\r\n" + _endTime.Substring(0, 2) + ":" + _endTime.Substring(2, _endTime.Length - 2) + " 抵达" + back_Airport + _EndBuilding + "航站楼,办理入境手续,之后前往提取行李";
  1202. //若为最后一行,则计算后备等时间
  1203. if (n == resultRows.Count() - 1)
  1204. {
  1205. //根据航班信息推算离开机场的时间
  1206. temp = Convert.ToInt32(_endTime.Substring(0, 2)) + 1;
  1207. leaveAirPortTime = temp < 10 ? "0" + temp.ToString() : temp.ToString();
  1208. leaveAirPortTime = leaveAirPortTime + ":" + _endTime.Substring(2, _endTime.Length - 2);
  1209. if (i == timeList.Count - 1)//如果本日是行程的最后一天,先增加酒店到机场的距离时间,再在末尾提醒“行程圆满结束”
  1210. {
  1211. trip = trip + ",圆满结束此次访问之行!";
  1212. }
  1213. else //如果本日不是行程的最后一天,正常提醒
  1214. {
  1215. trip += pushTrip(leaveAirPortTime, back_Airport, city,out leaveAirPortTime);
  1216. trip = trip + ";\r\n" + leaveAirPortTime + "搭乘专车前往酒店,抵达后办理入住;";
  1217. }
  1218. //整理离开机场的时间 +10分钟为"乘车前往酒店"的时刻
  1219. int hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  1220. int min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  1221. min = min + 10;
  1222. if (min > 59)
  1223. {
  1224. min = min - 60;
  1225. hour = hour + 1;
  1226. }
  1227. if (hour > 23)
  1228. {
  1229. hour = hour - 24;
  1230. }
  1231. leaveAirPortTime = hour < 10 ? "0" + hour.ToString() : hour.ToString();
  1232. leaveAirPortTime = leaveAirPortTime + ":" + (min < 10 ? "0" + min.ToString() : min.ToString());
  1233. }
  1234. #endregion
  1235. }
  1236. //若前行是生成的,则本行判定为新出发
  1237. else if (resultRows[n - 1]["Sign"].ToString() == "1")
  1238. {
  1239. #region trip编辑
  1240. //根据航班信息推算进入机场的时间
  1241. int temp = Convert.ToInt32(_startTime.Substring(0, 2)) - 2;//一般提前提前2小时
  1242. string result = PublicCode.GetCountryInfo(back_threecode.Country);//美国或者欧洲国家提前3小时
  1243. if (result.Contains("2"))
  1244. {
  1245. temp = Convert.ToInt32(_startTime.Substring(0, 2)) - 3;//提前3小时
  1246. }
  1247. if (temp < 0)
  1248. {
  1249. temp = temp + 24;
  1250. }
  1251. GoAirportTime = temp < 10 ? "0" + temp.ToString() : temp.ToString();
  1252. GoAirportTime = GoAirportTime + ":" + _startTime.Substring(2, _startTime.Length - 2);
  1253. //根据航班信息推算离开机场的时间
  1254. temp = Convert.ToInt32(_endTime.Substring(0, 2)) + 1;
  1255. leaveAirPortTime = temp < 10 ? "0" + temp.ToString() : temp.ToString();
  1256. leaveAirPortTime = leaveAirPortTime + ":" + _endTime.Substring(2, _endTime.Length - 2);
  1257. //第一天之后的行程可以加上“酒店出发到机场”的距离和时间
  1258. if (i > 0)
  1259. {
  1260. #region 酒店
  1261. foreach (HotelReservations h in listht)
  1262. {
  1263. if (Convert.ToDateTime(h.CheckInDate) < Convert.ToDateTime(timeList[i])
  1264. && Convert.ToDateTime(h.CheckOutDate) >= Convert.ToDateTime(timeList[i]))
  1265. {
  1266. //利用谷歌API计算路线
  1267. if (AirPort != "")
  1268. {
  1269. GoogleMapApiResult g = gmrs.GetByDiidAddress(di.Id, h.HotelAddress, font_Airport);
  1270. if (g != null)
  1271. {
  1272. //计算“酒店到机场”的时间
  1273. string CheckoutHotelTime;
  1274. //处理时间格式
  1275. string hours = "0", mins = "0";
  1276. if (g.Time.Contains("hour"))
  1277. {
  1278. g.Time = g.Time.Replace("hour", "h");
  1279. }
  1280. else if (g.Time.Contains("hours"))
  1281. {
  1282. g.Time = g.Time.Replace("hours", "h");
  1283. }
  1284. g.Time = g.Time.Replace("mins", "m");
  1285. if (g.Time.Contains("h"))
  1286. {
  1287. hours = g.Time.Split('h')[0].Trim();
  1288. }
  1289. else if (!g.Time.Contains("h"))
  1290. {
  1291. mins = g.Time.Split('m')[0].Trim();
  1292. }
  1293. int _hour = Convert.ToInt32(GoAirportTime.Substring(0, 2));
  1294. int _min = Convert.ToInt32(GoAirportTime.Substring(3, 2));
  1295. _min = _min - Convert.ToInt32(mins);
  1296. if (_min < 0)
  1297. {
  1298. _min = _min + 60;
  1299. _hour = _hour - 1;
  1300. }
  1301. if (hours != "")
  1302. {
  1303. _hour = _hour - Convert.ToInt32(hours);
  1304. }
  1305. if (_hour < 0)
  1306. {
  1307. _hour = _hour + 24;
  1308. }
  1309. CheckoutHotelTime = _hour < 10 ? "0" + _hour.ToString() : _hour.ToString();
  1310. CheckoutHotelTime = CheckoutHotelTime + ":" + (_min < 10 ? "0" + _min.ToString() : _min.ToString());
  1311. trip = trip + "\r\n"
  1312. + CheckoutHotelTime + " 乘车前往机场:(" + g.Distance + "," + g.Time + ")";
  1313. }
  1314. else
  1315. {
  1316. try
  1317. {
  1318. JObject Result = PublicCode.GetDirectionByGoogleApi(h.HotelAddress, font_Airport);
  1319. //计算“抵达酒店办理入住手续”的时间
  1320. string CheckoutHotelTime;
  1321. //处理时间格式
  1322. string Gtime = "", hours = "0", mins = "0";
  1323. if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hour"))
  1324. {
  1325. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hour", "h");
  1326. }
  1327. else if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hours"))
  1328. {
  1329. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hours", "h");
  1330. }
  1331. Gtime = Gtime.Replace("mins", "m");
  1332. if (!string.IsNullOrEmpty(Gtime) && Gtime.Contains("h"))
  1333. {
  1334. hours = Gtime.Split('h')[0].Trim();
  1335. }
  1336. else if (!string.IsNullOrEmpty(Gtime) && !Gtime.Contains("h"))
  1337. {
  1338. mins = Gtime.Split('m')[0].Trim();
  1339. }
  1340. int _hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  1341. int _min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  1342. _min = _min - Convert.ToInt32(mins);
  1343. if (_min < 0)
  1344. {
  1345. _min = _min + 60;
  1346. _hour = _hour - 1;
  1347. }
  1348. if (hours != "")
  1349. {
  1350. _hour = _hour + Convert.ToInt32(hours);
  1351. }
  1352. if (_hour < 0)
  1353. {
  1354. _hour = _hour + 24;
  1355. }
  1356. CheckoutHotelTime = _hour < 10 ? "0" + _hour.ToString() : _hour.ToString();
  1357. CheckoutHotelTime = CheckoutHotelTime + ":" + (_min < 10 ? "0" + _min.ToString() : _min.ToString());
  1358. trip = trip + "\r\n"
  1359. + CheckoutHotelTime + " 乘车前往机场:(" + g.Distance + "," + g.Time + ")";
  1360. GoogleMapApiResult gtemp = new GoogleMapApiResult();
  1361. gtemp.Diid = di.Id;
  1362. gtemp.Date = "";
  1363. gtemp.Moment = "";
  1364. gtemp.StartAddress = AirPort;
  1365. gtemp.EndAddress = h.HotelAddress;
  1366. gtemp.Time = Result["routes"][0]["legs"][0]["duration"]["text"].ToString();
  1367. gtemp.Distance = Result["routes"][0]["legs"][0]["distance"]["text"].ToString();
  1368. gmrs.Add(gtemp);
  1369. }
  1370. catch
  1371. {
  1372. trip = trip + "\r\n"
  1373. + " 乘车前往机场:(谷歌接口异常,无法测算的路程时间)";
  1374. }
  1375. }
  1376. }
  1377. }
  1378. }
  1379. #endregion
  1380. }
  1381. trip = trip
  1382. + "\r\n" + GoAirportTime + " 抵达" + font_Airport + _StartBuilding + "航站楼,办理登机手续:"
  1383. + "\r\n" + _startTime.Substring(0, 2) + ":" + _startTime.Substring(2, _startTime.Length - 2) + " 搭乘" + _aircompany_Name + "航空公司" + _flightcode + "航班,由" + font_City + "飞往" + back_City + ";"
  1384. + "\r\n" + " (" + font_Airport + "/" + back_Airport + " 机型:" + airModel + " 飞行时间" + (_flightTime) + ");"
  1385. + "\r\n" + _endTime.Substring(0, 2) + ":" + _endTime.Substring(2, _endTime.Length - 2) + " 抵达" + back_Airport + _EndBuilding + "航站楼,办理入境手续,之后前往提取行李";
  1386. if (i == timeList.Count - 1)//如果本日是行程的最后一天,先增加酒店到机场的距离时间,再在末尾提醒“行程圆满结束”
  1387. {
  1388. trip = trip + ",圆满结束此次访问之行!";
  1389. }
  1390. else //如果本日不是行程的最后一天,正常提醒
  1391. {
  1392. trip += pushTrip(leaveAirPortTime, back_Airport, city,out leaveAirPortTime);
  1393. trip = trip + ";\r\n" + leaveAirPortTime + "搭乘专车前往酒店,抵达后办理入住;";
  1394. }
  1395. //整理离开机场的时间 +10分钟为"乘车前往酒店"的时刻
  1396. int hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  1397. int min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  1398. min = min + 10;
  1399. if (min > 59)
  1400. {
  1401. min = min - 60;
  1402. hour = hour + 1;
  1403. }
  1404. if (hour > 23)
  1405. {
  1406. hour = hour - 24;
  1407. }
  1408. leaveAirPortTime = hour < 10 ? "0" + hour.ToString() : hour.ToString();
  1409. leaveAirPortTime = leaveAirPortTime + ":" + (min < 10 ? "0" + min.ToString() : min.ToString());
  1410. #endregion
  1411. }
  1412. }
  1413. }
  1414. }
  1415. #endregion
  1416. #region 行程和城市赋值
  1417. if (trip == "" || trip == " " || city == "" || city == " ")
  1418. {
  1419. //city = CityInDateList.Find(cid => cid.Date == timeList[i]).City;
  1420. city = CityInDateList[i].City;
  1421. //部分黄热病国家,需要提醒打疫苗
  1422. string result = PublicCode.GetCountryInfo(tcs.getByCity(city)[0].Country);
  1423. if (result.Contains("3"))
  1424. {
  1425. city += "(此地区为黄热病地区,请注意打疫苗)";
  1426. }
  1427. trip = city;
  1428. }
  1429. #endregion
  1430. #region 公务 20210820 贾文滔
  1431. string OATemp = "";//暂存公务活动
  1432. //根据团号和日期获取公务数据
  1433. List<OfficialActivities> listoa = oas.getByDiidAndDate(comb_Diid, timeList[i]);
  1434. //若listoa存在公务数据,进行排序,再进行导入
  1435. if (listoa != null && listoa.Count > 0)
  1436. {
  1437. //利用datatable存放公务活动数据
  1438. DataTable OA_DataTable = new DataTable();
  1439. OA_DataTable.Columns.Add("StartTime", typeof(string)); //activity开始时刻
  1440. OA_DataTable.Columns.Add("EndTime", typeof(string)); //activity结束时刻
  1441. OA_DataTable.Columns.Add("Client", typeof(string)); //activity单位
  1442. OA_DataTable.Columns.Add("Address", typeof(string)); //activity地址
  1443. OA_DataTable.Columns.Add("Contact", typeof(string)); //activity联系人
  1444. OA_DataTable.Columns.Add("Tel", typeof(string)); //activity联系人电话
  1445. OA_DataTable.Columns.Add("Dresscode", typeof(string)); //activity着装要求
  1446. OA_DataTable.Columns.Add("isTranslate", typeof(bool));//是否需要翻译人员
  1447. OA_DataTable.Columns.Add("Language", typeof(string));//是否需要翻译人员
  1448. //处理公务数据
  1449. for (int b = 0; b < listoa.Count; b++)
  1450. {
  1451. //起止时间
  1452. string[] time = new string[2];
  1453. if (listoa[b].Time.Contains('—'))
  1454. {
  1455. time = listoa[b].Time.Split('—');
  1456. }
  1457. else if (listoa[b].Time.Contains('-'))
  1458. {
  1459. time = listoa[b].Time.Split('-');
  1460. }
  1461. //添加数据
  1462. if (time.Length >= 2)
  1463. {
  1464. OA_DataTable.Rows.Add(time[0], time[1], listoa[b].Client, listoa[b].Address, listoa[b].Contact, listoa[b].Tel, listoa[b].Dresscode, listoa[b].IsNeedTrans, listoa[b].Language);
  1465. }
  1466. else
  1467. {
  1468. //PublicCode.GetAlertMsg(this, GetType(), timeList[i] + "的公务数据有误,请检查");
  1469. }
  1470. }
  1471. //排序
  1472. OA_DataTable.DefaultView.Sort = "StartTime asc";
  1473. OA_DataTable = OA_DataTable.DefaultView.ToTable();
  1474. //导入信息
  1475. for (int index = 0; index < OA_DataTable.Rows.Count; index++)
  1476. {
  1477. if (i == 0)//行程第一天的公务放在酒店后面,所以先暂存在一个变量里
  1478. {
  1479. if (OATemp != "")
  1480. {
  1481. OATemp = OATemp + "\r\n"
  1482. + OA_DataTable.Rows[index]["StartTime"].ToString()
  1483. + "-"
  1484. + OA_DataTable.Rows[index]["EndTime"].ToString()
  1485. + " 拜访" + OA_DataTable.Rows[index]["Client"].ToString()
  1486. + ",联系人:" + OA_DataTable.Rows[index]["Contact"].ToString()
  1487. + ",电话:" + OA_DataTable.Rows[index]["Tel"].ToString()
  1488. + ",地址:" + OA_DataTable.Rows[index]["Address"].ToString()
  1489. + ",着装要求:" + OA_DataTable.Rows[index]["Dresscode"].ToString()
  1490. + ",是否需要翻译:" + (bool.Parse(OA_DataTable.Rows[index]["isTranslate"].ToString()) ? "需要翻译人员" + "翻译语种为" + OA_DataTable.Rows[index]["Language"].ToString() : "不需要翻译人员")
  1491. + ",议题:-";
  1492. }
  1493. else
  1494. {
  1495. OATemp = OA_DataTable.Rows[index]["StartTime"].ToString()
  1496. + "-"
  1497. + OA_DataTable.Rows[index]["EndTime"].ToString()
  1498. + " 拜访" + OA_DataTable.Rows[index]["Client"].ToString()
  1499. + ",联系人:" + OA_DataTable.Rows[index]["Contact"].ToString()
  1500. + ",电话:" + OA_DataTable.Rows[index]["Tel"].ToString()
  1501. + ",地址:" + OA_DataTable.Rows[index]["Address"].ToString()
  1502. + ",着装要求:" + OA_DataTable.Rows[index]["Dresscode"].ToString()
  1503. + ",是否需要翻译:" + (bool.Parse(OA_DataTable.Rows[index]["isTranslate"].ToString()) ? "需要翻译人员" + "翻译语种为" + OA_DataTable.Rows[index]["Language"].ToString() : "不需要翻译人员")
  1504. + ",议题:-";
  1505. }
  1506. }
  1507. else
  1508. {
  1509. //导入公务
  1510. trip = trip + "\r\n"
  1511. + OA_DataTable.Rows[index]["StartTime"].ToString()
  1512. + "-"
  1513. + OA_DataTable.Rows[index]["EndTime"].ToString()
  1514. + " 拜访" + OA_DataTable.Rows[index]["Client"].ToString()
  1515. + ",联系人:" + OA_DataTable.Rows[index]["Contact"].ToString()
  1516. + ",电话:" + OA_DataTable.Rows[index]["Tel"].ToString()
  1517. + ",地址:" + OA_DataTable.Rows[index]["Address"].ToString()
  1518. + ",着装要求:" + OA_DataTable.Rows[index]["Dresscode"].ToString()
  1519. + ",是否需要翻译:" + (bool.Parse(OA_DataTable.Rows[index]["isTranslate"].ToString()) ? "需要翻译人员" + "翻译语种为" + OA_DataTable.Rows[index]["Language"].ToString() : "不需要翻译人员")
  1520. + ",议题:-";
  1521. }
  1522. //当天第一个公务或许都是从酒店出发,因此可计算酒店到公务地址的距离和时间
  1523. if (index == 0)
  1524. {
  1525. #region 酒店
  1526. foreach (HotelReservations h in listht)
  1527. {
  1528. if (Convert.ToDateTime(h.CheckInDate) <= Convert.ToDateTime(timeList[i])
  1529. && Convert.ToDateTime(h.CheckOutDate) > Convert.ToDateTime(timeList[i]))
  1530. {
  1531. //利用谷歌API计算路线
  1532. GoogleMapApiResult g = gmrs.GetByDiidAddress(di.Id, h.HotelAddress, OA_DataTable.Rows[0]["Address"].ToString());
  1533. if (g != null)
  1534. {
  1535. if (i == 0)//行程第一天的公务放在酒店后面,所以先暂存在一个变量里
  1536. {
  1537. OATemp = OATemp + "。 (" + g.Distance + "," + g.Time + ")";
  1538. }
  1539. else
  1540. {
  1541. trip = trip + "。 (" + g.Distance + "," + g.Time + ")";
  1542. }
  1543. }
  1544. else
  1545. {
  1546. try
  1547. {
  1548. JObject Result = PublicCode.GetDirectionByGoogleApi(h.HotelAddress, OA_DataTable.Rows[0]["Address"].ToString());
  1549. if (i == 0)//行程第一天的公务放在酒店后面,所以先暂存在一个变量里
  1550. {
  1551. OATemp = OATemp + "。 (" + Result["routes"][0]["legs"][0]["distance"]["text"].ToString() + ","
  1552. + Result["routes"][0]["legs"][0]["duration"]["text"].ToString() + ")";
  1553. }
  1554. else
  1555. {
  1556. trip = trip + "。 (" + Result["routes"][0]["legs"][0]["distance"]["text"].ToString() + ","
  1557. + Result["routes"][0]["legs"][0]["duration"]["text"].ToString() + ")";
  1558. }
  1559. GoogleMapApiResult gtemp = new GoogleMapApiResult();
  1560. gtemp.Diid = di.Id;
  1561. gtemp.Date = "";
  1562. gtemp.Moment = "";
  1563. gtemp.StartAddress = h.HotelAddress;
  1564. gtemp.EndAddress = OA_DataTable.Rows[0]["Address"].ToString();
  1565. gtemp.Time = Result["routes"][0]["legs"][0]["duration"]["text"].ToString();
  1566. gtemp.Distance = Result["routes"][0]["legs"][0]["distance"]["text"].ToString();
  1567. gmrs.Add(gtemp);
  1568. }
  1569. catch
  1570. {
  1571. if (i == 0)//行程第一天的公务放在酒店后面,所以先暂存在一个变量里
  1572. {
  1573. OATemp = OATemp + "。 (谷歌接口异常,无法测算路程时间)";
  1574. }
  1575. else
  1576. {
  1577. trip = trip + "。 (谷歌接口异常,无法测算路程时间)";
  1578. }
  1579. }
  1580. }
  1581. }
  1582. }
  1583. #endregion
  1584. }
  1585. //第二个公务是由中午的餐厅前往公务地址,具有随机性,因此不计算此方向距离时间;但可计算由公务地址回酒店的信息
  1586. else
  1587. {
  1588. #region 酒店
  1589. foreach (HotelReservations h in listht)
  1590. {
  1591. if (Convert.ToDateTime(h.CheckInDate) <= Convert.ToDateTime(timeList[i])
  1592. && Convert.ToDateTime(h.CheckOutDate) > Convert.ToDateTime(timeList[i]))
  1593. {
  1594. //利用谷歌API计算路线
  1595. GoogleMapApiResult g = gmrs.GetByDiidAddress(di.Id, OA_DataTable.Rows[index]["Address"].ToString(), h.HotelAddress);
  1596. if (g != null)
  1597. {
  1598. if (i == 0)//行程第一天的公务放在酒店后面,所以先暂存在一个变量里
  1599. {
  1600. OATemp = OATemp + "。 (" + g.Distance + "," + g.Time + ")";
  1601. }
  1602. else
  1603. {
  1604. trip = trip + "。 (" + g.Distance + "," + g.Time + ")";
  1605. }
  1606. }
  1607. else
  1608. {
  1609. try
  1610. {
  1611. JObject Result = PublicCode.GetDirectionByGoogleApi(OA_DataTable.Rows[index]["Address"].ToString(), h.HotelAddress);
  1612. if (i == 0)//行程第一天的公务放在酒店后面,所以先暂存在一个变量里
  1613. {
  1614. OATemp = OATemp + "。 (" + Result["routes"][0]["legs"][0]["distance"]["text"].ToString() + ","
  1615. + Result["routes"][0]["legs"][0]["duration"]["text"].ToString() + ")";
  1616. }
  1617. else
  1618. {
  1619. trip = trip + "。 (" + Result["routes"][0]["legs"][0]["distance"]["text"].ToString() + ","
  1620. + Result["routes"][0]["legs"][0]["duration"]["text"].ToString() + ")";
  1621. }
  1622. GoogleMapApiResult gtemp = new GoogleMapApiResult();
  1623. gtemp.Diid = di.Id;
  1624. gtemp.Date = "";
  1625. gtemp.Moment = "";
  1626. gtemp.StartAddress = OA_DataTable.Rows[0]["Address"].ToString();
  1627. gtemp.EndAddress = h.HotelAddress;
  1628. gtemp.Time = Result["routes"][0]["legs"][0]["duration"]["text"].ToString();
  1629. gtemp.Distance = Result["routes"][0]["legs"][0]["distance"]["text"].ToString();
  1630. gmrs.Add(gtemp);
  1631. }
  1632. catch
  1633. {
  1634. if (i == 0)//行程第一天的公务放在酒店后面,所以先暂存在一个变量里
  1635. {
  1636. OATemp = OATemp + "。 (谷歌接口异常,无法测算路程时间)";
  1637. }
  1638. else
  1639. {
  1640. trip = trip + "。 (谷歌接口异常,无法测算路程时间)";
  1641. }
  1642. }
  1643. }
  1644. }
  1645. }
  1646. #endregion
  1647. }
  1648. }
  1649. }
  1650. #endregion
  1651. #region 酒店
  1652. foreach (HotelReservations h in listht)
  1653. {
  1654. if (Convert.ToDateTime(h.CheckInDate) <= Convert.ToDateTime(timeList[i])
  1655. && Convert.ToDateTime(h.CheckOutDate) > Convert.ToDateTime(timeList[i]))//不去“》=”的原因是行程最后一天一般不会有酒店
  1656. {
  1657. //利用谷歌API计算路线
  1658. if (AirPort != "")
  1659. {
  1660. GoogleMapApiResult g = gmrs.GetByDiidAddress(di.Id, AirPort, h.HotelAddress);
  1661. if (g != null)
  1662. {
  1663. trip = trip + "\r\n"
  1664. + leaveAirPortTime + " 乘车前往酒店:(" + g.Distance + "," + g.Time + ")";
  1665. //计算“抵达酒店办理入住手续”的时间
  1666. string CheckInHotelTime;
  1667. //处理时间格式
  1668. string hours = "", mins = "";
  1669. if (g.Time.Contains("hour"))
  1670. {
  1671. g.Time = g.Time.Replace("hour", "h");
  1672. }
  1673. else if (g.Time.Contains("hours"))
  1674. {
  1675. g.Time = g.Time.Replace("hours", "h");
  1676. }
  1677. g.Time = g.Time.Replace("mins", "m");
  1678. if (g.Time.Contains("h"))
  1679. {
  1680. hours = g.Time.Split('h')[0].Trim();
  1681. }
  1682. else if (!g.Time.Contains("h"))
  1683. {
  1684. mins = g.Time.Split('m')[0].Trim();
  1685. }
  1686. int hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  1687. int min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  1688. min = min + Convert.ToInt32(mins);
  1689. if (min > 59)
  1690. {
  1691. min = min - 60;
  1692. hour = hour + 1;
  1693. }
  1694. if (hours != "")
  1695. {
  1696. hour = hour + Convert.ToInt32(hours);
  1697. }
  1698. if (hour > 23)
  1699. {
  1700. hour = hour - 24;
  1701. }
  1702. CheckInHotelTime = hour < 10 ? "0" + hour.ToString() : hour.ToString();
  1703. CheckInHotelTime = CheckInHotelTime + ":" + (min < 10 ? "0" + min.ToString() : min.ToString());
  1704. trip = trip + "\r\n"
  1705. + CheckInHotelTime + " 抵达酒店办理入住手续";
  1706. }
  1707. else
  1708. {
  1709. try
  1710. {
  1711. JObject Result = PublicCode.GetDirectionByGoogleApi(AirPort, h.HotelAddress);
  1712. trip = trip + "\r\n"
  1713. + leaveAirPortTime + " 乘车前往酒店:(" + Result["routes"][0]["legs"][0]["distance"]["text"].ToString() + ","
  1714. + Result["routes"][0]["legs"][0]["duration"]["text"].ToString() + ")";
  1715. //计算“抵达酒店办理入住手续”的时间
  1716. string CheckInHotelTime;
  1717. //处理时间格式
  1718. string Gtime = "", hours = "", mins = "";
  1719. if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hour"))
  1720. {
  1721. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hour", "h");
  1722. }
  1723. else if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hours"))
  1724. {
  1725. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hours", "h");
  1726. }
  1727. Gtime = Gtime.Replace("mins", "m");
  1728. if (!string.IsNullOrEmpty(Gtime) && Gtime.Contains("h"))
  1729. {
  1730. hours = Gtime.Split('h')[0].Trim();
  1731. }
  1732. else if (!string.IsNullOrEmpty(Gtime) && !Gtime.Contains("h"))
  1733. {
  1734. mins = Gtime.Split('m')[0].Trim();
  1735. }
  1736. int hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  1737. int min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  1738. min = min + Convert.ToInt32(mins);
  1739. if (min > 59)
  1740. {
  1741. min = min - 60;
  1742. hour = hour + 1;
  1743. }
  1744. if (hours != "")
  1745. {
  1746. hour = hour + Convert.ToInt32(hours);
  1747. }
  1748. if (hour > 23)
  1749. {
  1750. hour = hour - 24;
  1751. }
  1752. CheckInHotelTime = hour < 10 ? "0" + hour.ToString() : hour.ToString();
  1753. CheckInHotelTime = CheckInHotelTime + ":" + (min < 10 ? "0" + min.ToString() : min.ToString());
  1754. trip = trip + "\r\n"
  1755. + CheckInHotelTime + " 抵达酒店办理入住手续";
  1756. GoogleMapApiResult gtemp = new GoogleMapApiResult();
  1757. gtemp.Diid = di.Id;
  1758. gtemp.Date = "";
  1759. gtemp.Moment = "";
  1760. gtemp.StartAddress = AirPort;
  1761. gtemp.EndAddress = h.HotelAddress;
  1762. gtemp.Time = Result["routes"][0]["legs"][0]["duration"]["text"].ToString();
  1763. gtemp.Distance = Result["routes"][0]["legs"][0]["distance"]["text"].ToString();
  1764. gmrs.Add(gtemp);
  1765. }
  1766. catch
  1767. {
  1768. trip = trip + "\r\n"
  1769. + " (谷歌接口异常,无法测算的路程时间)";
  1770. }
  1771. }
  1772. }
  1773. trip = trip + "\r\n"
  1774. + " 酒店名称:" + h.HotelName + "\r\n"
  1775. + " 酒店地址:" + h.HotelAddress + "\r\n"
  1776. + " 酒店电话:" + h.HotelTel + " 酒店传真:" + (h.HotelFax == "" ? "-" : h.HotelFax);
  1777. if (i == 0 && !string.IsNullOrEmpty(OATemp))
  1778. {
  1779. trip = trip + "\r\n" + OATemp;
  1780. }
  1781. }
  1782. }
  1783. #endregion
  1784. #region 当天交通工具赋值
  1785. //一般行程第一天都是先乘坐飞机后乘坐汽车
  1786. if (i == 0)
  1787. {
  1788. tlTemp.Traffic_First = "飞机";
  1789. tlTemp.Traffic_Second = "汽车";
  1790. }
  1791. else
  1792. {
  1793. // 根据车导地接表数据判断交通工具:汽车
  1794. List<CarTouristGuideGroundReservations> ListCar = listctg.FindAll(c => Convert.ToDateTime(c.ServiceStartTime) <= Convert.ToDateTime(timeList[i])
  1795. && Convert.ToDateTime(c.ServiceEndTime) >= Convert.ToDateTime(timeList[i]));
  1796. //交通工具:汽车
  1797. if (ListCar.Count > 0)
  1798. {
  1799. tlTemp.Traffic_First = "汽车";
  1800. //交通工具:飞机
  1801. if (airSign == true)
  1802. {
  1803. tlTemp.Traffic_Second = "飞机";
  1804. }
  1805. else
  1806. {
  1807. tlTemp.Traffic_Second = "";
  1808. }
  1809. }
  1810. else
  1811. {
  1812. tlTemp.Traffic_First = "汽车";
  1813. //交通工具:飞机
  1814. if (airSign == true)
  1815. {
  1816. tlTemp.Traffic_Second = "飞机";
  1817. }
  1818. else
  1819. {
  1820. tlTemp.Traffic_Second = "";
  1821. }
  1822. }
  1823. }
  1824. #endregion
  1825. tlTemp.Trip = trip;
  1826. tlTemp.OPer = di.Id;
  1827. tlTemp.OPdate = PublicCode.GetBeijingTime().ToString("yyyy-MM-dd HH:mm:ss");
  1828. tlTemp.issel = 1;
  1829. tlTemp.diffgroup = 1;
  1830. tlTemp.Isdel = 0;
  1831. tls.AddTravelList(tlTemp);
  1832. }
  1833. }
  1834. else if (timeList.Count < listTravel.Count)//2改版天数<原版天数
  1835. {
  1836. //2.1替换日期
  1837. for (int i = 0; i < timeList.Count; i++)
  1838. {
  1839. //日期转换星期
  1840. string weekday = weekdays[(int)new DateTime(
  1841. Convert.ToInt32(timeList[i].Split('-')[0]),
  1842. Convert.ToInt32(timeList[i].Split('-')[1]),
  1843. Convert.ToInt32(timeList[i].Split('-')[2])).DayOfWeek];
  1844. //日期去掉0
  1845. string monthStr = "Unknown", dayStr = "Unknown";
  1846. if (!string.IsNullOrEmpty(timeList[i]))
  1847. {
  1848. DateTime dateTime = new DateTime();
  1849. bool convertResult = DateTime.TryParse(timeList[i], out dateTime);
  1850. if (convertResult)
  1851. {
  1852. monthStr = dateTime.Month.ToString();
  1853. dayStr = dateTime.Day.ToString();
  1854. }
  1855. }
  1856. //日期
  1857. listTravel[i].Date = monthStr + "月" + dayStr + "日";
  1858. //listTravel[i].Date = timeList[i].Substring(5, 2) + "月" + timeList[i].Substring(8, 2) + "日";
  1859. listTravel[i].WeekDay = weekday;
  1860. listTravel[i].OPer = UserId;
  1861. listTravel[i].OPdate = PublicCode.GetBeijingTime().ToString("yyyy-MM-dd HH:mm:ss");
  1862. listTravel[i].Isdel = 0;
  1863. tls.EditTravelList(listTravel[i]);
  1864. }
  1865. //2.2删除多余行程
  1866. tls.DelOld(comb_Diid, listTravel[timeList.Count - 1].Id, listTravel[listTravel.Count - 1].Id);
  1867. }
  1868. else//3改版天数=原版天数
  1869. {
  1870. //3.1替换日期
  1871. for (int i = 0; i < timeList.Count; i++)
  1872. {
  1873. //日期去掉0
  1874. string monthStr="Unknown", dayStr="Unknown";
  1875. if (!string.IsNullOrEmpty(timeList[i]))
  1876. {
  1877. DateTime dateTime = new DateTime();
  1878. bool convertResult = DateTime.TryParse(timeList[i], out dateTime);
  1879. if (convertResult)
  1880. {
  1881. monthStr = dateTime.Month.ToString();
  1882. dayStr = dateTime.Day.ToString();
  1883. }
  1884. }
  1885. //日期
  1886. listTravel[i].Date = monthStr + "月" + dayStr + "日";
  1887. //日期转换星期
  1888. string weekday = weekdays[(int)new DateTime(
  1889. Convert.ToInt32(timeList[i].Split('-')[0]),
  1890. Convert.ToInt32(timeList[i].Split('-')[1]),
  1891. Convert.ToInt32(timeList[i].Split('-')[2])).DayOfWeek];
  1892. listTravel[i].WeekDay = weekday;
  1893. listTravel[i].OPer = UserId;
  1894. listTravel[i].OPdate = PublicCode.GetBeijingTime().ToString("yyyy-MM-dd HH:mm:ss");
  1895. listTravel[i].Isdel = 0;
  1896. tls.EditTravelList(listTravel[i]);
  1897. }
  1898. }
  1899. }
  1900. else //若本团不存行程,则生成行程。 包含机票、酒店、车导地接等数据
  1901. {
  1902. //航班号标识
  1903. //string flightcode_Sign = "";
  1904. //三字码标识
  1905. //string citycode_Sign = "";
  1906. #region 城市数据 20210823 贾文滔
  1907. List<PublicCode.CityInDate> CityInDateList = PublicCode.GetCityByDataTable(dt);
  1908. #endregion
  1909. //生成行程
  1910. for (int i = 0; i < timeList.Count; i++)
  1911. {
  1912. //实、例化一个temp
  1913. Models.TravelList tlTemp = new Models.TravelList();
  1914. //团号
  1915. tlTemp.Diid = di.Id;
  1916. //天数序号
  1917. tlTemp.Days = i + 1;
  1918. //日期去掉0
  1919. var datetime1 = timeList[i];
  1920. string monthStr = "Unknown", dayStr = "Unknown";
  1921. if (!string.IsNullOrEmpty(datetime1))
  1922. {
  1923. DateTime dateTime = new DateTime();
  1924. bool convertResult = DateTime.TryParse(datetime1, out dateTime);
  1925. if (convertResult)
  1926. {
  1927. monthStr = dateTime.Month.ToString();
  1928. dayStr = dateTime.Day.ToString();
  1929. }
  1930. }
  1931. //日期
  1932. tlTemp.Date = monthStr + "月" + dayStr + "日";
  1933. //日期
  1934. //tlTemp.Date = timeList[i].Substring(5, 2) + "月" + timeList[i].Substring(8, 2) + "日";
  1935. //日期转换星期
  1936. string weekday = weekdays[(int)new DateTime(
  1937. Convert.ToInt32(timeList[i].Split('-')[0]),
  1938. Convert.ToInt32(timeList[i].Split('-')[1]),
  1939. Convert.ToInt32(timeList[i].Split('-')[2])).DayOfWeek];
  1940. tlTemp.WeekDay = weekday;
  1941. //行程
  1942. string trip = "";
  1943. //历经城市
  1944. string city = "";
  1945. #region 机票数据
  1946. //根据航班信息推出抵达机场的位置信息
  1947. string AirPort = "";
  1948. //根据航班时间前后推进入机场或离开机场的时间
  1949. string GoAirportTime = "", leaveAirPortTime = "";
  1950. //飞机标识
  1951. bool airSign = false;
  1952. //查询该日期下的航班信息
  1953. //resultRows字段顺序为:航班号,起飞日期,三字码,起飞时刻,到达时刻,出发航站楼,到达航站楼,机型,飞行时间,整理后的起飞日期,整理后的到达日期
  1954. DataRow[] resultRows = dt.Select("Day like '%" + timeList[i] + "%'");
  1955. if (resultRows.Count() > 0)
  1956. {
  1957. //修改标识
  1958. airSign = true;
  1959. }
  1960. //同一天只有一条数据走正常判定
  1961. if (resultRows.Count() == 1)
  1962. {
  1963. #region 三字码
  1964. string _citycode = resultRows[0]["Three"].ToString();
  1965. //起飞城市三字码
  1966. ThreeCode font_threecode = null;
  1967. string font_citycode = _citycode.Replace("/", string.Empty).Substring(0, 3);
  1968. //抵达城市
  1969. string font_City = "";
  1970. //起飞城市机场
  1971. string font_Airport = "";
  1972. //抵达城市三字码
  1973. ThreeCode back_threecode = null;
  1974. string end_citycode = _citycode.Replace("/", string.Empty).Substring(3, 3);
  1975. //抵达城市机场
  1976. string back_Airport = "";
  1977. //抵达城市
  1978. string back_City = "";
  1979. font_threecode = tcs.getByThree(font_citycode);
  1980. //验证是否存在三字码
  1981. if (font_threecode == null)
  1982. {
  1983. city = city + "【此三字码" + font_citycode + "未收录,请机票同事录入】" + "一";
  1984. font_Airport = "【此三字码" + font_citycode + "未收录,请机票同事录入】";
  1985. font_City = "【此三字码" + font_citycode + "未收录,请机票同事录入】";
  1986. }
  1987. else
  1988. {
  1989. city = city + "/" + font_threecode.City;
  1990. font_Airport = font_threecode.AirPort;
  1991. font_City = font_threecode.City; ;
  1992. }
  1993. back_threecode = tcs.getByThree(end_citycode);
  1994. if (back_threecode == null)
  1995. {
  1996. city = city + "【此三字码" + end_citycode + "未收录,请机票同事录入】" + "一";
  1997. back_Airport = "【此三字码" + end_citycode + "未收录,请机票同事录入】";
  1998. back_City = "【此三字码" + end_citycode + "未收录,请机票同事录入】";
  1999. }
  2000. else
  2001. {
  2002. city = city + "/" + back_threecode.City;
  2003. //部分黄热病国家,需要提醒打疫苗
  2004. string result = PublicCode.GetCountryInfo(back_threecode.Country);
  2005. if (result.Contains("3"))
  2006. {
  2007. city += "(此地区为黄热病地区,请注意打疫苗)";
  2008. }
  2009. back_Airport = back_threecode.AirPort;
  2010. back_City = back_threecode.City;
  2011. //查询酒店路线要用
  2012. AirPort = back_threecode.AirPort;
  2013. }
  2014. //行程里加入城市
  2015. #endregion
  2016. #region 信息准备
  2017. trip = city.TrimStart('/');
  2018. //起飞航站楼
  2019. string _StartBuilding = resultRows[0]["StartBuilding"].ToString();
  2020. //转机航站楼
  2021. string _EndBuilding = resultRows[0]["EndBuilding"].ToString();
  2022. //起飞时刻
  2023. string _startTime = resultRows[0]["StartTime"].ToString();
  2024. //飞行时刻
  2025. string _flightTime = resultRows[0]["FlightTime"].ToString();
  2026. _flightTime = _flightTime.Contains("H") ? _flightTime.Split('H')[0] + "小时" + _flightTime.Split('H')[1].Split('M')[0] + "分钟" : _flightTime.Split('M')[0] + "分钟";
  2027. //到达时刻
  2028. string _endTime = resultRows[0]["EndTime"].ToString();
  2029. //航班号
  2030. string _flightcode = resultRows[0]["Fliagtcode"].ToString();
  2031. //航司
  2032. AirCompany aircompany = acs.getByShortCode(_flightcode.Substring(0, 2));
  2033. string _aircompany_Name = "";
  2034. if (aircompany == null)
  2035. {
  2036. _aircompany_Name = "【此航司" + resultRows[0]["Fliagtcode"].ToString().Substring(0, 2) + "未收录,请机票同事录入】";
  2037. }
  2038. else
  2039. {
  2040. _aircompany_Name = aircompany.CnName;
  2041. }
  2042. //机型判断
  2043. string airModel = resultRows[0]["AirModel"].ToString();
  2044. airModel = PublicCode.GetLonger(airModel.Substring(0, 1)) + airModel;
  2045. #endregion
  2046. #region trip编辑
  2047. //若本行抵达时间包含"+1",则本行为母版行,仅提示登机
  2048. if (resultRows[0]["Sign"].ToString() == "0" && _endTime.Contains("+"))
  2049. {
  2050. //根据航班信息推算进入机场的时间
  2051. int temp = Convert.ToInt32(_startTime.Substring(0, 2)) - 2;//一般提前提前两小时
  2052. string result = PublicCode.GetCountryInfo(back_threecode.Country);//美国或者欧洲国家提前三小时
  2053. if (result.Contains("2"))
  2054. {
  2055. temp = Convert.ToInt32(_startTime.Substring(0, 2)) - 3;//提前3小时
  2056. }
  2057. if (temp < 0)
  2058. {
  2059. temp = temp + 24;
  2060. }
  2061. GoAirportTime = temp < 10 ? "0" + temp.ToString() : temp.ToString();
  2062. GoAirportTime = GoAirportTime + ":" + _startTime.Substring(2, _startTime.Length - 2);
  2063. //第一天之后的行程可以加上“酒店出发到机场”的距离和时间
  2064. if (i > 0)
  2065. {
  2066. #region 酒店
  2067. foreach (HotelReservations h in listht)
  2068. {
  2069. if (Convert.ToDateTime(h.CheckInDate) < Convert.ToDateTime(timeList[i])
  2070. && Convert.ToDateTime(h.CheckOutDate) > Convert.ToDateTime(timeList[i]))
  2071. {
  2072. //利用谷歌API计算路线
  2073. if (AirPort != "")
  2074. {
  2075. GoogleMapApiResult g = gmrs.GetByDiidAddress(di.Id, h.HotelAddress, font_Airport);
  2076. if (g != null)
  2077. {
  2078. //计算“酒店到机场”的时间
  2079. string CheckoutHotelTime;
  2080. //处理时间格式
  2081. string hours = "", mins = "";
  2082. if (g.Time.Contains("hour"))
  2083. {
  2084. g.Time = g.Time.Replace("hour", "h");
  2085. }
  2086. else if (g.Time.Contains("hours"))
  2087. {
  2088. g.Time = g.Time.Replace("hours", "h");
  2089. }
  2090. g.Time = g.Time.Replace("mins", "m");
  2091. if (g.Time.Contains("h"))
  2092. {
  2093. hours = g.Time.Split('h')[0].Trim();
  2094. }
  2095. else if (!g.Time.Contains("h"))
  2096. {
  2097. mins = g.Time.Split('m')[0].Trim();
  2098. }
  2099. int hour = Convert.ToInt32(GoAirportTime.Substring(0, 2));
  2100. int min = Convert.ToInt32(GoAirportTime.Substring(3, 2));
  2101. min = min - Convert.ToInt32(mins);
  2102. if (min < 0)
  2103. {
  2104. min = min + 60;
  2105. hour = hour - 1;
  2106. }
  2107. if (hours != "")
  2108. {
  2109. hour = hour - Convert.ToInt32(hours);
  2110. }
  2111. if (hour < 0)
  2112. {
  2113. hour = hour + 24;
  2114. }
  2115. CheckoutHotelTime = hour < 10 ? "0" + hour.ToString() : hour.ToString();
  2116. CheckoutHotelTime = CheckoutHotelTime + ":" + (min < 10 ? "0" + min.ToString() : min.ToString());
  2117. trip = trip + "\r\n"
  2118. + CheckoutHotelTime + " 乘车前往机场:(" + g.Distance + "," + g.Time + ")";
  2119. }
  2120. else
  2121. {
  2122. try
  2123. {
  2124. JObject Result = PublicCode.GetDirectionByGoogleApi(h.HotelAddress, font_Airport);
  2125. //计算“抵达酒店办理入住手续”的时间
  2126. string CheckoutHotelTime;
  2127. //处理时间格式
  2128. string Gtime = "", hours = "", mins = "";
  2129. if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hour"))
  2130. {
  2131. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hour", "h");
  2132. }
  2133. else if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hours"))
  2134. {
  2135. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hours", "h");
  2136. }
  2137. Gtime = Gtime.Replace("mins", "m");
  2138. if (!string.IsNullOrEmpty(Gtime) && Gtime.Contains("h"))
  2139. {
  2140. hours = Gtime.Split('h')[0].Trim();
  2141. }
  2142. else if (!string.IsNullOrEmpty(Gtime) && !Gtime.Contains("h"))
  2143. {
  2144. mins = Gtime.Split('m')[0].Trim();
  2145. }
  2146. int hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  2147. int min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  2148. min = min - Convert.ToInt32(mins);
  2149. if (min < 0)
  2150. {
  2151. min = min + 60;
  2152. hour = hour - 1;
  2153. }
  2154. if (hours != "")
  2155. {
  2156. hour = hour + Convert.ToInt32(hours);
  2157. }
  2158. if (hour < 0)
  2159. {
  2160. hour = hour + 24;
  2161. }
  2162. CheckoutHotelTime = hour < 10 ? "0" + hour.ToString() : hour.ToString();
  2163. CheckoutHotelTime = CheckoutHotelTime + ":" + (min < 10 ? "0" + min.ToString() : min.ToString());
  2164. trip = trip + "\r\n"
  2165. + CheckoutHotelTime + " 乘车前往机场:(" + g.Distance + "," + g.Time + ")";
  2166. GoogleMapApiResult gtemp = new GoogleMapApiResult();
  2167. gtemp.Diid = di.Id;
  2168. gtemp.Date = "";
  2169. gtemp.Moment = "";
  2170. gtemp.StartAddress = AirPort;
  2171. gtemp.EndAddress = h.HotelAddress;
  2172. gtemp.Time = Result["routes"][0]["legs"][0]["duration"]["text"].ToString();
  2173. gtemp.Distance = Result["routes"][0]["legs"][0]["distance"]["text"].ToString();
  2174. gmrs.Add(gtemp);
  2175. }
  2176. catch
  2177. {
  2178. trip = trip + "\r\n"
  2179. + " 乘车前往机场:(谷歌接口异常,无法测算的路程时间)";
  2180. }
  2181. }
  2182. }
  2183. }
  2184. }
  2185. #endregion
  2186. }
  2187. //行程
  2188. trip = trip
  2189. + "\r\n" + GoAirportTime + " 抵达" + font_Airport + _StartBuilding + "航站楼,办理登机手续:"
  2190. + "\r\n" + _startTime.Substring(0, 2) + ":" + _startTime.Substring(2, _startTime.Length - 2) + " 搭乘" + _aircompany_Name + "航空公司" + _flightcode + "航班,由" + font_City + "飞往" + back_City + ";"
  2191. + "\r\n" + " (" + font_Airport + "/" + back_Airport + " 机型:" + airModel + " 飞行时间" + (_flightTime) + ");";
  2192. //标记本行为母版行
  2193. //flightcode_Sign = resultRows[0]["Fliagtcode"].ToString();
  2194. //citycode_Sign = resultRows[0]["Three"].ToString();
  2195. }
  2196. //与前一行航班号,三字码相同且本行抵达时间不包含"+1",则本行是被生成的重复行,仅提示抵达
  2197. else if (resultRows[0]["Sign"].ToString() == "1") /* && (!_endTime.Contains("+"))&&(_flightcode == flightcode_Sign)&&(_citycode == citycode_Sign)*/
  2198. {
  2199. //行程
  2200. trip = trip
  2201. + "\r\n" + _endTime.Substring(0, 2) + ":" + _endTime.Substring(2, _endTime.Length - 2) + " 抵达" + back_Airport + _EndBuilding + "航站楼,办理入境手续,之后前往提取行李";
  2202. //根据航班信息推算离开机场的时间
  2203. int temp = Convert.ToInt32(_endTime.Substring(0, 2)) + 1;
  2204. leaveAirPortTime = temp < 10 ? "0" + temp.ToString() : temp.ToString();
  2205. leaveAirPortTime = leaveAirPortTime + ":" + _endTime.Substring(2, _endTime.Length - 2);
  2206. if (i == timeList.Count - 1)//如果本日是行程的最后一天,则提醒“行程圆满结束”
  2207. {
  2208. trip = trip + ",圆满结束此次访问之行!";
  2209. }
  2210. else //如果本日不是行程的最后一天,正常提醒
  2211. {
  2212. trip += pushTrip(leaveAirPortTime, back_Airport, city,out leaveAirPortTime);
  2213. trip = trip + ";\r\n" + leaveAirPortTime + "搭乘专车前往酒店,抵达后办理入住;";
  2214. }
  2215. //整理离开机场的时间 +10分钟为"乘车前往酒店"的时刻
  2216. int hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  2217. int min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  2218. min = min + 10;
  2219. if (min > 59)
  2220. {
  2221. min = min - 60;
  2222. hour = hour + 1;
  2223. }
  2224. if (hour > 23)
  2225. {
  2226. hour = hour - 24;
  2227. }
  2228. leaveAirPortTime = hour < 10 ? "0" + hour.ToString() : hour.ToString();
  2229. leaveAirPortTime = leaveAirPortTime + ":" + (min < 10 ? "0" + min.ToString() : min.ToString());
  2230. }
  2231. //正常提示
  2232. else
  2233. {
  2234. //根据航班信息推算进入机场的时间
  2235. int temp = Convert.ToInt32(_startTime.Substring(0, 2)) - 2;//一般提前提前2小时
  2236. string result = PublicCode.GetCountryInfo(back_threecode.Country);//美国或者欧洲国家提前3小时
  2237. if (result.Contains("2"))
  2238. {
  2239. temp = Convert.ToInt32(_startTime.Substring(0, 2)) - 3;//提前3小时
  2240. }
  2241. if (temp < 0)
  2242. {
  2243. temp = temp + 24;
  2244. }
  2245. GoAirportTime = temp < 10 ? "0" + temp.ToString() : temp.ToString();
  2246. GoAirportTime = GoAirportTime + ":" + _startTime.Substring(2, _startTime.Length - 2);
  2247. //根据航班信息推算离开机场的时间
  2248. temp = Convert.ToInt32(_endTime.Substring(0, 2)) + 1;
  2249. leaveAirPortTime = temp < 10 ? "0" + temp.ToString() : temp.ToString();
  2250. leaveAirPortTime = leaveAirPortTime + ":" + _endTime.Substring(2, _endTime.Length - 2);
  2251. //第一天之后的行程可以加上“酒店出发到机场”的距离和时间
  2252. if (i > 0)
  2253. {
  2254. #region 酒店
  2255. foreach (HotelReservations h in listht)
  2256. {
  2257. if (Convert.ToDateTime(h.CheckInDate) < Convert.ToDateTime(timeList[i])
  2258. && Convert.ToDateTime(h.CheckOutDate) >= Convert.ToDateTime(timeList[i]))
  2259. {
  2260. //利用谷歌API计算路线
  2261. if (AirPort != "")
  2262. {
  2263. GoogleMapApiResult g = gmrs.GetByDiidAddress(di.Id, h.HotelAddress, font_Airport);
  2264. if (g != null)
  2265. {
  2266. //计算“酒店到机场”的时间
  2267. string CheckoutHotelTime;
  2268. //处理时间格式
  2269. string hours = "0", mins = "0";
  2270. if (g.Time.Contains("hour"))
  2271. {
  2272. g.Time = g.Time.Replace("hour", "h");
  2273. }
  2274. else if (g.Time.Contains("hours"))
  2275. {
  2276. g.Time = g.Time.Replace("hours", "h");
  2277. }
  2278. g.Time = g.Time.Replace("mins", "m");
  2279. if (g.Time.Contains("h"))
  2280. {
  2281. hours = g.Time.Split('h')[0].Trim();
  2282. }
  2283. else if (!g.Time.Contains("h"))
  2284. {
  2285. mins = g.Time.Split('m')[0].Trim();
  2286. }
  2287. int _hour = Convert.ToInt32(GoAirportTime.Substring(0, 2));
  2288. int _min = Convert.ToInt32(GoAirportTime.Substring(3, 2));
  2289. _min = _min - Convert.ToInt32(mins);
  2290. if (_min < 0)
  2291. {
  2292. _min = _min + 60;
  2293. _hour = _hour - 1;
  2294. }
  2295. if (hours != "")
  2296. {
  2297. _hour = _hour - Convert.ToInt32(hours);
  2298. }
  2299. if (_hour < 0)
  2300. {
  2301. _hour = _hour + 24;
  2302. }
  2303. CheckoutHotelTime = _hour < 10 ? "0" + _hour.ToString() : _hour.ToString();
  2304. CheckoutHotelTime = CheckoutHotelTime + ":" + (_min < 10 ? "0" + _min.ToString() : _min.ToString());
  2305. trip = trip + "\r\n"
  2306. + CheckoutHotelTime + " 乘车前往机场:(" + g.Distance + "," + g.Time + ")";
  2307. }
  2308. else
  2309. {
  2310. try
  2311. {
  2312. JObject Result = PublicCode.GetDirectionByGoogleApi(h.HotelAddress, font_Airport);
  2313. //计算“抵达酒店办理入住手续”的时间
  2314. string CheckoutHotelTime;
  2315. //处理时间格式
  2316. string Gtime = "", hours = "0", mins = "0";
  2317. if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hour"))
  2318. {
  2319. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hour", "h");
  2320. }
  2321. else if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hours"))
  2322. {
  2323. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hours", "h");
  2324. }
  2325. Gtime = Gtime.Replace("mins", "m");
  2326. if (!string.IsNullOrEmpty(Gtime) && Gtime.Contains("h"))
  2327. {
  2328. hours = Gtime.Split('h')[0].Trim();
  2329. }
  2330. else if (!string.IsNullOrEmpty(Gtime) && !Gtime.Contains("h"))
  2331. {
  2332. mins = Gtime.Split('m')[0].Trim();
  2333. }
  2334. int _hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  2335. int _min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  2336. _min = _min - Convert.ToInt32(mins);
  2337. if (_min < 0)
  2338. {
  2339. _min = _min + 60;
  2340. _hour = _hour - 1;
  2341. }
  2342. if (hours != "")
  2343. {
  2344. _hour = _hour + Convert.ToInt32(hours);
  2345. }
  2346. if (_hour < 0)
  2347. {
  2348. _hour = _hour + 24;
  2349. }
  2350. CheckoutHotelTime = _hour < 10 ? "0" + _hour.ToString() : _hour.ToString();
  2351. CheckoutHotelTime = CheckoutHotelTime + ":" + (_min < 10 ? "0" + _min.ToString() : _min.ToString());
  2352. GoogleMapApiResult gtemp = new GoogleMapApiResult();
  2353. gtemp.Diid = di.Id;
  2354. gtemp.Date = "";
  2355. gtemp.Moment = "";
  2356. gtemp.StartAddress = AirPort;
  2357. gtemp.EndAddress = h.HotelAddress;
  2358. gtemp.Time = Result["routes"][0]["legs"][0]["duration"]["text"].ToString();
  2359. gtemp.Distance = Result["routes"][0]["legs"][0]["distance"]["text"].ToString();
  2360. gmrs.Add(gtemp);
  2361. trip = trip + "\r\n"
  2362. + CheckoutHotelTime + " 乘车前往机场:(" + gtemp.Distance + "," + gtemp.Time + ")";
  2363. }
  2364. catch
  2365. {
  2366. trip = trip + "\r\n"
  2367. + " 乘车前往机场:(谷歌接口异常,无法测算的路程时间)";
  2368. }
  2369. }
  2370. }
  2371. }
  2372. }
  2373. #endregion
  2374. }
  2375. trip = trip
  2376. + "\r\n" + GoAirportTime + " 抵达" + font_Airport + _StartBuilding + "航站楼,办理登机手续:"
  2377. + "\r\n" + _startTime.Substring(0, 2) + ":" + _startTime.Substring(2, _startTime.Length - 2) + " 搭乘" + _aircompany_Name + "航空公司" + _flightcode + "航班,由" + font_City + "飞往" + back_City + ";"
  2378. + "\r\n" + " (" + font_Airport + "/" + back_Airport + " 机型:" + airModel + " 飞行时间" + (_flightTime) + ");"
  2379. + "\r\n" + _endTime.Substring(0, 2) + ":" + _endTime.Substring(2, _endTime.Length - 2) + " 抵达" + back_Airport + _EndBuilding + "航站楼,办理入境手续,之后前往提取行李";
  2380. if (i == timeList.Count - 1)//如果本日是行程的最后一天,先增加酒店到机场的距离时间,再在末尾提醒“行程圆满结束”
  2381. {
  2382. trip = trip + ",圆满结束此次访问之行!";
  2383. }
  2384. else //如果本日不是行程的最后一天,正常提醒
  2385. {
  2386. trip += pushTrip(leaveAirPortTime, back_Airport, city,out leaveAirPortTime);
  2387. trip = trip + "\r\n" + leaveAirPortTime + " 搭乘专车前往酒店,抵达后办理入住;";
  2388. }
  2389. //整理离开机场的时间 +10分钟为"乘车前往酒店"的时刻
  2390. int hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  2391. int min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  2392. min = min + 10;
  2393. if (min > 59)
  2394. {
  2395. min = min - 60;
  2396. hour = hour + 1;
  2397. }
  2398. if (hour > 23)
  2399. {
  2400. hour = hour - 24;
  2401. }
  2402. leaveAirPortTime = hour < 10 ? "0" + hour.ToString() : hour.ToString();
  2403. leaveAirPortTime = leaveAirPortTime + ":" + (min < 10 ? "0" + min.ToString() : min.ToString());
  2404. }
  2405. #endregion
  2406. }
  2407. //同一天多条数据走分类讨论
  2408. else
  2409. {
  2410. for (int n = 0; n < resultRows.Count(); n++)
  2411. {
  2412. city = "";
  2413. #region 三字码
  2414. string _citycode = resultRows[n]["Three"].ToString();
  2415. //起飞城市三字码
  2416. ThreeCode font_threecode = null;
  2417. string font_citycode = _citycode.Replace("/", string.Empty).Substring(0, 3);
  2418. //抵达城市
  2419. string font_City = "";
  2420. //起飞城市机场
  2421. string font_Airport = "";
  2422. //抵达城市三字码
  2423. ThreeCode back_threecode = null;
  2424. string end_citycode = _citycode.Replace("/", string.Empty).Substring(3, 3);
  2425. //抵达城市机场
  2426. string back_Airport = "";
  2427. //抵达城市
  2428. string back_City = "";
  2429. font_threecode = tcs.getByThree(font_citycode);
  2430. //验证是否存在三字码
  2431. if (font_threecode == null)
  2432. {
  2433. city = city + "【此三字码" + font_citycode + "未收录,请机票同事录入】" + "一";
  2434. font_Airport = "【此三字码" + font_citycode + "未收录,请机票同事录入】";
  2435. font_City = "【此三字码" + font_citycode + "未收录,请机票同事录入】";
  2436. }
  2437. else
  2438. {
  2439. city = city + "/" + font_threecode.City;
  2440. font_Airport = font_threecode.AirPort;
  2441. font_City = font_threecode.City; ;
  2442. }
  2443. back_threecode = tcs.getByThree(end_citycode);
  2444. if (back_threecode == null)
  2445. {
  2446. city = city + "【此三字码" + end_citycode + "未收录,请机票同事录入】" + "一";
  2447. back_Airport = "【此三字码" + end_citycode + "未收录,请机票同事录入】";
  2448. back_City = "【此三字码" + end_citycode + "未收录,请机票同事录入】";
  2449. }
  2450. else
  2451. {
  2452. city = city + "/" + back_threecode.City;
  2453. //部分黄热病国家,需要提醒打疫苗
  2454. string result = PublicCode.GetCountryInfo(back_threecode.Country);
  2455. if (result.Contains("3"))
  2456. {
  2457. city += "(此地区为黄热病地区,请注意打疫苗)";
  2458. }
  2459. back_Airport = back_threecode.AirPort;
  2460. back_City = back_threecode.City;
  2461. //查询酒店路线要用
  2462. AirPort = back_threecode.AirPort;
  2463. }
  2464. //行程里加入城市
  2465. if (trip == "")
  2466. {
  2467. trip = city.TrimStart('/');
  2468. }
  2469. else
  2470. {
  2471. trip = trip + "\r\n"
  2472. + city.TrimStart('/');
  2473. }
  2474. //起飞航站楼
  2475. string _StartBuilding = resultRows[n]["StartBuilding"].ToString();
  2476. //转机航站楼
  2477. string _EndBuilding = resultRows[n]["EndBuilding"].ToString();
  2478. //起飞时刻
  2479. string _startTime = resultRows[n]["StartTime"].ToString();
  2480. //飞行时刻
  2481. string _flightTime = resultRows[n]["FlightTime"].ToString();
  2482. _flightTime = _flightTime.Contains("H") ? _flightTime.Split('H')[0] + "小时" + _flightTime.Split('H')[1].Split('M')[0] + "分钟" : _flightTime.Split('M')[0] + "分钟";
  2483. //到达时刻
  2484. string _endTime = resultRows[n]["EndTime"].ToString();
  2485. //航班号
  2486. string _flightcode = resultRows[n]["Fliagtcode"].ToString();
  2487. //航司
  2488. AirCompany aircompany = acs.getByShortCode(_flightcode.Substring(0, 2));
  2489. string _aircompany_Name = "";
  2490. if (aircompany == null)
  2491. {
  2492. _aircompany_Name = "【此航司" + resultRows[n]["Fliagtcode"].ToString().Substring(0, 2) + "未收录,请机票同事录入】";
  2493. }
  2494. else
  2495. {
  2496. _aircompany_Name = aircompany.CnName;
  2497. }
  2498. //机型判断
  2499. string airModel = resultRows[n]["AirModel"].ToString();
  2500. airModel = PublicCode.GetLonger(airModel.Substring(0, 1)) + airModel;
  2501. #endregion
  2502. //Sign字段为标识,string类型,含义:0表示为原生黑屏代码、1表示“+1”新增的黑屏代码
  2503. //目前存在两种情况:同一天的多条数据标识为“0->0”或“1->0”
  2504. //如下示例
  2505. //Day ArrivedDate Sign
  2506. //10 10 0
  2507. //10 11 0
  2508. //11 11 1
  2509. //11 12 0
  2510. //12 12 1
  2511. if (n == 0)
  2512. {
  2513. //原生机票代码
  2514. if (resultRows[n]["Sign"].ToString() == "0")
  2515. {
  2516. #region trip编辑
  2517. //根据航班信息推算进入机场的时间
  2518. int temp = Convert.ToInt32(_startTime.Substring(0, 2)) - 2;//一般提前提前两小时
  2519. string result = PublicCode.GetCountryInfo(back_threecode.Country);//美国或者欧洲国家提前三小时
  2520. if (result.Contains("2"))
  2521. {
  2522. temp = Convert.ToInt32(_startTime.Substring(0, 2)) - 3;//提前3小时
  2523. }
  2524. if (temp < 0)
  2525. {
  2526. temp = temp + 24;
  2527. }
  2528. GoAirportTime = temp < 10 ? "0" + temp.ToString() : temp.ToString();
  2529. GoAirportTime = GoAirportTime + ":" + _startTime.Substring(2, _startTime.Length - 2);
  2530. //第一天之后的行程可以加上“酒店出发到机场”的距离和时间
  2531. if (i > 0)
  2532. {
  2533. #region 酒店
  2534. foreach (HotelReservations h in listht)
  2535. {
  2536. if (Convert.ToDateTime(h.CheckInDate) < Convert.ToDateTime(timeList[i])
  2537. && Convert.ToDateTime(h.CheckOutDate) >= Convert.ToDateTime(timeList[i]))
  2538. {
  2539. //利用谷歌API计算路线
  2540. if (AirPort != "")
  2541. {
  2542. GoogleMapApiResult g = gmrs.GetByDiidAddress(di.Id, h.HotelAddress, font_Airport);
  2543. if (g != null)
  2544. {
  2545. //计算“酒店到机场”的时间
  2546. string CheckoutHotelTime;
  2547. //处理时间格式
  2548. string hours = "0", mins = "0";
  2549. if (g.Time.Contains("hour"))
  2550. {
  2551. g.Time = g.Time.Replace("hour", "h");
  2552. }
  2553. else if (g.Time.Contains("hours"))
  2554. {
  2555. g.Time = g.Time.Replace("hours", "h");
  2556. }
  2557. g.Time = g.Time.Replace("mins", "m");
  2558. if (g.Time.Contains("h"))
  2559. {
  2560. hours = g.Time.Split('h')[0].Trim();
  2561. }
  2562. else if (!g.Time.Contains("h"))
  2563. {
  2564. mins = g.Time.Split('m')[0].Trim();
  2565. }
  2566. int _hour = Convert.ToInt32(GoAirportTime.Substring(0, 2));
  2567. int _min = Convert.ToInt32(GoAirportTime.Substring(3, 2));
  2568. _min = _min - Convert.ToInt32(mins);
  2569. if (_min < 0)
  2570. {
  2571. _min = _min + 60;
  2572. _hour = _hour - 1;
  2573. }
  2574. if (hours != "")
  2575. {
  2576. _hour = _hour - Convert.ToInt32(hours);
  2577. }
  2578. if (_hour < 0)
  2579. {
  2580. _hour = _hour + 24;
  2581. }
  2582. CheckoutHotelTime = _hour < 10 ? "0" + _hour.ToString() : _hour.ToString();
  2583. CheckoutHotelTime = CheckoutHotelTime + ":" + (_min < 10 ? "0" + _min.ToString() : _min.ToString());
  2584. trip = trip + "\r\n"
  2585. + CheckoutHotelTime + " 乘车前往机场:(" + g.Distance + "," + g.Time + ")";
  2586. }
  2587. else
  2588. {
  2589. try
  2590. {
  2591. JObject Result = PublicCode.GetDirectionByGoogleApi(h.HotelAddress, font_Airport);
  2592. //计算“抵达酒店办理入住手续”的时间
  2593. string CheckoutHotelTime;
  2594. //处理时间格式
  2595. string Gtime = "", hours = "0", mins = "0";
  2596. if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hour"))
  2597. {
  2598. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hour", "h");
  2599. }
  2600. else if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hours"))
  2601. {
  2602. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hours", "h");
  2603. }
  2604. Gtime = Gtime.Replace("mins", "m");
  2605. if (!string.IsNullOrEmpty(Gtime) && Gtime.Contains("h"))
  2606. {
  2607. hours = Gtime.Split('h')[0].Trim();
  2608. }
  2609. else if (!string.IsNullOrEmpty(Gtime) && !Gtime.Contains("h"))
  2610. {
  2611. mins = Gtime.Split('m')[0].Trim();
  2612. }
  2613. int _hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  2614. int _min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  2615. _min = _min - Convert.ToInt32(mins);
  2616. if (_min < 0)
  2617. {
  2618. _min = _min + 60;
  2619. _hour = _hour - 1;
  2620. }
  2621. if (hours != "")
  2622. {
  2623. _hour = _hour + Convert.ToInt32(hours);
  2624. }
  2625. if (_hour < 0)
  2626. {
  2627. _hour = _hour + 24;
  2628. }
  2629. CheckoutHotelTime = _hour < 10 ? "0" + _hour.ToString() : _hour.ToString();
  2630. CheckoutHotelTime = CheckoutHotelTime + ":" + (_min < 10 ? "0" + _min.ToString() : _min.ToString());
  2631. trip = trip + "\r\n"
  2632. + CheckoutHotelTime + " 乘车前往机场:(" + g.Distance + "," + g.Time + ")";
  2633. GoogleMapApiResult gtemp = new GoogleMapApiResult();
  2634. gtemp.Diid = di.Id;
  2635. gtemp.Date = "";
  2636. gtemp.Moment = "";
  2637. gtemp.StartAddress = AirPort;
  2638. gtemp.EndAddress = h.HotelAddress;
  2639. gtemp.Time = Result["routes"][0]["legs"][0]["duration"]["text"].ToString();
  2640. gtemp.Distance = Result["routes"][0]["legs"][0]["distance"]["text"].ToString();
  2641. gmrs.Add(gtemp);
  2642. }
  2643. catch
  2644. {
  2645. trip = trip + "\r\n"
  2646. + " 乘车前往机场:(谷歌接口异常,无法测算的路程时间)";
  2647. }
  2648. }
  2649. }
  2650. }
  2651. }
  2652. #endregion
  2653. }
  2654. trip = trip
  2655. + "\r\n" + GoAirportTime + " 抵达" + font_Airport + _StartBuilding + "航站楼,办理登机手续:"
  2656. + "\r\n" + _startTime.Substring(0, 2) + ":" + _startTime.Substring(2, _startTime.Length - 2) + " 搭乘" + _aircompany_Name + "航空公司" + _flightcode + "航班,由" + font_City + "飞往" + back_City + ";"
  2657. + "\r\n" + " (" + font_Airport + "/" + back_Airport + " 机型:" + airModel + " 飞行时间" + (_flightTime) + ");"
  2658. + "\r\n" + _endTime.Substring(0, 2) + ":" + _endTime.Substring(2, _endTime.Length - 2) + " 抵达" + back_Airport + _EndBuilding + "航站楼,提取行李;";
  2659. #endregion
  2660. }
  2661. //"+1"生成的机票代码
  2662. else if (resultRows[n]["Sign"].ToString() == "1")
  2663. {
  2664. #region trip编辑
  2665. //行程
  2666. trip = trip
  2667. + "\r\n" + _endTime.Substring(0, 2) + ":" + _endTime.Substring(2, _endTime.Length - 2) + " 抵达" + back_Airport + _EndBuilding + "航站楼,提取行李;";
  2668. #endregion
  2669. }
  2670. }
  2671. else if (n > 0)
  2672. {
  2673. //若前行是原生的,则本行判定为转机
  2674. if (resultRows[n - 1]["Sign"].ToString() == "0")
  2675. {
  2676. #region trip编辑
  2677. int temp = Convert.ToInt32(_startTime.Substring(0, 2)) - 1;//一般提前提前2小时
  2678. if (temp < 0)
  2679. {
  2680. temp = temp + 24;
  2681. }
  2682. GoAirportTime = temp < 10 ? "0" + temp.ToString() : temp.ToString();
  2683. GoAirportTime = GoAirportTime + ":" + _startTime.Substring(2, _startTime.Length - 2);
  2684. trip = trip
  2685. + "\r\n" + GoAirportTime + " 抵达" + font_Airport + _StartBuilding + "航站楼,办理登机手续:"
  2686. + "\r\n" + _startTime.Substring(0, 2) + ":" + _startTime.Substring(2, _startTime.Length - 2) + " 搭乘" + _aircompany_Name + "航空公司" + _flightcode + "航班,由" + font_City + "飞往" + back_City + ";"
  2687. + "\r\n" + " (" + font_Airport + "/" + back_Airport + " 机型:" + airModel + " 飞行时间" + (_flightTime) + ");"
  2688. + "\r\n" + _endTime.Substring(0, 2) + ":" + _endTime.Substring(2, _endTime.Length - 2) + " 抵达" + back_Airport + _EndBuilding + "航站楼,办理入境手续,之后前往提取行李";
  2689. //若为最后一行,则计算后备等时间
  2690. if (n == resultRows.Count() - 1)
  2691. {
  2692. //根据航班信息推算离开机场的时间
  2693. temp = Convert.ToInt32(_endTime.Substring(0, 2)) + 1;
  2694. leaveAirPortTime = temp < 10 ? "0" + temp.ToString() : temp.ToString();
  2695. leaveAirPortTime = leaveAirPortTime + ":" + _endTime.Substring(2, _endTime.Length - 2);
  2696. if (i == timeList.Count - 1)//如果本日是行程的最后一天,先增加酒店到机场的距离时间,再在末尾提醒“行程圆满结束”
  2697. {
  2698. trip = trip + ",圆满结束此次访问之行!";
  2699. }
  2700. else //如果本日不是行程的最后一天,正常提醒
  2701. {
  2702. trip += pushTrip(leaveAirPortTime, back_Airport, city,out leaveAirPortTime);
  2703. trip = trip + ";\r\n" + leaveAirPortTime + "搭乘专车前往酒店,抵达后办理入住;";
  2704. }
  2705. //整理离开机场的时间 +10分钟为"乘车前往酒店"的时刻
  2706. int hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  2707. int min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  2708. min = min + 10;
  2709. if (min > 59)
  2710. {
  2711. min = min - 60;
  2712. hour = hour + 1;
  2713. }
  2714. if (hour > 23)
  2715. {
  2716. hour = hour - 24;
  2717. }
  2718. leaveAirPortTime = hour < 10 ? "0" + hour.ToString() : hour.ToString();
  2719. leaveAirPortTime = leaveAirPortTime + ":" + (min < 10 ? "0" + min.ToString() : min.ToString());
  2720. }
  2721. #endregion
  2722. }
  2723. //若前行是生成的,则本行判定为新出发
  2724. else if (resultRows[n - 1]["Sign"].ToString() == "1")
  2725. {
  2726. #region trip编辑
  2727. //根据航班信息推算进入机场的时间
  2728. int temp = Convert.ToInt32(_startTime.Substring(0, 2)) - 2;//一般提前提前2小时
  2729. string result = PublicCode.GetCountryInfo(back_threecode.Country);//美国或者欧洲国家提前3小时
  2730. if (result.Contains("2"))
  2731. {
  2732. temp = Convert.ToInt32(_startTime.Substring(0, 2)) - 3;//提前3小时
  2733. }
  2734. if (temp < 0)
  2735. {
  2736. temp = temp + 24;
  2737. }
  2738. GoAirportTime = temp < 10 ? "0" + temp.ToString() : temp.ToString();
  2739. GoAirportTime = GoAirportTime + ":" + _startTime.Substring(2, _startTime.Length - 2);
  2740. //根据航班信息推算离开机场的时间
  2741. temp = Convert.ToInt32(_endTime.Substring(0, 2)) + 1;
  2742. leaveAirPortTime = temp < 10 ? "0" + temp.ToString() : temp.ToString();
  2743. leaveAirPortTime = leaveAirPortTime + ":" + _endTime.Substring(2, _endTime.Length - 2);
  2744. //第一天之后的行程可以加上“酒店出发到机场”的距离和时间
  2745. if (i > 0)
  2746. {
  2747. #region 酒店
  2748. foreach (HotelReservations h in listht)
  2749. {
  2750. if (Convert.ToDateTime(h.CheckInDate) < Convert.ToDateTime(timeList[i])
  2751. && Convert.ToDateTime(h.CheckOutDate) >= Convert.ToDateTime(timeList[i]))
  2752. {
  2753. //利用谷歌API计算路线
  2754. if (AirPort != "")
  2755. {
  2756. GoogleMapApiResult g = gmrs.GetByDiidAddress(di.Id, h.HotelAddress, font_Airport);
  2757. if (g != null)
  2758. {
  2759. //计算“酒店到机场”的时间
  2760. string CheckoutHotelTime;
  2761. //处理时间格式
  2762. string hours = "0", mins = "0";
  2763. if (g.Time.Contains("hour"))
  2764. {
  2765. g.Time = g.Time.Replace("hour", "h");
  2766. }
  2767. else if (g.Time.Contains("hours"))
  2768. {
  2769. g.Time = g.Time.Replace("hours", "h");
  2770. }
  2771. g.Time = g.Time.Replace("mins", "m");
  2772. if (g.Time.Contains("h"))
  2773. {
  2774. hours = g.Time.Split('h')[0].Trim();
  2775. }
  2776. else if (!g.Time.Contains("h"))
  2777. {
  2778. mins = g.Time.Split('m')[0].Trim();
  2779. }
  2780. int _hour = Convert.ToInt32(GoAirportTime.Substring(0, 2));
  2781. int _min = Convert.ToInt32(GoAirportTime.Substring(3, 2));
  2782. _min = _min - Convert.ToInt32(mins);
  2783. if (_min < 0)
  2784. {
  2785. _min = _min + 60;
  2786. _hour = _hour - 1;
  2787. }
  2788. if (hours != "")
  2789. {
  2790. _hour = _hour - Convert.ToInt32(hours);
  2791. }
  2792. if (_hour < 0)
  2793. {
  2794. _hour = _hour + 24;
  2795. }
  2796. CheckoutHotelTime = _hour < 10 ? "0" + _hour.ToString() : _hour.ToString();
  2797. CheckoutHotelTime = CheckoutHotelTime + ":" + (_min < 10 ? "0" + _min.ToString() : _min.ToString());
  2798. trip = trip + "\r\n"
  2799. + CheckoutHotelTime + " 乘车前往机场:(" + g.Distance + "," + g.Time + ")";
  2800. }
  2801. else
  2802. {
  2803. try
  2804. {
  2805. JObject Result = PublicCode.GetDirectionByGoogleApi(h.HotelAddress, font_Airport);
  2806. //计算“抵达酒店办理入住手续”的时间
  2807. string CheckoutHotelTime;
  2808. //处理时间格式
  2809. string Gtime = "", hours = "0", mins = "0";
  2810. if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hour"))
  2811. {
  2812. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hour", "h");
  2813. }
  2814. else if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hours"))
  2815. {
  2816. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hours", "h");
  2817. }
  2818. Gtime = Gtime.Replace("mins", "m");
  2819. if (!string.IsNullOrEmpty(Gtime) && Gtime.Contains("h"))
  2820. {
  2821. hours = Gtime.Split('h')[0].Trim();
  2822. }
  2823. else if (!string.IsNullOrEmpty(Gtime) && !Gtime.Contains("h"))
  2824. {
  2825. mins = Gtime.Split('m')[0].Trim();
  2826. }
  2827. int _hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  2828. int _min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  2829. _min = _min - Convert.ToInt32(mins);
  2830. if (_min < 0)
  2831. {
  2832. _min = _min + 60;
  2833. _hour = _hour - 1;
  2834. }
  2835. if (hours != "")
  2836. {
  2837. _hour = _hour + Convert.ToInt32(hours);
  2838. }
  2839. if (_hour < 0)
  2840. {
  2841. _hour = _hour + 24;
  2842. }
  2843. CheckoutHotelTime = _hour < 10 ? "0" + _hour.ToString() : _hour.ToString();
  2844. CheckoutHotelTime = CheckoutHotelTime + ":" + (_min < 10 ? "0" + _min.ToString() : _min.ToString());
  2845. trip = trip + "\r\n"
  2846. + CheckoutHotelTime + " 乘车前往机场:(" + g.Distance + "," + g.Time + ")";
  2847. GoogleMapApiResult gtemp = new GoogleMapApiResult();
  2848. gtemp.Diid = di.Id;
  2849. gtemp.Date = "";
  2850. gtemp.Moment = "";
  2851. gtemp.StartAddress = AirPort;
  2852. gtemp.EndAddress = h.HotelAddress;
  2853. gtemp.Time = Result["routes"][0]["legs"][0]["duration"]["text"].ToString();
  2854. gtemp.Distance = Result["routes"][0]["legs"][0]["distance"]["text"].ToString();
  2855. gmrs.Add(gtemp);
  2856. }
  2857. catch
  2858. {
  2859. trip = trip + "\r\n"
  2860. + " 乘车前往机场:(谷歌接口异常,无法测算的路程时间)";
  2861. }
  2862. }
  2863. }
  2864. }
  2865. }
  2866. #endregion
  2867. }
  2868. trip = trip
  2869. + "\r\n" + GoAirportTime + " 抵达" + font_Airport + _StartBuilding + "航站楼,办理登机手续:"
  2870. + "\r\n" + _startTime.Substring(0, 2) + ":" + _startTime.Substring(2, _startTime.Length - 2) + " 搭乘" + _aircompany_Name + "航空公司" + _flightcode + "航班,由" + font_City + "飞往" + back_City + ";"
  2871. + "\r\n" + " (" + font_Airport + "/" + back_Airport + " 机型:" + airModel + " 飞行时间" + (_flightTime) + ");"
  2872. + "\r\n" + _endTime.Substring(0, 2) + ":" + _endTime.Substring(2, _endTime.Length - 2) + " 抵达" + back_Airport + _EndBuilding + "航站楼,办理入境手续,之后前往提取行李";
  2873. if (i == timeList.Count - 1)//如果本日是行程的最后一天,先增加酒店到机场的距离时间,再在末尾提醒“行程圆满结束”
  2874. {
  2875. trip = trip + ",圆满结束此次访问之行!";
  2876. }
  2877. else //如果本日不是行程的最后一天,正常提醒
  2878. {
  2879. trip += pushTrip(leaveAirPortTime, back_Airport, city,out leaveAirPortTime);
  2880. trip = trip + ";\r\n" + leaveAirPortTime + " 搭乘专车前往酒店,抵达后办理入住;";
  2881. }
  2882. //整理离开机场的时间 +10分钟为"乘车前往酒店"的时刻
  2883. int hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  2884. int min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  2885. min = min + 10;
  2886. if (min > 59)
  2887. {
  2888. min = min - 60;
  2889. hour = hour + 1;
  2890. }
  2891. if (hour > 23)
  2892. {
  2893. hour = hour - 24;
  2894. }
  2895. leaveAirPortTime = hour < 10 ? "0" + hour.ToString() : hour.ToString();
  2896. leaveAirPortTime = leaveAirPortTime + ":" + (min < 10 ? "0" + min.ToString() : min.ToString());
  2897. #endregion
  2898. }
  2899. }
  2900. }
  2901. }
  2902. #endregion
  2903. #region 行程和城市赋值
  2904. if (trip == "" || trip == " " || city == "" || city == " ")
  2905. {
  2906. city = CityInDateList.Find(cid => cid.Date == timeList[i]).City;
  2907. //部分黄热病国家,需要提醒打疫苗
  2908. string result = PublicCode.GetCountryInfo(tcs.getByCity(city)[0].Country);
  2909. if (result.Contains("3"))
  2910. {
  2911. city += "(此地区为黄热病地区,请注意打疫苗)";
  2912. }
  2913. trip = city;
  2914. }
  2915. #endregion
  2916. #region 公务 20210820 贾文滔
  2917. string OATemp = "";//暂存公务活动
  2918. //根据团号和日期获取公务数据
  2919. List<OfficialActivities> listoa = oas.getByDiidAndDate(comb_Diid, timeList[i]);
  2920. //若listoa存在公务数据,进行排序,再进行导入
  2921. if (listoa != null && listoa.Count > 0)
  2922. {
  2923. //利用datatable存放公务活动数据
  2924. DataTable OA_DataTable = new DataTable();
  2925. OA_DataTable.Columns.Add("StartTime", typeof(string)); //activity开始时刻
  2926. OA_DataTable.Columns.Add("EndTime", typeof(string)); //activity结束时刻
  2927. OA_DataTable.Columns.Add("Client", typeof(string)); //activity单位
  2928. OA_DataTable.Columns.Add("Address", typeof(string)); //activity地址
  2929. OA_DataTable.Columns.Add("Contact", typeof(string)); //activity联系人
  2930. OA_DataTable.Columns.Add("Tel", typeof(string)); //activity联系人电话
  2931. OA_DataTable.Columns.Add("Dresscode", typeof(string)); //activity着装要求
  2932. OA_DataTable.Columns.Add("isTranslate", typeof(bool));//是否需要翻译人员
  2933. OA_DataTable.Columns.Add("Language", typeof(string));//是否需要翻译人员
  2934. //处理公务数据
  2935. for (int b = 0; b < listoa.Count; b++)
  2936. {
  2937. //起止时间
  2938. string[] time = new string[2];
  2939. if (listoa[b].Time.Contains('—'))
  2940. {
  2941. time = listoa[b].Time.Split('—');
  2942. }
  2943. else if (listoa[b].Time.Contains('-'))
  2944. {
  2945. time = listoa[b].Time.Split('-');
  2946. }
  2947. //添加数据
  2948. if (time.Length >= 2)
  2949. {
  2950. OA_DataTable.Rows.Add(time[0], time[1], listoa[b].Client, listoa[b].Address, listoa[b].Contact, listoa[b].Tel, listoa[b].Dresscode, listoa[b].IsNeedTrans, listoa[b].Language);
  2951. }
  2952. else
  2953. {
  2954. //PublicCode.GetAlertMsg(this, GetType(), timeList[i] + "的公务数据有误,请检查");
  2955. }
  2956. }
  2957. //排序
  2958. OA_DataTable.DefaultView.Sort = "StartTime asc";
  2959. OA_DataTable = OA_DataTable.DefaultView.ToTable();
  2960. //导入信息
  2961. for (int index = 0; index < OA_DataTable.Rows.Count; index++)
  2962. {
  2963. if (i == 0)//行程第一天的公务放在酒店后面,所以先暂存在一个变量里
  2964. {
  2965. if (OATemp != "")
  2966. {
  2967. OATemp = OATemp + "\r\n"
  2968. + OA_DataTable.Rows[index]["StartTime"].ToString()
  2969. + "-"
  2970. + OA_DataTable.Rows[index]["EndTime"].ToString()
  2971. + " 拜访" + OA_DataTable.Rows[index]["Client"].ToString()
  2972. + ",联系人:" + OA_DataTable.Rows[index]["Contact"].ToString()
  2973. + ",电话:" + OA_DataTable.Rows[index]["Tel"].ToString()
  2974. + ",地址:" + OA_DataTable.Rows[index]["Address"].ToString()
  2975. + ",着装要求:" + OA_DataTable.Rows[index]["Dresscode"].ToString()
  2976. + ",是否需要翻译:" + (bool.Parse(OA_DataTable.Rows[index]["isTranslate"].ToString()) ? "需要翻译人员" + "翻译语种为" + OA_DataTable.Rows[index]["Language"].ToString() : "不需要翻译人员")
  2977. + ",议题:-";
  2978. }
  2979. else
  2980. {
  2981. OATemp = OA_DataTable.Rows[index]["StartTime"].ToString()
  2982. + "-"
  2983. + OA_DataTable.Rows[index]["EndTime"].ToString()
  2984. + " 拜访" + OA_DataTable.Rows[index]["Client"].ToString()
  2985. + ",联系人:" + OA_DataTable.Rows[index]["Contact"].ToString()
  2986. + ",电话:" + OA_DataTable.Rows[index]["Tel"].ToString()
  2987. + ",地址:" + OA_DataTable.Rows[index]["Address"].ToString()
  2988. + ",着装要求:" + OA_DataTable.Rows[index]["Dresscode"].ToString()
  2989. + ",是否需要翻译:" + (bool.Parse(OA_DataTable.Rows[index]["isTranslate"].ToString()) ? "需要翻译人员" + "翻译语种为" + OA_DataTable.Rows[index]["Language"].ToString() : "不需要翻译人员")
  2990. + ",议题:-";
  2991. }
  2992. }
  2993. else
  2994. {
  2995. //导入公务
  2996. trip = trip + "\r\n"
  2997. + OA_DataTable.Rows[index]["StartTime"].ToString()
  2998. + "-"
  2999. + OA_DataTable.Rows[index]["EndTime"].ToString()
  3000. + " 拜访" + OA_DataTable.Rows[index]["Client"].ToString()
  3001. + ",联系人:" + OA_DataTable.Rows[index]["Contact"].ToString()
  3002. + ",电话:" + OA_DataTable.Rows[index]["Tel"].ToString()
  3003. + ",地址:" + OA_DataTable.Rows[index]["Address"].ToString()
  3004. + ",着装要求:" + OA_DataTable.Rows[index]["Dresscode"].ToString()
  3005. + ",是否需要翻译:" + (bool.Parse(OA_DataTable.Rows[index]["isTranslate"].ToString()) ? "需要翻译人员" + "翻译语种为" + OA_DataTable.Rows[index]["Language"].ToString() : "不需要翻译人员")
  3006. + ",议题:-";
  3007. }
  3008. //当天第一个公务或许都是从酒店出发,因此可计算酒店到公务地址的距离和时间
  3009. if (index == 0)
  3010. {
  3011. #region 酒店
  3012. foreach (HotelReservations h in listht)
  3013. {
  3014. if (Convert.ToDateTime(h.CheckInDate) <= Convert.ToDateTime(timeList[i])
  3015. && Convert.ToDateTime(h.CheckOutDate) > Convert.ToDateTime(timeList[i]))
  3016. {
  3017. //利用谷歌API计算路线
  3018. GoogleMapApiResult g = gmrs.GetByDiidAddress(di.Id, h.HotelAddress, OA_DataTable.Rows[0]["Address"].ToString());
  3019. if (g != null)
  3020. {
  3021. if (i == 0)//行程第一天的公务放在酒店后面,所以先暂存在一个变量里
  3022. {
  3023. OATemp = OATemp + "。 (" + g.Distance + "," + g.Time + ")";
  3024. }
  3025. else
  3026. {
  3027. trip = trip + "。 (" + g.Distance + "," + g.Time + ")";
  3028. }
  3029. }
  3030. else
  3031. {
  3032. try
  3033. {
  3034. JObject Result = PublicCode.GetDirectionByGoogleApi(h.HotelAddress, OA_DataTable.Rows[0]["Address"].ToString());
  3035. if (i == 0)//行程第一天的公务放在酒店后面,所以先暂存在一个变量里
  3036. {
  3037. OATemp = OATemp + "。 (" + Result["routes"][0]["legs"][0]["distance"]["text"].ToString() + ","
  3038. + Result["routes"][0]["legs"][0]["duration"]["text"].ToString() + ")";
  3039. }
  3040. else
  3041. {
  3042. trip = trip + "。 (" + Result["routes"][0]["legs"][0]["distance"]["text"].ToString() + ","
  3043. + Result["routes"][0]["legs"][0]["duration"]["text"].ToString() + ")";
  3044. }
  3045. GoogleMapApiResult gtemp = new GoogleMapApiResult();
  3046. gtemp.Diid = di.Id;
  3047. gtemp.Date = "";
  3048. gtemp.Moment = "";
  3049. gtemp.StartAddress = h.HotelAddress;
  3050. gtemp.EndAddress = OA_DataTable.Rows[0]["Address"].ToString();
  3051. gtemp.Time = Result["routes"][0]["legs"][0]["duration"]["text"].ToString();
  3052. gtemp.Distance = Result["routes"][0]["legs"][0]["distance"]["text"].ToString();
  3053. gmrs.Add(gtemp);
  3054. }
  3055. catch
  3056. {
  3057. if (i == 0)//行程第一天的公务放在酒店后面,所以先暂存在一个变量里
  3058. {
  3059. OATemp = OATemp + "。 (谷歌接口异常,无法测算路程时间)";
  3060. }
  3061. else
  3062. {
  3063. trip = trip + "。 (谷歌接口异常,无法测算路程时间)";
  3064. }
  3065. }
  3066. }
  3067. }
  3068. }
  3069. #endregion
  3070. }
  3071. //第二个公务是由中午的餐厅前往公务地址,具有随机性,因此不计算此方向距离时间;但可计算由公务地址回酒店的信息
  3072. else
  3073. {
  3074. #region 酒店
  3075. foreach (HotelReservations h in listht)
  3076. {
  3077. if (Convert.ToDateTime(h.CheckInDate) <= Convert.ToDateTime(timeList[i])
  3078. && Convert.ToDateTime(h.CheckOutDate) > Convert.ToDateTime(timeList[i]))
  3079. {
  3080. //利用谷歌API计算路线
  3081. GoogleMapApiResult g = gmrs.GetByDiidAddress(di.Id, OA_DataTable.Rows[index]["Address"].ToString(), h.HotelAddress);
  3082. if (g != null)
  3083. {
  3084. if (i == 0)//行程第一天的公务放在酒店后面,所以先暂存在一个变量里
  3085. {
  3086. OATemp = OATemp + "。 (" + g.Distance + "," + g.Time + ")";
  3087. }
  3088. else
  3089. {
  3090. trip = trip + "。 (" + g.Distance + "," + g.Time + ")";
  3091. }
  3092. }
  3093. else
  3094. {
  3095. try
  3096. {
  3097. JObject Result = PublicCode.GetDirectionByGoogleApi(OA_DataTable.Rows[index]["Address"].ToString(), h.HotelAddress);
  3098. if (i == 0)//行程第一天的公务放在酒店后面,所以先暂存在一个变量里
  3099. {
  3100. OATemp = OATemp + "。 (" + Result["routes"][0]["legs"][0]["distance"]["text"].ToString() + ","
  3101. + Result["routes"][0]["legs"][0]["duration"]["text"].ToString() + ")";
  3102. }
  3103. else
  3104. {
  3105. trip = trip + "。 (" + Result["routes"][0]["legs"][0]["distance"]["text"].ToString() + ","
  3106. + Result["routes"][0]["legs"][0]["duration"]["text"].ToString() + ")";
  3107. }
  3108. GoogleMapApiResult gtemp = new GoogleMapApiResult();
  3109. gtemp.Diid = di.Id;
  3110. gtemp.Date = "";
  3111. gtemp.Moment = "";
  3112. gtemp.StartAddress = OA_DataTable.Rows[0]["Address"].ToString();
  3113. gtemp.EndAddress = h.HotelAddress;
  3114. gtemp.Time = Result["routes"][0]["legs"][0]["duration"]["text"].ToString();
  3115. gtemp.Distance = Result["routes"][0]["legs"][0]["distance"]["text"].ToString();
  3116. gmrs.Add(gtemp);
  3117. }
  3118. catch
  3119. {
  3120. if (i == 0)//行程第一天的公务放在酒店后面,所以先暂存在一个变量里
  3121. {
  3122. OATemp = OATemp + "。 (谷歌接口异常,无法测算路程时间)";
  3123. }
  3124. else
  3125. {
  3126. trip = trip + "。 (谷歌接口异常,无法测算路程时间)";
  3127. }
  3128. }
  3129. }
  3130. }
  3131. }
  3132. #endregion
  3133. }
  3134. }
  3135. }
  3136. #endregion
  3137. #region 酒店
  3138. foreach (HotelReservations h in listht)
  3139. {
  3140. if (Convert.ToDateTime(h.CheckInDate) <= Convert.ToDateTime(timeList[i])
  3141. && Convert.ToDateTime(h.CheckOutDate) > Convert.ToDateTime(timeList[i]))//不去“》=”的原因是行程最后一天一般不会有酒店
  3142. {
  3143. //利用谷歌API计算路线
  3144. if (AirPort != "")
  3145. {
  3146. GoogleMapApiResult g = gmrs.GetByDiidAddress(di.Id, AirPort, h.HotelAddress);
  3147. if (g != null)
  3148. {
  3149. trip = trip + "\r\n"
  3150. + leaveAirPortTime + " 乘车前往酒店:(" + g.Distance + "," + g.Time + ")";
  3151. //计算“抵达酒店办理入住手续”的时间
  3152. string CheckInHotelTime;
  3153. //处理时间格式
  3154. string hours = "", mins = "";
  3155. if (g.Time.Contains("hour"))
  3156. {
  3157. g.Time = g.Time.Replace("hour", "h");
  3158. }
  3159. else if (g.Time.Contains("hours"))
  3160. {
  3161. g.Time = g.Time.Replace("hours", "h");
  3162. }
  3163. g.Time = g.Time.Replace("mins", "m");
  3164. if (g.Time.Contains("h"))
  3165. {
  3166. hours = g.Time.Split('h')[0].Trim();
  3167. }
  3168. else if (!g.Time.Contains("h"))
  3169. {
  3170. mins = g.Time.Split('m')[0].Trim();
  3171. }
  3172. int hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  3173. int min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  3174. min = min + Convert.ToInt32(mins);
  3175. if (min > 59)
  3176. {
  3177. min = min - 60;
  3178. hour = hour + 1;
  3179. }
  3180. if (hours != "")
  3181. {
  3182. hour = hour + Convert.ToInt32(hours);
  3183. }
  3184. if (hour > 23)
  3185. {
  3186. hour = hour - 24;
  3187. }
  3188. CheckInHotelTime = hour < 10 ? "0" + hour.ToString() : hour.ToString();
  3189. CheckInHotelTime = CheckInHotelTime + ":" + (min < 10 ? "0" + min.ToString() : min.ToString());
  3190. trip = trip + "\r\n"
  3191. + CheckInHotelTime + " 抵达酒店办理入住手续";
  3192. }
  3193. else
  3194. {
  3195. try
  3196. {
  3197. JObject Result = PublicCode.GetDirectionByGoogleApi(AirPort, h.HotelAddress);
  3198. trip = trip + "\r\n"
  3199. + leaveAirPortTime + " 乘车前往酒店:(" + Result["routes"][0]["legs"][0]["distance"]["text"].ToString() + ","
  3200. + Result["routes"][0]["legs"][0]["duration"]["text"].ToString() + ")";
  3201. //计算“抵达酒店办理入住手续”的时间
  3202. string CheckInHotelTime;
  3203. //处理时间格式
  3204. string Gtime = "", hours = "", mins = "";
  3205. if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hour"))
  3206. {
  3207. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hour", "h");
  3208. }
  3209. else if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hours"))
  3210. {
  3211. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hours", "h");
  3212. }
  3213. Gtime = Gtime.Replace("mins", "m");
  3214. if (!string.IsNullOrEmpty(Gtime) && Gtime.Contains("h"))
  3215. {
  3216. hours = Gtime.Split('h')[0].Trim();
  3217. }
  3218. else if (!string.IsNullOrEmpty(Gtime) && !Gtime.Contains("h"))
  3219. {
  3220. mins = Gtime.Split('m')[0].Trim();
  3221. }
  3222. int hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  3223. int min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  3224. if (mins != "")
  3225. min = min + Convert.ToInt32(mins);
  3226. if (min > 59)
  3227. {
  3228. min = min - 60;
  3229. hour = hour + 1;
  3230. }
  3231. if (hours != "")
  3232. {
  3233. hour = hour + Convert.ToInt32(hours);
  3234. }
  3235. if (hour > 23)
  3236. {
  3237. hour = hour - 24;
  3238. }
  3239. CheckInHotelTime = hour < 10 ? "0" + hour.ToString() : hour.ToString();
  3240. CheckInHotelTime = CheckInHotelTime + ":" + (min < 10 ? "0" + min.ToString() : min.ToString());
  3241. trip = trip + "\r\n"
  3242. + CheckInHotelTime + " 抵达酒店办理入住手续";
  3243. GoogleMapApiResult gtemp = new GoogleMapApiResult();
  3244. gtemp.Diid = di.Id;
  3245. gtemp.Date = "";
  3246. gtemp.Moment = "";
  3247. gtemp.StartAddress = AirPort;
  3248. gtemp.EndAddress = h.HotelAddress;
  3249. gtemp.Time = Result["routes"][0]["legs"][0]["duration"]["text"].ToString();
  3250. gtemp.Distance = Result["routes"][0]["legs"][0]["distance"]["text"].ToString();
  3251. gmrs.Add(gtemp);
  3252. }
  3253. catch
  3254. {
  3255. trip = trip + "\r\n"
  3256. + " (谷歌接口异常,无法测算的路程时间)";
  3257. }
  3258. }
  3259. }
  3260. trip = trip + "\r\n"
  3261. + " 酒店名称:" + h.HotelName + "\r\n"
  3262. + " 酒店地址:" + h.HotelAddress + "\r\n"
  3263. + " 酒店电话:" + h.HotelTel + " 酒店传真:" + (h.HotelFax == "" ? "-" : h.HotelFax);
  3264. if (i == 0 && !string.IsNullOrEmpty(OATemp))
  3265. {
  3266. trip = trip + "\r\n" + OATemp;
  3267. }
  3268. }
  3269. }
  3270. #endregion
  3271. #region 当天交通工具赋值
  3272. //一般行程第一天都是先乘坐飞机后乘坐汽车
  3273. if (i == 0)
  3274. {
  3275. tlTemp.Traffic_First = "飞机";
  3276. tlTemp.Traffic_Second = "汽车";
  3277. }
  3278. else
  3279. {
  3280. // 根据车导地接表数据判断交通工具:汽车
  3281. List<CarTouristGuideGroundReservations> ListCar = listctg.FindAll(c => Convert.ToDateTime(c.ServiceStartTime) <= Convert.ToDateTime(timeList[i])
  3282. && Convert.ToDateTime(c.ServiceEndTime) >= Convert.ToDateTime(timeList[i]));
  3283. //交通工具:汽车
  3284. if (ListCar.Count > 0)
  3285. {
  3286. tlTemp.Traffic_First = "汽车";
  3287. //交通工具:飞机
  3288. if (airSign == true)
  3289. {
  3290. tlTemp.Traffic_Second = "飞机";
  3291. }
  3292. else
  3293. {
  3294. tlTemp.Traffic_Second = "";
  3295. }
  3296. }
  3297. else
  3298. {
  3299. tlTemp.Traffic_First = "汽车";
  3300. //交通工具:飞机
  3301. if (airSign == true)
  3302. {
  3303. tlTemp.Traffic_Second = "飞机";
  3304. }
  3305. else
  3306. {
  3307. tlTemp.Traffic_Second = "";
  3308. }
  3309. }
  3310. }
  3311. #endregion
  3312. tlTemp.Trip = trip;
  3313. tlTemp.OPer = di.Id;
  3314. tlTemp.OPdate = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
  3315. //tlTemp.OPdate = PublicCode.GetBeijingTime().ToString("yyyy-MM-dd hh:mm:ss");
  3316. tlTemp.issel = 1;
  3317. tlTemp.diffgroup = 1;
  3318. tlTemp.Isdel = 0;
  3319. tls.AddTravelList(tlTemp);
  3320. }
  3321. }
  3322. }
  3323. catch (Exception ex)
  3324. {
  3325. //Response.Write(ex.Message.ToString());
  3326. lblImport.Text = ex.Message;
  3327. }
  3328. lblImport.Text = "数据录入完成";
  3329. }
  3330. }
  3331. private string pushTrip(string timeStr, string startAddress , string endAddress , out string timeOut)
  3332. {
  3333. startAddress = startAddress.Trim().Replace("(此地区为黄热病地区,请注意打疫苗)","");
  3334. endAddress = endAddress.Trim().Replace("(此地区为黄热病地区,请注意打疫苗)", "");
  3335. decimal conversion = 1.61M;
  3336. DateTime tripTime = DateTime.Parse(timeStr).AddHours(-1);
  3337. endAddress = endAddress.TrimStart('/');
  3338. string CheckoutHotelTime = string.Empty;
  3339. string endCity = string.Empty;
  3340. if (endAddress.Contains("/"))
  3341. {
  3342. endCity = endAddress.Split('/')[1] + "市区";
  3343. }
  3344. else
  3345. {
  3346. endCity = endAddress + "市区";
  3347. }
  3348. string Time = string.Empty;
  3349. string Distance = string.Empty;
  3350. int GetGoogleResult = 0;
  3351. JObject Result = null;
  3352. try
  3353. {
  3354. Result = PublicCode.GetDirectionByGoogleApi(startAddress, endCity);
  3355. Time = Result["routes"][0]["legs"][0]["duration"]["text"].ToString();
  3356. Distance = Result["routes"][0]["legs"][0]["distance"]["text"].ToString();
  3357. if (Time.Contains("hours"))
  3358. {
  3359. Time = Time.Replace("hours", "小时");
  3360. }
  3361. else if (Time.Contains("hour"))
  3362. {
  3363. Time = Time.Replace("hour", "小时");
  3364. }
  3365. Time = Time.Replace("mins", "分钟");
  3366. if (Time.Contains("小时"))
  3367. {
  3368. GetGoogleResult = int.Parse(Regex.Split(Regex.Split(Time, "小时")[1], "分钟")[0]);
  3369. }
  3370. else if (Time.Contains("分钟"))
  3371. {
  3372. GetGoogleResult = int.Parse(Regex.Split(Time,"分钟")[0]);
  3373. }
  3374. if (Distance.Contains("mi"))
  3375. {
  3376. var distSp = Regex.Split(Distance, "mi");
  3377. if (distSp.Length > 0)
  3378. {
  3379. Distance = (decimal.Parse(distSp[0]) * conversion).ToString("#0.00") + " 公里";
  3380. }
  3381. }
  3382. else if (Distance.Contains("km"))
  3383. {
  3384. Distance = Distance.Replace("km", "公里");
  3385. }
  3386. Time = Time.Replace(" ", "");
  3387. Distance = Distance.Replace(" ", "");
  3388. }
  3389. catch (Exception e)
  3390. {
  3391. Time = "未知!";
  3392. Distance = "未知!";
  3393. }
  3394. string trip = string.Empty;
  3395. if (timeStr.Contains(":"))
  3396. {
  3397. int H = tripTime.Hour;
  3398. int M = tripTime.Minute;
  3399. if (H < 12)
  3400. {
  3401. tripTime = tripTime.AddMinutes(90);
  3402. CheckoutHotelTime = tripTime.ToString("HH:mm");
  3403. trip += $"\r\n{CheckoutHotelTime} 搭乘专车前往市区";
  3404. trip += $"({startAddress} - {endCity} 路程{Distance},耗时{Time})";
  3405. if (H <= 13)
  3406. {
  3407. tripTime = tripTime.AddMinutes(GetGoogleResult);
  3408. trip += $"\r\n{tripTime.ToString("HH:mm")} 午餐于当地餐厅;";
  3409. }
  3410. }
  3411. else if ( H == 12 && M <= 30)
  3412. {
  3413. tripTime = tripTime.AddMinutes(90);
  3414. CheckoutHotelTime = tripTime.ToString("HH:mm");
  3415. trip += $"\r\n{CheckoutHotelTime} 搭乘专车前往市区";
  3416. trip += $"({startAddress} - {endCity} 路程{Distance},耗时{Time})";
  3417. if (H <= 13)
  3418. {
  3419. tripTime = tripTime.AddMinutes(GetGoogleResult);
  3420. trip += $"\r\n{tripTime.ToString("HH:mm")} 午餐于当地餐厅;";
  3421. }
  3422. }
  3423. else if (H >= 14)
  3424. {
  3425. tripTime = tripTime.AddMinutes(90);
  3426. CheckoutHotelTime = tripTime.ToString("HH:mm");
  3427. trip += $"\r\n{CheckoutHotelTime} 搭乘专车前往市区;";
  3428. trip += $"({startAddress} - {endCity} 路程{Distance},耗时{Time})";
  3429. tripTime = DateTime.Parse(CheckoutHotelTime).AddMinutes(GetGoogleResult);
  3430. trip += $"\r\n{tripTime.ToString("HH:mm")} 晚餐于当地餐厅;";
  3431. }
  3432. }
  3433. timeOut = tripTime.AddMinutes(60).ToString("HH:mm");
  3434. return trip;
  3435. }
  3436. }
  3437. }