Skip to content

Commit

Permalink
添加签到
Browse files Browse the repository at this point in the history
  • Loading branch information
henleygao committed Dec 1, 2011
1 parent 0b47f25 commit 2b67ef0
Show file tree
Hide file tree
Showing 13 changed files with 267 additions and 27 deletions.
73 changes: 73 additions & 0 deletions SMS.Services/AttendanceManagement/AddAttendanceProcessor.cs
@@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SMS.Services.Entities;
using Youmay.Exceptions;
using Youmay.Services.Utils;
using NHibernate.Linq;
using SMS.Services.Enum;

namespace SMS.Services.AttendanceManagement
{
public class AddAttendanceProcessor
{
private ExecuteContext context;

public AddAttendanceProcessor(ExecuteContext context)
{
this.context = context;
}

public int Execute(AttendanceAddView view)
{
var student = LogicUtils.NotNull(context.Session.Get<Student>(context.OperatorInfo.OperatorId));
var lesson = LogicUtils.NotNull(context.Session.Get<Lesson>(context.OperatorInfo.OperatorId));

DateTime start = lesson.TakeClassDate;
DateTime end = lesson.TakeClassDate;

switch (lesson.LessonType)
{
case LessonType.Morning:
start = new DateTime(start.Year, start.Month, start.Day, 10, 0, 0);
end = new DateTime(start.Year, start.Month, start.Day, 11, 0, 0);
break;
case LessonType.Afternoon1:
start = new DateTime(start.Year, start.Month, start.Day, 12, 0, 0);
end = new DateTime(start.Year, start.Month, start.Day, 14, 0, 0);
break;
case LessonType.Afternoon2:
start = new DateTime(start.Year, start.Month, start.Day, 14, 0, 0);
end = new DateTime(start.Year, start.Month, start.Day, 16, 0, 0);
break;
case LessonType.Evening:
start = new DateTime(start.Year, start.Month, start.Day, 20, 0, 0);
end = new DateTime(start.Year, start.Month, start.Day, 22, 0, 0);
break;
default:
break;
}

if (lesson.TakeClassDate < start.AddMinutes(-15) || lesson.TakeClassDate > end)
throw new AttendanceException(AttendanceExceptionType.NotAttendanceTime);

var attendace = new Attendance()
{
Student = student,
Lesson = lesson,
AttendanceType = view.AttendanceType,
AttendanceDateTime = DateTime.Now,
Remark = view.Remark
};

using (var scope = context.Session.RequestTransaction())
{
context.Session.Save(attendace);
scope.Commit();
}
return attendace.Id;
}

}
}
17 changes: 17 additions & 0 deletions SMS.Services/AttendanceManagement/AttendanceAddView.cs
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SMS.Services.Enum;

namespace SMS.Services.AttendanceManagement
{
public class AttendanceAddView
{
public int LessonId { get; set; }

public AttendanceType AttendanceType { get; set; }

public string Remark { get; set; }
}
}
18 changes: 18 additions & 0 deletions SMS.Services/AttendanceManagement/AttendanceException.cs
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SMS.Services.Enum;

namespace SMS.Services.AttendanceManagement
{
public class AttendanceException : Exception
{
public AttendanceExceptionType Type { get; set; }

public AttendanceException(AttendanceExceptionType type)
{
this.Type = type;
}
}
}
11 changes: 11 additions & 0 deletions SMS.Services/Entities/Attendance.cs
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SMS.Services.Enum;

namespace SMS.Services.Entities
{
Expand All @@ -22,10 +23,20 @@ public class Attendance
/// </summary>
public virtual Student Student { get; set; }

/// <summary>
/// 出勤类型
/// </summary>
public virtual AttendanceType AttendanceType { get; set; }

/// <summary>
/// 出勤时间
/// </summary>
public virtual DateTime? AttendanceDateTime { get; set; }

/// <summary>
/// 原因
/// </summary>
public virtual string Remark { get; set; }

}
}
15 changes: 15 additions & 0 deletions SMS.Services/Enum/AttendanceExceptionType.cs
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SMS.Services.Enum
{
public enum AttendanceExceptionType
{
/// <summary>
/// 不是出勤时间,不能出勤
/// </summary>
NotAttendanceTime
}
}
23 changes: 23 additions & 0 deletions SMS.Services/Enum/AttendanceType.cs
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SMS.Services.Enum
{
public enum AttendanceType
{

/// <summary>
/// 到达
/// </summary>
Arrive,


/// <summary>
/// 请假
/// </summary>
AskOff,

}
}
5 changes: 5 additions & 0 deletions SMS.Services/SMS.Services.csproj
Expand Up @@ -64,6 +64,9 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AppContext.cs" />
<Compile Include="AttendanceManagement\AddAttendanceProcessor.cs" />
<Compile Include="AttendanceManagement\AttendanceAddView.cs" />
<Compile Include="AttendanceManagement\AttendanceException.cs" />
<Compile Include="Auth\AuthQueries.cs" />
<Compile Include="Auth\LoginProcessor.cs" />
<Compile Include="Auth\LoginException.cs" />
Expand All @@ -87,6 +90,8 @@
<Compile Include="Entities\Course.cs" />
<Compile Include="Entities\Student.cs" />
<Compile Include="Entities\Teacher.cs" />
<Compile Include="Enum\AttendanceExceptionType.cs" />
<Compile Include="Enum\AttendanceType.cs" />
<Compile Include="Enum\ClassSortType.cs" />
<Compile Include="Enum\Gender.cs" />
<Compile Include="Enum\LessonSortType.cs" />
Expand Down
55 changes: 55 additions & 0 deletions SMS.Web/Controllers/AttendanceController.cs
@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SMS.Services;
using SMS.Web.Models;
using SMS.Web.Models.Attendance;
using SMS.Services.AttendanceManagement;
using SMS.Web.Common;

namespace SMS.Web.Controllers
{
public class AttendanceController : ManagementController
{
private Repository repository;

private ProcessorManager manager;

public AttendanceController(Repository repository, ProcessorManager manager)
{
this.repository = repository;
this.manager = manager;
}

public ActionResult Index()
{
return View();
}

[HttpPost]
public ActionResult Create(CreateForm form)
{
if (ModelState.IsValid)
{
try
{
var processor = manager.Create<AddAttendanceProcessor>();
processor.Execute(ConvertTo<AttendanceAddView>(form));

ViewSuccessMessage("签到成功");

}
catch (AttendanceException e)
{
if (e.Type == Services.Enum.AttendanceExceptionType.NotAttendanceTime)
ViewErrorMessage("现在不是上课时间,不能签到");
}
}

return AjaxJson();
}

}
}
2 changes: 2 additions & 0 deletions SMS.Web/Controllers/ClassLessonController.cs
Expand Up @@ -29,5 +29,7 @@ public ClassLessonController(Repository repository, ProcessorManager manager)
return View(new IndexViewModel(manager.Create<ListClassLessonProcessor>().Execute(id.Value)));
}



}
}
17 changes: 17 additions & 0 deletions SMS.Web/Models/Attendance/CreateForm.cs
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SMS.Services.Enum;

namespace SMS.Web.Models.Attendance
{
public class CreateForm
{
public int LessonId { get; set; }

public AttendanceType AttendanceType { get; set; }

public string Remark { get; set; }
}
}
2 changes: 2 additions & 0 deletions SMS.Web/SMS.Web.csproj
Expand Up @@ -156,6 +156,7 @@
<Compile Include="Common\LogErrorAttribute.cs" />
<Compile Include="Common\ManagementController.cs" />
<Compile Include="Common\MasterInfo.cs" />
<Compile Include="Controllers\AttendanceController.cs" />
<Compile Include="Controllers\AuthController.cs" />
<Compile Include="Controllers\ClassController.cs" />
<Compile Include="Controllers\ClassLessonController.cs" />
Expand All @@ -166,6 +167,7 @@
<Compile Include="Global.asax.cs">
<DependentUpon>Global.asax</DependentUpon>
</Compile>
<Compile Include="Models\Attendance\CreateForm.cs" />
<Compile Include="Models\Auth\LoginForm.cs" />
<Compile Include="Models\ClassLesson\IndexViewModel.cs" />
<Compile Include="Models\Class\CreateForm.cs" />
Expand Down
26 changes: 25 additions & 1 deletion SMS.Web/Views/ClassLesson/Index.cshtml
Expand Up @@ -3,6 +3,29 @@
课表
}
@section SiteHead{
<script type="text/javascript">
$(document).ready(function () {
$(".sign-in").click(function () {
var self = $(this);
var lessonId = self.attr("val");
$.ajax({
type: "POST",
url: '@Url.Action("Create", "Attendance", new { AttendanceType = SMS.Services.Enum.AttendanceType.Arrive })',
data: "LessonId=" + lessonId,
success: function (data) {
alert(data.ErrorMessages.join("\n") + data.ModelErrors.join("\n"));
}
});
});
});
</script>
}
@section SiteMap{
课表
Expand Down Expand Up @@ -57,7 +80,8 @@
@Model.ClassLessons[start + j].Name
<br />
@Model.ClassLessons[start + j].TakeClassDate.ToString("yyyy年MM月dd日 ddd")
</span>
<br />
<a class="sign-in" val="@Model.ClassLessons[start + j].Id" href="#">签到</a> </span>
}
</td>
}
Expand Down
30 changes: 4 additions & 26 deletions SMS.Web/Web.config
Expand Up @@ -14,33 +14,11 @@
<add key="CustomerAttachmentMaxSize" value="2097152"/>
<add key="CustomerAttachmentTypes" value=".*"/>

<add key="UploadRootPath" value="D:\\wwwpub\FCSS\Upload" />
<add key="FtpUserName" value="ym"/>
<add key="FtpPassword" value="123456"/>
<add key="webpages:Version" value="1.0.0.0" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="DefaultPassword" value="8888" />
<add key="ListRecordCount" value="5"/>
<add key="ProjectContractExtension" value="E"/>
<add key="LessonType.Morning" value="10:00-11:00" />
<add key="LessonType.Afternoon1" value="12:00-14:00" />
<add key="LessonType.Afternoon2" value="14:00-16:00" />
<add key="LessonType.Evening" value="20:00-22:00" />

<add key="AdminPrivilege" value="262143"/>
<add key="CustomerServicePrivilege" value="260496"/>
<add key="ManagementerPrivilege" value="261534"/>
<add key="AssistantPrivilege" value="250879"/>
<add key="SubcontractorPrivilege" value="63872"/>

<add key="IsssueShutDownTime" value="7"/>
<add key="Domain" value="http://st002:1007/" />
<add key="AdminDomain" value="http://st002:1007/Admin/" />
<add key="AdministratorAccount" value="admin"/>
<add key="Version" value="1.0"/>
<!--Email落款人名称-->
<add key="Sign" value="FCSS-FUJITSU"/>
<!--Email落款人地址-->
<add key="SignEmailAddress" value="FCSS@homs-fujitsu.com"/>
<!--底部滚动信息-->
<add key="RollingInformation" value="可以设置了,配置文件里面 /底部滚动信息/ 里面设置即可。 "/>
</appSettings>
<connectionStrings>
<add name="connection_string" connectionString="Database=sms;Data Source=localhost;User Id=root;Password=123456" />
Expand Down

0 comments on commit 2b67ef0

Please sign in to comment.