/// <summary> /// IDをキーとして並び順・カテゴリIDを更新する /// </summary> /// <param name="logList">ログデータ</param> internal void UpdateTempOrderById(ObservableCollection <TempLogData> logList) { using (var database = new MyLogDatabase(Constants.DatabaseFile())) { try { database.Open(); database.BeginTrans(); var entity = new TempLogEntity(database); foreach (var data in logList) { if (data.IsCategory) { continue; } entity.ClearParams(); entity.AddParams(LogDetailEntity.Cols.Priority, data.Priority); entity.UpdateById(data.Id); } database.CommitTrans(); } catch (Exception ex) { database.RollbackTrans(); throw ex; } } }
/// <summary> /// Create Database File /// </summary> /// <param name="file">database file</param> public void CreateDatabase(string file = "") { if (0 == file.Length) { file = OsnCsLib.Common.Util.GetAppPath() + @"app.data"; } if (System.IO.File.Exists(file)) { this.BackupData(file); } else { using (var database = new MyLogDatabase(file)) { try { database.Open(); database.BeginTrans(); new CategoryEntity(database).Create(); new LogEntity(database).Create(); new LogDetailEntity(database).Create(); new TemplateEntity(database).Create(); new TemplateDetailEntity(database).Create(); database.CommitTrans(); } catch (Exception ex) { Message.ShowError(null, Message.ErrId.Err002, ex.Message); } } this.DatabaseFile = file; this.Save(); } }
/// <summary> /// IDをキーとしてテンプログを更新する /// </summary> /// <param name="id">ID</param> /// <param name="entity">エンティティ</param> private void UpdateLogDById(long id, TempLogEntity entity) { using (var database = new MyLogDatabase(Constants.DatabaseFile())) { try { database.Open(); database.BeginTrans(); entity.Database = database; entity.UpdateById(id); database.CommitTrans(); } catch (Exception ex) { database.RollbackTrans(); throw ex; } } }
/// <summary> /// IDをキーとして削除する /// </summary> /// <param name="id">ID</param> internal void DeleteTempLogById(long id) { using (var database = new MyLogDatabase(Constants.DatabaseFile())) { try { database.Open(); database.BeginTrans(); var entity = new TempLogEntity(database); entity.DeleteById(id); database.CommitTrans(); } catch (Exception ex) { database.RollbackTrans(); throw ex; } } }
/// <summary> /// テンプログの空行を作成する /// </summary> /// <param name="order">並び順</param> /// <returns></returns> internal TempLogData InsertEmptyTempLogRow(int order) { var result = new TempLogData(); using (var database = new MyLogDatabase(Constants.DatabaseFile())) { database.Open(); database.BeginTrans(); var entity = new TempLogEntity(database) { Priority = order }; result.Id = entity.Insert(); result.Priority = order; database.CommitTrans(); } return(result); }
/// <summary> /// テンプレート情報を更新する /// </summary> /// <param name="data">更新情報</param> /// <param name="isNew">true:新規、false:更新</param> /// <remarks>新規のケースもあるのでdelete → insertで処理を行う</remarks> internal void Update(TemplateData data, bool isNew) { using (var database = new MyLogDatabase(Constants.DatabaseFile())) { try { database.Open(); database.BeginTrans(); var headerEntity = new TemplateEntity(database); var detailEntity = new TemplateDetailEntity(database); // テンプレート情報(ヘッダ) headerEntity.Set(data); long id = data.Id; if (isNew) { id = headerEntity.Insert(); } else { headerEntity.Update(); } // テンプレート情報(明細) if (!isNew) { detailEntity.DeleteByTemplateId(id); } foreach (var detail in data.LogList) { if (detail.IsCategory) { continue; } detailEntity.Set(detail, id); detailEntity.Insert(); } database.CommitTrans(); } catch (Exception ex) { database.RollbackTrans(); throw ex; } } }
/// <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="categories">カテゴリ情報</param> internal void Update(ObservableCollection <CategoryData> categories) { using (var database = new MyLogDatabase(Constants.DatabaseFile())) { try { database.Open(); database.BeginTrans(); var entity = new CategoryEntity(database); foreach (var(category, index) in categories.Select((cateogry, index) => (cateogry, index))) { category.Priority = index; entity.Set(category); entity.UpdateById(category.Id); } database.CommitTrans(); } catch (Exception ex) { database.RollbackTrans(); throw ex; } } }
/// <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="logId">ログ情報ID</param> /// <param name="categoryId">カテゴリID</param> /// <param name="order">並び順</param> /// <returns></returns> internal LogDetailData InsertEmptyRow(long logId, long categoryId, int order) { var result = new LogDetailData(); using (var database = new MyLogDatabase(Constants.DatabaseFile())) { database.Open(); database.BeginTrans(); var entity = new LogDetailEntity(database) { LogId = logId, CategoryId = categoryId, Priority = order }; result.Id = entity.Insert(); result.LogId = logId; result.CategoryId = categoryId; result.Priority = order; database.CommitTrans(); } 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)); }