📄 unitinput.pas.~63~
字号:
unit unitInput;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, Buttons, DBGridEh, IBDatabase, IBCustomDataSet,
IBUpdateSQL, DB, IBQuery;
type
TfmInput = class(TForm)
Label1: TLabel;
lbLLY: TLabel;
Label3: TLabel;
Label4: TLabel;
lbSchool: TLabel;
Label6: TLabel;
lbKS: TLabel;
Label8: TLabel;
lbKSS: TLabel;
lbKM: TLabel;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
IBQuery1: TIBQuery;
IBUpdateSQL1: TIBUpdateSQL;
DataSource1: TDataSource;
StringGrid1: TStringGrid;
procedure StringGrid1SetEditText(Sender: TObject; ACol, ARow: Integer;
const Value: string);
procedure FormShow(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
SubjectName:String;
end;
implementation
uses UnitDatamodule, UnitGlobal;
{$R *.dfm}
procedure TfmInput.BitBtn1Click(Sender: TObject);
var
i:Integer;
j:Extended;
begin
dm.IBTrans1.Active:=false;
for i:=1 to StringGrid1.RowCount-1 do
begin
if not TryStrToFloat(StringGrid1.Cells[2,i],j) then
begin
Application.MessageBox('非法数据!','错误',MB_OK or MB_ICONERROR);
exit;
end;
IBQuery1.Close;
IBQuery1.SQL.Text:='Update '+CurrentAch+' set '+SubjectName+'='+
StringGrid1.Cells[2,i]+' where zkzh='''+StringGrid1.Cells[0,i]+'''';
IBQuery1.ExecSQL;
end;
try
dm.IBTrans1.Commit;
Application.MessageBox('成功提交数据','提示',MB_OK or MB_ICONINFORMATION);
Self.ModalResult:=mrOK;
except
dm.IBTrans1.Rollback;
Application.MessageBox('提交失败,可能是共享冲突,请稍候重试!','错误',MB_OK or MB_ICONERROR);
end;
end;
procedure TfmInput.FormShow(Sender: TObject);
var
i:Integer;
begin
StringGrid1.Cells[0,0]:='学号';
StringGrid1.Cells[1,0]:='姓名';
StringGrid1.Cells[2,0]:=lbKM.Caption+'成绩';
IBQuery1.Open;
IBQuery1.Last;
lbKSS.Caption:=Inttostr(IBQuery1.RecordCount);
StringGrid1.RowCount:=IBQuery1.RecordCount+1;
StringGrid1.FixedCols:=2;
StringGrid1.FixedRows:=1;
IBQuery1.First;
i:=1;
while not IBQuery1.Eof do
begin
StringGrid1.Cells[0,i]:=IBQuery1.Fields[0].AsString;
StringGrid1.Cells[1,i]:=IBQuery1.Fields[1].AsString;
StringGrid1.Cells[2,i]:=FloatToStr(IBQuery1.Fields[2].AsFloat);
IBQuery1.Next;
i:=i+1;
end;
IBQuery1.Close;
dm.IBTrans1.Active:=false;
end;
procedure TfmInput.StringGrid1SetEditText(Sender: TObject; ACol, ARow: Integer;
const Value: string);
var
j:Extended;
begin
if not tryStrToFloat(Value,j) then
begin
Application.MessageBox('非法数据!','错误',MB_OK or MB_ICONERROR);
Value:='0';
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -