Пример #1
0
        private int CadastroRaj(string raj)
        {
            using (capdeEntities context = new capdeEntities())
            {
                RAJ newRaj = new RAJ
                {
                    NomeRaj    = raj.ToUpper(),
                    IsExcluido = false,
                };

                CJ cj = new CJ
                {
                    RajId   = newRaj.RajId,
                    CjIdent = context.CJs.Count() + 1,
                    CjNome  = StringBase.TODOS.ToString()
                };

                Cidade cidade = new Cidade
                {
                    CjId       = cj.CjId,
                    NomeCidade = StringBase.TODOS.ToString(),
                };

                context.RAJs.Add(newRaj);
                context.CJs.Add(cj);
                context.Cidades.Add(cidade);
                context.SaveChanges();

                return(newRaj.RajId);
            }
        }
Пример #2
0
        private void CadastroRAJ()
        {
            using (capdeEntities context = new capdeEntities())
            {
                RAJ rajVerif = context.RAJs.Where(x => x.NomeRaj == textBox1.Text).FirstOrDefault();
                if (isEditing)
                {
                    RAJ raj = context.RAJs.Where(x => x.RajId == idEditing).FirstOrDefault();
                    raj.NomeRaj    = textBox1.Text;
                    raj.IsExcluido = false;
                }
                else if (rajVerif == null)
                {
                    RAJ raj = new RAJ
                    {
                        NomeRaj    = textBox1.Text,
                        RajIdent   = context.RAJs.Count() + 1,
                        IsExcluido = false,
                    };

                    CJ cj = new CJ
                    {
                        RajId      = raj.RajId,
                        CjIdent    = context.CJs.Count() + 1,
                        CjNome     = StringBase.TODOS.ToString(),
                        IsExcluido = false,
                    };

                    Cidade cidade = new Cidade
                    {
                        CjId       = cj.CjId,
                        NomeCidade = StringBase.TODOS.ToString(),
                        IsExcluido = false,
                    };

                    context.RAJs.Add(raj);
                    context.CJs.Add(cj);
                    context.Cidades.Add(cidade);
                }

                if (isEditing || rajVerif == null)
                {
                    common.SaveChanges_Database(context, true);
                    OutEditing();
                }
                else
                {
                    MessageBox_AlreadyCadastrado(textBox1, TypeForm.RAJ.ToString());
                }
            };
        }
Пример #3
0
        private DataTable VerifyRegistros(DataTable table)
        {
            using (capdeEntities context = new capdeEntities())
            {
                foreach (DataRow row in table.Rows)
                {
                    if (row.RowState != DataRowState.Deleted)
                    {
                        matricula = row[0].ToString();
                        nome      = row[1].ToString();
                        email     = row[2].ToString();
                        obs       = row[8].ToString();

                        Pessoa pessoa = context.Pessoas.Where(x => x.Registro == matricula).FirstOrDefault();

                        string rajValue    = row[4].ToString();
                        string cjValue     = row[5].ToString();
                        string cidadeValue = row[6].ToString();
                        string setorValue  = row[7].ToString();

                        raj = context.RAJs.Where(x => x.NomeRaj == rajValue).FirstOrDefault();

                        if (raj != null)
                        {
                            cj = context.CJs.Where(x => x.RajId == raj.RajId && x.CjNome == cjValue.ToUpper()).FirstOrDefault();
                        }
                        if (cj != null && cj.CjNome != null)
                        {
                            cidade = context.Cidades.Where(x => x.CjId == cj.CjId && x.NomeCidade == cidadeValue.ToUpper()).FirstOrDefault();
                        }
                        if (cidade != null && cidade.NomeCidade != null)
                        {
                            setor = context.Setors.Where(x => x.CidadeId == cidade.CidadeId && x.NomeSetor == setorValue.ToUpper())
                                    .FirstOrDefault();
                        }

                        string nomeCargo = row[3].ToString();
                        cargo = context.Cargoes.Where(x => x.NomeCargo == nomeCargo).FirstOrDefault();

                        if (String.IsNullOrEmpty(matricula))
                        {
                            row[9] = "Matrícula não pode ser nula";
                        }
                        else if (pessoa != null)
                        {
                            row[9] = "Matrícula existente. Registro não será cadastrado";
                        }
                        else if (String.IsNullOrEmpty(nome))
                        {
                            row[9] = "Nome não pode ser nulo";
                        }
                        else if (String.IsNullOrEmpty(rajValue))
                        {
                            row[9] = "RAJ não encontrada";
                        }
                        else if (cj == null)
                        {
                            row[9] = "CJ não encontrada";
                        }
                        else if (cidade == null)
                        {
                            row[9] = "Cidade não encontrada";
                        }
                        else if (setor == null)
                        {
                            row[9] = "Setor não encontrado";
                        }
                        else if (cargo == null)
                        {
                            row[9] = "Cargo não pode ser nulo";
                        }
                    }
                }
            }

            btnVerificar.Enabled = true;

            return(table);
        }