PlausiblyDamp
Administrators-
Posts
7016 -
Joined
-
Last visited
Content Type
Profiles
Forums
Blogs
Events
Articles
Resources
Downloads
Gallery
Everything posted by PlausiblyDamp
-
Here's a safer version as it requests the other applications to close - this way any cleanup code (form_close etc) code will be executed. Public Function PrevInstance() As Boolean Dim ReturnValue As Boolean Dim apps() As System.Diagnostics.Process apps = Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess.ProcessName) If apps.Length > 1 Then Dim Message As String Message = "A previous instance of this program is currently running." Message &= " Do you want to end the other program?" If MessageBox.Show(Message, "Kill Prev App", MessageBoxButtons.YesNo) = DialogResult.Yes Then For Each p As Process In apps If p.Id <> Process.GetCurrentProcess.Id Then SendMessage(p.MainWindowHandle(), WM_CLOSE, UIntPtr.Zero, IntPtr.Zero) End If Next Else Return True End If End If Return False End Function
-
Something like Public Function PrevInstance() As Boolean Dim ReturnValue As Boolean Dim apps() As System.Diagnostics.Process apps = Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess.ProcessName) If apps.Length > 1 Then Dim Message As String Message = "A previous instance of this program is currently running." Message &= " Do you want to end the other program?" If MessageBox.Show(Message, "Kill Prev App", MessageBoxButtons.YesNo) = DialogResult.Yes Then For Each p As Process In apps If p.Id <> Process.GetCurrentProcess.Id Then p.Kill() end if Next Else Return True End If End If Return False End Function should do the trick - although be aware the .Kill method will terminate the application without giving the user the chance to save any work etc.
-
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebServicesWebMethodAttributeClassTransactionOptionTopic.asp
-
Drop all tables created after a certain date
PlausiblyDamp replied to foz's topic in Database / XML / Reporting
Whoops - my bad. Can't even cut and paste properly :) -
If you do as Nerseus suggested in his post above and create a new type of control then the form wouldn't care which was which - the normal textboxes wouldn't handle the event and the new controls would have this 'event' handled internally. i.e. Public Class MyNewTextBox Inherits TextBox Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs) Me.Text = Me.Text.Trim() If Me.Text.Length = 2 Then Me.Parent.SelectNextControl(Me, True, True, True, True) End If End Sub End Class If you create a new WindowsControlLibrary project and delete the usercontrol that is autocreated, create a new class and paste the above code into the file. If you build the project a DLL should be created, you can now open up your Windows form project and add your DLL to the toolbox (right click add remove items - browse to the DLL). You can then use this new textbox anywhere you need to implement the above logic. Also as Nerseus suggested - you may want to think about the logic a bit more / improve the validation depending on your needs.
-
Drop all tables created after a certain date
PlausiblyDamp replied to foz's topic in Database / XML / Reporting
Normally databases like SQL like to work on data as a set - one operation that can affect many rows at once (SELECT, DELETE, UPDATE) and as long as the where clause is well written then this is the most effective way to cause mass updates. Cursors allow you to loop through records that match a criteria one at a time - effectively allowing you to loop through records one by one. -
Drop all tables created after a certain date
PlausiblyDamp replied to foz's topic in Database / XML / Reporting
Not sure if it's the only way (or even a good way) but you could do this with a cursor DECLARE tables_cursor CURSOR FOR SELECT name from sysobjects WHERE crdate >= '' and type = 'U' declare @tablename sysname OPEN tables_cursor -- Perform the first fetch. FETCH NEXT FROM tables_cursor into @TableName -- Check @@FETCH_STATUS to see if there are any more rows to fetch. WHILE @@FETCH_STATUS = 0 BEGIN exec ('drop table ' + @tablename) -- This is executed as long as the previous fetch succeeds. FETCH NEXT FROM tables_cursor END CLOSE tables_cursor DEALLOCATE tables_cursor usual disclaimers about running things like this on your own servers apply i.e. have a backup, test on a non-critical system etc ;) -
It is actually converting to a full ARGB format rather than just RGB (the A is the alpha channel). If you only require the RGB components you could always mask out the A part Dim c As Color = Color.Red Dim i, j As Int32 i = c.ToArgb j = c.ToArgb i = i And &HFFFFFF MessageBox.Show(j.ToString("X")) MessageBox.Show(i.ToString("X")) the above code does the same as before but j is the full ARGB and i will just be the RGB values. Out of interest what will you be doing with the Hex values? If you plan on converting back to a colour with the Color.FromARGB() function then you are better of using the full 32-bit ARGB value.
-
The following will display the Hex value as a string. Dim c As Color = Color.Red MessageBox.Show(c.ToArgb.ToString("X"))
-
dim startDate as DateTime = ds.Tables("TimeIn").Rows(0)("StartTime") dim endDate as DateTime = ds.Tables("TimeIn").Rows(0)("EndTime") dim diff as timeSpan = endDate.Subtract(startDate) Debug.WriteLine(diff.Hours)
-
You are probably best to wire the event handler up at runtime using the addhandler keyword. The sample below simply loops through all controls on the form in the form_load (if some are nested inside other controls then this will fail - reply and I'll show how to get that to work) and if it is a textbox then it sets the TextChanged handler to the other function. Inside the function it uses the sender object to identify which control raised the event. Private Sub TextField_Changed(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim t As TextBox t = DirectCast(sender, TextBox) t.Text = t.Text.Trim() If t.Text.Length = 2 Then Me.SelectNextControl(t, True, True, True, True) End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim t As TextBox For Each c As Control In Me.Controls If TypeOf c Is TextBox Then t = DirectCast(c, TextBox) AddHandler t.TextChanged, AddressOf TextField_Changed End If Next End Sub
-
Bit rough and ready but should give you the idea. In practice I would be more inclined to use stored procedures rather than hard coding the SELECT.... statements. You may also want to consider using a strongly typed DataSet rather than how I've done it below.... 'Just create 2 connections (1 per server) Dim conn As New SqlConnection("Initial Catalog=Northwind;Integrated Security=true;Data Source=(local)") 'assign the correct connection to each data adapter Dim daCustomers As New SqlDataAdapter("SELECT * FROM Customers", conn) Dim daOrders As New SqlDataAdapter("SELECT * FROM Orders", conn) Dim ds As New DataSet daCustomers.Fill(ds, "Customers") daOrders.Fill(ds, "Orders") Dim dr As New DataRelation("CustomerOrders", ds.Tables("Customers").Columns("CustomerID"), ds.Tables("Orders").Columns("CustomerID")) ds.Relations.Add(dr) DataGrid1.DataSource = ds.Tables("Customers")
-
public class SuperSquare : SQUARE { ... } also note that you can only inherit when using classes rather than structs.
-
Probably the best way would to be load the data into two seperate DataTables within the same DataSet. You could then create a DataRelation and add this to the DataSet's Relations collection. This would allow you to write code which could then navigate the relationship or alternatively the grid control for windows forms will display the relationship as well.
-
Can you access this remote component through code normally? If not the problem could be with permissions. Under .Net code running from a remote machine is restricted in what it can do. If you look under your administrative tools you should see a tool for Framework Configuration - you can use this to alter the access remote code has. If you search these forums you should find more information on changing these permissions. Just to check though - is there anything preventing you copying the assembly to your local machine during testing? Just curious as I've never personally run tests against remote assemblies.
-
in your original code If not Request.Cookies("shoresh")("newmasinblogs") is nothing it will try to evaluate Cookies("shoresh")("newmasinblogs") but if Cookies("shoresh") is nothing then it will fail, doing it in two stages makes sure both parts aren't nothing.
-
How about if you did If (not Request.Cookies("shoresh") is nothing) andalso (not Request.Cookies("shoresh")("newmasinblogs") is nothing) Then If Request.Cookies("shoresh")("newmasinblogs") = "כן" Then massagenum.Text = dataset.Tables("massages").Rows.Count CheckBox1.Checked = True End If End If
-
Does the dataset and the Table "massages" exist? IF so what is the value of dataset.Tables("massages").Rows.Count if you step through the code in the debugger?
-
http://www.gotdotnet.com/team/clr/AppdomainFAQ.aspx
-
Passing a varaible to SQL statement
PlausiblyDamp replied to cpopham's topic in Database / XML / Reporting
Access is it? IIRC you can include double quotes in your strings by using double double quotes (i.e. "") Also you would need to change the bit of VB code to If Me.rbtnCOTrans.Checked = True Then mstrPOType = ">= ""01""" Else mstrPOType = """00""" End If and then remove both single quotes from the SQL statement. -
Robert Plant?? My girlfriend would be going mad if she realised someone thought Robert Plant was in the Cure ;) Then again she did used to be a tad fanatical about them when she was younger.
-
Passing a varaible to SQL statement
PlausiblyDamp replied to cpopham's topic in Database / XML / Reporting
It looks like that in the line "AND ([tblReqNmbr(Master)].ReqChange) '" & strPOType & "')) " & _ you have an extra ' after ].ReqChange) the line looks like it should be "AND ([tblReqNmbr(Master)].ReqChange) " & strPOType & "')) " & _ -
You could try the following Uri uri = new Uri("http://server11/index.asp?FunctionName=miko^hagever&from_date=06/01/04",true); System.Net.WebRequest wr = System.Net.WebRequest.Create(uri); although it should only escape invalid characters though...
-
http://www.xtremedotnettalk.com/showthread.php?t=78598&highlight=sendmessage
-
Could you give a full example of a typical URL you would be using?