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

📄 cf0dmmc.pas

📁 根据箱号
💻 PAS
📖 第 1 页 / 共 2 页
字号:
  DlgSave:TsaveDialog;
  rec,count:integer;
  jxmc:string;
  mess,mess1:string;
  y,w,mess2:integer;
  fhjl:string;
begin
  inherited;
  adoquery1.Close;
  adoquery1.SQL.clear;
  adoquery1.sql.add('select distinct 机型 from '+main.usermc+' ');
  adoquery1.open;
  y:=0;
  while not adoquery1.Eof do
    begin
      y:=y+1;
      mytable[y,1]:=adoquery1.fieldbyname('机型').asstring;
      adoquery2.Close;
      adoquery2.SQL.clear;
      adoquery2.sql.add('select 电子串号 from '+main.usermc+' where 机型='''+adoquery1.fieldbyname('机型').AsString+'''');
      adoquery2.open;
      mytable[y,2]:=inttostr(adoquery2.RecordCount);
      adoquery1.Next;
     end;
  mess:='本次查询如下:'+#13+'';
  w:=y;
  y:=1;
  while y<=w do
      begin
        mess1:=mess1+#13+'机型名称为:【'+mytable[y,1]+'】,有【'+mytable[y,2]+'】个电子串号';
        mess2:=mess2+strtoint(mytable[y,2]);
        y:=y+1;
      end;
  mess:=mess+mess1+''+#13+'                    共计【'+inttostr(mess2)+'】个电子串号';
  if  application.MessageBox(pchar(mess),'注意',mb_yesno)=id_yes then
      begin
        DlgSave:=TsaveDialog.Create(nil);
        DlgSave.FileName:='串号明细.xls';
        DlgSave.Filter:='*.xls|*.xls';
        if DlgSave.Execute then
           Begin
             application.ProcessMessages;
             Filename:=DlgSave.FileName;
             if fileExists(DlgSave.FileName) then
             begin
          //   if application.MessageBox(pchar('系统发现【'+filename+'】文件已经存在,如果继续将删除原文件?'),'提示',mb_yesno)=id_yes then
             if messagedlg(pchar('系统发现【'+filename+'】文件已经存在,如果继续将删除原文件?'),mtWarning,[mbyes,mbno],0)=mryes then
                begin
                  DeleteFile(filename);
                  ExcelApp:= CreateOleObject( 'Excel.Application' );
                  ExcelApp.Caption :='电脑维护管理系统';//'Microsoft Excel';
                  ExcelApp.WorkBooks.Add;
                  application.ProcessMessages;
                  ExcelApp.WorkSheets[1].Activate;
                  //首行数据
                  ExcelApp.rows[1].font.name:='宋体';
                  ExcelApp.rows[1].font.size:=11;
                  ExcelApp.rows[1].Font.Color:=clblack;
                  ExcelApp.rows[1].Font.Bold:=true;
                  K:=1;
                  for i:=0 To DBGrid1.Columns.Count-1 Do
                      begin
                        if DBGrid1.Columns[i].Visible Then
                           begin
                             ExcelApp.Cells[1,K]:=DBGrid1.Columns[i].Title.Caption;
                           //  ExcelApp.rows[2].color:=clred;
                             k:=k+1;
                           end;//if
                       end; //for
                      //除首行外数据
                  j:=1;
                  begin
                  Gauge_process.Visible:=true;
                 //   stepcount:=DBGrid1.Columns.Count-1;
                  //  with progressBar1 do
                   //      begin
                   //        Min:=0;
                   //        Max:=stepcount;
                   //        Step:=1;
                    With Gauge_process do
                      begin
                        Gauge_process.MaxValue:=DBGrid1.Columns.Count*adoquery3.recordcount;
                        Gauge_process.Progress:=0;
                            for x:=0 to DBGrid1.Columns.Count-1 do
                               begin
                                 if DBGrid1.Columns[x].Visible=true Then
                                    begin
                                      adoquery3.First;
                                      for k:=1 To adoquery3.RecordCount Do
                                          begin
                                            ExcelApp.Cells[K+1,x+1]:=''''+adoquery3.FieldByName(DBGrid1.Columns[x].FieldName).Asstring+'';
                                       //     ExcelApp.rows[2].color:=clred;
                                            adoquery3.Next;
                                            Gauge_process.Progress :=Gauge_process.Progress +1;
                                          end;
                                    
                                     end;
                                   //  showmessage(''+inttostr(x)+'');
                         //            Stepit;

                                     end;

                           end;
                    end;
                 Gauge_process.Visible:=false;
                  for x:=1 To adoquery3.recordcount+1 Do
                  ExcelApp.rows[x].Font.SIZE:=10;
                  ExcelApp.Columns.AutoFit;
                  ExcelApp.ActiveWorkBook.saveas(filename);
                  ExcelApp.WorkBooks.Close;
                //  Application.MessageBox(pchar('数据导出成功,请到【'+filename+'】中查看!'),'数据导出',0);
                adoquery3.First;
                 while not adoquery3.Eof do
                   begin
                     if trim(adoquery3.fieldbyname('发货机率').AsString)='' then
                        fhjl:='1'
                     else
                        fhjl:=inttostr(strtoint(trim(adoquery3.fieldbyname('发货机率').AsString))+1);
                     adocommand1.CommandText:='update 串号管理 set 发货机率='''+fhjl+''' where 电子串号='''+adoquery3.fieldbyname('电子串号').asstring+'''';
                     adocommand1.Execute;
                     adoquery3.Next;
                   end;
                  messagedlg(pchar('数据导出成功,请到【'+filename+'】中查看!'),mtinformation,[mbok],0);
                  ExcelApp.Quit;
                  ExcelApp:=Unassigned;
                  DlgSave.Destroy;
               end;
             end
             else
               begin
                 ExcelApp:= CreateOleObject( 'Excel.Application' );
                  ExcelApp.Caption :='电脑维护管理系统';//'Microsoft Excel';
                  ExcelApp.WorkBooks.Add;
                  application.ProcessMessages;
                  ExcelApp.WorkSheets[1].Activate;
                  //首行数据
                  ExcelApp.rows[1].font.name:='宋体';
                  ExcelApp.rows[1].font.size:=11;
                  ExcelApp.rows[1].Font.Color:=clblack;
                  ExcelApp.rows[1].Font.Bold:=true;
                  K:=1;
                  for i:=0 To DBGrid1.Columns.Count-1 Do
                      begin
                        if DBGrid1.Columns[i].Visible Then
                           begin
                             ExcelApp.Cells[1,K]:=DBGrid1.Columns[i].Title.Caption;
                             k:=k+1;
                           end;//if
                       end; //for
                      //除首行外数据
                  j:=1;
                  begin
                    Gauge_process.Visible:=true;
                  //  stepcount:=DBGrid1.Columns.Count-1;
                   // with progressBar1 do
                    //     begin
                     //      Min:=0;
                      //     Max:=stepcount;
                       //    Step:=1;
                   With Gauge_process do
                      begin
                        Gauge_process.MaxValue:=DBGrid1.Columns.Count*adoquery3.recordcount;
                        Gauge_process.Progress:=0;
                            for x:=0 to DBGrid1.Columns.Count-1 do
                               begin
                                 if DBGrid1.Columns[x].Visible=true Then
                                    begin
                                      adoquery3.First;
                                      for k:=1 To adoquery3.RecordCount Do
                                          begin
                                            ExcelApp.Cells[K+1,x+1]:=''''+adoquery3.FieldByName(DBGrid1.Columns[x].FieldName).Asstring+'';
                                            adoquery3.Next;
                                             Gauge_process.Progress :=Gauge_process.Progress +1;
                                          end;
                                       //j:=j+1; 
                                      // Stepit;
                                    //   showmessage(''+inttostr(x)+'');
                                    //    Gauge_process.Progress :=Gauge_process.Progress +1;
                                     end;
                                  end;

                           end;
                    end;
                  Gauge_process.Visible:=false;
                  for x:=1 To adoquery3.recordcount+1 Do
                  ExcelApp.rows[x].Font.SIZE:=10;
                  ExcelApp.Columns.AutoFit;
                  ExcelApp.ActiveWorkBook.saveas(filename);
                  ExcelApp.WorkBooks.Close;
                //  Application.MessageBox(pchar('数据导出成功,请到【'+filename+'】中查看!'),'数据导出',0);
                 adoquery3.First;
                 while not adoquery3.Eof do
                   begin
                     if trim(adoquery3.fieldbyname('发货机率').AsString)='' then
                        fhjl:='1'
                     else
                        fhjl:=inttostr(strtoint(trim(adoquery3.fieldbyname('发货机率').AsString))+1);
                     adocommand1.CommandText:='update 串号管理 set 发货机率='''+fhjl+''' where 电子串号='''+adoquery3.fieldbyname('电子串号').asstring+'''';
                     adocommand1.Execute;
                     adoquery3.Next;
                   end;
                   messagedlg(pchar('数据导出成功,请到【'+filename+'】中查看!'),mtinformation,[mbok],0);
                  ExcelApp.Quit;
                  ExcelApp:=Unassigned;
                  DlgSave.Destroy;
               end;
          end;
      end;
end;

procedure Tf0dmmc.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  inherited;
  if DBGrid1.DataSource.DataSet.RecNo mod 2 = 1 then
     begin
       DBGrid1.Canvas.Brush.Color :=$00FFFFC2;
       dbgrid1.Canvas.Font.Color:=clwindowtext;
       DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
     end
  else
    begin
      DBGrid1.Canvas.Brush.Color :=$00F2F2F2;
      dbgrid1.Canvas.Font.Color:=clwindowtext;
      DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
    end;
end;

procedure Tf0dmmc.CheckBox1Click(Sender: TObject);
begin
  inherited;
  if checkbox1.Checked then
     begin
       datetimepicker1.Enabled:=true;
       datetimepicker2.Enabled:=true;
     end
  else
     begin
       datetimepicker1.Enabled:=false;
       datetimepicker2.Enabled:=false;
     end
end;

end.

⌨️ 快捷键说明

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