|
Hello !
But for my case described in my first post , can you write some code how should I use your idea ?
Thank you !
|
|
|
|
|
Well, list1 is just a list of articles so you can use Linq on the rest:
Private List1 As New List(Of Article)
Private Sub Window_Loaded(sender As Object, e As RoutedEventArgs)
For i As Integer = 0 To 6
Dim f As New Article
f.ID = 2
f.Td = i
List1.Add(f)
Next
lst.ItemsSource = List1
End Sub
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
SearchString = "id=2, td=3"
Dim predicate As Predicate(Of Article) = AddressOf FindArticles
lst.ItemsSource = List1.FindAll(predicate)
End Sub
Dim SearchString As String = ""
Private Function FindArticles(obj As Article) As Boolean
Dim ListOfProperties As New List(Of String)
Dim ValueOfProperties As New List(Of String)
If SearchString = "" Then
Return True
End If
Dim NumberOfArguments() As String
NumberOfArguments = SearchString.Split(",")
For Each Str As String In NumberOfArguments
Dim test() As String = Str.Trim.Split("=")
ListOfProperties.Add(test(0).Trim)
ValueOfProperties.Add(test(1).Trim)
Next
Dim ReturnValues As New List(Of Boolean)
' Dim TrueValue As Boolean = False
For Each p As System.Reflection.PropertyInfo In obj.GetType().GetProperties()
If p.CanRead And p.CanWrite Then
For i As Integer = 0 To ListOfProperties.Count - 1
If p.Name.ToLower = ListOfProperties(i).ToLower Then
Dim t As Type = If(Nullable.GetUnderlyingType(p.PropertyType), p.PropertyType)
Dim safeValue As Object = If((ValueOfProperties(i) Is Nothing), Nothing, Convert.ChangeType(ValueOfProperties(i), t))
'Get the value
Dim f = p.GetValue(obj)
'This would set the value
' p.SetValue(p, safeValue, Nothing)
'Is it the same type?
If safeValue IsNot Nothing Then
If f = safeValue Then
ReturnValues.Add(True)
Else
ReturnValues.Add(False)
End If
Else
'If you end up here you have entered the wrong element type of the property
' like an integer instead of a point etc
End If
End If
Next
End If
Next
Dim truevalue As Boolean = False
' This is And logic on the result
If ReturnValues.Count <> 0 Then
Dim tempvalue As Boolean = True
For Each Bools As Boolean In ReturnValues
tempvalue = tempvalue And Bools
Next
truevalue = tempvalue
End If
Return TrueValue
End Function
End Class
Class Article
Private pId As Integer
Public Property ID() As Integer
Get
Return pId
End Get
Set(ByVal value As Integer)
pId = value
End Set
End Property
Private pTd As Integer
Public Property Td() As Integer
Get
Return pTd
End Get
Set(ByVal value As Integer)
pTd = value
End Set
End Property
End Class
|
|
|
|
|
Hello !
List1 is a list of article , but in my case is a temporary list that change depending to some conditions and at the end the Tolist is called to retrieve data from database.
My problem is not to filter Articles because this is easy , but to filter the child entities F1 and F2.
|
|
|
|
|
Then re-query it?
list1 = From t In context.Articles.Include("F2") Order By t.name Ascending
Select t
|
|
|
|
|
I don't want to include all the child entities.
I want to include from F1 only the items with .vl1=5 , or I want to include from F2 only those items with date>12/03/2015
|
|
|
|
|
I've created a Custom Control that inherits a PictureBox control. When a TestApp uses my newly created custom control, I'd like to add some additional data to the MouseMove event that is returned. Currently the raised event would appear in the TestApp as....
Private Sub MyCustomControl_MouseMove(sender as object, e as MouseEventArgs) handles MyCustomControl.MouseMove
My first thought was to add additional arguments such as....
Private Sub MyCustomControl_MouseMove(sender as object, e as MouseEventArgs, MyExtraArgument as double) handles MyCustomControl.MouseMove
or as an alternative, add my extra argument to the MouseEventArgs class so it would appear as...
e.MyExtraArgument
Is either of these methods possible? I'm under the impression that these events/objects may not be overridden without being able to modify the original source code of the parent control. Are there any simple examples of doing either of these techniques? Ideally I'd like to keep all the code within my newly created control library so that the TestApp doesn't require anything other than dropping the newly created child control into it.
|
|
|
|
|
You should be adding your arguments as additional e MouseEventArgs so you conform to the existing structures. Google tossed up this article Step by Step: Event handling in C#[^] when I searched for overload event arguments.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hello !
I have project in vb.net using a sql server 2008r2 database and Entity Framework.
Several clients are using this program.
But sometimes I make modifications to program and to database structure ( for example new fileds are added to several tables , new tables are added...etc ).
I give to the clients the new ".exe" file , but the problem is that their database is not up to date according to my last modifications.
Let's suppose that I have the new database model as a empty SQL server backup file "Model.bak".
I want to add in my applications a "Update Database" command. This command should do the update process of the current client database according to the new structure of "Model.bak".
I want suggestions , how can I do this on vb.net ? ( I don't want to do this with other tools and programs. I want to give users only the new ".exe" file and the new template "Model.bak" and do te update process from my application )
I read somewhere that is possible to prepare a updating sql script that can do this process.
If this Is true , I have some questions :
1) How this script can be created ?
2) Is possible to store this script inside the "Model.bak" file , and to call inside my program ?
If this story of the script it's not true , any other suggestions ?
Thank you !
|
|
|
|
|
|
Thank you !
But as I understand , this article speak for Code First.
In my case I have first created the databse on sql server management studio , after using wizard inside VB.net I created the entity. It seems I'm using Databae First , or I'm wrong ???
So in my case how can I use this solution ?
|
|
|
|
|
I'm not going to be able to help with the EF stuff, can't stand the tool myself, but!
A .BAK file is a backup and therefore has absolutely nothing to do with your scripting changes to the database. And cannot be used as such AFAIK.
We use Red-Gates SQL Compare to generate the change scripts, but you can create the script manually. That script then needs to be transported to and run against your clients server. You could get your app to check a folder for a .sql file on startup, if it finds one then open the file and run the script of the connection in the app. Then archive the .sql so it cannot be automatically run again.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thank you !
For transporting this script , I think to have a one-field table inside the database . This field will keep the update script.
I want to give users only the new .exe file and the Model.Bak.
Is possible that inside my application to have a code that read this field inside the Model.Bak , get the script and run to update the current database on that computer ?
Maybe it's a stupid idea , but I want to find a way to give users only the exe file and the new Model.Bak , and they can make update process inside my program.
Thank you !
|
|
|
|
|
Just what is Model.bak and why are you supplying it with a new .exe?
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hello !
In my computer where I develop the application , I change the structure of the database when creating also the new .exe. and after I finish my application , I made a backup of the new database version. Model.bak is the new database version (empty) backup made from Sql server management Studio. I supply with the new exe , because my application has the possibility to create multiple databases and works with each of them. To create a new database the application use the Model.Bak template.
|
|
|
|
|
That is what I thought, it will not work for updating a database structure, you will restore an empty database and lose all the data.
You need to use a script to apply the changes.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I have just added functionality through a 3rd party API to a large programming project of mine. The 3rd party API requires me to set the target CPU to 64 bit for it to work on my machine.
So far so good. The section of the program which uses the API is working like a charm.
But here's the problem. Previously I was relying on API calls to SetCursorPos in another, previously totally functional part of the program. Those API calls no longer work as expected and the cursor is placed in bizarre locations when I try to call that after a 64 bit compile. If I set the target CPU back to x86 or AnyCPU, SetCursorPos works like a charm again -- but not the new 3rd party API based stuff.
I've gone searching and have found hints of other people having problems with the functionality of SetCursorPos on a x64 targeted compile, but haven't yet found any good workarounds. Thoughts?
Thanks in advance,
Frustrated in KTown
|
|
|
|
|
Sounds like you've got an incorrect P/Invoke declaration - something is declared as Integer when it should be IntPtr , or vice-versa.
According to pinvoke.net[^], the correct declaration should be:
<DllImport("user32.dll", SetLastError:=True)> _
Private Shared Function SetCursorPos(ByVal X As Integer, ByVal Y As Integer) As Boolean
End Function
If you're using Windows Forms, there's a managed API which might work better:
https://msdn.microsoft.com/en-us/library/system.windows.forms.cursor.position%28v=vs.110%29.aspx[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I created an access Lyric database. Then I added a table and a combo to hold song file data. Then, when the user selects a song and clicks play the code below gets executed. When I first did this it went well. WMPlayer opened up and played the song. Now it opens up the open dialog wanting me to select the file. It returns a 42. This is the first time I used this API command. Any help will be appreciated.
Private Sub cmdPlay_Click()
Const klShowApp As Long = 1
Dim sPath As String, sFile As String
Dim lReturn As Long
On Error GoTo ERR_cmdPlay_Click
sFile = ksQuote & Me.cboTuneLU.Column(1) & ksQuote
sPath = ksQuote & Me.cboTuneLU.Column(2) & ksQuote
lReturn = ShellExecute(Me.hWnd, "open", sPath, vbNullString, sFile, klShowApp)
Stop
EXIT_cmdPlay_Click:
Exit Sub
ERR_cmdPlay_Click:
ShowError "frmLyrics.cmdPlay_Click"
Resume EXIT_cmdPlay_Click
End Sub
modified 28-Jan-15 15:11pm.
|
|
|
|
|
|
The user actually selects the filespec (path & filename) from the open dialog box. I split the filespec into Path and filename and store each into their corresponding fields in a record. I know the path is correct because the open dialog opens to the correct folder. This was working great, but now It does this. I would sure like to find out what the return values of this API function mean. I tried every number fro 0 to 10 in the show parameter of the shellexecute API call.
The record is define as:
tblMP3
------
MP3Seq autonum index
MP3ID long
MP3VerID integer
MP3Path text
MP3File text
I wanted to be able to save more then one song file. The artist's version and a karaoke version. That's what the MP3VerID is for.
The MP3ID field is the same as the autonum field in the lyrics table.
I have had this program for a number of years. VB's Shell has been used all this time. But now on Win 7 I get a security message blocking me from using it. That's when I discovered ShellExecute.
Any help will be appreciated Roger
|
|
|
|
|
It's an exit code. usually 0 means all is good. 1 means error. But search for Windows Media Player Exit Codes.
You should load Quicktime, set it as default player, and give it a test first, before you tear your hair out.
|
|
|
|
|
Hi,
I am a newbie
I have problem with string builder. I want to show to Richtextbox in vb with Richtextbox template
ex. :
Jan 674 Meet 670 Not Meet 4
Feb 635 Meet 631 Not Meet 4
etc.
with source from datagirdview with 8 columns and xxxx rows.
for ex. columns are : Registered Date, Deadline Date, Month, Meet/Not Meet,etc.
This my Code :
For Each keyvalue As KeyValuePair(Of String, Integer) In DicMonth
CMonth.Items.Add(String.Format("{0}", keyvalue.Key))
sb.AppendLine(String.Format("{0} : {1}", UCase(keyvalue.Key), keyvalue.Value))
Next
For Each keyvalue1 As KeyValuePair(Of String, Integer) In DicMeetTotal
sb.AppendLine(String.Format("{0}", "MEET : " & keyvalue1.Value))
Next
RichTextBox2.Text = sb.ToString
and the result is :
JAN : 674
FEB : 635
MAR : 623
APR : 637
MAY : 888
JUN : 994
JUL : 452
AUG : 594
SEP : 526
NOV : 317
DEC : 305
MEET : 670
MEET : 631
MEET : 621
MEET : 637
MEET : 870
MEET : 968
MEET : 438
MEET : 583
MEET : 522
MEET : 287
MEET : 298
Please help me ?
I appreciate your help
|
|
|
|
|
You are creating all the month items first, and then all the MEET items. You need to combine your loops somehow so it selects both items together, i.e. (MONTH and number, MEET and number).
|
|
|
|
|
Thanks for your advice but I had already creating both of them.
please tell me how to combine it ?
Thanks
|
|
|
|
|
You need to match the entries in the two dictinaries so you get them in the correct order, probably by using an index value and a single loop.
|
|
|
|