2
Work in a school that makes the students frequency control by digital, each time a student "hits" the finger is added to a code to a txt, if the student hit 1 time is recorded input if he hit 2 times is marked input and output, I was able to read the text and save the data in the array Todosapontamento[12,31,X] that in the serious case Month and day, now I need to check if each student hit once or twice in the day
I made a script to save data from a txt in a multidimensional array, each line of txt contains a code that is saved in the array, I need to check if that code appears twice in the same array index, for example: array[dia,mes, code] but I don’t know how to do this, Obs: I also made a list to save the data in the database in the future.
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 MetroFramework;
using MetroFramework.Forms;
using System.IO; //declarando a biblioteca de entrada e saída de arquivos
//a biblioteca IO
namespace Pj_FrquenciaObjetivo
{
public partial class TratarDados : MetroFramework.Forms.MetroForm
{
public TratarDados()
{
InitializeComponent();
}
private void TratarDados_Load(object sender, EventArgs e)
{
try
{
int qtMaxima = 0;
int Coutap = 0;
//declarando a variavel do tipo StreamWriter
StreamReader x;
//Colocando o caminho fisico
string Caminho = "C:\\Apontamento\\Apontamento.txt";
//abrindo um arquivo texto
x = File.OpenText(Caminho);
while (x.EndOfStream != true)//quer dizer que não chegou no fim do
//arquivo
{
string linha2 = x.ReadLine();
if (linha2 == "")
{
x.Close();
break;
}
qtMaxima++;
}
string[,,] TodosApontamento = new string[12,31, qtMaxima];
x = File.OpenText(Caminho);
string recuperaDia ="", recuperaMes ="";
//enquanto nao retornar valor booleano true
while (x.EndOfStream != true)//quer dizer que não chegou no fim do
//arquivo
{
//le conteúdo da linha
string linha = x.ReadLine();
//escreve na tela o conteúdo da linha
// Aqui eu devo salvar o texto em pedaços para
// que eu possa criar o obj apontamento
string status = linha.Substring(0, 2);
string dia = linha.Substring(2, 2);
string mes = linha.Substring(4, 2);
string ano = linha.Substring(6, 4);
string hora = linha.Substring(10, 2);
string minuto = linha.Substring(12, 2);
string segundo = linha.Substring(14, 2);
string matricula = linha.Substring(16, 5);
if (recuperaMes==mes && recuperaDia==dia)
{
Coutap = 0;
}
while (TodosApontamento[int.Parse(mes), int.Parse(dia), Coutap] !=null)
{
Coutap++;
}
TodosApontamento[int.Parse(mes),int.Parse(dia), Coutap] = linha;
Apontamento apm = new Apontamento(status, dia, mes, ano, hora, minuto, segundo, matricula);
Controller.CarregaApontamentos(apm);
// MessageBox.Show("Mes: "+int.Parse(mes)+" - Dia: "+ int.Parse(dia) + " - Arrey : "+Coutap +" - Conteudo: "+ TodosApontamento[int.Parse(mes), int.Parse(dia), Coutap]) ;
Coutap++;
recuperaDia = dia;
recuperaMes = mes;
}
//após sair do while, é porque leu todo o conteúdo, então
//temos que fechar o arquivo texto que está aberto
x.Close();
}
catch (Exception)
{
MetroMessageBox.Show(this, "Erro ao tentar adicionar na lista.", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void btn_voltar_Click(object sender, EventArgs e)
{
Home Hhome = new Home();
this.Hide(); // use dessa maneira.
Hhome.ShowDialog();
}
private void metroButton2_Click(object sender, EventArgs e)
{
MessageBox.Show("Apontamento criado com seucesso");
MessageBox.Show("A quantidade de apontamentos é :" + Controller.L_apontamento1.Count());
}
}
}
I think you’d better serialize your object and save it as
XML
orJSON
. And when you read, deserialize for object.– Tony
Explain your problem because you can’t understand what you want to do with the matrix.
– Marcelo Shiniti Uchimura
you want to check if some value repeats in the same column in different rows?
– Leandro Angelo
This @Leandroangelo
– Reignomo
And how you will want to indicate or present this?
– Leandro Angelo
@Marcelouchimura work in a school that makes the students frequency control by digital, each time a student "hits" the finger is added to a code to a txt, if the student hit 1 time is recorded input if he hit 2 times is marked input and output, I was able to read the text and save the data in the array Todosapontamento[12,31,X] that in the serious case Month and day, now I need to check if each student hit once or twice in the day
– Reignomo
@Leandroangelo I want to do this check and if I have only 1 "note" of the same student on the day I will create a "note" and save in txt
– Reignomo