You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
212 lines
4.8 KiB
212 lines
4.8 KiB
unit scanner; |
|
|
|
{$mode objfpc}{$H+} |
|
|
|
interface |
|
|
|
uses |
|
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtDlgs, |
|
StdCtrls; |
|
|
|
type |
|
|
|
{ TScanForm } |
|
|
|
TScanForm = class(TForm) |
|
ScnaButton: TButton; |
|
Product: TComboBox; |
|
Destination: TComboBox; |
|
FolderName: TLabel; |
|
Origin: TComboBox; |
|
TypeSelector: TComboBox; |
|
dateButton: TButton; |
|
DateSelector: TCalendarDialog; |
|
DateView: TLabel; |
|
|
|
procedure FormCreate(Sender: TObject); |
|
procedure ProductChange(Sender: TObject); |
|
procedure DestinationChange(Sender: TObject); |
|
procedure dateButtonClick(Sender: TObject); |
|
procedure OriginChange(Sender: TObject); |
|
procedure ScnaButtonClick(Sender: TObject); |
|
procedure TypeSelectorChange(Sender: TObject); |
|
function ExportConfig(): string; |
|
function ExportOptions(dropDown: TComboBox): string; |
|
procedure UpdateTypes(); |
|
procedure UpdateFolder(); |
|
procedure MixLocations(d1: TComboBox; d2: TComboBox); |
|
private |
|
date: TDateTime; |
|
public |
|
|
|
end; |
|
|
|
var |
|
ScanForm: TScanForm; |
|
|
|
implementation |
|
|
|
{$R *.lfm} |
|
|
|
{ TScanForm } |
|
|
|
procedure TScanForm.MixLocations(d1: TComboBox; d2: TComboBox); |
|
var |
|
list: TStringList; |
|
begin |
|
list := TStringList.Create; |
|
list.Sorted := True; |
|
d1.Items.Add(d1.Text); |
|
d2.Items.Add(d2.Text); |
|
list.Assign(d1.Items); |
|
list.AddStrings(d2.Items); |
|
d1.Items.Assign(list); |
|
d2.Items.Assign(list); |
|
end; |
|
|
|
function TScanForm.ExportConfig(): string; |
|
begin |
|
Result := 'types:' + ExportOptions(TypeSelector) + #13; |
|
Result := Result + 'items:' + ExportOptions(Product) + #13; |
|
MixLocations(Origin, Destination); |
|
Result := Result + 'locations:' + ExportOPtions(Origin) + #13; |
|
end; |
|
|
|
function TScanForm.ExportOptions(dropDown: TComboBox): string; |
|
var |
|
list: TStringList; |
|
begin |
|
// make sure the current text appears in future lists |
|
dropDown.Items.Add(dropDown.Text); |
|
// create a StringList to sort and concatenate |
|
list := TStringList.Create; |
|
list.StrictDelimiter := True; |
|
list.Sorted := True; |
|
|
|
// put all items in the list, will sort and remove duplicates |
|
list.Assign(dropDown.Items); |
|
|
|
// update dropdown |
|
dropDown.Items.Assign(list); |
|
|
|
// return json array |
|
Result := list.DelimitedText |
|
end; |
|
|
|
procedure TScanForm.TypeSelectorChange(Sender: TObject); |
|
var |
|
state: boolean; |
|
begin |
|
TypeSelector.Tag := 1; |
|
state := TypeSelector.Text = 'Ticket'; |
|
Origin.Enabled := state; |
|
Origin.Visible := state; |
|
Destination.Enabled := state; |
|
Product.Enabled := not state; |
|
Product.Visible := not state; |
|
UpdateFolder(); |
|
end; |
|
|
|
procedure TScanForm.dateButtonClick(Sender: TObject); |
|
begin |
|
DateSelector.Execute; |
|
date := DateSelector.Date; |
|
DateView.Caption := FormatDateTime('YYYY-MM-DD', date); |
|
UpdateTypes(); |
|
TypeSelector.Enabled := True; |
|
UpdateFolder(); |
|
end; |
|
|
|
procedure TScanForm.OriginChange(Sender: TObject); |
|
begin |
|
Origin.Tag := 1; |
|
UpdateFolder(); |
|
end; |
|
|
|
procedure TScanForm.ScnaButtonClick(Sender: TObject); |
|
var |
|
config: TFileStream; |
|
filename: string; |
|
json: string; |
|
begin |
|
filename := GetEnvironmentVariable('HOME') + '/.config/belegscanner.conf'; |
|
json := ExportConfig(); |
|
try |
|
config := TFilestream.Create(filename, fmCreate); |
|
config.Write(json[1], json.Length); |
|
finally |
|
config.Free; |
|
end; |
|
|
|
end; |
|
|
|
procedure TScanForm.DestinationChange(Sender: TObject); |
|
begin |
|
Destination.Tag := 1; |
|
UpdateFolder(); |
|
end; |
|
|
|
procedure TScanForm.ProductChange(Sender: TObject); |
|
begin |
|
Product.Tag := 1; |
|
UpdateFolder(); |
|
end; |
|
|
|
procedure TScanForm.FormCreate(Sender: TObject); |
|
var |
|
filename: String; |
|
lines: TStringList; |
|
line: String; |
|
index: integer; |
|
begin |
|
filename := GetEnvironmentVariable('HOME') + '/.config/belegscanner.conf'; |
|
lines := TStringList.Create; |
|
try |
|
lines.LoadFromFile(filename); |
|
for index := 0 to lines.Count-1 do |
|
begin |
|
line:=lines.Strings[index]; |
|
if line.StartsWith('types:') then |
|
begin |
|
line := line.Substring(6); |
|
TypeSelector.Items.AddStrings(line.Split(',')); |
|
end; |
|
if line.StartsWith('items:') then |
|
begin |
|
line := line.Substring(6); |
|
Product.Items.AddStrings(line.Split(',')); |
|
end; |
|
if line.StartsWith('locations:') then |
|
begin |
|
line := line.Substring(10); |
|
Origin.Items.AddStrings(line.Split(',')); |
|
Destination.Items.AddStrings(line.Split(',')); |
|
end; |
|
end |
|
finally |
|
end; |
|
end; |
|
|
|
|
|
procedure TScanForm.UpdateFolder(); |
|
var |
|
tx: string; |
|
begin |
|
tx := FormatDateTime('YYYY-MM-DD', date) + ' - '; |
|
if (Product.Enabled and (Product.Tag > 0)) then |
|
tx := tx + Product.Text + ' von '; |
|
if (TypeSelector.Tag > 0) then |
|
tx := tx + TypeSelector.Text; |
|
if (Origin.Enabled and (Origin.Tag > 0)) then |
|
tx := tx + ': ' + Origin.Text; |
|
if (Destination.Enabled and (Destination.Tag > 0)) then |
|
tx := tx + ' - ' + Destination.Text; |
|
FolderName.Caption := tx; |
|
end; |
|
|
|
procedure TScanForm.UpdateTypes(); |
|
begin |
|
|
|
end; |
|
|
|
end.
|
|
|