This is what I ave datagrid first 3 columns are from a csv file. The rest of the columns will be a column combobox with a list of times in it. The combobox will reflect a day of the week with an in out time for each row.
I have the combobox displaying a drop down which works on a double click ? prefer a single click to get in it. Once every person in the list has had the times for in and out selected for the days they work I will then be doing two things with it.
1st is save the schedule as a new csv file that they can name.
2nd is I will be doing a new function to commit the schedule and that will be in an ini file.
So first thing to do is the save to new csv.
code behind it for the import csv.
Thanks
I have the combobox displaying a drop down which works on a double click ? prefer a single click to get in it. Once every person in the list has had the times for in and out selected for the days they work I will then be doing two things with it.
1st is save the schedule as a new csv file that they can name.
2nd is I will be doing a new function to commit the schedule and that will be in an ini file.
So first thing to do is the save to new csv.
xaml file:
<Window.DataContext>
<custom:GetCsvEmp/>
</Window.DataContext>
<Grid Background="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}">
<Grid.RowDefinitions>
<RowDefinition Height="70"/>
<RowDefinition/>
</Grid.RowDefinitions>
<DataGrid x:Name="EmpList" ItemsSource="{Binding EmpList}" AutoGenerateColumns="False"
AlternatingRowBackground="PowderBlue" Padding="120,20" Background="Gray" Margin="10,50,-10,20" Grid.RowSpan="2">
<DataGrid.Columns>
<DataGridTextColumn Header="Employee"
Binding="{Binding Path=EmpName}" Width="80"/>
<DataGridTextColumn Header="Payroll ID"
Binding="{Binding Path=EmpPayrollID}" Width="150"/>
<DataGridTextColumn Header="Job"
Binding="{Binding Path=JobName }" Width="110"/>
<DataGridComboBoxColumn x:Name="ComboBoxColumn" Header="Time In"
SelectedItemBinding="{Binding TimeIn}"/>
<DataGridComboBoxColumn x:Name="ComboBoxColumn2" Header="Time Out"
SelectedItemBinding="{Binding TimeOut}"/>
</DataGrid.Columns>
</DataGrid>
code behind it for the import csv.
Csv File import:
class GetCsvEmp
{
public List<EmpCsvGet> EmpList { get; set; } = GetEmpget();
public static List<EmpCsvGet> GetEmpget()
{
var file = @"c:\rcs\export\timecard.csv";
var lines = File.ReadAllLines(file);
var list = new List<EmpCsvGet>();
for (int i = 0; i < lines.Length; i++)
{
var line = lines[i].Split(',');
var empCsvGet = new EmpCsvGet()
{
EmpName = line[0],
EmpPayrollID = line[1],
JobName = line[11]
};
list.Add(empCsvGet);
};
return list;
}
}
public class EmpCsvGet
{
// [Index(0)]
public string EmpName { get; set; }
// [Index(1)]
public string EmpPayrollID { get; set; }
//[Index(11)]
public string JobName { get; set; }
}
mainwindow.xaml.cs code:
public partial class MainWindow : Window
{
public ObservableCollection<string> TimeIn { get; set; }
public ObservableCollection<string> TimeOut { get; set; }
public MainWindow()
{
TimeIn = new ObservableCollection<string>() { "7:00a", "8:00a", "9:00a", "10:00a", "11:00a", "12:00p", "1:00p", "2:00p", "3:00p",
"4:00p", "5:00p", "6:00p", "7:00p", "8:00p", "9:00p", "10:00p", "11:00p", "12:00a", "1:00a", "2:00a", "3:00a", "4:00a" };
TimeOut = new ObservableCollection<string>() { "7:00a", "8:00a", "9:00a", "10:00a", "11:00a", "12:00p", "1:00p", "2:00p", "3:00p",
"4:00p", "5:00p", "6:00p", "7:00p", "8:00p", "9:00p", "10:00p", "11:00p", "12:00a", "1:00a", "2:00a", "3:00a", "4:00a" };
InitializeComponent();
ComboBoxColumn.ItemsSource = TimeIn;
ComboBoxColumn2.ItemsSource = TimeOut;
}
}
Thanks