Ejemplo n.º 1
0
        private static void ExportDocument(IList <Form> forms, string name, string fileName, bool portrait, string type, Type sourceObjectType = null, bool recalculateForm = true, PrintSettings printSettings = null, MarginsI margins = null)
        {
            IDocumentExporter exporter;
            string            filename;
            bool?  toFile;
            string email;
            string subject;

            using (ExportDocuments dialog = new ExportDocuments(sourceObjectType ?? forms [0].SourceObject.GetType(), fileName)) {
                if (dialog.Run() != ResponseType.Ok)
                {
                    return;
                }

                exporter = dialog.DocumentExporter;
                filename = dialog.FileName;
                toFile   = dialog.ToFile;
                email    = dialog.Email;
                subject  = dialog.EmailSubject;
            }

            BusinessDomain.FeedbackProvider.TrackEvent("Export document", type);

            try {
                exporter.Export(filename, toFile, email, subject, name, forms, portrait, recalculateForm, printSettings, margins);
            } catch (LicenseLimitationException ex) {
                MessageError.ShowDialog(ex.Message, ErrorSeverity.Warning, ex);
            } catch (IOException ex) {
                MessageError.ShowDialog(string.Format(Translator.GetString("Error occurred while saving export to \"{0}\". Please check if you have write permissions to that location."), filename), ErrorSeverity.Warning, ex);
            } catch (Exception ex) {
                MessageError.ShowDialog(Translator.GetString("Error occurred while performing export."), ErrorSeverity.Warning, ex);
            }
        }
Ejemplo n.º 2
0
        public static void ExportData <T> (string defaultFileName, string dataTypeName, DataExchangeSet exportData)
        {
            IDataExporter exporter;
            string        filename;
            bool?         toFile;
            string        email;
            string        subject;

            using (ExportObjects <T> dialog = new ExportObjects <T> (exportData.Contents, defaultFileName)) {
                if (dialog.Run() != ResponseType.Ok)
                {
                    return;
                }

                exporter = dialog.Exporter;
                filename = dialog.FileName;
                toFile   = dialog.ToFile;
                email    = dialog.Email;
                subject  = dialog.EmailSubject;
            }

            BusinessDomain.FeedbackProvider.TrackEvent("Export data", dataTypeName);

            try {
                exporter.Export(filename, toFile, email, subject, exportData);
            } catch (LicenseLimitationException ex) {
                MessageError.ShowDialog(ex.Message, ErrorSeverity.Warning, ex);
            } catch (IOException ex) {
                MessageError.ShowDialog(string.Format(Translator.GetString("Error occurred while saving export to \"{0}\". Please check if you have write permissions to that location."), filename), ErrorSeverity.Warning, ex);
            } catch (Exception ex) {
                MessageError.ShowDialog(Translator.GetString("Error occurred while performing export."), ErrorSeverity.Warning, ex);
            }
        }
Ejemplo n.º 3
0
        private void btnRemove_Clicked(object sender, EventArgs e)
        {
            Button btn  = (Button)sender;
            User   user = (User)btn.Data ["User"];

            switch (User.RequestDelete(user.Id))
            {
            case DeletePermission.InUse:
                MessageError.ShowDialog(
                    Translator.GetString("This user cannot be deleted, because it is used in operations. Please, delete the corresponding operations in order to delete this user!"),
                    "Icons.User16.png");
                return;

            case DeletePermission.Reserved:
            case DeletePermission.No:
                MessageError.ShowDialog(string.Format(Translator.GetString("Cannot delete user \"{0}\"!"), user.Name),
                                        "Icons.User16.png");
                return;

            default:
                if (user.UserLevel == UserAccessLevel.Owner)
                {
                    bool foundOwner = false;
                    bool foundUser  = false;
                    foreach (User u in User.GetAll())
                    {
                        if (u.Id == User.DefaultId || u.Id == user.Id)
                        {
                            continue;
                        }

                        if (u.UserLevel == UserAccessLevel.Owner)
                        {
                            foundOwner = true;
                        }
                        else
                        {
                            foundUser = true;
                        }
                    }

                    if (!foundOwner && foundUser)
                    {
                        MessageError.ShowDialog(Translator.GetString("The last owner cannot be deleted before the rest of the users!"),
                                                "Icons.User16.png");
                        return;
                    }
                }
                break;
            }

            User.Delete(user.Id);
            RefreshUsersTable();
        }
Ejemplo n.º 4
0
        public override bool Validate()
        {
            foreach (Location location in locations)
            {
                location.Name = entries [location].Text;
            }

            for (int i = 0; i < locations.Count - 2; i++)
            {
                for (int j = i + 1; j < locations.Count - 1; j++)
                {
                    if (locations [i].Name != locations [j].Name)
                    {
                        continue;
                    }

                    if (MessageError.ShowDialog(string.Format(Translator.GetString("Location with the name \"{0}\" is used more than once! Are you sure you want to continue?"), locations [i].Name),
                                                buttons: MessageButtons.YesNo) != ResponseType.Yes)
                    {
                        return(false);
                    }
                }
            }

            foreach (Location location in locations)
            {
                if (!location.Validate((message, severity, code, state) =>
                {
                    using (MessageError dlgError = new MessageError(message, severity))
                        if (severity == ErrorSeverity.Warning)
                        {
                            dlgError.Buttons = MessageButtons.YesNo;
                            if (dlgError.Run() != ResponseType.Yes)
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            dlgError.Run();
                            return(false);
                        }

                    return(true);
                }, null))
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 5
0
        private void btn_Clicked(object sender, EventArgs e)
        {
            EventHandler <EntitySuggestedEventArgs> handler = EntitySuggested;

            if (handler == null)
            {
                return;
            }

            MessageError.ShowDialog(string.Format(Translator.GetString("You can enable the suggestions from {0}->{1}"), Translator.GetString("Settings"), Translator.GetString("Special")), ErrorSeverity.Information);
            BusinessDomain.AppConfiguration.ShowItemSuggestionsWhenNotFound = false;
            handler(this, new EntitySuggestedEventArgs(null));
        }
Ejemplo n.º 6
0
 public Form LoadForm(IDocument document)
 {
     try {
         return(document.LoadForm());
     } catch (Exception exception) {
         if (exception is XmlException)
         {
             MessageError.ShowDialog(string.Format(Translator.GetString("The file \"{0}\" has an incorrect structure (invalid XML)."),
                                                   Path.Combine(BusinessDomain.AppConfiguration.DocumentTemplatesFolder, Path.ChangeExtension(document.FormName, "xml"))), ErrorSeverity.Error);
         }
         ErrorHandling.LogException(exception);
         return(document.LoadForm(string.Empty));
     }
 }
Ejemplo n.º 7
0
        protected virtual void btnPrint_Clicked(object sender, EventArgs e)
        {
            try {
                if (PrintDocument.PrintSettings != null)
                {
                    PrintDocument.PrintSettings.Orientation = currentPreview.Portrait ? PageOrientation.Portrait : PageOrientation.Landscape;
                }

                FormHelper.PrintObject(document, PrintDocument.PrintSettings);
            } catch (Exception ex) {
                MessageError.ShowDialog(
                    Translator.GetString("An error occurred while printing document!"),
                    ErrorSeverity.Error, ex);
            }
        }
Ejemplo n.º 8
0
        private static void ImportData <T> (ImporterCallback <T> callback, bool usesLocation)
        {
            IDataImporter importer;
            string        filename;
            long?         locationId;

            BusinessDomain.FeedbackProvider.TrackEvent("Import data", typeof(T).Name.CamelSpace());

            using (ImportObjects <T> dialog = new ImportObjects <T> (usesLocation)) {
                if (dialog.Run() != ResponseType.Ok)
                {
                    return;
                }

                importer   = dialog.Importer;
                filename   = dialog.FileName;
                locationId = dialog.Location != null ? dialog.Location.Id : (long?)null;
            }

            if (importer.UsesFile && !File.Exists(filename))
            {
                MessageError.ShowDialog(Translator.GetString("Please select a valid source file to import!"));
                return;
            }

            try {
                PropertyMap propertyMap;
                using (ImportObjectsMapping <T> dialog = new ImportObjectsMapping <T> (importer, filename)) {
                    if (dialog.Run() != ResponseType.Ok)
                    {
                        return;
                    }

                    propertyMap = dialog.PropertyMap;
                }

                ExchangeHelper.ImportObjects(importer, filename, propertyMap, locationId, callback);
                MessageError.ShowDialog(Translator.GetString("Import completed successfully."), ErrorSeverity.Information);
            } catch (LicenseLimitationException ex) {
                MessageError.ShowDialog(ex.Message, ErrorSeverity.Warning, ex);
            } catch (IOException ex) {
                MessageError.ShowDialog(Translator.GetString("The selected source file is in use by another application! Please close all other applications and try again."), ErrorSeverity.Warning, ex);
            } catch (Exception ex) {
                MessageError.ShowDialog(Translator.GetString("Error occurred while performing import."), ErrorSeverity.Warning, ex);
            }
        }
Ejemplo n.º 9
0
        public void btnDelete_Clicked(object sender, EventArgs e)
        {
            T group = gPanel.GetSelectedGroup();
            DeletePermission permission = GetDeletePermission(group);

            switch (permission)
            {
            case DeletePermission.InUse:
                MessageError.ShowDialog(
                    Translator.GetString("This group cannot be deleted, because it is not empty. Please, delete or move to another group the containing items in order to delete this group!"),
                    "Icons.Group16.png");
                return;

            case DeletePermission.Reserved:
            case DeletePermission.No:
                MessageError.ShowDialog(
                    string.Format(Translator.GetString("Cannot delete group \"{0}\"!"), group.Name),
                    "Icons.Group16.png");
                return;
            }

            using (MessageOkCancel dialog = new MessageOkCancel(
                       Translator.GetString("Delete group"), "Icons.Group16.png",
                       string.Format(Translator.GetString("Do you want to delete group with name \"{0}\"?"), group.Name),
                       "Icons.Delete32.png")) {
                if (dialog.Run() != ResponseType.Ok)
                {
                    return;
                }
            }

            DeleteGroup(group);
            ReloadGroups();
            if (group.Parent != null)
            {
                gPanel.SelectGroupId(group.Parent.Id);
            }
            else
            {
                gPanel.SelectGroupId(-1);
            }
            OnGroupDeleted();
        }
Ejemplo n.º 10
0
        protected override void SetDate(DateTime d)
        {
            useCalculatedAvailability = false;
            if (date != DateTime.MinValue && d < BusinessDomain.Today)
            {
                if (BusinessDomain.AppConfiguration.AllowNegativeAvailability)
                {
                    useCalculatedAvailability = Message.ShowDialog(Translator.GetString("Stock-taking in the Past"), string.Empty,
                                                                   Translator.GetString("You are setting a date in the past. Do you want to use calculated availability for the selected date?"), "Icons.Question32.png",
                                                                   MessageButtons.YesNo) == ResponseType.Yes;
                }
                else
                {
                    MessageError.ShowDialog(Translator.GetString("You are setting a date in the past. Using calculated items availability " +
                                                                 "is only available when working with negative availability is allowed. The items availability in this moment will be used."));
                }
            }

            base.SetDate(d);
        }
Ejemplo n.º 11
0
        public override bool Validate()
        {
            IList <CustomerWrapper> allCustomers = GetAllCustomers();

            for (int i = 0; i < allCustomers.Count - 2; i++)
            {
                for (int j = i + 1; j < allCustomers.Count - 1; j++)
                {
                    if (allCustomers [i].Customer.Name != allCustomers [j].Customer.Name)
                    {
                        continue;
                    }

                    if (MessageError.ShowDialog(string.Format(Translator.GetString("Customer with the name \"{0}\" is used more than once! Are you sure you want to continue?"), allCustomers [i].Customer.Name),
                                                buttons: MessageButtons.YesNo) != ResponseType.Yes)
                    {
                        return(false);
                    }
                }
            }

            return(allCustomers.All(customer => customer.Validate((message, severity, code, state) =>
            {
                using (MessageError dlgError = new MessageError(message, severity))
                    if (severity == ErrorSeverity.Warning)
                    {
                        dlgError.Buttons = MessageButtons.YesNo;
                        if (dlgError.Run() != ResponseType.Yes)
                        {
                            return false;
                        }
                    }
                    else
                    {
                        dlgError.Run();
                        return false;
                    }

                return true;
            }, null)));
        }
        public bool Validate()
        {
            string name = txtName.Text.Trim();

            if (name.Length == 0)
            {
                MessageError.ShowDialog(Translator.GetString("Company name cannot be empty!"));
                return(false);
            }

            CompanyRecord c = CompanyRecord.GetByName(name);

            if (c != null && c.Id != companyRecord.Id)
            {
                if (Message.ShowDialog(Translator.GetString("Warning!"), string.Empty,
                                       Translator.GetString("Company with this name already exists! Do you want to continue?"), "Icons.Warning32.png",
                                       MessageButtons.YesNo) != ResponseType.Yes)
                {
                    return(false);
                }
            }

            string code = txtCode.Text.Trim();

            c = CompanyRecord.GetByCode(name);

            if (!string.IsNullOrEmpty(code) && c != null && c.Id != companyRecord.Id)
            {
                if (Message.ShowDialog(Translator.GetString("Warning!"), string.Empty,
                                       Translator.GetString("Company with this code already exists! Do you want to continue?"), "Icons.Warning32.png",
                                       MessageButtons.YesNo) != ResponseType.Yes)
                {
                    return(false);
                }
            }

            return(true);
        }
Ejemplo n.º 13
0
        public override void OnOperationSave(bool askForConfirmation)
        {
            bool printReceipt = false;

            if (!OperationValidate())
            {
                return;
            }

            if (!OperationDetailsValidate(true))
            {
                return;
            }

            if (askForConfirmation)
            {
                MessageOkCancel dialogSave;
                if (editMode)
                {
                    dialogSave = new MessageOkCancel(
                        Translator.GetString("Edit waste"), string.Empty,
                        Translator.GetString("Do you want to save the changes?"), "Icons.Question32.png");
                }
                else
                {
                    dialogSave = new MessageOkCancel(
                        Translator.GetString("Saving waste"), string.Empty,
                        Translator.GetString("Do you want to save the operation?"), "Icons.Question32.png");
                }

                if (dialogSave.Run() != ResponseType.Ok)
                {
                    operation.AddNewDetail();
                    EditGridField(operation.Details.Count - 1, colItem.Index);
                    return;
                }
            }

            if (BusinessDomain.AppConfiguration.IsPrintingAvailable())
            {
                if (BusinessDomain.AppConfiguration.AskBeforeDocumentPrint == AskDialogState.NotSaved)
                {
                    using (MessageYesNoRemember dialogPrint = new MessageYesNoRemember(
                               Translator.GetString("Print document"), string.Empty,
                               Translator.GetString("Do you want to print a document?"), "Icons.Question32.png")) {
                        ResponseType resp = dialogPrint.Run();
                        if (resp == ResponseType.Yes)
                        {
                            printReceipt = true;
                        }

                        if (dialogPrint.RememberChoice)
                        {
                            BusinessDomain.AppConfiguration.AskBeforeDocumentPrint = resp == ResponseType.Yes ? AskDialogState.Yes : AskDialogState.No;
                        }
                    }
                }
                else if (BusinessDomain.AppConfiguration.AskBeforeDocumentPrint == AskDialogState.Yes)
                {
                    printReceipt = true;
                }
            }

            try {
                PrepareOpertionForSaving();
                CommitOperation();
            } catch (InsufficientItemAvailabilityException ex) {
                MessageError.ShowDialog(string.Format(Translator.GetString("The waste cannot be saved due to insufficient quantity of item \"{0}\"."), ex.ItemName),
                                        ErrorSeverity.Warning, ex);
                EditGridField(ex.ItemName);
                return;
            } catch (Exception ex) {
                MessageError.ShowDialog(
                    Translator.GetString("An error occurred while saving the waste operation!"),
                    ErrorSeverity.Error, ex);
                return;
            }

            if (printReceipt && WaitForPendingOperationCompletion())
            {
                try {
                    WasteProtocol protocol = new WasteProtocol(operation);
                    FormHelper.PrintPreviewObject(protocol);
                } catch (Exception ex) {
                    MessageError.ShowDialog(
                        Translator.GetString("An error occurred while generating the protocol!"),
                        ErrorSeverity.Error, ex);
                }
            }

            OnOperationSaved();

            if (editMode)
            {
                OnPageClose();
            }
            else
            {
                ReInitializeForm(null);
            }
        }
Ejemplo n.º 14
0
        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);
        }
Ejemplo n.º 15
0
        public override void OnOperationSave(bool askForConfirmation)
        {
            #region Prepare the purchase object

            if (!OperationValidate())
            {
                return;
            }

            if (!OperationDetailsValidate(true))
            {
                return;
            }

            #endregion

            if (!TryApplyRules())
            {
                return;
            }

            bool printPayment;
            using (EditNewPayment dialogFinalize = new EditNewPayment(operation)) {
                if (dialogFinalize.Run() != ResponseType.Ok)
                {
                    ClearDetailsFromPriceRules(true);
                    return;
                }
                printPayment = dialogFinalize.PrintDocument;
            }

            if (!PriceRule.ApplyOnPaymentSet(operation))
            {
                return;
            }

            try {
                var newPayments = GetAllNewPayments(printPayment);
                PrepareOpertionForSaving();
                CommitOperation();
                PrintAllNewPayments(newPayments);
            } catch (InsufficientItemAvailabilityException ex) {
                MessageError.ShowDialog(string.Format(Translator.GetString("The purchase cannot be saved due to insufficient quantities of item \"{0}\"."), ex.ItemName),
                                        ErrorSeverity.Warning, ex);
                ClearDetailsFromPriceRules();
                EditGridField(ex.ItemName);
                return;
            } catch (Exception ex) {
                MessageError.ShowDialog(Translator.GetString("An error occurred while saving purchase document!"),
                                        ErrorSeverity.Error, ex);
                ClearDetailsFromPriceRules(true);
                return;
            }

            ApplyFinalPriceRules();

            if (BusinessDomain.AppConfiguration.AutoCreateInvoiceOnPurchase && !editMode &&
                WaitForPendingOperationCompletion())
            {
                using (EditNewInvoice dlgInvoice = new EditNewInvoice(operation))
                    dlgInvoice.Run();
            }

            #region Ask to print a document

            bool printReceipt = false;

            if (BusinessDomain.AppConfiguration.IsPrintingAvailable() && BusinessDomain.WorkflowManager.AllowPurchaseReceiptPrint(operation, false))
            {
                if (BusinessDomain.AppConfiguration.AskBeforeDocumentPrint == AskDialogState.NotSaved)
                {
                    using (MessageYesNoRemember dialogPrint = new MessageYesNoRemember(
                               Translator.GetString("Print document"), string.Empty,
                               Translator.GetString("Do you want to print a stock receipt?"), "Icons.Question32.png")) {
                        ResponseType resp = dialogPrint.Run();
                        if (resp == ResponseType.Yes)
                        {
                            printReceipt = true;
                        }

                        if (dialogPrint.RememberChoice)
                        {
                            BusinessDomain.AppConfiguration.AskBeforeDocumentPrint = resp == ResponseType.Yes ? AskDialogState.Yes : AskDialogState.No;
                        }
                    }
                }
                else if (BusinessDomain.AppConfiguration.AskBeforeDocumentPrint == AskDialogState.Yes)
                {
                    printReceipt = true;
                }
            }

            if (printReceipt && WaitForPendingOperationCompletion())
            {
                try {
                    PurchaseReceipt receipt = new PurchaseReceipt(operation);
                    FormHelper.PrintPreviewObject(receipt);
                } catch (Exception ex) {
                    MessageError.ShowDialog(
                        Translator.GetString("An error occurred while generating stock receipt!"),
                        ErrorSeverity.Error, ex);
                }
            }

            #endregion

            OnOperationSaved();

            if (editMode)
            {
                OnPageClose();
            }
            else
            {
                ReInitializeForm(null);
            }
        }