Files
ahtol/daq_testing/UserControlMeasure.cs
Wesley Hofman ecb076ce8b First Commit
2025-08-29 18:13:03 +02:00

978 lines
42 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Excel = Microsoft.Office.Interop.Excel;
namespace daq_testing
{
public partial class UserControlMeasure : UserControl
{
public List<int> PositionList { get; set; }
public string ProjectNumber { get => tbProjectNumber.Text; set => tbProjectNumber.Text = value; }
public string MeasurementLocation { get => lbLocation.SelectedItem.ToString(); }
public event EventHandler MeasureButtonClick;
public event EventHandler ClearAllMeasurementsBtnClick;
public string DataloggerSerial { get; set; }
public List<Result> results = new List<Result>();
public List<PslineConfig> pslineConfigs = new List<PslineConfig>();
public void OnClearAllMeasurementsBtnClick(EventArgs e)
{
ClearAllMeasurementsBtnClick?.Invoke(this, EventArgs.Empty);
}
public void OnMeasureButtonClick(EventArgs e)
{
MeasureButtonClick?.Invoke(this, EventArgs.Empty);
}
public UserControlMeasure()
{
InitializeComponent();
//PopulateButtons();
InitializePositions();
lbLocation.SetSelected(0, true);
progressBar.Visible = false;
}
public void InitializePositions()
{
int posCounter = 0;
foreach (var control in flowLayoutPanelPositionButtons.Controls)
{
if (control is CheckBox)
{
posCounter++;
CheckBox cb = (CheckBox)control;
cb.Name = string.Format("{0:00}", posCounter);
cb.Checked = true;
}
}
}
public void OnPositionButtonClicked(object sender, EventArgs e)
{
CheckBox checkbox = (CheckBox)sender;
UpdatePositionList();
foreach (var item in PositionList)
{
Console.WriteLine(item);
}
}
public void UpdatePositionList()
{
List<string> positionList = new List<string>();
foreach (var control in flowLayoutPanelPositionButtons.Controls)
{
if (control is CheckBox)
{
CheckBox checkbox = (CheckBox)control;
if (checkbox.Checked)
{
positionList.Add(checkbox.Name);
}
}
}
PositionList = positionList.Select(int.Parse).ToList();
Console.WriteLine("bla");
}
public void PopulateButtons()
{
const int MAXPOSITIONS = 40;
flowLayoutPanelPositionButtons.Controls.Clear();
for (int position = 1; position < MAXPOSITIONS + 1; position++)
{
CheckBox checkBox = new CheckBox();
checkBox.Height = 120;
checkBox.Width = 70;
checkBox.Name = string.Format("Position_{0}", position);
checkBox.Text = string.Format("P{0}", position);
checkBox.Appearance = Appearance.Button;
checkBox.Click += OnPositionButtonClicked;
flowLayoutPanelPositionButtons.Controls.Add(checkBox);
}
}
private void btnMeasure_Click(object sender, EventArgs e)
{
}
private List<string> GenFakeList()
{
List<string> values = new List<string>();
Random rnd = new Random();
for (int i = 0; i < 10; i++)
{
double dummyvalue = rnd.NextDouble();
values.Add(string.Format("{0:0.00}",dummyvalue));
}
return values;
}
public double GetResultValueByPositionAndPsline(int position, int Psline)
{
double value = 99999999;
foreach (var result in this.results)
{
if ((result.Position == position) & (Psline == result.PsLine))
{
value = result.Value;
}
}
return value;
}
public void PopulateVoltage( List<Result> Results)
{
this.results = Results;
lvRow1Front.View = View.Details;
lvRow2Front.View = View.Details;
lvRow3Front.View = View.Details;
lvRow4Front.View = View.Details;
lvRow5Front.View = View.Details;
lvRow1Front.Items.Clear();
lvRow2Front.Items.Clear();
lvRow3Front.Items.Clear();
lvRow4Front.Items.Clear();
lvRow5Front.Items.Clear();
lvRow1Back.View = View.Details;
lvRow2Back.View = View.Details;
lvRow3Back.View = View.Details;
lvRow4Back.View = View.Details;
lvRow5Back.View = View.Details;
lvRow1Back.Items.Clear();
lvRow2Back.Items.Clear();
lvRow3Back.Items.Clear();
lvRow4Back.Items.Clear();
lvRow5Back.Items.Clear();
foreach (var result in results)
{
if (result.Position == 1 & result.PsLine !=1)
{
lvRow1Front.Items.Add(new ListViewItem(new string[] { string.Format("PS:{0}:{1:0.00}",result.PsLine,result.Value) }));
lvRow1Front.Items[lvRow1Front.Items.Count-1].BackColor = GetPassFailColor(result);
}
if (result.Position == 9 & result.PsLine != 1)
{
lvRow2Front.Items.Add(new ListViewItem(new string[] { string.Format("PS:{0}:{1:0.00}", result.PsLine, result.Value) }));
lvRow2Front.Items[lvRow2Front.Items.Count - 1].BackColor = GetPassFailColor(result);
}
if (result.Position == 17 & result.PsLine != 1)
{
lvRow3Front.Items.Add(new ListViewItem(new string[] { string.Format("PS:{0}:{1:0.00}", result.PsLine, result.Value) }));
lvRow3Front.Items[lvRow3Front.Items.Count - 1].BackColor = GetPassFailColor(result);
}
if (result.Position == 25 & result.PsLine != 1)
{
lvRow4Front.Items.Add(new ListViewItem(new string[] { string.Format("PS:{0}:{1:0.00}", result.PsLine, result.Value) }));
lvRow4Front.Items[lvRow4Front.Items.Count - 1].BackColor = GetPassFailColor(result);
}
if (result.Position == 33 & result.PsLine != 1)
{
lvRow5Front.Items.Add(new ListViewItem(new string[] { string.Format("PS:{0}:{1:0.00}", result.PsLine, result.Value) }));
lvRow5Front.Items[lvRow5Front.Items.Count - 1].BackColor = GetPassFailColor(result);
}
if (result.Position == 8 & result.PsLine != 1)
{
lvRow1Back.Items.Add(new ListViewItem(new string[] { string.Format("PS:{0}:{1:0.00}", result.PsLine, result.Value) }));
lvRow1Back.Items[lvRow1Back.Items.Count - 1].BackColor = GetPassFailColor(result);
}
if (result.Position == 16 & result.PsLine != 1)
{
lvRow2Back.Items.Add(new ListViewItem(new string[] { string.Format("PS:{0}:{1:0.00}", result.PsLine, result.Value) }));
lvRow2Back.Items[lvRow2Back.Items.Count - 1].BackColor = GetPassFailColor(result);
}
if (result.Position == 24 & result.PsLine != 1)
{
lvRow3Back.Items.Add(new ListViewItem(new string[] { string.Format("PS:{0}:{1:0.00}", result.PsLine, result.Value) }));
lvRow3Back.Items[lvRow3Back.Items.Count - 1].BackColor = GetPassFailColor(result);
}
if (result.Position == 32 & result.PsLine != 1)
{
lvRow4Back.Items.Add(new ListViewItem(new string[] { string.Format("PS:{0}:{1:0.00}", result.PsLine, result.Value) }));
lvRow4Back.Items[lvRow4Back.Items.Count - 1].BackColor = GetPassFailColor(result);
}
if (result.Position == 40 & result.PsLine != 1)
{
lvRow5Back.Items.Add(new ListViewItem(new string[] { string.Format("PS:{0}:{1:0.00}", result.PsLine, result.Value) }));
lvRow5Back.Items[lvRow5Back.Items.Count - 1].BackColor = GetPassFailColor(result);
}
}
foreach (var control in flowLayoutPanelPositionButtons.Controls)
{
if (control is CheckBox)
{
CheckBox checkbox = (CheckBox)control;
int position = Convert.ToInt32(checkbox.Name);
int psline = 1;
var value = GetResultValueByPositionAndPsline(position, psline);
var isInTolerance = CheckIfWithinTolerance(psline,value);
if (isInTolerance)
{
checkbox.ForeColor = Color.Green;
}
else
{
checkbox.ForeColor = Color.Red;
}
checkbox.Text = String.Format("Pos:{0} {1:0.000}V", position, value);
}
}
}
public Color GetPassFailColor(Result result)
{
var isInTolerance = CheckIfWithinTolerance(result.PsLine, result.Value);
if (isInTolerance)
{
return Color.Green;
}
else
{
return Color.Red;
}
}
public bool CheckIfWithinTolerance(int psline, double value)
{
var tolerances = this.pslineConfigs.Where(x => x.Psline == psline).Select(x => x.Tolerance).ToList();
var setpoints = this.pslineConfigs.Where(x => x.Psline == psline).Select(x => x.Setpoint).ToList();
var tolerance = tolerances[0]/100;
var setpoint = setpoints[0];
var upperlimit = setpoint + (tolerance * setpoint);
var lowerlimit = setpoint - (tolerance * setpoint);
if ( value < upperlimit & value > lowerlimit)
{
return true;
}
else
{
return false;
}
}
private void btnRow1_CheckedChanged(object sender, EventArgs e)
{
List<int> buttons = new List<int> {0,1,2,3,4,5,6,7};
foreach (int button in buttons)
{
CheckBox cb = (CheckBox)flowLayoutPanelPositionButtons.Controls[button];
cb.Checked = btnRow1.Checked;
}
}
private void btnRow2_CheckedChanged(object sender, EventArgs e)
{
List<int> buttons = new List<int> { 8, 9, 10, 11, 12, 13, 14, 15 };
foreach (int button in buttons)
{
CheckBox cb = (CheckBox)flowLayoutPanelPositionButtons.Controls[button];
cb.Checked = btnRow2.Checked;
}
}
private void btnRow3_CheckedChanged(object sender, EventArgs e)
{
List<int> buttons = new List<int> { 16, 17, 18, 19, 20, 21, 22, 23 };
foreach (int button in buttons)
{
CheckBox cb = (CheckBox)flowLayoutPanelPositionButtons.Controls[button];
cb.Checked = btnRow3.Checked;
}
}
private void btnRow4_CheckedChanged(object sender, EventArgs e)
{
List<int> buttons = new List<int> { 24, 25, 26, 27, 28, 29, 30, 31 };
foreach (int button in buttons)
{
CheckBox cb = (CheckBox)flowLayoutPanelPositionButtons.Controls[button];
cb.Checked = btnRow4.Checked;
}
}
private void btnRow5_CheckedChanged(object sender, EventArgs e)
{
List<int> buttons = new List<int> { 32, 33, 34, 35, 36, 37, 38, 39 };
foreach (int button in buttons)
{
CheckBox cb = (CheckBox)flowLayoutPanelPositionButtons.Controls[button];
cb.Checked = btnRow5.Checked;
}
}
private void btnCol1_CheckedChanged(object sender, EventArgs e)
{
List<int> buttons = new List<int> { 0,8,16,24,32 };
foreach (int button in buttons)
{
CheckBox cb = (CheckBox)flowLayoutPanelPositionButtons.Controls[button];
cb.Checked = btnCol1.Checked;
}
}
private void bntCol2_CheckedChanged(object sender, EventArgs e)
{
List<int> buttons = new List<int> { 1, 9, 17, 25, 33 };
foreach (int button in buttons)
{
CheckBox cb = (CheckBox)flowLayoutPanelPositionButtons.Controls[button];
cb.Checked = bntCol2.Checked;
}
}
private void btnCol3_CheckedChanged(object sender, EventArgs e)
{
List<int> buttons = new List<int> { 2, 10, 18, 26, 34 };
foreach (int button in buttons)
{
CheckBox cb = (CheckBox)flowLayoutPanelPositionButtons.Controls[button];
cb.Checked = btnCol3.Checked;
}
}
private void btnCol4_CheckedChanged(object sender, EventArgs e)
{
List<int> buttons = new List<int> { 3, 11, 19, 27, 35 };
foreach (int button in buttons)
{
CheckBox cb = (CheckBox)flowLayoutPanelPositionButtons.Controls[button];
cb.Checked = btnCol4.Checked;
}
}
private void btnCol5_CheckedChanged(object sender, EventArgs e)
{
List<int> buttons = new List<int> { 4, 12, 20, 28, 36 };
foreach (int button in buttons)
{
CheckBox cb = (CheckBox)flowLayoutPanelPositionButtons.Controls[button];
cb.Checked = btnCol5.Checked;
}
}
private void btnCol6_CheckedChanged(object sender, EventArgs e)
{
List<int> buttons = new List<int> { 5, 13, 21, 29, 37 };
foreach (int button in buttons)
{
CheckBox cb = (CheckBox)flowLayoutPanelPositionButtons.Controls[button];
cb.Checked = btnCol6.Checked;
}
}
private void btnCol7_CheckedChanged(object sender, EventArgs e)
{
List<int> buttons = new List<int> { 6, 14, 22, 30, 38 };
foreach (int button in buttons)
{
CheckBox cb = (CheckBox)flowLayoutPanelPositionButtons.Controls[button];
cb.Checked = btnCol7.Checked;
}
}
private void btnCol8_CheckedChanged(object sender, EventArgs e)
{
List<int> buttons = new List<int> { 7, 15, 23, 31, 39 };
foreach (int button in buttons)
{
CheckBox cb = (CheckBox)flowLayoutPanelPositionButtons.Controls[button];
cb.Checked = btnCol8.Checked;
}
}
private void btnAll_CheckedChanged(object sender, EventArgs e)
{
btnRow1.Checked = btnAll.Checked;
btnRow2.Checked = btnAll.Checked;
btnRow3.Checked = btnAll.Checked;
btnRow4.Checked = btnAll.Checked;
btnRow5.Checked = btnAll.Checked;
btnCol1.Checked = btnAll.Checked;
bntCol2.Checked = btnAll.Checked;
btnCol3.Checked = btnAll.Checked;
btnCol4.Checked = btnAll.Checked;
btnCol5.Checked = btnAll.Checked;
btnCol6.Checked = btnAll.Checked;
btnCol7.Checked = btnAll.Checked;
btnCol8.Checked = btnAll.Checked;
foreach (var control in flowLayoutPanelPositionButtons.Controls)
{
if (control is CheckBox)
{
CheckBox cb = (CheckBox)control;
cb.Checked = btnAll.Checked;
}
}
}
private void lvRow1Front_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void btnSaveToExcel_Click_old(object sender, EventArgs e)
{
// Path to the desired Excel file (the file we want to check)
string filePath = string.Format(@"C:\configs\P{0}_sub{1}.xlsx", tbProjectNumber.Text, tbSub.Text);
//string filePath = @"C:\configs\" + tbProjectNumber.Text + ".xlsx";
// Path to the source file that will be copied if the target file doesn't exist
string sourceFilePath = @"C:\configs\P240262-3 RF_JESD22-6-A108 appendix.xlsx"; ;
// Check if the file exists
if (!File.Exists(filePath))
{
// If the file doesn't exist, copy the source file to the desired path
File.Copy(sourceFilePath, filePath);
Console.WriteLine($"File did not exist. Copied from {sourceFilePath} to {filePath}.");
}
else
{
Console.WriteLine("File exists, proceeding to open.");
}
// Create Excel Application instance
Excel.Application excelApp = new Excel.Application();
// Set the application to be invisible (optional)
excelApp.Visible = true;
excelApp.DisplayAlerts = false;
// Open the Excel workbook
Excel.Workbook workbook = excelApp.Workbooks.Open(filePath);
// Check if workbook "monkey" exists and open it
bool workbookFound = false;
string copiedSheetName = "";
foreach (Excel.Worksheet sheet in workbook.Sheets)
{
if (sheet.Name == "TEMPLATE")
{
Console.WriteLine("Workbook 'TEMPLATE' found. You can start editing.");
// Copy the sheet
sheet.Copy(After: workbook.Sheets[workbook.Sheets.Count]);
Excel.Worksheet copiedSheet = (Excel.Worksheet)workbook.Sheets[workbook.Sheets.Count];
copiedSheet.Name = "BIB" + workbook.Sheets.Count.ToString();
copiedSheetName = copiedSheet.Name;
Console.WriteLine("Sheet copied and renamed");
}
}
foreach (Excel.Worksheet sheet in workbook.Sheets)
{
workbookFound = true;
if (sheet.Name == copiedSheetName)
{
WriteDataToExcel(sheet,progressBar);
}
}
// Save the workbook if the sheet was found and edited
if (workbookFound)
{
workbook.Save();
Console.WriteLine("Changes saved successfully.");
MessageBox.Show("Results Saved Successfully");
}
else
{
Console.WriteLine("Workbook 'monkey' not found.");
}
// Close the workbook and quit Excel application
workbook.Close();
excelApp.Quit();
// Release COM objects to avoid memory leaks
ReleaseObject(workbook);
ReleaseObject(excelApp);
}
private bool SheetExists(Excel.Workbook workbook, string sheetName)
{
foreach (Excel.Worksheet sheet in workbook.Sheets)
{
if (sheet.Name.Equals(sheetName, StringComparison.OrdinalIgnoreCase))
{
return true;
}
}
return false;
}
private void btnSaveToExcel_Click(object sender, EventArgs e)
{
string filePath = $@"C:\configs\P{tbProjectNumber.Text}_sub{tbSub.Text}_step{tbStep.Text}.xlsx";
string sourceFilePath = $@"C:\configs\P240262-3 RF_JESD22-6-A108 appendix.xlsx";
if (!File.Exists(filePath))
{
File.Copy(sourceFilePath, filePath);
Console.WriteLine($"File did not exist. Copied from {sourceFilePath} to {filePath}.");
}
else
{
Console.WriteLine("File exists, proceeding to open.");
}
Excel.Application excelApp = new Excel.Application
{
Visible = false,
DisplayAlerts = false
};
Excel.Workbook workbook = excelApp.Workbooks.Open(filePath);
string copiedSheetName = "";
List<string> AllSheetNamesInWorkbook = new List<string>();
AllSheetNamesInWorkbook.Clear();
foreach (Excel.Worksheet sheet in workbook.Sheets)
{
AllSheetNamesInWorkbook.Add(sheet.Name);
}
foreach (Excel.Worksheet sheet in workbook.Sheets)
{
if (sheet.Name == "TEMPLATE")
{
Console.WriteLine("Workbook 'TEMPLATE' found. You can start editing.");
sheet.Copy(After: workbook.Sheets[workbook.Sheets.Count]);
Excel.Worksheet copiedSheet = (Excel.Worksheet)workbook.Sheets[workbook.Sheets.Count];
char postfix = 'A';
copiedSheetName = $@"BIB{tbBibID.Text}_{postfix}";
while (AllSheetNamesInWorkbook.Contains(copiedSheetName))
{
postfix += (char) 1;
copiedSheetName = $@"BIB{tbBibID.Text}_{postfix}";
}
copiedSheet.Name = copiedSheetName;
Console.WriteLine("Sheet copied and renamed");
/*
// Copy conditional formatting
Excel.Range sourceRange = sheet.UsedRange;
Excel.Range targetRange = copiedSheet.UsedRange;
//sourceRange.Copy();
//targetRange.PasteSpecial(Excel.XlPasteType.xlPasteFormats);
sourceRange.Copy(Type.Missing); // Still needed for PasteSpecial to work sometimes
targetRange.PasteSpecial(
Excel.XlPasteType.xlPasteFormats,
Excel.XlPasteSpecialOperation.xlPasteSpecialOperationNone,
false, false);
break;
*/
}
}
if (!string.IsNullOrEmpty(copiedSheetName))
{
Excel.Worksheet sheet = workbook.Sheets[copiedSheetName];
WriteDataToExcel(sheet,progressBar);
workbook.Save();
Console.WriteLine("Changes saved successfully.");
MessageBox.Show("Results Saved Successfully");
}
else
{
Console.WriteLine("Workbook 'TEMPLATE' not found.");
}
workbook.Close();
excelApp.Quit();
ReleaseObject(workbook);
ReleaseObject(excelApp);
}
private static long GetUnixTimestamp()
{
DateTimeOffset now = DateTimeOffset.Now;
return now.ToUnixTimeSeconds();
}
// Utility function to release COM objects
static void ReleaseObject(object obj)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
obj = null;
}
catch (Exception ex)
{
obj = null;
Console.WriteLine("Unable to release object: " + ex.ToString());
}
finally
{
GC.Collect();
}
}
public void WriteDataToExcel(Excel.Worksheet sheet, ProgressBar progressBar)
{
// Initialize the progress bar
progressBar.Minimum = 0;
progressBar.Maximum = results.Count;
progressBar.Value = 0;
progressBar.Visible = true;
foreach (var result in results)
{
//PS1
if (result.Position == 1 & result.PsLine == 1) { sheet.Cells[8, 3] = result.Value; }
if (result.Position == 2 & result.PsLine == 1) { sheet.Cells[8, 4] = result.Value; }
if (result.Position == 3 & result.PsLine == 1) { sheet.Cells[8, 5] = result.Value; }
if (result.Position == 4 & result.PsLine == 1) { sheet.Cells[8, 6] = result.Value; }
if (result.Position == 5 & result.PsLine == 1) { sheet.Cells[8, 7] = result.Value; }
if (result.Position == 6 & result.PsLine == 1) { sheet.Cells[8, 8] = result.Value; }
if (result.Position == 7 & result.PsLine == 1) { sheet.Cells[8, 9] = result.Value; }
if (result.Position == 8 & result.PsLine == 1) { sheet.Cells[8, 10] = result.Value; }
if (result.Position == 9 & result.PsLine == 1) { sheet.Cells[9, 3] = result.Value; }
if (result.Position == 10 & result.PsLine == 1) { sheet.Cells[9, 4] = result.Value; }
if (result.Position == 11 & result.PsLine == 1) { sheet.Cells[9, 5] = result.Value; }
if (result.Position == 12 & result.PsLine == 1) { sheet.Cells[9, 6] = result.Value; }
if (result.Position == 13 & result.PsLine == 1) { sheet.Cells[9, 7] = result.Value; }
if (result.Position == 14 & result.PsLine == 1) { sheet.Cells[9, 8] = result.Value; }
if (result.Position == 15 & result.PsLine == 1) { sheet.Cells[9, 9] = result.Value; }
if (result.Position == 16 & result.PsLine == 1) { sheet.Cells[9, 10] = result.Value; }
if (result.Position == 17 & result.PsLine == 1) { sheet.Cells[10, 3] = result.Value; }
if (result.Position == 18 & result.PsLine == 1) { sheet.Cells[10, 4] = result.Value; }
if (result.Position == 19 & result.PsLine == 1) { sheet.Cells[10, 5] = result.Value; }
if (result.Position == 20 & result.PsLine == 1) { sheet.Cells[10, 6] = result.Value; }
if (result.Position == 21 & result.PsLine == 1) { sheet.Cells[10, 7] = result.Value; }
if (result.Position == 22 & result.PsLine == 1) { sheet.Cells[10, 8] = result.Value; }
if (result.Position == 23 & result.PsLine == 1) { sheet.Cells[10, 9] = result.Value; }
if (result.Position == 24 & result.PsLine == 1) { sheet.Cells[10, 10] = result.Value; }
if (result.Position == 25 & result.PsLine == 1) { sheet.Cells[11, 3] = result.Value; }
if (result.Position == 26 & result.PsLine == 1) { sheet.Cells[11, 4] = result.Value; }
if (result.Position == 27 & result.PsLine == 1) { sheet.Cells[11, 5] = result.Value; }
if (result.Position == 28 & result.PsLine == 1) { sheet.Cells[11, 6] = result.Value; }
if (result.Position == 29 & result.PsLine == 1) { sheet.Cells[11, 7] = result.Value; }
if (result.Position == 30 & result.PsLine == 1) { sheet.Cells[11, 8] = result.Value; }
if (result.Position == 31 & result.PsLine == 1) { sheet.Cells[11, 9] = result.Value; }
if (result.Position == 32 & result.PsLine == 1) { sheet.Cells[11, 10] = result.Value; }
if (result.Position == 33 & result.PsLine == 1) { sheet.Cells[12, 3] = result.Value; }
if (result.Position == 34 & result.PsLine == 1) { sheet.Cells[12, 4] = result.Value; }
if (result.Position == 35 & result.PsLine == 1) { sheet.Cells[12, 5] = result.Value; }
if (result.Position == 36 & result.PsLine == 1) { sheet.Cells[12, 6] = result.Value; }
if (result.Position == 37 & result.PsLine == 1) { sheet.Cells[12, 7] = result.Value; }
if (result.Position == 38 & result.PsLine == 1) { sheet.Cells[12, 8] = result.Value; }
if (result.Position == 39 & result.PsLine == 1) { sheet.Cells[12, 9] = result.Value; }
if (result.Position == 40 & result.PsLine == 1) { sheet.Cells[12, 10] = result.Value; }
//PS2
if (result.Position == 1 & result.PsLine == 2) { sheet.Cells[8, 11] = result.Value; }
if (result.Position == 8 & result.PsLine == 2) { sheet.Cells[8, 12] = result.Value; }
if (result.Position == 9 & result.PsLine == 2) { sheet.Cells[9, 11] = result.Value; }
if (result.Position == 16 & result.PsLine == 2) { sheet.Cells[9, 12] = result.Value; }
if (result.Position == 17 & result.PsLine == 2) { sheet.Cells[10, 11] = result.Value; }
if (result.Position == 24 & result.PsLine == 2) { sheet.Cells[10, 12] = result.Value; }
if (result.Position == 25 & result.PsLine == 2) { sheet.Cells[11, 11] = result.Value; }
if (result.Position == 32 & result.PsLine == 2) { sheet.Cells[11, 12] = result.Value; }
if (result.Position == 33 & result.PsLine == 2) { sheet.Cells[12, 11] = result.Value; }
if (result.Position == 40 & result.PsLine == 2) { sheet.Cells[12, 12] = result.Value; }
//PS3
if (result.Position == 1 & result.PsLine == 3) { sheet.Cells[8, 13] = result.Value; }
if (result.Position == 8 & result.PsLine == 3) { sheet.Cells[8, 14] = result.Value; }
if (result.Position == 9 & result.PsLine == 3) { sheet.Cells[9, 13] = result.Value; }
if (result.Position == 16 & result.PsLine == 3) { sheet.Cells[9, 14] = result.Value; }
if (result.Position == 17 & result.PsLine == 3) { sheet.Cells[10, 13] = result.Value; }
if (result.Position == 24 & result.PsLine == 3) { sheet.Cells[10, 14] = result.Value; }
if (result.Position == 25 & result.PsLine == 3) { sheet.Cells[11, 13] = result.Value; }
if (result.Position == 32 & result.PsLine == 3) { sheet.Cells[11, 14] = result.Value; }
if (result.Position == 33 & result.PsLine == 3) { sheet.Cells[12, 13] = result.Value; }
if (result.Position == 40 & result.PsLine == 3) { sheet.Cells[12, 14] = result.Value; }
//PS4
if (result.Position == 1 & result.PsLine == 4) { sheet.Cells[8, 15] = result.Value; }
if (result.Position == 8 & result.PsLine == 4) { sheet.Cells[8, 16] = result.Value; }
if (result.Position == 9 & result.PsLine == 4) { sheet.Cells[9, 15] = result.Value; }
if (result.Position == 16 & result.PsLine == 4) { sheet.Cells[9, 16] = result.Value; }
if (result.Position == 17 & result.PsLine == 4) { sheet.Cells[10, 15] = result.Value; }
if (result.Position == 24 & result.PsLine == 4) { sheet.Cells[10, 16] = result.Value; }
if (result.Position == 25 & result.PsLine == 4) { sheet.Cells[11, 15] = result.Value; }
if (result.Position == 32 & result.PsLine == 4) { sheet.Cells[11, 16] = result.Value; }
if (result.Position == 33 & result.PsLine == 4) { sheet.Cells[12, 15] = result.Value; }
if (result.Position == 40 & result.PsLine == 4) { sheet.Cells[12, 16] = result.Value; }
//PS5
if (result.Position == 1 & result.PsLine == 5) { sheet.Cells[8, 17] = result.Value; }
if (result.Position == 8 & result.PsLine == 5) { sheet.Cells[8, 18] = result.Value; }
if (result.Position == 9 & result.PsLine == 5) { sheet.Cells[9, 17] = result.Value; }
if (result.Position == 16 & result.PsLine == 5) { sheet.Cells[9, 18] = result.Value; }
if (result.Position == 17 & result.PsLine == 5) { sheet.Cells[10, 17] = result.Value; }
if (result.Position == 24 & result.PsLine == 5) { sheet.Cells[10, 18] = result.Value; }
if (result.Position == 25 & result.PsLine == 5) { sheet.Cells[11, 17] = result.Value; }
if (result.Position == 32 & result.PsLine == 5) { sheet.Cells[11, 18] = result.Value; }
if (result.Position == 33 & result.PsLine == 5) { sheet.Cells[12, 17] = result.Value; }
if (result.Position == 40 & result.PsLine == 5) { sheet.Cells[12, 18] = result.Value; }
//PS6
if (result.Position == 1 & result.PsLine == 6) { sheet.Cells[26, 3] = result.Value; }
if (result.Position == 8 & result.PsLine == 6) { sheet.Cells[26, 4] = result.Value; }
if (result.Position == 9 & result.PsLine == 6) { sheet.Cells[27, 3] = result.Value; }
if (result.Position == 16 & result.PsLine == 6) { sheet.Cells[27, 4] = result.Value; }
if (result.Position == 17 & result.PsLine == 6) { sheet.Cells[28, 3] = result.Value; }
if (result.Position == 24 & result.PsLine == 6) { sheet.Cells[28, 4] = result.Value; }
if (result.Position == 25 & result.PsLine == 6) { sheet.Cells[29, 3] = result.Value; }
if (result.Position == 32 & result.PsLine == 6) { sheet.Cells[29, 4] = result.Value; }
if (result.Position == 33 & result.PsLine == 6) { sheet.Cells[30, 3] = result.Value; }
if (result.Position == 40 & result.PsLine == 6) { sheet.Cells[30, 4] = result.Value; }
//PS7
if (result.Position == 1 & result.PsLine == 7) { sheet.Cells[26, 5] = result.Value; }
if (result.Position == 8 & result.PsLine == 7) { sheet.Cells[26, 6] = result.Value; }
if (result.Position == 9 & result.PsLine == 7) { sheet.Cells[27, 5] = result.Value; }
if (result.Position == 16 & result.PsLine == 7) { sheet.Cells[27, 6] = result.Value; }
if (result.Position == 17 & result.PsLine == 7) { sheet.Cells[28, 5] = result.Value; }
if (result.Position == 24 & result.PsLine == 7) { sheet.Cells[28, 6] = result.Value; }
if (result.Position == 25 & result.PsLine == 7) { sheet.Cells[29, 5] = result.Value; }
if (result.Position == 32 & result.PsLine == 7) { sheet.Cells[29, 6] = result.Value; }
if (result.Position == 33 & result.PsLine == 7) { sheet.Cells[30, 5] = result.Value; }
if (result.Position == 40 & result.PsLine == 7) { sheet.Cells[30, 6] = result.Value; }
//PS8
if (result.Position == 1 & result.PsLine == 8) { sheet.Cells[26, 7] = result.Value; }
if (result.Position == 8 & result.PsLine == 8) { sheet.Cells[26, 8] = result.Value; }
if (result.Position == 9 & result.PsLine == 8) { sheet.Cells[27, 7] = result.Value; }
if (result.Position == 16 & result.PsLine == 8) { sheet.Cells[27, 8] = result.Value; }
if (result.Position == 17 & result.PsLine == 8) { sheet.Cells[28, 7] = result.Value; }
if (result.Position == 24 & result.PsLine == 8) { sheet.Cells[28, 8] = result.Value; }
if (result.Position == 25 & result.PsLine == 8) { sheet.Cells[29, 7] = result.Value; }
if (result.Position == 32 & result.PsLine == 8) { sheet.Cells[29, 8] = result.Value; }
if (result.Position == 33 & result.PsLine == 8) { sheet.Cells[30, 7] = result.Value; }
if (result.Position == 40 & result.PsLine == 8) { sheet.Cells[30, 8] = result.Value; }
//PS9
if (result.Position == 1 & result.PsLine == 9) { sheet.Cells[26, 9] = result.Value; }
if (result.Position == 8 & result.PsLine == 9) { sheet.Cells[26, 10] = result.Value; }
if (result.Position == 9 & result.PsLine == 9) { sheet.Cells[27, 9] = result.Value; }
if (result.Position == 16 & result.PsLine == 9) { sheet.Cells[27, 10] = result.Value; }
if (result.Position == 17 & result.PsLine == 9) { sheet.Cells[28, 9] = result.Value; }
if (result.Position == 24 & result.PsLine == 9) { sheet.Cells[28, 10] = result.Value; }
if (result.Position == 25 & result.PsLine == 9) { sheet.Cells[29, 9] = result.Value; }
if (result.Position == 32 & result.PsLine == 9) { sheet.Cells[29, 10] = result.Value; }
if (result.Position == 33 & result.PsLine == 9) { sheet.Cells[30, 9] = result.Value; }
if (result.Position == 40 & result.PsLine == 9) { sheet.Cells[30, 10] = result.Value; }
//PS10
if (result.Position == 1 & result.PsLine == 10) { sheet.Cells[26, 11] = result.Value; }
if (result.Position == 8 & result.PsLine == 10) { sheet.Cells[26, 12] = result.Value; }
if (result.Position == 9 & result.PsLine == 10) { sheet.Cells[27, 11] = result.Value; }
if (result.Position == 16 & result.PsLine == 10) { sheet.Cells[27, 12] = result.Value; }
if (result.Position == 17 & result.PsLine == 10) { sheet.Cells[28, 11] = result.Value; }
if (result.Position == 24 & result.PsLine == 10) { sheet.Cells[28, 12] = result.Value; }
if (result.Position == 25 & result.PsLine == 10) { sheet.Cells[29, 11] = result.Value; }
if (result.Position == 32 & result.PsLine == 10) { sheet.Cells[29, 12] = result.Value; }
if (result.Position == 33 & result.PsLine == 10) { sheet.Cells[30, 11] = result.Value; }
if (result.Position == 40 & result.PsLine == 10) { sheet.Cells[30, 12] = result.Value; }
// Update the progress bar
progressBar.Value++;
}
sheet.Unprotect();
WritePsuConfigData(sheet);
WriteStaticData(sheet);
progressBar.Visible = false;
}
private void WriteStaticData(Excel.Worksheet sheet)
{
sheet.Cells[57, 17] = DateTime.UtcNow.ToString();
sheet.Cells[58, 17] = DataloggerSerial;
sheet.Cells[59, 17] = tbProjectNumber.Text;
sheet.Cells[60, 17] = tbBibID.Text;
sheet.Cells[61, 17] = tbDriverID.Text;
sheet.Cells[62, 17] = lbLocation.SelectedItem.ToString();
}
private void WritePsuConfigData(Excel.Worksheet sheet)
{
foreach (var psuline in pslineConfigs)
{
switch (psuline.Psline)
{
case 1:
sheet.Cells[5, 3] = psuline.Description;
sheet.Cells[6, 3] = psuline.Setpoint;
sheet.Cells[7, 3] = psuline.Tolerance/100;
break;
case 2:
sheet.Cells[5, 11] = psuline.Description;
sheet.Cells[6, 11] = psuline.Setpoint;
sheet.Cells[7, 11] = psuline.Tolerance/100;
break;
case 3:
sheet.Cells[5, 13] = psuline.Description;
sheet.Cells[6, 13] = psuline.Setpoint;
sheet.Cells[7, 13] = psuline.Tolerance/100;
break;
case 4:
sheet.Cells[5, 15] = psuline.Description;
sheet.Cells[6, 15] = psuline.Setpoint;
sheet.Cells[7, 15] = psuline.Tolerance/100;
break;
case 5:
sheet.Cells[5, 17] = psuline.Description;
sheet.Cells[6, 17] = psuline.Setpoint;
sheet.Cells[7, 17] = psuline.Tolerance/100;
break;
case 6:
sheet.Cells[23, 3] = psuline.Description;
sheet.Cells[24, 3] = psuline.Setpoint;
sheet.Cells[25, 3] = psuline.Tolerance/100;
break;
case 7:
sheet.Cells[23, 5] = psuline.Description;
sheet.Cells[24, 5] = psuline.Setpoint;
sheet.Cells[25, 5] = psuline.Tolerance/100;
break;
case 8:
sheet.Cells[23, 7] = psuline.Description;
sheet.Cells[24, 7] = psuline.Setpoint;
sheet.Cells[25, 7] = psuline.Tolerance/100;
break;
case 9:
sheet.Cells[23, 9] = psuline.Description;
sheet.Cells[24, 9] = psuline.Setpoint;
sheet.Cells[25, 9] = psuline.Tolerance/100;
break;
case 10:
sheet.Cells[23, 11] = psuline.Description;
sheet.Cells[24, 11] = psuline.Setpoint;
sheet.Cells[25, 11] = psuline.Tolerance/100;
break;
case 11:
sheet.Cells[23, 13] = psuline.Description;
sheet.Cells[24, 13] = psuline.Setpoint;
sheet.Cells[25, 13] = psuline.Tolerance/100;
break;
case 12:
sheet.Cells[23, 15] = psuline.Description;
sheet.Cells[24, 15] = psuline.Setpoint;
sheet.Cells[25, 15] = psuline.Tolerance/100;
break;
default:
break;
}
}
}
private void button1_Click(object sender, EventArgs e)
{
OnClearAllMeasurementsBtnClick(EventArgs.Empty);
}
private void btnMeasure_Click_1(object sender, EventArgs e)
{
UpdatePositionList();
OnMeasureButtonClick(EventArgs.Empty);
}
private void UserControlMeasure_Load(object sender, EventArgs e)
{
}
}
}