Web form inheritance help

G

Guest

I had a windows form project that had a functions module that could control
objects on the referenced main form. How would I do the same with a web
project using a web form? See my windows form example, and let me know what I
must do to get this to work on a web form.
Imports System.Data
Imports System.Data.OleDb
Imports CrystalDecisions.CrystalReports.Engine
Imports System.Windows.Forms

Module ProcessFunctions
Public loading As Boolean = True
Dim SQadapterTime As New SqlClient.SqlDataAdapter
Dim SQadapterPhase As New SqlClient.SqlDataAdapter
Dim SQadapterTask As New SqlClient.SqlDataAdapter
Dim SQadapterActivity As New SqlClient.SqlDataAdapter
Dim SQadapterCLient As New SqlClient.SqlDataAdapter
Dim SQadapterMatter As New SqlClient.SqlDataAdapter
Dim SQadApterGetTime As New SqlClient.SqlDataAdapter
Dim SQadApterGetParams As New SqlClient.SqlDataAdapter
Dim SQLTime As New SqlClient.SqlCommand
Dim SQLPhase As New SqlClient.SqlCommand
Dim SQLTask As New SqlClient.SqlCommand
Dim SQLActivity As New SqlClient.SqlCommand
Dim SQLClient As New SqlClient.SqlCommand
Dim SQLMatter As New SqlClient.SqlCommand
Dim SQLGetime As New SQLClient.SqlCommand
Dim SQLGetParams As New SQLClient.SqlCommand
'Dim dreader As SqlClient.SqlDataReader
Dim dtTime As New DataTable
Dim dtPhase As New DataTable
Dim dtTask As New DataTable
Dim dtActivity As New DataTable
Dim dtCLient As New DataTable
Dim dtMatter As New DataTable



Public Sub LoadAllFormData(ByVal MainF As FrmMain, ByVal DataLoadType As
Integer)

Dim objectDBConnect As New Exception("Unable to connect to SQL
server Rc0101.")
Select Case DataLoadType
Case 1
SQLTime.CommandText = "SELECT Timekeeper, EmpName FROM
V_LiTimekeeper UNION SELECT 'L0', '-ALL-' FROM V_LiTimekeeper ORDER BY
EmpName"
SQLPhase.CommandText = "SELECT PhaseCode, PhaseName,
PhaseCode + ' - ' + PhaseName AS PhaseComb FROM LitPhase order by phasename"
SQLTask.CommandText = "SELECT PhaseCode,TaskCode, TaskName,
TaskCode + ' - ' + TaskName AS TaskComb FROM LitTask UNION SELECT
'9999','L0','-All-', '-ALL-' FROM Littask ORDER BY taskName"
SQLActivity.CommandText = "SELECT activity_code,
activity_desc, activity_code + ' - ' + activity_desc AS ActDrp FROM
LitActivity UNION SELECT 'L0','-All-', '-ALL-' FROM Littask ORDER BY
activity_desc"
SQLClient.CommandText = "SELECT CLIENT_CODE, CLIENT_NAME,
CLIENT_NAME + ' - ' + CLIENT_CODE AS CLientDrp FROM LitClients ORDER BY
CLIENT_NAME"
SQLMatter.CommandText = "SELECT CLIENT_CODE, MATTER_CODE,
MATTER_NAME, MATTER_NAME + ' -' + MATTER_CODE AS MatterDrp FROM LitMatters
UNION SELECT '99','L0',' -ALL-',' -ALL-' FROM Littask ORDER BY MATTER_NAME"

SQLTime.Connection = LitDatabase
SQLPhase.Connection = LitDatabase
SQLTask.Connection = LitDatabase
SQLActivity.Connection = LitDatabase
SQLClient.Connection = LitDatabase
SQLMatter.Connection = LitDatabase

SQadapterTime.SelectCommand = SQLTime
SQadapterPhase.SelectCommand = SQLPhase
SQadapterTask.SelectCommand = SQLTask
SQadapterActivity.SelectCommand = SQLActivity
SQadapterCLient.SelectCommand = SQLClient
SQadapterMatter.SelectCommand = SQLMatter
Try
' Load Timekeeper Dropdowns
SQadapterTime.Fill(dtTime).ToString()
MainF.DrpTimekeeper().DataSource = dtTime
MainF.DrpTimekeeper().DisplayMember =
dtTime.Columns(1).ToString
MainF.DrpTimekeeper().ValueMember =
dtTime.Columns(0).ToString

' Load Phase Dropdowns
SQadapterPhase.Fill(dtPhase).ToString()
MainF.drpPhase().DataSource = dtPhase
MainF.drpPhase().DisplayMember =
dtPhase.Columns(2).ToString
MainF.drpPhase().ValueMember = dtPhase.Columns(0).ToString

' Load Task Dropdowns
SQadapterTask.Fill(dtTask).ToString()
dtTask.DefaultView.RowFilter = "PhaseCode = '" &
MainF.drpPhase().SelectedValue & "' OR TaskComb= '-All-'"
MainF.drpTask().DataSource = dtTask
MainF.drpTask.SelectedIndex = 0
MainF.drpTask.DisplayMember = dtTask.Columns(3).ToString
MainF.drpTask.ValueMember = dtTask.Columns(1).ToString

' Load Activity Dropdowns
SQadapterActivity.Fill(dtActivity).ToString()
MainF.drpActivity().DataSource = dtActivity
MainF.drpActivity().DisplayMember =
dtActivity.Columns(2).ToString
MainF.drpActivity().ValueMember =
dtActivity.Columns(0).ToString

' Load Client Dropdowns
SQadapterCLient.Fill(dtCLient).ToString()
MainF.drpClient.DataSource = dtCLient
MainF.drpClient.DisplayMember =
dtCLient.Columns(2).ToString
MainF.drpClient.ValueMember = dtCLient.Columns(0).ToString

' Load Matter Dropdowns
SQadapterMatter.Fill(dtMatter).ToString()
dtMatter.DefaultView.RowFilter = "Client_Code = '" &
MainF.drpClient.SelectedValue & "' OR MatterDrp= ' -All-'"
MainF.drpMatter().DataSource = dtMatter
MainF.drpMatter.SelectedIndex = 0
MainF.drpMatter.DisplayMember =
dtMatter.Columns(3).ToString
MainF.drpMatter.ValueMember = dtMatter.Columns(1).ToString
Catch objectDataFill As Exception
'Throw objectDBConnect

MsgBox(objectDataFill.Message)


End Try

loading = False

MainF.RDActivity.Checked = True



Case 2
If loading = False Then
dtTask.DefaultView.RowFilter = "PhaseCode = '" &
MainF.drpPhase().SelectedValue & "' OR TaskComb= '-All-'"
MainF.drpTask().DataSource = dtTask
MainF.drpTask.SelectedIndex = 0
MainF.drpTask.DisplayMember = dtTask.Columns(3).ToString
MainF.drpTask.ValueMember = dtTask.Columns(1).ToString

MainF.drpTask().Enabled = True
End If
Case 3
If loading = False Then

dtMatter.DefaultView.RowFilter = "Client_Code = '" &
MainF.drpClient.SelectedValue & "' OR MatterDrp= ' -All-'"
MainF.drpMatter().DataSource = dtMatter
MainF.drpMatter.SelectedIndex = 0
MainF.drpMatter.DisplayMember =
dtMatter.Columns(3).ToString
MainF.drpMatter.ValueMember = dtMatter.Columns(1).ToString

MainF.drpMatter().Enabled = True
End If
End Select
'
End Sub
 
J

John Saunders

Eric said:
I had a windows form project that had a functions module that could control
objects on the referenced main form. How would I do the same with a web
project using a web form? See my windows form example, and let me know what I
must do to get this to work on a web form.

First of all, the idea of having a module control things on a form is
questionable, at best. Surely the form is capable of managing itself? Unless
you've got more than one FrmMain form, it makes no sense at all for this
code to be separate from the form. The module would be used once, on a
single form, so why not make the form be the module?

I suggest that you take the data which was in the module and put it into the
web form as Private data. I suggest that you take the LoadAllFormData method
and also place it into the web form as a private method. Call that method in
Page_Load in the web form:

If Not Page.IsPostBack Then
LoadAllFormData()
End If
 
G

Guest

John, Thanks for not answering the question. I didnt ask if the form could
manage itself, did I ? without seeing the entire solution, how could you
arrive at the trite resolution with a simple " You shouldn't be doing this" ?
Answer the darn question, or don't reply at all. People like you waste
precious MSDN time, along with my own. Please STOP replying to problems with
more problems
 
J

John Saunders

Eric said:
John, Thanks for not answering the question. I didnt ask if the form could
manage itself, did I ? without seeing the entire solution, how could you
arrive at the trite resolution with a simple " You shouldn't be doing
this" ?

Experience. :)

1) The existence of a module is almost always a mistake due to an
over-literal translation of VB6 into VB.NET
2) The code in the module did nothing w hich the form could not do on its
own.
3) My guess that this used to be VB6 code suggested to me that there might
be only a single instance of FrmMain, in which case, I could think of no
reason for the code and data which are now in the module to not be in the
form instead.
4) It's a fairly serious violation of encapsulation to have the module
operate on the form. That's almost always a mistake.

Finally, if you're determined to make those mistakes, perhaps due to some
overriding reason which you did not share with us, then you should change
the accessibility of the properties and methods of the form to Public. They
will then be accessible by the module.
Answer the darn question, or don't reply at all. People like you waste
precious MSDN time, along with my own. Please STOP replying to problems with
more problems

I'm still unclear on why it would cause a problem for you to simply move the
code. Is the module used with more than one form called FrmMain?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top