private bool ReLoadDatabases()
        {
            if (reloadingDatabases)
            {
                return(true);
            }

            dataBases = null;

            try {
                cboDatabase.Sensitive = false;
                btnOK.Sensitive       = false;
                reloadingDatabases    = true;
                cboDatabase.Load(new [] { Translator.GetString("Loading...") }, null, null, null);
                PresentationDomain.ProcessUIEvents();

                string dbProviderName = DbProvider;
                if (!BusinessDomain.TryConnect(dbProviderName, Server, SlaveServer, User, Password))
                {
                    cboDatabase.Load(new [] { Translator.GetString("None", "Database") }, null, null, null);
                    reloadingDatabases = false;
                    return(false);
                }

                DataHelper.FireAndForget(startedProvider =>
                {
                    try {
                        dataBases = BusinessDomain.GetDatabases();
                        // If the provider changed after we started to look for databases, don't show them
                        if (startedProvider != DbProvider)
                        {
                            return;
                        }

                        PresentationDomain.Invoke(() =>
                        {
                            bool hasDbs = dataBases.Length > 0;
                            if (hasDbs)
                            {
                                cboDatabase.Load(dataBases, null, null, BusinessDomain.AppConfiguration.DbDatabase);
                            }
                            else
                            {
                                cboDatabase.Load(new [] { Translator.GetString("None", "Database") }, null, null, null);
                            }
                            cboDatabase.Sensitive = hasDbs;
                            btnOK.Sensitive       = hasDbs;
                            reloadingDatabases    = false;
                        });
                    } catch {
                        cboDatabase.Load(new [] { Translator.GetString("None", "Database") }, null, null, null);
                        reloadingDatabases = false;
                    }
                }, dbProviderName);
                return(true);
            } catch (Exception ex) {
                ErrorHandling.LogException(ex);
                return(false);
            }
        }
Esempio n. 2
0
        public static void HideSplash()
        {
            if (splashWindow == null)
            {
                return;
            }

            if (BusinessDomain.AppConfiguration == null)
            {
                return;
            }

            if (!BusinessDomain.AppConfiguration.ShowSplashScreen)
            {
                return;
            }

            SetProgressBar(1.0d);
            PresentationDomain.ProcessUIEvents();

            if (PresentationDomain.MainFormCreated)
            {
                Thread.Sleep(2000);
            }
            else
            {
                Thread.Sleep(400);
            }

            splashWindow.Dispose();
            splashWindow            = null;
            AutoStartupNotification = true;
        }
        public void PulseCallback()
        {
            prgDialogProgress.Pulse();
            if (!customProgressText)
            {
                prgDialogProgress.Text = string.Empty;
            }

            PresentationDomain.ProcessUIEvents();
        }
Esempio n. 4
0
        public static void SetMessage(string message)
        {
            if (splashWindow == null)
            {
                return;
            }

            label.Markup = new PangoStyle {
                Size = PangoStyle.TextSize.Small, ColorText = colorText, Text = message
            };
            PresentationDomain.ProcessUIEvents();
        }
Esempio n. 5
0
        private static void SetProgressBar(double value)
        {
            if (splashWindow == null)
            {
                return;
            }

            if (value > 1.0)
            {
                return;
            }

            progress.Fraction = value;
            PresentationDomain.ProcessUIEvents();
        }
Esempio n. 6
0
        public static void ImportData <T> (EventHandler <ValidateEventArgs> validateCallback = null, EventHandler <ImportEventArgs> commitCallback = null, bool usesLocation = false) where T : IStrongEntity, IPersistableEntity <T>
        {
            Dictionary <int, bool> responses = new Dictionary <int, bool> ();

            using (MessageProgress progress = new MessageProgress(Translator.GetString("Importing..."), "Icons.Import24.png", Translator.GetString("Importing in progress..."))) {
                bool cancelImport = false;
                progress.Response          += delegate { cancelImport = true; };
                progress.CustomProgressText = true;

                StateHolder state = new StateHolder();
                state ["responses"]       = responses;
                state ["messageProgress"] = progress;

                ImportData(delegate(T entity, long?locationId, int current, int total, out bool cancel)
                {
                    progress.Show();
                    progress.Progress     = ((double)current * 100) / (total - 1);
                    progress.ProgressText = string.Format(Translator.GetString("{0} of {1}"), current + 1, total);
                    PresentationDomain.ProcessUIEvents();
                    cancel = cancelImport;
                    if (validateCallback != null)
                    {
                        ValidateEventArgs args = new ValidateEventArgs(InteractiveValidationCallback, state);
                        validateCallback(entity, args);
                        if (!args.IsValid)
                        {
                            return;
                        }
                    }

                    if (!entity.Validate(InteractiveValidationCallback, state))
                    {
                        return;
                    }

                    entity.CommitChanges();

                    if (commitCallback != null)
                    {
                        commitCallback(entity, new ImportEventArgs(locationId));
                    }
                }, usesLocation);
            }
        }
Esempio n. 7
0
        public static void ShowSplash(Assembly resourceAssembly, string textColor)
        {
            if (BusinessDomain.AppConfiguration != null && !BusinessDomain.AppConfiguration.ShowSplashScreen)
            {
                return;
            }

            colorText = textColor;
            if (!Init(resourceAssembly))
            {
                return;
            }

            AutoStartupNotification = false;
            splashWindow.ShowAll();
            PresentationDomain.ProcessUIEvents();

            SetProgressBar(0.0d);
        }
        public override void ShowTotals()
        {
            if (!initialized)
            {
                throw new ApplicationException("Visualizer not initialized.");
            }

            if (totalsCalculated)
            {
                grid.FooterVisible = true;
                return;
            }

            Dictionary <int, int> indexes = new Dictionary <int, int> ();
            List <double>         sums    = new List <double> ();

            for (int i = 0; i < model.Columns.Count; i++)
            {
                DbField field = dataQueryResult.Columns [i].Field;
                if (skip.Contains(field))
                {
                    continue;
                }

                switch (ReportProvider.GetDataFieldType(field))
                {
                case DataType.Quantity:
                case DataType.CurrencyIn:
                case DataType.CurrencyOut:
                case DataType.Currency:
                    indexes.Add(i, sums.Count);
                    sums.Add(0);
                    break;
                }
            }

            // If there are many rows to be calculated show progress message else calculate directly
            int total = model.Count;

            try {
                if (total > 10000)
                {
                    SwitchToWidget(tblCalculating);

                    for (int i = 0; i < total; i++)
                    {
                        foreach (KeyValuePair <int, int> pair in indexes)
                        {
                            if (listReset)
                            {
                                return;
                            }
                            sums [pair.Value] += (double)(dataQueryResult.Result [i] [pair.Key] ?? 0d);
                        }

                        if (i % 1000 != 0)
                        {
                            continue;
                        }

                        tblCalculating.Show();
                        double val = Math.Min((double)i / total, 1);
                        val = Math.Max(val, 0d);

                        prgCalculating.Fraction = val;
                        prgCalculating.Text     = string.Format(Translator.GetString("{0} of {1}"), i, total);
                        PresentationDomain.ProcessUIEvents();
                    }

                    ShowDataWidget();
                }
                else
                {
                    for (int i = 0; i < total; i++)
                    {
                        foreach (KeyValuePair <int, int> pair in indexes)
                        {
                            if (listReset)
                            {
                                return;
                            }
                            sums [pair.Value] += (double)(dataQueryResult.Result [i] [pair.Key] ?? 0d);
                        }
                    }
                }
            } catch (ArgumentOutOfRangeException) {
                return;
            }

            for (int i = 0; i < dataQueryResult.Result.Columns.Count; i++)
            {
                int index;
                if (!indexes.TryGetValue(i, out index))
                {
                    continue;
                }

                CellTextFooter footer;
                Column         column = grid.ColumnController [i];
                column.FooterValue = sums [index];

                DbField  field     = dataQueryResult.Columns [i].Field;
                DataType fieldType = ReportProvider.GetDataFieldType(field);
                switch (fieldType)
                {
                case DataType.Quantity:
                    column.FooterText = Quantity.ToString(sums [index]);
                    footer            = (CellTextFooter)column.FooterCell;
                    footer.Alignment  = Pango.Alignment.Right;
                    break;

                case DataType.CurrencyIn:
                    column.FooterText = Currency.ToString(sums [index], PriceType.Purchase);
                    footer            = (CellTextFooter)column.FooterCell;
                    footer.Alignment  = Pango.Alignment.Right;
                    break;

                case DataType.CurrencyOut:
                    column.FooterText = Currency.ToString(sums [index]);
                    footer            = (CellTextFooter)column.FooterCell;
                    footer.Alignment  = Pango.Alignment.Right;
                    break;

                case DataType.Currency:
                    column.FooterText = Currency.ToString(sums [index], PriceType.Unknown);
                    footer            = (CellTextFooter)column.FooterCell;
                    footer.Alignment  = Pango.Alignment.Right;
                    break;
                }
            }

            grid.FooterVisible = true;
            totalsCalculated   = true;
        }
        public void ProgressCallback(double percent)
        {
            Progress = percent;

            PresentationDomain.ProcessUIEvents();
        }