public string DataImportRain08(DateTime yearMonth) { StringBuilder message = new StringBuilder(); string yearMonthString = yearMonth.ToString("yyyyMM"); LiveData_BLL bll = new LiveData_BLL(); List <FileInfo> allFileList = FileHelper.GetShareFileInfos(@"\\172.18.226.109\市县一体化平台文档\检验\r24-8-p", yearMonthString.Substring(2, 4) + "*.000", "administrator", "yubk0501!"); if (allFileList.Count == 0) { return("未发现该月份降水文件!<br/>"); } foreach (FileInfo fileInfo in allFileList) { //DateTime datetime = DateTime.ParseExact("20" + fileInfo.Name.Substring(0, 6), "yyyyMMdd", CultureInfo.InvariantCulture); DateTime fileDateTime = DateTime.ParseExact("20" + fileInfo.Name.Substring(0, 6), "yyyyMMdd", CultureInfo.InvariantCulture); if (fileDateTime.Day == 9) { var aaa = fileDateTime; } DateTime dataDateTime = fileDateTime.AddDays(-1); string[] contents = FileHelper.GetShareTextLines(@"\\172.18.226.109\市县一体化平台文档\检验\r24-8-p\" + fileInfo.Name, "Administrator", "yubk0501!"); List <string> citycodes = CityUtility.AllCodeList(); foreach (string citycode in citycodes) { string line = contents.Where(a => a.Contains(citycode)).FirstOrDefault(); decimal rain = 0; if (!string.IsNullOrEmpty(line)) { rain = decimal.Parse(line.Substring(27, line.Length - 27).Trim()); } LiveData liveData = bll.Get(a => a.CountryCode == citycode && a.FDate == dataDateTime && a.Category == "08时"); if (liveData != null) { liveData.Rain = rain; bll.Update(liveData); } else { LiveData newModel = new LiveData(); newModel.LDID = Guid.NewGuid(); newModel.Category = "08时"; newModel.CountryCode = citycode; newModel.CountryName = CityUtility.GetName(citycode); newModel.CreateTime = DateTime.Now; newModel.Rain = rain; newModel.FDate = dataDateTime; bll.Add(newModel); } } } message.Append("导入降水量文件成功,共计导入" + allFileList.Count.ToString() + "个文件。<br/>"); return(message.ToString()); }
public void DataImport() { LiveData_BLL bll = new LiveData_BLL(); List <FileInfo> allFileList = FileHelper.GetShareFileInfos(@"\\172.18.226.109\市县一体化平台文档\检验\r24-8-p", "*.000", "administrator", "yubk0501!"); foreach (FileInfo fileInfo in allFileList) { DateTime fileDateTime = DateTime.ParseExact("20" + fileInfo.Name.Substring(0, 6), "yyyyMMdd", CultureInfo.InvariantCulture); if (fileDateTime.Day == 7) { var aaa = fileDateTime; } DateTime dataDateTime = fileDateTime.AddDays(-1); string[] contents = FileHelper.GetShareTextLines(@"\\172.18.226.109\市县一体化平台文档\检验\r24-8-p\" + fileInfo.Name, "Administrator", "yubk0501!"); List <string> citycodes = CityUtility.AllCodeList(); foreach (string citycode in citycodes) { string line = contents.Where(a => a.Contains(citycode)).FirstOrDefault(); decimal rain = 0; if (!string.IsNullOrEmpty(line)) { rain = decimal.Parse(line.Substring(27, 5).Trim()); } LiveData liveData = bll.Get(a => a.CountryCode == citycode && a.FDate == dataDateTime && a.Category == "08时"); if (liveData != null) { liveData.Rain = rain; bll.Update(liveData); } else { LiveData newModel = new LiveData(); newModel.LDID = Guid.NewGuid(); newModel.Category = "08时"; newModel.CountryCode = citycode; newModel.CountryName = CityUtility.GetName(citycode); newModel.CreateTime = DateTime.Now; newModel.Rain = rain; newModel.FDate = dataDateTime; bll.Add(newModel); } } } Response.Write(allFileList.Count.ToString()); }
public int JieXiBaoWen(BaoWens baowen) { try { string[] contents = baowen.Content.Replace("\r\n", ";").Split(';'); List <string> citycodes = CityUtility.AllCodeList(); List <WeatherDictionary> weathercodes = new WeatherDictionary_BLL().GetList().ToList(); BwYbs_BLL bll = new BwYbs_BLL(); foreach (string citycode in citycodes) { BwYbs model = new BwYbs(); model.BWID = baowen.BWID; model.BWYBID = Guid.NewGuid(); model.CountryCode = citycode; model.CountryName = CityUtility.GetName(citycode); model.CreateTime = DateTime.Now; model.BWFileName = baowen.FileName; model.YBDateTime = baowen.YBDateTime; model.YBType = baowen.BWType; model.YBUserID = baowen.YBUserID; model.YBUserName = baowen.YBUserName; string stringStart = contents.Where(a => a.Contains(citycode)).FirstOrDefault(); int indexStart = Array.IndexOf(contents, stringStart); model.TianQiCode12 = decimal.Parse(contents[indexStart + 1].Substring(113, 5).Trim()); model.TianQiCode24 = decimal.Parse(contents[indexStart + 2].Substring(113, 5).Trim()); model.TianQiCode36 = decimal.Parse(contents[indexStart + 3].Substring(113, 5).Trim()); model.TianQiCode48 = decimal.Parse(contents[indexStart + 4].Substring(113, 5).Trim()); model.TianQiCode60 = decimal.Parse(contents[indexStart + 5].Substring(113, 5).Trim()); model.TianQiCode72 = decimal.Parse(contents[indexStart + 6].Substring(113, 5).Trim()); model.WindDirCode12 = decimal.Parse(contents[indexStart + 1].Substring(119, 5).Trim()); model.WindDirCode24 = decimal.Parse(contents[indexStart + 2].Substring(119, 5).Trim()); model.WindDirCode36 = decimal.Parse(contents[indexStart + 3].Substring(119, 5).Trim()); model.WindDirCode48 = decimal.Parse(contents[indexStart + 4].Substring(119, 5).Trim()); model.WindDirCode60 = decimal.Parse(contents[indexStart + 5].Substring(119, 5).Trim()); model.WindDirCode72 = decimal.Parse(contents[indexStart + 6].Substring(119, 5).Trim()); model.WindSpeCode12 = decimal.Parse(contents[indexStart + 1].Substring(125, contents[indexStart + 1].Length - 125).Trim()); model.WindSpeCode24 = decimal.Parse(contents[indexStart + 2].Substring(125, contents[indexStart + 1].Length - 125).Trim()); model.WindSpeCode36 = decimal.Parse(contents[indexStart + 3].Substring(125, contents[indexStart + 1].Length - 125).Trim()); model.WindSpeCode48 = decimal.Parse(contents[indexStart + 4].Substring(125, contents[indexStart + 1].Length - 125).Trim()); model.WindSpeCode60 = decimal.Parse(contents[indexStart + 5].Substring(125, contents[indexStart + 1].Length - 125).Trim()); model.WindSpeCode72 = decimal.Parse(contents[indexStart + 6].Substring(125, contents[indexStart + 1].Length - 125).Trim()); model.MaxTemp24 = decimal.Parse(contents[indexStart + 2].Substring(65, 5).Trim()); model.MaxTemp48 = decimal.Parse(contents[indexStart + 4].Substring(65, 5).Trim()); model.MaxTemp72 = decimal.Parse(contents[indexStart + 6].Substring(65, 5).Trim()); model.MinTemp24 = decimal.Parse(contents[indexStart + 2].Substring(71, 5).Trim()); model.MinTemp48 = decimal.Parse(contents[indexStart + 4].Substring(71, 5).Trim()); model.MinTemp72 = decimal.Parse(contents[indexStart + 6].Substring(71, 5).Trim()); model.TianQiName12 = weathercodes.Where(a => a.Code == model.TianQiCode12 && a.Type == "天气").FirstOrDefault().Name; model.TianQiName24 = weathercodes.Where(a => a.Code == model.TianQiCode24 && a.Type == "天气").FirstOrDefault().Name; model.TianQiName36 = weathercodes.Where(a => a.Code == model.TianQiCode36 && a.Type == "天气").FirstOrDefault().Name; model.TianQiName48 = weathercodes.Where(a => a.Code == model.TianQiCode48 && a.Type == "天气").FirstOrDefault().Name; model.TianQiName60 = weathercodes.Where(a => a.Code == model.TianQiCode60 && a.Type == "天气").FirstOrDefault().Name; model.TianQiName72 = weathercodes.Where(a => a.Code == model.TianQiCode72 && a.Type == "天气").FirstOrDefault().Name; model.WindDirName12 = weathercodes.Where(a => a.Code == model.WindDirCode12 && a.Type == "风向").FirstOrDefault().Name; model.WindDirName24 = weathercodes.Where(a => a.Code == model.WindDirCode24 && a.Type == "风向").FirstOrDefault().Name; model.WindDirName36 = weathercodes.Where(a => a.Code == model.WindDirCode36 && a.Type == "风向").FirstOrDefault().Name; model.WindDirName48 = weathercodes.Where(a => a.Code == model.WindDirCode48 && a.Type == "风向").FirstOrDefault().Name; model.WindDirName60 = weathercodes.Where(a => a.Code == model.WindDirCode60 && a.Type == "风向").FirstOrDefault().Name; model.WindDirName72 = weathercodes.Where(a => a.Code == model.WindDirCode72 && a.Type == "风向").FirstOrDefault().Name; model.WindSpeName12 = weathercodes.Where(a => a.Code == model.WindSpeCode12 && a.Type == "风速").FirstOrDefault().Name; model.WindSpeName24 = weathercodes.Where(a => a.Code == model.WindSpeCode24 && a.Type == "风速").FirstOrDefault().Name; model.WindSpeName36 = weathercodes.Where(a => a.Code == model.WindSpeCode36 && a.Type == "风速").FirstOrDefault().Name; model.WindSpeName48 = weathercodes.Where(a => a.Code == model.WindSpeCode48 && a.Type == "风速").FirstOrDefault().Name; model.WindSpeName60 = weathercodes.Where(a => a.Code == model.WindSpeCode60 && a.Type == "风速").FirstOrDefault().Name; model.WindSpeName72 = weathercodes.Where(a => a.Code == model.WindSpeCode72 && a.Type == "风速").FirstOrDefault().Name; bll.Add(model, false); //var aa = model; } return(bll.SaveChange()); } catch (Exception ex) { return(0); } }
public void DataImport() { LiveData_BLL bll = new LiveData_BLL(); List <FileInfo> allFileList = FileHelper.GetShareFileInfos(@"\\172.18.226.109\市县一体化平台文档\检验\A", "A*", "administrator", "yubk0501!"); foreach (FileInfo fileInfo in allFileList) { List <LiveData> sklist = new List <LiveData>(); //string contents = File.ReadAllText(@"\\172.18.226.10\nt40\zdzh\" + item.Value); string countrycode = fileInfo.Name.Substring(1, 5); //string apath = @"P:\zdzh\" + item.Value; string contents = FileHelper.GetShareTextContent(@"\\172.18.226.109\市县一体化平台文档\检验\A\" + fileInfo.Name, "Administrator", "yubk0501!", Encoding.Default); string tbcontents = contents.Substring(contents.IndexOf("TB") + 4, (contents.IndexOf("IB") - contents.IndexOf("TB") - 7)).Replace("\r\n", ""); string[] tb = tbcontents.Split('.'); for (int i = 0; i < tb.Length; i++) { LiveData shikuang = new LiveData(); shikuang.LDID = Guid.NewGuid(); shikuang.FDate = DateTime.ParseExact(fileInfo.Name.Substring(7, 6) + (i + 1).ToString("00"), "yyyyMMdd", CultureInfo.InvariantCulture); shikuang.CountryCode = countrycode; shikuang.CreateTime = DateTime.Now; shikuang.CountryName = CityUtility.GetName(countrycode); shikuang.Category = "20时"; shikuang.MaxTemp = decimal.Parse(tb[i].Substring(119, 4)) / 10; shikuang.MinTemp = decimal.Parse(tb[i].Substring(129, 4)) / 10; sklist.Add(shikuang); } string raincontents = contents.Substring(contents.IndexOf("R6") + 4, tb.Length * 16 - 2).Replace("\r\n", "."); string raincontents2 = contents.Substring(contents.IndexOf("R6") + 4, tb.Length * 18 - 3).Replace("\r\n", "."); string[] rains = raincontents.Split('.'); for (int i = 0; i < rains.Length; i++) { string rainstr = rains[i].Substring(10, 4); if (rainstr != ",,,,") { sklist.ElementAt(i).Rain = decimal.Parse(rainstr) / 10; } else { sklist.ElementAt(i).Rain = (decimal)0.01; } } foreach (var item in sklist) { int count = bll.GetCount(a => a.CountryCode == item.CountryCode && a.FDate == item.FDate && a.Category == "20时"); if (count <= 0) { bll.Add(item); } } Response.Write(countrycode + " " + fileInfo.Name.Substring(7, 6) + sklist.Count().ToString()); } Response.Write(allFileList.Count().ToString()); }
public void Copy() { using (Ftp client = new Ftp()) { client.Connect("172.18.200.251"); client.Login("x25bejn", "bejn90"); var list = client.GetList("/user/BEJNUP/SURF/ST_DAY/"); List <string> citycodes = CityUtility.AllCodeList(); List <FtpItem> totalList = new List <FtpItem>(); foreach (string citycode in citycodes) { totalList.AddRange(list.Where(a => a.Name.Contains(citycode)).ToList()); } int fileSuccessCount = 0; File_Z_BLL bll = new File_Z_BLL(); foreach (FtpItem ftpItem in totalList) { string romoteName = @"user\BEJNUP\SURF\ST_DAY\" + ftpItem.Name; string month = ftpItem.Name.Substring(15, 6); string localPath = @"D:\市县一体化平台文档\检验\日z文件\" + month; if (!Directory.Exists(localPath)) { Directory.CreateDirectory(localPath); } string localName = localPath + @"\" + ftpItem.Name; try { client.Download(romoteName, localName); fileSuccessCount++; Console.WriteLine("成功复制:" + ftpItem.Name); ///存取数据库 string name = ftpItem.Name; string content = File.ReadAllText(localName); string[] contentLine = File.ReadAllLines(localName); string countrycode = contentLine[0].Substring(0, 5); string countryname = CityUtility.GetName(countrycode); DateTime date = DateTime.ParseExact(contentLine[1].Split(' ').ToList().ElementAt(0).Substring(0, 8), "yyyyMMdd", CultureInfo.InvariantCulture); string rain1_string = contentLine[1].Split(' ').ToList().ElementAt(1); string rain2_string = contentLine[1].Split(' ').ToList().ElementAt(2); decimal rain1 = 0; decimal rain2 = 0; if (rain1_string == ",,,,,") { rain1 = (decimal)0.01; } else { rain1 = decimal.Parse(rain1_string) / 10; } if (rain2_string == ",,,,,") { rain2 = (decimal)0.01; } else { rain2 = decimal.Parse(rain2_string) / 10; } File_Z model = bll.Get(a => a.Date == date && a.CountryCode == countrycode); if (model != null) { model.Twenty_Eight = rain1; model.Eight_Twenty = rain2; model.FileContent = content; model.FileName = name; model.CreateTime = DateTime.Now; bll.Update(model); } else { model = new File_Z() { FileID = Guid.NewGuid(), CountryCode = countrycode, CountryName = countryname, CreateTime = DateTime.Now, Date = date, Twenty_Eight = rain1, Eight_Twenty = rain2, FileContent = content, FileName = name }; bll.Add(model); } Console.WriteLine("成功入库:" + ftpItem.Name); } catch (Exception ex) { Console.WriteLine(ex); } } Console.WriteLine("成功复制:" + fileSuccessCount + "个文件,共有:" + totalList.Count() + "个文件。"); } }
public void CopyAll() { List <FileInfo> flist = FileHelper.GetShareFileInfos(@"\\172.18.226.109\市县一体化平台文档\检验\日z文件\201704", "administrator", "yubk0501!"); File_Z_BLL bll = new File_Z_BLL(); foreach (FileInfo fileInfo in flist) { ///存取数据库 string name = fileInfo.Name; string content = FileHelper.GetShareTextContent(@"\\172.18.226.109\市县一体化平台文档\检验\日z文件\201704\" + fileInfo.Name, "administrator", "yubk0501!", Encoding.Default); string[] contentLine = FileHelper.GetShareTextLines(@"\\172.18.226.109\市县一体化平台文档\检验\日z文件\201704\" + fileInfo.Name, "administrator", "yubk0501!"); string countrycode = contentLine[0].Substring(0, 5); string countryname = CityUtility.GetName(countrycode); DateTime date = DateTime.ParseExact(contentLine[1].Split(' ').ToList().ElementAt(0).Substring(0, 8), "yyyyMMdd", CultureInfo.InvariantCulture); string rain1_string = contentLine[1].Split(' ').ToList().ElementAt(1); string rain2_string = contentLine[1].Split(' ').ToList().ElementAt(2); decimal rain1 = 0; decimal rain2 = 0; if (rain1_string == ",,,,,") { rain1 = (decimal)0.01; } else { rain1 = decimal.Parse(rain1_string) / 10; } if (rain2_string == ",,,,,") { rain2 = (decimal)0.01; } else { rain2 = decimal.Parse(rain2_string) / 10; } File_Z model = bll.Get(a => a.Date == date && a.CountryCode == countrycode); if (model != null) { //model.Twenty_Eight = rain1; //model.Eight_Twenty = rain2; //model.FileContent = content; //model.FileName = name; //model.CreateTime = DateTime.Now; //bll.Update(model); } else { model = new File_Z() { FileID = Guid.NewGuid(), CountryCode = countrycode, CountryName = countryname, CreateTime = DateTime.Now, Date = date, Twenty_Eight = rain1, Eight_Twenty = rain2, FileContent = content, FileName = name }; bll.Add(model); } Console.WriteLine("成功入库:" + fileInfo.Name); } }