Example #1
0
        public static int InsertAgricultor(AgricultorVO Agricultor)
        {
            MySqlCommand cmd = new MySqlCommand("InsertAgricultor",
                                                new MySqlConnection(Classtratarconexao.GetConnectionString()));

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new MySqlParameter("nomedetentor", Agricultor.NomeDetentor));
            cmd.Parameters.Add(new MySqlParameter("moradadetentor", Agricultor.MoradaDetentor));
            cmd.Parameters.Add(new MySqlParameter("nif", Agricultor.Nif));
            cmd.Parameters.Add(new MySqlParameter("telefone", Agricultor.Telefone));
            cmd.Parameters.Add(new MySqlParameter("email", Agricultor.Email));
            cmd.Parameters.Add(new MySqlParameter("password", Agricultor.Password));
            cmd.Parameters.Add(new MySqlParameter("username", Agricultor.Username));
            try
            {
                if (Classtratarconexao.AbrirConexao(cmd.Connection))
                {
                    cmd.ExecuteNonQuery();
                }
                return(1);
            }
            catch (MySqlException ex)
            {
                new Exception(ex.Message);
                return(0);
            }
            finally
            {
                Classtratarconexao.FecharConexao(cmd.Connection);
            }
        }
Example #2
0
 public int InsertAgricultor(AgricultorVO Agricultor)
 {
     try
     {
         return(AgricultorDAO.InsertAgricultor(Agricultor));
     }
     catch
     {
         throw;
     }
 }
Example #3
0
        public static List <AgricultorVO> GetLoginAgricultor()
        {
            List <AgricultorVO> agricultorItemList = new List <AgricultorVO>();

            MySqlCommand cmd = new MySqlCommand("ConsultarLogin",
                                                new MySqlConnection(Classtratarconexao.GetConnectionString()));

            cmd.CommandType = CommandType.StoredProcedure;

            try
            {
                if (Classtratarconexao.AbrirConexao(cmd.Connection))
                {
                    MySqlDataReader dr =
                        cmd.ExecuteReader(CommandBehavior.CloseConnection);


                    while (dr.Read())
                    {
                        AgricultorVO Agri = new AgricultorVO();
                        Agri.Password = Convert.ToString(dr["password"]);
                        Agri.Username = Convert.ToString(dr["username"]);

                        agricultorItemList.Add(Agri);
                    }
                    dr.Close();

                    //cmd.Connection.Close(); //eu

                    return(agricultorItemList);
                }
                else
                {
                    return(agricultorItemList);
                }
            }
            catch (MySqlException ex)
            {
                new Exception(ex.Message);
                return(agricultorItemList);
            }
            finally
            {
                Classtratarconexao.FecharConexao(cmd.Connection);
            }
        }
Example #4
0
        private void registrar()
        {
            if ((tbnome.Text != "") && (tbmorada.Text != "") && (tbnif.Text != "") && (tbtlm.Text != "") && (tbemail.Text != "") && (tbuser.Text != "") && (tbpass.Text != ""))
            {
                try
                {
                    //MySqlCommand gravar = conexao.CreateCommand();
                    //gravar.CommandText = "Insert into agricultor (nomeDetentor,enderecoDetentor,nif,telefone,email,password,username) VALUE(@nomeDetentor,@enderecoDetentor,@nif,@telefone,@email,@password,@username)";
                    ////gravar.Parameters.AddWithValue("@nomeDetentor", tbnome.Text);
                    ////gravar.Parameters.AddWithValue("@enderecoDetentor", tbmorada.Text);
                    ////gravar.Parameters.AddWithValue("@nif", tbnif.Text);
                    ////gravar.Parameters.AddWithValue("@telefone", tbtlm.Text);
                    ////gravar.Parameters.AddWithValue("@email", tbemail.Text);
                    ////gravar.Parameters.AddWithValue("@password", tbpass.Text);
                    ////gravar.Parameters.AddWithValue("@username", tbuser.Text);
                    //conexao.Open();
                    //gravar.ExecuteNonQuery();

                    AgricultorVO Agricultor = new AgricultorVO();
                    Agricultor.NomeDetentor   = tbnome.Text;
                    Agricultor.MoradaDetentor = tbmorada.Text;
                    Agricultor.Nif            = tbnif.Text;
                    Agricultor.Telefone       = tbtlm.Text;
                    Agricultor.Email          = tbemail.Text;
                    Agricultor.Password       = tbpass.Text;
                    Agricultor.Username       = tbuser.Text;

                    AgricultorBUS Agricultorbus = new AgricultorBUS();

                    if (Agricultorbus.InsertAgricultor(Agricultor) == 1)
                    {
                        MessageBox.Show("Agricultor inserido");
                    }
                    else
                    {
                        MessageBox.Show(" falha");
                    }



                    tbnome.Clear();
                    tbmorada.Clear();
                    tbnif.Clear();
                    tbtlm.Clear();
                    tbemail.Clear();
                    tbuser.Clear();
                    tbpass.Clear();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Erro a criar utilizador!");
                    throw ex;
                    //conexao.Close();
                }
                finally
                {
                    //conexao.Close();
                    MessageBox.Show("Criado com sucesso!");
                }
            }
            else
            {
                MessageBox.Show("Verificar os campos!");
            }
        }