2017. 12. 26. 12:14

DataTable table = new DataTable();

//.......데이터 추가 하고... 중략 ..............

table = table.DefaultView.ToTable(true); //중복 제거



'언어 > C#' 카테고리의 다른 글

[WPF] 응용프로그램 따라해보기  (0) 2018.08.21
[C#] Textbox Multiline  (0) 2018.06.19
Tray Application  (0) 2017.07.13
C# 한글 인코딩  (0) 2017.06.18
[ini] ini파일 읽기 쓰기 기본 코드  (0) 2017.02.14
Posted by 까망후니
2017. 7. 13. 13:59


public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();


            this.WindowState = FormWindowState.Minimized;

            this.ShowInTaskbar = false;

            this.Visible = false;

            this.notifyIcon1.Visible = true;

            notifyIcon1.ContextMenuStrip = contextMenuStrip1;


            MaximizeBox = false;

            MinimizeBox = false;

            //getService();

           // test();

        }



        private void Form1_FormClosed(object sender, FormClosedEventArgs e)

        {

            Application.Exit();

            this.notifyIcon1.Visible = false;

        }


        private void Form1_FormClosing(object sender, FormClosingEventArgs e)

        {

            e.Cancel = true;

            WindowState = FormWindowState.Minimized;

            this.ShowInTaskbar = false;

        }


        private void notifyIcon1_DoubleClick(object sender, EventArgs e)

        {            

            this.Show();

            this.Visible = true;

            this.ShowInTaskbar = true;

            this.WindowState = FormWindowState.Normal;

        }


        private void 종료ToolStripMenuItem_Click(object sender, EventArgs e)

        {

            Application.ExitThread();

            Environment.Exit(0);

            Application.Exit();

            this.notifyIcon1.Visible = false;

            

            /*

             * Application 강제 Process Kill

             */

            //System.Diagnostics.Process.GetCurrentProcess().Kill();

        }


    }

'언어 > C#' 카테고리의 다른 글

[C#] Textbox Multiline  (0) 2018.06.19
C# 데이터 테이블 중복 제거  (0) 2017.12.26
C# 한글 인코딩  (0) 2017.06.18
[ini] ini파일 읽기 쓰기 기본 코드  (0) 2017.02.14
[Thread]쓰레드 기본 코드  (0) 2016.07.08
Posted by 까망후니
2017. 6. 18. 14:46

private string convertASCII(string value)

        {

            byte[] convertByte = Encoding.ASCII.GetBytes(value);

            for (int i = 0; i < convertByte.Length; i++)

            {


            }

            value = Encoding.ASCII.GetString(convertByte);

            return value;

        }


        private string convertBASE64(string value)

        {

            byte[] convertByte = Encoding.Unicode.GetBytes(value);

            for (int i = 0; i < convertByte.Length; i++)

            {


            }

            value = Convert.ToBase64String(convertByte);

            convertByte = Convert.FromBase64String(value);

            value = Encoding.UTF8.GetString(convertByte);


            return value;

        }


        private string convertUNI(string value)

        {

            byte[] convertByte = Encoding.Unicode.GetBytes(value);

            for (int i = 0; i < convertByte.Length; i++)

            {


            }

            //value = Convert.ToBase64String(convertByte);

            //convertByte = Convert.FromBase64String(value);

            value = Encoding.UTF8.GetString(convertByte);


            return value;

        }

'언어 > C#' 카테고리의 다른 글

C# 데이터 테이블 중복 제거  (0) 2017.12.26
Tray Application  (0) 2017.07.13
[ini] ini파일 읽기 쓰기 기본 코드  (0) 2017.02.14
[Thread]쓰레드 기본 코드  (0) 2016.07.08
[C#] 걸린 시간 체크  (0) 2016.06.08
Posted by 까망후니
2017. 2. 14. 09:19

using System.Runtime.InteropServices;       


        [DllImport("kernel32")]

        private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);

        [DllImport("kernel32")]

        private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size,             string filePath);


        private string FilePath = AppDomain.CurrentDomain.BaseDirectory + "init.ini";


// ini 파일에 쓰기

private void WriteIni(string section, string key, string value)

        {

            WritePrivateProfileString(section, key, value, FilePath);

        }


        // ini파일에서 읽기

        private string Readini(string section, string key)

        {

            StringBuilder temp = new StringBuilder(255);

            int ret = GetPrivateProfileString(section, key, "", temp, 255, FilePath);            

            return temp.ToString();

        }




         textBox.Text = Readini("Section 값", "Key 값"); //이렇게 읽고

         WriteIni("Section 값", "Key 값", textBox.Text); //이렇게 쓴다.

'언어 > C#' 카테고리의 다른 글

Tray Application  (0) 2017.07.13
C# 한글 인코딩  (0) 2017.06.18
[Thread]쓰레드 기본 코드  (0) 2016.07.08
[C#] 걸린 시간 체크  (0) 2016.06.08
[C#] ListView item 삭제  (0) 2016.03.22
Posted by 까망후니
2016. 7. 8. 14:16

쓰레드를 처음 쓰는 분들을 위한 예제 코드 입니다.


참조만 하세요..ㅎㅎ..




using System.Threading;



//---------------------------------------------------------------------------------------



public class Worker

    {

        private volatile bool _shouldStop;



        public void DoWork()

        {

            while (!_shouldStop)

            {

                Console.WriteLine("worker thread: start..." + DateTime.Now.ToString());


                try

                {

                    if (_shouldStop == true) break;

                  

//여기에 내가 돌리고 싶은 코드를 ~~~


                    

                }

                catch (Exception ex)

                {

                    Console.WriteLine(ex.ToString());

                }


                Thread.Sleep(1000);


            }

            Console.WriteLine("worker thread: terminating gracefully.");


            _shouldStop = false;

        }




        public void RequestStop()

        {

            _shouldStop = true;

        }

    }

//---------------------------------------------------------------------------------------


 private Worker worker = new Worker();

 private Thread workerThread;



 private void button1_Click(object sender, EventArgs e)

        {

            workerThread = new Thread(worker.DoWork);

            workerThread.Start();

            Console.WriteLine("Split Thread: Starting worker thread...");

        }


        private void button2_Click(object sender, EventArgs e)

        {

            try

            {

                worker.RequestStop();

                workerThread.Join();


            }

            catch (Exception ex)

            {

                System.Console.WriteLine(ex.ToString());               

            }           

        }




'언어 > C#' 카테고리의 다른 글

C# 한글 인코딩  (0) 2017.06.18
[ini] ini파일 읽기 쓰기 기본 코드  (0) 2017.02.14
[C#] 걸린 시간 체크  (0) 2016.06.08
[C#] ListView item 삭제  (0) 2016.03.22
[C#] ListView 에 Item 추가  (0) 2016.03.22
Posted by 까망후니
2016. 6. 8. 09:02
using System.Diagnostics;
  
Stopwatch SW = new Stopwatch();
string delay;

SW.Reset();
SW.Start();

~~~코딩~~~ 

SW.Stop();
 

delay = SW.Elapsed.ToString();                         // EX) "00:00:00.0000045"
//delay = SW.ElapsedMilliseconds.ToString() ;          // EX) "123"



[참고] http://overit.tistory.com/entry/C-%EC%8B%9C%EA%B0%84%EC%B2%B4%ED%81%ACStopwatch


'언어 > C#' 카테고리의 다른 글

[ini] ini파일 읽기 쓰기 기본 코드  (0) 2017.02.14
[Thread]쓰레드 기본 코드  (0) 2016.07.08
[C#] ListView item 삭제  (0) 2016.03.22
[C#] ListView 에 Item 추가  (0) 2016.03.22
[C#] Active Directory 사용자 리스트 가져오기  (0) 2015.12.08
Posted by 까망후니
2016. 3. 22. 17:22

선택된 ListView의 Item 삭제 방법입니다.


if (MessageBox.Show("선택하신 항목이 삭제 됩니다.\r계속 하시겠습니까?", "항목 삭제", MessageBoxButtons.YesNo) == DialogResult.Yes)

{

if (listView.SelectedItems.Count > 0)

{

int index = listView.FocusedItem.Index;

listView.Items.RemoveAt(index);

     }

else

{

MessageBox.Show("선택된 항목이 없습니다.");

}

}

'언어 > C#' 카테고리의 다른 글

[ini] ini파일 읽기 쓰기 기본 코드  (0) 2017.02.14
[Thread]쓰레드 기본 코드  (0) 2016.07.08
[C#] 걸린 시간 체크  (0) 2016.06.08
[C#] ListView 에 Item 추가  (0) 2016.03.22
[C#] Active Directory 사용자 리스트 가져오기  (0) 2015.12.08
Posted by 까망후니
2016. 3. 22. 17:20

아래처럼 하면 IP, Port, Product 순으로 넣을수 있다.


ListViewItem items = new ListViewItem();

items.Text = ip;    //Ip삽입

items.SubItems.Add(port);    //port삽입

items.SubItems.Add(product);    //product삽입

listView.Items.Add(items);    //실제 추가

'언어 > C#' 카테고리의 다른 글

[ini] ini파일 읽기 쓰기 기본 코드  (0) 2017.02.14
[Thread]쓰레드 기본 코드  (0) 2016.07.08
[C#] 걸린 시간 체크  (0) 2016.06.08
[C#] ListView item 삭제  (0) 2016.03.22
[C#] Active Directory 사용자 리스트 가져오기  (0) 2015.12.08
Posted by 까망후니
2015. 12. 8. 13:20


try

            {

                DirectoryEntry searchRoot = new DirectoryEntry("LDAP://piserver.com",  

                       "test", "Passw0rd");  //서버도메인 정보, 서버의 계정ID, 계정 PW

                DirectorySearcher directorySearcher = new DirectorySearcher(searchRoot);

      

                directorySearcher.Filter = "(&(objectCategory=person)(objectClass=user))";                

                string text = "sAMAccountName"; //ID를 가져오겠다는 뜻이다.

     

                //directorySearcher.PropertiesToLoad.Add("cn");

                directorySearcher.PropertiesToLoad.Add(text);

                directorySearcher.PropertiesToLoad.Add("mail"); //mail을 가져오겠다는 뜻이다.

                directorySearcher.PropertiesToLoad.Add("usergroup"); //usergroup을 가져오겠다는 뜻이다.

                directorySearcher.PropertiesToLoad.Add("displayname"); //표기이름을 가져오겠다는 뜻이다.


                SearchResultCollection resultCol = directorySearcher.FindAll();


                SearchResult result;

string userName = "";

                List<Users> lstADUsers = new List<Users>();

                if (resultCol != null)

                {

                    for (int counter = 0; counter < resultCol.Count; counter++)

                    {

                        string UserNameEmailString = string.Empty;

                        result = resultCol[counter];

                        if (result.Properties.Contains("samaccountname"))

                        {

                            Users objSurveyUsers = new Users();

                           

                            if(result.Properties["samaccountname"] != null)

                                userName = (String)result.Properties["samaccountname"][0];

//해당 항목을 주석처리 한 이유는 해당 항목이 미입력된 경우 에러가 출력되기 때문이다.ID는 반드시 있으므로 ID만 일단 해보는 걸로~

                            //if (result.Properties["displayname"] != null)  

                            //    objSurveyUsers.DisplayName = (String)result.Properties["displayname"][0];

                            //if (result.Properties["mail"] != null)

                            //    objSurveyUsers.Email = (String)result.Properties["mail"][0];

                            lstADUsers.Add(objSurveyUsers);

                        }

                    }

                }                            

            }

            catch(Exception ex)

            {

                System.Console.WriteLine("## Get Search AD User List Exception : " + ex.Message);

            }

[참조 : http://www.codeproject.com/Tips/599697/Get-list-of-Active-Directory-users-in-Csharp]

'언어 > C#' 카테고리의 다른 글

[ini] ini파일 읽기 쓰기 기본 코드  (0) 2017.02.14
[Thread]쓰레드 기본 코드  (0) 2016.07.08
[C#] 걸린 시간 체크  (0) 2016.06.08
[C#] ListView item 삭제  (0) 2016.03.22
[C#] ListView 에 Item 추가  (0) 2016.03.22
Posted by 까망후니