Ejemplo n.º 1
0
 private void c1Combo2_SelectedValueChanged(object sender, EventArgs e)
 {
     if (txMode == DataEntryModes.Add)
     {
         try
         {
             // get data
             dsCore                   ds = new dsCore();
             OrdersTableAdapter       od = new OrdersTableAdapter();
             OrderDetailsTableAdapter ta = new OrderDetailsTableAdapter();
             ds.EnforceConstraints = false;
             od.Connection         = AppHelper.GetDbConnection();
             od.FillByID(ds.Orders, (int)c1Combo2.SelectedValue);
             ta.Connection = AppHelper.GetDbConnection();
             ta.FillNotCompleted(ds.OrderDetails, (int)c1Combo2.SelectedValue);
             // clear grid
             dsCore1.OrderDetails.Clear();
             // fill grid with new data
             _grid.Redraw = false;
             DataRowView dv = (DataRowView)this.BindingContext[dsCore1, "Orders"].Current;
             dv["CompanyID"]  = ds.Orders[0].CompanyID;
             dv["CurrencyID"] = ds.Orders[0].CurrencyID;
             if (!ds.Orders[0].IsCompanyIDNull())
             {
                 c1Combo1.SelectedValue = ds.Orders[0].CompanyID;
             }
             if (!ds.Orders[0].IsCurrencyIDNull())
             {
                 c1Combo3.SelectedValue = ds.Orders[0].CurrencyID;
             }
             foreach (dsCore.OrderDetailsRow src in ds.OrderDetails.Rows)
             {
                 dsCore.OrderDetailsRow row = dsCore1.OrderDetails.NewOrderDetailsRow();
                 row.OrderID     = (int)dv["ID"];
                 row.ItemID      = src.ItemID;
                 row.ItemCode    = src.ItemCode;
                 row.ItemName    = src.ItemName;
                 row.Quantity    = src.Quantity;
                 row.UnitPrice   = src.UnitPrice;
                 row.TaxPct      = src.TaxPct;
                 row.Remarks     = src.Remarks;
                 row.MeasureCode = src.MeasureCode;
                 dsCore1.OrderDetails.AddOrderDetailsRow(row);
             }
             // redraw grid
             _grid.Redraw = true;
             _grid.Refresh();
             // recalculate order value
             c1Label1.Value = CountDetails();
         }
         catch (Exception ex)
         {
             // textfile logging
             Logger.ErrorRoutine(ex);
             // screen logging
             RibbonMessageBox.Show("ERROR Retrieving Detail Data: \n" + ex.Message,
                                   Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         }
     }
 }
        private void Report_Load(object sender, EventArgs e)
        {
            productsTableAdapter.Fill(NorthwindDataSet.Products);
            employeesTableAdapter.Fill(NorthwindDataSet.Employees);
            customersTableAdapter.Fill(NorthwindDataSet.Customers);
            OrdersTableAdapter.Fill(NorthwindDataSet.Orders);

            var q = from em in NorthwindDataSet.Employees
                    where em.EmployeeID == Convert.ToInt32(id)
                    select new
            {
                firstName = em.FirstName,
                lastName  = em.LastName
            };

            foreach (var i in q)
            {
                employee.Add(i.firstName);
                employee.Add(i.lastName);
            }

            ReportParameterCollection reportParameters = new ReportParameterCollection();

            reportParameters.Add(new ReportParameter("parameterFirstName", employee[0]));
            reportParameters.Add(new ReportParameter("parameterLastName", employee[1]));
            reportViewer1.LocalReport.SetParameters(reportParameters);

            da.Fill(ds.Tables["Orders"]);
            cb_OrderDetails.DataSource    = bs;
            cb_OrderDetails.DisplayMember = "OrderID";

            Order_DetailsTableAdapter.Fill(NorthwindDataSet.Order_Details);
            Order_Details_fill_name();
        }
Ejemplo n.º 3
0
        void InitializeDataSources()
        {
            var dataSource = new DataSet1();
            var connection = new OleDbConnection();

            connection.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\nwind.mdb";

            EmployeesTableAdapter employees = new EmployeesTableAdapter();

            employees.Connection = connection;
            employees.Fill(dataSource.Employees);

            CustomersTableAdapter customers = new CustomersTableAdapter();

            customers.Connection = connection;
            customers.Fill(dataSource.Customers);

            EmployeeCustomersTableAdapter employeeCustomers = new EmployeeCustomersTableAdapter();

            employeeCustomers.Connection = connection;
            employeeCustomers.Fill(dataSource.EmployeeCustomers);

            OrdersTableAdapter orders = new OrdersTableAdapter();

            orders.Connection = connection;
            orders.Fill(dataSource.Orders);

            Order_DetailsTableAdapter orderDetails = new Order_DetailsTableAdapter();

            orderDetails.Connection = connection;
            orderDetails.Fill(dataSource.Order_Details);

            SnapDocument document = snapControl1.Document;

            document.BeginUpdateDataSource();

            var employeesBinding = new BindingSource()
            {
                DataSource = dataSource, DataMember = employeeDataSourceName
            };

            document.DataSources.Add(new DataSourceInfo(employeeDataSourceName, employeesBinding));

            var customersBinding = new BindingSource()
            {
                DataSource = dataSource, DataMember = customerDataSourceName
            };

            document.DataSources.Add(new DataSourceInfo(customerDataSourceName, customersBinding));

            document.EndUpdateDataSource();
        }
Ejemplo n.º 4
0
        private void downloadData(string customerID)
        {
            DataSet1 myData = new DataSet1();
            CustomersTableAdapter customersTableAdapter = new CustomersTableAdapter();
            OrdersTableAdapter ordersTableAdapter = new OrdersTableAdapter();

            customersTableAdapter.Fill(myData.Customers, customerID);
            ordersTableAdapter.Fill(myData.Orders, customerID);

            dataGridView1.DataSource = myData.Tables["Customers"];
            dataGridView2.DataSource = myData.Tables["Orders"];

        }
Ejemplo n.º 5
0
 private void c1Combo1_SelectedValueChanged(object sender, EventArgs e)
 {
     if (txMode == DataEntryModes.Add)
     {
         try
         {
             // prevent redraw
             _grid.Redraw = false;
             // get data
             dsCore             ds = new dsCore();
             OrdersTableAdapter od = new OrdersTableAdapter();
             ds.EnforceConstraints = false;
             od.Connection         = AppHelper.GetDbConnection();
             od.FillOutstandingSalesInvoices(ds.Orders, (int)c1Combo1.SelectedValue);
             // clear grid
             dsCore1.OrderDetails.Clear();
             // fill grid with new data
             DataRowView dv = (DataRowView)this.BindingContext[dsCore1, "Orders"].Current;
             foreach (dsCore.OrdersRow src in ds.Orders.Rows)
             {
                 dsCore.OrderDetailsRow row = dsCore1.OrderDetails.NewOrderDetailsRow();
                 row.OrderID        = (int)dv["ID"];
                 row.ReferenceID    = src.ID;
                 row.ReferenceNo    = src.OrderNo;
                 row.ReferenceDate  = src.OrderDate;
                 row.ReferenceValue = src.OutstandingValue;
                 row.UnitPrice      = src.OutstandingValue;
                 row.Quantity       = 1;
                 row.TaxPct         = 0;
                 if (!src.IsRemarksNull())
                 {
                     row.Remarks = src.Remarks;
                 }
                 dsCore1.OrderDetails.AddOrderDetailsRow(row);
             }
             // recalculate
             CountDetails();
             // redraw grid
             _grid.Redraw = true;
             _grid.Refresh();
         }
         catch (Exception ex)
         {
             // textfile logging
             Logger.ErrorRoutine(ex);
             // screen logging
             RibbonMessageBox.Show("ERROR Retrieving Detail Data: \n" + ex.Message,
                                   Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         }
     }
 }
Ejemplo n.º 6
0
    protected void PobierzDaneZamowienia(string idKlienta)
    {
        DataSet mojZbiorDanych             = new DataSet();
        CustomersTableAdapter klientDA     = new CustomersTableAdapter();
        OrdersTableAdapter    zamowieniaDA = new OrdersTableAdapter();

        klientDA.Fill(mojZbiorDanych.Customers, idKlienta);
        zamowieniaDA.Fill(mojZbiorDanych.Orders, idKlienta);

        GridView1.DataSource = mojZbiorDanych.Tables["Customers"];
        GridView1.DataBind();

        GridView2.DataSource = mojZbiorDanych.Tables["Orders"];
        GridView2.DataBind();
    }
Ejemplo n.º 7
0
        public MainForm()
        {
            InitializeComponent();

            // Get Adapters.
            invTableAdapter    = new InventoryTableAdapter();
            custTableAdapter   = new CustomersTableAdapter();
            ordersTableAdapter = new OrdersTableAdapter();

            // Add tables to DS.
            invTableAdapter.Fill(autoLotDS.Inventory);
            custTableAdapter.Fill(autoLotDS.Customers);
            ordersTableAdapter.Fill(autoLotDS.Orders);

            // Bind to grids
            dataGridViewInventory.DataSource = autoLotDS.Inventory;
            dataGridViewCustomers.DataSource = autoLotDS.Customers;
            dataGridViewOrders.DataSource    = autoLotDS.Orders;
        }
 protected void SubmitOrder()
 {
     if (IsNotNull(txtBoxStreetName.Text) == true &&
         IsNotNull(TxtBoxUnit.Text) == true &&
         IsNotNull(TxtBoxPostal.Text) == true)
     {
         string spiceOption = "";
         foreach (ListItem o in CheckBoxSpice.Items)
         {
             if (o.Selected)
             {
                 spiceOption += " " + o.Value.ToString();
             }
         }
         OrdersTableAdapter orderta = new OrdersTableAdapter();
         orderta.Fill(ds.Orders);
         try
         {
             DataRow dr = ds.Orders.NewRow();
             dr["orderUser"]        = userName;
             dr["orderDate"]        = DateTime.Now;
             dr["orderDish"]        = DdlFoodChoice.SelectedItem.ToString();
             dr["orderSize"]        = DddlSizeOption.SelectedItem.ToString();
             dr["orderSpices"]      = spiceOption;
             dr["deliveryLocation"] = txtBoxStreetName.Text + " " + TxtBoxUnit.Text + " Postal Code " + TxtBoxPostal.Text;
             dr["orderStatus"]      = "Pending";
             ds.Tables["Orders"].Rows.Add(dr);
             orderta.Update(ds.Orders);
             LabelStatus.Text = "Order Submitted Successfully";
             ClearForm();
         }
         catch (Exception ex)
         {
             LabelStatus.Text = ex.ToString();
         }
     }
     else
     {
         LabelStatus.Text = "Error! Please enter the information for all fields.";
     }
 }
Ejemplo n.º 9
0
        /*
         * Function get_data()
         * Fills database tables using DataSet.
         */
        private void get_data()
        {
            ds   = new DataSet1();
            mt   = new MenuTableAdapter();
            it   = new InventoryTableAdapter();
            et   = new EmployeesTableAdapter();
            ot   = new OrdersTableAdapter();
            olt  = new OrderlineTableAdapter();
            st   = new SuppliersTableAdapter();
            pot  = new PurchaseOrdersTableAdapter();
            polt = new PurchaseOrderlineTableAdapter();

            mt.Fill(ds.Menu);
            it.Fill(ds.Inventory);
            et.Fill(ds.Employees);
            ot.Fill(ds.Orders);
            olt.Fill(ds.Orderline);
            st.Fill(ds.Suppliers);
            pot.Fill(ds.PurchaseOrders);
            polt.Fill(ds.PurchaseOrderline);
        }
        private static object CreateDataSource()
        {
            var dataSource = new nwindDataSet();
            var connection = new OleDbConnection();

            connection.ConnectionString = Properties.Settings.Default.nwindConnectionString;

            CustomersTableAdapter customers = new CustomersTableAdapter();

            customers.Connection = connection;
            customers.Fill(dataSource.Customers);

            OrdersTableAdapter orders = new OrdersTableAdapter();

            orders.Connection = connection;
            orders.Fill(dataSource.Orders);

            var bindingSource = new BindingSource();

            bindingSource.DataSource = dataSource;
            bindingSource.DataMember = "Customers";
            return(bindingSource);
        }
Ejemplo n.º 11
0
        public Example()

        {
            InitializeComponent();

            NWindDataSet dataSet = new
                                   NWindDataSet();

            OrdersTableAdapter ordersAdapter =
                new OrdersTableAdapter();

            ordersAdapter.Fill(dataSet.Orders);

            Order_DetailsTableAdapter detailAdapter
                = new Order_DetailsTableAdapter();

            detailAdapter.Fill(dataSet.Order_Details);

            radGridView1.AutoGenerateHierarchyFromDataSet = true;

            radGridView1.DataMember = dataSet.Tables["Orders"].TableName;

            radGridView1.ItemsSource = dataSet;
        }
Ejemplo n.º 12
0
 public OrderDAL()
 {
     adpOrder  = new OrdersTableAdapter();
     tblOrders = new MyDataSet.OrdersDataTable();
 }
Ejemplo n.º 13
0
        public override SdataTransactionResult Delete(string localID)
        {
            SdataTransactionResult tmpTransactionResult;

            Sage.Integration.Northwind.Adapter.Data.SalesOrders.DataSets.OrderTableAdapters.OrdersTableAdapter        tableAdapter        = new OrdersTableAdapter();
            Sage.Integration.Northwind.Adapter.Data.SalesOrders.DataSets.OrderTableAdapters.Order_DetailsTableAdapter detailsTableAdapter = new Order_DetailsTableAdapter();
            Sage.Integration.Northwind.Adapter.Data.SalesOrders.DataSets.Order order = new Sage.Integration.Northwind.Adapter.Data.SalesOrders.DataSets.Order();

            int id;

            if (!(Int32.TryParse(localID, out id)))
            {
                id = 0;
            }
            int recordCount;

            using (OleDbConnection connection = new OleDbConnection(_context.Config.ConnectionString))
            {
                try
                {
                    tableAdapter.Connection = connection;
                    recordCount             = tableAdapter.FillBy(order.Orders, id);
                    if (recordCount == 0)
                    {
                        tmpTransactionResult              = new SdataTransactionResult();
                        tmpTransactionResult.LocalId      = localID;
                        tmpTransactionResult.HttpMethod   = HttpMethod.DELETE;
                        tmpTransactionResult.ResourceKind = _resourceKind;
                        tmpTransactionResult.HttpStatus   = System.Net.HttpStatusCode.BadRequest;
                        tmpTransactionResult.HttpMessage  = ("salesorder not found");
                        return(tmpTransactionResult);
                    }

                    detailsTableAdapter.Connection = connection;
                    detailsTableAdapter.FillBy(order.Order_Details, id);
                    foreach (DataRow row in order.Order_Details.Rows)
                    {
                        row.Delete();
                    }
                    order.Orders[0].Delete();
                    detailsTableAdapter.Update(order.Order_Details);
                    tableAdapter.Update(order.Orders);
                    tmpTransactionResult              = new SdataTransactionResult();
                    tmpTransactionResult.LocalId      = localID;
                    tmpTransactionResult.HttpMethod   = HttpMethod.DELETE;
                    tmpTransactionResult.ResourceKind = _resourceKind;
                    tmpTransactionResult.HttpStatus   = System.Net.HttpStatusCode.OK;
                    return(tmpTransactionResult);
                }
                catch (Exception e)
                {
                    tmpTransactionResult              = new SdataTransactionResult();
                    tmpTransactionResult.LocalId      = localID;
                    tmpTransactionResult.HttpMethod   = HttpMethod.DELETE;
                    tmpTransactionResult.ResourceKind = _resourceKind;
                    tmpTransactionResult.HttpStatus   = System.Net.HttpStatusCode.BadRequest;
                    tmpTransactionResult.HttpMessage  = e.Message;
                    return(tmpTransactionResult);
                }
            }
        }
        /// <summary>
        /// Display inventory, customers, and orders report.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OutputForm_Load(object sender, EventArgs e)
        {
            // Create new strongly typed datatables, and associated table adapters.

            var inventoryTable = new AutoLotDataSet.InventoryDataTable();
            var ordersTable    = new AutoLotDataSet.OrdersDataTable();
            var customersTable = new AutoLotDataSet.CustomersDataTable();

            InventoryTableAdapter inventoryAdapter = new InventoryTableAdapter();
            CustomersTableAdapter customersAdapter = new CustomersTableAdapter();
            OrdersTableAdapter    ordersAdapter    = new OrdersTableAdapter();

            // now fill the tables with data

            inventoryAdapter.Fill(inventoryTable);
            customersAdapter.Fill(customersTable);
            ordersAdapter.Fill(ordersTable);

            // display all of the cars from inventory

            textBoxOutput.AppendText($"Inventory Count = {inventoryTable.Count()}{Environment.NewLine}");

            foreach (var car in inventoryTable)
            {
                textBoxOutput.AppendText($"{car.CarId} {car.Make} {car.Color} {car.Name}{Environment.NewLine}");
            }


            // display  only cars with Id < 5

            var carsQuery =
                from car in inventoryTable
                where car.CarId < 5
                select car;

            textBoxOutput.AppendText($"{Environment.NewLine}LINQ result CarId < 5{Environment.NewLine}");

            foreach (var car in carsQuery)
            {
                textBoxOutput.AppendText($"{car.CarId} {car.Make} {car.Color} {car.Name}{Environment.NewLine}");
            }

            // display all orders, and show customer first and last name

            var ordersQuery =
                from order in ordersTable
                from car in inventoryTable
                from customer in customersTable
                where order.CustId == customer.CustId
                where order.CarId == car.CarId
                select new
            {
                order.OrderId,
                car.CarId,      // note use of implicit names for new anon object
                car.Name,
                car.Make,
                CustomerId   = customer.CustId,
                CustomerName = customer.FirstName + " " + customer.LastName,
            };

            textBoxOutput.AppendText($"{Environment.NewLine}Orders Count = {ordersQuery.Count()}{Environment.NewLine}");
            foreach (var order in ordersQuery)
            {
                textBoxOutput.AppendText($"#{order.OrderId} {order.CarId} {order.Make} {order.Name} by {order.CustomerId} {order.CustomerName}{Environment.NewLine}");
            }
        }
Ejemplo n.º 15
0
        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);
        }
Ejemplo n.º 16
0
        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);
        }
Ejemplo n.º 17
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            OrdersTableAdapter tableAdapter = new OrdersTableAdapter();

            TextBox1.Text = Convert.ToString(tableAdapter.Order_Count());
        }
Ejemplo n.º 18
0
        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);
        }
Ejemplo n.º 19
0
        public OrdersDataProvider()
        {
            NorthwindDataSet dataset = NorthWindDataProvider.NorthwindDataSet;

            adapter = new OrdersTableAdapter();
            adapter.Fill(dataset.Orders);

            AddRowChangeHandlers();
        }
Ejemplo n.º 20
0
        public override SdataTransactionResult Update(Sage.Common.Syndication.FeedEntry payload)
        {
            SdataTransactionResult tmpTransactionResult;
            SalesOrderFeedEntry    salesorder = null;

            #region check input values
            if (!(payload is SalesOrderFeedEntry))
            {
                tmpTransactionResult              = new SdataTransactionResult();
                tmpTransactionResult.HttpMethod   = HttpMethod.PUT;
                tmpTransactionResult.ResourceKind = _resourceKind;
                tmpTransactionResult.HttpStatus   = System.Net.HttpStatusCode.BadRequest;
                tmpTransactionResult.HttpMessage  = ("salesorder payload missing");
                return(tmpTransactionResult);
            }
            salesorder = (payload as SalesOrderFeedEntry);

            if (salesorder == null)
            {
                tmpTransactionResult              = new SdataTransactionResult();
                tmpTransactionResult.HttpMethod   = HttpMethod.PUT;
                tmpTransactionResult.ResourceKind = _resourceKind;
                tmpTransactionResult.HttpStatus   = System.Net.HttpStatusCode.BadRequest;
                tmpTransactionResult.HttpMessage  = ("salesorder payload missing");
                return(tmpTransactionResult);
            }

            string customerID = "";

            if (salesorder.tradingAccount != null)
            {
                customerID = GetLocalId(salesorder.tradingAccount.UUID, SupportedResourceKinds.tradingAccounts);
            }


            if (String.IsNullOrEmpty(customerID))
            {
                tmpTransactionResult              = new SdataTransactionResult();
                tmpTransactionResult.HttpMethod   = HttpMethod.PUT;
                tmpTransactionResult.ResourceKind = _resourceKind;
                tmpTransactionResult.HttpStatus   = System.Net.HttpStatusCode.BadRequest;
                tmpTransactionResult.HttpMessage  = ("Trading Acount Id missing");
                return(tmpTransactionResult);
            }

            if (!customerID.StartsWith(Sage.Integration.Northwind.Application.API.Constants.CustomerIdPrefix))
            {
                tmpTransactionResult              = new SdataTransactionResult();
                tmpTransactionResult.HttpMethod   = HttpMethod.PUT;
                tmpTransactionResult.ResourceKind = _resourceKind;
                tmpTransactionResult.HttpStatus   = System.Net.HttpStatusCode.BadRequest;
                tmpTransactionResult.HttpMessage  = ("Salesorder submission is only supported by customers");
                return(tmpTransactionResult);
            }
            #endregion

            Sage.Integration.Northwind.Adapter.Data.SalesOrders.DataSets.OrderTableAdapters.OrdersTableAdapter        tableAdapter        = new OrdersTableAdapter();
            Sage.Integration.Northwind.Adapter.Data.SalesOrders.DataSets.OrderTableAdapters.Order_DetailsTableAdapter detailsTableAdapter = new Order_DetailsTableAdapter();

            Sage.Integration.Northwind.Adapter.Data.SalesOrders.DataSets.Order order = new Sage.Integration.Northwind.Adapter.Data.SalesOrders.DataSets.Order();

            int id;
            if (!(Int32.TryParse(payload.Key, out id)))
            {
                id = 0;
            }
            int recordCount;

            using (OleDbConnection connection = new OleDbConnection(_context.Config.ConnectionString))
            {
                tableAdapter.Connection = connection;
                recordCount             = tableAdapter.FillBy(order.Orders, id);
                if (recordCount == 0)
                {
                    return(null);
                }

                detailsTableAdapter.Connection = connection;
                detailsTableAdapter.FillBy(order.Order_Details, id);
            }


            Sage.Integration.Northwind.Adapter.Data.SalesOrders.DataSets.Order.OrdersRow row = (Sage.Integration.Northwind.Adapter.Data.SalesOrders.DataSets.Order.OrdersRow)order.Orders[0];


            #region fill dataset from document
            try
            {
                if (!salesorder.IsPropertyChanged("date"))
                {
                    row.SetOrderDateNull();
                }
                else
                {
                    row.OrderDate = salesorder.date;
                }

                if (!salesorder.IsPropertyChanged("dueDate"))
                {
                    row.SetRequiredDateNull();
                }
                else
                {
                    row.RequiredDate = (DateTime)salesorder.dueDate;
                }

                //if (orderDoc.shippedvia.IsNull)
                //    newOrder.SetShipViaNull();
                //else
                //    newOrder.ShipVia = (int)orderDoc.shippedvia.Value;


                if (salesorder.postalAddresses == null || salesorder.postalAddresses.Entries.Count == 0)
                {
                    row.SetShipAddressNull();
                    row.SetShipCityNull();
                    row.SetShipCountryNull();
                    row.SetShipPostalCodeNull();
                }
                else
                {
                    PostalAddressFeedEntry postadress = salesorder.postalAddresses.Entries[0];
                    row.ShipAddress    = postadress.address1;
                    row.ShipCity       = postadress.townCity;
                    row.ShipPostalCode = postadress.zipPostCode;
                    row.ShipCountry    = postadress.country;
                }


                if (!salesorder.IsPropertyChanged("carrierTotalPrice"))
                {
                    row.Freight = (decimal)0;
                }
                else
                {
                    row.Freight = (decimal)salesorder.carrierTotalPrice;
                }

                //row.CreateUser = _context.Config.CrmUser;
                row.ModifyUser = _context.Config.CrmUser;
                //row.CreateID = _context.Config.SequenceNumber;
                row.ModifyID = _context.Config.SequenceNumber;

                Guid itemUuid;


                List <Sage.Integration.Northwind.Adapter.Data.SalesOrders.DataSets.Order.Order_DetailsRow> rowsToDelete = new List <Sage.Integration.Northwind.Adapter.Data.SalesOrders.DataSets.Order.Order_DetailsRow>();
                List <Guid> itemUuids = new List <Guid>();
                if (salesorder.salesOrderLines != null)
                {
                    foreach (SalesOrderLineFeedEntry soLine in salesorder.salesOrderLines.Entries)
                    {
                        if ((soLine.UUID != null && soLine.UUID != Guid.Empty) && (!itemUuids.Contains(soLine.UUID)))
                        {
                            itemUuids.Add(soLine.UUID);
                        }
                    }
                }

                foreach (Sage.Integration.Northwind.Adapter.Data.SalesOrders.DataSets.Order.Order_DetailsRow detailsRow in order.Order_Details)
                {
                    string itemId = detailsRow.OrderID.ToString() + "-" + detailsRow.ProductID.ToString();
                    itemUuid = GetUuid(itemId, "", SupportedResourceKinds.salesOrderLines);
                    if (itemUuids.Contains(itemUuid))
                    {
                        foreach (SalesOrderLineFeedEntry soLine in salesorder.salesOrderLines.Entries)
                        {
                            if (soLine.UUID.Equals(itemUuid))
                            {
                                if (soLine.IsDeleted)
                                {
                                    rowsToDelete.Add(detailsRow);
                                    break;
                                }

                                /*if (soLine.IsEmpty)
                                 * {
                                 *  break;
                                 * }*/
                                detailsRow.ModifyUser = _context.Config.CrmUser;
                                detailsRow.ModifyID   = _context.Config.SequenceNumber;
                                if (soLine.IsPropertyChanged("quantity"))
                                {
                                    detailsRow.Quantity = Convert.ToInt16(soLine.quantity);
                                }
                                else
                                {
                                    detailsRow.Quantity = 0;
                                }

                                if (soLine.IsPropertyChanged("initialPrice"))
                                {
                                    detailsRow.UnitPrice = (Decimal)soLine.initialPrice;
                                }
                                else
                                {
                                    detailsRow.UnitPrice = 0;
                                }

                                if ((!soLine.IsPropertyChanged("discountTotal")) || (detailsRow.Quantity == 0) || (detailsRow.UnitPrice == 0))
                                {
                                    detailsRow.Discount = (float)0;
                                }
                                else
                                {
                                    // discountPC = discountsum / qunatity * listprice
                                    //detailRow.Discount = Convert.ToSingle((decimal)lineItemDoc.discountsum.Value / ((decimal)detailRow.Quantity * detailRow.UnitPrice));
                                    float discount = Convert.ToSingle((decimal)soLine.discountTotal / (detailsRow.UnitPrice));
                                    if (discount > 1)
                                    {
                                        discount = 0;
                                    }
                                    detailsRow.Discount = discount;
                                }
                                break;
                            }
                        }
                        itemUuids.Remove(itemUuid);
                    }
                    else
                    {
                        //delete item
                        rowsToDelete.Add(detailsRow);
                    }
                }

                if (salesorder.salesOrderLines != null)
                {
                    foreach (SalesOrderLineFeedEntry soLine in salesorder.salesOrderLines.Entries)
                    {
                        Guid soUuid = soLine.UUID;
                        if (itemUuids.Contains(soUuid))
                        {
                            itemUuids.Remove(soUuid);
                        }
                        else
                        {
                            continue;
                        }

                        try
                        {
                            Sage.Integration.Northwind.Adapter.Data.SalesOrders.DataSets.Order.Order_DetailsRow detailRow = order.Order_Details.NewOrder_DetailsRow();
                            Guid   productUuid     = soLine.commodity.UUID;
                            string productIdString = GetLocalId(productUuid, SupportedResourceKinds.commodities);

                            int productID;
                            if (!int.TryParse(productIdString, out productID))
                            {
                                continue;
                            }

                            string sorderID = payload.Key + "-" + productID.ToString();
                            detailRow.OrderID   = Convert.ToInt32(payload.Key);
                            detailRow.ProductID = productID;
                            if (soLine.IsPropertyChanged("quantity"))
                            {
                                detailRow.Quantity = Convert.ToInt16(soLine.quantity);
                            }
                            else
                            {
                                detailRow.Quantity = 0;
                            }

                            if (soLine.IsPropertyChanged("initialPrice"))
                            {
                                detailRow.UnitPrice = (Decimal)soLine.initialPrice;
                            }
                            else
                            {
                                detailRow.UnitPrice = 0;
                            }

                            if ((!soLine.IsPropertyChanged("discountTotal")) || (detailRow.Quantity == 0) || (detailRow.UnitPrice == 0))
                            {
                                detailRow.Discount = (float)0;
                            }
                            else
                            {
                                // discountPC = discountsum / qunatity * listprice
                                //detailRow.Discount = Convert.ToSingle((decimal)lineItemDoc.discountsum.Value / ((decimal)detailRow.Quantity * detailRow.UnitPrice));
                                float discount = Convert.ToSingle((decimal)soLine.discountTotal / (detailRow.UnitPrice));
                                if (discount > 1)
                                {
                                    discount = 0;
                                }
                                detailRow.Discount = discount;
                            }

                            detailRow.CreateUser = _context.Config.CrmUser;
                            detailRow.ModifyUser = _context.Config.CrmUser;
                            detailRow.CreateID   = _context.Config.SequenceNumber;
                            detailRow.ModifyID   = _context.Config.SequenceNumber;
                            order.Order_Details.AddOrder_DetailsRow(detailRow);
                        }
                        // this error occours in case of invalid data types
                        catch (Exception e)
                        {
                            tmpTransactionResult              = new SdataTransactionResult();
                            tmpTransactionResult.HttpMethod   = HttpMethod.POST;
                            tmpTransactionResult.ResourceKind = _resourceKind;
                            tmpTransactionResult.HttpStatus   = System.Net.HttpStatusCode.BadRequest;
                            tmpTransactionResult.HttpMessage  = e.Message;
                            return(tmpTransactionResult);
                        }
                    }
                }



                using (OleDbConnection connection = new OleDbConnection(_context.Config.ConnectionString))
                {
                    OleDbTransaction transaction = null;
                    try
                    {
                        connection.Open();
                        transaction = connection.BeginTransaction();

                        tableAdapter.Connection        = connection;
                        detailsTableAdapter.Connection = connection;

                        tableAdapter.SetTransaction(transaction);
                        detailsTableAdapter.SetTransaction(transaction);

                        foreach (Sage.Integration.Northwind.Adapter.Data.SalesOrders.DataSets.Order.Order_DetailsRow detailsRow in rowsToDelete)
                        {
                            detailsTableAdapter.Delete(detailsRow.OrderID,
                                                       detailsRow.ProductID,
                                                       detailsRow.UnitPrice, detailsRow.Quantity,
                                                       detailsRow.Discount, detailsRow.CreateID, detailsRow.CreateUser, detailsRow.ModifyID, detailsRow.ModifyUser);
                        }

                        tableAdapter.Update(order.Orders);
                        detailsTableAdapter.Update(order.Order_Details);

                        transaction.Commit();


                        tmpTransactionResult              = new SdataTransactionResult();
                        tmpTransactionResult.HttpMethod   = HttpMethod.PUT;
                        tmpTransactionResult.ResourceKind = _resourceKind;
                        tmpTransactionResult.HttpStatus   = System.Net.HttpStatusCode.OK;
                        tmpTransactionResult.LocalId      = payload.Key;
                        return(tmpTransactionResult);
                    }
                    catch (Exception transactionException)
                    {
                        if (transaction != null)
                        {
                            transaction.Rollback();
                        }
                        throw;
                    }
                }
            }
            catch (Exception e)
            {
                tmpTransactionResult              = new SdataTransactionResult();
                tmpTransactionResult.HttpMethod   = HttpMethod.PUT;
                tmpTransactionResult.ResourceKind = _resourceKind;
                tmpTransactionResult.HttpStatus   = System.Net.HttpStatusCode.BadRequest;
                tmpTransactionResult.HttpMessage  = e.ToString();
                return(tmpTransactionResult);
            }

            #endregion
        }