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

📄 price.pas

📁 Monitor.dfm Meter.dpr pasMain.pas
💻 PAS
字号:
unit price;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ComCtrls, DB;

type
  Tfrmprice = class(TForm)
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Rate_E: TEdit;
    Label3: TLabel;
    Label4: TLabel;
    Name_E: TEdit;
    Usg_E: TEdit;
    Label5: TLabel;
    Label6: TLabel;
    MCharge_E: TEdit;
    OCharge_E: TEdit;
    btnCancel: TButton;
    btnDelete: TButton;
    BillListView: TListView;
    bntAppend: TButton;
    procedure btnCancelClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure BillListViewSelectItem(Sender: TObject; Item: TListItem;
      Selected: Boolean);
    procedure bntAppendClick(Sender: TObject);
    procedure btnDeleteClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmprice: Tfrmprice;

implementation

uses DM, Promot;

{$R *.DFM}

procedure Tfrmprice.btnCancelClick(Sender: TObject);
begin
    close
end;


procedure Tfrmprice.FormCreate(Sender: TObject);
var
    ListItem: TListItem;
begin
//Load Billing Table
    DM1.BillDB.First;
    while not DM1.BillDB.Eof do
    with BillListView do
    begin
        ListItem := Items.add;
        ListItem.Caption := DM1.BillDB.FieldByname('NAME').AsString;
        ListItem.ImageIndex := -1;

        ListItem.SubItems.Add(DM1.BillDB.FieldByname('USG').AsString);
        ListItem.SubItems.Add(DM1.BillDB.FieldByname('RATE').AsString);
        ListItem.SubItems.Add(DM1.BillDB.FieldByname('MCHARGE').AsString);
        ListItem.SubItems.Add(DM1.BillDB.FieldByname('OCHARGE').AsString);
        DM1.BillDB.Next;
    end;

    frmPrice.Left := ( Screen.Width - frmPrice.Width ) div 2;
    frmPrice.Top := ( Screen.Height - frmPrice.Height ) div 2;

end;

procedure Tfrmprice.BillListViewSelectItem(Sender: TObject;
  Item: TListItem; Selected: Boolean);
begin
    if Selected = FALSE then exit;

    with BillListview do
    begin
        Name_E.Text := Items[Selected.index].Caption;
        Usg_E.Text :=Items[Selected.index].SubItems.Strings[0];
        Rate_E.Text := Items[Selected.index].SubItems.Strings[1];
        MCharge_E.Text := Trim(Items[Selected.index].SubItems.Strings[2]);
        OCharge_E.Text := Items[Selected.index].SubItems.Strings[3];
    end;

end;

procedure Tfrmprice.bntAppendClick(Sender: TObject);
var
    I, tStatus: Integer;
    ListItem: TListItem;
    Unit_Rate, MeterCharge, OtherCharge: Real;
begin

    if (Trim(Usg_E.Text) = '') or (Trim(Name_E.Text) = '') or (Trim(Rate_E.Text) = '') then exit;

    try
        Unit_Rate := StrToFloat(Rate_E.Text);
        MeterCharge := StrToFloat(MCharge_E.Text);
        OtherCharge := StrToFloat(OCharge_E.Text);
    except
        exit;
    end;

//Check current if having the record
    DM1.BillDB.Active := TRUE;
    if DM1.BillDB.Locate('USG',  Usg_E.Text, [loPartialKey]) then
    begin
        tStatus := 1;
        DM1.BillDB.Edit;
        frmPromot.Hide;
        frmPromot.Promot.Caption := '[是否修改' + Usg_E.Text + ']?';
        if frmPromot.ShowModal <> mrOK then exit;
    end
    else
    begin
        tStatus := 2;
        DM1.BillDB.append;
        frmPromot.Hide;
        frmPromot.Promot.Caption := '是否添加[' + Usg_E.Text + ']?';
        if frmPromot.ShowModal <> mrOK then exit;
    end;

//Modify data for ListView
    if tStatus = 1 then
    begin
        with BillListView do
        begin
            for I := 0 to Items.Count - 1 do
            begin
                if Items[I].SubItems.Strings[0] = Usg_E.Text then
                begin

                    Items[I].Caption := Name_E.Text;
                    Items[I].SubItems.Strings[1] := Rate_E.Text;
                    Items[I].SubItems.Strings[2] := MCharge_E.Text;
                    Items[I].SubItems.Strings[3] := OCharge_E.Text;
                    Items[I].Selected := True;
                    Items[I].Focused := True;
                end;
            end;
        end;
    end;

//Append data for ListView
    if tStatus = 2 then
    begin
        with BillListview do
        begin
            ListItem := Items.add;
            ListItem.Caption := Name_E.Text;
            ListItem.ImageIndex := -1;

            ListItem.SubItems.add(Usg_E.Text);
            ListItem.SubItems.add(Rate_E.Text);
            ListItem.SubItems.add(MCharge_E.Text);
            ListItem.SubItems.add(OCharge_E.Text);
        end;
    end;

//Write database
    DM1.BillDB.FieldByName('USG').AsString := Usg_E.text;
    DM1.BillDB.FieldByName('NAME').AsString := Name_E.Text;
    DM1.BillDB.FieldByName('RATE').AsString := Rate_E.text;
    DM1.BillDB.FieldByName('MCHARGE').AsString := MCharge_E.text;
    DM1.BillDB.FieldByName('OCHARGE').AsString := OCharge_E.text;

    DM1.BillDB.Post;
    DM1.BillDB.FlushBuffers ;
    dm1.billdb.Refresh;
end;

procedure Tfrmprice.btnDeleteClick(Sender: TObject);
begin
    if DM1.BillDB.Locate('USG',  VarArrayOf([Usg_E.Text]), [loPartialKey]) then
    begin
        frmPromot.Hide;
        frmPromot.Promot.Caption := '是否删除[' + Usg_E.Text + '] ?';
        if frmPromot.ShowModal <> mrOK then exit;

        DM1.BillDB.Delete;
        BillListView.Items.Delete(BillListView.Selected.Index);
    end
    else
    begin
        frmPromot.Hide;
        frmPromot.Promot.Caption := '无此[' + Usg_E.Text + ']用电类型?';
        if frmPromot.ShowModal <> mrOK then exit;
    end;
end;

end.

⌨️ 快捷键说明

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