Q&A

  • 왜 안되는지....
소스를 올립니다.

왜 안되는지 소스를 고쳐 주시면 더더욱 감사하겠습니다.



unit Unit1;



interface



uses

Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

StdCtrls, Buttons, Grids, DBGrids, Db, ADODB;



type

TForm1 = class(TForm)

DataSource1: TDataSource;

ADOQuery1: TADOQuery;

Label1: TLabel;

Label2: TLabel;

Label3: TLabel;

Edit1: TEdit;

Edit2: TEdit;

Edit3: TEdit;

Edit4: TEdit;

Edit5: TEdit;

Label4: TLabel;

Label5: TLabel;

Label6: TLabel;

Label7: TLabel;

Label8: TLabel;

Label9: TLabel;

Edit6: TEdit;

Edit7: TEdit;

Edit8: TEdit;

Label10: TLabel;

Label11: TLabel;

Label12: TLabel;

Edit9: TEdit;

Edit10: TEdit;

Edit11: TEdit;

Label13: TLabel;

Edit12: TEdit;

Label14: TLabel;

Edit13: TEdit;

DBGrid1: TDBGrid;

BitBtn1: TBitBtn;

BitBtn2: TBitBtn;

BitBtn3: TBitBtn;

BitBtn4: TBitBtn;

BitBtn5: TBitBtn;

procedure BitBtn5Click(Sender: TObject);

procedure FormCreate(Sender: TObject);

procedure BitBtn4Click(Sender: TObject);

procedure BitBtn1Click(Sender: TObject);

procedure BitBtn3Click(Sender: TObject);

procedure BitBtn2Click(Sender: TObject);

procedure DBGrid1MouseUp(Sender: TObject; Button: TMouseButton;

Shift: TShiftState; X, Y: Integer);

procedure DBGrid1KeyUp(Sender: TObject; var Key: Word;

Shift: TShiftState);

private

DB_Insert: string;

procedure DB_Refresh;

procedure DB_Input;

procedure Cls_Edit;

procedure Dsp_Edit;

procedure Move_Cell;

{ Private declarations }

public

{ Public declarations }

end;



var

Form1: TForm1;



implementation



{$R *.DFM}





procedure TForm1.DB_Refresh;

begin

ADOQuery1.Close;

ADOQuery1.SQL.Clear;

ADOQuery1.SQL.Add('Select * from year1 ');

ADOQuery1.SQL.Add('Order by 이름');

ADOQuery1.Open;

end;





procedure TForm1.DB_Input;

begin

ADOQuery1.Parameters.ParamValues['N1'] := Trim(Edit1.Text);

ADOQuery1.Parameters.ParamValues['N2'] := Trim(Edit2.Text);

ADOQuery1.Parameters.ParamValues['N3'] := Trim(Edit3.Text);

ADOQuery1.Parameters.ParamValues['N4'] := Trim(Edit4.Text);

ADOQuery1.Parameters.ParamValues['N5'] := Trim(Edit5.Text);

ADOQuery1.Parameters.ParamValues['N6'] := Trim(Edit6.Text);

ADOQuery1.Parameters.ParamValues['N7'] := Trim(Edit7.Text);

ADOQuery1.Parameters.ParamValues['N8'] := Trim(Edit8.Text);

ADOQuery1.Parameters.ParamValues['N9'] := Trim(Edit9.Text);

ADOQuery1.Parameters.ParamValues['N10'] := Trim(Edit10.Text);

ADOQuery1.Parameters.ParamValues['N11'] := Trim(Edit11.Text);

ADOQuery1.Parameters.ParamValues['N12'] := Trim(Edit12.Text);

ADOQuery1.Parameters.ParamValues['N13'] := Trim(Edit13.Text);

end;



procedure TForm1.Cls_Edit;

begin

Edit1.Text := '';

Edit2.Text := '';

Edit3.Text := '';

Edit4.Text := '';

Edit5.Text := '';

Edit6.Text := '';

Edit7.Text := '';

Edit8.Text := '';

Edit9.Text := '';

Edit10.Text := '';

Edit11.Text := '';

Edit12.Text := '';

Edit13.Text := '';

end;







procedure TForm1.Dsp_Edit;

begin

Edit1.Text := ADOQuery1.FieldbyName('이름').AsString;

Edit2.Text := ADOQuery1.FieldbyName('주민번호').AsString;

Edit3.Text := ADOQuery1.FieldbyName('주민세').AsString;

Edit4.Text := ADOQuery1.FieldbyName('소득세').AsString;

Edit5.Text := ADOQuery1.FieldbyName('의료보험').AsString;

Edit6.Text := ADOQuery1.FieldbyName('국민연금').AsString;

Edit7.Text := ADOQuery1.FieldbyName('산재보험').AsString;

Edit8.Text := ADOQuery1.FieldbyName('고용보험').AsString;

Edit9.Text := ADOQuery1.FieldbyName('기타금액').AsString;

Edit10.Text := ADOQuery1.FieldbyName('계약총액').AsString;

Edit11.Text := ADOQuery1.FieldbyName('월급(月)').AsString;

Edit12.Text := ADOQuery1.FieldbyName('총지출액').AsString;

Edit13.Text := ADOQuery1.FieldbyName('실지급액').AsString;

end;







procedure TForm1.Move_Cell;

begin

if BitBtn1.Caption = '취소(&C)' then

begin

BitBtn1.Caption := '추가(&A)';

BitBtn2.Enabled := True;

BitBtn4.Enabled := True;

DB_Insert := '불가능';

end;

Dsp_Edit;

end;









procedure TForm1.BitBtn5Click(Sender: TObject);

begin

Close;

end;



procedure TForm1.FormCreate(Sender: TObject);

begin

Cls_Edit;

Dsp_Edit;

DB_Insert := '불가능';

end;



procedure TForm1.BitBtn4Click(Sender: TObject);

var

Input_Str : String;

begin



Input_Str := InputBox('이름입력', '찾을 이름을 입력하세요','');



if Trim(Input_str) <> '' then

begin

ADOQuery1.Close;

ADOQuery1.SQL.Clear;

ADOQuery1.SQL.Add('Select * from year1 ');

ADOQuery1.SQL.Add('Where 이름 Like :NAME1');

ADOQuery1.Parameters.ParamByName('NAME1').Value := '%'+Input_Str+'%';

ADOQuery1.Open;

end;

end;



procedure TForm1.BitBtn1Click(Sender: TObject);

begin

if BitBtn1.Caption = '추가(&A)' then

begin

DB_Insert := '가능';

BitBtn1.Caption := '취소(&C)';

BitBtn2.Enabled := False;

BitBtn4.Enabled := False;

Cls_Edit;

end

else

begin

DB_Insert := '불가능';

BitBtn1.Caption := '추가(&A)';

BitBtn2.Enabled := True;

BitBtn4.Enabled := True;

DB_Refresh;

Dsp_Edit;

end;

Edit1.SetFocus;

end;



procedure TForm1.BitBtn3Click(Sender: TObject);

var

Select_no : integer;

begin

if Trim(Edit1.Text) = '' then

begin

ShowMessage('이름을 입력하지 않으면 추가나 저장을 할 수 없습니다.');

Edit1.SetFocus;

Exit;

end;



if DB_Insert = '가능' then

begin

ADOQuery1.Close;

ADOQuery1.SQL.Clear;

ADOQuery1.SQL.Add('Insert Into year1 ');

ADOQuery1.SQL.Add('(이름, 주민번호, 주민세, 소득세, 의료보험, 국민연금, 산재보험, 고용보험, 기타금액, 계약총액, 월급(月), 총지출액, 실지급액)');

ADOQuery1.SQL.Add('Values');

ADOQuery1.SQL.Add('( :N1, ');

ADOQuery1.SQL.Add(' :N2, ');

ADOQuery1.SQL.Add(' :N3, ');

ADOQuery1.SQL.Add(' :N4, ');

ADOQuery1.SQL.Add(' :N5, ');

ADOQuery1.SQL.Add(' :N6, ');

ADOQuery1.SQL.Add(' :N7, ');

ADOQuery1.SQL.Add(' :N8, ');

ADOQuery1.SQL.Add(' :N9, ');

ADOQuery1.SQL.Add(' :N10, ');

ADOQuery1.SQL.Add(' :N11, ');

ADOQuery1.SQL.Add(' :N12, ');

ADOQuery1.SQL.Add(' :N13)');

DB_Input;

DB_Insert := '불가능';

BitBtn1.Caption := '추가(&A)';

BitBtn2.Enabled := True;

BitBtn4.Enabled := True;

end

else

begin

Select_no := ADOQuery1.FieldByName('번호').AsInteger;

ADOQuery1.Close;

ADOQuery1.SQL.Clear;

ADOQuery1.SQL.Add('Update year1 ');

ADOQuery1.SQL.Add('Set 이름 = :N1, ');

ADOQuery1.SQL.Add('주민번호 = :N2, ');

ADOQuery1.SQL.Add('주민세 = :N3, ');

ADOQuery1.SQL.Add('소득세 = :N4, ');

ADOQuery1.SQL.Add('의료보험 = :N5, ');

ADOQuery1.SQL.Add('국민연금 = :N6, ');

ADOQuery1.SQL.Add('산재보험 = :N7, ');

ADOQuery1.SQL.Add('고용보험 = :N8, ');

ADOQuery1.SQL.Add('기타금액 = :N9, ');

ADOQuery1.SQL.Add('계약총액 = :N10, ');

ADOQuery1.SQL.Add('월 급(月) = :N11, ');

ADOQuery1.SQL.Add('총지출액 = :N12, ');

ADOQuery1.SQL.Add('실지급액 = :N13 ');

ADOQuery1.SQL.Add('Where 번호 = :N14');

DB_Input;

ADOQuery1.Parameters.ParamValues['N14'] := Select_no;

end;



ADOQuery1.ExecSQL;

DB_Refresh;

Edit1.SetFocus;





end;



procedure TForm1.BitBtn2Click(Sender: TObject);

var

ret_msg : integer;

Select_no : integer;

begin

if ADOQuery1.RecordCount <> 0 then

begin

ret_msg := MessageDlg('삭제하시겠습니까?', mtWarning, [mbYes, mbNo],0);

if ret_msg = mrYes then

begin

Select_no := ADOQuery1.FieldByName('번호').AsInteger;

ADOQuery1.Close;

ADOQuery1.SQL.Clear;

ADOQuery1.SQL.Add('Delete from year1 ');

ADOQuery1.SQL.Add('Where 번호 = :N1');

ADOQuery1.Parameters.ParamValues['N1'] := Select_no;

ADOQuery1.ExecSQL;

DB_Refresh;

Dsp_Edit;

end

else

Application.MessageBox('삭제가 취소되었습니다.', '삭제취소',MB_OK);



end;



end;



procedure TForm1.DBGrid1MouseUp(Sender: TObject; Button: TMouseButton;

Shift: TShiftState; X, Y: Integer);

begin

if Button = mbLeft then

Move_Cell;

end;



procedure TForm1.DBGrid1KeyUp(Sender: TObject; var Key: Word;

Shift: TShiftState);

begin

if (key >= 33) And (key <= 40) then

Move_Cell;

end;



end.



0  COMMENTS