employee.cs:
using System;
using System.Collections.Generic;
using System.Linq; using System.Text;
namespace ConsoleApplication21
{
class employee
{
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
private int id;
public int Id
{
get { return id; }
set { id = value; }
}
}
}
Program.cs:
using System;
using System.Collections.Generic;
using System.Linq; using System.Text;
using System.Collections;
namespace ConsoleApplication21
{
class Program
{
static void Main(string[] args)
{
employee em = new employee();
begin:
record re = new record();
Console.WriteLine("=======================");
Console.WriteLine("1.签到,2.签退,3.退出");
Console.WriteLine("=======================");
Console.WriteLine("请选择服务项目");
int value = Convert.ToInt32(Console.ReadLine());
switch (value )
{
case 1:
re.insign();
goto begin;
case 2:
re.signout();
goto begin;
case 3:
goto begin;
default :
Console.WriteLine("输入错误,请重新输入");
goto begin;
}
} } }
record.cs:
using System;
using System.Collections.Generic;
using System.Linq; using System.Text;
namespace ConsoleApplication21
{
class record
{
employee e = new employee();
private DateTime signintime;
public DateTime Signintime
{
get { return signintime; }
set { signintime = value; }
}
private DateTime signouttime;
public DateTime Signouttime
{
get { return signouttime; }
set { signouttime = value; }
}
public record()
{
init();
}
Dictionary<int, employee> em = new Dictionary<int, employee>();
public void init()
{
employee em1 = new employee();
em1.Name = "小熊";
em1.Id = 1;
employee em2 = new employee();
em2.Name = "小智";
em2.Id = 2;
em.Add(em1.Id , em1);
em.Add(em2.Id , em2);
}
DateTime dt = DateTime.Now;
int d = DateTime.Now.Hour;
bool isadd = false;
public void insign()
{
begin:
Console.WriteLine("请输入你的员工工号");
int value = Convert.ToInt32(Console.ReadLine ());
if (d > 15)
{
Console.WriteLine("请在8点前签到,现在时间为{0}",dt );
}
else
{
foreach (employee emp in em.Values)
{
if (emp.Id.Equals ( value))
{
if (isadd)
{
Console.WriteLine("今天员工已签到,不能重复签到");
}
else
{
Console.WriteLine("签到成功");
showtime();
signintime = dt;
isadd = true;
}
break;
}
else
{
Console.WriteLine("不存在该员工");
goto begin;
}
}
}
}
public void signout()
{
begin:
Console.WriteLine("请输入你的员工工号");
int value = Convert.ToInt32(Console.ReadLine());
foreach (employee eml in em.Values)
{
if (value.Equals (eml.Id))
{
bool isadd = true;
if (d < 10)
{
Console.WriteLine("请在17点之后签到,现在时间为{0}", dt);
}
else
{
if (isadd)
{
end:
Console.WriteLine("是否确认签退,1-确认,2-退出");
int a = Convert.ToInt32(Console.ReadLine());
switch (a)
{
case 1:
Console.WriteLine("签退成功");
showtime();
signouttime = dt;
continue;
case 2:
break;
default:
Console.WriteLine("输入错误,请重新输入");
goto end;
}
}
else
{
Console.WriteLine("还没签到,不能签退");
}
}
break;
}
else
{
Console.WriteLine("该员工不存在,请重新输入");
goto begin;
}
}
}
public void showtime()
{
DateTime dt = DateTime.Now;
Console.WriteLine(string .Format ("{0:yyyy-mm-dd hh:mm:ss}",dt ));
}
} }