河北行业网>国内 > 正文

计算器在线使用计算(SDO100怎样使用)

2023-07-11 08:27:16 来源: 科技网


(资料图片)

1、用ADOQUERY,如果您在Windows下使用(一般多数都使用windows,也用Unix等其它操作系统),建议使用ADOQUERY.因为ADO是微软的为开发数据连接而设定的一套协议。

2、以下是本人使用ADO的部分小片段(《建筑材料管理系统》软件):procedure TFormsdl513.BitBtn1Click(Sender: TObject);var Date1,Date2:TDateTime; StrSQl,StrCllb,StrClbm,sTempX:String; Ldate,Lstr,FileEXit,YesNo:Boolean; SL:TStrings; i:integer;begin Ldate:=False; Lstr:=False; Date1:=date; Date2:=date; YesNo:=False; if CheckBox1.Checked and (not CheckBox2.Checked) then //如果仅仅考虑日期 begin WIth dm.ADOTable_ChaXun do begin Date1:=FieldValues["D1"]; Date2:=FieldValues["D2"]+1;//含这一天,故加1 end; Ldate:=True; Lstr:=False; end; if (not CheckBox1.Checked) and CheckBox2.Checked then //如果仅仅考虑科目 begin StrCllb:=Leftstr(ComboBox1.Text,2); StrClbm:=Midstr(comboBox1.Text,4,2); Ldate:=False; Lstr:=True; end; if CheckBox1.Checked and CheckBox2.Checked then //考虑科目和日期 begin With dm.ADOTable_ChaXun do begin Date1:=FieldValues["D1"]; Date2:=FieldValues["D2"]+1;//含这一天,故加1 end;//With dm.ADOTable_ChaXun do StrCllb:=Leftstr(ComboBox1.Text,2); StrClbm:=Midstr(comboBox1.Text,4,2); Ldate:=True; Lstr:=True; end; //end if CheckBox1.Checked and CheckBox2.Checked then //考虑科目和日期 {开始具体处理} {首先,删除Temp513,并建立表的所有数据} FileExit:=False;//判断Temp513表是否存在 SL:=TStringList.Create; dm.ADOConnection1.GetTableNames(SL,false); for i := 0 to SL.Count-1 do if pos("Temp513",Sl.Strings[i])>0 then begin FileExit:=True;//表Temp513存在 break; end; SL.Free;//释放 SL if FileExit then //如果表temp存在,先删除它,再新建 with dm.ADOQuery_Public do begin if Active then Active:=False; SQL.Clear; SQL.Add("DROP Table Temp513"); ExecSQL; end; {以下16-17行是建立一个临时表Temp} strSQL:="Create Table Temp513(bm1 character(2),bm2 character(2)," +"mc character(16),sr double,zc double)"; {bm1,bm2,mc,sr,zc 分别是编码1,编码2,名称,收入,支出} with dm.ADOQuery_Public do begin if Active then Active:=False; SQL.Clear; SQL.Add(strSQl); ExecSQL; end; if CheckBox3.Checked and (LeftStr(ComboBox2.Text,4)<>"NoNo") then begin YesNo:=True; sTempX:=LeftStr(ComboBox2.Text,4); end; {仅仅考虑日期范围} if LDate and (not LStr) then //仅仅考虑日期范围 begin strSql:="Insert into Temp513(bm1,bm2,mc,sr,zc) " +"Select bm1,bm2,mc,sum(sr) as sr,sum(zc) as zc" +" From srzc WHERE rq>=:Date1_0 and rq<:Date2_0"; if YesNo then strSql:=strSql+" and xmbm=:xmbm_0"; strSql:=strSql+" Group By bm1,bm2,mc"; With dm.ADOQuery_Public do begin if Active then Active:=False; SQL.Clear; SQL.Add(strSql); Parameters[0].Value :=Date1; Parameters[1].Value :=Date2; if YesNo then Parameters[2].Value :=sTempX; ExecSQL; end; // end With dm.ADOQuery_Public do With dm.ADOTable_ChaXun do begin Active:=True; Edit; FieldByName("T2").AsString := "考虑自"+DateTimeTostr(Date1)+"至"+DateTimeTostr(Date2-1) +"止期间的数据("+MidStr(ComboBox2.Text,6,16)+")"; Post; end; end; //end if LDate and (not LStr) then //仅仅考虑日期范围 {仅仅考虑科目} if (not LDate) and LStr then //仅仅考虑科目 begin strSql:="Insert into Temp513(bm1,bm2,mc,sr,zc) " +"Select bm1,bm2,mc,sum(sr) as sr,sum(zc) as zc" +" From srzc WHERE bm1=:strcllb_0 and bm2=:strclbm_0"; if YesNo then strSql:=strSql+" and xmbm=:xmbm_0"; strSql:=strSql+" Group By bm1,bm2,mc"; With dm.ADOQuery_Public do begin if Active then Active:=False; SQL.Clear; SQL.Add(strSql); Parameters[0].Value :=strcllb; Parameters[1].Value :=strclbm; if YesNo then Parameters[2].Value :=sTempX; ExecSQL; end; // end With dm.ADOQuery_Public do with dm.ADOTable_ChaXun do begin Active:=True; Edit; FieldByName("T2").AsString := "考虑一级编码为:"+ strcllb +",二级编码为:"+ strclbm+"的数据("+ MidStr(ComboBox2.Text,6,16)+")"; Post; end; end; //end if (LDate=False and LStr=True) then //仅仅考虑科目 {科目和日期范围均考虑} if (LDate and LStr) then //科目和日期范围均考虑 begin strSql:="Insert into Temp513(bm1,bm2,mc,sr,zc) " +"Select bm1,bm2,mc,sum(sr) as sr,sum(zc) as zc" +" From srzc WHERE rq>=:Date1_0 and rq<:Date2_0 " +" and bm1=:strcllb_0 and bm2=:strclbm_0"; if YesNo then strSql:=strSql+" and xmbm=:xmbm_0"; strSql:=strSql+" Group By bm1,bm2,mc"; With dm.ADOQuery_Public do begin if Active then Active:=False; SQL.Clear; SQL.Add(strSql); Parameters[0].Value :=Date1; Parameters[1].Value :=Date2; Parameters[2].Value :=Strcllb; Parameters[3].Value :=strclbm; if YesNo then Parameters[4].Value :=sTempX; ExecSQL; end; // end With dm.ADOQuery_Public do with dm.ADOTable_ChaXun do begin Active:=True; Edit; FieldByName("T2").AsString := "考虑自"+DateTimeTostr(Date1)+"至"+DateTimeTostr(Date2-1) +" 一级编码为:"+ strcllb +",二级编码为:"+ strclbm+"的费用数据("+ MidStr(ComboBox2.Text,6,16)+")"; Post; end; //with dm.ADOTable_ChaXun do end; //end (LDate and LStr) then //科目和日期范围均考虑//Application.CreateForm(TFormsdl513_1, Formsdl513_1);Formsdl513_1:=TFormsdl513_1.Create(Application);Formsdl513_1.ShowModal; //明细表Formsdl513_1.Free;with dm.ADOQuery_Public dobeginif Active then Active:=False;SQL.Clear;SQL.Add("DROP Table Temp513");ExecSQL;end;{以上删除表Temp513}end;--------------------------------------------------------这里 dm.ADOQuery_Public就是dm这个数据模块中的TADOQUERY组件,你看到利用它可以在数据库中建表:strSQL:="Create Table Temp513(bm1 character(2),bm2 character(2)," +"mc character(16),sr double,zc double)";利用它可以在数据库中删表:SQL.Add("DROP Table Temp513");利用它可以在数据库中插入添加数据:strSql:="Insert into Temp513(bm1,bm2,mc,sr,zc) " +"Select bm1,bm2,mc,sum(sr) as sr,sum(zc) as zc" +" From srzc WHERE rq>=:Date1_0 and rq<:Date2_0"; if YesNo then strSql:=strSql+" and xmbm=:xmbm_0"; strSql:=strSql+" Group By bm1,bm2,mc";利用它可以在数据库中select等操作。

3、以上内容是实际源码,请多指教!只有大家都用它,我们一起才能取长补短,一起进步。

本文到此讲解完毕了,希望对大家有帮助。

关键词:

[责任编辑: sdhyw]