Untitled
unknown
plain_text
3 years ago
1.7 kB
9
Indexable
private void SendMessage()
{
try
{
SerialPort sp = new SerialPort();
sp.PortName = _port;
sp.Open();
sp.WriteLine("AT" + Environment.NewLine);
Thread.Sleep(100);
sp.WriteLine("AT+CMGF=1" + Environment.NewLine);
Thread.Sleep(100);
sp.WriteLine("AT+CMGS=\"" + guardiannumber + "\"" + Environment.NewLine);
Thread.Sleep(100);
sp.WriteLine($"Good day {guardianname}, greetings from Carmen National High School. Your son / daughter has {status} the school on {Now.ToString("dddd, dd MMMM yyyy")} at {Now:hh:mm tt}. This is a system generated message, please don't reply." + Environment.NewLine);
Thread.Sleep(100);
sp.Write(new byte[] { 26 }, 0, 1);
Thread.Sleep(100);
var response = sp.ReadExisting();
if (response.Contains("ERROR"))
{
_notifier.ShowError("Message was not sent! But the student was logged in the system successfully!");
//MessageBox.Show("Send failed", "Message", MessageBoxButton.OK, MessageBoxImage.Error);
}
else
{
_notifier.ShowSuccess("A message was sent to your listed guardian.!");
}
sp.Close();
}
catch
{
_notifier.ShowError("Error: Communication port not configured! But the student was logged successfully");
}
}Editor is loading...