diff --git a/MainApp/MainApp.sln b/MainApp/MainApp.sln new file mode 100644 index 0000000..3238964 --- /dev/null +++ b/MainApp/MainApp.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.32630.194 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MainApp", "MainApp\MainApp.csproj", "{E36379F3-3550-422D-9A73-A4A299E37E9C}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {E36379F3-3550-422D-9A73-A4A299E37E9C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E36379F3-3550-422D-9A73-A4A299E37E9C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E36379F3-3550-422D-9A73-A4A299E37E9C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E36379F3-3550-422D-9A73-A4A299E37E9C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {28805C16-E1C3-448C-A334-AA7F58FFAB84} + EndGlobalSection +EndGlobal diff --git a/MainApp/MainApp/Client.cs b/MainApp/MainApp/Client.cs new file mode 100644 index 0000000..89f32d2 --- /dev/null +++ b/MainApp/MainApp/Client.cs @@ -0,0 +1,167 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Diagnostics; +using System.Linq; +using System.Text; + +namespace MainApp +{ + class Client + { + public static void Create_Insert() + { + DataTable table = new DataTable(); + + // 컬럼 생성 + table.Columns.Add("no", typeof(int)); + table.Columns.Add("name", typeof(string)); + table.Columns.Add("date", typeof(DateTime)); + table.Columns.Add("food", typeof(string)); + + // 데이터 삽입 방법1 + DataRow row = table.NewRow(); + row["no"] = 1; + row["name"] = "Joe"; + row["date"] = DateTime.Now; + row["food"] = "Apple"; + table.Rows.Add(row); + + // 데이터 삽입 방법2 + table.Rows.Add(new object[] { 2, "Jane", DateTime.Now.AddDays(-1), "Tomato" }); + + // 데이터 추출: DataRow 내부에 ojbect 형태로 반환되며, 형변환 필요함 + + // for + for (int i = 0; i < table.Rows.Count; i++) + { + int no = Convert.ToInt32(table.Rows[i]["no"]); + string name = Convert.ToString(table.Rows[i]["name"]); + DateTime date = Convert.ToDateTime(table.Rows[i]["date"]); + string food = Convert.ToString(table.Rows[i]["food"]); + + Debug.WriteLine($"get1: {no} | {name} | {date} | {food}"); + } + + Console.WriteLine(); + + //foreach + foreach (DataRow item in table.Rows) + { + int no = Convert.ToInt32(item["no"]); + string name = Convert.ToString(item["name"]); + DateTime date = Convert.ToDateTime(item["date"]); + string food = Convert.ToString(item["food"]); + + Debug.WriteLine($"get2: {no} | {name} | {date} | {food}"); + } + } + + public static void Handling() + { + DataTable table = new DataTable(); + table.Columns.Add("no", typeof(int)); + table.Columns.Add("name", typeof(string)); + table.Columns.Add("date", typeof(DateTime)); + table.Columns.Add("food", typeof(string)); + + table.Rows.Add(new object[] { 1, "Joe", DateTime.Now, "Apple" }); + table.Rows.Add(new object[] { 2, "Jane", DateTime.Now.AddDays(-1), "Tomato" }); + + // Clone: DataRow를 제외한 스키마 전체를 복사 + DataTable clonedTable = table.Clone(); + Console.WriteLine("Clone"); + PrintTable(clonedTable); + + // ImportRow: DataRow를 가져옴 + DataTable importedTable = table.Clone(); + importedTable.ImportRow(table.Rows[0]); + Console.WriteLine("ImportRow"); + PrintTable(importedTable); + + // Select: 조건에 맞는 Row 선택 + DataRow[] selectedRows = table.Select("no = 1"); + Console.WriteLine("Select"); + PrintDataRows(selectedRows); + + // Copy: 테이블 복사 + DataTable copiedTable = table.Copy(); + Console.WriteLine("Copy"); + PrintTable(copiedTable); + + // Reset: 테이블 초기화 (new 와 동일) + + // Clear: 테이블 내부 DataRow 지움 + + // Compute: 연산 수행 + table.Rows.Add(new object[] { 3, "Jany", DateTime.Now.AddDays(-3), "Steak" }); + table.Rows.Add(new object[] { 4, "Tony", DateTime.Now.AddDays(-2), "Steak" }); + table.Rows.Add(new object[] { 5, "Carl", DateTime.Now.AddDays(-4), "Coke" }); + + object sum = table.Compute("sum(no)", "food = 'Steak'"); + Console.WriteLine($"steak no sum: {sum.ToString()}"); + + object count = table.Compute("count(no)", "food = 'Steak'"); + Console.WriteLine($"steak count: {count.ToString()}"); + + count = table.Compute("count(no)", "no < 5"); + Console.WriteLine($"no < 5 count: {count.ToString()}"); + + object avg = table.Compute("avg(no)", ""); + Console.WriteLine($"no avg: {avg.ToString()}"); + } + + public static DataTable GetSampleTable() + { + DataTable table = new DataTable(); + table.Columns.Add("no", typeof(int)); + table.Columns.Add("name", typeof(string)); + table.Columns.Add("date", typeof(DateTime)); + table.Columns.Add("food", typeof(string)); + + Random rnd = new Random(); + + table.Rows.Add(new object[] { 1, "Joe", DateTime.Now.AddDays(rnd.Next(-10, 1)), "Apple" }); + table.Rows.Add(new object[] { 2, "Jane", DateTime.Now.AddDays(rnd.Next(-10, 1)), "Tomato" }); + table.Rows.Add(new object[] { 3, "Jany", DateTime.Now.AddDays(rnd.Next(-10, 1)), "Steak" }); + table.Rows.Add(new object[] { 4, "Tony", DateTime.Now.AddDays(rnd.Next(-10, 1)), "Steak" }); + table.Rows.Add(new object[] { 5, "Carl", DateTime.Now.AddDays(rnd.Next(-10, 1)), "Coke" }); + + return table; + } + + private static void PrintTable(DataTable table) + { + Console.WriteLine("-------------------------------------"); + + foreach (DataRow item in table.Rows) + { + int no = Convert.ToInt32(item["no"]); + string name = Convert.ToString(item["name"]); + DateTime date = Convert.ToDateTime(item["date"]); + string food = Convert.ToString(item["food"]); + + Debug.WriteLine($"{no} | {name} | {date} | {food}"); + } + + Console.WriteLine("-------------------------------------"); + } + + private static void PrintDataRows(DataRow[] rows) + { + Console.WriteLine("-------------------------------------"); + + foreach (DataRow item in rows) + { + int no = Convert.ToInt32(item["no"]); + string name = Convert.ToString(item["name"]); + DateTime date = Convert.ToDateTime(item["date"]); + string food = Convert.ToString(item["food"]); + + Debug.WriteLine($"{no} | {name} | {date} | {food}"); + } + + Console.WriteLine("-------------------------------------"); + } + } +} diff --git a/MainApp/MainApp/MainApp.csproj b/MainApp/MainApp/MainApp.csproj new file mode 100644 index 0000000..17c1e36 --- /dev/null +++ b/MainApp/MainApp/MainApp.csproj @@ -0,0 +1,79 @@ + + + + + Debug + AnyCPU + {E36379F3-3550-422D-9A73-A4A299E37E9C} + WinExe + MainApp + MainApp + v4.0 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + Form + + + MainForm.cs + + + + + MainForm.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + \ No newline at end of file diff --git a/MainApp/MainApp/MainForm.Designer.cs b/MainApp/MainApp/MainForm.Designer.cs new file mode 100644 index 0000000..ae9fff1 --- /dev/null +++ b/MainApp/MainApp/MainForm.Designer.cs @@ -0,0 +1,64 @@ + +namespace MainApp +{ + partial class MainForm + { + /// + /// 필수 디자이너 변수입니다. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// 사용 중인 모든 리소스를 정리합니다. + /// + /// 관리되는 리소스를 삭제해야 하면 true이고, 그렇지 않으면 false입니다. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form 디자이너에서 생성한 코드 + + /// + /// 디자이너 지원에 필요한 메서드입니다. + /// 이 메서드의 내용을 코드 편집기로 수정하지 마세요. + /// + 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 new file mode 100644 index 0000000..e39e52d --- /dev/null +++ b/MainApp/MainApp/MainForm.cs @@ -0,0 +1,38 @@ +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 +{ + public partial class MainForm : Form + { + public MainForm() + { + InitializeComponent(); + + InitInstance(); + } + + private void InitInstance() + { + //Client.Create_Insert(); + + //Client.Handling(); + + BindTableToGridView(); + } + + private void BindTableToGridView() + { + mainGridView.SuspendLayout(); + mainGridView.DataSource = Client.GetSampleTable(); + mainGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; + mainGridView.ResumeLayout(); + } + } +} diff --git a/MainApp/MainApp/MainForm.resx b/MainApp/MainApp/MainForm.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/MainApp/MainApp/MainForm.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/Program.cs b/MainApp/MainApp/Program.cs new file mode 100644 index 0000000..86bdce9 --- /dev/null +++ b/MainApp/MainApp/Program.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; + +namespace MainApp +{ + static class Program + { + /// + /// 해당 애플리케이션의 주 진입점입니다. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm()); + } + } +} diff --git a/MainApp/MainApp/Properties/AssemblyInfo.cs b/MainApp/MainApp/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..c004d65 --- /dev/null +++ b/MainApp/MainApp/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("MainApp")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("MainApp")] +[assembly: AssemblyCopyright("Copyright © 2022")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("e36379f3-3550-422d-9a73-a4a299e37e9c")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를 +// 기본값으로 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/MainApp/MainApp/Properties/Resources.Designer.cs b/MainApp/MainApp/Properties/Resources.Designer.cs new file mode 100644 index 0000000..c0c1bb0 --- /dev/null +++ b/MainApp/MainApp/Properties/Resources.Designer.cs @@ -0,0 +1,70 @@ +//------------------------------------------------------------------------------ +// +// 이 코드는 도구를 사용하여 생성되었습니다. +// 런타임 버전:4.0.30319.42000 +// +// 파일 내용을 변경하면 잘못된 동작이 발생할 수 있으며, 코드를 다시 생성하면 +// 이러한 변경 내용이 손실됩니다. +// +//------------------------------------------------------------------------------ + + +namespace MainApp.Properties +{ + /// + /// 지역화된 문자열 등을 찾기 위한 강력한 형식의 리소스 클래스입니다. + /// + // 이 클래스는 ResGen 또는 Visual Studio와 같은 도구를 통해 StronglyTypedResourceBuilder + // 클래스에서 자동으로 생성되었습니다. + // 멤버를 추가하거나 제거하려면 .ResX 파일을 편집한 다음 /str 옵션을 사용하여 + // ResGen을 다시 실행하거나 VS 프로젝트를 다시 빌드하십시오. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// 이 클래스에서 사용하는 캐시된 ResourceManager 인스턴스를 반환합니다. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MainApp.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// 이 강력한 형식의 리소스 클래스를 사용하여 모든 리소스 조회에 대해 현재 스레드의 CurrentUICulture 속성을 + /// 재정의합니다. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/MainApp/MainApp/Properties/Resources.resx b/MainApp/MainApp/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/MainApp/MainApp/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/MainApp/MainApp/Properties/Settings.Designer.cs b/MainApp/MainApp/Properties/Settings.Designer.cs new file mode 100644 index 0000000..aeb4f61 --- /dev/null +++ b/MainApp/MainApp/Properties/Settings.Designer.cs @@ -0,0 +1,29 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + + +namespace MainApp.Properties +{ + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/MainApp/MainApp/Properties/Settings.settings b/MainApp/MainApp/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/MainApp/MainApp/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + +