public void AutoSendCanhBao() { try { Database mydatabase = new Database(); float nhietdotb = mydatabase.SumTemp(); float doamtb = mydatabase.SumHumi(); float level = doamtb / (float)20 - (float)(27 - nhietdotb) / (float)10; if (level > 4) { string command = CreateCommand(true,"B1","V4"); byte[] com1 = ConvertTobyte(command); WriteData(com1); mydatabase.DeleteData(); DisplayData("(" + DateTime.Now + "): Tu dong gui canh bao muc 4\r\n", tb); } if ((2.5 < level) && (level < 4)) { string command = CreateCommand(true,"B1","V3"); byte[] com = ConvertTobyte(command); WriteData(com); mydatabase.DeleteData(); DisplayData("(" + DateTime.Now + "): Tu dong gui canh bao muc 3\r\n", tb); } if ((2 < level) && (level < 2.5)) { string command = CreateCommand(true,"B1","V2"); byte[] com = ConvertTobyte(command); WriteData(com); mydatabase.DeleteData(); DisplayData("(" + DateTime.Now + "): Tu dong gui canh bao muc 2\r\n", tb); } if (level < 2) { string command = CreateCommand(true,"B1","V1"); byte[] com = ConvertTobyte(command); WriteData(com); mydatabase.DeleteData(); DisplayData("(" + DateTime.Now + "): Tu dong gui canh bao muc 1\r\n", tb); } } catch { DisplayData("Khong the gui muc canh bao", tb); } }
public int GetLevelSendCanhBao() { try { int lv = 0; Database mydatabase = new Database(); float nhietdotb = mydatabase.SumTemp(); float doamtb = mydatabase.SumHumi(); float level = doamtb / (float)20 - (float)(27 - nhietdotb) / (float)10; mydatabase.DeleteData(); if (level > 4) lv = 4; if ((2.5 < level) && (level < 4)) lv = 3; if ((2 < level) && (level < 2.5)) lv = 2; if (level < 2) lv = 1; return lv; } catch { return 0; } }