从记事本里导入工资数据到数据库的写法,
这种需要用的opendialog 要先添加这个组件;
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 //获取月份 14 if not InputQuery('输入月份', '输入月份', YueFen) then 15 begin 16 ShowMessage('请输入月份'); 17 Exit; 18 end; 19 //从剪切板取到数据 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('打开文件失败'); 29 end; 30 31 //取出空值逐行读取 32 for I := 0 to MyList.Count - 1 do 33 begin 34 if (MyList[I] <> '') and (MyList[I] <> '工资汇总:') then 35 begin 36 KeFuAry := MyList[I].Replace(':', ',').Replace('(', '').Replace(')', '').Replace('基本工资', '').Replace('- 个人社保', ',').Replace('- 个人公积金',','). 37 Replace('+ 加班请假', ',').Replace('+ 销售提成', ',').Replace('+ 销售奖金',',').Replace('+ 积分奖金', ',').Replace('+ QQ群奖金', ','). 38 Replace('= ',',').Replace(' 元','').Split([',']); 39 40 //写入数据库 41 with MyAdoq do 42 begin 43 Close; 44 SQL.Text := 'INSERT INTO 工资表(月份,姓名,基本工资,个人社保代缴,个人公积金代缴,加班请假,销售提成,销售奖金,售后积分奖金,QQ群等级奖金,工资总额) 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; 50 51 //防止程序假死 52 Application.ProcessMessages; 53 end; 54 55 //刷新下显示 56 frmDataPool.qry工资表.Close; 57 frmDataPool.qry工资表.Open; 58 finally 59 MyList.Free; 60 MyAdoq.Free; 61 end; 62 end;