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

C#

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


<C#>



=MSSQL


http://itsmart333.tistory.com/attachment/cfile21.uf@25726F4A55937E1E20B15B.pdf



<MSSQL_WORK>


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.IO; //파일 클래스 사용
using System.Data.SqlClient;

namespace MSSQL_WORK
{
    
public partial class Form1 : Form
    {
        FileInfo f 
= null;// 파일 정보 검색
        //서버연결 문자열
        string Constr = "server=localhost;uid=sa;pwd=1234;database=mook";
        
public Form1()
        {
            InitializeComponent();
        }

        
private void btnFile_Click(object sender, EventArgs e)
        {
            
if(this.ofdFile.ShowDialog() == DialogResult.OK)
            {
                
try
                {
                    
this.txtFile.Text = this.ofdFile.FileName;
                    f 
= new FileInfo(this.ofdFile.FileName);
                    
this.lbldisName.Text = f.Name;
                    
this.lbldisSize.Text = f.Length.ToString() + " byte";
                    
this.lbldisDate.Text = f.LastWriteTime.ToString();
                }
                
catch
                {
                    
return;
                }
            }
        }

        
private void btnUpload_Click(object sender, EventArgs e)
        {
            var fs 
= f.OpenRead();
            var bytebuffer 
= new byte[fs.Length];
            fs.Read(bytebuffer, 
0, Convert.ToInt32(fs.Length));
            var conn 
= new SqlConnection(Constr);
            conn.Open();
            var cmd 
= conn.CreateCommand();
            cmd.CommandType 
= CommandType.Text;
            var Sql 
= "update Table_File set M_File=@M_File, M_FileName='" +
                
//this.ofdFile.FileName + "' where M_Num=1";
                this.lbldisName.Text + "' where M_Num=1";

            cmd.CommandText 
= Sql;
            cmd.Parameters.Add(
new SqlParameter("@M_File", System.Data.SqlDbType.Image)).Value = bytebuffer;
            var iResult 
= cmd.ExecuteNonQuery();
            conn.Close();
            fs.Close();
            
if((iResult > 0&& (DataSave() > 0))
            {
                MessageBox.Show(
"저장이 정상적으로 되었습니다.","알림",
                MessageBoxButtons.OK, MessageBoxIcon.Information);
                
this.Close();
            }
            
else
            {
                MessageBox.Show(
"저장이 되지 않았습니다.","에러",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        
private int DataSave()
        {
            var Conn 
= new SqlConnection(Constr);
            Conn.Open();
            var strSQL 
= "update Table_Update set M_Date=M_Date+1";
            var myCom 
= new SqlCommand(strSQL, Conn);
            var i 
= myCom.ExecuteNonQuery();
            Conn.Close();
            
return i;
        }


    }
}


<mook_AutoMain>


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.IO; // 파일 클래스 사용
using System.Data.SqlClient; //SqlConnection 클래스 사용
using System.Diagnostics; //Process 클래스 사용
namespace mook_AutoMain
{
    
public partial class Form1 : Form
    {
        
public Form1()
        {
            InitializeComponent();
        }

        
private void Timer_Tick(object sender, EventArgs e)
        {
            
this.lbldisUpdate.Text = DateTime.Now.ToString();
            var srt 
= File.OpenText("setup.txt");
            var str 
= srt.ReadLine();
            
if(Convert.ToInt32(str) == Convert.ToInt32(DataCheck()))
            {
                srt.Close();
                
return;
            }
            
else if(Convert.ToInt32(str) < Convert.ToInt32(DataCheck()))
            {
                srt.Close();
                
this.Timer.Enabled = false;
                var dlr 
= MessageBox.Show("최신 프로그램을 다운로드 받으시겠습니까?",
                    
"알림", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                
if(dlr == System.Windows.Forms.DialogResult.Yes)
                {
                    var myproces 
= new Process();
                    myproces.StartInfo.FileName 
= "mook_AutoUpdate.exe";
                    myproces.Start();
                    Application.Exit();
                }
                
else
                {
                    
this.Timer.Enabled = true;
                    
return;
                }
            }
            
else
            {
                srt.Close();
                MessageBox.Show(
"잘못된 프로그램입니다.""알림",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                
this.Close();
            }
        }

        
private string DataCheck()
        {
            var Constr 
= "server=localhost;uid=sa;pwd=1234;database=mook";
            var Conn 
= new SqlConnection(Constr);
            Conn.Open();
            var Comm 
= new SqlCommand("Select * from Table_Update", Conn);
            var myRead 
= Comm.ExecuteReader();
            
if(myRead.Read())
            {
                var str 
= myRead["M_Date"].ToString();
                myRead.Close();
                Conn.Close();
                
return str;
            }
            
else
            {
                myRead.Close();
                Conn.Close();
                
return "1";
            }
        }

        
private void cbTime_SelectedIndexChanged(object sender, EventArgs e)
        {
            string[] temp 
= cbTime.Text.Split(new Char[] { ' ' });
            Timer.Interval 
= Convert.ToInt32(temp[0]) * 1000;
        }

        
private void Form1_Load(object sender, EventArgs e)
        {
            cbTime.SelectedIndex 
= 0;
            Timer.Interval 
= 1000;
        }
    }
}


<mook_AutoUpdate>


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.SqlClient;
using System.IO;
using System.Threading;
using System.Diagnostics;

namespace mook_AutoUpdate
{
    
public partial class Form1 : Form
    {
        
private Thread myDownload;
        
private string Constr = "server=localhost;uid=sa;pwd=1234;database=mook";
        
// This delegate enables asynchronous calls for setting
        // the text property on a TextBox control.
        delegate void SetProgCallback1( int totalLen, int Val);
        delegate 
void SetProgCallback2( int Val);
        delegate 
void SetProgCallback3();

        
public Form1()
        {
            InitializeComponent();
        }

        
private void Exit()
        {
            
// InvokeRequired required compares the thread ID of the
            // calling thread to the thread ID of the creating thread.
            // If these threads are different, it returns true.
            if (this.InvokeRequired)
            {
                SetProgCallback3 d 
= new SetProgCallback3(Exit);
                
this.Invoke(d, new object[] {});
            }
            
else
            {
                
this
.Close();
            }
        }

        
private void DataDownLoading()
        {
            byte[] bytes 
= DatabaseDownload(1);
            var fs 
= new FileStream("mook_AutoMain.exe", FileMode.Create);
            fs.Write(bytes, 
0, bytes.Length);
            fs.Close();
            Exit();
            
//this.Close();
        }

        
private void SetMax(int totalLen, int Val)
        {
            
// InvokeRequired required compares the thread ID of the
            // calling thread to the thread ID of the creating thread.
            // If these threads are different, it returns true.
            if (this.ProgressBar.InvokeRequired)
            {
                SetProgCallback1 d 
= new SetProgCallback1(SetMax);
                
this.Invoke(d, new object[] { totalLen, Val });
            }
            
else
            {
                
this.ProgressBar.Maximum = totalLen;
                
this.ProgressBar.Value =
 Val;
            }
        }


        
private void SetVal(int Val)
        {
            
// InvokeRequired required compares the thread ID of the
            // calling thread to the thread ID of the creating thread.
            // If these threads are different, it returns true.
            if (this.ProgressBar.InvokeRequired)
            {
                SetProgCallback2 d 
= new SetProgCallback2(SetVal);
                
this.Invoke(d, new object[] { Val });
            }
            
else
            {
                
this.ProgressBar.Value =
 Val;
            }
        }


        
private byte[] DatabaseDownload(int M_Num)
        {
            
using(var Conn = new SqlConnection(Constr))
            {
                Conn.Open();
                var sql 
= "select DataLength(M_File) From Table_File where M_NUM=@M_NUM";
                SqlParameter param 
= new SqlParameter("@M_NUM", SqlDbType.Int);
                param.Value 
= M_Num;
                SqlCommand cmd 
= new SqlCommand(sql,Conn);
                cmd.Parameters.Add(param);
                
int totalLength = Convert.ToInt32(cmd.ExecuteScalar());
                
//this.ProgressBar.Maximum = totalLength;
                //this.ProgressBar.Value = 0;
                this.SetMax(totalLength, 0
);
                sql
= "select M_File From Table_File where M_Num=@M_Num";
                param 
= new SqlParameter("@M_Num", SqlDbType.Int);
                param.Value 
= M_Num;
                cmd 
= new SqlCommand(sql,Conn);
                cmd.Parameters.Add(param);
                SqlDataReader reader 
= cmd.ExecuteReader(CommandBehavior.SequentialAccess);
                reader.Read();
                
long remainder = totalLength;
                
int bufferSize = 2048;
                
if(totalLength < bufferSize)
                    totalLength 
= bufferSize;
                byte[] buf 
= new byte[(int)totalLength];
                
int startIndex = 0;
                
long retval = reader.GetBytes(0,startIndex, buf, 0, bufferSize);
                remainder -
= retval;
                
while(remainder >0)
                {
                    startIndex +
= bufferSize;
                    
if(remainder < bufferSize)
                        bufferSize 
= (int)remainder;
                    retval 
= reader.GetBytes(0, startIndex, buf, startIndex, bufferSize);
                    remainder -
=retval;
                    
//this.ProgressBar.Value = startIndex;
                    this
.SetVal(startIndex);
                    Thread.Sleep(
100);
                }
                
//this.ProgressBar.Value = totalLength;
                this
.SetVal(totalLength);
                reader.Close();
                
return buf;

            }
        }

        
private void Form1_Load(object sender, EventArgs e)
        {
            
try
            {
                var tProcess 
= Process.GetProcessesByName("mook_AutoMain");
                
if (tProcess.Length == 1)
                    tProcess[
0].Kill();
            }
            
catch { }
            var fs 
= new FileStream("setup.txt", FileMode.Create);
            var sw 
= new StreamWriter(fs);
            sw.WriteLine(DataCheck());
            sw.Close();
            myDownload 
= new Thread(DataDownLoading);
            myDownload.Start();
        }

        
private string DataCheck()
        {
            var Conn 
= new SqlConnection(Constr);
            Conn.Open();
            var Comm 
= new SqlCommand("select * from Table_Update", Conn);
            var myRead 
= Comm.ExecuteReader();
            
if(myRead.Read())
            {
                string Update 
= myRead["M_Date"].ToString();
                myRead.Close();
                Conn.Close();
                
return Update;
            }
            
else
            {
                myRead.Close();
                Conn.Close();
                
return "1";
            }
        }

        
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            
if(this!=null)
            {
                myDownload.Abort();
                var myProcess 
= new Process();
                myProcess.StartInfo.FileName 
= "mook_AutoMain.exe";
                myProcess.Start();
            }
        }
    }
}



=테스트






=초기값 변경










=버전 1 파일 업로드

















=> 테스트를 위해 M_Date => 1로 셋팅




=자동업데이트 버전 1 실행




=자동업데이트 버전 2파일을 서버에 업로드










=자동업데이트 버전 1에서 업데이트 감지











=자동업데이트 버전 2자동 실행






=학생클래스를 

1. 데이타테이블로 => 그리드에 뿌리기

2. 링크 => 그리드에 뿌리기


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

20150706  (0) 2015.07.07
20150703  (0) 2015.07.03
20150630  (0) 2015.06.30
2015029  (0) 2015.06.30
20150626  (0) 2015.06.27
Posted by ahj333
,

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

C#

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


<C#>



=MSSQL





=DB 생성




=테이블 생성




=










=






=MDF => 복구 가능

-.LDF => 각종 설정















=데이터베이스 다이어그램








=visual studio















=학생클래스를 

1. 데이타테이블로 => 그리드에 뿌리기

2. 링크 => 그리드에 뿌리기


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

C++

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

<C++>



=컨테이터 ( STL )


<TStack.h>

#ifndef __TSTACK_H__
#define __TSTACK_H__
#include <iostream>
#include <stdlib.h>
#include <iostream>
#include <string.h>
#include <ctype.h>

#include <math.h>


using namespace std;

template<typename T>
class TStack
{
    
protected:
        T *Stack;
        
int Size;
        
int Top;
    
public:
        TStack(
int aSize)
        {
            Size
=aSize;
            Stack
=(T *)malloc(Size*sizeof(T));
            Top 
= -1;
        }
        
virtual ~TStack()
        {
            free(Stack);
        }
        
virtual bool Push(T data)
        {
            
if(Top < Size-1)
            {
                Top++;
                Stack[Top]
=data;
                
return true;
            }
            
else
            {
                
return false;
            }
        }
        
virtual T Pop()
        {
            
return Stack[Top--];
        }
        
virtual int GetTop()
        {
            
return Top;
        }

        
virtual T GetValue(int n)
        {
            
return Stack[n];
        }
};

#endif //__TSTACK_H__


<TextCalcTemplate.cc>


#include "TStack.h"

using namespace std;

int GetPriority(int op)
{
    
switch(op)
    {
        
case '(':
            
return 0;
        
case '+':
        
case '-':
            
return 1;
        
case '*':
        
case '/':
            
return 2;
        
case '^':
            
return 3;
    }
    
return 100;
}

void MakePostfix(char * Post, const char * Mid)
{
    
const char *m=Mid;
    
char *p = Post;
    
char c;
    TStack
<char> cS(256);

    
while(*m)
    {
        
//숫자 - 그대로 출력하고 뒤에 공백 하나를 출력한다.
        if(isdigit(*m))
        {
            
while(isdigit(*m) || *m=='.')
                *p++ 
= *m++;
            *p++ 
= ' ';

        }
        
else if(strchr("^*/+-",*m))
        {
            
while(cS.GetTop()!=-1 && GetPriority(cS.GetValue(cS.GetTop())) >= GetPriority(*m))
            {
                *p++ 
= cS.Pop();

            }
            cS.Push(*m++);

        }
        
else if(*m=='(')
        {
            cS.Push(*m++);
        }
        
else if(*m==')')
        {
            
for(;;)
            {
                c
=cS.Pop();
                
if(c=='(')
                    
break;
                *p++ 
= c;
            }
            m++;

        }
        
else
        {
            m++;
        }
    }
    
//스택에 남은 연산자들 모두 꺼낸다.
    while(cS.GetTop() != -1)
    {
        *p++ 
= cS.Pop();
    }
    *p
=0;
}

double CalcPostfix(const char * Post)
{
    
const char *p=Post;
    
double num;
    
double left, right;
    TStack
<double> dS(256);

    
while(*p)
    {
        
//숫자는 스택에 넣는다.
        if(isdigit(*p))
        {
            num
=atof(p);
            dS.Push(num);
            
for(;isdigit(*p) || *p=='.';p++)
            {;}

        }
        
else
        {
            
//연산자는 스택에서 두수를 꺼내 연산하고 다시 푸시한다.
            if(strchr("^*/+-",*p))
            {
                right 
= dS.Pop();
                left
=dS.Pop();
                
switch(*p)
                {
                    
case '+':
                        dS.Push(left+right);
                        
break;
                    
case '-':
                        dS.Push(left-right);
                        
break;
                    
case '*':
                        dS.Push(left*right);
                        
break;
                    
case '/':
                        
if(right ==0.0)
                        {
                            dS.Push(
0.0);
                        }
                        
else
                        {
                            dS.Push(left/right);
                        }
                        
break;
                    
case '^':
                        dS.Push(pow(left, right));
                        
break;
                                
                }
            }
            
// 연산 후 또는 연산자가 아닌경우 다음 문자로
            p++;
        }
    }
    
if(dS.GetTop() != -1)
    {
        num 
= dS.Pop();
    }
    
else
    {
        num 
= 0.0;
    }
    
return num;
}

double CalcExp(const char * exp, bool * bError=NULL)
{
    
char Post[256];
    
const char *p;
    
int count;

    
if(bError !=NULL)
    {
        
for(p=exp,count=0;*p;p++)
        {
            
if(*p=='('
                count ++;
            
if(*p==')')
                count--;
        }
        *bError 
= (count !=0);
    }
    MakePostfix(Post,exp);
    
return CalcPostfix(Post);
}

int main()
{
    
char exp[256];
    
bool bError;
    
double result;

    
char *p=(char *)strchr("^*/+-",NULL);
    strcpy(exp,
"2.2+3.5*4.1");
    cout 
<< exp << "= " <<  CalcExp(exp) << endl;
    strcpy(exp,
"(34+93)*2-(43/2)");
    cout 
<< exp << "= " <<  CalcExp(exp) << endl;
    strcpy(exp,
"1+(2+3)/4*5+2^10+(6/7)*8");
    cout 
<< exp << "= " <<  CalcExp(exp) << endl;

    
for(;;)
    {
        cout 
<< "수식을 입력하세요(끝낼 대 0) : \n";
        cin 
>> exp;
        
if(strcmp(exp,"0"== 0
            
break;
        result 
= CalcExp(exp,&bError);
        
if(bError)
        {
            cout 
<< "수식의 괄호짝이 틀립니다.\n";
        }
        
else
        {
            cout 
<< exp << "= " <<  result << endl;
        }
    }
    
return 0;
}









=템플릿 중첩

TStack<PosValue<int> > 

: 반드시  >>  => >'공백‘>




=예외처리






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

20150703  (0) 2015.07.03
20150701  (0) 2015.07.02
2015029  (0) 2015.06.30
20150626  (0) 2015.06.27
20150625  (0) 2015.06.26
Posted by ahj333
,

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

C#

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

<C#>



=인명부


- MySQL 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 MySql.Data.MySqlClient;


namespace DBTEST
{
    
    
public partial class Form1 : Form
    {
        
public string strCon = "server=localhost;user id=root;password=root;database=test";

        
//public List<int> id;
        private MySqlConnection conn = null;
        
private MySqlDataAdapter adapter = null;
        
private DataTable tbl = null;  // 멤버로 선언
        private DataSet ds = null;  // 멤버로 선언
        //private DataRow search = null;
        EnumerableRowCollection<DataRow> search = null;

        
public Form1()
        {
            InitializeComponent();
        }

        
private void Form1_Load(object sender, EventArgs e)
        {
            
// TODO: This line of code loads data into the 'dataset.myfriend' table. You can move, or remove it, as needed.
            this.myfriendTableAdapter.Fill(this.dataset.myfriend);

            conn 
= new MySqlConnection(strCon);
            adapter 
= new MySqlDataAdapter("select * from myfriend order by id", conn);
            ds 
= new DataSet();
            tbl 
= new
 DataTable();
            ds.Tables.Add(tbl);
            adapter.Fill(tbl);

            conn.Close();

            DataColumn[] keys 
= new DataColumn[1];
            keys[
0= tbl.Columns[0];
            tbl.Columns[
0].AutoIncrement = true;
            
if(0 != tbl.Rows.Count)
            tbl.Columns[
0].AutoIncrementSeed = Convert.ToInt16(this.tbl.Rows[tbl.Rows.Count-1][0]) + 1;
            tbl.PrimaryKey 
=
 keys;
        }

        
private void Control_Clear() // 입력란 공백 처리
        {
            
this.txt_Name.Clear();
            
this.txt_Email.Clear();
            
this.txt_Tel.Clear();
            
this.txt_Mobile.Clear();
            
this.txt_Addr.Clear();
            
this.txt_Com.Clear();
            
this.txt_Depart.Clear();
            
this.txt_Intro.Clear();
        }
        
private void Search()
        {
            
this.lst_Search.Items.Clear();
            search 
= from t in tbl.AsEnumerable()
                     where t.Field
<string>("name"== this.txt_Search.Text
                     select t;

            
if (0 == search.Count<DataRow>())
                
return
;

            foreach (DataRow r in search)
            {
                lst_Search.Items.Add(r[
1]);
            }
            lst_Search.SelectedIndex 
= 0;
            lst_Search.SetSelected(lst_Search.SelectedIndex, 
true);
            show_info();
        }


        
private void btn_Search_Click(object sender, EventArgs e)
        {
            
try
            {
                Search();

                
this.SelectNextControl((Control)sender, truetruetruetrue);
                
/*
                var result 
=
                    from t in tbl.AsEnumerable()
                    where t.Field
<string>("name") == this.txt_Search.Text
                    select t;

                search 
= new DataRow();
                foreach (DataRow r in result)
                {
                    search 
= r;
                }

                id 
= new List<int>();

                foreach (DataRow r in result)
                {
                    id.Add(Convert.ToInt32(r[0]));
                    lst_Search.Items.Add(r[1]);
                }          
                */
            }
            
catch
            {

            }
        }

        
private void show_info()
        {
            
try
            {
                Control_Clear();

                DataRow r 
= search.ElementAt<DataRow>(lst_Search.SelectedIndex);

                
this.txt_Name.Text = r[1].ToString();
                
this.txt_Email.Text = r[2].ToString();
                
this.txt_Tel.Text = r[3].ToString();
                
this.txt_Mobile.Text = r[4].ToString();
                
this.txt_Addr.Text = r[5].ToString();
                
this.txt_Com.Text = r[6].ToString();
                
this.txt_Depart.Text = r[7].ToString();
                
this.txt_Intro.Text = r[8].ToString();

                
/*
                var result 
= from t in tbl.AsEnumerable()
                             where t.Field
<int>("id") == id[lst_Search.SelectedIndex]
                             select t;
  
                foreach (DataRow r in result)
                {
                    this.txt_Name.Text 
= r[1].ToString();
                    this.txt_Email.Text 
= r[2].ToString();
                    this.txt_Tel.Text 
= r[3].ToString();
                    this.txt_Mobile.Text 
= r[4].ToString();
                    this.txt_Addr.Text 
= r[5].ToString();
                    this.txt_Com.Text 
= r[6].ToString();
                    this.txt_Depart.Text 
= r[7].ToString();
                    this.txt_Intro.Text 
= r[8].ToString();
                }
                */
            }
            
catch
            {
                MessageBox.Show(
"ERROR");
            }

        }

        
private void btn_Pre_Click(object sender, EventArgs e)
        {
            
try
            {             
                
if (0 == lst_Search.SelectedIndex)
                    
return;
                
else
                    lst_Search.SetSelected(--lst_Search.SelectedIndex, true);

                show_info();
            }
            
catch
            {
                MessageBox.Show(
"ERROR");
            }
        }

        
private void btn_Nxt_Click(object sender, EventArgs e)
        {
            
try
            {
                
if (lst_Search.Items.Count - 1 == lst_Search.SelectedIndex)
                    
return;
                
else
                    lst_Search.SetSelected(++lst_Search.SelectedIndex, true);

                show_info();

            }
            
catch
            {
                MessageBox.Show(
"ERROR");
            }
        }
      
        
private void btn_Add_Click(object sender, EventArgs e)
        {
            
try
            {
                
if(this.txt_Name.Text.Trim() == "" && this.txt_Email.Text.Trim() == "" &&
                    this.txt_Tel.Text.Trim() == "" && this.txt_Mobile.Text.Trim() == "" &&
                    this.txt_Addr.Text.Trim() == "" && this.txt_Com.Text.Trim() == "" &&
                    this.txt_Depart.Text.Trim() == "" && this.txt_Intro.Text.Trim() == "")
                    
return;

                DataRow row 
= tbl.NewRow();
                row[
"name"= this.txt_Name.Text.Trim();
                row[
"email"= this.txt_Email.Text.Trim();
                row[
"phone"= this.txt_Tel.Text.Trim();
                row[
"mobile"= this.txt_Mobile.Text.Trim();
                row[
"address"= this.txt_Addr.Text.Trim();
                row[
"company"= this.txt_Com.Text.Trim();
                row[
"department"= this.txt_Depart.Text.Trim();
                row[
"introduce"= this
.txt_Intro.Text.Trim();
                tbl.Rows.Add(row);


                
/*
                MySqlCommand command 
= new MySqlCommand(
                    "INSERT INTO myfriend (name, email, phone, mobile, address, company, department, introduce) " +
                    "VALUES ('" +
                    this.txt_Name.Text.Trim() + "','" + this.txt_Email.Text.Trim() + "','" + this.txt_Tel.Text.Trim() + "','" +
                    this.txt_Mobile.Text.Trim() + "','" + this.txt_Addr.Text.Trim() + "','" + this.txt_Com.Text.Trim() + "','" +
                    this.txt_Depart.Text.Trim() + "','" + this.txt_Intro.Text.Trim() + "')",conn);
                    //adapter.InsertCommand 
= command;

                */

                conn = new MySqlConnection(strCon);
                conn.Open();
                adapter 
= new MySqlDataAdapter("select * from myfriend", conn);

                MySqlCommandBuilder build 
= new MySqlCommandBuilder(adapter);
                adapter.InsertCommand 
=
 build.GetInsertCommand();
                
//DataTable dataChanges = tbl.GetChanges();
                //ds.AcceptChanges();
                //adapter.Update(ds, "TBL");
                adapter.Update(tbl);
                
//adapter.Update(dataChanges);
                tbl.Rows.Remove(tbl.Rows[tbl.Rows.Count-1]);
                adapter.Fill(tbl.Rows.Count, tbl.Rows.Count, tbl);
                build.Dispose();

                conn.Close();

                
//lst_Search.Items.Clear();
                Search();
                
this.myfriendTableAdapter.Fill(this.dataset.myfriend);
                Control_Clear();
                MessageBox.Show(
"ADDED");
            }
            
catch
            {
                MessageBox.Show(
"ERROR");
            }
        }

        
private void btn_Mod_Click(object sender, EventArgs e)
        {
            
try
            {
                
if (0 == search.Count<DataRow>())
                    
return;
                tbl.BeginLoadData();
                
//tbl.LoadDataRow(new object[] {  id[lst_Search.SelectedIndex],
                tbl.LoadDataRow(new object[] {  search.ElementAt<DataRow>(lst_Search.SelectedIndex)[0],
                                            
this.txt_Name.Text.Trim(),
                                            
this.txt_Email.Text.Trim(),
                                            
this.txt_Tel.Text.Trim(),
                                            
this.txt_Mobile.Text.Trim(),
                                            
this.txt_Addr.Text.Trim(),
                                            
this.txt_Com.Text.Trim(),
                                            
this.txt_Depart.Text.Trim(),
                                            
this.txt_Intro.Text.Trim()},
                                            
false
                                        );
                tbl.EndLoadData();

                conn 
= new MySqlConnection(strCon);
                conn.Open();
                adapter 
= new MySqlDataAdapter("select * from myfriend", conn);
                
                MySqlCommandBuilder build 
= new MySqlCommandBuilder(adapter);
                adapter.UpdateCommand 
=
 build.GetUpdateCommand();
                
//DataTable dataChanges = tbl.GetChanges();
                adapter.Update(tbl);
                build.Dispose();

                conn.Close();

                Search();
                
this.myfriendTableAdapter.Fill(this.dataset.myfriend);
                Control_Clear();

                MessageBox.Show(
"MODIFIED");
            }
            
catch
            {
                MessageBox.Show(
"ERROR");
            }
        }

        
private void btn_Del_Click(object sender, EventArgs e)
        {
            
try
            {
                
/*
                var result 
= from t in tbl.AsEnumerable()
                                where t.Field
<int>("id") == id[lst_Search.SelectedIndex]
                                select t;
                
                foreach (DataRow r in result)
                {
                    r.Delete();
                    //tbl.Rows.Remove(r);
                }
                */
                if (0 == search.Count<DataRow>())
                    
return;
                DataRow r 
= search.ElementAt<DataRow>(lst_Search.SelectedIndex);
                r.Delete();


                conn 
= new MySqlConnection(strCon);
                conn.Open();
                adapter 
= new MySqlDataAdapter("select * from myfriend", conn);

                MySqlCommandBuilder build 
= new MySqlCommandBuilder(adapter);
                adapter.DeleteCommand 
=
 build.GetDeleteCommand();
                
//DataTable dataChanges = tbl.GetChanges();
                adapter.Update(tbl);                
                build.Dispose();

                
//tbl.AcceptChanges();
                conn.Close();

                
//id.RemoveAt(lst_Search.SelectedIndex);
                //search = null;
                //lst_Search.Items.Clear();
                Search();
                

                
this.myfriendTableAdapter.Fill(this.dataset.myfriend);
                Control_Clear();
                MessageBox.Show(
"DELETED");
            }
            
catch
            {
                MessageBox.Show(
"ERROR");
            }
        }

        
private void lst_Search_Click(object sender, EventArgs e)
        {
            
if (0 > lst_Search.SelectedIndex)
                
return;
            //search.ElementAt
<DataRow>(lst_Search.SelectedIndex);
            show_info();
        }
        
        
private void lst_Search_KeyUp(object sender, KeyEventArgs e)
        {
            
if (e.KeyCode == Keys.Enter)
            {
                
//show_info();
                this.SelectNextControl((Control)sender, truetruetruetrue);
            }
        }

        
private void lst_Search_SelectedIndexChanged(object sender, EventArgs e)
        {
            show_info();
        }
    }
}




=혼합계정

sa

1234












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

C++

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

<C++>



=컨테이터 ( STL )


<TDArray.h>

#ifndef __TDARRAY_H__
#define __TDARRAY_H__
#include <iostream>
#include "stdlib.h"
#include <string.h>
using namespace std;
template <typename T>
class TDArray
{
    
protected:
        T *ar;
        
unsigned size;
        
unsigned num;
        
unsigned growby;
    
public:
        TDArray(
unsigned asize=100unsigned agrowby=10);
        
virtual ~TDArray();
        
virtual void Insert(int
 idx, T value);
        
virtual void Delete(int idx);
        
virtual void Append(T value);

        T GetAt(
int idx) {return ar[idx];}
        
unsigned GetSize() {return size;}
        
unsigned GetNum() {return num; }
        
void SetAt(int idx, T value) { ar[idx]=value;}
        
void Dump(char * sMark);
};

template <typename T>
TDArray<T>::TDArray(unsigned asize, unsigned agrowby)
{
    size 
= asize;
    growby
=agrowby;
    num
=0;
    ar
=(T *)malloc(size*sizeof
(T));
};

template <typename T>
TDArray<T>::~TDArray()
{
    free(ar);
}

template <typename T>
void TDArray<T>::Insert(int idx, T value)
{
    
unsigned need;

    need 
= num +1;
    
if(need > size)
    {
        size 
= need + growby;
        ar
=(T *)realloc(ar,size * sizeof(T));
    }
    memmove(ar+idx+
1, ar+idx,(num-idx)*sizeof(T));
    ar[idx]
=
value;
    num++;
}


template <typename T>
void TDArray<T>::Delete(int idx)
{
    memmove(ar+idx, ar+idx+
1,(num=idx-1)*sizeof(T));
    num--;
}

template <typename T>
void TDArray<T>::Append(T value)
{
    Insert(num, value);
}

template <typename T>
void TDArray<T>::Dump(char * sMark)
{
    
unsigned i;
    cout 
<< sMark << => 크기 =" << size << ".개수=" << num << ":";
    
for(i=0;i<num;i++)
    {
        cout 
<< GetAt(i) << ' ';
    }
    cout 
<< endl;
    
}
#endif //__TDARRAY_H__


<TDArrayTest.cc>

//#include <iostream>
#include "TDArray.h"
//#include <stdlib.h>

using namespace std;

int main()
{

    TDArray
<int> ari;
    TDArray
<double> ard;
    
int i;

    
for(i=1;i<=5;i++)
        ari.Append(i);
    ari.Dump(
"5개 추가");

    
for(i=1;i<=3;i++)
        ard.Append((
double)i*1.23
);
    ard.Dump(
"3개 추가");
    
return 0;
}






=TStack


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

class iStack
{
    
private:
        
int *Stack;
        
int Size;
        
int Top;
    
public:
        iStack(
int aSize)
        {
            Size 
= aSize;
            Stack 
= (int *)malloc(Size*sizeof(int));
            Top 
= -1;
        }
        
virtual ~iStack()
        {
            free(Stack);
        }
        
virtual bool Push(int data)
        {
            
if(Top < Size-1)
            {
                Top++;
                Stack[Top]
=data;
                
return true;
            }
            
else
            {
                
return false;
            }
        }
        
virtual int Pop()
        {
            
if(Top >=0)
            {
                
return Stack[Top--];
            }
            
else
            {
                
return -1;
            }
        }
};

int main()
{
    iStack iS(
256);
    iS.Push(
7);
    iS.Push(
0);
    iS.Push(
6);
    iS.Push(
2);
    iS.Push(
9);
    cout 
<< iS.Pop() << endl;
    cout 
<< iS.Pop() << endl;
    cout 
<< iS.Pop() << endl;
    cout 
<< iS.Pop() << endl;
    cout 
<< iS.Pop() <<
 endl;
    
return 0;
}







=예외처리




< C언어 형태 >

#include <iostream>
using namespace std;

int main()
{
    
int a;
    
int b;
    cin 
>> a;
    cin 
>> b;
    
if0 == b )
    {
        cout 
<< "0 으로 나눌 수 없습니다\n";
        
return 0;
    }
    cout 
<< "몫은 " << a/b << " 입니다\n";
    cout 
<< "나머지는 " << a%b << " 입니다\n";

    
return 0;
}


-Try

-Catch

-throw


#include <iostream>
using namespace std;



int main()
{
    
int a;
    
int b;
    cin 
>> a;
    cin 
>> b;
    
try
    {
        
if0 == b )
        {
            
throw b;
            
//cout << "0 으로 나눌 수 없습니다\n";
            //return 0;
        }
        cout 
<< "몫은 " << a/b << " 입니다\n";
        cout 
<< "나머지는 " << a%b << " 입니다\n";
    }
    
catch(int iTest)
    {
        cout 
<< iTest << "으로는 나눌수 없습니다\n";
    }
    
return 0;
}







=


#include <iostream>
using namespace std;

void div(int a, int b)
{
    
if0 == b )
    {
        
throw b;
    }
    cout 
<< "몫은 " << a/b << " 입니다\n";
    cout 
<< "나머지는 " << a%b << " 입니다\n";
    
return;
}

int main()
{
    
int a;
    
int b;
    cin 
>> a;
    cin 
>> b;
    
try
    {
        div(a,b);
        cout 
<< "-------------------------------------\n";
    }
    
catch(int iTest)
    {
        cout 
<< iTest << "으로는 나눌수 없습니다\n";
    }
    
return 0;
}









=함수의 지역 선언 객체 소멸


#include <iostream>
using namespace std;

class C
{
    
int a;
    
public:
        C()
        {
            cout 
<< "생성자 호출\n";
        }
        ~C()
        {
            cout 
<< "소멸자 호출\n";
        }
};

void divide(int a, int b)
{
    
if(0==b)
        
throw "0 으로는 나눌 수 없습니다.";
    cout 
<< "나누기 결과 = " << a/b << " 입니다\n";
}

void calc(int t, const char *m)
{
    C c;
    divide(
10,0);
}

int main()
{
    
try
    {
        calc(
1,"계산");
    }
    
catch(const char * message)
    {
        cout 
<< message << endl;
    }
    cout 
<< "프로그램이 종료됩니다\n";
    
return 0;
}








=중첩 예외 처리

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

int main()
{
    
int Num;
    
int Age;
    
char Name[128];

    
try
    {
        cout 
<< "학번을 입력하시오 : \n";
        cin 
>> Num;
        
if(Num <=0)
            
throw Num;

        
try
        {
            cout 
<< "이름을 입력하시오 :\n";
            cin 
>> Name;
            
if(strlen(Name) <4)
                
throw " 이름이 너무 짧습니다";
            cout 
<< "나이를 입력하시오 :\n";
            cin 
>> Age;
            
if(Age <= 0)
                
throw Age;

            cout 
<< "입력한 정보 => 학번: " << Num << ", 이름: " << Name << ", 나이: " << Age << endl;
        }
        
catch(const char * Message)
        {
            cout 
<< Message << endl;
        }
        
catch(int)
        {
            
throw;
        }
    }
    
catch(int n)
    {
        cout 
<< n << "은 음수이므로 적합하지 않습니다\n";
    }

    
return 0;
}






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

20150701  (0) 2015.07.02
20150630  (0) 2015.06.30
20150626  (0) 2015.06.27
20150625  (0) 2015.06.26
20150624  (0) 2015.06.24
Posted by ahj333
,

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

C#

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

<C#>



=LINQ TO DATASET

:VAR


// Fill the DataSet.
            DataSet ds = new DataSet();
            ds.Locale 
= CultureInfo.InvariantCulture;
            FillDataSet(ds);

            DataTable products 
= ds.Tables["Product"];

            IEnumerable
<DataRow> productsQuery =
                from product in products.AsEnumerable()
                select product;

            IEnumerable
<DataRow> largeProducts =
                productsQuery.Where(p => p.Field<string>("Size"== "L");

            Console.WriteLine(
"Products of size 'L':");
            foreach (DataRow product in largeProducts)
            {
                Console.WriteLine(product.Field
<string>("Name"));
            }






-클라우드

READER + ADAPTER( XML로 바꿔 줌)



=> 망고 DB ( 클라우드의 자원 사용 안하는 방향으로 )


=


찾기

리스트박스

(id)-primary key

이름

EMAIL

전화번호

핸드폰번호

주소

회사/학교

부서/과

소개


앞으로 뒤로 추가 수정 삭제



-DB


mysql> create table myfriend(

    -> id int,

    -> name varchar(20),

    -> email varchar(20),

    -> phone varchar(20),

    -> mobile varchar(20),

    -> address varchar(20),

    -> company varchar(20),

    -> department varchar(20),

    -> introduce varchar(80)

    -> );

Query OK, 0 rows affected (0.24 sec)


mysql> alter table myfriend add primary key(id);

Query OK, 0 rows affected (0.42 sec)

Records: 0  Duplicates: 0  Warnings: 0


mysql> alter table myfriend drop primary key;

Query OK, 0 rows affected (0.41 sec)

Records: 0  Duplicates: 0  Warnings: 0


mysql> alter table myfriend drop id;

Query OK, 0 rows affected (0.25 sec)

Records: 0  Duplicates: 0  Warnings: 0


mysql> alter table myfriend add id int not null auto_increment primary key;

Query OK, 0 rows affected (1.04 sec)

Records: 0  Duplicates: 0  Warnings: 0


mysql> alter table myfriend modify column id int first;

Query OK, 0 rows affected (0.42 sec)

Records: 0  Duplicates: 0  Warnings: 0


mysql> DESC MYFRIEND;

+------------+-------------+------+-----+---------+----------------+

| Field      | Type        | Null | Key | Default | Extra          |

+------------+-------------+------+-----+---------+----------------+

| id         | int(11)     | NO   | PRI | NULL    | auto_increment |

| name       | varchar(20) | YES  |     | NULL    |                |

| email      | varchar(20) | YES  |     | NULL    |                |

| phone      | varchar(20) | YES  |     | NULL    |                |

| mobile     | varchar(20) | YES  |     | NULL    |                |

| address    | varchar(20) | YES  |     | NULL    |                |

| company    | varchar(20) | YES  |     | NULL    |                |

| department | varchar(20) | YES  |     | NULL    |                |

| introduce  | varchar(80) | YES  |     | NULL    |                |

+------------+-------------+------+-----+---------+----------------+

9 rows in set (0.00 sec)



=



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

C++

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

<C++>



=템플릿 클래스 내의 static 변수

#include <iostream>
using namespace std;


template <class T>
class smart
{
    
public:
        
static T num;

};

template <typename T>
T smart<T>
::num;

int main()
{
    smart
<int> obj1;
    cout 
<< obj1.num << endl;
    
return 0;
}











=static 변수의 특수화



#include <iostream>
using namespace std;


template <class T>
class smart
{
    
public:
        
static T num;

};

template <typename T>
T smart<T>::num;


template <>
int smart<int>::num = 100;


int main()
{
    
smart<int> obj1;
    smart
<short> obj2;


     cout 
<< obj1.num << endl;
    cout 
<< obj2.num << endl;

    
return 0;
}
















=컨테이터 ( STL )




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

20150630  (0) 2015.06.30
2015029  (0) 2015.06.30
20150625  (0) 2015.06.26
20150624  (0) 2015.06.24
20150623  (0) 2015.06.23
Posted by ahj333
,

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

C#

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

<C#>



=메모리데이터베이스 : 프로그램 종료시 다 사라짐






=DATA GRID 추가






=

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;

namespace datatableexam
{
    
public partial class Form1 : Form
    {
        
private DataTable tbl = null;  // 멤버로 선언
        private int data_Index;
        
public Form1()
        {
            InitializeComponent();
        }

        
private void btn_DataTable_Click(object sender, EventArgs e)
        {
            tbl 
= new DataTable("classinfo"); // classInfo 테이블 생성
            DataColumn column;   // 컬럼 인스턴스 생성

            // 학번 컬럼 만들기
            column = new
 DataColumn();
            column.DataType 
= Type.GetType("System.String"); // 데이터형 지정 // 리플렉션
            column.ColumnName = "Name";  // 칼럼 이름 설정
            column.AllowDBNull = false;  // 널 값 허용 안함
            tbl.Columns.Add(column);     // 테이블에 칼럼 추가

            // 국어 컬럼 만들기
            column = new DataColumn();
            column.DataType 
= Type.GetType("System.Int32"); // 데이터형
            column.ColumnName = "Kor";  // 컬럼 이름
            column.AllowDBNull = false;  // 널값 허용 안함
            tbl.Columns.Add(column);  // 테이블에 컬럼 추가

            // 영어 컬럼 만들기
            column = new DataColumn();
            column.DataType 
= Type.GetType("System.Int32"); // 데이터형
            column.ColumnName = "Eng";  // 컬럼 이름
            column.AllowDBNull = false;  // 널값 허용 안함
            tbl.Columns.Add(column);  // 테이블에 컬럼 추가

            // 수학 컬럼 만들기
            column = new DataColumn();
            column.DataType 
= Type.GetType("System.Int32"); // 데이터형
            column.ColumnName = "Math";  // 컬럼 이름
            column.AllowDBNull = false;  // 널값 허용 안함
            tbl.Columns.Add(column);  // 테이블에 컬럼 추가

            // 평균 컬럼 만들기
            column = new DataColumn();
            column.DataType 
= Type.GetType("System.Double"); // 데이터형
            column.ColumnName = "Avg";  // 컬럼 이름
            column.AllowDBNull = false;  // 널값 허용 안함
            tbl.Columns.Add(column);  // 테이블에 컬럼 추가

            //학번 컬럼을 기본 키 설정
            DataColumn[] pk = new DataColumn[1];
            pk[
0= tbl.Columns["No"];
            tbl.PrimaryKey 
= pk;

            
// 새로운 레코드 추가하기
            DataRow row;
            row 
= tbl.NewRow();  // 200501 번 데이터
            row["Name"= "홍길동";
            row[
"Kor"= 90;
            row[
"Eng"= 83;
            row[
"Math"= 81;
            row[
"Avg"= (90 + 83 + 81) / 3.0;
            tbl.Rows.Add(row);

            row 
= tbl.NewRow();  // 200502 번 데이터
            row["Name"= "김동현";
            row[
"Kor"= 95;
            row[
"Eng"= 81;
            row[
"Math"= 90;
            row[
"Avg"= (95 + 81 + 90) / 3.0;
            tbl.Rows.Add(row);

            row 
= tbl.NewRow();  // 200503 번 데이터
            row["Name"= "오종석";
            row[
"Kor"= 80;
            row[
"Eng"= 90;
            row[
"Math"= 75;
            row[
"Avg"= (80 + 90 + 75) / 3.0;
            tbl.Rows.Add(row);

            data_Grid_view.DataSource 
= tbl;  // 데이터 그리드 화면 출력
            data_Grid.DataSource =
 tbl;
        }

        
private void btn_Add_Click(object sender, EventArgs e)
        {
            string name 
= this.txt_Name.Text.Trim();
            string kor 
= txt_Kor.Text.Trim();
            string eng 
= txt_Eng.Text.Trim();
            string math 
= txt_Math.Text.Trim();

            
if (name != "" && kor != "" && eng != "" && math != "")
            {
                
try
                {
                    
int kk = Convert.ToInt32(kor);
                    
int ee = Convert.ToInt32(eng);
                    
int mm = Convert.ToInt32(math);

                    DataRow row 
= tbl.NewRow();
                    row[
"Name"= name;
                    row[
"Kor"= kk;
                    row[
"Eng"= ee;
                    row[
"Math"= mm;
                    row[
"Avg"= (kk + ee + mm) / 3;
                    tbl.Rows.Add(row);
                }
                
catch
                {
                    MessageBox.Show(
" 국/영/수 성적이 잘못 입력되었습니다!");
                }
            }
            
else
            {
                MessageBox.Show(
"이름, 국/영/수 성적을 입력하세요!");
            }
        }

        
private void btn_Edit_Click(object sender, EventArgs e)
        {
            
try
            {
                
int kor = Convert.ToInt32(this.txt_Kor.Text.Trim());
                
int eng = Convert.ToInt32(this.txt_Eng.Text.Trim());
                
int math = Convert.ToInt32(this.txt_Math.Text.Trim());

                DataRow row 
= this.tbl.Rows[data_Index];
                row.BeginEdit();
                row[
"Name"= this.txt_Name.Text.Trim();
                row[
"Kor"= kor;
                row[
"Eng"= eng;
                row[
"Math"= math;
                row[
"Avg"= (kor + eng + math) / 3.0;
                row.EndEdit();
            }
            
catch
            {
                MessageBox.Show(
"데이터그리드에서 편집할 레코드를 선택하세요!");
            }

        }

        
private void btn_Delete_Click(object sender, EventArgs e)
        {
            
try
            {
                DataRow row 
= this.tbl.Rows[data_Index];
                row.Delete();

            }
            
catch (Exception ex)
            {
                MessageBox.Show(
"에러 발생 : " + ex.Message);
            }

        }

        
private void btn_Delete_All_Click(object sender, EventArgs e)
        {
            
try
            {
                tbl.Rows.Clear();   
// 전체 레코드 삭제
            }
            
catch (Exception ex)
            {
                MessageBox.Show(
"에러 메시지 : " + ex.Message);
            }

        }

        
private void data_Grid_Click(object sender, EventArgs e)
        {
            
try
            {
             
   data_Index = this.data_Grid.CurrentRowIndex;
                DataRow row 
= this
.tbl.Rows[data_Index];
                
this.txt_Name.Text = row["Name"].ToString();
                
this.txt_Kor.Text = row["Kor"].ToString();
                
this.txt_Eng.Text = row["Eng"].ToString();
                
this.txt_Math.Text = row["Math"].ToString();
            }
            
catch (Exception ex)
            {
                MessageBox.Show(
"에러 발생 : " + ex.Message);
            }

        }

        
private void data_Grid_view_Click(object sender, EventArgs e)
        {
            
try
            {
             
   data_Index = this.data_Grid_view.SelectedRows[0].Index;
                DataRow row 
= this
.tbl.Rows[data_Index];

                
this.txt_Name.Text = row["Name"].ToString();
                
this.txt_Kor.Text = row["Kor"].ToString();
                
this.txt_Eng.Text = row["Eng"].ToString();
                
this.txt_Math.Text = row["Math"].ToString();
            }
            
catch (Exception ex)
            {
                MessageBox.Show(
"에러 발생 : " + ex.Message);
            }

        }

    }
}













=DATA GRID VIEW






=Binding Navigator












=DATA GRID VIEW 마법사 이용 X - button1_Click()

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;

namespace WindowsFormsApplication1
{
    
public partial class Form1 : Form
    {
        
public Form1()
        {
            InitializeComponent();
        }

        
private void Form1_Load(object sender, EventArgs e)
        {


        }

        
private void button1_Click(object sender, EventArgs e)
        {
            
// TODO: This line of code loads data into the 'kdhong_dbDataSet.mem' table. You can move, or remove it, as needed.
            this.memTableAdapter.Fill(this.kdhong_dbDataSet.mem); // Form1_Load =>
 button1 click
        }
    }
}








=DATA GRID VIEW 마법사 이용 X - Form1_Load()





using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace WindowsFormsApplication1
{
    
public partial class Form1 : Form
    {
        
public Form1()
        {
            InitializeComponent();
        }

        
private void Form1_Load(object sender, EventArgs e)
        {
            
MySqlConnection conn = null;
            MySqlDataAdapter adapter 
= null;
            DataSet ds 
= null;
            DataTable table 
= null;
            string strCon 
= "server=localhost;user id=root;password=root;database=kdhong_db";
            conn 
= new MySqlConnection(strCon);
            adapter 
= new MySqlDataAdapter("select * from mem", conn);
            ds 
= new DataSet();
            table 
= new DataTable();
            adapter.Fill(ds);
            
this.dataGridView2.DataSource = ds.Tables[0];

        }

        
private void button1_Click(object sender, EventArgs e)
        {
            
// TODO: This line of code loads data into the 'kdhong_dbDataSet.mem' table. You can move, or remove it, as needed.
            this.memTableAdapter.Fill(this.kdhong_dbDataSet.mem); // Form1_Load => button1 click
        }
    }
}



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

C++

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

<C++>



=템플릿 - 형이 여러개

#include <iostream>
using namespace std;


template <class T, class T2>
//float add (float fNum, int iNum)
T add (T fNum, T2 iNum)
{
    
return fNum + (T)iNum;
}

int main()
{
    
float fNum = 2.1;
    
int iNum = 3;

   
 fNum = add<floatint>(fNum, iNum);
    cout 
<< fNum << endl;
    
return 0;
}





=디폴트 템플릿 인수

type

#include <iostream>
using namespace std;



template <class T, class T2=int>
T add2 (T fNum, T2 iNum)
{
    
return fNum + (T)iNum;
}

int main()
{
    
float fNum = 2.1;
    
int iNum = 3;

 
   fNum = add2<float>(fNum, iNum);
    cout 
<< fNum << endl;
    
return 0;
}






<cf>함수의 디폴트 인자

1. 오른쪽 인자 디폴트

#include <iostream>
using namespace std;

int add4 (int Num1, int Num2 = 2)
{
    
return Num1 + Num2;
}


int main()
{

    float fNum;

    fNum 
= add4(2);
    cout 
<< fNum << endl;
 
    
return 0;
}





2. 왼쪽 인자 디폴트


#include <iostream>
using namespace std;


int add5 (int Num1=2int Num2)
{
    
return Num1 + Num2;
}


int main()
{

    float fNum;

 
   fNum = add5(2);
    cout 
<< fNum << endl;
    
return 0;
}







=비타입 인수

template < typename T, int N >


:type이 인자가 아닌 값이 인자로 들어가는


#include <iostream>
using namespace std;


template <class T=intint N>
T add6 (T fNum)
{
    
return fNum + N;
}


int main()
{

    float fNum;


    fNum = add6<float3>(2.1);
    cout 
<< fNum << endl;
    
return 0;
}






=

컴파일에러


template <class T=intint N>
T add6 (T fNum)
{
    
return fNum + N;
}


int main()
{

     float fNum;


     fNum = add6<3>(2);
    cout 
<< fNum << endl;
    
return 0;
}








=디폴트 타입 / 디폴드 인자

template <class T=intint N2 = 2>
T add7 (T fNum)
{
    
return fNum + N2;
}
int main()
{
    
float fNum;

    fNum = add7<>(3);
    cout 
<< fNum << endl;
    
return 0;
}








=특수화 클래스


#include <iostream>
using namespace std;

template <typename T>
class PosValue
{
    
private:
        
int x,y;
        T value;
    
public:
        PosValue(
int ax, int ay, T av) : x(ax),y(ay),value(av) {}
        
void OutValue();
};

template <typename T>
void PosValue<T>::OutValue()
{
//    gotoxy(x,y);
    cout << value << endl;
}

struct tag_Friend
{
    
char Name[10];
    
int Age;
    
double Height;
};

template <> class PosValue<tag_Friend>
{
    
private:
        
int x,y;
        tag_Friend value;
    
public:
        PosValue(
int ax, int ay, tag_Friend av) : x(ax), y(ay), value(av){}
        
void OutValue();
};


void PosValue<tag_Friend>::OutValue()
{
  
//  gotoxy(x,y);
    cout << "이름: " << value.Name << ".나이: " << value.Age;
    cout 
<< ".키: " << value.Height << endl;
}

int main()
{
    PosValue
<int> iv(1,1,2);
    tag_Friend F
={"아무개"25177.7};
    
PosValue<tag_Friend> fv(2,2,F);
    iv.OutValue();
    fv.OutValue();

    
return 0;
}






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

2015029  (0) 2015.06.30
20150626  (0) 2015.06.27
20150624  (0) 2015.06.24
20150623  (0) 2015.06.23
20150622  (0) 2015.06.22
Posted by ahj333
,