www.pudn.com > dianlijiankong.rar > UKHYSXX.~pas, change:2005-12-23,size:11373b


unit UKHYSXX; 
 
interface 
 
uses 
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
  Dialogs, Buttons, ToolWin, ComCtrls, ExtCtrls, StdCtrls, Grids, DBGrids; 
 
type 
  TFRM_KHYSXX = class(TForm) 
    ToolBar1: TToolBar; 
    SpeedButton1: TSpeedButton; 
    SpeedButton2: TSpeedButton; 
    SpeedButton3: TSpeedButton; 
    SpeedButton4: TSpeedButton; 
    SpeedButton5: TSpeedButton; 
    SpeedButton6: TSpeedButton; 
    Panel1: TPanel; 
    Panel2: TPanel; 
    Label1: TLabel; 
    Label2: TLabel; 
    Label3: TLabel; 
    Label4: TLabel; 
    Label5: TLabel; 
    Label6: TLabel; 
    Label7: TLabel; 
    Edit1: TEdit; 
    ComboBox1: TComboBox; 
    Edit2: TEdit; 
    DateTimePicker1: TDateTimePicker; 
    Edit3: TEdit; 
    Edit4: TEdit; 
    Edit5: TEdit; 
    DBGrid1: TDBGrid; 
    procedure SpeedButton6Click(Sender: TObject); 
    procedure SpeedButton1Click(Sender: TObject); 
    procedure SpeedButton2Click(Sender: TObject); 
    procedure SpeedButton3Click(Sender: TObject); 
    procedure SpeedButton4Click(Sender: TObject); 
    procedure SpeedButton5Click(Sender: TObject); 
    procedure FormCreate(Sender: TObject); 
    procedure FormShow(Sender: TObject); 
    procedure DBGrid1CellClick(Column: TColumn); 
    procedure ComboBox1DropDown(Sender: TObject); 
    procedure ComboBox1Change(Sender: TObject); 
    procedure DateTimePicker1KeyPress(Sender: TObject; var Key: Char); 
    procedure Edit3KeyPress(Sender: TObject; var Key: Char); 
    procedure Edit4KeyPress(Sender: TObject; var Key: Char); 
    procedure ComboBox1KeyPress(Sender: TObject; var Key: Char); 
    procedure Edit2Change(Sender: TObject); 
    procedure Edit3Change(Sender: TObject); 
    procedure Edit4Change(Sender: TObject); 
    procedure Edit5Change(Sender: TObject); 
    procedure Edit1KeyPress(Sender: TObject; var Key: Char); 
    procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; 
      DataCol: Integer; Column: TColumn; State: TGridDrawState); 
  private 
    { Private declarations } 
  public 
    procedure tr;       //去除空字符 
    procedure bh;        //自动编号 
    Procedure GetAll;    //获得所有数据 
    Procedure Posting;   //提交数据 
    Procedure CLS;       //清除控件中内容 
    Procedure DIS;       //控件不可用 
    Procedure ENA;       //控件可用 
    Function CanSave:Boolean;   //判断是否保存 
    { Public declarations } 
  end; 
 
var 
  FRM_KHYSXX: TFRM_KHYSXX; 
 
implementation 
 
uses UMAIN, UDM; 
 
{$R *.dfm} 
procedure TFRM_KHYSXX.tr; 
var 
i:integer; 
begin 
  for i:=ComponentCount - 1 downto 0 do 
    if(Components[i] is TEdit) then 
    TEdit(Components[i]).Text:=trim(TEdit(Components[i]).Text); 
end; 
Function TFRM_KHYSXX.CanSave: Boolean; 
begin 
  if (Edit1.Text='') then 
  begin 
   Result:=False; 
   Application.MessageBox('验收编号不能为空!','提示信息',0+MB_ICONINFORMATION); 
   exit; 
  end; 
  if (ComboBox1.Text='') then 
  begin 
    Result:=False; 
    Application.MessageBox('客户名称不能为空!','提示信息',0+MB_ICONINFORMATION); 
    exit; 
  end; 
  if (Edit2.Text='') then 
  begin 
    Result:=False; 
    Application.MessageBox('托运单号不能为空!','提示信息',0+MB_ICONINFORMATION); 
    exit; 
  end; 
  if (Edit3.Text='') then 
  begin 
    Result:=False; 
    Application.MessageBox('验收单位不能为空!','提示信息',0+MB_ICONINFORMATION); 
    exit; 
  end; 
  if (Edit4.Text='') then 
  begin 
    Result:=False; 
    Application.MessageBox('验收人不能为空!','提示信息',0+MB_ICONINFORMATION); 
    exit; 
  end; 
end; 
 
procedure TFRM_KHYSXX.bh; 
var 
i:integer; 
s,m:string; 
begin 
  s:= 'YS'+ FormatDateTime('yyyymmdd',Now()); 
  With DM.QKHYSXX do 
  begin 
    Close; 
    SQL.Clear; 
    SQL.Add('select max(验收编号) as ss From 客户验收信息表'); 
    Open; 
  end; 
  If DM.QKHYSXX.FieldByName('ss').Value=null then 
    s := s + '001' 
  else 
  begin 
    m:= Trim(DM.QKHYSXX.FieldByName('ss').Value) ; 
    i:= StrToInt(Trim(Copy(m,11,8))) ; 
    if i<9 then 
      s:= s + '00'+ InttoStr(i +1) 
    else if i<99 then 
      s:= s + '0'+ InttoStr(i +1) 
    else 
      s:= s +InttoStr(i +1); 
  end; 
  Edit1.Text := s; 
end;           ///////////////////////////// 
 
procedure TFRM_KHYSXX.GetAll; 
begin 
  Edit1.Text:=DM.DSOKHYSXX.FieldByName('验收编号').AsString; 
  ComboBox1.Text:=DM.DSOKHYSXX.FieldByName('客户名称').AsString; 
  Edit2.Text:=DM.DSOKHYSXX.FieldByName('托运单号').AsString; 
  DateTimePicker1.Date:=DM.DSOKHYSXX.FieldByName('验收日期').AsDateTime; 
  Edit3.Text:=DM.DSOKHYSXX.FieldByName('验收单位').AsString; 
  Edit4.Text:=DM.DSOKHYSXX.FieldByName('验收人').AsString; 
  Edit5.Text:=DM.DSOKHYSXX.FieldByName('备注').AsString; 
end; 
procedure TFRM_KHYSXX.Posting; 
begin 
  if ActionCD='N' then 
  BEGIN 
    with DM.QKHYSXX do 
    begin 
      Close; 
      SQL.Clear; 
      SQL.Add('INSERT INTO 客户验收信息表(验收编号,客户名称,托运单号,验收日期,验收单位,验收人,备注)'); 
      SQL.Add('Values(:验收编号,:客户名称,:托运单号,:验收日期,:验收单位,:验收人,:备注)'); 
      Parameters.Items[0].Value:=Edit1.Text; 
      Parameters.Items[1].Value:=ComboBox1.Text; 
      Parameters.Items[2].Value:=Edit2.Text; 
      DateTimePicker1.Date:=Date(); 
      Parameters.Items[3].Value:=FormatDateTime('yyyy-mm-dd',DateTimePicker1.Date); 
      Parameters.Items[4].Value:=Edit3.Text; 
      Parameters.Items[5].Value:=Edit4.Text; 
      Parameters.Items[6].Value:=Edit5.Text; 
      Prepared:=True; 
      ExecSQL; 
    end; 
  END else 
  if ActionCD='M' then 
  begin 
    With DM.QKHYSXX DO 
    begin 
      Close; 
      SQL.Clear; 
      SQL.Add('update 客户验收信息表 Set 客户名称=:客户名称1,'); 
      SQL.Add('托运单号=:托运单号1,验收日期=:验收日期1,验收单位=:验收单位1,验收人=:验收人1,'); 
      SQL.Add('备注=:备注1 where 验收编号=:验收编号1'); 
      Parameters.Items[0].Value:=ComboBox1.Text; 
      Parameters.Items[1].Value:=Edit2.Text; 
      DateTimePicker1.Date:=Date(); 
      Parameters.Items[2].Value:=FormatDateTime('yyyy-mm-dd',DateTimePicker1.Date); 
      Parameters.Items[3].Value:=Edit3.Text; 
      Parameters.Items[4].Value:=Edit4.Text; 
      Parameters.Items[5].Value:=Edit5.Text; 
      Parameters.Items[6].Value:=DM.DSOKHYSXX.FieldByName('验收编号').AsString; 
      Prepared:=true; 
      ExecSQL; 
    end; 
  end; 
end; 
procedure TFRM_KHYSXX.ENA; 
var 
  i:integer; 
begin 
  for i:=ComponentCount-1 downto 0 do 
  begin 
    if (Components[i] is TEdit) then 
    begin 
      TEdit(Components[i]).Color:=clWindow; 
      TEdit(Components[i]).ReadOnly:=False; 
    end; 
  end; 
  ComboBox1.Color:=clWindow; 
  DateTimePicker1.Color:=clWindow; 
  SpeedButton1.Enabled:=False; 
  SpeedButton2.Enabled:=False; 
  SpeedButton3.Enabled:=True; 
  SpeedButton4.Enabled:=False; 
  Panel1.Enabled:=True; 
end; 
procedure TFRM_KHYSXX.DIS; 
var 
  i:integer; 
begin 
  for i:=ComponentCount-1 downto 0 do 
  begin 
    if (Components[i] is Tedit) then 
    begin 
      TEdit(Components[i]).Color:=$00EFEFEF; 
      TEdit(Components[i]).ReadOnly:=true; 
    end; 
  end; 
  ComboBox1.Color:=$00EFEFEF; 
  DateTimePicker1.Color:=$00EFEFEF; 
  SpeedButton1.Enabled:=True; 
  SpeedButton2.Enabled:=True; 
  SpeedButton3.Enabled:=False; 
  SpeedButton4.Enabled:=False; 
  Panel1.Enabled:=False; 
end; 
procedure TFRM_KHYSXX.CLS; 
var 
  i:integer; 
begin 
  for i:=ComponentCount-1 downto 0 do 
  begin 
    if(Components[i] is TEdit) then 
      TEdit(Components[i]).Clear; 
  end; 
  ComboBox1.Clear; 
  DateTimePicker1.Date:=now; 
end; 
///////////////////////////////////////////////////////////////////////// 
procedure TFRM_KHYSXX.SpeedButton6Click(Sender: TObject); 
begin 
  ACtionCD:=''; 
  Close; 
end; 
 
procedure TFRM_KHYSXX.SpeedButton1Click(Sender: TObject); 
begin 
  CLS; 
  ENA; 
  ActionCD := 'N'; 
  bh; 
  ComboBox1.SetFocus; 
end; 
 
procedure TFRM_KHYSXX.SpeedButton2Click(Sender: TObject); 
begin 
  ENA; 
  SpeedButton4.Enabled:=True; 
  ACtionCD := 'M'; 
end; 
 
procedure TFRM_KHYSXX.SpeedButton3Click(Sender: TObject); 
begin 
  if (cansave) then 
  begin 
    Posting; 
    DIS; 
    DM.DSOKHYSXX.Close; 
    DM.DSOKHYSXX.Open; 
    Application.MessageBox('保存成功!','提示!',64); 
    actioncd:=''; 
    self.Close; 
  end; 
end; 
 
procedure TFRM_KHYSXX.SpeedButton4Click(Sender: TObject); 
begin 
  if DM.DSOKHYSXX.RecordCount=0 then 
  begin 
    Application.MessageBox('没有记录可以删除!','提示',0+MB_ICONINFORMATION); 
    Exit; 
  end; 
  if DM.DSOKHYSXX.IsEmpty then 
    Exit; 
  if ID_YES=application.MessageBox('确实要删除这条记录吗?','提示',MB_YESNO) then 
  begin 
    DM.DSOKHYSXX.Delete; 
    Self.OnShow(Sender); 
  end; 
end; 
 
procedure TFRM_KHYSXX.SpeedButton5Click(Sender: TObject); 
begin 
  DIS; 
  SpeedButton4.Enabled:=False; 
  GetAll; 
  ActionCD:=''; 
end; 
 
procedure TFRM_KHYSXX.FormCreate(Sender: TObject); 
begin 
  with DM.QKHYSXX do 
  begin 
    Close; 
    SQL.Clear; 
    SQL.Add('Select * from 客户验收信息表'); 
    Open; 
  end; 
  DM.DSOKHYSXX.Open; 
end; 
 
procedure TFRM_KHYSXX.FormShow(Sender: TObject); 
begin 
  DIS; 
  if ActionCD = 'M' then 
    GetAll 
  else if ActionCD = 'N' then 
  begin 
    CLS; 
    ENA; 
  end; 
end; 
 
procedure TFRM_KHYSXX.DBGrid1CellClick(Column: TColumn); 
begin 
  GetAll; 
end; 
 
procedure TFRM_KHYSXX.ComboBox1DropDown(Sender: TObject); 
var 
i:integer; 
begin 
  ComboBox1.Clear; 
  With DM.QHWTYXX do 
  begin 
    CLose; 
    SQL.Clear; 
    SQL.Add('Select 客户名称 from 货物托运信息表'); 
    Open; 
    if (Recordcount>0) then 
      First; 
    for i:=0 to Recordcount-1 do 
    begin 
      ComboBox1.Items.Add(FieldByName('客户名称').AsString); 
      Next; 
    end; 
  end; 
end; 
 
procedure TFRM_KHYSXX.ComboBox1Change(Sender: TObject); 
begin 
  Edit2.Clear; 
  with DM.QHWTYXX do 
  begin 
    Close; 
    SQL.Clear; 
    SQL.Add('Select 托运单号 from 货物托运信息表 where 客户名称='+''''+ComboBox1.Text+''''); 
    Open; 
  end; 
  if ComboBox1.Text<>'' then 
  begin 
    Edit2.Text:=DM.QHWTYXX.FieldByName('托运单号').Value; 
  end; 
  DateTimePicker1.SetFocus; 
end; 
 
procedure TFRM_KHYSXX.DateTimePicker1KeyPress(Sender: TObject; 
  var Key: Char); 
begin 
  if key=#13 then 
    Edit3.SetFocus; 
end; 
 
procedure TFRM_KHYSXX.Edit3KeyPress(Sender: TObject; var Key: Char); 
begin 
  if key in['a'..'z','0'..'9','.'] then 
    key:=#0; 
  if key=#13 then 
    Edit4.SetFocus; 
end; 
 
procedure TFRM_KHYSXX.Edit4KeyPress(Sender: TObject; var Key: Char); 
begin 
  if key in['a'..'z','0'..'9','A'..'Z','.','-','+','*','/'] then 
    key:=#0; 
  if key=#13 then 
    Edit5.SetFocus; 
end; 
 
procedure TFRM_KHYSXX.ComboBox1KeyPress(Sender: TObject; var Key: Char); 
begin 
  if not (key in [#8,#13]) then 
    key:=#0; 
end; 
 
procedure TFRM_KHYSXX.Edit2Change(Sender: TObject); 
begin 
tr 
end; 
 
procedure TFRM_KHYSXX.Edit3Change(Sender: TObject); 
begin 
tr 
end; 
 
procedure TFRM_KHYSXX.Edit4Change(Sender: TObject); 
begin 
tr 
end; 
 
procedure TFRM_KHYSXX.Edit5Change(Sender: TObject); 
begin 
tr 
end; 
 
procedure TFRM_KHYSXX.Edit1KeyPress(Sender: TObject; var Key: Char); 
begin 
  key:=#0; 
end; 
 
procedure TFRM_KHYSXX.DBGrid1DrawColumnCell(Sender: TObject; 
  const Rect: TRect; DataCol: Integer; Column: TColumn; 
  State: TGridDrawState); 
begin 
  FRM_MAIN.SetDBGird(Sender as TDBGrid,DM.QKHYSXX ,Rect,DataCol,Column,State); 
end; 
 
end.