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

📄 spckgl.pas

📁 《仓库管理系统》 开发语言:Delphi7.0 数据库:SQLServer2000 数据库文件:仓库管理系统_Data.MDF,仓库管理系统_Log.LDF(mingrisoft仓库管理系统Da
💻 PAS
📖 第 1 页 / 共 2 页
字号:
  begin
    if StringGrid1.RowCount>2 then
    begin
      If Application.MessageBox('确实要删除该条记录吗?','提示',MB_YESNO )= ID_Yes then
      begin
       if IsNull = False then
       begin
         cl := StringGrid1.Cells[2,x];
         cp := StringGrid1.Cells[3,x];
         if CurrentIsCf = False then
           Label15.Caption := IntToStr(StrToInt(Label15.Caption)-1);
       end;
        ClearStrings;
        if x <> StringGrid1.RowCount-1 then
        begin
          For r := x+1 to StringGrid1.RowCount-1 do
            For l := 0 to StringGrid1.ColCount-1 do
              StringGrid1.Cells[l,r-1]:= StringGrid1.Cells[l,r];
        end;
        ClearStringEnd;
        StringGrid1.RowCount := StringGrid1.RowCount-1;
        StringGrid1.Col := 2;
        StringGrid1.Col := 1;
        if Trim(cl)<>'' then
          Label16.Caption := IntToStr(StrToInt(Label16.Caption)- StrToInt(cl));
        if Trim(cp)<>'' then
          Label17.Caption := FloatToStr(StrToFloat(Label17.Caption)-StrToFloat(cp));
        Exit;
      end;
    end
    else if  StringGrid1.RowCount = 2 then
    begin
      If Application.MessageBox('确实要删除该条记录吗?','提示',MB_YESNO )= ID_Yes then
      begin
        ClearStrings;
        Label15.Caption := '0';
        Label16.Caption :='0';
        Label17.Caption := '0.0';
        StringGrid1.SetFocus;
        StringGrid1.Col := 1;
      end;
    end;
  end;
  if (key = Vk_Next)and(DBGrid1.Visible = True)then
  begin
    DBGrid1.SetFocus;
    Exit;
  end;
  if (Key = VK_Down)and(IsNull = False)and(x = StringGrid1.RowCount-1) then
  begin
    StringGrid1.RowCount := StringGrid1.RowCount+1;
    StringGrid1.Cells[5,StringGrid1.RowCount-1]:= StringGrid1.Cells[5,StringGrid1.RowCount-2];
    StringGrid1.Cells[6,StringGrid1.RowCount-1]:= StringGrid1.Cells[6,StringGrid1.RowCount-2];
    StringGrid1.Cells[4,StringGrid1.RowCount-1]:= StringGrid1.Cells[4,StringGrid1.RowCount-2];
    StringGrid1.Col := 1;
    Exit;
  end;
  if key = vk_ReTurn then
    if Trim(StringGrid1.Cells[0,x])='' then
    begin
      Ss := True;
      DataSource1.DataSet := nil;
      DBGrid1.Visible := False;
      SelectSPXX;
      if Data.ADOQuery1.RecordCount>1 then
      begin
        DataSource1.DataSet := Data.ADOQuery1;
        DBGrid1.Visible := True;
        DBGrid1.SetFocus;
      end
      else if Data.ADOQuery1.RecordCount = 1  then
      begin
        StringGrid1.Cells[0,x]:= Data.ADOQuery1.FieldByName('商品编号').Value;
        StringGrid1.Cells[1,x]:= Data.ADOQuery1.FieldByName('商品名称').Value;
        StringGrid1.SetFocus;
        StringGrid1.Col := 2;
      end
      else
      begin
        Application.MessageBox('该商品不存在。','提示',64);
        ClearStrings;
        if StringGrid1.RowCount>2 then
          StringGrid1.RowCount := StringGrid1.RowCount-1;
      end;
    end;
    if (Key = VK_Shift)and(JCxmlb = True) then
      BitBtn4.SetFocus;
end;

function TForm35.IsNull: Boolean;
var
  a: Integer;
begin
  IsNull := False;
  For a:= 0 to StringGrid1.ColCount -1 do
  begin
    if Trim(Stringgrid1.Cells[a,x])='' then
    begin
      IsNull := True;
      Break;
    end;
  end;
end;

function TForm35.CurrentIsCF: Boolean;
var
  i: Integer;
begin
  ReSult := False;
  if x > 1 then
  begin
    For i := 1 to x-1 do
    begin
      if  Trim(StringGrid1.Cells[0,x])= Trim(StringGrid1.Cells[0,i]) then
      begin
        ReSult := True;
        Break;
        Exit;
      end;
    end;
    For i := x+1 to StringGrid1.RowCount-1 do
    begin
      if  Trim(StringGrid1.Cells[0,x])= Trim(StringGrid1.Cells[0,i]) then
      begin
        ReSult := True;
        Break;
        Exit;
      end;
    end;
  end
  else if x = 1 then
  begin
    For i := 2 to StringGrid1.RowCount-1 do
      if  Trim(StringGrid1.Cells[0,x])= Trim(StringGrid1.Cells[0,i]) then
      begin
        ReSult := True;
        Break;
        Exit;
      end;
  end;
end;


procedure TForm35.ClearStrings;
var
  i: Integer;
begin
  For i := 0 to 3 do
    StringGrid1.Cells[i,x]:= '';
end;


procedure TForm35.ClearStringEnd;
var
  mm: Integer;
begin
  For mm:= 0 to 3 do
    StringGrid1.Cells[mm,StringGrid1.RowCount-1]:= '';
end;
procedure TForm35.SelectSPxx;
begin
  with Data.ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select * from 商品基础信息表 where 商品名称 = :b ');
    Parameters.ParamByName('b').Value := Trim(StringGrid1.Cells[1,x]);
    Open;
  end;
end;

procedure TForm35.DBGrid1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = vk_ReTurn then
    DBGrid1.OnDblClick(Sender);
end;

procedure TForm35.DBGrid1DblClick(Sender: TObject);
begin
  StringGrid1.Cells[0,x]:= Data.ADOQuery1.FieldByName('商品编号').Value;
  StringGrid1.Cells[1,x]:= Data.ADOQuery1.FieldByName('商品名称').Value;
  DataSource1.DataSet := nil;
  DBGrid1.Visible := False;
  StringGrid1.SetFocus;
  StringGrid1.Col := 2;
end;

procedure TForm35.Clear;
var
  r,c: integer;
begin
  Edit2.ReadOnly := False;
  Label14.Caption := '';
  Label10.Caption := '';
  Edit2.Clear;
  Label15.Caption := '0';
  DataSource1.DataSet := Nil;
  DBGrid1.Visible := False;
  Label16.Caption := '0';
  Label17.Caption := '0.0';
  For r := 1 to StringGrid1.RowCount-1 do
    For c := 0 to StringGrid1.ColCount-1 do
      StringGrid1.Cells[c,r]:='';
  StringGrid1.RowCount  :=2;
end;

procedure TForm35.BitBtn7Click(Sender: TObject);
begin
  Clear;
  Edit2.ReadOnly := False;
  BitBtn3.SetFocus;
end;

procedure TForm35.BitBtn4Click(Sender: TObject);
var
  Spjg: Real;//记录商品进价
  i: Integer;
  Sum: Integer;
begin
  SPjg := 0.0;
  Sum := 0;
  if (Trim(Edit2.Text)<>'')and(JCxmlb = True) then
  begin
    Data.ADOConnection1.BeginTrans;
    Try
      For i := 1 to StringGrid1.RowCount-1 do
      begin
        with Data.ADOQuery1 do
        begin
          Close;
          SQL.Clear;
          SQL.Add('select * from 库存表 where 商品编号 = :a');
          Parameters.ParamByName('a').Value := Trim(StringGrid1.Cells[0,i]);
          Open;
        end;
        if Data.ADOQuery1.RecordCount>0 then
        begin
          Sum := GroupSL(Trim(StringGrid1.Cells[0,i]));
          if Sum > Data.ADOQuery1.FieldByName('库存数量').Value then
          begin
            Application.MessageBox(Pchar('商品编号为' + Trim(StringGrid1.Cells[0,i])+ '的商品数量大于库存数量,不能完成该操作。'),'提示',64);
            Exit;
          end;
        end
        else
        begin
          Application.MessageBox(Pchar('商品编号为' + Trim(StringGrid1.Cells[0,i])+ '的商品在库中不存在。'),'提示',64);
          Exit;
        end;
      end;
      with Data.ADOQuery1 do
      begin
        Close;
        SQL.Clear;
        SQL.Add('Insert 商品提货票号表 values (:a ,:b,:c,:d ,Default)');
        Parameters.ParamByName('a').Value := Trim(Label10.Caption);
        Parameters.ParamByName('b').Value := StrToInt(Label15.Caption);
        Parameters.ParamByName('c').Value := StrToInt(Label16.Caption);
        Parameters.ParamByName('d').Value := StrToFloat(Label17.Caption);
        ExecSQL;
      end;
      For i := 1 to StringGrid1.RowCount-1 do
      begin
        with Data.ADOQuery1 do
        begin
          Close;
          SQL.Clear;
          SQL.Add('Insert 商品提货表 values (:a ,:b,:c,:d,:e,:f)');
          Parameters.ParamByName('a').Value := Trim(StringGrid1.Cells[0,i]);
          Parameters.ParamByName('b').Value := Trim(StringGrid1.Cells[1,i]);
          Parameters.ParamByName('c').Value := Trim(Edit2.Text);
          Parameters.ParamByName('d').Value := StrToInt(StringGrid1.Cells[2,i]);
          Parameters.ParamByName('e').Value := StrToFloat(StringGrid1.Cells[3,i]);
          Parameters.ParamByName('f').Value := Trim(Label10.Caption);
          ExecSQL;
        end;
        with Data.ADOQuery1 do
        begin
          Close;
          SQL.Clear;
          SQL.Add('Select * from 商品基础信息表 where 商品编号 = :a');
          Parameters.ParamByName('a').Value := Trim(StringGrid1.Cells[0,i]);
          Open;
        end;
        Spjg := Data.ADOQuery1.FieldByName('进价').Value;
        with Data.ADOQuery1 do
        begin
          Close;
          SQL.Clear;
          SQL.Add('Update 库存表 set 库存数量 = 库存数量 - :a ,库存金额 = 库存金额- :b where 商品编号 = :c');
          Parameters.ParamByName('c').Value := Trim(StringGrid1.Cells[0,i]);
          Parameters.ParamByName('a').Value := StrToInt(StringGrid1.Cells[2,i]);
          Parameters.ParamByName('b').Value  := Spjg* StrToInt(StringGrid1.Cells[3,i]);
          ExecSQL;
        end;
      end;
      Data.ADOConnection1.CommitTrans;
      Application.MessageBox('操作成功。','提示',64);
      BitBtn7.OnClick(Sender);
      BitBtn3.SetFocus;
    Except
      Data.ADOConnection1.RollbackTrans;
      Application.MessageBox('系统出错。','提示',64);
      Close;
    end;
  end
  else
    Application.MessageBox('项目列表有误。','提示',64);
end;

function TForm35.GroupSL(SPbh: String): Integer;
var
  i: Integer;
begin
  ReSult := 0;
  For i := 1 to StringGrid1.RowCount -1 do
  begin
    if Trim(Spbh)= Trim(StringGrid1.Cells[0,i]) then
      Result := ReSult + StrToInt(StringGrid1.Cells[2,i]);
  end;
end;

end.

⌨️ 快捷键说明

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