Reputation: 77
I am trying to delevop a tasklist scheduler that is linked to a DB. Depending on taskgroup, each task as a specific dependency and this path depends on DB relations.
The WPF form consists on a template of working periods (30 mins) per line. On initialization, form should read the DB looking for entries of that day and fill them at the correct lines (periods).
My question is, which is the best solution for this situation? I will need lines separated as the template (30m periods), even if they are blank, and OnDoubleClick alike events to trigger task entries.
UPDATE: Template
Project | Product | Task | SubTask
07:30
08:00 XXXX XXXX XXXX XXXX
08:30
Upvotes: 0
Views: 90
Reputation: 701
Here is a really rough mock of what I was talking about...
public partial class MainWindow : Window
{
public List<Schedule> _schedules { get; set; }
List<MyTask> _dbContext = new List<MyTask>();
public MainWindow()
{
InitializeComponent();
_schedules = new List<Schedule>();
LoadTimeIntervals(DateTime.Now);
LoadDbContext();
LoadTasks();
DataContext = this;
}
private void LoadTimeIntervals(DateTime selectedDate)
{
var starting = DateTime.Parse(selectedDate.Date.ToShortDateString() + " 00:00:00");
for (var i = starting; i < DateTime.Parse(selectedDate.Date.ToShortDateString() + " 23:59:00"); i += new TimeSpan(0, 30, 0))
{
_schedules.Add(new Schedule() { TaskDT = i, Tasks = new List<MyTask>() });
}
}
private void LoadTasks()
{
foreach (var interval in _schedules)
{
interval.Tasks = _dbContext.Where(x => x.DueDt == interval.TaskDT).ToList();
}
}
private void LoadDbContext()
{
for (int i = 1; i < 24; i++)
{
if ((i & 1) == 0)
_dbContext.Add(new MyTask() { DueDt = DateTime.Parse(DateTime.Now.Date.ToShortDateString() + " " + i.ToString().PadLeft(2, '0') + ":00:00"), Name = "Task #" + i.ToString(), Completed = false });
}
for (int i = 1; i < 24; i++)
{
if ((i & 1) == 0)
_dbContext.Add(new MyTask() { DueDt = DateTime.Parse(DateTime.Now.Date.ToShortDateString() + " " + i.ToString().PadLeft(2, '0') + ":00:00"), Name = "Task #" + i + 24, Completed = false });
}
}
}
public class Schedule
{
public DateTime TaskDT { get; set; }
public List<MyTask> Tasks { get; set; }
}
public class MyTask
{
public DateTime DueDt { get; set; }
public string Name { get; set; }
public bool Completed { get; set; }
}
And the XAML...
<Grid>
<ItemsControl ItemsSource="{Binding _schedules}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding TaskDT}" Margin="3" />
<ItemsControl ItemsSource="{Binding Tasks}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" Margin="3" />
<TextBlock Text="{Binding DueDt, StringFormat={}Due: {0}}" Margin="3" />
<CheckBox IsChecked="{Binding Completed}" Content="Status:" Margin="3" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
Again, this is a rough mock up and min. style and funct. as been done, but you can see how this could start. If you need help with styling just let me know and I can post more code to help you out.
Upvotes: 0
Reputation: 10865
Try creating a wire frame first and from the user's perspective see what makes more sense. After creating a wire frame, I would create a simple prototype and test it against your users, so that you will be able to know what are the pros and cons of each control. Second, there are really no difference between using either Grid, DataGrid or other controls other than you get a built in control that has is built for a specific task.
Does the control fulfills what your requirement is? You don't know, no one does until you create it, test and verify it.
In my opinion, if you have a very large dataset, then DataGrid will save you time, because the control already provided you the solution for handling those. If you use a Grid or a custom control, then you'll have to handle it by yourself.
Whatever the control you choose, you will still have the same business requirements, and and coding the UI logic will be pretty much the same for the controls you choose.
Upvotes: 1