public static int saveComInfo(string comName, string address, string phone, string email, string web, string password) { int result; DataBaseHelper db = new DataBaseHelper(); NpgsqlParameter[] param ={ DataBaseHelper.MakeParam("@comName",NpgsqlTypes.NpgsqlDbType.Varchar,70, ParameterDirection.Input, comName), DataBaseHelper.MakeParam("@address",NpgsqlTypes.NpgsqlDbType.Varchar,100, ParameterDirection.Input, address), DataBaseHelper.MakeParam("@phone",NpgsqlTypes.NpgsqlDbType.Varchar,20, ParameterDirection.Input, phone), DataBaseHelper.MakeParam("@email",NpgsqlTypes.NpgsqlDbType.Varchar,40, ParameterDirection.Input, email), DataBaseHelper.MakeParam("@website",NpgsqlTypes.NpgsqlDbType.Varchar,20, ParameterDirection.Input, web), DataBaseHelper.MakeParam("@pass",NpgsqlTypes.NpgsqlDbType.Varchar,70, ParameterDirection.Input, password), DataBaseHelper.MakeParam("@retVal",NpgsqlTypes.NpgsqlDbType.Integer,1, ParameterDirection.Output, 0) }; db.Run("createCompany", param); //db.Close(); if ((int)param[6].Value == 0) result = 0; else if ((int)param[6].Value > 0) { result = (int)param[6].Value; } else result = -1; return result; }
public bool alarmStatus(string unitID, string speed, string recTimeRevised, string comID, double lat, double lng) { string rulesValue, rulesOP; DataBaseHelper db = new DataBaseHelper(); DataSet ds = new DataSet(); DataSet dsRules = new DataSet(); string strSQL = "select isnull(rulesID,0) as rulesID from tblunitwiserules where unitid=" + unitID + " and isActive=1;"; strSQL += " select isnull(geofenceid,0) as geofenceid from tblunitwiserules where unitid=" + unitID + " and isGeofenceActive=1"; ds = db.Run(strSQL); //db.Close(); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { strSQL = "select f.rulesfor,r.rulesOperator,r.RulesValue from tblrules r inner join tblrulesfor f on f.rulesforid=r.rulesforid where rulesid=" + ds.Tables[0].Rows[i]["rulesID"].ToString() + ""; dsRules = db.Run(strSQL); //db.Close(); for (int j = 0; j < dsRules.Tables[0].Rows.Count; j++) { rulesValue = dsRules.Tables[0].Rows[j]["RulesValue"].ToString(); rulesOP = dsRules.Tables[0].Rows[j]["rulesOperator"].ToString(); if (dsRules.Tables[0].Rows[j]["rulesfor"].ToString() == "Time") { if (chkUnitTimeStatus(recTimeRevised, unitID, comID, rulesValue)) { return true; } } if (dsRules.Tables[0].Rows[j]["rulesfor"].ToString() == "Speed") { if (chkUnitSpeedStatus(unitID, speed, rulesOP, comID, rulesValue)) { return true; } } } } if (ds.Tables[1].Rows.Count > 0) for (int i = 0; i < ds.Tables[1].Rows.Count; i++) if (ds.Tables[1].Rows[i]["geofenceid"].ToString() != "") { if (chkGeofence.isViolate(unitID, comID, lat, lng, ds.Tables[1].Rows[i]["geofenceid"].ToString())) { return true; } } return false; }
//public struct PermissionInfo //{ // public bool delete; // public bool view; // public bool edit; // public bool insert; // public int formIDs; //} public static void LoadPermission(string userID) { DataBaseHelper db = new DataBaseHelper(); //PermissionInfo [] userPermission = new PermissionInfo[20]; //int[] formIDs; //formIDs = new int[20]; try { int i = 0; string sql = @"SELECT * FROMtblSchemePermission JOIN tblForms" + @" ON(tblSchemePermission.formID = tblForms.id)"; sql += @" WHERE schemeID = (SELECT schemeID FROM tblUserWiseScheme WHERE userID =" + userID.ToString() + ");"; ds = db.Run(sql); //if (ds.Tables[0].Rows.Count > 0) //{ // foreach (DataRow row in ds.Tables[0].Rows) // { // userPermission[i].delete = (bool)row["delete"]; // userPermission[i].view = (bool)row["view"]; // userPermission[i].insert = (bool)row["insert"]; // userPermission[i].edit = (bool)row["Edit"]; // userPermission[i].formIDs = (int)row["formID"]; // i++; // } //} } catch (Exception ex) { //return formIDs; } finally { } //return userPermission; }
public static bool isViolate(string unitID, string comID, double lat, double lng, string geofenceID) { double _distance; double _radius = 0; double _Lat1 = 0, _Lng1 = 0, _Lat2 = 0, _Lng2 = 0; string _strSQL = ""; _strSQL = "select centerLat,centerLng,radius from tblGeofence where comID=" + comID + " and ID=" + geofenceID + ""; try { DataBaseHelper _db = new DataBaseHelper(); DataSet _ds = new DataSet(); _ds = _db.Run(_strSQL); if (_ds.Tables[0].Rows.Count > 0) { _Lat1 = Convert.ToDouble(_ds.Tables[0].Rows[0]["centerLat"].ToString()); _Lng1 = double.Parse(_ds.Tables[0].Rows[0]["centerLng"].ToString()); _radius = double.Parse(_ds.Tables[0].Rows[0]["radius"].ToString()); _Lat2 = lat; _Lng2 = lng; _distance = DistanceCalculator.CalcDistance(_Lat1, _Lng1, _Lat2, _Lng2); if (_distance > _radius) { return true; } } return true; } catch (Exception ex) { } return false; }
public static bool saveTimeZone(string location, string utcVal) { int retVal = 0; string strInsertCommand = "insert into tblrptTimeZone(rptLocation,tzValue)"; strInsertCommand += "values("; strInsertCommand += "'" + location + "',"; strInsertCommand += "'" + utcVal + "')"; try { DataBaseHelper db = new DataBaseHelper(); retVal = db.ExecuteNonQuery(strInsertCommand, CommandType.StoredProcedure); } catch (NpgsqlException ex) { ex.Message.ToString(); } if (retVal >= 1) return true; else return false; }