Example #1
0
        /// <summary>
        /// Shows suggestions for new partners to be added to the system
        /// </summary>
        /// <param name="value">Returns suggested partners or null if browsing for partners should be used</param>
        /// <param name="operation"></param>
        /// <returns></returns>
        public static Partner [] ShowPartnerMissing(string value, object operation)
        {
            var providers = AllSuggestionProviders.Where(s =>
                                                         s.SupportedEntities == SuggestionEntityType.Partner &&
                                                         s.CheckAvailableFor(value)).ToList();

            if (providers.Count == 0)
            {
                return(null);
            }

            providers.Add(new PartnerBrowse());
            providers.Add(new PartnerAlwaysBrowse());

            Partner suggestedEntity;

            using (EntityMissing dialog = new EntityMissing()) {
                dialog.DialogControl.Title = string.Format(Translator.GetString("Partner \"{0}\" cannot be found!"), value);
                dialog.DialogControl.Icon  = FormHelper.LoadImage("Icons.Partner16.png").Pixbuf;
                dialog.SetSuggestions(providers, value, operation);
                if (dialog.Run() != ResponseType.Ok)
                {
                    return(new Partner [0]);
                }

                suggestedEntity = (Partner)dialog.SuggestedEntity;
                if (suggestedEntity == null)
                {
                    return(null);
                }
            }

            // Getti may use an existing partner when a customer card is swiped
            if (suggestedEntity.Id > 0)
            {
                return new [] { suggestedEntity }
            }
            ;

            if (BusinessDomain.AppConfiguration.AutoGeneratePartnerCodes && string.IsNullOrWhiteSpace(suggestedEntity.Code))
            {
                suggestedEntity.AutoGenerateCode();
            }

            using (EditNewPartner dlgItem = new EditNewPartner(suggestedEntity, allowSaveAndNew: false)) {
                if (dlgItem.Run() != ResponseType.Ok)
                {
                    return(new Partner [0]);
                }

                return(new [] { dlgItem.GetPartner().CommitChanges() });
            }
        }
    }
Example #2
0
        /// <summary>
        /// Shows suggestions for new items to be added to the system
        /// </summary>
        /// <param name="value">Returns suggested items or null if browsing for items should be used</param>
        /// <param name="operation"></param>
        /// <returns></returns>
        public static Item [] ShowItemMissing(string value, object operation)
        {
            var providers = AllSuggestionProviders.Where(s =>
                                                         s.SupportedEntities == SuggestionEntityType.Item &&
                                                         s.CheckAvailableFor(value)).ToList();

            if (providers.Count == 0)
            {
                return(null);
            }

            providers.Add(new ItemBrowse());
            providers.Add(new ItemAlwaysBrowse());

            Item suggestedEntity;

            using (EntityMissing dialog = new EntityMissing()) {
                dialog.DialogControl.Title = string.Format(Translator.GetString("Item \"{0}\" cannot be found!"), value);
                dialog.DialogControl.Icon  = FormHelper.LoadImage("Icons.Goods16.png").Pixbuf;
                dialog.SetSuggestions(providers, value, operation);
                if (dialog.Run() != ResponseType.Ok)
                {
                    return(new Item [0]);
                }

                suggestedEntity = (Item)dialog.SuggestedEntity;
                if (suggestedEntity == null)
                {
                    return(null);
                }
            }

            if (BusinessDomain.AppConfiguration.AutoGenerateItemCodes && string.IsNullOrWhiteSpace(suggestedEntity.Code))
            {
                suggestedEntity.AutoGenerateCode();
            }

            using (EditNewItem dlgItem = new EditNewItem(suggestedEntity, allowSaveAndNew: false)) {
                if (dlgItem.Run() != ResponseType.Ok)
                {
                    return(new Item [0]);
                }

                return(new [] { dlgItem.GetItem().CommitChanges() });
            }
        }