main.pas
来自「是一个手机功能的模拟程序」· PAS 代码 · 共 1,568 行 · 第 1/5 页
PAS
1,568 行
form_progressbar.Label_status.Caption:='保存短消息成功';
form_progressbar.ProgressBar1.StepIt;
doputSMSRecord(p);
PShortMessage(shortmessagelist[CurInsSMS_Index]).serialNo:=strtoint(PShortMessage(shortmessagelist[CurInsSMS_Index]).sn);
configsmslist;
form_main.statusbar1.Panels[0].Text:='保存消息记录已完成';
end;
PC_SMS_status_CopySMS://存到手机信箱
begin
form_progressbar.Label_status.Caption:='复制短消息成功';
form_progressbar.ProgressBar1.StepIt;
doCopySMS(p);
PShortMessage(shortmessagelist[CurInsSMS_Index]).serialNo:=strtoint(PShortMessage(shortmessagelist[CurInsSMS_Index]).sn);
configsmslist;//将删除的短消息从shortmessagelist中删除
form_main.statusbar1.Panels[0].Text:='复制短消息记录已完成';
end;
end;
CurSMS_index:=1;
status_SMS:=PC_SMS_status_init;
form_main.Panel_sms.Caption:='短消息: PC中条目数:'+inttostr(Count_SMS_PC)
+',手机存储器中条目数:'+inttostr(Count_SMS_Flash)+'(最多'+inttostr(MaxCount_SMS_FLash)
+'),SIM卡中条目数:'+inttostr(Count_SMS_SIM)+'(最多'+inttostr(MaxCount_SMS_SIM)+')';
form_progressbar.ProgressBar1.Position:=1;
form_progressbar.Hide;
form_progressbar.close;
//根据上次选择显示的状态来显示新的内容
case Form_main.FLastViewState_ShortMessage of
ALL_SMS:Form_main.SpeedButton_ShortMessageClick(nil);
V_SMS: Form_main.ListView_ShortMessage_subClick(nil);
S_SMS: Form_main.ListView_ShortMessage_subClick(nil);
P_SMS: Form_main.ListView_ShortMessage_subClick(nil);
end;
end;
procedure TForm_main.EditSMS;
var tempsmsRec:TPC_SMS_Content;
objmsg:array[0..MAX_MSG_LEN-1] of char;
rp:byte;
index:integer;
i:integer;
begin
if Form_Shortmessage.ShowModal=mrOK then
begin
fillchar(tempsmsRec,sizeof(TPC_SMS_Content),#0);
if EditState_SMS<>NewSMS then
begin
index:=strtoint(ListView_Shortmessage_main.Selected.SubItems[6]);
move(PShortMessage(ShortMessageList.Items[index]).data,tempsmsRec,sizeof(TPC_SMS_Content));
end else
tempsmsRec.state:=PCSYN_SMS_STOR_UNSENT;
if Form_ShortMessage.ListView_number.Items.Count>0 then
begin
strpcopy(tempsmsRec.addr,Form_ShortMessage.ListView_number.Items[0].caption);
strpcopy(tempsmsRec.name,Form_ShortMessage.ListView_number.Items[0].subitems[0]);
end;
fillchar(objmsg,sizeof(objmsg),#0);
strpcopy(objmsg,Form_ShortMessage.Edit_msg.Lines.Text);
fillchar(tempsmsRec.sms_msg,sizeof(tempsmsRec.sms_msg),#0);
tempsmsRec.msg_len:=ASCtoUnicode(objmsg,tempsmsRec.sms_msg);
if tempsmsRec.msg_len=length(Form_ShortMessage.Edit_msg.Lines.Text) then
tempsmsRec.dcs:=$00
else
tempsmsRec.dcs:=$08;
//在读取状态,所有的短消息的状态都保持原样;只有在做新建、编辑、回复、转发等行为时,我们都认为属于新的PCSYN_SMS_STOR_UNSENT的类型
//note:tempsmsitem.dcs在target端的mmi_Sys_Sim完成,所以这里的dcs不用附值,但是我们是用它在往PC数据库上添加记录时作为一个判断依据
tempsmsRec.flag:=true;
rp := 0; //* reply path = 0
if Form_ShortMessage.RadioButton_send.Checked then
begin
status_SMS:=PC_SMS_status_SendSMS;//send
tempsmsRec.state:=PCSYN_SMS_STOR_UNSENT;
fillchar(tempsmsRec.time,sizeof(T_MFW_SMS_SCTP),#0);
putSMSRecord(PC_SMS_status_SendSMS,rp,@tempsmsRec,@pc_callback_SMSGetInfo);
form_progressbar.Label_status.Caption:='正在发送短消息……';
form_progressbar.ProgressBar1.Max:=1;
form_progressbar.ProgressBar1.Min:=1;
form_progressbar.ProgressBar1.Step:=1;
form_progressbar.ProgressBar1.Position:=1;
form_progressbar.Showmodal;
end;
if Form_ShortMessage.RadioButton_savesend.Checked then
begin
if Count_SMS_SIM>=MaxCount_SMS_SIM then begin showmessage('SIM卡短消息已满,无法增加新记录!');exit; end;
status_SMS:=PC_SMS_status_SaveSendSMS;//send and save
tempsmsRec.state:=PCSYN_SMS_STOR_SENT;
fillchar(tempsmsRec.time,sizeof(T_MFW_SMS_SCTP),#0);
for i:=Count_SMS_PC+Count_SMS_Flash to shortmessagelist.count-1 do
begin
//查询是否是紧挨着的
if (i-Count_SMS_PC-Count_SMS_Flash+1>=PShortmessage(shortmessagelist[i]).data.id) then continue;
break;
end;
if (Count_SMS_PC+Count_SMS_Flash=shortmessagelist.count) then i:=Count_SMS_PC+Count_SMS_Flash;
tempsmsRec.id:=i-Count_SMS_PC-Count_SMS_Flash+1;//找到空的位置存放
CurInsSMS_Index:=Form_main.AddSmsToList(@tempsmsRec,'SIM');
putSMSRecord(PC_SMS_status_SendSMS,rp,@tempsmsRec,@pc_callback_SMSGetInfo);
form_progressbar.Label_status.Caption:='正在发送保存短消息……';
form_progressbar.ProgressBar1.Max:=1;
form_progressbar.ProgressBar1.Min:=1;
form_progressbar.ProgressBar1.Step:=1;
form_progressbar.ProgressBar1.Position:=1;
form_progressbar.Showmodal;
end;
if Form_ShortMessage.RadioButton_save.Checked then
begin
if Count_SMS_SIM>=MaxCount_SMS_SIM then begin showmessage('SIM卡短消息已满,无法增加新记录!');exit; end;
status_SMS:=PC_SMS_status_SaveSMS;//save
tempsmsRec.state:=PCSYN_SMS_STOR_UNSENT;
fillchar(tempsmsRec.time,sizeof(T_MFW_SMS_SCTP),#0);
for i:=Count_SMS_PC+Count_SMS_Flash to shortmessagelist.count-1 do
begin
if (i-Count_SMS_PC-Count_SMS_Flash+1>=PShortmessage(shortmessagelist[i]).data.id) then continue;
break;
end;
if (Count_SMS_PC+Count_SMS_Flash=shortmessagelist.count) then i:=Count_SMS_PC+Count_SMS_Flash;
tempsmsRec.id:=i-Count_SMS_PC-Count_SMS_Flash+1;//找到空的位置存放
CurInsSMS_Index:=Form_main.AddSmsToList(@tempsmsRec,'SIM');
putSMSRecord(PC_SMS_status_SaveSMS,rp,@tempsmsRec,@pc_callback_SMSGetInfo);
form_progressbar.Label_status.Caption:='正在保存短消息……';
form_progressbar.ProgressBar1.Max:=1;
form_progressbar.ProgressBar1.Min:=1;
form_progressbar.ProgressBar1.Step:=1;
form_progressbar.ProgressBar1.Position:=1;
form_progressbar.Showmodal;
end;
if Form_ShortMessage.RadioButton_copy.Checked then
begin //只有针对sim卡中的短消息才能做save to flash,手机内的短消息不可能做这一步
if Count_SMS_Flash>=MaxCount_SMS_FLash then begin showmessage('手机短消息已满,无法增加新记录!');exit; end;
status_SMS:=PC_SMS_status_CopySMS;//save to flash
if MessageDlg('删除SIM卡中该消息?',mtConfirmation, [mbYes, mbNo], 0)=mrYes then
begin
PShortMessage(ShortMessageList.Items[index]).serialNo:=-1;
//如果要复制到手机flash中去,则需要将sim卡里的记录状态改成为手机里的记录状态
case tempsmsRec.state of
PCSYN_SMS_UNREAD,
PCSYN_SMS_READ:tempsmsRec.state:=PCSYN_SMS_MT;
PCSYN_SMS_STOR_UNSENT:tempsmsRec.state:=PCSYN_SMS_STOR_UNSENT;
PCSYN_SMS_STOR_SENT:tempsmsRec.state:=PCSYN_SMS_STOR_SENT;
end;
tempsmsRec.id:=Count_SMS_Flash+1;
CurInsSMS_Index:=Form_main.AddSmsToList(@tempsmsRec,'手机');
CopySMS(1,strtoint(ListView_Shortmessage_main.Selected.SubItems[0]),@tempsmsRec,@pc_callback_SMSGetInfo);
form_progressbar.Label_status.Caption:='正在复制短消息……';
form_progressbar.ProgressBar1.Max:=1;
form_progressbar.ProgressBar1.Min:=1;
form_progressbar.ProgressBar1.Step:=1;
form_progressbar.ProgressBar1.Position:=1;
form_progressbar.Showmodal;
end else
begin
case tempsmsRec.state of
PCSYN_SMS_UNREAD,
PCSYN_SMS_READ:tempsmsRec.state:=PCSYN_SMS_MT;
PCSYN_SMS_STOR_UNSENT:tempsmsRec.state:=PCSYN_SMS_STOR_UNSENT;
PCSYN_SMS_STOR_SENT:tempsmsRec.state:=PCSYN_SMS_STOR_SENT;
end;
tempsmsRec.id:=Count_SMS_Flash+1;
CurInsSMS_Index:=AddSmsToList(@tempsmsRec,'手机');
CopySMS(0,strtoint(ListView_Shortmessage_main.Selected.SubItems[0]),@tempsmsRec,@pc_callback_SMSGetInfo);
form_progressbar.Label_status.Caption:='正在复制短消息……';
form_progressbar.ProgressBar1.Max:=1;
form_progressbar.ProgressBar1.Min:=1;
form_progressbar.ProgressBar1.Step:=1;
form_progressbar.ProgressBar1.Position:=1;
form_progressbar.Showmodal;
end;
end;
if Form_ShortMessage.RadioButton_Delete.Checked then
begin
ToolButton_delSMSclick(self);
end;
if Form_ShortMessage.RadioButton_savePC.Checked then
begin
if (EditState_SMS=ModifySMS)and(Form_ShortMessage.RadioButton_pc.Checked) then
begin
tempsmsRec.state:=PCSYN_SMS_STOR_UNSENT;
UpdateSMStoPC(@tempsmsRec,PShortMessage(ShortMessageList.Items[index]).serialNo);
end else
AddSMStoPC(@tempsmsRec);
end;
end;
end;
procedure TForm_main.AddSMStoPC(ulrecn:PPC_SMS_Content);
var smssort:string;
smsname:string;
objmsg:array[0..MAX_MSG_LEN-1] of char;
smsdatetime:string;
objtime:array[0..sizeof(T_MFW_SMS_SCTP)+6] of char;
smsmsg:string;
tempsms:PShortMessage;
begin
Query1.Active:=False;
Query1.SQL.Clear;
Query1.SQL.Text:='insert into shortmessage ([Status],PhoneNo,Name,[Date],Message) values (:[Status],:PhoneNo,:Name,:[Date],:Message)';
case ulrecn.state of
PCSYN_SMS_UNKNOWN: smssort:='UNKNOWN';
PCSYN_SMS_UNREAD: smssort:='REC UNREAD';
PCSYN_SMS_READ: smssort:='REC READ';
PCSYN_SMS_STOR_UNSENT: smssort:='STO UNSENT';
PCSYN_SMS_STOR_SENT: smssort:='STO SENT';
PCSYN_SMS_ALL: smssort:='SMS_ALL';
PCSYN_SMS_FLASH: smssort:='SMS_FLASH';
PCSYN_SMS_FLASH_MO: smssort:='FLASH MO';
PCSYN_SMS_FLASH_MT: smssort:='FLASH MT';
PCSYN_SMS_MO: smssort:='SIM MO'; //* MO SMS message */
PCSYN_SMS_MT: smssort:='SIM MT'; //* MT SMS message */
end;
// Query1.Parameters.ParamByName('SerialNo').Value:=2147483647;
Query1.Parameters.ParamByName('[Status]').Value:=smssort;
Query1.Parameters.ParamByName('PhoneNo').Value:=strpas(ulrecn.addr);
// UnicodetoASC(ulrecn.name,objname); //将姓名unicode中文转换为asc
// strpcopy(tempSMS.name,objname);
smsname:=ulrecn.name;
Query1.Parameters.ParamByName('Name').Value:=smsname;
if ord(ulrecn.time.month[1])<>0 then//月份不为0,则说明有日期
begin
ChangeTime(objtime,@ulrecn.time);
smsdatetime:=objtime+'+'+format('%.2d',[ulrecn.time.timezone]);
end;
Query1.Parameters.ParamByName('[Date]').Value:=smsdatetime;
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);
smsmsg:=strpas(objmsg);
Query1.Parameters.ParamByName('Message').Value:=smsmsg;
Query1.ExecSQL;
Query1.close;
ADOQuery_sms.Close;
ADOQuery_sms.SQL.Clear;
ADOQuery_sms.SQL.Add('select * from shortmessage ');
ADOQuery_sms.Open;
ADOQuery_sms.Last;
getmem(tempSMS,sizeof(TShortMessage));
fillchar(tempSMS^,sizeof(TShortMessage),#0);
move(ulrecn^,tempSMS.data,sizeof(TPC_SMS_Content));
tempsms.Location:='PC';
//SN存放的是sim和flash类型短消息在手机中的唯一索引号,flash类别的这个值是连续的,sim卡这个值可能不连续
//对于PC类型,sn存放的是顺序号
//下载的过程中,flash类别的是按时间递减排序的,sim卡是按这个id值递增排序的
strpcopy(tempsms.SN,format('%.3d',[ADOQuery_sms.RecordCount]));
//serialNo现在只有对PC类型有用,存放的是PC类型每条记录在数据库中的自增变量serialNo
//并且当serialNo=-1时表示这条记录失效,configsmslist后,就会删除它
tempsms.serialNo:=ADOQuery_smsSerialNo.asInteger;
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中获取了大部分信息,但是还缺短信息类型和时间
// if trim(ADOQuery_smsDate.AsString)<>'' then
// UnChangetime(tempsms.data.flashsmsitem.time,tempsms.datetime);
// tempsms.data.flashsmsitem.flag:=true;
ShortmessageList.insert(Count_SMS_PC,tempsms);
Count_SMS_PC:=ADOQuery_sms.RecordCount;
ADOQuery_sms.Close;
ListView_ShortMessageSort('');
end;
procedure TForm_main.UpdateSMStoPC(ulrecn:PPC_SMS_Content;sn:integer);
var smssort:string;
smsname:string;
objmsg:array[0..MAX_MSG_LEN-1] of char;
smsdatetime:string;
objtime:array[0..sizeof(T_MFW_SMS_SCTP)+6] of char;
smsmsg:string;
tempsms:PShortMessage;
i:integer;
begin
Query1.Active:=False;
Query1.SQL.Clear;
Query1.SQL.Text:='update shortmessage set [Status]=:[Status],PhoneNo=:PhoneNo,Name=:Name,[Date]=:[Date],Message=:Message where SerialNo=:SerialNo';
case ulrecn.state of
PCSYN_SMS_UNKNOWN: smssort:='UNKNOWN';
PCSYN_SMS_UNREAD: smssort:='REC UNREAD';
PCSYN_SMS_READ: smssort:='REC READ';
PCSYN_SMS_STOR_UNSENT: smssort:='STO UNSENT';
PCSYN_SMS_STOR_SENT: smssort:='STO SENT';
PCSYN_SMS_ALL: smssort:='SMS_ALL';
PCSYN_SMS_FLASH: smssort:='SMS_FLASH';
PCSYN_SMS_FLASH_MO: smssort:='FLASH MO';
PCSYN_SMS_FLASH_MT: smssort:='FLASH MT';
PCSYN_SMS_MO: smssort:='SIM MO'; //* MO SMS message */
PCSYN_SMS_MT: smssort:='SIM MT'; //* MT SMS message */
end;
// Query1.Parameters.ParamByName('SerialNo').Value:=2147483647;
Query1.Parameters.ParamByName('[Status]').Value:=smssort;
Query1.Parameters.ParamByName('PhoneNo').Value:=strpas(ulrecn.addr);
// UnicodetoASC(ulrecn.name,objname); //将姓名unicode中文转换为asc
// strpcopy(tempSMS.name,objname);
smsname:=ulrecn.name;
Query1.Parameters.ParamByName('Name').Value:=smsname;
if ord(ulrecn.time.month[1])<>0 then//月份不为0,则说明有日期
begin
ChangeTime(objtime,@ulrecn.time);
smsdatetime:=objtime+'+'+format('%.2d',[ulrecn.time.timezone]);
end;
Query1.Parameters.ParamByName('[Date]').Value:=smsdatetime;
fillchar(objmsg,sizeof(objmsg),#0);
if (ulrecn.dcs=$08)or(ulrecn.dcs=$18) then
UnicodetoASC(ulrecn.sms_msg,objmsg) //将姓名unicode中文转换为asc
else
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?