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

📄 datasourceformunit1.pas

📁 delphi开发的抄表数据管理系统
💻 PAS
字号:
unit datasourceformunit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, ComCtrls, Buttons,pcomm,inifiles,StrUtils;

type
  TComSettingForm = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    Button1: TButton;
    Button2: TButton;
    Bevel2: TBevel;
    Bevel1: TBevel;
    ComboBox1: TComboBox;
    Label1: TLabel;
    Label2: TLabel;
    ComboBox2: TComboBox;
    Label3: TLabel;
    ComboBox3: TComboBox;
    Label4: TLabel;
    ComboBox4: TComboBox;
    Label5: TLabel;
    ComboBox5: TComboBox;
    Label6: TLabel;
    ComboBox6: TComboBox;
    BitBtn1: TBitBtn;
    Bevel3: TBevel;
    Bevel4: TBevel;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    Panel1: TPanel;
    DateTimePicker1: TDateTimePicker;
    DateTimePicker2: TDateTimePicker;
    procedure BitBtn1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button2Click(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
    procedure TabSheet2Hide(Sender: TObject);
    procedure TabSheet2Show(Sender: TObject);
    procedure TabSheet1Hide(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure RadioButton1Click(Sender: TObject);
    procedure RadioButton2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  ComSettingForm: TComSettingForm;

implementation

{$R *.dfm}

procedure TComSettingForm.BitBtn1Click(Sender: TObject);
begin
    if length(combobox1.Text)=0 then
       exit
    else
    begin
       combobox2.Text :='9600';
       combobox3.Text :='8';
       combobox4.text :='无';
       combobox5.Text :='1';
       combobox6.Text :='硬件';
    end;
end;

procedure TComSettingForm.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
    ComSettingForm:=nil;
    action:=cafree;
end;

procedure TComSettingForm.Button2Click(Sender: TObject);
begin
    ComSettingForm.Close;
end;

procedure TComSettingForm.ComboBox1Change(Sender: TObject);
begin
    if length(combobox1.Text)=0 then
       button1.Enabled:=false
    else
       button1.Enabled:=true;
end;

procedure TComSettingForm.TabSheet2Hide(Sender: TObject);
begin
    combobox1.Clear;
    combobox2.Clear;
    combobox3.Clear;
    combobox4.Clear;
    combobox5.Clear;
    combobox6.Clear;
    button1.Enabled:=false;
end;

procedure TComSettingForm.TabSheet2Show(Sender: TObject);
var
  i,ret:integer;
  TempProfile:tinifile;
begin
    for i:=1 to 16 do
    begin
        ret:=sio_open(i);
        if ret=0 then
           begin
               combobox1.Items.Add('COM'+inttostr(i));
               sio_close(i);
           end
        else if ret=-1 then
           exit
        else if ret=-5 then
           continue;
    end;
    combobox2.Items.Add('110');
    combobox2.Items.Add('300');
    combobox2.Items.Add('1200');
    combobox2.Items.Add('2400');
    combobox2.Items.Add('4800');
    combobox2.Items.Add('9600');
    combobox2.Items.Add('19200');
    combobox2.Items.Add('38400');
    combobox2.Items.Add('38400');
    combobox2.Items.Add('115200');
    combobox2.Items.Add('230400');
    combobox2.Items.Add('460800');
    combobox2.Items.Add('921600');
    combobox3.Items.Add('4');
    combobox3.Items.Add('5');
    combobox3.Items.Add('6');
    combobox3.Items.Add('7');
    combobox3.Items.Add('8');
    combobox4.Items.Add('偶校验');
    combobox4.Items.Add('奇校验');
    combobox4.Items.Add('无');
    combobox4.Items.Add('标记');
    combobox4.Items.Add('空格');
    combobox5.Items.Add('1');
    combobox5.Items.Add('1.5');
    combobox5.Items.Add('2');
    combobox6.Items.Add('Xon / Xoff');
    combobox6.Items.Add('硬件');
    combobox6.Items.Add('无');
    //**********
    if FileExists(extractfilepath(application.ExeName)+'\TempProfile.ini') then
    begin
        TempProfile:=tinifile.Create(extractfilepath(application.ExeName)+'\TempProfile.ini');
        combobox1.Text:='COM'+TempProfile.ReadString('端口号','ComNo','');
        combobox2.Text:=TempProfile.ReadString('每秒位数','BBBB','');
        combobox3.Text:=TempProfile.ReadString('数据位','D','');
        if TempProfile.ReadString('奇偶校验','P','')='E' then
            combobox4.Text:='偶校验'
        else if TempProfile.ReadString('奇偶校验','P','')='0' then
            combobox4.Text:='奇校验'
        else if TempProfile.ReadString('奇偶校验','P','')='N' then
            combobox4.Text:='无'
        else if TempProfile.ReadString('奇偶校验','P','')='M' then
            combobox4.Text:='标记'
        else if TempProfile.ReadString('奇偶校验','P','')='S' then
            combobox4.Text:='空格';
        combobox5.Text:=TempProfile.ReadString('停止位','S','');
        if TempProfile.ReadString('数据流控制','H','')='ComXonXOff' then
            combobox6.Text:='Xon / Xoff'
        else if TempProfile.ReadString('数据流控制','H','')='ComRTS' then
            combobox6.Text:='硬件'
        else if TempProfile.ReadString('数据流控制','H','')='ComNone' then
            combobox6.Text:='无';
    end;
end;

procedure TComSettingForm.TabSheet1Hide(Sender: TObject);
begin
    radiobutton1.Checked:=false;
    radiobutton2.Checked:=false;
    datetimepicker1.Enabled :=false;
    datetimepicker2.Enabled :=false;
    datetimepicker1.Checked :=false;
    datetimepicker2.Checked :=false;
    button1.Enabled:=false;
end;

procedure TComSettingForm.Button1Click(Sender: TObject);
var
    BBBB, P, D, S, H, No,StartDate,EndDate : String;
    TempProfile:tinifile;
begin
    if tabsheet1.Showing  then
    begin
       if datetimepicker1.Checked and datetimepicker2.Checked then
       begin
           StartDate:=datetostr(datetimepicker1.date) + ' ' + '00:00:00';
           EndDate:=datetostr(datetimepicker2.date) + ' ' + '23:59:59';
       end
       else if datetimepicker1.Checked and not datetimepicker2.Checked then
       begin
           StartDate:=datetostr(datetimepicker1.date) + ' ' + '00:00:00';
           EndDate:='';
       end
       else if not datetimepicker1.Checked and datetimepicker2.Checked then
       begin
           StartDate:='';
           EndDate:=datetostr(datetimepicker2.date) + ' ' + '23:59:59';
       end
       else if radiobutton2.Checked then
       begin
           StartDate:='';
           EndDate:='';
       end;
       TempProfile:=tinifile.Create(extractfilepath(application.ExeName)+'\TempProfile.ini');
       TempProfile.WriteString('数据来源','DataSource','AGR');
       TempProfile.WriteString('起始日期','StartDate',StartDate);
       TempProfile.WriteString('结束日期','EndDate',EndDate);
    end
    else if tabsheet2.Showing then
    begin
       No:=rightstr(trim(combobox1.Text),1);
       BBBB:=trim(combobox2.Text);
       if trim(combobox4.Text)='偶校验' then
          P:='E'
       else if trim(combobox4.Text)='奇校验' then
          P:='0'
       else if trim(combobox4.Text)='无' then
          P:='N'
       else if trim(combobox4.Text)='标记' then
          P:='M'
       else if trim(combobox4.Text)='空格' then
          P:='S';
       if trim(combobox6.Text)='Xon / Xoff' then
          H:='ComXonXOff'
       else if trim(combobox6.Text)='硬件' then
          H:='ComRTS'
       else if trim(combobox6.Text)='无' then
          H:='ComNone';
       D:=trim(combobox3.Text);
       S:=trim(combobox5.Text);
       TempProfile:=tinifile.Create(extractfilepath(application.ExeName)+'\TempProfile.ini');
       TempProfile.WriteString('数据来源','DataSource','WCTU');
       TempProfile.WriteString('端口号','ComNo',No);
       TempProfile.WriteString('每秒位数','BBBB',BBBB);
       TempProfile.WriteString('数据位','D',D);
       TempProfile.WriteString('奇偶校验','P',P);
       TempProfile.WriteString('停止位','S',S);
       TempProfile.WriteString('数据流控制','H',H);
    end;
    TempProfile.Destroy;
    ComSettingForm.Close;
end;

procedure TComSettingForm.RadioButton1Click(Sender: TObject);
begin
    if RadioButton1.Checked then
    begin
        datetimepicker1.Enabled :=true;
        datetimepicker2.Enabled :=true;
        button1.Enabled:=true;
    end;
end;

procedure TComSettingForm.RadioButton2Click(Sender: TObject);
begin
    if RadioButton2.Checked then
    begin
        datetimepicker1.Enabled :=false;
        datetimepicker2.Enabled :=false;
        datetimepicker1.Checked :=false;
        datetimepicker2.Checked :=false;
        button1.Enabled:=true;
    end;
end;

end.

⌨️ 快捷键说明

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