Ejemplo n.º 1
0
        public bool UpdateParishioner(Parishioner P)
        {
            var  conn     = new SqlConnection();
            var  command  = new SqlCommand();
            var  dataBase = new DBConnect();
            bool answ;

            try
            {
                conn = dataBase.Open();
                command.Connection  = conn;
                command.CommandText = "UpdateParishioner";
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@Id", P.Id);
                command.Parameters.AddWithValue("@Name", P.Name);
                command.Parameters.AddWithValue("@Surname", P.Surname);
                command.Parameters.AddWithValue("@Documento", P.Documento);
                if (P.BirthDate == null)
                {
                    command.Parameters.AddWithValue("@BirthDate", Convert.DBNull);
                }
                else
                {
                    command.Parameters.AddWithValue("@BirthDate", P.BirthDate);
                }
                command.Parameters.AddWithValue("@Observation", P.Observation);
                command.ExecuteNonQuery();
                answ = true;
            }
            catch (Exception e)
            {
                MessageBox.Show(String.Concat(e.Message, e.StackTrace), "");
                answ = false;
            }
            finally
            {
                if (conn.State == System.Data.ConnectionState.Open)
                {
                    conn.Close();
                    conn.Dispose();
                }
            }
            return(answ);
        }
Ejemplo n.º 2
0
        }//Listar

        public List <Parishioner> ListParishByActivity(string Name, int activityId)
        {
            var conn     = new SqlConnection();
            var command  = new SqlCommand();
            var dataBase = new DBConnect();
            var Lista    = new List <Parishioner>();

            try
            {
                conn = dataBase.Open();
                command.Connection  = conn;
                command.CommandText = "ListParishByActivity";
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@Name", Name);
                command.Parameters.AddWithValue("@ActivityId", activityId);
                var rdr = command.ExecuteReader();

                while (rdr != null && rdr.Read())
                {
                    var reg = new Parishioner();
                    reg.Id        = (int)rdr["Id"];
                    reg.Name      = (string)rdr["Name"];
                    reg.Surname   = (string)rdr["Surname"];
                    reg.Documento = (string)rdr["Documento"];
                    if (rdr["BirthDate"] is DBNull)
                    {
                        reg.BirthDate = null;
                    }
                    else
                    {
                        reg.BirthDate = Convert.ToDateTime(rdr["BirthDate"]);
                    }
                    reg.Telephone   = Convert.ToString(rdr["Telephone"] is DBNull ? "" : rdr["Telephone"]);
                    reg.Address     = Convert.ToString(rdr["Address"] is DBNull ? "" : rdr["Address"]);
                    reg.Mail        = Convert.ToString(rdr["Mail"] is DBNull ? "" : rdr["Mail"]);
                    reg.Observation = Convert.ToString(rdr["Observation"] is DBNull ? "" : rdr["Observation"]);
                    if (rdr["IdTel"] is DBNull)
                    {
                        reg._parishionerData.IdTel = null;
                    }
                    else
                    {
                        reg._parishionerData.IdTel = (int)rdr["IdTel"];
                    }
                    if (rdr["IdAddress"] is DBNull)
                    {
                        reg._parishionerData.IdAddress = null;
                    }
                    else
                    {
                        reg._parishionerData.IdAddress = (int)rdr["IdAddress"];
                    }
                    if (rdr["IdMail"] is DBNull)
                    {
                        reg._parishionerData.IdMail = null;
                    }
                    else
                    {
                        reg._parishionerData.IdMail = (int)rdr["IdMail"];
                    }
                    Lista.Add(reg);
                }//while
            }
            catch (Exception e)
            {
                MessageBox.Show(String.Concat(e.Message, e.StackTrace), "");
            }
            finally
            {
                if (conn.State == System.Data.ConnectionState.Open)
                {
                    conn.Close();
                    conn.Dispose();
                }
            }

            return(Lista);
        }//Listar
Ejemplo n.º 3
0
 public ParishionerByActivity()
 {
     _activity    = new Activity();
     _parishioner = new Parishioner();
 }