Advertisement
Guest User

С 83 строки трабл

a guest
Feb 25th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using Microsoft.VisualBasic;
  12.  
  13. namespace LogRead {
  14.  
  15.     public struct logUser {
  16.         public string IP;
  17.         public DateTime date;
  18.         public logUser( logUser data) : this() {
  19.             this.date = data.date;
  20.             this.IP = data.IP;
  21.         }
  22.     }
  23.  
  24.     public struct user {
  25.         public string name;
  26.         public System.Collections.Generic.List<logUser> logUserList;
  27.     }
  28.  
  29.     public partial class Form1 : Form {
  30.  
  31.         public List<user> usersList = new System.Collections.Generic.List<user>();
  32.         public logUser cUser = new logUser();
  33.         public user us = new user();
  34.  
  35.         public Form1() {
  36.                    
  37.             InitializeComponent();
  38.  
  39.             usersList.Clear();
  40.         }
  41.  
  42.         private void openFileButton_Click(object sender, EventArgs e) {
  43.             openFileDialog.ShowDialog();
  44.             filePath.Text = openFileDialog.FileName;
  45.         }
  46.  
  47.         private void button1_Click(object sender, EventArgs e) {
  48.             if( File.Exists(filePath.Text.ToString())) {
  49.                 StreamReader file = new StreamReader(filePath.Text.ToString());
  50.                 string line = "";
  51.                 string cName = "";
  52.                 int curUserNum;
  53.                 int lastIndex = 0;
  54.                 int state = 0;
  55.  
  56.                 //progressBar1.Maximum = File.ReadAllLines("file.txt").Length;
  57.                 while ((line = file.ReadLine()) != null) {
  58.                     switch (state) {
  59.                         case 0:
  60.                             if (line.LastIndexOf("Сведения  ") != -1) {
  61.                                 cUser.date = DateTime.Parse(line.Substring(lastIndex + 9, 17));
  62.                                 state = 1;
  63.                                 //cUser.date = DateTime.ParseExact(line.Substring(lastIndex + 9, 17), format, System.Globalization.CultureInfo.InvariantCulture);
  64.                             }; break;
  65.                         case 1:
  66.                             if (line.LastIndexOf("/Пользователь: ") != -1) {
  67.                                 cName = line.Substring("/Пользователь: ".Length - 1, line.Length - "/Пользователь: ".Length);
  68.                                 state = 2;
  69.                             }; break;
  70.                         case 2:
  71.                             if (line.LastIndexOf("Адрес сети источника: ") != -1) {
  72.                                 cUser.IP = line.Substring("Адрес сети источника: ".Length - 1, line.Length - "Адрес сети источника: ".Length);
  73.                                 state = 0;
  74.                                 curUserNum = -1;
  75.                                 for(int i = 0; i < usersList.Count && curUserNum == -1; i++) {
  76.                                     if( usersList[i].name == cName) {
  77.                                         curUserNum = i;
  78.                                     };
  79.                                 };
  80.                                 if( curUserNum == -1) {
  81.                                     us.name = cName;
  82.                                     us.logUserList = null;
  83.                                     usersList.Add(us);
  84.                                     //usersList.Add(new user());
  85.                                     curUserNum = 0;
  86.                                 }
  87.                                 //usersList[curUserNum].name = cName;
  88.                                 usersList[curUserNum].logUserList.Add(cUser);
  89.                             };
  90.                             break;
  91.                         default: break;
  92.                     };
  93.                     progressBar1.PerformStep();              
  94.                 }
  95.                 if (usersList.Count != 0) {
  96.                     comboBox1.Items.Clear();
  97.                     for (int i = 0; i != usersList.Count; i++) {
  98.                         comboBox1.Items.Add(usersList[i].name);
  99.                     };
  100.                     this.SetClientSizeCore(348, 470);
  101.                 }else {
  102.                     MessageBox.Show("Результат чтения", "Результатов не найдено", MessageBoxButtons.OK, MessageBoxIcon.Error);
  103.                 }
  104.             }
  105.             else {
  106.                 MessageBox.Show("Файл не существует","Проверка наличия файла в системе", MessageBoxButtons.OK, MessageBoxIcon.Error);
  107.             }
  108.         }
  109.  
  110.         private void Form1_Load(object sender, EventArgs e) {
  111.             this.SetClientSizeCore(348, 100);
  112.         }
  113.     }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement