Q&A

  • SQL Update 이중 입력?
procedure TfrmOrder.BtnOSettlementClick(Sender: TObject);
begin
        frmSettlement:=TfrmSettlement.Create(Application);
        if frmSettlement.ShowModal = mrOK then
        begin
        with OQuery do
                begin
                        Close;
                        SQL.Clear;
                        SQL.Add('Update jajaeorder');
                        SQL.Add(' Set 공사명 = :VL공사명, 공사번호 = :VL공사번호 ');
                        SQL.Add(', 발주처 = :VL발주처, 정산사항 = :VL정산사항 ');
                        SQL.Add(', 품목 = :VL품목, 규격 = :VL규격 ');
                        SQL.Add(', 폭 = :VL폭, 길이 = :VL길이 ');
                        SQL.Add(', 재질 = :VL재질, jajaeorder."수량" = :VL수량 ' );
                        SQL.Add(', 단위 = :VL단위, jajaeorder."단가" = :VL단가 ' );
                        SQL.Add(', 입고여부 = :VL입고여부, 입고완료일 = :VL입고완료일 ');
                        SQL.Add(', 결제여부 = :VL결제여부, 결제완료일 = :VL결제완료일 ');
                        SQL.Add(', 입고요청일 = :VL입고요청일, 비고 = :VL비고 ');
                        SQL.Add(', jajaeorder."중량" = :VL중량, jajaeorder."금액" = :VL금액 ' );
                        SQL.Add(' Where jajaeorder."Index" = :VLNo');
                                ParamByName('VLNo').AsInteger:= StrToInt(frmSettlement.Edit19.Text);
                                ParamByName('VL공사명').AsString:= frmSettlement.Edit1.Text;
                                ParamByName('VL공사번호').AsString:= frmSettlement.Edit2.Text;
                                ParamByName('VL정산사항').AsString:= frmSettlement.Edit4.Text;
                                ParamByName('VL품목').AsString:= frmSettlement.Edit5.Text;
                                ParamByName('VL규격').AsString:= frmSettlement.Edit6.Text;
                                ParamByName('VL폭').AsString:= frmSettlement.Edit7.Text;
                                ParamByName('VL길이').AsString:= frmSettlement.Edit8.Text;
                                ParamByName('VL재질').AsString:= frmSettlement.Edit9.Text;
                                ParamByName('VL수량').AsInteger:= StrToInt(frmSettlement.Edit10.Text);
                                ParamByName('VL단위').AsString:= frmSettlement.Edit11.Text;
                                ParamByName('VL중량').AsInteger:= StrToInt(frmSettlement.Edit12.Text);
                                ParamByName('VL단가').AsCurrency:= StrToFloat(frmSettlement.Edit13.Text);
                                ParamByName('VL발주처').AsString:= frmSettlement.Edit15.Text;
                                ParamByName('VL입고요청일').AsString:= DateToStr(frmSettlement.DateTimePicker2.Date);
                                ParamByName('VL비고').AsString:= frmSettlement.Edit17.Text;
                                ParamByName('VL금액').AsCurrency:= StrToInt(frmSettlement.Edit12.Text) * StrToFloat(frmSettlement.Edit13.Text);
                                ParamByName('VL입고여부').AsString:= frmSettlement.ComboBox1.Text;
                                ParamByName('VL입고완료일').AsString:= DateToStr(frmSettlement.DateTimePicker3.Date);
                                ParamByName('VL결제여부').AsString:= frmSettlement.ComboBox2.Text;
                                ParamByName('VL결제완료일').AsString:= DateToStr(frmSettlement.DateTimePicker1.Date);
                end;

                if not OQuery.Prepared then
                        OQuery.Prepare;
                OQuery.ExecSQL;
                OQuery.Close;
                frmSettlement.ComboBox1Change(Sender);

                OQuery.SQL.Clear;
                OQuery.SQL.Add('Select * from jajaeorder');
                OQuery.Open;
        end;
end;

--------------------------------------

procedure TfrmSettlement.ComboBox1Change(Sender: TObject);
begin
        with frmOrder.OQuery do
                begin
                        Close;
                        SQL.Clear;
                        SQL.Add('Update jajaeorder');
                        SQL.Add('Set 입고여부 = :VL입고여부, 입고완료일 = :VL입고완료일 ');
                        SQL.Add(', 결제여부 = :VL결제여부, 결제완료일 = :VL결제완료일 ');
                        SQL.Add(' Where jajaeorder."Index" = :VLNo');

                        if ComBoBox1.ItemIndex = 0 then
                                ComboBox2.Enabled:= True;
                                ComboBox2Change(Sender);
                                DateTimePicker3.Enabled:= True;

                                begin
                                ParamByName('VLNo').AsInteger:= StrToInt(frmSettlement.Edit19.Text);
                                ParamByName('VL입고여부').AsString:= frmSettlement.ComboBox1.Text;
                                ParamByName('VL입고완료일').AsString:= DateToStr(frmSettlement.DateTimePicker3.Date);
                                ParamByName('VL결제여부').AsString:= '';
                                ParamByName('VL결제완료일').AsString:= '';
                                end;

                        if ComboBox1.ItemIndex = 1 then
                                DateTimePicker3.Enabled:= False;
                                ComboBox2.Enabled:= False;
                                DateTimePicker1.Enabled:= False;

                                begin
                                ParamByName('VLNo').AsInteger:= StrToInt(frmSettlement.Edit19.Text);
                                ParamByName('VL입고여부').AsString:= '';
                                ParamByName('VL입고완료일').AsString:= '';
                                ParamByName('VL결제여부').AsString:= '';
                                ParamByName('VL결제완료일').AsString:= '';
                                end;
                end;

                if not frmOrder.OQuery.Prepared then frmOrder.OQuery.Prepare;
                frmOrder.OQuery.ExecSQL;
                frmOrder.OQuery.Close;

                frmOrder.OQuery.SQL.Clear;
                frmOrder.OQuery.SQL.Add('Select * from jajaeorder');
                frmOrder.OQuery.Open;
end;


조건에 따라 필드값 입력이 변견되게끔 코딩을 해보았습니다.
밑에 문에서 ComboBox1.ItemIndex 값이 0 일때와 1일때 부분 필드만 변경을 하려고 하는데..
아무래도 똑같은 값을 두번 처리하게끔 해서 인지 실행해서 0 이나 1을 선택하면 애러 발생입니다.
ㅠ_ㅠ

도와주세요 ㅠ_ㅠ
2  COMMENTS
  • Profile
    정경철 2006.12.12 22:39
    if 문에 Bigin이 좀 이상한거 갔아서 다음과 같이 고쳤습니다.

    if ComBoBox1.ItemIndex = 0 then
    begin
        ComboBox2.Enabled:= True;
        ComboBox2Change(Sender);
        DateTimePicker3.Enabled:= True;

        ParamByName('VLNo').AsInteger:= StrToInt(frmSettlement.Edit19.Text);
        ParamByName('VL입고여부').AsString:= frmSettlement.ComboBox1.Text;
        ParamByName('VL입고완료일').AsString:= DateToStr(frmSettlement.DateTimePicker3.Date);
        ParamByName('VL결제여부').AsString:= '';
        ParamByName('VL결제완료일').AsString:= '';
    end;

    if ComboBox1.ItemIndex = 1 then
    begin
        ateTimePicker3.Enabled:= False;
        ComboBox2.Enabled:= False;
        DateTimePicker1.Enabled:= False;

        ParamByName('VLNo').AsInteger:= StrToInt(frmSettlement.Edit19.Text);
        ParamByName('VL입고여부').AsString:= '';
        ParamByName('VL입고완료일').AsString:= '';
        ParamByName('VL결제여부').AsString:= '';
        ParamByName('VL결제완료일').AsString:= '';
    end;
  • Profile
    윤정운 2006.12.17 07:53
    좋은 힌트가 되었습니다.

    감사합니다.