public OrdersForm(string CustID) { // // Required for Windows Form Designer support // InitializeComponent(); _CustID = CustID; // create an instance of the orders Web Service // and fetch the data OrdersService.RemotingOrders wsOrders = new OrdersService.RemotingOrders(); _dsOrders = wsOrders.Orders(CustID); _dsLookups = wsOrders.Lookups(); BindData(); // set some default values for new rows _dsOrders.Tables["Orders"].Columns["CustomerID"].DefaultValue = _CustID; _dsOrders.Tables["Orders"].Columns["ShipVia"].DefaultValue = _dsLookups.Tables["Shippers"].Rows[0]["ShipperID"]; // set the position for the first row // this ensures that the buttons/textboxes are enabled or disabled according to the data OrdersRowPosition_Changed(this.BindingContext[_dsOrders, "Orders"], (EventArgs)null); }
// the errors form has been closed so refresh the data void ErrorFormClosed(Object sender, EventArgs e) { OrdersService.RemotingOrders wsOrders = new OrdersService.RemotingOrders(); DataSet dsOrders = wsOrders.Orders(_CustID); _dsOrders.Merge(dsOrders, false); _dsOrders.AcceptChanges(); }
//process all of the updates private void btnUpdate_Click(object sender, System.EventArgs e) { OrdersService.RemotingOrders OrdersService; // Stop any current edits. this.BindingContext[_dsOrders, "Orders"].EndCurrentEdit(); this.BindingContext[_dsOrders, "Orders.CustOrders"].EndCurrentEdit(); // Check to see if any changes have been made. if (_dsOrders.HasChanges()) { DataSet dsUpdate; DataSet dsChanges; // Clear all old errors in the Customers table before // we attempt to save ClearAllErrors(); // Get the changes that have been made to the main dataset. dsChanges = _dsOrders.GetChanges(); if (dsChanges != null) { // update the data source OrdersService = new OrdersService.RemotingOrders(); dsUpdate = OrdersService.UpdateOrders(_CustID, dsChanges); // clear the current data // it will be reloaded with the full data returned from the web service _dsOrders.Clear(); // merge the changed rows back into the original data _dsOrders.Merge(dsUpdate, false); // If there are errors show the error form if (_dsOrders.HasErrors) { ErrorsForm f = new ErrorsForm(_CustID, dsUpdate, _dsLookups); this.AddOwnedForm(f); f.Show(); // add a handler so that we know when the error form has been closed f.Closed += new EventHandler(ErrorFormClosed); } else { // no errors, so just accept the changes _dsOrders.AcceptChanges(); } } } }