/// <summary> /// 農薬内容削除コールバック /// </summary> private void DeletePesticideContent() { if (0 == WorkContent.Id) { WorkContent.PesticideContents.RemoveAt(selectedPesticideContentIndex); } else { if (false == PesticideContent.DeleteDbRecord()) { MessageBox.Show("IDに不備があります"); return; } WorkContent.PesticideContents = new ObservableCollection <PesticideContent>(DataBaseManager.DBManager.GetPesticideContents(WorkContent.Id)); } PesticideContent = new PesticideContent(); }
/// <summary> /// 農薬内容更新コールバック /// </summary> private void UpdatePesticideContent() { PesticideContent.PestcideMaster = new PesticideMaster(PesticideMaster); PesticideContent.PesticideId = PesticideContent.PestcideMaster.Id; if (0 == WorkContent.Id) { WorkContent.PesticideContents[selectedPesticideContentIndex] = new PesticideContent(PesticideContent); } else { if (false == PesticideContent.UpdateDbRecord()) { MessageBox.Show("入力情報に不備があります"); return; } WorkContent.PesticideContents = new ObservableCollection <PesticideContent>(DataBaseManager.DBManager.GetPesticideContents(WorkContent.Id)); } PesticideContent = new PesticideContent(); }
/// <summary> /// 農薬内容登録コールバック /// </summary> private void RegisterPesticideContent() { PesticideContent.PestcideMaster = new PesticideMaster(PesticideMaster); PesticideContent.PesticideId = PesticideContent.PestcideMaster.Id; // 既存データの有無により対応を変更 if (0 == WorkContent.Id) { WorkContent.PesticideContents.Add(new PesticideContent(PesticideContent)); } else { PesticideContent.WorkContentId = WorkContent.Id; if (false == PesticideContent.RegisterDbRecord()) { MessageBox.Show("入力情報に不備があります"); return; } WorkContent.PesticideContents = new ObservableCollection <PesticideContent>(DataBaseManager.DBManager.GetPesticideContents(WorkContent.Id)); } PesticideContent = new PesticideContent(); }
/// <summary> /// 農薬マスタ更新コールバック /// </summary> private void UpdatePesticideMaster() { if (false == RegisterPesticide.UpdateDbRecord()) { MessageBox.Show("入力情報に不備があります"); return; } // バッファで保持している項目がある場合は、DB更新のタイミングで保持している内容を変更する List <PesticideContent> tmp = new List <PesticideContent>(); foreach (PesticideContent pc in WorkContent.PesticideContents) { PesticideContent tmpPc = new PesticideContent(pc); if (pc.PesticideId == RegisterPesticide.Id) { pc.PestcideMaster = new PesticideMaster(RegisterPesticide); } tmp.Add(tmpPc); } PesticideMasters = new ObservableCollection <PesticideMaster>(DataBaseManager.DBManager.GetPesticideMasters()); RegisterPesticide = new PesticideMaster(); PesticideMasterIndex = 0; }
/// <summary> /// コンストラクタ /// </summary> public MainWindowViewModel() { DataBaseManager.ConnectDB("WorkTaskApp.db"); WorkContents = new ObservableCollection <WorkContent>(DataBaseManager.DBManager.GetWorkContents()); PesticideMasters = new ObservableCollection <PesticideMaster>(DataBaseManager.DBManager.GetPesticideMasters()); WorkerMasters = new ObservableCollection <WorkerMaster>(DataBaseManager.DBManager.GetWorkerMasters()); WorkContent = new WorkContent(); PesticideContent = new PesticideContent(); WorkerMaster = new WorkerMaster(); RegisterPesticide = new PesticideMaster(); RegisterWorker = new WorkerMaster(); // 農薬内容登録コマンド登録 RegisterPesticideContentClicked = new DelegateCommand( () => RegisterPesticideContent()); // 農薬内容更新コマンド登録 UpdatePesticideContentClicked = new DelegateCommand( () => UpdatePesticideContent()); // 農薬内容削除コマンド登録 DeletePesticideContentClicked = new DelegateCommand( () => DeletePesticideContent()); // 農薬内容読み込みコマンド登録(クリックで取得したインスタンスで登録用インスタンスを上書き) PesticideContentsClicked = new DelegateCommand <Object>( (readPesticideContent) => { if (readPesticideContent is PesticideContent) { // インデックスを取得 selectedPesticideContentIndex = PesticideContentIndex; // リスト内の要素が選択されている場合のみ、インスタンスを上書きする PesticideContent = new PesticideContent((PesticideContent)readPesticideContent); PesticideMasterIndex = PesticideMasters.ToList().FindIndex(master => PesticideContent.PestcideMaster.Id == master.Id); } }); // 作業内容登録コマンド登録 RegisterWorkContentClicked = new DelegateCommand( () => RegisterWorkContent()); // 作業内容更新コマンド登録 UpdateWorkContentClicked = new DelegateCommand( () => UpdateWorkContent()); // 作業内容削除コマンド登録 DeleteWorkContentClicked = new DelegateCommand( () => DeleteWorkContent()); // 作業内容読み込みコマンド登録(クリックで取得したインスタンスで登録用インスタンスを上書き) WorkContentsClicked = new DelegateCommand <Object>( (readWorkContent) => { if (readWorkContent is WorkContent) { // リスト内の要素が選択されている場合のみ、インスタンスを上書きする WorkContent = new WorkContent((WorkContent)readWorkContent); WorkerMasterIndex = WorkerMasters.ToList().FindIndex(master => WorkContent.UserId == master.Id); } }); // 農薬マスタ登録コマンド登録 RegisterPesticideClicked = new DelegateCommand( () => RegisterPesticideMaster()); // 農薬マスタ更新コマンド登録 UpdatePesticideClicked = new DelegateCommand( () => UpdatePesticideMaster()); // 農薬マスタ削除コマンド登録 DeletePesticideClicked = new DelegateCommand( () => DeletePesticideMaster()); // 農薬マスタ読み込みコマンド登録(クリックで取得したインスタンスで登録用インスタンスを上書き) PesticideMasterClicked = new DelegateCommand <Object>( (readPesticide) => { if (readPesticide is PesticideMaster) { // リスト内の要素が選択されている場合のみ、インスタンスを上書きする RegisterPesticide = new PesticideMaster((PesticideMaster)readPesticide); } }); // 作業者マスタ登録コマンド登録 RegisterWorkerClicked = new DelegateCommand( () => RegisterWorkerMaster()); // 作業者マスタ更新コマンド登録 UpdateWorkerClicked = new DelegateCommand( () => UpdateWorkerMaster()); // 作業者マスタ削除コマンド登録 DeleteWorkerClicked = new DelegateCommand( () => DeleteWorkerMaster()); // 作業者マスタ読み込みコマンド登録(クリックで取得したインスタンスで登録用インスタンスを上書き) WorkerMasterClicked = new DelegateCommand <Object>( (readWorker) => { if (readWorker is WorkerMaster) { // リスト内の要素が選択されている場合のみ、インスタンスを上書きする RegisterWorker = new WorkerMaster((WorkerMaster)readWorker); } }); }