private void CopyOrders(IOdb odb, ref double progress) { var orders = new List<Order>(); var customers = new Hashtable(); var employees = new Hashtable(); var shippers = new Hashtable(); //Processing Orders LogMessage("Reading Orders...", false); var adapter1 = new OrdersTableAdapter(); var table1 = adapter1.GetData(); LogMessage("processing " + table1.Count.ToString() + " rows", true); foreach (var row in table1) { var o = new Order { OrderID = row.OrderID, Freight = row.IsFreightNull() ? 0 : Convert.ToDouble(row.Freight), ShipName = row.IsShipNameNull() ? null : row.ShipName, ShipAddress = row.IsShipAddressNull() ? null : row.ShipAddress, ShipCity = row.IsShipCityNull() ? null : row.ShipCity, ShipRegion = row.IsShipRegionNull() ? null : row.ShipRegion, ShipPostalCode = row.IsShipPostalCodeNull() ? null : row.ShipPostalCode, ShipCountry = row.IsShipCountryNull() ? null : row.ShipCountry }; if (!row.IsCustomerIDNull()) customers.Add(o.OrderID, row.CustomerID); if (!row.IsEmployeeIDNull()) employees.Add(o.OrderID, row.EmployeeID); if (!row.IsShipViaNull()) shippers.Add(o.OrderID, row.ShipVia); if (!row.IsOrderDateNull()) o.OrderDate = row.OrderDate; if (!row.IsRequiredDateNull()) o.RequiredDate = row.RequiredDate; if (!row.IsShippedDateNull()) o.ShippedDate = row.ShippedDate; orders.Add(o); } foreach (var o in orders) { LogMessage("Order: " + o.OrderID.ToString() + " ...", false); if (customers.ContainsKey(o.OrderID)) { LogMessage("linking member...", false); var customerID = Convert.ToString(customers[o.OrderID]); var found = NDbUtil.GetByStringID<Customer>(odb, Customer.PK, customerID); o.Customer = found; } if (employees.ContainsKey(o.OrderID)) { LogMessage("linking member...", false); var employeeID = Convert.ToInt64(employees[o.OrderID]); var found = NDbUtil.GetByNumericalID<Employee>(odb, Employee.PK, employeeID); o.Employee = found; } if (shippers.ContainsKey(o.OrderID)) { LogMessage("linking member...", false); var shipperID = Convert.ToInt64(shippers[o.OrderID]); var found = NDbUtil.GetByNumericalID<Shipper>(odb, Shipper.PK, shipperID); o.ShipVia = found; } odb.Store(o); StepFinished(progress += 0.029); LogMessage("saved (" + o.OrderID.ToString() + ")", true); } odb.Commit(); LogMessage("Commit done, starting create index ...", false); odb.IndexManagerFor<Order>().AddUniqueIndexOn("Order_OrderID_PK_index", Order.PK); odb.Commit(); LogMessage(" index created.", true); long objectCount = NDbUtil.GetAllInstances<Order>(odb).Count; if (table1.Count == objectCount) LogMessage(table1.Count + " objects saved", true); else LogMessage("Error: " + table1.Count + " rows retrieved but " + objectCount + " objects were saved", true); LogMessage("Done with Orders" + Environment.NewLine, true); }
public void CopyOrders() { List<Order> orders = new List<Order>(); Hashtable customers = new Hashtable(); Hashtable employees = new Hashtable(); Hashtable shippers = new Hashtable(); //Processing Orders LogMessage("Reading Orders...", false); OrdersTableAdapter adapter1 = new OrdersTableAdapter(); NorthwindDb4o.NorthwindDataSet.OrdersDataTable table1 = adapter1.GetData(); LogMessage("processing " + table1.Count.ToString() + " rows", true); foreach (NorthwindDb4o.NorthwindDataSet.OrdersRow row in table1) { Order o = new Order(); o.OrderID = row.OrderID; if (!row.IsCustomerIDNull()) customers.Add(o.OrderID, row.CustomerID); if (!row.IsEmployeeIDNull()) employees.Add(o.OrderID, row.EmployeeID); if (!row.IsShipViaNull()) shippers.Add(o.OrderID, row.ShipVia); if (!row.IsOrderDateNull()) o.OrderDate = row.OrderDate; if (!row.IsRequiredDateNull()) o.RequiredDate = row.RequiredDate; if (!row.IsShippedDateNull()) o.ShippedDate = row.ShippedDate; o.Freight = row.IsFreightNull() ? 0 : Convert.ToDouble(row.Freight); o.ShipName = row.IsShipNameNull() ? null : row.ShipName; o.ShipAddress = row.IsShipAddressNull() ? null : row.ShipAddress; o.ShipCity = row.IsShipCityNull() ? null : row.ShipCity; o.ShipRegion = row.IsShipRegionNull() ? null : row.ShipRegion; o.ShipPostalCode = row.IsShipPostalCodeNull() ? null : row.ShipPostalCode; o.ShipCountry = row.IsShipCountryNull() ? null : row.ShipCountry; orders.Add(o); } foreach (Order o in orders) { LogMessage("Order: " + o.OrderID.ToString() + " ...", false); if (customers.ContainsKey(o.OrderID)) { LogMessage("linking member...", false); string customerID = Convert.ToString(customers[o.OrderID]); Customer found = (Customer)Db4oUtil.GetByStringID(container, typeof(Customer), "customerID", customerID); o.CustomerID = found; } if (employees.ContainsKey(o.OrderID)) { LogMessage("linking member...", false); long employeeID = Convert.ToInt64(employees[o.OrderID]); Employee found = (Employee)Db4oUtil.GetByNumericalID(container, typeof(Employee), "employeeID", employeeID); o.EmployeeID = found; } if (shippers.ContainsKey(o.OrderID)) { LogMessage("linking member...", false); long shipperID = Convert.ToInt64(shippers[o.OrderID]); Shipper found = (Shipper)Db4oUtil.GetByNumericalID(container, typeof(Shipper), "shipperID", shipperID); o.ShipVia = found; } container.Store(o); LogMessage("saved (" + o.OrderID.ToString() + ")", true); } container.Commit(); long objectCount = Db4oUtil.GetAllInstances(container, typeof(Order)).Count; if (table1.Count == objectCount) LogMessage(table1.Count + " objects saved", true); else LogMessage("Error: " + table1.Count + " rows retrieved but " + objectCount + " objects were saved", true); LogMessage("Done with Orders" + Environment.NewLine, true); }
private void CopyOrders(IOdb odb, ref double progress) { var orders = new List <Order>(); var customers = new Hashtable(); var employees = new Hashtable(); var shippers = new Hashtable(); //Processing Orders LogMessage("Reading Orders...", false); var adapter1 = new OrdersTableAdapter(); var table1 = adapter1.GetData(); LogMessage("processing " + table1.Count.ToString() + " rows", true); foreach (var row in table1) { var o = new Order { OrderID = row.OrderID, Freight = row.IsFreightNull() ? 0 : Convert.ToDouble(row.Freight), ShipName = row.IsShipNameNull() ? null : row.ShipName, ShipAddress = row.IsShipAddressNull() ? null : row.ShipAddress, ShipCity = row.IsShipCityNull() ? null : row.ShipCity, ShipRegion = row.IsShipRegionNull() ? null : row.ShipRegion, ShipPostalCode = row.IsShipPostalCodeNull() ? null : row.ShipPostalCode, ShipCountry = row.IsShipCountryNull() ? null : row.ShipCountry }; if (!row.IsCustomerIDNull()) { customers.Add(o.OrderID, row.CustomerID); } if (!row.IsEmployeeIDNull()) { employees.Add(o.OrderID, row.EmployeeID); } if (!row.IsShipViaNull()) { shippers.Add(o.OrderID, row.ShipVia); } if (!row.IsOrderDateNull()) { o.OrderDate = row.OrderDate; } if (!row.IsRequiredDateNull()) { o.RequiredDate = row.RequiredDate; } if (!row.IsShippedDateNull()) { o.ShippedDate = row.ShippedDate; } orders.Add(o); } foreach (var o in orders) { LogMessage("Order: " + o.OrderID.ToString() + " ...", false); if (customers.ContainsKey(o.OrderID)) { LogMessage("linking member...", false); var customerID = Convert.ToString(customers[o.OrderID]); var found = NDbUtil.GetByStringID <Customer>(odb, Customer.PK, customerID); o.Customer = found; } if (employees.ContainsKey(o.OrderID)) { LogMessage("linking member...", false); var employeeID = Convert.ToInt64(employees[o.OrderID]); var found = NDbUtil.GetByNumericalID <Employee>(odb, Employee.PK, employeeID); o.Employee = found; } if (shippers.ContainsKey(o.OrderID)) { LogMessage("linking member...", false); var shipperID = Convert.ToInt64(shippers[o.OrderID]); var found = NDbUtil.GetByNumericalID <Shipper>(odb, Shipper.PK, shipperID); o.ShipVia = found; } odb.Store(o); StepFinished(progress += 0.029); LogMessage("saved (" + o.OrderID.ToString() + ")", true); } odb.Commit(); LogMessage("Commit done, starting create index ...", false); odb.IndexManagerFor <Order>().AddUniqueIndexOn("Order_OrderID_PK_index", Order.PK); odb.Commit(); LogMessage(" index created.", true); long objectCount = NDbUtil.GetAllInstances <Order>(odb).Count; if (table1.Count == objectCount) { LogMessage(table1.Count + " objects saved", true); } else { LogMessage("Error: " + table1.Count + " rows retrieved but " + objectCount + " objects were saved", true); } LogMessage("Done with Orders" + Environment.NewLine, true); }