TableDataSource.DesignExt.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using FastReport.Forms;
  2. using System;
  3. using System.Reflection;
  4. using System.Windows.Forms;
  5. namespace FastReport.Data
  6. {
  7. partial class TableDataSource : IHasEditor
  8. {
  9. #region Public Methods
  10. /// <inheritdoc/>
  11. public bool InvokeEditor()
  12. {
  13. using (QueryWizardForm form = new QueryWizardForm(this))
  14. {
  15. return form.ShowDialog() == DialogResult.OK;
  16. }
  17. }
  18. #endregion Public Methods
  19. #region Private Methods
  20. private void TryToLoadData()
  21. {
  22. // we are in the VS design mode, so dataset is empty. To fill it with real data, try to
  23. // find the table adapter, instantiate it and invoke its Fill method.
  24. if (Report != null && (Report.IsVSDesignMode || Report.AutoFillDataSet) &&
  25. Table != null && Table.Rows.Count == 0)
  26. {
  27. string tableAdapterName = Table.GetType().Name;
  28. if (tableAdapterName.EndsWith("DataTable"))
  29. tableAdapterName = tableAdapterName.Substring(0, tableAdapterName.Length - 9);
  30. tableAdapterName += "TableAdapter";
  31. Assembly dataAssembly = Table.GetType().Assembly;
  32. foreach (Type type in dataAssembly.GetTypes())
  33. {
  34. if (type.Name == tableAdapterName)
  35. {
  36. object tableAdapter = Activator.CreateInstance(type);
  37. try
  38. {
  39. MethodInfo fillMethod = tableAdapter.GetType().GetMethod("Fill");
  40. if (fillMethod != null)
  41. fillMethod.Invoke(tableAdapter, new object[] { Table });
  42. }
  43. catch
  44. {
  45. }
  46. finally
  47. {
  48. if (tableAdapter is IDisposable)
  49. (tableAdapter as IDisposable).Dispose();
  50. }
  51. break;
  52. }
  53. }
  54. }
  55. }
  56. #endregion Private Methods
  57. }
  58. }