private bool CreatePTB(string Filename, UGfamilies ugf) { if (ugf == null) return false; var file = new System.IO.StreamWriter(Filename); file.WriteLine("!"); file.WriteLine("!This part table waf generated by UGPipingCrossSection"); file.WriteLine("!"); file.WriteLine("VERSION 120"); file.WriteLine("!"); file.WriteLine("COLUMNS"); var NamesParam = ugf.getParamNames(); var TypesParam = ugf.getParamTypes(); for (int i = 0; i < ugf.CountParams; i++) file.WriteLine("\t{0}\t\t{1}", TypesParam[i], FieldNameFromFamName(NamesParam[i])); file.WriteLine("\t{0}\t\t{1}", "STRING/HIDE", "PART_NAME"); file.WriteLine("END_OF_COLUMNS"); file.WriteLine(""); file.WriteLine("DATA"); file.WriteLine("!"); string tempS = "!"; for (int i = 0; i < ugf.CountParams; i++) tempS += FieldNameFromFamName(NamesParam[i]) + "\t"; tempS += "PART_NAME"; file.WriteLine(tempS); file.WriteLine("!"); for (int p = 0; p < ugf.CountParts; p++) { var values = ugf.getValuesFromPartNumber(p); tempS = ""; for (int i = 0; i < ugf.CountParams; i++) { if (TypesParam[i] == "STRING/HIDE") tempS += "\"" + values[i] + "\"" + "\t"; if (TypesParam[i] == "REAL") tempS += values[i] + "\t"; } //tempS += "\"" + ugf.PART_NAME + "\""; file.WriteLine(tempS); } file.WriteLine("END_OF_DATA"); file.Close(); return true; }
//Анализ файла void Button1Click(object sender, EventArgs e) { string[] row; ListViewItem LVI; try { prt = new UGprt(PRTFilenameBox.Text); fam = new UGfamilies(prt); } catch (Exception) { MessageBox.Show("Ошибка открытия файл", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //Заполнение listViewCH //создание столбцов for (int i = 0; i < fam.CountParams; i++) { var column = new ColumnHeader(); column.Text = fam.getTypeParam(i); column.TextAlign = HorizontalAlignment.Center; column.Width = column.Text == UGfamilies.typeField[0] ? 100:40; listViewCH.Columns.Add(column); } //заполнение полей LVI = new ListViewItem(fam.getParamNames()); listViewCH.Items.Add(LVI); for (int i = 0; i < fam.CountParts; i++) { row = fam.getValuesFromPartNumber(i); LVI = new ListViewItem(row); listViewCH.Items.Add(LVI); } listViewCH.SetHeaderDropdownToAll(true); listViewCH.HeaderDropdown += listViewCH_HeaderDropdown; }