Example #1
0
 public MainForm()
 {
     InitializeComponent();
     _pattern = new PattertInfo();
     //_columns = new List<ColumnInfo>();
     FillColumns();
     _allOffers       = new AllOffers();
     _offerCategories = new OfferCategories();
 }
Example #2
0
        private string CalculateValue(Offer offer, PattertInfo pattern, ColumnInfo prop, bool withDescriptor = false)
        {
            switch (prop.ColumnType)
            {
            case ColumnType.Flag:
            case ColumnType.Number:
                return(prop.Value.ToString());

            case ColumnType.Text:
                return(TrimByLength(prop.Value.ToString(), prop.Size));

            case ColumnType.Collection:
            case ColumnType.Value:
                var content = offer.GetContent();
                var name    = prop.Name;
                var value   = content.Element(name).Value;
                switch (name)
                {
                case "picture":
                    var n = 0;
                    foreach (var picture in content.Elements(name))
                    {
                        if (prop.Subindex == n++)
                        {
                            return(picture.Value);
                        }
                    }
                    return("");

                case "description":
                    var desc = "(смотри справа, в отдельном окне)";
                    if (withDescriptor)
                    {
                        desc = offer.GetDescriptorText(_pattern);
                    }
                    return(desc);

                case "name":
                    return(TrimByLength(value, prop.Size));

                default:
                    if (prop.ColumnType != ColumnType.Collection)
                    {
                        return(TrimByLength(value, prop.Size));
                    }
                    else
                    {
                        return(value);
                    }
                }

            default:
                return("(not defined)");
            }
        }
Example #3
0
        public string GetDescriptorText(PattertInfo pattern)
        {
            var content = this.GetContent();
            var value   = content.Element("description").Value;
            var prop    = pattern.Columns.First(item => item.Name == "description");
            var desc    = TrimByLength(pattern.CleanHtmlFromDescription ? Helper.CleanFromHtml(value) : value, prop.Size) + Environment.NewLine;

            if (pattern.AddArticleBeforeDescription)
            {
                desc = "Артикул: " + this.Id + Environment.NewLine + Environment.NewLine + desc;
            }
            if (pattern.AddParamAfterDescription && content.Elements("param").Count() > 0)
            {
                desc += Environment.NewLine + "Характеристики:" + Environment.NewLine;
                foreach (var param in content.Elements("param"))
                {
                    desc += Environment.NewLine + Helper.CleanMoreSpaces(param.Attribute("name").Value) + ": " +
                            Helper.CleanMoreSpaces(param.Value) + Environment.NewLine;
                }
            }
            if (pattern.AddExtraFieldsAfterDescription)
            {
                var names = new List <string>();
                foreach (var item in content.Elements()
                         .Select(x => x.Name.ToString())
                         .Distinct()
                         .OrderBy(name => name))
                {
                    names.Add(item);
                }
                foreach (var column in pattern.Columns)
                {
                    names.Remove(column.Name);
                }
                names.Remove("param");
                if (names.Count > 0)
                {
                    desc += Environment.NewLine + "Дополнительные поля:" + Environment.NewLine;
                    foreach (var name in names)
                    {
                        var fieldvalue = content.Element(name).Value;
                        if (string.IsNullOrWhiteSpace(fieldvalue.Trim()))
                        {
                            continue;
                        }
                        desc += Environment.NewLine + name + ": " + Helper.CleanMoreSpaces(fieldvalue) + Environment.NewLine;
                    }
                }
            }
            return(desc);
        }