숫자 필드 콤마 찍기 미분류

REPLACE(CONVERT(NVARCHAR(100), CONVERT(MONEY,  숫자필드), 1),  '.00',  '')

Ionic.Zip.ZipFile 사용시 한글 파일명 깨짐 현상 막기 기타

기본적으로 ZIP파일은 IBM437 Encoding을 따른다.

            using (Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile())
            {
                // 압축할 파일 리스트
                ArrayList files = GenerateFileList(압축할 파일들이 있는 폴더 패스);
               
                byte[] b = null;
                string d = null;

                foreach (string file in files)
                {
                    // 시스템의 기본 인코딩 타입으로 읽어서
                    b = System.Text.Encoding.Default.GetBytes(file);
                    // IBM437로 변환해 준다.
                    d = System.Text.Encoding.GetEncoding("IBM437").GetString(b);
                   
                    zip.AddEntry(d, "Entry에 표기될 폴더명\\", File.ReadAllBytes(file));
                   
                }

                zip.Save(생성될 ZIP파일 패스);
            }

* Ionic.Zip.dll - 1.8.4.26 버전으로 테스트 되었습니다.


NullReferenceException - EditingControls_CommonMouseEventHandler

팝업에 DataGridView가 있는데 팝업 띄워서 Row를 DoubleClick 했을 때
EditingControls_CommonMouseEventHandler에서 NullReferenceException 오류가 나면
try-catch로 잡을 수 없는 .Net 내부 오류다.


한참 동안 헤맸는데 원인은 팝업에 있던 DataGridView의 칼럼이 ReadOnly=false로 되어 있으면 이런 오류가 발생하는 것이었다.

ReadOnly=true로 해놓고 테스트한 결과 더이상 이런 오류는 나지 않았다.

C# 단색 비트맵 이미지 만들기 기타

using System.Drawing.Imaging;


Bitmap b = this.Make1bitIndexed(new Bitmap(변경할 파일명), 0.5);
// 여기까지는 화면에서 볼 때 색상만 단색 비트맵(흑,백)으로 보일 뿐이다.
// 이상태에서 그림판으로 열면 칼라를 변경할 수 있도록 되어 있다.
// 아래와 같이 해줘야지만 그림판에서 인식하는 단색 비트맵 이미지가 된다.

EncoderParameters parameters = new EncoderParameters(1);
parameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 1);

b.Save(변경된 파일명, this.getEncoderInfo("image/bmp"), parameters);


// 필요 메소드들 ==============================================================================================

public void SetIndexedPixel(int x, int y, BitmapData bmd, bool pixel)
{
    int index = y * bmd.Stride + (x >> 3);

    byte p = System.Runtime.InteropServices.Marshal.ReadByte(bmd.Scan0, index);

    byte mask = (byte)(0x80 >> (x & 0x7));

    if (pixel)
    {
        p = (byte)(p | mask);
    }
    else
    {
        p = (byte)(p & mask ^ 0xff);
    }

    System.Runtime.InteropServices.Marshal.WriteByte(bmd.Scan0, index, p);
}


public Bitmap Make1bitIndexed(Bitmap b, float brightness)
{
    Bitmap cb = new Bitmap(b.Width, b.Height, PixelFormat.Format1bppIndexed);
    BitmapData bmdn = cb.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format1bppIndexed);
    Color c = new Color();

    for (int y = 0; y < b.Height; y++)
    {
        for (int x = 0; x < b.Width; x++)
        {
            c = b.GetPixel(x, y);
            if (c.GetBrightness() > brightness)
            {
                SetIndexedPixel(x, y, bmdn, true); // set it if its bright.            
            }
        }
    }

    cb.UnlockBits(bmdn);

    return cb;
}

private ImageCodecInfo getEncoderInfo(string mimeType)
{
    // Get image codecs for all image formats
    ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();

    // Find the correct image codec
    for (int i = 0; i < codecs.Length; i++)
        if (codecs[i].MimeType == mimeType)
            return codecs[i];
    return null;
}


네오딘 sp_0055_i 테스트

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;


public class CallREST {
 public static void main(String[] args) throws Exception {
  String xml = "<?xml version='1.0' encoding='utf-8'?>  " +
     "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>" +
     "  <soap:Body>" +
     "    <SP_0055 xmlns='http://tempuri.org/'>" +
     "      <P_USER_ID>L07168</P_USER_ID>" +
     "      <P_DATE>20111115</P_DATE>" +
     "      <P_HOSPITAL_CODE>19804</P_HOSPITAL_CODE>" +
     "      <P_DEPT>6119</P_DEPT>" +
     "      <P_SEQ>5</P_SEQ>" +
     "      <P_SUB_SEQ>3</P_SUB_SEQ>" +
     "      <P_MEMO>ASDF</P_MEMO>" +
     "    </SP_0055>" +
     "  </soap:Body>" +
     "</soap:Envelope>";
  
  URL url = new URL("http://219.252.39.22:8050/mrec/sp_0055_i.asmx");
  HttpURLConnection conn = (HttpURLConnection)url.openConnection();
  OutputStreamWriter wr = null;
  
  try{
   
      conn.setDoOutput(true);
   conn.setRequestMethod("POST");
   // Header 영역에 쓰기
   conn.addRequestProperty("Content-Type", "text/xml");
      // BODY 영역에 쓰기
      wr = new OutputStreamWriter(conn.getOutputStream());
      wr.write(xml);
   wr.flush();
   wr.close();
  }catch(Exception e){
   System.out.println("============> " + e.toString());
   
   return;
  }
  
  try{
      // 리턴된 결과 읽기
      String inputLine = null;
         BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
         while ((inputLine = in.readLine()) != null) {
          System.out.println("----------> " + inputLine);
         }
         in.close();
  }catch(Exception e){
   System.out.println("============> " + e.toString());
   
   return;
  }   
 }
}


1 2 3 4 5 6 7 8 9 10 다음