Example #1
0
        private void btn_Sorgula_Click(object sender, EventArgs e)
        {
            var names = new List <string> {
                "aaa", "bbb"
            };

            names.Add("ccc");

            var context = new PatifoodDataContext();
            //var orders = context.Orders.ToList();


            //var orders = context.Orders.Where(c => c.OrderProducts.Any(op => names.Contains(op.product.category.name) && op.product.category.name == cmb_Il.SelectedValue && op.product.name == cmb_TeslimYeri.SelectedValue )).ToList();

            var orders = context.OrderProducts.Where(c => c.product.name == cmb_TeslimYeri.SelectedValue).ToList();

            Dgw1.DataSource = orders;
        }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            logTxt.Text = "StartDate: " + dateTimePicker1.Value + " EndDate: " + dateTimePicker2.Value;

            logTxt.AppendText("\r\ngetOrders");
            var param = new Dictionary <string, string>();

            param.Add("act", "getOrders");
            param.Add("start_date", String.Format("{0:yyyy-MM-dd}", dateTimePicker1.Value));
            param.Add("end_date", String.Format("{0:yyyy-MM-dd}", dateTimePicker2.Value));

            var pageContent = HttpPostRequest(param);


            XmlSerializer serializer = new XmlSerializer(typeof(Orders.items));
            StringReader  rdr        = new StringReader(pageContent);

            Orders.items orders = (Orders.items)serializer.Deserialize(rdr);

            progressBar1.Maximum = orders.item.Count();

            // bool hataVar = false;

            var say = 0;



            foreach (var orderItem in orders.item)
            {
                var context  = new PatifoodDataContext();
                var newOrder = false;

                logTxt.AppendText("\r\n");
                logTxt.AppendText("OrderId:" + orderItem.order_id + " Name" + orderItem.firstname + " " + orderItem.lastname);
                say++;
                progressBar1.Value = say;
                lblStatus.Text     = say + "/" + progressBar1.Maximum;

                var order = context.Orders.Where(c => c.order_id == orderItem.order_id).FirstOrDefault();

                if (order != null)
                {
                    continue;
                }
                else
                {
                    order = Form1.newOrder(orderItem);

                    newOrder = true;
                }
                //if (say == 94)
                //    MessageBox.Show("");

                //if (orderItem.order_status_id != 1 && orderItem.order_status_id != 12)
                //    continue;

                param = new Dictionary <string, string>();

                logTxt.AppendText("\r\n");
                logTxt.AppendText("getOrderProducts");

                param.Add("act", "getOrderProducts");
                param.Add("order_id", orderItem.order_id.ToString());

                pageContent = HttpPostRequest(param);

                serializer = new XmlSerializer(typeof(OrderProducts.items));
                rdr        = new StringReader(pageContent);
                OrderProducts.items orderProducts = (OrderProducts.items)serializer.Deserialize(rdr);

                foreach (var orderProduct in orderProducts.item)
                {
                    logTxt.AppendText("\r\n");
                    logTxt.AppendText("OrderProductId:" + orderProduct.order_product_id + " Name" + orderProduct.name);

                    var orderProductContext = context.OrderProducts.FirstOrDefault(c => c.order_product_id == orderProduct.order_product_id);

                    if (orderProductContext == null)
                    {
                        orderProductContext = new OrderProduct();

                        orderProductContext.Id                    = Guid.NewGuid();
                        orderProductContext.customer_id           = orderProduct.customer_id;
                        orderProductContext.model                 = orderProduct.model;
                        orderProductContext.name                  = orderProduct.name;
                        orderProductContext.option_code           = orderProduct.option_code;
                        orderProductContext.option_name           = orderProduct.option_name;
                        orderProductContext.order                 = order;
                        orderProductContext.order_product_id      = orderProduct.order_product_id;
                        orderProductContext.price                 = orderProduct.price;
                        orderProductContext.price_code            = orderProduct.price_code;
                        orderProductContext.quantity              = orderProduct.quantity;
                        orderProductContext.receiving_price       = orderProduct.receiving_price;
                        orderProductContext.reward                = orderProduct.reward;
                        orderProductContext.tax                   = orderProduct.tax;
                        orderProductContext.tax_class_description = orderProduct.tax_class_description;
                        orderProductContext.total                 = orderProduct.total;
                    }


                    logTxt.AppendText("\r\n");
                    logTxt.AppendText("getOrderProducts");

                    param = new Dictionary <string, string>();

                    param.Add("act", "getProduct");
                    param.Add("product_id", orderProduct.product_id.ToString());

                    pageContent = HttpPostRequest(param);

                    serializer = new XmlSerializer(typeof(XmlModel.Product.items));
                    rdr        = new StringReader(pageContent);
                    XmlModel.Product.items product = (XmlModel.Product.items)serializer.Deserialize(rdr);

                    var productContext = context.Products.Where(c => c.product_id == product.item.product_id).FirstOrDefault();

                    //if (productContext != null)
                    //    order.Products.Add(productContext);
                    //else
                    {
                        productContext = new PatifoodDataModel.Models.Product();

                        productContext.Id                        = Guid.NewGuid();
                        productContext.category_names            = product.item.category_names;
                        productContext.cevirmen_id               = product.item.cevirmen_id;
                        productContext.customer_id               = product.item.customer_id;
                        productContext.date_added                = product.item.date_added;
                        productContext.date_available            = product.item.date_available;
                        productContext.date_in_stock             = product.item.date_in_stock;
                        productContext.date_modified             = product.item.date_modified;
                        productContext.delivery_info             = product.item.delivery_info;
                        productContext.description               = product.item.description;
                        productContext.entegrasyon_code          = product.item.entegrasyon_code;
                        productContext.height                    = product.item.height;
                        productContext.image                     = product.item.image;
                        productContext.index_status              = product.item.index_status;
                        productContext.language_id               = product.item.language_id;
                        productContext.length                    = product.item.length;
                        productContext.location                  = product.item.location;
                        productContext.manufacturer_id           = int.Parse(product.item.manufacturer_id.ToString());
                        productContext.maximum                   = product.item.maximum;
                        productContext.meta_description          = product.item.meta_description;
                        productContext.meta_keyword              = product.item.meta_keyword;
                        productContext.minimum                   = product.item.minimum;
                        productContext.model                     = product.item.model;
                        productContext.name                      = product.item.name;
                        productContext.price                     = product.item.price;
                        productContext.price_code                = product.item.price_code;
                        productContext.product_id                = int.Parse(product.item.product_id.ToString());
                        productContext.quantity                  = product.item.quantity;
                        productContext.receiving_price           = product.item.receiving_price;
                        productContext.shipping_day              = product.item.shipping_day;
                        productContext.shipping_free             = product.item.shipping_free;
                        productContext.shipping_price            = product.item.shipping_price;
                        productContext.show_badges               = product.item.show_badges;
                        productContext.show_export               = product.item.show_export;
                        productContext.show_mainpage             = product.item.show_mainpage;
                        productContext.small_description         = product.item.small_description;
                        productContext.sort_order                = product.item.sort_order;
                        productContext.special_customer_group_id = product.item.special_customer_group_id;
                        productContext.special_price             = product.item.special_price;
                        productContext.status                    = product.item.status;
                        productContext.stock_status_id           = product.item.stock_status_id;
                        productContext.tag                       = product.item.tag;
                        productContext.tax_class_id              = product.item.tax_class_id;
                        productContext.title                     = product.item.title;
                        productContext.tur_id                    = product.item.tur_id;
                        productContext.video                     = product.item.video;
                        productContext.viewed                    = product.item.viewed;
                        productContext.weight                    = product.item.weight;
                        productContext.width                     = product.item.width;
                        productContext.yayinevi_id               = product.item.yayinevi_id;
                        productContext.yazar_id                  = product.item.yazar_id;
                    }

                    var categoryIds = !string.IsNullOrEmpty(product.item.category_ids) ? product.item.category_ids.Split(';').ToList() : new List <string>();

                    productContext.Categorys = new List <ProductCategory>();

                    foreach (var categoryId in categoryIds)
                    {
                        var category = context.Categorys.FirstOrDefault(c => c.category_id == categoryId);

                        if (category == null)
                        {
                            param = new Dictionary <string, string>();

                            param.Add("act", "getCategory");
                            param.Add("category_id", categoryId);

                            pageContent = HttpPostRequest(param);

                            serializer = new XmlSerializer(typeof(Categorys.items));
                            rdr        = new StringReader(pageContent);
                            Categorys.items categorys = (Categorys.items)serializer.Deserialize(rdr);

                            category = new Category();

                            category.Id                 = Guid.NewGuid();
                            category.bottom             = categorys.item.First().bottom;
                            category.category_id        = categorys.item.First().category_id;
                            category.column             = categorys.item.First().column;
                            category.date_added         = categorys.item.First().date_added;
                            category.date_close         = categorys.item.First().date_close;
                            category.date_modified      = categorys.item.First().date_modified;
                            category.description        = categorys.item.First().description;
                            category.entegrasyon_code   = categorys.item.First().entegrasyon_code;
                            category.footer_description = categorys.item.First().footer_description;
                            category.icon               = categorys.item.First().icon;
                            category.image              = categorys.item.First().image;
                            category.language_id        = categorys.item.First().language_id;
                            category.left               = categorys.item.First().left;
                            category.meta_description   = categorys.item.First().meta_description;
                            category.meta_keyword       = categorys.item.First().meta_keyword;
                            category.name               = categorys.item.First().name;
                            category.parent_id          = categorys.item.First().parent_id;
                            category.sort_order         = categorys.item.First().sort_order;
                            category.status             = categorys.item.First().status;
                            category.taksit_ayarlari    = categorys.item.First().taksit_ayarlari;
                            category.title              = categorys.item.First().title;
                            category.top                = categorys.item.First().top;

                            context.Categorys.Add(category);
                        }

                        var productCategory = new ProductCategory();

                        productCategory.Id       = Guid.NewGuid();
                        productCategory.Category = category;
                        productCategory.Product  = productContext;

                        productContext.Categorys.Add(productCategory);

                        if (product.item.category_id == categoryId)
                        {
                            productContext.category = category;
                        }
                    }

                    int?birim = null;

                    var name = string.Empty;

                    if (string.IsNullOrEmpty(orderProductContext.option_name))
                    {
                        name = orderProductContext.name;
                    }
                    else
                    {
                        name = orderProductContext.option_name;
                    }

                    if (name.ToLower().Contains("adet"))
                    {
                        birim = getAdet(name);
                        orderProductContext.BirimName = "Adet";
                    }
                    else
                    {
                        birim = getKg(name);
                        orderProductContext.BirimName = "Kg";
                    }

                    orderProductContext.Birim = birim;

                    orderProductContext.product = productContext;
                    order.OrderProducts         = new List <OrderProduct>();
                    order.OrderProducts.Add(orderProductContext);
                }

                if (newOrder)
                {
                    context.Orders.Add(order);
                }

                context.SaveChanges();
            }
        }
Example #3
0
        private void Sorgulama_Load(object sender, EventArgs e)
        {
            var context = new PatifoodDataContext();

            var categorys = context.Categorys.Where(c => c.parent_id == kumbaraParentId).GroupBy(c => c.name)
                            .Select(c => c.FirstOrDefault().name).ToDictionary(c => c, c => c);

            cmb_Il.DataSource    = new BindingSource(categorys, null);
            cmb_Il.DisplayMember = "Value";
            cmb_Il.ValueMember   = "Key";

            var products = context.Products.Where(c => c.category.parent_id == kumbaraParentId).GroupBy(c => c.name)
                           .Select(c => c.FirstOrDefault().name).ToDictionary(c => c, c => c);

            cmb_TeslimYeri.DataSource    = new BindingSource(products, null);
            cmb_TeslimYeri.DisplayMember = "Value";
            cmb_TeslimYeri.ValueMember   = "Key";

            var list = context.OrderProducts.Where(c => c.product.category.parent_id == kumbaraParentId).Select(c => new { c.Id, BarinakName = c.name, UrunName = c.option_name, c.Birim, c.BirimName, Adet = c.quantity, UrunOptionCode = c.option_code, Toplam = c.quantity * c.Birim }).ToList();

            //        var groupList = list.GroupBy(
            //p => p.BarinakName,
            //p => p.UrunName,
            //(key, g) => new { BarinakName = key, UrunName = g.Fir() }).Select(c => new { c.BarinakName, c.UrunName, Birim = list.Where(p => p.BarinakName == c.BarinakName && p.UrunName == c.UrunName).Sum(p => p.Adet) } ).ToList();


            var groupList = list.GroupBy(n => new { n.BarinakName, n.UrunName })
                            .Select(c => new { c.Key.BarinakName, c.Key.UrunName, Birim = list.Where(p => p.BarinakName == c.Key.BarinakName && p.UrunName == c.Key.UrunName).Sum(p => p.Toplam) }).ToList();

            Dgw2.DataSource = groupList.OrderBy(x => x.BarinakName).ThenBy(x => x.Birim).ToList();
            //return;
            var deletePAcket = context.Packet.Where(c => c.IsTemp);


            context.PacketOrderProduct.RemoveRange(deletePAcket.SelectMany(c => c.PacketOrderProducts));
            context.PacketOrderProduct.RemoveRange(deletePAcket.SelectMany(c => c.UnPacketOrderProducts));

            context.Packet.RemoveRange(deletePAcket);
            context.SaveChanges();

            var bariknameGroup = list.GroupBy(n => n.BarinakName)
                                 .Select(c => new { BarinakName = c.Key }).ToList();

            bariknameGroup = bariknameGroup.Where(c => c.BarinakName.Contains("Mehmet Ali Turgut")).ToList();
            foreach (var bariknameItem in bariknameGroup)
            {
                var packet = new Packet();

                packet.Id                    = Guid.NewGuid();
                packet.Name                  = bariknameItem.BarinakName;
                packet.IsTemp                = true;
                packet.CargoStatus           = 0;
                packet.PacketOrderProducts   = new List <PacketOrderProduct>();
                packet.UnPacketOrderProducts = new List <PacketOrderProduct>();
                var ids = new List <Guid>();

                var packedGroupItems = groupList.Where(c => c.BarinakName == bariknameItem.BarinakName);

                foreach (var packedGroupItem in packedGroupItems)
                {
                    var tempProducts         = list.Where(p => p.BarinakName == packedGroupItem.BarinakName && p.UrunName == packedGroupItem.UrunName);
                    var productOptCodeGroups = tempProducts.GroupBy(c => c.UrunOptionCode).Select(c => new { OptionCode = c.Key });

                    foreach (var productOptCodeGroup in productOptCodeGroups)
                    {
                        var conf            = context.ProductConfig.First(c => c.OptionCode == productOptCodeGroup.OptionCode);
                        var optCodeProducts = tempProducts.Where(c => c.UrunOptionCode == productOptCodeGroup.OptionCode).ToList();

                        var urunAdet = optCodeProducts.Sum(c => c.Toplam);

                        if (conf.Quantity > 1)
                        {
                            for (int i = urunAdet.Value / conf.Quantity; i > 0; i--)
                            {
                                indexlist = new List <int>();
                                strlist   = new List <string>();
                                x         = optCodeProducts.Select(c => c.Toplam.Value).ToList();

                                calculate(x, conf.Quantity * i, indexlist);

                                if (strlist != null && strlist.Count > 0)
                                {
                                    foreach (var strItem in strlist)
                                    {
                                        var sayilar = strItem.Split(',');

                                        foreach (var sayi in sayilar)
                                        {
                                            var optCodeProduct = optCodeProducts.First(c => c.Toplam.Value == int.Parse(sayi));
                                            packet.PacketOrderProducts.Add(new PacketOrderProduct
                                            {
                                                OrderProduct = context.OrderProducts.First(c => c.Id == optCodeProduct.Id),
                                                Id           = Guid.NewGuid(),
                                                DateCreated  = DateTime.Now
                                            });

                                            optCodeProducts.Remove(optCodeProduct);
                                        }
                                    }
                                }
                            }

                            ids = optCodeProducts.Select(o => o.Id).ToList();
                            var unPackedProducts = context.OrderProducts.Where(c => ids.Contains(c.Id)).ToList();

                            foreach (var unPacketOrderProduct in unPackedProducts)
                            {
                                packet.UnPacketOrderProducts.Add(new PacketOrderProduct
                                {
                                    OrderProduct = unPacketOrderProduct,
                                    Id           = Guid.NewGuid(),
                                    DateCreated  = DateTime.Now
                                });
                            }
                        }
                        else
                        {
                            ids = optCodeProducts.Select(o => o.Id).ToList();
                            var packedProducts = context.OrderProducts.Where(c => ids.Contains(c.Id)).ToList();

                            foreach (var packedProduct in packedProducts)
                            {
                                packet.PacketOrderProducts.Add(new PacketOrderProduct
                                {
                                    OrderProduct = packedProduct,
                                    Id           = Guid.NewGuid(),
                                    DateCreated  = DateTime.Now
                                });
                            }
                        }


                        //var uyanlar = GetCombinations(sayilar, 15 * (32 / 15), "");
                        //var uyanlar = GetCombinations(sayilar, 15 * (15 / 15), "");

                        //Toplamlarının conf a bölümü kadar for dön (büyükten küçüğe)
                        //GetCombinations çalıştır uyanları packet packet.PacketOrderProducts ekle listeden çıkart
                        //bütün döngü bittikten sonra kalan varsa packet.UnPacketOrderProducts ekle
                        //ssss
                    }
                }
                context.Packet.Add(packet);

                context.SaveChanges();
            }
        }