public static ArrayList getCSV(string FilePath, string strEncoding) { ArrayList csvData = new ArrayList(); if (strEncoding == "") { strEncoding = "Shift_JIS"; } Encoding encode = Encoding.GetEncoding(strEncoding); Microsoft.VisualBasic.FileIO.TextFieldParser tfp = new Microsoft.VisualBasic.FileIO.TextFieldParser(FilePath, encode); //区切り文字を,とする tfp.Delimiters = new string[] { "," }; //フィールドを"で囲み、改行文字、区切り文字を含めることができるか //デフォルトでtrueなので、必要なし tfp.HasFieldsEnclosedInQuotes = true; //フィールドの前後からスペースを削除する //デフォルトでtrueなので、必要なし tfp.TrimWhiteSpace = true; while (!tfp.EndOfData) { string[] fields = tfp.ReadFields(); csvData.Add(fields); } tfp.Close(); return(csvData); }
static List <InvoiceTotal> ReadTotalsFile(string totalsFile) { List <InvoiceTotal> totalsList = new List <InvoiceTotal>(); try { using (Microsoft.VisualBasic.FileIO.TextFieldParser parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(totalsFile)) { parser.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited; parser.SetDelimiters(","); while (!parser.EndOfData) { string[] words = parser.ReadFields(); if (!words[0].Any(Char.IsLetter)) { totalsList.Add(new InvoiceTotal(int.Parse(words[0]), decimal.Parse(words[1]))); } } parser.Close(); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } return(totalsList); }
private IEnumerable <Task> Parse(AirportInfoDelegate airportInfoCallback) { var parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(this.csvFile); parser.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited; parser.SetDelimiters(","); while (!parser.EndOfData) { //Process row string[] fields = parser.ReadFields(); if (7 != fields.Count()) { continue; } var identifier = fields[0]; var city = fields[1]; var state = fields[2]; var name = fields[3]; var chart = fields[4]; var region = fields[5]; var afdlink = fields[6]; yield return(airportInfoCallback.Invoke(identifier, city, state, name, chart, region, afdlink)); } parser.Close(); }
/// <summary> /// 读取CSV文件到DataTable /// </summary> /// <param name="fpath"></param> /// <param name="header">第一行数据是否为表头</param> /// <returns></returns> public static DataTable CSVToDataTable(string fpath, bool header = true) { DataTable dt = new DataTable(); if (File.Exists(fpath)) { DataRow row = null; string[] rowArr = null; using (Microsoft.VisualBasic.FileIO.TextFieldParser parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(fpath, Encoding.GetEncoding("GB2312"))) { parser.Delimiters = new string[] { "," }; parser.TrimWhiteSpace = true; while (!parser.EndOfData) { if (parser.LineNumber == 1) { rowArr = parser.ReadFields(); if (!header) { for (int i = 0; i < rowArr.Length; i++) { dt.Columns.Add(i.ToString()); } row = dt.NewRow(); for (int i = 0; i < dt.Columns.Count; i++) { row[i] = rowArr[i]; } dt.Rows.Add(row); } else { foreach (string col in rowArr) { dt.Columns.Add(col); } } } else { rowArr = parser.ReadFields(); row = dt.NewRow(); for (int i = 0; i < dt.Columns.Count; i++) { row[i] = rowArr[i]; } dt.Rows.Add(row); } } parser.Close(); } } else { throw new FileNotFoundException(); } return(dt); }
/// <summary> /// Read the CSV file from the specified <paramref name="reader" /> using the specified field <paramref name="separator" />. /// </summary> /// <param name="reader">The <see cref="TextReader" /> responsible reading the CSV contents.</param> /// <param name="separator">The field separator to use.</param> /// <returns>An enumerable containing a <see cref="String" /> array all the fields in each row.</returns> /// <exception cref="ArgumentNullException"><paramref name="reader" /> or <paramref name="separator" /> is null or empty.</exception> public static IEnumerable <string[]> OpenCSV(TextReader reader, string separator) { //http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.fileio.textfieldparser.aspx using (var tfp = new Microsoft.VisualBasic.FileIO.TextFieldParser(reader)) { try { tfp.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited; tfp.SetDelimiters(separator); while (!tfp.EndOfData) { yield return(tfp.ReadFields()); } } finally { tfp.Close(); } } }
/// <summary> /// 从Excel读取数据 /// </summary> /// <param name="strPhysicalPath"></param> /// <returns></returns> public string ImportEmployeeMonthlySalary(GenerateUserInfo GenerateUser, string strPhysicalPath, string year, string month, string owerCompayId, ref string UImsg) { if (DateTime.Now.Hour != Convert.ToInt32(ConfigurationManager.AppSettings["ElapsedHour"])) { } string msg = string.Empty; Microsoft.VisualBasic.FileIO.TextFieldParser TF = new Microsoft.VisualBasic.FileIO.TextFieldParser(strPhysicalPath, Encoding.GetEncoding("GB2312")); EmployeeBLL empBll = new EmployeeBLL(); var User = empBll.GetEmployeeDetailView(GenerateUser.GenerateUserId); TF.Delimiters = new string[] { "," }; //设置分隔符 string[] strLine; EmployeeSalaryRecordBLL bll = new EmployeeSalaryRecordBLL(); while (!TF.EndOfData) { try { strLine = TF.ReadFields(); string strIDNUMBER = strLine[0]; //身份证号码 string strEmployeeName = strLine[1]; //员工姓名 string strSalaryItemName = strLine[2]; //员工薪资项目名 string strSalaryItemSUM = strLine[3]; //员工薪资项目金额 var employee = (from ent in dal.GetObjects <T_HR_EMPLOYEE>() where ent.IDNUMBER == strIDNUMBER select ent).FirstOrDefault(); if (employee == null) { msg = "薪资项目导入,根据身份证未找到相关员工档案,身份证号码:" + strIDNUMBER; UImsg += msg + System.Environment.NewLine; Tracer.Debug(msg); continue; } else { Tracer.Debug("薪资项目导入,根据身份证找到相关员工档案,身份证号码:" + strIDNUMBER + " 导入的员工姓名:" + strEmployeeName + " 根据身份证号查到的员工姓名:" + employee.EMPLOYEECNAME + " 薪资项目名:" + strSalaryItemName + " 薪资项目金额:" + strSalaryItemSUM + " 导入人id:" + GenerateUser.GenerateUserId + " 名称:" + User.EMPLOYEENAME + " 导入人主岗位id(结算岗位):" + " 名称:" + GenerateUser.GeneratePostId + User.EMPLOYEEPOSTS[0].PostName + " 导入人所属公司id(发薪机构):" + GenerateUser.GenerateCompanyId + " 名称:" + User.EMPLOYEEPOSTS[0].CompanyName); } var salaryAchive = bll.GetEmployeeAcitiveSalaryArchive(employee.EMPLOYEEID, GenerateUser.GeneratePostId, GenerateUser.GenerateCompanyId, int.Parse(year), int.Parse(month)); T_HR_EMPLOYEESALARYRECORD record = (from r in dal.GetTable() where r.EMPLOYEEID == employee.EMPLOYEEID && r.SALARYMONTH == month && r.SALARYYEAR == year && r.OWNERCOMPANYID == owerCompayId select r).FirstOrDefault(); #region 新建薪资项目 if (record == null) { try { Tracer.Debug("导入员工薪资项目,未生成员工月薪,开始生成,员工姓名:" + employee.EMPLOYEECNAME + " " + year + "年" + month + "月" + "的月薪,record == null" + " 导入的员工姓名:" + strEmployeeName + " 根据身份证号查到的员工姓名:" + employee.EMPLOYEECNAME + " 薪资项目名:" + strSalaryItemName + " 薪资项目金额:" + strSalaryItemSUM); record = new T_HR_EMPLOYEESALARYRECORD(); record.EMPLOYEESALARYRECORDID = Guid.NewGuid().ToString(); record.EMPLOYEEID = employee.EMPLOYEEID; record.CREATEUSERID = GenerateUser.GenerateUserId; record.CREATEPOSTID = GenerateUser.GeneratePostId; // record.CREATEPOSTID = archive.CREATEPOSTID; record.CREATEDEPARTMENTID = GenerateUser.GenerateDepartmentId; record.CREATECOMPANYID = GenerateUser.GenerateCompanyId; record.OWNERID = employee.EMPLOYEEID;; record.OWNERPOSTID = employee.OWNERPOSTID; record.OWNERDEPARTMENTID = employee.OWNERDEPARTMENTID; record.OWNERCOMPANYID = employee.OWNERCOMPANYID; record.ATTENDANCEUNUSUALTIMES = employee.OWNERCOMPANYID; //记录薪资人的所属公司 record.ATTENDANCEUNUSUALTIME = employee.OWNERPOSTID; //记录薪资人的所属岗位 record.ABSENTTIMES = salaryAchive.SALARYARCHIVEID; //记录生成薪资使用的薪资档案 record.PAIDTYPE = bll.GetPaidType(employee.EMPLOYEEID); //发放方式 record.REMARK = "薪资项目导入生成"; record.PAIDTYPE = bll.GetPaidType(employee.EMPLOYEEID); record.EMPLOYEECODE = salaryAchive.EMPLOYEECODE; record.EMPLOYEENAME = salaryAchive.EMPLOYEENAME; record.PAYCONFIRM = "0"; record.CHECKSTATE = "0"; record.CREATEDATE = System.DateTime.Now; record.SALARYYEAR = year; record.SALARYMONTH = month; record.T_HR_EMPLOYEESALARYRECORDITEM.Clear(); int i = dal.Add(record); if (i == 1) { ImportSalaryRecordItem(ref UImsg, ref msg, strIDNUMBER, strEmployeeName, strSalaryItemName, strSalaryItemSUM, employee, record, salaryAchive); } else { msg = "薪资项目导入添加员工薪资记录失败!" + " 身份证号码:" + strIDNUMBER + " 导入的员工姓名:" + strEmployeeName + " 根据身份证号查到的员工姓名:" + employee.EMPLOYEECNAME + " 薪资项目名:" + strSalaryItemName + " 薪资项目金额:" + strSalaryItemSUM; UImsg += msg + System.Environment.NewLine; Tracer.Debug(msg); } } catch (Exception ex) { msg = "薪资项目导入添加员工薪资记录失败!" + ex.ToString() + " 身份证号码:" + strIDNUMBER + " 导入的员工姓名:" + strEmployeeName + " 根据身份证号查到的员工姓名:" + employee.EMPLOYEECNAME + " 薪资项目名:" + strSalaryItemName + " 薪资项目金额:" + strSalaryItemSUM; UImsg += msg + System.Environment.NewLine; Tracer.Debug(msg); } ; } #endregion #region 更新薪资项目 else { var SalaryRecord = (from a in dal.GetObjects <T_HR_EMPLOYEESALARYRECORD>() join b in dal.GetObjects <T_HR_EMPLOYEESALARYRECORDITEM>() on a.EMPLOYEESALARYRECORDID equals b.T_HR_EMPLOYEESALARYRECORD.EMPLOYEESALARYRECORDID join c in dal.GetObjects <T_HR_SALARYITEM>() on b.SALARYITEMID equals c.SALARYITEMID where a.EMPLOYEEID == employee.EMPLOYEEID && a.SALARYYEAR == year && a.SALARYMONTH == month && a.OWNERCOMPANYID == owerCompayId && a.CHECKSTATE == "0" && c.SALARYITEMNAME == strSalaryItemName select new { b.SALARYRECORDITEMID, c.SALARYITEMNAME, b.SUM }); var item = SalaryRecord.FirstOrDefault(); if (item != null) { var q = from ent in dal.GetObjects <T_HR_EMPLOYEESALARYRECORDITEM>() where ent.SALARYRECORDITEMID == item.SALARYRECORDITEMID select ent; var entsum = q.FirstOrDefault(); if (entsum != null) { entsum.SUM = AES.AESEncrypt(strSalaryItemSUM); int i = dal.Update(entsum); if (i >= 1) { msg = "薪资项目导入成功,受影响的条数:" + i + " 身份证号码:" + strIDNUMBER + " 导入的员工姓名:" + strEmployeeName + " 根据身份证号查到的员工姓名:" + employee.EMPLOYEECNAME + " 薪资项目名:" + strSalaryItemName + " 薪资项目金额:" + strSalaryItemSUM; UImsg += msg + System.Environment.NewLine; Tracer.Debug(msg); } else { msg = "薪资项目导入失败,受影响的条数:" + i + " 身份证号码:" + strIDNUMBER + " 导入的员工姓名:" + strEmployeeName + " 根据身份证号查到的员工姓名:" + employee.EMPLOYEECNAME + " 薪资项目名:" + strSalaryItemName + " 薪资项目金额:" + strSalaryItemSUM; UImsg += msg + System.Environment.NewLine; Tracer.Debug(msg); continue; } } else { msg = "薪资项目导入失败,未找到薪资项目," + " 身份证号码:" + strIDNUMBER + " 导入的员工姓名:" + strEmployeeName + " 根据身份证号查到的员工姓名:" + employee.EMPLOYEECNAME + " 薪资项目名:" + strSalaryItemName + " 薪资项目金额:" + strSalaryItemSUM; UImsg += msg + System.Environment.NewLine; Tracer.Debug(msg); continue; } } else { ImportSalaryRecordItem(ref UImsg, ref msg, strIDNUMBER, strEmployeeName, strSalaryItemName, strSalaryItemSUM, employee, record, salaryAchive); } } #endregion } catch (Exception ex) { UImsg += "导入薪资项目异常:" + ex + System.Environment.NewLine; Utility.SaveLog(ex.ToString()); continue; } } TF.Close(); return(UImsg); }
/// <summary> /// List of invoice items. /// This is used for free-form invoices. /// </summary> /// <returns>The list of invoices.</returns> public IList <InvoiceItem> ListLineItems() { if (_listLineItems == null) { _listLineItems = new List <InvoiceItem>(); // Null check if (string.IsNullOrEmpty(CsvLineItems)) { return(_listLineItems); } // Get memory stream of data System.IO.MemoryStream stream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(CsvLineItems)); // Use the inbuildt .NET CSV parser var parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(stream) { TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited }; parser.SetDelimiters(","); List <string> headers = new List <string>(); int lineindex = 0; while (!parser.EndOfData) { string[] fields = parser.ReadFields(); int fieldindex = 0; InvoiceItem invocieitem = null; foreach (string field in fields) { // Header, or content? if (lineindex == 0) { headers.Add(field); } else { if (invocieitem == null) { invocieitem = new InvoiceItem(); } // Parse by header name switch (headers[fieldindex]) { case "kind": invocieitem.Kind = field; break; case "description": invocieitem.Description = field; break; case "quantity": invocieitem.Quantity = decimal.Parse(field, System.Globalization.CultureInfo.InvariantCulture); break; case "unit_price": invocieitem.UnitPrice = decimal.Parse(field, System.Globalization.CultureInfo.InvariantCulture); break; case "amount": invocieitem.Amount = decimal.Parse(field, System.Globalization.CultureInfo.InvariantCulture); break; case "taxed": invocieitem.Taxed = bool.Parse(field); break; case "taxed2": invocieitem.Taxed2 = bool.Parse(field); break; case "project_id": invocieitem.ProjectId = string.IsNullOrEmpty(field) ? 0 : long.Parse(field); break; } } fieldindex++; } lineindex++; if (invocieitem != null) { _listLineItems.Add(invocieitem); } } parser.Close(); } return(_listLineItems); }
/// <summary> /// CSVファイルを読み込み、DataTableで返す /// </summary> /// <param name="csvFileName">CSVファイル名</param> /// <param name="delimiter">区切り文字</param> /// <param name="hasHeaderRow">ヘッダー行の有無</param> /// <param name="hasFieldsEnclosedInQuotes">フィールドを"で囲み、改行文字、区切り文字を含めることができるか</param> /// <param name="trimWhiteSpace">フィールドの前後からスペースを削除か</param> /// <returns></returns> public static DataTable ReadCsv(string csvFileName, string delimiter, bool hasHeaderRow = true, bool hasFieldsEnclosedInQuotes = true, bool trimWhiteSpace = true) { DataTable tbl = new DataTable(); try { //Shift JISで読み込む Microsoft.VisualBasic.FileIO.TextFieldParser tfp = new Microsoft.VisualBasic.FileIO.TextFieldParser(csvFileName, System.Text.Encoding.GetEncoding(932)); //フィールドが文字で区切られているとする tfp.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited; //区切り文字セット string[] delimiters = new string[] { delimiter }; tfp.Delimiters = delimiters; //フィールドを"で囲み、改行文字、区切り文字を含めることができるか tfp.HasFieldsEnclosedInQuotes = hasFieldsEnclosedInQuotes; //フィールドの前後からスペースを削除する tfp.TrimWhiteSpace = trimWhiteSpace; if (tfp.EndOfData == true) { return(tbl); } string[] fields; //ヘッダー行があるならColumn名とする if (hasHeaderRow == true) { fields = tfp.ReadFields(); // 1行めからカラム名をロードする foreach (string cnm in fields) { if (string.IsNullOrWhiteSpace(cnm.Trim())) { continue; } DataColumn col = new DataColumn(cnm, typeof(string)); col.AllowDBNull = true; tbl.Columns.Add(col); } } bool bfirst = true; //データ読み込み while (!tfp.EndOfData) { //フィールドを読み込む fields = tfp.ReadFields(); //ヘッダー行がない時、データ1行目のカラム数分、カラムを作成する if (hasHeaderRow == false && bfirst == true) { int colNo = 0; foreach (string cnm in fields) { DataColumn col = new DataColumn("clm" + colNo.ToString(), typeof(string)); col.AllowDBNull = true; tbl.Columns.Add(col); colNo++; } bfirst = false; } // データをロードする DataRow row = tbl.NewRow(); int idx = 0; foreach (string cdat in fields) { row[idx++] = cdat; if (idx >= tbl.Columns.Count) { break; } } tbl.Rows.Add(row); } //後始末 tfp.Close(); } catch (Exception ex) { throw new CSVException(CommonConst.ErrCSVFile, ex); } return(tbl); }
/// <summary> /// List of invoice items. /// This is used for free-form invoices. /// </summary> /// <returns>The list of invoices.</returns> public IList<InvoiceItem> ListLineItems() { if (_listLineItems == null) { _listLineItems = new List<InvoiceItem>(); // Null check if (string.IsNullOrEmpty(CsvLineItems)) return _listLineItems; // Get memory stream of data System.IO.MemoryStream stream = new System.IO.MemoryStream(System.Text.Encoding.UTF8.GetBytes(CsvLineItems)); // Use the inbuildt .NET CSV parser Microsoft.VisualBasic.FileIO.TextFieldParser parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(stream); parser.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited; parser.SetDelimiters(","); List<string> headers = new List<string>(); int lineindex = 0; while (!parser.EndOfData) { string[] fields = parser.ReadFields(); int fieldindex = 0; InvoiceItem invocieitem = null; foreach (string field in fields) { // Header, or content? if (lineindex == 0) { headers.Add(field); } else { if (invocieitem == null) invocieitem = new InvoiceItem(); // Parse by header name switch (headers[fieldindex]) { case "kind": invocieitem.Kind = field; break; case "description": invocieitem.Description = field; break; case "quantity": invocieitem.Quantity = decimal.Parse(field, System.Globalization.CultureInfo.InvariantCulture); break; case "unit_price": invocieitem.UnitPrice = decimal.Parse(field, System.Globalization.CultureInfo.InvariantCulture); break; case "amount": invocieitem.Amount = decimal.Parse(field, System.Globalization.CultureInfo.InvariantCulture); break; case "taxed": invocieitem.Taxed = bool.Parse(field); break; case "taxed2": invocieitem.Taxed2 = bool.Parse(field); break; case "project_id": invocieitem.ProjectId = string.IsNullOrEmpty(field) ? 0 : long.Parse(field); break; } } fieldindex++; } lineindex++; if (invocieitem != null) _listLineItems.Add(invocieitem); } parser.Close(); } return _listLineItems; }
static List <InvoiceClass> ReadInvoiceFile(string invoiceFile) { string prevInvoiceNumber = "0"; List <InvoiceClass> invoiceList = new List <InvoiceClass>(); List <ItemsClass> itemsList = new List <ItemsClass>(); var format = new NumberFormatInfo(); format.NegativeSign = "-"; /* * i is used to iterate through invoiceList. If an invoice number is the same * as the previous invoice number (prevInvoiceNumber), it does not increment. This creates in object * that includes all items with the same invoice number. * - invoice #12345 might include multiple items */ int i = -1; try { /* * using TextFieldParser from Visual Basic to parse the CSV file * I originally had a problem parsing company names that contained commas. * This is the simplest method I found to ignore anything between double quotes. */ using (Microsoft.VisualBasic.FileIO.TextFieldParser parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(invoiceFile)) { parser.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited; parser.SetDelimiters(","); while (!parser.EndOfData) { string[] words = parser.ReadFields(); InvoiceClass invoice = new InvoiceClass(0, "", itemsList, 0); // Only continue if the first item in the words list does not contain any letters. // This is to skip anything that doesn't start with an invoice number. // Usually the first two lines and the last line of the file should be skipped. if (!words[0].Any(Char.IsLetter)) { if (words[0] != prevInvoiceNumber) { List <ItemsClass> items = new List <ItemsClass>(); // words[2] is the item name words[3] is the item price. items.Add(new ItemsClass(words[2], decimal.Parse(words[3], format))); // words[0] is the item number. words[1] is the invoice name invoiceList.Add(new InvoiceClass(int.Parse(words[0]), words[1], items, 0)); i++; prevInvoiceNumber = words[0]; } else { // words[2] is the item name. words[3] is the item price. invoiceList[i].InvoiceItemArray.Add(new ItemsClass(words[2], decimal.Parse(words[3], format))); prevInvoiceNumber = words[0]; } } } parser.Close(); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } return(invoiceList); }
public async Task <bool> Analyze() { bool ret = false; await Task.Run(() => { // インク消費量からカラー/モノクロのページ数を算出 string[] args = { "gs", "-dBATCH", "-dNOPAUSE", "-dSAFER", "-dNoCancel", "-sDEVICE=inkcov", "-sOutputFile=" + InkFileName, "-r75", "-f", FileName }; int result = GSDLL.Execute(args); Microsoft.VisualBasic.FileIO.TextFieldParser tfp = new Microsoft.VisualBasic.FileIO.TextFieldParser(InkFileName); tfp.Delimiters = new string[] { " " }; while (!tfp.EndOfData) { string[] fields = tfp.ReadFields(); double[] ink = { 0.0, 0.0, 0.0, 0.0 }; int i = 0; foreach (string s in fields) { if (s.Length > 0) { ink[i] = Convert.ToDouble(s); i++; } if (i > 3) { break; } } if (ink[0] + ink[1] + ink[2] > 0.0) { Pages.Color++; } else if (ink[3] > 0.0) { Pages.Mono++; } else { Pages.Blank++; } } tfp.Close(); ret = true; FILEUTIL.SafeDelete(InkFileName); }); return(ret); }
private bool InitializeData() { try { using (System.IO.StreamReader sr = new System.IO.StreamReader( Application.StartupPath + "/shared/quirk/quirk_library.json")) { quirk_data = Newtonsoft.Json.JsonConvert.DeserializeObject<JsonQuirkData>(sr.ReadToEnd()); quirks = quirk_data.quirks.ToList(); sr.Close(); } using (System.IO.FileStream fs = System.IO.File.OpenRead( Application.StartupPath + "/curios/curio_type_library.csv")) using (Microsoft.VisualBasic.FileIO.TextFieldParser parser = new Microsoft.VisualBasic.FileIO.TextFieldParser(fs)) { List<string> curiotypes = new List<string>(); int i = 0; parser.Delimiters = new[] { "," }; while (!parser.EndOfData) { if (parser.ReadFields()[1] != "") { for (i = 0; i < 7; i++) { if (!parser.EndOfData) { parser.ReadLine(); } else break; } curiotypes.Add(parser.ReadFields()[2]); } } cbx_curiotags.Items.Add("(none)"); cbx_curiotags.Items.AddRange( curiotypes.Select(a => a).Distinct().OrderBy(b => b).ToArray()); parser.Close(); } using (System.IO.StreamReader sr = new System.IO.StreamReader( Application.StartupPath + "/shared/buffs/buff_library.json")) { buff_data = Newtonsoft.Json.JsonConvert.DeserializeObject<JsonBuffData>(sr.ReadToEnd()); lbx_buffroster.Items.AddRange( buff_data.buffs.Select( a => a.id) .Distinct() .OrderBy(b => b) .ToArray()); sr.Close(); } descriptions = XDocument.Load( Application.StartupPath + "/localization/quirks.string_table.xml"); dialogue = XDocument.Load( Application.StartupPath + "/localization/dialogue.string_table.xml"); return true; } catch //(Exception ex) { MessageBox.Show("Move this application to your game's installation folder\nor varify your game cache.", "Error"); //System.Diagnostics.Debug.WriteLine(ex); } return false; }
static void Main(string[] args) { //string RQ4_SERVICE_URL = "https://vmi7.iqmetrix.net/VMIService.asmx"; // TEST string RQ4_SERVICE_URL = "https://vmi1.iqmetrix.net/VMIService.asmx"; // PRODUCTION //Guid RQ4_CLIENT_ID = new Guid("{aac62064-a98d-4c1e-95ac-6fc585c6bef8}"); // PRODUCTION ARCH Guid RQ4_CLIENT_ID = new Guid("{23f1f07a-3a9c-4ea6-bc9a-efa628afb56d}"); // PRODUCTION LIPSEY //Guid RQ4_CLIENT_ID = new Guid("{aad193b3-f55a-43ef-b28a-c796c1e608de}"); // PRODUCTION CA WIRELESS //Guid RQ4_CLIENT_ID = new Guid("{ab3d009d-77ee-4df8-b10e-f651f344a218}"); // PRODUCTION MAYCOM //Guid RQ4_CLIENT_ID = new Guid("{6a443ad0-b057-4330-b4e6-8b0579a52863}"); // SOLUTIONS CENTER //Guid RQ4_CLIENT_ID = new Guid("{fb6ed46e-5bd9-445c-9308-6161a504a933}"); // PRODUCTION NAWS //Guid RQ4_CLIENT_ID = new Guid("{54d739a1-3ce9-425e-bb28-cf934209f088}"); // PRODUCTION TOUCHTEL //Guid RQ4_CLIENT_ID = new Guid("{3949d039-069a-4ea0-a616-9adafcf553d7}"); //PRODUCTION MOBILE CENTER string infile = null; string outfile = null; string errfile = null; using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.Title = "input csv"; ofd.Filter = "csv files (*.csv)|*.csv"; if (ofd.ShowDialog() == DialogResult.OK) { infile = ofd.FileName; } } if ((infile == null) || (!System.IO.File.Exists(infile))) { return; } outfile = infile + "-out.csv"; if ((outfile == null) || (outfile == "")) { return; } errfile = infile + "-error.csv"; if ((errfile == null) || (errfile == null)) { return; } Dictionary <String, RMA> rmas = new Dictionary <string, RMA>(); System.IO.StreamWriter LOG = new System.IO.StreamWriter(outfile); LOG.AutoFlush = true; LOG.WriteLine("id,po"); Microsoft.VisualBasic.FileIO.TextFieldParser csvfile = new Microsoft.VisualBasic.FileIO.TextFieldParser(infile); csvfile.Delimiters = new string[] { "," }; csvfile.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited; csvfile.ReadFields(); // headers // Internal ID Document Number PO/Check Number Memo (Main) Display Name Quantity Item Rate storeid rqsku rqid while (!csvfile.EndOfData) { String[] fields = csvfile.ReadFields(); if ((fields != null) && (fields.Length == 10)) { if (!rmas.ContainsKey(fields[1])) { RMA r = new RMA(); r.OrderID = fields[0]; r.OrderNumber = fields[1]; r.PONumber = fields[2]; r.Memo = fields[3]; r.StoreID = fields[7]; rmas.Add(r.OrderNumber, r); } RMAItem ri = new RMAItem(); ri.VendorSKU = fields[4]; ri.Quantity = Math.Abs(Convert.ToInt16(fields[5])); ri.ItemRate = Convert.ToDecimal(fields[6]); ri.RQ4SKU = fields[8]; ri.RQ4ItemID = fields[9]; rmas[fields[1]].ItemList.Add(ri); } } try { csvfile.Close(); } catch { } Console.WriteLine("RMAS FOUND: " + rmas.Count); Console.WriteLine(); Console.WriteLine("PUSH ENTER TO START"); Console.ReadLine(); if (rmas.Count == 0) { return; } int rmanum = 1; RQ4.VMIService vmi = new RQ4.VMIService(); vmi.CookieContainer = new System.Net.CookieContainer(); vmi.Url = RQ4_SERVICE_URL; RQ4.VendorIdentity vid = new RQ4.VendorIdentity(); vid.Username = "******"; vid.Password = "******"; vid.VendorID = new Guid("F9B982C3-E7B1-4FD5-9C24-ABE752E058C7"); vid.Client = new RQ4.ClientAgent(); vid.Client.ClientID = RQ4_CLIENT_ID; foreach (KeyValuePair <string, RMA> kvp in rmas) { Console.Write(rmanum + "/" + rmas.Count + " - " + kvp.Key + " -> "); vid.Client.StoreID = Convert.ToInt16(kvp.Value.StoreID); RQ4.ReturnMerchandiseAuthorization rma = new RQ4.ReturnMerchandiseAuthorization(); rma.VendorRMANumber = kvp.Value.OrderNumber; rma.Comments = kvp.Value.OrderNumber; // <--------- required List <RQ4.RMAProduct> items = new List <RQ4.RMAProduct>(); foreach (RMAItem item in kvp.Value.ItemList) { RQ4.RMAProduct prod = new RQ4.RMAProduct { RQProductID = Convert.ToInt16(item.RQ4ItemID), RQProductSku = item.RQ4SKU, TotalQuantity = item.Quantity, NonSellableQuantity = 0, UnitCost = item.ItemRate, ActionTaken = RQ4.ActionTaken.Credit }; items.Add(prod); } rma.ProductData = items.ToArray(); RQ4.ReturnMerchandiseAuthorization outrma = null; try { outrma = vmi.CreateRMA(vid, rma); Console.WriteLine(outrma.RMAIDByStore); LOG.WriteLine(kvp.Value.OrderID + "," + outrma.RMAIDByStore); LOG.Flush(); } catch (System.Web.Services.Protocols.SoapException se) { Console.WriteLine("error"); WriteOrder(kvp.Value, errfile); LOG.WriteLine(kvp.Value.OrderID + "," + Quote(se.Message).Replace("\r", "").Replace("\n", "")); LOG.Flush(); } catch (Exception ex) { Console.WriteLine("error"); WriteOrder(kvp.Value, errfile); LOG.WriteLine(kvp.Value.OrderID + ",error"); LOG.Flush(); } rmanum++; System.Threading.Thread.Sleep(250); } try { LOG.Flush(); LOG.Close(); } catch { } Console.WriteLine(); Console.WriteLine("done"); Console.ReadLine(); }
public static System.Collections.Generic.List<System.Collections.ArrayList> readCSV(string filename) { Microsoft.VisualBasic.FileIO.TextFieldParser tfp = new Microsoft.VisualBasic.FileIO.TextFieldParser(filename); tfp.Delimiters = new string[] { "," }; tfp.HasFieldsEnclosedInQuotes = false; List<System.Collections.ArrayList> a = new List<System.Collections.ArrayList>(); try { while (!tfp.EndOfData) { string[] s = tfp.ReadFields(); a.Add(new System.Collections.ArrayList(s)); } } catch (Exception err) { } finally { tfp.Close(); } return a; }