public List <T> SearchObjects() { object searchTemplate = new T(); ObjectPropertyForm opf = new ObjectPropertyForm(searchTemplate, true); ArrayList parameters = new ArrayList(); string query = string.Empty; if (opf.ShowDialog() != DialogResult.OK) { return(null); } foreach (FieldEntry fe in opf.SearchParams) { string name = fe.FieldInfo.Name; FieldInfo fi = fe.FieldInfo; query += "[" + name + "]"; string op = " = "; if (fi.FieldType == typeof(string)) { op = " LIKE "; } query += op; query += "{" + parameters.Count + "}"; parameters.Add(fe.Value); } if (query == string.Empty) { query = null; } NDOQuery <T> ndoQuery = new NDOQuery <T>(pm, query, false); if (parameters.Count > 0) { foreach (object par in parameters) { ndoQuery.Parameters.Add(par); } } return(ndoQuery.Execute()); }
private void btnEdit_Click(object sender, EventArgs e) { object displayedObject = null; switch (this.tabControl1.SelectedTab.Text) { case "Customers": displayedObject = SelectedCustomer; break; case "Employees": displayedObject = SelectedEmployee; break; case "Orders": displayedObject = SelectedOrder; break; case "Order Details": displayedObject = SelectedOrderDetail; break; case "Products": displayedObject = SelectedProduct; break; } if (displayedObject != null) { // In a real world application it would make more sense to write specialized // Forms for creating and editing the different objects. In this forms you can // do things like showing the customer fotos or querying for related objects // as it is the case with the shipper of an order. ObjectPropertyForm opf = new ObjectPropertyForm(displayedObject, false); if (opf.ShowDialog() == DialogResult.OK) { pm.Save(); } } }
private void btnAdd_Click(object sender, EventArgs e) { try { object displayedObject = null; BindingSource list = null; switch (this.tabControl1.SelectedTab.Text) { case "Customers": displayedObject = new Customer(); this.pm.MakePersistent(displayedObject); list = customerBindingSource; break; case "Employees": displayedObject = new Employee(); this.pm.MakePersistent(displayedObject); list = employeeBindingSource; break; case "Orders": Customer c = SelectedCustomer; Employee emp = SelectedEmployee; if (c != null && emp != null) { Order o = c.NewOrder(); o.Employee = emp; o.OrderDate = DateTime.Now.Date; o.RequiredDate = DateTime.Now.Date + TimeSpan.FromDays(14); o.ShippedDate = DateTime.Now.Date; o.ShipName = c.CompanyName; o.ShipCity = c.City; o.ShipCountry = c.Country; o.ShipAddress = c.Address; o.Freight = 374m; o.Shipper = this.DefaultShipper; o.ShipPostalCode = c.PostalCode; o.ShipRegion = c.Region; displayedObject = o; list = orderBindingSource; } break; case "Order Details": OrderDetail od = new OrderDetail(); Product p = SelectedProduct; od.Product = p; od.Order = SelectedOrder; od.Quantity = 1; od.UnitPrice = p.UnitPrice; displayedObject = od; pm.MakePersistent(od); list = orderDetailBindingSource; break; case "Products": MessageBox.Show("Sorry, adding products is not implemented."); break; } if (displayedObject != null) { ObjectPropertyForm opf = new ObjectPropertyForm(displayedObject, false); if (opf.ShowDialog() == DialogResult.OK) { pm.Save(); list.Add(displayedObject); } else { pm.Abort(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); pm.Abort(); } }