unit U_LabelInput; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ComCtrls, ToolWin, StdCtrls, BtnEdit, ExtCtrls, DB, ADODB, RM_System, RM_Common, RM_Class, RM_GridReport, Buttons, RTComboBox, RM_Preview, RM_e_Xls, RM_e_Graphic, RM_e_bmp, RM_BarCode, RM_DsgGridReport, RM_Dataset, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, cxDBData, cxGridLevel, cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxClasses, cxControls, cxGridCustomView, cxGrid; type TfrmLabelInput = class(TForm) Panel1: TPanel; Label3: TLabel; note: TMemo; ToolBar1: TToolBar; Tsave: TToolButton; Tclose: TToolButton; ADOQueryCmd: TADOQuery; Label9: TLabel; LabelCaption: TEdit; Label10: TLabel; ADOQueryTmp: TADOQuery; LabelType: TComboBox; procedure TcloseClick(Sender: TObject); procedure TsaveClick(Sender: TObject); procedure FormShow(Sender: TObject); private function SaveData(): Boolean; procedure InitWinData(); public FLabelId: string; end; var frmLabelInput: TfrmLabelInput; implementation uses U_DataLink, U_RTFun; {$R *.dfm} procedure TfrmLabelInput.TcloseClick(Sender: TObject); begin close; end; procedure TfrmLabelInput.TsaveClick(Sender: TObject); begin if trim(labelCaption.Text) = '' then begin application.MessageBox('标签名称不能为空!', '提示'); labelCaption.SetFocus; exit; end; if trim(LabelCaption.Text) = '' then begin application.MessageBox('标签类型不能为空!', '提示'); exit; end; if SaveData() then begin ModalResult := 1; end; end; ///////////////////////////////////////////////////////////////////// //函数功能:保存数据 ///////////////////////////////////////////////////////////////////// function TfrmLabelInput.SaveData(): Boolean; var maxno: string; begin try ADOQueryCmd.Connection.BeginTrans; if Trim(FLabelId) = '' then begin if GetLSNo(ADOQueryCmd, maxno, 'LB', 'Dye_Label', 3, 1) = False then begin ADOQueryCmd.Connection.RollbackTrans; Application.MessageBox('取最大号失败!', '提示', 0); Exit; end; end else begin maxno := Trim(FLabelId); end; with ADOQueryCmd do begin Close; sql.Clear; SQL.Add('select * from Dye_Label where LabelId=''' + Trim(FLabelId) + ''''); Open; end; with ADOQueryCmd do begin if Trim(FLabelId) = '' then begin Append; FieldByName('FillId').Value := Trim(DCode); FieldByName('Filler').Value := Trim(DName); FieldByName('EditTime').Value := SGetServerDateTime(ADOQueryTmp); end else begin Edit; FieldByName('EditId').Value := Trim(DCode); FieldByName('Editer').Value := Trim(DName); FieldByName('EditTime').Value := SGetServerDateTime(ADOQueryTmp); end; RTSetsavedata(ADOQueryCmd, 'Dye_Label', Panel1, 1); FieldByName('LabelId').Value := Trim(maxno); Post; end; with ADOQueryTmp do begin Close; sql.Clear; sql.Add('select * from Dye_Label where LabelCaption=''' + Trim(LabelCaption.text) + ''''); Open; end; if ADOQueryTmp.RecordCount > 1 then begin ADOQueryCmd.Connection.RollbackTrans; Result := False; Application.MessageBox('标签名称重复!', '提示', 0); Exit; end; ADOQueryCmd.Connection.CommitTrans; result := true; except ADOQueryCmd.Connection.RollbackTrans; Result := false; application.MessageBox('保存标签模板出错!', '警告信息', 0); end; end; //////////////////////////////////////////////////////////// //初始化窗口数据 //////////////////////////////////////////////////////////// procedure TfrmLabelInput.InitWinData(); begin with ADOQueryTmp do begin close; sql.Clear; sql.Add('select A.*'); sql.Add('from Dye_Label A'); sql.Add('WHERE LabelId=' + QuotedStr(FLabelId)); Open; SCSHData(ADOQueryTmp, panel1, 1); end; end; procedure TfrmLabelInput.FormShow(Sender: TObject); begin InitWinData(); end; end.