employee leave management system
employee can take 2 leaves in a month.if he is not taking leave then leave will be carry forward to next month.but after total 2 years these carry forward leaves can't be used.how can i calculate available leaves every month.
public bool CheckLeaveStatus(int empid, DateTime date)
{
bool temp = false;
int totalleave = 0;
string qry = "select joining from profile where profileid=@id";
MySqlParameter idP = new MySqlParameter("@id", empid);
DataRow dr = MySqlHelper.ExecuteDataRow(Common.GetConnectionString(), qry, idP);
if (dr != null)
{
DateTime joiningdate = Convert.ToDateTime(dr["joining"]);
int legaldate = joiningdate.Day;
if (legaldate <= 15)
{
totalleave += 2;
}
else
{
totalleave += 0;
}
int monthspassed = Common.MonthDifference(date, joiningdate);
if (monthspassed > 3)
{
int startmonth = joiningdate.Month + 1;
int endmonth = date.Month;
int monthdiffernce = endmonth - startmonth;
if (monthdiffernce > 24)
{
monthdiffernce = 24;
}
int leaves = (monthdiffernce) * 2;
int allowedleaves = leaves + totalleave;
int availablelaves = allowedleaves - LeaveTaken(empid);
if (availablelaves > 0)
{
temp = true;
}
}
}
return temp;
}
public int LeaveTaken(int empid)
{
try
{
int taken = 0;
string qry = "select count(*) from leavestatus where empid=@id";
MySqlParameter idP = new MySqlParameter("@id", empid);
taken = Convert.ToInt32(MySqlHelper.ExecuteScalar(Common.GetConnectionString(), qry, idP));
return taken;
}
catch
{
return 0;
}
}
public void AddLeaves(int empid, DateTime date, string status)
{
if (status == "L")
{
string qry = "insert into leavestatus(empid,takenon)values(@empid,@takenon)";
MySqlParameter idP = new MySqlParameter("@empid", empid);
MySqlParameter takenonP = new MySqlParameter("@takenon", date);
MySqlParameter[] p = { idP, takenonP };
MySqlHelper.ExecuteNonQuery(Common.GetConnectionString(), qry, p);
}
}
What I have tried:
how can i done this. pls tell me