private bool RebindUI(bool saveObject, bool rebind) { // disable events ProjectBindingSource.RaiseListChangedEvents = false; VendorsBindingSource.RaiseListChangedEvents = false; try { // unbind the UI UnbindBindingSource(VendorsBindingSource, saveObject, false); UnbindBindingSource(ProjectBindingSource, saveObject, true); VendorsBindingSource.DataSource = ProjectBindingSource; // save or cancel changes if (saveObject) { Project.ApplyEdit(); try { Project = Project.Save(); } catch (DataPortalException ex) { MessageBox.Show(ex.BusinessException.ToString(), "Error saving", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error Saving", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } } else { Project.CancelEdit(); } return(true); } finally { // rebind UI if requested if (rebind) { BindUI(); } // restore events ProjectBindingSource.RaiseListChangedEvents = true; VendorsBindingSource.RaiseListChangedEvents = true; if (rebind) { // refresh the UI if rebinding ProjectBindingSource.ResetBindings(false); VendorsBindingSource.ResetBindings(false); } } }
public override void btnAddNew_Click(object sender, EventArgs e)//新增 { try { VendorsBindingSource.AddNew(); } catch (Exception ex) { MessageBox.Show(ex.Message); } this.vendorsDataGridView.Refresh(); ReadOnly = false; setReadOnly(); }
public override void btnLast_Click(object sender, EventArgs e)//末筆 { VendorsBindingSource.MoveLast(); }
public override void btnNext_Click(object sender, EventArgs e)//次筆 { VendorsBindingSource.MoveNext(); }
public override void btnPrior_Click(object sender, EventArgs e)//前筆 { VendorsBindingSource.MovePrevious(); }
public override void btnSaveChange_Click(object sender, EventArgs e)//儲存 { VendorsBindingSource.EndEdit(); this.SSEntities.SaveChanges(); ResetVendorsData(); }
public override void btnCancelEdit_Click(object sender, EventArgs e)//取消 { VendorsBindingSource.CancelEdit(); ResetVendorsData(); }