EditFormulaViewModel.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using MuchInfo.Chart.Data.Models;
  2. using MuchInfo.Chart.DataAdapter;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Threading.Tasks;
  6. namespace MuchInfo.Chart.FormulaEdit
  7. {
  8. public class EditFormulaViewModel
  9. {
  10. private IDataService _iDataService;
  11. public EditFormulaViewModel(List<ProgramModel> programModels)
  12. {
  13. _programModels = programModels;
  14. _iDataService = new DataService();
  15. SelectProgramModel = _programModels.FirstOrDefault();
  16. }
  17. //编辑公式集合
  18. private List<ProgramModel> _programModels;
  19. /// <summary>
  20. /// 编辑公式集合
  21. /// </summary>
  22. public List<ProgramModel> ProgramModels
  23. {
  24. get { return _programModels; }
  25. set { _programModels = value; }
  26. }
  27. private ProgramModel _selectProgramModel;
  28. /// <summary>
  29. /// 当前选择的公式
  30. /// </summary>
  31. public ProgramModel SelectProgramModel
  32. {
  33. get { return _selectProgramModel; }
  34. set { _selectProgramModel = value; }
  35. }
  36. /// <summary>
  37. /// 修改用户编辑参数
  38. /// </summary>
  39. public void ChangeParam()
  40. {
  41. Task.Factory.StartNew(() =>
  42. {
  43. _iDataService.SaveFormulaParams(ProgramModels);
  44. });
  45. }
  46. /// <summary>
  47. /// 调用公式编辑器编辑公式
  48. /// </summary>
  49. public void EditFormula()
  50. {
  51. if (SelectProgramModel != null)
  52. {
  53. var formula = SelectProgramModel.CovertToFormulaModel();
  54. _iDataService.EditFormula(formula.FormulaName);
  55. }
  56. }
  57. /// <summary>
  58. /// 打开公式管理器
  59. /// </summary>
  60. public void OpenEditer()
  61. {
  62. if (SelectProgramModel != null)
  63. {
  64. var formula = SelectProgramModel.CovertToFormulaModel();
  65. _iDataService.OpenFormulaEdit(formula.FormulaName);
  66. }
  67. }
  68. }
  69. }