Example #1
0
        private void TestAll(object sender, EventArgs e)
        {
            bool testar = false;
            foreach (Control ctrl in tableLayoutPanel1.Controls)
            {
                if (ctrl.GetType().ToString().Equals("System.Windows.Forms.TextBox"))
                {
                    TextBox obj = (TextBox)ctrl;
                    if (obj.Text.Equals(obj.Name))
                    {
                        testar = true;
                        break;
                    }
                }
                else if (ctrl.GetType().ToString().Equals("System.Windows.Forms.ComboBox"))
                {
                    ComboBox obj = (ComboBox)ctrl;
                    if (obj.Text.Equals(obj.Name))
                    {
                        testar = true;
                        break;
                    }
                }
            }
            if (!testar)
            {
               // List<string> pessoa = new List<string>();

                Funcionario pessoa = new Funcionario();

                pessoa.nome = Nome.Text;
                pessoa.nascimento = Dia.Text + "/" + Mês.Text + "/" + Ano.Text;
                pessoa.sexualidade = Sexualidade.Text;
                pessoa.profissão = Profissão.Text;
                pessoa.estadoCivil = EstadoCivil.Text;
                pessoa.pais = País.Text;
                pessoa.rg = RG.Text;
                pessoa.cidade = Cidade.Text;
                pessoa.rua = Rua.Text;
                pessoa.complemento = Complemento.Text;
                pessoa.n = int.Parse(Nº.Text);
                pessoa.ddd = int.Parse(DDD.Text);
                pessoa.tel = int.Parse(Telefone.Text);
                pessoa.email = Email.Text;
                pessoa.email_rest = Rest.Text;
                pessoa.sangue = Sangue.Text;
                pessoa.raca = Raça.Text;
                pessoa.nFilhos = int.Parse(Filhos.Text);
                funcionarios.Add(pessoa.nome + "#" + pessoa.nascimento + "#" + pessoa.sexualidade + "#" + pessoa.profissão + "#" +
                    pessoa.estadoCivil + "#" + pessoa.pais + "#" + pessoa.rg + "#" + pessoa.cidade + "#" + pessoa.rua + "#" +
                    pessoa.complemento + "#" + pessoa.n + "#" + pessoa.ddd + "#" + pessoa.tel + "#" + pessoa.email +
                    "#" + pessoa.email_rest + "#" + pessoa.sangue + "#" + pessoa.raca + "#" + pessoa.nFilhos);
                listBox1.Items.Add(pessoa.nome + "|" + pessoa.profissão + "|" + pessoa.pais);
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"Text.txt", true))
                {
                    file.WriteLine(funcionarios.Last());
                }
            }
            else
                MessageBox.Show("Preencha todas as informações.");
        }
        public void Salvar_Click(object sender, EventArgs e)
        {
            bool ok = true;
            nomeBox.Text = Regex.Replace(Convert.ToString(nomeBox.Text), "(?i)[^a-z À-ÿ]", "");
            profBox.Text = Regex.Replace(Convert.ToString(profBox.Text), "(?i)[^a-z À-ÿ]", "");
            addBox.Text = Regex.Replace(Convert.ToString(addBox.Text), "(?i)[^a-z0-9 À-ÿ]", "");
            diaBox.Text = Regex.Replace(Convert.ToString(diaBox.Text), "[^0-9]", "");
            mesBox.Text = Regex.Replace(Convert.ToString(mesBox.Text), "[^0-9]", "");
            anoBox.Text = Regex.Replace(Convert.ToString(anoBox.Text), "[^0-9]", "");
            salBox.Text = Regex.Replace(Convert.ToString(salBox.Text), "[^0-9,]", "");

            if (nomeBox.Text == "") { nomeSave.Text = "*"; ok = false; } else { nomeSave.Text = " "; }
            if (diaBox.Text == "" || mesBox.Text == "" || anoBox.Text == "") {
                dataSave.Text = "*";
                ok = false;
            }else{
                dataSave.Text = " ";
                if (Convert.ToDouble(diaBox.Text) < 1 || Convert.ToDouble(diaBox.Text) > 31 || Convert.ToDouble(mesBox.Text) < 1 || Convert.ToDouble(mesBox.Text) > 12 || Convert.ToDouble(anoBox.Text) < 1900 || Convert.ToDouble(anoBox.Text) > 2015){
                    dataSave.Text = "*";
                    ok = false;
                }
            }
            if (profBox.Text == "") { profSave.Text = "*"; ok = false; } else { profSave.Text = " "; }
            if (salBox.Text == "") { salSave.Text = "*"; ok = false; } else { salSave.Text = " "; }
            if (addBox.Text == "") { addSave.Text = "*"; ok = false; } else { addSave.Text = " "; }
            switch (bloodBox.Text) {
                case "O+":case "O-":
                case "A+":case "A-":
                case "B+":case "B-":
                case "AB+":case "AB-":
                case "C#":
                    bloodSave.Text = " ";
                    break;
                default:
                    bloodSave.Text = "*";
                    bloodBox.Text = "";
                    ok = false;
                    break;
            }

            if (genderM.Checked){genderText = "Masculino";}
            else if (genderF.Checked){genderText = "Feminino";}
            else if (genderOutro.Checked){genderText = "Outro";}

            if (NF0.Checked){filhoText = "0 filhos";}
            else if (NF1.Checked){filhoText = "1 filho";}
            else if (NF2.Checked){filhoText = "2 filhos";}
            else if (NF3.Checked){filhoText = "3+ filhos";}

            if (statusS.Checked) { statusText = "Solteiro"; }
            else if (statusC.Checked) { statusText = "Casado"; }
            else if (statusA.Checked) { statusText = "Assexuado"; }

            if (ok){
                Funcionario f = new Funcionario();
                f.nome = nomeBox.Text;
                f.nascimento = diaBox.Text + "/" + mesBox.Text + "/" + anoBox.Text;
                f.gender = genderText;
                f.prof = profBox.Text;
                f.sal = salBox.Text;
                f.status = statusText;
                f.NF = filhoText;
                f.blood = bloodBox.Text;
                f.add = addBox.Text;

                funcionarios.Add(f);

                if (nameList.SelectedIndex == -1){
                    nameList.Items.Add("<Novo>");
                    nameList.SelectedIndex = 0;
                }

                bool hadPrevious = false;
                string[] allLines;
                try{
                    allLines = System.IO.File.ReadAllLines(pathname + @"\Index.txt");
                }catch{
                    allLines = new string[1];
                }
                File.Delete(pathname + @"\Index.txt");
                foreach (string line in allLines){
                    if (Convert.ToString(nameList.Items[nameList.SelectedIndex]) != "<Novo>" && line.Contains(Convert.ToString(nameList.Items[nameList.SelectedIndex]))){
                        using (StreamWriter file = new StreamWriter(pathname + @"\Index.txt", true)){
                            file.WriteLine(f.asString());
                        }
                        hadPrevious = true;
                    }else{
                        using (StreamWriter file = new StreamWriter(pathname + @"\Index.txt", true)){
                            file.WriteLine(line);
                        }
                    }
                }
                if (!(!(!hadPrevious))){ //Hehe :3
                    using (StreamWriter file = new StreamWriter(pathname + @"\Index.txt", true)){
                        file.WriteLine(f.asString());
                    }
                }

                nameList.Items[nameList.SelectedIndex] = f.nome;
            }else{
                Console.WriteLine("Erro!");
            }
        }