|
The first error tells you you try to use a method with a wrong signature.
The second error tells you the method you're trying to use is not static (i.e. you can't access it from its class, you have to use an instance of the panelMasterList to call the method).
So, if your main form holds an instance of panelMasterList, use the variable referencing this instance to call the method :
myPanelMasterList.contextDeleteMasterList_Click(sender, e);
Or make the method static in the panelMasterList Class :
public static void contextDeleteMasterList_Click(object sender, EventArgs e) {...}
But, depending on how you organized your application, there could be some more issues. This is only what I can think of regarding the informations you provided.
Kind regards.
|
|
|
|
|
Hi all
I have googled it for days now I can only find information on how to get the ActiveMdiChild form from the main MDI form(parent).
I have a MDI application with a few children and a non child form that is used to update data on the active child.
In Borland Delphi you could add the following to any form Parent or not and it will allow you access to that selected child's controls.
Delphi
______
TfMDIChild(fMainForm.ActiveMDIChild).Label1.caption := 'Some text';
Is there any way to do this in C#
Ta
|
|
|
|
|
Deneys wrote: Is there any way to do this in C#
That would roughly translate to this;
(this.ActiveMdiChild as FormTableBrowser).Label1.Text = "Some Text"; "this" pointing to the mainform, which has a ActiveMdiChild property. That's a form that can be casted, just like we did in Delphi. A big difference is that "Label1" has become "label1", it's private by default. You can change this by setting the Modifiers -property in the designer to public .
Hope this helps
I are Troll
|
|
|
|
|
I have around 1.5 million words/phrases. I have to search these words/phrases in the text file which contains more than 1000 pages. If words/phrases are found then I need the position of the words/phrases. Can anybody get me the search logic which works faster.
Thanks in Advance.
|
|
|
|
|
K Suresh Reddy wrote: I have around 1.5 million words/phrases. I have to search these words/phrases in the text file which contains more than 1000 pages. If words/phrases are found then I need the position of the words/phrases. Can anybody get me the search logic which works faster.
An algorithm like Boyer-Moore? Or more a technique, like caching?
There's several options, depending on your needs. In general, an ad-hoc search would be slow, and this can be improved by preparing an index in advance, listing in what pages each word occurs. This would look something like a table;
Word Page
------- --------
1 1,2,6,9
2 1,3,4
3 1,2,3,9 Sql Express has a text-indexing feature[^], that might save some time, compared to indexing the words by hand. Another advantage is that the resultset would be available to multiple clients; I imagine that you'll need lots of CPU-power to process the results.
I are Troll
|
|
|
|
|
Hello everyone,
My problem is as follows:
- When I select text in a textbox I want the following things happen:
example: I select the word "hello", and pressing a button I want the selected word becomes
"[b]hello[/b]".
How can I do? (I speak of a web application not windows form)!
Please help me!!!
|
|
|
|
|
_ASPAle_ wrote: I speak of a web application not windows form
Then why didn't you ask in the ASP.NET forum?
You want to highlight text in a textbox and make it bold? AFAIK it can't be done. The input element does not allow it.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I'm sorry, I've posted my message here becouse I thought this message boards is not only for windows forms application!
I apologize again!
|
|
|
|
|
|
|
I have created CR which is evoked by passing a number(which is a variable) and according to that no. a corresponding image has to come from web.
By the way, the whole data on CR is coming from online database.
So how to pass a variable in CR for picture?
|
|
|
|
|
Hi everyone,
I'm dealing with a problem I can't figure out how to solve, and I'd love to hear some suggestions.
[NOTE: I realise I'm asking several questions; however, answers need to take into account all of the issues, so I cannot split this into several questions]
Here's the deal: I'm implementing a system that underlies user applications and that protect shared objects from concurrent accesses. The application programmer (whose application will run on top of my system) defines such shared objects like this:
public class MyAtomicObject {
public virtual int x { get; set; }
public virtual List<int> list { get; set; }
public virtual MyClassA objA { get; set; }
public virtual MyClassB objB { get; set; }
}
As you can see they declare the fields of their class as auto-generated properties (auto-generated means they don't need to implement get and set). This is so that I can go in and extend their class and implement each get and set myself in order to handle possible concurrent accesses, etc. This is all well and good, but now it starts to get ugly: the application threads run transactions, like this:
1. The thread signals it's starting a transaction. This means we now need to monitor its accesses to the fields of the atomic objects.
2. The thread runs its code, possibly accessing fields for reading or writing. If there are accesses for writing, we'll hide them from the other transactions (other threads), and only make them visible in step 3. This is because the transaction may fail and have to roll back (undo) its updates, and in that case we don't want other threads to see its "dirty" data.
3. The thread signals it wants to commit the transaction. If the commit is successful, the updates it made will now become visible to everyone else. Otherwise, the transaction will abort, the updates will remain invisible, and no one will ever know the transaction was there.
So basically the concept of transaction is a series of accesses that appear to have happened atomically, that is, all at the same time, in the same instant, which would be the moment of successful commit. (This is as opposed to its updates becoming visible as it makes them)
In order to hide the write accesses in step 2, I clone the accessed field (let's say it's the field list ) and put it in the transaction's write log. After that, any time the transaction accesses list , it will actually be accessing the clone in its write log, and not the global copy everyone else sees. Like this, any changes it makes will be done to the (invisible) clone, not to the global copy.
If in step 3 the commit is successful, the transaction should replace the global copy with the updated list it has in its write log, and then the changes become visible for everyone else at once. It would be something like this:
myAtomicObject.list = updatedCloneOfListInTheWriteLog;
Problem #1: possible references to the list. Let's say someone puts a reference to the global list in a dictionary. When I do...
myAtomicObject.list = updatedCloneOfListInTheWriteLog; ...I'm just replacing the reference in the field list , but not the real object (I'm not overwriting the data), so in the dictionary we'll still have a reference to the old version of the list. A possible solution would be to overwrite the data (in the case of a list, empty the global list and add all the elements of the clone). More generically, I would need to copy the fields of one list to the other. I can do this with reflection, but that's not very pretty. Is there any other way to do it?
Problem #2: even if problem #1 is solved, I still have a similar problem with the clone: the application programmer doesn't know I'm giving him a clone and not the global copy. What if he puts the clone in a dictionary? Then at commit there will be some references to the global copy and some to the clone, when in truth they should all point to the same object. I thought about providing a wrapper object that contains both the cloned list and a pointer to the global copy, but the programmer doesn't know about this wrapper, so they're not going to use the pointer at all [EDIT: this has changed; see update below].
The wrapper would be like this:
public class Wrapper<T> : T {
private T thisPtr;
}
I do need this wrapper for comparisons: if I have a dictionary that has an entry with the global copy as key, if I look it up with the clone, like this:
dictionary[updatedCloneOfListInTheWriteLog] I need it to return the entry, that is, to think that updatedCloneOfListInTheWriteLog and the global copy are the same thing. For this, I can just override Equals, GetHashCode, operator== and operator!=, no problem. However I still don't know how to solve the case in which the programmer unknowingly inserts a reference to the clone in a dictionary.
Problem #3: the wrapper must extend the class of the object it wraps (if it's wrapping MyClassA, it must extend MyClassA) so that it's accepted wherever an object of that class (MyClass) would be accepted. However, that class (MyClassA) may be final.
This is pretty horrible :$. Any suggestions? I don't need to use a wrapper, anything you can think of is fine. What I cannot change is the write log (I need to have a write log) and the fact that the programmer doesn't know about the clone. [EDIT: again, this has changed; see update below]
I hope I've made some sense. Feel free to ask for more info if something needs some clearing up. Thanks so much!
UPDATE: Ok, the programmer not knowing about the clone is no longer an issue: I can override the programmer's methods, analyse the methods' bodies with reflection, and tweak them to use thisPtr (or whatever I want) instead of the reference to the clone. However, all the other issues still remain. Also (maybe because I've been working all day and my brain won't work anymore) it's still not obvious to me when I should replace a reference with its thisPtr. Is it always? I'd appreciate some input on this.
|
|
|
|
|
A very long post, a very long problem and a very long solution.
From what I understand you want to have shared objects (atomic objects) that can be modified using a transactional mechanism. And your main problem is that when a transaction is running what data you show to other requests.
If this is the case why don't you do as in a sql transactional server? When a transaction is started the atomic object is blocked until the transaction finishes succesfully or not. As for the data you provide to client requests, you don't give them acces to the main object, but to a clone of the object. And all changes must be made using an global object that supplies procedures following some rulles (meaning that in order to change the list of the object, you don't change the list, but call a procedure of that global object that does the job).
There are a couple of ways you could handle the transactional mechanism. One of them is to use a transaction object on which you use a mutex or something.
Hope this helps.
I have no smart signature yet...
|
|
|
|
|
Stanciu Vlad wrote: A very long post, a very long problem and a very long solution.
Indeed.
Stanciu Vlad wrote: From what I understand you want to have shared objects (atomic objects) that can be modified using a transactional mechanism. And your main problem is that when a transaction is running what data you show to other requests.
That's right.
Stanciu Vlad wrote: If this is the case why don't you do as in a sql transactional server? When a transaction is started the atomic object is blocked until the transaction finishes successfully or not. As for the data you provide to client requests, you don't give them access to the main object, but to a clone of the object.
Yeah, this is what I want to do. The problem is how. I have almost everything figured out except for the issues with the clones.
Stanciu Vlad wrote: And all changes must be made using an global object that supplies procedures following some rules (meaning that in order to change the list of the object, you don't change the list, but call a procedure of that global object that does the job).
This is what I had in mind. However, my main problem (problem #2, making sure they don't leave any references to the clone) still remains. Updating the right object isn't really problematic, I just didn't like the way I'm doing it now (replacing the fields one by one, as explained in problem #1). But when I give the programmer a clone instead of the global copy, what if he then goes and puts it in a dictionary or something? Then when the transaction commits there will be some references to the global object and some to the clone.
Stanciu Vlad wrote: There are a couple of ways you could handle the transactional mechanism. One of them is to use a transaction object on which you use a mutex or something.
I've been investigating this and I'm not having much luck, maybe you can help with this. The thing is, the whole point of my project is writing this transactional system (it's a software transactional memory[^] system). It's important that I have control over conflict resolution between transactions (deciding which one wins when they compete for the same lock) and what happens at commit, rollback, etc. From what I can see, Transaction[^] doesn't give me that control, since I cannot override TransactionManager[^]. Please correct me if I'm wrong (I hope I am).
Thanks for your help, I know this is pretty heavy stuff.
|
|
|
|
|
I think that tracking the clone is not the right way to do this; and .net's Transaction and TransactionManager classes I don't know if they wore built for customization. I looked a bit with Reflector in that assembly and all I can say is that messy stuff happens there.
The way I see a system like this is:
1) you should set up a workspace, the place where you keep your objects (original ones).
2) every clone provided to the user outside a transaction is "as it is". It's only purpose is to store values.
3) inside transactions, that's where all the crazy stuff takes place. A transaction should have a context (and by context I mean a part of or all the objects managed in the system workspace cloned and stuffed togheter outside the workspace). In the transaction context the user can do whatever he likes with the objects, because when he commits the transaction, the whole transaction context (meaning the changed objects) replaces the system workspace.
4) when a users requests to read or write a object in the context (the get or set method, or whatever implementation you have there) the object should be locked to the transaction that owns the context, and all the other transaction contexts should be notified about this lock (you do not want two users to change the same object in aproximatively the same time and both transactions to be comitted succesfully)
5) when a transaction is finished (successfully or not) all the objects locked to that transaction should be unlocked.
If you follow these steps maybe you can use the system like this:
using(MyCustomTransaction trans = new MyCustomTransaction())
{
trans.Context.TransactionalObject.x = 10;
(trans.Context.ManagedObjects["my object"] as aCustomTransactionalType).y = trans.Context.TransactionalObject.x * 100;
}
If you follow these steps there will be a lot of "lock(someContext)" and stuff like that. And the object locking mechanism in my opinion is the most messy part. A solution is to make a Mutex for each object in the system workspace, and center all the action in your TransactionManager and Transaction based on those mutex'es.
I don't know if this was the type of answer you were expecting )
I have no smart signature yet...
|
|
|
|
|
Hi Stanciu. Thanks for your answer.
What you describe is very similar to what I do. I actually have class called TransactionContext
But... I have problems with the following:
Stanciu Vlad wrote: In the transaction context the user can do whatever he likes with the objects, because when he commits the transaction, the whole transaction context (meaning the changed objects) replaces the system workspace.
Yes, but that requires registering the reads/writes somehow, and I don't know how to do that without tracking the objects. I do have write logs and read logs where I will register such accesses, but I don't know how to detect the accesses without somehow extending the code of the object's class to make the object notify them when they happen.
Actually, ideally what I'd like is to be able to write a monitoring agent that sees the bytecode that is running and registers every read/write, but I don't know how to do this in C#. I do know how to write the agent, but I don't know how to "plug it in" so that it can see the running bytecode. If you know how to do this it would pretty much solve all my problems, and I like it way better than what I'm doing right now -- which by the way doesn't work
Apart from that, my locking policy is slightly different, etc, but it would work if I can detect and register accesses correctly.
Thanks again for your answer
|
|
|
|
|
You problem seemed like a challenge for me , so, in the weekend, having some spare time in front of the computer, I've created a basic transactional system. It is basic because it can't use communicate with other processes, it only works inside the same application domain (manages multiple threads), but in my opinion it can be extended.
Do you want the source code? (maybe this will provide more answers for you).
I have no smart signature yet...
|
|
|
|
|
|
i have a system paramters table in my sql server to control everything about the system and I am currentlly saving all parameters as public variables in my C# windows form applicaton upon user login to the system..
I was just thinking if that's the best practice to do or I should save all in a local INI or XML file upon the user login the replace the file everytime the user login again?
what's your recommandation?
|
|
|
|
|
It all depends on your security requirement. Having an ini or xml file to store said data would render it available for tampering at will whilst variables make it quite difficult for your normal users.
If the post was helpful, please vote, eh!
Current activities:
Book: Devils by Fyodor Dostoyevsky
Project: Hospital Automation, final stage
Learning: Image analysis, LINQ
Now and forever, defiant to the end.
What is Multiple Sclerosis[ ^]?
|
|
|
|
|
what if i encrypt it in the local file or make it in a binary file for example?
|
|
|
|
|
Encrypting would still leave it open for tampering, whether malicious or not.
If the string "XLJKHSD7FR6W2345HLKSDFHO978W642O5KJH3RFO987Y" was the Base64 equivalent of some password, then if I change an alphanumeric character I have rendered the whole thing useless. Don't forget, INI and XML files are clear text. I would be against having clear text files that contain such crucial information.
A binary file would hamper any tampering effects, but that doesn't mean that the file could be deleted, again by mistake or on purpose.
If the post was helpful, please vote, eh!
Current activities:
Book: Devils by Fyodor Dostoyevsky
Project: Hospital Automation, final stage
Learning: Image analysis, LINQ
Now and forever, defiant to the end.
What is Multiple Sclerosis[ ^]?
|
|
|
|
|
Won't help against a hacker, he has the program and therefore either the key or the code that retrieves/calculates the key (and, therefore, the key). The only way to make it impossible for a hacker to get the key, would be to give the program no knowledge about the key or how to get it, but then you're stuck with an encrypted file which you can not decrypt.
There are many ways to make it "harder" for normal users to mess around too much, of course.
Making it a binary file would help, putting it through a DeflateStream would help too, xoring every byte with some funny number (say 0x34) would also help - but only against normal users.
They could, of course, randomly mess the file up..
|
|
|
|
|
I prefer to access the database each time a parameter value is required.
For one thing, it allows changing the configuration without restarting the application.
I use a class that offers properties that access the parameter database.
|
|
|
|
|
Hi there
I need print something with variable number of copies.
I used printdocument component.
private void Print_b_Click(object sender, EventArgs e)
{
printDocument1.PrinterSettings.Copies = 2;
printDocument1.Print();
}
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.PageSettings.PrinterSettings.Copies = 2;
e.Graphics.DrawString("Test Print", new Font("Tahoma", 14, System.Drawing.FontStyle.Bold), Brushes.Black, 50, 50);
}
I used PrinterSettings.Copies = 2; in both block but does't work.
If you know why? tell me please.
Best Regards,
Reza Shojaee
|
|
|
|
|