|
Hello !
i'm using vb.net 2017 with EF 6
I have 2 tables on my database : Product and ProductDetail
I have also 2 bindingsource Productbindingsource and ProductDetailsbindingsource.
I have also 2 datagridview each of them bound to the respective bindingsource.
When the user select a product in the first datagridview , the other datagridview is filled with Productdetails for the selected product.
I have this code :
Private sub Fill_Product
context.Products.Where(Function(t2) t2.cl>5).Load
ProductBindingsource.datasource=context.Products.Local.ToBindinglist
End sub
Private Sub ProductBindingSource_CurrentChanged(sender As Object, e As EventArgs) Handles ProductBindingSource.CurrentChanged
context.Entry(ProductBindingSource.Current).Collection("ProductDetails").Load()
ProductDetailsBindingsource.Datasource=DirectCast(ProductBindingSource.Current, Product).ProductDetails
End sub
Private Sub RollBack()
Dim changedEntries = context.ChangeTracker.Entries().Where(Function(x) x.State <> EntityState.Unchanged).ToList()
For Each entry In changedEntries
Select Case entry.State
Case EntityState.Modified
entry.CurrentValues.SetValues(entry.OriginalValues)
entry.State = EntityState.Unchanged
Case EntityState.Added
entry.State = EntityState.Detached
Case EntityState.Deleted
entry.State = EntityState.Unchanged
End Select
Next
End Sub
I have 2 problems with this code :
1.when I delete a ProductDetail from the second Grid , and after execute the rollback Sub , the deleted ProductDetail is not back on that datagrid , andalso when I add new Productdetail when I rollback this is not removed from the gridview.( other modifications in values , are reverted to original values).
2.On the sub ProductBindingSource_CurrentChanged , everytime that the user select a product in the first grid , the second grid is filled with ProductDetails and database is queried with .Load. But this is ok when the user select a Product for the first time . What about when the user select a Product for the second or third time ? The product Details are already loaded , so what to do to not query again from database but use local data ?
Thank you !
modified 6-Dec-18 7:17am.
|
|
|
|
|
The drawlines feature does not work correctly in the following codes. but it works correctly when the same data is drawn with the drawline. Drawlines draws lines that are not real. What are your comments?
Dim uImage As Bitmap = New Bitmap(PictureBox1.Size.Width, PictureBox1.Size.Height, 4, Imaging.PixelFormat.Format32bppPArgb, 0)
Dim Grafik As Graphics = Graphics.FromImage(uImage)
Grafik.Clear(Color.Black)
Dim Offset As Integer = 0
Dim Gain As Integer = 1
Dim Freq As Integer = 1
Dim N As Integer = PictureBox1.Size.Width
Dim D(N - 1) as PointF
For i As Integer = 0 To N - 1
D(i).X = i
D(i).Y = Offset + Gain * Math.Cos(i * Freq * Math.PI / 180.0)
Next
Dim sx As Double = PictureBox1.Size.Width / (N - 1)
Dim sy As Double = PictureBox1.Size.Height * 0.5
sy=sy*32000
For i As Integer = 0 To N - 1
D(i).X = D(i).X * sx
D(i).Y = PictureBox1.Size.Height * 0.5 - D(i).Y * sy
Next
Grafik.DrawLines(New Pen(Color.Blue), D)
For i As Integer = 1 To N - 1
Grafik.DrawLine(New Pen(Color.Red), D(i - 1), D(i))
Next
PictureBox1.Image = Nothing
PictureBox1.Image = uImage
Grafik.Dispose()
I would like to provide additional information. Errors may occur when Picturebox reaches a specific size. The dimensions for this example are 720; 530 pixels. the following image is being obtained:
Blue lines should not appear in the image. Should overlap with the red lines.
https://i.hizliresim.com/MVXM2g.png[^]
|
|
|
|
|
When I try to open the picture it says "403, forbidden". Have you ever heard of the phrase "SELECT is not broken"?
Have the program print the values that you calculate, there might be a rounding error somewhere.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Option Explicit
Sub Button4_Click()
Dim rng As Range
Dim temp As Variant
Dim i As Long
Dim a As Long
Dim rng_dest As Range
Application.ScreenUpdating = False
i = 1
Set rng_dest = Sheets("Invoice data").Range("C:H")
' Find first empty row in columns D:G on sheet Invoice data
Do Until WorksheetFunction.CountA(rng_dest.Rows(i)) = 0
i = i + 1
Loop
'Copy range B16:I38 on sheet Invoice to Variant array
Set rng = Sheets("Invoice").Range("A22:C33")
' Copy rows containing values to sheet Invoice data
For a = 1 To rng.Rows.Count
If WorksheetFunction.CountA(rng.Rows(a)) <> 0 Then
rng_dest.Rows(i).Value = rng.Rows(a).Value
'Copy Invoice number
Sheets("Invoice data").Range("A" & i).Value = Sheets("Invoice").Range("J8").Value
'Copy Date
Sheets("Invoice data").Range("B" & i).Value = Sheets("Invoice").Range("J7").Value
'Copy Company name
Sheets("Invoice data").Range("C" & i).Value = Sheets("Invoice").Range("C13").Value
i = i + 1
End If
Next a
Application.ScreenUpdating = True
Range("J8").Value = Range("J8").Value + 1
'Sheets("Invoice").Range("Invoicebody").Clear
'ActiveSheet.Range("J8").Value = ActiveSheet.Range("J8").Value + 1
End Sub
Sub Macro1()
'
' Macro1 Macro
'
'
Range("E19").Select
Selection.Copy
Sheets("Invoice data").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
End Sub
result here
Invoice No. Date Customer Category Product Description Quantity Unit Price Amount
1/15/1900 12/4/2018 Kashif GDFItems 214, 421 #N/A #N/A #N/A
1/15/1900 12/4/2018 Kashif GDAItems Honda 2036 #N/A #N/A #N/A
1/15/1900 12/4/2018 Kashif GeneralItems Injector Cleaner STP Diesel #N/A #N/A #N/A
1/15/1900 12/4/2018 Kashif GDFItems 214, 421 #N/A #N/A #N/A
1/15/1900 12/4/2018 Kashif GDFItems 471 - 215 - 433 - 206 #N/A #N/A #N/A
1/15/1900 12/4/2018 Kashif GDFItems 471 - 215 - 433 - 206 #N/A #N/A #N/A
1/15/1900 12/4/2018 Kashif GDOItems Fiat Tractor 508 #N/A #N/A #N/A
1/15/1900 12/4/2018 Kashif GDFItems 214, 421 #N/A #N/A #N/A
1/15/1900 12/4/2018 Kashif GDFItems 221 #N/A #N/A #N/A
1/15/1900 12/4/2018 Kashif GDOItems 1 C toyota 412 #N/A #N/A #N/A
1/15/1900 12/4/2018 Kashif GDOItems 1 C toyota 412 #N/A #N/A #N/A
1/15/1900 12/4/2018 Kashif GeneralItems Injector Cleaner STP Petrol #N/A #N/A #N/A
from this invoice
INVOICE
1
Your Complete Adress
------ CUSTOMER ID SEFS
------ INVOICE DATE December 4, 2018
PHONE : 000-0000000 INVOICE NUMBER 16
FAX: 000-0000000 PAYMENT DATE BY December 19, 2018
BILL TO
NAME Kashif
CONPONEY NAME
ADDRESS
PHONE : 000-0000000
EMAIL ID abc@example.com
Category Product Description Quentity Unit Price Amount
GDFItems 214, 421 4 Rs. 5.00 Rs 20.00
GDAItems Honda 2036 2 Rs. 6.00 Rs 12.00
GeneralItems Injector Cleaner STP Diesel 3 Rs. 5.00 Rs 15.00
GDFItems 214, 421 3 Rs. 5.00 Rs 15.00
GDFItems 471 - 215 - 433 - 206 3 Rs. 5.00 Rs 15.00
GDFItems 471 - 215 - 433 - 206 3 Rs. 5.00 Rs 15.00
GDOItems Fiat Tractor 508 4 Rs. 5.00 Rs 20.00
GDFItems 214, 421 3 Rs. 5.00 Rs 15.00
GDFItems 221 3 Rs. 2.00 Rs 6.00
GDOItems 1 C toyota 412 2 Rs. 5.00 Rs 10.00
GDOItems 1 C toyota 412 3 Rs. 3.00 Rs 9.00
GeneralItems Injector Cleaner STP Petrol 3 Rs. 6.00 Rs 18.00
SPECIAL INSTRECTIONS SUBTOTAL Rs. 33,288.00
1. Please mention ur invoice number in cheque. TAX [% ] 2
2. Last date to deposit your due ammount by 15 days of invoice . TAX AMOUNT Rs. 665.76
DISCOUNT Rs. 222.00
TOTAL Rs. 33,731.76
WITHOUT TAX Rs. 33,066.00
Customer Signature Signature
make sure your cheque is payable to deep
For any inquiry you can contact us : abc@email.com
Thanks for your business
|
|
|
|
|
Did you forget to include the question in your post?
|
|
|
|
|
Hello !
I have an application on vb.net 2017 , that reads from excel and save to database.
When I process large data from excel , at some point the application stop , and inside visual studio I get this error :
Managed Debugging Assistant 'ContextSwitchDeadlock' : 'The CLR has been unable to transition from COM context 0x1b387fb0 to COM context 0x1b387e88 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.'
If I press Continue inside visual studio , the program continue to execute and finish the job without error.
But every time I have repeated the proces i get that error .
What can I do ?
Thank you !
|
|
|
|
|
desanti wrote: What can I do ? Offer smaller files.
It's the same with any application in Windows; if it doesn't respond, it is assumed to be dead. If an application does so, Windows will offer to terminate the application.
Or disable the break in the IDE, saving you from having to press F5.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
sorry , but my application does respond and it's not dead.
until the point that this error is displayed , all the data are saved on database .
1 second before this error is displayed , a record was saved on database.
But suddenly this error appear , and I have to press continue , and after the execution goes without problem until the end.
so , the application is alive , why windows consider it to be dead ?
|
|
|
|
|
desanti wrote: sorry , but my application does respond and it's not dead.
until the point that this error is displayed , all the data are saved on database .
1 second before this error is displayed , a record was saved on database.
But suddenly this error appear , and I have to press continue , and after the execution goes without problem until the end.
so , the application is alive , why windows consider it to be dead ?
It says literally so in the error; "The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages."
If the app does not process messages, it is considered "not responding". Most apps that go into an uncontrolled loop do not respond to those messages, and it is a way of detecting if the app is still active. If it is doing a lot in one thread, then the thread won't be replying to messages.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
And what you propose as a solution , because I've read that I should use a background worker , but the problem is that I need to access the UI objects during the process and this is not possible on a background worker.
|
|
|
|
|
Since you wont be changing the COM-control, You'd be either ignoring the message, or offering smaller files.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I can't offer smaller files.
also I've read that I can do some configuration to ignore the message.
but the problem is , what about when I finish my program and install it to client pc ?
I've read also that I can use application.doevents.
But executing this on every step of the loop cause the program to slow down.
Is there way to call this only when necessary so windows can detect that my application is alive ?
|
|
|
|
|
desanti wrote: also I've read that I can do some configuration to ignore the message.
but the problem is , what about when I finish my program and install it to client pc ? You can; the IDE only breaks on exceptions that you want it to. What happens without the IDE can easily be tested by running your app outside of it. Then you'll know what happens on the client-PC.
desanti wrote: I've read also that I can use application.doevents. No, you can't.
desanti wrote: But executing this on every step of the loop cause the program to slow down. It is a loop inside a COM-component. Do you have the source to that control?
desanti wrote: Is there way to call this only when necessary so windows can detect that my application is alive ? You application IS alive (and answering messages), but the COM-component that you're using is not. If you know WHY it is not answering messages, then it is not a problem. You simply wait for it to be done and hope it is not in an endless loop.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
|
If the loop is in your program, then it should be in a backgroundworker on its own thread. If the loop is inside the COM-component, you can't change much.
Application.DoEvents is a crutch for people doing too much on the UI-thread.
--edit
Go to the menu "Debug / Exceptions", find "Managed Debugging Assistants", uncheck ContextSwitchDeadlock.
And sometimes, the message is even bogus[^].
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
the loop is inside my program , but the problem is that inside the loop I use the values from some controls in my form ( there's a spreadsheet control that have all the data from excel file or directly written by user and some other textboxes that have all the data and parameters that I use on that loop). so I can't use a background worker because I've read that I can't use the UI controls inside it. Or I'm wrong !!!!!
|
|
|
|
|
desanti wrote: so I can't use a background worker because I've read that I can't use the UI controls inside it. Or I'm wrong !!!!! You can't access them directly, you'd have to do an invoke.
Is this actually occuring in the release-version?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Yes , I noticed at least 2-3 times in the release version.
I've tried with Application.doevents executed on every step of the loop , and no problems but the application slows down.
So i'm asking if there's a way to know the interval that windows check for application status , so i'm calling application.doevents not on every step of the loop but for example every x seconds ? Is this possible ?
|
|
|
|
|
desanti wrote: So i'm asking if there's a way to know the interval that windows check for application status , so i'm calling application.doevents not on every step of the loop but for example every x seconds ? Is this possible ? I never found any specification on how often Windows checks it, might even vary between versions. Instead of doing it every N seconds, you could do it after N items. Still, that metric may vary on another system.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
But if you see my original error message , it says.... "60 seconds". Maybe this is the time or is another thing ?
|
|
|
|
|
Yup, that's what it says, you're right. Get the current time before the loop.
Inside the loop, distract that value from the current time. If the difference is more than N seconds, call your doevents.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
a Timer object will be a help or no ?
|
|
|
|
|
Which timer-object? There's multiple, and one of them relies on the application processing messages (ie, not being too busy).
It's easier to simply check inside the loop how much time has passed.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
|
The one from System.Windows.Forms says this in the docs;
Implements a timer that raises an event at user-defined intervals. This timer is optimized for use in Windows Forms applications and must be used in a window. Meaning it won't fire if it doesn't get to process the message.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|