Пример #1
0
 public FieldType(FieldType fieldType)
 {
     Copy(fieldType);
 }
Пример #2
0
 public void Copy(FieldType fieldType)
 {
     // copy all of the properties
     foreach (PropertyInfo pi in fieldType.GetType().GetProperties())
     {
         // get the value of the property
         var val = pi.GetValue(fieldType, null);
         pi.SetValue(this, val, null);
     }
 }
Пример #3
0
        private void RenderEditTaskFields(Task task, ListType listtype, bool primary, bool renderTaskListField)
        {
            if (renderTaskListField == true)
            {
                FieldType fieldType = new FieldType() { Name = "TaskListID", DisplayName = "list", DisplayType = "TaskList" };
                RenderEditTaskField(task, fieldType);
            }

            // render fields
            foreach (Field f in listtype.Fields.Where(f => f.IsPrimary == primary).OrderBy(f => f.SortOrder))
            {
                FieldType fieldType;
                // get the field type for this field
                try
                {
                    fieldType = App.ViewModel.Constants.FieldTypes.Single(ft => ft.FieldTypeID == f.FieldTypeID);
                }
                catch (Exception)
                {
                    continue;
                }

                // render this field
                RenderEditTaskField(task, fieldType);
            }

            // refresh the keyboard tabstops
            keyboardHelper.RefreshTabbedControls(null);
        }
Пример #4
0
        public void Copy(FieldType obj)
        {
            if (obj == null)
                return;

            // copy all of the properties
            foreach (PropertyInfo pi in obj.GetType().GetProperties())
            {
                // get the value of the property
                var val = pi.GetValue(obj, null);
                pi.SetValue(this, val, null);
            }
        }
Пример #5
0
        private void RenderEditTaskField(Task task, FieldType fieldType)
        {
            PropertyInfo pi;

            // make sure the property exists on the local type
            try
            {
                pi = task.GetType().GetProperty(fieldType.Name);
                if (pi == null)
                    return;  // see comment below
            }
            catch (Exception)
            {
                // we can't do anything with this property since we don't have it on the local type
                // this indicates that the phone software isn't caught up with the service version
                return;
            }

            // get the value of the property
            var val = pi.GetValue(task, null);

            ListBoxItem listBoxItem = new ListBoxItem();
            StackPanel EditStackPanel = new StackPanel();
            listBoxItem.Content = EditStackPanel;
            EditStackPanel.Children.Add(
                new TextBlock()
                {
                    Text = fieldType.DisplayName,
                    Style = (Style)App.Current.Resources["PhoneTextNormalStyle"]
                });

            // create a textbox (will be used by the majority of field types)
            double minWidth = App.Current.RootVisual.RenderSize.Width;
            if ((int)minWidth == 0)
                minWidth = ((this.Orientation & PageOrientation.Portrait) == PageOrientation.Portrait) ? 480.0 : 800.0;

            TextBox tb = new TextBox() { DataContext = taskCopy, MinWidth = minWidth, IsTabStop = true };
            tb.SetBinding(TextBox.TextProperty, new Binding(pi.Name) { Mode = BindingMode.TwoWay });

            bool notMatched = false;
            // render the right control based on the type
            switch (fieldType.DisplayType)
            {
                case "String":
                    tb.InputScope = new InputScope() { Names = { new InputScopeName() { NameValue = InputScopeNameValue.Text } } };
                    tb.LostFocus += new RoutedEventHandler(delegate { pi.SetValue(taskCopy, tb.Text, null); });
                    tb.TabIndex = tabIndex++;
                    tb.KeyUp += new KeyEventHandler(TextBox_KeyUp);
                    EditStackPanel.Children.Add(tb);
                    break;
                case "TextBox":
                    tb.InputScope = new InputScope() { Names = { new InputScopeName() { NameValue = InputScopeNameValue.Text } } };
                    tb.AcceptsReturn = true;
                    tb.TextWrapping = TextWrapping.Wrap;
                    tb.Height = 300;
                    tb.TabIndex = tabIndex++;
                    tb.LostFocus += new RoutedEventHandler(delegate { pi.SetValue(taskCopy, tb.Text, null); });
                    EditStackPanel.Children.Add(tb);
                    break;
                case "Phone":
                case "PhoneNumber":
                    tb.InputScope = new InputScope() { Names = { new InputScopeName() { NameValue = InputScopeNameValue.TelephoneNumber } } };
                    tb.LostFocus += new RoutedEventHandler(delegate { pi.SetValue(taskCopy, tb.Text, null); });
                    tb.TabIndex = tabIndex++;
                    StackPanel innerPanel = RenderEditTaskImageButtonPanel(tb);
                    ImageButton imageButton = (ImageButton)innerPanel.Children[1];
                    imageButton.Click += new RoutedEventHandler(delegate
                    {
                        PhoneNumberChooserTask chooser = new PhoneNumberChooserTask();
                        chooser.Completed += new EventHandler<PhoneNumberResult>((sender, e) =>
                        {
                            if (e.TaskResult == TaskResult.OK && e.PhoneNumber != null && e.PhoneNumber != "")
                                pi.SetValue(task, e.PhoneNumber, null);
                        });
                        chooser.Show();
                    });
                    EditStackPanel.Children.Add(innerPanel);
                    break;
                case "Website":
                    tb.InputScope = new InputScope() { Names = { new InputScopeName() { NameValue = InputScopeNameValue.Url } } };
                    tb.LostFocus += new RoutedEventHandler(delegate { pi.SetValue(taskCopy, tb.Text, null); });
                    tb.TabIndex = tabIndex++;
                    tb.KeyUp += new KeyEventHandler(TextBox_KeyUp);
                    EditStackPanel.Children.Add(tb);
                    break;
                case "Email":
                    tb.InputScope = new InputScope() { Names = { new InputScopeName() { NameValue = InputScopeNameValue.EmailSmtpAddress } } };
                    tb.LostFocus += new RoutedEventHandler(delegate { pi.SetValue(taskCopy, tb.Text, null); });
                    tb.TabIndex = tabIndex++;
                    tb.KeyUp += new KeyEventHandler(TextBox_KeyUp);
                    innerPanel = RenderEditTaskImageButtonPanel(tb);
                    imageButton = (ImageButton)innerPanel.Children[1];
                    imageButton.Click += new RoutedEventHandler(delegate
                    {
                        EmailAddressChooserTask chooser = new EmailAddressChooserTask();
                        chooser.Completed += new EventHandler<EmailResult>((sender, e) =>
                        {
                            if (e.TaskResult == TaskResult.OK && e.Email != null && e.Email != "")
                                pi.SetValue(task, e.Email, null);
                        });
                        chooser.Show();
                    });
                    EditStackPanel.Children.Add(innerPanel);
                    break;
                case "Location":
                case "Address":
                    tb.InputScope = new InputScope()
                    {
                        Names =
                            {
                                new InputScopeName() { NameValue = InputScopeNameValue.AddressStreet },
                                new InputScopeName() { NameValue = InputScopeNameValue.AddressCity },
                                new InputScopeName() { NameValue = InputScopeNameValue.AddressStateOrProvince },
                                new InputScopeName() { NameValue = InputScopeNameValue.AddressCountryName },
                            }
                    };
                    tb.LostFocus += new RoutedEventHandler(delegate { pi.SetValue(taskCopy, tb.Text, null); });
                    tb.TabIndex = tabIndex++;
                    tb.KeyUp += new KeyEventHandler(TextBox_KeyUp);
                    innerPanel = RenderEditTaskImageButtonPanel(tb);
                    imageButton = (ImageButton)innerPanel.Children[1];
                    imageButton.Click += new RoutedEventHandler(delegate
                    {
                        // start the location service
                        GeoCoordinateWatcher watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
                        watcher.MovementThreshold = 20; // Use MovementThreshold to ignore noise in the signal.
                        watcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>((sender, e) =>
                        {
                            if (e.Status == GeoPositionStatus.Ready)
                            {
                                // Use the Position property of the GeoCoordinateWatcher object to get the current location.
                                GeoCoordinate co = watcher.Position.Location;
                                tb.Text = co.Latitude.ToString("0.000") + "," + co.Longitude.ToString("0.000");
                                //Stop the Location Service to conserve battery power.
                                watcher.Stop();
                            }
                        });
                        watcher.Start();
                    });
                    EditStackPanel.Children.Add(innerPanel);
                    break;
                case "Priority":
                    ListPicker lp = new ListPicker()
                    {
                        MinWidth = minWidth,
                        FullModeItemTemplate = (DataTemplate) App.Current.Resources["FullListPickerTemplate"],
                        IsTabStop = true
                    };
                    lp.ItemsSource = App.ViewModel.Constants.Priorities;
                    lp.DisplayMemberPath = "Name";
                    int? lpval = (int?)pi.GetValue(taskCopy, null);
                    if (lpval != null)
                        lp.SelectedIndex = (int)lpval;
                    else
                        lp.SelectedIndex = 1;  // HACK: hardcode to "Normal" priority.  this should come from a table.
                    lp.SelectionChanged += new SelectionChangedEventHandler(delegate { pi.SetValue(taskCopy, lp.SelectedIndex == 1 ? (int?)null : lp.SelectedIndex, null); });
                    lp.TabIndex = tabIndex++;
                    EditStackPanel.Children.Add(lp);
                    break;
                case "TaskList":
                    ListPicker taskListPicker = new ListPicker() { MinWidth = minWidth, IsTabStop = true };
                    taskListPicker.ItemsSource = App.ViewModel.TaskLists;
                    taskListPicker.DisplayMemberPath = "Name";
                    TaskList tl = App.ViewModel.TaskLists.FirstOrDefault(list => list.ID == taskList.ID);
                    taskListPicker.SelectedIndex = App.ViewModel.TaskLists.IndexOf(tl);
                    taskListPicker.SelectionChanged += new SelectionChangedEventHandler(delegate { pi.SetValue(taskCopy, App.ViewModel.TaskLists[taskListPicker.SelectedIndex].ID, null); });
                    taskListPicker.TabIndex = tabIndex++;
                    EditStackPanel.Children.Add(taskListPicker);
                    break;
                case "Integer":
                    tb.InputScope = new InputScope() { Names = { new InputScopeName() { NameValue = InputScopeNameValue.Digits } } };
                    tb.LostFocus += new RoutedEventHandler(delegate { pi.SetValue(taskCopy, Convert.ToInt32(tb.Text), null); });
                    tb.TabIndex = tabIndex++;
                    tb.KeyUp += new KeyEventHandler(TextBox_KeyUp);
                    EditStackPanel.Children.Add(tb);
                    break;
                case "Date":
                    DatePicker dp = new DatePicker() { DataContext = taskCopy, MinWidth = minWidth, IsTabStop = true };
                    dp.SetBinding(DatePicker.ValueProperty, new Binding(pi.Name) { Mode = BindingMode.TwoWay });
                    dp.ValueChanged += new EventHandler<DateTimeValueChangedEventArgs>(delegate
                    {
                        pi.SetValue(taskCopy, dp.Value, null);
                        taskList.NotifyPropertyChanged("FirstDue");
                        taskList.NotifyPropertyChanged("FirstDueColor");
                    });
                    dp.TabIndex = tabIndex++;
                    EditStackPanel.Children.Add(dp);
                    break;
                case "Boolean":
                    CheckBox cb = new CheckBox() { DataContext = taskCopy, IsTabStop = true };
                    cb.SetBinding(CheckBox.IsCheckedProperty, new Binding(pi.Name) { Mode = BindingMode.TwoWay });
                    cb.TabIndex = tabIndex++;
                    EditStackPanel.Children.Add(cb);
                    break;
                case "TagList":
                    TextBox taglist = new TextBox() { MinWidth = minWidth, IsTabStop = true };
                    taglist.KeyUp += new KeyEventHandler(TextBox_KeyUp);
                    taglist.TabIndex = tabIndex++;
                    RenderEditTaskTagList(taglist, taskCopy, pi);
                    EditStackPanel.Children.Add(taglist);
                    break;
                case "ListPointer":
                    innerPanel = RenderEditTaskListPointer(pi, minWidth);
                    EditStackPanel.Children.Add(innerPanel);
                    break;
                default:
                    notMatched = true;
                    break;
            }

            // if wasn't able to match field type by display type, try matching by CLR type
            if (notMatched == true)
            {
                string typename = GetTypeName(pi);
                switch (typename)
                {
                    case "String":
                        tb.InputScope = new InputScope() { Names = { new InputScopeName() { NameValue = InputScopeNameValue.Text } } };
                        tb.LostFocus += new RoutedEventHandler(delegate { pi.SetValue(taskCopy, tb.Text, null); });
                        tb.TabIndex = tabIndex++;
                        tb.KeyUp += new KeyEventHandler(TextBox_KeyUp);
                        EditStackPanel.Children.Add(tb);
                        break;
                    case "Int32":
                        tb.InputScope = new InputScope() { Names = { new InputScopeName() { NameValue = InputScopeNameValue.Digits } } };
                        tb.LostFocus += new RoutedEventHandler(delegate { pi.SetValue(taskCopy, Convert.ToInt32(tb.Text), null); });
                        tb.TabIndex = tabIndex++;
                        tb.KeyUp += new KeyEventHandler(TextBox_KeyUp);
                        EditStackPanel.Children.Add(tb);
                        break;
                    case "DateTime":
                        DatePicker dp = new DatePicker() { DataContext = taskCopy, MinWidth = minWidth, IsTabStop = true };
                        dp.SetBinding(DatePicker.ValueProperty, new Binding(pi.Name) { Mode = BindingMode.TwoWay });
                        dp.ValueChanged += new EventHandler<DateTimeValueChangedEventArgs>(delegate
                        {
                            pi.SetValue(taskCopy, dp.Value, null);
                            taskList.NotifyPropertyChanged("FirstDue");
                            taskList.NotifyPropertyChanged("FirstDueColor");
                        });
                        dp.TabIndex = tabIndex++;
                        EditStackPanel.Children.Add(dp);
                        break;
                    case "Boolean":
                        CheckBox cb = new CheckBox() { DataContext = taskCopy, IsTabStop = true };
                        cb.SetBinding(CheckBox.IsEnabledProperty, new Binding(pi.Name) { Mode = BindingMode.TwoWay });
                        cb.TabIndex = tabIndex++;
                        EditStackPanel.Children.Add(cb);
                        break;
                    default:
                        break;
                }
            }

            // add the listboxitem to the listbox
            EditListBox.Items.Add(listBoxItem);
        }