Hello. I have a job to do. It consists in loading the file in C # (I have 3 datasets), changing symbols, for example, a, b, c to numbers from 1 to 3. Find the smallest and largest value in the columns. I have to load the file into windows form (I have to do gui). Reading in by pressing the button.
What I have tried:
I sit on it for 3 days and I haven't come up with anything. I just have something like this. I know how to check the maximum value for only one column. I don't know how to convert symbols to numbers. In another file there are a, b, c etc. And the size of the cells differs. I don't know how to do it automatically either.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Data.OleDb;
using System.Text.RegularExpressions;
namespace testtabele
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
DataTable table = new DataTable();
private void Form1_Load(object sender, EventArgs e)
{
table.Columns.Add("A1", typeof(string));
table.Columns.Add("A2", typeof(string));
table.Columns.Add("A3", typeof(string));
table.Columns.Add("A4", typeof(string));
table.Columns.Add("A5", typeof(string));
table.Columns.Add("A6", typeof(string));
table.Columns.Add("A7", typeof(string));
table.Columns.Add("A8", typeof(string));
table.Columns.Add("A9", typeof(string));
table.Columns.Add("A10", typeof(string));
table.Columns.Add("A11", typeof(string));
table.Columns.Add("A12", typeof(string));
table.Columns.Add("A13", typeof(string));
table.Columns.Add("A14", typeof(string));
table.Columns.Add("A15", typeof(string));
table.Columns.Add("A16", typeof(string));
table.Columns.Add("A17", typeof(string));
dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = table;
}
private void button1_Click(object sender, EventArgs e)
{
string[] lines = File.ReadAllLines(@"C:\australian.dat");
string[] values;
for (int i = 0; i < lines.Length; i++)
{
values = lines[i].ToString().Split(' ', ',');
string[] row = new string[values.Length];
for (int j = 0; j < values.Length; j++)
{
row[j] = values[j].Trim();
}
table.Rows.Add(row);
}
double max = 0;
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (max < double.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString().Replace(".", ",")))
{
max = double.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString().Replace(".", ","));
textBox1.Text = max.ToString();
}
}
double min = 0;
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (i == 0)
{
min = double.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString().Replace(".", ","));
}
if (min > double.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString().Replace(".", ",")))
{
min = double.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString().Replace(".", ","));
}
}
textBox2.Text = min.ToString();
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
}
}
}