我的 asp.net 项目中有一个页面,我想在其中显示员工的出勤情况。应在中继器中显示在场时和在节假日P
时缺席时。现在在我的网页上,我有 2 个文本框,我可以通过它们输入年份和月份,并且该月我想获得出勤率。我的数据库表如下。A
H
(1) 压延机
CalederID Year Month WorkingDays
1 2013 January 1111001111100111110011111001111
2 2013 February 1001111100111110011111001111
等等 。这里 1 代表当月的工作日,0 代表星期六和星期日,我正在使用这种模式,因为在我的一个页面上,复选框被选中(星期六和星期日)而其他人没有选中,所以我知道这些是假期
(2) 考勤表
AttendanceID EmpID PresentDays CalenderID LeaveDate
1 1 Null 1 2013-01-14
2 1 Null 2 2013-02-15
3 1 Null 4 2013-04-11
4 3 Null 6 2013-06-26
(3) EmpInfo 表
EmpID EmpName and so on
1 Joe
2 Sandra
现在,当我输入年份和月份时,我的网页上出现了问题,我想将带有标题的转发器显示为代表该月日期的日期编号。现在,如果该月有 30 天,则显示 30 个数字。使用另一个中继器,它必须以 P、A、H 格式显示出勤率,如上所述
我的中继器看起来像这样
<table class="table1" >
<asp:Repeater ID="Repeater1" runat="server">
<HeaderTemplate>
<tr>
<td>Employee ID</td>
</HeaderTemplate>
<ItemTemplate>
<td><asp:Label ID="lbldates" runat="server" Text='<%# Eval("Dates") %>' ></asp:Label></td>
</ItemTemplate>
<FooterTemplate>
<td>TOTAL</td></tr>
<tr>
</FooterTemplate>
</asp:Repeater>
<asp:Repeater id="rptAttendance" runat="server" OnItemDataBound="rptAttendance_ItemDataBound">
<ItemTemplate>
<tr>
<td><asp:Label ID="lblEmpName" runat="server" /></td>
<asp:Repeater ID="rptAttendanceCode" runat="server" OnItemDataBound="rptAttendanceCode_ItemDataBound" >
<ItemTemplate><td><asp:Label ID="lblAttendanceCode" runat="server" /></td></ItemTemplate>
</asp:Repeater>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
后面的代码是
protected void Page_Load(object sender, EventArgs e)
{
}
public void search(object sender, EventArgs e)
{
string cnnString = "Server=localhost;Port=3307;Database=leavesystem;Uid=root;Pwd=ashish";
MySqlConnection cnx = new MySqlConnection(cnnString);
cnx.Open();
string cmdText1 = "SELECT DAY(LAST_DAY(CAST(CONCAT('" + year.Value + "', '-', MONTH(STR_TO_DATE('" + month.Value + "', '%M')), '-', 1) AS DATE))) ";
MySqlCommand cmd1 = new MySqlCommand(cmdText1, cnx);
MySqlDataAdapter adapter1 = new MySqlDataAdapter();
DataSet ds1 = new DataSet();
adapter1.SelectCommand = cmd1;
adapter1.Fill(ds1);
DataRow dr;
dr = ds1.Tables[0].Rows[0];
string value = dr[0].ToString();
string cmdText2 = "SELECT Dates from temp where Dates <= " + value + " ";
MySqlCommand cmd2 = new MySqlCommand(cmdText2, cnx);
MySqlDataAdapter adapter2 = new MySqlDataAdapter();
DataSet ds2 = new DataSet();
adapter2.SelectCommand = cmd2;
adapter2.Fill(ds2);
DataTable dt = ds2.Tables[0];
Repeater1.DataSource = dt;
Repeater1.DataBind();
string cmdText3 = "SELECT CalenderID, WorkingDays from calender where Year = '" + year.Value + "' and Month = '" + month.Value + "' ";
MySqlCommand cmd3 = new MySqlCommand(cmdText3, cnx);
MySqlDataAdapter adapter3 = new MySqlDataAdapter();
DataSet ds3 = new DataSet();
adapter3.SelectCommand = cmd3;
adapter3.Fill(ds3);
DataTable calender = ds3.Tables[0];
DataRow dr3;
dr3 = ds3.Tables[0].Rows[0];
string CalenderID = dr3[0].ToString();
string cmdText4 = "SELECT EmpID,EmpName from empinfo ";
MySqlCommand cmd4 = new MySqlCommand(cmdText4, cnx);
MySqlDataAdapter adapter4 = new MySqlDataAdapter();
DataSet ds4 = new DataSet();
adapter4.SelectCommand = cmd4;
adapter4.Fill(ds4);
DataTable employees = ds4.Tables[0];
string cmdText5 = "SELECT EmpID,DAY(LeaveDate) AS LeaveDayOfMonth from attendance where CalenderID = '" + CalenderID + "' ";
MySqlCommand cmd5 = new MySqlCommand(cmdText5, cnx);
MySqlDataAdapter adapter5 = new MySqlDataAdapter();
DataSet ds5 = new DataSet();
adapter5.SelectCommand = cmd5;
adapter5.Fill(ds5);
DataTable attendance = ds5.Tables[0];
List<Tuple<string, string[]>> info = new List<Tuple<string, string[]>>();
int calendarID = calender.Rows[0].Field<int>("CalenderID");
string days = calender.Rows[0].Field<string>("WorkingDays");
days = days.Replace("1", "P");
days = days.Replace("0", "H");
string[] daysList = days.Select(d => d.ToString()).ToArray();
int present = 0;
int holidays = 0;
for (int i = 0; i < daysList.Length; ++i)
{
if (daysList[i] == "P")
present++;
if (daysList[i] == "H")
holidays++;
}
int working = (monthdays - holidays);
string total = (present + "/" + working);
Tuple<string, string[],string> employeeAttendance = null;
foreach (DataRow employee in employees.Rows)
{
employeeAttendance = new Tuple<string, string[],string>(employee.Field<string>("EmpName"), daysList,total);
foreach (DataRow absentDay in attendance.AsEnumerable().Where(a => a.Field<int>("EmpID") == employee.Field<int>("EmpID")))
{
var leaveDay = absentDay.Field<Int64>("LeaveDayOfMonth");
int leaveDay1 = Convert.ToInt16(leaveDay);
leaveDay1 = leaveDay1 - 1;
employeeAttendance.Item2[leaveDay1] = "A";
}
info.Add(employeeAttendance);
}
this.rptAttendance.DataSource = info;
this.rptAttendance.DataBind();
}
protected void rptAttendance_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Tuple<string, string[],string> info = (Tuple<string, string[],string>)e.Item.DataItem;
((Label)e.Item.FindControl("lblEmpName")).Text = info.Item1;
((Label)e.Item.FindControl("lbltotal")).Text = info.Item3;
Repeater attendanceCode = (Repeater)e.Item.FindControl("rptAttendanceCode");
attendanceCode.DataSource = info.Item2;
attendanceCode.DataBind();
}
}
protected void rptAttendanceCode_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
((Label)e.Item.FindControl("lblAttendanceCode")).Text = e.Item.DataItem.ToString();
}
}
在后面的代码中,我得到该月的天数,然后将其与具有 31 个日期的表格进行比较,然后根据该逻辑,我显示我的数字,并在左下角使用中继器 2 显示我的 EmpID,现在在它们旁边的日期数字下方我想显示出席情况。有人可以告诉我如何做到这一点。我的出勤表中的 PresendtDays 列是空的,但我不知道如何使用它。请帮助我,我已经尝试了很多小时,这就是为什么我发布了我的完整代码,以便有人可以帮助我。寻求早期回应。提前致谢 !!