|
You're welcome
I are Troll
|
|
|
|
|
Hope you guys can help, because I'm stumped on this one. Okay, so I have a VB.NET 2008 program I'm writing, I'm trying to load some PHP reports in a WebBrowser control. On one form there is a WB control and the different buttons for different reports, two of them have to be able to be filtered by date, user, etc., so on those another form opens up with those options. All of this works fine, the options set variables for use in the url to the report, but when I try to navigate to the the report's url, the WB control does nothing.
I figure I need to reference the open instance of the child form with the browser on it, but I haven't been able to find how to do that.
Anything you guys can help me with would be appreciated. Thanks!
|
|
|
|
|
You can access all the open forms in your application via the My.Application.OpenForms methods.
Expose a public method on one form and pass a variable across from the other form e.g. To pass a value to Form1 from Form2
Form1.SomeMethod(SomeVariable)
Then in the SomeMethod on Form1 build the new browser url and navigate to it.
|
|
|
|
|
don't know why, but I can't seem to get a value to pass across.
Public Function GetURL(ByVal report As String)<br />
Return report<br />
End Function
It just returns Null no matter what I put into it. Don't think I'm doing anything wrong but I might be, help me out please.
|
|
|
|
|
OmegaMaximum wrote:
Public Function GetURL(ByVal report As String)
Return report
End Function
aren't you missing the return type in your function header, example
Public Function GetURL(ByVal report As String) As String
Return report
End Function
|
|
|
|
|
Thanks for pointing that out, but it still won't work. After some testing with message boxes, I've found that it just seems to stop after the Return line. No matter what I put after the Return is ignored.
|
|
|
|
|
it will, the Return effectively steps out of the function as if to say, "i've done everything i need to do, now return to the caller"
|
|
|
|
|
Thanks for all your help guys, I got it to properly reference the opened instance of the form with this,
Dim f1 As frmMain_A_C = CType(My.Application.OpenForms("frmMain_A_C"), frmMain_A_C)
Thanks again for all the help!
|
|
|
|
|
Hi,
The default scrollbar of windows seems to be to narrow for the ListView i'm developing for the application, this is why i have created a custom ScrollBar. The question is how do i attach the scrollbar to the listview that when scrolled the listview will scroll.
Please advice.
Thanks
|
|
|
|
|
Why does it seem too narrow? it will be standard across the OS, if you try and change one scrollbar in your application, it will then look different to everything else and just seem a bit odd.
I don't know how to do it without spending hours searching the docs and google etc. So hopefully someone more knowledgeable will respond, but one method would be to set up your scrollbar relative to the number of items in the listview, and then when you scroll, change the listview.topitem property to simulate a scroll. You would have to monitor the listview changes also, as well as what to do if the user uses arrow up and down while listview has focus.
Seems way to much effort for something that you should not need to think about. i.e. leave the original scrollbars as is.
modified on Sunday, January 24, 2010 3:27 PM
|
|
|
|
|
Eli Nurman wrote: The default scrollbar of windows seems to be to narrow for the ListView
That doesn't make sense to me. Most scrollbars look the same in Windows. For some sizes, see SystemInformation class, the HorizontalScrollBarXyz and VerticalScrollBarXyz properties.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that. [The QA section does it automatically now, I hope we soon get it on regular forums as well]
|
|
|
|
|
OK. the width is the same everywhere, but i need for this app specifically a wide scrollbar
|
|
|
|
|
Hello to All,
Actually i am Developing application with Vb.net and C#. And My Next operation is Developing those application to MAC OS Environment.
So Please Help me for How to Develop those applcation to MAC Environment.I have not any idea of MAC.
THANKS
If you can think then I Can.
|
|
|
|
|
|
Install Mono[^]
I are Troll
|
|
|
|
|
Thank you sir How to Work WIth MONO.
If you can think then I Can.
|
|
|
|
|
Download and install Mono from here. A basic introduction on running a C# application using Mono can be found here.
I are Troll
|
|
|
|
|
I'm modifying code that was written 9 years ago in VB.Net and JavaScript.
I revised the code to successfully write to Excel but the javascript controls are now in the Excel file.
I'm receiving error: Value of typ 'system.Reflection.PropertyInfo' cannot be converted to 'Boolean'.
Private Sub ClearControls(ByVal control As Control)
For i As Integer = control.Controls.Count - 1 To 0 Step -1
ClearControls(control.Controls(i))
Next
If Not (TypeOf control Is TableCell) Then
If control.[GetType]().GetProperty("SelectedItem") IsNot Nothing Then
Dim literal As New LiteralControl()
control.Parent.Controls.Add(literal)
Try
literal.Text = DirectCast(control.[GetType]().GetProperty("SelectedItem").GetValue(control, Nothing), String)
Catch
End Try
control.Parent.Controls.Remove(control)
ElseIf control.[GetType]().GetProperty("Text") IsNot Nothing Then
Dim literal As New LiteralControl()
control.Parent.Controls.Add(literal)
literal.Text = DirectCast(control.[GetType]().GetProperty("Text").GetValue(control, Nothing), String)
control.Parent.Controls.Remove(control)
End If
End If
Exit Sub
End Sub
|
|
|
|
|
I would use a different approach - you know the underlying data so why not convert it to a CSV and download the file?
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
The former programmer did all in code queries and did not use datasets or data adapters. I plan to re-write the code but for now, I have to correct errors.
do you think that removing the javascript is not possible?
|
|
|
|
|
technette wrote: do you think that removing the javascript is not possible?
Sorry, I'm a winforms dev so my ASP knowledge is limited so naturally I look for a non ASP solution.
How did he get the data from the database if he did not use the data collections? He must have used a collection of some sort. I would find that collection and work with that.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
In ASP.Net you can write SQL queries and use a data connection in code to connect to the database just by creating the connection in web.config then referencing the connection on the code behind page. The programmer has each page written with connections, if then statments that, based upon the query, print to a "select" page.
I spend hours trying to reference a collection that would export directly to excel to no avail.
|
|
|
|
|
Ok so you have the tools to do this
Connection can be accessed from the code behind, the select statement is in the gridview somewhere, take that out to the code behind. Use these two to get a datatable and set it as the datasource for the gridview and databind it. That should give you the same functionality as you currently have and you now have access to the datatable.
Note: I've never used the database => control binding so I'm not sure if it will work but I use the database => DAL => code behind => control style and that gives me complete control over my data, and therefore I do not have this issue.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
When I rewrite the code, I will be creating stored procedures for the various select statements because there are 13 pages of code that is written as javascript functions and vb code that display on a "select" page so the selection is not currently tied to the gridview.
The following code may appear to display in a gridview but this is not functioning in the actual program. Each query displays in another page "Select", which opens a separate window.
I will probable have to try programming in javascript using a remove element function of some type as opposed to html for now.
I was trying to do a temporary fix to buy more time while I re-design and re-write.
Sample code from one page...I cut out a lot.
Public Property DateSortDirection() As String
Get
Return ViewState("DateSortDirection")
End Get
Set(ByVal value As String)
ViewState("DateSortDirection") = value
End Set
End Property
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
Me.DateSortDirection = "ASC"
End If
ibtnVersion.Attributes.Add("onClick", "OpenUpdateDate();")
ibtnHelp.Attributes.Add("onClick", "OpenHelp();")
ibtnMap.Attributes.Add("onClick", "OpenJobWindow('Location');")
End Sub
Function PadQuotes(ByVal sTxt As Object)
Dim iX As Integer
iX = InStr(sTxt, "'")
Do While iX > 0
sTxt = Left$(sTxt, iX) & "'" & Right$(sTxt, Len(sTxt) - iX)
iX = iX + 2 ' get past inserted quotes
If Len(sTxt) < iX Then
iX = 0
Else
iX = InStr(iX, sTxt, "'")
End If
Loop
PadQuotes = sTxt
End Function
Function GetURL() As String
'CntrNoLst("[Contract].[Contract]")
Dim stringcntr As String = "2;3,5;7;"
Return "http://localhost/webapplication2/cntrprofilegen.aspx?page=cntrgen&id=" & stringcntr
End Function
Function CntrNoLst(ByVal sSortStr As String) As System.Data.SqlClient.SqlDataReader
'Dim connectionString As String = "server='PARSQL21'; user id='BusDev';password='psbd'; Database='hawk'"
'Dim sqlConnection As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(connectionString)
Dim sqlConnection As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim queryString As String
Dim sFrom As String
Dim sWhere As String
Dim sOrder As String
' queryString = "SELECT DISTINCT [Contract].[Contract], [Contract].[ContractDesc], [JobKeys].[ClientName], [JobKeys].[ProjMgrName], " & _
'"[Contract].[ContractValue], [Contract].[BeginDate], [Contract].[EndDate], " & _
'"[Entity].[EntityName] "
queryString = "SELECT DISTINCT Contract.Contract, Contract.ContractDesc, JobKeys.ClientName, " & _
"JobKeys.ProjMgrName, Contract.ContractValue, Contract.BeginDate, Contract.EndDate, Entity.EntityName"
sFrom = "FROM Contract INNER JOIN " & _
"JobKeys ON Contract.Contract = JobKeys.Contract INNER JOIN " & _
"Entity ON JobKeys.Entity = Entity.Entity INNER JOIN " & _
"Office ON JobKeys.Office = Office.Office "
sWhere = "WHERE 1=1"
'=================================
'sFrom = "FROM [Contract], [JobKeys], [Entity], [Office] "
'sWhere = "WHERE [Contract].[Contract]=[JobKeys].[Contract] AND [JobKeys].[Entity] = [Entity].[Entity] AND [JobKeys].[Office] = [Office].[Office] "
Dim iWhereLen As String = Len(sWhere)
sOrder = " ORDER by " & sSortStr
If Len(txtJob.Text) > 1 Then
sWhere = sWhere & " AND [JobKeys].[Job] in (" & CreateInStatement(PadQuotes(txtJob.Text)) & ") "
End If
If Len(txtProjectMgr.Text) > 1 Then
sWhere = sWhere & " and [JobKeys].[ProjMgrNum] in (" & CreateInStatement(PadQuotes(txtProjectMgr.Text)) & ") "
End If
If Len(lstCntrTerm.SelectedItem.Value) > 1 Then
sWhere = sWhere & " AND [JobKeys].[ContractTerms] in (" & CreateInStatement(lstCntrTerm.SelectedItem.Value) & ") "
End If
If Len(txtClient.Text) > 1 Then
sWhere = sWhere & " AND [JobKeys].[Client] in (" & CreateInStatement(PadQuotes(txtClient.Text)) & ") "
End If
If Len(txtClientName.Text) > 1 Then
sWhere = sWhere & " AND [JobKeys].[ClientName] in (" & CreateInStatement(PadQuotes(txtClientName.Text)) & ") "
End If
'If lstAllEntity.Enabled = False Then
If Len(lstEntity.SelectedItem.Value) > 1 Then
sWhere = sWhere & " AND [JobKeys].[Entity] in (" & CreateInStatement(lstEntity.SelectedItem.Value) & ") "
End If
'End If
'If lstEntity.Enabled = False Then
' If Len(lstAllEntity.SelectedItem.Value) > 1 Then
' sWhere = sWhere & " AND [JobKeys].[Entity] in (" & CreateInStatement(lstAllEntity.SelectedItem.Value) & ") "
' End If
'End If
If Len(txtProposal.Text) > 1 Then
sWhere = sWhere & " and [JobKeys].[Proposal] in (" & CreateInStatement(PadQuotes(txtProposal.Text)) & ") "
End If
If Len(txtContract.Text) > 1 Then
sWhere = sWhere & " and [JobKeys].[Contract] in (" & CreateInStatement(txtContract.Text) & ") "
End If
If Len(lstStatus.SelectedItem.Value) > 1 Or Len(lstBusArrang.SelectedItem.Value) > 1 Or Len(lstStand.SelectedItem.Value) > 1 Then
'sFrom = sFrom & ", [Contract] "
sWhere = sWhere & " and [Contract].[Contract] = [JobKeys].[Contract] "
If Len(lstStatus.SelectedItem.Value) > 1 Then
sWhere = sWhere & " AND [Contract].[Status] in (" & CreateInStatement(lstStatus.SelectedItem.Value) & ") "
End If
If Len(lstBusArrang.SelectedItem.Value) > 1 Then
sWhere = sWhere & " AND [Contract].[BusArrangement] in (" & CreateInStatement(lstBusArrang.SelectedItem.Value) & ") "
End If
If Len(lstStand.SelectedItem.Value) > 1 Then
sWhere = sWhere & " AND [Contract].[StdIndustry] in (" & CreateInStatement(lstStand.SelectedItem.Value) & ") "
End If
End If
'If lstAllOffice.Enabled = False Then
If Len(lstOffice.SelectedItem.Value) > 0 Then
sWhere = sWhere & " AND [JobKeys].[Office] in (" & CreateInStatement(lstOffice.SelectedItem.Text) & ") "
End If
'End If
'If lstOffice.Enabled = False Then
' If Len(lstAllOffice.SelectedItem.Value) > 0 Then
' sWhere = sWhere & " AND [JobKeys].[Office] in (" & CreateInStatement(lstAllOffice.SelectedItem.Text) & ") "
' End If
'End If
If Len(txtProjectID.Text) > 0 Then
sWhere = sWhere & " AND [JobKeys].[Project] in (" & CreateInStatement(PadQuotes(txtProjectID.Text)) & ") "
End If
If Len(txtCntrValue.Text) > 0 Then
sWhere = sWhere & " AND [Contract].[ContractValue] >= " & ConvertToDollars(PadQuotes(txtCntrValue.Text)) & " "
End If
If Len(lstScope.SelectedItem.Value) > 0 Then
sFrom = sFrom & ", [JobBDCodes] "
sWhere = sWhere & " AND [JobKeys].[Job] = [JobBDCodes].[Job] "
sWhere = sWhere & " AND [JobBDCodes].[BDCodeType] = 'ScopeSrvcs' AND [JobBDCodes].[BDCode] in "
'sWhere = sWhere & " ('" & CreateInStatement(lstScope.SelectedItem.Value) & "') "
sWhere = sWhere & " (" & CreateInStatement(lstScope.SelectedItem.Value) & ") "
End If
If Len(lstComMkt.SelectedItem.Value) > 0 Then
sFrom = sFrom & ", [JobBDCodes] "
sWhere = sWhere & " AND [JobKeys].[Job] = [JobBDCodes].[Job] "
sWhere = sWhere & " AND [JobBDCodes].[BDCodeType] = 'CoMrktg' AND [JobBDCodes].[BDCode] in"
'sWhere = sWhere & " ('" & CreateInStatement(lstComMkt.SelectedItem.Value) & "') "
sWhere = sWhere & " (" & CreateInStatement(lstComMkt.SelectedItem.Value) & ") "
End If
If Len(lstCorpMkt.SelectedItem.Value) > 0 Then
sFrom = sFrom & ", [JobBDCodes] "
sWhere = sWhere & " AND [JobKeys].[Job] = [JobBDCodes].[Job] "
sWhere = sWhere & " AND [JobBDCodes].[BDCodeType] = 'CorpMrktg' AND [JobBDCodes].[BDCode] in"
'sWhere = sWhere & " ('" & CreateInStatement(lstCorpMkt.SelectedItem.Value) & "') "
sWhere = sWhere & " (" & CreateInStatement(lstCorpMkt.SelectedItem.Value) & ") "
End If
If Len(lstSF254.SelectedItem.Value) > 0 Then
sFrom = sFrom & ", [JobBDCodes] "
sWhere = sWhere & " AND [JobKeys].[Job] = [JobBDCodes].[Job] "
sWhere = sWhere & " AND [JobBDCodes].BDCodeType = 'SF254' AND [JobBDCodes].BDCode in"
'sWhere = sWhere & " ('" & CreateInStatement(lstSF254.SelectedItem.Value) & "') "
sWhere = sWhere & " (" & CreateInStatement(lstSF254.SelectedItem.Value) & ") "
End If
'-------- Nel
If Len(txtSubcntr.Text) > 0 Then
'txtSubcntr = Replace(txtSubcntr.Text, "'", "''")
sFrom = sFrom & ", [JobSubcontractors], [Subcontractor] "
sWhere = sWhere & " AND [JobKeys].[Job] = [JobSubcontractors].[Job] "
'sWhere = sWhere & " AND JS.SubcontractorName in (" & CreateInStatement(txtSubcntr.Text) & ") "
sWhere = sWhere & " AND [JobSubcontractors].[SubcontractorName]=[Subcontractor].[SubcontractorName]" & _
"and [Subcontractor].[Subcontractor] in (" & CreateInStatement(PadQuotes(txtSubcntr.Text)) & ") "
End If
'-----------
If IsDate(txtCloseDate.Text) Then
sWhere = sWhere & " AND ([JobKeys].[ClosedDate] IS NULL or [JobKeys].[ClosedDate] >= '"
sWhere = sWhere & txtCloseDate.Text & "')"
End If
If iWhereLen = Len(sWhere) Then ' no criteria entered!
lblMsg.Text = "Selection criteria must be entered before initiating a search"
Else
lblMsg.Text = ""
queryString = queryString & " " & sFrom & " " & sWhere & "" & sOrder
Dim queryString2 As String
Dim queryString3 As String
'queryString3 = "INSERT INTO ContractNo (Contract, ContractDesc, ClientName, ProjMgrName, ContractValue, BeginDate, EndDate, EntityName) VALUES(3022, 'John', 'Smith', 2101,3022, 'John', 'Smith', 2101)"
'Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString3, sqlConnection)
Dim sqlCommand1 As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)
sqlConnection.Open()
Dim dataReader As System.Data.SqlClient.SqlDataReader = sqlCommand1.ExecuteReader(System.Data.ConnectionState.Executing)
Dim stringcntr As String
While dataReader.Read()
stringcntr &= dataReader("Contract").ToString() & ";"
End While
'lbl3.Text = stringcntr
End If
End Function
Public Function CreateInStatement(ByVal sData As String)
' This routine will take in a vanilla text string,
' and create an SQL 'in' statement
Dim iCnt As Integer
Dim iX As Integer
Dim sText As String
iCnt = InStr(sData, ",")
If iCnt = 0 Then
CreateInStatement = "'" & sData & "'"
Exit Function
End If
iX = 0
Do While iCnt > 0
sText = sText & "'" & Trim$(Mid$(sData, iX + 1, iCnt - iX - 1)) & "', "
iX = iCnt
iCnt = InStr(iX + 1, sData, ",")
Loop
' now append last key
sText = sText & "'" & Trim$(Right$(sData, Len(sData) - iX)) & "'"
CreateInStatement = sText
End Function
Public Function ConvertToDollars(ByVal sAmt As String)
' This routine will strip off any dollars signs, comma, etc.
Dim sHoldAmt As String
Dim sHoldTxt As String
Dim iCnt As Integer
For iCnt = 1 To Len(sAmt)
sHoldTxt = Mid$(sAmt, iCnt, 1)
If Val(sHoldTxt) > 0 Or sHoldTxt = "0" Or sHoldTxt = "." Then
sHoldAmt = sHoldAmt & sHoldTxt
End If
Next
ConvertToDollars = sHoldAmt
End Function
Function Qrysf254() As System.Data.SqlClient.SqlDataReader
'Dim connectionString As String = "server='PARSQL21'; user id='BusDev';password='psbd'; Database='hawk'"
'Dim sqlConnection As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(connectionString)
Dim sqlConnection As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim queryString As String = "Select distinct [BDCodeDesc], [BDCode] from [BDCodes] " & _
"where [BDCodeType] = 'SF254' ORDER BY [BDCodeDesc]"
Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)
sqlConnection.Open()
Dim dataReader As System.Data.SqlClient.SqlDataReader = sqlCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
Return dataReader
End Function
Function Qrystand() As System.Data.SqlClient.SqlDataReader
'Dim connectionString As String = "server='PARSQL21'; user id='BusDev';password='psbd'; Database='hawk'"
'Dim sqlConnection As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(connectionString)
Dim sqlConnection As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim queryString As String = "Select distinct [BDCodeDesc], [BDCode] from [BDCodes] " & _
"where [BDCodeType] = 'StdIndustr' ORDER BY [BDCodeDesc]"
Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)
sqlConnection.Open()
Dim dataReader As System.Data.SqlClient.SqlDataReader = sqlCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
Return dataReader
End Function
Function Qryscope() As System.Data.SqlClient.SqlDataReader
'Dim connectionString As String = "server='PARSQL21'; user id='BusDev';password='psbd'; Database='hawk'"
'Dim sqlConnection As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(connectionString)
Dim sqlConnection As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim queryString As String = "Select distinct [BDCodeDesc], [BDCode] from [BDCodes] " & _
"where [BDCodeType] = 'ScopeSrvcs' ORDER BY [BDCodeDesc]"
Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)
sqlConnection.Open()
Dim dataReader As System.Data.SqlClient.SqlDataReader = sqlCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
Return dataReader
End Function
Function Qrycommakt() As System.Data.SqlClient.SqlDataReader
'Dim connectionString As String = "server='PARSQL21'; user id='BusDev';password='psbd'; Database='hawk'"
'Dim sqlConnection As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(connectionString)
Dim sqlConnection As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim queryString As String = "SELECT [BDCode], [BDCodeDesc] FROM [BDCodes] " & _
"WHERE [BDCodeType] = 'CoMrktg' ORDER BY [BDCodeDesc] "
Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)
sqlConnection.Open()
Dim dataReader As System.Data.SqlClient.SqlDataReader = sqlCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
Return dataReader
End Function
Function Qrycorpmkt() As System.Data.SqlClient.SqlDataReader
'Dim connectionString As String = "server='PARSQL21'; user id='BusDev';password='psbd'; Database='hawk'"
'Dim sqlConnection As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(connectionString)
Dim sqlConnection As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim queryString As String = "SELECT [BDCode], [BDCodeDesc] FROM [BDCodes] " & _
"WHERE [BDCodeType] = 'CorpMrktg' ORDER BY [BDCodeDesc] "
Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)
sqlConnection.Open()
Dim dataReader As System.Data.SqlClient.SqlDataReader = sqlCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
Return dataReader
End Function
Function Qryoffice() As System.Data.SqlClient.SqlDataReader
'Dim connectionString As String = "server='PARSQL21'; user id='BusDev';password='psbd'; Database='hawk'"
'Dim sqlConnection As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(connectionString)
Dim sqlConnection As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim queryString As String = "Select DISTINCT [Office], [OfficeName] from [Office] " & _
" ORDER BY [OfficeName]"
Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)
sqlConnection.Open()
Dim dataReader As System.Data.SqlClient.SqlDataReader = sqlCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
Return dataReader
End Function
Function Qrycntrterm() As System.Data.SqlClient.SqlDataReader
Dim sqlConnection As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim queryString As String = "Select distinct [ContractTermsText], [ContractTerms] " & _
"from [ContractTerms] ORDER BY [ContractTermsText]"
Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)
sqlConnection.Open()
Dim dataReader As System.Data.SqlClient.SqlDataReader = sqlCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
Return dataReader
End Function
Function Qrystatus() As System.Data.SqlClient.SqlDataReader
Dim sqlConnection As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim queryString As String = "Select Distinct [Status] from [Contract] order by [Status]"
Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)
sqlConnection.Open()
Dim dataReader As System.Data.SqlClient.SqlDataReader = sqlCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
Return dataReader
End Function
Function Qrybusarrang() As System.Data.SqlClient.SqlDataReader
Dim sqlConnection As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim queryString As String = "SELECT [BDCodeDesc],[BDCode] FROM [BDCodes] " & _
"WHERE [BDCodeType] = 'BusArrange' ORDER BY [BDCodeDesc] "
Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)
sqlConnection.Open()
Dim dataReader As System.Data.SqlClient.SqlDataReader = sqlCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
Return dataReader
End Function
Function Qryentity() As System.Data.SqlClient.SqlDataReader
Dim sqlConnection As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim queryString As String = "Select DISTINCT [Entity], [EntityName] from [Entity] " & _
" ORDER BY [EntityName]"
Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)
sqlConnection.Open()
Dim dataReader As System.Data.SqlClient.SqlDataReader = sqlCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
Return dataReader
End Function
Function Qryemp(ByVal sSortStr As String) As System.Data.SqlClient.SqlDataReader
Dim sqlConnection As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim queryString As String
Dim sFrom As String
Dim sWhere As String
Dim sOrder As String
queryString = "SELECT DISTINCT Contract.Contract, Contract.ContractDesc, JobKeys.ClientName, JobKeys.ProjMgrName, " & _
"Contract.ContractValue, Contract.BeginDate, " & _
"Contract.EndDate, Entity.EntityName "
sFrom = "FROM Contract INNER JOIN JobKeys ON Contract.Contract = JobKeys.Contract " & _
"INNER JOIN Entity ON JobKeys.Entity = Entity.Entity " & _
"CROSS JOIN Office "
sWhere = "WHERE 1=1"
Dim iWhereLen As String = Len(sWhere)
sOrder = " ORDER by " & sSortStr
If Len(txtJob.Text) > 1 Then
sWhere = sWhere & " AND [JobKeys].[Job] in (" & CreateInStatement(PadQuotes(txtJob.Text)) & ") "
End If
If Len(txtProjectMgr.Text) > 1 Then
sWhere = sWhere & " and [JobKeys].[ProjMgrNum] in (" & CreateInStatement(PadQuotes(txtProjectMgr.Text)) & ") "
End If
If Len(lstCntrTerm.SelectedItem.Value) > 1 Then
sWhere = sWhere & " AND [JobKeys].[ContractTerms] in (" & CreateInStatement(lstCntrTerm.SelectedItem.Value) & ") "
End If
If Len(txtClient.Text) > 1 Then
sWhere = sWhere & " AND [JobKeys].[Client] in (" & CreateInStatement(PadQuotes(txtClient.Text)) & ") "
End If
If Len(txtClientName.Text) > 1 Then
sWhere = sWhere & " AND [JobKeys].[ClientName] in (" & CreateInStatement(PadQuotes(txtClientName.Text)) & ") "
End If
If Len(lstStatus.SelectedItem.Value) > 1 Or Len(lstBusArrang.SelectedItem.Value) > 1 Or Len(lstStand.SelectedItem.Value) > 1 Then
'sFrom = sFrom & ", [Contract] "
sWhere = sWhere & " and [Contract].[Contract] = [JobKeys].[Contract] "
If Len(lstStatus.SelectedItem.Value) > 1 Then
sWhere = sWhere & " AND [Contract].[Status] in (" & CreateInStatement(lstStatus.SelectedItem.Value) & ") "
End If
If Len(lstBusArrang.SelectedItem.Value) > 1 Then
sWhere = sWhere & " AND [Contract].[BusArrangement] in (" & CreateInStatement(lstBusArrang.SelectedItem.Value) & ") "
End If
If Len(lstStand.SelectedItem.Value) > 1 Then
sWhere = sWhere & " AND [Contract].[StdIndustry] in (" & CreateInStatement(lstStand.SelectedItem.Value) & ") "
End If
End If
If Len(lstOffice.SelectedItem.Value) > 0 Then
sWhere = sWhere & " AND [JobKeys].[Office] in (" & CreateInStatement(lstOffice.SelectedItem.Value) & ") "
End If
If Len(txtProjectID.Text) > 0 Then
sWhere = sWhere & " AND [JobKeys].[Project] in (" & CreateInStatement(PadQuotes(txtProjectID.Text)) & ") "
End If
If Len(txtCntrValue.Text) > 0 Then
sWhere = sWhere & " AND [Contract].[ContractValue] >= " & ConvertToDollars(PadQuotes(txtCntrValue.Text)) & " "
End If
If Len(lstScope.SelectedItem.Value) > 0 Then
sFrom = sFrom & ", [JobBDCodes] "
sWhere = sWhere & " AND [JobKeys].[Job] = [JobBDCodes].[Job] "
sWhere = sWhere & " AND [JobBDCodes].[BDCodeType] = 'ScopeSrvcs' AND [JobBDCodes].[BDCode] in "
'sWhere = sWhere & " ('" & CreateInStatement(lstScope.SelectedItem.Value) & "') "
sWhere = sWhere & " (" & CreateInStatement(lstScope.SelectedItem.Value) & ") "
End If
If Len(lstComMkt.SelectedItem.Value) > 0 Then
sFrom = sFrom & ", [JobBDCodes] "
sWhere = sWhere & " AND [JobKeys].[Job] = [JobBDCodes].[Job] "
sWhere = sWhere & " AND [JobBDCodes].[BDCodeType] = 'CoMrktg' AND [JobBDCodes].[BDCode] in"
'sWhere = sWhere & " ('" & CreateInStatement(lstComMkt.SelectedItem.Value) & "') "
sWhere = sWhere & " (" & CreateInStatement(lstComMkt.SelectedItem.Value) & ") "
End If
If Len(lstCorpMkt.SelectedItem.Value) > 0 Then
sFrom = sFrom & ", [JobBDCodes] "
sWhere = sWhere & " AND [JobKeys].[Job] = [JobBDCodes].[Job] "
sWhere = sWhere & " AND [JobBDCodes].[BDCodeType] = 'CorpMrktg' AND [JobBDCodes].[BDCode] in"
'sWhere = sWhere & " ('" & CreateInStatement(lstCorpMkt.SelectedItem.Value) & "') "
sWhere = sWhere & " (" & CreateInStatement(lstCorpMkt.SelectedItem.Value) & ") "
End If
If Len(lstSF254.SelectedItem.Value) > 0 Then
sFrom = sFrom & ", [JobBDCodes] "
sWhere = sWhere & " AND [JobKeys].[Job] = [JobBDCodes].[Job] "
sWhere = sWhere & " AND [JobBDCodes].BDCodeType = 'SF254' AND [JobBDCodes].BDCode in"
'sWhere = sWhere & " ('" & CreateInStatement(lstSF254.SelectedItem.Value) & "') "
sWhere = sWhere & " (" & CreateInStatement(lstSF254.SelectedItem.Value) & ") "
End If
If IsDate(txtCloseDate.Text) Then
sWhere = sWhere & " AND ([JobKeys].[ClosedDate] IS NULL or [JobKeys].[ClosedDate] >= '"
sWhere = sWhere & txtCloseDate.Text & "')"
End If
If iWhereLen = Len(sWhere) Then ' no criteria entered!
lblMsg.Text = "Selection criteria must be entered before initiating a search"
Else
lblMsg.Text = ""
queryString = queryString & " " & sFrom & " " & sWhere & "" & sOrder
Dim queryString2 As String
Dim queryString3 As String
'queryString3 = "INSERT INTO ContractNo (Contract, ContractDesc, ClientName, ProjMgrName, ContractValue, BeginDate, EndDate, EntityName) VALUES(3022, 'John', 'Smith', 2101,3022, 'John', 'Smith', 2101)"
'Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString3, sqlConnection)
Dim sqlCommand1 As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection)
sqlConnection.Open()
Dim dataReader As System.Data.SqlClient.SqlDataReader = sqlCommand1.ExecuteReader(System.Data.ConnectionState.Executing)
'While dataReader.Read()
'lbl3.Text &= dataReader("Contract").ToString() & ";"
'End While
Return dataReader
End If
End Function
Private Sub lstEntity_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstEntity.Init
lstEntity.DataSource = Qryentity()
lstEntity.DataBind()
lstEntity.Items.Insert(0, "")
lstEntity.SelectedIndex = 0
End Sub
'Private Sub lstAllEntity_Init(ByVal sender As System.Object, ByVal e As System.EventArgs)
' lstAllEntity.DataSource = QryAllentity()
' lstAllEntity.DataBind()
' lstAllEntity.Items.Insert(0, "")
' lstAllEntity.SelectedIndex = 0
'End Sub
Private Sub lstOffice_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstOffice.Init
lstOffice.DataSource = Qryoffice()
lstOffice.DataBind()
lstOffice.Items.Insert(0, "")
lstOffice.SelectedIndex = 0
End Sub
'Private Sub lstAllOffice_Init(ByVal sender As System.Object, ByVal e As System.EventArgs)
' lstAllOffice.DataSource = QryAlloffice()
' lstAllOffice.DataBind()
' lstOffice.Items.Insert(0, "")
' lstOffice.SelectedIndex = 0
'End Sub
Private Sub lstCntrTerm_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstCntrTerm.Init
lstCntrTerm.DataSource = Qrycntrterm()
lstCntrTerm.DataBind()
lstCntrTerm.Items.Insert(0, "")
lstCntrTerm.SelectedIndex = 0
End Sub
Private Sub lstStatus_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstStatus.Init
lstStatus.DataSource = Qrystatus()
lstStatus.DataBind()
lstStatus.Items.Insert(0, "")
lstStatus.SelectedIndex = 0
End Sub
Private Sub lstBusArrang_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstBusArrang.Init
lstBusArrang.DataSource = Qrybusarrang()
lstBusArrang.DataBind()
lstBusArrang.Items.Insert(0, "")
lstBusArrang.SelectedIndex = 0
End Sub
Private Sub lstStand_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstStand.Init
lstStand.DataSource = Qrystand()
lstStand.DataBind()
lstStand.Items.Insert(0, "")
lstStand.SelectedIndex = 0
End Sub
Private Sub lstScope_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstScope.Init
lstScope.DataSource = Qryscope()
lstScope.DataBind()
lstScope.Items.Insert(0, "")
lstScope.SelectedIndex = 0
End Sub
Private Sub lstComMkt_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstComMkt.Init
lstComMkt.DataSource = Qrycommakt()
lstComMkt.DataBind()
lstComMkt.Items.Insert(0, "")
lstComMkt.SelectedIndex = 0
End Sub
Private Sub lstCorpMkt_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstCorpMkt.Init
lstCorpMkt.DataSource = Qrycorpmkt()
lstCorpMkt.DataBind()
lstCorpMkt.Items.Insert(0, "")
lstCorpMkt.SelectedIndex = 0
End Sub
Private Sub lstSF254_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstSF254.Init
lstSF254.DataSource = Qrysf254()
lstSF254.DataBind()
lstSF254.Items.Insert(0, "")
lstSF254.SelectedIndex = 0
End Sub
Private Sub imgSearch_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgSearch.Click
gridContract.Visible = True
gridContract.DataSource = Qryemp("[Contract].[Contract]")
gridContract.DataBind()
CntrNoLst("[Contract].[Contract]")
lblrecordnum.Text = rsnum & " rows returned"
End Sub
Private Sub gridContract_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles gridContract.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
arrlstCntr.Add(CType(e.Item.DataItem, System.Data.Common.DbDataRecord).Item("Contract"))
'((System.Data.Common.DbDataRecord)e.Item.DataItem)["solution"].ToString();
rsnum = arrlstCntr.Count
End If
End Sub
Private Sub gridContract_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles gridContract.SortCommand
Dim NewSortExpr As String
Select Case e.SortExpression
Case "Contract"
If Me.DateSortDirection = "ASC" Then
NewSortExpr = "[Contract].[Contract] Desc"
Me.DateSortDirection = "DESC"
Else
NewSortExpr = "[Contract].[Contract] Asc"
Me.DateSortDirection = "ASC"
End If
Case "ContractDesc"
If Me.DateSortDirection = "ASC" Then
NewSortExpr = "[Contract].[ContractDesc] Desc"
Me.DateSortDirection = "DESC"
Else
NewSortExpr = "[Contract].[ContractDesc] Asc"
Me.DateSortDirection = "ASC"
End If
Case "ClientName"
If Me.DateSortDirection = "ASC" Then
NewSortExpr = "[JobKeys].[ClientName] Desc"
Me.DateSortDirection = "DESC"
Else
NewSortExpr = "[JobKeys].[ClientName] Asc"
Me.DateSortDirection = "ASC"
End If
Case "ProjMgrName"
If Me.DateSortDirection = "ASC" Then
NewSortExpr = "[JobKeys].[ProjMgrName] Desc"
Me.DateSortDirection = "DESC"
Else
NewSortExpr = "[JobKeys].[ProjMgrName] Asc"
Me.DateSortDirection = "ASC"
End If
Case "ContractValue"
If Me.DateSortDirection = "ASC" Then
NewSortExpr = "[Contract].[ContractValue] Desc"
Me.DateSortDirection = "DESC"
Else
NewSortExpr = "[Contract].[ContractValue] Asc"
Me.DateSortDirection = "ASC"
End If
Case "BeginDate"
If Me.DateSortDirection = "ASC" Then
NewSortExpr = "[Contract].[BeginDate] Desc"
Me.DateSortDirection = "DESC"
Else
NewSortExpr = "[Contract].[BeginDate] Asc"
Me.DateSortDirection = "ASC"
End If
Case "EndDate"
If Me.DateSortDirection = "ASC" Then
NewSortExpr = "[Contract].[EndDate] Desc"
Me.DateSortDirection = "DESC"
Else
NewSortExpr = "[Contract].[EndDate] Asc"
Me.DateSortDirection = "ASC"
End If
Case "EntityName"
If Me.DateSortDirection = "ASC" Then
NewSortExpr = "[Entity].[EntityName] Desc"
Me.DateSortDirection = "DESC"
Else
NewSortExpr = "[Entity].[EntityName] Asc"
Me.DateSortDirection = "ASC"
End If
End Select
gridContract.DataSource = Qryemp(NewSortExpr)
gridContract.DataBind()
End Sub
End Class
|
|
|
|
|
What I try to do is reading any existed row in the table 'Info' (normally only 1 row existed) then update that row immediately, but I have an error when execute at cmd2.ExecuteNonQuery()
- However, if I move the If room_N > 0 Then out of the While loop & place it under lrd.Close() then it works OK! Can some one know the reason?
Dim ra As Integer
Dim cmd As New SqlCommand
Dim cnt_del As Integer
Dim room_N As Integer
Dim str As String
con.ConnectionString = strOpen
con.Open()
cmd.Connection = con
cmd.CommandText = "SELECT * FROM Info"
Dim lrd As SqlDataReader = cmd.ExecuteReader()
If lrd.HasRows Then
Try
'Dim lwr As SqlDataReader
While lrd.Read()
ListBox1.Items.Clear()
str = lrd.GetValue(0).ToString() + ","
str = str + lrd.GetValue(1).ToString() + ","
str = str + lrd.GetValue(2).ToString() + ","
str = str + lrd.GetValue(3).ToString() + ","
str = str + lrd.GetValue(4).ToString() + ","
str = str + lrd.GetValue(5).ToString()+ ","
str = str + lrd.GetValue(6).ToString()
ListBox1.Items.Insert(cnt_del, str)
cnt_del = cnt_del + 1
ListBox_Available.Items.Clear()
room_N = SearchAvailableRooms(lrd.GetValue(2), lrd.GetValue(3), lrd.GetValue(4), lrd.GetValue(0), lrd.GetValue(1))
If room_N > 0 Then
cmd.CommandText = "UPDATE Reservations SET AvailRoomsRates = 'Trials'"
cmd.ExecuteNonQuery()
End If
End While
lrd.Close()
Catch ex As Exception
cnt_error = cnt_error + 1
TextBox_Error.Text = cnt_error.ToString()
End Try
End If
con.Close() 'Whether there is error or not. Close the connection.
|
|
|
|
|