using System.Collections.Generic;
using System.Windows.Forms;
namespace FileComparisonApp
public partial class ComparisonForm : Form
private Record testRecord;
private List<Record> productionRecords;
public ComparisonForm(Record testRecord, List<Record> productionRecords)
this.testRecord = testRecord;
this.productionRecords = productionRecords;
private void InitializeUI()
Text = "Comparison Window";
Size = new Size(500, 300);
StartPosition = FormStartPosition.CenterScreen;
Label lblTest = new Label { Text = "Test Record", Location = new Point(10, 10), AutoSize = true };
Label lblProduction = new Label { Text = "Production Record", Location = new Point(250, 10), AutoSize = true };
ListView listView = new ListView
Location = new Point(10, 40),
Size = new Size(460, 200),
listView.Columns.Add("Property", 150);
listView.Columns.Add("Test Value", 150);
listView.Columns.Add("Production Value", 150);
Controls.Add(lblProduction);
CompareRecords(listView);
private void CompareRecords(ListView listView)
var matchingRecord = productionRecords.FirstOrDefault(r => r.Pan == testRecord.Pan);
if (matchingRecord != null)
AddComparisonRow(listView, "Pan", testRecord.Pan, matchingRecord.Pan);
AddComparisonRow(listView, "Property1", testRecord.Property1, matchingRecord.Property1);
AddComparisonRow(listView, "Property2", testRecord.Property2, matchingRecord.Property2);
MessageBox.Show("No matching record found in Production file.");
private void AddComparisonRow(ListView listView, string property, string testValue, string prodValue)
var item = new ListViewItem(property);
item.SubItems.Add(testValue);
item.SubItems.Add(prodValue);
if (testValue != prodValue)
item.UseItemStyleForSubItems = false;
item.SubItems[1].ForeColor = Color.Red;
item.SubItems[2].ForeColor = Color.Red;
listView.Items.Add(item);
namespace FileComparisonApp
public partial class MainForm : Form
private List<string> testRecords = new List<string>();
private List<Record> productionRecords = new List<Record>();
private void InitializeUI()
Button btnLoadTest = new Button { Text = "Load Test File", Location = new System.Drawing.Point(10, 10), Width = 150 };
Button btnLoadProduction = new Button { Text = "Load Production File", Location = new System.Drawing.Point(180, 10), Width = 150 };
ListBox lstTestRecords = new ListBox { Location = new System.Drawing.Point(10, 50), Size = new System.Drawing.Size(320, 200) };
btnLoadTest.Click += (sender, e) => LoadTestFile(lstTestRecords);
btnLoadProduction.Click += (sender, e) => LoadProductionFile();
lstTestRecords.DoubleClick += (sender, e) => OpenComparisonWindow(lstTestRecords);
Controls.Add(btnLoadTest);
Controls.Add(btnLoadProduction);
Controls.Add(lstTestRecords);
Text = "File Comparison App";
Size = new System.Drawing.Size(360, 300);
StartPosition = FormStartPosition.CenterScreen;
private void LoadTestFile(ListBox listBox)
OpenFileDialog openFileDialog = new OpenFileDialog
Filter = "Text Files (*.txt)|*.txt",
if (openFileDialog.ShowDialog() == DialogResult.OK)
testRecords = File.ReadAllLines(openFileDialog.FileName).ToList();
listBox.Items.AddRange(testRecords.ToArray());
private void LoadProductionFile()
OpenFileDialog openFileDialog = new OpenFileDialog
Filter = "Text Files (*.txt)|*.txt",
Title = "Load Production File"
if (openFileDialog.ShowDialog() == DialogResult.OK)
productionRecords = File.ReadAllLines(openFileDialog.FileName)
.Select(line => Record.Parse(line))
private void OpenComparisonWindow(ListBox listBox)
if (listBox.SelectedItem != null && productionRecords.Any())
string selectedTestRecord = listBox.SelectedItem.ToString();
Record testRecord = Record.Parse(selectedTestRecord);
ComparisonForm comparisonForm = new ComparisonForm(testRecord, productionRecords);
comparisonForm.ShowDialog();
MessageBox.Show("Please load both files and select a record to compare.");
public string Pan { get; set; }
public string Property1 { get; set; }
public string Property2 { get; set; }
public static Record Parse(string line)
var parts = line.Split(',');
Property1 = parts.Length > 1 ? parts[1] : string.Empty,
Property2 = parts.Length > 2 ? parts[2] : string.Empty