private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e) { string title = checkedListBox1.SelectedItem.ToString(); string sLine; int lineNo = 1; string currentRef = null; string currentSheet = String.Empty; char[] lineDelimiter = { '\t' }; //char[] lineDelSpace = { ' ' }; //char[] dash = { '-' }; char[] colon = { ':' }; char[] period = { '.' }; if (e.NewValue == CheckState.Checked) { // make sure source template name has been specified if (sourceTemplateInput.Text.Length <= 0) { MessageBox.Show("Template Spreadsheet must be specified", "Template Spreadsheet Missing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); e.NewValue = CheckState.Unchecked; return; } //if (grids.ContainsKey(title)) //{ // return; //} resultGrid grid = null; TabPage tabPage = null; if (fileToGrid.ContainsKey(title)) { grid = fileToGrid[title]; tabPage = grid.tabPage; tabControl1.TabPages.Add(tabPage); return; } // add data to grid view string fullItemName = Path.Combine(Properties.Settings.Default.LastResultsPath, title); string fileName = Path.GetFileNameWithoutExtension(fullItemName); StreamReader SrcInput = new StreamReader(fullItemName); errorList.Items.Add("====================================================================="); errorList.Items.Add(string.Format("Parsing: {0}", fullItemName)); errorList.Items.Add("====================================================================="); //AddFileToZip("Output.zip", fullItemName); // read the first line and pull off the parameter names sLine = SrcInput.ReadLine(); string[] parms = sLine.Split(lineDelimiter, StringSplitOptions.None); /////////////////////////////////////////////////////////////////////////////////// while ((sLine = SrcInput.ReadLine()) != null) { string[] parts = sLine.Split(lineDelimiter, StringSplitOptions.None); if (sLine == "END") { break; } lineNo++; int pos = Array.IndexOf(ignoreSet, parts[4]); if (pos > -1) { string error = String.Format("Note: True Position coordinate skipped - Line: {0} - Description: {1}", lineNo, parts[2]); errorList.Items.Add(error); continue; } //string[] idParts = parts[2].Split(lineDelSpace, StringSplitOptions.None); //string[] idParts = parts[2].Split(dash, StringSplitOptions.None); var resultArray = Regex.Split(parts[2], @"[^0-9\.]+").Where(c => c != "." && c.Trim() != ""); string[] idParts = resultArray.ToArray(); int nIdParts = idParts.Count(); //string istic = idParts[0]; // make sure there are parts to parse int cnt = idParts.Length; //if (cnt < 2) if (cnt < 1) { string error = String.Format("Error: Cannot parse row - Line: {0} - Description: {1}", lineNo, parts[2]); errorList.Items.Add(error); continue; } string istic = idParts[0]; // make sure it's a valid characteristic that we can parse double dNum; bool isNum = double.TryParse(idParts[0], out dNum); if (!isNum) { string error = String.Format("Error: Calypso description missing hyphen after characteristic number - Line: {0} - Description: {1}", lineNo, parts[2]); errorList.Items.Add(error); continue; } //if (idParts[1] != "-") //{ // double dNum; // bool isNum = double.TryParse(idParts[0], out dNum); // if (!isNum) // { // string error = String.Format("Error: Calypso description missing hyphen after characteristic number - Line: {0} - Description: {1}", lineNo, parts[2]); // errorList.Items.Add(error); // continue; // } //} if (charInfos.ContainsKey(istic) == false) { //string error = String.Format("Error: Calypso characteristic ({2}) not in ballooned drawing - Line: {0} - Description: {1}", lineNo, parts[2], istic); string error = String.Format("Error: Calypso characteristic ({2}) not in Solidworks spreadsheet - Line: {0} - Description: {1}", lineNo, parts[2], istic); errorList.Items.Add(error); continue; } //if (charInfos[istic].IsUsed()) //{ // string error = String.Format("Warning: Calypso characteristic ({2}) already used - Line: {0} - Description: {1}", lineNo, parts[2], istic); // errorList.Items.Add(error); // continue; //} // save run number charInfos[istic].AddRun(parts[1]); // save the decription charInfos[istic].AddDesc(parts[2]); string actual = String.Empty; double actualVal = 0.0; string deviation = String.Empty; double deviationVal = 0.0; if (parts[7].Contains("999") && parts[8].Contains("999")) { // we have a basic dimension string x = parts[8]; string y = parts[9]; charInfos[istic].SetBasic(true); } // Actual if (parts[5].Length > 0) { actual = parts[5]; // determine if this is a degree/minute/sec measure if (actual.Contains(':')) { string[] dms = actual.Split(colon, StringSplitOptions.None); int deg = Convert.ToInt16(dms[0]); int min = Convert.ToInt16(dms[1]); int sec = Convert.ToInt16(dms[2]); actualVal = Math.Abs((1.0 * deg) + (1.0 * min / 60.0) + (1.0 * sec / 3600.0)); } else { actualVal = Math.Abs(Convert.ToDouble(actual)); } charInfos[istic].AddAct(actualVal); charInfos[istic].AddActual(actualVal); } // Exceed if (parts[10].Length > 0) { deviation = parts[10]; deviationVal = Math.Abs(Convert.ToDouble(deviation)); charInfos[istic].AddDev(deviationVal); charInfos[istic].AddDeviation(deviationVal); } else { charInfos[istic].AddDev(-999.00); } // Comment string comment = parts[14]; charInfos[istic].MarkUsed(); } SrcInput.Close(); /////////////////////////////////////////////////////////////////////////////////// foreach (charInfo cInfo in charInfos.Values) { if (cInfo.run.Length == 0) { if (cInfo.isCMM) { //string text = String.Format("Error - Characteristic in spreadsheet, but missing from txt data: CharNo={0}, Nominal={1}", cInfo.charNo, cInfo.nominal); string text = String.Format("Error - Characteristic in Solidworks spreadsheet, but missing from Calypso chr data: CharNo={0}, Nominal={1}", cInfo.charNo, cInfo.nominal); errorList.Items.Add(text); } continue; } if (currentRef == null || currentRef != cInfo.run) { currentRef = cInfo.run; currentSheet = string.Format("Form3_{0}", currentRef); grid = new resultGrid(title, currentRef); tabPage = new TabPage(currentSheet); grid.tabPage = tabPage; // saving a copy of this grids parent tabPage tabPage.Controls.Add(grid.gridControl); tabPage.Controls.Add(grid.label); tabPage.Controls.Add(grid.fileName); tabControl1.TabPages.Add(tabPage); //fileToGrid.Add(title, grid); try { fileToGrid.Add(title, grid); } catch (Exception ex) { errorList.Items.Add(string.Format("Error: {0}. Run# {1}, Characteristic {2}", ex.Message, currentRef, cInfo.charNo)); continue; } } DataGridViewRow row = (DataGridViewRow)grid.gridControl.Rows[0].Clone(); row.DefaultCellStyle = new DataGridViewCellStyle() { //Font = new System.Drawing.Font("InspectionXpert GDT", 9.5F) Font = newFont }; row.Cells[0].Value = cInfo.charNo; row.Cells[1].Value = cInfo.nominal; row.Cells[2].Value = cInfo.upper; row.Cells[3].Value = cInfo.lower; row.Cells[4].Value = cInfo.actVal.ToString(fontFormat); row.Cells[5].Value = (cInfo.devVal == -999.00) ? "" : row.Cells[5].Value = cInfo.devVal; grid.gridControl.Rows.Add(row); } } else { // unchecked resultGrid grid = fileToGrid[title]; TabPage tabPage = grid.tabPage; tabControl1.TabPages.Remove(tabPage); } }
private void checkedListBox1_ItemCheck(object sender, ItemCheckEventArgs e) { string title = checkedListBox1.SelectedItem.ToString(); string sLine; int lineNo = 0; string currentRef = null; string currentSheet = String.Empty; char[] lineDelimiter = { '\t' }; char[] lineDelSpace = { ' ' }; char[] colon = { ':' }; char[] period = { '.' }; if (e.NewValue == CheckState.Checked) { // make sure source template name has been specified if (sourceTemplateInput.Text.Length <= 0) { MessageBox.Show("Template Spreadsheet must be specified", "Template Spreadsheet Missing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); e.NewValue = CheckState.Unchecked; return; } if (grids.ContainsKey(title)) { return; } resultGrid grid = null; TabPage tabPage = null; // add data to grid view string fullItemName = Path.Combine(Properties.Settings.Default.LastResultsPath, title); string fileName = Path.GetFileNameWithoutExtension(fullItemName); StreamReader SrcInput = new StreamReader(fullItemName); //string sLine; //int lineNo = 0; //string currentRef = null; //string currentSheet = String.Empty; //char[] lineDelimiter = { '\t' }; //char[] lineDelSpace = { ' ' }; //char[] colon = { ':' }; //char[] period = { '.' }; // read the first line and pull off the parameter names sLine = SrcInput.ReadLine(); string[] parms = sLine.Split(lineDelimiter, StringSplitOptions.None); /////////////////////////////////////////////////////////////////////////////////// while ((sLine = SrcInput.ReadLine()) != null) { string[] parts = sLine.Split(lineDelimiter, StringSplitOptions.None); if (sLine == "END") { break; } lineNo++; int pos = Array.IndexOf(ignoreSet, parts[4]); if (pos > -1) { string error = String.Format("Note: True Position coordinate skipped - Line: {0} - Description: {1}", lineNo, parts[2]); errorList.Items.Add(error); continue; } string[] idParts = parts[2].Split(lineDelSpace, StringSplitOptions.None); string istic = idParts[0]; // make sure there are parts to parse int cnt = idParts.Length; if (cnt < 2) { string error = String.Format("Error: Can not parse row - Line: {0} - Description: {1}", lineNo, parts[2]); errorList.Items.Add(error); continue; } // make sure it's a valid characteristic that we can parse if (idParts[1] != "-") { string error = String.Format("Error: Calypso description missing hypen after characteristic number - Line: {0} - Description: {1}", lineNo, parts[2]); errorList.Items.Add(error); continue; } if (charInfos.ContainsKey(istic) == false) { string error = String.Format("Error: Calypso characteristic ({2}) not in ballooned drawing - Line: {0} - Description: {1}", lineNo, parts[2], istic); errorList.Items.Add(error); continue; } //if (charInfos[istic].IsUsed()) //{ // string error = String.Format("Warning: Calypso characteristic ({2}) already used - Line: {0} - Description: {1}", lineNo, parts[2], istic); // errorList.Items.Add(error); // continue; //} // save run number charInfos[istic].AddRun(parts[1]); // save the decription charInfos[istic].AddDesc(parts[2]); string actual = String.Empty; double actualVal = 0.0; string deviation = String.Empty; double deviationVal = 0.0; // Actual if (parts[5].Length > 0) { actual = parts[5]; // determine if this is a degree/minute/sec measure if (actual.Contains(':')) { string[] dms = actual.Split(colon, StringSplitOptions.None); int deg = Convert.ToInt16(dms[0]); int min = Convert.ToInt16(dms[1]); int sec = Convert.ToInt16(dms[2]); actualVal = Math.Abs((1.0 * deg) + (1.0 * min / 60.0) + (1.0 * sec / 3600.0)); } else { actualVal = Math.Abs(Convert.ToDouble(actual)); } charInfos[istic].AddAct(actualVal); charInfos[istic].AddActual(actualVal); } // Exceed if (parts[10].Length > 0) { deviation = parts[10]; deviationVal = Math.Abs(Convert.ToDouble(deviation)); charInfos[istic].AddDev(deviationVal); charInfos[istic].AddDeviation(deviationVal); } else { charInfos[istic].AddDev(-999.00); } // Comment string comment = parts[14]; charInfos[istic].MarkUsed(); } SrcInput.Close(); /////////////////////////////////////////////////////////////////////////////////// foreach (charInfo cInfo in charInfos.Values) { if (cInfo.run.Length == 0) { string text = String.Format("Error - Characteristic in spreadsheet, but missing from txt data: CharNo={0}, Nominal={1}", cInfo.charNo, cInfo.nominal); errorList.Items.Add(text); continue; } if (currentRef == null || currentRef != cInfo.run) { currentRef = cInfo.run; currentSheet = string.Format("Form3_{0}", currentRef); grid = new resultGrid(title, currentRef); tabPage = new TabPage(currentSheet); grid.tabPage = tabPage; // saving a copy of this grids parent tabPage tabPage.Controls.Add(grid.gridControl); tabPage.Controls.Add(grid.label); tabPage.Controls.Add(grid.fileName); tabControl1.TabPages.Add(tabPage); grids.Add(currentSheet, grid); } DataGridViewRow row = (DataGridViewRow)grid.gridControl.Rows[0].Clone(); row.DefaultCellStyle = new DataGridViewCellStyle() { Font = new System.Drawing.Font("InspectionXpert GDT", 9.5F) }; row.Cells[0].Value = cInfo.charNo; row.Cells[1].Value = cInfo.nominal; row.Cells[2].Value = cInfo.upper; row.Cells[3].Value = cInfo.lower; row.Cells[4].Value = cInfo.actVal.ToString(formatCode.Text); row.Cells[5].Value = (cInfo.devVal == -999.00) ? "" : row.Cells[5].Value = cInfo.devVal; grid.gridControl.Rows.Add(row); } //while ((sLine = SrcInput.ReadLine()) != null) //{ // string[] parts = sLine.Split(lineDelimiter, StringSplitOptions.None); // if (sLine == "END") break; // lineNo++; // if (currentRef == null || currentRef != parts[1]) // { // // first time here // currentRef = parts[1]; // currentSheet = string.Format("Form3_{0}", currentRef); // grid = new resultGrid(title, currentRef); // tabPage = new TabPage(currentSheet); // grid.tabPage = tabPage; // saving a copy of this grids parent tabPage // tabPage.Controls.Add(grid.gridControl); // tabPage.Controls.Add(grid.label); // tabPage.Controls.Add(grid.fileName); // tabControl1.TabPages.Add(tabPage); // grids.Add(currentSheet, grid); // } // //if (parts[4] == "gdtPosPol2d.X" || parts[4] == "gdtPosPol2d.Y" || parts[4] == "gdtPosPol2d.Z") // //{ // // string error = String.Format("Note: True Position coordinate skipped - Line: {0} - Description: {1}", lineNo, parts[2]); // // errorList.Items.Add(error); // // continue; // //} // int pos = Array.IndexOf(ignoreSet, parts[4]); // if (pos > -1) // { // string error = String.Format("Note: True Position coordinate skipped - Line: {0} - Description: {1}", lineNo, parts[2]); // errorList.Items.Add(error); // continue; // } // string[] idParts = parts[2].Split(lineDelSpace, StringSplitOptions.None); // string istic = idParts[0]; // // make sure it's a valid characteristic that we can parse // if (idParts[1] != "-") // { // string error = String.Format("Error: Calypso description missing hypen after characteristic number - Line: {0} - Description: {1}", lineNo, parts[2]); // errorList.Items.Add(error); // continue; // } // if (charInfos.ContainsKey(istic) == false) // { // string error = String.Format("Error: Calypso characteristic ({2}) not in ballooned drawing - Line: {0} - Description: {1}", lineNo, parts[2], istic); // errorList.Items.Add(error); // continue; // } // if (charInfos[istic].IsUsed()) // { // string error = String.Format("Warning: Calypso characteristic ({2}) already used - Line: {0} - Description: {1}", lineNo, parts[2], istic); // errorList.Items.Add(error); // continue; // } // // save the decription // charInfos[istic].AddDesc(parts[2]); // int nRow = charInfos[istic].charRow; // string charNo = charInfos[istic].charNo; // string nominal = charInfos[istic].nominal; // string upper = charInfos[istic].upper; // string lower = charInfos[istic].lower; // string actual = String.Empty; // double actualVal = 0.0; // string deviation = String.Empty; // double deviationVal = 0.0; // // Actual // if (parts[5].Length > 0) // { // actual = parts[5]; // // determine if this is a degree/minute/sec measure // if (actual.Contains(':')) // { // string[] dms = actual.Split(colon, StringSplitOptions.None); // int deg = Convert.ToInt16(dms[0]); // int min = Convert.ToInt16(dms[1]); // int sec = Convert.ToInt16(dms[2]); // actualVal = Math.Abs((1.0 * deg) + (1.0 * min / 60.0) + (1.0 * sec / 3600.0)); // } // else // { // actualVal = Math.Abs(Convert.ToDouble(actual)); // } // charInfos[istic].AddActual(actualVal); // } // // Exceed // if (parts[10].Length > 0) // { // deviation = parts[10]; // deviationVal = Math.Abs(Convert.ToDouble(deviation)); // } // // Comment // string comment = parts[14]; // DataGridViewRow row = (DataGridViewRow)grid.gridControl.Rows[0].Clone(); // row.DefaultCellStyle = new DataGridViewCellStyle() // { // Font = new System.Drawing.Font("InspectionXpert GDT", 9.5F) // }; // if (charNo.Contains('.')) // { // string[] decVals = charNo.Split(period, StringSplitOptions.None); // string fraction = string.Format("{0,2:D2}", Convert.ToInt16(decVals[1])); // row.Cells[0].Value = decVals[0] + '.' + fraction; // } // else // { // row.Cells[0].Value = charNo + ".00"; // } // //row.Cells[0].Value = charNo; // //double x = Convert.ToDouble(charNo); // row.Cells[1].Value = nominal; // //row.Cells[1].Style = new DataGridViewCellStyle() // //{ // // Font = new System.Drawing.Font("InspectionXpert GDT", 8F), // // BackColor = (nominal.Length <= 0) ? System.Drawing.Color.LightYellow : System.Drawing.Color.White // //}; // row.Cells[2].Value = upper; // row.Cells[3].Value = lower; // row.Cells[4].Value = actualVal.ToString(formatCode.Text); // row.Cells[5].Value = deviation; // grid.gridControl.Rows.Add(row); // int cnt = grid.gridControl.Rows.Count; // charInfos[istic].MarkUsed(); //} //SrcInput.Close(); } else { //MessageBox.Show("un-checked"); } }