Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public static bool InteractiveValidationCallback(string message, ErrorSeverity severity, int code, StateHolder state)
        {
            Dictionary <int, bool> responses       = (Dictionary <int, bool>)state ["responses"];
            MessageProgress        messageProgress = null;

            if (state.ContainsKey("messageProgress"))
            {
                messageProgress = (MessageProgress)state ["messageProgress"];
            }

            if (responses.ContainsKey(code))
            {
                return(severity == ErrorSeverity.Warning && responses [code]);
            }

            try {
                if (messageProgress != null)
                {
                    messageProgress.Hide();
                }
                using (MessageError dlgError = new MessageError(message, severity)) {
                    if (severity == ErrorSeverity.Warning)
                    {
                        dlgError.Buttons = MessageButtons.YesNo | MessageButtons.Remember;
                        ResponseType resp = dlgError.Run();
                        if (dlgError.RememberChoice)
                        {
                            responses [code] = resp == ResponseType.Yes;
                        }

                        return(resp == ResponseType.Yes);
                    }
                    else
                    {
                        dlgError.Buttons = MessageButtons.OK | MessageButtons.Remember;
                        dlgError.Run();
                        if (dlgError.RememberChoice)
                        {
                            responses [code] = true;
                        }
                        return(false);
                    }
                }
            } finally {
                if (messageProgress != null)
                {
                    messageProgress.Show();
                }
            }
        }
Exemplo n.º 3
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)));
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        public static bool ShowMessageHasInvoice <TOper> (TOper oper, long invNum, string icon, out bool allowView, bool annulling = false, DocumentChoiceType choiceType = DocumentChoiceType.Choose) where TOper : Operation
        {
            string message = null;

            allowView = false;
            if (annulling)
            {
                if (oper.OperationType == OperationType.Purchase)
                {
                    message = Translator.GetString("Document No.{0} cannot be annulled because the received invoice " +
                                                   "No.{1} is attached to it. Please, void the invoice before annulling this document.");
                }
                else
                {
                    message = Translator.GetString("Document No.{0} cannot be annulled because the issued invoice " +
                                                   "No.{1} is attached to it. Please, void the invoice before annulling this document.");
                }
            }
            else if (choiceType == DocumentChoiceType.CreateChildDocument)
            {
                if (oper.OperationType == OperationType.Purchase)
                {
                    message = Translator.GetString("Document No.{0} cannot be attached to invoice because the received invoice " +
                                                   "No.{1} is already attached to it. Please, void the invoice before attaching another invoice to this document.");
                }
                else
                {
                    message = Translator.GetString("Document No.{0} cannot be attached to another invoice because the issued invoice " +
                                                   "No.{1} is already attached to it. Please, void the invoice before attaching another invoice to this document.");
                }
            }

            if (message == null)
            {
                allowView = true;
                if (BusinessDomain.LoggedUser.UserLevel > UserAccessLevel.Operator)
                {
                    return(ShowMessageHasInvoiceChangeUser(oper, invNum, icon, out allowView));
                }

                if (oper.OperationType == OperationType.Consignment)
                {
                    message = Translator.GetString("Consignment No.{0} cannot be edited because the issued invoice " +
                                                   "No.{1} is attached to a sale on it. Please, void the invoice before editing this consignment.");
                }
                else if (oper.OperationType != OperationType.Purchase)
                {
                    message = Translator.GetString("Document No.{0} cannot be edited because the issued invoice " +
                                                   "No.{1} is attached to it. Please, void the invoice before editing this document.");
                }
                else
                {
                    message = Translator.GetString("Document No.{0} cannot be edited because the received invoice " +
                                                   "No.{1} is attached to it. Please, void the invoice before editing this document.");
                }
            }

            using (MessageError msg = new MessageError(string.Format(message,
                                                                     Operation.GetFormattedOperationNumber(oper.Id),
                                                                     Operation.GetFormattedOperationNumber(invNum)), icon, ErrorSeverity.Warning, null))
                msg.Run();

            return(false);
        }