Ejemplo n.º 1
0
        /// <summary>
        /// Create a study record from <see cref="DicomDataset"/>.
        /// </summary>
        /// <param name="dcmData"><see cref="DicomDataset"/></param>
        /// <returns>Study record <see cref="{DataModel.StudyRecord}"/></returns>
        public static StudyRecord CreateStudy(this DicomDataset dcmData)
        {
            string studyUID = dcmData.GetString(DicomTag.StudyInstanceUID);
            var    record   = new StudyRecord(studyUID);                  // 1

            record.StudyID     = dcmData.GetString(DicomTag.StudyID);     // 2
            record.PatientName = dcmData.GetString(DicomTag.PatientName); // 3

            string dcmDate = null;

            dcmDate = dcmData.GetString(DicomTag.StudyDate);
            string dcmTime = null;

            dcmTime         = dcmData.GetString(DicomTag.StudyTime);
            record.DateTime = CombineDateTime(dcmDate, dcmTime);            // 4

            record.PatientID = dcmData.GetString(DicomTag.PatientID);       // 5

            string sex = dcmData.GetString(DicomTag.PatientSex);

            record.PatientSex = (int)DcmConvert.GetPatientSex(sex);                 // 6

            record.PatientAge       = dcmData.GetString(DicomTag.PatientAge);       // 7
            record.Modality         = dcmData.GetString(DicomTag.Modality);         // 8
            record.StudyDescription = dcmData.GetString(DicomTag.StudyDescription); // 9

            return(record);
        }
Ejemplo n.º 2
0
 private void InitData()
 {
     if (Chapter != null)
     {
         //尝试获取该课程章节的学习记录
         Record = StudyRecordAccessor.GetStudyRecord(StudentId, Chapter.ChapterId);
         ID     = Record != null ? Record.RecordId : IDProvider.NewId;
     }
 }
Ejemplo n.º 3
0
 public vStudyRecord(StudyRecord model)
 {
     this.ID = model.ID;
     this.LessionID = model.ID;
     this.Lession = model.Lession;
     this.UserID = model.UserID;
     this.User = model.User ;
     this.Time = Helpers.Time.ToTimeTip(model.Time);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取用户针对指定课程章节的学习记录
        /// </summary>
        /// <param name="userId">用户ID</param>
        /// <param name="chapterId">课程章节ID</param>
        /// <returns></returns>
        public static StudyRecord GetStudyRecord(long userId, long chapterId)
        {
            StudyRecord record = null;

            using (var db = new DataContext())
            {
                record = (from p in db.StudyRecord
                          where p.UserId == userId && p.ChapterId == chapterId
                          select p).FirstOrDefault();
            }

            return(record);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 添加学习记录
        /// </summary>
        /// <returns></returns>
        private bool Add()
        {
            var record = new StudyRecord
            {
                RecordId   = ID,
                UserId     = StudentId,
                CourseId   = Chapter.CourseId,
                ChapterId  = Chapter.ChapterId,
                ReadCount  = 1,
                CreateTime = DateTime.Now,
                UpdateTime = DateTime.Now
            };

            return(StudyRecordAccessor.Insert(record));
        }
Ejemplo n.º 6
0
 void rptContents_ItemDataBound(object sender, RepeaterItemEventArgs e)
 {
     if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
     {
         var tbId            = (Literal)e.Item.FindControl("tbId");
         var tbName          = (Literal)e.Item.FindControl("tbName");
         var tbState         = (Literal)e.Item.FindControl("tbState");
         var tbLastStudyTime = (Literal)e.Item.FindControl("tbLastStudyTime");
         var studyInfo       = new StudyRecord(e.Item.DataItem);
         tbId.Text            = studyInfo.Id.ToString();
         tbName.Text          = studyInfo.UserName;
         tbState.Text         = studyInfo.StudyState == 0?"未完成":"已完成";
         tbLastStudyTime.Text = studyInfo.LastStudyTime.ToString();
     }
 }
Ejemplo n.º 7
0
            public async Task TodayRecord()
            {
                ulong id = Context.User.Id;
                Dictionary <DateTimeOffset, StudyRecord> records = await student.GetStudyTime(id);

                StudyRecord record = records.GetValueOrDefault(DateTimeOffset.Now.Date);

                if (record == null)
                {
                    await SendMsg("오늘 공부한 기록이 없습니다.");
                }
                else
                {
                    await SendMsg($"오늘 {TimeFormat.SpanToProper(record.span)} 공부했습니다.");
                }
            }
Ejemplo n.º 8
0
        /// <summary>
        /// 插入一条用户学习记录
        /// </summary>
        /// <param name="record"></param>
        /// <returns></returns>
        public static bool Insert(StudyRecord record)
        {
            if (record == null)
            {
                return(false);
            }

            bool success = false;

            using (var db = new DataContext())
            {
                db.StudyRecord.Add(record);

                success = db.SaveChanges() > 0;
            }

            return(success);
        }
Ejemplo n.º 9
0
        public async Task <Dictionary <DateTimeOffset, StudyRecord> > GetStudyTime(ulong id)
        {
            await InitDB(id);

            Dictionary <DateTimeOffset, StudyRecord> record = new Dictionary <DateTimeOffset, StudyRecord>();

            using (SQLiteConnection con = new SQLiteConnection($"Data Source={DB_LOCATION + id}.db;Version=3;"))
            {
                await con.OpenAsync();

                SQLiteCommand    command = new SQLiteCommand("SELECT Start, Finish, Span, Comment FROM StudyRecord;", con);
                SQLiteDataReader reader  = (SQLiteDataReader)await command.ExecuteReaderAsync();

                while (await reader.ReadAsync())
                {
                    //Republic of Korea, UTC+9
                    DateTimeOffset at = new DateTimeOffset(
                        (
                            DateTimeOffset.ParseExact(reader["Start"].ToString(), "yyyy/MM/dd HH:mm:ss", null).Ticks +
                            DateTimeOffset.ParseExact(reader["Finish"].ToString(), "yyyy/MM/dd HH:mm:ss", null).Ticks
                        ) / 2, new TimeSpan(9, 0, 0)).Date;
                    List <string> commt = new List <string>();
                    commt.Add(reader["Comment"].ToString());
                    StudyRecord rec = new StudyRecord()
                    {
                        comment = commt,
                        span    = TimeSpan.FromSeconds((long)reader["Span"])
                    };

                    if (record.ContainsKey(at))
                    {
                        record[at] = record[at] + rec;
                    }
                    else
                    {
                        record.Add(at, rec);
                    }
                }
            }
            return(record);
        }
Ejemplo n.º 10
0
            private async Task <TimeSpan> GetSpanOfRange(Range range)
            {
                ulong id = Context.User.Id;
                Dictionary <DateTimeOffset, StudyRecord> records = await student.GetStudyTime(id);

                DateTimeOffset today = DateTimeOffset.Now;
                StudyRecord    sum   = new StudyRecord()
                {
                    comment = new List <string>(),
                    span    = TimeSpan.FromSeconds(0)
                };

                switch (range)
                {
                case Range.WEEK:
                    int            diff        = (7 + (today.DayOfWeek - DayOfWeek.Monday)) % 7;
                    DateTimeOffset BeginOfWeek = today.AddDays(-1 * diff).Date;
                    for (int i = 0; i < 7; i++)
                    {
                        if (BeginOfWeek.CompareTo(today) > 0)
                        {
                            break;
                        }
                        StudyRecord dayRecord = records.GetValueOrDefault(BeginOfWeek);
                        BeginOfWeek.AddDays(1);
                        if (dayRecord == null)
                        {
                            continue;
                        }
                        sum += dayRecord;
                    }
                    break;

                case Range.MONTH:
                    DateTimeOffset date            = DateTimeOffset.Now;
                    DateTimeOffset firstDayOfMonth = new DateTime(date.Year, date.Month, 1).Date;
                    DateTimeOffset lastDayOfMonth  = firstDayOfMonth.AddMonths(1).AddDays(-1).Date;
                    do
                    {
                        if (records.ContainsKey(firstDayOfMonth))
                        {
                            sum += records[firstDayOfMonth];
                        }
                        firstDayOfMonth = firstDayOfMonth.AddDays(1);
                    } while (firstDayOfMonth.CompareTo(lastDayOfMonth) <= 0 && firstDayOfMonth.CompareTo(today) <= 0);
                    break;

                case Range.YEAR:
                    DateTimeOffset firstDayOfYear = new DateTime(today.Year, 1, 1).Date;
                    DateTimeOffset lastDayOfYear  = firstDayOfYear.AddYears(1).AddDays(-1).Date;
                    do
                    {
                        if (records.ContainsKey(firstDayOfYear))
                        {
                            sum += records[firstDayOfYear];
                        }
                        firstDayOfYear = firstDayOfYear.AddDays(1);
                    } while (firstDayOfYear.CompareTo(lastDayOfYear) <= 0 && firstDayOfYear.CompareTo(today) <= 0);
                    break;

                case Range.TOTAL:
                    foreach (StudyRecord rec in records.Values)
                    {
                        sum += rec;
                    }
                    break;

                default:
                    throw new ArgumentException($"Unexpected range: {range}");
                }
                return(sum.span);
            }