|
The reason I was wanting to put those controls in the main window , is most people that i'm making this program for, only use 800 x 600 screen settings and opening a second child window takes up too much space inside the main window with my current program version. So figured if i put them on the back of the main window they'd always be visible if needed, and there when not needed. Thanks for your help, probably go with the visible property route, i had thought about that, but wasn't certain if this would be the best route.
|
|
|
|
|
Putting them on top of the Child windows would probably confuse them. Looking at other applications, the standard is to put controls that are used only once in a while onto a modal dialog form to get input like that. Just having a control pop up in the middle of their document would be confusing.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
The thing is I'm not wanting the controls to show through the child window.. If you were to create a mdi window and throw some controls on it, then have a child window open inside that mdi window. The controls that you put on the mdi window show through the Child window, as if the the controls are infront of the child window you just opened. I was trying to prevent this, easily, but taking your suggestion. I'm setting the visibilty property of the controls that are on the main window to false when a mdi child window opens, and setting them back to true when the child window closes.
|
|
|
|
|
Currently i am building a windows service.
1. How to make a windows service that its icon display on the task bar?
2. How to show a form when we click the icon?
3. I have problem when starting the windows service, if the service have a windows component such as notifyicon, timers etc. If i am using timers from windows component instead of system.timers.timers, the error "System.Reflection.TargetInvocationException" will come out when we start the service. Could the windows service use windows component?
4. does the "timers" is elapsed every time according to the interval or just elapse once for the first time when the timers is enabled?
Thanks...
Learning .NET
|
|
|
|
|
mythinky wrote:
1. How to make a windows service that its icon display on the task bar?
Your Service would have to include a Form that you can put a NotifyIcon component on. When you service is installed, you'll have to go into the Services Control Panel and tag your service and "Allow interaction with Desktop". Make sure your Form's ShowInTaskbar property is set to False and it's Style is set to Minimized.
mythinky wrote:
2. How to show a form when we click the icon?
In the, say, double-click event handler for the NotifyIcon component, just do Form1.Show(), or whatever you want to call your form.
mythinky wrote:
3. I have problem when starting the windows service, if the service have a windows component such as notifyicon, timers etc. If i am using timers from windows component instead of system.timers.timers, the error "System.Reflection.TargetInvocationException" will come out when we start the service. Could the windows service use windows component?
It can use Windows components, but you have to have a host form to put the components on AND tag your service as "Allow interaction with Desktop" in the Services Control Panel.
mythinky wrote:
4. does the "timers" is elapsed every time according to the interval or just elapse once for the first time when the timers is enabled?
When you Enable the timer, it will NOT fire the Elapsed event until the specified interval has elapsed first. It will continue to fire Elapsed events every Interval milliseconds, wheather your ready for them or not, until the timer is no longer enabled.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
It can use Windows components, but you have to have a host form to put the components on AND tag your service as "Allow interaction with Desktop" in the Services Control Panel.
What do you mean by the "Host Form"? How is the form being coded as a host form? Do we need to have another new project solution, or just having the form in the windows service solution?
Thanks a lot to you. You have helped me a lot in my assignment.
Learning .NET
|
|
|
|
|
mythinky wrote:
What do you mean by the "Host Form"?
This is merely the form that you drag and drop the NotifyIcon component on. You don't have to change the form to be a "host form" for a control. You don't need to have another solution, just add the Form to the Service Solution.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
As you say, we need it set the "Allow interaction with Desktop." for displaying windows form. I have tried it out.
It works fine and ok.
However, Can we set "Allow interaction with Desktop." automatically when we install the service?
|
|
|
|
|
No, using the VS Installer project, it has to be done after the service is installed.
It can be done using other installer packages, like Wise Package Studio.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
is the Wise Package Studio built in with VS.Net?
Learning .NET
|
|
|
|
|
Not on your life. Though it blows away Microsoft's anemic .MSI Installer project in Visual Studio .NET, Wise's version (Wise for Visual Studio .NET, completely integrated with the VS.NET IDE) will set you back a cool US $1,200. The lowest end product they have is US $450.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Helo, I have build a windows service that send email automatically.
Problem comes when we start the service, it will stop directly since it has nothing to do.
How can we start the service then it runs for long time, it shouldn't stop the service if have nothing to do, because i need to check every time.
I have attached the code for email windows service. Please review it.
Imports System.ComponentModel
Imports System.ServiceProcess
Imports System.Configuration.Install
Imports System.Data
Imports System.Data.OleDb
Imports System.DBNull
Imports System.Runtime.InteropServices
Imports System.Net
Public Class LibraryEmail
Inherits System.ServiceProcess.ServiceBase
Public Sub New()
MyBase.New()
' This call is required by the Component Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call
End Sub
Shared Sub Main()
Dim ServicesToRun() As System.ServiceProcess.ServiceBase
' More than one NT Service may run within the same process. To add
' another service to this process, change the following line to
' create a second service object. For example,
'
' ServicesToRun = New System.ServiceProcess.ServiceBase () {New UserService1, New MySecondUserService}
'
ServicesToRun = New System.ServiceProcess.ServiceBase() {New LibraryEmail()}
System.ServiceProcess.ServiceBase.Run(ServicesToRun)
End Sub
#Region " Component Designer generated code "
'Required by the Component Designer
Private components As System.ComponentModel.IContainer
' NOTE: The following procedure is required by the Component Designer
' It can be modified using the Component Designer.
' Do not modify it using the code editor.
Friend WithEvents Timer1 As System.Timers.Timer
'<system.diagnostics.debuggerstepthrough()>
Friend WithEvents ServiceController1 As System.ServiceProcess.ServiceController
Friend WithEvents Process1 As System.Diagnostics.Process
Friend WithEvents Timer2 As System.Timers.Timer
Private Sub InitializeComponent()
Me.Timer1 = New System.Timers.Timer()
Me.ServiceController1 = New System.ServiceProcess.ServiceController()
Me.Process1 = New System.Diagnostics.Process()
Me.Timer2 = New System.Timers.Timer()
CType(Me.Timer1, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.Timer2, System.ComponentModel.ISupportInitialize).BeginInit()
'
'Timer1
'
'
'Process1
'
'
'Timer2
'
Me.Timer2.Enabled = True
'
'LibraryEmail
'
Me.ServiceName = "LibraryEmail"
CType(Me.Timer1, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.Timer2, System.ComponentModel.ISupportInitialize).EndInit()
End Sub
#End Region
Public sConnectDBLib As String
Public sConnectDBSchool As String
Public sDBLib, sDBSch As String
Public objConnect As OleDbConnection
<dllimport("wininet.dll")> _
Public Shared Function InternetGetConnectedState(ByRef description As Integer, ByVal reservedValue As Integer) As Boolean
End Function
Public Shared Function IsConnectedToInternet() As Boolean
Dim desc As Integer
Return InternetGetConnectedState(desc, 0)
End Function
Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should set things
' in motion so your service can do its work.
Timer1.Enabled = True
Dim sServer, sUsername, sPassword As String
Dim bConnect As Boolean
Dim i As Integer
sServer = GetSetting("Library", "DBConn", "server", "")
sDBLib = GetSetting("Library", "DBConn", "dblib", "")
sUsername = GetSetting("Library", "DBConn", "username", "")
sPassword = GetSetting("Library", "DBConn", "password", "")
sConnectDBLib = "Provider=SQLOLEDB; Data Source = " & sServer & _
";Initial catalog=" & sDBLib & "; User ID=" & sUsername & _
"; Password=" & sPassword & ";"
For i = 1 To 3
If Not CheckConnection(sConnectDBLib) Then
MsgBox("Check the database setting first")
Else
bConnect = True
End If
If bConnect Then
objConnect = Nothing
Exit For
Else
If i <> 3 Then
MsgBox("Connection Failed! Please try again!")
Else
MsgBox("Connection Failed! Fail to run the program!")
End If
End If
Next i
End Sub
Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop your service.
End Sub
Function CheckConnection(ByVal sConnDBLib As String) As Boolean
Dim bConn As Boolean
Dim oConnDBLib As OleDbConnection = New OleDbConnection(sConnDBLib)
Try
oConnDBLib.Open()
bConn = True
Catch err As Exception
bConn = False
End Try
oConnDBLib = Nothing
Return bConn
End Function
Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
Dim objConLib As OleDb.OleDbConnection = New OleDb.OleDbConnection(sConnectDBLib)
Dim objDataAdp As OleDb.OleDbDataAdapter
Dim objDataSet As DataSet
' To see if the date has changed
'If DateDiff(DateInterval.Day, dteLastDate, Date.Now) > 0 Then
' MsgBox("Today is now yesterday")
'End If
' To see if it's a certain time
'If Date.Now.ToShortTimeString = "9:50 PM" Then
Dim Before, After As Integer
Dim DDay As Boolean
Before = Val(GetSetting("Library", "Setting", "Before", "3"))
After = Val(GetSetting("Library", "Setting", "After", "3"))
DDay = CBool(GetSetting("Library", "Setting", "DueDate", "1"))
Dim countBefore, countToday, countAfter As Integer
Dim countBeforeMsg, countTodayMsg, countAfterMsg As Integer
objDataAdp = New OleDb.OleDbDataAdapter()
Dim SMTPServer As String
objDataAdp.SelectCommand = New OleDbCommand("SELECT * FROM SETTING", objConLib)
objDataAdp.SelectCommand.CommandType = CommandType.Text
objDataAdp.Fill(objDataSet, "SMTP")
If objDataSet.Tables("SMTP").Rows.Count > 0 Then
SMTPServer = objDataSet.Tables("SMTP").Rows(0).ItemArray(2).ToString
Else
MsgBox("Message can't be send due to SMTP server name. Please check it first.")
Exit Sub
End If
'select all loan where 3 days before due date
objDataAdp.SelectCommand = New OleDb.OleDbCommand("SELECT M.EMAIL FROM MEMBER M LEFT JOIN " & _
"USERS A ON M.MEMBERID= A.ID LEFT JOIN LOANITEM LI ON LI.LOANID=M.LOANID WHERE " & _
"LI.DATERETURNED IS NULL AND LI.DUEDATE = '" & FormatDateTime(DateAdd(DateInterval.Day, Before, Now), DateFormat.ShortDate) & "'", objConLib)
objDataAdp.SelectCommand.CommandType = CommandType.Text
objDataSet = New DataSet()
objDataAdp.Fill(objDataSet, "BEFOREOVERDUEEMAIL")
countBefore = objDataSet.Tables("BEFOREOVERDUEEMAIL").Rows.Count
Dim toEmail, subject, body As String
Dim i As Integer
If countBefore = 0 Then
exit sub
Else
Try
For i = 0 To countBefore - 1
toEmail = objDataSet.Tables("BEFOREOVERDUEEMAIL").Rows(i).Item("Type").ToString & ";"
Next
Dim newEmail As System.Web.Mail.MailMessage
newEmail = New System.Web.Mail.MailMessage()
With newEmail
.To = toEmail
.From = "librarian@wefgroup.com"
.Subject = "helo"
.Body = "test"
End With
System.Web.Mail.SmtpMail.SmtpServer = SMTPServer
If IsConnectedToInternet() Then
Try
' Try and resolve the address of the mail server.
Dim hostEntry As IPHostEntry = Dns.GetHostByName(SMTPServer)
' If we get here, then the DNS Resolve worked and
'we must be connected to the 'Net.
Try
System.Web.Mail.SmtpMail.Send(newEmail)
MsgBox("Email sent!!!")
Catch ex As Exception
' Send message failed for some reason...
MsgBox(ex.InnerException.InnerException.Message)
End Try
Catch ex As Exception
' DNS Resolve failed. We can't send the message...
MsgBox("Message can't be send due to SMTP server. Please check it first.")
End Try
Else
MsgBox("Please check the internet connection")
End If
Catch exc As Exception
MsgBox(exc.Message)
End Try
end if
End Class
<runinstallerattribute(true)> _
Public Class ProjectInstaller
Inherits Installer
Private serviceInstaller As serviceInstaller
Private processInstaller As ServiceProcessInstaller
Private otherServiceInstaller As serviceInstaller
Sub New()
processInstaller = New ServiceProcessInstaller()
serviceInstaller = New ServiceInstaller()
processInstaller.Account = ServiceAccount.LocalSystem
serviceInstaller.StartType = ServiceStartMode.Automatic
serviceInstaller.ServiceName = "LibraryEmail"
Installers.Add(serviceInstaller)
Installers.Add(processInstaller)
End Sub
End Class
Learning .NET
|
|
|
|
|
It looks like you only running this code once a day. This is not a good candidate for a service. This should have been written as a normal Windows app and run as a Scheduled Task. This will prevent your app from consuming system resources all day and not doing anything with them.
Anyway...
There are lots of problems with your code, but I'll just cover a few for now...
mythinky wrote:
Public Shared Function InternetGetConnectedState(ByRef description As Integer, ByVal reservedValue As Integer) As Boolean
End Function
Public Shared Function IsConnectedToInternet() As Boolean
Dim desc As Integer
Return InternetGetConnectedState(desc, 0)
End Function
This will always return False because your InternetGetConnectedState function doesn't have any code in it.
Drop your CheckConnection code. You don't need it. Instead rewrite it as GetDatabaseConnection. This function should accept the Server, DBLib, Username and Password as parameters, build its own connection string, then try and get a connection to the database. If the connection succeeds, return the SqlConnection object, else do nothing. The Exception will pop up the call stack and get handled in the Elapsed Try/Catch block.
Opening a connection and keeping it open for the duration of your app is a really bad idea. This will keep an expensive licensed connection open on the SQL server not release it. You should get a connection to the server as late as possible and release it as early as possible in your code. Don't hog server resources by keeping a connection open.
You have two timers in your app, only one of which you are using. Remove all Timer code and references.
Don't start your timers until all of your initalization is done. This means don't put Timer1.Enable at the start of your OnStart code, put it at the end.
Also, in your OnStart code, forget checking your database connection. You don't need it. When your Timer Elapsed code runs, your sequence should be something like this:
Disable the Timer. (Yes, you heard me right!)
Check to see if it's time to go to work
If not, Exit Sub
Get the app settings.
Try
Get a connection to the database, passing the settings we got.
Get the information we need from the SQL Server.
Do we need to do anything with the data.
No, report this to the EventLog.
Else
Try
Do our processing on the EMail message.
Report to the EventLog what we did.
End Try
End If
Catch
Report any errors to the Event Log.
Finally
Make sure our connection object is closed and disposed.
End Try
Re-enable the Timer.
Why is the timer being disabled at the beginning of the Elapsed event code? Because this will prevent the Timer from firing another Elapsed event in case we're still in the middle of handling the last Elapsed event. When were done handling the event, re-enable the timer.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
<dllimport wininit.dll="">
Public Shared Function InternetGetConnectedState(ByRef description As Integer, ByVal reservedValue As Integer) As Boolean
End Function
Does the InternetGetConnectedState do anything once i import the dll library? I am not sure about the name of the dll that i've imported.
------------------------------------------
How to highlight the message become to a specific color displayed in the forum? Sometimes I want to quote, i just copy it, then just post it
Disable the Timer. (Yes, you heard me right!)
Check to see if it's time to go to work
If not, Exit Sub
Get the app settings.
"What does the get application settings means? What is it used for?"
Try
Get a connection to the database, passing the settings we got.
Get the information we need from the SQL Server.
Do we need to do anything with the data.
No, report this to the EventLog.
Else
Try
Do our processing on the EMail message.
Report to the EventLog what we did.
End Try
End If
Catch
Report any errors to the Event Log.
Finally
Make sure our connection object is closed and disposed.
End Try
Re-enable the Timer.
Thanks
Learning .NET
|
|
|
|
|
DllImport wininit.dll
'The code are put before the "InternetGetConnectedState"
function.
I put the code in between "< >", thus it appears nothing in the forum.
Learning .NET
|
|
|
|
|
The function your using has nothing to do with determining the connection state of the Internet. Go figure... It's actually a refleciton of the connection type state of Internet Explorer. And the .DLL import is "wininet.dll"... Your function declaration should look like this:
Declare Function InternetGetConnectedState Lib "wininet.dll" _
(ByRef lpdwDlags As Integer, ByVal dwReserved) As Integer
Then, when you want to call the function, you use this:
Dim returnValue As Integer = 0
Dim igcsFlags As Integer = 0
returnValue = InternetGetConnectedState( igcsFlags, 0 ) ' 2nd parameter MUST be 0!
BTW: When you post something using the < and > symbols, replaced them with
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
mythinky wrote:
Does the InternetGetConnectedState do anything once i import the dll library? I am not sure about the name of the dll that i've imported.
Not unless you call it properly. And it your code, I don't think you did.
mythinky wrote:
Get the app settings.
"What does the get application settings means? What is it used for?"
I don't know...you wrote the code!
sServer = GetSetting("Library", "DBConn", "server", "")
sDBLib = GetSetting("Library", "DBConn", "dblib", "")
sUsername = GetSetting("Library", "DBConn", "username", "")
sPassword = GetSetting("Library", "DBConn", "password", "")
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi,
I have a ASP.NET web application project. When I try saving it, The Save File As dialog box appears and it gives me 3 saving format options:
Save as type:
Text Solution File (*.sln)
UTF-8 Solution File (*.sln)
Unicode Solution File (*.sln)
|
|
|
|
|
Oops, sorry. Here's the question:
What are the differences amongst the 3 options? Which format should I save my project/solution in?
I'm quite new to ASP.NET web apps. Any help is appreciated. Thanks!
|*Ooraclec*|
|
|
|
|
|
For an English project, it really doesn't matter. By default, your project will be saved with UTF-8 Encoding. If you were making a website that used 16-bit (or larger) character, like Hebrew, Chinese, Arabic, or Japanese, then your would use the Unicode or UTF-16 Encoding.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I am running one application and i want when user minimize that package the icon should appear in system tray and when user bouble click that icon in system tray the package will maximized.
How i can do that? Can any body gime some tips.
|
|
|
|
|
You have to include a NotifyIcon in your application. See this[^] for the docs on the component class.
You'll also have to change the Form's ShowInTaskbar property to False. When the user Minimizes the Form, your NotifyIcon will be the only way the user can restore the form.
You'll then have to handle the NotifyIcon's DoubleClick event and set the Form's WindowState to FormWindowState.Normal and then Show() the Form.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Is there any way to select Root element?
VB6
|
|
|
|
|
Define "Root element". You can have multiple root TreeNodes in the Nodes collection, any of which are selectable. Can you be a bit more specific about what your trying to accomplish?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
just like "root element" in xml
|
|
|
|
|