본문 바로가기

c#

(26)
[c#][mssql] Spatial Data type을 취급하기 위한 필수 패키지 C# 코딩에서 mssql Spatial Type을 취급하기 위한 필수 nuget 패키지 DotSpatial.Projections- 좌표계 변환 함수 포함 GeoJSON for Entity Framework 6 Spatial Data and WKT- Spatial m WKT 타입을 GeoJSON 으로 변경하는 함수 Microsoft.SqlServer.Types- Sql 서버의 타입 정의
Convert string format to Datetime string testDateString = "19900712"; DateTime testDatetime = DateTime.ParseExact(testDateString, "yyyyMMdd"); string resultDateString = string.Format("{0:yyyy년MM월dd일}", testDatetime); msdn : https://goo.gl/kLdZ9k
[c#] 해당 경로에 파일 복사하기 string fileName = "{{복사 할 파일명}}"; string sourceFilePath = "{{원본 경로}}"; string targetFilePath = "{{복사 할 경로}}"; boolean existsCheck = false; boolean fileExists = false; FileInfo file; sourceFilePath = sourceFilePath + @"/" + fileName; file = new FileInfo(sourceFilePath); fileExists = file.Exists; if(fileExists) { try { if (!Directory.Exists(targetFilePath)) Directory.CreateDirectory(targetFilePath..
[c#] 경과 시간을 표시할 때 String saveTempString = string.empty;DateTime tempDateTime = DateTime.Now; // 시작하는 위치 ... 처리 로직 TimeSpan diff = DateTime.Now - tempDateTime; saveTempString = string.Format("{0:hh\\:mm\\:ss}", diff); Console.WriteLine(saveTempString);
[c#] StreamWriter 로 텍스트 파일 생성/쓰기 StreamWriter 로 텍스트 파일 생성/쓰기 public static void SaveFile(string filePath, string saveData = null) { if (!File.Exists(filePath)) { using (StreamWriter sw = File.CreateText(filePath)) { sw.Write(saveData); sw.AutoFlush = true; } } else { using (StreamWriter sw = File.AppendText(filePath)) { sw.Write("\r\n" + saveData); sw.AutoFlush = true; } } } 참조 : StreamWriter MSDN
[c#][Linq][EntityFramework] 메모리 누수 방지를 위한 Skip, Take 사용방법 int totalCount = 0;int amountToSkip = 0;int processAmount = 0;Boolean finished = false; using(var context = new {{DataContext}}()){ totalCount = context.{{테이블}}.Where({{조건절}}).Count(); while (!finished) { resultList = context.{{테이블}} .Where({{조건절}}) .OrderBy({{정렬조건}}) //Skip, Take 사용을 위해 정렬 필수 .Skip(amountToSkip) .Take(1000).ToList(); //Take 수는 적절히 조정 processAmount = resultList.Count; if (result..
[C#]제곱미터를 평으로 변환 /// /// 제곱미터를 평으로 변환 /// /// /// public string tranferSqaureMeterToPyeung(string squareMeter) { double tempSquareMeter = 0.0; string tempPyeung = "0"; try { tempSquareMeter = double.Parse(getRealNumber(squareMeter)); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } tempPyeung = Math.Round((tempSquareMeter * pyeongValue), 2).ToString(); return tempPyeung; } getRealNumber 참조
[C#]문자열에서 실수부분만 추출 /// /// 문자열에서 실수부분만 추출 /// /// /// public string getRealNumber(string number) { string tempValue = "0"; try { Regex pattern = new Regex(@"[0-9]+(\.|\,)[0-9]+"); Match match = pattern.Match(number); tempValue = match.Value; } catch (Exception ex) { Console.WriteLine(ex.ToString()); } return tempValue; }