C# Windows Form Application for Employee Management

Windows Form Calculations C#

Make every input textbox of your form use the same TextChanged event and set the ReadOnly property to True for the TxtTotal

 // Here just to clarify, you could use 
// the Form designer to register this event handler
Txt1.TextChanged += onChanged;
Txt2.TextChanged += onChanged;
Txt3.TextChanged += onChanged;
TxtTotal.ReadOnly = true;

now write the TextChanged event handler to something like this

 private void onChanged(object sender, EventArgs e)
{
int t1;
int t2;
int t3;

Int32.TryParse(Txt1.Text, out t1);
Int32.TryParse(Txt2.Text, out t2);
Int32.TryParse(Txt3.Text, out t3);

txtTotal.Text = (t1+t2+t3).ToString();
}

This code assumes that every textbox contains an integer and doesn't care if the textbox is empty or contains a text that cannot be converted to an integer. In this case the value of the converted variable will be zero and doesn't change the result.

More code will be needed if you want to emit error messages. And if you have decimals then use an appropriate decimal variable and decimal.TryParse instead of Int32.TryParse

How to give the permission to each user in winforms using c#

you should develop a Role-Base windows application. This tutorial describe what you need
i hope it helps you

How to find employee by id with textbox and button

You have collection of employee in your form.

You just need simple Linq to find an employee for given employeeid.

var found = employee.FirstOrDefault(e=>e.EmployeeIDNum == employeeid);

if(found != null)
{
// logic here.
// found.employeeInformationToString();

listBox1.Items.Clear(); // check this if you want to clear.
listBox1.Items.Add(found.employeeInformationToString());
}

So your complete search code should be something like...

private void sreachbtn_Click(object sender, EventArgs e) 
{
//// Need Some Thing Here

int employeeid;

if(int.TryParse(textbo1.Text, out employeeid)) // use your textbox name.
{
var found = employee.FirstOrDefault(e=>e.EmployeeIDNum == employeeid);

if(found != null)
{
// logic here.
found.employeeInformationToString()
}
}

}

Update :

Looks like you are not familiar with Linq , in this case try uing traditional looping.

private void sreachbtn_Click(object sender, EventArgs e) 
{
//// Need Some Thing Here

int employeeid;

if(int.TryParse(textbo1.Text, out employeeid))
{
Employee found= null;

foreach(var emp in employee)
{
if(emp.EmployeeIDNum == employeeid)
{
found = emp;
break;
}
}

//var found = employee.FirstOrDefault(e=>e.EmployeeIDNum == employeeid);

if(found != null)
{
// logic here.
found.employeeInformationToString()
}
}
}

How to open a form into a panel from third form?

Here's one possible approach.

The Parent of your instance of frmmenus will be a Panel. From that Panel you can call FindForm() to get a reference to the main Home instance. Next you can use Controls.Find() to search for your Panel called "pncontainer". From there, simply clear the panel and add your desired form instance to it:

private void btnsetting_Click(object sender, EventArgs e)
{
frmEmployee employee = new frmEmployee()
{
Dock = DockStyle.Fill,
TopLevel = false,
};


Form frm = this.Parent.FindForm();
Control match = frm.Controls.Find("pncontainer", true).FirstOrDefault();
if (match != null && match is Panel)
{
Panel p = (Panel)match;
p.Controls.Clear();
p.Controls.Add(employee);
employee.Show();
}
}


Related Topics



Leave a reply



Submit