public void Do() { MySqlHelper mySqlHelper = MySqlHelper.CreateInstance(); string sqlCommand = "SELECT PLATFORM_SERIAL_NO, INVOICE_REMOTE_PATH FROM IM_E_INVOICE WHERE ID >= 15450 AND INVOICE_STATE = 1"; DataSet queryResult = mySqlHelper.Query(sqlCommand); if (null == queryResult || null == queryResult.Tables || queryResult.Tables.Count.Equals(0)) { return; } Dictionary <string, string> name2Url = new Dictionary <string, string>(); foreach (DataRow item in queryResult.Tables[0].Rows) { string platformSerialNo = item["PLATFORM_SERIAL_NO"].ToString(); string url = item["INVOICE_REMOTE_PATH"].ToString(); name2Url.Add(platformSerialNo, url); string fileName = "E:/LG/" + platformSerialNo + ".pdf"; WebClient webClient = new WebClient(); byte[] pdfByteFromWebClient = webClient.DownloadData(url); using (FileStream pdfFile = new FileStream(fileName, FileMode.OpenOrCreate)) { pdfFile.Write(pdfByteFromWebClient, 0, pdfByteFromWebClient.Length); } } }
public void Do() { string filePath = @"D:\workspace\guigang\微信绑定关系\绑定关系.csv"; string tableName = "TEMP_OPENID_2_CUSTOMER_ID"; List <string> infos = new List <string>(); using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.None)) { StreamReader sr = new StreamReader(fs, System.Text.Encoding.Default); string str = string.Empty; while (str != null) { str = sr.ReadLine(); if (string.IsNullOrEmpty(str)) { break; } infos.Add(str); } sr.Close(); } int totalCount = infos.Count; int stepSize = 500; int steps = totalCount / stepSize; int tail = totalCount % stepSize; MySqlHelper sqlHelper = MySqlHelper.CreateInstance(); for (int index = 0; index < steps; index++) { StringBuilder sqlCommand = new StringBuilder(500); sqlCommand.Append("INSERT INTO ").Append(tableName).Append(" VALUES"); for (int index_1 = index * stepSize; index_1 < (index + 1) * stepSize; index_1++) { string[] infoDetail = infos[index_1].Split(','); sqlCommand.Append("('").Append(infoDetail[0]).Append("',"); sqlCommand.Append("'").Append(infoDetail[1]).Append("'),"); } sqlHelper.Insert(sqlCommand.ToString().Trim(',')); Console.WriteLine(sqlCommand.ToString().Trim(',')); } StringBuilder sqlCommand_tail = new StringBuilder(500); sqlCommand_tail.Append("INSERT INTO ").Append(tableName).Append(" VALUES"); for (int index = stepSize * steps; index < totalCount; index++) { if (index > totalCount) { break; } string[] infoDetail = infos[index].Split(','); sqlCommand_tail.Append("('").Append(infoDetail[0]).Append("',"); sqlCommand_tail.Append("'").Append(infoDetail[1]).Append("'),"); } sqlHelper.Insert(sqlCommand_tail.ToString().Trim(',')); Console.WriteLine(sqlCommand_tail.ToString().Trim(',')); }
public void Do() { string filePath = @"D:\workspace\guiyang\批量处理数据\批量过户\南明分公司2018年8-12月过户批量修改0308.csv"; string tableName = "[南明批量过户_20190311]"; List <string> infos = new List <string>(); using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.None)) { StreamReader sr = new StreamReader(fs, System.Text.Encoding.Default); string str = string.Empty; while (str != null) { str = sr.ReadLine(); if (string.IsNullOrEmpty(str)) { break; } infos.Add(str); } sr.Close(); } int totalCount = infos.Count; int stepSize = 500; int steps = totalCount / stepSize; int tail = totalCount % stepSize; MySqlHelper sqlHelper = MySqlHelper.CreateInstance(); for (int index = 0; index < steps; index++) { StringBuilder sqlCommand = new StringBuilder(500); sqlCommand.Append("INSERT INTO ").Append(tableName).Append(" VALUES"); for (int index_1 = index * stepSize; index_1 < (index + 1) * stepSize; index_1++) { string[] infoDetail = infos[index_1].Split(','); string cardId = string.Empty; string oldCardName = string.Empty; string newCardName = string.Empty; string contact = string.Empty; cardId = infoDetail[0]; oldCardName = infoDetail[1]; newCardName = infoDetail[2]; if (infoDetail.Length >= 4) { contact = infoDetail[3]; } sqlCommand.Append("('").Append(cardId).Append("',"); sqlCommand.Append("'").Append(newCardName).Append("',"); sqlCommand.Append("'").Append(contact).Append("',"); sqlCommand.Append("'").Append(oldCardName).Append("'),"); } sqlHelper.Insert(sqlCommand.ToString().Trim(',')); Console.WriteLine(sqlCommand.ToString().Trim(',')); } StringBuilder sqlCommand_tail = new StringBuilder(500); sqlCommand_tail.Append("INSERT INTO ").Append(tableName).Append(" VALUES"); for (int index = stepSize * steps; index < totalCount; index++) { if (index > totalCount) { break; } string[] infoDetail = infos[index].Split(','); string cardId = string.Empty; string oldCardName = string.Empty; string newCardName = string.Empty; string contact = string.Empty; cardId = infoDetail[0]; oldCardName = infoDetail[1]; newCardName = infoDetail[2]; if (infoDetail.Length >= 4) { contact = infoDetail[3]; } sqlCommand_tail.Append("('").Append(cardId).Append("',"); sqlCommand_tail.Append("'").Append(newCardName).Append("',"); sqlCommand_tail.Append("'").Append(contact).Append("',"); sqlCommand_tail.Append("'").Append(oldCardName).Append("'),"); } sqlHelper.Insert(sqlCommand_tail.ToString().Trim(',')); Console.WriteLine(sqlCommand_tail.ToString().Trim(',')); }