Exemplo n.º 1
0
 public static void Insert(Funcionario fn)
 {
     try
     {
         using (conn = new SqlConnection(connectionString))
         {
             conn.Open();
             string     q   = "INSERT INTO Funcionario (Nome, Motorista, Tecnico, Identidade, CLT, Salario, Observacao) VALUES (@n, @m, @t, @i, @c, @s, @o) SET @ID = SCOPE_IDENTITY();";
             SqlCommand cmd = new SqlCommand(q, conn);
             cmd.Parameters.Add("@n", SqlDbType.VarChar).Value  = fn.nome;
             cmd.Parameters.Add("@m", SqlDbType.Bit).Value      = fn.motorista;
             cmd.Parameters.Add("@t", SqlDbType.Bit).Value      = fn.tecnico;
             cmd.Parameters.Add("@i", SqlDbType.VarChar).Value  = fn.identidade;
             cmd.Parameters.Add("@c", SqlDbType.VarChar).Value  = fn.CLT;
             cmd.Parameters.Add("@s", SqlDbType.Float).Value    = fn.salario;
             cmd.Parameters.Add("@o", SqlDbType.VarChar).Value  = fn.observacao;
             cmd.Parameters.Add("@ID", SqlDbType.Int).Direction = ParameterDirection.Output;
             cmd.ExecuteNonQuery();
             int i = (int)cmd.Parameters["@ID"].Value;
             fn.telefone.setFuncionario(i);
             fn.endereco.setFuncionario(i);
             DALTelefone.Insert(fn.telefone);
             DALEndereco.Insert(fn.endereco);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 2
0
 public static void Insert(Cliente cl)
 {
     try
     {
         using (conn = new SqlConnection(connectionString))
         {
             conn.Open();
             string     doc = (cl.CPF != "" && cl.CPF != null) ? "CPF" : "CNPJ";
             string     q   = "INSERT INTO Cliente (Nome, " + doc + ", Email) VALUES (@n, @d, @m) SET @ID = SCOPE_IDENTITY();";
             SqlCommand cmd = new SqlCommand(q, conn);
             cmd.Parameters.Add("@n", SqlDbType.VarChar).Value  = cl.nome;
             cmd.Parameters.Add("@d", SqlDbType.VarChar).Value  = (cl.CPF != "" && cl.CPF != null) ? cl.CPF : cl.CNPJ;
             cmd.Parameters.Add("@m", SqlDbType.VarChar).Value  = cl.email;
             cmd.Parameters.Add("@ID", SqlDbType.Int).Direction = ParameterDirection.Output;
             cmd.ExecuteNonQuery();
             int i = (int)cmd.Parameters["@ID"].Value;
             cl.telefone.setCliente(i);
             cl.endereco.setCliente(i);
             DALTelefone.Insert(cl.telefone);
             DALEndereco.Insert(cl.endereco);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }