Lin Min did not know 2002-6-25
I recently bought a NOKIA3210 data cable on the computer city, playing a few days to change LOGO, and then throw the data line aside after the ringing. Until a few days, I saw the secondary development control with a mobile phone short message on http://oxygensoftware.com, I remembered how many data cables don't have to be used, and I have recently learned C #, I feel that a short message is made with C #. Normal, after a multi-day test, finally realize the mode of using computer data cable mobile phone, and realize the short message on the local area network platform. Since there are many places where the unit uses a mobile phone short message, it may be from the web page, it may be a form in Outlook, or some system of a host of a non-Windows operating system, so after thinking, it feels best The solution is to use Windows "Services", and the corresponding information is read from the fixed format text file in a directory and sent it. Other clients only need to write text messages to this directory. Let us start after thinking down! Let's explain the development platform first: Windows 2000 Advance Server operating system, Visual Studio .NET, Oxygen SMS ActiveX Control V2.3 (Share Ware), NOKIA 3210 mobile phone is connected to COM1 through the data cable. Run Visual Studio .NET, create a new C # project, select the "Windows Server" type project, named "SMSServer". At the design screen of Server1, "ServerName" is named "SMSServer". Click the "View Designer button" to switch to the design screen, drag the clock control in the "Windows Forms" toolbox, name "SmStimer", drag a "EventLog" control in the "Components" toolbox. Name "EventLog1". Click "Add Reference" in the Project menu, select the "COM" page, browse to the directory where the Oxygen SMS ActiveX Control V2.3 program is installed, and find SMSControl.ocx to add to "Selected Components".
The Server1.cs replace the code P>
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.ServiceProcess; using System.IO; using System. Text; P>
namespace SmsServer {public class SmsServer: System.ServiceProcess.ServiceBase {private System.Timers.Timer SmsTimer; private System.Diagnostics.EventLog eventLog1; public O2SMSXControl.O2SMSX SmsX1; // objects defined SMS P>
/// public smsserver () {/ / This call is required by the windows.forms component design; p> // Todo: add anyinitizational after the initcomponent call} p> // the main entry Point for the process static void Main () {System.ServiceProcess.ServiceBase [] ServicesToRun; P> // More than one user Service may run within the same process to add // another service to this process, change the. FOLLOWING LINE TO / / Create a second service object For example, // // ServicesToRun = New System.ServiceProcess.ServiceBase [] {new Service1 (), new MySecondUserService ()};. // ServicesToRun = new System.ServiceProcess.ServiceBase [] {new SMSServer ()}; p> system.serviceProcess.serviceBase.Run (ServiceStorun);} p> /// (System.comPonentModel.isupportInitialize). BeginInit (); (this.ComponentModel.isupportInitialize) (this.EventLog1)). Begininit (); // // smstimer // this.smstimer.enable = true; this.SmsTimer.Elapsed = new System.Timers.ElapsedEventHandler (this.SmsTimer_Elapsed); // // SmsServer // this.ServiceName = "SmsServer"; ((System.ComponentModel.ISupportInitialize) (this.SmsTimer) .Ndinit (); (this.ComponentModel.isupportInitialize) (this.EventLog1)). Endinit (); p> } p> /// /// /// private void smstimer_elapsed (object sender, system.timers.elapsendeventargs e) {// When f: / sms / data / filetosend has file, turn off the clock first It sends out and deletes files and then starts the clock this.smstimer.enabled = false; p> // directory object DirectoryInfo CD = new system.io.directoryInfo (" F: // sms // data // filetosend "); // Database record variable string rsid; string rsphonenum; string rsSMSText; p> string strsql; p> // First, The current directory lists all current SMS files for Fore (fileInfo filesend in cd.getfiles ()) {TRY {// Open each file read file content filestream fs = new filestream (CD.FullName "//" Filesend .Name, FileMode.Open, FileAccess.read; StreamReader Sr; Sr = New StreamReader (FS, UnicodeEncoding.Getencoding ("GB2312")); RSID = filesend.name .tostring (); RSID = rsid.replace. SMS "," "); rsid = rsid.trim (); rsphonenum = sr.readline (); rsphonenum = rsphonenenum.trim (); if (RsphonenUm.length> 11) rsphonenum = rsphonenum.substring (0, 10); rsSMSText (); rsSMSTEXT = rsSMSText.trim (); if (rsSMSText.length> 50) rsSMSText.Substring (0,49); fs.close (); sr.close (); p> < P> // Send short information SMSX1.sendunicoicodesmsMsmessage (RSSMSTEXT.TOSTRING (), rsSMSText.toString (), 6, false, ""); p> // backup and delete file fiesend.copyto ("f : // SMS // Data // Hadbeensend // " Filesend.Name, True); Filesend.Delete ();} catch (system.exception e) {// error Write the log file EventLog1.writentry (E.MESSAGE.TOSTRING ());}} // Restart the clock this.smstimer.enabled = true;}}} In Server1.cs switching design screen, click "Add Installer" under the Properties window ", The system automatically adds the ProjectInstaller.cs file, click ServiceInstaller1, set" Server Name "to" SMSServer ", click" ServiceProcessInstaller1 ", set the Account to" Localsystem ". Select "Generate SMSServer" in the menu "Generate" to correct possible errors. Perform a DOS command line, perform the INSTALLUTIL SMSSERVER, and if the installutil program is not found, you can't find the installutil program. At this time, "SMSServer" service can be found under "service" of the management tool. Start the service.