📄 ddbview.cs
字号:
//
this.tabRem.Controls.AddRange(new System.Windows.Forms.Control[] {
this.radioRem4,
this.radioRem3,
this.radioRem2,
this.radioRem1,
this.dataGridRem});
this.tabRem.Location = new System.Drawing.Point(4, 24);
this.tabRem.Name = "tabRem";
this.tabRem.Size = new System.Drawing.Size(593, 384);
this.tabRem.TabIndex = 1;
this.tabRem.Text = "远程数据库查询";
//
// radioRem4
//
this.radioRem4.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
this.radioRem4.Location = new System.Drawing.Point(451, 332);
this.radioRem4.Name = "radioRem4";
this.radioRem4.Size = new System.Drawing.Size(121, 29);
this.radioRem4.TabIndex = 7;
this.radioRem4.Text = "开发商信息";
//
// radioRem3
//
this.radioRem3.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
this.radioRem3.Location = new System.Drawing.Point(310, 332);
this.radioRem3.Name = "radioRem3";
this.radioRem3.Size = new System.Drawing.Size(141, 29);
this.radioRem3.TabIndex = 6;
this.radioRem3.Text = "广州楼盘信息";
//
// radioRem2
//
this.radioRem2.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
this.radioRem2.Location = new System.Drawing.Point(170, 332);
this.radioRem2.Name = "radioRem2";
this.radioRem2.Size = new System.Drawing.Size(140, 29);
this.radioRem2.TabIndex = 5;
this.radioRem2.Text = "上海楼盘信息";
//
// radioRem1
//
this.radioRem1.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
this.radioRem1.Checked = true;
this.radioRem1.Location = new System.Drawing.Point(18, 332);
this.radioRem1.Name = "radioRem1";
this.radioRem1.Size = new System.Drawing.Size(142, 29);
this.radioRem1.TabIndex = 4;
this.radioRem1.TabStop = true;
this.radioRem1.Text = "北京楼盘信息";
//
// tabJoin
//
this.tabJoin.Controls.AddRange(new System.Windows.Forms.Control[] {
this.radioJoin2,
this.radioJoin1,
this.dataGridJoin});
this.tabJoin.Location = new System.Drawing.Point(4, 24);
this.tabJoin.Name = "tabJoin";
this.tabJoin.Size = new System.Drawing.Size(593, 384);
this.tabJoin.TabIndex = 2;
this.tabJoin.Text = "联合数据查询";
//
// radioJoin2
//
this.radioJoin2.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
this.radioJoin2.Enabled = false;
this.radioJoin2.Location = new System.Drawing.Point(10, 341);
this.radioJoin2.Name = "radioJoin2";
this.radioJoin2.Size = new System.Drawing.Size(562, 28);
this.radioJoin2.TabIndex = 6;
this.radioJoin2.Text = "在上海查询信誉为100的地产开发商在三地开发的所有地产信息";
//
// radioJoin1
//
this.radioJoin1.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
this.radioJoin1.Checked = true;
this.radioJoin1.Enabled = false;
this.radioJoin1.Location = new System.Drawing.Point(10, 313);
this.radioJoin1.Name = "radioJoin1";
this.radioJoin1.Size = new System.Drawing.Size(562, 28);
this.radioJoin1.TabIndex = 5;
this.radioJoin1.TabStop = true;
this.radioJoin1.Text = "在广州查询上海楼盘每平米大于5000的开发商的信息";
//
// DdbView
//
this.AutoScaleBaseSize = new System.Drawing.Size(8, 18);
this.ClientSize = new System.Drawing.Size(619, 483);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.tabJoinDS,
this.btnCreDB,
this.InitialButton,
this.Createbutton,
this.BtClose,
this.Qbutton});
this.Menu = this.mainMenu1;
this.Name = "DdbView";
this.Text = "远程分布式数据库查询系统";
this.Load += new System.EventHandler(this.DdbView_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridLoc)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataGridRem)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataGridJoin)).EndInit();
this.tabJoinDS.ResumeLayout(false);
this.tabLoc.ResumeLayout(false);
this.tabRem.ResumeLayout(false);
this.tabJoin.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new DdbView());
}
private void OnQuery(object sender, System.EventArgs e)
{
try
{
DataSet ds1;
string temp=((DbServer)LocalDbServer).GetId();
//如果现在查询本地数据库
if(tabJoinDS.SelectedIndex==0)
{
//如果是查询本地楼盘信息
if(radioLoc1.Checked==true)
{
ds1=((DbServer)LocalDbServer).Query(temp,"select * from RealEstate");
dataGridLoc.DataSource=ds1;
dataGridLoc.DataMember="Result";
}
else
{
//这时查询地产商信息,但是只要北京才可以
ds1=((DbServer)LocalDbServer).Query(temp,"select * from Developer");
dataGridLoc.DataSource=ds1;
dataGridLoc.DataMember="Result";
}
}
else if(tabJoinDS.SelectedIndex==1)
{
//这时应查询远程数据库
if(radioRem1.Checked==true)
{
ds1=((DbServer)LocalDbServer).Query("北京","select * from RealEstate");
dataGridRem.DataSource=ds1;
dataGridRem.DataMember="Result";
}
else if(radioRem2.Checked==true)
{
ds1=((DbServer)LocalDbServer).Query("上海","select * from RealEstate");
dataGridRem.DataSource=ds1;
dataGridRem.DataMember="Result";
}
else if(radioRem3.Checked==true)
{
ds1=((DbServer)LocalDbServer).Query("广州","select * from RealEstate");
dataGridRem.DataSource=ds1;
dataGridRem.DataMember="Result";
}
else
{
ds1=((DbServer)LocalDbServer).Query("北京","select * from Developer");
dataGridRem.DataSource=ds1;
dataGridRem.DataMember="Result";
}
}
else
{
//这时连结三地一起查询,但是只能在上海或广州才成
if(radioJoin1.Checked==true)
{
//在广州查询上海楼盘每平米大于5000的开发商的信息
//首先查出上海楼盘价大于5000的楼盘及开发商,并传到北京的机器上
string t1=((DbServer)LocalDbServer).CreateTempTable("上海","北京","select RealName,RealDev from RealEstate where RealPrice>5000");
//然后在北京机器上作连接操作,并把结果传回给广州
string[] ProjectAttributes={t1+".RealName","Developer.RealDev","Developer.DevAdd","Developer.DevTel","Developer.DevFame"};
string JoinString=((DbServer)LocalDbServer).JoinString(t1,"Developer",ProjectAttributes,"RealDev");
string t2=((DbServer)LocalDbServer).CreateTempTable("北京",JoinString);
//显示出结果
ds1=((DbServer)LocalDbServer).Query("广州","select * from "+t2);
dataGridJoin.DataSource=ds1;
dataGridJoin.DataMember="Result";
}
else
{
//在上海查询信誉为100的地产开发商在三地开发的所有地产信息
//首先在北京的机器上查出信誉为100的地产开发商存在北京并传到上海、广州
string t1=((DbServer)LocalDbServer).CreateTempTable("北京","select RealDev from Developer where DevFame=100");
string t2=((DbServer)LocalDbServer).CreateTempTable("北京","北京","select RealDev from Developer where DevFame=100");
string t3=((DbServer)LocalDbServer).CreateTempTable("北京","广州","select RealDev from Developer where DevFame=100");
//然后分别在三地作连接,并把结果传回给上海
string[] ProjectAttributes={"RealEstate.RealDev","RealEstate.RealName","RealEstate.RealAdd","RealEstate.RealPrice"};
string JoinString=((DbServer)LocalDbServer).JoinString(t1,"RealEstate",ProjectAttributes,"RealDev");
string t4=((DbServer)LocalDbServer).CreateTempTable("上海",JoinString);
JoinString=((DbServer)LocalDbServer).JoinString(t2,"RealEstate",ProjectAttributes,"RealDev");
string t5=((DbServer)LocalDbServer).CreateTempTable("北京",JoinString);
JoinString=((DbServer)LocalDbServer).JoinString(t3,"RealEstate",ProjectAttributes,"RealDev");
string t6=((DbServer)LocalDbServer).CreateTempTable("广州",JoinString);
//将三个结果合起来
string t7=((DbServer)LocalDbServer).HMergeTable(t4,t5);
string t8=((DbServer)LocalDbServer).HMergeTable(t6,t7);
//显示出结果
ds1=((DbServer)LocalDbServer).Query("上海","select * from "+t8);
dataGridJoin.DataSource=ds1;
dataGridJoin.DataMember="Result";
}
}
}
///无法获得则捕捉异常,异常情况有可能是:指定的url地址不可达或者指定获得的对象定义不对
catch( NullReferenceException nullExp )
{
MessageBox.Show( "The url for the object is invalid " + nullExp.Message );
}
catch( RemotingException remExp )
{
MessageBox.Show( "The object type is not defined properly, it needs to be derived for a remoting class " + remExp.Message );
}
}
private void OnClose(object sender, System.EventArgs e)
{
Dispose(true);
}
private void Createbutton_Click(object sender, System.EventArgs e)
{
}
private void InitialButton_Click(object sender, System.EventArgs e)
{
try
{
//get the Server Object:
LocalDbServer = ( DbServer )Activator.GetObject(typeof(DbServer),"tcp://localhost:"+port+"/DDB");
//初始化并返回本机所在地(北京、上海、广州)
string id=((DbServer)LocalDbServer).Initial();
// ((DbServer)LocalDbServer).Initial("A");
// string id="北京";
//在标题中显示出本机所在地
DdbView.ActiveForm.Text+="("+id+")";
//根据本机地址,把不能执行的查询禁止掉
if(id=="北京")
{
radioLoc2.Enabled=true;
radioRem1.Enabled=false;
radioRem4.Enabled=false;
}
else if (id=="上海")
{
radioJoin2.Enabled=true;
radioRem2.Enabled=false;
}
else
{
radioJoin1.Enabled=true;
radioRem3.Enabled=false;
}
}
///无法获得则捕捉异常,异常情况有可能是:指定的url地址不可达或者指定获得的对象定义不对
catch( NullReferenceException nullExp )
{
MessageBox.Show( "The url for the object is invalid " + nullExp.Message );
}
catch( RemotingException remExp )
{
MessageBox.Show( "The object type is not defined properly, it needs to be derived for a remoting class " + remExp.Message );
}
}
private string TypeConvert(Type myDataType)
{
string myOleDbType="";
switch(myDataType.FullName)
{
case "System.String":
myOleDbType="text";
break;
case "System.Boolean":
myOleDbType="Bit";
break;
case "System.Double":
case "System.Single":
myOleDbType="Double";
break;
case "System.DateTime":
myOleDbType="Date";
break;
default:
myOleDbType="Integer";
break;
}
return myOleDbType;
}
private void btnCreDB_Click(object sender, System.EventArgs e)
{
}
private void DdbView_Load(object sender, System.EventArgs e)
{
}
private void menuItem1_Click(object sender, System.EventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -