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

📄 手机短信息的编程.htm

📁 GPS的资料,上来和大家分享,正做这个的朋友可以看看.
💻 HTM
📖 第 1 页 / 共 5 页
字号:
&lt;returns&gt;信息长度及编码后的字符串&lt;/returns&gt;<BR>static public string 
EncodingUCS2(string s)<BR>{<BR>StringBuilder sb=new StringBuilder();<BR>byte [] 
buf=Encoding.Unicode.GetBytes(s);<BR>sb.Append(buf.Length.ToString("X2"));<BR>for(int 
i=0;i&lt;buf.Length;i+=2)<BR>{<BR>sb.Append(buf[i+1].ToString("X2"));<BR>sb.Append(buf[i].ToString("X2"));<BR>}<BR>return 
sb.ToString();<BR>}</P>
<P>/// &lt;summary&gt;<BR>/// 中文短信息UCS2解码<BR>/// &lt;/summary&gt;<BR>/// 
&lt;param name="s"&gt;要解码的信息&lt;/param&gt;<BR>/// 
&lt;returns&gt;解码后的中文字符串&lt;/returns&gt;<BR>static public string 
DecodingUCS2(string s)<BR>{<BR>byte [] buf=new byte[s.Length];<BR>for(int 
i=0;i&lt;s.Length;i+=4)<BR>{<BR>buf[i/2]=byte.Parse(s.Substring(2+i,2),System.Globalization.NumberStyles.AllowHexSpecifier);<BR>buf[i/2+1]=byte.Parse(s.Substring(i,2),System.Globalization.NumberStyles.AllowHexSpecifier);<BR>}<BR>return 
Encoding.Unicode.GetString(buf);<BR>}</P>
<P>}<BR>}<BR></P>&nbsp;<A 
href="http://liujace.itpub.net/post/4284/240834">查看全文</A>
<P></P><BR style="CLEAR: both"></DIV>
<DIV class=contentcomments><A class=commentfoot 
href="http://liujace.itpub.net/post/4284/240834#comments">评论 (0)</A> <A 
class=commentfoot href="http://liujace.itpub.net/trackbacks/4284/240834">引用 
(0)</A> <A class=commentfoot 
href="http://liujace.itpub.net/category/4284/10421">手机编程[3]</A> <A 
class=commentfoot href="http://liujace.itpub.net/category/4284/7950">技术资源[7]</A> 
<A class=commentfoot 
href="http://liujace.itpub.net/category/4284/7956">开源项目[1]</A> <A 
class=commentfoot 
href="http://liujace.itpub.net/category/4284/7955">C#编程[11]</A> <A 
class=commentfoot 
href="http://liujace.itpub.net/category/4284/42845">随心记事[0]</A> </DIV></DIV>
<DIV class=post><!-- <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"                                   xmlns:dc="http://purl.org/dc/elements/1.1/"                                   xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"><rdf:Description                             rdf:about="http://liujace.itpub.net/post/4284/240833"                             dc:identifier="http://liujace.itpub.net/post/4284/240833"                             dc:title="C#2.0下的串口编程-手机连接2"                             trackback:ping="http://blog.itpub.net//trackback.php?id=240833"/></rdf:RDF> -->
<DIV class=contenttitle><A 
href="http://liujace.itpub.net/post/4284/240833">C#2.0下的串口编程-手机连接2</A></DIV>
<DIV class=contenttime>liujace - by - 14 十二月, 2006 21:56</DIV>
<DIV id=blogbody>
<P>
<P>using System;<BR>using System.Collections.Generic;<BR>using 
System.ComponentModel;<BR>using System.Data;<BR>using System.Drawing;<BR>using 
System.Text;<BR>using System.Windows.Forms;<BR>using System.IO.Ports;<BR>using 
System.Threading;</P>
<P>namespace amoi<BR>{<BR>public partial class Form2 : Form<BR>{<BR>private 
SerialPort sp = new SerialPort();<BR>private StringBuilder sb = new 
StringBuilder();<BR>public Form2()<BR>{<BR>InitializeComponent();<BR>}</P>
<P>private void Form2_Load(object sender, EventArgs e)<BR>{<BR>string[] ports = 
SerialPort.GetPortNames();<BR>cmbCurCom.DataSource = 
ports;<BR>cmbBitRate.SelectedIndex = 0;<BR>cmbCurCom.SelectedIndex = 0;<BR>}</P>
<P>private void btOpenCom_Click(object sender, EventArgs e)<BR>{<BR>//SerialPort 
sp = new SerialPort();<BR>sp.BaudRate = 
int.Parse(cmbBitRate.Text);<BR>sp.DataBits = 8;<BR>sp.Parity = 
Parity.None;<BR>sp.PortName = cmbCurCom.Text;<BR>sp.StopBits = 
StopBits.One;<BR>// sp.Close();<BR>sp.Open();<BR>btOpenCom.Enabled = 
false;<BR>btCloseCom.Enabled = true;</P>
<P>
<P>}</P>
<P>private void btCloseCom_Click(object sender, EventArgs e)<BR>{<BR>if 
(sp.IsOpen)<BR>{<BR>sp.Close();<BR>}<BR>btOpenCom.Enabled = 
true;<BR>btCloseCom.Enabled = false;<BR>}</P>
<P>private void btTestAT_Click(object sender, EventArgs 
e)<BR>{<BR>//发送数据<BR>//SendStringData(sp,"AT");<BR>//也可用字节的形式发送数据<BR>if 
(!sp.IsOpen)<BR>{<BR>sp.Open();<BR>}<BR>SendBytesData(sp, "atr");</P>
<P>//开启接收数据线程<BR>ReceiveData(sp);</P>
<P><BR>}</P>
<P>//==============================<BR>//发送字符串数据<BR>private void 
SendStringData(SerialPort serialPort, string 
txt)<BR>{<BR>serialPort.Write(txt);<BR>}</P>
<P>/// &lt;summary&gt;<BR>/// 开启接收数据线程<BR>/// &lt;/summary&gt;<BR>private void 
ReceiveData(SerialPort serialPort)<BR>{<BR>//同步阻塞接收数据线程<BR>Thread threadReceive 
= new Thread(new 
ParameterizedThreadStart(SynReceiveData));<BR>threadReceive.Start(serialPort);</P>
<P><BR>//也可用异步接收数据线程<BR>//Thread threadReceiveSub = new Thread(new 
ParameterizedThreadStart(AsyReceiveData));<BR>//threadReceiveSub.Start(serialPort);</P>
<P>}</P>
<P>//发送二进制数据<BR>private void SendBytesData(SerialPort serialPort, string 
txt)<BR>{//61 74 0D 0A 0A<BR>//97 116 13 10 10<BR>byte[] bytesSend = 
System.Text.Encoding.Default.GetBytes(txt);<BR>serialPort.Write(bytesSend, 0, 
bytesSend.Length);<BR>}</P>
<P>//同步阻塞读取<BR>private void SynReceiveData(object 
serialPortobj)<BR>{<BR>SerialPort serialPort = 
(SerialPort)serialPortobj;<BR>System.Threading.Thread.Sleep(0);<BR>serialPort.ReadTimeout 
= 1000;<BR>try<BR>{<BR>//阻塞到读取数据或超时(这里为2秒)<BR>byte firstByte = 
Convert.ToByte(serialPort.ReadByte());<BR>int bytesRead = 
serialPort.BytesToRead;<BR>byte[] bytesData = new byte[bytesRead + 
1];<BR>bytesData[0] = firstByte;<BR>for (int i = 1; i &lt;= bytesRead; 
i++)<BR>bytesData[i] = 
Convert.ToByte(serialPort.ReadByte());<BR>//txtReceive.Text = 
System.Text.Encoding.Default.GetString(bytesData);</P>
<P>sb.AppendLine(System.Text.Encoding.Default.GetString(bytesData)); //+ 
System.Environment.NewLine;<BR>// Convert.ToBase64String(bytesData, 
Base64FormattingOptions.None);<BR>//sb.AppendLine(Convert.ToBase64String(bytesData, 
Base64FormattingOptions.None));<BR>}<BR>catch (Exception 
e)<BR>{<BR>MessageBox.Show(e.Message);<BR>//处理超时错误<BR>}</P>
<P>serialPort.Close();</P>
<P>}</P>
<P>//异步读取<BR>private void AsyReceiveData(object 
serialPortobj)<BR>{<BR>SerialPort serialPort = 
(SerialPort)serialPortobj;<BR>System.Threading.Thread.Sleep(500);<BR>try<BR>{<BR>//txtReceive.Text 
= serialPort.ReadExisting();<BR>sb.AppendLine(serialPort.ReadExisting());// 
+System.Environment.NewLine;<BR>}<BR>catch (Exception 
e)<BR>{<BR>MessageBox.Show(e.Message);<BR>//处理错误<BR>}<BR>serialPort.Close();<BR>}</P>
<P>///////////////////////////////</P>
<P>private void btTestCom_Click(object sender, EventArgs 
e)<BR>{<BR>txtDebug.Text = sb.ToString();<BR>sb.Remove(0, sb.Length);<BR>}</P>
<P>private void btSmsCenter_Click(object sender, EventArgs 
e)<BR>{<BR>//发送数据<BR>//SendStringData(sp,"AT");<BR>//也可用字节的形式发送数据<BR>if 
(!sp.IsOpen)<BR>{<BR>sp.Open();<BR>}<BR>SendBytesData(sp, "at+csca ?rn");</P>
<P>//开启接收数据线程<BR>ReceiveData(sp);</P>
<P><BR>// txtDebug.Text += "输出缓冲区:"+sp.WriteBufferSize.ToString() + 
System.Environment.NewLine;<BR>//// txtDebug.Text += sp.ReadLine() + 
System.Environment.NewLine;</P>
<P>// txtDebug.Text += "输入缓冲区:" + sp.ReadBufferSize.ToString() + 
System.Environment.NewLine;</P>
<P>}</P>
<P>private void btExeMyCode_Click(object sender, EventArgs 
e)<BR>{<BR>//发送数据<BR>//SendStringData(sp,"AT");<BR>//也可用字节的形式发送数据<BR>if 
(!sp.IsOpen)<BR>{<BR>sp.Open();<BR>}<BR>SendBytesData(sp, txtMyCode.Text.Trim() 
+ "rn");</P>
<P>//开启接收数据线程<BR>ReceiveData(sp);</P>
<P>
<P>}</P>
<P>private void btJieMa_Click(object sender, EventArgs e)<BR>{<BR>string s = 
txtDebug.Text;<BR>string phone = "";<BR>string text = "";<BR>DateTime sendTime = 
new DateTime();<BR>jace.CN.SMSLib.CNText.GSMCode code = new 
jace.CN.SMSLib.CNText.GSMCode();<BR>string SCA = "";<BR>bool isOK = 
jace.CN.SMSLib.CNText.DecodingMsg(s, ref phone, ref text, ref sendTime, ref 
code, ref SCA);<BR>if (isOK)<BR>{<BR>//来源电话号<BR>txtCnInfo.Text += phone + 
System.Environment.NewLine;</P>
<P>//信息内容<BR>txtCnInfo.Text += text + 
System.Environment.NewLine;<BR>txtCnInfo.Text += sendTime.ToString() + 
System.Environment.NewLine;<BR>txtCnInfo.Text += SCA + 
System.Environment.NewLine;<BR>txtCnInfo.Text += isOK.ToString() + 
System.Environment.NewLine;<BR>}<BR>}</P>
<P><BR>}<BR>}</P>&nbsp;<A 
href="http://liujace.itpub.net/post/4284/240833">查看全文</A>
<P></P><BR style="CLEAR: both"></DIV>
<DIV class=contentcomments><A class=commentfoot 
href="http://liujace.itpub.net/post/4284/240833#comments">评论 (0)</A> <A 
class=commentfoot href="http://liujace.itpub.net/trackbacks/4284/240833">引用 
(0)</A> <A class=commentfoot 
href="http://liujace.itpub.net/category/4284/10421">手机编程[3]</A> <A 
class=commentfoot href="http://liujace.itpub.net/category/4284/7950">技术资源[7]</A> 
<A class=commentfoot 
href="http://liujace.itpub.net/category/4284/7956">开源项目[1]</A> <A 
class=commentfoot 
href="http://liujace.itpub.net/category/4284/7955">C#编程[11]</A> <A 
class=commentfoot 
href="http://liujace.itpub.net/category/4284/42845">随心记事[0]</A> </DIV></DIV>
<DIV class=post><!-- <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"                                   xmlns:dc="http://purl.org/dc/elements/1.1/"                                   xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"><rdf:Description                             rdf:about="http://liujace.itpub.net/post/4284/240685"                             dc:identifier="http://liujace.itpub.net/post/4284/240685"                             dc:title="关于.NET 中计算列的问题"                             trackback:ping="http://blog.itpub.net//trackback.php?id=240685"/></rdf:RDF> -->
<DIV class=contenttitle><A 
href="http://liujace.itpub.net/post/4284/240685">关于.NET 中计算列的问题</A></DIV>
<DIV class=contenttime>liujace - by - 14 十二月, 2006 11:31</DIV>
<DIV id=blogbody>
<P>
<P>一般在.NET中连接数据库,然后因为某些列要进行自动计算(根据其它列值的结果),有朋友可以在数据库中定义"计算列",确实在部分情况下在数据库在定义"计算列"可以解决问题,但是如果对应的"计算公式"是变化的,例如:工资的计算公式,那么就不能每次修改数据库的"计算列"来处理,于是用到了.NET中的dt.Columns["列"].Expression属性,但这个属性一但设置好后,是可以计算出正常的结果,并显示于DataGridView中,但在提交更新da.Update(dt)时会出现"来自 
SourceColumn“列”的列映射失败,原因在于 DataColumn“列”是计算所得的列。",此原因是由于约束造成的.解决此问题的办法:</P>
<P>1.遍历DataGridView或dt中各行的值,依次插入到数据库中</P>
<P>2.遍历DataGridView或dt中各行的值,依次插入到另一个另一个dt中,再update</P>
<P>以上两法都行,但由上两法简处理得:</P>
<P>DataTable dt1 = dt.Clone();<BR>for (int i = 0; i &lt; dt1.Columns.Count; 
i++)<BR>{<BR>dt1.Columns[i].Expression = 
null;<BR>}<BR>dt1.Merge(dt);<BR>da.Update(dt1);</P>
<P>道理同上一样,当然你得生成UpdateCommand与其它命令.</P>
<P>注意:</P>

⌨️ 快捷键说明

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