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

📄 strct.pas

📁 西门子与计算机通讯程序包括源代码 程序说明 可以进行时时数据采集记录
💻 PAS
字号:
unit strct;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Mask,  ADODB,ComCtrls,DB, ExtCtrls,TypInfo,prodave,ComObj;

type
  TForm9 = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    ComboBox1: TComboBox;
    ComboBox2: TComboBox;
    Edit1: TEdit;
    Edit2: TEdit;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Edit3: TEdit;
    Panel1: TPanel;
    ListView1: TListView;
    Button5: TButton;
    Edit4: TEdit;
    ComboBox3: TComboBox;
    ComboBox4: TComboBox;
    Edit5: TEdit;
    Edit6: TEdit;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Edit7: TEdit;
    Label14: TLabel;
    Button4: TButton;
    procedure Button1Click(Sender: TObject);
    procedure ListView1CustomDrawSubItem(Sender: TCustomListView;
      Item: TListItem; SubItem: Integer; State: TCustomDrawState;
      var DefaultDraw: Boolean);
    procedure Button2Click(Sender: TObject);
    procedure ListView1SelectItem(Sender: TObject; Item: TListItem;
      Selected: Boolean);
    procedure Button3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Button5Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form9: TForm9;

implementation

uses main;

var
cat:Variant;
filename,sqlstring:string;
my_adoquery:TADOquery;


{$R *.dfm}

procedure TForm9.Button1Click(Sender: TObject);
var
index1:integer;
item1:TListitem;
begin
index1:=ListView1.ItemIndex  ;
if index1<0  then index1:= ListView1.Items.Count ;
if  ComboBox1.ItemIndex <0  then ComboBox1.ItemIndex := 0 ;
if  ComboBox2.ItemIndex <0  then ComboBox2.ItemIndex := 0 ;
if strtoint(Edit1.Text)<0 then edit1.text:='1';
 if strtoint(Edit2.Text)<0 then edit2.text:='0';
if   ( ( ComboBox1.ItemIndex >=3) and (ComboBox1.ItemIndex<=5))  then ComboBox2.ItemIndex := 1;
 if ComboBox1.ItemIndex<>5 then  Edit1.Text:='0';

 item1:=ListView1.Items.Insert(index1+1);
 item1.SubItems.Insert(0,GetEnumName(TypeInfo(TmemEnumType),ComboBox1.ItemIndex) );
 item1.SubItems.Insert(1,GetEnumName(TypeInfo(TtypeEnumType),ComboBox2.ItemIndex) );
 item1.SubItems.Insert(2,Edit1.Text);
 item1.SubItems.Insert(3,Edit2.Text);
 item1.Caption:=edit3.text ;

  //item1.Caption:=edit3.text+GetEnumName(TypeInfo(TtypeEnumType),ComboBox2.ItemIndex) ;
end;

procedure TForm9.ListView1CustomDrawSubItem(Sender: TCustomListView;
  Item: TListItem; SubItem: Integer; State: TCustomDrawState;
  var DefaultDraw: Boolean);
begin
 case  Item.Index mod 3  of
 0:     Sender.Canvas.Brush.Color :=claqua  ;
 1:     Sender.Canvas.Brush.Color :=cllime;
 2:     Sender.Canvas.Brush.Color :=clred;
 end  ;

end;

procedure TForm9.Button2Click(Sender: TObject);
begin
ListView1.DeleteSelected;  
end;

procedure TForm9.ListView1SelectItem(Sender: TObject; Item: TListItem;
  Selected: Boolean);
begin
Label7.Caption:='当前行号'+inttostr(ListView1.ItemIndex);


end;

procedure TForm9.Button3Click(Sender: TObject);
begin
ListView1.Clear;
end;

procedure TForm9.FormCreate(Sender: TObject);
begin

 ComboBox1.ItemIndex :=0;
 ComboBox2.ItemIndex:=0;
end;

procedure TForm9.Button5Click(Sender: TObject);
var
  I,j: Integer;
  pchar1:pchar;
  sqlstr:string;
  sqlvaue:string;
begin

 if not DirectoryExists( ExtractFilePath(Application.Exename)+'data') then   //二次目录存在否
       CreateDirectory(PChar(ExtractFilePath(Application.Exename)+'data'),nil);    //创建目录
   filename:=ExtractFilePath(Application.Exename)+'data/'+FormatdateTime('yy/mm/dd/hh.nn.ss',now)+'db.mdb';
     Label8.Caption:= application.GetNamePath;
  if Fileexists(filename) then              //判断是否存在重名数据库
        if Application.MessageBox('已存在相同时间的数据库!!!' + #13#10 +
          '是否建立另一时间的数据库', '警告', MB_YESNO + MB_DEFBUTTON2 + MB_TOPMOST) =  IDNO
        then
          exit;


  //建立数据库表
       databasetable:='';
       databasetype:='';
       datalogname:='(状态,日期';
   for I := 0 to ListView1.Items.Count -1 do    // Iterate
   begin
     databasetable:=databasetable+','+ TrimRight (ListView1.Items[i].Caption)+'  '+'int'; //创建数据库表名
     datalogname:=datalogname+ ','+TrimRight (ListView1.Items[i].Caption );

   end;    // for
     datalogname:=datalogname+')';
     sqlstring:=  'create table db('+ '状态 int ,日期 date'+databasetable+')';
         try
           cat:=CreateOleObject('ADOX.Catalog');      //创建数据库类
           cat.Create(Format('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s',[filename]));
           cat:=Unassigned;
         except
           showmessage('数据创建失败!');
         end;

         databasetype:=  'itemname CHARACTER (40),memtype CHARACTER (10),memsize CHARACTER (10),dbnumber INTEGER,datanum INTEGER' ;
         try
             my_adoquery:=Tadoquery.Create(self);    //创建adoquery组件
             my_adoquery.connectionstring:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+filename+';';
             my_adoquery.SQL.Clear ;
             my_adoquery.SQL.Add(sqlstring);
             my_adoquery.ExecSQL;
             
             sqlstring:= 'create table type1('+databasetype+')';
             my_adoquery.SQL.Clear ;
             my_adoquery.SQL.Add(sqlstring);
             my_adoquery.ExecSQL;


               sqlvaue:='';
               sqlstr:='INSERT INTO type1 (itemname, memtype,memsize,dbnumber,datanum) values (' ;

               for I := 0 to  ListView1.Items.Count -1 do    // Iterat
                   begin
                   sqlvaue:='';
                   sqlvaue:=sqlstr+''''+ListView1.Items[i].Caption+''''+','+''''+ListView1.Items[i].SubItems[0]+''''+',' +''''+ListView1.Items[i].SubItems[1]+''''+','+
                   ListView1.Items[i].SubItems[2]+','+ListView1.Items[i].SubItems[3]+')'  ;                   ;
                my_adoquery.SQL.Clear ;
                my_adoquery.SQL.Add(sqlvaue);
                my_adoquery.ExecSQL;
                   end;

                my_adoquery.Destroy;
              databasenamelog:=filename;
              databaselogok:=true; // showmessage('创建成功!');
           
         except
          showmessage( '创建数据表失败!'+ #13#10+'请确认数据表名称栏是否有重复项');
          my_adoquery.Destroy;
         end;  //creat end

   //创建命令字 数组
   //创建数据库表项 数组
   j:=0;
   for I := 0 to  ListView1.Items.Count -1 do    // Iterate
   begin


         databasetablearay[i]:='';
         databasetablearay[i]:=TrimRight (ListView1.Items[i].Caption);

         pchar1:=pchar((ListView1.Items[i].SubItems[0]));
     mixdata[i].Typ:=(pchar1[0]);
         pchar1:=pchar((ListView1.Items[i].SubItems[1]));
     mixdata[i].Size:=(pchar1[0]);
     mixdata[i].BstNr:=strtoint(ListView1.Items[i].SubItems[2]);
     mixdata[i].Nr:=strtoint(ListView1.Items[i].SubItems[3]);



       if mixdata[i].Size=('b') then
       begin
         mixdatatype[j]:=('b');
         j:=j+1;
       end else
       begin
         mixdatatype[j]:=('w');
         mixdatatype[j+1]:=('z');
         j:=j+2;
       end;

         
   end;    // for




   mixdata[ListView1.Items.Count].Typ:= char(0);
   mixdatatype[j]:=char(byte(0));
   mixdatacount:=ListView1.Items.count;
  if databaselogok    then form9.Close;
  if databaselogok then databaselogconnectok:=false;
end;

end.

⌨️ 快捷键说明

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