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

📄 cgjh.pas

📁 这是用Delphi编写的中小企业管理系统
💻 PAS
📖 第 1 页 / 共 4 页
字号:
        CellRect := bg.CellRect(Col1,Row1);
        CellRect.Left := CellRect.Left+bg.Left;
        CellRect.Right := CellRect.Right+ bg.Left;
        CellRect.Top := bg.Top+ CellRect.Top;
        Grid1.Left := CellRect.Right+1;
        Grid1.Top := CellRect.Top;
        Grid1.Visible := True;
      end;
      Grid1.Tag := 1;
    end
    else
    begin
      DataSource1.DataSet := Nil;
      Grid1.Visible := False;
      Application.MessageBox('该库存信息不存在.','提示',64);
      kc := True;
      bg.Cells[ckmc,Row1]:='';
      bg.Col := ckmc;
    end;
  end 
  {todo 按商品代码查询商品信息}
  else if (Col1 = spdm)and(kc= false)and(Trim(bg.Cells[spmc,Row1])='') then
  begin
    With Data.Query1 do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select * from t_spjcxx where spdm like :a and cs = :b and spzl = :c');
      ParamByName('a').AsString := Trim(bg.Cells[spdm,Row1])+ '%';
      paramByName('b').AsString := Trim(cs.Text);
      paramByName('c').AsString := Trim(bg.Cells[cklb,Row1]);
      Open;
    end;
    if Data.Query1.RecordCount>0 then
    begin
      Grid1.Columns.Clear;
      //在数据表格中需要显示6个字段
      For ColNum := 0 to 5 do
      begin
        Column1 := Grid1.Columns.Add;
        Column1.Title.Alignment := taCenter;
        Column1.Title.Font.Color := clRed;
        Case ColNum of
          0: begin
               Column1.FieldName := 'spdm';
               Column1.Title.Caption := '商品代码';
             end;
          1: begin
               Column1.FieldName := 'spmc';
               Column1.Title.Caption := '商品名称';
             end;
          2: begin
               Column1.FieldName := 'cgdw';
               Column1.Title.Caption := '采购单位';
             end;
          3: begin
               if (Trim(ksb.Text)= '应税内含')or(Trim(ksb.Text)= '其他(税内含)') then
               begin
                 Column1.FieldName := 'hsj';
                 Column1.Title.Caption := '含税价';
               end
               else
               begin
                 Column1.FieldName := 'wsj';
                 Column1.Title.Caption := '未税价';
               end;
             end;
          4: begin
               Column1.FieldName := 'sl';
               Column1.Title.Caption := '税率';
             end;
          5: begin
               Column1.FieldName := 'se';
               Column1.Title.Caption := '税额';
             end;
        end;
      end;
      DataSource1.DataSet := Data.Query1;
      if Grid1.Visible = False then
      begin
        CellRect := bg.CellRect(Col1,Row1);
        CellRect.Left := CellRect.Left+bg.Left;
        CellRect.Right := CellRect.Right+ bg.Left;
        CellRect.Top := bg.Top+ CellRect.Top;
        Grid1.Left := CellRect.Right+1;
        Grid1.Top := CellRect.Top;
        Grid1.Visible := True;
      end;
    end;
    Grid1.Tag := 2;
  end
  { DONE : 按商品名称查找商品信息 }
  else if (Col1 = spmc)and(kc= false)and(Trim(bg.Cells[spdm,Row1])='') then
  begin
    With Data.Query1 do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select * from t_spjcxx where spmc like :a and cs = :b and spzl = :c');
      ParamByName('a').AsString := Trim(bg.Cells[spmc,Row1])+ '%';
      paramByName('b').AsString := Trim(cs.Text);
      ParamByName('c').AsString := Trim(bg.Cells[cklb,Row1]);
      Open;
    end;
    if Data.Query1.RecordCount>0 then
    begin
      Grid1.Columns.Clear;
      //在数据表格中需要显示6个字段
      For ColNum := 0 to 5 do
      begin
        Column1 := Grid1.Columns.Add;
        Column1.Title.Alignment := taCenter;
        Column1.Title.Font.Color := clRed;
        Case ColNum of
          0: begin
               Column1.FieldName := 'spdm';
               Column1.Title.Caption := '商品代码';
             end;
          1: begin
               Column1.FieldName := 'spmc';
               Column1.Title.Caption := '商品名称';
             end;
          2: begin
               Column1.FieldName := 'cgdw';
               Column1.Title.Caption := '采购单位';
             end;
          3: begin
               if (Trim(ksb.Text)= '应税内含')or(Trim(ksb.Text)= '其他(税内含)') then
               begin
                 Column1.FieldName := 'hsj';
                 Column1.Title.Caption := '含税价';
               end
               else
               begin
                 Column1.FieldName := 'wsj';
                 Column1.Title.Caption := '未税价';
               end;
             end;
          4: begin
               Column1.FieldName := 'sl';
               Column1.Title.Caption := '税率';
             end;
          5: begin
               Column1.FieldName := 'se';
               Column1.Title.Caption := '税额';
             end;
        end;
      end;
      DataSource1.DataSet := Data.Query1;
      if Grid1.Visible = False then
      begin
        CellRect := bg.CellRect(Col1,Row1);
        CellRect.Left := CellRect.Left+bg.Left;
        CellRect.Right := CellRect.Right+ bg.Left;
        CellRect.Top := bg.Top+ CellRect.Top;
        Grid1.Left := CellRect.Right+1;
        Grid1.Top := CellRect.Top;
        Grid1.Visible := True;
      end;
    end;
    Grid1.Tag := 2;
  end;
end;

procedure Tf_cgjh.bgKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  Rect1: TRect;
  col,row: integer;
begin
  kc:= False;
  if (Key = vk_shift)and(Grid1.Visible = True) then //显示网格
  begin
    Grid1.SetFocus;
    Exit;
  end;
  if Key = vk_Delete then //删除当前记录
  begin
    if Application.MessageBox('确实要删除当前记录吗?','提示',mb_YesNo)=ID_Yes then
    begin
      ClearCurrentRow;
      if bg.RowCount>2 then
      begin
        if Row1<>bg.RowCount-1 then
        begin
          For row := Row1+1to (bg.RowCount-1) do
            For col:=0 to bg.ColCount-1 do
              bg.Cells[col,row-1]:= bg.Cells[col,row];
        end;
        ClearEndRow;
        bg.RowCount := bg.RowCount-1;
      end
      else
        bg.Cells[zk,Row1]:= '1.0';
      jhxj.Text := Format('%8.4f',[GroupPrice]);
      jhse.Text := Format('%8.4f',[GroupTax]);
      bg.SetFocus;
      bg.Col := ckmc;
    end;
  end;
  if (Key= vk_insert)and(CurrentIsNull = False)and(Row1 = bg.RowCount-1) then  //添加新行
  begin
    bg.RowCount := bg.RowCount+1;
    bg.Row:= Bg.Row+1;
    bg.Cells[zk,Row1]:='1.0';
    bg.Col:=ckmc;
    exit;
  end;
  if Key = vk_Return then    //查询定位计算数据
  begin
    if Grid1.Visible = True then
      Grid1.Visible := False;
    if Col1 = bzq then //当当前字段为保质期时,按回车键显示时间控件
    begin
      Rect1 := bg.CellRect(bzq,Row1);
      Rect1.Left := Rect1.Left+bg.left;
      Rect1.Right :=Rect1.Right+bg.Left;
      Rect1.Top := bg.Top+ Rect1.Top;
      timer.Left := Rect1.Left;
      timer.Top := Rect1.Top+1;
      timer.Height := bg.DefaultRowHeight;
      timer.Visible := True;
      timer.SetFocus;
      Exit;
    end;
    if Trim(bg.Cells[ckmc,Row1])='' then
      Exit;
    if (Col1 = ckmc)and(Trim(bg.Cells[ckmc,Row1])<>'') then //不在列表中选择,直接输入库存信息时,判断库存信息是否存在
    begin
      With Data.Query1 do
      begin
        Close;
        SQL.Clear;
        SQL.Add('select * from t_kcjcxx where kcdm = :a or kcmc = :a');
        ParamByName('a').AsString := Trim(bg.Cells[ckmc,Row1]);
        Open;
      end;
      if Data.Query1.RecordCount>0 then
      begin
        bg.Cells[ckmc,Row1]:= Trim(Data.Query1.Fields[1].AsString);
        bg.Cells[cklb,Row1]:= Trim(Data.Query1.Fields[2].AsString);
        if Row1 = 1 then
          bg.Cells[zk,row1]:='1.0';
        bg.SetFocus;
        bg.Col := bg.Col+1;
      end
      else
      begin
        kc := True;
        bg.Cells[ckmc,Row1]:='';
      end;
    end
    else if (Col1 = spdm)and(Trim(bg.Cells[spdm,Row1])<>'')and(Trim(bg.Cells[ckmc,Row1])<>'') then
    begin
      With Data.Query1 do
      begin
        Close;
        SQL.Clear;
        SQL.Add('select * from t_spjcxx where spdm = :a and spzl = :b ');
        ParamByName('a').AsString := Trim(bg.Cells[spdm,Row1]);
        ParamByName('b').AsString := Trim(bg.Cells[cklb,Row1]);
        Open;
      end;
      if Data.Query1.RecordCount>0 then
      begin
        bg.Cells[spdm,Row1]:= Trim(Data.Query1.Fields[0].AsString);
        bg.Cells[spmc,Row1]:= Trim(Data.Query1.Fields[1].AsString);
        if (Trim(ksb.Text)='应税内含')or(Trim(ksb.Text)='其他(税内含)') then
        begin
          bg.Cells[dj,Row1]:= Trim(Data.Query1.FieldByName('hsj').AsString);
          if  Trim(ksb.Text)='应税内含' then
            bg.Cells[sl,Row1]:= Trim(Data.Query1.FieldByName('sl').AsString)
          else
            bg.Cells[sl,Row1]:= '0.0';
        end
        else // (Trim(ksb.Text)='应税外加')or(Trim(ksb.Text)='其他(税外加)')then
        begin
          bg.Cells[dj,Row1]:= Trim(Data.Query1.FieldByName('wsj').AsString);
          if Trim(ksb.Text)='应税外加' then
            bg.Cells[sl,Row1]:= Trim(Data.Query1.FieldByName('sl').AsString)
          else
            bg.Cells[sl,Row1]:='0.0';
        end;
        //else //免税
        bg.Cells[jbdw,Row1]:= Trim(Data.Query1.FieldByName('jbdw').AsString);
        bg.Cells[cgdw,Row1]:= Trim(Data.Query1.FieldByName('cgdw').AsString);
        bg.SetFocus;
        bg.Col := bg.Col+1;
      end
      else
      begin
        kc := True;
        bg.Cells[spdm,Row1]:='';
        bg.Cells[spmc,Row1]:='';
        bg.Cells[cgdw,Row1]:='';
      end;
    end
    else if (Col1 = spmc)and(Trim(bg.Cells[spmc,Row1])<>'')and(Trim(bg.Cells[spdm,Row1])='')and(Trim(bg.Cells[ckmc,Row1])<>'') then
    begin
      With Data.Query1 do
      begin
        Close;
        SQL.Clear;
        SQL.Add('select * from t_spjcxx where spmc = :a and spzl = :b ');
        ParamByName('a').AsString := Trim(bg.Cells[spmc,Row1]);
        ParamByName('b').AsString := Trim(bg.Cells[cklb,Row1]);
        Open;
      end;
      if Data.Query1.RecordCount>0 then
      begin
        bg.Cells[spdm,Row1]:= Trim(Data.Query1.Fields[0].AsString);
        bg.Cells[spmc,Row1]:= Trim(Data.Query1.Fields[1].AsString);
        bg.Cells[jbdw,Row1]:= Trim(Data.Query1.FieldByName('jbdw').AsString);
        if (Trim(ksb.Text)='应税内含')or(Trim(ksb.Text)='其他(税内含)') then
        begin
          bg.Cells[dj,Row1]:= Trim(Data.Query1.FieldByName('hsj').AsString);
          if  Trim(ksb.Text)='应税内含' then
            bg.Cells[sl,Row1]:= Trim(Data.Query1.FieldByName('sl').AsString)
          else
            bg.Cells[sl,Row1]:= '0.0';
        end
        else //if (Trim(ksb.Text)='应税外加')or(Trim(ksb.Text)='其他(税外加)')then
        begin
          bg.Cells[dj,Row1]:= Trim(Data.Query1.FieldByName('wsj').AsString);
          if Trim(ksb.Text)='应税外加' then
            bg.Cells[sl,Row1]:= Trim(Data.Query1.FieldByName('sl').AsString)
          else
            bg.Cells[sl,Row1]:='0.0';
        end;
        //else 免税
        bg.Cells[jbdw,Row1]:= Trim(Data.Query1.FieldByName('jbdw').AsString);
        bg.Cells[cgdw,Row1]:= Trim(Data.Query1.FieldByName('cgdw').AsString);
        bg.SetFocus;
        bg.Col := bg.Col+1;
      end
      else
      begin
        kc := True;
        bg.Cells[spdm,Row1]:='';
        bg.Cells[spmc,Row1]:='';
        bg.Cells[cgdw,Row1]:='';
      end;
    end
    else
    begin
      bg.SetFocus;
      if bg.Col<bg.ColCount-1 then
        bg.Col := bg.Col+1;
    end;
  end;
end;

procedure Tf_cgjh.Grid1DblClick(Sender: TObject);
begin
  Case Grid1.Tag of
    1: begin
         bg.Cells[ckmc,Row1]:= Trim(Data.Query1.FieldByName('kcmc').AsString);
         bg.Cells[cklb,Row1]:= Trim(Data.Query1.FieldByName('kclb').AsString);
         if Row1 = 1 then
           bg.Cells[zk,Row1]:= '1.0';
         bg.SetFocus;
         bg.Col := bg.Col+1;
       end;
    2: begin
         bg.Cells[spdm,Row1]:= Trim(Data.Query1.FieldByName('spdm').AsString);
         bg.Cells[spmc,Row1]:= Trim(Data.Query1.FieldByName('spmc').AsString);
         bg.Cells[cgdw,Row1]:= Trim(Data.Query1.FieldByName('cgdw').AsString);
         bg.Cells[jbdw,Row1]:= Trim(Data.Query1.FieldByName('jbdw').AsString);
         if (Trim(ksb.Text)='应税内含')or(Trim(ksb.Text)='其他(税内含)') then
         begin
           bg.Cells[dj,Row1]:= Trim(Data.Query1.FieldByName('hsj').AsString);
          if  Trim(ksb.Text)='应税内含' then
            bg.Cells[sl,Row1]:= Trim(Data.Query1.FieldByName('sl').AsString)
          else
            bg.Cells[sl,Row1]:= '0.0';
         end
         else //if (Trim(ksb.Text)='应税外加')or(Trim(ksb.Text)='其他(税外加)')then
         begin
           bg.Cells[dj,Row1]:= Trim(Data.Query1.FieldByName('wsj').AsString);
           if Trim(ksb.Text)='应税外加' then
             bg.Cells[sl,Row1]:= Trim(Data.Query1.FieldByName('sl').AsString)
           else
             bg.Cells[sl,Row1]:='0.0';
         end;
         bg.SetFocus;
         bg.Col := bg.Col+1;
       end;
  end;
  Grid1.Visible := False;
end;

procedure Tf_cgjh.Grid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = vk_Return then
    Grid1.OnDblClick(Sender);
end;

function Tf_cgjh.CurrentIsNull: Boolean;
var
  a: Integer;
begin
  Result := False;
  For a:= 0 to bg.ColCount -1 do
  begin
    if Trim(bg.Cells[a,Row1])='' then
    begin
      Result := True;
      Break;
    end;
  end;
end;
  

⌨️ 快捷键说明

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