|
benjamin yap wrote: why cant i just cast it to mainform then get the staffTable from there? thought it should work?
Casting will create a new instance so you won't be able to access the original.
Options:
1. Send the hashtable to the other form in FrmLogin constructor so it can be modified.
2. Send the FrmMain to FrmLogin in FrmLogin constructor so all objects of the FrmMain object instance can be accessed/modified - similar to number 1.
3. Make FrmLogin raise an event - preferred.
I've based this on your code as requested but it doesn't exactly make sense this way as I couldn't properly figure out your code flow - a staff member is added to the staff table in the FrmLogin contructor??? Anyway... here is a working sample. Again I've added a button to the frmLogin and the hardcoded staff is added there. Staff class remains unchanged.
FrmMain:
namespace EBMS
{
public partial class FrmMain : Form
{
public Hashtable staffTable;
public FrmMain()
{
InitializeComponent();
staffTable = new Hashtable();
}
private void frmMain_Load(object sender, EventArgs e)
{
FrmLogin childLogin = new FrmLogin();
childLogin.StaffChange += new OnStaffChange(childLogin_StaffChange);
childLogin.ShowDialog(this);
childLogin.Dispose();
}
void childLogin_StaffChange(object sender, StaffChangeEventArgs e)
{
staffTable.Add(e.Staff.NRIC, e.Staff);
MessageBox.Show("Added " + e.Staff.NRIC + " to table.");
}
}
}
FrmLogin:
namespace EBMS
{
public delegate void OnStaffChange(object sender, StaffChangeEventArgs e);
public partial class FrmLogin : Form
{
public event OnStaffChange StaffChange;
public FrmLogin()
{
InitializeComponent();
}
private void FireStaffChange(Staff staff)
{
if (StaffChange != null)
{
StaffChange(this, new StaffChangeEventArgs(staff));
}
}
private void button1_Click(object sender, EventArgs e)
{
Staff staff = new Staff(
"Admin",
"S123456I",
"pass123",
"13 April 1988",
"address",
12345678,
12346567,
true,
true,
false,
true);
FireStaffChange(staff);
Close();
}
}
}
StaffChangeEventArgs:
namespace EBMS
{
public class StaffChangeEventArgs : EventArgs
{
private Staff m_Staff;
public Staff Staff
{
get { return m_Staff; }
set { m_Staff = value; }
}
public StaffChangeEventArgs(Staff staff)
{
m_Staff = staff;
}
}
}
Dave
|
|
|
|
|
oh oh i forgot to tell you that the user is created in the constructor because i want it to automatically create a default user first. thats why i added it in the constructor.
btw, where do i add this code
namespace EBMS{
public class StaffChangeEventArgs : EventArgs
{
private Staff m_Staff;
public Staff Staff
{
get { return m_Staff; }
set { m_Staff = value; }
}
public StaffChangeEventArgs(Staff staff)
{
m_Staff = staff;
}
}
}
modified on Sunday, July 6, 2008 12:13 PM
|
|
|
|
|
anywhere! Create a new class and simply call it StaffChangeEventArgs then overwrite with this code
Dave
|
|
|
|
|
I've been thinking about this a little more...
In this case it seems that the staffTable is really the link between the two forms (and maybe others too?). If it is, maybe you should create a static class and create the staffTable as public static in there.
Doing it this way, it will accessible to both the FrmMain and FrmLogin, and you could create any events required in the staffTable... then, when the FrmLogin alters the staffTable - the staffTable can raise the event which you can make FrmMain listen for and react accordingly. A much better way!
Dave
|
|
|
|
|
Omg means i got to create alot different class? because i still have Product hastable, catalogue hashtable, order hashtable and a few more..
So u mean create a new class for example AllData.cs
Then inside , i put the attriubutes as
public static Hashtable staffTable;
public static Hashtable productTable;
public static Hashtable orderTable;
then for the constructor
public AllData()
{
staffTable = new Hashtable();
productTable = new Hashtable();
orderTable = new Hashtable();
}
Then inside my FrmMain i create a new AllData class?
FrmMain.cs
public AllData allData;
public FrmMain()
{
allData = new AllData();
}
Then from the child form, how do i access this allData created in the FrmMain
|
|
|
|
|
There's no need to cretae an instance of the AllData class if the contents are static.
public static class AllData
{
public static Hashtable staffTable = new Hashtable();
public static Hashtable productTable = new Hashtable();
public static Hashtable productTable = new Hashtable();
}
You can then simply call AllData.staffTable from any class in the same namespace, or specify the namespace as well if not.
Dave
|
|
|
|
|
Thanks davey
I use the constructor method and pass the hashtabble
|
|
|
|
|
I have a combobox that is bound to the database. When I update this combobox, selected value changes.
Let's say that we have these values in combobox: AAA, BBB, CCC. The selected value is CCC. When the combobox
is updated, the selected value changes to AAA. It always changes to the first item in combobox.
Does anyone have any idea how to solve this?
Thanks
|
|
|
|
|
Hi, I am new to C# and im working trying some image processing, im using this bit of code to invert the pixels on an image grabbed from a video file, how do I extract the RGB values from a pixel in C# using the image buffer? Speed is of the essence...
Thanks in advance.
unsafe
{
byte* p = (byte *)(void *)pBuffer;
int nWidth = Width * 3;
for(int y = 0; y < Height; y++)
{
for(int x = 0; x < nWidth; x++ )
{
p[0] = (byte)(255-p[0]);
p++;
|
|
|
|
|
See this article[^], there are some examples how to extract and modify the RGB values of an image.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
This is how you get the color components of a pixel, specified by the x and y coordinates:
byte* p = (byte *)(void *)pBuffer;
p += (x + y * Width) * 3;
byte r = *(p++);
byte g = *(p++);
byte b = *p;
If you increase the pointer for the last component also, it will point to the next pixel. This is very useful if you access the pixels in sequence, as you don't have to calculate a new address for each pixel.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi All,
I have a field that I which to filter on using the Contains operator but currently its throwing a wobbly. Can anyone advise? Is this even a legal operator to use in the DataView?
filter = filter + "and fileName Contains '" + _freetext.ToString() + "'";
fileName is of type string. For instance the _freetext maybe something like "day" so things like "daytime", "sunday" would both be included.
Thanks in advance.
Jammer
Going where everyone here has gone before!
My Blog
|
|
|
|
|
Hi..
I deployed my widows project successfully( included SQL express, .net frame work, Database file, Project files)
I installed my .exe file (setup file) on client machine(system) its installed successfully.
But when i run that application ,i got the below error:
============================
Login failed for user 'sa'. The user is not associated with a trusted SQL Server connection.
<configuration>
<system.windows.forms jitDebugging="true"/>
</configuration>
When JIT debugging is enabled any unhandled exception will be sent to the JIT debugger registered on the computer rather than be handled by this dialog box.
=============================
please help me...
thanks in advance
|
|
|
|
|
How did you get this far and not know that the login you use needs to match the SQL Server installation you're using ? Also, why is your user logging in as SA ?
You need to create a user with just the permissions they need, and make sure that your connection string and the SQL Server instance you're using, match in terms of username/password/etc.
Christian Graus
Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.
|
|
|
|
|
hi Graus
actually we developed windows application using (Visual Studio 2008 C# & LINQ and sqlserever 2005 express edition).and i have to create setup and deployment for this project. i was added new project as "setup and Deployment" for my windows project .And i also included all the prerequisites to my project.exe layer.but main problem is "How can i deploy the database in Client machine ".
i tried this in client Machine :
it was installing All the Prerequisites in Client machine ,it was runnig succcesfully ,but it was showing "user is not trusted user" ,How can i solve this ,could u please help me,and i was strucking from last 3 weeks.
Thanks in advance.
|
|
|
|
|
im trying to change NumberDecimalSeparator but everytime i get error that its read-only instance.
here is all code i tried :
System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.CurrencyDecimalSeparator = ".";
System.Threading.Thread.CurrentThread.CurrentCulture.NumberFormat.NumberDecimalSeparator = ".";
System.Globalization.CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator = ".";
System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator = ".";
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
You need to create your own culture and set the separator for that.
Dave
|
|
|
|
|
ok i did but how to set permanently ? here is my code that is working temporary
CultureInfo tmp_ci = (CultureInfo)CultureInfo.CurrentCulture.Clone();
tmp_ci.NumberFormat.NumberDecimalSeparator = ",";
System.Threading.Thread.CurrentThread.CurrentCulture = tmp_ci;
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
I think you have to use SetLocaleInfo in kernel32.dll
Edit: MSDN[^]
Dave
|
|
|
|
|
In my project i want to implement sound recording what we have in windows xp so i want consume that.
Give me suggestion how to implement recording sound in .net any dll is avliable?
help me out
Ashok Nalam
|
|
|
|
|
Ashok Nalam wrote: Give me suggestion how to implement recording sound in .net any dll is avliable?
Is it a question or are you demanding it? Ever heard about Google? It has many pages for you to explore[^]
By the way, don't post in multiple forums, it's rude.
Giorgi Dalakishvili
#region signature
my articles
#endregion
|
|
|
|
|
hai all
i want to use the folloiwing code of line in my application.
FolderParam flParam = new FolderParam();
When i build this i am getting error like this.
The type or name space of folderparam cannot be found. are u mising assembly reference
can any one help me to slove this problem?
Regrds
Lijo
|
|
|
|
|
You need to add a reference to a dll that contains FolderParam class.
Giorgi Dalakishvili
#region signature
my articles
#endregion
|
|
|
|
|
Can u tell me in which dll folderparam class contains?
Regrds
Lijo
|
|
|
|
|
You are writing a piece of code which uses folderparam class and you don't know it comes from? In that case you even won't know what the class is for!
Giorgi Dalakishvili
#region signature
my articles
#endregion
|
|
|
|