Ejemplo n.º 1
0
        public static List <cStyle> GetStyles(List <cStyleFlat> FlatData)
        {
            var grpStyle = FlatData.GroupBy(x => x.Style_Number);

            List <cStyle> styles = new List <cStyle>();

            //int maxhue = 0;
            //int minoverride = 1;
            foreach (var grp in grpStyle)
            {
                var    colors = GetColors(FlatData, grp.Key);
                var    sizes  = GetSizes(FlatData, grp.Key);
                cStyle style  = grp.Select(x => new cStyle
                {
                    Style_Number         = x.Style_Number,
                    Detailed_Description = x.Detailed_Description,
                    Gender          = x.Gender,
                    Manufacturer    = x.Manufacturer,
                    Print_Positions = x.Print_Positions
                    ,
                    ColorSize           = new List <cColorSize>(),
                    Website_Description = x.Website_Description,
                    MaxHue      = int.Parse(x.Max_Hue),
                    MinOverride = int.Parse(x.Min_Override)
                }).First();
                foreach (var color in colors)
                {
                    foreach (var size in sizes)
                    {
                        var q = grp.Where(x => x.Color_Description == color.Color_Description && x.Size == size.Size_Description).Select(x => x.Catalog_Price).FirstOrDefault();
                        if (q != null)
                        {
                            cColorSize colorsize = new cColorSize {
                                Catalog_Price = q, color = color, size = size
                            };
                            style.ColorSize.Add(colorsize);
                        }
                    }
                }
                styles.Add(style);
            }
            return(styles);
        }
        public static List <cStyle> GetStylesByClientID(int ClientID)
        {
            OleDbConnection Conn = new OleDbConnection();
            DataTable       dt   = new DataTable();

            using (OleDbConnection con = new OleDbConnection(string.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=MSAccess.mdb;Persist Security Info=False;")))
            {
                StringBuilder sql = new StringBuilder();
                sql.Append("SELECT billing_shirt_style.ID as ID, billing_shirt_style.* ");
                sql.Append("FROM billing_shirt_style ");
                sql.Append("INNER JOIN Customer_Buys ON billing_shirt_style.ID = Customer_Buys.Style ");
                sql.Append("WHERE Customer_Buys.Customer_Name=" + ClientID + " AND customer_buys.discontinued=false AND billing_shirt_style.discontinued = false ");
                OleDbDataAdapter da = new OleDbDataAdapter(sql.ToString(), con);
                da.Fill(dt);
            }
            var colors  = GetColorsByClientID(ClientID);
            var sizes   = GetSizesByClientID(ClientID);
            var pricing = GetPricingByClientID(ClientID);
            var styles  = ImportHelper.GetObjectsFromDataTable <cStyle>(dt);

            foreach (var style in styles)
            {
                style.Gender = (Globals.GenderDictionary.ContainsKey(style.Gender) ? Globals.GenderDictionary[style.Gender] : "Other");

                style.ColorSize = new List <cColorSize>();
                int maxhue      = 0;
                int minoverride = 1;
                var stylecolor  = colors.Where(x => x.shirt_style_number == style.ID);
                var stylesizes  = sizes.Where(x => x.Shirt_Style_Number == style.ID);
                var styleprices = pricing.Where(x => x.Shirt_Style == style.ID);
                foreach (var color in stylecolor)
                {
                    foreach (var size in stylesizes.OrderBy(x => x.size_id))
                    {
                        if (int.Parse(color.Hue) > 0)
                        {
                            maxhue = 1;
                        }
                        if (int.Parse(color.Underbase_NO_Override) < 1)
                        {
                            minoverride = 0;
                        }

                        cColorSize colorsize = new cColorSize {
                            color = color, size = size
                        };

                        var price = styleprices.Where(x => x.Size == size.Size_Description && x.Color_Type == color.Color_Type).FirstOrDefault();
                        if (price != null)
                        {
                            colorsize.Catalog_Price = price.Catalog_Price;
                        }

                        style.ColorSize.Add(colorsize);
                    }
                }
                style.MaxHue      = maxhue;
                style.MinOverride = minoverride;
            }

            return(styles);
        }