--- dao/DelphiScanner/Main.pas 2015/08/26 19:13:14 2681 +++ dao/DelphiScanner/Main.pas 2015/08/26 19:52:38 2682 @@ -12,13 +12,12 @@ UITypes, PakkeshopLabels, StBarC, - Math // DegToRad() bruges i PrintPakkeshopLabel - + Math, // DegToRad() bruges i PrintPakkeshopLabel + Utils ; type - TStrArray = array of string; TMainForm = class(TForm) StregkodeST: TStaticText; RuteNummerST: TStaticText; @@ -95,11 +94,8 @@ menuIndlevering: TMenuItem; - function Explode(var a: TStrArray; Border, S: string): Integer; - function BarCodeValid (ACode: string): boolean; function Sto_GetFmtFileVersion(const FileName: String = ''): String; - function TColorToHex(Color : TColor) : string; - function HexToTColor(sColor : string) : TColor; + function getProddato() : TDate; function getProddag() : String; function retRutenummer(rutenummer : String) : String; @@ -107,7 +103,6 @@ function SavePChar(p: PChar): PChar; function AdobeReaderExists(): Boolean; function FileTime2DateTime(FileTime: TFileTime): TDateTime; - function split(input: string; schar: Char; s: Integer): string; function CheckUrl(url:string):boolean; procedure PlaySound(filename : PWideChar); @@ -186,7 +181,6 @@ procedure Manualgenerel1Click(Sender: TObject); procedure TjekkerUrls(); - procedure RoundCornerOf(Control: TWinControl); procedure menuIndleveringClick(Sender: TObject); procedure PrintPakkeshopLabel( PakkeshopLabel : TPakkeshopLabel); @@ -256,7 +250,6 @@ Barcode : TStBarcode; - function CheckSumModulo10(const data:string):string; { used for EAN 8/13 } procedure PrintLabel(RuteNummer, Kommentar, BoghandlerNavn, Koreliste, SmsKode, DBKbane, Leveringssted : String; var PrintNyLabel : Boolean; BoghandlerNummer : String = ''); procedure SendTilPrinter(kontrolKoreliste, RuteNummer, Kommentar, BoghandlerNavn, Koreliste, SmsKode, DBKbane, Leveringssted : String; var PrintNyLabel : Boolean; BoghandlerNummer : string = ''); @@ -290,23 +283,6 @@ implementation {$R *.dfm} -function TMainForm.TColorToHex(Color : TColor) : string; -begin - Result := - IntToHex(GetRValue(Color), 2) + - IntToHex(GetGValue(Color), 2) + - IntToHex(GetBValue(Color), 2) ; -end; - -function TMainForm.HexToTColor(sColor : string) : TColor; -begin - Result := - RGB( - StrToInt('$'+Copy(sColor, 1, 2)), - StrToInt('$'+Copy(sColor, 3, 2)), - StrToInt('$'+Copy(sColor, 5, 2)) - ) ; -end; procedure TMainForm.InitForm(Farve,Titel,Url : String); begin @@ -413,7 +389,7 @@ StartScreen(); MainForm.Caption := Titel; - MainForm.Color := HexToTColor(Farve); + MainForm.Color := TUtils.HexToTColor(Farve); MainForm.Farve := Farve; MainForm.Titel := Titel; MainForm.Url := Url; @@ -473,13 +449,13 @@ end else begin - logTekst := 'Speciel version til: '+split(Titel, ':', 2)+' ('+Sted+')'; + logTekst := 'Speciel version til: ' + TUtils.split(Titel, ':', 2) + ' ('+Sted+')'; end; SkrivScanningLogFil(logTekst); end else begin - logTekst := 'Speciel version til: '+split(Titel, ':', 2)+' ('+SpecialVersionSted+')'; + logTekst := 'Speciel version til: ' + TUtils.split(Titel, ':', 2) + ' ('+SpecialVersionSted+')'; SkrivScanningLogFil(logTekst); end; end; @@ -561,12 +537,12 @@ btnNulstil.BringToFront; - RoundCornerOf(PanelManglendePakker1); - RoundCornerOf(PanelManglendePakker2); - RoundCornerOf(PanelManglendePakker3); - RoundCornerOf(PanelManglendePakker4); - RoundCornerOf(PanelManglendePakker5); - RoundCornerOf(PanelManglendePakker6); + TUtils.RoundCornerOf(PanelManglendePakker1); + TUtils.RoundCornerOf(PanelManglendePakker2); + TUtils.RoundCornerOf(PanelManglendePakker3); + TUtils.RoundCornerOf(PanelManglendePakker4); + TUtils.RoundCornerOf(PanelManglendePakker5); + TUtils.RoundCornerOf(PanelManglendePakker6); // Hvis mappen Docs eksisterer kan vi vælge Manual i menuen Hjælp @@ -1622,9 +1598,9 @@ BoghandlerTjekkode := Stregkode; PakkeshopText1.Caption := 'Stregkode'; if (PakkeshopLevering1.Checked) then - MainForm.Color := HexToTColor(FarvePakkeshoplevering); + MainForm.Color := TUtils.HexToTColor(FarvePakkeshoplevering); if (Pakkernormal1.Checked) then - MainForm.Color := HexToTColor(FarveNormal); + MainForm.Color := TUtils.HexToTColor(FarveNormal); btnNulstil.Visible := false; end else @@ -1684,7 +1660,7 @@ end; if ( Pakkernormal1.Checked and (pakkeErScannet = 0) and (pakkeForkertSted = 0) and (tjekkodemangler = 0) and (RuteNummerST.Caption <> 'Ukendt') ) or (Copy(Kommentar,1,2) = 'Ok') then begin - MainForm.Color := HexToTColor(Farve); + MainForm.Color := TUtils.HexToTColor(Farve); if Storepakker1.Checked then begin PlaySound(PWideChar(ScannetOkStorLyd)); @@ -1697,7 +1673,7 @@ end else if (Returpakkerfradao1.Checked or Returpakkerfraboghandler1.Checked) then begin - MainForm.Color := HexToTColor(Farve); + MainForm.Color := TUtils.HexToTColor(Farve); if Storepakker1.Checked then begin PlaySound(PWideChar(ScannetOkStorLyd)); @@ -1822,11 +1798,11 @@ if (pos('/', wrkAntal) > 0) then // både pakker idag og senere begin wrkAntal := wrkAntal + '/'; // tilføjer '/' sidst i feltet af hensyn til split funktionen - wrkAntalIdag := StrToInt(split(wrkAntal, '/', 2)); + wrkAntalIdag := StrToInt( TUtils.split(wrkAntal, '/', 2)); // ShowMessage(SPLIT('data/another/yet/again/more/','/',3)); // ShowMessage(SPLIT('data/another/','/',3)); // ShowMessage(SPLIT('data/another','/',3)); - wrkAntalSenere := StrToInt(split(wrkAntal, '/', 3)); + wrkAntalSenere := StrToInt( TUtils.split(wrkAntal, '/', 3)); end else // kun idag begin @@ -2350,7 +2326,7 @@ nytRuteNummer, nyFarve : String; begin if Budlevering1.Checked then - RuteNummerST.Color := HexToTColor(Farve); + RuteNummerST.Color := TUtils.HexToTColor(Farve); pakkeErScannet := pos('PAKKEN ER SCANNET', BoghandlerNavn); if pakkeErScannet = 0 then @@ -2406,7 +2382,7 @@ PrintNyLabel := true; RuteNummerST.Caption := RuteNummer+' -> ny rute: '+nytRuteNummer; nyFarve := Farve; - RuteNummerST.Color := HexToTColor(nyFarve); + RuteNummerST.Color := TUtils.HexToTColor(nyFarve); List1msg := TimeToStr(now) + '; ' + RuteNummer+' -> ny rute: '+nytRuteNummer; RuteNummer := nytRuteNummer; ListBox1.Items.Insert(0,List1Msg); @@ -3157,7 +3133,7 @@ // MainForm.Color := HexToTColor(Farve); if Farve <> '' then begin - MainForm.Color := HexToTColor(Farve); + MainForm.Color := TUtils.HexToTColor(Farve); // 20150312: start (* end @@ -3357,36 +3333,7 @@ end; end; -{ - VERY fast split function - this function returns part of a string based on - constant defineable delimiters, such as ";". So - SPLIT('this is a test ',' ',3) = 'is' or - SPLIT('data;another;yet;again;more;',';',4) = 'yet' - - Split function shifts index integer by two to - be compatible with commonly used PD split function - gpl 2004 / Juhani Suhonen -} -function TMainForm.split(input: string; schar: Char; s: Integer): string; -var - c: array of Integer; - b, t: Integer; -begin - Dec(s, 2); // for compatibility with very old & slow split function - t := 0; // variable T needs to be initialized... - setlength(c, Length(input)); - for b := 0 to pred(High(c)) do - begin - c[b + 1] := posex(schar, input, succ(c[b])); - // BREAK LOOP if posex looped (position before previous) - // or wanted position reached.. - if (c[b + 1] < c[b]) or (s < t) then break - else - Inc(t); - end; - Result := Copy(input, succ(c[s]), pred(c[s + 1] - c[s])); -end; + procedure TMainForm.Om1Click(Sender: TObject); const @@ -3417,12 +3364,12 @@ end else begin - tekst := tekst+crlf+crlf+'Speciel version til: '+split(Titel, ':', 2)+' ('+Sted+')'; + tekst := tekst+crlf+crlf+'Speciel version til: ' + TUtils.split(Titel, ':', 2) + ' ('+Sted+')'; end; end else begin - tekst := tekst+crlf+crlf+'Speciel version til: '+split(Titel, ':', 2)+' ('+SpecialVersionSted+')'; + tekst := tekst+crlf+crlf+'Speciel version til: ' + TUtils.split(Titel, ':', 2) + ' ('+SpecialVersionSted+')'; end; end; @@ -4071,7 +4018,7 @@ else MessageBox(Handle, 'fejl', 'Stregkode', MB_OK); } - Svar := 'Beregnet: '+CheckSumModulo10(LeftStr(Barcode,Length(Barcode)-1))+', Indtastet: '+Barcode; + Svar := 'Beregnet: ' + TUtils.CheckSumModulo10(LeftStr(Barcode,Length(Barcode)-1))+', Indtastet: '+Barcode; MessageBox(Handle, PWideChar(Svar), 'Stregkode', MB_OK); CheckCode(); @@ -4079,45 +4026,6 @@ end; -function TMainForm.BarCodeValid (ACode: string): boolean; -var - I: integer; - SumOdd, SumEven: integer; - ADigit, AChecksumDigit: integer; -begin - SumOdd := 0; - SumEven := 0; - for I := 1 to (Length (ACode) - 1) do begin - ADigit := StrToIntDef (ACode [I], 0); - if (I MOD 2 = 0) then begin - SumEven := SumEven + ADigit; - end else begin - SumOdd := SumOdd + ADigit; - end; {if} - end; {for} - AChecksumDigit := StrToIntDef (ACode [Length (ACode)], 0); - Result := ((SumOdd*3 + SumEven + AChecksumDigit) MOD 10 = 0); -end; {--BarCodeValid--} - -{ used for EAN 8/13 } -function TMainForm.CheckSumModulo10(const data:string):string; - var i,fak,sum : Integer; -begin - sum := 0; - fak := Length(data); - for i:=1 to Length(data) do - begin - if (fak mod 2) = 0 then - sum := sum + (StrToInt(data[i])*1) - else - sum := sum + (StrToInt(data[i])*3); - dec(fak); - end; - if (sum mod 10) = 0 then - result := data+'0' - else - result := data+IntToStr(10-(sum mod 10)); -end; // // Bladhus *** @@ -4619,19 +4527,6 @@ ListBox1.SetFocus; // for at flytte fokus væk fra download knappen så denne ikke aktiveres ved scanning / indtastning af stregkode end; -function TMainForm.Explode(var a: TStrArray; Border, S: string): Integer; -var - S2: string; -begin - Result := 0; - S2 := S + Border; - repeat - SetLength(A, Length(A) + 1); - a[Result] := Copy(S2, 0,Pos(Border, S2) - 1); - Delete(S2, 1,Length(a[Result] + Border)); - Inc(Result); - until S2 = ''; -end; // ToDo: PrintPakkeshopLabel() procedure TMainForm.PrintPakkeshopLabel( PakkeshopLabel : TPakkeshopLabel); @@ -4922,7 +4817,7 @@ // stregkoderMedTjekkodeArray[linienr] := stregkode; if (pos(' ', stregkode) > 0) then begin - stregkoderMedTjekkodeArray[linienr] := split(stregkode, ' ', 2); // Fjerner lige en evt. fremtidig dato fra feltet + stregkoderMedTjekkodeArray[linienr] := TUtils.split(stregkode, ' ', 2); // Fjerner lige en evt. fremtidig dato fra feltet end else begin @@ -5204,10 +5099,10 @@ ReadLn(SomeTxtFile, buffer) ; S := buffer; SetLength(A,0); - Explode(A, ';', S); + TUtils.Explode(A, ';', S); if (length(A) < 2) then begin - Explode(A, ',', S); + TUtils.Explode(A, ',', S); end; if (length(A) > 1) then begin @@ -5281,10 +5176,10 @@ ReadLn(SomeTxtFile, buffer) ; S := buffer; SetLength(A,0); - Explode(A, ';', S); + TUtils.Explode(A, ';', S); if (length(A) < 3) then begin - Explode(A, ',', S); + TUtils.Explode(A, ',', S); end; if (A[0]=imorgenYmd) then begin @@ -5538,25 +5433,6 @@ end; -procedure TMainForm.RoundCornerOf(Control: TWinControl); -var - R: TRect; - Rgn: HRGN; -begin - with Control do - begin - R := ClientRect; -// rgn := CreateRoundRectRgn(R.Left, R.Top, R.Right, R.Bottom, 20, 20) ; - rgn := CreateRoundRectRgn(R.Left, R.Top, R.Right, R.Bottom, 25, 25) ; -// rgn := CreateRoundRectRgn(R.Left, R.Top, R.Right, R.Bottom, 30, 30) ; - Perform(EM_GETRECT, 0, lParam(@r)) ; - InflateRect(r, - 4, - 4) ; - Perform(EM_SETRECTNP, 0, lParam(@r)) ; - SetWindowRgn(Handle, rgn, True) ; - Invalidate; - end; -end; - procedure TMainForm.CheckPrintQue(tjektype : string); type TJobs = array [0..1000] of JOB_INFO_1;