I'm having some problems creating a List of Arrays, I'm using Visual C #, .NET 3.5.
Code:
using Database;
//...
namespace Sample {
public partial class Form1 : Form {
//...
private void Button1_Click(object sender, EventArgs e) {
if ((TextBox1.Text).Equals("") || (TextBox2.Text).Equals("")) {
MessageBox.Show(null, "Preencha todos os campos!", "Erro");
} else {
ClassDatabase Call = new ClassDatabase();
Call.RegDatabase(TextBox1.Text, TextBox2.Text);
//...
}
}
//...
}
}
namespace Database {
class ClassDatabase {
List<string[]> InfoList = new List<string[]>();
public void RegDatabase(String A, String B) {
string[] DataSet = new string[2];
DataSet[0] = A;
DataSet[1] = B;
this.InfoList.AddRange(DataSet);
} public bool InDatabase (String A, String B) {
int j = InfoList.Count;
for (int i = 0; i < j; i ++) {
string[] DataGet = new string[2];
DataGet = this.InfoList[i];
if (DataGet[0].Equals(A) && DataGet[1].Equals(B)) {
return true;
} else {
return false;
}
}
}
}
}
using Database;
//...
namespace Sample {
public partial class Form2 : Form {
//...
ClassDatabase Call = new ClassDatabase();
private void Button1_Click(object sender, EventArgs e) {
if (Call.InDatabase(TextBox1.Text, TextBox2.Text)) {
//...
} else {
MessageBox.Show(null, "Falha ao entrar.", "Erro");
}
}
//...
}
}
What was to happen there is a record, then a validation.
The user registers and presses the button to confirm, the information is sent to the RegDatabase
method of the ClassDatabase
class, which adds this information to the list of type string [] ,% with%. When the user tries to enter, he places the information in the TextBox and clicks the button, this sends the information to the other method of class InfoList
, ClassDatabase
, this method takes the InDatabase
list % and opens each array, comparing the data of each array within the InfoList
list with the data entered by the user; if it satisfies the if condition, the method returns true and enters the system, otherwise it returns false and this generates an error message.
Well, that's what I tried to make it happen, but it's not what happens, the problem, perhaps, is my lack of experience, but anyway, how could I do the above?
Is there any more practical way of doing this registration / validation (DLL, for example)? If so, which one?