/// <summary> /// 空のログを作成する /// </summary> /// <param name="recordedOn">記録日</param> /// <returns>空のログデータ</returns> internal LogData CreateEmptyLog(string recordedOn) { var result = new LogData() { LogList = new ObservableCollection <LogDetailData>() }; using (var database = new MyLogDatabase(Constants.DatabaseFile())) { try { database.Open(); var categoryEntity = new CategoryEntity(database); var categories = new Dictionary <long, string>(); using (var recset = categoryEntity.Select()) { while (recset.Read()) { if (!recset.GetBool(CategoryEntity.Cols.Visible)) { continue; } result.LogList.Add(new LogDetailData() { CategoryId = recset.GetLong(CategoryEntity.Cols.Id), CategoryName = recset.GetString(CategoryEntity.Cols.Name), IsCategory = true }); } } database.BeginTrans(); var logEntity = new LogEntity(database) { RecordedOn = recordedOn }; result.Id = logEntity.Insert(); database.CommitTrans(); } catch (Exception ex) { database.RollbackTrans(); throw ex; } } return(result); }
/// <summary> /// ログ情報(ヘッダ)を作成する /// </summary> /// <param name="recordedOn">記録日</param> /// <returns>ID</returns> internal long InsertHeader(string recordedOn) { long result; using (var database = new MyLogDatabase(Constants.DatabaseFile())) { try { database.Open(); database.BeginTrans(); var entity = new LogEntity(database) { RecordedOn = recordedOn }; result = entity.Insert(); database.CommitTrans(); } catch (Exception ex) { database.RollbackTrans(); throw ex; } } return(result); }
/// <summary> /// テンプレートからログを作成する。 /// </summary> /// <param name="templateId">テンプレートID</param> /// /// <param name="recordedOn">日付</param> /// <returns></returns> internal LogData CreateLogByTemplateId(long templateId, string recordedOn) { using (var database = new MyLogDatabase(Constants.DatabaseFile())) { database.Open(); try { database.BeginTrans(); var logEntity = new LogEntity(database) { RecordedOn = recordedOn }; var id = logEntity.Insert(); var templateDetailEntity = new TemplateDetailEntity(database); templateDetailEntity.InsertToLog(templateId, id); database.CommitTrans(); } catch (Exception ex) { database.RollbackTrans(); throw ex; } } return(this.SelectByRecordedOn(recordedOn)); }