Q&A

  • [질문] Query 이미지 생성 수정 저장 삭제하는 소스좀 완성좀 부탁드립니다.
안녕하십니까? 전봉수 입니다.
이미지 생성 수정 저장 삭제하는 프로그램을 처음 접하다보니 방법을 몰라서 고수님들께
고견을 듣고자 합니다.(요부분 1,2,3번 입니다.)
운영체제 Win_Xp P.R.O  Delphi 6.0  

// Query 테이블 생성
procedure TFmsThForm.MupmutbClick(Sender: TObject);
VAR
  Q1: TQUERY;
begin
  // PRIMARY INDEX FILE 및 관련 INDEX FILE 삭제하기
  IF FILEEXISTS(EXTRACTFILEPATH(APPLICATION.EXENAME)+'DATA\Mupmu.PX') THEN
    BEGIN
      DELETEFILE(EXTRACTFILEPATH(APPLICATION.EXENAME)+'DATA\Mupmu.PX');
      DELETEFILE(EXTRACTFILEPATH(APPLICATION.EXENAME)+'DATA\Mupmu.XGO');
      DELETEFILE(EXTRACTFILEPATH(APPLICATION.EXENAME)+'DATA\Mupmu.YGO');
    END;
    // 업무일지 TABLE CREATE 하기
    Q1:=TQUERY.CREATE(SELF);
    Q1.DATABASENAME:=ALIASNAME;
    Q1.SQL.CLEAR;
    Q1.SQL.ADD('CREATE TABLE "Mupmu.DB" ');
    Q1.SQL.ADD(' ( ');
    Q1.SQL.ADD(' Mdate   Date, ');                    // 작성일자
    Q1.SQL.ADD(' SEQ     NUMERIC(5,0) DEFAULT 1, ');  // 순번
    Q1.SQL.ADD(' Myoil   VARCHAR(4), ');              // 요일
    Q1.SQL.ADD(' Mnarci  VARCHAR(15), ');             // 날씨
    Q1.SQL.ADD(' Mname   VARCHAR(8), ');              // 담당자
    Q1.SQL.ADD(' Scode   VARCHAR(7), ');              // 신고부서코드
    Q1.SQL.ADD(' Hcode   VARCHAR(7), ');              // 처리부서코드
    Q1.SQL.ADD(' Memo1   BLOB(200), ');               // 명일 예정사항
    Q1.SQL.ADD(' Code1   VARCHAR(7) , ');             // 코드1
    Q1.SQL.ADD(' NAME1   VARCHAR(20), ');             // 품명1
    Q1.SQL.ADD(' SPACK1  VARCHAR(20), ');             // 규격1
    Q1.SQL.ADD(' QTY1    NUMERIC(7,0) DEFAULT 0,');   // 수량1
    Q1.SQL.ADD(' Sayong1 VARCHAR(30), ');             // 사용내역1
    Q1.SQL.ADD(' Memo2   BLOB(200), ');               // 지시사항
    Q1.SQL.ADD(' Memo3   BLOB(200), ');               // 특이사항
    Q1.SQL.ADD(' Out1    VARCHAR(5), ');              // 점검결과1
    Q1.SQL.ADD(' Joch1   VARCHAR(20), ');             // 문제점1
    Q1.SQL.ADD(' Bigo1   VARCHAR(20), ');             // 조치사항1

// 1. 요부분
//-----------------------------------------------------------------
    // 이미지 테이블 생성
    Q1.SQL.ADD(' IdImg   BLOB Graphic(200), ');       // 을측담당
    Q1.SQL.ADD(' IsImg   BLOB Graphic(200), ');       // 을츠소장
    Q1.SQL.ADD(' KdImg   BLOB Graphic(200), ');       // 갑측담당
    Q1.SQL.ADD(' KtImg   BLOB Graphic(200), ');       // 갑측팀장
//-----------------------------------------------------------------
    Q1.SQL.ADD(' PRIMARY KEY(Mdate,SEQ) ');
    Q1.SQL.ADD(' ) ');
    TRY
      Q1.ExecSQL;
    EXCEPT
      APPLICATION.MESSAGEBOX('업무일지 테이블 생성도중 에러발생!!!',
                             '알림',MB_OK+MB_ICONINFORMATION);
      Q1.Close;
      Q1.Free;
      EXIT;
    END;
    Q1.Close;

    // INDEX FILE CREATE 하기
    Q1.SQL.CLEAR;
    Q1.SQL.ADD('CREATE INDEX MupmuX1 ON "Mupmu.DB"(Mname,Mdate)');
    TRY
      Q1.ExecSQL;
    EXCEPT
      DELETEFILE(EXTRACTFILEPATH(APPLICATION.EXENAME)+'DATA\Mupmu.DB');
      DELETEFILE(EXTRACTFILEPATH(APPLICATION.EXENAME)+'DATA\Mupmu.PX');
      APPLICATION.MESSAGEBOX('업무일지 테이블 인덱스 생성도중 에러발생!!!',
                             '알림',MB_OK+MB_ICONINFORMATION);
      Q1.Close;
      Q1.Free;
      EXIT;
    END;
    Q1.Close;

    // INDEX2 FILE CREATE 하기
    Q1.SQL.CLEAR;
    Q1.SQL.ADD('CREATE INDEX Mupmu2 ON "Mupmu.DB"(SCode,Hcode,Mname,Mdate)');
    TRY
      Q1.ExecSQL;
    EXCEPT
      DELETEFILE(EXTRACTFILEPATH(APPLICATION.EXENAME)+'DATA\Mupmu.DB');
      DELETEFILE(EXTRACTFILEPATH(APPLICATION.EXENAME)+'DATA\Mupmu.PX');
      DELETEFILE(EXTRACTFILEPATH(APPLICATION.EXENAME)+'DATA\MupmuXGO');
      DELETEFILE(EXTRACTFILEPATH(APPLICATION.EXENAME)+'DATA\Mupmu.YGO');
      APPLICATION.MESSAGEBOX('업무일지 테이블 인덱스 생성도중 에러발생!!!',
                             '알림',MB_OK+MB_ICONINFORMATION);
      Q1.Close;
      Q1.Free;
      EXIT;
    END;
    Q1.Close;
    Q1.FREE;
    Mupmutb.ENABLED:=FALSE;
    ALLtB.ENABLED :=FALSE;
end;

// 디비에 저장 수정 삭제
procedure TMupmuForm.BtnSAVEClick(Sender: TObject);
VAR
  Q1  : TQUERY;
  sSQL: STRING;
  nSEQ,wYEAR,wMONTH,wDAY: WORD;
begin
  // 작성일자 점검
  IF MODETYPE = mNone THEN
    EXIT;
    TRY
      STRTODATE(TRIM(ED_MDATE.TEXT));
    EXCEPT
      ED_MDATE.TEXT:='';
      APPLICATION.MESSAGEBOX('작성일자를 정확하게 지정후 작업하세요...','작성일자 점검',
                            MB_OK+MB_ICONINFORMATION);
      EXIT;
    END;

  // 추가모드시 순번을 자동으로 구한다.
  IF MODETYPE = mAppend THEN
    nSEQ:=StrToInt(Get_Number(Get_Code_Desc('Mupmu',1,[3],
                  ['MDATE'],[ED_MDATE.TEXT],'MAX(SEQ)'))) + 1
  ELSE
    nSEQ:=StrToInt(ED_SEQ.TEXT);

  // 삭제모드시 삭제 확인 메세지
  IF (MODETYPE = mDelete) AND
    (APPLICATION.MESSAGEBOX('정말 삭제 하시겠습니까?','삭제확인',
                             MB_YESNO+MB_ICONQUESTION) <> IDYES) THEN
    EXIT;

    Q1:=TQUERY.CREATE(SELF);
    Q1.DATABASENAME:=ALIASNAME;
    Q1.SQL.CLEAR;

    CASE MODETYPE OF
      mDelete:
        BEGIN
          sSQL:='DELETE FROM Mupmu Where '+
                'MDATE = :PMDATE '+
                 FORMAT(' AND SEQ = %4d', [nSEQ]);
          Q1.SQL.ADD(sSQL);
          Q1.ParamByName('PMDATE').ASDATETIME:=STRTODATE(TRIM(ED_MDATE.TEXT));
        END;
      mUpdate: // 수정 업데이트
        BEGIN
          DECODEDATE(STRTODATE(TRIM(ED_MDATE.TEXT)),wYEAR,wMONTH,wDAY);
          sSQL:='UPDATE Mupmu Set '+
                 FORMAT(' Myoil   = ''%S''',[TRIM(ED_Myoil.TEXT)])+
                 FORMAT(',Mnarci  = ''%S''',[TRIM(Ed_Mnarci.TEXT)])+
                 FORMAT(',Mname   = ''%S''',[TRIM(Ed_Mname.TEXT)])+
                 FORMAT(',Scode   = ''%S''',[TRIM(Ed_Scode.TEXT)])+
                 FORMAT(',Hcode   = ''%s''',[TRIM(Ed_Hcode.TEXT)])+
                 FORMAT(',Memo1   = ''%S''',[TRIM(MEMO1.LINES.TEXT)])+
                 FORMAT(',Code1   = ''%S''',[TRIM(STRINGGRID1.CELLS[0,1])])+
                 FORMAT(',NAME1   = ''%s''',[TRIM(STRINGGRID1.CELLS[1,1])])+
                 FORMAT(',SPACK1  = ''%S''',[TRIM(STRINGGRID1.CELLS[2,1])])+
                 FORMAT(',QTY1    =   %7d', [STRTOINT(GET_NUMBER(STRINGGRID1.CELLS[3,1]))])+
                 FORMAT(',Sayong1 = ''%s''',[TRIM(STRINGGRID1.CELLS[4,1])])+
                 FORMAT(',Memo2   = ''%S''',[TRIM(MEMO2.LINES.TEXT)])+
                 FORMAT(',Memo3   = ''%S''',[TRIM(MEMO3.LINES.TEXT)])+
                 FORMAT(',Out1    = ''%s''',[TRIM(STRINGGRID3.CELLS[1,1])])+
                 FORMAT(',Joch1   = ''%S''',[TRIM(STRINGGRID3.CELLS[2,1])])+
                 FORMAT(',Bigo1   = ''%S''',[TRIM(STRINGGRID3.CELLS[3,1])])+
                 'Where '+
                 FORMAT('     EXTRACT (YEAR FROM MDATE) = %4d', [wYEAR])+
                 FORMAT(' AND EXTRACT(MONTH FROM MDATE) = %2d', [wMONTH])+
                 FORMAT(' AND EXTRACT(DAY   FROM MDATE) = %2d', [wDAY])+
                 FORMAT(' AND SEQ = %5d',[nSEQ]);

          Q1.SQL.ADD(sSQL);

          // 2. 요부분
          //-------------------------------------------------------------------
          // 이미지 수정
          TBlobField(Q1.FieldByNAme('IdImg')).Assign(Image5.Picture.Graphic);
          TBlobField(Q1.FieldByName('IsImg')).Assign(Image2.Picture.Graphic);
          TBlobField(Q1.FieldByName('KdImg')).Assign(Image3.Picture.Graphic);
          TBlobField(Q1.FieldByName('KtImg')).Assign(Image4.Picture.Graphic);
          //-------------------------------------------------------------------
        END;
      mAppend: //저장
        BEGIN
          sSQL:='Insert Into Mupmu (MDATE,SEQ,Myoil,Mnarci,Mname,Scode,Hcode, '+
                'MEMO1,Code1,Name1,Spack1,Qty1,Sayong1,Memo2,Memo3,Out1,Joch1, '+
                'Bigo1,IdImg,IsImg,KdImg,KtImg) '+
                'Values (:PMdate'+
                 FORMAT(',  %5d', [nSEQ])+
                 FORMAT(',''%S''',[TRIM(ED_Myoil.TEXT)])+
                 FORMAT(',''%S''',[TRIM(Ed_Mnarci.TEXT)])+
                 FORMAT(',''%S''',[TRIM(Ed_Mname.TEXT)])+
                 FORMAT(',''%S''',[TRIM(Ed_Scode.TEXT)])+
                 FORMAT(',''%s''',[TRIM(Ed_Hcode.TEXT)])+
                 FORMAT(',''%S''',[TRIM(MEMO1.LINES.TEXT)])+
                 FORMAT(',''%S''',[TRIM(STRINGGRID1.CELLS[0,1])])+
                 FORMAT(',''%s''',[TRIM(STRINGGRID1.CELLS[1,1])])+
                 FORMAT(',''%S''',[TRIM(STRINGGRID1.CELLS[2,1])])+
                 FORMAT(',  %7d', [STRTOINT(GET_NUMBER(STRINGGRID1.CELLS[3,1]))])+
                 FORMAT(',''%s''',[TRIM(STRINGGRID1.CELLS[4,1])])+
                 FORMAT(',''%S''',[TRIM(MEMO2.LINES.TEXT)])+
                 FORMAT(',''%S''',[TRIM(MEMO3.LINES.TEXT)])+
                 FORMAT(',''%S''',[TRIM(STRINGGRID3.CELLS[1,1])])+
                 FORMAT(',''%s''',[TRIM(STRINGGRID3.CELLS[2,1])])+
                 FORMAT(',''%S''',[TRIM(STRINGGRID3.CELLS[3,1])])+
               ')';
          Q1.SQL.ADD(sSQL);
          Q1.ParamByName('PMdate').ASDATETIME:=STRTODATE(TRIM(ED_MDATE.TEXT));

          // 3. 요부분
          //-------------------------------------------------------------------
          // 이미지 저장
          TBlobField(Q1.FieldByName('IdImg')).Assign(Image5.Picture.Graphic);
          TBlobField(Q1.FieldByName('IsImg')).Assign(Image2.Picture.Graphic);
          TBlobField(Q1.FieldByName('KdImg')).Assign(Image3.Picture.Graphic);
          TBlobField(Q1.FieldByName('KtImg')).Assign(Image4.Picture.Graphic);
          //-------------------------------------------------------------------
        END;
    END;
    TRY
       Q1.EXECSQL;
    EXCEPT
      Q1.CLOSE;
      Q1.FREE;
      APPLICATION.MESSAGEBOX('업무일지 TABLE 저장도중 Error 발생','저장중 오류',
                              MB_OK+MB_ICONINFORMATION);
      EXIT;
    END;
    Q1.CLOSE;
    Q1.FREE;

    // 초기화
    COMPONENTCLEAR;

    // 수정 또는 추가 자료를 화면 오른쪽에 반영
    QR_Mupmu.CLOSE;
    QR_Mupmu.OPEN;
    COMPONENTCLEAR;
    ACTIVECONTROL:=ED_MDATE;
end;
0  COMMENTS