DeliveryAdminWindow: Allow date and time to be edited
This commit is contained in:
@ -521,6 +521,36 @@ namespace Elwig.Helpers {
|
||||
return new(true, null);
|
||||
}
|
||||
|
||||
public static ValidationResult CheckTime(TextBox input, bool required) {
|
||||
string text = "";
|
||||
int pos = input.CaretIndex;
|
||||
int v = 0;
|
||||
for (int i = 0; i < input.Text.Length; i++) {
|
||||
char ch = input.Text[i];
|
||||
if (v >= 0 && v < 5 && v != 2 && char.IsAsciiDigit(ch)) {
|
||||
if ((v == 0 && ch <= '2') || (v == 1 && (text[0] < '2' || ch <= '3')) || (v == 3 && ch <= '5') || v == 4) {
|
||||
text += ch;
|
||||
v++;
|
||||
}
|
||||
} else if (v == 2 && ch == ':') {
|
||||
text += ch;
|
||||
v++;
|
||||
}
|
||||
if (i == input.CaretIndex - 1)
|
||||
pos = text.Length;
|
||||
}
|
||||
input.Text = text;
|
||||
input.CaretIndex = pos;
|
||||
|
||||
if (text.Length == 0) {
|
||||
return required ? new(false, "Wert ist nicht optional") : new(true, null);
|
||||
} else if (v != 5) {
|
||||
return new(false, "Zeit ist ungültig");
|
||||
} else {
|
||||
return new(true, null);
|
||||
}
|
||||
}
|
||||
|
||||
public static ValidationResult CheckFbNr(TextBox input, bool required, AppDbContext ctx, AreaCom? c) {
|
||||
var res = CheckInteger(input, required);
|
||||
if (!res.IsValid) {
|
||||
|
@ -482,6 +482,14 @@ namespace Elwig.Windows {
|
||||
InputLostFocus((TextBox)sender, Validator.CheckDate);
|
||||
}
|
||||
|
||||
protected void TimeInput_TextChanged(object sender, RoutedEventArgs evt) {
|
||||
InputTextChanged((TextBox)sender, Validator.CheckTime);
|
||||
}
|
||||
|
||||
protected void TimeInput_LostFocus(object sender, RoutedEventArgs evt) {
|
||||
InputLostFocus((TextBox)sender, Validator.CheckTime);
|
||||
}
|
||||
|
||||
protected void PlzInput_TextChanged(object sender, RoutedEventArgs evt) {
|
||||
var plz = (TextBox)sender;
|
||||
InputTextChanged(plz, Validator.CheckPlz);
|
||||
|
@ -72,6 +72,10 @@
|
||||
<MenuItem Header="Exportieren">
|
||||
<MenuItem x:Name="Menu_Export_Bki" Header="Traubentransportscheinliste (BKI)"/>
|
||||
</MenuItem>
|
||||
<MenuItem Header="Einstellungen">
|
||||
<MenuItem x:Name="Menu_Settings_EnableFreeEditing" Header="Freie Bearbeitung aktivieren"
|
||||
IsCheckable="True" Checked="Menu_Settings_EnableFreeEditing_Checked" Unchecked="Menu_Settings_EnableFreeEditing_Unchecked"/>
|
||||
</MenuItem>
|
||||
</Menu>
|
||||
|
||||
<Grid Grid.Row="1" Margin="5,0,0,0">
|
||||
@ -228,18 +232,21 @@
|
||||
|
||||
<Label Content="LieferscheinNr.:" Margin="10,10,0,0" Grid.Column="0"/>
|
||||
<TextBox x:Name="LsNrInput" Width="126" Grid.Column="1" HorizontalAlignment="Left" Margin="0,10,0,0"
|
||||
IsReadOnly="True" IsTabStop="False"/>
|
||||
IsReadOnly="True" IsTabStop="False"
|
||||
TextChanged="TextBox_TextChanged"/>
|
||||
|
||||
<Label Content="Datum/Uhrzeit:" Margin="10,40,0,0" Grid.Column="0"/>
|
||||
<TextBox x:Name="DateInput" Width="77" Grid.Column="1" HorizontalAlignment="Left" Margin="0,40,0,0"
|
||||
IsReadOnly="True" IsTabStop="False"
|
||||
TextChanged="DateInput_TextChanged"/>
|
||||
IsReadOnly="True"
|
||||
TextChanged="DateInput_TextChanged" LostFocus="DateInput_LostFocus"/>
|
||||
<TextBox x:Name="TimeInput" Width="44" Grid.Column="1" HorizontalAlignment="Left" Margin="82,40,0,0"
|
||||
IsReadOnly="True" IsTabStop="False"/>
|
||||
IsReadOnly="True"
|
||||
TextChanged="TimeInput_TextChanged" LostFocus="TimeInput_LostFocus"/>
|
||||
|
||||
<Label Content="Zweigstelle:" Margin="10,70,0,0" Grid.Column="0"/>
|
||||
<ComboBox x:Name="BranchInput" Width="126" Margin="0,70,10,0" Grid.Column="1" HorizontalAlignment="Left"
|
||||
IsEnabled="False"
|
||||
SelectionChanged="BranchInput_SelectionChanged"
|
||||
DisplayMemberPath="Name" TextSearch.TextPath="Name"/>
|
||||
|
||||
<Label Content="Anmerkung:" Margin="10,100,0,10"/>
|
||||
|
@ -180,11 +180,30 @@ namespace Elwig.Windows {
|
||||
doc.Show();
|
||||
}
|
||||
|
||||
private void Menu_Settings_EnableFreeEditing_Checked(object sender, RoutedEventArgs evt) {
|
||||
if (IsEditing || IsCreating) {
|
||||
DateInput.IsReadOnly = false;
|
||||
TimeInput.IsReadOnly = false;
|
||||
BranchInput.IsEnabled = true;
|
||||
if (IsCreating) TimeInput.Text = "";
|
||||
OnSecondPassed(null, null);
|
||||
}
|
||||
}
|
||||
|
||||
private void Menu_Settings_EnableFreeEditing_Unchecked(object sender, RoutedEventArgs evt) {
|
||||
DateInput.IsReadOnly = true;
|
||||
TimeInput.IsReadOnly = true;
|
||||
BranchInput.IsEnabled = false;
|
||||
OnSecondPassed(null, null);
|
||||
}
|
||||
|
||||
private void OnSecondPassed(object? sender, EventArgs? evt) {
|
||||
if (IsReceipt && IsCreating) {
|
||||
if (IsReceipt && IsCreating && !Menu_Settings_EnableFreeEditing.IsChecked) {
|
||||
var now = DateTime.Now;
|
||||
TimeInput.Text = now.ToString("HH:mm");
|
||||
DateInput.Text = now.ToString("dd.MM.yyyy");
|
||||
SetDefaultValue(TimeInput);
|
||||
SetDefaultValue(DateInput);
|
||||
}
|
||||
}
|
||||
|
||||
@ -663,10 +682,10 @@ namespace Elwig.Windows {
|
||||
if (deliveryNew || InputHasChanged(DateInput)) {
|
||||
d.LNr = await Context.NextLNr(d.Date);
|
||||
}
|
||||
if (IsCreating) {
|
||||
if (IsCreating && !InputIsNotDefault(TimeInput)) {
|
||||
d.TimeString = DateTime.Now.ToString("HH:mm:ss");
|
||||
} else if (InputHasChanged(TimeInput)) {
|
||||
d.TimeString = TimeInput.Text + ":00";
|
||||
} else if (IsCreating || InputHasChanged(TimeInput)) {
|
||||
d.TimeString = (TimeInput.Text != "") ? TimeInput.Text + ":00" : null;
|
||||
}
|
||||
d.ZwstId = (BranchInput.SelectedItem as Branch)?.ZwstId;
|
||||
d.LsNr = LsNrInput.Text;
|
||||
@ -1269,9 +1288,9 @@ namespace Elwig.Windows {
|
||||
AbgewertetInput.IsEnabled = false;
|
||||
ManualWeighingInput.IsEnabled = false;
|
||||
LsNrInput.IsReadOnly = true;
|
||||
DateInput.IsReadOnly = true;
|
||||
TimeInput.IsReadOnly = true;
|
||||
BranchInput.IsEnabled = false;
|
||||
DateInput.IsReadOnly = !Menu_Settings_EnableFreeEditing.IsChecked;
|
||||
TimeInput.IsReadOnly = !Menu_Settings_EnableFreeEditing.IsChecked;
|
||||
BranchInput.IsEnabled = Menu_Settings_EnableFreeEditing.IsChecked;
|
||||
}
|
||||
|
||||
private void DisableWeighingButtons() {
|
||||
@ -1295,15 +1314,25 @@ namespace Elwig.Windows {
|
||||
if (DateInput.Text == "" || BranchInput.SelectedItem == null) {
|
||||
LsNrInput.Text = "";
|
||||
} else {
|
||||
var branch = (Branch)BranchInput.SelectedItem;
|
||||
var date = DateOnly.ParseExact(DateInput.Text, "dd.MM.yyyy");
|
||||
var lnr = await Context.NextLNr(date);
|
||||
LsNrInput.Text = Utils.GenerateLsNr(date, branch.ZwstId, lnr);
|
||||
try {
|
||||
var branch = (Branch)BranchInput.SelectedItem;
|
||||
var date = DateOnly.ParseExact(DateInput.Text, "dd.MM.yyyy");
|
||||
var lnr = await Context.NextLNr(date);
|
||||
LsNrInput.Text = Utils.GenerateLsNr(date, branch.ZwstId, lnr);
|
||||
} catch {
|
||||
LsNrInput.Text = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DateInput_TextChanged(object sender, TextChangedEventArgs evt) {
|
||||
if (IsCreating) UpdateLsNr().GetAwaiter().GetResult();
|
||||
base.DateInput_TextChanged(sender, evt);
|
||||
if (IsEditing || IsCreating) UpdateLsNr().GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
private void BranchInput_SelectionChanged(object sender, RoutedEventArgs evt) {
|
||||
base.ComboBox_SelectionChanged(sender, evt);
|
||||
if (IsEditing || IsCreating) UpdateLsNr().GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
private void UpdateWineVariety(bool valid) {
|
||||
|
Reference in New Issue
Block a user