'2009/07/08'에 해당되는 글 1건

  1. 2009/07/08 C# 유용한 예제 모음
2009/07/08 03:51 My major/JAVA
1. 소켓 통신

 [ SERVER ]
 private int PORT = 4000;

IPAddress ip = IPAddress.Parse("210.000.000.000");
TcpListener listener = new TcpListener(ip, 4000);
listener.Start();
while(true){
            TcpClient client = listener.AcceptTcpClient();
            NetworkStream ns = client.GetStream();
            Console.WriteLine("accept the TCP connection request  ");
            Console.WriteLine("(" + DateTime.Now + ":" + ")");
            Runner rn = new Runner(ns);
            ThreadStart ts = new ThreadStart(rn.run);
            Thread th = new Thread(ts);
            th.Start();
}


2. JAVA의 StringTokenizer와 같은 역할을 할만한 루틴..

 String[] stringToken = SharedData.name.Split(new char[1]{'.'});
  String outputName = stringToken[0] + ".xls";


3. 엑셀파일 저장 및 열기

 object missingType = Type.Missing;
Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook excelBook = excelApp.Workbooks.Add(missingType);
Microsoft.Office.Interop.Excel.Worksheet flowWorksheet =                (Microsoft.Office.Interop.Excel.Worksheet)
excelBook.Worksheets.Add(missingType, missingType, missingType, missingType);
excelApp.Visible = false;
                for (int i = 0; i < flow.Length; i++)
                {
                    flowWorksheet.Cells[0, i] = det_id[i];
                    for (int k = 0; k < flow[i].Length; k++)
                    {
                        flowWorksheet.Cells[k + 2, i] = flow[i][k];
                    }
                }
excelBook.SaveAs(@outputName, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, missingType, missingType , missingType, missingType, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlNoChange, missingType,
 missingType, missingType, missingType, missingType);


3. File dialog

 OpenFileDialog openDialog = new OpenFileDialog();
openDialog.Filter = "VISSIM File(*.inp)|*.inp";
openDialog.Title = "Open Vissim file";

                if (openDialog.ShowDialog() == DialogResult.OK)
                {
                    //MessageBox.Show(openDialog.FileName);
                    vis = new Vissim();                        //create simulation
                    vis.LoadNet(openDialog.FileName, 0);
                }
                else
                {
                    mainForm.PrintMessage("File is not correct");
                    return;
                }





추가중..
posted by joyoungtae