==========================================================================================

C#

==========================================================================================


<C#>


=1

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20150618
{
    
class Student
    {
        
public string name
        {
            get;
            set;
        }
        
public int math
        {
            get;
            set;
        }
        
public int eng
        {
            get;
            set;
        }
        
public int sci
        {
            get;
            set;
        }

    }

    
class Program
    {

        
static void Input2(List<string[]> arrStu)
        {
            Student stu 
= new Student();

            
//Func 델리게이트 활용 (인자 3 마지막 args는 반환,out) : SUM
            Func<intintintint> Sum = (x, y, z) => x + y + z;
            
//Func 델리게이트 활용 (인자 3 마지막 args는 반환,out) : AVG
            Func<intintintdouble> Avg = (x, y, z) => Sum(x, y, z) / 3.0
;

            Console.WriteLine(
"--------------------------------------------------");

            
while (true)
            {
                Console.Write(
"이름입력 .. (입력종료:q) : ");
                string quit 
= Console.ReadLine();
                
if (quit == "q")
                {
                    
break;
                }

                stu.name 
= quit;
                Console.Write(
"수학 : ");
                stu.math 
= int.Parse(Console.ReadLine());

                Console.Write(
"영어 : ");
                stu.eng 
= int.Parse(Console.ReadLine());

                Console.Write(
"과학 : ");
                stu.sci 
= int.Parse(Console.ReadLine());

                Console.Write(
"\n");

                string[] arrStu1 
= new string[6];

                arrStu1[
0= (stu.name);
                arrStu1[
1= ((stu.math).ToString());
                arrStu1[
2= ((stu.eng).ToString());
                arrStu1[
3= ((stu.sci).ToString());

                arrStu1[
4= ((Sum(stu.math, stu.eng, stu.sci)).ToString());
                arrStu1[
5= (string.Format("{0:N2}", Avg(stu.math, stu.eng, stu.sci)));

                arrStu.Add(arrStu1);
            }
            Console.WriteLine(
"--------------------------------------------------");

            var dst 
= from studs in arrStu
                      orderby studs[
4
] descending
                      select studs;


            
//var dst = Rank(arrStu, 4); // VAR TYPE : 지역만 사용 가능 => 인자 전달 불가

            String[] row = { "이름""수학""영어""과학""총점""평균""순위" };
            
int i = 0;
            
int j;

            Console.WriteLine(
"학생 성적 정렬");

            foreach (string k in row)
            {

                Console.Write(
"{0,-4}", k);

                i++;
            }
            Console.WriteLine();

            i 
= 0;
            
int Rank = 1;
            
int TRank = 0;
            
int temp = 0;
            foreach (var p in dst)
            {
                j 
= 0;
                foreach (var r in p)
                {
                    
if (0 == j)
                        Console.Write(
"{0,-4}", r);
                    
else
                        Console.Write("{0,-6}", r);
                    j 
= 1;
                }
                
if (i != 0)
                {
                    
if (TRank > int.Parse(p[4]))
                    {
                        Rank +
= (1 + temp);
                        temp 
= 0;
                    }
                    
else
                    {
                        ++temp;
                    }
                }
                TRank 
= int.Parse(p[4]);
                Console.Write(
"{0,-4}"
, Rank.ToString());
                Console.WriteLine();
                ++i;
            }

            
return;
        }

        
static void Main(string[] args)
        {
            
try
            {
                List
<string[]> arrStu = new List<string[]>();
                Input2(arrStu);
            }
            
catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}


=2

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20150619
{
    
class Student
    {
        
public string name
        {
            get;
            set;
        }
        
public int math
        {
            get;
            set;
        }
        
public int eng
        {
            get;
            set;
        }
        
public int sci
        {
            get;
            set;
        }

    }

    
class Program
    {

        
static void Input2(List<string[]> arrStu)
        {
            Student stu 
= new Student();

            
//Func 델리게이트 활용 (인자 3 마지막 args는 반환,out) : SUM
            Func<intintintint> Sum = (x, y, z) => x + y + z;
            
//Func 델리게이트 활용 (인자 3 마지막 args는 반환,out) : AVG
            Func<intintintdouble> Avg = (x, y, z) => Sum(x, y, z) / 3.0;

            Console.WriteLine(
"--------------------------------------------------");

            
while (true)
            {
                Console.Write(
"이름입력 .. (입력종료:q) : ");
                string quit 
= Console.ReadLine();
                
if (quit == "q")
                {
                    
break;
                }

                stu.name 
= quit;
                Console.Write(
"수학 : ");
                stu.math 
= int.Parse(Console.ReadLine());

                Console.Write(
"영어 : ");
                stu.eng 
= int.Parse(Console.ReadLine());

                Console.Write(
"과학 : ");
                stu.sci 
= int.Parse(Console.ReadLine());

                Console.Write(
"\n");

                string[] arrStu1 
= new string[7];

                arrStu1[
0= (stu.name);
                arrStu1[
1= ((stu.math).ToString());
                arrStu1[
2= ((stu.eng).ToString());
                arrStu1[
3= ((stu.sci).ToString());

                arrStu1[
4= ((Sum(stu.math, stu.eng, stu.sci)).ToString());
                arrStu1[
5= (string.Format("{0:N2}", Avg(stu.math, stu.eng, stu.sci)));

                arrStu.Add(arrStu1);
            }
            Console.WriteLine(
"--------------------------------------------------");

           
 var dst =   from studs in arrStu
                        orderby studs[
4] descending
                        select 
new 
                        { 
                            Name 
= studs[0],
                            Math 
= studs[1],
                            Eng 
= studs[2],
                            Sci 
= studs[3],
                            Sum 
= studs[4],
                            Avg 
= studs[5],
                            Rank 
= ((from o in arrStu
                            where 
int.Parse(o[4]) > int.Parse(studs[4])
                            select o).Count() + 
1).ToString()
                        };


            String[] row 
= { "이름""수학""영어""과학""총점""평균""순위" };
            
int i = 0;
            
int j;

            Console.WriteLine(
"학생 성적 정렬");

            foreach (string k in row)
            {
                Console.Write(
"{0,-4}", k);
                i++;
            }
            Console.WriteLine();

           
 foreach (var p in dst)
            {
                Console.WriteLine(
"{0,-4}{1,-6}{2,-6}{3,-6}{4,-6}{5,-6}{6,-6}"

                 p.Name, p.Math, p.Eng, p.Sci, p.Sum, p.Avg, p.Rank);
            }


            
return;
        }

        
static void Main(string[] args)
        {
            
try
            {
                List
<string[]> arrStu = new List<string[]>();
                Input2(arrStu);
            }
            
catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}


=3

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _20150619_2
{
    
class Student
    {
        
public string name
        {
            get;
            set;
        }
        
public int math
        {
            get;
            set;
        }
        
public int eng
        {
            get;
            set;
        }
        
public int sci
        {
            get;
            set;
        }

    }

    
class Program
    {

        
static void Input2(List<string[]> arrStu)
        {
            Student stu 
= new Student();

            
//Func 델리게이트 활용 (인자 3 마지막 args는 반환,out) : SUM
            Func<intintintint> Sum = (x, y, z) => (x + y + z);
            
//Func 델리게이트 활용 (인자 3 마지막 args는 반환,out) : AVG
            Func<intintint, string> Avg = (x, y, z) => string.Format("{0:N2}",(Sum(x, y, z)/ 3.0
));

            Console.WriteLine(
"--------------------------------------------------");

            
while (true)
            {
                Console.Write(
"이름입력 .. (입력종료:q) : ");
                string quit 
= Console.ReadLine();
                
if (quit == "q")
                {
                    
break;
                }

                stu.name 
= quit;
                Console.Write(
"수학 : ");
                stu.math 
= int.Parse(Console.ReadLine());

                Console.Write(
"영어 : ");
                stu.eng 
= int.Parse(Console.ReadLine());

                Console.Write(
"과학 : ");
                stu.sci 
= int.Parse(Console.ReadLine());

                Console.Write(
"\n");

                string[] arrStu1 
= new string[4];

                arrStu1[
0= (stu.name);
                arrStu1[
1= ((stu.math).ToString());
                arrStu1[
2= ((stu.eng).ToString());
                arrStu1[
3= ((stu.sci).ToString());

                
//arrStu1[4] = ((Sum(stu.math, stu.eng, stu.sci)).ToString());
                //arrStu1[5] =
 (string.Format("{0:N2}", Avg(stu.math, stu.eng, stu.sci)));

                arrStu.Add(arrStu1);
            }
            Console.WriteLine(
"--------------------------------------------------");

            var dst = from studs in arrStu
                      orderby Sum(
int.Parse(studs[1]), int.Parse(studs[2]), int.Parse(studs[3])) descending                    
                      select 
new List<string>
                      {
                          studs[
0],
                          studs[
1],
                          studs[
2],
                          studs[
3],
                          Sum(
int.Parse(studs[1]), int.Parse(studs[2]), int.Parse(studs[3])).ToString(),
                          Avg(
int.Parse(studs[1]), int.Parse(studs[2]), int.Parse(studs[3])),
                          ((from o in arrStu where (Sum(
int.Parse(o[1]), int.Parse(o[2]), int.Parse(o[3]))) > 

                                                       (Sum(int.Parse(studs[1]), int.Parse(studs[2]), int.Parse(studs[3])))
                                                        select o).Count() + 
1).ToString()
                                                        };


            String[] row 
= { "이름""수학""영어""과학""총점""평균""순위" };
            
int i = 0;
            
int j;

            Console.WriteLine(
"학생 성적 정렬");

            foreach (string k in row)
            {
                Console.Write(
"{0,-4}", k);
                i++;
            }
            Console.WriteLine();


            foreach (var p in dst)
            {
                j 
= 0;
                foreach (var r in p)
                {
                    
if (0 == j)
                        Console.Write(
"{0,-4}", r);
                    
else
                        Console.Write("{0,-6}", r);
                    j 
= 1
;
                }
                Console.WriteLine();
            }

            
return;
        }

        
static void Main(string[] args)
        {
            
try
            {
                List
<string[]> arrStu = new List<string[]>();
                Input2(arrStu);
            }
            
catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}

 





=ADO(단순 연결) <=> ADO.NET : 기본 데이터처리 모든 것 담고 있음 ( LINQ...)(윈도우/콘솔/모바일/..)






=다른 SQL간 소통 가능 : XML


=




=연결




=





=




=DATA SET

:DATA TABLE



=인명부 실습


 (수정본)ADONET&엑세스 연동.pdf



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;

namespace WindowsFormsApplication1
{
    
public partial class Form1 : Form
    {
        
public Form1()
        {
            InitializeComponent();
        }
        // MSoffice 2003 데이터베이스 연결 문자열
        private string StrSQL = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\..\Human.mdb";
        
//;Mode=ReadWrite"; 
        // MSoffice 2007 / 2010 / 2013 데이터베이스 연결 문자열
        //private string StrSQL = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=..\..\..\..\Human.accdb

        ;Mode=ReadWrite"; 

        private string Human_Name, Human_Phone; // 선택된 lvList 컨트롤 행의 값 저장

        private void Form1_Load(object sender, EventArgs e)
        {
            var Conn 
= new OleDbConnection(StrSQL);
            Conn.Open();
            
if (Conn != null)
            { MessageBox.Show(
"connect"); }
            lvList_OleDb_View();
        }
        
        
private void btnSave_Click(object sender, EventArgs e)
        {
            
if (Control_Check() == true)
            {
                var Conn 
= new OleDbConnection(StrSQL);
                Conn.Open();
                string Sql 
= "INSERT INTO HumanInfo(M_Name, M_Age, M_Phone) VALUES('";
                Sql +
= this.txtName.Text + "','" + this.txtAge.Text + "', '" +
                
this.txtCellPhone.Text + "')";
                var Comm 
= new OleDbCommand(Sql, Conn);
                
int i = Comm.ExecuteNonQuery();
                Conn.Close();
                
if (i == 1)
                {
                    MessageBox.Show(
"정상적으로 데이터가 저장되었습니다.""알림",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                    lvList_OleDb_View();
                    Control_Clear();
                }
                
else
                {
                    MessageBox.Show(
"정상적으로 데이터가 저장되지 않았습니다.""에러",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }

        
private Boolean Control_Check()
        {
            
if (this.txtName.Text == ""// 이름 입력란 공백 체크
            {
                MessageBox.Show(
"이름을 입력하세요!!""에러", MessageBoxButtons.OK,
                MessageBoxIcon.Error);
                
this.txtName.Focus();
                
return false;
            }
            
else if (this.txtAge.Text == ""// 나이 입력란 공백 체크
            {
                MessageBox.Show(
"나이를 입력하세요!!""에러", MessageBoxButtons.OK,
                MessageBoxIcon.Error);
                
this.txtAge.Focus();
                
return false;
            }
            
else if (this.txtCellPhone.Text == ""// 전화번호 입력란 공백 체크
            {
                MessageBox.Show(
"전화번호를 입력하세요!!""에러", MessageBoxButtons.OK,
                MessageBoxIcon.Error);
                
this.txtCellPhone.Focus();
                
return false;
            }
            
else
            {
                
return true;
            }
        }

        
private void Control_Clear() // 입력란 공백 처리
        {
            
this.txtName.Clear();
            
this.txtAge.Clear();
            
this.txtCellPhone.Clear();
        }

        
private void lvList_OleDb_View()
        {
            
this.lvList.Items.Clear();
            var Conn 
= new OleDbConnection(StrSQL);
            Conn.Open();
            var Comm 
= new OleDbCommand("SELECT * FROM HumanInfo", Conn);
            var myRead 
= Comm.ExecuteReader();
            
while (myRead.Read())
            {
                var strArray 
= new String[] { myRead["M_Name"].ToString(),
                myRead[
"M_Age"].ToString(), myRead["M_Phone"].ToString() };
                var lvt 
= new ListViewItem(strArray);
                
this.lvList.Items.Add(lvt);
            }
            myRead.Close();
            Conn.Close();
        }

        
private void btnModify_Click(object sender, EventArgs e)
        {
            
if (Control_Check() == true)
            {
                var Conn 
= new OleDbConnection(StrSQL);
                Conn.Open();
                string Sql 
= "UPDATE HumanInfo SET M_Name ='" +
                
this.txtName.Text + "', M_Age=" +
                Convert.ToInt32(
this.txtAge.Text);
                Sql +
= ", M_Phone='" + this.txtCellPhone.Text + "'";
                Sql +
= "WHERE M_Name ='" + this.Human_Name + "' AND M_Phone ='" +
                
this.Human_Phone + "'";
                var Comm 
= new OleDbCommand(Sql, Conn);
                
int i = Comm.ExecuteNonQuery();
                Conn.Close();
                
if (i == 1)
                {
                    MessageBox.Show(
"정상적으로 데이터가 수정되었습니다.""알림",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                    lvList_DataSet_View();
                    Control_Clear();
                }
                
else
                {
                    MessageBox.Show(
"정상적으로 데이터가 수정되지 않았습니다.""에러",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }

        
private void lvList_DataSet_View()
        {
            
this.lvList.Items.Clear();
            var Conn 
= new OleDbConnection(StrSQL);
            Conn.Open();
            var OleAdapter 
= new OleDbDataAdapter("SELECT * FROM HumanInfo", Conn);
            DataSet ds 
= new DataSet();
            DataTable dt 
= ds.Tables.Add("dsTable");
            OleAdapter.Fill(ds, 
"dsTable");
            IEnumerable
<DataRow> query =
            from HumanInfo in dt.AsEnumerable()
            select HumanInfo;
            foreach (DataRow HumData in query)
            {
                var strArray 
= new String[] { HumData.Field<string>("M_Name"),
                    HumData.Field
<int>("M_Age").ToString(), HumData.Field<string>("M_Phone") };
                
this.lvList.Items.Add(new ListViewItem(strArray));
            }
            Conn.Close();
        }
        
private void btnDel_Click(object sender, EventArgs e)
        {
            DialogResult dlr 
= MessageBox.Show("선택한 데이터를 삭제할까요?""알림",
            MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            
switch (dlr)
            {
                
case DialogResult.Yes:
                    var Conn 
= new OleDbConnection(StrSQL);
                    Conn.Open();
                    string Sql 
= "DELETE FROM HumanInfo WHERE M_Name='" +
                    
this.Human_Name + "' AND M_Phone ='" + this.Human_Phone + "'";
                    var Comm 
= new OleDbCommand(Sql, Conn);
                    
int i = Comm.ExecuteNonQuery();
                    Conn.Close();
                    
if (i == 1)
                    {
                        MessageBox.Show(
"정상적으로 데이터가 삭제되었습니다.""알림",
                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                        lvList_DataSetRamda_View();
                        Control_Clear();
                    }
                    
else
                    {
                        MessageBox.Show(
"정상적으로 데이터가 삭제되지 않았습니다.""에러",
                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    
break;
                
case DialogResult.No:
                    
break;
            }
        }
        
private void lvList_DataSetRamda_View()
        {
            
this.lvList.Items.Clear();
            var Conn 
= new OleDbConnection(StrSQL);
            Conn.Open();
            var OleAdapter 
= new OleDbDataAdapter("SELECT * FROM HumanInfo", Conn);
            DataSet ds 
= new DataSet();
            DataTable dt 
= ds.Tables.Add("dsTable");
            OleAdapter.Fill(ds, 
"dsTable");
            var query 
= dt.AsEnumerable().
            Select(HumanInfo 
=> new
            {
                Name 
= HumanInfo.Field<string>("M_Name"),
                Age 
= HumanInfo.Field<int>("M_Age").ToString(),
                Phone 
= HumanInfo.Field<string>("M_Phone")
            });
            foreach (var HumData in query)
            {
                var strArray 
= new String[] { HumData.Name, HumData.Age, HumData.Phone };
                
this.lvList.Items.Add(new ListViewItem(strArray));
            }
            Conn.Close();
        }

        
private void lvList_Click(object sender, EventArgs e) //선택한 Items의 각 컬럼값을 입력 컨트롤에 대입
        {
            
this.txtName.Text = this.lvList.SelectedItems[0].SubItems[0].Text;
            
this.txtAge.Text = this.lvList.SelectedItems[0].SubItems[1].Text;
            
this.txtCellPhone.Text = this.lvList.SelectedItems[0].SubItems[2].Text;
            Human_Name 
= this.lvList.SelectedItems[0].SubItems[0].Text;
            Human_Phone 
= this.lvList.SelectedItems[0].SubItems[2].Text;
        }
        
    }
}




// LOAD /  SAVE / MODIFY / DELETE 가능







=DB접속으로 변경

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
//using System.Data.Sql;
using System.Data.SqlClient; 
// DB 연결

namespace WindowsFormsApplication1
{
    
public partial class Form1 : Form
    {
        
public Form1()
        {
            InitializeComponent();
        }
       
 //DB연결
        private string StrSQL = "server=211.179.124.57;database=test2;uid=sa;pwd=admin";

        
// MSoffice 2003 데이터베이스 연결 문자열
        //private string StrSQL = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\..\Human.mdb";
        //;Mode=ReadWrite"; 
        // MSoffice 2007 / 2010 / 2013 데이터베이스 연결 문자열
        //private string StrSQL = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=..\..\..\..\Human.accdb;Mode=ReadWrite"; 
        
        
private string Human_Name, Human_Phone; // 선택된 lvList 컨트롤 행의 값 저장

        private void Form1_Load(object sender, EventArgs e)
        {
            var Conn = new SqlConnection(StrSQL);
            Conn.Open();
            
if (Conn != null)
            { MessageBox.Show(
"connect"); }
            lvList_Sql_View();
        }
        
        
private void btnSave_Click(object sender, EventArgs e)
        {
            
if (Control_Check() == true)
            {
                var Conn = new SqlConnection(StrSQL);
                Conn.Open();
                string Sql 
= "INSERT INTO HumanInfo(M_Name, M_Age, M_Phone) VALUES('";
                Sql +
= this.txtName.Text + "','" + this.txtAge.Text + "', '" +
                
this.txtCellPhone.Text + "')";
                var Comm = new SqlCommand(Sql, Conn);
                
int i = Comm.ExecuteNonQuery();
                Conn.Close();
                
if (i == 1)
                {
                    MessageBox.Show(
"정상적으로 데이터가 저장되었습니다.""알림",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                    lvList_Sql_View();
                    Control_Clear();
                }
                
else
                {
                    MessageBox.Show(
"정상적으로 데이터가 저장되지 않았습니다.""에러",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }

        
private Boolean Control_Check()
        {
            
if (this.txtName.Text == ""// 이름 입력란 공백 체크
            {
                MessageBox.Show(
"이름을 입력하세요!!""에러", MessageBoxButtons.OK,
                MessageBoxIcon.Error);
                
this.txtName.Focus();
                
return false;
            }
            
else if (this.txtAge.Text == ""// 나이 입력란 공백 체크
            {
                MessageBox.Show(
"나이를 입력하세요!!""에러", MessageBoxButtons.OK,
                MessageBoxIcon.Error);
                
this.txtAge.Focus();
                
return false;
            }
            
else if (this.txtCellPhone.Text == ""// 전화번호 입력란 공백 체크
            {
                MessageBox.Show(
"전화번호를 입력하세요!!""에러", MessageBoxButtons.OK,
                MessageBoxIcon.Error);
                
this.txtCellPhone.Focus();
                
return false;
            }
            
else
            {
                
return true;
            }
        }

        
private void Control_Clear() // 입력란 공백 처리
        {
            
this.txtName.Clear();
            
this.txtAge.Clear();
            
this.txtCellPhone.Clear();
        }

        
private void lvList_Sql_View()
        {
            
this.lvList.Items.Clear();
            var Conn = new SqlConnection(StrSQL);
            Conn.Open();
            var Comm = new SqlCommand("SELECT * FROM HumanInfo", Conn);
            var myRead 
= Comm.ExecuteReader();
            
while (myRead.Read())
            {
                var strArray 
= new String[] { myRead["M_Name"].ToString(),
                myRead[
"M_Age"].ToString(), myRead["M_Phone"].ToString() };
                var lvt 
= new ListViewItem(strArray);
                
this.lvList.Items.Add(lvt);
            }
            myRead.Close();
            Conn.Close();
        }

        
private void btnModify_Click(object sender, EventArgs e)
        {
            
if (Control_Check() == true)
            {
                var Conn = new SqlConnection(StrSQL);
                Conn.Open();
                string Sql 
= "UPDATE HumanInfo SET M_Name ='" +
                
this.txtName.Text + "', M_Age=" +
                Convert.ToInt32(
this.txtAge.Text);
                Sql +
= ", M_Phone='" + this.txtCellPhone.Text + "'";
                Sql +
= "WHERE M_Name ='" + this.Human_Name + "' AND M_Phone ='" +
                
this.Human_Phone + "'";
                var Comm = new SqlCommand(Sql, Conn);
                
int i = Comm.ExecuteNonQuery();
                Conn.Close();
                
if (i == 1)
                {
                    MessageBox.Show(
"정상적으로 데이터가 수정되었습니다.""알림",
                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                    lvList_DataSet_View();
                    Control_Clear();
                }
                
else
                {
                    MessageBox.Show(
"정상적으로 데이터가 수정되지 않았습니다.""에러",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }

        
private void lvList_DataSet_View()
        {
            
this.lvList.Items.Clear();
            var Conn = new SqlConnection(StrSQL);
            Conn.Open();
            var OleAdapter = new SqlDataAdapter("SELECT * FROM HumanInfo", Conn);
            DataSet ds 
= new DataSet();
            DataTable dt 
= ds.Tables.Add("dsTable");
            OleAdapter.Fill(ds, 
"dsTable");
            IEnumerable
<DataRow> query =
            from HumanInfo in dt.AsEnumerable()
            select HumanInfo;
            foreach (DataRow HumData in query)
            {
                var strArray 
= new String[] { HumData.Field<string>("M_Name"),
                    HumData.Field
<int>("M_Age").ToString(), HumData.Field<string>("M_Phone") };
                
this.lvList.Items.Add(new ListViewItem(strArray));
            }
            Conn.Close();
        }
        
private void btnDel_Click(object sender, EventArgs e)
        {
            DialogResult dlr 
= MessageBox.Show("선택한 데이터를 삭제할까요?""알림",
            MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            
switch (dlr)
            {
                
case DialogResult.Yes:
                    var Conn = new SqlConnection(StrSQL);
                    Conn.Open();
                    string Sql 
= "DELETE FROM HumanInfo WHERE M_Name='" +
                    
this.Human_Name + "' AND M_Phone ='" + this.Human_Phone + "'";
                    var Comm = new SqlCommand(Sql, Conn);
                    
int i = Comm.ExecuteNonQuery();
                    Conn.Close();
                    
if (i == 1)
                    {
                        MessageBox.Show(
"정상적으로 데이터가 삭제되었습니다.""알림",
                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                        lvList_DataSetRamda_View();
                        Control_Clear();
                    }
                    
else
                    {
                        MessageBox.Show(
"정상적으로 데이터가 삭제되지 않았습니다.""에러",
                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    
break;
                
case DialogResult.No:
                    
break;
            }
        }
        
private void lvList_DataSetRamda_View()
        {
            
this.lvList.Items.Clear();
            var Conn = new SqlConnection(StrSQL);
            Conn.Open();
            var OleAdapter = new SqlDataAdapter("SELECT * FROM HumanInfo", Conn);
            DataSet ds 
= new DataSet();
            DataTable dt 
= ds.Tables.Add("dsTable");
            OleAdapter.Fill(ds, 
"dsTable");
            var query 
= dt.AsEnumerable().
            Select(HumanInfo 
=> new
            {
                Name 
= HumanInfo.Field<string>("M_Name"),
                Age 
= HumanInfo.Field<int>("M_Age").ToString(),
                Phone 
= HumanInfo.Field<string>("M_Phone")
            });
            foreach (var HumData in query)
            {
                var strArray 
= new String[] { HumData.Name, HumData.Age, HumData.Phone };
                
this.lvList.Items.Add(new ListViewItem(strArray));
            }
            Conn.Close();
        }

        
private void lvList_Click(object sender, EventArgs e) //선택한 Items의 각 컬럼값을 입력 컨트롤에 대입
        {
            
this.txtName.Text = this.lvList.SelectedItems[0].SubItems[0].Text;
            
this.txtAge.Text = this.lvList.SelectedItems[0].SubItems[1].Text;
            
this.txtCellPhone.Text = this.lvList.SelectedItems[0].SubItems[2].Text;
            Human_Name 
= this.lvList.SelectedItems[0].SubItems[0].Text;
            Human_Phone 
= this.lvList.SelectedItems[0].SubItems[2].Text;
        }
        
    }
}







==========================================================================================

C++

==========================================================================================



<C++>



==> 에러수정(재귀함수로 무한 반복)

#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
using namespace std;

class Str
{
  
friend ostream & operator <<(ostream &c, const Str & S);
  
friend const Str operator +(const char *ptr, Str &s);
  
friend bool operator ==(const char *ptr, Str & s);
  
friend bool operator !=(const char *ptr, Str & s);
  
friend bool operator >(const char *ptr, Str & s);
  
friend bool operator <(const char *ptr, Str & s);
  
friend bool operator >=(const char *ptr, Str & s);
  
friend bool operator <=(const char *ptr, Str & s);
protected:
  
char * buf;
  
int size;
public:
  Str();
  Str(
const char *ptr);
  Str(
const Str &Other);
  
explicit Str(int num);
  
virtual ~Str();

  
int length() const
  {
    
return strlen(buf);
  }
  Str 
&operator =(const Str &Other);
  Str 
&operator +=(Str &Other);
  Str 
&operator +=(const char *ptr);
  
char &operator [](int idx)
  {
    
return buf[idx];
  }
  
const char &operator[](int idx) const
  {
    
return buf[idx];
  }
  
operator const char *()
  {
    
return (const char *)buf;
  }
  
operator int()
  {
    
return atoi(buf);
  }
  
const Str operator +(Str &Other) const;
  
const Str operator +(const char *ptr) const
  {
    Str t(ptr);
    
return *this + t;
    
//return *this + Str(ptr); // 재귀호출 에러
  }
  
bool operator ==(Str &Other)
  {
    
return strcmp(buf, Other.buf) == 0;
  }
  
bool operator ==(const char *ptr)
  {
    
return strcmp(buf, ptr) == 0;
  }
  
bool operator !=(Str &Other)
  {
    
return strcmp(buf, Other.buf) != 0;
  }
  
bool operator !=(const char *ptr)
  {
    
return strcmp(buf, ptr) != 0;
  }
  
bool operator >(Str &Other)
  {
    
return strcmp(buf, Other.buf)>0;
  }
  
bool operator >(const char *ptr)
  {
    
return strcmp(buf, ptr)>0;
  }
  
bool operator <(Str &Other)
  {
    
return strcmp(buf, Other.buf)<0;
  }
  
bool operator <(const char *ptr)
  {
    
return strcmp(buf, ptr)<0;
  }
  
bool operator >=(Str &Other)
  {
    
return strcmp(buf, Other.buf) >= 0;
  }
  
bool operator >=(const char *ptr)
  {
    
return strcmp(buf, ptr) >= 0;
  }
  
bool operator <=(Str &Other)
  {
    
return strcmp(buf, Other.buf) <= 0;
  }
  
bool operator <=(const char *ptr)
  {
    
return strcmp(buf, ptr) <= 0;
  }
  
void Format(const char *fmt, ...);
};
//디폴트 생성자
Str::Str()
{
  size 
= 1;
  buf 
= new char[size];
  buf[
0= 0;
}
//문자열로부터 생성하기
Str::Str(const char *ptr)
{
  size 
= strlen(ptr) + 1;
  buf 
= new char[size];
  strcpy(buf, ptr);
}
//복사생성자
Str::Str(const Str &Other)
{
  size 
= Other.length() + 1;
  buf 
= new char[size];
  strcpy(buf, Other.buf);
}
//정수형 변환 생성자
Str::Str(int num)
{
  
char temp[128= { "100" };

  
//itoa(num, temp, 10);
  size = strlen(temp) + 1;
  buf 
= new char[size];
  strcpy(buf, temp);
}

//파괴자
Str::~Str()
{
  
delete[] buf;
}
//대입 연산자
Str &Str::operator =(const Str &Other)
{
  
if (this != &Other)
  {
    size 
= Other.length() + 1;
    
delete[] buf;
    buf 
= new char[size];
    strcpy(buf, Other.buf);
  }
  
return *this;
}
//복합 연결 연산자
Str &Str::operator +=(Str &Other)
{
  
char * old;
  old 
= buf;
  size +
= Other.length();
  buf 
= new char[size];
  strcpy(buf, old);
  strcat(buf, Other.buf);
  
delete[] old;
  
return *this;
}

Str 
&Str::operator +=(const char *ptr)
{
  Str t(ptr);
  
return *this += t;
  
//return *this += Str(ptr); // 재귀호출 에러
}
//연결 연산자
const Str Str::operator +(Str &Other)const
{
  Str T;

  
delete[] T.buf;
  T.size 
= length() + Other.length() + 1;
  T.buf 
= new char[T.size];
  strcpy(T.buf, buf);
  strcat(T.buf, (
const char *)Other);
  
return T;
}


//출력 연산자
ostream &operator <<(ostream &c, const Str & S)
{
  c 
<< S.buf;
  
return c;
}
//더하기 및 관계 연산자
const Str operator +(const char *ptr, Str & s)
{
  
return Str(ptr) + s;
}
bool operator ==(const char *ptr, Str & s)
{
  
return strcmp(ptr, s.buf) == 0;
}
bool operator !=(const char *ptr, Str & s)
{
  
return strcmp(ptr, s.buf) != 0;
}
bool operator >(const char *ptr, Str & s)
{
  
return strcmp(ptr, s.buf) > 0;
}
bool operator <(const char *ptr, Str & s)
{
  
return strcmp(ptr, s.buf) < 0;
}
bool operator >=(const char *ptr, Str & s)
{
  
return strcmp(ptr, s.buf) >= 0;
}
bool operator <=(const char *ptr, Str & s)
{
  
return strcmp(ptr, s.buf) <= 0;
}
//서식 조립 함수
void Str::Format(const char *fmt, ...)
{
  
char temp[1024];
  va_list marker;

  va_start(marker, fmt);
  vsprintf(temp, fmt, marker);
  *
this = Str(temp);
}

int main()
{
  Str s 
= "125";
  
int k;
  k 
= (int)s + 123;
  cout 
<< k << endl;

  Str s1(
"문자열");   //문자열로 생성자
  Str s2(s1);         //복사 생성자
  Str s3;             //디폴트 생성자
  s3 = s1;              //대입 연산자



  //출력 연산자
  cout << "s1=" << s1 << ",s2=" << s2 << ",s3=" << s3 << endl;
  cout 
<< "길이=" << s1 << endl;

  
//정수형 변환 생성자와 변환 연산자
  Str s4(1234);
  cout 
<< "s4=" << s4 << endl;
  
int num = int(s4) + 1;
  cout 
<< "num=" << num << endl;
  
//문자열 연결 테스트
  Str s5 = "First";
  Str s6 
= "Second";
  cout 
<< s5 + s6 << endl;
  cout 
<< s6 + "Third" << endl;
  cout 
<< "Zero" + s5 << endl;
  cout 
<< "s1은 "+s1+"이고 s5는 " + s5 + "이다." << endl;
  s5 +
= s6;
  cout 
<< "s5와 s6을 연결하면 " << s5 << "이다." << endl;
  s5+
="Concatination";
  cout 
<< "s5에 문자열을 덧붙이면 " << s5 << "이다." << endl;
  
//비교연산자테스트
  if (s1 == s2)
  {
    cout 
<< "두 문자열은 같다." << endl;
  }
  
else
  {
    cout 
<< "두 문자열은 다르다." << endl;
  }

  
//char * 형과의 연산테스트
  Str s7;
  s7 
= "상수 문자열";
  cout 
<< s7 << endl;
  
char str[128];
  strcpy(str, s7);
  cout 
<< str << endl;
  
//첨자 연산자 테스트
  Str s8("Index");
  cout 
<< "s8[2]=" << s8[2<< endl;
  s8[
2= 'k';
  cout 
<< "s8[2]=" << s8[2<< endl;
  
//서식 조립 테스트
  Str sf;
  
int i = 9876;
  
double d = 1.234567;
  sf.Format(
"서식 조립 가능하다. 정수=%d, 실수=%2f", i, d);
  cout 
<< sf << endl;
  
return 0;
}







= STL : (Standard Templete Lib)


  int length() const
  {
    
return strlen(buf);
  }


//디폴트 생성자
Str::Str()
{
  size 
= 1;
  buf 
= new char[size];
  buf[
0= 0;
}

 

string.h에 클래스 string


#include <string.h>
#include <iostream>

using namespace std;

int main()
{
    
string obj("123456");
    cout 
<< obj<<endl;
    cout 
<< obj.length() << endl;
    string obj1(
"789");
    obj 
= obj+obj1;
    cout 
<< obj << endl;
    cout 
<< obj.length() << endl;
    
return 0;
}





=20150615

=gotoxy

#include <curses.h>
#include <iostream>
using namespace std;
void gotoxy(int x, int y)
{
    printf(
"\33[%d;%df]",y,x);
    fflush(stdout);
    
return;
}
int main()
{

     initscr()
    wmove(stdscr, 
3,1);
    cout
<<"@@@@\n";

     
     gotoxy(
3,1);

     refresh();

     sleep(10);

     endwin();
    
return 0;
}


=

#include <stdio.h>
#include <curses.h>
#include <stdlib.h>
#include <unistd.h>

#include <string.h>
//이동 삽입 특성 등의 실습 예

int main()
{
 
const char witch_one[]=" First Witch  ";
 
const char witch_Two[]=" Second Witch ";
 
const char * scan_ptr;
 
int i,j;
 
 initscr();
 
 move(
5,15);
 
//=========문자의 특성을 켠다 
 attron(A_BOLD);//  <===  <===
 printw("%s","Macbeth");
 
//=========문자의 특성을 off한다.
 attroff(A_BOLD);//  <===  <===
 refresh();
 sleep(
1);

 move(
8,15);
 attron(A_STANDOUT);
 printw(
"%s","Thunder and Lightning");
 attroff(A_STANDOUT);
 refresh();
 sleep(
1);

 move(
10,10);
 printw(
"%s","When shall we three meet again");
 move(
11,23);
 printw(
"%s","In thunder, lightning, or in rain ?");
 move(
13,10);
 printw(
"%s","When the hurlyburly's done,");
 move(
14,23);
 printw(
"%s","When the batle's lost and won.");
 refresh();
 sleep(
1);

 attron(A_DIM);
 scan_ptr 
= witch_one + strlen(witch_one) -1;
 
while(scan_ptr != witch_one)
 {
  move(
10,10);
  insch(*scan_ptr--);
// <== <== 배우의 이름을 한문자 단위로 삽입 
  
 }
 scan_ptr 
= witch_Two + strlen(witch_Two)-1;
 
while(scan_ptr != witch_Two)
 {
  move(
13,10);
  insch(*scan_ptr--);
// <== <== 배우의 이름을 한문자 단위로 삽입 
  
 }
 attroff(A_DIM);
 refresh();
 sleep(
1);

//커서를 하위 우측으로 이동시킨다.

 move(LINES -1 ,COLS -1);
 refresh();
 sleep(
1);
 
 endwin();

 
return 0;



=가상함수 테이블



'2015 스마트 콘트롤러 > 업무일지' 카테고리의 다른 글

20150623  (0) 2015.06.23
20150622  (0) 2015.06.22
20150618  (0) 2015.06.18
20150617  (0) 2015.06.17
20150616  (0) 2015.06.16
Posted by ahj333
,