/// <summary>
        /// create a new tram
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAddSubmit_Click(object sender, EventArgs e)
        {
            int tramOnRail = 0;
            int status = 0;
            switch (ddlAddStatus.SelectedItem.Text) //get tram status
            {
                case "Ok":
                    status = 1;
                    break;
                case "Vies":
                    status = 2;
                    break;
                case "Defect":
                    status = 3;
                    break;
                case "Vies en Defect":
                    status = 4;
                    break;
            }

            if (cbAddOnTrack.Checked)
            {
                tramOnRail = 1;
            }
            Tram tram = new Tram(1, "test", new Rail(1, true, false, 1, "Combino"), new User(2323, "test", "test", 1), 1, true);
            if (tbAddName.Text != "")   //tram name cannot be emtpy
            {
                bool result = Int32.TryParse(tbAddName.Text, out number);
                if (result)
                {
                    //if there is already a tram on this rail, give message
                    ContentPlaceHolder cph = (ContentPlaceHolder)this.Master.FindControl("MainContent");
                    Label tlbl = (Label)cph.FindControl("rail" + ddlAddLocation.Text);
                    if (tlbl.BackColor != Color.DimGray)
                    {
                        //add the tram
                        if (
                                tram.AddTram(Convert.ToInt32(tbAddName.Text),
                                    Convert.ToInt32(ddlAddLocation.SelectedItem.Text),
                                status,
                                tramOnRail))
                        {
                            tram.Rail.Taken = true;
                            refreshGUI();   //refresh the GUI
                            return;
                        }
                        //error messages
                        ClientScript.RegisterStartupScript(Page.GetType(), "alert", "alert('Kan tram niet toevoegen');", true);
                        //ClientScript.RegisterStartupScript(GetType(), "myalert", "alert('Kan tram niet toevoegen')", true);
                    }
                    ClientScript.RegisterStartupScript(Page.GetType(), "alert", "alert('Er staat al een tram op dit spoor');", true);
                    //ClientScript.RegisterStartupScript(GetType(), "myalert", "alert('Er staat al een tram op dit spoor')", true);
                }
                ClientScript.RegisterStartupScript(Page.GetType(), "alert", "alert('Voer een nummer in');", true);
                //ClientScript.RegisterStartupScript(GetType(), "myalert", "alert('Voer een nummer in')", true);
            }
            ClientScript.RegisterStartupScript(Page.GetType(), "alert", "alert('Geef tramnummer mee');", true);
            //ClientScript.RegisterStartupScript(GetType(), "myalert", "alert('Geef tramnummer mee')", true);
        }
 public void TestTramOnRail()
 {
     Rail rail = new Rail(1, true, false, 1, "Combino");
     User user = new User(2323, "test", "test", 1);
     Tram tram = new Tram(1, "test", rail, user, 1, false);
     tram.OnRail = true;
     Assert.AreEqual(true, tram.OnRail, "Tram on rail");
 }
 public void TestMoveTram()
 {
     Rail rail = new Rail(1, true, false, 1, "Combino");
     Rail rail2 = new Rail(2, true, false, 1, "Combino");
     User user = new User(2323, "test", "test", 1);
     Tram tram = new Tram(1, "test", rail, user, 1, true);/*
     tram.AddTram(1, 1, 1, 1);
     tram.MoveTram(2, 1, 1);
     Assert.AreEqual(2, rail2.Id, "rail 2");*/
     Assert.AreEqual(1,1);
 }
 public void TestTramProperties()
 {
     Rail rail = new Rail(1, true, false, 1, "Combino");
     User user = new User(2323, "test", "test", 1);
     Tram tram = new Tram(1, "test", rail, user, 1, true);
     Assert.AreEqual(tram.Id, 1, "TramID");
     Assert.AreEqual(tram.Type, "test", "tramID");
     Assert.AreEqual(tram.Rail, rail, "tram rail");
     Assert.AreEqual(tram.Driver, user, "tram driver");
     Assert.AreEqual(tram.OnRail, true, "tram onrail");
     Assert.AreEqual(tram._Status, 1, "tram status");
 }
        public void Assign(Tram tram)
        {
            Rail rail = ReturnRail(tram);
            int tramnr = tram.Id;
            if (rail != null)
            {
                tram.Rail = rail;
                if (tram.Rail.Taken)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('A tram is already parked here. Unable to park this tram right now.')", true);
                }
                else
                {
                    if (tram.OnRail)
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('The tram is already parked and should be on its rail.')", true);
                    }
                    else
                    {
                        if (tram.Rail.IsRailBlocked(tram.Rail.Id))
                        {
                            ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('This rail is blocked')", true);
                        }
                        else
                        {
                            try
                            {
                                //rail = parkingsystem.InsertTramNr(Convert.ToInt32(tbTramnr.Text), status);
                                tram._Status = 1;
                                tram.OnRail = true;
                                tram.Rail.Taken = true;
                                if (!padatabase.RefreshRaildatabase(tram.Rail.Id, 1))
                                {
                                    ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('The raildatabase wasn't updated.')", true);
                                }
                                ///Fix update raillist
                                if (!padatabase.RefreshTramdatabase(tramnr))
                                {
                                    ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('The tramdatabase wasn't updated.')", true);
                                }
                            }
                            catch (NullReferenceException)
                            {
                                ClientScript.RegisterStartupScript(this.GetType(), "alert", "A rail with that number doesnt exist.", true);
                            }
                        }
                    }
                }

            }
            Updatedll();
        }
 /// <summary>
 /// not implemented
 /// </summary>
 /// <param name="tram"></param>
 /// <returns></returns>
 public bool DeleteTram(Tram tram)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// addon for enabling tabs. not used anymore
        /// </summary>
        /// <param name="page"></param>
        /// <param name="boolean"></param>
        // public void EnableTab(TabPage page, bool boolean)
        //{
        //    foreach (Control ctl in page.Controls) ctl.Enabled = boolean;
        //}
        public void UpdateTramList()
        {
            GetTramList.Clear();

                foreach (Dictionary<string, object> T in addatabase.GetAllTrams())
                {
                    Rail rail = null;
                    int status = 0;
                    bool onRail = false;

                if ((string)T["status"] == "Ok")
                    {
                        status = 1;
                    }
                if ((string)T["status"] == "Vies")
                    {
                        status = 2;
                    }
                if ((string)T["status"] == "Defect")
                    {
                        status = 3;
                    }
                if ((string)T["status"] == "ViesEnDefect")
                    {
                        status = 4;
                    }
                    if (Convert.ToInt32(T["aanwezigopspoor"]) == 0)
                    {
                        onRail = false;
                    }
                    else
                    {
                        onRail = true;
                    }
                    foreach (Rail R in Administration.GetRailList)
                    {
                        if (R.Id == Convert.ToInt32(T["spoorid"]))
                        {
                            rail = R;

                        }
                    }
                Tram t = new Tram(Convert.ToInt32(T["tramid"]), (string)T["type"], rail, LoggedInUser, status, onRail);
                    GetTramList.Add(t);
                }
        }
 /// <summary>
 /// notimplemented
 /// </summary>
 /// <param name="tram"></param>
 /// <returns></returns>
 public bool TramToDepartment(Tram tram)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Returns a Rail on which the tram can stand
 /// </summary>
 /// <param name="tram">The tram you want to get all posible tracks of</param>
 /// <returns>The rail</returns>
 public Rail ReturnRail(Tram tram)
 {
     List<Rail> Possibletracks = Login.administration.GetRailsOfType(tram.Type);
     if (Possibletracks.Count > 0)
     {
         return Possibletracks.First();
     }
     return null;
 }
 /// <summary>
 /// notimplemented
 /// </summary>
 /// <param name="tram"></param>
 /// <returns></returns>
 public string ChangeTramStatus(Tram tram)
 {
     throw new NotImplementedException();
 }
 protected void btnDriveInAssign_Click(object sender, EventArgs e)
 {
     Tram tram = new Tram(1, "test", new Rail(1, true, false, 1, "Combino"), new User(2323, "test", "test", 1), 1, true);
     if (lboxDriveInList.SelectedItem != null)
     {
         //updates the tram
         if (tram.MoveTram(Convert.ToInt32(lboxDriveInList.SelectedItem.Text),
             Convert.ToInt32(ddlDriveInLocation.SelectedItem.Text), 1))
         {
             refreshGUI();   //refresh GUI
             return;
         }
         ClientScript.RegisterStartupScript(Page.GetType(), "alert", "alert('Kan tram niet verplaatsen');", true);
         //ClientScript.RegisterStartupScript(GetType(), "myalert", "alert('Kan tram niet verplaatsen')", true);
     }
     ClientScript.RegisterStartupScript(Page.GetType(), "alert", "alert('Geen tram geselecteerd');", true);
     //ClientScript.RegisterStartupScript(GetType(), "myalert", "alert('Geen tram geselecteerd')", true);
 }
 /// <summary>
 /// Deletes the selected tram
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void btnDetailsRemove_Click(object sender, EventArgs e)
 {
     Tram tram = new Tram(1, "test", new Rail(1, true, false, 1, "Combino"), new User(2323, "test", "test", 1), 1, true);
     if (tbDetailsName.Text != "")
     {
         //tramname needs to be a number
         bool result = Int32.TryParse(tbDetailsName.Text, out number);
         if (result)
         {
             //delete the tram
             if (tram.DeleteTram(Convert.ToInt32(tbDetailsName.Text)) == true)
             {
                 //refresh the GUI
                 refreshGUI();
                 return;
             }
             //error messages
             ClientScript.RegisterStartupScript(Page.GetType(), "alert", "alert('Kan tram niet verwijderen');", true);
             //ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Kan tram niet verwijderen')",true);
         }
         ClientScript.RegisterStartupScript(Page.GetType(), "alert", "alert('Voer een nummer in');", true);
        // ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Voer een nummer in')", true);
     }
     ClientScript.RegisterStartupScript(Page.GetType(), "alert", "alert('Geef tramnummer mee');", true);
     //ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Geef tramnummer mee')", true);
 }
        /// <summary>
        /// Edit a tram
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnDetailsEdit_Click(object sender, EventArgs e)
        {
            Tram tram = new Tram(1, "test", new Rail(1, true, false, 1, "Combino"), new User(2323, "test", "test", 1), 1, true);
            int status = 0;
            switch (ddlDetailsStatus.SelectedItem.Text) //check the tram status
            {
                case "Ok":
                    status = 1;
                    break;
                case "Vies":
                    status = 2;
                    break;
                case "Defect":
                    status = 3;
                    break;
                case "Vies en Defect":
                    status = 4;
                    break;
            }

            if (tbDetailsName.Text != "")   //tram name cannot be empty
            {
                bool result = Int32.TryParse(tbDetailsName.Text, out number); //tram name needs to be a number
                if (result)
                {
                    //edit the tram
                    if (
                        tram.MoveTram(Convert.ToInt32(tbDetailsName.Text),
                            Convert.ToInt32(ddlDetailsLocation.SelectedItem.Text), status))
                    {
                        refreshGUI();   //refresh the GUI
                        return;
                    }
                    //error messages
                    ClientScript.RegisterStartupScript(Page.GetType(), "alert", "alert('Kan tram niet aanpassen');", true);
                    //ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Kan tram niet aanpassen')", true);
                }
                ClientScript.RegisterStartupScript(Page.GetType(), "alert", "alert('Voer een nummer in');", true);
                //ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Voer een nummer in')", true);
            }
            ClientScript.RegisterStartupScript(Page.GetType(), "alert", "alert('Geef tramnummer mee');", true);
            //ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Geef tramnummer mee')", true);
        }