怎么把下面代码换成存储过程来处理?不会用那些declare呀之类的东西
我写的存储过程都是很简单那种的,刚项目经理说这样写以后维护起来不方便,郁闷,不懂写.
int pid = 0;
string pwd = "";
OutgoingWebResponseContext outgoingResponse = WebOperationContext.Current.OutgoingResponse;
outgoingResponse.Headers.Add("Cache-Control", "no-cache");
outgoingResponse.Headers.Add("Pragma", "no-cache");
DateTime now = DateTime.Now;
using (SqlDatabase db = new SqlDatabase())
{
//读取需考勤人员
if (Dekey.Eias.Security.SecurityManager.GetCurrentUserId() != 0)
{
Dekey.Eias.Security.User user = Dekey.Eias.Security.UserManager.Default.GetUser(Dekey.Eias.Security.SecurityManager.GetCurrentUserId());
if (user != null)
{
pid = user.UserID;
//pwd = user.Password;
}
}
//验证标识是否正确
db.CommandText = "SELECT COUNT(*) FROM [dk_Membership] WHERE [UserID] = @PID AND Status = 0";
db.CreateParameter<int>("@PID", pid, System.Data.SqlDbType.Int);
if ((int)db.ExecuteScalar() == 1)
{
//获取考勤参考时间
db.Parameters.Clear();
db.CommandText = "SELECT * FROM [dk_Attendance_Members] WHERE [MemberID] = @PID AND ([AttendanceType] = N'0' OR [AttendanceType] IS NULL)";
db.CreateParameter<int>("@PID", pid, System.Data.SqlDbType.Int);
using (DataReaderWrapper dr = db.ExecuteReader())
{
if (dr.Read())
{
DateTime checkInTimeStr = dr.GetDateTime("CheckInTime");
DateTime checkOutTimeStr = dr.GetDateTime("CheckOutTime");
dr.Close();
string today = now.ToString("yyyy-MM-dd");
//确定今天是否已有的考勤记录
db.Parameters.Clear();
db.CommandText = "SELECT CheckInTime, CheckOutTime FROM [dk_Attendance_Records] WHERE [MemberID] = @PID AND [AttendanceDate] = @Today";
db.CreateParameter<int>("@PID", pid, System.Data.SqlDbType.Int);
db.CreateParameter<string>("@Today", today, System.Data.SqlDbType.VarChar, 10);
bool hasRecord = false;
DateTime amTime = new DateTime();
DateTime pmTime = new DateTime();
using (DataReaderWrapper drw = db.ExecuteReader())
{
if (drw.Read())
{
//已有考勤记录,读取上下班的时间记录。
hasRecord = true;
amTime = drw.GetDateTime("CheckInTime");
pmTime = drw.GetDateTime("CheckOutTime");
}
}