Exemplo n.º 1
0
 public void CopyRaceType(RaceType aRaceType)
 {
     this.RaceTypeID = aRaceType.RaceTypeID;
     this.Name = aRaceType.Name;
     this.Points = aRaceType.Points;
     this.Memo = aRaceType.Memo;
     this.SportID = aRaceType.SportID;
 }
Exemplo n.º 2
0
 public void CopyRaceType(RaceType aRaceType)
 {
     this.RaceTypeID = aRaceType.RaceTypeID;
     this.Name       = aRaceType.Name;
     this.Points     = aRaceType.Points;
     this.Memo       = aRaceType.Memo;
     this.SportID    = aRaceType.SportID;
 }
Exemplo n.º 3
0
        public void TestClearRaceTypeOldRaceTypePresent()
        {
            Int32 anID = 10;
            string aName = "Super Sprint";
            int points = 20;
            string aMemo = "Triathlón Super Sprint (350/10/2,5)";
            int aSportID = 1;

            RaceType aRaceType = new RaceType(anID, aName, points, aMemo, aSportID);
            RaceType oldRaceType = new RaceType();

            Assert.AreEqual(anID, aRaceType.RaceTypeID);
            Assert.AreEqual(aName, aRaceType.Name);
            Assert.AreEqual(points, aRaceType.Points);
            Assert.AreEqual(aMemo, aRaceType.Memo);
            Assert.AreEqual(aSportID, aRaceType.SportID);

            Assert.AreEqual(0, oldRaceType.RaceTypeID);
            Assert.AreEqual(null, oldRaceType.Name);
            Assert.AreEqual(0, oldRaceType.Points);
            Assert.AreEqual(null, oldRaceType.Memo);
            Assert.AreEqual(0, oldRaceType.SportID);

            oldRaceType.CopyRaceType(aRaceType);

            Assert.AreEqual(anID, aRaceType.RaceTypeID);
            Assert.AreEqual(aName, aRaceType.Name);
            Assert.AreEqual(points, aRaceType.Points);
            Assert.AreEqual(aMemo, aRaceType.Memo);
            Assert.AreEqual(aSportID, aRaceType.SportID);

            Assert.AreEqual(anID, oldRaceType.RaceTypeID);
            Assert.AreEqual(aName, oldRaceType.Name);
            Assert.AreEqual(points, oldRaceType.Points);
            Assert.AreEqual(aMemo, oldRaceType.Memo);
            Assert.AreEqual(aSportID, oldRaceType.SportID);

            aRaceType.ClearRaceType();

            Assert.AreEqual(0, aRaceType.RaceTypeID);
            Assert.AreEqual(null, aRaceType.Name);
            Assert.AreEqual(0, aRaceType.Points);
            Assert.AreEqual(null, aRaceType.Memo);
            Assert.AreEqual(0, aRaceType.SportID);

            Assert.AreEqual(anID, oldRaceType.RaceTypeID);
            Assert.AreEqual(aName, oldRaceType.Name);
            Assert.AreEqual(points, oldRaceType.Points);
            Assert.AreEqual(aMemo, oldRaceType.Memo);
            Assert.AreEqual(aSportID, oldRaceType.SportID);
        }
Exemplo n.º 4
0
        public void TestRaceTypeConstructorWithData()
        {
            Int32 anID = 10;
            string aName = "Super Sprint";
            int points = 20;
            string aMemo = "Triathlón Super Sprint (350/10/2,5)";
            int aSportID = 1;

            RaceType aRaceType = new RaceType(anID,aName,points,aMemo,aSportID);

            Assert.AreEqual(anID, aRaceType.RaceTypeID);
            Assert.AreEqual(aName, aRaceType.Name);
            Assert.AreEqual(points, aRaceType.Points);
            Assert.AreEqual(aMemo, aRaceType.Memo);
            Assert.AreEqual(aSportID, aRaceType.SportID);
        }
Exemplo n.º 5
0
        public void TestRaceTypeConstructorWithoutData()
        {
            Int32 anID=0;
            string aName=null;
            int points=0;
            string aMemo = null;
            Int32 aSportID = 0;

            RaceType aRaceType = new RaceType();

            Assert.AreEqual(anID, aRaceType.RaceTypeID);
            Assert.AreEqual(aName, aRaceType.Name);
            Assert.AreEqual(points, aRaceType.Points);
            Assert.AreEqual(aMemo, aRaceType.Memo);
            Assert.AreEqual(aSportID, aRaceType.SportID);
        }
Exemplo n.º 6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                rtUsed = new RaceType();
                oldRtUsed = new RaceType();
                using (var db = new ClubSiteContext())
                {
                    rtUsed = (from raceTypes in db.RaceTypes
                              orderby raceTypes.Name
                              select raceTypes).FirstOrDefault();

                    if (rtUsed == null)
                    {
                        rtUsed = new RaceType();
                        X.Msg.Alert("Atención", "No hay ningún tipo de competición registrada en la Base de datos.").Show();
                    }
                    oldRtUsed.CopyRaceType(rtUsed);
                    LoadRaceTypeInForm(rtUsed);

                    Store store = this.cbxDeportes.GetStore();
                    store.DataSource = from s in db.Sports select new { s.SportID, s.Name };
                    store.DataBind();
                }
            }
        }
Exemplo n.º 7
0
        protected void GridPanel1_Cell_Click(object sender, EventArgs e)
        {
            try
            {
                CellSelectionModel sm = this.GridPanel1.GetSelectionModel() as CellSelectionModel;
                Int32 actualRtId = Convert.ToInt32(sm.SelectedCell.RecordID);
                using (var db = new ClubSiteContext())
                {
                    rtUsed = (from raceTypes in db.RaceTypes
                              orderby raceTypes.Name
                              where raceTypes.RaceTypeID == actualRtId
                              select raceTypes).FirstOrDefault();

                    if (rtUsed == null)
                        X.Msg.Alert("Atención", "No hay ningún tipo de competición registrada en la Base de datos.").Show();
                    oldRtUsed.CopyRaceType(rtUsed);

                    //Loads model object data into form
                    LoadRaceTypeInForm(rtUsed);
                }
            }
            catch (Exception) { }
            btnBorrar.Enabled = true;
        }
Exemplo n.º 8
0
 public void LoadRaceTypeInForm(RaceType aRaceType)
 {
     txbxId.Text = Convert.ToString(aRaceType.RaceTypeID);
     //txbxSportID.Text = Convert.ToString(aRaceType.SportID);
     if (aRaceType.SportID == 0)
         cbxDeportes.Value = "";
     else
     {
         object SportID = aRaceType.SportID;
         cbxDeportes.Select(SportID);
     }
     txbxName.Text = aRaceType.Name;
     try
     {
         txbxPuntos.Text = Convert.ToString(aRaceType.Points);
     }
     catch (Exception)
     {
         txbxPuntos.Text = "0";
     }
     txbxMemo.Text = aRaceType.Memo;
 }
Exemplo n.º 9
0
        public void DoSave()
        {
            bool sigue = true;
            int points = 0;
            int aSportIDSelected = 0;
            string messageError = null;

            //Verify name exists
            if (txbxName.Text == "")
            {
                sigue = false;
                messageError = "Falta el nombre del tipo de competición.";
            }

            //Verify points exists and are between 0 and 10.000
            if (sigue)
            {
                try
                {
                    points = Convert.ToInt32(txbxPuntos.Text);
                    if (points < 0 || points > 10000)
                    {
                        sigue = false;
                        messageError="Los puntos asignados deben ser un número entre 0 y 10.000";
                    }
                }
                catch (Exception)
                {
                    sigue = false;
                    messageError="Debes asignar un valor numérico entre 0 y 10.000 para los puntos.";
                }
            }

            //Verify is a SportID was choosed.
            if (sigue)
            {
                try
                {
                    aSportIDSelected = Convert.ToInt32(cbxDeportes.SelectedItem.Value);//Convert.ToInt32(txbxSportID.Text);
                    if (aSportIDSelected <= 0)
                    {
                        sigue = false;
                        messageError = "Escoje el tipo de deporte al que pertenece la competición.";
                    }
                }
                catch (Exception)
                {
                    sigue = false;
                    messageError = "Escoje el tipo de deporte al que pertenece la competición.";
                }
            }

            //Save if conditions are ok.
            if (sigue)
            {
                using (var db = new ClubSiteContext())
                {
                    RaceType aRacetype;
                    if (rtUsed.RaceTypeID == 0)
                    { //New Race Type
                        aRacetype = new RaceType();
                        aRacetype.Name = txbxName.Text;
                        aRacetype.Points = points;
                        aRacetype.SportID = aSportIDSelected;
                        aRacetype.Memo = txbxMemo.Text;
                        db.RaceTypes.Add(aRacetype);
                    }
                    else
                    { //Update actual Race Type
                        aRacetype = (from racetypes in db.RaceTypes
                                     where racetypes.RaceTypeID == rtUsed.RaceTypeID
                                     select racetypes).FirstOrDefault();
                        if (aRacetype == null)
                        {
                            // The item wasn't found
                            ModelState.AddModelError("", String.Format("Tipo de competición con Id : {0} no encontrada", rtUsed.RaceTypeID));
                            X.Msg.Alert("Atención","Tipo de competición no encontrada").Show();
                            return;
                        }
                        aRacetype.Name = txbxName.Text;
                        aRacetype.Points = points;
                        aRacetype.SportID = aSportIDSelected;
                        aRacetype.Memo = txbxMemo.Text;
                    }
                    db.SaveChanges();
                    LoadRaceTypeInForm(aRacetype);  //To update the ID (identity file)
                    rtUsed.CopyRaceType(aRacetype);
                    oldRtUsed.CopyRaceType(rtUsed);
                    this.Store1.DataBind();
                    X.Msg.Alert("Atención", "Nuevo tipo de competición grabada.").Show();
                }
                btnBorrar.Enabled = true;
            }
            else
            {
                X.Msg.Alert("Atención", messageError).Show();
            }
        }
Exemplo n.º 10
0
        public void DoDel()
        {
            Notification.Show(new NotificationConfig { Title = "Aviso", Icon = Icon.Information, Html = "Borrando el tipo de competición en pantalla." });
            if (rtUsed.RaceTypeID == 0)
            { //No Race Type selected
                X.Msg.Alert("Atención", "No hay nada que borrar ya que no hay tipos de competición registrados.").Show();
            }
            else
            {
                //Del racetype
                using (var db = new ClubSiteContext())
                {
                    RaceType item = (from racetypes in db.RaceTypes
                                     where racetypes.RaceTypeID == rtUsed.RaceTypeID
                                     select racetypes).FirstOrDefault();
                    if (item == null)
                    {
                        // The item wasn't found
                        ModelState.AddModelError("", String.Format("Tipo de competición con id : {0} no encontrada", rtUsed.RaceTypeID));
                        X.Msg.Alert("Atención", "Tipo de competición no encontrada. Borrado cancelado,").Show();
                        return;
                    }
                    db.RaceTypes.Remove(item);
                    db.SaveChanges();
                    this.Store1.DataBind();
                    X.Msg.Alert("Atención", "Tipo de competición borrada.").Show();

                    //Load data for first race type
                    rtUsed = (from raceTypes in db.RaceTypes
                              orderby raceTypes.Name
                              select raceTypes).FirstOrDefault();
                    if (rtUsed == null)
                    {
                        //Last item was erased. No items in BD.
                        rtUsed = new RaceType();
                        X.Msg.Alert("Atención", "No queda ningún tipo de competición registrada en la Base de datos.").Show();
                    }
                    oldRtUsed.CopyRaceType(rtUsed);
                    //Loads model object data into form
                    LoadRaceTypeInForm(rtUsed);
                }
            }
        }