Пример #1
0
        public void EditSettings(object settings, Action onOk, Action onCancel)
        {
            var settingsExplorerType = ShUtils.GetUIComponentType <ISettingsEditorControl>();

            if (settingsExplorerType == null)
            {
                throw new ShAppException("Cannot find implementation for type ISettingsEditorControl");
            }


            var instance = Activator.CreateInstance(settingsExplorerType) as ISettingsEditorControl;

            instance.SetOptionsObject(settings);

            var instanceControl = instance as ShUserControlBase;

            ShFormUtils.ShowModal(instanceControl,
                                  (s, e) =>
            {
                if (onOk != null)
                {
                    onOk();
                }
            },
                                  (s, e) =>
            {
                if (onCancel != null)
                {
                    onCancel();
                }
            });
        }
Пример #2
0
        public void EditEntity(string title, object entity,
                               Action onOk)
        {
            Type defaultEditorType = ShUtils.GetUIComponentType <IEntityEditorControl>();

            if (defaultEditorType == null)
            {
                throw new ShAppException("Can't find impl for interface IEntityEditorControl");
            }

            EditEntity(defaultEditorType, title, entity, null, onOk, null);
        }
Пример #3
0
        public void WithLongOperation(Action <LongOperationHandle> action)
        {
            var form = new Form
            {
                Width  = 750,
                Height = 450
            };

            var hasClose = false;

            try
            {
                form.ShowIcon      = false;
                form.ShowInTaskbar = false;

                var longOperationControl = ShUtils.GetUIComponentType <ILongOperationControl>();
                var instance             = Activator.CreateInstance(longOperationControl);

                var instanceControl = instance as ShUserControlBase;

                instanceControl.Dock = DockStyle.Fill;

                form.MaximizeBox = false;
                form.MinimizeBox = false;

                form.StartPosition = FormStartPosition.CenterScreen;

                form.Controls.Add(instanceControl);

                form.Shown += (sss, eee) =>
                {
                    var handle = new LongOperationHandle();

                    handle.OnEnd += (rr, tt) =>
                    {
                        form.WithSafeUIUpdate(() =>
                        {
                            form.DialogResult = DialogResult.OK;
                            form.Close();
                        });

                        hasClose = true;
                    };

                    action(handle);
                };

                form.ShowDialog();

                hasClose = true;
            }
            catch (Exception e)
            {
                if (!hasClose)
                {
                    form.WithSafeUIUpdate(() =>
                    {
                        form.DialogResult = DialogResult.OK;
                        form.Close();
                    });
                }

                throw e;
            }
        }
Пример #4
0
        public static void WithLongOperation(
            Form parentForm,
            Action <Form> progressForm,
            Action <ShBusinessEntityDataService.LongOperationHandle> action)
        {
            var form = GetProgressForm(parentForm, f =>
            {
                f.Text = "Working...";
            });

            if (progressForm != null)
            {
                progressForm(form);
            }

            var hasClose = false;

            try
            {
                form.ShowIcon      = false;
                form.ShowInTaskbar = false;

                var longOperationControl = ShUtils.GetUIComponentType <ILongOperationControl>();
                var instance             = Activator.CreateInstance(longOperationControl);
                var instanceControl      = instance as ShUserControlBase;

                instanceControl.Dock = DockStyle.Fill;

                form.MaximizeBox = false;
                form.MinimizeBox = false;

                //form.StartPosition = FormStartPosition.CenterScreen;

                form.Controls.Add(instanceControl);

                form.Shown += (sss, eee) =>
                {
                    var handle = new ShBusinessEntityDataService.LongOperationHandle();

                    handle.OnOutput = (m) =>
                    {
                        var cc = (MetroLongOperationControl)instance;
                        cc.SetLogMessage(m);
                    };

                    handle.OnEnd += (rr, tt) =>
                    {
                        form.WithSafeUIUpdate(() =>
                        {
                            form.DialogResult = DialogResult.OK;
                            form.Close();
                        });

                        hasClose = true;
                    };

                    action(handle);
                };

                form.ShowDialog();

                hasClose = true;
            }
            catch (Exception longOperationException)
            {
                if (!hasClose)
                {
                    form.WithSafeUIUpdate(() =>
                    {
                        form.DialogResult = DialogResult.OK;
                        form.Close();
                    });
                }

                throw longOperationException;
            }
        }