unit U_PBGYSInPutSubBank; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, cxGraphics, cxCustomData, cxStyles, cxTL, cxMaskEdit, DB, ADODB, cxInplaceContainer, cxDBTL, cxControls, cxTLData, ComCtrls, ToolWin, StdCtrls, cxFilter, cxData, cxDataStorage, cxEdit, cxDBData, DBClient, cxGridCustomTableView, cxGridTableView, cxGridDBTableView, ExtCtrls, cxSplitter, cxGridLevel, cxClasses, cxGridCustomView, cxGrid, cxGridCustomPopupMenu, cxGridPopupMenu, RM_Dataset, RM_System, RM_Common, RM_Class, RM_GridReport, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdFTP,ShellAPI,IniFiles, cxCheckBox, cxCalendar, cxButtonEdit, cxTextEdit, cxDropDownEdit, cxPC; type TfrmPBGYSInPutSubBank = class(TForm) ADOQueryTemp: TADOQuery; ADOQueryCmd: TADOQuery; ADOQueryMain: TADOQuery; Panel2: TPanel; Label13: TLabel; Label19: TLabel; KHLXRMX: TEdit; KHNameMX: TEdit; ToolBar1: TToolBar; TBAdd: TToolButton; TBClose: TToolButton; TBAddXJ: TToolButton; Panel3: TPanel; Label1: TLabel; LabGYSName: TLabel; Panel1: TPanel; Label8: TLabel; Label9: TLabel; Label10: TLabel; Label12: TLabel; Label23: TLabel; Button3: TButton; HangNo: TEdit; BankNo: TEdit; BankName: TEdit; BankType: TComboBox; HuMing: TEdit; procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure TBCloseClick(Sender: TObject); procedure FormShow(Sender: TObject); procedure TBAddClick(Sender: TObject); procedure Button3Click(Sender: TObject); procedure TBAddXJClick(Sender: TObject); procedure BankTypeChange(Sender: TObject); private { Private declarations } function SaveDataBank():Boolean; procedure initBtnColor(panel12:TPanel); public { Public declarations } FKHMainid,FKHSubId,FBKID:String; PState:Integer; end; var frmPBGYSInPutSubBank: TfrmPBGYSInPutSubBank; implementation uses U_DataLink,U_Fun,U_ZDYHelp; {$R *.dfm} procedure TfrmPBGYSInPutSubBank.FormClose(Sender: TObject; var Action: TCloseAction); begin Action:=caFree; end; procedure TfrmPBGYSInPutSubBank.initBtnColor(panel12:TPanel); var i:Integer; begin with panel12 do begin for i:=0 to panel12.ControlCount-1 do begin if Controls[i] is TEdit then begin TEdit(Controls[i]).Color:=clMenu; TEdit(Controls[i]).ReadOnly:=True; end else if Controls[i] is TMemo then begin TMemo(Controls[i]).Color:=clMenu; TMemo(Controls[i]).ReadOnly:=True; end else if Controls[i] is TComboBox then begin TComboBox(Controls[i]).Color:=clMenu; TComboBox(Controls[i]).Enabled:=False; end; end; end; end; procedure TfrmPBGYSInPutSubBank.TBCloseClick(Sender: TObject); begin Close; end; procedure TfrmPBGYSInPutSubBank.FormShow(Sender: TObject); begin KHNameMX.SetFocus; with ADOQueryTemp do begin Close; SQL.Clear; sql.Add('select * from KH_Sub where KHSubID='''+Trim(FKHSubId)+''''); Open; end; //主表 if ADOQueryTemp.IsEmpty=false then SCSHDataNew(ADOQueryTemp,Panel2,2); with ADOQueryTemp do begin Close; sql.Clear; sql.Add('select * from KH_Sub_Bank where BKID='''+Trim(FBKID)+''''); Open; end; SCSHDataNew(ADOQueryTemp,Panel1,3); BankNo.Hint:=Trim(FBKID); if PState=0 then begin Button3.Caption:='新增保存'; BankType.Enabled:=False; BankType.Color:=clMenu; TBAdd.Visible:=True; TBAddXJ.Visible:=True; end else if PState=1 then begin Button3.Caption:='修改保存'; BankType.Enabled:=True; BankType.Color:=clWindow; TBAdd.Visible:=False; TBAddXJ.Visible:=False; end else if PState=2 then begin Button3.Visible:=False; BankType.Enabled:=False; BankType.Color:=clMenu; TBAdd.Visible:=False; TBAddXJ.Visible:=False; initBtnColor(Panel1); end; end; procedure TfrmPBGYSInPutSubBank.TBAddClick(Sender: TObject); begin BankNo.Hint:=''; BankType.ItemIndex:=0; HuMing.Text:=Trim(KHNameMX.Text); HuMing.Color:=clMenu; HuMing.ReadOnly:=True; HangNo.SetFocus; end; procedure TfrmPBGYSInPutSubBank.Button3Click(Sender: TObject); begin if Trim(BankType.Text)='' then begin application.MessageBox('类型不能为空','提示'); exit; end; if Trim(BankNo.Text)='' then begin application.MessageBox('账号不能为空','提示'); exit; end; if Trim(HuMing.Text)='' then begin application.MessageBox('户名不能为空','提示'); exit; end; if SaveDataBank() then begin Application.MessageBox('保存成功!','提示',0); ModalResult:=1; end; end; function TfrmPBGYSInPutSubBank.SaveDataBank():Boolean; var maxno:String; begin result:=false; try ADOQueryCmd.Connection.BeginTrans; if PState=0 then begin if GetLSNo(ADOQueryCmd,maxno,'BK','KH_Sub_Bank',4,1)=False then begin ADOQueryCmd.Connection.RollbackTrans; Application.MessageBox('开户行最大ID失败!','提示',0); Exit; end; end else if PState=1 then begin maxno:=Trim(FBKID); end; with ADOQueryCmd do begin Close; SQL.Clear; sql.Add('select * from KH_Sub_Bank where BKID='''+Trim(maxno)+''''); Open; end; with ADOQueryCmd do begin if PState=0 then begin Append; FieldByName('Filler').Value:=Trim(DName); FieldByName('FillerCode').Value:=Trim(DCode); FieldByName('FillTime').Value:=SGetServerDateTime(ADOQueryTemp); FieldByName('Valid').Value:='Y'; end else if PState=1 then begin Edit; FieldByName('Editer').Value:=Trim(DName); FieldByName('EditerCode').Value:=Trim(DCode); FieldByName('EditTime').Value:=SGetServerDateTime(ADOQueryTemp); end; FieldByName('KHMainId').Value:=Trim(FKHMainid); FieldByName('KHSubId').Value:=Trim(FKHSubId); FieldByName('BKID').Value:=Trim(maxno); RTSetsavedata(ADOQueryCmd,'KH_Sub_Bank',Panel1,3); if BankType.ItemIndex=0 then begin FieldByName('HuMing').Value:=Trim(KHNameMX.Text); end; Post; end; with ADOQueryCmd do begin Close; sql.Clear; sql.Add('select * from KH_Sub_Bank where BankName='''+Trim(BankName.Text)+''''); sql.Add(' and KHSubId='''+Trim(FKHMainid)+''' and valid=''Y'' '); Open; end; if ADOQueryCmd.RecordCount>1 then begin ADOQueryCmd.Connection.RollbackTrans; Application.MessageBox('开户行重复!','提示',0); Exit; end; with ADOQueryCmd do begin Close; sql.Clear; sql.Add('select * from KH_Sub_Bank where BankNo='''+Trim(BankNo.Text)+''''); sql.Add(' and KHSubId='''+Trim(FKHMainid)+''' and valid=''Y'' '); Open; end; if ADOQueryCmd.RecordCount>1 then begin ADOQueryCmd.Connection.RollbackTrans; Application.MessageBox('账号重复!','提示',0); Exit; end; if PState=0 then begin with ADOQueryCmd do begin Close; sql.Clear; sql.Add('UPdate KH_Sub_Bank Set XH=isnull((select Max(XH) from KH_Sub_Bank A where A.KHSubId=KH_Sub_Bank.KHSubId and A.Valid=''Y''),0)+1'); sql.Add(' where BKID='''+Trim(maxno)+''''); ExecSQL; end; end; ADOQueryCmd.Connection.CommitTrans; result:=true; except ADOQueryCmd.Connection.RollbackTrans; Application.MessageBox('数据保存失败!','提示',0); end; end; procedure TfrmPBGYSInPutSubBank.TBAddXJClick(Sender: TObject); begin BankNo.Hint:=''; BankType.ItemIndex:=1; HuMing.Text:=Trim(KHLXRMX.Text); HuMing.Color:=clWindow; HuMing.ReadOnly:=False; HangNo.SetFocus; end; procedure TfrmPBGYSInPutSubBank.BankTypeChange(Sender: TObject); begin if BankType.ItemIndex=0 then begin HuMing.Color:=clMenu; HuMing.ReadOnly:=True; HuMing.Text:=Trim(KHNameMX.Text); end else begin HuMing.Color:=clWindow; HuMing.ReadOnly:=False; end; end; end.