📄 untmeasureset.pas
字号:
unit untMeaSureSet;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, untBaseMDEdit, DB, ADODB, StdCtrls, Buttons, ExtCtrls, Grids,
DBGrids, jpeg, DBCtrls, Mask, untGlobalVar, fcButton, fcImgBtn;
type
TfrmMeasureSet = class(TfrmBaseMDEdit)
Label1: TLabel;
Label3: TLabel;
Label4: TLabel;
DBEdit1: TDBEdit;
DBEdit3: TDBEdit;
DBLookupComboBox1: TDBLookupComboBox;
adsDetailcode: TStringField;
adsDetailMeasurecode: TStringField;
adsDetailName: TStringField;
adsDetailneedFormula: TBooleanField;
adsDetailFormula: TStringField;
dsQuestionGrp: TDataSource;
adsQuestionGrp: TADODataSet;
adsQuestionGrpcode: TStringField;
adsQuestionGrpname: TStringField;
adsDetailContent: TStringField;
Label2: TLabel;
dstype: TDataSource;
adstype: TADODataSet;
dblkcbbtype: TDBLookupComboBox;
procedure grdDetailEditButtonClick(Sender: TObject);
procedure adsDetailBeforePost(DataSet: TDataSet);
procedure adsDetailneedFormulaGetText(Sender: TField; var Text: String;
DisplayText: Boolean);
procedure adsDetailneedFormulaSetText(Sender: TField;
const Text: String);
private
{ Private declarations }
protected
procedure CheckAvoild; override;
procedure DoBeforePost; override;
procedure AfterFormShow; override;
procedure InitComponents; override;
public
{ Public declarations }
end;
function SetMeasure(ADataSet: TADODataSet; AOpMode: TOperatorMode): Boolean;
implementation
uses untGlobalFun, untFormulaEdit;
function SetMeasure(ADataSet: TADODataSet; AOpMode: TOperatorMode): Boolean;
begin
with TfrmMeasureSet.Create(Application) do
try
adstype.Active:=True;
DataSet := ADataSet;
Title := '心理量表';
OpMode := AOpMode;
ContinueAppend := true;
Result := ShowModal=mrOK;
finally
Free;
end;
end;
{$R *.dfm}
{ TfrmMeasureSet }
procedure TfrmMeasureSet.AfterFormShow;
begin
inherited;
if OpMode = omModi then
DBEdit1.Enabled := false;
with adsDetail do begin
if Active then Active := false;
Connection := DataSet.Connection;
CommandText := 'select * from tMeasure_Item where Measurecode='
+QuotedStr(DataSet.FieldByName('code').AsString);
Active := true;
end;
end;
procedure TfrmMeasureSet.CheckAvoild;
begin
inherited;
if OpMode = omNew then begin
if GetDBValue(DataSet.Connection, 'select count(*) from tMeasure where code='+QuotedStr(Trim(DBEdit1.Text))) > 0 then
begin
if DBEdit1.CanFocus then DBEdit1.SetFocus;
raise Exception.Create('编号重复,请重输!');
end;
end;
end;
procedure TfrmMeasureSet.DoBeforePost;
var
ABookStr: TBookmarkStr;
MaxID: Integer;
begin
inherited;
with adsDetail do begin
if State in [dsInsert, dsEdit] then Post;
DisableControls;
ABookStr := Bookmark;
First;
MaxID := GetMaxID(DataSet.Connection, 'tMeasure_Item','code');
while not Eof do begin
Edit;
if adsDetailMeasurecode.Value <> DataSet.FieldByName('code').AsString then
adsDetailMeasurecode.Value := DataSet.FieldByName('code').AsString;
if adsDetailcode.IsNull then begin
adsDetailcode.Value := StringOfChar('0',10-Length(IntToStr(MaxID)))+IntToStr(MaxID);
Inc(MaxID);
end;
Post;
Next;
end;
EnableControls;
end;
end;
procedure TfrmMeasureSet.InitComponents;
begin
inherited;
with adsQuestionGrp do begin
if Active then Active := false;
Active := true;
end;
if OpMode = omNew then
DataSet.FieldByName('code').Value := GetMaxID('tMeasure', 'code', DataSet.Connection);
end;
procedure TfrmMeasureSet.grdDetailEditButtonClick(Sender: TObject);
var
strFormula: string;
begin
inherited;
//使用户直接在公式列输入的字符生效
grdDetail.SelectedIndex := grdDetail.SelectedIndex-1;
grdDetail.SelectedIndex := grdDetail.SelectedIndex+1;
strFormula := GetFormula(adsDetail.FieldByName('Formula').AsString);
if not (adsDetail.State in [dsInsert, dsEdit]) then
adsDetail.Edit;
adsDetail['Formula'] := strFormula;
end;
procedure TfrmMeasureSet.adsDetailBeforePost(DataSet: TDataSet);
begin
inherited;
if DataSet.FieldByName('NeedFormula').AsBoolean
and (DataSet.FieldByName('formula').IsNull
or (Trim(DataSet.FieldByName('formula').AsString)='')) then
begin
DataSet.FieldByName('formula').FocusControl;
raise Exception.Create('公式不能为空!');
end;
end;
procedure TfrmMeasureSet.adsDetailneedFormulaGetText(Sender: TField;
var Text: String; DisplayText: Boolean);
begin
inherited;
if Sender.IsNull then Exit;
if Sender.Value then Text := '是'
else Text := '否';
end;
procedure TfrmMeasureSet.adsDetailneedFormulaSetText(Sender: TField;
const Text: String);
begin
inherited;
if Text = '是' then Sender.Value := true
else Sender.Value := False;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -