我正在编写一个程序来管理工具库存,并在用户将工具标记为“固定”时遇到问题。从不同的ViewModel调用方法
程序应该工作如下:
使用TIView,TIViewModel,TIModel:
- 员工检查工具了。
- 工具在使用过程中会发生损坏。
- 员工回报的工具将其标记为损坏并报告问题。
- 该工具被标记为退回并锁定,直至被修复。
使用VPRView,VPRViewModel和VPRModel:
- 检查员进入表示有问题的所有工具数据网格。
检查员纠正问题,将工具标记为已修复,然后提交数据。
该程序更新SQLite数据库与检查员身份证号码,他们的解决方案,将问题标记为已修复并记录日期/时间完成。
的问题步骤:
8.然后程序运行从TIViewModel的PopulateToolInventory方法来更新库存列表中,这样的工具不再锁定。
总结:
当检查员标记工具作为数据库使用的是VPRView,VPRViewModel和VPRModel更新固定。在TIViewModel中可以找到为工具清单提取数据的方法。在通过VPRViewModel将数据上传到数据库之后,如何让应用程序通过VPRViewModel执行“PopulateToolInventory”方法?
代码示例:
VPRViewModel:
public void SubmitSolution()
{
VPRModel vprm = new VPRModel();
vprm.SubmitProblemSolution(ProblemSolved, ProblemSolution, InspectorID, SelectedReport[0].ToString());
ProblemReports = vprm.RetrieveProblemReports();
InspectorID = null;
ProblemSolution = null;
ProblemSolved = false;
MessageBox.Show("Solution successfully recorded!", "Success!", MessageBoxButton.OK);
// This is where I would want to call the method from the TIViewModel to update the data grid on the TIView.
}
TIViewModel:
private DataTable _toolInventory;
public DataTable ToolInventory
{
get { return _toolInventory; }
set
{
_toolInventory = value;
NotifyOfPropertyChange(() => ToolInventory);
}
}
public void PopulateToolInventory()
{
TIModel tim = new TIModel();
ToolInventory = tim.RetrieveToolInventory();
}
ShellViewModel:
class ShellViewModel : Conductor<object>
{
public void Open_ToolInventory()
{
ActivateItem(new TIViewModel());
}
public void ViewProblemReport()
{
WindowManager wm = new WindowManager();
VPRViewModel vprvm = new VPRViewModel();
wm.ShowDialog(vprvm);
}
}
供参考:我使用Caliburn.Micro如果这有助于任何解决方案。
希望这是足够的信息。如果没有,只要问你需要什么!另外,请不要吃我的代码活着。我自学成才,知道我远离专业开发人员,但这是我的激情,我真的很喜欢它。受到建设性的批评,请不要让我感到愚蠢。
请参阅:https://caliburnmicro.codeplex.com/wikipage?title=The%20Event%20Aggregator – Xiaoy312
看起来这可能是一个解决方案。我在理解如何通过EventAggregator实际调用TIViewModel上的方法时遇到了一些问题。 –
你的'TIViewModel'实例在哪里?它和'VPRViewModel'实例都是同一父级的子级?如果是这样,给'VPRViewModel'一个'SolutionSubmitted'事件,并让父级设置一个处理程序,使'TIViewModel'完成它需要的任何事情。或者你有什么方案可以让观看者创建自己的观看模型,这样他们就不能相互交谈了?后者是一个糟糕的主意;它会使MVVM向后退出。请勿与事件聚合器或定位器接触任何东西;这些都是拜占庭式的,不必要的设计,以实现以视图为中心的设计的反模式。 –