|
Hi,
not sure what it is you want.
Your code needs to reside inside a method, probably an event handler with a "sender" parameter.
Anyway, the solution probably needs a simple this.CurrentForm=sender as Form; with CurrentForm declared as a general Form, not a specialized one.
OTOH, if you were to explain your needs at a higher level, maybe a different approach would be advisable.
|
|
|
|
|
Yeah but then i cant use any methods hat are in the forms class
if (Sender is form1)
{
form1 temp = (form1)Sender;
form1.login()
}
The above works but i cant use form1 outside the if statment, I need a way os saving it at runtime like the class varibles here.
class Login
{
Form CurrentForm;
|
|
|
|
|
if all candidate senders share some user-defined functionality (would be necessary if you want to invoke a method on such sending form), then the solution would be to define an interface, and make all those forms "implement" the interface, which should mean you add ", IMyFunctionality" to the class declaration, as in:
public class MyForm1 : Form, IMyCommonFormFunctionality { ... }
where you need to define the interface, something like (outside all classes!):
public interface IMyCommonFormFunctionality {
void login();
}
Then in your class, do:
IMyCommonFormFunctionality CurrentForm;
...
CurrentForm=sender as IMyCommonFormFunctionality;
BTW: by convention public method names should be CamelCased, i.e. start with an upper-case letter.
[ADDED]
I doubt very much that adding login logic to a bunch of forms is the right way to go. Object orientation dictates to separate concerns, not mix them like that.
[/ADDED]
|
|
|
|
|
For anyone who's familiar with Telerik's RadGrid...
I have placed all rows into EditMode by setting AllowMultiRowEdit = true, then doing this:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
foreach (GridItem item in RadGrid1.MasterTableView.Items)
{
if (item is GridEditableItem)
{
GridEditableItem editableItem = item as GridDataItem;
editableItem.Edit = true;
}
}
RadGrid1.Rebind();
}
The problem now is - I don't see any way to force the grid to save changes. I tried:
protected void cmdSaveChanges_Click(object sender, EventArgs e)
{
SqlDataSource1.Update();
}
But it didn't work. How do I save changes in the grid? I do NOT want Edit or Update button columns in the grid.Everything makes sense in someone's mind
|
|
|
|
|
Hi all.
I have some issue with data encoding.
I have a txt file, which was open like this:
StreamWriter m_ComissionShopWriter = new StreamWriter(Directory.GetCurrentDirectory() + "\\logs\\1.txt", false, Encoding.GetEncoding(1251));
then I user WriteLine method to put there some data, which was taken from some stream:
sr = new StreamReader(stream, Encoding.GetEncoding(1251));
After, I try to load it into table, which has the following collumn:
varchar(100) cp1251_general_ci
Insertion goes great!
But when I run select query on it, I got some junk data instead of readable, 1251 encoded, data.
What is wrong, and how can I fix it?
Thanks!
|
|
|
|
|
When you open a stream with a specific encoding, it applies to the stream, not the data in memory; in .NET strings in memory are using Unicode no matter what. So you are reading/writing Unicode strings from/to the database, which requires nvarchar fields.
If you insist on having a particular encoding in the database, then you must read/write byte arrays, which you convert to/from Unicode strings using Encoding.GetString()/GetBytes().
|
|
|
|
|
Well, I tried it but it didn't work.
Here is a part of my code, can you tell me, please, what I did wrong?
MySqlConnection connection = new MySqlConnection(MyConString);
MySqlCommand command = connection.CreateCommand();
try
{
connection.Open();
Console.WriteLine("Connected to DB");
}
catch (Exception e)
{
Console.WriteLine("Failed to connect to DB");
return;
}
command.CommandText = "truncate table test_tb";
command.ExecuteNonQuery();
connection.Close();
StreamReader sr = new StreamReader("somefile.txt", Encoding.GetEncoding(1251));
string line, query;
string[] data;
byte[] temp = new byte[10000];
int j = 0;
while ((line = sr.ReadLine()) != null && j < 10)
{
data = line.Split('~');
query = "insert into test_tb (name, id) values(N'" + data[2] + "'," + j.ToString() + ")";
temp = ASCIIEncoding.GetEncoding(1251).GetBytes(query);
command.CommandText = ASCIIEncoding.GetEncoding(1251).GetString(temp);
connection.Open();
command.ExecuteNonQuery();
connection.Close();
++j;
}
The column in table os varchar(1000) type, with windows-1251 encoding
thanks a lot.
|
|
|
|
|
Hi,
I need to change my COM1 port to COM5. I can easily do it by opening the port advanced properties in the Device Manager and changing it from COM1 to COM5.
However, I searched google all over for a solution to do it from my code, and didn't find anything.
I can read the port settings using the SerialPort class or WMI, for example, I can read the DeviceID property of the Win32_SerialPort class. But I can't write to this property, it's read-only. Is there any other way to accomplish the same thing?
|
|
|
|
|
Hi,
your app should not try and change port names; instead your app should allow you to choose which port is to be used, just like a text editor allows you to choose which file gets read or written.
SerialPort.GetPortNames() could be useful.
And you should consider remembering your last choice, so by default the same port is used again and again.
|
|
|
|
|
It's not actually an app, I'm writing a setup script and I have a requirement to rename COM1 to COM5 during setup.
Because it's a requirement, not doing this is not an option
I was considering writing a small .net exe to do the job for me, but was stuck.
|
|
|
|
|
I'm trying to make my own Custom Control, to be more specific: a Composite Control with various Labels and Progress Bars. However I need the entire Control to act like a button so that No matter which control within the composite that the user clicks, it will still run the Click event I assign to the Control in my program. I've read that this can be done with Bubbling, but I’m having trouble understanding the concept and how it applies to my needs.
I've seen various examples of Bubbling, but I'm still uncertain because I can't see in those examples whether or not the events are "Bubbled" to the overall control's event within a program - they seem to end after the creation of the control.
|
|
|
|
|
Simply - the container type control subscribes to relavent events of it's hosted controls. The event handlers all call a
protected virtual void OnClick(EventArgs e) method that raises the host's Click event.Dave
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
So, are you saying I can have each of my controls inside a container call the OnClick method whenever they're clicked? Then the Container's "Click" event will trigger? I'm not sure I'm understanding this right.
|
|
|
|
|
Yes - a simple experiment would verify this for you.
This is the idea:
public partial class MyUserControl : UserControl
{
public MyUserControl()
{
InitializeComponent();
}
private void textBox_Click(object sender, EventArgs e)
{
OnClick(e);
}
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void myUserControl_Click(object sender, EventArgs e)
{
MessageBox.Show("Click Event");
}
} As you will see, the TextBox 's Click event is now 'bubbled' up to the surface by the MyUserControl .Dave
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Hello all,
my employer Kryptiva and I have put out a first release of a new plugin for Microsoft Outlook 2003 and 2007 called echotracker.
echotracker is a mail indexer and personnal information aggregator that installs itself as an panel in Microsoft Outlook. The software isn't feature-complete but is already providing useful information about mails in Microsoft Outlook.
This is released under the terms of the LGPL 2.1 license which means it's OPEN-SOURCE! There aren't that many open-source Outlook plugin out there so I think this is interesting stuff for developers.
We need developers and courageous users to build and test first developer preview. We accept bug reports and patch on our mailing lists. I'd be glad to answer any kind of questions on this forum but we would prefer people to use mailing lists.
François-Denis Gonthier
|
|
|
|
|
You would probably be better off posting this in the Catalog.Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
Help humanity, join the CodeProject grid computing team here
|
|
|
|
|
Thanks! Will do. I'm rather new here.
|
|
|
|
|
is this [echotracker] ?
'g'
|
|
|
|
|
Yes it was before it was deleted.
|
|
|
|
|
I am in the process of coding an application wherein there is a server application running as a Windows Service on a "big, powerful" box. Scattered around the country are computers that communicate with this "Host" in real-time. There will be a few thousand "clients" connected (10K or less) at any given time.
That's the background. I've already written the Sockets logic for both server and client, and the connections are speedy (using the Send* calls), so that's not an issue.
Here is my situation and question: at a pre-determined time every day, each of these clients' data needs to be tallied/processed/whatever-you-want-to-call-it and then the client needs to be notified this processing has completed. Every client could have a different time-of-day at which this needs to be done. Is there a more efficient way than using a timer (with the appropriate Interval calculated) for each client? I was thinking that perhaps using a single timer and some sort of hashtable that associates clients with time-of-day may work. But I'm soliciting all ideas. Don't assume your idea is not good enough...I want to hear as many possibilities as I can.
Thanks.
Tim
|
|
|
|
|
I'm assumeing the tallying is being done on the "big, powerful" box. Couldn't you simply send a message back to the client when it happens? I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Thanks for your reply, but you missed my point. I'm trying to design the mechanism that determines the time has been reached to process the subset of clients whose "closeout time" (a time of day) has been reached.
|
|
|
|
|
TimWallace wrote: Thanks for your reply, but you missed my point. I'm trying to design the mechanism that determines the time has been reached to process the subset of clients whose "closeout time" (a time of day) has been reached.
I can't reach your point even now.
I just don't get what you want. I mean you need the time that has beeen reached ... whose "closeout time" has been reached
|
|
|
|
|
Remote machines ("clients") may all have a unique "closeout" time, which is a time of day at which the host process ("server") needs to do processing specific to that client. When the processing is done, the server sends a message to the client. Does this clear things up for you?
|
|
|
|
|
yep but there is nothing I could add to the asnwers offered by Mark, Anticast and others.
|
|
|
|