Skip to content

Commit

Permalink
Require a single project when using the Export Strata feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexembrey committed Sep 11, 2020
1 parent bbfc84b commit 0a02941
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 29 deletions.
31 changes: 5 additions & 26 deletions src/ExportStrataForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ public List<int> GetSelectedStratumIds()
return Ids;
}

public void Initialize(Library library)
public void Initialize(Project project)
{
this.m_Library = library;
this.m_Project = this.GetActiveProject();
this.m_Project = project;
this.m_Library = project.Library;

this.LabelLibrary.Text = this.m_Library.Connection.ConnectionString;
this.LabelProject.Text = this.m_Project.Name;
Expand All @@ -83,8 +83,8 @@ public void Initialize(Library library)

private void EnableControls()
{
this.ButtonOK.Enabled = (this.m_Project != null && this.AnyStratumSelected());
this.ButtonBrowse.Enabled = (this.m_Project != null && this.DataGridViewMain.Rows.Count > 0);
this.ButtonOK.Enabled = (this.AnyStratumSelected());
this.ButtonBrowse.Enabled = (this.DataGridViewMain.Rows.Count > 0);
}

private void SaveLocation()
Expand All @@ -108,11 +108,6 @@ private void RestoreLocation()

private void FillStrataGrid()
{
if (this.m_Project == null)
{
return;
}

DataSheet ds = this.m_Project.GetDataSheet("stsim_Stratum");

if (ds == null)
Expand Down Expand Up @@ -147,22 +142,6 @@ private void FillStrataGrid()
this.DataGridViewMain.DataSource = this.m_StrataView;
}

private Project GetActiveProject()
{
if (this.m_Library.Session.ActiveProject == null)
{
Shared.ShowMessageBox(
"No projects found in specified library.",
MessageBoxButtons.OK);

return null;
}
else
{
return this.m_Library.Session.ActiveProject;
}
}

private bool AnyStratumSelected()
{
foreach (DataRow dr in this.m_Strata.Rows)
Expand Down
50 changes: 47 additions & 3 deletions src/SessionTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,63 @@ private void OnUpdateExportStrata(Command cmd)
}
}

private static Project GetProject(Library library)
{
if (library == null)
{
Debug.Assert(false);
return null;
}

int c = 0;
Project Proj = null;

foreach (Project p in library.Projects)
{
if (!p.IsDeleted)
{
if (Proj == null)
{
Proj = p;
}

c++;
}
}

if (c == 0)
{
Shared.ShowMessageBox(
"The Export Strata feature is only available for Libraries with at least one Project.",
MessageBoxButtons.OK);

return null;
}
else if (c > 1)
{
Shared.ShowMessageBox(
"The Export Strata feature is only available for Libraries with a single Project.",
MessageBoxButtons.OK);

return null;
}

return Proj;
}

private void OnExecuteExportStrata(Command cmd)
{
ExportStrataForm f = new ExportStrataForm();
WinFormSession wfs = (WinFormSession)this.Session;
Library lib = wfs.Application.GetSelectedLibrary();
Project Proj = GetProject(lib);

if (lib == null)
if (Proj == null)
{
Debug.Assert(false);
return;
}

f.Initialize(lib);
f.Initialize(Proj);

if (f.ShowDialog() != DialogResult.OK)
{
Expand Down

0 comments on commit 0a02941

Please sign in to comment.