📄 selclass.pas.~2~
字号:
// daDep
//
Self.daDep.Active := False;
Self.daDep.DataSet := nil;
Self.daDep.DataTable := nil;
Self.daDep.DeleteCommand := Self.bdpDeleteCommand2;
Self.daDep.InsertCommand := Self.bdpInsertCommand2;
Self.daDep.SelectCommand := Self.bdpSelectCommand2;
Self.daDep.StartRecord := 0;
Self.daDep.UpdateCommand := Self.bdpUpdateCommand2;
//
// bdpDeleteCommand2
//
Self.bdpDeleteCommand2.CommandOptions := nil;
Self.bdpDeleteCommand2.CommandText := 'DELETE FROM dbo.Department WHERE ID' +
' = ? AND Name = ?';
Self.bdpDeleteCommand2.CommandType := System.Data.CommandType.Text;
Self.bdpDeleteCommand2.Connection := Self.BdpConnection1;
Self.bdpDeleteCommand2.ParameterCount := (SmallInt(2));
Self.bdpDeleteCommand2.Parameters.Add(Borland.Data.Common.BdpParameter.Create('I' +
'DOriginal', Borland.Data.Common.BdpType.&String, Borland.Data.Common.BdpType.stFixed,
2, System.Data.ParameterDirection.Input, False, (Byte(0)), (Byte(0)),
0, 'ID', System.Data.DataRowVersion.Original, nil));
Self.bdpDeleteCommand2.Parameters.Add(Borland.Data.Common.BdpParameter.Create('N' +
'ameOriginal', Borland.Data.Common.BdpType.&String, Borland.Data.Common.BdpType.stFixed,
20, System.Data.ParameterDirection.Input, False, (Byte(0)), (Byte(0)),
0, 'Name', System.Data.DataRowVersion.Original, nil));
Self.bdpDeleteCommand2.SchemaName := nil;
Self.bdpDeleteCommand2.Transaction := nil;
Self.bdpDeleteCommand2.UpdatedRowSource := System.Data.UpdateRowSource.None;
//
// bdpInsertCommand2
//
Self.bdpInsertCommand2.CommandOptions := nil;
Self.bdpInsertCommand2.CommandText := 'INSERT INTO dbo.Department (ID, Nam' +
'e ) VALUES ( ?, ?)';
Self.bdpInsertCommand2.CommandType := System.Data.CommandType.Text;
Self.bdpInsertCommand2.Connection := Self.BdpConnection1;
Self.bdpInsertCommand2.ParameterCount := (SmallInt(2));
Self.bdpInsertCommand2.Parameters.Add(Borland.Data.Common.BdpParameter.Create('I' +
'D', Borland.Data.Common.BdpType.&String, Borland.Data.Common.BdpType.stFixed,
2, System.Data.ParameterDirection.Input, False, (Byte(0)), (Byte(0)),
0, 'ID', System.Data.DataRowVersion.Current, nil));
Self.bdpInsertCommand2.Parameters.Add(Borland.Data.Common.BdpParameter.Create('N' +
'ame', Borland.Data.Common.BdpType.&String, Borland.Data.Common.BdpType.stFixed,
20, System.Data.ParameterDirection.Input, False, (Byte(0)), (Byte(0)),
0, 'Name', System.Data.DataRowVersion.Current, nil));
Self.bdpInsertCommand2.SchemaName := nil;
Self.bdpInsertCommand2.Transaction := nil;
Self.bdpInsertCommand2.UpdatedRowSource := System.Data.UpdateRowSource.None;
//
// bdpSelectCommand2
//
Self.bdpSelectCommand2.CommandOptions := nil;
Self.bdpSelectCommand2.CommandText := 'SELECT * FROM dbo.Department';
Self.bdpSelectCommand2.CommandType := System.Data.CommandType.Text;
Self.bdpSelectCommand2.Connection := Self.BdpConnection1;
Self.bdpSelectCommand2.ParameterCount := (SmallInt(0));
Self.bdpSelectCommand2.SchemaName := nil;
Self.bdpSelectCommand2.Transaction := nil;
Self.bdpSelectCommand2.UpdatedRowSource := System.Data.UpdateRowSource.None;
//
// bdpUpdateCommand2
//
Self.bdpUpdateCommand2.CommandOptions := nil;
Self.bdpUpdateCommand2.CommandText := 'UPDATE dbo.Department SET ID = ?, N' +
'ame = ? WHERE ID = ? AND Name = ?';
Self.bdpUpdateCommand2.CommandType := System.Data.CommandType.Text;
Self.bdpUpdateCommand2.Connection := Self.BdpConnection1;
Self.bdpUpdateCommand2.ParameterCount := (SmallInt(4));
Self.bdpUpdateCommand2.Parameters.Add(Borland.Data.Common.BdpParameter.Create('I' +
'D', Borland.Data.Common.BdpType.&String, Borland.Data.Common.BdpType.stFixed,
2, System.Data.ParameterDirection.Input, False, (Byte(0)), (Byte(0)),
0, 'ID', System.Data.DataRowVersion.Current, nil));
Self.bdpUpdateCommand2.Parameters.Add(Borland.Data.Common.BdpParameter.Create('N' +
'ame', Borland.Data.Common.BdpType.&String, Borland.Data.Common.BdpType.stFixed,
20, System.Data.ParameterDirection.Input, False, (Byte(0)), (Byte(0)),
0, 'Name', System.Data.DataRowVersion.Current, nil));
Self.bdpUpdateCommand2.Parameters.Add(Borland.Data.Common.BdpParameter.Create('I' +
'DOriginal', Borland.Data.Common.BdpType.&String, Borland.Data.Common.BdpType.stFixed,
2, System.Data.ParameterDirection.Input, False, (Byte(0)), (Byte(0)),
0, 'ID', System.Data.DataRowVersion.Original, nil));
Self.bdpUpdateCommand2.Parameters.Add(Borland.Data.Common.BdpParameter.Create('N' +
'ameOriginal', Borland.Data.Common.BdpType.&String, Borland.Data.Common.BdpType.stFixed,
20, System.Data.ParameterDirection.Input, False, (Byte(0)), (Byte(0)),
0, 'Name', System.Data.DataRowVersion.Original, nil));
Self.bdpUpdateCommand2.SchemaName := nil;
Self.bdpUpdateCommand2.Transaction := nil;
Self.bdpUpdateCommand2.UpdatedRowSource := System.Data.UpdateRowSource.None;
//
// dsAdmin1
//
Self.dsAdmin1.DataSetName := 'dsAdmin';
Self.dsAdmin1.Locale := System.Globalization.CultureInfo.Create('zh-CN');
Self.dsAdmin1.Namespace := 'http://www.changeme.now/dsAdmin.xsd';
//
// btnOK
//
Self.btnOK.DialogResult := System.Windows.Forms.DialogResult.OK;
Self.btnOK.Location := System.Drawing.Point.Create(240, 40);
Self.btnOK.Name := 'btnOK';
Self.btnOK.Size := System.Drawing.Size.Create(64, 23);
Self.btnOK.TabIndex := 10;
Self.btnOK.Text := '确定';
Include(Self.btnOK.Click, Self.btnOK_Click);
//
// btnCancel
//
Self.btnCancel.DialogResult := System.Windows.Forms.DialogResult.Cancel;
Self.btnCancel.Location := System.Drawing.Point.Create(240, 88);
Self.btnCancel.Name := 'btnCancel';
Self.btnCancel.Size := System.Drawing.Size.Create(64, 23);
Self.btnCancel.TabIndex := 11;
Self.btnCancel.Text := '取消';
//
// Label1
//
Self.Label1.Location := System.Drawing.Point.Create(16, 16);
Self.Label1.Name := 'Label1';
Self.Label1.Size := System.Drawing.Size.Create(56, 16);
Self.Label1.TabIndex := 12;
Self.Label1.Text := '系别:';
//
// Label2
//
Self.Label2.Location := System.Drawing.Point.Create(16, 80);
Self.Label2.Name := 'Label2';
Self.Label2.Size := System.Drawing.Size.Create(56, 16);
Self.Label2.TabIndex := 13;
Self.Label2.Text := '班级:';
//
// frmSelClass
//
Self.AutoScaleBaseSize := System.Drawing.Size.Create(6, 14);
Self.ClientSize := System.Drawing.Size.Create(322, 143);
Self.Controls.Add(Self.Label2);
Self.Controls.Add(Self.Label1);
Self.Controls.Add(Self.btnCancel);
Self.Controls.Add(Self.btnOK);
Self.Controls.Add(Self.cbClsName);
Self.Controls.Add(Self.cbDepName);
Self.FormBorderStyle := System.Windows.Forms.FormBorderStyle.FixedSingle;
Self.Name := 'frmSelClass';
Self.StartPosition := System.Windows.Forms.FormStartPosition.CenterParent;
Self.Text := '选择班级';
Include(Self.Load, Self.frmSelClass_Load);
(System.ComponentModel.ISupportInitialize(Self.daCls)).EndInit;
(System.ComponentModel.ISupportInitialize(Self.daDep)).EndInit;
(System.ComponentModel.ISupportInitialize(Self.dsAdmin1)).EndInit;
Self.ResumeLayout(False);
end;
{$ENDREGION}
procedure frmSelClass.Dispose(Disposing: Boolean);
begin
if Disposing then
begin
if Components <> nil then
Components.Dispose();
end;
inherited Dispose(Disposing);
end;
constructor frmSelClass.Create;
begin
inherited Create;
//
// Required for Windows Form Designer support
//
InitializeComponent;
//
// TODO: Add any constructor code after InitializeComponent call
//
end;
//单击“确定”按钮时得到用户选择的班号
procedure frmSelClass.btnOK_Click(sender: System.Object; e: System.EventArgs);
begin
ReturnValue:=cbClsName.SelectedValue.ToString;
end;
procedure frmSelClass.frmSelClass_Load(sender: System.Object; e: System.EventArgs);
begin
AdminSetRelation;
//绑定cbDepName
cbDepName.DataSource:=dsAdmin1;
cbDepName.DisplayMember:='Department.Name';
cbDepName.ValueMember:='Department.ID';
//绑定cbClsName
cbClsName.DataSource:=dsAdmin1;
cbClsName.DisplayMember:='Department.DepartmentClass.Subject';
cbClsName.ValueMember:='Department.DepartmentClass.ID';
end;
//设置本模块中Department表和Class表的关系
procedure frmSelClass.AdminSetRelation;
var
dtDep:DataTable;
dtCls:DataTable;
parentCol:DataColumn;
childCol:DataColumn;
relDepCls:DataRelation;
begin
dtDep:=dsAdmin1.Tables['Department'];
dtCls:=dsAdmin1.Tables['Class'];
daDep.Fill(dtDep);
daCls.Fill(dtCls);
parentCol := dtDep.Columns['ID'];
childCol := dtCls.Columns['DepID'];
relDepCls:=DataRelation.Create('DepartmentClass', parentCol, childCol);
dsAdmin1.Relations.Clear;
dsAdmin1.Relations.Add(relDepCls);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -