⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 修改中 contract.pas

📁 主要是介绍DELPHI三层应用以及分布式数据库的应用
💻 PAS
📖 第 1 页 / 共 3 页
字号:
  with Query_contract_client  do
  begin
    if active then close;
    unprepare;
    sql.Clear;
    sql.Add('select distinct 客户名称  from pub_z_client');
    prepare;
    open;
    DBComboBox1.Items.Clear;
    while not eof do
    begin
      DBComboBox1.Items.Add(fieldbyname('客户名称').AsString);
      next;
    end;
  end;
end;

procedure TForm_contract.FormKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then //如果是一个Enter键盘
  begin
    if not (ActiveControl is TDBGrid) then  //如果当前的控件不是TDBGrid
    begin
       Key := #0;
       Perform(WM_NEXTDLGCTL, 0, 0); { move to next control }
    end
    else if (ActiveControl is TDBGrid) then //在TDBGrid中
    begin
       with TDBGrid(ActiveControl) do
       begin
         if selectedindex <(fieldcount -1) then //如果不是最后一个字段
            selectedindex := selectedindex +1
         else
            selectedindex := 0;
       end;
   end;
end;
end;



procedure TForm_contract.DBComboBox5Exit(Sender: TObject);
begin

//DBRadioGroup1.ItemIndex :=0;
DBRadioGroup1.SetFocus;
end;

procedure TForm_contract.DBComboBox1Exit(Sender: TObject);
var
aaa: string;
intb: integer;
begin
  if DBComboBox1.Items.IndexOf(DBComboBox1.Text )< 0 then//not find records
     begin //1
     if  dm_wxp.Table_contract.State = dsInsert  then //yes  /add new //保留text 值
       begin //
             aaa:= DBComboBox1.Text ;
             if MessageBox(handle,'此客户名称不存在, 是否要输入一个新的客户名称?! 要输入新客户,按"是(Y)" ; 选择一个已有的客户名称,按"否(N)" ! ' , '选择客户' ,MB_IconQuestion+ MB_YESNO )= IDNO then
              begin
               //重新输入 ;
               self.DBComboBox1.SetFocus ;
               self.DBComboBox1.SelText :=aaa;
              end
             else//打开客户表,选择一个 或着新增一个,在选择一个。。。
              begin

              Unit_public_jin.form_comtract_cstm_flag:= true;// 是否可以在客户表中赋值

              Application.CreateForm(TFrm_cstm , Frm_cstm);
              Frm_cstm.Show ;

           
              end //end no
       end;
     if  dm_wxp.Table_contract.State = dsEdit  then //add new   dsEdit;//保留原来的值
       begin   //
             if MessageBox(handle,'此客户名称不存在, 是否要输入一个新的客户名称?! 要输入新客户,按"是(Y)" ; 选择一个已有的客户名称,按"否(N)" ! ' , '选择客户' ,MB_IconQuestion+ MB_YESNO )= IDNO then
             begin // 重新输入
               dm_wxp.Table_contract.FieldByName('买方名称').AsString := DBComboBox1_str;
               self.DBComboBox1.SetFocus ;
               self.DBComboBox1.SelText := DBComboBox1_str; //   DBComboBox1_str is  a public var
             end ;
       end;  //
     end //1
  else //是一个客户名称
    begin
      //根据客户名称,选择其它字段等;

    aaa:= DBComboBox1.Text ;
      // 合同编号
    with  self.Query_contract_client  do
       begin
         if active then close;
         unprepare;
         sql.Clear;
         sql.Add('select  客户号,客户地址,电话号码,传真,邮编 from pub_z_client');
         sql.Add('where  客户名称  = :khmc');
         self.Query_contract_client.ParamByName('khmc').AsString := aaa;
         prepare;
         open;
         while not eof do
            begin
               dm_wxp.Table_contract.FieldByName('客户号').AsString:=Query_contract_client.FieldByName('客户号').AsString;
               DBComboBox2.Text:= Query_contract_client.FieldByName('客户号').AsString;

               dm_wxp.Table_contract.FieldByName('买方住所').AsString:=Query_contract_client.FieldByName('客户地址').AsString;
               DBEdit5.Text:= Query_contract_client.FieldByName('客户地址').AsString;

               dm_wxp.Table_contract.FieldByName('买方电话').AsString:=Query_contract_client.FieldByName('电话号码').AsString;
               DBEdit6.Text:= Query_contract_client.FieldByName('电话号码').AsString;

               dm_wxp.Table_contract.FieldByName('买方传真').AsString:=Query_contract_client.FieldByName('传真').AsString;
               DBEdit11.Text:= Query_contract_client.FieldByName('传真').AsString;

               dm_wxp.Table_contract.FieldByName('买方邮编').AsString:=Query_contract_client.FieldByName('邮编').AsString;
               DBEdit18.Text:= Query_contract_client.FieldByName('邮编').AsString;

               next;
            end;
       end;
    //self.DBComboBox2.SetFocus ;
    self.EditDBEdit11.SetFocus;
    end;//else end;
//////////new
end;

procedure TForm_contract.Button1Click(Sender: TObject);
begin   //
 
 dm_wxp.Query_contract_machine.Append;
 dm_wxp.Query_contract_machine.FieldByName('合同号').AsString:=dm_wxp.Table_contract.fieldbyname('合同号').asstring;

end;

procedure TForm_contract.Button3Click(Sender: TObject);
begin
  dm_wxp.Query_contract_machine.ApplyUpdates ;
end;

procedure TForm_contract.Button2Click(Sender: TObject);
begin
 if application.MessageBox(pchar('确信要删除这条记录嘛?'),
        pchar('注意'),MB_OKCANCEL)=IDOK then
  dm_wxp.Query_contract_machine.Delete;
end;

procedure TForm_contract.DBComboBox7Enter(Sender: TObject);
begin
//new add
  DBComboBox1_str :=DBComboBox7.Text;//  Query_contract_client.FieldByName('客户名称').AsString;
  DBComboBox1_index:=DBComboBox7.Items.IndexOf(DBComboBox1_str) ;

  //////// ///////////////////
  //hetong hao
  with Query_contract_client  do
  begin
    if active then close;
    unprepare;
    sql.Clear;
    sql.Add('select distinct 合同号  from pub_z_contract');
    prepare;
    open;
    DBComboBox7.Items.Clear;
    while not eof do
    begin
      DBComboBox7.Items.Add(fieldbyname('合同号').AsString);
      next;
    end;
  end;
  ////////////////////
end;

procedure TForm_contract.DBComboBox7Exit(Sender: TObject);
var
aaa: string;
intb: integer;
begin
  aaa:=DBComboBox7.Text;
  if DBComboBox7.Items.IndexOf(DBComboBox7.Text )>= 0 then//not find records
  begin //1
     if  dm_wxp.Table_contract.State = dsInsert  then //yes  /add new //保留text 值
       begin //
             //aaa:= DBComboBox7.Text ;
             if MessageBox(handle,'此合同号已存在, 请重新输入一个新的合同号!', '出错:合同编号重名' ,MB_IconQuestion+ MB_OK )= IDOK then
              begin
               //重新输入 ;
               self.DBComboBox7.SelText :=aaa;
               self.DBComboBox7.SetFocus ;
              end

       end;  //dsInsert end;

     if  dm_wxp.Table_contract.State = dsEdit  then //add new   dsEdit;//保留原来的值
       begin   //
           if MessageBox(handle,'此合同号已存在, 请重新输入一个新的合同号!', '出错:合同编号重名' ,MB_IconQuestion+ MB_OK )= IDOK then
            begin // 重新输入
                  self.DBComboBox7.SelText := DBComboBox1_str; //   DBComboBox1_str is  a public var
                  self.DBComboBox7.SetFocus ;
            end ;
     end;  //
  end //1
  else
  begin
    //合同编号不能为空;
    if length(self.DBComboBox7.Text)<=0 then
       begin
         Beep;
         if MessageBox(handle,'合同号不能为空, 请重新输入合同号!', '出错:合同编号' ,MB_IconQuestion+ MB_OK )= IDOK then
         begin
         self.DBComboBox7.SetFocus;
         end
       end
     else
        begin
         self.DBComboBox1.SetFocus ;
       end;
  end;
end;//else end;




procedure TForm_contract.btn_filterfieldClick(Sender: TObject);
begin
        Application.CreateForm(TForm_search, Form_search);
        form_search.TransADO  := dm_wxp.Table_contract ;
        unit_wxp.WhichForm:=300;
        form_search.Show ;
end;

procedure TForm_contract.Button5Click(Sender: TObject);
begin

dm_wxp.Query_contract_money.Append;
dm_wxp.Query_contract_money.FieldByName('合同号').AsString:=dm_wxp.Table_contract.fieldbyname('合同号').asstring;

end;

procedure TForm_contract.Button6Click(Sender: TObject);
begin
dm_wxp.Query_contract_money.ApplyUpdates ;
end;

procedure TForm_contract.Button7Click(Sender: TObject);
begin

 if application.MessageBox(pchar('确信要删除这条记录嘛?'),
        pchar('注意'),MB_OKCANCEL)=IDOK then
 dm_wxp.Query_contract_money.Delete;
end;

procedure TForm_contract.Button4Click(Sender: TObject);
begin
     //dm_wxp.Table_contract
     dm_wxp.Table_contract.Active :=false;
     dm_wxp.Table_contract.SQL.Clear ;
     dm_wxp.Table_contract.SQL.Add('select * from pub_z_contract ');
     dm_wxp.Table_contract.Active :=true;
     unit_wxp.FinalSql:= 'select * from pub_z_contract ';
end;

procedure TForm_contract.btn_filterrecordClick(Sender: TObject);
begin
     Application.CreateForm(TQReport_contract, QReport_contract);
     QReport_contract.ADOQuery1 .Active :=false;
     QReport_contract.ADOQuery1.SQL.Clear ;
     QReport_contract.ADOQuery1.SQL.Add(unit_wxp.FinalSql );
     QReport_contract.ADOQuery1.Active :=true;
     QReport_contract.Preview ;
     QReport_contract.Free ;
end;

procedure TForm_contract.DBGrid1Enter(Sender: TObject);
begin


 if self.DBGrid1.Columns[self.DBGrid1.SelectedIndex].Fieldname ='型号' then
 begin
 with Query_contract_client  do
   begin
    if active then close;
    unprepare;
    sql.Clear;
    sql.Add('select distinct 机型 FROM std_machine');
    prepare;
    open;


    //self.DBGrid1.Columns.Items[3].PickList.clear;//机型
    self.DBGrid1.Columns[self.DBGrid1.SelectedIndex].PickList.clear;//机型

    while not eof do
    begin
       self.DBGrid1.Columns[self.DBGrid1.SelectedIndex].PickList.add(fieldbyname('机型').AsString) ;
       next;
    end;
  end;
end;
end;

procedure TForm_contract.DBGrid1ColEnter(Sender: TObject);
begin
//条件了
if self.DBGrid1.Columns[self.DBGrid1.SelectedIndex].Fieldname = '型号' then
 begin
 with Query_contract_client  do
   begin
    if active then close;
    unprepare;
    sql.Clear;
    sql.Add('select distinct 机型 FROM std_machine');
    prepare;
    open;
    //self.DBGrid1.Columns.Items[3].PickList.clear;//机型
    self.DBGrid1.Columns[self.DBGrid1.SelectedIndex].PickList.clear;//机型

    while not eof do
    begin
       self.DBGrid1.Columns[self.DBGrid1.SelectedIndex].PickList.add(fieldbyname('机型').AsString) ;
       next;
    end;
  end;
end;






end;

procedure TForm_contract.PageControl_contractChange(Sender: TObject);
begin
 self.PageControl_contract.Top := 4;
 self.VertScrollBar.Position:= 0;
 self.ScrollBox.VertScrollBar.Position:= 0;

end;

procedure TForm_contract.DBComboBox7Click(Sender: TObject);
begin
  if  dm_wxp.Table_contract.State = dsEdit  then
  begin
   //self.DBComboBox7.Hint := '合同号不能修改的!' ;
  // self.DBComboBox7.ShowHint:=true;
   //application.ShowHint:=true;
  end;



    //if MessageBox(handle,'此合同号已存在, 请重新输入一个新的合同号!', '出错:合同编号重名' ,MB_IconQuestion+ MB_OK )= IDOK then
      //          begin // 重新输入
        //          self.DBComboBox7.SelText := DBComboBox1_str; //   DBComboBox1_str is  a public var
          //        self.DBCombo

end;

procedure TForm_contract.btn_del1Click(Sender: TObject);
begin
if application.MessageBox(pchar('确信要删除这条记录嘛?'),pchar('注意'),MB_OKCANCEL)=IDOK then
   begin
    if application.MessageBox(pchar('删除这条记录,会同时删除掉此合同号的标的物,预期付款记录!,'),pchar('确认?'),MB_OKCANCEL)=IDOK then
      begin

        //,先删除从表,再删除主表;
        with dm_wxp.Query_contract_machine do
        begin
          if active then close;
           unprepare;
           parambyname('hth').AsString:=dm_wxp.Table_contract.fieldbyname('合同号').asstring;
           prepare;
           open;
           while not eof do
           begin
             dm_wxp.Query_contract_machine.Delete;
           end
       end;
       with dm_wxp.Query_contract_money do
       begin
         if active then close;
          unprepare;
         parambyname('hth').AsString:=dm_wxp.Table_contract.fieldbyname('合同号').asstring;
         prepare;
        open;
         while not eof do
         begin
           dm_wxp.Query_contract_money.Delete;
         end
       end; //删除从表 结束
       //删除主表
       dm_wxp.Table_contract.Delete;//主表
    end;
   end;
end;

procedure TForm_contract.TabSheet1Enter(Sender: TObject);
begin
self.ScrollBox.VertScrollBar.Position:=0;
end;

procedure TForm_contract.DBGrid1ColExit(Sender: TObject);
var i ,lie1,lie2,lie3: integer;
    sumall: double;
begin
//条件了

 for i:= 0 to self.DBGrid1.FieldCount-1  do
 begin
 if self.DBGrid1.Columns[i].FieldName = '台数' then lie1:= i;
 if self.DBGrid1.Columns[i].FieldName = '单价' then lie2:= i;
 if self.DBGrid1.Columns[i].FieldName = '价款' then lie3:= i;
 end ;

// if ( self.DBGrid1.Columns[self.DBGrid1.SelectedIndex].Fieldname = '台数')or(self.DBGrid1.Columns[self.DBGrid1.SelectedIndex].Fieldname = '单价') then
// begin
 //  sumall:= self.DBGrid1.Fields[lie1].Value.AsInteger* self.DBGrid1.Fields[lie2].Value.AsFloat;
 //  self.DBGrid1.Fields[lie3].Value := sumall;
 //end ;

end ;





end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -