Sunteți pe pagina 1din 8

using

using
using
using
using
using
using
using
using
using
using

System;
System.Collections.Generic;
System.ComponentModel;
System.Data;
System.Drawing;
System.Linq;
System.Text;
System.IO.Ports;
System.Threading;
System.Windows.Forms;
System.Data.SqlClient;

namespace Health_Monitoring_CEP00365
{
public partial class ReadPaitentDetailscs : Form
{
internal delegate void SerialDataReceivedEventHandlerDelegate(object sender,
SerialDataReceivedEventArgs e);
//delegate void SetTextCallback(string text);
string InputData = String.Empty;
string theText;
string mn;
string sip;
public string inputbuf = String.Empty;
public string inputbuf1 = String.Empty;
public int n, i;
int a;
int rat=70;
SqlConnection con1 = new
SqlConnection("server=cyberstudents.in;uid=student;password=jv9N#w21;database=student");
SqlCommand cmd;
string txt = String.Empty;
public ReadPaitentDetailscs()
{
InitializeComponent();
}
private void ReadPaitentDetailscs_Load(object sender, EventArgs e)
{
string[] ArrayComPortsNames = null;
int index = -1;
string ComPortName = null;
//Com Ports
ArrayComPortsNames = SerialPort.GetPortNames();
do
{
index += 1;
cboPorts.Items.Add(ArrayComPortsNames[index]);
}
while (!((ArrayComPortsNames[index] == ComPortName) || (index ==
ArrayComPortsNames.GetUpperBound(0))));
Array.Sort(ArrayComPortsNames);
if (index == ArrayComPortsNames.GetUpperBound(0))

ComPortName = ArrayComPortsNames[0];

}
//get first item print in text
cboPorts.Text = ArrayComPortsNames[0];
cboBaudRate.Items.Add(300);
cboBaudRate.Items.Add(600);
cboBaudRate.Items.Add(1200);
cboBaudRate.Items.Add(2400);
cboBaudRate.Items.Add(9600);
cboBaudRate.Items.Add(14400);
cboBaudRate.Items.Add(19200);
cboBaudRate.Items.Add(38400);
cboBaudRate.Items.Add(57600);
cboBaudRate.Items.Add(115200);
cboBaudRate.Items.ToString();
cboBaudRate.Text = cboBaudRate.Items[4].ToString();
}
private void button1_Click(object sender, EventArgs e)
{
if (serialPort1.IsOpen == false)
{
serialPort1.PortName = Convert.ToString(cboPorts.Text);
serialPort1.BaudRate = Convert.ToInt32(cboBaudRate.Text);
serialPort1.Open();
SerialButton.Text = "DisConnect";
}
else if (serialPort1.IsOpen == true)
{
serialPort1.Close();
SerialButton.Text = "Connect";
}
}
delegate void SetTextCallback(string text);
private void SetText(string text)
{
// InvokeRequired required compares the thread ID of the
// calling thread to the thread ID of the creating thread.
// If these threads are different, it returns true.
if (this.richTextBox1.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
this.Invoke(d, new object[] { text });
}
else
{
this.richTextBox1.Text = text;
}
}
private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
txt += serialPort1.ReadExisting().ToString();
SetText(txt.ToString());
}
//private void SetText(string text)

//{
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//

inputbuf = text;
richTextBox1.Text = inputbuf;
n = inputbuf.Length;
string rich = richTextBox1.Text;
if (rich.Contains("$"))
{
int vale = rich.IndexOf("$");
string rem = rich.Substring(vale);
if (rem.Length > 9)
{
textBox2.Text = rem.Substring(1, 3);
textBox3.Text = rem.Substring(4, 3);
textBox4.Text = rem.Substring(7, 3);
updat();
mess();
rich = null;
rich = "";
}
}

//}
//private void button1_Click(object sender, EventArgs e)
//{
// if (serialPort1.IsOpen == true)
// {
//
//
//
//
//
//
//

serialPort1.Write("AT" + "\r\n");
Thread.Sleep(500);
serialPort1.Write("AT+CMGF=1" + "\r\n");
Thread.Sleep(500);
serialPort1.Write("AT+CNMI=2,2,0,0,0" + "\r\n");
Thread.Sleep(500);

// else MessageBox.Show("Port is closed", "Msg", MessageBoxButtons.OK,


MessageBoxIcon.Error);
//}
private void button2_Click(object sender, EventArgs e)
{
if (serialPort1.IsOpen == true)
{
serialPort1.Write("AT" + "\r\n");
Thread.Sleep(500);
serialPort1.Write("AT+CMGF=1" + "\r\n");
Thread.Sleep(500);
serialPort1.Write("AT+CNMI=2,2,0,0,0" + "\r\n");
Thread.Sleep(500);
}
else MessageBox.Show("Port is closed", "Msg", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
private void groupBox2_Enter(object sender, EventArgs e)
{

}
private void updat()
{
cmd = new SqlCommand("Update CEP365_Heart_Monitoring set
Temprature=@Temprature,Heart_Beat=@Heart_Beat,Respiratory=@Respiratory where
Patient_Id=@Patient_Id", con1);
cmd.Parameters.AddWithValue("@Patient_Id", textBox1.Text);
cmd.Parameters.AddWithValue("@Temprature", textBox2.Text);
cmd.Parameters.AddWithValue("@Heart_Beat", textBox3.Text);
cmd.Parameters.AddWithValue("@Respiratory", textBox3.Text);
con1.Open();
cmd.ExecuteNonQuery();
con1.Close();
MessageBox.Show("Values Updated Successfully");
}
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
if (richTextBox1.Text.Contains("$"))
{
int i = richTextBox1.Text.IndexOf("$");
string s = richTextBox1.Text.Substring(i);
if (s.Length == 10)
{
textBox2.Text = s.Substring(1, 3);
Thread.Sleep(500);
textBox3.Text = s.Substring(4, 3);
Thread.Sleep(500);
textBox4.Text = s .Substring(7, 3);
}
}
if (textBox4.Text != "")
{
//updat();
}
//mess();
}
private void mess()
{
char c = '"';
if(rat < Convert.ToInt32(textBox3.Text))
{
byte[] b = BitConverter.GetBytes(c);
serialPort1.Write("AT+CMGS=");
serialPort1.Write(b, 0, 1);
mn = "9750422969";
serialPort1.Write(mn);
serialPort1.Write(b, 0, 1);
serialPort1.Write("\r\n");
Thread.Sleep(2000);
sip = textBox1.Text + " This patient is now abnormal condition...So please give a
treatement immediately..";
serialPort1.Write(sip);

serialPort1.Write(Char.ConvertFromUtf32(26));
serialPort1.Write(char.ConvertFromUtf32(13));
}

private void groupBox1_Enter(object sender, EventArgs e)


{
}
}

Login Page in C#.net

GSMInitialization

Andoid

<?xml version="1.0" encoding="utf-8"?>


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.monitor"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >

</activity>
<activity

android:name=".Login"
android:label="@string/title_activity_login" >

<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />


</intent-filter>
</activity>
<activity
android:name=".Patients"
android:label="@string/title_activity_patients" >
</activity>
</application>

</manifest>

S-ar putea să vă placă și