Example #1
0
 private void listbox_Show_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if ((string)lbl_Title.Content == "Jobs")
     {
         JobO chosenJob = (JobO)listbox_Show.SelectedItem;
         SelectedTemp.ChosenJob = chosenJob;
         ShowDetails sdJ = new ShowDetails((string)lbl_Title.Content);
         sdJ.Show();
         this.Close();
     }
     else if ((string)lbl_Title.Content == "Users")
     {
         UserO chosenUser = (UserO)listbox_Show.SelectedItem;
         SelectedTemp.ChosenUser = chosenUser;
         ShowDetails sdU = new ShowDetails((string)lbl_Title.Content);
         sdU.Show();
         this.Close();
     }
     else if ((string)lbl_Title.Content == "Tarif")
     {
         TO chosenTarif = (TO)listbox_Show.SelectedItem;
         SelectedTemp.ChosenTarif = chosenTarif;
         ShowDetails sdT = new ShowDetails((string)lbl_Title.Content);
         sdT.Show();
         this.Close();
     }
     else if ((string)lbl_Title.Content == "ESPs")
     {
         ESPO chosenESP = (ESPO)listbox_Show.SelectedItem;
         SelectedTemp.ChosenESP = chosenESP;
         ShowDetails sdESP = new ShowDetails((string)lbl_Title.Content);
         sdESP.Show();
         this.Close();
     }
     else if ((string)lbl_Title.Content == "Resources")
     {
         RO chosenR = (RO)listbox_Show.SelectedItem;
         SelectedTemp.ChosenR = chosenR;
         ShowDetails sdR = new ShowDetails((string)lbl_Title.Content);
         sdR.Show();
         this.Close();
     }
     else if ((string)lbl_Title.Content == "ResourceTypes")
     {
         RTO chosenRT = (RTO)listbox_Show.SelectedItem;
         SelectedTemp.ChosenRT = chosenRT;
         ShowDetails sdRT = new ShowDetails((string)lbl_Title.Content);
         sdRT.Show();
         this.Close();
     }
 }
Example #2
0
        //By BKP
        private static DateTime CalculateBestSpot(Queue queue, JobO currentJob)
        {
            DateTime    now           = DateTime.Now;
            DateTime?   ESPtempTime   = null;
            DateTime?   TarifTempTime = null;
            DateTime    tempTime      = new DateTime();
            List <ESPO> avaibleESPs   = DB.GetESPs(now, currentJob.Deadline);
            List <TO>   avaibleTarifs = DB.SelectAllTarifs(true);

            for (int i = 0; i < avaibleESPs.Count; i++)
            {
                ESPO currentESP = avaibleESPs[i];
                ESPtempTime = FindSpotInEsp(currentESP, currentJob, now);
                if (ESPtempTime != null)
                {
                    tempTime = (DateTime)ESPtempTime;
                    i        = avaibleESPs.Count;
                }
            }
            if (ESPtempTime == null)
            {
                for (int t = 0; t < avaibleTarifs.Count; t++)
                {
                    TO currentTarif = avaibleTarifs[t];
                    TarifTempTime = FindSpotInTarif(currentTarif, currentJob, now);
                    if (TarifTempTime != null)
                    {
                        tempTime = (DateTime)TarifTempTime;
                        t        = avaibleTarifs.Count;
                    }
                }
            }


            return(tempTime);

            /*int hour = 00;
             * tempTime = Convert.ToDateTime($"{hour}:00:00");
             * int index = queue.jobsInQueue.FindIndex(item => item.ExeTime == tempTime);
             * if (index < 0)
             * {
             *  return tempTime;
             * }
             * else
             * {
             *  hour++;
             *  tempTime = Convert.ToDateTime($"{hour}:00:00");
             *  return tempTime;
             * }*/
        }
Example #3
0
        public static List <TO> SelectAllTarifs(bool OrderByAsc)
        {
            List <TO> tList = new List <TO>();

            OpenConnection();
            SqlCommand    getT   = new SqlCommand("SELECT * FROM Tarif ORDER BY Price ASC", myConnection);
            SqlDataReader reader = getT.ExecuteReader();

            while (reader.Read())
            {
                TO t = new TO();
                t.StartTime = reader.GetTimeSpan(1);
                t.EndTime   = reader.GetTimeSpan(2);
                t.Cost      = reader.GetDouble(3);
                t.TarifID   = reader.GetInt32(0);
                tList.Add(t);
            }
            CloseConnection();
            return(tList);
        }
Example #4
0
        public ShowDetails(string subject)
        {
            InitializeComponent();
            if (CurrentUser.IsAdmin == false)
            {
                btn_Delete.IsEnabled = false;
                btn_Edit.IsEnabled   = false;
            }

            if (subject == "Jobs")
            {
                lbl_Title.Content = "Job";
                JobO chosenJob = SelectedTemp.ChosenJob;
                lbl_CreatedFill.Content  = chosenJob.Created;
                lbl_DeadlineFill.Content = chosenJob.Deadline;
                UserO createdBy = DB.GetUser(chosenJob.CreatedUserID);
                lbl_CreatedByFill.Content = (createdBy.FirstName + "" + createdBy.SurName);
                lbl_NameFill.Content      = chosenJob.JobName;
                lbl_PriorityFill.Content  = chosenJob.Priority;
            }
            else if (subject == "Users")
            {
                lbl_Title.Content = "User";
                UserO chosenUser = SelectedTemp.ChosenUser;
                lbl_NameTitle.Content      = ("Username: "******"Fornavn: ");
                lbl_CreatedTitle.Content   = ("Efternavn: ");
                lbl_DeadlineTitle.Content  = ("Password: "******"Is User admin:");
                lbl_NameFill.Content       = chosenUser.UserName;
                lbl_CreatedByFill.Content  = chosenUser.FirstName;
                lbl_CreatedFill.Content    = chosenUser.SurName;
                lbl_DeadlineFill.Content   = chosenUser.Password;
                lbl_PriorityFill.Content   = chosenUser.IsAdmin;
            }
            else if (subject == "Tarif")
            {
                lbl_Title.Content = "Tarif";
                TO chosenTarif = SelectedTemp.ChosenTarif;
                lbl_NameTitle.Content      = ("Price: ");
                lbl_CreatedByTitle.Content = ("Start: ");
                lbl_CreatedTitle.Content   = ("End: ");
                lbl_DeadlineTitle.Content  = ("");
                lbl_PriorityTitle.Content  = ("");
                lbl_NameFill.Content       = chosenTarif.Cost;
                lbl_CreatedByFill.Content  = chosenTarif.StartTime;
                lbl_CreatedFill.Content    = chosenTarif.EndTime;
            }
            else if (subject == "ESPs")
            {
                lbl_Title.Content = "ESP";
                ESPO chosenESP = SelectedTemp.ChosenESP;
                lbl_NameTitle.Content      = ("Energy Surplus: ");
                lbl_CreatedByTitle.Content = ("Start date: ");
                lbl_CreatedTitle.Content   = ("End date: ");
                lbl_DeadlineTitle.Content  = ("start time: ");
                lbl_PriorityTitle.Content  = ("End time: ");
                lbl_NameFill.Content       = chosenESP.EnergySurplus;
                lbl_CreatedByFill.Content  = chosenESP.StartDate;
                lbl_CreatedFill.Content    = chosenESP.EndDate;
                lbl_DeadlineFill.Content   = chosenESP.StartTime;
                lbl_PriorityFill.Content   = chosenESP.EndTime;
            }
            else if (subject == "Resources")
            {
                RO chosenR = SelectedTemp.ChosenR;
                lbl_Title.Content          = "Resource";
                lbl_NameTitle.Content      = ("Name: ");
                lbl_CreatedByTitle.Content = ("");
                lbl_CreatedTitle.Content   = ("");
                lbl_DeadlineTitle.Content  = ("");
                lbl_PriorityTitle.Content  = ("");
                lbl_NameFill.Content       = chosenR.Name;
            }
            else if (subject == "ResourceTypes")
            {
                RTO chosenRT = SelectedTemp.ChosenRT;
                lbl_Title.Content          = "Resource type";
                lbl_NameTitle.Content      = ("Name: ");
                lbl_CreatedByTitle.Content = ("");
                lbl_CreatedTitle.Content   = ("");
                lbl_DeadlineTitle.Content  = ("");
                lbl_PriorityTitle.Content  = ("");
                lbl_NameFill.Content       = chosenRT.Name;
            }
        }
Example #5
0
        private static DateTime?FindSpotInTarif(TO currentTarif, JobO currentJob, DateTime now)
        {
            DateTime tarifStart = DateTime.Today + currentTarif.StartTime;
            DateTime?startDateTime = null;
            DateTime tarifEnd = DateTime.Today + currentTarif.EndTime, possibleStart = now, possibleEnd, soonestStart = now;
            bool     spotFound;
            bool     needToResetToTarifStart = true;

            if (currentTarif.EndTime < currentTarif.StartTime)
            {
                tarifEnd = DateTime.Today.AddDays(1) + currentTarif.EndTime;
            }
            else
            {
                tarifEnd = DateTime.Today + currentTarif.EndTime;
            }

            if (tarifStart < now && tarifEnd < now)
            {
                tarifEnd   = tarifEnd.AddDays(1);
                tarifStart = tarifStart.AddDays(1);
            }

            if (tarifStart > possibleStart)
            {
                soonestStart            = tarifStart;
                needToResetToTarifStart = false;
            }
            DateTime testDeadline = currentJob.Deadline.AddDays(1);

            while (testDeadline >= tarifEnd)
            {
                possibleStart = soonestStart;

                int jobHours = currentJob.DurationHours;
                possibleEnd = possibleStart.AddHours(jobHours);
                while (possibleEnd <= tarifEnd && currentJob.Deadline >= possibleEnd)
                {
                    spotFound = DB.IsResourceAvailable(possibleStart, possibleEnd, currentJob);
                    if (spotFound == true)
                    {
                        startDateTime = possibleStart;
                        return(startDateTime);
                    }
                    possibleStart = possibleStart.AddHours(1);
                    possibleEnd   = possibleStart.AddHours(jobHours);
                }
                if (needToResetToTarifStart)
                {
                    soonestStart = tarifStart.AddDays(1);
                }
                else
                {
                    soonestStart            = soonestStart.AddDays(1);
                    needToResetToTarifStart = false;
                }

                tarifEnd = tarifEnd.AddDays(1);
            }

            return(startDateTime);
        }