コード例 #1
0
        internal static List <ESPO> GetESPs(DateTime now, DateTime endDate)
        {
            List <ESPO> eList = new List <ESPO>();

            OpenConnection();
            SqlCommand getESP = new SqlCommand("SELECT DISTINCT * FROM ESP WHERE (StartDate > @startDate OR StartDate < @endDate) OR (EndDate > @startDate OR EndDate < @endDate) ORDER BY EnergySurplus DESC", myConnection);

            getESP.Parameters.Add("@startDate", SqlDbType.DateTime);
            getESP.Parameters["@startDate"].Value = now;
            getESP.Parameters.Add("@endDate", SqlDbType.DateTime);
            getESP.Parameters["@endDate"].Value = endDate;
            SqlDataReader reader = getESP.ExecuteReader();

            while (reader.Read())
            {
                ESPO e = new ESPO();
                e.StartDate     = reader.GetDateTime(1);
                e.EndDate       = reader.GetDateTime(2);
                e.StartTime     = reader.GetTimeSpan(3);
                e.EndTime       = reader.GetTimeSpan(4);
                e.EnergySurplus = reader.GetDouble(5);
                eList.Add(e);
            }
            CloseConnection();
            return(eList);
        }
コード例 #2
0
ファイル: Scheduler.cs プロジェクト: xZjarr/Alpha-KHMB
        private static DateTime?FindSpotInEsp(ESPO currentESP, JobO currentJob, DateTime now)
        {
            DateTime soonestStart = DateTime.Today + currentESP.StartTime;
            DateTime ESPEnd, possibleStart, possibleEnd, ESPFinalEnd = currentESP.EndDate + currentESP.EndTime;
            DateTime?startDateTime = soonestStart;
            bool     spotFound;


            if (currentESP.EndTime < currentESP.StartTime)
            {
                ESPEnd = DateTime.Today.AddDays(1) + currentESP.EndTime;
            }
            else
            {
                ESPEnd = DateTime.Today + currentESP.EndTime;
            }
            if (soonestStart < now && ESPEnd < now)
            {
                soonestStart = soonestStart.AddDays(1);
                ESPEnd       = ESPEnd.AddDays(1);
            }

            while (soonestStart < currentESP.EndDate)
            {
                if (currentJob.Deadline > ESPEnd)
                {
                    possibleStart = soonestStart;

                    int jobHours = currentJob.DurationHours;
                    possibleEnd = possibleStart.AddHours(jobHours);
                    while (possibleEnd <= ESPEnd)
                    {
                        spotFound = DB.IsResourceAvailable(possibleStart, possibleEnd, currentJob);
                        if (spotFound == true)
                        {
                            startDateTime = possibleStart;
                            return(startDateTime);
                        }
                        possibleStart = possibleStart.AddHours(1);
                        possibleEnd   = possibleStart.AddHours(jobHours);
                    }
                    startDateTime = null;
                }
                else
                {
                    startDateTime = null;
                }
                soonestStart = soonestStart.AddDays(1);
                ESPEnd       = ESPEnd.AddDays(1);
            }

            return(startDateTime);
        }
コード例 #3
0
ファイル: ShowList.xaml.cs プロジェクト: xZjarr/Alpha-KHMB
 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();
     }
 }
コード例 #4
0
ファイル: Scheduler.cs プロジェクト: xZjarr/Alpha-KHMB
        //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;
             * }*/
        }
コード例 #5
0
        public static List <ESPO> SelectAllESP()
        {
            List <ESPO> eList = new List <ESPO>();

            OpenConnection();
            SqlCommand    getESP = new SqlCommand("SELECT * FROM ESP", myConnection);
            SqlDataReader reader = getESP.ExecuteReader();

            while (reader.Read())
            {
                ESPO e = new ESPO();
                e.StartDate     = reader.GetDateTime(1);
                e.EndDate       = reader.GetDateTime(2);
                e.StartTime     = reader.GetTimeSpan(3);
                e.EndTime       = reader.GetTimeSpan(4);
                e.EnergySurplus = reader.GetDouble(5);
                e.ESP_ID        = reader.GetInt32(0);
                eList.Add(e);
            }
            CloseConnection();
            return(eList);
        }
コード例 #6
0
ファイル: ShowDetails.xaml.cs プロジェクト: xZjarr/Alpha-KHMB
        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;
            }
        }