Esempio n. 1
0
        public void ClearRace()
        {
            Int32 anID = 10;
            string aName = "Ejemplo de carrera";
            DateTime aRaceDate = DateTime.Now;
            string aStreet = "Street";
            string aNumber = "1a";
            string aCity = "City";
            string aCountry = "Country";
            string aPostalCode = "18007";
            Address anAddress = new Address(aStreet, aNumber, aCity, aCountry, aPostalCode);
            Int32 aRaceTypeId = 20;
            string aMemo = "memo";
            double aLatitud = 3;
            double aLongitud = 36;
            string aImgURL = "imagen url";
            int aPartMasc = 1000;
            int aPartFem = 100;

            Race aRace = new Race(anID, aName, aRaceDate, anAddress, aRaceTypeId, aMemo, aImgURL, aLongitud, aLatitud, aPartMasc, aPartFem);
            aRace.ClearRace();

            anID = 0;
            aName = null;
            aRaceDate = DateTime.Now;
            anAddress = null;
            aRaceTypeId = 0;
            aMemo = null;
            aLatitud = 0;
            aLongitud = 0;
            aImgURL = null;
            aPartMasc = 0;
            aPartFem = 0;

            Assert.AreEqual(anID, aRace.Id);
            Assert.AreEqual(aName, aRace.Name);
            Assert.AreEqual(aRaceDate.ToShortDateString(), aRace.RaceDate.ToShortDateString());
            Assert.AreEqual(null, aRace.Address);
            Assert.AreEqual(aRaceTypeId, aRace.RaceTypeID);
            Assert.AreEqual(aMemo, aRace.Memo);
            Assert.AreEqual(aImgURL, aRace.ImageURL);
            Assert.AreEqual(aLatitud, aRace.Latitud);
            Assert.AreEqual(aLongitud, aRace.Longitud);
            Assert.AreEqual(aPartFem, aRace.PartFem);
            Assert.AreEqual(aPartMasc, aRace.PartMasc);
        }
Esempio n. 2
0
        public void DoDelRace()
        {
            bool sigue = true;
            string messageError = "";

            //Verify race exists
            if (txbxUserName.Text == "")
            {
                sigue = false;
                messageError = "No hay competiciones que quitar.";
            }

            if (sigue)
            {
                if (actualRaceId == 0)
                {
                    messageError = "Seleccione una competición para quitar de la tabla.";
                    sigue = false;
                }
            }

            if (sigue)
            {
                //Load data for username
                using (var db = new ClubSiteContext())
                {
                    Member aMember = new Member();
                    Race aRace = new Race();
                    aMember = (from m in db.Members where m.UserName == memberUsed.UserName select m).FirstOrDefault();
                    aRace = (from r in db.Races where r.Id == actualRaceId select r).FirstOrDefault();
                    try
                    {
                        aRace.Members.Remove(aMember);
                        db.SaveChanges();
                        LoadDataInGridForRacesForClubber();
                        X.Msg.Alert("Atención", memberUsed.UserName + " quitad@ de la competición.").Show();
                    }
                    catch (Exception)
                    {
                        X.Msg.Alert("Atención", "Hubo un problema al quitar a " + memberUsed.UserName + " de la competición seleccionada.").Show();
                    }

                }
            }

            if (!sigue)
            {
                X.Msg.Alert("Atención", messageError).Show();
            }
        }
Esempio n. 3
0
        public void DoAddRace()
        {
            bool sigue = true;
            string messageError = "";

            //Load data for Race/Clubber
            using (var db = new ClubSiteContext())
            {
                Member aMember = new Member();
                Race aRace = new Race();
                aMember = (from m in db.Members where m.UserName == memberUsed.UserName select m).FirstOrDefault();
                aRace = (from r in db.Races where r.Id == actualRaceId select r).FirstOrDefault();

                //verify if member is in members list for race
                if (aRace.Members.Contains(aMember) == true)
                {
                    messageError = memberUsed.UserName + " ya esta inscrit@ en esa competición.";
                    sigue = false;
                }
                else
                {
                    try
                    {
                        aRace.Members.Add(aMember);
                        db.SaveChanges();
                        LoadDataInGridForRacesForClubber();
                        X.Msg.Alert("Atención", "Se ha inscrito a " + memberUsed.UserName + " en la competición.").Show();
                    }
                    catch (Exception)
                    {
                        X.Msg.Alert("Atención", "Hubo un problema al añadir a " + memberUsed.UserName + "a la lista de participantes en la competición.").Show();
                    }
                }
            }

            if (!sigue)
            {
                X.Msg.Alert("Atención", messageError).Show();
            }
        }
Esempio n. 4
0
        protected void GPRaces_Cell_Click(object sender, EventArgs e)
        {
            try
            {
                CellSelectionModel sm = this.GPRaces.GetSelectionModel() as CellSelectionModel;
                Int32 actualRId = Convert.ToInt32(sm.SelectedCell.RecordID);
                using (var db = new ClubSiteContext())
                {
                    rUsed = (from races in db.Races
                             where races.Id == actualRId
                             select races).FirstOrDefault();

                    if (rUsed == null)
                        X.Msg.Alert("Atención", "No hay ninguna carrera registrada en la Base de datos.").Show();
                    oldRUsed.CopyRace(rUsed);

                    //Loads model object data into form
                    LoadRaceInForm(rUsed);
                }
            }
            catch (Exception) { }
            btnBorrar.Enabled = true;
        }
Esempio n. 5
0
        public void DoSave()
        {
            bool sigue = true;
            string messageError = null;

            //Save if conditions are ok.
            if (sigue)
            {
                using (var db = new ClubSiteContext())
                {
                    Race aRace;
                    if (rUsed.Id == 0)
                    { //New Race
                        aRace = new Race();
                        aRace.Name = txbxName.Text;
                        aRace.Name = txbxName.Text;
                        aRace.RaceDate = Convert.ToDateTime(txbxDate.Text);
                        aRace.ImageURL = rUsed.ImageURL;
                        aRace.RaceTypeID = aRaceIdSelectedInCombo;
                        try
                        {
                            aRace.PartFem = Convert.ToInt16(txbxPartGenFem.Text);
                        }
                        catch (Exception)
                        {
                            aRace.PartFem = 0;
                        }
                        try
                        {
                            aRace.PartMasc = Convert.ToInt16(txbxPartGenMasc.Text);
                        }
                        catch (Exception)
                        {
                            aRace.PartMasc = 0;
                        }
                        Address anAddres = new Address(txbxStreet.Text, txbxNumber.Text, txbxCity.Text, txbxCountry.Text, txbxPostalCode.Text);
                        aRace.Address = anAddres;
                        aRace.Memo = txbxMemo.Text;
                        string aux = ReformatNumber(txbxLatitud.Text);
                        if (aux == null)
                            aRace.Latitud = 0;
                        else
                        {
                            aRace.Latitud = Convert.ToDouble(aux);
                        }

                        aux = ReformatNumber(txbxLongitud.Text);
                        if (aux == null)
                            aRace.Longitud = 0;
                        else
                        {
                            aRace.Longitud = Convert.ToDouble(aux);
                        }

                        db.Races.Add(aRace);
                        messageError = "Nueva competición grabada";
                    }
                    else
                    { //Update actual Race
                        aRace = (from races in db.Races
                                 where races.Id == rUsed.Id
                                 select races).FirstOrDefault();
                        if (aRace == null)
                        {
                            // The item wasn't found
                            ModelState.AddModelError("", String.Format("Competición con Id : {0} no encontrada", rUsed.Id));
                            X.Msg.Alert("Atención", "Competición no encontrada. Grabación de datos cancelada.").Show();
                            return;
                        }
                        aRace.Name = txbxName.Text;
                        aRace.RaceDate = Convert.ToDateTime(txbxDate.Text);
                        aRace.ImageURL = rUsed.ImageURL;
                        aRace.RaceTypeID = aRaceIdSelectedInCombo;
                        Address anAddres = new Address(txbxStreet.Text, txbxNumber.Text, txbxCity.Text, txbxCountry.Text, txbxPostalCode.Text);
                        aRace.Address = anAddres;
                        aRace.Memo = txbxMemo.Text;
                        string aux = ReformatNumber(txbxLatitud.Text);
                        if (aux == null)
                            aRace.Latitud = 0;
                        else
                        {
                            aRace.Latitud = Convert.ToDouble(aux);
                        }

                        aux = ReformatNumber(txbxLongitud.Text);
                        if (aux == null)
                            aRace.Longitud = 0;
                        else
                        {
                            aRace.Longitud = Convert.ToDouble(aux);
                        }
                        messageError = "Datos de competición actualizados";
                    }
                    db.SaveChanges();
                    LoadRaceInForm(aRace);  //To update the ID (identity file)
                    rUsed.CopyRace(aRace);
                    oldRUsed.CopyRace(rUsed);
                    StoreGPRaces.DataBind();
                    X.Msg.Alert("Atención", messageError).Show();
                }
                btnBorrar.Enabled = true;
            }
            else
            {
                X.Msg.Alert("Atención", messageError).Show();
            }
        }
Esempio n. 6
0
        public void DoDel()
        {
            Notification.Show(new NotificationConfig { Title = "Aviso", Icon = Icon.Information, Html = "Borrando la competición en pantalla." });
            if (rUsed.Id == 0)
            { //No Race selected
                X.Msg.Alert("Atención", "No hay nada que borrar ya que no hay competiciones registradas.").Show();
            }
            else
            {
                //Del race
                using (var db = new ClubSiteContext())
                {
                    Race item = (from races in db.Races
                                 where races.Id == rUsed.Id
                                 select races).FirstOrDefault();
                    if (item == null)
                    {
                        // The item wasn't found
                        ModelState.AddModelError("", String.Format("Competición con id : {0} no encontrada", rUsed.Id));
                        X.Msg.Alert("Atención", "Competición no encontrada. Borrado cancelado,").Show();
                        return;
                    }
                    db.Races.Remove(item);
                    db.SaveChanges();
                    this.StoreGPRaces.DataBind();
                    X.Msg.Alert("Atención", "Competición borrada.").Show();

                    //Load data for first race type
                    rUsed = (from races in db.Races
                             orderby races.RaceDate descending, races.Name
                             select races).FirstOrDefault();
                    if (rUsed == null)
                    {
                        //Last item was erased. No items in BD.
                        rUsed = new Race();
                        X.Msg.Alert("Atención", "No queda ninguna competición registrada en la Base de datos.").Show();
                    }
                    oldRUsed.CopyRace(rUsed);
                    //Loads model object data into form
                    LoadRaceInForm(rUsed);
                }
            }
        }
Esempio n. 7
0
        private void LoadRaceInForm(Race aRace)
        {
            txbxID.Text = Convert.ToString(aRace.Id);
            txbxName.Text = aRace.Name;
            txbxDate.Text = aRace.RaceDate.ToShortDateString();
            imgImage.ImageUrl = aRace.ImageURL;
            imgImage.AlternateText = "(Sin imagen)";
            FileUImg.Text = "";
            //Load data for RaceType combo
            if (aRace.RaceTypeID == 0)
                cbRaceTypes.Value = "";
            else
            {
                object aRaceTypeID = aRace.RaceTypeID;
                cbRaceTypes.Select(aRaceTypeID);
            }
            //ListItem aValue = ddlRaceTypes.Items.FindByValue(txbxRaceTypeID.Text);
            //ddlRaceTypes.SelectedIndex = ddlRaceTypes.Items.IndexOf(aValue);

            if (aRace.Address == null)
            {
                txbxStreet.Text = null;
                txbxCity.Text = null;
                txbxPostalCode.Text = null;
                txbxCountry.Text = null;
                txbxNumber.Text = null;
            }
            else
            {
                txbxStreet.Text = aRace.Address.Street;
                txbxCity.Text = aRace.Address.City;
                txbxPostalCode.Text = aRace.Address.PostalCode;
                txbxCountry.Text = aRace.Address.Country;
                txbxNumber.Text = aRace.Address.Number;
            }
            txbxMemo.Text = aRace.Memo;

            ////To avoid problems with the , and . in decimal numbers
            System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("en-US");
            txbxLatitud.Text = Convert.ToString(aRace.Latitud, culture);
            txbxLongitud.Text = Convert.ToString(aRace.Longitud, culture);

            //Load Members taken part in actual race
            LoadDataInGridForMembersInRace();

            //Load age gropus for race
            LoadDataInGridForAgeGroups();

            //Load data for participants
            txbxPartGenFem.Text = Convert.ToString(aRace.PartFem);
            txbxPartGenMasc.Text = Convert.ToString(aRace.PartMasc);

            //Search points asigned to race an put on txbxPoints
            if (aRace.RaceTypeID == 0)
                txbxPoints.Text = "0";
            else if (aRace.RaceType != null)
                txbxPoints.Text = aRace.RaceType.Points.ToString();
        }
Esempio n. 8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                rUsed = new Race();
                oldRUsed = new Race();
                using (var db = new ClubSiteContext())
                {
                    rUsed = (from races in db.Races
                             orderby races.RaceDate descending, races.Name
                             select races).FirstOrDefault();

                    if (rUsed == null)
                    {
                        rUsed = new Race();
                        X.Msg.Alert("Atención", "No hay ningúna competición registrada en la Base de datos.").Show();
                    }

                    //Load data for racetypes combobox
                    LoadDataInGridForRaceTypes();

                    //Load data for clubbers combobox
                    LoadDataInGridForClubbers();

                    //Load data for Members in Race
                    LoadDataInGridForMembersInRace();

                    oldRUsed.CopyRace(rUsed);
                    LoadRaceInForm(rUsed);
                }
            }
        }
Esempio n. 9
0
        public void TestRaceConstructorWithoutData()
        {
            Int32 anID = 0;
            string aName = null;
            DateTime aRaceDate = DateTime.Now;
            Address anAddress = null;
            Int32 aRaceTypeId = 0;
            string aMemo = null;
            double aLatitud = 0;
            double aLongitud = 0;
            string aImgURL = null;

            Race aRace = new Race();

            Assert.AreEqual(anID, aRace.Id);
            Assert.AreEqual(aName, aRace.Name);
            Assert.AreEqual(aRaceDate.ToShortDateString(), aRace.RaceDate.ToShortDateString());
            Assert.AreEqual(anAddress, aRace.Address);
            Assert.AreEqual(aRaceTypeId, aRace.RaceTypeID);
            Assert.AreEqual(aMemo, aRace.Memo);
            Assert.AreEqual(aImgURL, aRace.ImageURL);
            Assert.AreEqual(aLatitud, aRace.Latitud);
            Assert.AreEqual(aLongitud, aRace.Longitud);
        }
Esempio n. 10
0
 public void CopyRace(Race aRace)
 {
     this.Id = aRace.Id;
     this.Name = aRace.Name;
     this.RaceDate = aRace.RaceDate;
     this.Address = aRace.Address;
     this.RaceTypeID = aRace.RaceTypeID;
     this.Memo = aRace.Memo;
     this.ImageURL = aRace.ImageURL;
     this.Latitud = aRace.Latitud;
     this.Longitud = aRace.Longitud;
     this.PartFem = aRace.PartFem;
     this.PartMasc = aRace.PartMasc;
 }