public bool Load(string path) { try { string[] lines = File.ReadAllLines(path, Encoding.Default); for (int i = 0; i < lines.Length; i++) { string str = lines[i]; if (string.IsNullOrEmpty(str)) { continue; } if (i == 0) //第1行直接付给变量NC_Documentation { this.NC_Documentation = str.Replace("NC-Documentation:", "").Trim(); } else if (i == 1) //第2行跳过 { } else if (i == 2) //第3行直接付给变量PUTNC_Datei { this.PUTNC_Datei = str.Replace("PUTNC Datei:", "").Trim(); } else if (str.TrimStart().StartsWith("NC-Job:")) //以NC-Job:开头,增加一个job { NCJob job = new NCJob(); this.AddJob(job); int index = str.IndexOf(":"); job.NC_Job = str.Substring(index + 1, str.Length - index - 1); for (i += 1; i < lines.Length; i++) { str = lines[i].Trim(); if (str.StartsWith("Tool : ")) { job.Tool = str; } else if (!string.IsNullOrEmpty(str)) { index = str.IndexOf(":"); string key = str.Substring(0, index).Trim(); string val = str.Substring(index + 1, str.Length - index - 1).Trim(); job.dictionary.Add(key, val); } else { //空行,结束本Job break; } } } } } catch { return(false); } return(true); }
//程序单输出 public bool WritePgmList(string fileName, NCListData exceldata) { Microsoft.Office.Interop.Excel.Application xls = new Microsoft.Office.Interop.Excel.Application(); _Workbook book = null; _Worksheet sheet = null; try { book = xls.Workbooks.Open(fileName, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value); xls.Visible = false; xls.DisplayAlerts = true; sheet = (_Worksheet)book.Worksheets.get_Item(1); Microsoft.Office.Interop.Excel.Range cellRange = sheet.Cells; NCDoc doc = exceldata.NcDoc; VWConf vwConf = VWConf.Instance; int timeTotle = 0; //Jobs明细输出 List <NCJob> jobs = doc.Jobs; for (int i = 0; i < jobs.Count; i++) { NCJob job = jobs[i]; //程序名 cellRange[i + 23, 1] = job.NC_Job; //加工内容 cellRange[i + 23, 3] = vwConf.GetProgramDispString(job.NC_Job_Code); //刀具-直径 cellRange[i + 23, 5] = "D" + job.Tool_D; //刀具-半径 cellRange[i + 23, 6] = "R" + job.Tool_R; //刀具-悬长 cellRange[i + 23, 7] = job.TotalToolLength; //加工角度 cellRange[i + 23, 8] = job.MachineAxis; //余量 cellRange[i + 23, 11] = job.Stockallow; //料厚 cellRange[i + 23, 12] = job.Wallthick; //步距 cellRange[i + 23, 13] = job.Stepover; //F值 cellRange[i + 23, 14] = job.F; //刀补 cellRange[i + 23, 15] = job.IsR ? "有" : ""; //理论用时 cellRange[i + 23, 16] = job.NCTime; timeTotle += job.Time_Seconds; } //2-19行基本信息 cellRange[2, 2] = exceldata.ProjectName; cellRange[2, 5] = exceldata.ModuleName; cellRange[4, 2] = exceldata.PartName; cellRange[4, 5] = exceldata.SingleName; cellRange[6, 2] = exceldata.Procedure; cellRange[6, 5] = exceldata.LeftRight; cellRange[8, 2] = DateTime.Now.ToString("yyyy-MM-dd"); cellRange[8, 5] = exceldata.BenchMark; cellRange[11, 2] = VWUtil.FormatHMS(timeTotle); cellRange[11, 5] = exceldata.Side; cellRange[16, 2] = doc.NC_Documentation; cellRange[18, 2] = doc.PUTNC_Datei; //图片 Microsoft.Office.Interop.Excel.Range picRange = null; picRange = sheet.get_Range("R2", Missing.Value); picRange.Select(); Microsoft.Office.Interop.Excel.Pictures pics = (Microsoft.Office.Interop.Excel.Pictures)sheet.Pictures(Missing.Value); pics.Delete(); pics.Insert(exceldata.PicturePath, Missing.Value); book.Save(); book.Close(false, Missing.Value, Missing.Value); return(true); } catch (Exception ex) { return(false); } finally { xls.Quit(); xls = null; sheet = null; book = null; GC.Collect(); } }
public void AddJob(NCJob job) { Jobs.Add(job); }