Skip to content

Commit

Permalink
Merge pull request #2750 from dannyparsons/climsoft
Browse files Browse the repository at this point in the history
work on import from climsoft dialog
  • Loading branch information
dannyparsons authored Mar 6, 2017
2 parents b4c8715 + 8fd54e4 commit 6eb66fb
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 2 deletions.
38 changes: 36 additions & 2 deletions instat/dlgClimSoft.vb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,18 @@
' You should have received a copy of the GNU General Public License k
' along with this program. If not, see <http://www.gnu.org/licenses/>.

Imports instat
Imports instat.Translations
Public Class dlgClimSoft
Private bFirstLoad As Boolean = True
Private bReset As Boolean = True
Private clsRDatabaseConnect As New RFunction
Public bConnectionActive As Boolean = False
Private clsRDatabaseDisconnect As New RFunction
Private clsRImportFromClimsoft As New RFunction
Private clsHasConnection As New RFunction
Private bResetSubdialog As Boolean = False

Private Sub dlgClimSoft_Load(sender As Object, e As EventArgs) Handles MyBase.Load
autoTranslate(Me)
If bFirstLoad Then
Expand All @@ -32,9 +40,14 @@ Public Class dlgClimSoft
End Sub
Private Sub InitialiseDialog()
ucrBase.iHelpTopicID = 329

ucrReceiverMultipleStations.Selector = ucrSelectorForClimSoft
ucrReceiverMultipleStations.SetItemType("database_variables")
ucrReceiverMultipleStations.strDatabaseQuery = "SELECT stationId FROM station;"

ucrReceiverMultipleElements.Selector = ucrSelectorForClimSoft
ucrReceiverMultipleStations.SetMeAsReceiver()
ucrReceiverMultipleElements.SetItemType("database_variables")
ucrReceiverMultipleElements.strDatabaseQuery = "SELECT obselement.elementName FROM obselement,observationfinal WHERE obselement.elementId=observationfinal.describedBy AND observationfinal.recordedFrom in (10202200,10306100) GROUP BY observationfinal.describedBy;"
ucrChkObservationData.SetText("Observation Data")
End Sub

Expand All @@ -43,15 +56,36 @@ Public Class dlgClimSoft
End Sub

Private Sub SetDefaults()
TestOKEnabled()
ucrSelectorForClimSoft.Reset()
ucrReceiverMultipleStations.SetMeAsReceiver()

clsRDatabaseConnect.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$database_connect")
clsRDatabaseDisconnect.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$database_disconnect")
clsRImportFromClimsoft.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$import_from_climsoft")
clsHasConnection.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$has_database_connection")
TestOKEnabled()
End Sub

Private Sub cmdEstablishConnection_Click(sender As Object, e As EventArgs) Handles cmdEstablishConnection.Click
sdgImportFromClimSoft.SetRDatabaseConnection(clsRDatabaseConnect, clsRDatabaseDisconnect, clsHasConnection, bConnectionActive, bResetSubdialog)
bResetSubdialog = False
sdgImportFromClimSoft.ShowDialog()
SetConnectionActiveStatus(sdgImportFromClimSoft.GetConnectionActiveStatus())
End Sub

Private Sub SetConnectionActiveStatus(bCurrentStatus As Boolean)
bConnectionActive = bCurrentStatus
End Sub

Private Sub ucrBase_ClickReset(sender As Object, e As EventArgs) Handles ucrBase.ClickReset
SetDefaults()
End Sub

Private Sub ucrReceiverMultipleStations_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrReceiverMultipleStations.ControlValueChanged
If ucrReceiverMultipleStations.IsEmpty Then
ucrReceiverMultipleElements.strDatabaseQuery = "SELECT obselement.elementName FROM obselement,observationfinal WHERE obselement.elementId=observationfinal.describedBy GROUP BY observationfinal.describedBy;"
Else
ucrReceiverMultipleElements.strDatabaseQuery = "SELECT obselement.elementName FROM obselement,observationfinal WHERE obselement.elementId=observationfinal.describedBy AND observationfinal.recordedFrom IN (" & String.Join(",", ucrReceiverMultipleStations.GetVariableNamesList) & ") GROUP BY observationfinal.describedBy;"
End If
End Sub
End Class
58 changes: 58 additions & 0 deletions instat/sdgImportFromClimSoft.vb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,64 @@
' along with this program. If not, see <http://www.gnu.org/licenses/>.

Imports instat.Translations
Imports RDotNet

Public Class sdgImportFromClimSoft
Private clsRDatabaseConnect As RFunction
Private clsRDatabaseDisconnect As RFunction
Private clsHasConnection As New RFunction
Private bControlsInitialised As Boolean = False
Private bConnected As Boolean = False
Private strConnected As String = "Connected"
Private strNoConnection As String = "No Connection"

Private Sub sdgImportFromClimSoft_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If Not bControlsInitialised Then
InitialiseControls()
End If
End Sub

Private Sub InitialiseControls()
ucrInputDatabaseName.SetParameter(New RParameter("dbname"))
ucrInputHost.SetParameter(New RParameter("host"))
ucrInputPart.SetParameter(New RParameter("port"))
ucrInputUserName.SetParameter(New RParameter("user"))

bControlsInitialised = True
End Sub

Public Function GetConnectionActiveStatus() As Boolean
Return bConnected
End Function

Public Sub SetRDatabaseConnection(clsNewRDatabaseConnect As RFunction, clsNewRDatabaseDisconnect As RFunction, clsNewHasConnection As RFunction, Optional bConnectionActive As Boolean = False, Optional bResetSubdialog As Boolean = False)
clsRDatabaseConnect = clsNewRDatabaseConnect
clsRDatabaseDisconnect = clsNewRDatabaseDisconnect
clsHasConnection = clsNewHasConnection
If Not bControlsInitialised Then
InitialiseControls()
End If
SetRCode(Me, clsRDatabaseConnect, bResetSubdialog)
End Sub

Private Sub cmdEnterPassword_Click(sender As Object, e As EventArgs) Handles cmdEnterPassword.Click
Dim expTemp As SymbolicExpression

If bConnected Then
frmMain.clsRLink.RunScript(clsRDatabaseDisconnect.ToScript(), strComment:="Disconnect database connection.")
End If
frmMain.clsRLink.RunScript(clsRDatabaseConnect.ToScript(), strComment:="Connect database connection.")

expTemp = frmMain.clsRLink.RunInternalScriptGetValue(clsHasConnection.ToScript())
If Not expTemp.Type = Internals.SymbolicExpressionType.Null Then
bConnected = expTemp.AsLogical(0)
Else
bConnected = False
End If
If bConnected Then
lblConnection.Text = strConnected
Else
lblConnection.Text = strNoConnection
End If
End Sub
End Class
5 changes: 5 additions & 0 deletions instat/static/InstatObject/R/instat_object_R6.R
Original file line number Diff line number Diff line change
Expand Up @@ -1249,5 +1249,10 @@ instat_object$set("public", "database_disconnect", function() {
dbDisconnect(private$.database_connection)
self$set_database_connection(NULL)
}
}
)

instat_object$set("public", "import_from_climsoft", function(stations = c(), elements = c(), include_observation_data = FALSE, start_date, end_date) {

}
)

0 comments on commit 6eb66fb

Please sign in to comment.