コード例 #1
0
 public static FileTableColumn Create(ControlRow control)
 {
     switch (control.Type)
     {
         case Constant.Control.Note:
         case Constant.DatabaseColumn.File:
         case Constant.DatabaseColumn.RelativePath:
             return new FileTableNoteColumn(control);
         case Constant.DatabaseColumn.ImageQuality:
             return new FileTableChoiceColumn(control);
         case Constant.Control.Counter:
             return new FileTableCounterColumn(control);
         case Constant.DatabaseColumn.DateTime:
             return new FileTableDateTimeColumn(control);
         case Constant.DatabaseColumn.DeleteFlag:
         case Constant.Control.Flag:
             return new FileTableFlagColumn(control);
         case Constant.Control.FixedChoice:
             return new FileTableChoiceColumn(control);
         case Constant.DatabaseColumn.UtcOffset:
             return new FileTableUtcOffsetColumn(control);
         default:
             throw new NotSupportedException(String.Format("Unhandled control type {0}.", control.Type));
     }
 }
コード例 #2
0
        protected DataEntryControl(ControlRow control, DataEntryControls styleProvider)
        {
            // populate properties from database definition of control
            // this.Content and Tooltip can't be set, however, as the caller hasn't instantiated the content control yet
            this.Copyable = control.Copyable;
            this.DataLabel = control.DataLabel;
            this.DefaultValue = control.DefaultValue;

            // Create the stack panel
            this.Container = new StackPanel();
            Style style = styleProvider.FindResource(Constant.ControlStyle.ContainerStyle) as Style;
            this.Container.Style = style;

            // use the containers's tag to point back to this so event handlers can access the DataEntryControl
            // this is needed by callbacks such as DataEntryHandler.Container_PreviewMouseRightButtonDown() and CarnassialWindow.CounterControl_MouseLeave()
            this.Container.Tag = this;
        }
コード例 #3
0
 public FileTableCounterColumn(ControlRow control)
     : base(control)
 {
 }
コード例 #4
0
 /// <summary>
 /// Update the database row for the control to the current content of the template table.  The caller is responsible for ensuring the data row wrapped
 /// by the ControlRow object is present in both the data table and database versions of the template table.
 /// </summary>
 public void SyncControlToDatabase(ControlRow control)
 {
     this.CreateBackupIfNeeded();
     this.Database.Update(Constant.DatabaseTable.Controls, control.GetColumnTuples());
 }
コード例 #5
0
        public void RemoveUserDefinedControl(ControlRow controlToRemove)
        {
            this.CreateBackupIfNeeded();

            string controlType = controlToRemove.Type;
            if (Constant.Control.StandardTypes.Contains(controlType))
            {
                throw new NotSupportedException(String.Format("Standard control of type {0} cannot be removed.", controlType));
            }

            // capture state
            long removedControlOrder = controlToRemove.ControlOrder;
            long removedSpreadsheetOrder = controlToRemove.SpreadsheetOrder;

            // drop the control from the database and data table
            string where = Constant.DatabaseColumn.ID + " = " + controlToRemove.ID;
            this.Database.DeleteRows(Constant.DatabaseTable.Controls, where);
            this.GetControlsSortedByControlOrder();

            // regenerate counter and spreadsheet orders; if they're greater than the one removed, decrement
            List<ColumnTuplesWithWhere> controlUpdates = new List<ColumnTuplesWithWhere>();
            foreach (ControlRow control in this.Controls)
            {
                long controlOrder = control.ControlOrder;
                long spreadsheetOrder = control.SpreadsheetOrder;

                if (controlOrder > removedControlOrder)
                {
                    List<ColumnTuple> controlUpdate = new List<ColumnTuple>();
                    controlUpdate.Add(new ColumnTuple(Constant.Control.ControlOrder, controlOrder - 1));
                    control.ControlOrder = controlOrder - 1;
                    controlUpdates.Add(new ColumnTuplesWithWhere(controlUpdate, control.ID));
                }

                if (spreadsheetOrder > removedSpreadsheetOrder)
                {
                    List<ColumnTuple> controlUpdate = new List<ColumnTuple>();
                    controlUpdate.Add(new ColumnTuple(Constant.Control.SpreadsheetOrder, spreadsheetOrder - 1));
                    control.SpreadsheetOrder = spreadsheetOrder - 1;
                    controlUpdates.Add(new ColumnTuplesWithWhere(controlUpdate, control.ID));
                }
            }
            this.Database.Update(Constant.DatabaseTable.Controls, controlUpdates);

            // update the in memory table to reflect current database content
            // should not be necessary but this is done to mitigate divergence in case a bug results in the delete lacking perfect fidelity
            this.GetControlsSortedByControlOrder();
        }
コード例 #6
0
        private ComboBox CreateComboBox(DataEntryControls styleProvider, ControlRow control)
        {
            ComboBox comboBox = new ComboBox();
            comboBox.ToolTip = control.Tooltip;
            comboBox.Width = control.Width;
            foreach (string choice in control.GetChoices())
            {
                comboBox.Items.Add(choice);
            }
            comboBox.SelectedIndex = 0;

            Style style = styleProvider.FindResource(ControlContentStyle.ChoiceComboBox.ToString()) as Style;
            comboBox.Style = style;
            return comboBox;
        }
コード例 #7
0
 private UtcOffsetPicker CreateUtcOffsetPicker(ControlRow control)
 {
     UtcOffsetPicker utcOffsetPicker = new UtcOffsetPicker();
     utcOffsetPicker.ToolTip = control.Tooltip;
     utcOffsetPicker.Value = Constant.ControlDefault.DateTimeValue.Offset;
     utcOffsetPicker.Width = control.Width;
     return utcOffsetPicker;
 }
コード例 #8
0
        public bool Synchronize(ControlRow other)
        {
            bool synchronizationMadeChanges = false;
            if (this.Copyable != other.Copyable)
            {
                this.Copyable = other.Copyable;
                synchronizationMadeChanges = true;
            }
            if (this.ControlOrder != other.ControlOrder)
            {
                this.ControlOrder = other.ControlOrder;
                synchronizationMadeChanges = true;
            }
            if (this.DefaultValue != other.DefaultValue)
            {
                this.DefaultValue = other.DefaultValue;
                synchronizationMadeChanges = true;
            }
            if (this.Label != other.Label)
            {
                this.Label = other.Label;
                synchronizationMadeChanges = true;
            }
            if (this.List != other.List)
            {
                this.List = other.List;
                synchronizationMadeChanges = true;
            }
            if (this.SpreadsheetOrder != other.SpreadsheetOrder)
            {
                this.SpreadsheetOrder = other.SpreadsheetOrder;
                synchronizationMadeChanges = true;
            }
            if (this.Tooltip != other.Tooltip)
            {
                this.Tooltip = other.Tooltip;
                synchronizationMadeChanges = true;
            }
            if (this.Visible != other.Visible)
            {
                this.Visible = other.Visible;
                synchronizationMadeChanges = true;
            }
            if (this.Width != other.Width)
            {
                this.Width = other.Width;
                synchronizationMadeChanges = true;
            }

            return synchronizationMadeChanges;
        }
コード例 #9
0
        private CheckBox CreateFlag(DataEntryControls styleProvider, ControlRow control)
        {
            CheckBox checkBox = new CheckBox();
            checkBox.Visibility = Visibility.Visible;
            checkBox.ToolTip = control.Tooltip;

            Style style = styleProvider.FindResource(ControlContentStyle.FlagCheckBox.ToString()) as Style;
            checkBox.Style = style;
            return checkBox;
        }
コード例 #10
0
 private DateTimeOffsetPicker CreateDateTimePicker(ControlRow control)
 {
     DateTimeOffsetPicker dateTimePicker = new DateTimeOffsetPicker();
     dateTimePicker.Value = Constant.ControlDefault.DateTimeValue;
     dateTimePicker.ToolTip = control.Tooltip;
     dateTimePicker.Width = control.Width;
     return dateTimePicker;
 }
コード例 #11
0
        private RadioButton CreateCounterLabelButton(DataEntryControls styleProvider, ControlRow control)
        {
            RadioButton radioButton = new RadioButton();
            radioButton.GroupName = "DataEntryCounter";
            radioButton.Content = control.Label;
            radioButton.ToolTip = control.Tooltip;

            Style style = styleProvider.FindResource(ControlLabelStyle.CounterButton.ToString()) as Style;
            radioButton.Style = style;
            return radioButton;
        }
コード例 #12
0
 private void VerifyControl(ControlRow control)
 {
     Assert.IsTrue(control.ControlOrder > 0);
     // nothing to sanity check for control.Copyable
     Assert.IsFalse(String.IsNullOrWhiteSpace(control.DataLabel));
     // nothing to sanity check for control.DefaultValue
     Assert.IsTrue(control.ID >= 0);
     Assert.IsFalse(String.IsNullOrWhiteSpace(control.Label));
     // nothing to sanity check for control.List
     Assert.IsTrue(control.SpreadsheetOrder > 0);
     Assert.IsTrue(control.Width > 0);
     Assert.IsFalse(String.IsNullOrWhiteSpace(control.Tooltip));
     Assert.IsFalse(String.IsNullOrWhiteSpace(control.Type));
     // nothing to sanity check for control.Visible
 }
コード例 #13
0
 public void Verify(ControlRow control)
 {
     Assert.IsTrue(control.ControlOrder == this.ControlOrder, "{0}: Expected ControlOrder '{1}' but found '{2}'.", this.DataLabel, this.ControlOrder, control.ControlOrder);
     Assert.IsTrue(control.Copyable == this.Copyable, "{0}: Expected Copyable '{1}' but found '{2}'.", this.DataLabel, this.Copyable, control.Copyable);
     Assert.IsTrue(control.DataLabel == this.DataLabel, "{0}: Expected DataLabel '{1}' but found '{2}'.", this.DataLabel, this.DataLabel, control.DataLabel);
     Assert.IsTrue(control.DefaultValue == this.DefaultValue, "{0}: Expected DefaultValue '{1}' but found '{2}'.", this.DataLabel, this.DefaultValue, control.DefaultValue);
     Assert.IsTrue(control.ID == this.ID, "{0}: Expected ID '{1}' but found '{2}'.", this.DataLabel, this.ID, control.ID);
     Assert.IsTrue(control.Label == this.Label, "{0}: Expected Label '{1}' but found '{2}'.", this.DataLabel, this.Label, control.Label);
     Assert.IsTrue(control.List == this.List, "{0}: Expected List '{1}' but found '{2}'.", this.DataLabel, this.List, control.List);
     Assert.IsTrue(control.SpreadsheetOrder == this.SpreadsheetOrder, "{0}: Expected SpreadsheetOrder '{1}' but found '{2}'.", this.DataLabel, this.SpreadsheetOrder, control.SpreadsheetOrder);
     Assert.IsTrue(control.Width == this.TextBoxWidth, "{0}: Expected TextBoxWidth '{1}' but found '{2}'.", this.DataLabel, this.TextBoxWidth, control.Width);
     Assert.IsTrue(control.Tooltip == this.Tooltip, "{0}: Expected Tooltip '{1}' but found '{2}'.", this.DataLabel, this.Tooltip, control.Tooltip);
     Assert.IsTrue(control.Type == this.Type, "{0}: Expected Type '{1}' but found '{2}'.", this.DataLabel, this.Type, control.Type);
     Assert.IsTrue(control.Visible == this.Visible, "{0}: Expected Visible '{1}' but found '{2}'.", this.DataLabel, this.Visible, control.Visible);
 }
コード例 #14
0
 public FileTableDateTimeColumn(ControlRow control)
     : base(control)
 {
 }
コード例 #15
0
 private ColumnDefinition CreateFileDataColumnDefinition(ControlRow control)
 {
     if (control.DataLabel == Constant.DatabaseColumn.DateTime)
     {
         return new ColumnDefinition(control.DataLabel, "DATETIME", DateTimeHandler.ToDatabaseDateTimeString(Constant.ControlDefault.DateTimeValue));
     }
     if (control.DataLabel == Constant.DatabaseColumn.UtcOffset)
     {
         // UTC offsets are typically represented as TimeSpans but the least awkward way to store them in SQLite is as a real column containing the offset in
         // hours.  This is because SQLite
         // - handles TIME columns as DateTime rather than TimeSpan, requiring the associated DataTable column also be of type DateTime
         // - doesn't support negative values in time formats, requiring offsets for time zones west of Greenwich be represented as positive values
         // - imposes an upper bound of 24 hours on time formats, meaning the 26 hour range of UTC offsets (UTC-12 to UTC+14) cannot be accomodated
         // - lacks support for DateTimeOffset, so whilst offset information can be written to the database it cannot be read from the database as .NET
         //   supports only DateTimes whose offset matches the current system time zone
         // Storing offsets as ticks, milliseconds, seconds, minutes, or days offers equivalent functionality.  Potential for rounding error in roundtrip
         // calculations on offsets is similar to hours for all formats other than an INTEGER (long) column containing ticks.  Ticks are a common
         // implementation choice but testing shows no roundoff errors at single tick precision (100 nanoseconds) when using hours.  Even with TimeSpans
         // near the upper bound of 256M hours, well beyond the plausible range of time zone calculations.  So there does not appear to be any reason to
         // avoid using hours for readability when working with the database directly.
         return new ColumnDefinition(control.DataLabel, "REAL", DateTimeHandler.ToDatabaseUtcOffsetString(Constant.ControlDefault.DateTimeValue.Offset));
     }
     if (String.IsNullOrWhiteSpace(control.DefaultValue))
     {
          return new ColumnDefinition(control.DataLabel, Constant.Sql.Text);
     }
     return new ColumnDefinition(control.DataLabel, Constant.Sql.Text, control.DefaultValue);
 }
コード例 #16
0
        private Label CreateLabel(DataEntryControls styleProvider, ControlRow control)
        {
            Label label = new Label();
            label.Content = control.Label;
            label.ToolTip = control.Tooltip;

            Style style = styleProvider.FindResource(ControlLabelStyle.DefaultLabel.ToString()) as Style;
            label.Style = style;
            return label;
        }
コード例 #17
0
 protected FileTableColumn(ControlRow control)
 {
     this.ControlType = control.Type;
     this.DataLabel = control.DataLabel;
 }
コード例 #18
0
        private TextBox CreateTextBox(DataEntryControls styleProvider, ControlRow control)
        {
            TextBox textBox = new TextBox();
            textBox.Text = control.DefaultValue;
            textBox.ToolTip = control.Tooltip;
            textBox.Width = control.Width;

            Style style = styleProvider.FindResource(ControlContentStyle.NoteCounterTextBox.ToString()) as Style;
            textBox.Style = style;
            return textBox;
        }
コード例 #19
0
 public FileTableFlagColumn(ControlRow control)
     : base(control)
 {
 }
コード例 #20
0
 public FileTableChoiceColumn(ControlRow control)
     : base(control)
 {
     this.choices = control.GetChoices();
     this.defaultValue = control.DefaultValue;
 }