mainunit.pas

来自「Gestione Cellulari Nokia」· PAS 代码 · 共 1,844 行 · 第 1/4 页

PAS
1,844 行
字号
          FBUS1.PhoneBook.CloseDatabase(sApplicationPath+GetPhoneIMEI+'.pbf');
          exit;
       end;
    else
      begin
        MessageDlg(msg,mtWarning,[mbOk],0);
        bContinueLoop:=false;
        if frmConnEst.visible then
          begin
            frmConnEst.Label1.caption:='Error Connecting to Phone';
          end;
      end;
  end
end;

procedure TfrmMain.Connect1Click(Sender: TObject);
begin
 Application.createForm(TfrmConnEst,frmConnEst);
 frmConnEst.show;
 application.ProcessMessages;
 sleep(500);

 FBUS1.Comport:=TCOMPORT(ComportToUse); //Set the comport to use

 FBus1.Connect;

 repeat
   application.processmessages;
 until (fBUS1.Connected) or (bContinueLoop=false);

 if fBUS1.Connected then
   begin
      if frmConnEst.visible then frmConnEst.close;
      sleep(500);
      if FormatDateTime('dd MMM YYYY',FBUS1.GetTime) <> '30 Dec 1899' then
        DateTimeLabel.caption:=DateTimetoStr(FBUS1.GetTime)
      else
        DateTimeLabel.caption:='';
        PopulateListViews;
   end;
end;

procedure TfrmMain.Disconnect1Click(Sender: TObject);
begin
  FBus1.PhoneBook.CloseDatabase(sApplicationPath+GetPhoneIMEI+'.pbf');
  FBus1.PhoneBeep;
  FBus1.Disconnect;
  MFBUSStatusBar1.Panels[0].text:='Disconnected';
  MFBUSStatusBar1.panels[1].text:='';
end;

procedure TfrmMain.ChangeComport1Click(Sender: TObject);
begin
  ChangeComport;
end;

procedure TfrmMain.SoftReset1Click(Sender: TObject);
begin
  fBus1.ResetPhone(rsSoft);
end;

procedure TfrmMain.HardReset1Click(Sender: TObject);
begin
  fBus1.ResetPhone(rsHard);
end;

procedure TfrmMain.Button3Click(Sender: TObject);
begin
  FBUS1.SetAlarmTime(StrToTime(txtTime.text));
end;

procedure TfrmMain.FormCreate(Sender: TObject);
begin

  bFirstTime:=true;
  sApplicationPath:=GetCurrentDir+'\';

  bContinueLoop:=true;

  FourthShortcutBar1.PanelIndex:=0;
  Notebook1.PageIndex:=0;
  cmbpMemType.itemindex:=1;
  rgrpDTMFType.itemindex:=0;
  cmboLogoType.itemindex:=2;

  fWin95:= (GetVersion() and $80000000)<>0;


  if Not fWin95 then
    begin
      rgrpPlayDevice.Items.add('PC Speaker');
      rgrpPlayDevice.Items.add('MIDI Device');
      rgrpPlayDevice.Items.add('Phone');
      rgrpPlayDevice.itemindex:=1;
    end
  else
    begin
      rgrpPlayDevice.Items.add('MIDI Device');
      rgrpPlayDevice.Items.add('Phone');
      rgrpPlayDevice.itemindex:=0;
    end;
  LoadCharSets;
end;

procedure TfrmMain.LoadSMSMessages;
begin
  screen.cursor:=crHourGlass;
  Notebook1.PageIndex:=2;
  lblText.caption:='SMS Messages';
  application.processmessages;
  cmboSMSMemType.itemindex:=2;
  if not bSMSLoaded then frmMain.FBUS1.SMS.RefreshSMSList;
  lvSMS.LoadSMS(cmboSMSMemType.itemindex+11);
  screen.cursor:=crDefault;
  IsAlive;
  bSMSLoaded:=true;
end;
procedure TfrmMain.cmbpMemTypeClick(Sender: TObject);
begin
  if fBus1.Connected then
    begin
      lvPhonebook.items.clear;
      FBus1.Phonebook.PopulateListView(TMemType(cmbpMemType.itemindex),lvPhoneBook);
      ShowPhoneBookUsage;
    end
  else
    Notebook1.PageIndex:=1;
end;

procedure TfrmMain.btnPBRefreshClick(Sender: TObject);
begin
  if messageDlg('This will check the Phone book entries on the Phone with the local database. This may take a few minutes. Continue?',mtConfirmation,[mbYes,mbNo],0)=mrYes then
   begin
    if fBus1.Connected then
      begin
        screen.cursor:=crHourGlass;
        FBUS1.PhoneBook.SyncPhoneandDB(TMemType(cmbpMemType.itemindex));  //mem type needed here
        screen.cursor:=crDefault;
      end
    else
     begin
      Notebook1.PageIndex:=1;
      messagedlg('The phone is not connected. Plece connect phone and try again',mtinformation,[mbOk],0);
     end;
   end;

end;

procedure TfrmMain.btnPBAddnewClick(Sender: TObject);
begin
   application.Createform(TfrmAddNewPBEntry,frmAddNewPBEntry);
   frmAddNewPBEntry.execute;
   ShowPhoneBookUsage;
end;

procedure TfrmMain.Exit1Click(Sender: TObject);
begin
  if fBus1.Connected then Disconnect1Click(Self);
  application.terminate;
end;

procedure TfrmMain.btnPBDeleteClick(Sender: TObject);
var
  SelectedItem : TListItem;
begin

  if messagedlg('Are you sure you want to delete this entry?',mtConfirmation,[mbYes,mbNo],0) = mrYes then
    begin
      if lvPhoneBook.SelCount >0 then
        begin
          SelectedItem:=lvPhoneBook.selected;
          FBUS1.PhoneBook.DeleteEntryByIndex(TMemType(1),StrToInt(SelectedItem.SubItems[2]));
          PopulatePhoneBookListView;
        end;
      ShowPhoneBookUsage;
    end;

end;

procedure TfrmMain.imgPhoneMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
 image4.visible:=false;
end;

procedure TfrmMain.imgPhoneMouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
var
  bNormalCursor:boolean;
begin

  bNormalCursor:=true;
   if ((y>207) and (y<220)) then
     begin
        bNormalCursor:=false;
        if((x>11) and (x<31)) or((x>39) and (x<59)) or ((x>65) and (x<85)) then
          screen.Cursor:=crHandPoint
        else
          screen.Cursor:=crDefault;
     end;

    if ((y>225) and (y<236)) then
      begin
        bNormalCursor:=false;
        if((x>11) and (x<31)) or((x>39) and (x<59)) or ((x>65) and (x<85)) then
          screen.Cursor:=crHandPoint
        else
          screen.Cursor:=crDefault;
      end;

    if ((y>243) and (y<256)) then
      begin
        bNormalCursor:=false;
        if((x>11) and (x<31)) or((x>39) and (x<59)) or ((x>65) and (x<85)) then
          screen.Cursor:=crHandPoint
        else
          screen.Cursor:=crDefault;
      end;

 if bNormalCursor then
  screen.Cursor:=crDefault;
end;

procedure TfrmMain.imgPhoneMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin

   if ((y>207) and (y<220)) then  //first row of keyboad
     begin
        // - Only keys 2 - 9 are uesed for speed dials
        if ((x>39) and (x<59)) then
          FindSpeedDialDetails(2);
        if ((x>65) and (x<85)) then
          FindSpeedDialDetails(3);
     end;


   if ((y>225) and (y<236)) then  //Second row of keyboad
     begin
        if ((x>11) and (x<31)) then
          FindSpeedDialDetails(4);
        if ((x>39) and (x<59)) then
          FindSpeedDialDetails(5);
        if ((x>65) and (x<85)) then
          FindSpeedDialDetails(6);
     end;

   if ((y>243) and (y<256)) then  //Third row of keyboad
     begin
        if ((x>11) and (x<31)) then
          FindSpeedDialDetails(7);
        if ((x>39) and (x<59)) then
          FindSpeedDialDetails(8);
        if ((x>65) and (x<85)) then
          FindSpeedDialDetails(9);
     end;

end;

procedure TfrmMain.FindSpeedDialDetails(iValue:integer);
begin
  txtSpeedName.text:='';
  txtSpeedNumber.text:='';
  txtSpeedGroup.text:='';

  lblLocation.caption:=IntToStr(iValue);
  lblSpeedPosition.caption:=IntToStr(ivalue);

  if FBUS1.PhoneBook.FindSpeedDial(iValue) then
    begin

      lblLocation.caption:=IntToStr(iValue);
      lblSpeedPosition.caption:=IntToStr(ivalue);


      txtSpeedName.text:=FBUS1.PhoneBook.field('name').value;
      txtSpeedNumber.text:=FBUS1.PhoneBook.field('number').value;
      txtSpeedGroup.text:=FBUS1.PhoneBook.field('Group').value;

      cmboSpeedMem.itemindex:=Ord(StrToInt(FBUS1.PhoneBook.field('memType').value));
      btnAddSpeedDial.visible:=false;
      lvSpeedDial.visible:=false;
    end
  else
    begin
      txtSpeedName.enabled:=True;
      txtSpeedNumber.enabled:=True;
      txtSpeedGroup.enabled:=True;
      btnAddSpeedDial.visible:=True;

      if lvPhoneBook.items.count = 0 then
        begin
          FBus1.Phonebook.PopulateListView(TMemType(cmbpMemType.itemindex),lvPhoneBook);
          ShowPhoneBookUsage;
        end;

      if lvSpeedDial.items.count =0 then
        begin
          lvSpeedDial.items.clear;
          lvSpeedDial.items:=lvPhoneBook.items;
          lvSpeedDial.Checkboxes:=false;
          lvSpeedDial.visible:=True;
        end;
    end;

end;
procedure TfrmMain.btnAddSpeedDialClick(Sender: TObject);
begin
  if lvSpeedDial.selcount =0 then
     messagedlg('Select the name and number from the list of PhoneBook entries.',mtInformation,[mbOk],0)
  else
    begin
      FBUS1.PhoneBook.AddSpeedDial(StrToInt(lblLocation.caption),lvSpeedDial.Selected.Caption,TmemType(cmboSpeedMem.itemindex));
      lvSpeedDial.visible:=false;
      FindSpeedDialDetails(StrToInt(lblLocation.caption)); //refresh the screen with the new entry
    end;
end;

procedure TfrmMain.btnEditSpeedDialClick(Sender: TObject);
begin
  if lvSpeedDial.visible=True then
    begin
      FBUS1.PhoneBook.EditSpeedDial(StrToInt(lblLocation.caption),lvSpeedDial.Selected.caption,TmemType(cmboSpeedMem.itemindex),(lvSpeedDial.Selected.index+1));
      lvSpeedDial.visible:=false;
      FindSpeedDialDetails(StrToInt(lblLocation.caption)); //refresh the screen with the new entry
    end
  else
    begin
      if lvPhoneBook.items.count = 0 then
        begin
          FBus1.Phonebook.PopulateListView(TMemType(cmbpMemType.itemindex),lvPhoneBook);
          ShowPhoneBookUsage;
        end;

      if lvSpeedDial.items.count =0 then
        begin
          lvSpeedDial.items.clear;
          lvSpeedDial.items:=lvPhoneBook.items;
          lvSpeedDial.Checkboxes:=false;
        end;
        lvSpeedDial.visible:=True;
    end;

end;

procedure TfrmMain.cmboSMSMemTypeClick(Sender: TObject);
begin
  lvSMS.LoadSMS(cmboSMSMemType.itemindex+11);
end;

procedure TfrmMain.FBUS1DelivaryCount(iSMSCount: Integer);
begin
  if cmboSMSMemType.itemindex = 0 then smsMemory.position:=iSMSCount;
end;

procedure TfrmMain.FBUS1InboxCount(iSMSCount: Integer);
begin
  if cmboSMSMemType.itemindex = 2 then smsMemory.position:=iSMSCount;
end;

procedure TfrmMain.FBUS1OutBoxCount(iSMSCount: Integer);
begin
  if cmboSMSMemType.itemindex = 1 then smsMemory.position:=iSMSCount;
end;

procedure TfrmMain.lvSMSClick(Sender: TObject);
begin
  if lvSMS.Selindex >-1 then
     btnDeleteSMS.Visible:=true
  else
     btnDeleteSMS.Visible:=false;
end;

procedure TfrmMain.btnSMSSendSMSClick(Sender: TObject);
begin
    application.CreateForm(TfrmSendSMS,frmSendSMS);
    frmSendSMS.showmodal;
end;

procedure TfrmMain.lvSMSDblClick(Sender: TObject);
var
 sSender: string;
begin

  if lvSMS.SelIndex >-1 then
    begin
      Application.createForm(TfrmSMSView,frmSMSView);
      frmSMSView.lblSMSDate.caption:=FormatDateTime('dd/mm/yyyy',lvSMS.Selected.msg_Date);
      sSender:=FindSendersName(lvSMS.Selected.sSender);
      if sSender ='' then
        frmSMSView.lblSMSFrom.caption:=lvSMS.Selected.sSender
      else
        frmSMSView.lblSMSFrom.caption:=lvSMS.Selected.sSender+', '+sSender;
      frmSMSView.moMessage.text:=lvSMS.Selected.sMessage;

      frmSMSView.showmodal;
    end;

end;

function TfrmMain.FindSendersName(sNumber:string):string;
var
 iPos:integer;
 res:string;
begin
  res:='';
  
  for iPos:=0 to lvPhoneBook.items.count-1 do
    if  Pos(Copy(sNumber,4,length(sNumber)),lvPhoneBook.items[iPos].subitems[0]) >0 then
      begin
        res:= lvPhoneBook.items[ipos].caption;
        break;
      end;

  Result:=res;
end;
procedure TfrmMain.FBUS1SMSSent;
begin
   frmSendSMS.close;
   MessageDlg('SMS Delivered',mtInformation,[mbok],0);
end;

procedure TfrmMain.FBUS1SMSSendError;
begin
  MessageDlg('There was an error Delivering the SMS Message.',mtInformation,[mbok],0);
end;

procedure TfrmMain.btnDeleteSMSClick(Sender: TObject);
begin
  if lvSMS.SelIndex >-1 then
    begin
      fBus1.SMS.DeleteMessageByIndex(cmboSMSMemType.ItemIndex,(lvSMS.SelIndex+1)); //must be +1 as Listview items are zero based, and the SMS items are one based
      lvSMS.Delete(lvSMS.SelIndex);
      btnDeleteSMS.visible:=false;
    end;
end;

procedure TfrmMain.btnPBSendSMSClick(Sender: TObject);
begin
  if lvPhoneBook.selcount >0 then
    begin
      application.CreateForm(TfrmSendSMS,frmSendSMS);
      frmSendSMS.txtDestination.text:=lvPhoneBook.items[lvPhoneBook.Selected.Index].SubItems[0];
      frmSendSMS.showmodal;
    end;
end;

procedure TfrmMain.btnPlayToneClick(Sender: TObject);
begin
  if (FileListBox1.FileName <> '') and  (rgrpPlayDevice.itemindex<>-1) and (IsRingTone(FileListBox1.Filename)) then
    begin
      if FBUS1.RingTone.ReadFile(FileListBox1.Filename) then //this will only continue IF the file exitst
        begin
          if Not fWin95 then
           FBUS1.RingTone.Play(rgrpPlayDevice.itemindex)
          else
           FBUS1.RingTone.Play(rgrpPlayDevice.itemindex+1);
        end
      else
          Messagedlg('The File "'+FileListBox1.Filename+'" does not exist',mtWarning,[mbok],0);
    end;

⌨️ 快捷键说明

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