main.pas

来自「是一个手机功能的模拟程序」· PAS 代码 · 共 1,568 行 · 第 1/5 页

PAS
1,568
字号
    GSMtoASC2(ulrecn.sms_msg,objmsg,ulrecn.msg_len);
  smsmsg:=strpas(objmsg);
  Query1.Parameters.ParamByName('Message').Value:=smsmsg;
  Query1.Parameters.ParamByName('SerialNo').Value:=sn;
  Query1.ExecSQL;
  Query1.close;
  ADOQuery_sms.Close;
  ADOQuery_sms.SQL.Clear;
  ADOQuery_sms.SQL.Add('select * from shortmessage where SerialNo='+inttostr(sn));
  ADOQuery_sms.Open;

  tempSMS:=nil;
  for i:=0 to Count_SMS_PC-1 do
  begin
    if PShortMessage(ShortmessageList.Items[i]).serialNo=sn then
    begin
      tempSMS:=ShortmessageList.Items[i];
      break;
    end;
  end;
  if tempSMS=nil then exit;

  move(ulrecn^,tempSMS.data,sizeof(TPC_SMS_Content));
  strpCopy(tempsms.Sort,ADOQuery_smsstatus.AsString);
  strpcopy(tempsms.number,ADOQuery_smsPhoneNo.AsString);
  strpcopy(tempsms.Name,ADOQuery_smsName.AsString);
  strpcopy(tempsms.datetime,ADOQuery_smsDate.AsString);
  strpcopy(tempsms.sms_msg,ADOQuery_smsMessage.AsString);

  //这里已经从Form_ShortMessage中获取了大部分信息,但是还缺短信息类型和时间
  ADOQuery_sms.Close;
  ListView_ShortMessageSort('');
end;

function TForm_main.DeleteSMSinPC(id:integer):boolean;
begin
  result:=false;
  if id>0 then
  begin
    query1.SQL.Clear;
    query1.SQL.Add('delete from shortmessage where ');
    query1.SQL.Add(' SerialNo='+inttostr(id));
    try
      query1.ExecSQL;
      result:=true;
    except
      result:=false;
    end;
  end;
end;

function TForm_main.AddSmsToList(ulrecn:PPC_SMS_Content;Location:string):integer;
var tempSMS:PShortMessage;
    objname:array[0..PHB_name_len+3-1] of char;
    objmsg:array[0..MAX_MSG_LEN-1] of char;
    smsdatetime:string;
    objtime:array[0..sizeof(T_MFW_SMS_SCTP)+6] of char;
    i,oldcount:integer;
    str1,str2:string;
begin
  result:=-1;
  getmem(tempSMS,sizeof(TShortMessage));
  fillchar(tempSMS^,sizeof(TShortMessage),#0);
  move(ulrecn^,tempSMS.data,sizeof(TPC_SMS_Content));
  strpcopy(tempsms.Location,Location);
  tempsms.serialNo:=-1;
  strpcopy(tempsms.SN,format('%.3d',[ulrecn.id]));

  if Location='手机' then  //flash内显示的类型和sim卡、pc显示的类型有一些不同
  begin
    case ulrecn.state of
    PCSYN_SMS_STOR_UNSENT:
      begin
        tempSMS.Sort:='STO UNSENT';
        inc(Count_SMS_Flash_MO);
      end;
    PCSYN_SMS_STOR_SENT:
      begin
        tempSMS.Sort:='STO SENT';
        inc(Count_SMS_Flash_MO);
      end;
    PCSYN_SMS_MT:
      begin
        tempSMS.Sort:='SMS MT';
        inc(Count_SMS_Flash_MT);
      end;
    end;
    Count_SMS_Flash:= Count_SMS_Flash_MO+Count_SMS_Flash_MT;
  end;
  if Location='SIM' then
  begin
    case ulrecn.state of
      PCSYN_SMS_UNKNOWN:  tempSMS.Sort:='UNKNOWN';
      PCSYN_SMS_UNREAD:
        begin
          tempSMS.Sort:='REC UNREAD';
          inc(Count_SMS_SIM_MT);
        end;
      PCSYN_SMS_READ:
        begin
          tempSMS.Sort:='REC READ';
          inc(Count_SMS_SIM_MT);
        end;
      PCSYN_SMS_STOR_UNSENT:
        begin
          tempSMS.Sort:='STO UNSENT';
          inc(Count_SMS_SIM_MO);
        end;
      PCSYN_SMS_STOR_SENT:
        begin
          tempSMS.Sort:='STO SENT';
          inc(Count_SMS_SIM_MO);
        end;
    end;
    Count_SMS_SIM:=Count_SMS_SIM_MO+Count_SMS_SIM_MT;
  end;

  strcopy(tempSMS.number,ulrecn.addr);
  UnicodetoASC(ulrecn.name,objname); //将姓名unicode中文转换为asc
  strpcopy(tempSMS.name,objname);

  if ord(ulrecn.time.month[1])<>0 then//如果有月份表示
  begin
    ChangeTime(objtime,@ulrecn.time);
    smsdatetime:=objtime+'+'+format('%.2d',[ulrecn.time.timezone]);
    strpcopy(tempSMS.datetime,smsdatetime);
  end;
  fillchar(objmsg,sizeof(objmsg),#0);
  if (ulrecn.dcs=$08)or(ulrecn.dcs=$18) then
    UnicodetoASC(ulrecn.sms_msg,objmsg) //将短消息unicode中文转换为asc
  else
    GSMtoASC2(ulrecn.sms_msg,objmsg,ulrecn.msg_len);
  move(objmsg[0],tempsms.sms_msg[0],ulrecn.msg_len);

//将新建的短消息加入每个类型末尾的一个单元
  if Location='PC' then
  begin
    ShortMessageList.Insert(Count_SMS_PC,tempsms);
    result:=Count_SMS_PC;
  end else
    if Location='手机' then
    begin
      ShortMessageList.Insert(Count_SMS_PC+Count_SMS_Flash-1,tempsms);
      result:=Count_SMS_PC+Count_SMS_Flash-1;
    end else
      if Location='SIM' then
      begin
        oldcount:=ShortMessageList.count;
        for i:=Count_SMS_PC+Count_SMS_Flash to ShortMessageList.count-1 do
        begin
          str1:=PShortMessage(ShortMessageList.Items[i]).SN;
          str2:=tempSMS.SN;
          if CompareText(str2,str1)>0 then continue;
          ShortMessageList.Insert(i,tempsms);
          result:=i;
          break;
        end;
        if ShortMessageList.count=oldcount then//如果id是最大的,那么就把这条记录放在最后
        begin
          ShortMessageList.Add(tempSMS);
          result:=ShortMessageList.count-1;
        end;
      end;
end;

//*****************CallRecord**********************//
procedure configCRlist;
var listcount:integer;
begin
  listcount:=CallRecordList.Count;
  while listcount>0 do
  begin
    if PCallRecord(CallRecordList.Items[listcount-1]).serialNo=-1 then
    begin
      if PCallRecord(CallRecordList.Items[listcount-1]).CRType='未接电话' then
        dec(Count_CR_LMN);
      if PCallRecord(CallRecordList.Items[listcount-1]).CRType='已接电话' then
        dec(Count_CR_LRN);
      if PCallRecord(CallRecordList.Items[listcount-1]).CRType='已拨电话' then
        dec(Count_CR_LDN);
      freemem(CallRecordList.Items[listcount-1]);
      CallRecordList.Delete(listcount-1);
    end;
    dec(listcount);
  end;
end;

procedure docompleteCR;
begin
  CurCR_index:=0;
  status_CR:=PC_CR_status_init;
  sleep(1000);
  form_progressbar.Hide;
  form_progressbar.close;
  case form_main.FLastViewState_callrecord of
    ALL_CR:Form_main.SpeedButton_callrecordClick(nil);
    M_CR: Form_main.ListView_callrecord_subClick(nil);
    R_CR: Form_main.ListView_callrecord_subClick(nil);
    D_CR: Form_main.ListView_callrecord_subClick(nil);
  end;
end;

procedure pc_callback_CRGetInfo(p:pointer);
begin
  if pPC_Interface_Info(p).status<>ord(PC_Error_NoError) then
  begin
    case pPC_Interface_Info(p).status of
      ord(PC_Error_SerialNoResponse):
      begin
        form_main.statusbar1.Panels[0].Text:='通讯超时,可能串口连接有故障';//说明target响应timeout,for example:serial is invalid
        Serial_Close;
        Comhandle:=2;
        form_main.StatusBar1.Panels[1].Text:='未连接';
      end;
      ord(PC_Error_MMINotAllow):form_main.statusbar1.Panels[0].Text:='手机未设在同步状态菜单内';//手机不允许pc同步, 要先进入菜单工具箱->pc同步
      ord(PC_Error_MMINeedPause):form_main.statusbar1.Panels[0].Text:='有电话进来,同步暂停';
      ord(App_Error_ReadError):form_main.statusbar1.Panels[0].Text:='读取通话记录过程中有错误!';
      ord(App_Error_DeleteError):form_main.statusbar1.Panels[0].Text:='删除通话记录失败,记录在手机里已经不存在';
      ord(App_Error_InfoError):form_main.statusbar1.Panels[0].Text:='获取通话记录信息有错误';
    end;
    configCRlist;
    docompleteCR;
    exit;
  end;

  case status_CR of
    PC_CR_status_init://下载取消时
    begin
      if PPC_Interface_Info(p).pdata_cmd<>nil then
        freemem(PPC_Interface_Info(p).pdata_cmd);
      if PPC_Interface_Info(p).pdata_dlbuff<>nil then
        freemem(PPC_Interface_Info(p).pdata_dlbuff);
      if PPC_Interface_Info(p).pdata_ulbuff<>nil then
        freemem(PPC_Interface_Info(p).pdata_ulbuff);
      if p<>nil then
      begin
        freemem(p);
        p:=nil;
      end;
      docompleteCR;
      exit;
    end;
    PC_CR_status_getCRcount: //获得各种来电的数目
    begin
      doCRCount(p);
      form_main.Panel_cr.Caption:='通话记录: 未接电话数:'+inttostr(Count_CR_LMN)
                                  +',已接电话数:'+inttostr(Count_CR_LRN)
                                  +',已拨电话数:'+inttostr(Count_CR_LDN);
      form_main.statusbar1.Panels[0].Text:='正在下载通话记录信息...';

      if Count_CR_LMN+Count_CR_LRN+Count_CR_LDN>0 then
      begin
        form_progressbar.Label_status.Caption:='正在下载通话记录('+inttostr(CurCR_index)+'/'+inttostr(Count_CR_LMN+Count_CR_LRN+Count_CR_LDN)+')';
        form_progressbar.ProgressBar1.Max:=Count_CR_LMN+Count_CR_LRN+Count_CR_LDN+1;
        form_progressbar.ProgressBar1.Min:=1;
        form_progressbar.ProgressBar1.Step:=1;
        form_progressbar.ProgressBar1.Position:=1;
      end else
      begin
        form_progressbar.Label_status.Caption:='正在下载通话记录';
        form_progressbar.ProgressBar1.Max:=2;
        form_progressbar.ProgressBar1.Min:=1;
        form_progressbar.ProgressBar1.Position:=2;
      end;
      //清空所有内存列表
      CurCR_index:=0;
      while (CallRecordList.Count>0) do
      begin
        freemem(Pchar(CallRecordList[0]));
        CallRecordList.Delete(0);
      end;

      if Count_CR_LMN>0 then
      begin
        status_CR:=PC_CR_status_getCRLMNList;
        GetCRContent(CR_TYPE_LMN,CurCR_index,@pc_callback_CRGetInfo);
        exit;
      end else
      begin
        if Count_CR_LRN>0 then
        begin
          status_CR:=PC_CR_status_getCRLRNList;
          GetCRContent(CR_TYPE_LRN,CurCR_index,@pc_callback_CRGetInfo);
          exit;
        end else
        begin
          if Count_CR_LDN>0 then
          begin
            status_CR:=PC_CR_status_getCRLDNList;
            GetCRContent(CR_TYPE_LDN,CurCR_index,@pc_callback_CRGetInfo);
            exit;
          end;
        end;
      end;
      form_main.statusbar1.Panels[0].Text:='下载通话记录已完成';
    end;
    PC_CR_status_getCRLMNList:
    begin
      doCRList(p,CR_TYPE_LMN);
      form_progressbar.ProgressBar1.StepIt;
      inc(CurCR_index);
      form_progressbar.Label_status.Caption:='正在下载通话记录('+inttostr(CurCR_index)+'/'+inttostr(Count_CR_LMN+Count_CR_LRN+Count_CR_LDN)+')';
      if CurCR_index<Count_CR_LMN then
      begin
        GetCRContent(CR_TYPE_LMN,CurCR_index,@pc_callback_CRGetInfo);
        exit;
      end else
      begin
        CurCR_index:=0;
        if Count_CR_LRN>0 then
        begin
          status_CR:=PC_CR_status

⌨️ 快捷键说明

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