Let's say you have a table containing customer orders. An order has an ID, a status, and a number of other things including creation date and user. As the order is processed, the status will change and you want to be able to report each status change.
Rather than having one row and overwriting the previous values, you can create a new row with the new values.
In this way you can easily see the details of an order's life all in one table. When a new state is created, the only change you make to the previous state is to set the NextID field. And the current record is the one with NextID==null.
I need to create a desktop application using C# as frontend and postgresql/postgis for the database.
I have google maps V3 embedded into web browser control.
My question is, is there any way to visualize geometry column of postgis into google maps using C#.
You get Access Denied because the account your code is running under does not have permissions to the remote machine. By default, if you don't specify any account information in the Management connection objects, it'll use the account your code is running under. If that account doesn't have permissions on the remote machine, it'll fail.
I have a form with a progressBar on it. I'm doing writes in another class (through my interface) and need to show my progress of doing the writes, but I'm getting an error message *. Hopefully someone has an idea how to get the error to go away and so I can update my progressBar from a different class.
I'm more of a C++ developer doing C#, so there might be something that an experienced C# person would know of that I'm missing.
It looks like this:
Form with progressBar displayed
privateint writeIt(ref byte wDat, byte sDat)
result = cr.ProcessTWriting(ref wDat, ref pb_Progress.Value); //this passes a ref to the progressBar value
* In the code above, I'm getting "A property, indexer or dynamic member access may not be passed as an out or ref parameter" error message.
My interface looks like this:
iCR.cs (which is in another VS project due to future CR6, etc. which will use the interface)
int ProcessTWriting(ref byte wDat, refint pb_value);
Then, I want to pass my references (to progressBar value) to where I'm writing my bytes (i to 1024), and update the reference to the progressBar as it iterates through, writing to it's destination.
This would be in my CR5.cs which implements iCR.cs (and is in another VS project still...think Factory pattern):
Sorry in advance for my english. Possibly is not good enough yet...
Do you have the possibility to change your interface?
I'm thinking that a solution to your problem could be the use of events on your CR5 class. (Observer pattern)
You could create an event on CR5 class that can be subscribed by the class that contains the progress bar. Then, you can fire your event on the AttempWrite function with a parameter that indicates de current progress value to set into the progress bar.
Is it a possibility? Or are you constrained to this interface contract?
That's a good idea. I'll give that a try. I can absolutely change my interface. That's why I'm showing the progressBar value in the interface now. I'm not absolutely sure how to send a value when I fire an event, but I'll take a look. Thanks!
inside one of the Framework class. likewise we can also define our own delegates that suits to our need. here instead of using the native handler I defined a custom delegate to fire an event. Read the following articles which explains more about events and delegates. Events-and-Delegates-Simplified and Step-by-Step-Event-handling-in-C#
class MyCR: CRInterface
publicevent ProgressChangeHandler ProgressChanged;
publicint ProcessTWriting(ref byte WDat, refint pb_value)
status = AttemptWrites(ref pb_value);
privateint AttemptWrites(refint pb_value)
for (int i = 0; i < ((wDat.Length) / 4); i++)
//as it does writes, I want to set pb_value here to % complete
privatevoid RaiseProgressChange(int progress)
Finally Subscribe for event change in your FormClass i.e PC.cs
// call this line just below where you create the instance of CR5 classprivate FormLoad(...)
cr.ProgressChanged += new ProgressChangeHandler(CR_ProgressChanged);
privatevoid CR_ProgressChanged(int progress)
progressBar.Value = progress;
The above code sample is working version if you closely look at the sample you can find that delegate method is defined in the dll where iCR is located and you don't need to use the Public access specifier for Interface methods and data.
This will definitely work and I have done same stuff in the past.
ProgressChangeHandler must be defined globally so that this delegate is accessible by all members.
If I could add one more little question onto the above, which I got to work. I also have a C_Comm.cs class which is referenced in my CR5.cs, the original PC.cs, and iCR.cs. It turns out that one area I need to update my progress bar (in PC.cs) from is C_Comm, which is also in a different VS project. I'm trying to get it working, and am getting an error: Cannot implicitly convert type 'ProgressChangeHandler' to C_Comm.ProgressChangeHandler'
Right now it looks like this:
PC.cs (the form code)
publicevent ProgressChangeHandler ProgressChanged;
cr.ProgressChanged += new ProgressChangeHandler(updateProgressBar); //cr is instance of CR5 through iCR interface/factory
cb.ProgressChanged += new ProgressChangeHandler(updateProgressBar); //cb is C_Comm
publicint updateProgressBar(int i)
pb.Value = i;
I tried to just have the delegate in my C_Comm.cs (not in iCR), and now in my CR5.cs class, I get the error "The name 'ProgressChanged' does not exist in the current context" in my RaiseProgressChange method. Then if I try to use cb.ProgressChanged != null, I get the error "The event 'C_Comm.ProgressChanged' can only appear on the left hand side of += or -=". I'm not very clear on using events! Do you have any ideas?
C_Comm.cs is a separate VS project, separate dll, commonly referenced by everything (CR5.cs, PC.cs). Do you think I still need everything except the delegate part in my iCR? The CR5 implements iCR and that's the only way I can see getting the ProgressChanged defined in CR5 from PC.cs, but when I take out the delegate part, I get "The type or namespace name 'ProgressChangeHandler' could not be found (are you missing a using directive or an assembly reference?)". I can't keep my iCR.cs and C_Comm.cs in the same dll because of the whole layout. The VS project layout is:
Project 1 has iCR.cs
Project 2 has PC.cs and a couple of other things. (update - this has form with progress bar)
Project 3 has CR5 (implements iCR) and a couple of other things.
Project 4 has CR_Factory which will return a CR5 through the iCR interface to my PC.cs
Project 5 has C_Comm.cs. It is referenced in PC.cs, CR5, and iCR.
In the future I'll have a CR6 project like the CR5.
As far as cb.ProgressChanged != null, I'm just trying to get what you suggested originally to work with my delegate in my C_Comm. Yes, checking for null before I send the update.
I wound up leaving the original delegate in my iCR and everything you originally recommended above. Then I created a separate delegate and handler in my C_Comm.cs class. I couldn't see any other way to update my progressBar and also share the same delegate and event. Thanks for the help!
I dont see any error in your declaration, i.e the delegate method is declared in Comm.cs file which is referred in all the other 3(or more project) iCR,CR5 and form Class. so the delegate should be available in all other classes and you need to include the proper namespaces in other project files.
Thank you so much for the help. We have a very small work group here, and they are not programmers and don't understand this stuff (not to mention me having a tough time with events and this architecture). It turned out I wasn't "using" C_Comm in my interface. Once I did that and fixed a couple of declarations to use the C_Comm version of the Handler, all worked.
@jibesh - I added an interface (see my recent question), and my event is null when I try to update my progress bar. I know you have a good idea about events and interfaces. If you could take a look at my newly posted question(Thursday post maybe), I'd appreciate it. Thanks!
i never use Dependency Injection in apps. i go through few article with Dependency Injection and found the concept is interesting but believe hard to implement in real life. now i want to implement Dependency Injection in my win form apps.
our company work with many shipping company like UPS, Fedex, Purolator etc for now but in future they have plan to works with many other shipping company. i have developed separate separate class library projects for all those shipping company like UPS, Fedex, Purolator and include those dll into our main form apps. the problem is many time we hard code few things in our code like country code etc.
for example i have one form where 4 buttons are there. like those buttons are "Ship with UPS WorldShip", another button there called "Ship with UPS WebAPI", another button there called "Ship with FedEX Desktop Apps" and another last button called "Ship with Fedex WebAPI".
when user click on UPS WorldShip button then a flat file generate in a folder. when user click on UPS WebAPI button then a request goes to UPS site.
when user click on FedEX WinApps button then a flat file generate in a folder. when user click on FedEX WebAPI button then a request goes to FedEx site.
so what i do now when user click on any button then i call a specific function exist in dll to complete the task.
everything is working fine at my end but the problem is when our company start working with another new shipping company then i have to create another class library for that company.
i said i never use DI ever in my apps and have no experience. so some one guide me how could i handle my situation with DI as a result when a new shipping company will join then i do not have to write any extra code. so guide me how to implement DI in my apps and also guide me with how to handle my situation with sample DI code for guidance.
DI doesn't work this way. If you have new functionality, then you have to write code. So, if you add a new company and that has specific logic, then you will have to write that logic - DI is not a magic bullet. What it would do, is save you having to write any logic to hook it up to your UI, for instance.
If you're going to do this, then I'd suggest that you read a few artioles here on Code Project. This[^] is a good place to start. Beyond that, I'd also consider investigating MEF.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
Adding a bit more emphasis to the previous reply - because you are accessing an external service provider you will always need to write new code for each.
Given your description of how you are implementing this it also seems unlikely that you can generalize it either. Which isn't to say that you are doing it wrong but rather because you are using all the shipping options rather than attempting to normalize it that you won't be able to generalize it. And actually I suspect that if you try to generalize it too much that you could end up with problems.
Tridip Bhattacharjee wrote:
then i have to create another class library for that company.
This doesn't sound like a job for plain DI. It sounds more like a job for MEF which is more of a plug-in architecture.
How much of the code is straight up copy & paste between different companies?
If the code is 99% duplicate, why not just move the differences into a SQL database or XML file and just have a single common engine that reads the params and uses them? I.e. like instead of hardcoding one dll to fedex and another to ups, just have one method where you pass in the URL or whatever?
Even if the code is more like 50% to 75% different, I'd refactor it to a data driven engine instead of a plug-in architecture.
I'm guessing most of the code is identical... go to this URL to create an order, go to this URL to do this, etc.
Last Visit: 31-Dec-99 18:00 Last Update: 17-Aug-17 17:29