Example #1
0
        public void CopyProducts()
        {
            List<Product> products = new List<Product>();
            Hashtable suppliers = new Hashtable();
            Hashtable categories = new Hashtable();
            //Processing Products
            LogMessage("Reading Products...", false);
            ProductsTableAdapter adapter1 = new ProductsTableAdapter();
            NorthwindDb4o.NorthwindDataSet.ProductsDataTable table1 = adapter1.GetData();
            LogMessage("processing " + table1.Count.ToString() + " rows", true);
            foreach (NorthwindDb4o.NorthwindDataSet.ProductsRow row in table1)
            {
                Product p = new Product();

                p.ProductID = row.ProductID;
                p.ProductName = row.ProductName;
                if (!row.IsSupplierIDNull())
                    suppliers.Add(p.ProductID, row.SupplierID);
                if (!row.IsCategoryIDNull())
                    categories.Add(p.ProductID, row.CategoryID);
                p.QuantityPerUnit = row.IsQuantityPerUnitNull() ? null : row.QuantityPerUnit;
                p.UnitPrice = row.IsUnitPriceNull() ? 0 : Convert.ToDouble(row.UnitPrice);
                p.UnitsInStock = row.IsUnitsInStockNull() ? 0 : row.UnitsInStock;
                p.UnitsOnOrder = row.IsUnitsOnOrderNull() ? 0 : row.UnitsOnOrder;
                p.ReorderLevel = row.IsReorderLevelNull() ? 0 : row.ReorderLevel;
                p.Discontinued = row.Discontinued;

                products.Add(p);
            }
            foreach (Product p in products)
            {
                LogMessage("Product: " + p.ProductID.ToString() + " ...", false);
                if (suppliers.ContainsKey(p.ProductID))
                {
                    LogMessage("linking member...", false);
                    long supplierID = Convert.ToInt64(suppliers[p.ProductID]);
                    Supplier found = (Supplier)Db4oUtil.GetByNumericalID(container, typeof(Supplier), "supplierID", supplierID);
                    p.SupplierID = found;
                }
                if (categories.ContainsKey(p.ProductID))
                {
                    LogMessage("linking member...", false);
                    long categoryID = Convert.ToInt64(categories[p.ProductID]);
                    Category found = (Category)Db4oUtil.GetByNumericalID(container, typeof(Category), "categoryID", categoryID);
                    p.CategoryID = found;
                }
                container.Store(p);
                LogMessage("saved (" + p.ProductID.ToString() + ")", true);
            }
            container.Commit();
            long objectCount = Db4oUtil.GetAllInstances(container, typeof(Product)).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 Products" + Environment.NewLine, true);
        }
Example #2
0
        private void printDocument1_BeginPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            sayfaNo = 1;
            printLabel.Text = string.Empty;
            printLabel.Visible = true;
            printProgress.Value = int.Parse(sayfaNo.ToString());
            printProgress.Maximum = int.Parse(toplamSayfa.ToString());
            printProgress.Minimum = printProgress.Value;
            printProgress.Visible = true;

            //Veriler = new List<ProductClass>();

            using (ProductsTableAdapter ta =
                new ProductsTableAdapter())
            {
                var dt = ta.GetData();

                //Veriler = dt.Select(x => new ProductClass()
                //{
                //    ProductID = x.ProductID.ToString(),
                //    ProductName = x.ProductName,
                //    UnitPrice = x.UnitPrice.ToString(),
                //    UnitsInStock = x.UnitsInStock.ToString(),
                //    TotalPrice = x.TotalPrice.ToString()
                //}).ToList();

                Bitmap bm = new Bitmap(100, 100);
                Graphics g = Graphics.FromImage(bm);

                Veriler = (from x in dt
                           select new ProductClass()
                             {
                                 ProductID = x.ProductID.ToString(),
                                 ProductIDWidth = g.MeasureString(x.ProductID.ToString(), f).Width + 5,
                                 ProductName = x.ProductName,
                                 ProductNameWidth = g.MeasureString(x.ProductName, f).Width + 5,
                                 UnitPrice = x.UnitPrice.ToString("N2"),
                                 UnitPriceWidth = g.MeasureString(x.UnitPrice.ToString("N2"), f).Width + 5,
                                 UnitsInStock = x.UnitsInStock.ToString(),
                                 UnitsInStockWidth = g.MeasureString(x.UnitsInStock.ToString(), f).Width + 5,
                                 TotalPrice = x.TotalPrice.ToString("N2"),
                                 TotalPriceWidth = g.MeasureString(x.TotalPrice.ToString("N2"), f).Width + 5,
                             }).ToList();

                KolonGenislikleri.Clear();
                KolonGenislikleri.Add("ProductID",
                    g.MeasureString("Product ID ", f).Width + 5);

                KolonGenislikleri.Add("ProductName",
                    g.MeasureString("Product Name ", f).Width + 5);

                KolonGenislikleri.Add("UnitPrice",
                    g.MeasureString("Unit Price ", f).Width + 5);

                KolonGenislikleri.Add("UnitsInStock",
                    g.MeasureString("Units In Stock ", f).Width + 5);

                KolonGenislikleri.Add("TotalPrice",
                    g.MeasureString("Total Price ", f).Width + 5);

                float ff = Veriler.Max(x => x.ProductIDWidth);
                if (KolonGenislikleri["ProductID"] < ff)
                    KolonGenislikleri["ProductID"] = ff;

                ff = Veriler.Max(x => x.ProductNameWidth);
                if (KolonGenislikleri["ProductName"] < ff)
                    KolonGenislikleri["ProductName"] = ff;

                ff = Veriler.Max(x => x.UnitPriceWidth);
                if (KolonGenislikleri["UnitPrice"] < ff)
                    KolonGenislikleri["UnitPrice"] = ff;

                ff = Veriler.Max(x => x.UnitsInStockWidth);
                if (KolonGenislikleri["UnitsInStock"] < ff)
                    KolonGenislikleri["UnitsInStock"] = ff;

                ff = Veriler.Max(x => x.TotalPriceWidth);
                if (KolonGenislikleri["TotalPrice"] < ff)
                    KolonGenislikleri["TotalPrice"] = ff;

                satirYuksekligi =
                    g.MeasureString("ĞÖİ纪Çygğ", f).Height;
            }
        }
Example #3
0
        private void CopyProducts(IOdb odb)
        {
            var products = new List<Product>();
            var suppliers = new Hashtable();
            var categories = new Hashtable();
            //Processing Products
            LogMessage("Reading Products...", false);
            var adapter1 = new ProductsTableAdapter();
            var table1 = adapter1.GetData();
            LogMessage("processing " + table1.Count.ToString() + " rows", true);
            foreach (var row in table1)
            {
                var p = new Product
                            {
                                ProductID = row.ProductID,
                                ProductName = row.ProductName,
                                QuantityPerUnit = row.IsQuantityPerUnitNull() ? null : row.QuantityPerUnit,
                                UnitPrice = row.IsUnitPriceNull() ? 0 : Convert.ToDouble(row.UnitPrice),
                                UnitsInStock = row.IsUnitsInStockNull() ? 0 : row.UnitsInStock,
                                UnitsOnOrder = row.IsUnitsOnOrderNull() ? 0 : row.UnitsOnOrder,
                                ReorderLevel = row.IsReorderLevelNull() ? 0 : row.ReorderLevel,
                                Discontinued = row.Discontinued
                            };

                if (!row.IsSupplierIDNull())
                    suppliers.Add(p.ProductID, row.SupplierID);
                if (!row.IsCategoryIDNull())
                    categories.Add(p.ProductID, row.CategoryID);

                products.Add(p);
            }
            foreach (var p in products)
            {
                LogMessage("Product: " + p.ProductID.ToString() + " ...", false);
                if (suppliers.ContainsKey(p.ProductID))
                {
                    LogMessage("linking member...", false);
                    var supplierID = Convert.ToInt64(suppliers[p.ProductID]);
                    var found = NDbUtil.GetByNumericalID<Supplier>(odb, Supplier.PK, supplierID);
                    p.Supplier = found;
                }
                if (categories.ContainsKey(p.ProductID))
                {
                    LogMessage("linking member...", false);
                    var categoryID = Convert.ToInt64(categories[p.ProductID]);
                    var found = NDbUtil.GetByNumericalID<Category>(odb, Category.PK, categoryID);
                    p.Category = found;
                }
                odb.Store(p);

                LogMessage("saved (" + p.ProductID.ToString() + ")", true);
            }
            odb.Commit();

            LogMessage("Commit done, starting create index ...", false);
            odb.IndexManagerFor<Product>().AddUniqueIndexOn("Product_ProductID_PK_index", Product.PK);
            odb.Commit();
            LogMessage(" index created.", true);

            long objectCount = NDbUtil.GetAllInstances<Product>(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 Products" + Environment.NewLine, true);
        }
        private void CopyProducts(IOdb odb)
        {
            var products   = new List <Product>();
            var suppliers  = new Hashtable();
            var categories = new Hashtable();

            //Processing Products
            LogMessage("Reading Products...", false);
            var adapter1 = new ProductsTableAdapter();
            var table1   = adapter1.GetData();

            LogMessage("processing " + table1.Count.ToString() + " rows", true);
            foreach (var row in table1)
            {
                var p = new Product
                {
                    ProductID       = row.ProductID,
                    ProductName     = row.ProductName,
                    QuantityPerUnit = row.IsQuantityPerUnitNull() ? null : row.QuantityPerUnit,
                    UnitPrice       = row.IsUnitPriceNull() ? 0 : Convert.ToDouble(row.UnitPrice),
                    UnitsInStock    = row.IsUnitsInStockNull() ? 0 : row.UnitsInStock,
                    UnitsOnOrder    = row.IsUnitsOnOrderNull() ? 0 : row.UnitsOnOrder,
                    ReorderLevel    = row.IsReorderLevelNull() ? 0 : row.ReorderLevel,
                    Discontinued    = row.Discontinued
                };

                if (!row.IsSupplierIDNull())
                {
                    suppliers.Add(p.ProductID, row.SupplierID);
                }
                if (!row.IsCategoryIDNull())
                {
                    categories.Add(p.ProductID, row.CategoryID);
                }

                products.Add(p);
            }
            foreach (var p in products)
            {
                LogMessage("Product: " + p.ProductID.ToString() + " ...", false);
                if (suppliers.ContainsKey(p.ProductID))
                {
                    LogMessage("linking member...", false);
                    var supplierID = Convert.ToInt64(suppliers[p.ProductID]);
                    var found      = NDbUtil.GetByNumericalID <Supplier>(odb, Supplier.PK, supplierID);
                    p.Supplier = found;
                }
                if (categories.ContainsKey(p.ProductID))
                {
                    LogMessage("linking member...", false);
                    var categoryID = Convert.ToInt64(categories[p.ProductID]);
                    var found      = NDbUtil.GetByNumericalID <Category>(odb, Category.PK, categoryID);
                    p.Category = found;
                }
                odb.Store(p);

                LogMessage("saved (" + p.ProductID.ToString() + ")", true);
            }
            odb.Commit();

            LogMessage("Commit done, starting create index ...", false);
            odb.IndexManagerFor <Product>().AddUniqueIndexOn("Product_ProductID_PK_index", Product.PK);
            odb.Commit();
            LogMessage(" index created.", true);

            long objectCount = NDbUtil.GetAllInstances <Product>(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 Products" + Environment.NewLine, true);
        }