Generic collection of small project staff punching, set of Staff punching
Project Style
Requirement Description: 1. Implement new employees
2. Use the DataGrideView space to display employee information
3. Delete employee information
4. Right-click the main form to sign in and exit from work.
5. If you select sign-in, You must retrieve the employee's punch history. If you have already signed in, you are prompted that you cannot sign in again.
6. If you select to sign back, You must retrieve the employee's logging record. If you have signed back, you are prompted that you cannot sign back.
7. Use the DataGrideView control to display employee attendance records
Project start:
First, set up the form to create the staff class SE punch-in time class.
Public class SE
{
Public int id {get; set;} // store employee id
Public string name {get; set;} // store employee name
Public int age {get; set;} // store employee age
Public string sex {get; set;} // store employees
Public int type; // stores the punch type 1, 2, 3
}
Public class Time
{
Public DateTime start {get; set;} // stores the check-in time
Public DateTime close {get; set;} // store the token return time
Public int id {get; set;} // stores the punch type 1, 2, 3
Public string name {get; set;} // store employee name
}
Create a generic set list
Public List <SE> list = new List <SE> (); // stores the set of employees.
Public static Dictionary <string, Time> dic = new Dictionary <string, Time> (); // stores Logging
Bind a data source when the form load time is DataGrideView
SE s1 = new SE ();
S1.id = 111;
S1.name = "Wang xiaomao ";
S1.age = 26;
S1.sex = "male ";
SE s2 = new SE ();
S2.id = 112;
S2.name = "Zhou Xinyu ";
S2.age = 22;
S2.sex = "female ";
SE s3 = new SE ();
S3.name = "Zhang Ye ";
S3.id = 113;
S3.age = 30;
S3.sex = "male ";
List. Add (s1 );
List. Add (s2 );
List. Add (s3 );
DataGridView1.DataSource = list;
Add is jump to add employee form
Click Add to save new employee information to the set
SE s = new SE ();
S. id = Convert. ToInt32 (textBox1.Text );
S. name = textBox2.Text;
S. age = Convert. ToInt32 (textBox3.Text );
S. sex = textBox4.Text;
Frm1.list. Add (s );
MessageBox. Show ("New RR added successfully! ");
Frm1.Show ();
Frm1.clear (frm1.list );
This. Close ();
Modifying employee information involves passing values in a form. This time we upload a SE object.
First, modify the employee information form to create a new SE object.
Click Modify in the main form to jump to modify the employee information form.
Form3 frm = new Form3 ();
Frm. name = maid [1]. Value. ToString ();
Foreach (SE s in list)
{
If (s. id. ToString () = maid (selectedcells [0]. Value. ToString ())
{
Frm. s = s;
Break;
}
}
Frm. f = this;
Frm. Show ();
This. Hide ();
Jump to the modify employee information form. You can edit employee information in textBox.
Click Modify to save the data.
SE s = new SE ();
S. id = Convert. ToInt32 (textBox1.Text );
S. age = Convert. ToInt32 (textBox3.Text );
S. sex = textBox4.Text;
For (int I = 0; I <f. list. Count; I ++)
{
If (f. list [I]. name = name)
{
F. list [I]. age = Convert. ToInt32 (textBox3.Text );
F. list [I]. id = Convert. ToInt32 (textBox1.Text );
F. list [I]. sex = textBox4.Text;
Break;
}
}
MessageBox. Show ("modification successful! ");
F. clear (f. list );
F. Show ();
Add ContextMenuTrip in the DataGrideView of the main form, and add sign-in and sign-off
Click sign-in and sign-out to add a data entry to the collection.
String name = maid [1]. Value. ToString ();
SE s = new SE ();
Foreach (SE se in list)
{
If (se. name = name)
{
S = se;
Break;
}
}
Num = s. type;
If (num = 0)
{
Time t = new Time ();
T. id = Convert. ToInt32 (maid [0]. Cells [0]. Value );
T. name = maid [0]. Cells [1]. Value. ToString ();
T. start = DateTime. Now;
Dic. Add (t. name, t );
S. type = 1;
MessageBox. Show ("sign-in successful ~ ");
}
Else
{
MessageBox. Show ("You have signed in ");
}
Check whether the sign-in is complete. The sign-in is the same as the sign-out.
Click the logging record to view the staff logging information.
In this way, a simple small program is finished.