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

📄 realtyc211.pas

📁 物业管理系统系统特点 一、 实现集中式管理 系统将集团公司、各分公司、各物业管理处连接到一起
💻 PAS
字号:
unit RealtyC211;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, dbcgrids, Grids, DBGrids, DB, ADODB, StdCtrls, Buttons, ExtCtrls,
  StrUtils, ExtDlgs, ComCtrls, math, Menus, ImgList, ToolWin;

type
    Tf_RealtyC211 = class(TForm)
    L1: TLabel;
    Label2: TLabel;
    Label9: TLabel;
    Label1: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit5: TEdit;
    combobox1: TComboBox;
    Button5: TButton;
    Button7: TButton;
    ComboBox2: TComboBox;

    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormCreate(Sender: TObject);

    procedure combobox1Select(Sender: TObject);
    procedure N25Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button7Click(Sender: TObject);
    procedure getid;
    procedure Button5Click(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
       bOK:bool;
       bsuccess:bool;
  end;

var
    f_RealtyC211: Tf_RealtyC211;
    sNum:string;

implementation

uses data, main, RealtyA14,RealtyC21;

{$R *.dfm}

procedure Tf_RealtyC211.FormCreate(Sender: TObject);
Var
      query:TADOQuery;
      s:string;
      i:integer;
begin 
      Query:=TADOQuery.Create(nil);
      Query.Connection:=DataModuleADO.ADOConnection1;

      query.sql.add('select * from 辅助资料 where 类别='''+'收费项目类别'+'''');
      query.Open;
      while not query.eof do
      begin
          Combobox1.Items.Add(query.fieldbyname('名称').Value);
          query.Next;
      end;

      if f_realtyC21.bMod=false then
      begin
          getid;
      end;

      query.SQL.Clear;
      query.SQL.Add('select * from 仪表种类');
      query.Open;
      while not query.eof do
      begin
          Combobox2.Items.Add(query.fieldbyname('名称').Value);
          query.Next;
      end;

      if f_realtyC21.bMod=true then
      begin
          if f_RealtyC21.ListView1.Selected.Subitems[1]='抄表收费项目' then
          begin
             combobox2.Enabled:=true;
          end
          else combobox2.Enabled:=false;

          edit1.Text:=f_RealtyC21.ListView1.Selected.Caption;
          edit5.Text:=f_RealtyC21.ListView1.Selected.Subitems[0];
          combobox1.ItemIndex:=combobox1.Items.IndexOf(f_RealtyC21.ListView1.Selected.Subitems[1]);
          combobox2.ItemIndex:=combobox2.items.IndexOf(f_RealtyC21.ListView1.Selected.Subitems[2]);
          edit2.Text:=f_RealtyC21.ListView1.Selected.Subitems[3];
      end;

      Query.Close;
      Query.Free;
end;

procedure Tf_RealtyC211.getid;
Var
      query:TADOQuery;
      s:string;
      i:integer;
begin
      Query:=TADOQuery.Create(nil);
      Query.Connection:=DataModuleADO.ADOConnection1;

      s := 'select top 1 * from 收费项目 ORDER BY 编号 DESC';

      Query.SQL.Add(s);
      Query.Open ;
      if query.recordcount > 0 then
      begin
          s:= Query.Fieldbyname('编号').AsString;
          s:= Copy(S, 1, 4);
          i:= strtoint(s)+1;
          if i<10 then edit1.text := '000'+inttostr(i)
          else if (i > 9) and (i<100) then edit1.text := '00'+inttostr(i)
          else if (i > 99) and (i<1000) then edit1.text := '0'+inttostr(i)
          else if i>999 then edit1.text := inttostr(i);
      end
      else  edit1.text := '0001';
      Query.Close;
      Query.Free;
end;


//Tab
procedure Tf_RealtyC211.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
    if key=13 then
        Begin
            key:=0;
            perform(WM_NEXTDLGCTL,0,0);
        end
    else if key=VK_ESCAPE then close;
end;

//关闭
procedure Tf_RealtyC211.combobox1Select(Sender: TObject);
begin
    combobox2.Items.Clear;

    if Combobox1.text='抄表收费项目' then
    begin
        combobox2.Enabled:=true;
        Combobox2.Items.Add('水表');
        combobox2.Items.Add('电表');
    end
    else
    begin
        combobox2.Enabled:=false;
    end;
end;

procedure Tf_RealtyC211.N25Click(Sender: TObject);
begin

     close ;

end;

procedure Tf_RealtyC211.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
    bok:=false;
    action:=cafree;
end;

procedure Tf_RealtyC211.Button7Click(Sender: TObject);
Var
    query:TADOQuery;
    s,s1:String;
    i:integer;
begin
    //1
    if edit1.Text='' then
    begin
         showmessage('请输入编号!');
         edit1.SetFocus;
         exit;
    end;

    if edit5.Text='' then
    begin
         showmessage('请输入名称!');
         edit5.SetFocus;
         exit;
    end;

    if combobox1.Text='' then
    begin
         showmessage('请输入费用项目类型!');
         combobox1.SetFocus;
         exit;
    end;

    //数据完整
    s1:='-';
    if combobox2.Text<>'' then s1:=combobox2.Text;

    if edit2.Text='' then edit2.Text:='-';

    //3
    query:=TADOquery.Create(nil);
    query.Connection:=DataModuleADO.ADOConnection1;


    //4修改
    if f_RealtyC21.bMod=true then
    begin
        //1判断
        if Edit1.Text<>f_RealtyC21.ListView1.Selected.Caption then
        begin
            query.SQL.Add('select * from 收费项目 where 编号='''+edit1.Text+'''');
            query.Open;
            if query.RecordCount>0 then
            begin
                showmessage('编号重复');
                query.Close;
                query.Free;
                exit;
            end;
        end;

        //2存储数据
        s:='update 收费项目 set 编号='''+edit1.Text;
        s:=s+''',名称='''+edit5.Text;
        s:=s+''',费用项目类型='''+combobox1.Text;
        s:=s+''',仪表种类='''+s1;
        s:=s+''',说明='''+edit2.Text;
        s:=s+''' where 编号='''+f_RealtyC21.ListView1.Selected.Caption;
        s:=s+'''';

        DataModuleADO.ADOConnection1.BeginTrans;
        query.sql.clear;
        query.SQL.Text:=s;
        query.ExecSQL;
        DataModuleADO.ADOConnection1.CommitTrans;

        //3更新列表显示
        query.SQL.Clear;
        query.SQL.Add('select * from 收费项目 where 编号='''+edit1.Text+'''');
        query.Open;
        if query.RecordCount>0 then
        begin
             with f_RealtyC21.listview1.Selected do
             begin
                  Caption:=query.fieldbyname('编号').Value;
                  subitems[0]:=query.fieldbyname('名称').Value;
                  subitems[1]:=query.fieldbyname('费用项目类型').Value;
                  subitems[2]:=query.fieldbyname('仪表种类').Value;
                  subitems[3]:=query.fieldbyname('说明').Value;
             end;
        end;

        //4关闭连接,释放内存
        query.Close;
        query.Free;

        //5修改保存后关闭自己
        close;
    end;



    //5新增数据
    if f_RealtyC21.bMod=false then
    begin
        //1判断是否符合数据存储条件
        query.sql.clear;
        query.SQL.Add('select * from 收费项目 where 编号='''+edit1.Text+'''');
        query.Open;
        if query.RecordCount>0 then
        begin
            showmessage('编号重复');
            query.Close;
            query.Free;
            exit;
        end;

        //2将数据写入数据库
        s:='insert into 收费项目 (编号,名称,费用项目类型,仪表种类,说明)';
        s:=s+'values(:s1,:s2,:s3,:s4,:s5)';

        query.sql.clear;
        query.SQL.Add(s);

        query.Parameters.ParamByName('s1').Value:=edit1.Text;
        query.Parameters.ParamByName('s2').Value:=edit5.Text;
        query.Parameters.ParamByName('s3').Value:=combobox1.Text;
        query.Parameters.ParamByName('s4').Value:=s1;
        query.Parameters.ParamByName('s5').Value:=edit2.text;

        DataModuleADO.ADOConnection1.BeginTrans;
        query.ExecSQL;
        DataModuleADO.ADOConnection1.CommitTrans;


        //3更新上个窗口的列表显示
        query.SQL.Clear;
        query.SQL.Add('select * from 收费项目 where 编号='''+edit1.Text+'''');
        query.Open;
        if query.RecordCount>0 then
        begin
             with f_RealtyC21.listview1.Items.Add do
             begin
                  Caption:=query.fieldbyname('编号').value;
                  SubItems.Add(query.fieldbyname('名称').Value);
                  SubItems.Add(query.fieldbyname('费用项目类型').Value);
                  SubItems.Add(Query.FieldByName('仪表种类').Value);
                  SubItems.Add(Query.FieldByName('说明').Value);
             end;
        end;

        //4关闭数据连接,释放内存
        query.Close;
        query.Free;


        //5清空数据,编号累加
        getid;
        edit2.text:='';
        combobox2.ItemIndex:=combobox2.Items.IndexOf('');
        edit5.text:='';
        combobox1.ItemIndex:=combobox1.Items.IndexOf('');

        Edit1.SetFocus;
    end;
end;

procedure Tf_RealtyC211.Button5Click(Sender: TObject);
begin
    close;
end;

end.

⌨️ 快捷键说明

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