예제 #1
1
    public IEnumerable<ProductViewModel> Create(ProductViewModel product)
    {
        using (var northwind = new Northwind())
        {
            // Create a new Product entity and set its properties from target
            var target = new Product
            {
                ProductName = product.ProductName,
                UnitPrice = product.UnitPrice,
                UnitsInStock = product.UnitsInStock,
                Discontinued = product.Discontinued
            };

            // Add the entity
            northwind.Products.AddObject(target);

            // Insert all created product to the database
            northwind.SaveChanges();

            product.ProductID = target.ProductID;

            // Return the inserted product - the Kendo Grid needs their ProductID which is generated by SQL server during insertion
            return new[] { product };
        }
    }
예제 #2
0
    public GridModel Read(int take, int skip) 
    {
        using (var northwind = new Northwind())
        {
            IQueryable<ProductViewModel> data = northwind.Products
                // Use a view model to avoid serializing internal Entity Framework properties as JSON
                .Select(p => new ProductViewModel
                {
                    ProductID = p.ProductID,
                    ProductName = p.ProductName,
                    UnitPrice = p.UnitPrice,
                    UnitsInStock = p.UnitsInStock,
                    Discontinued = p.Discontinued
                });
            var total = data.Count();

            var gridModel = new GridModel()
            {
                 Data = data.OrderBy(p=>p.ProductID).Skip(skip)
                            .Take(take)
                            .ToList(),
                 Total = total
            };

            return gridModel;
        }
    }
예제 #3
0
 protected string DisplayPrice(Northwind.ProductsRow product)
 {
     // If price is less than $20.00, return the price, highlighted
     if (!product.IsUnitPriceNull() && product.UnitPrice < 20)
         return string.Concat("<span class=\"AffordablePriceEmphasis\">", product.UnitPrice.ToString("C"), "</span>");
     else
         // Otherwise return the text, "Please call for a price quote"
         return "<span>Please call for a price quote</span>";
 }
 protected string DisplayDaysOnJob(Northwind.EmployeesRow employee)
 {
     // Make sure HiredDate is not null... if so, return "Unknown"
     if (employee.IsHireDateNull())
         return "Unknown";
     else
     {
         // Returns the number of days between the current
         // date/time and hiredDate
         TimeSpan ts = DateTime.Now.Subtract(employee.HireDate);
         return ts.Days.ToString("#,##0");
     }
 }
예제 #5
0
        public EmployeeManagerGrids()
        {
            InitializeComponent();

            db = new Northwind(Program.connString);
            var employeeQuery = from employee in db.Employees
                                orderby employee.LastName
                                select employee;
            //ToBindingList 方法可将查询转换成支持 IBindingList 的结构。
            //需要将 Table<T> 转换成绑定列表,以便可以正确跟踪
            //实体的添加和删除情况。
            employeeBindingSource.DataSource = employeeQuery;
            managerBindingSource.DataSource = employeeQuery.ToList();
        }
        public EmployeeManagerGrids()
        {
            InitializeComponent();

            db = new Northwind(Program.connString);
            var employeeQuery = from employee in db.Employees
                                orderby employee.LastName
                                select employee;
            //ToBindingList method converts query into a structure that supports IBindingList.
            //The Table<T> is required to convert to a binding list so that the addition and
            //deletion of entities are tracked correctly.
            employeeBindingSource.DataSource = employeeQuery;
            managerBindingSource.DataSource = employeeQuery.ToList();
        }
예제 #7
0
 public IEnumerable<ProductViewModel> Read()
 {
     using (var northwind = new Northwind())
     {
         return northwind.Products
             .OrderByDescending(p => p.ProductID) //EF requires sorted IQueryable in order to do paging
             // Use a view model to avoid serializing internal Entity Framework properties as JSON
             .Select(p => new ProductViewModel
             {
                 ProductID = p.ProductID,
                 ProductName = p.ProductName,
                 UnitPrice = p.UnitPrice,
                 UnitsInStock = p.UnitsInStock,
                 Discontinued = p.Discontinued
             })
             .ToList();
     }
 }
예제 #8
0
 public DataSourceResult Read(int take, int skip, IEnumerable<Sort> sort, Filter filter) 
 {
     using (var northwind = new Northwind())
     {
         return northwind.Products
             .OrderBy(p => p.ProductID) // EF requires oredered IQueryable to do paging
             // Use a view model to avoid serializing internal Entity Framework properties as JSON
             .Select(p => new ProductViewModel
             {
                 ProductID = p.ProductID,
                 ProductName = p.ProductName,
                 UnitPrice = p.UnitPrice,
                 UnitsInStock = p.UnitsInStock,
                 Discontinued = p.Discontinued
             })
             .ToDataSourceResult(take, skip, sort, filter);
     }
 }
예제 #9
0
    public GridModel Create(IEnumerable<ProductViewModel> products)
    {
        var result = new List<Product>();

        using (var northwind = new Northwind())
        {
            //Iterate all created products which are posted by the Kendo Grid
            foreach (var productViewModel in products)
            {
                // Create a new Product entity and set its properties from productViewModel
                var product = new Product
                {
                    ProductName = productViewModel.ProductName,
                    UnitPrice = productViewModel.UnitPrice,
                    UnitsInStock = productViewModel.UnitsInStock,
                    Discontinued = productViewModel.Discontinued
                };

                // store the product in the result
                result.Add(product);

                // Add the entity
                northwind.Products.AddObject(product);
            }

            // Insert all created products to the database
            northwind.SaveChanges();

            // Return the inserted products - the Kendo Grid needs their ProductID which is generated by SQL server during insertion

            return new GridModel()
            {
                Data = result.Select(p => new ProductViewModel
                {
                    ProductID = p.ProductID,
                    ProductName = p.ProductName,
                    UnitPrice = p.UnitPrice,
                    UnitsInStock = p.UnitsInStock,
                    Discontinued = p.Discontinued
                })
                .ToList()
            };
        }
    }
 protected void cleanup(Northwind db)
 {
     try
     {
         // Get the name of the Order Details table properly evaluating the Annotation
         string tableName = null;// db.Vendor.GetSqlFieldSafeName("order details"); //eg. "[Order Details]"
         foreach (object obj in typeof(OrderDetail).GetCustomAttributes(true))
         {
             if (obj is System.Data.Linq.Mapping.TableAttribute)
             {
                 tableName = ((System.Data.Linq.Mapping.TableAttribute)obj).Name;
             }
         }
         string sql = string.Format("DELETE FROM {0} WHERE OrderID=3 AND ProductID=2", tableName);
         db.ExecuteCommand(sql);
     }
     catch (Exception)
     {
     }
 }
예제 #11
0
        static void Main(string[] args)
        {
            // For this sample to work, you need an active database server or SqlExpress.
            // Here is a connection to the Data sample project that ships with Microsoft Visual Studio 2008.
            string dbPath = Path.GetFullPath(Path.Combine(Application.StartupPath, @"..\..\..\..\Data\NORTHWND.MDF"));
            string sqlServerInstance = @".\SQLEXPRESS";
            string connString = "AttachDBFileName='" + dbPath + "';Server='" + sqlServerInstance + "';user instance=true;Integrated Security=SSPI;Connection Timeout=60";

            // Here is an alternate connect string that you can modify for your own purposes.
            // string connString = "server=test;database=northwind;user id=test;password=test";

            Northwind db = new Northwind(connString);
            db.Log = Console.Out;

            var query =
                db.Customers.Where("City == @0 and Orders.Count >= @1", "London", 10).
                OrderBy("CompanyName").
                Select("New(CompanyName as Name, Phone)");

            Console.WriteLine(query);
            Console.ReadLine();
        }
예제 #12
0
파일: Program.cs 프로젝트: jetlive/skiaming
        static void Main(string[] args)
        {
            // 要使此示例能够运行,需要活动数据库服务器或 SqlExpress。
            // 下面是与 Microsoft Visual Studio 2008 附带的 Data 示例项目的连接。
            string dbPath = Path.GetFullPath(Path.Combine(Application.StartupPath, @"..\..\..\..\Data\NORTHWND.MDF"));
            string sqlServerInstance = @".\SQLEXPRESS";
            string connString = "AttachDBFileName='" + dbPath + "';Server='" + sqlServerInstance + "';user instance=true;Integrated Security=SSPI;Connection Timeout=60";

            // 下面是可按自己的目的修改的备用连接字符串。
            // string connString = "server=test;database=northwind;user id=test;password=test";

            Northwind db = new Northwind(connString);
            db.Log = Console.Out;

            var query =
                db.Customers.Where("City == @0 and Orders.Count >= @1", "London", 10).
                OrderBy("CompanyName").
                Select("New(CompanyName as Name, Phone)");

            Console.WriteLine(query);
            Console.ReadLine();
        }
    public void Destroy(IEnumerable<ProductViewModel> products)
    {
        using (var northwind = new Northwind())
        {
            //Iterate all destroyed products which are posted by the Kendo Grid
            foreach (var productViewModel in products)
            {
                // Create a new Product entity and set its properties from productViewModel
                var product = new Product
                {
                    ProductID = (int)productViewModel.ProductID,
                };

                // Attach the entity
                northwind.Products.Attach(product);
                // Delete the entity
                northwind.Products.DeleteObject(product);
            }

            // Delete the products from the database
            northwind.SaveChanges();
        }
    }
예제 #14
0
    public void Update(ProductViewModel product)
    {
        using (var northwind = new Northwind())
        {
            // Create a new Product entity and set its properties from target
            var target = new Product
            {
                ProductID = (int)product.ProductID,
                ProductName = product.ProductName,
                UnitPrice = product.UnitPrice,
                UnitsInStock = product.UnitsInStock,
                Discontinued = product.Discontinued
            };

            // Attach the entity
            northwind.Products.Attach(target);
            // Change its state to Modified so Entity Framework can update the existing target instead of creating a new one
            northwind.ObjectStateManager.ChangeObjectState(target, EntityState.Modified);

            // Save all updated product to the database
            northwind.SaveChanges();
        }
    }
 /// <summary>Initializes a new instance of the <see cref="DynamicRelation"/> class.</summary>
 /// <param name="leftOperand">The left operand.</param>
 /// <param name="joinType">Type of the join. If None is specified, Inner is assumed.</param>
 /// <param name="rightOperand">The right operand which is an entity type.</param>
 /// <param name="aliasRightOperand">The alias of the right operand. If you don't want to / need to alias the right operand (only alias if you have to), specify string.Empty.</param>
 /// <param name="onClause">The on clause for the join.</param>
 public DynamicRelation(DerivedTableDefinition leftOperand, JoinHint joinType, Northwind.Data.EntityType rightOperand, string aliasRightOperand, IPredicate onClause)
 {
     this.InitClass(joinType, string.Empty, aliasRightOperand, onClause, leftOperand, GeneralEntityFactory.Create(rightOperand));
 }
예제 #16
0
 public CustomersModel(Northwind injectedContext)
 {
     db = injectedContext;
 }
        protected async void Form0Submit(Category args)
        {
            var northwindUpdateCategoryResult = await Northwind.UpdateCategory(int.Parse(CategoryID), category);

            UriHelper.NavigateTo("Categories");
        }
예제 #18
0
 private IQueryable <Employee> filterByOrderCountGreaterThan(Northwind db, IQueryable <Employee> allEmployees, int minimumOrderNumber)
 {
     return(from e in allEmployees.Where(e => e.Orders.Count > minimumOrderNumber) select e);
 }
 private List <Orders> ApplyFilter(Northwind NorthwindSource)
 {
     // records are filtered based on CustomerID column
     return(NorthwindSource.Orders.Where(item => item.CustomerID.Contains(filterTextBox.Text)).ToList());
 }
예제 #20
0
 private static Customer GetCustomerById(Northwind db, string id)
 {
     return(db.Customers.SingleOrDefault(c => c.CustomerID == id));
 }
예제 #21
0
        protected async void Load()
        {
            var northwindGetOrdersQriesResult = await Northwind.GetOrdersQries();

            getOrdersQriesResult = northwindGetOrdersQriesResult;
        }
예제 #22
0
 public HomeController(Northwind wstrzyknientyKontekst)
 {
     bd = wstrzyknientyKontekst;
 }
예제 #23
0
        protected async void Form0Submit(Employee args)
        {
            var northwindCreateEmployeeResult = await Northwind.CreateEmployee(employee);

            DialogService.Close(employee);
        }
예제 #24
0
        protected async void Form0Submit(OrderDetail args)
        {
            var northwindUpdateOrderDetailResult = await Northwind.UpdateOrderDetail(int.Parse(OrderID), int.Parse(ProductID), orderdetail);

            UriHelper.NavigateTo("OrderDetails");
        }
        protected async System.Threading.Tasks.Task Load()
        {
            var northwindGetOrderSubtotalsResult = await Northwind.GetOrderSubtotals();

            getOrderSubtotalsResult = northwindGetOrderSubtotalsResult;
        }
 //Constructor
 public ShipperModel(Northwind injectedContext)
 {
     db = injectedContext;
 }
        /// <summary>
        /// 	Update an existing row in the datasource.
        /// </summary>
        /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
        /// <param name="entity">Northwind.Entities.Customers object to update.</param>
        /// <remarks>
        ///		After updating the datasource, the Northwind.Entities.Customers object will be updated
        /// 	to refelect any changes made by the datasource. (ie: identity or computed columns)
        /// </remarks>
        /// <returns>Returns true if operation is successful.</returns>
        /// <exception cref="System.Exception">The command could not be executed.</exception>
        /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception>
        /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception>
        public override bool Update(TransactionManager transactionManager, Northwind.Entities.Customers entity)
        {
            SqlDatabase database = new SqlDatabase(this._connectionString);
            DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.sp_nt_Customers_Update", _useStoredProcedure);

            database.AddInParameter(commandWrapper, "@CustomerId", DbType.StringFixedLength, entity.CustomerId );
            database.AddInParameter(commandWrapper, "@OriginalCustomerId", DbType.StringFixedLength, entity.OriginalCustomerId);
            database.AddInParameter(commandWrapper, "@CompanyName", DbType.String, entity.CompanyName );
            database.AddInParameter(commandWrapper, "@ContactName", DbType.String, entity.ContactName );
            database.AddInParameter(commandWrapper, "@ContactTitle", DbType.String, entity.ContactTitle );
            database.AddInParameter(commandWrapper, "@Address", DbType.String, entity.Address );
            database.AddInParameter(commandWrapper, "@City", DbType.String, entity.City );
            database.AddInParameter(commandWrapper, "@Region", DbType.String, entity.Region );
            database.AddInParameter(commandWrapper, "@PostalCode", DbType.String, entity.PostalCode );
            database.AddInParameter(commandWrapper, "@Country", DbType.String, entity.Country );
            database.AddInParameter(commandWrapper, "@Phone", DbType.String, entity.Phone );
            database.AddInParameter(commandWrapper, "@Fax", DbType.String, entity.Fax );

            int results = 0;

            //Provider Data Requesting Command Event
            OnDataRequesting(new CommandEventArgs(commandWrapper, "Update", entity));

            if (transactionManager != null)
            {
                results = Utility.ExecuteNonQuery(transactionManager, commandWrapper);
            }
            else
            {
                results = Utility.ExecuteNonQuery(database,commandWrapper);
            }

            //Stop Tracking Now that it has been updated and persisted.
            if (DataRepository.Provider.EnableEntityTracking)
            {
                EntityManager.StopTracking(entity.EntityTrackingKey);
            }

            entity.OriginalCustomerId = entity.CustomerId;

            entity.AcceptChanges();

            //Provider Data Requested Command Event
            OnDataRequested(new CommandEventArgs(commandWrapper, "Update", entity));

            return Convert.ToBoolean(results);
        }
    public void Update(IEnumerable<ProductViewModel> products)
    {
        using (var northwind = new Northwind())
        {
            //Iterate all updated products which are posted by the Kendo Grid
            foreach (var productViewModel in products)
            {
                // Create a new Product entity and set its properties from productViewModel
                var product = new Product
                {
                    ProductID = (int)productViewModel.ProductID,
                    ProductName = productViewModel.ProductName,
                    UnitPrice = productViewModel.UnitPrice,
                    UnitsInStock = productViewModel.UnitsInStock,
                    Discontinued = productViewModel.Discontinued
                };

                // Attach the entity
                northwind.Products.Attach(product);
                // Change its state to Modified so Entity Framework can update the existing product instead of creating a new one
                northwind.ObjectStateManager.ChangeObjectState(product, EntityState.Modified);
            }

            // Save all updated products to the database
            northwind.SaveChanges();
        }
    }
 //Constructor to instantiate this db
 // Instantiate Northwind just once : use for Get() and Post()
 public AllCustomersModel(Northwind InjectedContext)
 {
     db = InjectedContext;
 }
예제 #30
0
 private IQueryable <Employee> filterByNameOrSurnameContains(Northwind db, IQueryable <Employee> allEmployees, string namePart)
 {
     return(from e in allEmployees.Where(e => e.FirstName.Contains(namePart) || e.LastName.Contains(namePart)) select e);
 }
        /// <summary>
        /// 	Inserts a Northwind.Entities.Categories object into the datasource using a transaction.
        /// </summary>
        /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
        /// <param name="entity">Northwind.Entities.Categories object to insert.</param>
        /// <remarks>
        ///		After inserting into the datasource, the Northwind.Entities.Categories object will be updated
        /// 	to refelect any changes made by the datasource. (ie: identity or computed columns)
        /// </remarks>	
        /// <returns>Returns true if operation is successful.</returns>
        /// <exception cref="System.Exception">The command could not be executed.</exception>
        /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception>
        /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception>
        public override bool Insert(TransactionManager transactionManager, Northwind.Entities.Categories entity)
        {
            SqlDatabase database = new SqlDatabase(this._connectionString);
            DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.sp_nt_Categories_Insert", _useStoredProcedure);

            database.AddOutParameter(commandWrapper, "@CategoryId", DbType.Int32, 4);
            database.AddInParameter(commandWrapper, "@CategoryName", DbType.String, entity.CategoryName );
            database.AddInParameter(commandWrapper, "@Description", DbType.String, entity.Description );
            database.AddInParameter(commandWrapper, "@Picture", DbType.Binary, entity.Picture );

            int results = 0;

            //Provider Data Requesting Command Event
            OnDataRequesting(new CommandEventArgs(commandWrapper, "Insert", entity));

            if (transactionManager != null)
            {
                results = Utility.ExecuteNonQuery(transactionManager, commandWrapper);
            }
            else
            {
                results = Utility.ExecuteNonQuery(database,commandWrapper);
            }

            object _categoryId = database.GetParameterValue(commandWrapper, "@CategoryId");
            entity.CategoryId = (System.Int32)_categoryId;

            entity.AcceptChanges();

            //Provider Data Requested Command Event
            OnDataRequested(new CommandEventArgs(commandWrapper, "Insert", entity));

            return Convert.ToBoolean(results);
        }
예제 #32
0
 public CustomersController(Northwind context)
 {
     _context = context;
 }
 public IEnumerable<ProductViewModel> Read()
 {
     using (var northwind = new Northwind())
     {
         return northwind.Products
             // Use a view model to avoid serializing internal Entity Framework properties as JSON
             .Select(p => new ProductViewModel
             {
                 ProductID = p.ProductID,
                 ProductName = p.ProductName,
                 UnitPrice = p.UnitPrice,
                 UnitsInStock = p.UnitsInStock,
                 Discontinued = p.Discontinued
             })
             .ToList();
     }
 }
예제 #34
0
 public CategoriesController(Northwind context)
 {
     _context = context;
 }
        protected async void Load()
        {
            var northwindGetOrderSubtotalsResult = await Northwind.GetOrderSubtotals();

            getOrderSubtotalsResult = northwindGetOrderSubtotalsResult;
        }
예제 #36
0
        static void Main(string[] args)
        {
            using (var db = new Northwind())
            {
                ILoggerFactory loggerFactory = db.GetService <ILoggerFactory>();
                loggerFactory.AddProvider(new ConsoleLogProvider());

                using (IDbContextTransaction ct = db.Database.BeginTransaction())
                {
                    WriteLine($"Isolation level: {ct.GetDbTransaction().IsolationLevel}");

                    WriteLine("List of categories and the number of products:");

                    IQueryable <Category> cats;
                    // = db.Categories.Include(c => c.Products);

                    Write("Enable eager loading? (Y/N): ");
                    bool eagerloading    = (ReadKey().Key == ConsoleKey.Y);
                    bool explicitloading = false;
                    WriteLine();
                    if (eagerloading)
                    {
                        cats = db.Categories.Include(c => c.Products);
                    }
                    else
                    {
                        cats = db.Categories;
                        Write("Enable explicit loading? (Y/N): ");
                        explicitloading = (ReadKey().Key == ConsoleKey.Y);
                        WriteLine();
                    }


                    foreach (Category c in cats)
                    {
                        if (explicitloading)
                        {
                            Write($"Explicitly load products for {c.CategoryName}? (Y/N):");
                            if (ReadKey().Key == ConsoleKey.Y)
                            {
                                var products = db.Entry(c).Collection(c2 => c2.Products);
                                if (!products.IsLoaded)
                                {
                                    products.Load();
                                }
                            }
                            WriteLine();
                        }
                        WriteLine($"{c.CategoryName} has {c.Products.Count} products.");
                    }

                    WriteLine(@"List of products that cost more than a given price    
                    with most expensive first.");

                    string  input;
                    decimal price;
                    do
                    {
                        Write("Enter a product price: ");
                        input = ReadLine();
                    } while (!decimal.TryParse(input, out price));

                    IQueryable <Product> prods = db.Products
                                                 .Where(product => product.UnitPrice > price)
                                                 .OrderByDescending(product => product.UnitPrice);

                    foreach (Product item in prods)
                    {
                        WriteLine($"{item.ProductID}: {item.ProductName} costs {item.UnitPrice:$#,##0.00}");
                    }

                    WriteLine();

                    var newProduct = new Product
                    {
                        CategoryID  = 6, // Meat & Poultry
                        ProductName = "Bob's Burger",
                        UnitPrice   = 500M
                    };
                    // mark product as added in change tracking
                    db.Products.Add(newProduct);
                    // save tracked changes to database
                    db.SaveChanges();
                    foreach (var item in db.Products)
                    {
                        WriteLine($"{item.ProductID}: {item.ProductName} costs {item.UnitPrice:$#,##0.00}");
                    }

                    WriteLine();

                    Product deleteProduct = db.Products.First(p => p.ProductName.StartsWith("Bob"));
                    db.Products.Remove(deleteProduct);
                    db.SaveChanges();
                    foreach (var item in db.Products)
                    {
                        WriteLine($"{item.ProductID}: {item.ProductName} costs{item.UnitPrice:$#,##0.00}");
                    }

                    ct.Commit();
                }
            }
        }
예제 #37
0
 public CustomersController(Northwind injectedContext)
 {
     db = injectedContext;
 }
예제 #38
0
        protected async void Form0Submit(Employee args)
        {
            var northwindUpdateEmployeeResult = await Northwind.UpdateEmployee(int.Parse(EmployeeID), employee);

            DialogService.Close(employee);
        }
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        string resourceFileName = "XtraReport2.resx";

        this.Detail       = new DevExpress.XtraReports.UI.DetailBand();
        this.xrLabel1     = new DevExpress.XtraReports.UI.XRLabel();
        this.TopMargin    = new DevExpress.XtraReports.UI.TopMarginBand();
        this.BottomMargin = new DevExpress.XtraReports.UI.BottomMarginBand();
        this.northwind1   = new Northwind();
        this.CatID        = new DevExpress.XtraReports.Parameters.Parameter();
        ((System.ComponentModel.ISupportInitialize)(this.northwind1)).BeginInit();
        ((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
        //
        // Detail
        //
        this.Detail.Controls.AddRange(new DevExpress.XtraReports.UI.XRControl[] {
            this.xrLabel1
        });
        this.Detail.HeightF       = 47F;
        this.Detail.Name          = "Detail";
        this.Detail.Padding       = new DevExpress.XtraPrinting.PaddingInfo(0, 0, 0, 0, 100F);
        this.Detail.TextAlignment = DevExpress.XtraPrinting.TextAlignment.TopLeft;
        //
        // xrLabel1
        //
        this.xrLabel1.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] {
            new DevExpress.XtraReports.UI.XRBinding("Text", null, "spProducts.ProductName")
        });
        this.xrLabel1.LocationFloat = new DevExpress.Utils.PointFloat(225F, 12.5F);
        this.xrLabel1.Name          = "xrLabel1";
        this.xrLabel1.Padding       = new DevExpress.XtraPrinting.PaddingInfo(2, 2, 0, 0, 100F);
        this.xrLabel1.SizeF         = new System.Drawing.SizeF(206.25F, 23F);
        this.xrLabel1.Text          = "xrLabel1";
        //
        // TopMargin
        //
        this.TopMargin.HeightF       = 100F;
        this.TopMargin.Name          = "TopMargin";
        this.TopMargin.Padding       = new DevExpress.XtraPrinting.PaddingInfo(0, 0, 0, 0, 100F);
        this.TopMargin.TextAlignment = DevExpress.XtraPrinting.TextAlignment.TopLeft;
        //
        // BottomMargin
        //
        this.BottomMargin.HeightF       = 100F;
        this.BottomMargin.Name          = "BottomMargin";
        this.BottomMargin.Padding       = new DevExpress.XtraPrinting.PaddingInfo(0, 0, 0, 0, 100F);
        this.BottomMargin.TextAlignment = DevExpress.XtraPrinting.TextAlignment.TopLeft;
        //
        // northwind1
        //
        this.northwind1.DataSetName             = "Northwind";
        this.northwind1.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema;
        //
        // CatID
        //
        this.CatID.Name          = "CatID";
        this.CatID.ParameterType = DevExpress.XtraReports.Parameters.ParameterType.Int32;
        this.CatID.Value         = 0;
        //
        // XtraReport2
        //
        this.Bands.AddRange(new DevExpress.XtraReports.UI.Band[] {
            this.Detail,
            this.TopMargin,
            this.BottomMargin
        });
        this.DataMember = "spProducts";
        this.DataSource = this.northwind1;
        this.Parameters.AddRange(new DevExpress.XtraReports.Parameters.Parameter[] {
            this.CatID
        });
        this.Version      = "9.3";
        this.BeforePrint += new System.Drawing.Printing.PrintEventHandler(this.XtraReport2_BeforePrint);
        ((System.ComponentModel.ISupportInitialize)(this.northwind1)).EndInit();
        ((System.ComponentModel.ISupportInitialize)(this)).EndInit();
    }
 protected override void AddItemToDbContext(Northwind dbContext, Category newItem)
 {
     dbContext.Categories.Add(newItem);
 }
예제 #41
0
 public SuppliersModel(Northwind injectedContext)
 {
     db = injectedContext;
 }
 public EditCustomerModel(Northwind InjectedContext)
 {
     db = InjectedContext;
 }
예제 #43
0
 public KlienciModel(Northwind wstrzyknietyKontekst)
 {
     db = wstrzyknietyKontekst;
 }
 public MyModel()
 {
     this.northwind = new Northwind();
 }
 /// <summary>Initializes a new instance of the <see cref="DynamicRelation"/> class.</summary>
 /// <param name="leftOperand">The left operand, which is an entity.</param>
 /// <param name="joinType">Type of the join. If None is specified, Inner is assumed.</param>
 /// <param name="rightOperand">The right operand which is an entity.</param>
 /// <param name="aliasLeftOperand">The alias of the left operand. If you don't want to / need to alias the left operand (only alias if you have to), specify string.Empty.</param>
 /// <param name="aliasRightOperand">The alias of the right operand. If you don't want to / need to alias the right operand (only alias if you have to), specify string.Empty.</param>
 /// <param name="onClause">The on clause for the join.</param>
 public DynamicRelation(Northwind.Data.EntityType leftOperand, JoinHint joinType, Northwind.Data.EntityType rightOperand, string aliasLeftOperand, string aliasRightOperand, IPredicate onClause)
 {
     this.InitClass(joinType, aliasLeftOperand, aliasRightOperand, onClause, GeneralEntityFactory.Create(leftOperand), GeneralEntityFactory.Create(rightOperand));
 }
예제 #46
0
 public HomeController(Northwind injectedContext)
 {
     db = injectedContext;
 }
 /// <summary>General factory entrance method which will return an EntityFields2 object with the format generated by the factory specified</summary>
 /// <param name="relatedEntityType">The type of entity the fields are for</param>
 /// <returns>The IEntityFields instance requested</returns>
 public static IEntityFields2 CreateEntityFieldsObject(Northwind.Data.EntityType relatedEntityType)
 {
     return FieldInfoProviderSingleton.GetInstance().GetEntityFields(InheritanceInfoProviderSingleton.GetInstance(), _entityTypeNamesCache[relatedEntityType]);
 }
        public ReadTest_Complex()
        {
            db = CreateDB();

        }
        /// <summary>
        /// 	Update an existing row in the datasource.
        /// </summary>
        /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
        /// <param name="entity">Northwind.Entities.Employees object to update.</param>
        /// <remarks>
        ///		After updating the datasource, the Northwind.Entities.Employees object will be updated
        /// 	to refelect any changes made by the datasource. (ie: identity or computed columns)
        /// </remarks>
        /// <returns>Returns true if operation is successful.</returns>
        /// <exception cref="System.Exception">The command could not be executed.</exception>
        /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception>
        /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception>
        public override bool Update(TransactionManager transactionManager, Northwind.Entities.Employees entity)
        {
            SqlDatabase database = new SqlDatabase(this._connectionString);
            DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.sp_nt_Employees_Update", _useStoredProcedure);

            database.AddInParameter(commandWrapper, "@EmployeeId", DbType.Int32, entity.EmployeeId );
            database.AddInParameter(commandWrapper, "@LastName", DbType.String, entity.LastName );
            database.AddInParameter(commandWrapper, "@FirstName", DbType.String, entity.FirstName );
            database.AddInParameter(commandWrapper, "@Title", DbType.String, entity.Title );
            database.AddInParameter(commandWrapper, "@TitleOfCourtesy", DbType.String, entity.TitleOfCourtesy );
            database.AddInParameter(commandWrapper, "@BirthDate", DbType.DateTime, (entity.BirthDate.HasValue ? (object) entity.BirthDate : System.DBNull.Value) );
            database.AddInParameter(commandWrapper, "@HireDate", DbType.DateTime, (entity.HireDate.HasValue ? (object) entity.HireDate : System.DBNull.Value) );
            database.AddInParameter(commandWrapper, "@Address", DbType.String, entity.Address );
            database.AddInParameter(commandWrapper, "@City", DbType.String, entity.City );
            database.AddInParameter(commandWrapper, "@Region", DbType.String, entity.Region );
            database.AddInParameter(commandWrapper, "@PostalCode", DbType.String, entity.PostalCode );
            database.AddInParameter(commandWrapper, "@Country", DbType.String, entity.Country );
            database.AddInParameter(commandWrapper, "@HomePhone", DbType.String, entity.HomePhone );
            database.AddInParameter(commandWrapper, "@Extension", DbType.String, entity.Extension );
            database.AddInParameter(commandWrapper, "@Photo", DbType.Binary, entity.Photo );
            database.AddInParameter(commandWrapper, "@Notes", DbType.String, entity.Notes );
            database.AddInParameter(commandWrapper, "@ReportsTo", DbType.Int32, (entity.ReportsTo.HasValue ? (object) entity.ReportsTo : System.DBNull.Value) );
            database.AddInParameter(commandWrapper, "@PhotoPath", DbType.String, entity.PhotoPath );

            int results = 0;

            //Provider Data Requesting Command Event
            OnDataRequesting(new CommandEventArgs(commandWrapper, "Update", entity));

            if (transactionManager != null)
            {
                results = Utility.ExecuteNonQuery(transactionManager, commandWrapper);
            }
            else
            {
                results = Utility.ExecuteNonQuery(database,commandWrapper);
            }

            //Stop Tracking Now that it has been updated and persisted.
            if (DataRepository.Provider.EnableEntityTracking)
            {
                EntityManager.StopTracking(entity.EntityTrackingKey);
            }

            entity.AcceptChanges();

            //Provider Data Requested Command Event
            OnDataRequested(new CommandEventArgs(commandWrapper, "Update", entity));

            return Convert.ToBoolean(results);
        }
예제 #50
0
 public Northwind CreateDB(System.Data.ConnectionState state)
 {
     CheckRecreateSqlite();
     XSqlConnection conn = new XSqlConnection(connStr);
     if (state == System.Data.ConnectionState.Open)
         conn.Open();
     Northwind db = new Northwind(conn);
     return db;
 }
        /// <summary>
        /// 	Inserts a Northwind.Entities.Region object into the datasource using a transaction.
        /// </summary>
        /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
        /// <param name="entity">Northwind.Entities.Region object to insert.</param>
        /// <remarks>
        ///		After inserting into the datasource, the Northwind.Entities.Region object will be updated
        /// 	to refelect any changes made by the datasource. (ie: identity or computed columns)
        /// </remarks>	
        /// <returns>Returns true if operation is successful.</returns>
        /// <exception cref="System.Exception">The command could not be executed.</exception>
        /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception>
        /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception>
        public override bool Insert(TransactionManager transactionManager, Northwind.Entities.Region entity)
        {
            SqlDatabase database = new SqlDatabase(this._connectionString);
            DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.sp_nt_Region_Insert", _useStoredProcedure);

            database.AddInParameter(commandWrapper, "@RegionId", DbType.Int32, entity.RegionId );
            database.AddInParameter(commandWrapper, "@RegionDescription", DbType.StringFixedLength, entity.RegionDescription );

            int results = 0;

            //Provider Data Requesting Command Event
            OnDataRequesting(new CommandEventArgs(commandWrapper, "Insert", entity));

            if (transactionManager != null)
            {
                results = Utility.ExecuteNonQuery(transactionManager, commandWrapper);
            }
            else
            {
                results = Utility.ExecuteNonQuery(database,commandWrapper);
            }

            entity.OriginalRegionId = entity.RegionId;

            entity.AcceptChanges();

            //Provider Data Requested Command Event
            OnDataRequested(new CommandEventArgs(commandWrapper, "Insert", entity));

            return Convert.ToBoolean(results);
        }
 public CategoriesController(Northwind db)
 {
     _db = db;
 }
        /// <summary>
        /// 	Update an existing row in the datasource.
        /// </summary>
        /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
        /// <param name="entity">Northwind.Entities.Categories object to update.</param>
        /// <remarks>
        ///		After updating the datasource, the Northwind.Entities.Categories object will be updated
        /// 	to refelect any changes made by the datasource. (ie: identity or computed columns)
        /// </remarks>
        /// <returns>Returns true if operation is successful.</returns>
        /// <exception cref="System.Exception">The command could not be executed.</exception>
        /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception>
        /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception>
        public override bool Update(TransactionManager transactionManager, Northwind.Entities.Categories entity)
        {
            SqlDatabase database = new SqlDatabase(this._connectionString);
            DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.sp_nt_Categories_Update", _useStoredProcedure);

            database.AddInParameter(commandWrapper, "@CategoryId", DbType.Int32, entity.CategoryId );
            database.AddInParameter(commandWrapper, "@CategoryName", DbType.String, entity.CategoryName );
            database.AddInParameter(commandWrapper, "@Description", DbType.String, entity.Description );
            database.AddInParameter(commandWrapper, "@Picture", DbType.Binary, entity.Picture );

            int results = 0;

            //Provider Data Requesting Command Event
            OnDataRequesting(new CommandEventArgs(commandWrapper, "Update", entity));

            if (transactionManager != null)
            {
                results = Utility.ExecuteNonQuery(transactionManager, commandWrapper);
            }
            else
            {
                results = Utility.ExecuteNonQuery(database,commandWrapper);
            }

            //Stop Tracking Now that it has been updated and persisted.
            if (DataRepository.Provider.EnableEntityTracking)
            {
                EntityManager.StopTracking(entity.EntityTrackingKey);
            }

            entity.AcceptChanges();

            //Provider Data Requested Command Event
            OnDataRequested(new CommandEventArgs(commandWrapper, "Update", entity));

            return Convert.ToBoolean(results);
        }
예제 #54
0
 public AddCustomerModel(Northwind AddContext)
 {
     db = AddContext;
 }
예제 #55
0
        private DbTransaction BeginTransaction(Northwind db)
        {
            db.Connection.Open();
            DbTransaction t = db.Connection.BeginTransaction();
            db.Transaction = t;

            return t;
        }
        protected async System.Threading.Tasks.Task Load()
        {
            var northwindGetRegionByRegionIdResult = await Northwind.GetRegionByRegionId(int.Parse($"{RegionID}"));

            region = northwindGetRegionByRegionIdResult;
        }
예제 #57
0
        protected async void Form0Submit(Shipper args)
        {
            var northwindCreateShipperResult = await Northwind.CreateShipper(shipper);

            DialogService.Close(shipper);
        }
예제 #58
0
    public void Destroy(IEnumerable<ProductViewModel> products)
    {
        using (var northwind = new Northwind())
        {
            //Iterate all destroyed products which are posted by the Kendo Grid
            foreach (var productViewModel in products)
            {
                var product = northwind.Products.FirstOrDefault(p => p.ProductID == productViewModel.ProductID);
                if (product != null)
                {
                    northwind.Products.DeleteObject(product);
                }

            }

            // Delete the products from the database
            northwind.SaveChanges();
        }
    }
        /// <summary>
        /// 	Update an existing row in the datasource.
        /// </summary>
        /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
        /// <param name="entity">Northwind.Entities.OrderDetails object to update.</param>
        /// <remarks>
        ///		After updating the datasource, the Northwind.Entities.OrderDetails object will be updated
        /// 	to refelect any changes made by the datasource. (ie: identity or computed columns)
        /// </remarks>
        /// <returns>Returns true if operation is successful.</returns>
        /// <exception cref="System.Exception">The command could not be executed.</exception>
        /// <exception cref="System.Data.DataException">The <paramref name="transactionManager"/> is not open.</exception>
        /// <exception cref="System.Data.Common.DbException">The command could not be executed.</exception>
        public override bool Update(TransactionManager transactionManager, Northwind.Entities.OrderDetails entity)
        {
            SqlDatabase database = new SqlDatabase(this._connectionString);
            DbCommand commandWrapper = StoredProcedureProvider.GetCommandWrapper(database, "dbo.sp_nt_OrderDetails_Update", _useStoredProcedure);

            database.AddInParameter(commandWrapper, "@OrderId", DbType.Int32, entity.OrderId );
            database.AddInParameter(commandWrapper, "@OriginalOrderId", DbType.Int32, entity.OriginalOrderId);
            database.AddInParameter(commandWrapper, "@ProductId", DbType.Int32, entity.ProductId );
            database.AddInParameter(commandWrapper, "@OriginalProductId", DbType.Int32, entity.OriginalProductId);
            database.AddInParameter(commandWrapper, "@UnitPrice", DbType.Currency, entity.UnitPrice );
            database.AddInParameter(commandWrapper, "@Quantity", DbType.Int16, entity.Quantity );
            database.AddInParameter(commandWrapper, "@Discount", DbType.Single, entity.Discount );

            int results = 0;

            //Provider Data Requesting Command Event
            OnDataRequesting(new CommandEventArgs(commandWrapper, "Update", entity));

            if (transactionManager != null)
            {
                results = Utility.ExecuteNonQuery(transactionManager, commandWrapper);
            }
            else
            {
                results = Utility.ExecuteNonQuery(database,commandWrapper);
            }

            //Stop Tracking Now that it has been updated and persisted.
            if (DataRepository.Provider.EnableEntityTracking)
            {
                EntityManager.StopTracking(entity.EntityTrackingKey);
            }

            entity.OriginalOrderId = entity.OrderId;
            entity.OriginalProductId = entity.ProductId;

            entity.AcceptChanges();

            //Provider Data Requested Command Event
            OnDataRequested(new CommandEventArgs(commandWrapper, "Update", entity));

            return Convert.ToBoolean(results);
        }
예제 #60
0
        protected async void Form0Submit(Category args)
        {
            var northwindUpdateCategoryResult = await Northwind.UpdateCategory(int.Parse(CategoryID), category);

            DialogService.Close(category);
        }