Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using Microsoft.VisualBasic;
- namespace LogRead {
- public struct logUser {
- public string IP;
- public DateTime date;
- public logUser( logUser data) : this() {
- this.date = data.date;
- this.IP = data.IP;
- }
- }
- public struct user {
- public string name;
- public System.Collections.Generic.List<logUser> logUserList;
- }
- public partial class Form1 : Form {
- public List<user> usersList = new System.Collections.Generic.List<user>();
- public logUser cUser = new logUser();
- public user us = new user();
- public Form1() {
- InitializeComponent();
- usersList.Clear();
- }
- private void openFileButton_Click(object sender, EventArgs e) {
- openFileDialog.ShowDialog();
- filePath.Text = openFileDialog.FileName;
- }
- private void button1_Click(object sender, EventArgs e) {
- if( File.Exists(filePath.Text.ToString())) {
- StreamReader file = new StreamReader(filePath.Text.ToString());
- string line = "";
- string cName = "";
- int curUserNum;
- int lastIndex = 0;
- int state = 0;
- //progressBar1.Maximum = File.ReadAllLines("file.txt").Length;
- while ((line = file.ReadLine()) != null) {
- switch (state) {
- case 0:
- if (line.LastIndexOf("Сведения ") != -1) {
- cUser.date = DateTime.Parse(line.Substring(lastIndex + 9, 17));
- state = 1;
- //cUser.date = DateTime.ParseExact(line.Substring(lastIndex + 9, 17), format, System.Globalization.CultureInfo.InvariantCulture);
- }; break;
- case 1:
- if (line.LastIndexOf("/Пользователь: ") != -1) {
- cName = line.Substring("/Пользователь: ".Length - 1, line.Length - "/Пользователь: ".Length);
- state = 2;
- }; break;
- case 2:
- if (line.LastIndexOf("Адрес сети источника: ") != -1) {
- cUser.IP = line.Substring("Адрес сети источника: ".Length - 1, line.Length - "Адрес сети источника: ".Length);
- state = 0;
- curUserNum = -1;
- for(int i = 0; i < usersList.Count && curUserNum == -1; i++) {
- if( usersList[i].name == cName) {
- curUserNum = i;
- };
- };
- if( curUserNum == -1) {
- us.name = cName;
- us.logUserList = null;
- usersList.Add(us);
- //usersList.Add(new user());
- curUserNum = 0;
- }
- //usersList[curUserNum].name = cName;
- usersList[curUserNum].logUserList.Add(cUser);
- };
- break;
- default: break;
- };
- progressBar1.PerformStep();
- }
- if (usersList.Count != 0) {
- comboBox1.Items.Clear();
- for (int i = 0; i != usersList.Count; i++) {
- comboBox1.Items.Add(usersList[i].name);
- };
- this.SetClientSizeCore(348, 470);
- }else {
- MessageBox.Show("Результат чтения", "Результатов не найдено", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- else {
- MessageBox.Show("Файл не существует","Проверка наличия файла в системе", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- private void Form1_Load(object sender, EventArgs e) {
- this.SetClientSizeCore(348, 100);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement