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

📄 unit1.pas

📁 一个旅行社管理系统,我也不太了解用什么开发的,反正能运行可看源码.
💻 PAS
字号:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, ExtCtrls, Grids, Buttons, DB, ADODB,
  AdvGrid, BaseGrid, DateM, TFlatComboBoxUnit, Rep1;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Edit1: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Edit2: TEdit;
    Edit3: TEdit;
    Memo1: TMemo;
    Memo2: TMemo;
    Panel3: TPanel;
    SpeedButton1: TSpeedButton;
    Label8: TLabel;
    SpeedButton2: TSpeedButton;
    DateTime1: TDateTimePicker;
    DateTime2: TDateTimePicker;
    StringGrid1: TAdvStringGrid;
    SpeedButton3: TSpeedButton;
    SpeedButton4: TSpeedButton;
    FlatComboBox1: TFlatComboBox;
    procedure FormCreate(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure StringGrid1GetEditorType(Sender: TObject; ACol,
      ARow: Integer; var AEditor: TEditorType);
    procedure SpeedButton3Click(Sender: TObject);
    procedure SpeedButton4Click(Sender: TObject);
  private
    { Private declarations }
    function InputCheckData():string;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
//var
//  inno:integer;
begin
  speedbutton2.Enabled:=false;
  speedbutton4.Enabled:=false;
  stringgrid1.ClearComboString;
  stringgrid1.AddComboString('男');
  stringgrid1.AddComboString('女');
  //edit5.Text:=formatdatetime('yyyy年MM月dd日',now);
  DateTime1.Date:=date;
  DateTime2.Date:=date;
  {stringgrid1.Cells[1,0] :='姓名';
  stringgrid1.Cells[2,0] :='性别';
  stringgrid1.Cells[3,0] :='身份证';
  stringgrid1.Cells[4,0] :='电话号码';
  for inno:=1 to stringgrid1.RowCount-1 do
  begin
    stringgrid1.Cells[0,inno] := IntToStr(inno);
    stringgrid1.Cells[1,inno] := '';
    stringgrid1.Cells[2,inno] := '';
    stringgrid1.Cells[3,inno] := '';
    stringgrid1.Cells[4,inno] := '';
  end;}
end;

function TForm1.InputCheckData: string;
var checki :integer;
begin
    if edit1.Text='' then
  begin
    Result :='请输入表单号!';
    Exit;
  end;
  if edit2.Text='' then
  begin
    Result :='请输入始发地!';
    Exit;
  end;
  if edit3.Text='' then
  begin
    Result :='请输入终点地!';
    Exit;
  end;
  if memo1.Text='' then
  begin
    Result :='请输入详细路程!';
    Exit;
  end;
  if memo2.Text='' then
  begin
    Result :='请输入详细路程(外)!';
    Exit;
  end;
  for checki:=1 to StringGrid1.RowCount-1 do
  begin
    if StringGrid1.Cells[1,checki]='' then
    Break;
  end;
  if Checki<2 then Result :='至少需要输入一条详细记录!';
end;

procedure TForm1.SpeedButton1Click(Sender: TObject);
var CheckData :boolean;
    ErrorMess :string;
    SaveClient :integer;
    checki:integer;
begin
  CheckData := true;
  ErrorMess := InputCheckData;
  if ErrorMess <>'' then
  begin
    MessageBox(Handle,Pchar(ErrorMess),'注意',MB_ICONINFORMATION+MB_OK+MB_DEFBUTTON1);
    CheckData := false;
  end;

if CheckData then
  begin  //保存数据
    try
      //保存主表数据
      dm.ADOConnection1.BeginTrans;
      with dm.ADOQuery1 do
      begin
        Close;
        SQL.Clear;
        SQL.Add('Insert Into Mdate Values(:表单号, :始发, :终点, :开始时间, :终止时间, :详细路程, :详细路程外)');
        Parameters.ParamByName('表单号').Value := edit1.Text;
        Parameters.ParamByName('始发').Value := edit2.Text;
        Parameters.ParamByName('终点').Value := edit3.Text;
        Parameters.ParamByName('开始时间').Value := FormatDateTime('yyyy-mm-dd',DateTime1.Date);
        Parameters.ParamByName('终止时间').Value := FormatDateTime('yyyy-mm-dd',DateTime2.Date);
        Parameters.ParamByName('详细路程').Value := memo1.Text;
        Parameters.ParamByName('详细路程外').Value := memo2.Text;
        ExecSQL;
      end;
      //保存从表数据
      for SaveClient :=1 to StringGrid1.RowCount-1 do
      begin
        if StringGrid1.Cells[1,SaveClient]<>'' then
        begin
          with dm.ADOQuery2 do
          begin
            Close;
            SQL.Clear;
            SQL.Add('Insert Into CDate Values(:表单号, :姓名, :性别, :身份证, :电话号码)');
            Parameters.ParamByName('表单号').Value := Edit1.Text;
            Parameters.ParamByName('姓名').Value := StringGrid1.Cells[1,SaveClient];
            Parameters.ParamByName('性别').Value := StringGrid1.Cells[2,SaveClient];
            Parameters.ParamByName('身份证').Value := StringGrid1.Cells[3,SaveClient];
            Parameters.ParamByName('电话号码').Value := StringGrid1.Cells[4,SaveClient];
            ExecSQL;
          end;
        end;
      end;
      dm.ADOConnection1.CommitTrans;
      //指针回到原位
      stringgrid1.SelectRange(1,1,1,1);
      //清空多余字段
      for checki:=1 to StringGrid1.RowCount-1 do
      begin
        if StringGrid1.Cells[1,checki]='' then
        begin
        stringgrid1.Cells[2,checki]:='';
        stringgrid1.Cells[3,checki]:='';
        stringgrid1.Cells[4,checki]:='';
        end;
      end;
      showMessage('数据已经成功保存至数据库!');
      edit1.Enabled:=false;
      edit2.Enabled:=false;
      edit3.Enabled:=false;
      datetime1.Enabled:=false;
      datetime2.Enabled:=false;
      memo1.Enabled:=false;
      memo2.Enabled:=false;
      stringgrid1.Enabled:=false;
      speedbutton1.Enabled:=false;
      speedbutton2.Enabled:=true;
      speedbutton4.Enabled:=true;
    except
      dm.ADOConnection1.RollbackTrans;
      showMessage('保存数据至服务器时失败!'+#13+
      '请检查数据的有效性,比如数据输入字母之类。');
    end;
  end;
end;  

procedure TForm1.SpeedButton2Click(Sender: TObject);
var CheckData :boolean;
    ErrorMess :string;
    SaveClient :integer;
    Checki :integer;
begin
    if SpeedButton2.Caption ='修改数据' then
    begin
      begin
        SpeedButton2.Caption :='保存数据';
        stringgrid1.Look:=glStandard;
      edit2.Enabled:=true;
      edit3.Enabled:=true;
      datetime1.Enabled:=true;
      datetime2.Enabled:=true;
      memo1.Enabled:=true;
      memo2.Enabled:=true;
      stringgrid1.Enabled:=true;
      speedbutton4.Enabled:=false;
      speedbutton3.Enabled:=false;
      end;
    end else
    begin
      CheckData := true;
       ErrorMess := InputCheckData;
      if ErrorMess <>'' then
       begin
       MessageBox(Handle,Pchar(ErrorMess),'注意',MB_ICONINFORMATION+MB_OK+MB_DEFBUTTON1);
       CheckData := false;
       end;
       end;
  if CheckData=true then
  begin  //修改数据
    try
      //修改主表数据
      dm.ADOConnection1.BeginTrans;
      with dm.ADOQuery1 do
      begin
        Close;
        SQL.Clear;
        SQL.Add('Update Mdate Set 始发=:sf, 终点=:zd, 开始时间=:kssj, '+
        '终止时间=:zzsj, 详细路程=:xxlc, 详细路程外=:xxlcw Where 表单号=:bdh');
        Parameters.ParamByName('bdh').Value := edit1.Text;
        Parameters.ParamByName('sf').Value := edit2.Text;
        Parameters.ParamByName('zd').Value := edit3.Text;
        Parameters.ParamByName('kssj').Value := FormatDateTime('yyyy-mm-dd',DateTime1.Date);
        Parameters.ParamByName('zzsj').Value := FormatDateTime('yyyy-mm-dd',DateTime2.Date);
        Parameters.ParamByName('xxlc').Value := memo1.Text;
        Parameters.ParamByName('xxlcw').Value := memo2.Text;
        ExecSQL;
      end;
      //保存从表数据
      begin
        with dm.ADOQuery2 do
        begin
        Close;
        SQL.Clear;
        SQL.Add('Delete from CDate Where 表单号=:bdh');
        Parameters.ParamByName('bdh').Value :=Edit1.Text;
        ExecSQL;
        end;
      end;
      for SaveClient :=1 to StringGrid1.RowCount-1 do
      begin
        if StringGrid1.Cells[1,SaveClient]<>'' then
        begin
          with dm.ADOQuery2 do
          begin
            Close;
            //SQL.Clear;
            //SQL.Add('Update CDate Set 姓名=:name, 性别=:sex, 身份证=:sfz, '+
            //'电话号码=:phone where 表单号=:bdh');
            //Parameters.ParamByName('bdh').Value := Edit1.Text;
            //Parameters.ParamByName('name').Value := StringGrid1.Cells[1,SaveClient];
            //Parameters.ParamByName('sex').Value := StringGrid1.Cells[2,SaveClient];
            //Parameters.ParamByName('sfz').Value := StringGrid1.Cells[3,SaveClient];
            //Parameters.ParamByName('phone').Value := StringGrid1.Cells[4,SaveClient];
            //ExecSQL;
            SQL.Clear;
            SQL.Add('Insert Into CDate Values(:表单号, :姓名, :性别, :身份证, :电话号码)');
            Parameters.ParamByName('表单号').Value := Edit1.Text;
            Parameters.ParamByName('姓名').Value := StringGrid1.Cells[1,SaveClient];
            Parameters.ParamByName('性别').Value := StringGrid1.Cells[2,SaveClient];
            Parameters.ParamByName('身份证').Value := StringGrid1.Cells[3,SaveClient];
            Parameters.ParamByName('电话号码').Value := StringGrid1.Cells[4,SaveClient];
            ExecSQL;
          end;
        end;
      end;
      dm.ADOConnection1.CommitTrans;
      //指针回到原位
      stringgrid1.SelectRange(1,1,1,1);
      //清空多余字段
      for checki:=1 to StringGrid1.RowCount-1 do
      begin
        if StringGrid1.Cells[1,checki]='' then
        begin
        stringgrid1.Cells[2,checki]:='';
        stringgrid1.Cells[3,checki]:='';
        stringgrid1.Cells[4,checki]:='';
        end;
      end;
      stringgrid1.Look:=glxp;
      speedbutton3.Enabled:=true;
      edit1.Enabled:=false;
      edit2.Enabled:=false;
      edit3.Enabled:=false;
      datetime1.Enabled:=false;
      datetime2.Enabled:=false;
      memo1.Enabled:=false;
      memo2.Enabled:=false;
      stringgrid1.Enabled:=false;
      speedbutton4.Enabled:=true;
      showMessage('数据已经成功保存至数据库!');
      speedButton2.Caption :='修改数据';
    except
      dm.ADOConnection1.RollbackTrans;
      showMessage('保存数据至服务器时失败!'+#13+
      '请检查数据的有效性,比如数据输入字母之类。');
    end;
  end; 

end;

procedure TForm1.StringGrid1GetEditorType(Sender: TObject; ACol,
  ARow: Integer; var AEditor: TEditorType);
begin
  case acol of
  2:aeditor:=edcombolist;
  end;
end;

procedure TForm1.SpeedButton3Click(Sender: TObject);
begin
  edit1.Enabled:=true;
  edit2.Enabled:=true;
  edit3.Enabled:=true;
  datetime1.Enabled:=true;
  datetime2.Enabled:=true;
  memo1.Enabled:=true;
  memo2.Enabled:=true;
  stringgrid1.Enabled:=true;
  speedbutton1.Enabled:=true;
  speedbutton2.Enabled:=false;
  speedbutton4.Enabled:=false;
  edit1.Clear;
  edit2.Clear;
  edit3.Clear;
  memo1.Clear;
  memo2.Clear;
  stringgrid1.ClearNormalCells;;
end;

procedure TForm1.SpeedButton4Click(Sender: TObject);
begin
  if flatcombobox1.Text='报表1' then
  begin
  rep1.Form2.TName1.Caption:= StringGrid1.Cells[1,1];
  rep1.Form2.TName2.Caption:= StringGrid1.Cells[1,2];
  rep1.Form2.TName3.Caption:= StringGrid1.Cells[1,3];
  rep1.Form2.TName4.Caption:= StringGrid1.Cells[1,4];
  rep1.Form2.TName5.Caption:= StringGrid1.Cells[1,5];
  rep1.Form2.TName6.Caption:= StringGrid1.Cells[1,6];
  rep1.Form2.TName7.Caption:= StringGrid1.Cells[1,7];
  rep1.Form2.TName8.Caption:= StringGrid1.Cells[1,8];
  rep1.Form2.TName9.Caption:= StringGrid1.Cells[1,9];
  rep1.Form2.TName10.Caption:= StringGrid1.Cells[1,10];

  rep1.Form2.TSex1.Caption:= StringGrid1.Cells[2,1];
  rep1.Form2.TSex2.Caption:= StringGrid1.Cells[2,2];
  rep1.Form2.TSex3.Caption:= StringGrid1.Cells[2,3];
  rep1.Form2.TSex4.Caption:= StringGrid1.Cells[2,4];
  rep1.Form2.TSex5.Caption:= StringGrid1.Cells[2,5];
  rep1.Form2.TSex6.Caption:= StringGrid1.Cells[2,6];
  rep1.Form2.TSex7.Caption:= StringGrid1.Cells[2,7];
  rep1.Form2.TSex8.Caption:= StringGrid1.Cells[2,8];
  rep1.Form2.TSex9.Caption:= StringGrid1.Cells[2,9];
  rep1.Form2.TSex10.Caption:= StringGrid1.Cells[2,10];

  rep1.Form2.TSFZ1.Caption:= StringGrid1.Cells[3,1];
  rep1.Form2.TSFZ2.Caption:= StringGrid1.Cells[3,2];
  rep1.Form2.TSFZ3.Caption:= StringGrid1.Cells[3,3];
  rep1.Form2.TSFZ4.Caption:= StringGrid1.Cells[3,4];
  rep1.Form2.TSFZ5.Caption:= StringGrid1.Cells[3,5];
  rep1.Form2.TSFZ6.Caption:= StringGrid1.Cells[3,6];
  rep1.Form2.TSFZ7.Caption:= StringGrid1.Cells[3,7];
  rep1.Form2.TSFZ8.Caption:= StringGrid1.Cells[3,8];
  rep1.Form2.TSFZ9.Caption:= StringGrid1.Cells[3,9];
  rep1.Form2.TSFZ10.Caption:= StringGrid1.Cells[3,10];

  rep1.Form2.TPhone1.Caption:= StringGrid1.Cells[4,1];
  rep1.Form2.TPhone2.Caption:= StringGrid1.Cells[4,2];
  rep1.Form2.TPhone3.Caption:= StringGrid1.Cells[4,3];
  rep1.Form2.TPhone4.Caption:= StringGrid1.Cells[4,4];
  rep1.Form2.TPhone5.Caption:= StringGrid1.Cells[4,5];
  rep1.Form2.TPhone6.Caption:= StringGrid1.Cells[4,6];
  rep1.Form2.TPhone7.Caption:= StringGrid1.Cells[4,7];
  rep1.Form2.TPhone8.Caption:= StringGrid1.Cells[4,8];
  rep1.Form2.TPhone9.Caption:= StringGrid1.Cells[4,9];
  rep1.Form2.TPhone10.Caption:= StringGrid1.Cells[4,10];

  rep1.Form2.TBdh1.Caption:= Edit1.Text;
  rep1.Form2.SF1.Caption:= Edit2.Text;
  rep1.Form2.ZD1.Caption:= Edit3.Text;
  rep1.Form2.Time1.Caption:= formatdatetime('yyyy年MM月dd日',datetime1.Date);
  rep1.Form2.Time2.Caption:= formatdatetime('yyyy年MM月dd日',datetime2.Date);
  rep1.Form2.QRMemo1.Lines:= Memo1.Lines;
  rep1.Form2.QRMemo2.Lines:= Memo2.Lines;
  
  rep1.Form2.QuickRep1.Preview;
  end;
  if flatcombobox1.Text='报表2' then
  showmessage('########');
end;

end.
 

⌨️ 快捷键说明

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