コード例 #1
0
ファイル: Form1.cs プロジェクト: gustavobosch/Cadastro
        // Botões

        private void btnCadastro_Click(object sender, EventArgs e)
        {
            string nome = this.edNome.Text;
            string cpf  = (this.edCPF.MaskCompleted) ? this.edCPF.Text : "";
            string tel  = (this.edTelefone.MaskCompleted) ? this.edTelefone.Text : "";

            if ((String.IsNullOrWhiteSpace(nome)) || (String.IsNullOrWhiteSpace(cpf)) || (String.IsNullOrWhiteSpace(tel)))
            {
                MessageBox.Show("Preencha os campos corretamente", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            int pos;

            if ((pos = FormCadastro.CpfExiste(this.Users, cpf)) >= 0)
            {
                MessageBox.Show("CPF já cadastrado!");
                list.Items[pos].Selected = true;
                list.Select();
                return;
            }

            User user = new User(++this.UltimoID, nome, cpf, tel);

            this.Users.Add(user);
            this.list.Items.Add(FormCadastro.ItemFromUser(user));

            this.edNome.Clear();
            this.edCPF.Clear();
            this.edTelefone.Clear();
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: gustavobosch/Cadastro
        private static ListViewItem[] ItemsFromUserList(List <User> users)
        {
            ListViewItem[] items = new ListViewItem[users.Count];
            int            i     = 0;

            foreach (User user in users)
            {
                items[i++] = FormCadastro.ItemFromUser(user);
            }
            return(items);
        }