public override bool TransferFile(string path) { // K1xxx 表示零件层信息 ->QFile // K2xxx 表示参数层信息 ->QCharacteristic // K0xxx 表示测量数据 -> QDataItem QFile qf = new QFile(); qf[1001] = "excel[0][1]"; QCharacteristic qc = new QCharacteristic(); qc[2001] = "k2001"; qf.Charactericstics.Add(qc); QDataItem dataItem = new QDataItem(); dataItem.SetValue("excel[x][y]"); dataItem.date = DateTime.Parse("2018-1-1 15:00:00"); dataItem[0006] = ""; qc.data.Add(dataItem); qf.ToDMode(); qf.SaveToFile("d:\\abcd.dfq"); return(true); }
private int indexOf(List <QCharacteristic> qchs, QCharacteristic qc) { for (int i = 0; i < qchs.Count; i++) { if (qchs[i][2001].ToString() == qc[2001].ToString() && qchs[i][2002].ToString() == qc[2002].ToString()) { return(i); } } return(-1); }
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) { COMReader reader = new COMReader(infile); string K1900 = reader.GetCell("B5"); // string K1041 = reader.GetCell("B8"); // string K0008 = reader.GetCell("B11"); double days = double.Parse(reader.GetCell("D5")); double time = double.Parse(reader.GetCell("D8")); DateTime K0004 = new DateTime(1900, 1, 1).AddDays(-2).AddDays(days + time); string K0012 = reader.GetCell("D11"); string K1001 = reader.GetCell("F8");// string K0014 = reader.GetCell("F11"); QCatalog qlog = getCatlog(); int startRow = 13; int endRow = reader.GetRowCount(); // A: char, B: Actual, C: Nominal, D: Upper Tol; E: Lower Tol; F: Deviation QFile qf = new QFile(); qf[1001] = K1001; qf[1041] = K1041; qf[1900] = K1900; for (int i = startRow; i < endRow; 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 = new QDataItem(); di.date = K0004; di.SetValue(K0001); di[0008] = qlog.getCatalogPID("K4093", K0008); di[0012] = qlog.getCatalogPID("K4073", K0012); di[0014] = K0014; qc.data.Add(di); qf.Charactericstics.Add(qc); } qf.ToDMode(); return(SaveDfq(qf, string.Format("{0}\\{1}_{2}.dfq", pd.GetOutDirectory(infile), // output directory K1001, // filename from all info. DateTimeHelper.ToFullString(DateTime.Now)))); // time stamp. }
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) { 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); }
private List <QCharacteristic> ProcessModel(List <string[]> model) { List <QCharacteristic> qcs = new List <QCharacteristic>(); string[] titles = model[0]; string type = titles[F].ToUpper().Trim(); // ----------------------------- Case 1 & 2 ----------------------------- if (type == "BPT" || type == "KPT" || type == "FPT") { QCharacteristic qc = new QCharacteristic(); qc[2001] = model[0][D]; string k2112 = "", k2113 = ""; string k2002 = type == "FPT" ? "A_" : "B_"; bool afagEmpty = titles[AF].ToLower().Length == 0 || titles[AG].ToLower().Length == 0; string ay = model[0][AY].ToLower(); if (ay.Contains("x")) { k2002 += "x"; if (afagEmpty) { k2112 = titles[Z]; k2113 = titles[AA]; } else { k2112 = titles[AF]; k2113 = titles[AG]; } } else if (ay.Contains("y")) { k2002 = "y"; if (afagEmpty) { k2112 = titles[AB]; k2113 = titles[AC]; } else { k2112 = titles[AF]; k2113 = titles[AG]; } } else if (ay.Contains("z")) { k2002 = "z"; if (afagEmpty) { k2112 = titles[AD]; k2113 = titles[AE]; } else { k2112 = titles[AF]; k2113 = titles[AG]; } } qc[2002] = k2002; qc[2101] = 0; qc[2112] = k2112; qc[2113] = k2113; for (int i = 1; i < model.Count; i++) { QDataItem qdi = new QDataItem(); qdi.SetValue(model[i][BH]); setTime(qdi, model[i][BV]); qdi[0014] = model[i][BU]; qc.data.Add(qdi); } qcs.Add(qc); } else if (type == "KRE" || type == "RLO" || type == "SYP" || type == "LLO") { QCharacteristic qcx = new QCharacteristic(); qcx[2001] = model[0][D]; qcx[2002] = "X"; qcx[2112] = titles[Z]; qcx[2113] = titles[AA]; QCharacteristic qcy = new QCharacteristic(); qcy[2001] = model[0][D]; qcy[2002] = "Y"; qcy[2112] = titles[AB]; qcy[2113] = titles[AC]; QCharacteristic qcz = new QCharacteristic(); qcz[2001] = model[0][D]; qcz[2002] = "Z"; qcz[2112] = titles[AD]; qcz[2113] = titles[AE]; for (int i = 1; i < model.Count; i++) { QDataItem qdix = new QDataItem(); qdix.SetValue(model[i][BE]); setTime(qdix, model[i][BV]); qdix[0014] = model[i][BU]; qcx.data.Add(qdix); QDataItem qdiy = new QDataItem(); qdiy.SetValue(model[i][BF]); setTime(qdiy, model[i][BV]); qdiy[0014] = model[i][BU]; qcy.data.Add(qdiy); QDataItem qdiz = new QDataItem(); qdiz.SetValue(model[i][BG]); setTime(qdiz, model[i][BV]); qdiz[0014] = model[i][BU]; qcz.data.Add(qdiz); } if (qcx[2112].ToString().Length > 0 && qcx[2113].ToString().Length > 0) { qcs.Add(qcx); } if (qcy[2112].ToString().Length > 0 && qcy[2113].ToString().Length > 0) { qcs.Add(qcy); } if (qcz[2112].ToString().Length > 0 && qcz[2113].ToString().Length > 0) { qcs.Add(qcz); } } //----------------------- CASE 4 ----------------------- else if (type == "ABS") { QCharacteristic qcx = new QCharacteristic(); qcx[2001] = model[0][D]; qcx[2002] = "dX"; qcx[2112] = titles[AH]; qcx[2113] = titles[AI]; QCharacteristic qcy = new QCharacteristic(); qcy[2001] = model[0][D]; qcy[2002] = "dY"; qcy[2112] = titles[AJ]; qcy[2113] = titles[AK]; QCharacteristic qcz = new QCharacteristic(); qcz[2001] = model[0][D]; qcz[2002] = "dZ"; qcz[2112] = titles[AL]; qcz[2113] = titles[AM]; for (int i = 1; i < model.Count; i++) { QDataItem qdix = new QDataItem(); qdix.SetValue(model[i][BI]); setTime(qdix, model[i][BV]); qdix[0014] = model[i][BU]; qcx.data.Add(qdix); QDataItem qdiy = new QDataItem(); qdiy.SetValue(model[i][BJ]); setTime(qdiy, model[i][BV]); qdiy[0014] = model[i][BU]; qcy.data.Add(qdiy); QDataItem qdiz = new QDataItem(); qdiz.SetValue(model[i][BK]); setTime(qdiz, model[i][BV]); qdiz[0014] = model[i][BU]; qcz.data.Add(qdiz); } if (qcx[2112].ToString().Length > 0 && qcx[2113].ToString().Length > 0) { qcs.Add(qcx); } if (qcy[2112].ToString().Length > 0 && qcy[2113].ToString().Length > 0) { qcs.Add(qcy); } if (qcz[2112].ToString().Length > 0 && qcz[2113].ToString().Length > 0) { qcs.Add(qcz); } } return(qcs); }
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); }