public override bool TransferFile(string infile) { QCatalog qlog = QCatalog.GetCatlog(); COMReader reader = new COMReader(infile); double days = double.Parse(reader.GetCell("D5")); double time = double.Parse(reader.GetCell("F5")); DateTime dt = new DateTime(1900, 1, 1).AddDays(-2).AddDays(days + time); string allinfo = reader.GetCell("B8"); string K1001 = allinfo.Split('_')[1]; // modified string K1002 = reader.GetCell("F8"); // modified string K0006 = allinfo.Split('_')[0]; // modified string K0007 = reader.GetCell("B11"); // modified string K0008 = reader.GetCell("D8"); // modified string K0010 = reader.GetCell("F11"); string K0012 = reader.GetCell("D11"); string K0061 = allinfo.Split('_')[2]; QDataItem qdi = new QDataItem(); qdi[0006] = K0006; // modified qdi[0007] = qlog.GetCatalogPIDString("K4092", K0007); // modified qdi[0008] = K0008; // modified qdi[0010] = qlog.GetCatalogPIDString("K4062", K0010); qdi[0012] = qlog.GetCatalogPIDString("K4072", K0012); qdi[0061] = qlog.GetCatalogPIDString("K4272", K0061); // The first row of data. If it is not fixed, modify this variable. int startrow = 13; QFile qf = new QFile(); qf[1001] = K1001; // modified qf[1002] = K1002; // modified for (int i = startrow; i < reader.GetRowCount(); i++) { // Characteristic Actual Nominal Upper Tol Lower Tol Deviation // K2002, K0001, K2101, K2113, K2112 string K2002 = reader.GetCell(i, 0); string K0001 = reader.GetCell(i, 1); string K2101 = reader.GetCell(i, 2); string K2113 = reader.GetCell(i, 3); string K2112 = reader.GetCell(i, 4); QCharacteristic qc = new QCharacteristic(); qc[2001] = qf.Charactericstics.Count + 1; qc[2002] = K2002; qc[2022] = "8"; qc[2101] = K2101; qc[2112] = K2112; qc[2113] = K2113; qc[2120] = 1; qc[2121] = 1; qc[2142] = "mm"; qc[8500] = 5; qc[8501] = 0; QDataItem di = qdi.Clone(); di.SetValue(K0001); qc.data.Add(di); qf.Charactericstics.Add(qc); } qf.ToDMode(); return(SaveDfq(qf, string.Format("{0}\\{1}_{2}.dfq", pd.GetOutDirectory(infile), // output directory allinfo, // filename from all info. DateTimeHelper.ToFullString(DateTime.Now)))); // time stamp. }
public override bool TransferFile(string infile) { QCatalog qlog = QCatalog.GetCatlog(@"Z:\Projects\QTransducer\2017年\2017_10_重庆_Nemak\20180112_Problems"); COMReader reader = new COMReader(infile); /************ 内容检测,有空不转换 **************/ // 检测内容:Date (D4)/Time(D7)/Order(F4)/ Operator(B10)/ CMM(D10)/Part NO(F7)/Product(F10) if (reader.GetCell("D5").Trim().Length == 0 || reader.GetCell("D8").Trim().Length == 0 || reader.GetCell("F5").Trim().Length == 0 || reader.GetCell("B11").Trim().Length == 0 || reader.GetCell("D11").Trim().Length == 0 || reader.GetCell("F8").Trim().Length == 0 || reader.GetCell("F11").Trim().Length == 0) { LogList.Add(new Classes.TransLog(infile, "无", "表头有空值,无法转换。", Classes.LogType.Fail, "根据需求,以下表头禁止为空:Date /time/order/ operator/ CMM/Part NO/Product。")); return(false); } /************ 从Excel文件读取标题K域 **************/ string K1001 = reader.GetCell("B8"); string K0008 = reader.GetCell("B11"); double days = double.Parse(reader.GetCell("D5")); double time = double.Parse(reader.GetCell("D8")); DateTime dt = new DateTime(1900, 1, 1).AddDays(-2).AddDays(days + time); string K0012 = reader.GetCell("D11"); string K0061 = reader.GetCell("F5"); string K0014 = reader.GetCell("F8"); string K1002 = reader.GetCell("F11"); // 年份(2位)_天数(3位)_班次(1位)_设备号(1位)_当日序列号(3位)_设备累计序列号(7位)_工件状态(1位) string K0006 = null; string K0007 = null; string K0010 = null; try { K0006 = K0014.Substring(0, 5); // K0007: 截取班次(1位). K0007 = K0014.Substring(5, 1); // K0007: 截取班次(1位). K0010 = K0014.Substring(6, 1); // K0010: 截取设备号(1位) } catch (Exception ex) { Console.WriteLine(ex.Message); } /************ K值模板 **************/ QFile qf = new QFile(); qf[1001] = K1001; qf[1002] = K1002; QDataItem qdi = new QDataItem(); if (K0006 != null) { qdi[0006] = K0006; } if (K0007 != null) { qdi[0007] = qlog.GetCatalogPIDString("K4252", K0007); } qdi[0008] = qlog.GetCatalogPIDString("K4092", K0008); if (K0010 != null) { qdi[0010] = qlog.GetCatalogPIDString("K4062", K0010); } qdi[0012] = qlog.GetCatalogPIDString("K4072", K0012); qdi[0014] = K0014; qdi[0061] = qlog.GetCatalogPIDString("K4272", K0061); // The first row of data. If it is not fixed, modify this variable. int firstRow = 13; int lastRow = reader.GetRowCount(); for (int i = firstRow; i < reader.GetRowCount(); i++) { // Characteristic Actual Nominal Upper Tol Lower Tol Deviation // K2002, K0001, K2101, K2113, K2112 string K2002 = reader.GetCell(i, 0); string K0001 = reader.GetCell(i, 1); string K2101 = reader.GetCell(i, 2); string K2113 = reader.GetCell(i, 3); string K2112 = reader.GetCell(i, 4); if (K2002 == null || K2002.Trim().Length == 0) { break; // 根据20180112 问题 第2条 修改。 } QCharacteristic qc = new QCharacteristic(); qc[2001] = qf.Charactericstics.Count + 1; qc[2002] = K2002; qc[2022] = "8"; qc[2101] = K2101; qc[2112] = K2112; qc[2113] = K2113; qc[2120] = 1; qc[2121] = 1; qc[2142] = "mm"; qc[8500] = 5; qc[8501] = 0; QDataItem di = qdi.Clone(); di.SetValue(K0001); di.date = dt; // DateTime.Now; // 根据20180112 问题 第3条 修改。 qc.data.Add(di); qf.Charactericstics.Add(qc); } qf.ToDMode(); bool result = SaveDfq(qf, string.Format("{0}\\{1}_{2}.dfq", pd.GetOutDirectory(infile), // output directory K0014, // filename from all info. DateTimeHelper.ToFullString(DateTime.Now))); // time stamp. Thread.Sleep(1000); return(result); }
public override bool TransferFile(string path) { IniAccess ia = new IniAccess("userconfig.ini"); string catalogfile = ia.ReadValue("catalog"); QCatalog catalog = QCatalog.GetCatlog(File.Exists(catalogfile) ? catalogfile : "catalog.dfd"); Workbook wb = new Workbook(); wb.LoadFromFile(path); Worksheet sheet = wb.Worksheets[0]; QFile qf = new QFile(); qf[1001] = sheet[3, 2].Value; qf[1053] = sheet[3, 4].Value; qf[1086] = sheet[3, 5].Value; qf[1110] = sheet[3, 6].Value; // 1100 -> 1110 qf[1101] = sheet[2, 1].Value; qf[1102] = sheet[3, 1].Value; int rowid = 5; while (true) { if (isEmpty(sheet, rowid)) { break; } QCharacteristic qc = new QCharacteristic(); qf.Charactericstics.Add(qc); string pid = sheet[rowid, 1].Value != null ? sheet[rowid, 1].Value.ToString() : ""; qc[2001] = pid.Replace('(', ' ').Replace(')', ' ').Trim(); qc[2002] = sheet[rowid, 2].Value; qc[2005] = sheet[rowid, 13].Value.Contains("是") ? 4 : 1; // 不包括是时为 1 还是0 ,文档中有错误。 qc[2022] = 4; qc[2101] = sheet[rowid, 3].Value; qc[2113] = sheet[rowid, 4].Value; qc[2112] = sheet[rowid, 5].Value; qc[2120] = 1; qc[2121] = 1; qc[2142] = "mm"; qc[8500] = 5; qc[8501] = 0; QDataItem di = new QDataItem(); di.SetValue(sheet[rowid, 6].Value); di.date = sheet[3, 10].DateTimeValue; di[0006] = sheet[3, 3].Value; di[0008] = catalog.getCatalogPID("K4093", sheet[3, 11].Value); di[0010] = catalog.getCatalogPID("K4063", sheet[rowid, 11].Value); di[0011] = sheet[rowid, 10].Value; di[0012] = catalog.getCatalogPID("K4072", sheet[rowid, 10].Value); di[0061] = catalog.getCatalogPID("K4273", sheet[3, 7].Value); qc.data.Add(di); // Console.WriteLine("{0}, {0}, {0}, {0}", di[0008], di[0010], di[0012], di[0061]); rowid++; } qf.ToDMode(); SaveDfqByFilename(qf, Path.GetFileNameWithoutExtension(path) + ".dfq"); return(base.TransferFile(path)); }
public override bool TransferFile(string infile) { COMReader reader = new COMReader(infile, ExcelVersion.Excel2003); string K0012 = reader.GetCell("G3"); QCatalog qlog = QCatalog.GetCatlog(@"Z:\Projects\QTransducer\2017年\2017_08_Antai_密度\P180116\CATALOG.dfd"); List <QFile> qfs = new List <QFile>(); DateTime date = new DateTime(1900, 1, 1); for (int row = 5; row < reader.GetRowCount(); row++) { try { DateTime dt = date.AddDays(int.Parse(reader.GetCell("A" + row)) - 2); string K1002 = reader.GetCell("B" + row); string K0014 = reader.GetCell("C" + row); string K0016 = reader.GetCell("D" + row); string K0010 = reader.GetCell("E" + row); string K1001 = reader.GetCell("F" + row); string K0011 = reader.GetCell("I" + row) + '\\' + reader.GetCell("J" + row) + '\\' + reader.GetCell("K" + row) + '\\' + reader.GetCell("L" + row); string K0001 = reader.GetCell("M" + row); double value = double.Parse(K0001); string K2110 = ""; string K2111 = ""; string K2120 = ""; string colN = reader.GetCell(row, "N"); // 上下限写入同一单元格并用 "-"间隔,即:下限-上限。 // 将中横杠前的数据写入K2110,中横杠后的数据写入K2111。 // 1、当密度要求值出现中横杠"_"时,代表该行信息不需要输出 if (colN == null || colN.Trim().Length == 1) { continue; } else if (colN.Contains("-")) { K2110 = colN.Split('-')[0]; K2111 = colN.Split('-')[1]; } // 2、当密度要求值出现中横杠”≥”时,该参数只有下限K2110, // 例如≥30,输出K2110 = 30,K2111为空,K2120 = 1 else if (colN.Contains("≥")) { K2110 = colN.Split('≥')[1]; K2120 = "1"; } // 3、当密度要求值出现中横杠” >”时,该参数只有下限,且为下自然界线。 // 例如 > 30,输出K2110 = 30,K2111为空,K2120 = 2 else if (colN.Contains(">")) { K2110 = colN.Split('>')[1]; K2120 = "2"; } string K0008 = reader.GetCell("Q" + row); if (K1001 == "" && K1002 == "") { LogList.Add(new TransLog(infile, "", "K1001 和 K1002 均为空。", LogType.Fail)); break; } QFile qf = getQFile(qfs, K1001, K1002); if (qf.Charactericstics.Count == 0) { QCharacteristic qc = new QCharacteristic(); qf.Charactericstics.Add(qc); qc[2002] = "密度g/cm³"; qc[2022] = 8; if (K2110.Length > 0) { qc[2110] = K2110; } if (K2111.Length > 0) { qc[2111] = K2111; } qc[2120] = 1; qc[2121] = 1; if (K2120.Length > 0) { qc[2120] = K2120; } qc[2142] = "g/cm³"; qc[8500] = 5; qc[8501] = 0; } QDataItem qdi = new QDataItem { date = dt }; qdi.SetValue(K0001); qdi[0008] = qlog.getCatalogPID("K4093", K0008); qdi[0010] = qlog.getCatalogPID("K4063", K0010); qdi[0011] = K0011; qdi[0012] = qlog.getCatalogPID("K4073", K0012); qdi[0014] = K0014; qdi[0016] = K0016; qf.Charactericstics[0].data.Add(qdi); // Console.WriteLine("K0008({0})->K4093={1}", K0008, qlog.getCatalogPID("K4093", K0008)); } catch (Exception ex) { StringBuilder sb = new StringBuilder(); sb.Append("Row " + row + ": "); for (int col = 0; col < reader.GetColumnCount(); col++) { sb.Append(reader.GetCell(row, col) + ", "); } Console.WriteLine(sb.ToString() + ". Error message: " + ex.Message); } } foreach (QFile qf in qfs) { qf.ToDMode(); SaveDfqByFilename(qf, qf[1001] + "_" + qf[1002] + ".dfq"); } return(true); }