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

📄 xsth.pas

📁 这是用Delphi编写的中小企业管理系统
💻 PAS
📖 第 1 页 / 共 3 页
字号:
         bg.Cells[cbj,Row]:= Format('%8.4f',[CalculateCB(Trim(Data.Query1.FieldByName('spdm').AsString))]);
         bg.Cells[bzsj,Row]:= Format('%8.4f',[querybzsj(bg.Cells[spdm,Row])]);
         if Row = 1 then
           bg.Cells[zk,Row]:= '1.0';
         bg.SetFocus;
         bg.Col := bg.Col+1;
       end;
  end;
  Grid1.Visible := False;
end;

procedure Tf_xsth.Grid1Exit(Sender: TObject);
begin
  Grid1.Visible := False;
end;

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

procedure Tf_xsth.bgKeyPress(Sender: TObject; var Key: Char);
var
  i: Boolean;
begin
  if Col = sl then  //防止在数量单元格输入非法字符
  begin
    i := (Key<#8)or(Key>#8)and(Key<#48)or(Key>#57);
    if i then
      Key := #0;
  end
  else if Col = zk then
  begin
    i := (Key<#8)or(Key>#8)and(Key<#46)or(Key>#46)and(Key<#48)or(Key>#57);
    if i then
      Key := #0;
  end;
end;

procedure Tf_xsth.bgKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  Rect1: TRect;
  col1,row1: 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 Row<>bg.RowCount-1 then
        begin
          For row1 := Row+1to (bg.RowCount-1) do
            For col1:=0 to bg.ColCount-1 do
              bg.Cells[col1,row1-1]:= bg.Cells[col1,row1];
        end;
        ClearEndRow;
        bg.RowCount := bg.RowCount-1;
      end
      else
        bg.Cells[zk,Row]:= '1.0';
      thxj.Text := Format('%8.4f',[GroupPrice]);
      bg.SetFocus;
      bg.Col := spdm;
    end;
  end;
  if (Key= vk_insert)and(CurrentIsNull = False)and(Row = bg.RowCount-1) then  //添加新行
  begin
    bg.RowCount := bg.RowCount+1;
    bg.Row:= Bg.Row+1;
    bg.Cells[zk,Row]:='1.0';
    bg.Col:=spdm;
    exit;
  end;
  if Key = vk_Return then    //查询定位计算数据
  begin
    if Grid1.Visible = True then
      Grid1.Visible := False;
    if Col = bzq then
    begin
      Rect1 := bg.CellRect(bzq,Row);
      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 (Col = Kcmc)and(Trim(bg.Cells[Kcmc,Row])<>'')and(bg.Cells[jbdw,Row]<>'') then //不在列表中选择,直接输入库存信息时,判断库存信息是否存在
    begin
      With Data.Query1 do
      begin
        Close;
        SQL.Clear;
        SQL.Add('select * from t_kcjcxx where (kcdm = :a or kcmc = :a )and kclb in(select spzl from t_spjcxx where spdm = :c)');
        ParamByName('a').AsString := Trim(bg.Cells[Kcmc,Row]);
        ParamByName('c').AsString := Trim(bg.Cells[spdm,Row]);
        Open;
      end;
      if Data.Query1.RecordCount>0 then
      begin
        bg.Cells[kcmc,Row]:= Trim(Data.Query1.Fields[1].AsString);
        bg.Cells[kclb,Row]:= Trim(Data.Query1.Fields[2].AsString);
        bg.SetFocus;
        bg.Col := bg.Col+1;
      end
      else
      begin
        kc := True;
        bg.Cells[kclb,Row]:='';
        bg.Cells[kcmc,Row]:='';
      end;
    end
    else if (Col = spdm)and(Trim(bg.Cells[spdm,Row])<>'')then
    begin
      With Data.Query1 do
      begin
        Close;
        SQL.Clear;
        SQL.Add('select * from t_spjcxx where spdm in(select distinct spdm from t_kc where spdm  =:a)');
        ParamByName('a').AsString := Trim(bg.Cells[spdm,Row]);
        Open;
      end;
      if Data.Query1.RecordCount>0 then
      begin
        bg.Cells[spdm,Row]:= Trim(Data.Query1.Fields[0].AsString);
        bg.Cells[spmc,Row]:= Trim(Data.Query1.Fields[1].AsString);
        bg.Cells[jbdw,Row]:= Trim(Data.Query1.FieldByName('jbdw').AsString);
        bg.Cells[bzsj,Row]:= Format('%8.4f',[querybzsj(bg.Cells[spdm,Row])]);
        bg.Cells[cbj,Row]:= FloatToStr(CalculateCB(Trim(Data.Query1.FieldByName('spdm').AsString)));
        bg.SetFocus;
        bg.Col := bg.Col+1;
      end
      else
      begin
        kc := True;
        bg.Cells[spdm,Row]:='';
        bg.Cells[spmc,Row]:='';
        bg.Cells[jbdw,Row]:='';
      end;
    end
    else if (Col = spmc)and(Trim(bg.Cells[spmc,Row])<>'')and(Trim(bg.Cells[spdm,Row])='') then
    begin
      With Data.Query1 do
      begin
        Close;
        SQL.Clear;
        SQL.Add('select * from t_spjcxx where spmc = :a and spdm in(select distinct spdm from t_kc )');
        ParamByName('a').AsString := Trim(bg.Cells[spmc,Row]);
        Open;
      end;
      if Data.Query1.RecordCount>0 then
      begin
        bg.Cells[spdm,Row]:= Trim(Data.Query1.Fields[0].AsString);
        bg.Cells[spmc,Row]:= Trim(Data.Query1.Fields[1].AsString);
        bg.Cells[jbdw,Row]:= Trim(Data.Query1.FieldByName('jbdw').AsString);
        bg.Cells[bzsj,Row]:= Format('%8.4f',[querybzsj(bg.Cells[spdm,Row])]);
        bg.Cells[cbj,Row]:= FloatToStr(CalculateCB(Trim(Data.Query1.FieldByName('spdm').AsString)));
        bg.SetFocus;
        bg.Col := bg.Col+1;
      end
      else
      begin
        kc := True;
        bg.Cells[spdm,Row]:='';
        bg.Cells[spmc,Row]:='';
        bg.Cells[jbdw,Row]:='';
      end;
    end
    else
    begin
      bg.SetFocus;
      if bg.Col<bg.ColCount-1 then
        bg.Col := bg.Col+1;
    end;
  end;
end;

procedure Tf_xsth.bgSetEditText(Sender: TObject; ACol, ARow: Integer;
  const Value: String);
var
  Column1: TColumn;
  cellRect: TRect; //得到当前单元格的区域,用于定位表格
  ColNum: Integer;
begin
  if (Trim(kh.Text)='')and(kc = False) then
  begin
    Application.MessageBox('请输入客户信息.','提示',64);
    kc := True;
    kh.SetFocus;
    Exit;
  end;
  if (Trim(thr.Text)='')and(kc = False) then
  begin
    Application.MessageBox('请输入退货人.','提示',64);
    kc := True;
    thr.SetFocus;
    Exit;
  end;
  if Trim(bg.Cells[kcmc,row])<>'' then
  begin
    kh.Enabled := False;
  end;
  if (Col = kcmc)and(kc= False)and(Trim(bg.Cells[jbdw,Row])<>'') then
  begin
    With Data.Query1 do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select * from t_kcjcxx where (kcdm like :a or kcmc like :a)and kclb in(select spzl from t_spjcxx where spdm = :c)');
      ParamByName('a').AsString := Trim(bg.Cells[kcmc,Row])+ '%';
      ParamByName('c').AsString := Trim(bg.Cells[spdm,Row]);
      Open;
    end;
    if Data.Query1.RecordCount>0 then
    begin
      Grid1.Columns.Clear;
      Column1 := Grid1.Columns.Add;
      Column1.FieldName := 'kcdm';
      Column1.Title.Caption := '库存代码';
      Column1.Title.Alignment := taCenter;
      Column1.Title.Font.Color := clRed;
      Column1 := Grid1.Columns.Add;
      Column1.FieldName := 'kcmc';
      Column1.Title.Alignment := taCenter;
      Column1.Title.Font.Color := clRed;
      Column1.Title.Caption := '库存名称';
      Column1 := Grid1.Columns.Add;
      Column1.FieldName := 'kclb';
      Column1.Title.Alignment := taCenter;
      Column1.Title.Font.Color := clRed;
      Column1.Title.Caption := '库存类别';
      DataSource1.DataSet := Data.Query1;
      if Grid1.Visible = False then
      begin
        CellRect := bg.CellRect(Col,Row);
        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;
        if (Grid1.Left + Grid1.Width)>Grid1.Width then
          Grid1.Left := CellRect.Left-Grid1.Width;
        Grid1.Visible := True;
      end;
      Grid1.Tag := 1;
    end
    else
    begin
      DataSource1.DataSet := Nil;
      Grid1.Visible := False;
      Application.MessageBox('该库存信息不存在.','提示',64);
      kc := True;
      bg.Cells[kcmc,Row]:='';
      bg.Cells[kclb,Row]:='';
      bg.Col := kcmc;
    end;
  end
  else if Trim(bg.Cells[jbdw,Row])<>'' then //基本单位不为空即表示商品代码,商品名称不为空,
  begin
    if (Trim(bg.Cells[sl,Row])<>'')and(Trim(bg.Cells[cbj,Row])<>'')and(Trim(bg.Cells[zk,Row])<>'') then //数量,单价,折扣不为空
    begin
      if StrToFloat(bg.Cells[zk,Row])>1 then
      begin
        Application.MessageBox('折扣不能大于一.','提示',64);
        bg.Cells[zk,Row] := '1.0';
      end;
      if StrToFloat(bg.Cells[bzsj,Row])>0 then
        bg.Cells[je,Row]:= Format('%8.4f',[StrToInt(bg.Cells[sl,Row])*StrToFloat(bg.Cells[bzsj,row])*StrToFloat(bg.Cells[zk,Row])])
      else
      begin
        bg.Cells[je,Row]:= '';
        Application.MessageBox('该商品没有定价,不能退货.','提示',64);
        Exit;
      end;
      thxj.Text := Format('%8.4f',[GroupPrice-StrToFloat(thzr.Text)]);
      czje.Text := Format('%8.4f',[StrToFloat(thxj.Text)-StrToFloat(thzr.Text)]);
    end
    else
    begin
      kc := True;
      bg.Cells[je,Row]:='';
      if (Trim(bg.Cells[sl,Row])='')then
        bg.Cells[je,Row]:= '';
    end;
  end
  {DONE: 按商品代码查询商品信息}
  else if (Col = spdm)and(kc= false)and(Trim(bg.Cells[spmc,Row])='') then
  begin
    With Data.Query1 do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select * from t_spjcxx where spdm in(select distinct spdm from t_kc where spdm like :a )');
      ParamByName('a').AsString := Trim(bg.Cells[spdm,Row])+'%';
      Open;
    end;
    if Data.Query1.RecordCount>0 then
    begin
      Grid1.Columns.Clear;
      For ColNum := 0 to 2 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 := 'jbdw';
               Column1.Title.Caption := '基本单位';
             end;
        end;
      end;
      DataSource1.DataSet := Data.Query1;
      if Grid1.Visible = False then
      begin
        CellRect := bg.CellRect(Col,Row);
        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 (Col = spmc)and(kc= false)and(Trim(bg.Cells[spdm,Row])='') then
  begin
    With Data.Query1 do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select * from t_spjcxx where  spmc like :a  and spdm in(select distinct spdm from t_kc)');
      ParamByName('a').AsString := Trim(bg.Cells[spmc,Row])+'%';
      Open;
    end;
    if Data.Query1.RecordCount>0 then
    begin
      Grid1.Columns.Clear;
      For ColNum := 0 to 2 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 := 'jbdw';
               Column1.Title.Caption := '基本单位';
             end;
        end;
      end;
      DataSource1.DataSet := Data.Query1;
      if Grid1.Visible = False then
      begin
        CellRect := bg.CellRect(Col,Row);
        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_xsth.TimerClick(Sender: TObject);
var
  Key: Word;
begin
  Key := vk_Return;
  Timer.OnKeyDown(Nil,key,[ssctrl]);
end;
procedure Tf_xsth.TimerExit(Sender: TObject);
begin
  Timer.Visible := False;
  bg.SetFocus;
  bg.Col := je;
  bg.Col := bzq;
end;

procedure Tf_xsth.TimerKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = vk_Return then
  begin
    if timer.DateTime<=Now then
    begin
      Application.MessageBox('保质期不能小于等于当前时间.','提示',64);
      Exit;
    end;
    bg.Cells[bzq,Row]:= FormatDateTime('yyyy-mm-dd',timer.Date);
    Timer.Visible := False;
    bg.SetFocus;
    bg.Col := bg.Col+1;
  end;
end;

procedure Tf_xsth.FormShow(Sender: TObject);
begin
  sj.Date := Now;
  timer.Date := Now;
  Row := 1;
  Col := 0;
end;

function Tf_xsth.Isgq: Boolean;
var
  i: Integer;
begin
  Result := False;
  For i := 1 to bg.RowCount-1 do
  begin
    if Trim(bg.Cells[bzq,i])<>'' then
      if StrToDateTime(bg.Cells[bzq,i])<Now then
      begin
        Result := True;
        Break;
      end;
  end;
end;

procedure Tf_xsth.FormCreate(Sender: TObject);
var
  i: Integer;
begin
  SetWindowLong(tc.Handle,gwl_style,getwindowlong(tc.Handle,gwl_style)or bs_multiline);
  tc.Caption := '退'+ #13 +'出';
  Sumzdkd := 0;
  For i := 0 to zds-1 do
  begin
    Azdkd[i]:= 1;
    sumzdkd := Sumzdkd+ Azdkd[i];
  end;
  Rowzdkd := Cols*(Sumzdkd/zds);
end;

procedure Tf_xsth.thzrChange(Sender: TObject);
begin
  if Trim(thzr.Text)<>'' then
  begin

⌨️ 快捷键说明

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