diff --git a/MainApp/MainApp/AdoClient.cs b/MainApp/MainApp/AdoClient.cs
new file mode 100644
index 0000000..b317dd6
--- /dev/null
+++ b/MainApp/MainApp/AdoClient.cs
@@ -0,0 +1,81 @@
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Data.SqlClient;
+using System.Diagnostics;
+using System.Linq;
+using System.Text;
+
+namespace MainApp
+{
+ class AdoClient
+ {
+ public static AdoClient Instance { get; } = new AdoClient();
+
+ private string connString;
+ private SqlConnection conn;
+
+
+ public bool SetConnection(string server, string database, string uid, string password)
+ {
+ connString = $"server={server}; database={database}; uid={uid}; pwd={password};";
+
+ using (conn = new SqlConnection(connString))
+ {
+ try
+ {
+ conn.Open();
+ conn.Close();
+ }
+ catch (Exception ex)
+ {
+ Debug.WriteLine(ex.Message);
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ public DataSet Query(string sql)
+ {
+ using (conn = new SqlConnection(connString))
+ {
+ conn.Open();
+
+ SqlDataAdapter adapter = new SqlDataAdapter(sql, conn);
+ DataSet dataSet = new DataSet();
+ adapter.Fill(dataSet);
+
+ conn.Close();
+ return dataSet;
+ }
+ }
+
+ public DataSet Query(string sql, int pageStart, int pageSize, string tableName)
+ {
+ using (conn = new SqlConnection(connString))
+ {
+ conn.Open();
+
+ SqlDataAdapter adapter = new SqlDataAdapter(sql, conn);
+ DataSet dataSet = new DataSet();
+ adapter.Fill(dataSet, pageStart, pageSize, tableName);
+
+ conn.Close();
+ return dataSet;
+ }
+ }
+
+ public int NonQuery(string sql)
+ {
+ using (conn = new SqlConnection(connString))
+ {
+ conn.Open();
+
+ SqlCommand cmd = new SqlCommand(sql, conn);
+ return cmd.ExecuteNonQuery();
+ }
+ }
+ }
+}
diff --git a/MainApp/MainApp/Controls/Insert_Select_Control.Designer.cs b/MainApp/MainApp/Controls/Insert_Select_Control.Designer.cs
new file mode 100644
index 0000000..1e1ad47
--- /dev/null
+++ b/MainApp/MainApp/Controls/Insert_Select_Control.Designer.cs
@@ -0,0 +1,62 @@
+
+namespace MainApp.Controls
+{
+ partial class Insert_Select_Control
+ {
+ ///
+ /// 필수 디자이너 변수입니다.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// 사용 중인 모든 리소스를 정리합니다.
+ ///
+ /// 관리되는 리소스를 삭제해야 하면 true이고, 그렇지 않으면 false입니다.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region 구성 요소 디자이너에서 생성한 코드
+
+ ///
+ /// 디자이너 지원에 필요한 메서드입니다.
+ /// 이 메서드의 내용을 코드 편집기로 수정하지 마세요.
+ ///
+ private void InitializeComponent()
+ {
+ this.mainGridView = new System.Windows.Forms.DataGridView();
+ ((System.ComponentModel.ISupportInitialize)(this.mainGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // mainGridView
+ //
+ this.mainGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.mainGridView.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.mainGridView.Location = new System.Drawing.Point(0, 0);
+ this.mainGridView.Name = "mainGridView";
+ this.mainGridView.RowTemplate.Height = 23;
+ this.mainGridView.Size = new System.Drawing.Size(267, 316);
+ this.mainGridView.TabIndex = 1;
+ //
+ // Insert_Select_Control
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.Controls.Add(this.mainGridView);
+ this.Name = "Insert_Select_Control";
+ this.Size = new System.Drawing.Size(267, 316);
+ ((System.ComponentModel.ISupportInitialize)(this.mainGridView)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.DataGridView mainGridView;
+ }
+}
diff --git a/MainApp/MainApp/Controls/Insert_Select_Control.cs b/MainApp/MainApp/Controls/Insert_Select_Control.cs
new file mode 100644
index 0000000..a832e20
--- /dev/null
+++ b/MainApp/MainApp/Controls/Insert_Select_Control.cs
@@ -0,0 +1,63 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Windows.Forms;
+
+namespace MainApp.Controls
+{
+ public partial class Insert_Select_Control : UserControl
+ {
+ private Timer _timer;
+ private int _idx;
+ private Random _rnd;
+
+ public Insert_Select_Control(int startIdx)
+ {
+ InitializeComponent();
+
+ InitInstance(startIdx);
+ }
+
+ private void InitInstance(int startIdx)
+ {
+ if (!AdoClient.Instance.SetConnection("peacecloud.synology.me,21433", "Study", "study", "Study123$"))
+ {
+ MessageBox.Show("Cannot access database.");
+ return;
+ }
+
+ _idx = startIdx;
+ _rnd = new Random();
+ _timer = new Timer();
+ _timer.Interval = 5 * 1000;
+ _timer.Tick += timer_Tick;
+ timer_Tick(null, null);
+ _timer.Start();
+ }
+
+ private void BindTableToGridView(DataTable table)
+ {
+ mainGridView.SuspendLayout();
+ mainGridView.DataSource = table;
+ mainGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
+ mainGridView.ResumeLayout();
+ }
+
+ private void DoWork()
+ {
+ AdoClient.Instance.NonQuery($"INSERT INTO EMPLOYEE (ENO, ENAME, JOB, HIREDATE) VALUES ({_idx++}, 'e{_rnd.Next(1, 1000)}', 'tester', '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}')");
+
+ DataSet dataSet = AdoClient.Instance.Query("SELECT * FROM EMPLOYEE");
+ BindTableToGridView(dataSet.Tables[0]);
+ }
+
+ private void timer_Tick(object sender, EventArgs e)
+ {
+ DoWork();
+ }
+ }
+}
diff --git a/MainApp/MainApp/Controls/Insert_Select_Control.resx b/MainApp/MainApp/Controls/Insert_Select_Control.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/MainApp/MainApp/Controls/Insert_Select_Control.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/MainApp/MainApp/Controls/Paging_Control.Designer.cs b/MainApp/MainApp/Controls/Paging_Control.Designer.cs
new file mode 100644
index 0000000..5c69fff
--- /dev/null
+++ b/MainApp/MainApp/Controls/Paging_Control.Designer.cs
@@ -0,0 +1,142 @@
+
+namespace MainApp.Controls
+{
+ partial class Paging_Control
+ {
+ ///
+ /// 필수 디자이너 변수입니다.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// 사용 중인 모든 리소스를 정리합니다.
+ ///
+ /// 관리되는 리소스를 삭제해야 하면 true이고, 그렇지 않으면 false입니다.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region 구성 요소 디자이너에서 생성한 코드
+
+ ///
+ /// 디자이너 지원에 필요한 메서드입니다.
+ /// 이 메서드의 내용을 코드 편집기로 수정하지 마세요.
+ ///
+ private void InitializeComponent()
+ {
+ this.mainGridView = new System.Windows.Forms.DataGridView();
+ this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
+ this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel();
+ this.prevButton = new System.Windows.Forms.Button();
+ this.nextButton = new System.Windows.Forms.Button();
+ this.pageLabel = new System.Windows.Forms.Label();
+ ((System.ComponentModel.ISupportInitialize)(this.mainGridView)).BeginInit();
+ this.tableLayoutPanel1.SuspendLayout();
+ this.tableLayoutPanel2.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // mainGridView
+ //
+ this.mainGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.mainGridView.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.mainGridView.Location = new System.Drawing.Point(3, 3);
+ this.mainGridView.Name = "mainGridView";
+ this.mainGridView.RowTemplate.Height = 23;
+ this.mainGridView.Size = new System.Drawing.Size(383, 438);
+ this.mainGridView.TabIndex = 2;
+ //
+ // tableLayoutPanel1
+ //
+ this.tableLayoutPanel1.ColumnCount = 1;
+ this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
+ this.tableLayoutPanel1.Controls.Add(this.mainGridView, 0, 0);
+ this.tableLayoutPanel1.Controls.Add(this.tableLayoutPanel2, 0, 1);
+ this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0);
+ this.tableLayoutPanel1.Name = "tableLayoutPanel1";
+ this.tableLayoutPanel1.RowCount = 2;
+ this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
+ this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 35F));
+ this.tableLayoutPanel1.Size = new System.Drawing.Size(389, 479);
+ this.tableLayoutPanel1.TabIndex = 3;
+ //
+ // tableLayoutPanel2
+ //
+ this.tableLayoutPanel2.ColumnCount = 3;
+ this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
+ this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 100F));
+ this.tableLayoutPanel2.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 100F));
+ this.tableLayoutPanel2.Controls.Add(this.prevButton, 1, 0);
+ this.tableLayoutPanel2.Controls.Add(this.nextButton, 2, 0);
+ this.tableLayoutPanel2.Controls.Add(this.pageLabel, 0, 0);
+ this.tableLayoutPanel2.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.tableLayoutPanel2.Location = new System.Drawing.Point(3, 447);
+ this.tableLayoutPanel2.Name = "tableLayoutPanel2";
+ this.tableLayoutPanel2.RowCount = 1;
+ this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
+ this.tableLayoutPanel2.Size = new System.Drawing.Size(383, 29);
+ this.tableLayoutPanel2.TabIndex = 3;
+ //
+ // prevButton
+ //
+ this.prevButton.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.prevButton.Location = new System.Drawing.Point(186, 3);
+ this.prevButton.Name = "prevButton";
+ this.prevButton.Size = new System.Drawing.Size(94, 23);
+ this.prevButton.TabIndex = 0;
+ this.prevButton.Text = "< Prev";
+ this.prevButton.UseVisualStyleBackColor = true;
+ this.prevButton.Click += new System.EventHandler(this.prevButton_Click);
+ //
+ // nextButton
+ //
+ this.nextButton.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.nextButton.Location = new System.Drawing.Point(286, 3);
+ this.nextButton.Name = "nextButton";
+ this.nextButton.Size = new System.Drawing.Size(94, 23);
+ this.nextButton.TabIndex = 0;
+ this.nextButton.Text = "Next >";
+ this.nextButton.UseVisualStyleBackColor = true;
+ this.nextButton.Click += new System.EventHandler(this.nextButton_Click);
+ //
+ // pageLabel
+ //
+ this.pageLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.pageLabel.AutoSize = true;
+ this.pageLabel.Location = new System.Drawing.Point(3, 17);
+ this.pageLabel.Name = "pageLabel";
+ this.pageLabel.Size = new System.Drawing.Size(11, 12);
+ this.pageLabel.TabIndex = 1;
+ this.pageLabel.Text = "0";
+ this.pageLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
+ //
+ // Paging_Control
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.Controls.Add(this.tableLayoutPanel1);
+ this.Name = "Paging_Control";
+ this.Size = new System.Drawing.Size(389, 479);
+ ((System.ComponentModel.ISupportInitialize)(this.mainGridView)).EndInit();
+ this.tableLayoutPanel1.ResumeLayout(false);
+ this.tableLayoutPanel2.ResumeLayout(false);
+ this.tableLayoutPanel2.PerformLayout();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.DataGridView mainGridView;
+ private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
+ private System.Windows.Forms.TableLayoutPanel tableLayoutPanel2;
+ private System.Windows.Forms.Button prevButton;
+ private System.Windows.Forms.Button nextButton;
+ private System.Windows.Forms.Label pageLabel;
+ }
+}
diff --git a/MainApp/MainApp/Controls/Paging_Control.cs b/MainApp/MainApp/Controls/Paging_Control.cs
new file mode 100644
index 0000000..99aac43
--- /dev/null
+++ b/MainApp/MainApp/Controls/Paging_Control.cs
@@ -0,0 +1,71 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Windows.Forms;
+
+namespace MainApp.Controls
+{
+ public partial class Paging_Control : UserControl
+ {
+ const int PAGE_SIZE = 10;
+ int _pageStartIdx = 0;
+ string _tableName = "Employees";
+
+ public Paging_Control()
+ {
+ InitializeComponent();
+ InitInstance();
+ }
+
+ private void InitInstance()
+ {
+ if (!AdoClient.Instance.SetConnection("peacecloud.synology.me,21433", "Study", "study", "Study123$"))
+ {
+ MessageBox.Show("Cannot access database.");
+ return;
+ }
+
+ DoWork(0);
+ }
+
+ private void BindTableToGridView(DataSet dataSet)
+ {
+ mainGridView.SuspendLayout();
+ mainGridView.DataSource = dataSet;
+ mainGridView.DataMember = _tableName;
+ mainGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
+ mainGridView.ResumeLayout();
+ }
+
+ private void DoWork(int pageStart = 0, int pageSize = PAGE_SIZE)
+ {
+ BindTableToGridView(GetData(pageStart, pageSize));
+
+ pageLabel.Text = $"- {_pageStartIdx / PAGE_SIZE + 1} -";
+ }
+
+ private DataSet GetData(int pageStart = 0, int pageSize = PAGE_SIZE)
+ {
+ return AdoClient.Instance.Query("SELECT * FROM EMPLOYEE", pageStart, pageSize, _tableName);
+ }
+
+ private void prevButton_Click(object sender, EventArgs e)
+ {
+ if (_pageStartIdx - PAGE_SIZE < 0)
+ return;
+
+ _pageStartIdx -= PAGE_SIZE;
+ DoWork(_pageStartIdx);
+ }
+
+ private void nextButton_Click(object sender, EventArgs e)
+ {
+ _pageStartIdx += PAGE_SIZE;
+ DoWork(_pageStartIdx);
+ }
+ }
+}
diff --git a/MainApp/MainApp/Controls/Paging_Control.resx b/MainApp/MainApp/Controls/Paging_Control.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/MainApp/MainApp/Controls/Paging_Control.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/MainApp/MainApp/MainApp.csproj b/MainApp/MainApp/MainApp.csproj
index 17c1e36..28d15f4 100644
--- a/MainApp/MainApp/MainApp.csproj
+++ b/MainApp/MainApp/MainApp.csproj
@@ -44,7 +44,20 @@
+
+
+ UserControl
+
+
+ Insert_Select_Control.cs
+
+
+ UserControl
+
+
+ Paging_Control.cs
+
Form
@@ -53,6 +66,12 @@
+
+ Insert_Select_Control.cs
+
+
+ Paging_Control.cs
+
MainForm.cs
diff --git a/MainApp/MainApp/MainForm.Designer.cs b/MainApp/MainApp/MainForm.Designer.cs
index ae9fff1..e5dfafc 100644
--- a/MainApp/MainApp/MainForm.Designer.cs
+++ b/MainApp/MainApp/MainForm.Designer.cs
@@ -29,36 +29,20 @@ namespace MainApp
///
private void InitializeComponent()
{
- this.mainGridView = new System.Windows.Forms.DataGridView();
- ((System.ComponentModel.ISupportInitialize)(this.mainGridView)).BeginInit();
this.SuspendLayout();
//
- // mainGridView
- //
- this.mainGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
- this.mainGridView.Dock = System.Windows.Forms.DockStyle.Fill;
- this.mainGridView.Location = new System.Drawing.Point(0, 0);
- this.mainGridView.Name = "mainGridView";
- this.mainGridView.RowTemplate.Height = 23;
- this.mainGridView.Size = new System.Drawing.Size(521, 500);
- this.mainGridView.TabIndex = 0;
- //
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(521, 500);
- this.Controls.Add(this.mainGridView);
this.Name = "MainForm";
this.Text = "Form1";
- ((System.ComponentModel.ISupportInitialize)(this.mainGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
-
- private System.Windows.Forms.DataGridView mainGridView;
}
}
diff --git a/MainApp/MainApp/MainForm.cs b/MainApp/MainApp/MainForm.cs
index e39e52d..67d3e26 100644
--- a/MainApp/MainApp/MainForm.cs
+++ b/MainApp/MainApp/MainForm.cs
@@ -1,7 +1,9 @@
-using System;
+using MainApp.Controls;
+using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
+using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
@@ -11,6 +13,8 @@ namespace MainApp
{
public partial class MainForm : Form
{
+
+
public MainForm()
{
InitializeComponent();
@@ -24,15 +28,15 @@ namespace MainApp
//Client.Handling();
- BindTableToGridView();
- }
+ //BindTableToGridView(Client.GetSampleTable());
- private void BindTableToGridView()
- {
- mainGridView.SuspendLayout();
- mainGridView.DataSource = Client.GetSampleTable();
- mainGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
- mainGridView.ResumeLayout();
+ //Insert_Select_Control control = new Insert_Select_Control(900);
+ //control.Dock = DockStyle.Fill;
+ //this.Controls.Add(control);
+
+ Paging_Control control = new Paging_Control();
+ control.Dock = DockStyle.Fill;
+ this.Controls.Add(control);
}
}
}