public bool ModifyDataFromCsv(string csvFilename, bool bface6, ref double sheetWidth, ref double sheetLength) { int thickness = 0; //发现水平孔位的Z值有超过板厚的数据。将这数据过滤掉 宋新刚 20171101 try { StreamReader sr = new StreamReader(csvFilename, Encoding.Default); string strLine = sr.ReadLine(); //strLine = sr.ReadToEnd(); int RouteSetIndex = 0; int routeswqindex = 0; ArrayList Seqlist = new ArrayList(); Seqlist.Clear(); bool hasend = false; ArrayList outstrlist = new ArrayList(); BorderSequenceEntity borderSeq = new BorderSequenceEntity(strLine); sheetWidth = 0; double.TryParse(borderSeq.PanelWidth, out sheetWidth); sheetLength = 0; double.TryParse(borderSeq.PanelLength, out sheetLength); while (strLine != null) { strLine = strLine.Replace("D8.5", "129").Replace("D10", "130"); if (strLine.IndexOf("EndSequence,") == 0) { hasend = true; outstrlist.Add(strLine); } ////处理每行的字符串 else if (strLine.IndexOf("BorderSequence,") == 0) { borderSeq.NestRoutesCount = "0"; borderSeq.Edgeband1 = borderSeq.Edgeband1.Replace("MM", "mm"); borderSeq.Edgeband2 = borderSeq.Edgeband1.Replace("MM", "mm"); borderSeq.Edgeband3 = borderSeq.Edgeband1.Replace("MM", "mm"); borderSeq.Edgeband4 = borderSeq.Edgeband1.Replace("MM", "mm"); if (borderSeq.CurrentZoneName == "AD") { borderSeq.CurrentZoneName = "M"; borderSeq.RunField = "3"; } if (borderSeq.CurrentZoneName == "DA") { borderSeq.CurrentZoneName = "N"; borderSeq.RunField = "4"; } thickness = Convert.ToInt32(borderSeq.PanelThickness); //发现水平孔位的Z值有超过板厚的数据。将这数据过滤掉 宋新刚 20171101 if (bface6) { borderSeq.Face6FileName = Path.GetFileNameWithoutExtension(csvFilename); } else { borderSeq.FileName = Path.GetFileNameWithoutExtension(csvFilename); } string output = borderSeq.OutPutCsvString(); outstrlist.Add(output); } else if (strLine.IndexOf("HDrillSequence,") == 0) { ModifyRouteSeqV2(bface6, borderSeq, Seqlist, ref routeswqindex, ref outstrlist); HDrillSequenceEntity hdrillSeq = new HDrillSequenceEntity(strLine); hdrillSeq.HDrillFeedSpeed = "3000"; hdrillSeq.HDrillEntrySpeed = "2700"; /*** 用于解决水平孔加工面产生小数点的问题 宋新刚20161115 * **/ if (hdrillSeq.CurrentFace == "1.0000") { hdrillSeq.CurrentFace = "1"; } else if (hdrillSeq.CurrentFace == "2.0000") { hdrillSeq.CurrentFace = "2"; } else if (hdrillSeq.CurrentFace == "3.0000") { hdrillSeq.CurrentFace = "3"; } else if (hdrillSeq.CurrentFace == "4.0000") { hdrillSeq.CurrentFace = "4"; } // 以下是解决工程部 双向拉杆有水平孔为0的情况 if (hdrillSeq.HDrillDiameter == "0" || hdrillSeq.HDrillDiameter == "0.0000") { strLine = sr.ReadLine(); continue; } // 以下是发现水平孔位的Z值有超过板厚的数据。将这数据过滤掉 宋新刚 20171101 if (Convert.ToDouble(hdrillSeq.HDrillY) > thickness) //发现其高度值有小数。所以这里必须得是Double类型 宋新刚20171106 { strLine = sr.ReadLine(); continue; } // 以下是解决工程部 水平孔的坐标出现负数的情况 if (hdrillSeq.HDrillZ.IndexOf("-") == 0 || hdrillSeq.HDrillX.IndexOf("-") == 0 || hdrillSeq.HDrillY.IndexOf("-") == 0) { // MessageBox.Show(" 以下是解决工程部 水平孔的坐标出现负数的情况"); strLine = sr.ReadLine(); continue; } // 宋新刚 20161114 // 以下是解决舟山翻床厚背板镜像加工 在面1和面2上多出现10的水平孔 通过式PTP无法加工 if (hdrillSeq.HDrillDiameter == "10.0000" || hdrillSeq.HDrillDiameter == "10") { strLine = sr.ReadLine(); continue; } //证明水平孔不可能有10的情况。遇到有10的水平孔全部删除 string output = hdrillSeq.OutPutCsvString(); outstrlist.Add(output); } else if (strLine.IndexOf("VdrillSequence,") == 0) { ModifyRouteSeqV2(bface6, borderSeq, Seqlist, ref routeswqindex, ref outstrlist); VdrillSequenceEntity vdrillSeq = new VdrillSequenceEntity(strLine); vdrillSeq.VDrillFeedSpeed = "3000"; vdrillSeq.VDrillEntrySpeed = "8000"; // 以下是解决工程部 垂直孔的坐标出现负数的情况 if (vdrillSeq.VDrillX.IndexOf("-") == 0 || vdrillSeq.VDrillY.IndexOf("-") == 0 || vdrillSeq.VDrillZ.IndexOf("-") == 0) { strLine = sr.ReadLine(); continue; } //以下是解决工程部模型 孔位超出板材范围的情况 if (Convert.ToDouble(vdrillSeq.VDrillY) - Convert.ToDouble(borderSeq.PanelWidth) > 0) { strLine = sr.ReadLine(); continue; } if (Convert.ToDouble(vdrillSeq.VDrillX) - Convert.ToDouble(borderSeq.PanelLength) > 0) { strLine = sr.ReadLine(); continue; } // 宋新刚 20161114 string output = vdrillSeq.OutPutCsvString(); outstrlist.Add(output); } else if (strLine.IndexOf("RouteSetMillSequence,") == 0) { ModifyRouteSeqV2(bface6, borderSeq, Seqlist, ref routeswqindex, ref outstrlist); RouteSetIndex++; RouteSetMillSequenceEntity routeSeq = new RouteSetMillSequenceEntity(strLine); routeSeq.RouteSetMillCounter = RouteSetIndex.ToString(); routeSeq.RouteVectorCounter = ""; routeSeq.RouteVectorCount = ""; // 发现AD出来的只要有偏置的地方都需要对调一下 宋新刚 20170118 if (Convert.ToDouble(routeSeq.RouteToolComp) == 1) { routeSeq.RouteToolComp = "2"; } else if (Convert.ToDouble(routeSeq.RouteToolComp) == 2) { routeSeq.RouteToolComp = "1"; } // 发现AD出来的只要有偏置的地方都需要对调一下 宋新刚 20170118 if (Convert.ToDouble(routeSeq.RouteSetMillZ) == 9.25 && Convert.ToDouble(routeSeq.RouteDiameter) == 8.5 && Convert.ToDouble(routeSeq.RouteZ) == 9.25) //发现AD过来的背板槽 有固定的9.25深 修复为5mm深 宋新刚 2018年1月26日 { routeSeq.RouteSetMillZ = "5"; routeSeq.RouteZ = "5"; } Seqlist.Add(routeSeq); } else if (strLine.IndexOf("RouteSequence,") == 0) { routeswqindex++; RouteSetMillSequenceEntity routeSeq = new RouteSetMillSequenceEntity(strLine); routeSeq.RouteSetMillCounter = RouteSetIndex.ToString(); routeSeq.RouteVectorCounter = routeswqindex.ToString(); routeSeq.RouteVectorCount = ""; // 发现AD出来的只要有偏置的地方都需要对调一下 宋新刚 20170118 if (Convert.ToDouble(routeSeq.RouteToolComp) == 1) { routeSeq.RouteToolComp = "2"; } else if (Convert.ToDouble(routeSeq.RouteToolComp) == 2) { routeSeq.RouteToolComp = "1"; } // 发现AD出来的只要有偏置的地方都需要对调一下 宋新刚 20170118 if (Convert.ToDouble(routeSeq.RouteSetMillZ) == 9.25 && Convert.ToDouble(routeSeq.RouteDiameter) == 8.5 && Convert.ToDouble(routeSeq.RouteZ) == 9.25) //发现AD过来的背板槽 有固定的9.25深 修复为5mm深 宋新刚 2018年1月26日 { routeSeq.RouteSetMillZ = "5"; routeSeq.RouteZ = "5"; } Seqlist.Add(routeSeq); } strLine = sr.ReadLine(); } sr.Close(); ModifyRouteSeqV2(bface6, borderSeq, Seqlist, ref routeswqindex, ref outstrlist); //string TempFile = Path.ChangeExtension(csvFilename, "temp"); StreamWriter sw = new StreamWriter(csvFilename, false, Encoding.Default); foreach (string str in outstrlist) { if (string.IsNullOrEmpty(str)) { continue; } sw.WriteLine(str); } if (!hasend) { sw.WriteLine("EndSequence,,,,"); } sw.Flush(); sw.Close(); return(true); } catch (SystemException ex) { MessageBox.Show("代码转换出现异常 " + ex.Message + "\n" + csvFilename); return(false); } }
public bool ReadDataFromCsv(string csvFilename, bool bface6) { try { StreamReader sr = new StreamReader(csvFilename, Encoding.Default); string strLine = sr.ReadLine(); //strLine = sr.ReadToEnd(); int RouteSetIndex = 0; int routeswqindex = 0; ArrayList Seqlist = new ArrayList(); Seqlist.Clear(); ArrayList outstrlist = new ArrayList(); BorderSequenceEntity borderSeq = new BorderSequenceEntity(strLine); while (strLine != null) { strLine = strLine.Replace("D8.5", "129").Replace("D10", "130"); ////处理每行的字符串 if (strLine.IndexOf("BorderSequence,") == 0) { //BorderSequenceEntity borderSeq = new BorderSequenceEntity(strLine); borderSeq.NestRoutesCount = "0"; borderSeq.FileName = Path.GetFileNameWithoutExtension(csvFilename); borderSeq.Edgeband1 = borderSeq.Edgeband1.Replace("MM", "mm"); borderSeq.Edgeband2 = borderSeq.Edgeband1.Replace("MM", "mm"); borderSeq.Edgeband3 = borderSeq.Edgeband1.Replace("MM", "mm"); borderSeq.Edgeband4 = borderSeq.Edgeband1.Replace("MM", "mm"); string output = borderSeq.OutPutCsvString(); outstrlist.Add(output); } else if (strLine.IndexOf("HDrillSequence,") == 0) { ModifyRouteSeqV2(bface6, borderSeq, Seqlist, ref routeswqindex, ref outstrlist); HDrillSequenceEntity hdrillSeq = new HDrillSequenceEntity(strLine); hdrillSeq.HDrillFeedSpeed = "3000"; hdrillSeq.HDrillEntrySpeed = "2700"; string output = hdrillSeq.OutPutCsvString(); outstrlist.Add(output); } else if (strLine.IndexOf("VdrillSequence,") == 0) { ModifyRouteSeqV2(bface6, borderSeq, Seqlist, ref routeswqindex, ref outstrlist); VdrillSequenceEntity vdrillSeq = new VdrillSequenceEntity(strLine); vdrillSeq.VDrillFeedSpeed = "3000"; vdrillSeq.VDrillEntrySpeed = "8000"; string output = vdrillSeq.OutPutCsvString(); outstrlist.Add(output); } else if (strLine.IndexOf("RouteSetMillSequence,") == 0) { ModifyRouteSeqV2(bface6, borderSeq, Seqlist, ref routeswqindex, ref outstrlist); RouteSetIndex++; RouteSetMillSequenceEntity routeSeq = new RouteSetMillSequenceEntity(strLine); routeSeq.RouteSetMillCounter = RouteSetIndex.ToString(); routeSeq.RouteVectorCounter = ""; routeSeq.RouteVectorCount = ""; // 发现AD出来的只要有偏置的地方都需要对调一下 宋新刚 20170118 if (Convert.ToDouble(routeSeq.RouteToolComp) == 1) { routeSeq.RouteToolComp = "2"; } else if (Convert.ToDouble(routeSeq.RouteToolComp) == 2) { routeSeq.RouteToolComp = "1"; } // 发现AD出来的只要有偏置的地方都需要对调一下 宋新刚 20170118 Seqlist.Add(routeSeq); } else if (strLine.IndexOf("RouteSequence,") == 0) { routeswqindex++; RouteSetMillSequenceEntity routeSeq = new RouteSetMillSequenceEntity(strLine); routeSeq.RouteSetMillCounter = RouteSetIndex.ToString(); routeSeq.RouteVectorCounter = routeswqindex.ToString(); routeSeq.RouteVectorCount = ""; // 发现AD出来的只要有偏置的地方都需要对调一下 宋新刚 20170118 if (Convert.ToDouble(routeSeq.RouteToolComp) == 1) { routeSeq.RouteToolComp = "2"; } else if (Convert.ToDouble(routeSeq.RouteToolComp) == 2) { routeSeq.RouteToolComp = "1"; } // 发现AD出来的只要有偏置的地方都需要对调一下 宋新刚 20170118 Seqlist.Add(routeSeq); } strLine = sr.ReadLine(); } sr.Close(); ModifyRouteSeqV2(bface6, borderSeq, Seqlist, ref routeswqindex, ref outstrlist); string TempFile = Path.ChangeExtension(csvFilename, "temp"); StreamWriter sw = new StreamWriter(TempFile, false, Encoding.Default); foreach (string str in outstrlist) { if (string.IsNullOrEmpty(str)) { continue; } sw.WriteLine(str); } sw.Flush(); sw.Close(); return(true); } catch (SystemException ex) { return(false); } }