Exemplo n.º 1
0
        public static FrameworkElement GenAppropriateElement(Column c, out string title, bool isPKeyEditable = false, bool containsSuggestedValue = false)
        {
            FrameworkElement elem;

            title = c.Name;
            // If the item displays a primary key, it is not editable by the user, so a label is used to display the data without it being editable
            if (c.Constraints.IsPrimaryKey && !isPKeyEditable)
            {
                elem = new Label()
                {
                    Content = "",
                    Margin  = new Thickness(0, -5, 0, 0)
                };
            }
            // An SQL bit is a boolean value, so a checkbox can be used to help prevent insertion of invalid data
            else if (c.Constraints.Type == "bit")
            {
                elem = new CheckBox()
                {
                    Margin          = new Thickness(5, 0, 0, 0),
                    RenderTransform = new ScaleTransform(2, 2)
                };
                if (containsSuggestedValue)
                {
                    ((CheckBox)elem).IsChecked = (bool)GetSuggestedValue(c);
                }
            }
            else if (c.Constraints.Type == "date")
            {
                elem = new ValidatedDatePicker(c)
                {
                    Margin              = new Thickness(5, 0, 0, 0),
                    FontSize            = 16,
                    HorizontalAlignment = HorizontalAlignment.Left,
                    VerticalAlignment   = VerticalAlignment.Top
                };
            }
            else if (c.Name == "Appointment Type ID" && !c.Constraints.IsPrimaryKey)
            {
                elem = new ComboBox()
                {
                    ItemsSource = DBMethods.MetaRequests.GetAllFromTable("Appointment Type").Select(x => x[3]),
                    Margin      = new Thickness(5, 0, 0, 0)
                };
                title = "Appointment Type";
            }
            else if (c.Name == "Staff ID" && !c.Constraints.IsPrimaryKey)
            {
                elem = new ComboBox()
                {
                    ItemsSource = DBMethods.MetaRequests.GetAllFromTable("Staff").Select(x => x[1]),
                    Margin      = new Thickness(5, 0, 0, 0)
                };
                title = "Staff Member";
            }
            else if (c.Name == "Grooming Room ID" && !c.Constraints.IsPrimaryKey)
            {
                elem = new ComboBox()
                {
                    ItemsSource = DBMethods.MetaRequests.GetAllFromTable("Grooming Room").Select(x => x[1]),
                    Margin      = new Thickness(5, 0, 0, 0)
                };
                title = "Grooming Room";
            }
            // Otherwise, a text box is used to allow the user to enter data
            else
            {
                elem = new ValidatedTextbox(c)
                {
                    Margin = new Thickness(5, 0, 0, 0),
                    HorizontalAlignment = HorizontalAlignment.Left,
                    VerticalAlignment   = VerticalAlignment.Top
                };

                // If the text box has the potential of containing a lot of data, double its height to allow the text it contains to be easier to read.
                if (c.Constraints.Type == "varchar")
                {
                    if (Convert.ToInt32(c.Constraints.MaxSize) > 50)
                    {
                        ((ValidatedTextbox)elem).SetHeight(elem.Height * 2);
                    }
                }
            }

            if (elem is ComboBox cmb && containsSuggestedValue)
            {
                cmb.SelectedIndex = 0;
            }

            if (elem is ValidatedItem item && containsSuggestedValue)
            {
                item.Text = GetSuggestedValue(c).ToString();
            }


            return(elem);
        }
Exemplo n.º 2
0
        public ShiftManager()
        {
            InitializeComponent();

            shiftColumns    = DBObjects.DB.Tables.Where(t => t.Name == "Shift").First().Columns;
            shiftExcColumns = DBObjects.DB.Tables.Where(t => t.Name == "Shift Exception").First().Columns;

            // Get the colours for filters
            colours = new Color[]
            {
                Color.FromRgb(183, 28, 28),                // Red
                Color.FromRgb(2, 119, 189),                // Blue
                Color.FromRgb(190, 96, 0),                 // Dark orange? Not quite brown
                Color.FromRgb(46, 125, 50),                // Green
                Color.FromRgb(49, 27, 146)                 // Deep Purple
            };

            rctBase.Width  = dayWidth;
            rctBase.Height = hourHeight * 7;
            rctBase.Fill   = Brushes.Orange;

            List <List <string> > staffData   = MetaRequests.GetAllFromTable("Staff");
            List <Panel>          staffPanels = new List <Panel>();

            foreach (List <string> staff in staffData)
            {
                staffPanels.Add(GenForStaff(staff.ToArray()));
            }

            List <List <string> > shiftData = MetaRequests.GetAllFromTable("Shift");

            foreach (List <string> shift in shiftData)
            {
                Panel shiftPanel = GenShiftWithData(shift.ToArray());
                staffPanels[Convert.ToInt32(shift[1])].Children.Add(shiftPanel);
            }

            UpdateShiftExcs();

            FrameworkElement elemNewExStaff = UIMethods.GenAppropriateElement(shiftExcColumns[1], out _, false, true);

            elemNewExStaff.LayoutTransform = new ScaleTransform(1.5, 1.5);
            elemNewExStaff.Margin          = new Thickness(0, 0, 10, 0);
            stpNewExc.Children.Add(elemNewExStaff);

            ValidatedDatePicker dtpNewExStart = new ValidatedDatePicker(shiftExcColumns[2]);

            dtpNewExStart.ToggleImage();
            dtpNewExStart.SetWidth(160);
            dtpNewExStart.SelectedDate = DateTime.Now.Date;
            stpNewExc.Children.Add(dtpNewExStart);

            Label lbl = new Label()
            {
                Content  = " to ",
                FontSize = 20
            };

            stpNewExc.Children.Add(lbl);

            ValidatedDatePicker dtpNewExEnd = new ValidatedDatePicker(shiftExcColumns[3]);

            dtpNewExEnd.ToggleImage();
            dtpNewExEnd.SetWidth(160);
            dtpNewExEnd.SelectedDate = DateTime.Now.Date.AddDays(7);
            stpNewExc.Children.Add(dtpNewExEnd);

            Button btnConfirmNewEx = new Button()
            {
                Content             = " Submit ",
                FontSize            = 20,
                HorizontalAlignment = HorizontalAlignment.Right
            };

            btnConfirmNewEx.Click += BtnConfirmNewEx_Click;
            grdNewExc.Children.Add(btnConfirmNewEx);

            Thread loopThread = new Thread(Loop)
            {
                IsBackground = true
            };

            loopThread.Start();
        }