2013년 9월 23일 월요일

Oracle 에서 Sequence 생성과 사용 ( Dual )

Unique Key 로 보통 Auto Increment 로 설정하여 사용하여도 되나, 아래와 같이 Sequence 를 생성하여 사용 할 수 있다

[생성]
CREATE SEQUENCE 시퀀스이름
  START WITH 1
  MAXVALUE 999999999
  MINVALUE 1
  NOCYCLE
  NOCACHE
  NOORDER; COMMIT;

[사용]
select 시퀀스이름.nextval from dual;

2013년 9월 22일 일요일

Byte Array to Float

[ 설명 ]
- 아래 함수면 왠만한 예외 상황은 해결
- ordering : 송신측의 상황에 따라 변경해서 사용
- IsNaN : Return Value 의 상태에 따라 적당히 사용하면 되겠다
- Math.Round : 아래 함수를 사용 할 때, Return Value 가 무한소수점이 반환 된다면, 다른 쪽에서 여러가지 문제가 발생 할 수 있다. Parameter 로 소수점 자리수를 조절해도 괜찮을 것이다. 일단 급해서 hard coding...

        public static float ByteToFloat(byte[] buf, int startIndex, int nLen, bool ordering)
        {
            try
            {
                float fRtn = 0.00f;

                byte[] tempBuf = new byte[nLen];
                Buffer.BlockCopy(buf, startIndex, tempBuf, 0, nLen);

                if (ordering == false)
                {
                    fRtn = System.BitConverter.ToSingle(tempBuf, 0);
                }
                else
                {
                    fRtn = System.BitConverter.ToSingle(tempBuf.Reverse().ToArray(), tempBuf.Length - sizeof(Single) - 0);
                }

                if (float.IsNaN(fRtn))
                    return (float)0;
                else
                {
                    return (float)Math.Round(fRtn, 2);
                }
            }
            catch
            {
                return (float)0;
            }
        }

2013년 9월 15일 일요일

ERWin7 에서 한글 Column Name Display

[환경]
 - ERWin7.2.5

1. Physical 선택 후, 여백화면에서 오른쪽 마우스 클릭 후 Harden Physical Names 선택
2. Logical 로 변경
3. 메뉴 [Model] - [Domain Dictionary] 후, Name Inherited by Attribute 항목을 "%ColumnsComment" 로 변경
4. 메뉴 [Model] - [Attributes] 선택 후, Reset 클릭, Reset all attributes in model 선택 후 Select Properties to Reset 항목은 Name 만 선택

2013년 9월 5일 목요일

c# 에서 Queue 사용

어떤 객체에 대해서, 한 곳에서 처리하기 위해 간단히 Queue 를 사용해 본다
Transaction 이 거시기 한 Cubrid( invalid buffer position 등과 같은 Exception Error ) 에, 짧은 순간 많은 쿼리를 처리 하거나 할 때...

선언
using System.Collections;
public Queue m_sqlQueue = new Queue();


구현
        public override bool SQLAdd(string sQuery)
        {
            try
            {
                m_sqlQueue.Enqueue(sQuery);
                return true;
            }
            catch (Exception ex)
            {
                MiddlewareLog.LogDebug(ex);
                return false;
            }

        }

// 아래 예제 스레드는 간단하지만, diffTick 을 20ms 으로 고정하지 않고, 짱구를 좀 굴리면 좀 더 최적화 해서 처리 할 수 있다, 여기선 Pass
        private void DoDBApply()
        {
            try
            {
                int startTick = Environment.TickCount;
                int currTick = 0;
                int diffTick = 0;
                do
                {
                    System.Threading.Thread.Sleep(1);

                    if (bShutdown == true) break;

                    currTick = Environment.TickCount;
                    diffTick = currTick - startTick;
                    if (diffTick > 20)
                    {
                        startTick = Environment.TickCount;
                        diffTick = 0;

                        if (m_sqlQueue.Count > 0)
                        {
                            object str = m_sqlQueue.Dequeue();
                            QueryExecute((string)str);
                        }
                    }
                } while (bShutdown == false);
            }
            catch
            {
            }
        }

2013년 9월 4일 수요일

Windows 부팅 시 로그인 안 물어보기

command prompt > control userpasswords2

2013년 9월 3일 화요일

Dictionary 를 Array List 처럼 사용하기

선언

public static Dictionary<string, object> jsonSPDM24n = new Dictionary<string, object>();


할당

두번째 인자인 object 에 다시 같은 형태의 Dictionary<string, object> 를 Add 메소드를 사용하여 추가하거나, Assign 해서 사용 할 수 있다

                if (jsonSPDM24n.ContainsKey(json["device_id"].ToString() + "_" + json["addressno"].ToString()) == true)
                {
                    jsonSPDM24n[json["device_id"].ToString() + "_" + json["addressno"].ToString()] = json;
                }
                else
                {
                    jsonSPDM24n.Add(json["device_id"].ToString() + "_" + json["addressno"].ToString(), json);
                }

즉, 아래와 같은 의미가 되겠다

Dictionary<string, Dictionary<string, object>>


사용

이제 이걸 꺼내서 사용하는 것은,

                foreach (KeyValuePair<string, object> temp in jsonSPDM24n)
                {
                    Dictionary<string, object> json = (Dictionary<string, object>)temp.Value;
                    if ((string)json["producttype"] == "spdm24n")
                    {
                        ....
                     }
                 }