📄 tcourse1unit.pas
字号:
if messagebox(handle,'您确定要删除吗?','提示',MB_YESNO + MB_ICONQUESTION)=ID_yes then
begin
sqlStr := 'delete from TCoursel where tclno='+quotedstr(temptclno);
ToExecSQL(sqlStr, DM.ADOConnection1);
showmessage('删除成功!');
adoquery1.Close;
adoquery1.Open;
end;
end;
procedure TTCourse1Form.BitBtn4Click(Sender: TObject);
begin
if messagebox(handle,'您确定要修改吗?','提示',MB_YESNO + MB_ICONQUESTION)=ID_yes then
begin
flag:=2;
ControlTheEnablePro(false);
// cbxtscode.Enabled:=false;
//cbxtcscode.Enabled:=false;
edttcdepartment.Enabled:=false;
edttclno.Enabled:=false;
end;
end;
procedure TTCourse1Form.BitBtn5Click(Sender: TObject);
begin
adoquery1.Open;
{ with adoquery1 do
begin
edttclno.Text := fieldByName('tclno').AsString;
edtthname.Text := fieldByName('thname').AsString;
edttnamen.Text := fieldByName('tnamen').AsString;
edttweekcount.Text := fieldByname('tweekcount').AsString;
edttcredit.Text := fieldByName('tcredit').AsString;
edttclassno.Text:=fieldbyname('tclassno').AsString;
edttstarttoend.Text:=fieldbyname('tstarttoend').AsString;
edttcname.Text:=fieldbyname('tcname').AsString;
cbxtselect.Text := fieldbyname('tselect').AsString;
edtadress.Text:=fieldbyname('tadress').AsString;
edttgrade.Text:=fieldbyname('tgrade').AsString;
//cbxtdepartment.ItemIndex := cbxtdepartment.Items.IndexOf(fieldByname('tdepartment').AsString); }
ControlTheEnablePro(true);
// end;
end;
procedure TTCourse1Form.BitBtn7Click(Sender: TObject);
begin
close;
end;
procedure TTCourse1Form.BitBtn6Click(Sender: TObject);
var
sqlStr,uno: string;
begin
if edtthname.Text='' then
begin
if application.MessageBox('教研室名称不能为空','提示消息', mb_iconInformation+mb_ok)=idok then
edtthname.SetFocus;
end
else
if cbxtselect.Text = '请选择' then
begin
application.MessageBox('"必/选/修"不能为空','提示消息', mb_iconInformation+mb_ok);
cbxtselect.SetFocus;
end
else
if edttweekcount.Text = '' then
begin
application.MessageBox('时间不能为空','提示消息', mb_iconInformation+mb_ok);
edttweekcount.SetFocus;
end
else
if edttclassno.Text = '' then
begin
application.MessageBox('教学班号不能为空','提示消息', mb_iconInformation+mb_ok);
edttclassno.SetFocus;
end
else
if edttstarttoend.Text = '' then
begin
application.MessageBox('起止周不能为空','提示消息', mb_iconInformation+mb_ok);
edttstarttoend.SetFocus;
end
else
if edttcname.Text = '' then
begin
application.MessageBox('优选类别不能为空','提示消息', mb_iconInformation+mb_ok);
edttcname.SetFocus;
end
else
if edtadress.Text = '' then
begin
application.MessageBox('地址不能为空','提示消息', mb_iconInformation+mb_ok);
edtadress.SetFocus;
end
else
if edttgrade.Text = '' then
begin
application.MessageBox('年级不能为空','提示消息', mb_iconInformation+mb_ok);
edttgrade.SetFocus;
end
else
begin
// 数据库添加修改操作
//********************************************************************************
if flag=1 then // flag=1表示此时是增加状态
begin
adoquery1.Close;
uno := GetUno; // 自动获取用户编号
sqlStr := 'INSERT TCoursel(tclno,thname, '
+ ' tweekcount, tselect, tcredit,tscode,'
+'tclassno,tstarttoend,tcname,tadress,tcscode,tgrade)'
+ 'Values('
+ QuotedStr(uno)+','
+ QuotedStr(edtthname.Text)+','
+ QuotedStr(edttweekcount.Text)+','
+ QuotedStr(cbxtselect.Text) + ','
+ QuotedStr(edttcredit.Text) + ','
+ QuotedStr(cbxtscode.Text)+','
+ QuotedStr(edttclassno.Text)+','
+ QuotedStr(edttstarttoend.Text)+','
+ QuotedStr(edttcname.Text) + ','
//+ QuotedStr(edttlesson.Text) + ','
+ QuotedStr(edtadress.Text)+','
+ QuotedStr(temptcscode) + ','
+ QuotedStr(edttgrade.Text)
+')';
ToExecSQL(sqlStr, DM.ADOConnection1); //插入记录到用户表
showmessage('添加成功!');
end;
if flag=2 then // flag=2表示此时是修改状态
begin
sqlStr := 'UPDATE TCoursel SET thname=' + QuotedStr(edtthname.Text) +','
+ 'tweekcount=' + QuotedStr(edttweekcount.Text) + ','
+ 'tselect=' + QuotedStr(cbxtselect.Text) +','
+ 'tcredit=' + QuotedStr(edttcredit.Text) + ','
+ 'tscode=' + QuotedStr(cbxtscode.Text) + ','
+ 'tclassno=' + QuotedStr(edttclassno.Text)+ ','
+ 'tstarttoend=' + QuotedStr(edttstarttoend.Text) + ','
+ 'tcname=' + QuotedStr(edttcname.Text)+','
+ 'tadress=' + QuotedStr(edtadress.Text) + ','
+ 'tcscode=' + QuotedStr(cbxtcscode.Text) + ','
+ 'tgrade=' + QuotedStr(edttgrade.Text)
+' WHERE tclno=' + QuotedStr(adoquery1.fieldbyname('tclno').AsString);
ToExecSQL(sqlStr, DM.ADOConnection1);
showmessage('修改成功!');
end;
//********************************************************************************
adoquery1.Close;
adoquery1.Open;
ControlTheEnablePro(true);
flag := 0;
end;
end;
procedure TTCourse1Form.btnFindClick(Sender: TObject);
var
sqlStr: string;
begin
sqlStr :='select tcl.tclno,tcl.thname,tcl.tcscode,tcl.tscode,'
+' tt.tno,tt.tname,tcl.tweekcount,tcl.tclassno,'
+' tl.tlesson,tcl.tselect,tcl.tgrade,tcl.tadress,tcl.tcredit,tcl.tstarttoend,tcl.tcname,tt.tcdepartment'
+' from TLesson tl inner join TCoursel tcl on tl.tscode = tcl.tscode'
+' inner join TTeacher tt on tt.tno = tcl.tcscode WHERE 1=1';
if edttnamen2.Text <> '' then
sqlStr := sqlstr+ ' AND tname like ''%' + edttnamen2.Text + '%''';
if cbxtselect2.ItemIndex <> 0 then
sqlStr := sqlStr + ' AND tselect=' + QuotedStr(cbxtselect2.Text);
if edtthname2.Text <> ''then
sqlStr := sqlStr + ' AND thname=' + QuotedStr(edtthname2.Text);
if cbxtlesson2.ItemIndex <> 0 then
sqlStr := sqlStr + ' AND tlesson=' + QuotedStr(cbxtlesson2.Text);
if cbxtdepartment2.ItemIndex <> 0 then
sqlStr := sqlStr + ' AND tcdepartment=' + QuotedStr(cbxtdepartment2.Text);
if edttgrade2.Text<>'' then
sqlStr := sqlStr + ' AND tgrade=' + QuotedStr(edttgrade2.Text);
with adoquery1 do
begin
Sql.Text := sqlStr;
Open;
end;
edttnamen2.Text:='';
edtthname2.Text:='';
edttgrade2.Text:='';
cbxtselect2.ItemIndex:=0;
cbxtlesson2.ItemIndex:=0;
cbxtdepartment2.ItemIndex:=0;
end;
procedure TTCourse1Form.btnReportClick(Sender: TObject);
begin
TCourse1QRForm.TCourse1FormQR.Preview;
end;
procedure TTCourse1Form.Button1Click(Sender: TObject);
begin
CopyDbDataToExcel([DBGrid1]);
end;
procedure TTCourse1Form.CopyDbDataToExcel(Args: array of const);
var
iCount, jCount: Integer;
XLApp: Variant;
Sheet: Variant;
I: Integer;
qzw1: Variant;
begin
Screen.Cursor := crHourGlass;
if not VarIsEmpty(XLApp) then
begin
XLApp.DisplayAlerts := False;
XLApp.Quit;
VarClear(XLApp);
end;
try
XLApp := CreateOleObject('Excel.Application');
except
Screen.Cursor := crDefault;
Exit;
end;
XLApp.WorkBooks.Add;
XLApp.SheetsInNewWorkbook := High(Args) + 1;
for I := Low(Args) to High(Args) do
begin
//XLApp.WorkBooks[1].WorkSheets[I+1].Name :=TDBGrid(Args[I].VObject).Name;
// Sheet := XLApp.Workbooks[1].WorkSheets[TDBGrid(Args[I].VObject).Name];
XLApp.WorkBooks[1].WorkSheets[I+1].Name :='总课程表';
Sheet := XLApp.Workbooks[1].WorkSheets['总课程表'];
if not TDBGrid(Args[I].VObject).DataSource.DataSet.Active then
begin
Screen.Cursor := crDefault;
Exit;
end;
TDBGrid(Args[I].VObject).DataSource.DataSet.first;
for iCount := 0 to TDBGrid(Args[I].VObject).Columns.Count - 1 do
Sheet.Cells[2, iCount + 1] :=TDBGrid(Args[I].VObject).Columns.Items[iCount].Title.Caption;
jCount := 2;
while not TDBGrid(Args[I].VObject).DataSource.DataSet.Eof do
begin
for iCount := 0 to TDBGrid(Args[I].VObject).Columns.Count - 1 do
Sheet.Cells[jCount + 1, iCount + 1] := TDBGrid(Args[I].VObject).Columns.Items[iCount].Field.AsString;
Inc(jCount);
TDBGrid(Args[I].VObject).DataSource.DataSet.Next;
end;
// 控制表头
//*********************************************
//合并单元格 根据DBgrid的 记录数来 决定 单元格第二个列 值
qzw1:=Sheet.Range['A1','n1'];
qzw1.Merge;
// 更改 Excel 标题栏:
XLApp.Caption := '总课程表';
//设置指定列的名称,以第一列为例:
XLApp.Cells[1,1].Value := ' 总课程表';
//设置第一行字体属性:
XLApp.ActiveSheet.Rows[1].Font.Name := '隶书';
XLApp.ActiveSheet.Rows[1].Font.Color := clblack;
XLApp.ActiveSheet.Rows[1].Font.Bold := True;
XLApp.ActiveSheet.Rows[1].Font.size := 20;
//设置指定行的高度(单位:磅)(1磅=0.035厘米),以第1行为例:
XLApp.ActiveSheet.Rows[1].RowHeight := 1/0.035; // 1厘米
//设置指定列的宽度(单位:字符个数),以第一列为例:
//XLApp.ActiveSheet.Columns[1].ColumnsWidth := 10;
//***************************************************************
XlApp.Visible := True;
end;
Screen.Cursor := crDefault;
end;
procedure TTCourse1Form.cbxtscodeChange(Sender: TObject);
var
adoqry:Tadoquery;
begin
adoqry:=Tadoquery.Create(self);
with adoqry do
begin
Connection:=dm.ADOConnection1;
sql.Text:='select tlesson from TLesson where tscode = '+quotedstr(cbxtscode.Text);
Open;
edttlesson.Text := fieldByname('tlesson').AsString;
end;
adoqry.Free;
end;
procedure TTCourse1Form.cbxtcscodeChange(Sender: TObject);
var
adoqry:Tadoquery;
begin
adoqry:=Tadoquery.Create(self);
with adoqry do
begin
Connection:=dm.ADOConnection1;
sql.Text:='select * from TTeacher where tno = '+quotedstr(cbxtcscode.Text);
Open;
edttnamen.Text:=fieldByname('tname').AsString;
//edttpost.Text:=fieldbyname('tpost').AsString;
edttcdepartment.Text := fieldByName('tcdepartment').AsString;
// if fieldByName('tbool').AsString = '是' then
// cbtcout.Checked:=true
// else
// cbtcout.Checked:=false;
end;
adoqry.Free;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -