예제 #1
0
        // A method used for saving the ShiftTemplate to the database by calling the Execute function
        public void SaveInfoShiftTemplate()
        {
            ShiftTemplate template = this;
            string        sql      = "INSERT INTO ShiftTemplate (start, end, tag) values ('" + template.StartTime.ToString() + "', '" + template.EndTime.ToString() + "', '" + Database.Instance.ListToString(template.Tag) + "')";

            Database.Instance.Execute(sql);
        }
        //Called when Delete Template is Clicked
        //Finds a ShiftTemplate, then removes it, then reloads list
        private void DeleteTemplate_Click(object sender, RoutedEventArgs e)
        {
            if (Core.Instance.GetAllTemplates().Count > 0 && TemplateList.SelectedItems.Count > 0)
            {
                ShiftTemplate toRemove = null;
                toRemove = Core.Instance.GetAllTemplates().Find(x => x.ToString() == ((ShiftTemplate)TemplateList.SelectedItem).ToString());

                if (toRemove != null)
                {
                    toRemove.DeleteShiftTemplate();
                }
            }
            LoadShift();
        }
예제 #3
0
파일: Core.cs 프로젝트: githuis/P2Manage
        public void LoadShiftTemplatesFromDatabase()
        {
            string sql = "SELECT * FROM ShiftTemplate";

            Database.Instance.Read(sql, ref _info, Database.Instance.ShiftTemplateTableColumns);
            ShiftTemplate t;

            foreach (var item in _info)
            {
                string[] split2 = item.Split(new Char[] { ',' });
                t = new ShiftTemplate(DateTime.Parse(split2[1]), DateTime.Parse(split2[2]), split2[3]);
                t.GeneratePrintableInfo();
                _allTemplates.Add(t);
            }
        }
예제 #4
0
파일: Core.cs 프로젝트: githuis/P2Manage
        // Serches the userlist for Users matching the tags in the specified ShiftTemplate
        private void GetCompatibleUsers(List <User> AllUsers, ShiftTemplate shiftTemplates, List <User> CompatibleUsers)
        {
            foreach (User u in AllUsers)
            {
                if (shiftTemplates.Tag.Any())
                {
                    CompatibleUsers.Add(u);
                }

                else if (CompareTags(u.Tags, shiftTemplates.Tag))
                {
                    CompatibleUsers.Add(u);
                }
            }
        }
        // If: Starttime is valid format, endtime is valid format and there is a day selected
        //starttime is before endtime
        //
        private void Save_ShiftTemplate(object sender, RoutedEventArgs e)
        {
            // If the bool isValidated at one of the checks is marked as false the ShiftTemplate will not be created.
            // Instead a message explaning the error will be written
            bool isValidated;

            if (!CheckIfValidTime(Start_Time.Text))
            {
                isValidated           = false;
                Error_message.Content = "Start time is not a valid hour format";
            }

            else if (!CheckIfValidTime(End_Time.Text))
            {
                isValidated           = false;
                Error_message.Content = "End time is not a valid minute format";
            }

            else if (Day_List.SelectedItem == null)
            {
                isValidated           = false;
                Error_message.Content = "A day haven't been selected";
            }
            else if (CompareTime(Start_Time.Text, End_Time.Text))
            {
                isValidated           = false;
                Error_message.Content = "Start time must be before end time";
            }
            else
            {
                isValidated = true;
            }

            // If all validation checkout then the ShiftTemplate infomration is exstracted and saved to the database
            if (isValidated == true)
            {
                ListBoxItem SelectedDay = Day_List.SelectedItem as ListBoxItem;

                int DayInWeek = 0;
                switch (SelectedDay.Content.ToString())
                {
                case "Monday":
                    DayInWeek = 1;
                    break;

                case "Tuesday":
                    DayInWeek = 2;
                    break;

                case "Wednesday":
                    DayInWeek = 3;
                    break;

                case "Thursday":
                    DayInWeek = 4;
                    break;

                case "Friday":
                    DayInWeek = 5;
                    break;

                case "Saturday":
                    DayInWeek = 6;
                    break;

                case "Sunday":
                    DayInWeek = 7;
                    break;

                default:
                    DayInWeek = 0;
                    break;
                }

                // Creates a datetime with the given times.
                DateTime Start;
                DateTime End;
                string   s = DayInWeek + "/01/2007 ";
                string   t = s;
                s += Start_Time.Text;
                t += End_Time.Text;
                s += ":00";
                t += ":00";

                // If the datatime is not able to be parsed to a DataTime object, the ShiftTemplate is not made
                // As of the validation this should not be able to happen
                if (!(DateTime.TryParse(s, out Start) && DateTime.TryParse(t, out End)))
                {
                    throw new ArgumentException("Start or End is not a valid datetime");
                }

                // Gets the selected tags and adds them to a list of strings
                List <string> TemplateTags = new List <string>();
                foreach (ListBoxItem item in Tag_List.SelectedItems)
                {
                    string tag = item.Content.ToString();
                    TemplateTags.Add(tag);
                }

                // The ShiftTemplate object is made with the gathered information
                ShiftTemplate shiftTemplate = new ShiftTemplate(Start, End, Database.Instance.ListToString(TemplateTags));
                shiftTemplate.SaveInfoShiftTemplate();

                // After the object is saved it is saved to the database and the inputboxes are cleared
                Core.Instance.AddTemplateToList(shiftTemplate);
                Start_Time.Clear();
                End_Time.Clear();
                Error_message.Content = "";
                Tag_List.UnselectAll();
                LoadShift();
            }
        }
예제 #6
0
파일: Core.cs 프로젝트: githuis/P2Manage
 public void AddTemplateToList(ShiftTemplate template)
 {
     _allTemplates.Add(template);
 }