Esempio n. 1
0
        private void initializeTable()
        {
            table = CreateTable <Timer>();

            CustomDataGridViewColumnDescriptorBuilder <Timer> builder;

            // Column: ID
            builder = GetColumnDescriptorBuilderForTable <Timer>();
            builder.Type(DataGridViewColumnType.TextBox);
            builder.Header("ID");
            builder.Width(30);
            builder.UpdaterMethod((timer, cell) => { cell.Value = string.Format("#{0}", timer.ID); });
            builder.AddChangeEvent(nameof(Timer.ID));
            builder.BuildAndAdd();

            // Column: title
            builder = GetColumnDescriptorBuilderForTable <Timer>();
            builder.Type(DataGridViewColumnType.TextBox);
            builder.Header("Title");
            builder.Width(150);
            builder.CellStyle(BOLD_TEXT_CELL_STYLE);
            builder.UpdaterMethod((timer, cell) => { cell.Value = timer.Title; });
            builder.AddChangeEvent(nameof(Timer.Title));
            builder.BuildAndAdd();

            // Column: mode image
            builder = GetColumnDescriptorBuilderForTable <Timer>();
            builder.Type(DataGridViewColumnType.Image);
            builder.Header("");
            builder.Width(30);
            builder.CellStyle(TWO_PIXELS_PADDING_CELL_STYLE);
            builder.UpdaterMethod((timer, cell) => { cell.Value = modeImageConverter.Convert(timer.Mode); });
            builder.AddChangeEvent(nameof(Timer.Mode));
            builder.BuildAndAdd();

            // Column: mode label
            builder = GetColumnDescriptorBuilderForTable <Timer>();
            builder.Type(DataGridViewColumnType.TextBox);
            builder.Header("Mode");
            builder.Width(100);
            builder.DividerWidth(DEFAULT_DIVIDER_WIDTH);
            builder.UpdaterMethod((timer, cell) => { cell.Value = modeLabelConverter.Convert(timer.Mode); });
            builder.AddChangeEvent(nameof(Timer.Mode));
            builder.BuildAndAdd();

            // Column: running state
            builder = GetColumnDescriptorBuilderForTable <Timer>();
            builder.Type(DataGridViewColumnType.Image);
            builder.Header("");
            builder.Width(30);
            builder.CellStyle(TWO_PIXELS_PADDING_CELL_STYLE);
            builder.UpdaterMethod((timer, cell) => {
                if (timer.Mode == TimerMode.Clock)
                {
                    cell.Value = STATE_IMAGE_NOTSHOWN;
                }
                else
                {
                    cell.Value = timer.Running ? STATE_IMAGE_RUNNING : STATE_IMAGE_STOPPED;
                }
            });
            builder.AddChangeEvent(nameof(Timer.Mode));
            builder.BuildAndAdd();

            // Column: current value
            builder = GetColumnDescriptorBuilderForTable <Timer>();
            builder.Type(DataGridViewColumnType.TextBox);
            builder.Header("Current value");
            builder.Width(100);
            builder.CellStyle(BOLD_TEXT_CELL_STYLE);
            builder.UpdaterMethod((timer, cell) => { cell.Value = timer.TimeSpan.ToString(@"hh\:mm\:ss"); });
            builder.AddChangeEvent(nameof(Timer.Seconds));
            builder.BuildAndAdd();

            // Column: start value
            builder = GetColumnDescriptorBuilderForTable <Timer>();
            builder.Type(DataGridViewColumnType.TextBox);
            builder.Header("Start value");
            builder.Width(100);
            builder.DividerWidth(DEFAULT_DIVIDER_WIDTH);
            builder.UpdaterMethod((timer, cell) => {
                cell.Value = (timer.Mode == TimerMode.Backwards) ? TimeSpan.FromSeconds(timer.CountdownSeconds).ToString(@"hh\:mm\:ss") : "";
            });
            builder.AddChangeEvent(nameof(Timer.CountdownSeconds));
            builder.BuildAndAdd();

            // Column: edit button
            builder = GetColumnDescriptorBuilderForTable <Timer>();
            builder.Type(DataGridViewColumnType.Button);
            builder.Header("Edit");
            builder.Width(70);
            builder.ButtonText("Edit");
            builder.CellContentClickHandlerMethod((timer, cell, e) => {
                var editWindow = new TimerEditWindow(timer);
                editWindow.ShowAsChild();
            });
            builder.BuildAndAdd();

            // Column: delete button
            builder = GetColumnDescriptorBuilderForTable <Timer>();
            builder.Type(DataGridViewColumnType.Button);
            builder.Header("Delete");
            builder.Width(70);
            builder.DividerWidth(DEFAULT_DIVIDER_WIDTH);
            builder.ButtonText("Delete");
            builder.CellContentClickHandlerMethod((timer, cell, e) => {
                string msgBoxText = string.Format("Do you really want to delete this timer?\n(#{0}) {1}", timer.ID, timer.Title);
                var confirm       = MessageBox.Show(msgBoxText, "Delete confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (confirm == DialogResult.Yes)
                {
                    TimerDatabase.Instance.Remove(timer);
                }
            });
            builder.BuildAndAdd();

            // Column: start button
            builder = GetColumnDescriptorBuilderForTable <Timer>();
            builder.Type(DataGridViewColumnType.ImageButton);
            builder.Header("");
            builder.Width(40);
            builder.ButtonImage(BUTTON_IMAGE_START);
            builder.ButtonImagePadding(DEFAULT_IMAGE_BUTTON_PADDING);
            builder.UpdaterMethod((timer, cell) => { ((DataGridViewDisableButtonCell)cell).Enabled = timer.CanStart; });
            builder.CellContentClickHandlerMethod((timer, cell, e) => { timer.Start(); });
            builder.AddChangeEvent(nameof(Timer.Mode));
            builder.AddChangeEvent(nameof(Timer.Running));
            builder.BuildAndAdd();

            // Column: stop button
            builder = GetColumnDescriptorBuilderForTable <Timer>();
            builder.Type(DataGridViewColumnType.ImageButton);
            builder.Header("");
            builder.Width(40);
            builder.ButtonImage(BUTTON_IMAGE_STOP);
            builder.ButtonImagePadding(DEFAULT_IMAGE_BUTTON_PADDING);
            builder.UpdaterMethod((timer, cell) => { ((DataGridViewDisableButtonCell)cell).Enabled = timer.CanStop; });
            builder.CellContentClickHandlerMethod((timer, cell, e) => { timer.Stop(); });
            builder.AddChangeEvent(nameof(Timer.Mode));
            builder.AddChangeEvent(nameof(Timer.Running));
            builder.BuildAndAdd();

            // Column: reset button
            builder = GetColumnDescriptorBuilderForTable <Timer>();
            builder.Type(DataGridViewColumnType.ImageButton);
            builder.Header("");
            builder.Width(40);
            builder.DividerWidth(DEFAULT_DIVIDER_WIDTH);
            builder.ButtonImage(BUTTON_IMAGE_RESET);
            builder.ButtonImagePadding(DEFAULT_IMAGE_BUTTON_PADDING);
            builder.UpdaterMethod((timer, cell) => { ((DataGridViewDisableButtonCell)cell).Enabled = timer.CanReset; });
            builder.CellContentClickHandlerMethod((timer, cell, e) => { timer.Reset(); });
            builder.AddChangeEvent(nameof(Timer.Mode));
            builder.AddChangeEvent(nameof(Timer.Running));
            builder.BuildAndAdd();

            // Column: open timer window button
            builder = GetColumnDescriptorBuilderForTable <Timer>();
            builder.Type(DataGridViewColumnType.Button);
            builder.Header("Open window");
            builder.Width(100);
            builder.ButtonText("Open window");
            builder.CellContentClickHandlerMethod((timer, cell, e) => {
                var timerWindow = new TimerWindow(timer);
                timerWindow.ShowAsChild();
            });
            builder.BuildAndAdd();

            // Bind database
            table.BoundCollection = TimerDatabase.Instance;
        }
Esempio n. 2
0
        private void addTimerButton_Click(object sender, EventArgs e)
        {
            var editWindow = new TimerEditWindow(null);

            editWindow.ShowAsChild();
        }