Commit 190f69a8 by 施晓雨

加入读取本地结果的功能

parent 28f1e677
...@@ -47,17 +47,18 @@ ...@@ -47,17 +47,18 @@
this.label5 = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox(); this.groupBox1 = new System.Windows.Forms.GroupBox();
this.panel2 = new System.Windows.Forms.Panel(); this.panel2 = new System.Windows.Forms.Panel();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.groupBox4 = new System.Windows.Forms.GroupBox(); this.groupBox4 = new System.Windows.Forms.GroupBox();
this.dgvResults = new System.Windows.Forms.DataGridView(); this.dgvResults = new System.Windows.Forms.DataGridView();
this.groupBox3 = new System.Windows.Forms.GroupBox();
this.btnSave = new System.Windows.Forms.Button(); this.btnSave = new System.Windows.Forms.Button();
this.btnLoadData = new System.Windows.Forms.Button();
this.panel1.SuspendLayout(); this.panel1.SuspendLayout();
this.groupBox2.SuspendLayout(); this.groupBox2.SuspendLayout();
this.groupBox1.SuspendLayout(); this.groupBox1.SuspendLayout();
this.panel2.SuspendLayout(); this.panel2.SuspendLayout();
this.groupBox3.SuspendLayout();
this.groupBox4.SuspendLayout(); this.groupBox4.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dgvResults)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dgvResults)).BeginInit();
this.groupBox3.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// label1 // label1
...@@ -246,17 +247,6 @@ ...@@ -246,17 +247,6 @@
this.panel2.Size = new System.Drawing.Size(481, 450); this.panel2.Size = new System.Drawing.Size(481, 450);
this.panel2.TabIndex = 4; this.panel2.TabIndex = 4;
// //
// groupBox3
//
this.groupBox3.Controls.Add(this.btnSave);
this.groupBox3.Dock = System.Windows.Forms.DockStyle.Bottom;
this.groupBox3.Location = new System.Drawing.Point(0, 381);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(481, 69);
this.groupBox3.TabIndex = 0;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "操作";
//
// groupBox4 // groupBox4
// //
this.groupBox4.Controls.Add(this.dgvResults); this.groupBox4.Controls.Add(this.dgvResults);
...@@ -278,9 +268,21 @@ ...@@ -278,9 +268,21 @@
this.dgvResults.Size = new System.Drawing.Size(475, 361); this.dgvResults.Size = new System.Drawing.Size(475, 361);
this.dgvResults.TabIndex = 0; this.dgvResults.TabIndex = 0;
// //
// groupBox3
//
this.groupBox3.Controls.Add(this.btnLoadData);
this.groupBox3.Controls.Add(this.btnSave);
this.groupBox3.Dock = System.Windows.Forms.DockStyle.Bottom;
this.groupBox3.Location = new System.Drawing.Point(0, 381);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(481, 69);
this.groupBox3.TabIndex = 0;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "操作";
//
// btnSave // btnSave
// //
this.btnSave.Location = new System.Drawing.Point(15, 34); this.btnSave.Location = new System.Drawing.Point(394, 34);
this.btnSave.Name = "btnSave"; this.btnSave.Name = "btnSave";
this.btnSave.Size = new System.Drawing.Size(75, 23); this.btnSave.Size = new System.Drawing.Size(75, 23);
this.btnSave.TabIndex = 0; this.btnSave.TabIndex = 0;
...@@ -288,6 +290,16 @@ ...@@ -288,6 +290,16 @@
this.btnSave.UseVisualStyleBackColor = true; this.btnSave.UseVisualStyleBackColor = true;
this.btnSave.Click += new System.EventHandler(this.btnSave_Click); this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
// //
// btnLoadData
//
this.btnLoadData.Location = new System.Drawing.Point(18, 34);
this.btnLoadData.Name = "btnLoadData";
this.btnLoadData.Size = new System.Drawing.Size(110, 23);
this.btnLoadData.TabIndex = 1;
this.btnLoadData.Text = "读取本地数据库";
this.btnLoadData.UseVisualStyleBackColor = true;
this.btnLoadData.Click += new System.EventHandler(this.btnLoadData_Click);
//
// FrmMain // FrmMain
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
...@@ -303,9 +315,9 @@ ...@@ -303,9 +315,9 @@
this.groupBox1.ResumeLayout(false); this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout(); this.groupBox1.PerformLayout();
this.panel2.ResumeLayout(false); this.panel2.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.groupBox4.ResumeLayout(false); this.groupBox4.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dgvResults)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.dgvResults)).EndInit();
this.groupBox3.ResumeLayout(false);
this.ResumeLayout(false); this.ResumeLayout(false);
} }
...@@ -335,5 +347,6 @@ ...@@ -335,5 +347,6 @@
private System.Windows.Forms.DataGridView dgvResults; private System.Windows.Forms.DataGridView dgvResults;
private System.Windows.Forms.GroupBox groupBox3; private System.Windows.Forms.GroupBox groupBox3;
private System.Windows.Forms.Button btnSave; private System.Windows.Forms.Button btnSave;
private System.Windows.Forms.Button btnLoadData;
} }
} }
\ No newline at end of file
...@@ -85,13 +85,35 @@ namespace Kivii.Client.Test.Forms ...@@ -85,13 +85,35 @@ namespace Kivii.Client.Test.Forms
private void btnSave_Click(object sender, EventArgs e) private void btnSave_Click(object sender, EventArgs e)
{ {
var results=dgvResults.DataSource as List<Member>; IDbConnection conn = null;
if (results == null||results.Count==0) return; try
var conn = KiviiContext.GetOpenedDbConnection<Member>();
foreach (var member in results)
{ {
if (conn.Exists<Member>(o => o.Kvid == member.Kvid)) continue; var results = dgvResults.DataSource as List<Member>;
conn.Insert(member); if (results == null || results.Count == 0) return;
conn = KiviiContext.GetOpenedDbConnection<Member>();//和服务器上的用法一样,只是连接的数据库在本地的Config文件中指定了
foreach (var member in results)
{
if (conn.Exists<Member>(o => o.Kvid == member.Kvid)) continue;
conn.Insert(member);
}
}
finally//这个方法不管try中有没有catch,都会最后执行,方便释放数据库连接,在客户端模式下,所有的连接不会自己自动释放,需要人为的释放,切记。
{
if (conn != null) conn.Dispose();
}
}
private void btnLoadData_Click(object sender, EventArgs e)
{
IDbConnection conn = null;
try
{
conn = KiviiContext.GetOpenedDbConnection<Member>();//和服务器上的用法一样,只是连接的数据库在本地的Config文件中指定了
dgvResults.DataSource = conn.Select<Member>();
}
finally//这个方法不管try中有没有catch,都会最后执行,方便释放数据库连接,在客户端模式下,所有的连接不会自己自动释放,需要人为的释放,切记。
{
if (conn != null) conn.Dispose();
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment