unit U_ZdyAttInputGYS_ZXX; 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 TfrmZdyAttInputGYS_ZXX = class(TForm) ADOQueryTemp: TADOQuery; ADOQueryCmd: TADOQuery; ADOQueryMain: TADOQuery; Panel2: TPanel; Label3: TLabel; Label4: TLabel; Label5: TLabel; Label6: TLabel; Label7: TLabel; Label8: TLabel; Label10: TLabel; GYSName: TEdit; GYSFZRen: TEdit; GYSNameZC: TEdit; GYSTel: TEdit; GYSCodeFW: TMemo; Note: TMemo; GYSAdd: TMemo; GYSNo: TEdit; ToolBar1: TToolBar; ToolButton3: TToolButton; TBClose: TToolButton; Panel1: TPanel; Label2: TLabel; procedure FormDestroy(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure TBCloseClick(Sender: TObject); procedure FormShow(Sender: TObject); procedure TBRafreshClick(Sender: TObject); procedure ToolButton3Click(Sender: TObject); private { Private declarations } procedure InitGrid(); function SaveData():Boolean; public { Public declarations } FKHMainid,formid:String; end; var frmZdyAttInputGYS_ZXX: TfrmZdyAttInputGYS_ZXX; implementation uses U_DataLink,U_Fun,U_ZDYHelp,U_FjList_RZ; {$R *.dfm} procedure TfrmZdyAttInputGYS_ZXX.InitGrid(); begin with ADOQueryMain do begin Filtered:=False; Close; SQL.Clear; sql.Add('select * from KH_Main where KHMainID='''+Trim(FKHMainid)+''''); Open; end; //主表 if ADOQueryMain.IsEmpty=false then SCSHDataNew(ADOQueryMain,Panel2,2); end; procedure TfrmZdyAttInputGYS_ZXX.FormDestroy(Sender: TObject); begin frmZdyAttInputGYS_ZXX:=nil; end; procedure TfrmZdyAttInputGYS_ZXX.FormClose(Sender: TObject; var Action: TCloseAction); begin Action:=caFree; end; procedure TfrmZdyAttInputGYS_ZXX.TBCloseClick(Sender: TObject); begin Close; end; procedure TfrmZdyAttInputGYS_ZXX.FormShow(Sender: TObject); begin InitGrid(); end; procedure TfrmZdyAttInputGYS_ZXX.TBRafreshClick(Sender: TObject); begin InitGrid(); end; function TfrmZdyAttInputGYS_ZXX.SaveData():Boolean; var maxId,CRID,fzdyCode,FYSSubId,maxno,maxnum,FMXNO:String; begin ///取maxId result:=false; ADOQueryCmd.Connection.BeginTrans; if Trim(FKHMainid)='' then begin if GetLSNo(ADOQueryCmd,maxId,'KH','KH_Main',4,1)=False then begin Result:=False; ADOQueryCmd.Connection.RollbackTrans; Application.MessageBox('取最大号失败!','提示',0); Exit; end; if GetLSNo(ADOQueryCmd,fzdyCode,'PB','KH_Main',4,0)=False then begin Result:=False; ADOQueryCmd.Connection.RollbackTrans; Application.MessageBox('取最大号失败!','提示',0); Exit; end; GYSNo.Text:=Trim(fzdyCode); end else begin maxId:=Trim(FKHMainid); end; with ADOQueryCmd do begin Close; SQL.Clear; sql.Add('select * from KH_Main where KHMainID='''+Trim(FKHMainid)+''''); Open; If IsEmpty then begin append; FieldByName('Filler').Value:=Trim(DName); FieldByName('fillcode').Value:=Trim(DCode); end else begin Edit; FieldByName('Editer').Value:=Trim(DName); FieldByName('Edittime').Value:=SGetServerDateTime(ADOQueryTemp); end; FieldByName('KHMainID').Value:=Trim(maxId); FieldByName('GYSType').Value:='坯布'; SSetsaveSqlNew(ADOQueryCmd,'KH_Main',Panel2,2); post; end; if FKHMainid='' then begin if GetLSNo(ADOQueryCmd,maxno,'HB','KH_Sub',4,1)=False then begin ADOQueryCmd.Connection.RollbackTrans; Application.MessageBox('取系人最大ID失败!','提示',0); Exit; end; with ADOQueryCmd do begin Close; SQL.Clear; sql.Add('select * from KH_Sub where KHSubid='''+Trim(maxno)+''''); Open; If IsEmpty then begin append; FieldByName('XHNo').Value:=1; end else begin Edit; end; FieldByName('KHSubid').Value:=Trim(maxno); FieldByName('KHMainID').Value:=Trim(maxId); FieldByName('KHMXName').Value:=Trim(GYSName.Text); FieldByName('KHMXJC').Value:=Trim(GYSNameZC.Text); FieldByName('KHMXLXR').Value:=Trim(GYSFZRen.Text); FieldByName('KHMXTel').Value:=Trim(GYSTel.Text); FieldByName('KHMXAdd').Value:=Trim(GYSAdd.Text); FieldByName('KHMXSJAdd').Value:=Trim(GYSAdd.Text); FieldByName('KHMXNo').Value:=Trim(fzdyCode); //FieldByName('KHMXNote').Value:=Trim(Note.Text); post; end; end; FKHMainid:=maxId; with ADOQueryCmd do begin Close; sql.Clear; sql.Add('select * from KH_Main where GYSName='''+Trim(GYSName.Text)+''''); sql.Add(' and GYSType=''坯布'' '); 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_Main where GYSNameZC='''+Trim(GYSNameZC.Text)+''''); sql.Add(' and GYSType=''坯布'' '); Open; end; if ADOQueryCmd.RecordCount>1 then begin ADOQueryCmd.Connection.RollbackTrans; Application.MessageBox('供应商简称重复!','提示',0); Exit; end; ADOQueryCmd.Connection.CommitTrans; result:=true; end; procedure TfrmZdyAttInputGYS_ZXX.ToolButton3Click(Sender: TObject); begin Panel2.SetFocus; IF trim(GYSName.Text)='' then begin application.MessageBox('供应商不能为空!','提示信息',MB_ICONERROR); exit; end; if Trim(GYSNameZC.Text)='' then begin application.MessageBox('简称不能为空!','提示信息',MB_ICONERROR); exit; end; if Application.MessageBox('确定要保存数据吗?','提示',32+4)<>IDYES then Exit; if SaveData() then begin Application.MessageBox('保存成功!','提示',0); ModalResult:=1; end; end; end.