Created
June 22, 2012 12:27
-
-
Save harshadura/2972463 to your computer and use it in GitHub Desktop.
Ralapanawa
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.ralapanawa.sms.controller; | |
import org.ralapanawa.sms.db.DBConnect; | |
import java.sql.Connection; | |
import java.sql.ResultSet; | |
import java.sql.SQLException; | |
import java.sql.Statement; | |
import com.mysql.jdbc.PreparedStatement; | |
public class LevelFilter { | |
private DBConnect dbConnect; | |
private Connection con; | |
private Statement stm; | |
public LevelFilter() throws SQLException { | |
dbConnect = new DBConnect(); | |
con = dbConnect.connect(); | |
stm = con.createStatement(); | |
} | |
public void WaterLevelFiller(String message, String mobileNum) { | |
try { | |
String sql2 = "select Tank_id, FSD from tanks where tankmobileno='" + mobileNum + "'"; | |
ResultSet rst2 = stm.executeQuery(sql2); | |
int TankID = Integer.parseInt(rst2.getString("Tank_id")); | |
int DangerLevel = Integer.parseInt(rst2.getString("FSD")); | |
int smsLevel = Integer.parseInt(message); | |
if (rst2.next() == false) { | |
System.out.println("No Record Found!"); | |
return; | |
} else { | |
Log_PIC_WaterLevel(smsLevel, TankID); // Log the Water Level to DB, got from PIC | |
DangerLevelCheck(smsLevel, DangerLevel, TankID); // Check for Danger level | |
} | |
rst2.close(); | |
} catch (Exception e) { | |
System.out.println(e); | |
} | |
} | |
/** | |
* Check for Danger Water Level !? | |
* @param smsLevel | |
* @param DangerLevel | |
*/ | |
public void DangerLevelCheck(int smsLevel, int DangerLevel, int TankID){ | |
if (smsLevel >= DangerLevel) { | |
try { | |
String sql3 = "select * from destric_persons where tank_id='" + TankID + "'"; | |
ResultSet rst3 = stm.executeQuery(sql3); | |
if (rst3.next()) { | |
String staff_ids[] = null; | |
String staff_tps[] = null; | |
staff_ids[0] = rst3.getString("GA_ID"); | |
staff_ids[1] = rst3.getString("DD_ID"); | |
staff_ids[2] = rst3.getString("Eng_ID"); | |
staff_ids[3] = rst3.getString("Irrigator_ID"); | |
for (int i = 0; i <= 3; i++) { | |
String sql4 = "select login_mpphone from ralapanawa_login where login_id='" + staff_ids[i] + "'"; | |
staff_tps[i] = stm.executeQuery(sql4).getString("login_mpphone"); | |
} | |
// Send Messages | |
SendAlertSMS_to_All(staff_tps); | |
} else { | |
System.out.println("No Record to Update!"); | |
return; | |
} | |
rst3.close(); | |
} catch (SQLException ex) { | |
System.out.println(ex); | |
} | |
} | |
} | |
/** | |
* Log PIC Water levels to the Database. | |
* @param smsLevel | |
* @param TankID | |
* @throws SQLException | |
*/ | |
public void Log_PIC_WaterLevel(int smsLevel, int TankID) throws SQLException { | |
String sql1 = "insert into pic_water_level (tankid, Depth) values(?,?)"; | |
PreparedStatement stmt = (PreparedStatement) con.prepareStatement(sql1); | |
stmt.setString(1, String.valueOf(TankID)); | |
stmt.setString(2, String.valueOf(smsLevel)); | |
stmt.executeUpdate(); | |
} | |
/** | |
* Send SMS messages to all the Staff | |
* @param TP | |
* @param msg | |
*/ | |
public void SendAlertSMS_to_All(String staff_tps[]){ | |
SMS_Sender app = new SMS_Sender(); | |
String AlertMessage = "Warning Flood Alert !!!"; | |
try { | |
for (int i=0; i<=staff_tps.length; i++){ | |
app.doIt(staff_tps[i], AlertMessage); | |
} | |
} catch (Exception e) { | |
System.out.println(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment