private static void WriteSale(XmlWriter writer, Vendor item)
 {
     writer.WriteStartElement("sale");
     writer.WriteAttributeString("vendor", item.Name);
     IEnumerable<VendorSale> result = SummaryReportByVendor(item.Id);
     foreach (var vendorItem in result)
     {
         writer.WriteStartElement("summary");
         writer.WriteAttributeString("date", vendorItem.Date.ToString("dd-MMM-yyyy"));
         writer.WriteAttributeString("total-sum", vendorItem.Sum.ToString("N" + 2));
         writer.WriteEndElement();
     }
     writer.WriteEndElement();
 }
        public static void WriteVendorExpensesReport(SupermarketsEntities sqlserver, string filename)
        {
            using (XmlReader reader = XmlReader.Create(filename))
            {
                string currentVendor = string.Empty;

                while (reader.Read())
                {
                    if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "sale"))
                    {
                        currentVendor = reader.GetAttribute("vendor");

                        if (sqlserver.Vendors.Any(v => v.Name == currentVendor))
                        {
                            Vendor vendor = new Vendor();
                            vendor.Name = currentVendor;
                            sqlserver.Vendors.Add(vendor);
                        }
                    }
                    if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "expenses"))
                    {
                        Vendor vendor = sqlserver.Vendors.Where(v => v.Name == currentVendor).FirstOrDefault();

                        if (vendor != null)
                        {
                            DateTime monthDate = DateTime.Parse(string.Format("01-{0}", reader.GetAttribute("month")));

                            VendorExpenses expense = new VendorExpenses();
                            expense.VendorId = vendor.Id;
                            expense.Month = monthDate.Month;
                            expense.Year = monthDate.Year;
                            expense.Expenses = reader.ReadElementContentAsDecimal();

                            sqlserver.VendorExpenses.Add(expense);

                            AddToMongoDB(expense);
                        }
                    }
                }

                sqlserver.SaveChanges();
            }
        }
예제 #3
0
        private static void TransferDB(SupermarketsContext db)
        {
            using (db)
            {
                using (var mySqlContext = new ProductsModel())
                {
                    var products = mySqlContext.Products.ToList();
                    var measures = mySqlContext.Measures.ToList();
                    var vendors = mySqlContext.Vendors.ToList();   
                    db.SaveChanges();

                    foreach (var vendor in vendors)
                    {                        
                        var newVendor = new Supermarkets.Model.Vendor { Name = vendor.VendorName };
                        newVendor.Id = vendor.VendorID;
                        db.Vendors.Add(newVendor);
                    }                   

                   
                    foreach (var measure in measures)
                    {                       
                        var newMeasure = new Supermarkets.Model.Measure { Name = measure.MeasureName };
                        newMeasure.Id = measure.MeasureID;
                        db.Measures.Add(newMeasure);
                    }                

                    foreach (var product in products)
                    {
                        var newProduct = new Supermarkets.Model.Product { Id = product.ProductsID, Name = product.ProductName };
                        newProduct.Vendor = db.Vendors.Find(product.VendorID);
                        newProduct.Measure = db.Measures.Find(product.MeasureID);
                        db.Products.Add(newProduct);
                        db.SaveChanges();
                    }
                    db.SaveChanges();
                }
            }
        }