请大家帮忙看看,谢谢
WEB层代码:
foreach(DataGridItem item in this.DataGrid1.Items)
{
row = table.NewRow();
row["ProjectID"]= item.Cells[7].Text.Trim();
row["NodeID"] =item.Cells[8].Text.Trim();
row["TS_Rtime"] =((Lion.Data.Library.Calendar)item.Cells[3].Controls[1]).DateTime;
row["WorkTime"] =((TextBox)item.Cells[4].Controls[1]).Text.Trim();
row["OverTime"] =((TextBox)item.Cells[5].Controls[1]).Text.Trim();
row["TS_Comment"] =((TextBox)item.Cells[6].Controls[1]).Text.Trim();
row["Res_ID"] =item.Cells[9].Text.Trim();
// row["EditorID"] =item.Cells[10].Text.Trim();
// row["EditTime"] =item.Cells[11].Text.Trim();//在BIZ层设值
DateTime TS_Rtime=Convert.ToDateTime(row["TS_Rtime"].ToString());
DateTime CurDateTime=System.DateTime.Now;
DateTime PastTime=CurDateTime.AddDays(-7);
float sum1=0;
if(DateTime.Compare(TS_Rtime,PastTime)<0||DateTime.Compare(TS_Rtime,CurDateTime)>0)//判断提交日期是否在七日之内
{
this.RegisterStartupScript("alert","<script>alert('您只能提交此前七日内的工时记录!');</script>");
return;
}
else
{
if((row["WorkTime"].ToString()=="")&&(row["OverTime"].ToString()=="")) //正常工时和加班工时同时为空时不写入数据库
{ }
else
{
tS_Rtime=((Lion.Data.Library.Calendar)item.Cells[3].Controls[1]).DateTime;//定义tS_Rtime
if(row["WorkTime"].ToString()=="")
{
workTime=0;
}
else
{
//workTime=Convert.ToSingle(((TextBox)item.Cells[4].Controls[1]).Text.Trim()); //正常工时累计
sum1+=Convert.ToSingle(((TextBox)item.Cells[4].Controls[1]).Text.Trim()); / /将这一列多行值相加,为什么还是只能返回第一行的值????
workTime=sum1; 将这一列值的总和赋给worktime,传到DAO层做判断
}
if(row["OverTime"].ToString()=="")
{
overTime=0;
}
else
{
overTime=Convert.ToSingle(((TextBox)item.Cells[5].Controls[1]).Text.Trim()); //加班工时累计
}
// if(tS.JudgeWorkWeekend(tS_Rtime)) //判断正常工作的周末
// {
// this.RegisterStartupScript("alert","<script>alert('请按正常工作日提交今天的工时记录!');</script>");
// }
//
// if(tS.JudgeSpecialHoliday(tS_Rtime)) //判断特殊节假日(法定假日和调休周末)
// {
// //this.RegisterStartupScript("alert","<script>alert('请按正常工作日提交今天的工时记录!');</script>");
// overTime=workTime+overTime;
// workTime=0;
// }
if(tS.JudgeWorkingHours(tS_Rtime,workTime,overTime)) //判断工时限制:workTime<=8,overTime<=24,并且workTime+overTime<=24
{
table.Rows.Add(row);
countRows+= 1;
}
else
{
this.RegisterStartupScript("alert","<script>alert('本工时或总工时数已超过正常范围!');</script>");
}
}
}
}
tS.AddTimeSheetsList(table); //传递页面信息
if (countRows==0) //如果workTime,overTime同时为空,给出提示
{
this.RegisterStartupScript("alert","<script>alert('您必须填写正常工时或加班工时信息!');</script>");
}
if(countRows>0)
{
Response.Write("<script language=javascript>alert('保存成功!');</script>");
}
else
{Response.Write("<script language=javascript>alert('保存失败!');</script>");}
BindGrid();
}
对应的BIZ层代码:
public void AddTimeSheetsList(DataTable table)
{
foreach(DataRow row in table.Rows)
{tS.AddTimeSheetsList(Convert.ToInt32(row[0]),Convert.ToInt32(row[1]),Convert.ToDateTime(row[2]),Convert.ToSingle(row[3]),Convert.ToSingle(row[4]),Convert.ToString(row[5]),Convert.ToInt32(row[6]));}
}
DAO层的判断代码
//判断工时限制:workTime<=8,overTime<=24,并且workTime+overTime<=24
public bool JudgeWorkingHours(DateTime tS_Rtime,float workTime,float overTime)
{
float Value1,Value2;
try
{
int day = tS_Rtime.Day;
int mon = tS_Rtime.Month;
int year = tS_Rtime.Year;
string sql1 = "Select isNull(sum(WorkTime),0) From TimeSheets where day(TS_Rtime)= "+day +"and month(TS_Rtime)="+mon +"and year(TS_Rtime)="+year;
Value1 = Convert.ToSingle(DB.ReturnValue(sql1))+ workTime;
string sql2 = "Select isNull(sum(OverTime),0) From TimeSheets where day(TS_Rtime)= "+day +"and month(TS_Rtime)="+mon +"and year(TS_Rtime)="+year;
Value2 = Convert.ToSingle(DB.ReturnValue(sql2))+ overTime;
//判断
if (( Value1 <=8.0) && (Value2 <=24.0)&&(Value1+Value2<=24.0))
{
return(true);
}
else
{
return (false);
}
}
catch
{
return (false);
}
}