Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- #!/usr/bin/mcs -r:System.Windows.Forms.dll -r:System.Drawing.dll
- set path=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Roslyn\;%path%
- csc.exe -debug+ -target:winexe -r:System.Windows.Forms.dll -r:System.Drawing.dll c#_winforms_base.cs
- */
- using System;
- using System.Windows.Forms;
- using System.Drawing;
- using System.Data;
- using System.Collections.Generic; // for List()
- using System.Text;
- using System.Text.RegularExpressions;
- using System.IO;
- //using System.Text.RegularExpressions;
- public class Program
- {
- static MenuStrip strip = new MenuStrip();
- static StatusStrip statusStrip = new StatusStrip();
- static ToolStripStatusLabel statusLabel = new ToolStripStatusLabel();
- static ToolStripComboBox separator = new ToolStripComboBox();
- static ToolStripTextBox filter = new ToolStripTextBox();
- static DataGridView dataGridView = new DataGridView();
- [STAThread]
- public static void Main()
- {
- try
- {
- var f = new Form();
- f.Text = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
- f.Size = new Size(500, 400);
- ToolStripMenuItem fileItem = new ToolStripMenuItem("&Fájl");
- var openFileMenuItem = fileItem.DropDownItems.Add("&Megnyitás");
- openFileMenuItem.Click += new EventHandler (Open);
- var saveFileMenuItem = fileItem.DropDownItems.Add("M&entés");
- saveFileMenuItem.Enabled = false;
- // username.Click += (s, e) => SomeTextBox.Text = "...";
- var quitMenuItem = fileItem.DropDownItems.Add("&Kilépés");
- quitMenuItem.Click += new EventHandler ( Exit );
- strip.Items.Add(fileItem);
- separator.Items.AddRange( new object[] { ",", ";"} );
- separator.Text = ";";
- separator.Width = 30;
- strip.Items.AddRange( new ToolStripItem[] { separator });
- filter.Text = ".*";
- strip.Items.AddRange( new ToolStripItem[] { filter });
- f.Controls.Add(strip);
- statusStrip.Items.AddRange(new ToolStripItem[] {statusLabel});
- statusStrip.LayoutStyle = ToolStripLayoutStyle.HorizontalStackWithOverflow;
- f.Controls.Add(statusStrip);
- dataGridView.Location = new Point(5, 30);
- dataGridView.Size = new Size(f.Width-25, f.Height-95);
- dataGridView.Anchor = ( AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right );
- dataGridView.ReadOnly = true;
- dataGridView.MultiSelect = true;
- dataGridView.AllowUserToAddRows = false;
- dataGridView.AutoResizeColumns();
- dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
- f.Controls.Add(dataGridView);
- //dataGridView.Dock = DockStyle.Fill; // Ez valószínűleg csak MainMenu tipus esetén működik.
- Application.Run(f);
- }
- catch (Exception e)
- {
- statusLabel.Text = e.Message;
- }
- }
- static private void Exit (object sender, EventArgs e)
- {
- Application.Exit();
- }
- static private void Open (object sender, EventArgs e)
- {
- OpenFileDialog openDialog = new OpenFileDialog();
- openDialog.Title = "Select A File";
- openDialog.Filter = "Text Files (*.csv)|*.csv" + "|" +
- "All Files (*.*)|*.*";
- openDialog.InitialDirectory = Environment.CurrentDirectory;
- if ( openDialog.ShowDialog() == DialogResult.OK )
- {
- statusLabel.Text = openDialog.FileName;
- try
- {
- //dataGridView.AutoGenerateColumns = false;
- dataGridView.DataSource = null;
- //dataTable.Clear();
- //dataTable.Reset();
- DataTable dataTable = new DataTable();
- string s = "";
- ulong i = 0;
- var regexp = new Regex(filter.Text);
- using (StreamReader sr = new StreamReader(statusLabel.Text,Encoding.GetEncoding("Windows-1250"),false,64*1024*1024)) // .NET 5-től nem jó
- //using (StreamReader sr = new StreamReader(statusLabel.Text,Encoding.GetEncoding("UTF-8"),false,64*1024*1024)) //
- // using (StreamReader sr = new StreamReader(statusLabel.Text, Encoding.UTF8, false, 64 * 1024 * 1024)) // .NET5
- {
- s = String.Empty;
- while ((s = sr.ReadLine()) != null)
- {
- if ( i++ == 0 )
- {
- foreach ( var data in s.Split(separator.Text[0]) )
- {
- dataTable.Columns.Add(data,typeof(string));
- }
- }
- else
- {
- if ( regexp.Match(s).Success )
- dataTable.Rows.Add(s.Split(separator.Text[0]));
- }
- statusLabel.Text = i.ToString();
- statusStrip.Update();
- }
- }
- dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None; // Enélkül folyamatosan újraszámol, igazítja a cellákat, ami sokszorosára növeli az időigényt.
- dataGridView.DataSource = dataTable;
- foreach (DataGridViewRow dgrow in dataGridView.Rows)
- {
- dgrow.HeaderCell.Value = String.Format("{0}", dgrow.Index + 1);
- dgrow.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
- }
- dataGridView.AutoResizeRowHeadersWidth( DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders );
- dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
- //dataGridView.Update();
- //dataGridView.Refresh();
- statusLabel.Text = dataTable.Rows.Count.ToString();
- //DateTime.Now.ToString("h:mm:ss tt");
- }
- catch (Exception e2)
- {
- //System.Diagnostics.Debug.WriteLine(e2.Message);
- statusLabel.Text = e2.Message;
- statusStrip.Update();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement