0
私は構造化されたファイルを持っています。 アプリケーションでは、2つの読み込み2つのファイルがあり、両方のファイルで同じ最初の2つの要素を比較します。 最初の要素と2番目の要素であるcombobox1とcombobox2を同じロードする場合。 2番目のコンボボックスで、それぞれの年を選択すると、選択された4番目の要素が読み込まれますか? 各行の4番目から最後の要素は1月から12月の月、3番目の要素は1から31の月の日です。 選択した年の各月のデータを読み込む方法コンボボックスから?.CSVファイルのフィルタ読み込み行を行うにはどうすればよいですか?C#
18050,1976,1,0.390,0.660,0.290,0.740,9.160,1.400,0.670,3.120,0.460,0.420,0.360,0.400,
18050,1976,2,0.390,0.520,0.290,0.740,7.540,1.270,0.670,2.660,0.460,0.420,0.360,0.380,
18050,1976,3,0.390,0.450,0.240,0.660,5.260,1.270,0.670,2.510,0.460,0.420,0.410,0.400,
18050,1976,4,0.390,0.450,0.240,0.660,4.400,1.180,0.620,2.360,0.460,0.410,0.400,0.440,
18050,1976,5,0.390,0.450,0.290,0.660,4.220,1.080,0.620,2.360,0.460,0.410,0.400,4.750,
18050,1976,6,0.520,0.390,0.240,0.580,4.040,1.270,0.620,4.200,0.460,0.410,0.380,2.810,
18050,1976,7,0.390,0.390,0.240,0.520,3.680,37.800,0.620,5.870,0.460,0.400,0.360,1.620,
18050,1976,8,0.390,0.390,0.200,0.580,3.330,22.900,0.580,4.570,0.460,0.380,0.360,0.980,
18050,1976,9,0.390,0.390,0.200,0.660,2.830,11.200,0.580,4.020,0.460,0.360,0.360,0.740,
18050,1976,10,0.390,0.340,0.200,1.380,2.650,8.120,0.580,3.660,0.440,0.360,0.360,0.520,
18050,1976,11,0.340,0.390,0.200,2.260,2.350,5.870,0.580,3.270,0.440,0.360,0.360,0.460,
18050,1976,12,0.340,0.450,0.200,1.700,2.350,4.750,0.580,4.570,0.440,0.360,0.360,0.460,
18050,1976,13,0.340,0.390,0.200,1.590,2.350,3.840,0.540,4.020,0.440,0.340,0.360,0.440,
18050,1976,14,0.340,0.390,0.290,2.120,2.200,3.120,0.540,3.660,0.420,0.340,0.340,0.520,
18050,1976,15,0.290,0.390,0.290,2.400,2.050,2.970,0.540,3.270,0.420,0.400,0.340,0.520,
18050,1976,16,0.290,0.390,0.240,1.590,1.770,2.810,0.540,2.970,0.420,0.360,0.340,0.440,
18050,1976,17,0.290,0.340,0.290,1.170,1.520,2.660,0.540,2.660,0.410,0.360,0.330,0.420,
18050,1976,18,0.290,0.340,0.290,1.170,1.270,2.360,0.540,2.210,0.410,0.410,0.340,0.420,
18050,1976,19,0.240,0.340,0.390,1.170,1.080,2.210,0.540,2.060,0.410,0.410,0.400,0.410,
18050,1976,20,0.290,0.340,0.390,1.010,1.080,2.060,0.520,1.760,0.400,0.400,1.340,0.400,
18050,1976,21,0.290,0.290,0.390,0.920,1.270,1.760,0.520,1.200,0.740,0.400,2.660,0.400,
18050,1976,22,0.340,0.290,0.450,0.820,2.860,1.480,0.520,1.080,0.580,0.380,1.760,0.400,
18050,1976,23,0.340,0.290,0.520,0.740,3.050,1.200,0.520,0.980,0.580,0.380,0.980,0.400,
18050,1976,24,0.340,0.290,0.520,0.660,4.000,0.980,0.540,0.810,0.540,0.380,0.520,0.380,
18050,1976,25,0.340,0.290,0.920,0.740,2.680,0.890,2.810,0.670,0.520,0.360,0.460,0.380,
18050,1976,26,0.390,0.290,1.380,1.380,2.060,0.810,2.510,0.580,0.520,0.360,0.440,0.380,
18050,1976,27,0.740,0.290,1.490,2.570,1.770,0.810,2.510,0.580,0.490,0.360,0.420,0.380,
18050,1976,28,1.280,0.290,1.380,2.730,1.770,0.740,4.750,0.520,0.460,0.360,0.410,0.360,
18050,1976,29,1.010,0.290,1.090,3.610,1.650,0.740,5.480,0.520,0.420,0.360,0.410,0.360,
18050,1976,30,0.820,,0.820,4.000,1.520,0.670,4.210,0.490,0.420,0.360,0.400,0.360,
18050,1976,31,0.660,,0.740,,1.520,,3.660,0.460,,0.360,,0.440,
マイコード:私は半時間、この問題を見てきたと私はまだあなたが達成したいのか分からない
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;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
label3.Hide();
label4.Hide();
}
string pathFolder;
string pathFolder2;
string resultStation;
string resultStation2;
List<string> resultYears = new List<string>();
List<string> resultYears2 = new List<string>();
private void button1_Click(object sender, EventArgs e)
{
using (OpenFileDialog dialog = new OpenFileDialog())
{
if (dialog.ShowDialog(this) == DialogResult.OK)
{
string sFileName = dialog.FileName;
pathFolder = sFileName;
label3.Text = pathFolder;
label3.Show();
string[] lines = System.IO.File.ReadAllLines(dialog.FileName);
int i = 0;
foreach (var line in lines)
{
var splittedValues = line.Split(',');
var firstWord = splittedValues[0];
var firstYear = splittedValues[1];
// var JanuaryFirst = splittedValues[3];
// var lastJanuary = File.ReadLines(pathFolder).Last();
// var JanuaryLast = lastJanuary[3];
if (!resultYears.Contains(firstYear))
{
resultYears.Add(firstYear);
}
if (i == 0)
{
resultStation = firstWord;
}
else
{
if (resultStation != firstWord)
{
MessageBox.Show("Файла с дневни данни трябва да съдържа само една станция!");
return;
}
}
i++;
}
resultYears.Sort();
}
}
}
private void button2_Click(object sender, EventArgs e)
{
using (OpenFileDialog dialog = new OpenFileDialog())
{
if (dialog.ShowDialog(this) == DialogResult.OK)
{
string sFileName = dialog.FileName;
pathFolder2 = sFileName;
label4.Text = pathFolder2;
label4.Show();
string[] lines = System.IO.File.ReadAllLines(dialog.FileName);
int i = 0;
foreach (var line in lines)
{
var splittedValues = line.Split(',');
var firstWord = splittedValues[0];
var firstYear2 = splittedValues[1];
if (!resultYears2.Contains(firstYear2))
{
resultYears2.Add(firstYear2);
}
if (i == 0)
{
resultStation2 = firstWord;
}
else
{
if (resultStation2 != firstWord)
{
MessageBox.Show("Файла с месечни данни трябва съдържа само една станция!");
return;
}
}
i++;
}
resultYears2.Sort();
}
}
}
public void label3_Click(object sender, EventArgs e)
{
}
public void label4_Click(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
if (resultStation != resultStation2)
{
MessageBox.Show("Номера на станцията в единия файл не отговаря на номера на станцията в другият файл!" + Environment.NewLine + Environment.NewLine +
"ЗАБЕЛЕЖКА!" + Environment.NewLine + Environment.NewLine + "В двата файла, номера на станцията трябва да бъде един и същ!");
}
comboBox1.Items.Add(resultStation);
if (string.Join(", ", resultYears) == string.Join(", ", resultYears2))
//if (resultYears.Equals(resultYears2))
{
for (int i = 0; i < this.resultYears.Count; i++)
{
comboBox2.Items.Add(resultYears[i]);
}
}
else
{
MessageBox.Show("Годините от двата файла не съвпадат.");
}
}
}
}
おそらく、そのデータをよりクエリ可能な形式に解析します。 JSONを使用するか、データベースを使用する場合はデータベースにインポートします。 –
ファイルの大きさはどれくらいですか?一度にメモリに読み込むことはできますか? – trailmax
はい、私はすべてのオプションを受け入れます...しかし、あなたは私にこの怪物を読むことができますか? –