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); } }
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 override bool CommitChanges(StepPartners step, Assistant assistant) { BackgroundJob job = new BackgroundJob(step); job.Action += () => { PresentationDomain.Invoke(() => { step.Notebook.Sensitive = false; }); IList <CustomerWrapper> allCustomers = GetAllCustomers(); if (allCustomers.Count <= 0) { return; } CustomerWrapper def = allCustomers [0]; // Substitute the default customer def.Customer.Id = Partner.DefaultId; def.CommitChanges(); foreach (CustomerWrapper customer in allCustomers) { customer.CommitChanges(); } }; assistant.EnqueueBackgroundJob(job); return(true); }
public override bool CommitChanges(StepLocations step, Assistant assistant) { BackgroundJob job = new BackgroundJob(step); job.Action += () => { PresentationDomain.Invoke(() => { if (step.Notebook != null) { step.Notebook.Sensitive = false; } else { tbl.Sensitive = false; } }); // Substitute the default location if (locations.Count > 0) { locations [0].Id = Location.DefaultId; } foreach (Location location in locations) { location.CommitChanges(); } }; assistant.EnqueueBackgroundJob(job); return(true); }
protected override void OnEntitiesChanged(long?groupId = null) { BusinessDomain.CurrentCompany = CompanyRecord.GetDefault(); PresentationDomain.RefreshMainFormStatusBar(); base.OnEntitiesChanged(groupId); }
private void Assistant_StatusChanged(object sender, EventArgs e) { if (!AllStepsFinished()) { UpdateStepStatuses(); return; } PresentationDomain.Invoke(SetMessageCompleted); }
public void PulseCallback() { prgDialogProgress.Pulse(); if (!customProgressText) { prgDialogProgress.Text = string.Empty; } PresentationDomain.ProcessUIEvents(); }
public static void Main(string [] args) { DataHelper.ProductName = "Warehouse Open"; DataHelper.ProductSupportEmail = "*****@*****.**"; DataHelper.CompanyName = "Microinvest"; DataHelper.CompanyAddress = "Tsar Boris III 215, floor 12, Sofia, Bulgaria"; DataHelper.CompanyWebSite = "http://www.microinvest.net"; BusinessDomain.WorkflowManager = new WorkflowManager(); PresentationDomain.Run(new ResourceHandler(), "#707070"); }
public static void SetMessage(string message) { if (splashWindow == null) { return; } label.Markup = new PangoStyle { Size = PangoStyle.TextSize.Small, ColorText = colorText, Text = message }; PresentationDomain.ProcessUIEvents(); }
public Assistant(AssistType assistType) { this.assistType = assistType; allSteps = StepBase.GetAllSteps(assistType); Initialize(); if (assistType == AssistType.ApplicationSetup) { AppendStep(new StepAppSetup()); } else if (assistType == AssistType.DatabaseSetup) { AppendStep(new StepDBSetup()); } else { throw new ArgumentOutOfRangeException("assistType"); } backgroundWorker = new Thread(delegate() { while (true) { if (backgroundJobs.Count > 0) { BackgroundJob job = backgroundJobs.Dequeue(); try { PresentationDomain.Invoke(() => job.Step.ChangeStatus(StepStatus.InProgress)); job.Action(); PresentationDomain.Invoke(() => job.Step.ChangeStatus(StepStatus.Complete)); } catch (Exception ex) { PresentationDomain.Invoke(() => job.Step.ChangeStatus(StepStatus.Failed)); ErrorHandling.LogException(ex, ErrorSeverity.FatalError); } } else { Thread.Sleep(100); } if (stopBackgroundWorker) { return; } } }) { IsBackground = true, Name = "Setup Assistant Worker" }; backgroundWorker.Start(); }
private static void SetProgressBar(double value) { if (splashWindow == null) { return; } if (value > 1.0) { return; } progress.Fraction = value; PresentationDomain.ProcessUIEvents(); }
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); } }
public Assistant(StepBase step) { assistType = AssistType.ApplicationSetup; allSteps = new List <StepBase> { step }; Initialize(); AppendStep(step); backgroundWorker = new Thread(delegate() { while (true) { if (backgroundJobs.Count > 0) { BackgroundJob job = backgroundJobs.Dequeue(); try { PresentationDomain.Invoke(() => job.Step.ChangeStatus(StepStatus.InProgress)); job.Action(); PresentationDomain.Invoke(() => job.Step.ChangeStatus(StepStatus.Complete)); } catch (Exception ex) { PresentationDomain.Invoke(() => job.Step.ChangeStatus(StepStatus.Failed)); ErrorHandling.LogException(ex, ErrorSeverity.FatalError); } } else { Thread.Sleep(100); } if (stopBackgroundWorker) { return; } } }) { IsBackground = true, Name = "Setup Assistant Worker" }; backgroundWorker.Start(); }
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); }
protected void btnOK_Clicked(object o, EventArgs args) { if (edited) { TryApplyShortcut(); BusinessDomain.FeedbackProvider.TrackEvent("Key shortcuts", "Edited"); } if (changedShortcuts.Count > 0) { if (Message.ShowDialog(Translator.GetString("Restart now?"), null, string.Format(Translator.GetString("In order for the change to take effect you need to restart {0}. Do you want to restart {0} now?"), DataHelper.ProductName), "Icons.Question32.png", MessageButtons.Restart | MessageButtons.Cancel) != ResponseType.Apply) { return; } KeyShortcuts.Save(changedShortcuts); PresentationDomain.QueueRestart(); } dlgEditKeyShortcuts.Respond(ResponseType.Ok); }
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(); }
public override void WillTerminate(NSNotification notification) { PresentationDomain.Quit(); }
public static void EditOperation(OperationType type, long id) { string message; bool readOnlyView; if (!BusinessDomain.CanEditOperation(type, id, out message, out readOnlyView) && !readOnlyView) { if (!string.IsNullOrWhiteSpace(message)) { MessageError.ShowDialog(message); } return; } WbpOperationBase page = null; long invNum; bool allowView = false; switch (type) { case OperationType.Purchase: if (BusinessDomain.RestrictionTree.GetRestriction("mnuEditDocsDelivery") != UserRestrictionState.Allowed) { break; } invNum = DocumentBase.GetLastDocumentNumber(id, OperationType.Purchase); if (invNum <= 0) { if (!PresentationDomain.CheckPurchasePricesDisabled()) { page = new WbpPurchase(id); } } else { ShowMessageHasInvoice(Purchase.GetById(id), invNum, "Icons.Purchase16.png", out allowView); if (allowView) { page = new WbpPurchase(id); } } break; case OperationType.Sale: if (BusinessDomain.RestrictionTree.GetRestriction("mnuEditDocsSale") != UserRestrictionState.Allowed) { break; } invNum = DocumentBase.GetLastDocumentNumber(id, OperationType.Sale); if (invNum <= 0) { page = new WbpSale(id); } else { ShowMessageHasInvoice(Sale.GetById(id), invNum, "Icons.Sale16.png", out allowView); if (allowView) { page = new WbpSale(id); } } break; case OperationType.Waste: if (BusinessDomain.RestrictionTree.GetRestriction("mnuEditDocsWaste") != UserRestrictionState.Allowed) { break; } page = new WbpWaste(id); break; case OperationType.StockTaking: if (BusinessDomain.RestrictionTree.GetRestriction("mnuEditDocsRevision") != UserRestrictionState.Allowed) { break; } if (!StockTaking.GetById(id).CheckIsNewFormat()) { break; } page = new WbpStockTaking(id); break; case OperationType.TransferIn: case OperationType.TransferOut: if (BusinessDomain.RestrictionTree.GetRestriction("mnuEditDocsTransfer") != UserRestrictionState.Allowed) { break; } page = new WbpTransfer(id); break; case OperationType.ComplexRecipeMaterial: case OperationType.ComplexRecipeProduct: if (BusinessDomain.RestrictionTree.GetRestriction("mnuOperProductionComplexRecipes") != UserRestrictionState.Allowed) { break; } if (!PresentationDomain.CheckPurchasePricesDisabled()) { using (EditNewComplexRecipe dlgRecipe = new EditNewComplexRecipe(ComplexRecipe.GetById(id))) dlgRecipe.Run(); } break; case OperationType.ComplexProductionMaterial: case OperationType.ComplexProductionProduct: if (BusinessDomain.RestrictionTree.GetRestriction("mnuEditDocsComplexProduction") != UserRestrictionState.Allowed) { break; } if (!PresentationDomain.CheckPurchasePricesDisabled()) { page = new WbpProduction(id); } break; default: if (operationEditors == null) { operationEditors = new List <IOperationEditor> (); foreach (TypeExtensionNode node in AddinManager.GetExtensionNodes("/Warehouse/Presentation/OperationEditor")) { IOperationEditor editor = node.CreateInstance() as IOperationEditor; if (editor != null) { operationEditors.Add(editor); } } } foreach (IOperationEditor editor in operationEditors) { if (editor.SupportedType != type) { continue; } page = editor.GetEditorPage(id); break; } break; } if (page == null) { return; } if (readOnlyView || allowView) { page.SetReadOnly(); } PresentationDomain.MainForm.AddNewPage(page); }
public static HardwareErrorResponse ShowHardwareErrorMessage(HardwareErrorException ex, MessageButtons buttonsMask) { HardwareErrorResponse ret = new HardwareErrorResponse { CancelLastReceipt = true }; string message = string.Empty; MessageButtons buttons = MessageButtons.Retry | MessageButtons.Cancel; ErrorState error = ex.Error; if (error.Check(ErrorState.CashReceiptPrinterDisconnected)) { message = Translator.GetString("Unable to connect to the cash receipt printer!"); } else if (error.Check(ErrorState.NonFiscalPrinterDisconnected)) { message = Translator.GetString("Unable to connect to the receipt printer!"); } else if (error.Check(ErrorState.ExternalDisplayDisconnected)) { message = Translator.GetString("Unable to connect to the external display!"); } else if (error.Check(ErrorState.CardReaderDisconnected)) { message = Translator.GetString("Unable to connect to the card reader!"); } else if (error.Check(ErrorState.KitchenPrinterError)) { if ((buttonsMask & MessageButtons.OK) == MessageButtons.OK) { message = Translator.GetString("Unable to print on the kitchen printer! Press \"Retry\" to try again or \"OK\" to print the receipt on the printer for customer orders."); buttons |= MessageButtons.OK; } else { message = Translator.GetString("Unable to print on the kitchen printer! Press \"Retry\" to try again."); } } else if (error.Check(ErrorState.KitchenPrinterDisconnected)) { message = Translator.GetString("Unable to connect to the kitchen printer!"); } else if (error.Check(ErrorState.ElectronicScaleDisconnected)) { message = Translator.GetString("Unable to connect to the electronic scale!"); } else if (error.Check(ErrorState.ElectronicScaleNotEnabled)) { message = Translator.GetString("There is no electronic scale installed or the electronic scale is not enabled!"); buttons = MessageButtons.Cancel; } else if (error.Check(ErrorState.SalesDataControllerDisconnected)) { message = Translator.GetString("Unable to connect to the sales data controller!"); } else if (error.Check(ErrorState.ClockNotSet)) { message = Translator.GetString("The clock of the fiscal printer is not set. Please set it to the correct time!"); } else if (error.Check(ErrorState.KitchenPrinterNoPaper)) { message = Translator.GetString("The kitchen printer is out of paper!"); buttons |= MessageButtons.OK; } else if (error.CheckError(ErrorState.NoPaper)) { message = Translator.GetString("The fiscal printer is out of paper. Please replace!"); ret.RetryWithoutPrint = true; } else if (error.Check(ErrorState.FiscalPrinterNotReady)) { message = Translator.GetString("The fiscal printer is not ready to print. Please make sure that the fiscal printer is in the correct mode!"); } else if (error.Check(ErrorState.WaitingPaperReplaceConfirmation)) { message = Translator.GetString("The fiscal printer waits for key combination to accept the replaced paper roll!"); ret.RetryWithoutPrint = true; } else if (error.CheckError(ErrorState.LittlePaper)) { message = Translator.GetString("There is a little paper in the printer. Please replace!"); ret.RetryWithoutPrint = true; } else if (error.Check(ErrorState.Report24HRequired)) { message = Translator.GetString("24 Hour report is required before you can continue working with the fiscal printer!"); } else if (error.Check(ErrorState.BadSerialPort)) { message = Translator.GetString("There was a problem connecting with the serial port. Please check the serial port!"); } else if (error.Check(ErrorState.BadConnectionParameters)) { message = Translator.GetString("There was a problem connecting with the device. Please check the connection parameters!"); } else if (error.Check(ErrorState.BadPassword)) { message = Translator.GetString("The password for the device is not correct!"); } else if (error.Check(ErrorState.BadLogicalAddress)) { message = Translator.GetString("The logical address for the device is not correct!"); } else if (error.Check(ErrorState.NotEnoughCashInTheRegister)) { message = Translator.GetString("There is not enough cash in the register to return change for the payment!"); ret.AskForPayment = true; } else if (error.Check(ErrorState.FiscalPrinterOverflow)) { message = Translator.GetString("An overflow occurred while transferring data to the fiscal printer!"); } else if (error.Check(ErrorState.TooManyTransactionsInReceipt)) { message = Translator.GetString("There are too many transactions in the operation for the fiscal printer to handle!"); buttons = MessageButtons.Cancel; } else if (error.Check(ErrorState.VATGroupsMismatch)) { message = Translator.GetString("The VAT groups defined does not match the VAT groups of the fiscal printer!"); buttons = MessageButtons.Cancel; } else if (error.Check(ErrorState.EvalItemsLimitation)) { message = string.Format(Translator.GetString("This is not a licensed version of {0}! Only less than 5 lines are allowed in a sale."), DataHelper.ProductName); buttons = MessageButtons.Cancel; } else if (error.Check(ErrorState.EvalPriceLimitation)) { message = string.Format(Translator.GetString("This is not a licensed version of {0}! Only prices less than 10 are allowed in a sale."), DataHelper.ProductName); buttons = MessageButtons.Cancel; } else if (error.Check(ErrorState.EvalQttyLimitation)) { message = string.Format(Translator.GetString("This is not a licensed version of {0}! Only quantities less than 3 are allowed in a sale."), DataHelper.ProductName); buttons = MessageButtons.Cancel; } else if (error.Check(ErrorState.EvalLimitation)) { message = string.Format(Translator.GetString("This is not a licensed version of {0}! Please purchase a license to use this device."), DataHelper.ProductName); buttons = MessageButtons.Cancel; } else if (error.Check(ErrorState.DriverNotFound)) { message = Translator.GetString("The device driver was not found. Please verify that it is properly installed and try again."); buttons = MessageButtons.Cancel; } else if (error.Count > 0) { message = Translator.GetString("An error in a peripheral device has occurred!"); message += "\n" + error; } using (MessageError msgDialog = new MessageError(message, ErrorSeverity.Error, ex)) { msgDialog.Buttons = buttons & buttonsMask; PresentationDomain.OnShowingDialog(); ret.Retry = false; ret.Button = MessageButtons.None; switch (msgDialog.Run()) { case ResponseType.Reject: ret.Button |= MessageButtons.Retry; ret.Retry = true; break; case ResponseType.Ok: ret.Button |= MessageButtons.OK; break; case ResponseType.Cancel: ret.Button |= MessageButtons.Cancel; break; case ResponseType.Yes: ret.Button |= MessageButtons.Yes; break; case ResponseType.No: ret.Button |= MessageButtons.No; break; } } return(ret); }
public void EnqueueBackgroundJob(BackgroundJob job) { PresentationDomain.Invoke(() => job.Step.ChangeStatus(StepStatus.Waiting), false, true); backgroundJobs.Enqueue(job); }
protected override void btnEdit_Clicked(object o, EventArgs args) { int selectedRow = grid.FocusedRow; if (selectedRow < 0) { return; } User user = entities [selectedRow]; selectedId = user.Id; if (user.Id == User.DefaultId) { MessageError.ShowDialog(string.Format(Translator.GetString("Cannot edit the default user \"{0}\"!"), user.Name), "Icons.User16.png"); return; } if (!user.CanEdit()) { MessageError.ShowDialog(Translator.GetString("Editing users with access level higher or equal of the current\'s one is not allowed!")); return; } // Added transaction to ensure that we are connected to the same server in case of // master-slave replication using (new DbMasterScope(BusinessDomain.DataAccessProvider)) { UserAccessLevel oldUserLevel = user.UserLevel; using (EditNewUser dialog = new EditNewUser(user, selectedGroupId)) { if (dialog.Run() != ResponseType.Ok) { ReinitializeGrid(true, null); return; } user = dialog.GetUser().CommitChanges(); selectedId = user.Id; bool refreshRestrictions = false; if (oldUserLevel != user.UserLevel) { if (Message.ShowDialog(Translator.GetString("Reset Permissions"), null, Translator.GetString("The access level of the user was changed. " + "Do you want to reset the permissions of this user to the default ones for the new access level?"), "Icons.Question32.png", MessageButtons.YesNo) == ResponseType.Yes) { BusinessDomain.RestrictionTree.ResetLevelRestrictions(user.Id, user.UserLevel); BusinessDomain.RestrictionTree.SaveRestrictions(); refreshRestrictions = true; } } if (BusinessDomain.LoggedUser.Id == user.Id) { PresentationDomain.RefreshMainFormStatusBar(); if (refreshRestrictions) { PresentationDomain.RefreshMainFormRestrictions(); } } } OnEntitiesChanged(user.Deleted ? UsersGroup.DeletedGroupId : user.GroupId); } }
private void ShowProgress(double progress) { PresentationDomain.Invoke(() => exportProgress.Progress = progress, true); }