示例#1
0
    private AttendanceInfo BuildEntity()
    {
        AttendanceInfo attendance = new AttendanceInfo();
        attendance.ID = GetFormInteger("id");
        attendance.UserID = Request.Form["userId"];
        attendance.Date = Request.Form["date"];
        attendance.Duration = Convert.ToDecimal(Request.Form["duration"]);
        attendance.InWell = Request.Form["inWell"] == "true";
        attendance.NightWork = GetFormInteger("nightWork");

        return attendance;
    }
示例#2
0
        public static int Add(AttendanceInfo attendance, bool checkDuplication = true)
        {
            SqlParameter[] parameters = new SqlParameter[6];
            parameters[0] = new SqlParameter("@UserID", SqlDbType.VarChar, 6);
            parameters[0].Value = attendance.UserID;
            parameters[1] = new SqlParameter("@Date", SqlDbType.VarChar, 20);
            parameters[1].Value = attendance.Date;
            parameters[2] = new SqlParameter("@Duration", SqlDbType.Decimal);
            parameters[2].Value = attendance.Duration;
            parameters[3] = new SqlParameter("@InWell", SqlDbType.Int);
            parameters[3].Value = attendance.InWell ? 1:0;
            parameters[4] = new SqlParameter("@NightWork", SqlDbType.Int);
            parameters[4].Value = attendance.NightWork;
            parameters[5] = new SqlParameter("@Approved", SqlDbType.Int);
            parameters[5].Value = attendance.Approved ? 1 : 0;

            StringBuilder sql = new StringBuilder();
            if (checkDuplication) {
                sql.AppendLine("DECLARE @ID int");
                sql.AppendLine("IF EXISTS(SELECT * FROM AttendanceMng WHERE userId = @UserID AND DATE = @Date) BEGIN");
                sql.AppendLine("	SET @ID = 0");
                sql.AppendLine("END");
                sql.AppendLine("ELSE BEGIN");
                sql.AppendLine("	INSERT INTO AttendanceMng (userId, DATE, workDurs, ifIn, nightWork, state)");
                sql.AppendLine("	VALUES (@UserID, @Date, @Duration, @InWell, @NightWork, @Approved)");
                sql.AppendLine("	SET @ID = SCOPE_IDENTITY()");
                sql.AppendLine("END");
                sql.AppendLine("SELECT @ID");
            }
            else {
                sql.AppendLine("DECLARE @ID int");
                sql.AppendLine("INSERT INTO AttendanceMng (userId, DATE, workDurs, ifIn, nightWork, state)");
                sql.AppendLine("VALUES (@UserID, @Date, @Duration, @InWell, @NightWork, @Approved)");
                sql.AppendLine("SET @ID = SCOPE_IDENTITY()");
                sql.AppendLine("SELECT @ID");
            }
            int newID = (int)helper.ExecuteScalar(sql.ToString(), parameters);
            return newID;
        }
示例#3
0
        public static bool Update(AttendanceInfo attendance)
        {
            SqlParameter[] parameters = new SqlParameter[5];
            parameters[0] = new SqlParameter("@Date", SqlDbType.VarChar, 20);
            parameters[0].Value = attendance.Date;
            parameters[1] = new SqlParameter("@Duration", SqlDbType.Decimal);
            parameters[1].Value = attendance.Duration;
            parameters[2] = new SqlParameter("@InWell", SqlDbType.Int);
            parameters[2].Value = attendance.InWell ? 1 : 0;
            parameters[3] = new SqlParameter("@NightWork", SqlDbType.Int);
            parameters[3].Value = attendance.NightWork;
            parameters[4] = new SqlParameter("@ID", SqlDbType.Int);
            parameters[4].Value = attendance.ID;

            StringBuilder sql = new StringBuilder();
            sql.AppendLine("UPDATE AttendanceMng SET DATE = @Date, workDurs = @Duration, ifIn = @InWell, nightWork = @NightWork");
            sql.AppendLine("WHERE ID = @ID");
            int rowCount = helper.ExecuteNonQuery(sql.ToString(), parameters.ToArray());
            return rowCount > 0;
        }
示例#4
0
 public static int Save(AttendanceInfo attendance, bool checkDuplication = true)
 {
     int id;
     if (attendance.ID <= 0) {
         id = AttendanceDao.Add(attendance, checkDuplication);
     }
     else {
         id = AttendanceDao.Update(attendance) ? attendance.ID : 0;
     }
     return id;
 }