⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 deltovb.~pas

📁 delphi 自动生成 vb 数据窗体
💻 ~PAS
📖 第 1 页 / 共 2 页
字号:
        add('dt1.recordset.update');
        //Add('case 1:dt1.recordsource ="updata '+ dname + 'set '+ filed +' where ' + list1.Items.Strings[0] + '='#39'" & txt' + list1.Items.Strings[0] + ' &"'#39'');
        add('case 2:dt1.recordsource ="delete from ' + dname + ' where ' + list1.Items.Strings[0] + '='#39'" & txt' + list1.Items.Strings[0] + ' &"'#39'');
        add('case 3:unload me ');
        add('end select');
        add('if index<>3  then');
        Add('dt1.Refresh');
        add('call addmfgdata(dt1,mfg)');
        add('end if ');
        add('end sub');
        //函数把数据写到msf控件里
        add('function addmfgdata(dt1 as data,mfg as MSHFlexGrid )');
        add('dim i as integer');
        add('i=1');
        add('mfg.Cols=' + inttostr(list.Items.Count));
        for i:=0 to list.Items.Count -1 do
        add('mfg.TextMatrix(0,' + inttostr(i)+ ')="' + list.Items.Strings[i] + '"');
        add('do while not dt1.recordset.eof ');
        add('Mfg.Rows = Mfg.Rows + 1');

        for i:=0 to list.Items.Count -1 do
        add('mfg.TextMatrix(i,'+ inttostr(i) + ')=dt1.recordset!' + list.Items.Strings[i] + ' & ""');
        add('i=i+1');
        add('dt1.recordset.movenext');
        add('loop');
        add('end function');
        //窗体的 初始化
        add('Private Sub Form_Load()');
        Add('dt1.Connect = "dBASE 5.0;"');
        Add('dt1.DatabaseName = "'+ path +'"');
        Add('dt1.RecordsetType = 1 ');
        add('dt1.recordsource="select ' + filstr + ' from ' + dname + '"' );
        add('dt1.refresh');
        Add(' call addmfgdata(dt1,mfg)');
        add('End Sub');
        //mfg点击事件
        Add('Private Sub mfg_Click()');
        Add('Dim i As Integer');
        Add('With mfg');
        for i:=0 to list.Count  -1 do
        Add('txt'+list.Items.Strings[i]+'.text=.TextMatrix(.row,'+inttostr(i)+')');
        //Add('txt'+ list.Items.strings[list.Count -1] +'.text=.textmatrix(.row,0)');
        Add('end with');
        Add('End Sub');
 end;
 dBaselink:=true;
end;
//++++++++++++ FoxPro  表格的连接操作 ++++++++++++++++++++++
function foxprolink(list:tlistbox;list1:tlistbox;table:string;memo:tmemo):boolean;
begin
with memo.Lines  do
 begin
        //add('dt1.Connect = "dBASE 5.0;" ');
//dt1.DatabaseName = "d:\数据库"
//dt1.RecordsetType = 1
//dt1.RecordSource = "select * from BXLLD"
//dt1.Refresh');
 end;
 foxprolink:=true;
end;
//+++++++++++++Paradox 表格的连接操作++++++++++++++++++++++++++
function Paradoxlink(list:tlistbox;list1:tlistbox;table:string;memo:tmemo):boolean;
begin
with memo.Lines  do
 begin
        add('');
 end;
 Paradoxlink:=true;
end;
//+++++++++++++Ms SQL 表格的连接操作+++++++++++++++++++++++++++++++++
function MsSQLlink (list:tlistbox;list1:tlistbox;table:string;memo:tmemo):boolean;
begin
with memo.Lines  do
 begin
        add('');
 end;
 MsSQLlink:=true;
end;
//function MFGRowAdd(dname:string;path:string;

procedure TForm1.Button1Click(Sender: TObject);
var SQLServer:Variant;
ServerList:Variant;
i,nServers:integer;
constr:widestring;
begin
case combobox1.ItemIndex of
0:od.Filter:='*.mdb|*.mdb';
1..2:od.Filter:='*.dbf|*.dbf';
3:od.Filter:='*.db|*.db';
else
        begin
        SQLServer := CreateOleObject('SQLDMO.Application');
        ServerList:= SQLServer.ListAvailableSQLServers;
        nServers:=ServerList.Count;
        combobox2.Clear ;
        for i := 1 to nservers do
                comboBox2.Items.Add(ServerList.Item(i));
        SQLServer:=NULL;
        serverList:=NULL;
        gb1.Visible :=true;
        gb2.Top := 194;
        self.Height :=450;
        button7.Top :=gb2.Top +gb2.Height +7;
        end;

end;
if (combobox1.ItemIndex=0) or (combobox1.ItemIndex=1) or (combobox1.ItemIndex=2) or (combobox1.ItemIndex=3) then
begin
od.Execute;
combobox2.Text:=od.FileName ;

case combobox1.ItemIndex of
0:begin
  if combobox2.Text <>'' then
  begin
  label5.Visible :=true;
  combobox5.Visible :=true;
  constr:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+combobox2.Text  +';Persist Security Info=False';
  strcnn:=constr;
  ac.ConnectionString:=constr;
  ac.GetTableNames(combobox5.Items,false);
  end;
end;
1:begin
  tb.TableType:=ttDBase;
  tb.TableName :=combobox2.Text ;
  tb.GetFieldNames(listbox1.Items);
  end;
2:begin
  tb.TableType :=ttFoxPro;
  tb.TableName :=combobox2.Text ;
  tb.GetFieldNames(listbox1.Items );
  end;
3:begin
  tb.TableType :=ttParadox;
  tb.TableName :=combobox2.Text ;
  tb.GetFieldNames(listbox1.Items);
  end;
end;
gb2.Top:= 88;
self.Height :=365;
button7.Top :=gb2.Top +gb2.Height +7;
end;
end;

procedure TForm1.ComboBox2Click(Sender: TObject);
begin
if combobox1.ItemIndex=4 then
GB1.Visible :=true;

end;

procedure TForm1.Button6Click(Sender: TObject);
var constr :widestring;
begin
if labelededit2.Text ='' then
constr:='Provider=SQLOLEDB.1;Persist Security Info=False;User ID='+labelededit1.Text +';Data Source=' + combobox2.Text
else
constr:='Provider=SQLOLEDB.1;Password='+ labelededit2.Text  +';Persist Security Info=False;User ID='+labelededit1.Text +';Data Source=' + combobox2.Text;

aq.ConnectionString:=constr;
aq.Close;
aq.SQL.Add ('select name  from OPENDATASOURCE('#39'MSDASQL'#39','#39'DRIVER={SQL Server};SERVER=yueqiong;UID=sa'#39').master.dbo.sysdatabases');
aq.Open ;
combobox3.clear;
while not aq.Eof do
begin
combobox3.Items.Add(aq.FieldValues['name']);
aq.Next;
end;
GB1.Height :=105;
end;

procedure TForm1.ComboBox3Click(Sender: TObject);
var constr:widestring;
begin

constr:='Provider=SQLOLEDB.1;Persist Security Info=False;User ID='+labelededit1.Text +';Initial Catalog='+ combobox3.Text  +';Data Source=' + combobox2.Text;
strcnn:=constr;
ac.ConnectionString:=constr;
ac.Open(labelededit1.Text,labelededit2.Text);
ac.GetTableNames(combobox4.Items,true);
ac.Close ;
end;

procedure TForm1.ComboBox4Click(Sender: TObject);
begin
listbox1.Clear ;
ac.Open(labelededit1.Text,labelededit2.Text);
ac.GetFieldNames(combobox4.Text,listbox1.Items );
ac.Close ;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
if listbox1.ItemIndex >=0 then
listbox2.Items.Add(listbox1.Items.Strings[listbox1.Itemindex ]);
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
if listbox2.ItemIndex >=0 then
listbox2.DeleteSelected;

end;
procedure TForm1.Button2Click(Sender: TObject);
var i:integer;
begin
for i:=0 to  listbox1.Items.Count-1 do
        listbox2.Items.Add(listbox1.Items.Strings[i]);
        listbox1.Clear; 

end;

procedure TForm1.Button3Click(Sender: TObject);
var i:integer;
begin
for i:=0 to  listbox2.Items.Count-1 do
        listbox1.Items.Add(listbox2.Items.Strings[i]);
        listbox2.Clear;
end;

procedure TForm1.ComboBox5Click(Sender: TObject);
begin
listbox1.Clear ;
ac.GetFieldNames(combobox5.Text,listbox1.Items);
end;

procedure TForm1.Button7Click(Sender: TObject);
var tabindex:integer;
    left:integer;
    top:real;
    i:integer;
begin
top:=(int(listbox1.Count /3)+1) *480 +2440;

tabindex:=listbox1.Items.Count +4;
left:=360;//2200
AddButton('添加','0',inttostr(left),inttostr(tabindex),floattostr(top),memo1);
AddButton('修改','1',inttostr(left+2200),inttostr(tabindex-1),floattostr(top),memo1);
AddButton('删除','2',inttostr(left+4400),inttostr(tabindex-2),floattostr(top),memo1);
AddButton('关闭','3',inttostr(left+6600),inttostr(tabindex-3),floattostr(top),memo1);
tabindex:=tabindex-4;
for i:=0 to listbox1.Items.Count-1 do
begin
left:=1200+3120*(i mod 3);
top:=2400+int(i /3) *480;
addtext(listbox1.Items.Strings[i],inttostr(left),inttostr(tabindex-i),listbox1.Items.Strings[i],floattostr(top),memo1);
end;
for i:=0 to listbox1.Items.Count-1 do
begin
top:=2400+int(i /3) *480;
left:=120+3120*(i mod 3);
addlabel(listbox1.Items.Strings[i],inttostr(left),'0',listbox1.Items.Strings[i],floattostr(top),memo1);
end;
if (combobox1.ItemIndex<>0) and (combobox1.ItemIndex<>4)  then
adddata('dt1',memo1);
memo1.Lines.Add('End');
memo1.Lines.Add('Attribute VB_Name = "Form1"');
memo1.Lines.Add('Attribute VB_GlobalNameSpace = False');
memo1.Lines.Add('Attribute VB_Creatable = False');
memo1.Lines.Add('Attribute VB_PredeclaredId = True');
memo1.Lines.Add('Attribute VB_Exposed = False');
case combobox1.ItemIndex of
0:AccessLink(listbox1,listbox2,combobox5.Text,memo1);
1:dBaselink(listbox1,listbox2,combobox2.Text,memo1);
2:Paradoxlink(listbox1,listbox2,combobox2.Text,memo1);
3:foxprolink(listbox1,listbox2,combobox2.Text,memo1);
4:MsSQLlink (listbox1,listbox2,combobox2.Text,memo1);
end;
memo1.Lines.SaveToFile('C:\form1.frm');
end;


end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -