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

📄 grouprateform.pas

📁 求是科技出版的《Delphi串口通信工程开发实例导航》所有的源代码。是一本很好的书。拿出来与大家共享。
💻 PAS
字号:
unit GroupRateForm;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  DialogBaseForm, StdCtrls, Buttons, ExtCtrls, ComCtrls, Spin, Grids,
  DBGrids, Db, DBCtrls, ADODB;

type
  TfrmGroupRate = class(TfrmDialogBase)
    PageControl1: TPageControl;
    tstTimePhase: TTabSheet;
    Panel2: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    sdtStartHour1: TSpinEdit;
    sdtStartMin1: TSpinEdit;
    sdtEndHour1: TSpinEdit;
    sdtEndMin1: TSpinEdit;
    sdtStartHour2: TSpinEdit;
    sdtStartMin2: TSpinEdit;
    sdtEndHour2: TSpinEdit;
    sdtEndMin2: TSpinEdit;
    sdtStartHour3: TSpinEdit;
    sdtStartMin3: TSpinEdit;
    sdtEndHour3: TSpinEdit;
    sdtEndMin3: TSpinEdit;
    sdtStartHour4: TSpinEdit;
    sdtStartMin4: TSpinEdit;
    sdtEndHour4: TSpinEdit;
    sdtEndMin4: TSpinEdit;
    tstGroupRate: TTabSheet;
    dsParkGroup: TDataSource;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    tstFeeRate: TTabSheet;
    Panel3: TPanel;
    Panel4: TPanel;
    DBGrid1: TDBGrid;
    DBNavigator1: TDBNavigator;
    Panel5: TPanel;
    Panel6: TPanel;
    dgdParkGroup: TDBGrid;
    tblParkGroup: TADOTable;
    tblFeeRate: TADOTable;
    Label17: TLabel;
    dsFeeRate: TDataSource;
    tblTimePhase: TADOTable;
    cbxParkGroup: TComboBox;
    procedure tblParkGroupBeforeDelete(DataSet: TDataSet);
    procedure cbxParkGroupChange(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
    function InsertFeeRate(AGroupId : integer): integer;
  public
    { Public declarations }
    function TimePhase2DB():integer;
    function DB2TimePhase():integer;

    function ActiveDB():integer;
    procedure FillCBX_ParkGroup();
  end;

var
  frmGroupRate: TfrmGroupRate;

implementation
uses
    GlobalUnit,
    plmsDM;
{$R *.DFM}

{ TfrmGroupRate }

function TfrmGroupRate.ActiveDB: integer;
var
    mConnection : TADOConnection ;
begin
    mConnection := GetRemoteConnection();
    if mConnection = nil then mConnection := GetLocalConnection();
    if mConnection = nil then
    begin

    end;

    with tblParkGroup do
    begin
        if not Active then
        begin
            //激活数据表
            try
                Connection := mConnection;
                TableName := 'park_group';
                Active := True;
                //记录指针到第一个
                if RecordCount > 0 then First;
                Result := 1;
            except
                //
                Result := -1;
            end;
        end;
    end;

    with tblFeeRate do
    begin
        if not Active then
        begin
            //激活数据表
            try
                Connection := mConnection;
                TableName := 'fee_rate';
                Active := True;
                //记录指针到第一个
                if RecordCount > 0 then First;
                Result := 1;
            except
                //
                Result := -1;
            end;
        end;
    end;
end;

function TfrmGroupRate.DB2TimePhase: integer;
var
    mConnection : TADOConnection;
begin
    with tblTimePhase do
    begin
        if not Active then
        begin
            mConnection := GetRemoteConnection();
            if mConnection = nil then mConnection := GetLocalConnection();
            if mConnection = nil then
            begin

            end;
            Connection := mConnection;
            TableName := 'time_phase';
            Active := True;
        end;
            //激活数据表
        try
            //记录指针到第一个
            if RecordCount > 0 then
            begin
                First;
                sdtStartHour1.Value:= FieldByName('start_hour1').AsInteger;
                sdtStartMin1.Value:= FieldByName('start_min1').AsInteger;
                sdtEndHour1.Value:= FieldByName('end_hour1').AsInteger;
                sdtEndMin1.Value:= FieldByName('end_min1').AsInteger;
                sdtStartHour2.Value:= FieldByName('start_hour2').AsInteger;
                sdtStartMin2.Value:= FieldByName('start_min2').AsInteger;
                sdtEndHour2.Value:= FieldByName('end_hour2').AsInteger;
                sdtEndMin2.Value:= FieldByName('end_min2').AsInteger;
                sdtStartHour3.Value:= FieldByName('start_hour3').AsInteger;
                sdtStartMin3.Value:= FieldByName('start_min3').AsInteger;
                sdtEndHour3.Value:= FieldByName('end_hour3').AsInteger;
                sdtEndMin3.Value:= FieldByName('end_min3').AsInteger;
                sdtStartHour4.Value:= FieldByName('start_hour4').AsInteger;
                sdtStartMin4.Value:= FieldByName('start_min4').AsInteger;
                sdtEndHour4.Value:= FieldByName('end_hour4').AsInteger;
                sdtEndMin4.Value:= FieldByName('end_min4').AsInteger;
            end
            else begin
                sdtStartHour1.Value:= 0;
                sdtStartMin1.Value:= 0;
                sdtEndHour1.Value:= 0;
                sdtEndMin1.Value:= 0;
                sdtStartHour2.Value:= 0;
                sdtStartMin2.Value:= 0;
                sdtEndHour2.Value:= 0;
                sdtEndMin2.Value:= 0;
                sdtStartHour3.Value:= 0;
                sdtStartMin3.Value:= 0;
                sdtEndHour3.Value:= 0;
                sdtEndMin3.Value:= 0;
                sdtStartHour4.Value:= 0;
                sdtStartMin4.Value:= 0;
                sdtEndHour4.Value:= 0;
                sdtEndMin4.Value:= 0;
            end;
            Result := 1;
        except
            //
            Result := -1;
        end;
    end;
end;

function TfrmGroupRate.TimePhase2DB: integer;
var
    mConnection : TADOConnection;
begin
    with tblTimePhase do
    begin
        if not Active then
        begin
            mConnection := GetRemoteConnection();
            if mConnection = nil then mConnection := GetLocalConnection();
            if mConnection = nil then
            begin

            end;
            Connection := mConnection;
            TableName := 'time_phase';
            Active := True;
        end;
            //激活数据表
        try
            //记录指针到第一个
            if RecordCount > 0 then
            begin
                First;
                Edit;
            end
            else begin
                Append;
            end;

            FieldByName('start_hour1').AsInteger :=     sdtStartHour1.Value;
            FieldByName('start_min1').AsInteger :=     sdtStartMin1.Value;
            FieldByName('end_hour1').AsInteger :=    sdtEndHour1.Value;
            FieldByName('end_min1').AsInteger :=    sdtEndMin1.Value;
            FieldByName('start_hour2').AsInteger :=    sdtStartHour2.Value;
            FieldByName('start_min2').AsInteger :=    sdtStartMin2.Value;
            FieldByName('end_hour2').AsInteger :=    sdtEndHour2.Value;
            FieldByName('end_min2').AsInteger :=    sdtEndMin2.Value;

            FieldByName('start_hour3').AsInteger :=    sdtStartHour3.Value;
            FieldByName('start_min3').AsInteger :=    sdtStartMin3.Value;
            FieldByName('end_hour3').AsInteger :=    sdtEndHour3.Value;
            FieldByName('end_min3').AsInteger :=    sdtEndMin3.Value;
            FieldByName('start_hour4').AsInteger :=    sdtStartHour4.Value;
            FieldByName('start_min4').AsInteger :=    sdtStartMin4.Value;
            FieldByName('end_hour4').AsInteger :=    sdtEndHour4.Value;
            FieldByName('end_min4').AsInteger :=    sdtEndMin4.Value;

            Post();
            Result := 1;
        except
            //
            Result := -1;
        end;
    end;
end;

procedure TfrmGroupRate.tblParkGroupBeforeDelete(DataSet: TDataSet);
var
    mGroupId :integer;
begin
    mGroupId := tblParkGroup.FieldByName('park_group_id').AsInteger;
    with tblFeeRate do
    begin
        First;
        while not EOF do
        begin
            if FieldByName('group_id').AsInteger = mGroupId then Delete
            else Next;
        end;
        //Post;
    end;
end;

procedure TfrmGroupRate.FillCBX_ParkGroup;
var
    mRec : integer;
    mStr : string;
begin
    with tblParkGroup do
    begin
        if Active = False then Exit;
        mRec := RecNo ;
        DisableControls;
        First;
        cbxParkGroup.Items.Clear;
        while not EOF do
        begin
            mStr := FieldByName('park_group_id').AsString  + '-' + FieldByName('group_name').AsString;
            cbxParkGroup.Items.Add(mStr);
            Next;
        end;
        RecNo := mRec;
        EnableControls;
    end;
end;

procedure TfrmGroupRate.cbxParkGroupChange(Sender: TObject);
var
    mGroupId : string;
begin
    inherited;
    with tblFeeRate do
    begin
        mGroupId := cbxParkGroup.Text;
        mGroupId := Copy(mGroupId,1,Pos('-', mGroupId)-1);
        if mGroupId <> '' then
        begin
            filter := 'group_id =' + mGroupId;
            Filtered := True;
            if RecordCount <= 0 then InsertFeeRate(StrToInt(mGroupId));
        end
        else filter := 'group_id = -1';
        filtered := True;
        //新添加的
    end;
end;

procedure TfrmGroupRate.PageControl1Change(Sender: TObject);
begin
    inherited;
    if PageControl1.ActivePage <> tstFeeRate then Exit;
    FillCBX_ParkGroup();
    cbxParkGroupChange(Self);
end;

function TfrmGroupRate.InsertFeeRate(AGroupId : integer): integer;
var
    i : integer;
begin
    for i := 1 to 8 do
    begin
        with tblFeeRate do
        begin
            Append;
            FieldByName('group_id').AsInteger := AGroupId;
            FieldByName('week_no').AsInteger := i;
            FieldByName('fee_rate1').AsFloat := 0.0;
            FieldByName('fee_rate2').AsFloat := 0.0;
            FieldByName('fee_rate3').AsFloat := 0.0;
            FieldByName('fee_rate4').AsFloat := 0.0;
            Post;
        end;
    end;
end;

procedure TfrmGroupRate.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
    with tblTimePhase do
    begin
        if BOF or EOF then
        begin
            Last;
        end;
        try
            Close;
        except

        end;
    end;
    with tblParkGroup do
    begin
        if BOF or EOF then
        begin
            Last;
        end;
        try
            Close;
        except

        end;
    end;
    with tblFeeRate do
    begin
        if BOF or EOF then
        begin
            Last;
        end;
        try
            Close;
        except

        end;
    end;
end;

end.

⌨️ 快捷键说明

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