Guest User

Untitled

a guest
Jan 21st, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.07 KB | None | 0 0
  1. namespace CRG08KDHT.ViewModel
  2. {
  3. public class CiclosViewModel : ViewModelBase
  4. {
  5. public RelayCommand AdicionarCicloCommand { get; }
  6. public RelayCommand AbrirSecagensCommand { get; }
  7. public RelayCommand AbrirRelatorioCommand { get; }
  8. public RelayCommand AtualizarCommand { get; }
  9. public RelayCommand ExcluirCommand { get; }
  10. public RelayCommand GerenciarProdutosCommand { get; }
  11. public RelayCommand FinalizarCommand { get; }
  12. public RelayCommand ImportarCommand { get; }
  13. public RelayCommand ExportarCommand { get; }
  14. public RelayCommand SairCommand { get; }
  15.  
  16. public RelayCommand AbrirFiltroCommand { get; }
  17. public RelayCommand AplicarFiltroCommand { get; }
  18. public RelayCommand FecharFiltroCommand { get; }
  19. public RelayCommand ResetarFiltroCommand { get; }
  20.  
  21. public RelayCommand AbrirAlterarCommand { get; }
  22. public RelayCommand SalvarAlterarCommand { get; }
  23. public RelayCommand CancelarAlterarCommand { get; }
  24.  
  25. public ObservableCollection<Ciclo> CiclosEmAndamento { get; set; }
  26. public ObservableCollection<Ciclo> CiclosFinalizados { get; set; }
  27.  
  28. public ICollectionView FilteredCiclosFinalizados
  29. {
  30. get
  31. {
  32. var source = CollectionViewSource.GetDefaultView(CiclosFinalizados);
  33. Filtro = FiltrosSecagensAccess.GetFiltro();
  34. source.Filter = (p) =>
  35. {
  36. var c = (Ciclo)p;
  37. var aparelhoOk = !Filtro.ApenasAparelho || c.Crg == Filtro.Aparelho;
  38. var dataOk = Filtro.QualquerData ||
  39. (Filtro.Ultimas24Horas && c.DataInicio >= DateTime.Now.AddDays(-1)) ||
  40. (Filtro.UltimaSemana && c.DataInicio >= DateTime.Now.AddDays(-7)) ||
  41. (Filtro.UltimoMes && c.DataInicio >= DateTime.Now.AddMonths(-1)) ||
  42. (Filtro.Personalizado && c.DataInicio >= Filtro.DataInicio && c.DataFim <= Filtro.DataFim);
  43. return aparelhoOk && dataOk;
  44. };
  45. return source;
  46. }
  47. }
  48.  
  49. public ObservableCollection<Ciclo> CiclosEmAndamentoSelecionados { get; set; }
  50. public ObservableCollection<Ciclo> CiclosFinalizadosSelecionados { get; set; }
  51.  
  52. public CiclosViewModel()
  53. {
  54. if (IsInDesignMode) return;
  55.  
  56. AdicionarCicloCommand = new RelayCommand(AdicionarCiclo);
  57. AbrirSecagensCommand = new RelayCommand(AbrirSecagens);
  58. AbrirRelatorioCommand = new RelayCommand(AbrirRelatorio, CanAbrirRelatorio);
  59. AtualizarCommand = new RelayCommand(Atualizar, CanAtualizar);
  60. ExcluirCommand = new RelayCommand(Excluir, CanExcluir);
  61. GerenciarProdutosCommand = new RelayCommand(GerenciarProdutos);
  62. FinalizarCommand = new RelayCommand(Finalizar, CanFinalizar);
  63. ImportarCommand = new RelayCommand(Importar, CanImportar);
  64. ExportarCommand = new RelayCommand(Exportar, CanExportar);
  65. SairCommand = new RelayCommand(Sair);
  66.  
  67. AbrirFiltroCommand = new RelayCommand(AbrirFiltro);
  68. AplicarFiltroCommand = new RelayCommand(AplicarFiltro);
  69. ResetarFiltroCommand = new RelayCommand(ResetarFiltro);
  70. FecharFiltroCommand = new RelayCommand(FecharFiltro);
  71.  
  72. AbrirAlterarCommand = new RelayCommand(AbrirAlterar, CanAbrirAlterar);
  73. SalvarAlterarCommand = new RelayCommand(SalvarAlterar);
  74. CancelarAlterarCommand = new RelayCommand(CancelarAlterar);
  75.  
  76. CiclosEmAndamentoSelecionados = new ObservableCollection<Ciclo>();
  77. CiclosFinalizadosSelecionados = new ObservableCollection<Ciclo>();
  78.  
  79. CiclosEmAndamento = new ObservableCollection<Ciclo>();
  80. CiclosFinalizados = new ObservableCollection<Ciclo>();
  81.  
  82. RefreshEmAndamento();
  83. RefreshFinalizados();
  84. }
  85.  
  86. private FiltroSecagens _filtro;
  87. public FiltroSecagens Filtro
  88. {
  89. get => _filtro;
  90. set => Set(() => Filtro, ref _filtro, value);
  91. }
  92.  
  93. public List<int> AparelhosDisponiveis => Enumerable.Range(1, 32).ToList();
  94.  
  95. private bool _filtroAberto = false;
  96. public bool FiltroAberto
  97. {
  98. get => _filtroAberto;
  99. set
  100. {
  101. if (Set(() => FiltroAberto, ref _filtroAberto, value))
  102. {
  103. RaisePropertyChanged(() => OverlayAberto);
  104. }
  105. }
  106. }
  107.  
  108. private string _alterarDescricaoText;
  109. public string AlterarDescricaoText
  110. {
  111. get => _alterarDescricaoText;
  112. set => Set(() => AlterarDescricaoText, ref _alterarDescricaoText, value);
  113. }
  114.  
  115. private bool _alterarAberto;
  116. public bool AlterarAberto
  117. {
  118. get => _alterarAberto;
  119. set
  120. {
  121. if (Set(() => AlterarAberto, ref _alterarAberto, value))
  122. {
  123. RaisePropertyChanged(() => OverlayAberto);
  124. }
  125. }
  126. }
  127.  
  128. private Ciclo _secagemEmEdicao;
  129. public Ciclo SecagemEmEdicao
  130. {
  131. get => _secagemEmEdicao;
  132. set => Set(() => SecagemEmEdicao, ref _secagemEmEdicao, value);
  133. }
  134.  
  135. public bool OverlayAberto => FiltroAberto || AlterarAberto;
  136.  
  137. public string AvisoFiltroStr
  138. {
  139. get
  140. {
  141. if (TabControlIndex == 0) return string.Empty;
  142.  
  143. var filteredCount = FilteredCiclosFinalizados.Cast<Ciclo>().Count();
  144.  
  145. if (CiclosFinalizados.Count == 0 || CiclosFinalizados.Count == filteredCount) return string.Empty;
  146.  
  147. var sobra = CiclosFinalizados.Count - filteredCount;
  148.  
  149. if (sobra > 1)
  150. {
  151. return $"{sobra} secagens ocultas devido ao filtro.";
  152. }
  153. else
  154. {
  155. return $"{sobra} secagem oculta devido ao filtro.";
  156. }
  157. }
  158. }
  159.  
  160. private bool _isLoading = false;
  161. public bool IsLoading
  162. {
  163. get => _isLoading;
  164. set => Set(() => IsLoading, ref _isLoading, value);
  165. }
  166.  
  167. private string _loadingText = string.Empty;
  168. public string LoadingText
  169. {
  170. get => _loadingText;
  171. set => Set(() => LoadingText, ref _loadingText, value);
  172. }
  173.  
  174. private int _tabControlIndex = 0;
  175. public int TabControlIndex
  176. {
  177. get => _tabControlIndex;
  178. set
  179. {
  180. if (Set(() => TabControlIndex, ref _tabControlIndex, value))
  181. {
  182. RaisePropertyChanged(() => AvisoFiltroStr);
  183. }
  184. }
  185. }
  186.  
  187. public void AdicionarCiclo()
  188. {
  189. var wnd = new SelecionarComunicacao();
  190. Navigator.OpenWindowAsDialog(wnd);
  191.  
  192. if (!wnd.ViewModel.Confirmado)
  193. {
  194. return;
  195. }
  196.  
  197. List<int> listaBytes;
  198.  
  199. int crg = -1;
  200.  
  201. if (wnd.ViewModel.IsPendrive)
  202. {
  203. var pdWindow = new SelecionarArquivoPendrive();
  204. Navigator.OpenWindowAsDialog(pdWindow);
  205. var pdVm = (SelecionarArquivoPendriveViewModel)pdWindow.DataContext;
  206. if (!pdVm.Confirmado) return;
  207. crg = pdVm.AparelhoSelecionado;
  208. listaBytes = File.ReadAllBytes(pdVm.ArquivoSelecionado.CaminhoCompleto).Select(b => Convert.ToInt32(b)).ToList();
  209. }
  210. else
  211. {
  212. LoadingText = "Carregando a secagem...";
  213. IsLoading = true;
  214. Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new ThreadStart(delegate { }));
  215. listaBytes = CrgCommunication.PuxarSecagemDoAparelho(wnd.ViewModel.AparelhoSelecionado);
  216. crg = wnd.ViewModel.AparelhoSelecionado;
  217. IsLoading = false;
  218. }
  219.  
  220. if (listaBytes == null || listaBytes.Count == 0)
  221. {
  222. MessageBox.Show(messageBoxText: "Algum erro ocorreu ao puxar a secagem!",
  223. caption: "Erro", button: MessageBoxButton.OK,
  224. icon: MessageBoxImage.Error);
  225. return;
  226. }
  227.  
  228. var ciclo = CrgDecifrator.DecifrarSecagem(listaBytes);
  229.  
  230. if (ciclo == null)
  231. {
  232. MessageBox.Show(messageBoxText: "Algum erro ocorreu ao puxar a secagem!",
  233. caption: "Erro", button: MessageBoxButton.OK,
  234. icon: MessageBoxImage.Error);
  235. return;
  236. }
  237.  
  238. ciclo.Crg = crg;
  239.  
  240. var ret = CiclosAccess.AtualizarCiclo(ciclo);
  241.  
  242. if (ret == 0)
  243. {
  244. MessageBox.Show(messageBoxText: "Secagem já está presente!",
  245. caption: "", button: MessageBoxButton.OK,
  246. icon: MessageBoxImage.Information);
  247. }
  248. else if (ret == 1)
  249. {
  250. MessageBox.Show(messageBoxText: "Secagem atualizada com sucesso!",
  251. caption: "", button: MessageBoxButton.OK,
  252. icon: MessageBoxImage.Information);
  253. }
  254. else if (ret == 2)
  255. {
  256. var add = new AdicionarCiclo(ciclo);
  257. Navigator.OpenWindowAsDialog(add);
  258.  
  259. if (((AdicionarCicloViewModel)add.DataContext).Confirmado)
  260. {
  261. CiclosAccess.SalvarCiclo(ciclo);
  262. MessageBox.Show(messageBoxText: "Secagem adicionada com sucesso!",
  263. caption: "", button: MessageBoxButton.OK,
  264. icon: MessageBoxImage.Information);
  265. }
  266. else
  267. {
  268. return;
  269. }
  270. }
  271.  
  272. //var db = new CrgContext();
  273.  
  274. //var existente = db.Ciclos.Include(c => c.DadosTratamento).FirstOrDefault(x =>
  275. // x.NumeroSerie == ciclo.NumeroSerie && x.NumeroSecagem == ciclo.NumeroSecagem &&
  276. // x.Crg == ciclo.Crg)
  277. // ;
  278.  
  279.  
  280. //if (existente != null)
  281. //{
  282. // if (existente.NumeroLeituras == ciclo.NumeroLeituras ||
  283. // existente.DadosTratamento.LeiturasTratamento.Count ==
  284. // ciclo.DadosTratamento.LeiturasTratamento.Count)
  285. // {
  286. // MessageBox.Show("Esta secagem já está atualizada.");
  287. // return;
  288. // }
  289. // else
  290. // {
  291. // ciclo.Id = existente.Id;
  292. // db.Ciclos.AddOrUpdate(ciclo);
  293. // }
  294. //}
  295. //else
  296. //{
  297. // var add = new AdicionarCiclo(ciclo);
  298. // Navigator.OpenWindowAsDialog(add);
  299.  
  300. // if (((AdicionarCicloViewModel) add.DataContext).Confirmado)
  301. // {
  302. // db.Ciclos.Add(ciclo);
  303. // }
  304. // else
  305. // {
  306. // return;
  307. // }
  308. //}
  309.  
  310. //db.SaveChanges();
  311.  
  312. RefreshEmAndamento();
  313. RefreshFinalizados();
  314. }
  315.  
  316. public void AbrirSecagens()
  317. {
  318. var wnd = new HistoricoSecagens();
  319. Navigator.OpenWindowAsDialog(wnd);
  320. }
  321.  
  322. public void AbrirRelatorio()
  323. {
  324. var ciclos = TabControlIndex == 0 ? CiclosEmAndamentoSelecionados : CiclosFinalizadosSelecionados;
  325.  
  326. if (ciclos.Count == 1)
  327. {
  328. var detalhesCiclo = new DetalhesCiclo(ciclos[0]);
  329. Navigator.OpenWindowAsDialog(detalhesCiclo);
  330. }
  331. else if (ciclos.Count > 1)
  332. {
  333. MessageBox.Show(messageBoxText: "Você deve ter apenas 1 ciclo selecionado para abrir o relatório.",
  334. caption: "", button: MessageBoxButton.OK, icon: MessageBoxImage.Information);
  335. }
  336. else
  337. {
  338. MessageBox.Show(messageBoxText: "Selecione um ciclo para abrir o relatório.",
  339. caption: "", button: MessageBoxButton.OK, icon: MessageBoxImage.Stop);
  340. }
  341.  
  342. }
  343.  
  344. public bool CanAbrirRelatorio()
  345. {
  346. var ciclos = TabControlIndex == 0 ? CiclosEmAndamentoSelecionados : CiclosFinalizadosSelecionados;
  347.  
  348. return ciclos.Count == 1;
  349. }
  350.  
  351. public void Atualizar()
  352. {
  353. var ciclo = CiclosEmAndamentoSelecionados.First();
  354. LoadingText = "Atualizando a secagem...";
  355. IsLoading = true;
  356. Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new ThreadStart(delegate { }));
  357. var secagem = CrgCommunication.PuxarSecagemDoAparelho(ciclo.Crg, new Model.Items.ItemHistoricoSecagem
  358. {
  359. Crg = ciclo.Crg,
  360. DataInicio = ciclo.DataInicio,
  361. NumeroSecagem = ciclo.NumeroSecagem
  362. });
  363.  
  364. if (secagem == null || secagem.Count == 0)
  365. {
  366. IsLoading = false;
  367. MessageBox.Show(messageBoxText: "Erro ao atualizar a secagem!",
  368. caption: "Erro", button: MessageBoxButton.OK,
  369. icon: MessageBoxImage.Error);
  370. return;
  371. }
  372.  
  373. var novoCiclo = CrgDecifrator.DecifrarSecagem(secagem);
  374. novoCiclo.Crg = ciclo.Crg;
  375. if (novoCiclo == null)
  376. {
  377. IsLoading = false;
  378. MessageBox.Show(messageBoxText: "Erro ao atualizar a secagem!",
  379. caption: "Erro", button: MessageBoxButton.OK,
  380. icon: MessageBoxImage.Error);
  381. return;
  382. }
  383.  
  384. var ret = CiclosAccess.AtualizarCiclo(novoCiclo);
  385.  
  386. if (ret == 0)
  387. {
  388. IsLoading = false;
  389. MessageBox.Show(messageBoxText: "A secagem já está atualizada!",
  390. caption: "", button: MessageBoxButton.OK, icon: MessageBoxImage.Information);
  391. return;
  392. }
  393. else if (ret == 1)
  394. {
  395. IsLoading = false;
  396. MessageBox.Show(messageBoxText: "Secagem atualizada com sucesso!",
  397. caption: "", button: MessageBoxButton.OK, icon: MessageBoxImage.Information);
  398. }
  399. else if (ret == 2)
  400. {
  401. IsLoading = false;
  402. MessageBox.Show(messageBoxText: "Secagem não encontrada no aparelho!",
  403. caption: "Erro", button: MessageBoxButton.OK,
  404. icon: MessageBoxImage.Error);
  405. return;
  406. }
  407.  
  408. RefreshEmAndamento();
  409. RefreshFinalizados();
  410. }
  411.  
  412. public bool CanAtualizar()
  413. {
  414. return TabControlIndex == 0 && CiclosEmAndamentoSelecionados.Count == 1;
  415. }
  416.  
  417. public void Excluir()
  418. {
  419. var ciclos = TabControlIndex == 0 ? CiclosEmAndamentoSelecionados : CiclosFinalizadosSelecionados;
  420.  
  421. if (MessageBox.Show($"Deseja realmente excluir a secagem selecionada?",
  422. "Tem certeza?",
  423. MessageBoxButton.YesNo,
  424. MessageBoxImage.Question) != MessageBoxResult.Yes)
  425. {
  426. return;
  427. }
  428.  
  429. var db = new CrgContext();
  430.  
  431. var ciclosId = ciclos.Select(x => x.Id).ToList();
  432.  
  433. db.Ciclos.RemoveRange(db.Ciclos.Where(c => ciclosId.Contains(c.Id))
  434. .Include(c => c.LeiturasCiclo)
  435. .Include(c => c.DadosTratamento)
  436. .Include(c => c.DadosTratamento.LeiturasTratamento)
  437. .Include(c => c.Programa)
  438. .Include(c => c.Programa.Fases)
  439. .Include(c => c.Interrupcoes)
  440. .Include(c => c.Produtos));
  441. db.SaveChanges();
  442. RefreshEmAndamento();
  443. RefreshFinalizados();
  444. }
  445.  
  446. public bool CanExcluir()
  447. {
  448. var ciclos = TabControlIndex == 0 ? CiclosEmAndamentoSelecionados : CiclosFinalizadosSelecionados;
  449.  
  450. return ciclos.Count >= 1;
  451. }
  452.  
  453. public void GerenciarProdutos()
  454. {
  455. Navigator.OpenWindowAsDialog(new GerenciarGenerico());
  456. }
  457.  
  458. public void Finalizar()
  459. {
  460. var ciclos = CiclosEmAndamentoSelecionados;
  461. if (MessageBox.Show("Deseja enviar a secagem selecionada para os ciclos finalizados?",
  462. "Tem certeza?",
  463. MessageBoxButton.YesNo,
  464. MessageBoxImage.Question) != MessageBoxResult.Yes)
  465. {
  466. return;
  467. }
  468.  
  469. var db = new CrgContext();
  470. foreach (var ciclo in ciclos)
  471. {
  472. ciclo.Finalizado = true;
  473. db.Ciclos.AddOrUpdate(ciclo);
  474. }
  475. db.SaveChanges();
  476.  
  477. RefreshEmAndamento();
  478. RefreshFinalizados();
  479. }
  480.  
  481. public bool CanFinalizar()
  482. {
  483. return TabControlIndex == 0 && CiclosEmAndamentoSelecionados.Count >= 1;
  484. }
  485.  
  486. public void Importar()
  487. {
  488. var od = new OpenFileDialog()
  489. {
  490. Filter = "*.CRG08KDHTsec | *.CRG08KDHTsec"
  491. };
  492. od.ShowDialog(Navigator.GetWindowByDataContext(this));
  493.  
  494. if (string.IsNullOrWhiteSpace(od.FileName) || !od.FileName.Contains(".CRG08KDHTsec"))
  495. {
  496. MessageBox.Show(messageBoxText: "Nome do arquivo inválido!",
  497. caption: "Inválido!", button: MessageBoxButton.OK,
  498. icon: MessageBoxImage.Error);
  499. return;
  500. }
  501.  
  502. var buff = File.ReadAllBytes(od.FileName);
  503.  
  504. var listaCiclos = ObjectConverter.ByteArrayToObject(buff);
  505.  
  506. if (listaCiclos != null && listaCiclos is List<Ciclo> lista)
  507. {
  508. var msgs = new List<string>();
  509. foreach (var ciclo in lista)
  510. {
  511. if (MessageBox.Show($"Deseja incluir a secagem {ciclo.NumeroSecagem} do aparelho {ciclo.Crg} com período de {ciclo.DataInicio:dd/MM/yyyy HH:mm} até {ciclo.DataFim:dd/MM/yyyy HH:mm}?",
  512. "Inclusão", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
  513. {
  514. ciclo.Id = -1;
  515. var atRes = CiclosAccess.AtualizarCiclo(ciclo);
  516. if (atRes == 0)
  517. {
  518. msgs.Add($"Secagem {ciclo.NumeroSecagem} ({ciclo.DataInicio:dd/MM/yyyy HH:mm} até {ciclo.DataFim:dd/MM/yyyy HH:mm}) já está atualizada!");
  519. }
  520. if (atRes == 1)
  521. {
  522. msgs.Add($"Secagem {ciclo.NumeroSecagem} ({ciclo.DataInicio:dd/MM/yyyy HH:mm} até {ciclo.DataFim:dd/MM/yyyy HH:mm}) atualizada com sucesso!");
  523. continue;
  524. }
  525. if (atRes == 2)
  526. {
  527. CiclosAccess.SalvarCiclo(ciclo);
  528. msgs.Add($"Secagem {ciclo.NumeroSecagem} ({ciclo.DataInicio:dd/MM/yyyy HH:mm} até {ciclo.DataFim:dd/MM/yyyy HH:mm}) adicionada com sucesso!");
  529. }
  530. }
  531. }
  532. if (msgs.Count > 0)
  533. {
  534. var str = "Logs de importação:";
  535. foreach (var msg in msgs)
  536. {
  537. str += Environment.NewLine + msg;
  538. }
  539. MessageBox.Show(str);
  540. RefreshEmAndamento();
  541. RefreshFinalizados();
  542. }
  543. }
  544. else
  545. {
  546. MessageBox.Show(messageBoxText: "Arquivo inválido!",
  547. caption: "Erro", button: MessageBoxButton.OK,
  548. icon: MessageBoxImage.Error);
  549. }
  550. }
  551.  
  552. public bool CanImportar()
  553. {
  554. return true;
  555. }
  556.  
  557. public void Exportar()
  558. {
  559. var od = new SaveFileDialog
  560. {
  561. Filter = "*.CRG08KDHTsec|*.CRG08KDHTsec"
  562. };
  563.  
  564. od.ShowDialog(Navigator.GetWindowByDataContext(this));
  565.  
  566.  
  567. if (string.IsNullOrWhiteSpace(od.FileName) || !od.FileName.Contains(".CRG08KDHTsec"))
  568. {
  569. return;
  570. }
  571.  
  572.  
  573. List<Ciclo> lista;
  574. if (TabControlIndex == 0)
  575. {
  576. lista = CiclosEmAndamentoSelecionados.ToList();
  577. }
  578. else
  579. {
  580. lista = CiclosFinalizadosSelecionados.ToList();
  581. }
  582.  
  583. var CiclosCompletos = new List<Ciclo>();
  584.  
  585. foreach(var Ciclo in lista)
  586. {
  587. var CicloCompleto = CiclosAccess.RetornarCiclo(Ciclo.Id);
  588. if(CicloCompleto != null)
  589. {
  590. CiclosCompletos.Add(CicloCompleto);
  591. }
  592. }
  593.  
  594. var bArray = ObjectConverter.ObjectToByteArray(CiclosCompletos);
  595.  
  596. File.WriteAllBytes(od.FileName, bArray);
  597.  
  598. if (lista.Count == 1)
  599. {
  600. MessageBox.Show(messageBoxText: "Secagem exportada com sucesso!",
  601. caption: "", button: MessageBoxButton.OK, icon: MessageBoxImage.Information);
  602. }
  603. //else
  604. //{
  605. // MessageBox.Show("Secagens exportadas com sucesso!");
  606. //}
  607.  
  608. }
  609.  
  610. public bool CanExportar()
  611. {
  612. if (TabControlIndex == 0)
  613. {
  614. return CiclosEmAndamentoSelecionados.Count >= 1;
  615. }
  616. else
  617. {
  618. return CiclosFinalizadosSelecionados.Count >= 1;
  619. }
  620. }
  621.  
  622. public void Sair()
  623. {
  624. Navigator.CloseWindowByDataContext(this);
  625. }
  626.  
  627. public void AbrirFiltro()
  628. {
  629. FiltroAberto = true;
  630. }
  631.  
  632. public void AplicarFiltro()
  633. {
  634. FiltrosSecagensAccess.SalvarFiltro(Filtro);
  635. RefreshFiltro();
  636. FiltroAberto = false;
  637. }
  638.  
  639. public void ResetarFiltro()
  640. {
  641. FiltrosSecagensAccess.SalvarFiltro(new FiltroSecagens
  642. {
  643. ApenasAparelho = false,
  644. Aparelho = 1,
  645. DataInicio = DateTime.Now,
  646. DataFim = DateTime.Now,
  647. QualquerData = true
  648. });
  649. RefreshFiltro();
  650. FiltroAberto = false;
  651. }
  652.  
  653. public void RefreshFiltro()
  654. {
  655. RaisePropertyChanged(() => Filtro);
  656. FilteredCiclosFinalizados.Refresh();
  657. RaisePropertyChanged(() => AvisoFiltroStr);
  658. }
  659.  
  660. public void FecharFiltro()
  661. {
  662. FiltroAberto = false;
  663. RaisePropertyChanged(() => Filtro);
  664. }
  665.  
  666. public void AbrirAlterar()
  667. {
  668. SecagemEmEdicao = CiclosEmAndamentoSelecionados.First();
  669. AlterarDescricaoText = SecagemEmEdicao.Descricao;
  670. AlterarAberto = true;
  671. var wnd = Navigator.GetWindowByDataContext(this) as Ciclos;
  672. FocusManager.SetFocusedElement(wnd, wnd.TxtAlterarDescricao);
  673. wnd.TxtAlterarDescricao.CaretIndex = wnd.TxtAlterarDescricao.Text.Length-1;
  674. }
  675.  
  676. public bool CanAbrirAlterar()
  677. {
  678. return CiclosEmAndamentoSelecionados.Count == 1 && TabControlIndex == 0;
  679. }
  680.  
  681. public void SalvarAlterar()
  682. {
  683. CiclosAccess.AtualizarDescricao(SecagemEmEdicao, AlterarDescricaoText);
  684. RefreshEmAndamento();
  685. AlterarAberto = false;
  686. }
  687.  
  688. public void CancelarAlterar()
  689. {
  690. AlterarAberto = false;
  691. }
  692.  
  693. public void RefreshEmAndamento()
  694. {
  695. CiclosEmAndamento.Clear();
  696. var db = new CrgContext();
  697. var ciclosEmAndamento = db.Ciclos.Where(x => x.Finalizado == false)
  698. .OrderBy(x => x.Crg)
  699. .ThenBy(x => x.DataInicio).ToList();
  700.  
  701. foreach (var ciclo in ciclosEmAndamento)
  702. {
  703. CiclosEmAndamento.Add(ciclo);
  704. }
  705. }
  706.  
  707. public void RefreshFinalizados()
  708. {
  709. CiclosFinalizados.Clear();
  710. var db = new CrgContext();
  711. var ciclosFinalizados = db.Ciclos.Where(x => x.Finalizado)
  712. .OrderBy(x => x.Crg)
  713. .ThenBy(x => x.DataInicio).ToList();
  714.  
  715. foreach (var ciclo in ciclosFinalizados)
  716. {
  717. CiclosFinalizados.Add(ciclo);
  718. }
  719. RefreshFiltro();
  720. RaisePropertyChanged(() => AvisoFiltroStr);
  721. }
  722. }
  723. }
Add Comment
Please, Sign In to add comment