Import payroll data from Notepad to the database,
This need to use the OpenDialog to first add this component;
1 procedure TForm3.N6Click(Sender: TObject);
2 var
3 KeFuAry: TArray<string>;
4 YueFen: string;
5 MyList: TStringList;
6 MyAdoq: TADOQuery;
7 I: Integer;
8 begin
9 MyList := TStringList.Create;
10 MyAdoq := TADOQuery.Create(nil);
11 try
12 MyAdoq.Connection := frmDataPool.ADOConnection1;
13 / / get month
14 if not inputquery ("input month", "input month", Yuefen) then
15 begin
16 showmessage ('Please enter the month ');
17 Exit;
18 end;
19 / / get data from the clipboard
20 try
21 if OpenDialog1.Execute then
22 begin
23 MyList.Clear;
24 MyList.LoadFromFile(OpenDialog1.FileName);
25 end;
26 except
27 on E:EReadError do
28 showmessage ('failed to open file ');
29 end;
Thirty
31 / / take out the null value and read it line by line
32 for I := 0 to MyList.Count - 1 do
33 begin
34 If (mylist [i] < and (mylist [i] < payroll summary: ') then
35 begin
36 kefuary: = mylist [i]. Replace (':', '). Replace (', '). Replace (', '). Replace ('), '). Replace (' - personal social security ','). Replace ('- personal provident fund', ',')
37 replace ('+ overtime leave', ','). Replace ('+ sales commission', '). Replace (' + sales bonus', '). Replace (' + point bonus', ','). Replace ('+ QQ group bonus',', ')
38 replace ('=', ','). Replace ('yuan ','). Split ([',']);
Thirty-nine
40 / / write to database
41 with MyAdoq do
42 begin
43 Close;
44 SQL. Text: = 'insert into salary table (month, name, basic salary, individual social security payment, individual accumulation fund payment, overtime leave, sales commission, sales bonus, after-sales bonus, QQ group level bonus, total salary) values (' + Yuefen. Quotedstring + ',' + kefuary [0]. Quotedstring + ',')+
45 KeFuAry[1]+‘,-‘+KeFuAry[2]+‘,-‘+KeFuAry[3]+‘,‘+KeFuAry[4]+‘,‘+KeFuAry[5]+‘,‘+
46 KeFuAry[6]+‘,‘+KeFuAry[7]+‘,‘+KeFuAry[8]+‘,‘+KeFuAry[9]+‘)‘;
47 ExecSQL;
48 end;
49 end;
Fifty
51 / / prevent program death
52 Application.ProcessMessages;
53 end;
Fifty-four
55 / / refresh the display
56 frmdatapool.qry payroll.close;
57 frmDataPool.qry payroll.Open;
58 finally
59 MyList.Free;
60 MyAdoq.Free;
61 end;
62 end;
How to import payroll data to a database from Notepad