public void InsertDataIntoDB(IEnumerable <string> content, IList <string> format) { int indexForName = format.IndexOf("Name"); int indexForDescription = format.IndexOf("Description"); int indexForPrice = format.IndexOf("Price"); int indexForCompatibility = format.IndexOf("Compatibility"); int indexForManufacturer = format.IndexOf("Manufacturer"); int indexForType = format.IndexOf("Type"); int iterations = 1; foreach (var singleRow in content) { var rowEntities = singleRow.Split(new[] { Constants.DividerForExcelRead }, StringSplitOptions.None); var autoPartObject = new AutoPart(); autoPartObject.Name = rowEntities[indexForName]; autoPartObject.Description = rowEntities[indexForDescription]; autoPartObject.Price = decimal.Parse(rowEntities[indexForPrice]); autoPartObject.Compatibility = this.db.Compatibilities.Find(int.Parse(rowEntities[indexForCompatibility])); autoPartObject.Manufacturer = this.db.Manufacturers.Find(int.Parse(rowEntities[indexForManufacturer])); autoPartObject.Type = this.db.PartTypes.Find(int.Parse(rowEntities[indexForType])); autoPartObject.BuiltOn = DateTime.Now; if (iterations % 100 == 0) { this.db.SaveChanges(); this.db.Dispose(); this.db = new AutopartsDbContext(); } this.db.AutoParts.Add(autoPartObject); iterations++; } this.db.SaveChanges(); }
public void InsertDataIntoDB(IEnumerable<string> content, IList<string> format) { int indexForName = format.IndexOf("Name"); int indexForDescription = format.IndexOf("Description"); int indexForPrice = format.IndexOf("Price"); int indexForCompatibility = format.IndexOf("Compatibility"); int indexForManufacturer = format.IndexOf("Manufacturer"); int indexForType = format.IndexOf("Type"); int iterations = 1; foreach (var singleRow in content) { var rowEntities = singleRow.Split(new[] { Constants.DividerForExcelRead }, StringSplitOptions.None); var autoPartObject = new AutoPart(); autoPartObject.Name = rowEntities[indexForName]; autoPartObject.Description = rowEntities[indexForDescription]; autoPartObject.Price = decimal.Parse(rowEntities[indexForPrice]); autoPartObject.Compatibility = this.db.Compatibilities.Find(int.Parse(rowEntities[indexForCompatibility])); autoPartObject.Manufacturer = this.db.Manufacturers.Find(int.Parse(rowEntities[indexForManufacturer])); autoPartObject.Type = this.db.PartTypes.Find(int.Parse(rowEntities[indexForType])); autoPartObject.BuiltOn = DateTime.Now; if (iterations % 100 == 0) { this.db.SaveChanges(); this.db.Dispose(); this.db = new AutopartsDbContext(); } this.db.AutoParts.Add(autoPartObject); iterations++; } this.db.SaveChanges(); }
private void FillAutopartsReportsTableData(PdfPTable table, AutopartsDbContext db) { decimal totalSum = 0; var autoPartsReport = db.AutoParts.Select( c => new { ProductName = c.Name, Manufacturer = c.Manufacturer.Name, Price = c.Price, Quantity = c.Quantity, Sum = c.Price * c.Quantity }).ToList(); foreach (var autopart in autoPartsReport) { table.AddCell(autopart.ProductName); table.AddCell(autopart.Manufacturer); table.AddCell(autopart.Price.ToString()); table.AddCell(autopart.Quantity.ToString()); table.AddCell(autopart.Sum.ToString()); totalSum += autopart.Sum; } var totalCell = new PdfPCell(new Phrase(TotalColumName)); totalCell.BackgroundColor = BaseColor.LIGHT_GRAY; table.AddCell(new PdfPCell { Colspan = 3 }); table.AddCell(totalCell); table.AddCell(totalSum.ToString()); }
public void GenerateJsonFiles(string path, AutopartsDbContext db) { // var db = new AutopartsDbContext(); var autoParts = db.AutoParts.ToList(); var mysqlParser = new MySqlConnectionProvider(); foreach (var item in autoParts) { mysqlParser.AddContent(item); var jsonObj = JsonConvert.SerializeObject(item, Formatting.Indented); var adress = path + item.Id + ".json"; File.WriteAllText(adress, jsonObj.ToString()); } Console.WriteLine("JSON file in Reports/JSON/ created."); }
private void FillAutopartsReportsTableData(PdfPTable table, AutopartsDbContext db) { var computersReports = db.AutoParts .Select(c => new { ModelColumnHeader = c.Name, ManufacturerNameColumnHeader = c.Manufacturer.Name, PriceColumnHeader = c.Price, }) .ToList(); foreach (var computer in computersReports) { table.AddCell(computer.ManufacturerNameColumnHeader.ToString()); table.AddCell(computer.ModelColumnHeader.ToString()); table.AddCell(computer.PriceColumnHeader.ToString() + " $"); } }
public static void Main() { // TODO: Test all of parsers and reports again Database.SetInitializer(new MigrateDatabaseToLatestVersion <AutopartsDbContext, Configuration>()); var db = new AutopartsDbContext(); // db.Manufacturers.Add(new Manufacturer() { Name = "Bosch" }); // db.SaveChanges(); // Console.WriteLine(db.Manufacturers.Count()); //ZipFile zipFile = new ZipFile(Constants.PathToFiles + "/Files.zip"); //zipFile.ExtractAll(Constants.PathToFiles + "/Extracted/"); //Console.WriteLine(Constants.PathToFiles); // var autopart = new AutoPart { Id=1, Compatibility = new Compatibility(),Type = new PartType(), Description = "bla bla bla", Manufacturer = new Manufacturer { Name = "PeshoMotors" }, Quantity = 30, Price = 500, Name = "Driving wheel" }; // db.AutoParts.Add(autopart); // db.SaveChanges(); // var report = new PdfReport(); // report.GenerateAutopartsReports(Constants.PathForCreatedPDFReports, "pavkata", db); // var jsonExporter = new JsonReporter(); // jsonExporter.GenerateJsonFiles(Constants.PathForCreatedJsonReports, db); // var xmlReportTest = new XmlReport(); // xmlReportTest.GenerateAutoPartReport(Constants.PathForCreatedXMLReports + "/" + "AutoParts.xml"); // var columnNames = new List<string>() // { // "Name", "Description", "Price", "Compatibility", "Manufacturer", "Type" // }; // var xmlReader = new XMLToDB(); // xmlReader.ParseXmlToDb(Constants.PathToFiles + "/" + "AutoParts.xml", columnNames); // var zipReaderdbParser = new ZipToAutoPart(); // zipReaderdbParser.ParseZipToDB(Constants.PathToFiles + "/Files.zip", columnNames); }
public static void Main() { // TODO: Test all of parsers and reports again Database.SetInitializer(new MigrateDatabaseToLatestVersion<AutopartsDbContext, Configuration>()); var db = new AutopartsDbContext(); // db.Manufacturers.Add(new Manufacturer() { Name = "Bosch" }); // db.SaveChanges(); // Console.WriteLine(db.Manufacturers.Count()); //ZipFile zipFile = new ZipFile(Constants.PathToFiles + "/Files.zip"); //zipFile.ExtractAll(Constants.PathToFiles + "/Extracted/"); //Console.WriteLine(Constants.PathToFiles); // var autopart = new AutoPart { Id=1, Compatibility = new Compatibility(),Type = new PartType(), Description = "bla bla bla", Manufacturer = new Manufacturer { Name = "PeshoMotors" }, Quantity = 30, Price = 500, Name = "Driving wheel" }; // db.AutoParts.Add(autopart); // db.SaveChanges(); // var report = new PdfReport(); // report.GenerateAutopartsReports(Constants.PathForCreatedPDFReports, "pavkata", db); // var jsonExporter = new JsonReporter(); // jsonExporter.GenerateJsonFiles(Constants.PathForCreatedJsonReports, db); // var xmlReportTest = new XmlReport(); // xmlReportTest.GenerateAutoPartReport(Constants.PathForCreatedXMLReports + "/" + "AutoParts.xml"); // var columnNames = new List<string>() // { // "Name", "Description", "Price", "Compatibility", "Manufacturer", "Type" // }; // var xmlReader = new XMLToDB(); // xmlReader.ParseXmlToDb(Constants.PathToFiles + "/" + "AutoParts.xml", columnNames); // var zipReaderdbParser = new ZipToAutoPart(); // zipReaderdbParser.ParseZipToDB(Constants.PathToFiles + "/Files.zip", columnNames); }
public void GenerateAutoPartReport(string path) { var db = new AutopartsDbContext(); var entries = db.AutoParts.ToList(); XElement autoParts = new XElement("AutoParts"); foreach (var entry in entries) { XElement autoPart = new XElement("AutoPart"); XElement name = new XElement("Name", entry.Name); XElement description = new XElement("Description", entry.Description); XElement type = new XElement("Type", entry.Type.Id); XElement manufacturer = new XElement("Manufacturer", entry.Manufacturer.Name); XAttribute manId = new XAttribute("ID", entry.Manufacturer.Id); manufacturer.Add(manId); XElement compatibility = new XElement("Compatibility"); XAttribute compatibilityId = new XAttribute("ID", entry.Compatibility.Id); compatibility.Add(compatibilityId); XElement model = new XElement("Model", entry.Compatibility.Model.Model); XElement brand = new XElement("Model", entry.Compatibility.Brand.Brand); XElement price = new XElement("Price", entry.Price); XElement quantity = new XElement("Quantity", entry.Quantity); autoPart.Add(name); autoPart.Add(description); autoPart.Add(type); autoPart.Add(manufacturer); compatibility.Add(brand); compatibility.Add(model); autoPart.Add(compatibility); autoPart.Add(price); autoPart.Add(quantity); autoParts.Add(autoPart); } autoParts.Save(path); }
public void GenerateAutopartsReports(string filePath, string fileName, AutopartsDbContext db) { fileName = UniqueFileNameGenerator.AddUniqueFilenameSuffix(fileName); if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } var document = new Document(PageSize.A4, 50, 50, 25, 25); var output = new FileStream(filePath + fileName, FileMode.Create, FileAccess.Write); var writer = PdfWriter.GetInstance(document, output); PdfPTable table = this.CreateAutopartsReportsTable(); this.AddAutopartsReportsTableHeader(table); this.AddAutopartsReportsTableColumns(table); this.FillAutopartsReportsTableData(table, db); document.Open(); document.Add(table); document.Close(); }
public StringSetToAutoPart(AutopartsDbContext database) : this() { this.db = database; }
public StringSetToAutoPart() { this.db = new AutopartsDbContext(); }