Esempio n. 1
0
        public async Task DisposeStudy()
        {
            ulong id = Context.User.Id;
            StudyTransactionResult result = await student.DisposeStudy(id);

            if (result == StudyTransactionResult.SUCESS)
            {
                await SendMsg("공부를 마쳤습니다. 공부시간: 없음");
            }
            else if (result == StudyTransactionResult.START_BEFORE_CLOSE)
            {
                await SendMsg($"공부를 일단 시작해야 합니다.");
            }
        }
Esempio n. 2
0
        public async Task FinishAndSave()
        {
            ulong id = Context.User.Id;
            StudyTransactionResult result = await student.FinishStudy(id);

            if (result == StudyTransactionResult.SUCESS)
            {
                await SendMsg("공부를 마쳤습니다.");
            }
            else if (result == StudyTransactionResult.START_BEFORE_CLOSE)
            {
                await SendMsg($"공부를 일단 시작해야 합니다..");
            }
        }
Esempio n. 3
0
        public async Task StartStudy([Remainder] string comment)
        {
            ulong id = Context.User.Id;
            StudyTransactionResult result = await student.BeginStudy(id, DateTimeOffset.Now, comment);

            if (result == StudyTransactionResult.SUCESS)
            {
                await SendMsg(comment + "공부를 시작했습니다");
            }
            else if (result == StudyTransactionResult.CLOSE_BEFORE_START)
            {
                string From = await student.ReadStudyTable <string>(id, "Start");
                await SendMsg($"이미 공부중입니다. ({From}-)");
            }
        }
Esempio n. 4
0
        public async Task <StudyTransactionResult> FinishStudy(ulong id)
        {
            await InitDB(id);

            StudyTransactionResult result = StudyTransactionResult.ERROR;

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

                SQLiteCommand checkIfStudying = new SQLiteCommand(
                    "SELECT Finish FROM StudyRecord WHERE ID=(SELECT MAX(ID) FROM StudyRecord);", con);
                bool isStarted = false;
                using (SQLiteDataReader studyingRd = (SQLiteDataReader)await checkIfStudying.ExecuteReaderAsync())
                {
                    while (await studyingRd.ReadAsync())
                    {
                        if (studyingRd["Finish"] == DBNull.Value)
                        {
                            isStarted = true;
                        }
                    }
                }
                if (isStarted)
                {
                    DateTimeOffset start    = DateTimeOffset.ParseExact(await ReadStudyTable <string>(id, "Start"), "yyyy/MM/dd HH:mm:ss", null);
                    DateTimeOffset finished = DateTimeOffset.Now;
                    TimeSpan       gap      = finished.Subtract(start);

                    SQLiteCommand write = new SQLiteCommand("UPDATE StudyRecord SET Finish=@finish, Span=@span " +
                                                            "WHERE ID=(SELECT MAX(ID) FROM StudyRecord);", con);
                    write.Parameters.AddWithValue("@finish", finished.ToString("yyyy/MM/dd HH:mm:ss"));
                    write.Parameters.AddWithValue("@span", gap.TotalSeconds);
                    await write.ExecuteNonQueryAsync();

                    studying--;
                    result = StudyTransactionResult.SUCESS;
                }
                else
                {
                    result = StudyTransactionResult.START_BEFORE_CLOSE;
                }
            }
            return(result);
        }
Esempio n. 5
0
        public async Task <StudyTransactionResult> BeginStudy(ulong id, DateTimeOffset start, string comment)
        {
            await InitDB(id);

            StudyTransactionResult result = StudyTransactionResult.ERROR;

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

                SQLiteCommand checkIfStudying = new SQLiteCommand(
                    "SELECT Finish FROM StudyRecord WHERE ID=(SELECT MAX(ID) FROM StudyRecord);", con);
                bool isStudying = false;
                using (SQLiteDataReader studyingRd = (SQLiteDataReader)await checkIfStudying.ExecuteReaderAsync())
                {
                    while (await studyingRd.ReadAsync())
                    {
                        if (studyingRd["Finish"] == DBNull.Value)
                        {
                            isStudying = true;
                        }
                    }
                }
                if (isStudying)
                {
                    result = StudyTransactionResult.CLOSE_BEFORE_START;
                }
                else
                {
                    SQLiteCommand command = new SQLiteCommand("INSERT INTO StudyRecord " +
                                                              "(Start, Comment) VALUES (@start, @comment);", con);
                    command.Parameters.AddWithValue("@start", start.ToString("yyyy/MM/dd HH:mm:ss"));
                    command.Parameters.AddWithValue("@comment", comment);
                    await command.ExecuteNonQueryAsync();

                    studying++;
                    result = StudyTransactionResult.SUCESS;
                }
            }
            return(result);
        }
Esempio n. 6
0
        public async Task <StudyTransactionResult> DisposeStudy(ulong id)
        {
            await InitDB(id);

            StudyTransactionResult result = StudyTransactionResult.ERROR;

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

                SQLiteCommand checkIfStudying = new SQLiteCommand(
                    "SELECT Finish FROM StudyRecord WHERE ID=(SELECT MAX(ID) FROM StudyRecord);", con);
                bool isStarted = false;
                using (SQLiteDataReader studyingRd = (SQLiteDataReader)await checkIfStudying.ExecuteReaderAsync())
                {
                    while (await studyingRd.ReadAsync())
                    {
                        if (studyingRd["Finish"] == DBNull.Value)
                        {
                            isStarted = true;
                        }
                    }
                }
                if (isStarted)
                {
                    SQLiteCommand command = new SQLiteCommand("DELETE FROM StudyRecord WHERE ID=(SELECT MAX(ID) FROM StudyRecord);", con);
                    await command.ExecuteNonQueryAsync();

                    studying--;
                    result = StudyTransactionResult.SUCESS;
                }
                else
                {
                    result = StudyTransactionResult.START_BEFORE_CLOSE;
                }
            }
            return(result);
        }