从右键菜单里粘贴复制的工资到数据库里
在popupmenu的onclick事件里添加如下事件处理程序
1 procedure TForm3.N1Click(Sender: TObject); 2 var 3 KeFuAry: TArray<string>; 4 YueFen: string; 5 MyList: TStringList; 6 MyAdoq: TADOQuery; 7 I: Integer; 8 MyClipboard: TClipboard; 9 begin 10 MyList := TStringList.Create; 11 MyAdoq := TADOQuery.Create(nil); 12 MyClipboard := TClipboard.Create; 13 try 14 MyAdoq.Connection := frmDataPool.ADOConnection1; 15 //获取月份 16 if not InputQuery('输入月份', '输入月份', YueFen) then 17 begin 18 ShowMessage('请输入月份'); 19 Exit; 20 end; 21 //从剪切板取到数据 22 MyList.Text := MyClipboard.AsText; 23 24 25 //取出空值逐行读取 26 for I := 0 to MyList.Count - 1 do 27 begin 28 if (MyList[I] <> '') and (MyList[I] <> '工资汇总:') then 29 begin 30 KeFuAry := MyList[I].Replace(':', ',').Replace('(', '').Replace(')', '').Replace('基本工资', '').Replace('- 个人社保', ',').Replace('- 个人公积金',','). 31 Replace('+ 加班请假', ',').Replace('+ 销售提成', ',').Replace('+ 销售奖金',',').Replace('+ 积分奖金', ',').Replace('+ QQ群奖金', ','). 32 Replace('= ',',').Replace(' 元','').Split([',']); 33 34 //写入数据库 35 with MyAdoq do 36 begin 37 Close; 38 SQL.Text := 'INSERT INTO 工资表(月份,姓名,基本工资,个人社保代缴,个人公积金代缴,加班请假,销售提成,销售奖金,售后积分奖金,QQ群等级奖金,工资总额) VALUES ('+YueFen.QuotedString+','+KeFuAry[0].QuotedString+','+ 39 KeFuAry[1]+',-'+KeFuAry[2]+',-'+KeFuAry[3]+','+KeFuAry[4]+','+KeFuAry[5]+','+ 40 KeFuAry[6]+','+KeFuAry[7]+','+KeFuAry[8]+','+KeFuAry[9]+')'; 41 ExecSQL; 42 end; 43 end; 44 45 //防止程序假死 46 Application.ProcessMessages; 47 end; 48 49 //刷新下显示 50 frmDataPool.qry工资表.Close; 51 frmDataPool.qry工资表.Open; 52 finally 53 MyList.Free; 54 MyAdoq.Free; 55 MyClipboard.Free; 56 end; 57 end;