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

📄 stock_u.~pas

📁 汽车维修系统的设计
💻 ~PAS
📖 第 1 页 / 共 2 页
字号:
                end;
            end
        else
            begin
               stringgrid1.RowCount:=stringgrid1.RowCount+1;
               selectgoodsfrm:=Tselectgoodsfrm.Create(self);
               selectgoodsfrm.Edit2.Text :=IntToStr(stringGrid1.RowCount);
               selectgoodsfrm.ShowModal ;
               selectgoodsfrm.Free ;
            end;
      end;

end;

procedure TStockfrm.DelMenuClick(Sender: TObject);
begin
  if stringGrid1.RowCount >2 then
     begin
       stringgrid1.RowCount:=stringgrid1.RowCount-1;
       i:=i-1;
     end
  else
      ClearStringGrid();
end;

procedure TStockfrm.BitBtn3Click(Sender: TObject);
begin
   ClearEdit();
   ClearStringGrid();
end;


procedure TStockfrm.StringGrid1SelectCell(Sender: TObject; ACol,
  ARow: Integer; var CanSelect: Boolean);
var
  a:TRect;
begin
  with StringGrid1 do
      //设置2,3,4,7列为只读
      if (ACol =2) or (ACol =3) or (ACol =4) or (ACol =7)  then
          Options := Options - [goEditing]
      else
         Options := Options + [goEditing];

   a:=StringGrid1.CellRect(Acol,ARow);
   a.Left :=a.Left +StringGrid1.Left ;
   a.Right :=a.Right +StringGrid1.Left ;
   a.Top :=a.Top+StringGrid1.Top;
   a.Bottom :=a.Bottom +StringGrid1.Top ;

  if Acol=8 then  //仓库列
     begin
        DBLookupComboBox1.Left :=a.Left+2;
        DBLookupComboBox1.Top :=a.Top +3;
        DBLookupComboBox1.Width :=StringGrid1.ColWidths[Acol];
        DBLookupComboBox1.Height :=StringGrid1.RowHeights[ARow];
        DBLookupComboBox1.Visible:=True;
        DBLookupComboBox1.SetFocus ;
     end
   else
     DBLookupComboBox1.Visible:=false;

   if Acol=9 then  //仓位列
     begin
        DBLookupComboBox3.Left :=a.Left+2;
        DBLookupComboBox3.Top :=a.Top +3;
        DBLookupComboBox3.Width :=StringGrid1.ColWidths[Acol];
        DBLookupComboBox3.Height :=StringGrid1.RowHeights[ARow];
        DBLookupComboBox3.Visible:=True;
        DBLookupComboBox3.SetFocus ;
     end
   else
     DBLookupComboBox3.Visible:=false;

end;

procedure TStockfrm.StringGrid1DrawCell(Sender: TObject; ACol,
  ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
  if Arow<>0 then
  //设置2,3,4,7列以不同的颜色显示
  if (ACol =2) or (ACol =3) or (ACol =4) or (ACol =7)  then
     with stringgrid1 do
        begin
           canvas.Brush.color:=clInfoBk;
           canvas.FillRect(Rect);
           canvas.TextOut(rect.left+2,rect.top+2,cells[acol,arow])
        end;

end;

procedure TStockfrm.StringGrid1KeyPress(Sender: TObject; var Key: Char);
begin
   if (Stringgrid1.Col=5) or (Stringgrid1.Col=6) then  //数量和单价列限定只能录入数字和小数点
      if key<>#13 then
         if (key <#8)or(key>#8)and(key < #45)or (key>#46)and(key<#48)or(key>#57)then key := #0 ;


   if (Stringgrid1.Col=1) then
      if key=#13 then
         if stringGrid1.Cells[ Stringgrid1.Col,Stringgrid1.Row]<>'' then
            begin
              with ADOQuery3 do
                begin
                  close;
                  sql.Clear ;
                  sql.Add('select * from goodsinf where goodsCode=:a0');
                  parameters[0].Value :=stringGrid1.Cells[Stringgrid1.Col,Stringgrid1.Row];
                  open;
                end;
              if ADOQuery3.RecordCount <=0 then
                 begin
                     application.MessageBox('您输入的物品编码不合法!','提示',mb_ok+mb_IconExclamation);
                     stringgrid1.Cells[Stringgrid1.Col,Stringgrid1.Row]:='';
                     exit;
                 end;
              stringgrid1.Cells[1,Stringgrid1.Row]:=trim(Adoquery3.FieldByName('goodscode').Asstring) ;
              stringgrid1.Cells[2,Stringgrid1.Row]:=trim(Adoquery3.FieldByName('goodsname').Asstring) ;
              stringgrid1.Cells[3,Stringgrid1.Row]:=trim(Adoquery3.FieldByName('goodstype').Asstring) ;
              stringgrid1.Cells[4,Stringgrid1.Row]:=trim(Adoquery3.FieldByName('goodsUnit').Asstring) ;
              stringgrid1.Cells[5,Stringgrid1.Row]:='1' ;  //数量
              stringgrid1.Cells[6,Stringgrid1.Row]:=Adoquery3.FieldByName('进货价').AsString  ;
              stringgrid1.Cells[7,Stringgrid1.Row]:=Adoquery3.FieldByName('进货价').AsString  ;
              Edit6.Text:=IntTostr(stringgrid1.RowCount-1);
            end;
   CalculateTotalMoney();
   Edit7.Text:=FloatToStr(SumTotalMoney());
end;

procedure TStockfrm.DBLookupComboBox3Exit(Sender: TObject);
begin
   StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row]:=DBLookupComboBox3.Text ;
   DBLookupComboBox3.Visible :=false;
end;

procedure TStockfrm.DBLookupComboBox1Exit(Sender: TObject);
begin
   StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row]:=DBLookupComboBox1.Text ;
   DBLookupComboBox1.Visible :=false;
   //StringGrid1Exit(self);
   with ADOQuery2 do
      begin
          close;
          sql.Clear ;
          sql.Add('select * from stlayer where storageName=:a0');
          parameters[0].Value :=StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row];
          open;
      end;
    if ADOQuery2.RecordCount <=0 then StringGrid1.Cells[StringGrid1.Col+1,StringGrid1.Row]:='';

end;

procedure TStockfrm.StringGrid1Exit(Sender: TObject);
begin
   if StringGrid1.Col =8 then
      if StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row]='' then
         //StringGrid1.Cells[StringGrid1.Col+1,StringGrid1.Row]:=''
      else
          with ADOQuery2 do
              begin
                 close;
                 sql.Clear ;
                 sql.Add('select * from stlayer where storageName=:a0');
                 parameters[0].Value :=StringGrid1.Cells[StringGrid1.Col,StringGrid1.Row];
                 open;
              end;

   CalculateTotalMoney();
   Edit7.Text:=FloatToStr(SumTotalMoney());
end;

procedure TStockfrm.StringGrid1RowMoved(Sender: TObject; FromIndex,
  ToIndex: Integer);
begin
  DBLookupComboBox1.Visible :=false;
  DBLookupComboBox3.Visible :=false;

end;

procedure TStockfrm.StringGrid1ColumnMoved(Sender: TObject; FromIndex,
  ToIndex: Integer);
begin
  DBLookupComboBox1.Visible :=false;
  DBLookupComboBox3.Visible :=false;
  
end;

Procedure TStockfrm.CalculateTotalMoney();  //计算金额=数量x 单价
var
  I:Integer;
  T:variant;
begin
  for i:=1 to StringGrid1.RowCount -1 do
      begin
          if (StringGrid1.Cells[5,i])='' then StringGrid1.Cells[5,i]:='1';
          if (StringGrid1.Cells[6,i])='' then StringGrid1.Cells[6,i]:='0';
          T:=StrToFloat(StringGrid1.Cells[5,i])*StrToFloat(StringGrid1.Cells[6,i]);
          StringGrid1.Cells[7,i]:=FloatTostr(T);
      end;
end;

Function TStockfrm.SumTotalMoney():currency;
var
  I:Integer;
  Num,Price,TMoney:variant;
begin
  for i:=1 to StringGrid1.RowCount -1 do
      begin
          if (StringGrid1.Cells[5,i])='' then StringGrid1.Cells[5,i]:='0';
          if (StringGrid1.Cells[6,i])='' then StringGrid1.Cells[6,i]:='0';
          Num:=StrToFloat(StringGrid1.Cells[5,i]);    //数量
          price:=StrToFloat(StringGrid1.Cells[6,i]);  //单价
          TMoney:=TMoney+Num * price;
      end;
  result:=TMoney;

end;

Function TStockfrm.UpdateDataToTable():Boolean;  //保存数据
var
    R:integer;//stringgrid1列表的行数
    I:integer;//计数器
begin
  try
    begin
    //保存主表
    with MainQuery do
        begin
            close;
            sql.Clear ;
            sql.Add('insert into goodsi(Billcode,billtype,stockDate,stockCode,provideCode,stockMan,others,stockItems,');
            sql.Add('TotalMoney,制单人) values(:a0,:a1,:a2,:a3,:a4,:a5,:a6,:a7,:a8,:a9)');
            parameters[0].Value :=Edit3.Text;
            parameters[1].Value :='IA';
            parameters[2].Value :=DateTimePicker1.DateTime;
            parameters[3].Value :=trim(Edit4.Text);
            parameters[4].Value :=trim(edit1.Text);
            parameters[5].Value :=trim(edit2.Text);
            parameters[6].Value :=trim(edit5.Text);
            parameters[7].Value :=StrToInt(edit6.Text);
            parameters[8].Value :=StrToFloat(Edit7.text);
            parameters[9].Value :=trim(edit8.Text);
            ExecSQL;
        end;
       R:=Stringgrid1.RowCount -1;

      //保存明细表
       for I:=1 to R do
       with DetailsQuery do
        begin
            close;
            sql.Clear ;
            sql.Add('Insert into goodsiDetails(Billcode,goodsCode,goodsname,goodsType,goodsUnit,Num,price,Tmoney,仓库,仓位,others)');
            sql.Add('values(:b0,:b1,:b2,:b3,:b4,:b5,:b6,:b7,:b8,:b9,:b10)') ;
            parameters[0].Value :=Edit3.Text;
            parameters[1].Value :=Stringgrid1.Cells[1,i] ;
            parameters[2].Value :=Stringgrid1.Cells[2,i];
            parameters[3].Value :=Stringgrid1.Cells[3,i];
            parameters[4].Value :=Stringgrid1.Cells[4,i];
            parameters[5].Value :=strToFloat(Stringgrid1.Cells[5,i]);
            parameters[6].Value :=strToFloat(Stringgrid1.Cells[6,i]);
            parameters[7].Value :=strToFloat(Stringgrid1.Cells[7,i]);
            parameters[8].Value :=Stringgrid1.Cells[8,i];
            parameters[9].Value :=Stringgrid1.Cells[9,i];
            parameters[10].Value :=Stringgrid1.Cells[10,i];
            ExecSQL;
        end;
        result:=True;
      end;
   except
       result:=False;
   end;
end;

procedure TStockfrm.BitBtn1Click(Sender: TObject);
begin
   ClearEdit();
   ClearStringGrid();
   BitBtn1.Enabled :=False;
   BitBtn2.Enabled :=True;
   BitBtn3.Enabled :=True;
end;

end.

⌨️ 快捷键说明

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