Ejemplo n.º 1
0
        public Result addMember(string firstName, string lastName, DateTime birthDate, string gender, bool isUnitMember, string priesthood, int unitId)
        {
            firstName = firstName.Trim();
            lastName  = lastName.Trim();

            MySqlCommand cmd = new MySqlCommand("insert into lds_member (first_name, last_name, birthdate, unit_id, created_by, member_record, active, restricted, gender, unit_member) values " +
                                                "(@first_name, @last_name, @birthdate, @unit_id, now(), null, 1, 0, @gender, @unit_member)");

            cmd.Parameters.AddWithValue("first_name", firstName);
            cmd.Parameters.AddWithValue("last_name", lastName);
            cmd.Parameters.AddWithValue("birthdate", common.convertDate(birthDate, true));
            cmd.Parameters.AddWithValue("unit_id", unitId);
            cmd.Parameters.AddWithValue("gender", gender);
            cmd.Parameters.AddWithValue("unit_member", common.convertBool(isUnitMember));
            Result result = database.executeQuery(cmd);

            if (result.Success)
            {
                if (priesthood != "0" && gender == "M")
                {
                    result = new Priesthood().addPriesthood(result.Id, common.convertNumber(priesthood));
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        public Result updateMember(int id, string firstName, string lastName, DateTime birthDate, string gender, bool isUnitMember, string priesthood, int unitId)
        {
            firstName = firstName.Trim();
            lastName  = lastName.Trim();

            MySqlCommand cmd = new MySqlCommand("update lds_member set first_name = @first_name, last_name = @last_name, birthdate = @birthdate, gender = @gender, unit_member = @unit_member " +
                                                " where id = @id and unit_id = @unit_id");

            cmd.Parameters.AddWithValue("first_name", firstName);
            cmd.Parameters.AddWithValue("last_name", lastName);
            cmd.Parameters.AddWithValue("birthdate", common.convertDate(birthDate, true));
            cmd.Parameters.AddWithValue("gender", gender);
            cmd.Parameters.AddWithValue("unit_member", common.convertBool(isUnitMember));
            cmd.Parameters.AddWithValue("id", id);
            cmd.Parameters.AddWithValue("unit_id", unitId);
            Result result = database.executeQuery(cmd);

            if (result.Success)
            {
                result = new Priesthood().deletePriesthood(id);
                if (priesthood != "0" && gender == "M" && result.Success)
                {
                    result = new Priesthood().addPriesthood(id, common.convertNumber(priesthood));
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// File format: first;last;1982-12-23;M
        ///              first;last;1989-07-12;F
        /// </summary>
        /// <param name="file"></param>
        /// <param name="unitId"></param>
        /// <returns></returns>
        public Result execute(StreamReader file, int unitId)
        {
            Result result = new Result(true);
            int errors = 0;

            if (file != null)
            {
                string line;

                // Read the file and display it line by line.
                while ((line = file.ReadLine()) != null)
                {
                    string[] data = line.Split(',');

                    if (data.Length >= 4)
                    {
                        string firstName = data[1].Trim();
                        string lastName = data[0].Trim();
                        DateTime birthDate = common.convertDate(data[2].Trim(), true);
                        string gender = data[3].Trim();

                        int priesthood = 0;
                        if (data.Length > 4)
                            priesthood = common.convertNumber(data[4].Trim());

                        Member member = new Member().findMember(lastName, firstName, birthDate, gender, unitId);

                        if (member == null || member.Id == 0)
                        {
                            MySqlCommand cmd = new MySqlCommand("insert into lds_member (first_name, last_name, birthdate, unit_id, created_by, active, restricted, gender, unit_member) values " +
                                "(@first_name, @last_name, @birthdate, @unit_id, now(), 1, 0, @gender, 1)");
                            cmd.Parameters.AddWithValue("first_name", firstName);
                            cmd.Parameters.AddWithValue("last_name", lastName);
                            cmd.Parameters.AddWithValue("birthdate", birthDate);
                            cmd.Parameters.AddWithValue("unit_id", unitId);
                            cmd.Parameters.AddWithValue("gender", gender);
                            result = database.executeQuery(cmd);

                            if (result.Success)
                            {
                                if (gender == "M" && priesthood != 0)
                                {
                                    result = new Priesthood().addPriesthood(result.Id, priesthood);
                                    if (!result.Success)
                                        errors++;
                                }
                            }
                            else
                                errors++;
                        }
                        else
                        {
                            int priestH = new Priesthood().getMemberPriesthood(member.Id);
                            if (priestH != priesthood)
                            {
                                result = new Priesthood().deletePriesthood(member.Id);
                                if (result.Success)
                                {
                                    result = new Priesthood().addPriesthood(member.Id, priesthood);
                                    if (!result.Success)
                                        errors++;
                                }
                                else
                                    errors++;
                            }
                        }
                    }
                }

                file.Close();
            }

            if (errors > 0)
                result.Success = false;

            return result;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// File format: first;last;1982-12-23;M
        ///              first;last;1989-07-12;F
        /// </summary>
        /// <param name="file"></param>
        /// <param name="unitId"></param>
        /// <returns></returns>
        public Result execute(StreamReader file, int unitId)
        {
            Result result = new Result(true);
            int    errors = 0;

            if (file != null)
            {
                string line;

                // Read the file and display it line by line.
                while ((line = file.ReadLine()) != null)
                {
                    string[] data = line.Split(',');

                    if (data.Length >= 4)
                    {
                        string   firstName = data[1].Trim();
                        string   lastName  = data[0].Trim();
                        DateTime birthDate = common.convertDate(data[2].Trim(), true);
                        string   gender    = data[3].Trim();

                        int priesthood = 0;
                        if (data.Length > 4)
                        {
                            priesthood = common.convertNumber(data[4].Trim());
                        }

                        Member member = new Member().findMember(lastName, firstName, birthDate, gender, unitId);

                        if (member == null || member.Id == 0)
                        {
                            MySqlCommand cmd = new MySqlCommand("insert into lds_member (first_name, last_name, birthdate, unit_id, created_by, active, restricted, gender, unit_member) values " +
                                                                "(@first_name, @last_name, @birthdate, @unit_id, now(), 1, 0, @gender, 1)");
                            cmd.Parameters.AddWithValue("first_name", firstName);
                            cmd.Parameters.AddWithValue("last_name", lastName);
                            cmd.Parameters.AddWithValue("birthdate", birthDate);
                            cmd.Parameters.AddWithValue("unit_id", unitId);
                            cmd.Parameters.AddWithValue("gender", gender);
                            result = database.executeQuery(cmd);

                            if (result.Success)
                            {
                                if (gender == "M" && priesthood != 0)
                                {
                                    result = new Priesthood().addPriesthood(result.Id, priesthood);
                                    if (!result.Success)
                                    {
                                        errors++;
                                    }
                                }
                            }
                            else
                            {
                                errors++;
                            }
                        }
                        else
                        {
                            int priestH = new Priesthood().getMemberPriesthood(member.Id);
                            if (priestH != priesthood)
                            {
                                result = new Priesthood().deletePriesthood(member.Id);
                                if (result.Success)
                                {
                                    result = new Priesthood().addPriesthood(member.Id, priesthood);
                                    if (!result.Success)
                                    {
                                        errors++;
                                    }
                                }
                                else
                                {
                                    errors++;
                                }
                            }
                        }
                    }
                }

                file.Close();
            }

            if (errors > 0)
            {
                result.Success = false;
            }

            return(result);
        }
Ejemplo n.º 5
0
        public Result updateMember(int id, string firstName, string lastName, DateTime birthDate, string gender, bool isUnitMember, string priesthood, int unitId)
        {
            firstName = firstName.Trim();
            lastName = lastName.Trim();

            MySqlCommand cmd = new MySqlCommand("update lds_member set first_name = @first_name, last_name = @last_name, birthdate = @birthdate, gender = @gender, unit_member = @unit_member " +
                " where id = @id and unit_id = @unit_id");
            cmd.Parameters.AddWithValue("first_name", firstName);
            cmd.Parameters.AddWithValue("last_name", lastName);
            cmd.Parameters.AddWithValue("birthdate", common.convertDate(birthDate, true));
            cmd.Parameters.AddWithValue("gender", gender);
            cmd.Parameters.AddWithValue("unit_member", common.convertBool(isUnitMember));
            cmd.Parameters.AddWithValue("id", id);
            cmd.Parameters.AddWithValue("unit_id", unitId);
            Result result = database.executeQuery(cmd);
            if (result.Success)
            {
                result = new Priesthood().deletePriesthood(id);
                if (priesthood != "0" && gender == "M" && result.Success)
                    result = new Priesthood().addPriesthood(id, common.convertNumber(priesthood));
            }
            return result;
        }
Ejemplo n.º 6
0
        public Result addMember(string firstName, string lastName, DateTime birthDate, string gender, bool isUnitMember, string priesthood, int unitId)
        {
            firstName = firstName.Trim();
            lastName = lastName.Trim();

            MySqlCommand cmd = new MySqlCommand("insert into lds_member (first_name, last_name, birthdate, unit_id, created_by, member_record, active, restricted, gender, unit_member) values " +
                "(@first_name, @last_name, @birthdate, @unit_id, now(), null, 1, 0, @gender, @unit_member)");
            cmd.Parameters.AddWithValue("first_name", firstName);
            cmd.Parameters.AddWithValue("last_name", lastName);
            cmd.Parameters.AddWithValue("birthdate", common.convertDate(birthDate, true));
            cmd.Parameters.AddWithValue("unit_id", unitId);
            cmd.Parameters.AddWithValue("gender", gender);
            cmd.Parameters.AddWithValue("unit_member", common.convertBool(isUnitMember));
            Result result = database.executeQuery(cmd);
            if (result.Success)
            {
                if (priesthood != "0" && gender == "M")
                    result = new Priesthood().addPriesthood(result.Id, common.convertNumber(priesthood));
            }
            return result;
        }