I’ve just finished creating a data base for my assignment at school just wanted to ask if there is any improvementes I could make.

//Adicionar public void Add() {

ltbDados.Items.Add(txtNumero.Text + ‘t’ + txtUltimo.Text + ‘t’ + txtCompleto.Text + ‘t’ + txtTurma.Text + ‘t’ + cbbCurso.Text + ‘t’ + ccbAno.Text + ‘t’ + txtNascimento.Text + ‘t’ + txtLocal.Text + ‘t’ + txtMorada.Text + ‘t’ + txtCodigo.Text + ‘t’);

 txtNumero.Text = ""; txtUltimo.Text = ""; txtCompleto.Text = ""; txtTurma.Text = ""; cbbCurso.Text = ""; ccbAno.Text = ""; txtNascimento.Text = ""; txtLocal.Text = ""; 

txtMorada.Text = “”;

 txtCodigo.Text = ""; txtNumero.Enabled = true; txtNumero.Focus(); txtUltimo.Enabled = false; txtCompleto.Enabled = false; txtTurma.Enabled = false; cbbCurso.Enabled = false; ccbAno.Enabled = false; 

txtNascimento.Enabled = false;

 txtLocal.Enabled = false; txtMorada.Enabled = false; txtCodigo.Enabled = false; Flag = 0; } //Limpar as textboxes public void Limpar() { txtNumero.Text = ""; txtUltimo.Text = ""; txtCompleto.Text = ""; txtTurma.Text = ""; cbbCurso.Text = ""; ccbAno.Text = ""; txtNascimento.Text = ""; txtLocal.Text = ""; txtMorada.Text = ""; txtCodigo.Text = ""; txtNumero.Enabled = true; txtNumero.Focus(); txtUltimo.Enabled = false; txtCompleto.Enabled = false; txtTurma.Enabled = false; cbbCurso.Enabled = false; ccbAno.Enabled = false; txtNascimento.Enabled = false; txtLocal.Enabled = false; txtMorada.Enabled = false; txtCodigo.Enabled = false; Flag = 0; } //Verificar se e um numero static string Numero(string num) { int N1 = 0; if (int.TryParse(num, out N1) == true) { return num; } else { num = ""; return num; } } //Avançar nas textboxes int Flag = 1; public void Avançar() { switch (Flag) { case 1: Flag++; txtNumero.Enabled = true; txtNumero.Focus(); break; case 2: Flag++; txtUltimo.Enabled = true; txtUltimo.Focus(); txtNumero.Enabled = false; break; case 3: Flag++; txtCompleto.Enabled = true; txtCompleto.Focus(); txtUltimo.Enabled = false; break; case 4: Flag++; txtTurma.Enabled = true; txtTurma.Focus(); txtCompleto.Enabled = false; break; case 5: Flag++; cbbCurso.Enabled = true; cbbCurso.Focus(); txtTurma.Enabled = false; break; case 6: Flag++; ccbAno.Enabled = true; ccbAno.Focus(); cbbCurso.Enabled = false; break; case 7: Flag++; txtLocal.Enabled = true; txtLocal.Focus(); ccbAno.Enabled = false; break; case 8: Flag++; txtMorada.Enabled = true; txtMorada.Focus(); txtLocal.Enabled = false; break; case 9: Flag++; txtCodigo.Enabled = true; txtCodigo.Focus(); txtMorada.Enabled = false; break; case 10: Flag++; txtNascimento.Enabled = true; txtNascimento.Focus(); txtCodigo.Enabled = false; break; case 11: Flag = 1; txtNascimento.Enabled = false; txtNumero.Enabled = true; txtNumero.Focus(); break; } } public Form1() { InitializeComponent(); } //Editar public void Edit() { // Método para editar int i = 0, j; int flag = 0; string sub; string message = Convert.ToString(ltbDados.SelectedItem); j = message.IndexOf('t'); while (j != -1 && i != message.Length - 1 ) { sub = message.Substring(i, j - i + 1); if (flag == 0) { txtNumero.Text = sub; flag++; } else if (flag == 1) { txtUltimo.Text = sub; flag++; } else if (flag == 2) { txtCompleto.Text = sub; flag++; } else if (flag == 3) { txtTurma.Text = sub; flag++; } else if (flag == 4) { cbbCurso.Text = sub; flag++; } else if (flag == 5) { ccbAno.Text = sub; flag++; } else if (flag == 6) { txtNascimento.Text = sub; flag++; } else if (flag == 7) { txtLocal.Text = sub; flag++; } else if (flag == 8) { txtMorada.Text = sub; flag++; }else if (flag == 9) { txtCodigo.Text = sub; flag++; } sub = message.Remove(j); sub = message.Substring(i); i = j + 1; j = message.IndexOf('t', i); Avançar(); txtNumero.Enabled = true; txtNumero.Focus(); } } //Inicio do Codigo private void txtNumero_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) { if (txtNumero.Text != "") Avançar(); } } private void txtUltimo_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)13) { if (txtUltimo.Text != "") Avançar(); } } private void txtCompleto_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)13) { if (txtCompleto.Text != "") Avançar(); } } private void txtTurma_KeyPress(object sender, KeyPressEventArgs e) { } private void txtNascimento_KeyPress(object sender, KeyPressEventArgs e) { } private void txtLocal_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) { if (txtLocal.Text != "") Avançar(); } } private void txtMorada_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) { if (txtMorada.Text != "") Avançar(); } } private void txtCodigo_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) { if (txtCodigo.Text != "") Avançar(); } } private void cbbCurso_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar != 13) { e.KeyChar = Convert.ToChar(0); } else if (e.KeyChar == 13) { if (cbbCurso.Text != "") Avançar(); } } private void cbbCurso_SelectedIndexChanged(object sender, EventArgs e) { } private void btnClear_Click(object sender, EventArgs e) { Limpar(); } private void btnEdit_Click(object sender, EventArgs e) { Edit(); } private void btnAdd_Click(object sender, EventArgs e) { Add(); Flag = 1; } private void ccbAno_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar != 13) { e.KeyChar = Convert.ToChar(0); } else if (e.KeyChar == 13) { if (ccbAno.Text != "") Avançar(); } } private void txtNumero_TextChanged(object sender, EventArgs e) { } private void txtTurma_KeyPress_1(object sender, KeyPressEventArgs e) { if(e.KeyChar == 13) { if (txtTurma.Text.StartsWith("P")) { Avançar(); }else if (txtTurma.Text.StartsWith("p")) { txtTurma.Text = txtTurma.Text.ToUpper(); Avançar(); } else { txtTurma.Text = "P" + txtTurma.Text; Avançar(); } } } private void txtNascimento_KeyPress_1(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) { if (txtNascimento.Text != "") Avançar(); } 

submitted by /u/Brainwreeck
[link] [comments]

Leave a Reply