Ejemplo n.º 1
0
        public static Description getDescription(int connID)
        {
            //Basic Constructs
            Description description = new Description();
            Database localDatabase = new Database();
            DataTable table = null;
            description.setDesc("");
            //Create description query and populate table
            string query = "SELECT * FROM Description WHERE connID=" + connID;

            try
            {
                table = localDatabase.executeQueryLocal(query);
            }
            catch (ODBC2KMLException ex)
            {
                ex.errorText = "Error retreiving description from the local database";
                throw ex;
            }

            foreach (DataRow row in table.Rows)
            {
                description.setDesc(row["description"].ToString());
            }//End outer loop

            return description;
        }
Ejemplo n.º 2
0
        protected void confirmEdit(object sender, EventArgs e)
        {
            ImageButton sendBtn = (ImageButton)sender;
            String args = sendBtn.CommandArgument.ToString();

            Database dbCheck = new Database();
            DataTable dtCheck;

            try
            {
                dtCheck = dbCheck.executeQueryLocal("SELECT name,dbName,userName,password,port,address,type,protocol,serviceName,SID FROM Connection WHERE ID=\'" + args + "\'");
            }
            catch (ODBC2KMLException)
            {
                ErrorHandler eh = new ErrorHandler("There was an error retreiving connection information for connection " + args + ".", errorPanel1);
                eh.displayError();
                return;
            }

            foreach (DataRow dr in dtCheck.Rows)
            {
                editConnName.Text = dr[0].ToString();
                editConnDBName.Text = dr[1].ToString();
                editConnUser.Text = dr[2].ToString();
                editConnPass.Attributes.Add("value", dr[3].ToString());
                editConnDBPort.Text = dr[4].ToString();
                editConnDBAddr.Text = dr[5].ToString();
                if (Convert.ToInt32(dr[6].ToString()) == ConnInfo.MYSQL)
                {
                    editConnDBType.SelectedValue = "MySQL";
                }
                else if (Convert.ToInt32(dr[6].ToString()) == ConnInfo.MSSQL)
                {
                    editConnDBType.SelectedValue = "MSSQL";
                }
                else
                {
                    editConnDBType.SelectedValue = "Oracle";
                }
                editConnDBType.Text = dr[6].ToString();
                editOracleProtocol.Text = dr[7].ToString();
                editOracleService.Text = dr[8].ToString();
                editOracleSID.Text = dr[9].ToString();
            }
            saveAndEditConn.CommandArgument = args;
            saveEditConn.CommandArgument = args;

            this.editConnModalPopUp.Show();
        }
Ejemplo n.º 3
0
        protected void updateConnection(object sender, CommandEventArgs e)
        {
            Button sendBtn = (Button)sender;
            String args = sendBtn.CommandArgument.ToString();

            ConnInfo tempConnInfo = new ConnInfo();

            tempConnInfo.setConnectionName(editConnName.Text);
            tempConnInfo.setDatabaseName(editConnDBName.Text);
            tempConnInfo.setServerAddress(editConnDBAddr.Text);
            tempConnInfo.setPortNumber(editConnDBPort.Text);
            tempConnInfo.setUserName(editConnUser.Text);
            tempConnInfo.setPassword(editConnPass.Text);
            tempConnInfo.setDatabaseType((editConnDBType.SelectedIndex));
            tempConnInfo.setOracleProtocol(editOracleProtocol.Text);
            tempConnInfo.setOracleServiceName(editOracleService.Text);
            tempConnInfo.setOracleSID(editOracleSID.Text);

            //If the connection information is bad, report the error and cancel the function. This does NOT run against the database.
            try
            {
                if (!tempConnInfo.isValid(Convert.ToInt32(args)))
                {
                    throw new ODBC2KMLException("");  // Throw any error. The catch is generic.
                }
            }
            catch
            {
                String error = "The entered connection information is invalid. Please make sure all fields are filled and that they are in proper format.";

                if (tempConnInfo.getDatabaseType() == ConnInfo.ORACLE)
                {
                    error = "The entered connection information is invalid. Please verify that all fields have a value and the value is of proper type."
                        + " Also, make sure that Oracle SID or Oracle Service Name and Oracle Protocol have been entered.";
                }

                ErrorHandler eh = new ErrorHandler(error, errorPanel1);
                this.editConnModalPopUp.Hide();
                eh.displayError();
                return;
            }

            //Create database and test it
            Database db = new Database(tempConnInfo);

            //See if you can reach the database. If not, error out and don't save.
            try
            {
                if (tempConnInfo.getDatabaseType() == ConnInfo.MSSQL)
                {
                    String query = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA != 'information_schema' AND TABLE_NAME != 'sysdiagrams'";
                    db.executeQueryRemote(query);
                }

                else if (tempConnInfo.getDatabaseType() == ConnInfo.MYSQL)
                {
                    String query = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA != 'information_schema' && TABLE_SCHEMA != 'mysql'";
                    db.executeQueryRemote(query);
                }

                else if (tempConnInfo.getDatabaseType() == ConnInfo.ORACLE)
                {
                    String query = "select TABLE_NAME from user_tables";
                    db.executeQueryRemote(query);
                }
            }
            catch
            {
                ErrorHandler eh = new ErrorHandler("The database entered could not be connected to. Please verify the information is correct.", errorPanel1);
                this.editConnModalPopUp.Hide();
                eh.displayError();
                return;
            }

            db.executeQueryLocal("UPDATE Connection SET name='" + tempConnInfo.getConnectionName()
                + "', dbName='" + tempConnInfo.getDatabaseName() + "', userName='******', password='******', port='" + tempConnInfo.getPortNumber()
                + "', address='" + tempConnInfo.getServerAddress() + "', type='" + tempConnInfo.getDatabaseType()
                + "', protocol='" + tempConnInfo.getOracleProtocol() + "', serviceName='" + tempConnInfo.getOracleServiceName()
                + "', SID='" + tempConnInfo.getOracleSID() + "' WHERE (ID='" + args + "')");

            Connection conn = new Connection(Convert.ToInt16(args));

            try
            {
                conn.populateFields();
                //Force the connection into a safe state, if it is not
                if (!conn.safeStateConnection())
                {
                    String error = "Invalid connection information. Please verify all of your fields are filled in correctly."
                    + "If you are using an oracle connection, please make sure you filled out the oracle specific information.";
                    ErrorHandler eh = new ErrorHandler(error, errorPanel1);
                    this.editConnModalPopUp.Hide();
                    eh.displayError();
                    return;
                }
            }
            catch (ODBC2KMLException err)
            {
                ErrorHandler eh = new ErrorHandler(err.errorText, errorPanel1);
                this.editConnModalPopUp.Hide();
                eh.displayError();
                return;
            }

            if (e.CommandName.Equals("saveConn"))
            {
                this.editConnModalPopUp.Hide();
                Response.Redirect("Main.aspx");
            }
            else
            {
                this.editConnModalPopUp.Hide();
                Response.Redirect("ConnDetails.aspx?ConnID=" + ((Button)sender).CommandArgument.ToString() + "&locked=false");
            }
        }
Ejemplo n.º 4
0
        protected void executeQuery(object sender, EventArgs e)
        {
            //try
            //{
                Database db;
                DataTable dt;
                Label title = new Label();

                if (connectionSelector.SelectedItem.Text == "local")
                {
                    try
                    {
                        db = new Database();

                        dt = db.executeQueryLocal(queryString.Text);
                    }
                    catch (ODBC2KMLException ex)
                    {
                        ErrorHandler eh = new ErrorHandler(ex.errorText, errorPanel1);
                        eh.displayError();
                        return;
                    }
                }
                else
                {
                    ConnInfo info = new ConnInfo();

                    try
                    {
                        db = new Database();

                        string query = "SELECT * FROM Connection WHERE ID=" + connectionSelector.SelectedItem.Value;
                        dt = db.executeQueryLocal(query);
                        if (dt.HasErrors)
                        {
                            throw new ODBC2KMLException("Unknown Database error");
                        }
                    }
                    catch (ODBC2KMLException ex)
                    {
                        ErrorHandler eh = new ErrorHandler(ex.errorText, errorPanel1);
                        eh.displayError();
                        return;
                    }

                    try
                    {
                        info = ConnInfo.getConnInfo(int.Parse(connectionSelector.SelectedItem.Value));
                    }
                    catch (ODBC2KMLException ex)
                    {
                        ErrorHandler eh = new ErrorHandler(ex.errorText, errorPanel1);
                        eh.displayError();
                        return;
                    }

                    db.setConnInfo(info);
                    try
                    {
                        dt = db.executeQueryRemote(queryString.Text);
                    }
                    catch (ODBC2KMLException ex)
                    {
                        ErrorHandler eh = new ErrorHandler(ex.errorText, errorPanel1);
                        eh.displayError();
                        return;
                    }
                }

                resultsPanel.Visible = true;

                resultsPanel.Controls.Add(new LiteralControl("<span class=\"connectionStyle\">&nbsp;Database Query Results</span>"));
                resultsPanel.Controls.Add(new LiteralControl("<div class=\"mainBoxP\">"));

                resultsPanel.Controls.Add(new LiteralControl("<table cellpadding=\"5\" cellspacing=\"0\" class=\"mainBox2\">"));

                resultsPanel.Controls.Add(new LiteralControl("<tr><td>"));
                resultsPanel.Controls.Add(new LiteralControl("<div class=\"omainBox4\">"));
                resultsPanel.Controls.Add(new LiteralControl("<table class=\"omainBox5\" cellspacing=\"0\" cellpadding=\"0\">"));

                resultsPanel.Controls.Add(new LiteralControl("<tr>"));
                foreach (DataColumn dc in dt.Columns)
                {
                    resultsPanel.Controls.Add(new LiteralControl("<td><b>" + dc.ColumnName + "<br/></b></td>"));
                }
                resultsPanel.Controls.Add(new LiteralControl("</tr><tr><td><br/></td></tr>"));

                foreach (DataRow dr in dt.Rows)
                {
                    resultsPanel.Controls.Add(new LiteralControl("<tr>"));
                    foreach (Object data in dr.ItemArray)
                    {
                        resultsPanel.Controls.Add(new LiteralControl("<td>" + data.ToString() + "</td>"));
                    }
                    resultsPanel.Controls.Add(new LiteralControl("</tr>"));
                }
                resultsPanel.Controls.Add(new LiteralControl("</table>"));
                resultsPanel.Controls.Add(new LiteralControl("<div align=\"right\" style=\"padding-top: 20px;\">"));
                resultsPanel.Controls.Add(new LiteralControl("<input type=\"submit\" ID=\"hideResults\" value=\"Hide Results\" class=\"button\" />"));
                resultsPanel.Controls.Add(new LiteralControl("</div>"));
                resultsPanel.Controls.Add(new LiteralControl("</td></tr>"));
                resultsPanel.Controls.Add(new LiteralControl("</div>"));
                resultsPanel.Controls.Add(new LiteralControl("</span>"));

                ModalPopupExtender6.Show();
            //}
            /*catch(Exception exception)
            {
                errorPanel1.Visible = true;
                errorPanel1.Controls.Add(new LiteralControl("<div style=\"color: black\"><p>"+exception.Message+"</p></div>"));
                errorPanel1.Controls.Add(new LiteralControl("<script type=\"text/javascript\">$(\"#errorPanel1\").dialog('open')</script>"));
            }*/
        }
Ejemplo n.º 5
0
        protected void editAndSaveConnectionInformation(object sender, CommandEventArgs e)
        {
            Button sendBtn = (Button)sender;
            String args = sendBtn.CommandArgument.ToString();

            Database dbCheck = new Database();
            DataTable dtCheck;
            DataRow dr;

            try
            {
                dtCheck = dbCheck.executeQueryLocal("SELECT name,dbName,userName,password,port,address,type,protocol,serviceName,SID FROM Connection WHERE ID=\'" + args + "\'");
                dr = dtCheck.Rows[0];
            }
            catch (ODBC2KMLException)
            {
                ErrorHandler eh = new ErrorHandler("There was an error retreiving connection information for connection " + args + ".", errorPanel1);
                eh.displayError();
                return;
            }

            ConnInfo tempConnInfo = new ConnInfo();

            tempConnInfo.setConnectionName(editConnName.Text);
            tempConnInfo.setDatabaseName(editConnDBName.Text);
            tempConnInfo.setServerAddress(editConnDBAddr.Text);
            tempConnInfo.setPortNumber(editConnDBPort.Text);
            tempConnInfo.setUserName(editConnUser.Text);
            tempConnInfo.setPassword(editConnPass.Text);
            tempConnInfo.setDatabaseType((editConnDBType.SelectedIndex));
            tempConnInfo.setOracleProtocol(editOracleProtocol.Text);
            tempConnInfo.setOracleServiceName(editOracleService.Text);
            tempConnInfo.setOracleSID(editOracleSID.Text);

            if (editConnName.Text.Equals(dr["name"].ToString()) && editConnDBName.Text.Equals(dr["dbName"].ToString()) && editConnDBAddr.Text.Equals(dr["address"].ToString())
                && editConnDBPort.Text.Equals(dr["port"].ToString()) && editConnUser.Text.Equals(dr["userName"].ToString()) && editConnPass.Text.Equals(dr["password"].ToString())
                && editConnDBType.SelectedIndex.ToString().Equals(dr["type"].ToString()) && editOracleProtocol.Text.Equals(dr["protocol"].ToString()) && editOracleService.Text.Equals(dr["serviceName"].ToString())
                && editOracleSID.Text.Equals(dr["SID"].ToString()))
            {
                updateConnection(sender, e);

            }else{
                this.editConnModalPopUp.Hide();
                this.warningModal.Show();
                continueUpdate.CommandName = e.CommandName.ToString();
                continueUpdate.CommandArgument = args;
            }
        }
Ejemplo n.º 6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            fileSaveLoc = Server.MapPath("/icons/");
            //Get the DB stuff from here
            Database db = new Database();
            DataTable dt;

            try
            {
                dt = db.executeQueryLocal("SELECT id,name FROM CONNECTION");
            }
            catch (ODBC2KMLException)
            {
                ErrorHandler eh = new ErrorHandler("There was an error getting the current connections", errorPanel1);
                eh.displayError();
                return;
            }

            int i = 0;
            if (dt.Rows.Count == 0)
            {
                ConnectionsAvailable.Controls.Add(new LiteralControl("<tr><td class=\"tableTD\">No connections currently exist.</td></tr>\n"));
            }
            else
            {
                foreach (DataRow dr in dt.Rows)
                {
                    string dbID = dr.ItemArray.ElementAt(0).ToString();
                    string odbcName = dr.ItemArray.ElementAt(1).ToString();

                    //Defines buttons
                    ImageButton openConn = new ImageButton();
                    openConn.CssClass = "openIcon";
                    openConn.ImageUrl = "graphics/connIcon.gif";
                    openConn.AlternateText = "Open Connection";
                    openConn.ToolTip = "Open Connection";
                    openConn.PostBackUrl = "ConnDetails.aspx?ConnID=" + dbID + "&locked=true";

                    ImageButton editConn = new ImageButton();
                    editConn.CssClass = "editIcon";
                    editConn.ImageUrl = "graphics/connIcon.gif";
                    editConn.AlternateText = "Edit Connection";
                    editConn.ToolTip = "Edit Connection";
                    editConn.Click += new ImageClickEventHandler(confirmEdit);
                    editConn.CommandArgument = dbID;

                    ImageButton deleteConn = new ImageButton();
                    deleteConn.ID = "dc" + Convert.ToString(i);
                    deleteConn.CssClass = "deleteIcon";
                    deleteConn.ImageUrl = "graphics/connIcon.gif";
                    deleteConn.AlternateText = "Delete Connection";
                    deleteConn.ToolTip = "Delete Connection";
                    deleteConn.Click += new ImageClickEventHandler(confirmDelete);
                    deleteConn.CommandArgument = dbID;
                    deleteConn.CommandArgument += "#" + odbcName;

                    ImageButton genKML = new ImageButton();
                    genKML.CssClass = "kmlIcon";
                    genKML.ImageUrl = "graphics/connIcon.gif";
                    genKML.AlternateText = "Generate KML File";
                    genKML.ToolTip = "Generate KML File";
                    genKML.Click += new ImageClickEventHandler(genKMLFunction);
                    genKML.CommandArgument = dbID;

                    //End button definition
                    if (i % 2.00 == 0)
                    {
                        ConnectionsAvailable.Controls.Add(new LiteralControl("<tr class=\"oddConn\">\n"));
                    }
                    else
                    {
                        ConnectionsAvailable.Controls.Add(new LiteralControl("<tr class=\"evenConn\">\n"));
                    }

                    ConnectionsAvailable.Controls.Add(new LiteralControl("<td>\n"));
                    ConnectionsAvailable.Controls.Add(new LiteralControl("<span id=\"Conn" + dbID + "\">" + odbcName + "</span>\n"));
                    ConnectionsAvailable.Controls.Add(new LiteralControl("<a href=\"#\" title=\"Open Connection\"></a>\n"));
                    ConnectionsAvailable.Controls.Add(new LiteralControl("</td>\n"));
                    ConnectionsAvailable.Controls.Add(new LiteralControl("<td class=\"connIcons\">\n"));
                    ConnectionsAvailable.Controls.Add(new LiteralControl("<table>\n"));
                    ConnectionsAvailable.Controls.Add(new LiteralControl("<tr>\n"));
                    ConnectionsAvailable.Controls.Add(new LiteralControl("<td>\n"));
                    ConnectionsAvailable.Controls.Add(openConn);
                    ConnectionsAvailable.Controls.Add(new LiteralControl("</td>\n"));
                    ConnectionsAvailable.Controls.Add(new LiteralControl("<td>\n"));
                    ConnectionsAvailable.Controls.Add(editConn);
                    ConnectionsAvailable.Controls.Add(new LiteralControl("</td>\n"));
                    ConnectionsAvailable.Controls.Add(new LiteralControl("<td>\n"));
                    ConnectionsAvailable.Controls.Add(deleteConn);
                    ConnectionsAvailable.Controls.Add(new LiteralControl("</td>\n"));
                    ConnectionsAvailable.Controls.Add(new LiteralControl("<td>\n"));
                    ConnectionsAvailable.Controls.Add(genKML);
                    ConnectionsAvailable.Controls.Add(new LiteralControl("</td>\n"));
                    ConnectionsAvailable.Controls.Add(new LiteralControl("</tr>\n"));
                    ConnectionsAvailable.Controls.Add(new LiteralControl("</table>\n"));
                    ConnectionsAvailable.Controls.Add(new LiteralControl("</td>\n"));
                    ConnectionsAvailable.Controls.Add(new LiteralControl("</tr>\n"));

                    i += 1;
                }
            }
        }
Ejemplo n.º 7
0
 public void setIDfromDBoverlay(int connID, int overlayID)
 {
     Database DB = new Database();
     DataTable id = new DataTable();
     try
     {
         id = DB.executeQueryLocal("SELECT ID FROM OverlayCondition WHERE connID="
             + connID + " and overlayID=" + overlayID + " "
             + "and lowerBound=\'" + this.lowerBound + "\' "
             + "and upperBound=\'" + this.upperBound + "\' "
             + "and lowerOperator=\'" + this.lowerOperator + "\' "
             + "and upperOperator=\'" + this.upperOperator + "\' "
             + "and fieldName=\'" + this.fieldName + "\' "
             + "and tableName=\'" + this.tableName + "\'");
     }
     catch (ODBC2KMLException ex)
     {
         throw new ODBC2KMLException(ex.errorText);
     }
     foreach (DataRow row in id.Rows)
     {
         this.id = (int)row[0];
     }
 }
Ejemplo n.º 8
0
        protected void deleteConnFunction(object sender, EventArgs e)
        {
            //Delete the connection
            Button sendBtn = (Button)sender;
            String args = sendBtn.CommandArgument.ToString();
            Database db = new Database();

            try
            {
                db.executeQueryLocal("DELETE FROM CONNECTION WHERE ID=" + args);
            }
            catch (ODBC2KMLException)
            {
                ErrorHandler eh = new ErrorHandler("There was an error deleting the connection", errorPanel1);
                eh.displayError();
                return;
            }

            this.deletePopupExtender.Hide();
            Response.Redirect("Main.aspx");
        }
Ejemplo n.º 9
0
        protected void addConditionToOverlay(object sender, EventArgs e)
        {
            Button btn = (Button)sender;
            string args = btn.CommandArgument.ToString();
            TextBox lowerBound = (TextBox)Page.FindControl("addOverlayLowerBound" + args);
            DropDownList lowerOperator = (DropDownList)Page.FindControl("addOverlayLowerOperator" + args);
            DropDownList tableName = (DropDownList)Page.FindControl("addOverlayTable" + args);
            DropDownList fieldName = (DropDownList)Page.FindControl("addOverlayField" + args);
            DropDownList upperOperator = (DropDownList)Page.FindControl("addOverlayUpperOperator" + args);
            TextBox upperBound = (TextBox)Page.FindControl("addOverlayUpperBound" + args);
            UpdatePanel modifyIconConditionInsidePopupPanel = (UpdatePanel)Page.FindControl("modifyOverlayConditionInsidePopupPanel" + args);
            string overlayId = args;

            Condition condition = new Condition();
            condition.setId(tempId--);
            condition.setLowerBound(lowerBound.Text.ToString());
            condition.setUpperBound(upperBound.Text.ToString());
            condition.setTableName(tableName.Text.ToString());
            condition.setFieldName(fieldName.Text.ToString());
            if (lowerOperator != null)
                condition.setLowerOperator(lowerOperator.SelectedItem.Text.ToString());
            if (upperOperator != null)
                condition.setUpperOperator(upperOperator.SelectedItem.Text.ToString());

            string conditionErrors = condition.getErrorText();
            if (conditionErrors != "")
            {
                ErrorHandler eh = new ErrorHandler(conditionErrors, (UpdatePanel)Page.FindControl("modifyOverlayConditionInsidePopupPanel" + overlayId), "MPE_OVERLAY_" + overlayId);
                eh.displayError();
                lowerBound.Text = condition.getLowerBound();
                lowerOperator.SelectedValue = condition.getLowerOperator();
                tableName.SelectedValue = condition.getTableName();
                fieldName.SelectedValue = condition.getFieldName();
                upperOperator.SelectedValue = condition.getUpperOperator();
                upperBound.Text = condition.getUpperBound();
                return;
            }

            //Verify that the bounds are of the same datatype as the column value
            if (conditionErrors == "")
            {
                //Create database based on the connInfo
                Database testDB = new Database(conn.connInfo);
                DataTable testTable = null;

                try
                {
                    //Create the datatable to parse through
                    testTable = testDB.executeQueryRemote("SELECT " + condition.getFieldName() + " FROM " + condition.getTableName());
                }
                catch (ODBC2KMLException)
                {
                    ErrorHandler eh = new ErrorHandler("There was an error connecting to the remote database to verify overlay condition information", errorPanel1);
                    eh.displayError();
                    return;
                }

                //Counter to break out of the loop, this way only a subset of the data is tested
                int counter = 0;

                //Check the bounds against the database values
                foreach (DataRow row in testTable.Rows)
                {

                    //If both conditions....
                    if (condition.getLowerBound() != "" && condition.getUpperBound() != "")
                    {
                        //Need variables for Try parse
                        Double lower;
                        Double upper;

                        //See if both conditions evaluate to doubles
                        if (Double.TryParse(condition.getLowerBound(), out lower) && Double.TryParse(condition.getUpperBound(), out upper))
                        {
                            Double value;
                            //If value is not a double, throw an error
                            if (!Double.TryParse(row[condition.getFieldName()].ToString(), out value) && row[condition.getFieldName()] != null && row[condition.getFieldName()].ToString() != "")
                            {
                                conditionErrors = "The datatype of the entered bounds do not match the datatype of the database values.";
                                ErrorHandler eh = new ErrorHandler(conditionErrors, (UpdatePanel)Page.FindControl("modifyOverlayConditionInsidePopupPanel" + overlayId), "MPE_OVERLAY_" + overlayId);
                                lowerBound.Text = condition.getLowerBound();
                                lowerOperator.SelectedValue = condition.getLowerOperator();
                                tableName.SelectedValue = condition.getTableName();
                                fieldName.SelectedValue = condition.getFieldName();
                                upperOperator.SelectedValue = condition.getUpperOperator();
                                upperBound.Text = condition.getUpperBound();
                                eh.displayError();
                                return;
                            }

                            //test five elements
                            if (++counter > 5)
                                break;
                        }
                        else //They evaluate to strings
                        {
                            Double value;
                            //If value is a double, throw an error
                            if (Double.TryParse(row[condition.getFieldName()].ToString(), out value) && row[condition.getFieldName()] != null && row[condition.getFieldName()].ToString() != "")
                            {
                                conditionErrors = "The datatype of the entered bounds do not match the datatype of the database values.";
                                ErrorHandler eh = new ErrorHandler(conditionErrors, (UpdatePanel)Page.FindControl("modifyOverlayConditionInsidePopupPanel" + overlayId), "MPE_OVERLAY_" + overlayId);
                                lowerBound.Text = condition.getLowerBound();
                                lowerOperator.SelectedValue = condition.getLowerOperator();
                                tableName.SelectedValue = condition.getTableName();
                                fieldName.SelectedValue = condition.getFieldName();
                                upperOperator.SelectedValue = condition.getUpperOperator();
                                upperBound.Text = condition.getUpperBound();
                                eh.displayError();
                                return;
                            }
                            else //Decrement counter, this row wasn't a valid row and should be ignored

                            //test five elements
                            if (++counter > 5)
                                break;
                        }
                    }
                    else if (condition.getLowerBound() != "")
                    {
                        //Need variables for Try parse
                        Double lower;

                        //See if the lower conditions evaluate to doubles
                        if (Double.TryParse(condition.getLowerBound(), out lower))
                        {
                            Double value;
                            //If value is not a double, throw an error
                            if (!Double.TryParse(row[condition.getFieldName()].ToString(), out value) && row[condition.getFieldName()] != null && row[condition.getFieldName()].ToString() != "")
                            {
                                conditionErrors = "The datatype of the entered bounds do not match the datatype of the database values.";
                                ErrorHandler eh = new ErrorHandler(conditionErrors, (UpdatePanel)Page.FindControl("modifyOverlayConditionInsidePopupPanel" + overlayId), "MPE_OVERLAY_" + overlayId);
                                lowerBound.Text = condition.getLowerBound();
                                lowerOperator.SelectedValue = condition.getLowerOperator();
                                tableName.SelectedValue = condition.getTableName();
                                fieldName.SelectedValue = condition.getFieldName();
                                upperOperator.SelectedValue = condition.getUpperOperator();
                                upperBound.Text = condition.getUpperBound();
                                eh.displayError();
                                return;
                            }

                            //test five elements
                            if (++counter > 5)
                                break;
                        }
                        else //They evaluate to strings
                        {
                            Double value;
                            //If value is a double, throw an error
                            if (Double.TryParse(row[condition.getFieldName()].ToString(), out value) && row[condition.getFieldName()] != null && row[condition.getFieldName()].ToString() != "")
                            {
                                conditionErrors = "The datatype of the entered bounds do not match the datatype of the database values.";
                                ErrorHandler eh = new ErrorHandler(conditionErrors, (UpdatePanel)Page.FindControl("modifyOverlayConditionInsidePopupPanel" + overlayId), "MPE_OVERLAY_" + overlayId);
                                lowerBound.Text = condition.getLowerBound();
                                lowerOperator.SelectedValue = condition.getLowerOperator();
                                tableName.SelectedValue = condition.getTableName();
                                fieldName.SelectedValue = condition.getFieldName();
                                upperOperator.SelectedValue = condition.getUpperOperator();
                                upperBound.Text = condition.getUpperBound();
                                eh.displayError();
                                return;
                            }

                            //test five elements
                            if (++counter > 5)
                                break;
                        }
                    }
                    else
                    {
                        //Need variables for Try parse
                        Double upper;

                        //See if the lower conditions evaluate to doubles
                        if (Double.TryParse(condition.getUpperBound(), out upper))
                        {
                            Double value;
                            //If value is not a double, throw an error
                            if (!Double.TryParse(row[condition.getFieldName()].ToString(), out value) && row[condition.getFieldName()] != null && row[condition.getFieldName()].ToString() != "")
                            {
                                conditionErrors = "The datatype of the entered bounds do not match the datatype of the database values.";
                                ErrorHandler eh = new ErrorHandler(conditionErrors, (UpdatePanel)Page.FindControl("modifyOverlayConditionInsidePopupPanel" + overlayId), "MPE_OVERLAY_" + overlayId);
                                lowerBound.Text = condition.getLowerBound();
                                lowerOperator.SelectedValue = condition.getLowerOperator();
                                tableName.SelectedValue = condition.getTableName();
                                fieldName.SelectedValue = condition.getFieldName();
                                upperOperator.SelectedValue = condition.getUpperOperator();
                                upperBound.Text = condition.getUpperBound();
                                eh.displayError();
                                return;
                            }

                            //test five elements
                            if (++counter > 5)
                                break;
                        }
                        else //They evaluate to strings
                        {
                            Double value;
                            //If value is a double, throw an error
                            if (Double.TryParse(row[condition.getFieldName()].ToString(), out value) && row[condition.getFieldName()] != null && row[condition.getFieldName()].ToString() != "")
                            {
                                conditionErrors = "The datatype of the entered bounds do not match the datatype of the database values.";
                                ErrorHandler eh = new ErrorHandler(conditionErrors, (UpdatePanel)Page.FindControl("modifyOverlayConditionInsidePopupPanel" + overlayId), "MPE_OVERLAY_" + overlayId);
                                lowerBound.Text = condition.getLowerBound();
                                lowerOperator.SelectedValue = condition.getLowerOperator();
                                tableName.SelectedValue = condition.getTableName();
                                fieldName.SelectedValue = condition.getFieldName();
                                upperOperator.SelectedValue = condition.getUpperOperator();
                                upperBound.Text = condition.getUpperBound();
                                eh.displayError();
                                return;
                            }

                            //test five elements
                            if (++counter > 5)
                                break;
                        }
                    }
                }
            }

            foreach (Overlay overlay in conn.overlays)
            {
                if (overlay.getId() == overlayId)
                {
                    overlay.setConditions(condition);
                }
            }
            try
            {
                genOverlayConditionTable(sender, e);
            }
            catch (ODBC2KMLException ex)
            {
                ErrorHandler eh = new ErrorHandler(ex.errorText, errorPanel1);
                eh.displayError();
                return;
            }
            sessionSave();
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Function to validate a description string. Checks URLs and Field tags. 
        /// URLs - verifies that there is one and only one TITLE element and that the title and URL are not empty, and that there is an open and closing tag
        /// Field tag - verifies that there one and only one set of TBL and COL tags, that the tags are not empty, and that there is an open and closing tag
        /// </summary>
        /// <param name="currentConnInfo">ConnInfo object containing the current connection info for the description being tested</param>
        /// <param name="currentMapping">Mapping object containing the current mapping for the description being tested</param>
        /// <returns>true if a description is valid and false if it is not</returns>
        public bool isValid(ConnInfo currentConnInfo, Mapping currentMapping)
        {
            //validate field tags
            int startIndex = 0;
            int endIndex = 0;
            int lengthOfTag = 0;
            //if start of field tag is found
            while (desc.IndexOf("[FIELD]", startIndex, StringComparison.InvariantCultureIgnoreCase) != -1)
            {
                //if end of field tag is found, set startindex, else return false
                if (desc.IndexOf("[/FIELD]", StringComparison.InvariantCultureIgnoreCase) != -1)
                {
                    //get the index of end of tag and calculate lengthoftag
                    endIndex = desc.IndexOf("[/FIELD]", startIndex, StringComparison.InvariantCultureIgnoreCase);
                    lengthOfTag = endIndex - startIndex;
                }
                else
                {
                    return false;
                }

                //if start of table tag found look for end of field tag else return false
                if (desc.IndexOf("[TBL]", startIndex, lengthOfTag, StringComparison.InvariantCultureIgnoreCase) != -1)
                {
                    //if we find a close tbl tag before the open tbl tag return false
                    if ((desc.IndexOf("[/TBL]", startIndex, lengthOfTag, StringComparison.InvariantCultureIgnoreCase)) < (desc.IndexOf("[TBL]", startIndex, lengthOfTag, StringComparison.InvariantCultureIgnoreCase)))
                        return false;
                    //if we find another tbl tag, return false
                    else if (desc.IndexOf("[TBL]", desc.IndexOf("[TBL]", startIndex, lengthOfTag, StringComparison.InvariantCultureIgnoreCase) + 4, endIndex - desc.IndexOf("[TBL]", startIndex, lengthOfTag, StringComparison.InvariantCultureIgnoreCase) + 4, StringComparison.InvariantCultureIgnoreCase) != -1)
                        return false;
                    //else if we don't find a close tbl tag, return false
                    else if (desc.IndexOf("[/TBL]", desc.IndexOf("[TBL]", startIndex, lengthOfTag, StringComparison.InvariantCultureIgnoreCase) + 4, endIndex - desc.IndexOf("[TBL]", startIndex, lengthOfTag, StringComparison.InvariantCultureIgnoreCase) + 4, StringComparison.InvariantCultureIgnoreCase) == -1)
                        return false;
                    //else if the length of the table tag is 0, return false
                    else if (desc.IndexOf("[TBL]", startIndex, lengthOfTag) + 5 - desc.IndexOf("[/TBL]", desc.IndexOf("[TBL]") + 4, endIndex - desc.IndexOf("[TBL]", startIndex, lengthOfTag) + 4, StringComparison.InvariantCultureIgnoreCase) == 0)
                        return false;

                    //validate table name
                    int openTbl = desc.IndexOf("[TBL]", startIndex, lengthOfTag, StringComparison.InvariantCultureIgnoreCase);
                    int closeTbl = desc.IndexOf("[/TBL]", desc.IndexOf("[TBL]", startIndex, lengthOfTag, StringComparison.InvariantCultureIgnoreCase) + 4, endIndex - desc.IndexOf("[TBL]", startIndex, lengthOfTag, StringComparison.InvariantCultureIgnoreCase) + 4, StringComparison.InvariantCultureIgnoreCase);
                    string table = desc.Substring(openTbl+5, closeTbl - openTbl - 5);
                    //if the table isn't the currently mapped table, return false
                    if (!table.Trim().Equals(currentMapping.tableName))
                        return false;
                }
                else
                {
                    return false;
                }
                //if start of column tag is found, look for end of field tag else return false
                if (desc.IndexOf("[COL]", startIndex, lengthOfTag, StringComparison.InvariantCultureIgnoreCase) != -1)
                {
                    //if we find a close col tag before the open col tag return false
                    if ((desc.IndexOf("[/COL]", startIndex, lengthOfTag, StringComparison.InvariantCultureIgnoreCase)) < (desc.IndexOf("[COL]", startIndex, lengthOfTag, StringComparison.InvariantCultureIgnoreCase)))
                        return false;
                    //if we find another col tag, return false
                    if (desc.IndexOf("[COL]", desc.IndexOf("[COL]", startIndex, lengthOfTag, StringComparison.InvariantCultureIgnoreCase) + 4, endIndex - desc.IndexOf("[COL]", startIndex, lengthOfTag, StringComparison.InvariantCultureIgnoreCase) + 4, StringComparison.InvariantCultureIgnoreCase) != -1)
                        return false;
                    //else if we don't find a close col tag, return false
                    else if (desc.IndexOf("[/COL]", desc.IndexOf("[COL]", startIndex, lengthOfTag, StringComparison.InvariantCultureIgnoreCase) + 4, endIndex - desc.IndexOf("[COL]", startIndex, lengthOfTag, StringComparison.InvariantCultureIgnoreCase) + 4, StringComparison.InvariantCultureIgnoreCase) == -1)
                        return false;
                    //else if the length of the column tag is 0, return false
                    else if (desc.IndexOf("[COL]", startIndex, lengthOfTag, StringComparison.InvariantCultureIgnoreCase) + 5 - desc.IndexOf("[/COL]", desc.IndexOf("[COL]", StringComparison.InvariantCultureIgnoreCase) + 4, endIndex - desc.IndexOf("[COL]", startIndex, lengthOfTag, StringComparison.InvariantCultureIgnoreCase) + 4, StringComparison.InvariantCultureIgnoreCase) == 0)
                        return false;

                    //validate column name
                    int openCol = desc.IndexOf("[COL]", startIndex, lengthOfTag, StringComparison.InvariantCultureIgnoreCase);
                    int closeCol = desc.IndexOf("[/COL]", desc.IndexOf("[COL]", startIndex, lengthOfTag, StringComparison.InvariantCultureIgnoreCase) + 4, endIndex - desc.IndexOf("[COL]", startIndex, lengthOfTag, StringComparison.InvariantCultureIgnoreCase) + 4, StringComparison.InvariantCultureIgnoreCase);
                    string column = desc.Substring(openCol+5, closeCol - openCol - 5);
                    Database db = new Database(currentConnInfo);
                    string query = "SELECT " + column.Trim() + " FROM " + currentMapping.tableName;
                    try
                    {
                        db.executeQueryRemote(query);
                    }
                    catch (ODBC2KMLException)
                    {
                        return false;
                    }
                }
                else
                {
                    return false;
                }
                startIndex = endIndex + 8;
            }

            //validate url tags
            startIndex = 0;
            endIndex = 0;
            lengthOfTag = 0;
            //if start of url tag is found
            while (desc.IndexOf("[URL]", startIndex, StringComparison.InvariantCultureIgnoreCase) != -1)
            {
                //if end of url tag is found, set startindex, else return false
                if (desc.IndexOf("[/URL]", StringComparison.InvariantCultureIgnoreCase) != -1)
                {
                    //get the index of end of tag and calculate lengthoftag
                    endIndex = desc.IndexOf("[/URL]", startIndex, StringComparison.InvariantCultureIgnoreCase);
                    lengthOfTag = endIndex - startIndex;
                }
                else
                {
                    return false;
                }
                //if start of title tag found look for end of title tag else return false
                if (desc.IndexOf("[TITLE]", startIndex, lengthOfTag, StringComparison.InvariantCultureIgnoreCase) != -1)
                {
                    //if we find another title tag, return false
                    if (desc.IndexOf("[TITLE]", desc.IndexOf("[TITLE]", startIndex, lengthOfTag, StringComparison.InvariantCultureIgnoreCase) + 7, endIndex - desc.IndexOf("[TITLE]", startIndex, lengthOfTag, StringComparison.InvariantCultureIgnoreCase) - 7, StringComparison.InvariantCultureIgnoreCase) != -1)
                        return false;
                    //else if we don't find a close title tag, return false
                    else if (desc.IndexOf("[/TITLE]", desc.IndexOf("[TITLE]", startIndex, lengthOfTag, StringComparison.InvariantCultureIgnoreCase) + 7, endIndex - desc.IndexOf("[TITLE]", startIndex, lengthOfTag, StringComparison.InvariantCultureIgnoreCase) - 7, StringComparison.InvariantCultureIgnoreCase) == -1)
                        return false;
                    //else if the length of the title tag is 0, return false
                    else if (desc.IndexOf("[TITLE]", startIndex, lengthOfTag, StringComparison.InvariantCultureIgnoreCase) + 8 - desc.IndexOf("[/TITLE]", desc.IndexOf("[TITLE]", StringComparison.InvariantCultureIgnoreCase) + 7, endIndex - desc.IndexOf("[TITLE]", startIndex, lengthOfTag, StringComparison.InvariantCultureIgnoreCase) - 7, StringComparison.InvariantCultureIgnoreCase) == 0)
                        return false;
                }
                else
                {
                    return false;
                }
                //if length of url is 0 return false
                if (desc.IndexOf("[/TITLE]", startIndex, lengthOfTag, StringComparison.InvariantCultureIgnoreCase) + 8 - desc.IndexOf("[/URL]", desc.IndexOf("[URL]", startIndex, lengthOfTag, StringComparison.InvariantCultureIgnoreCase) + 5, endIndex - desc.IndexOf("[URL]", startIndex, lengthOfTag, StringComparison.InvariantCultureIgnoreCase) - 5, StringComparison.InvariantCultureIgnoreCase) == 0)
                    return false;

                startIndex = endIndex + 6;
            }

            return true;
        }
Ejemplo n.º 11
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Database db = new Database();
                DataTable dt;

                try
                {
                    dt = db.executeQueryLocal("SELECT id,name FROM CONNECTION");
                }
                catch (ODBC2KMLException)
                {
                    ErrorHandler eh = new ErrorHandler("There was an error getting the list of connections", errorPanel1);
                    eh.displayError();
                    return;
                }

                connectionSelector.DataSource = dt;
                connectionSelector.DataTextField = "name";
                connectionSelector.DataValueField = "id";
                connectionSelector.DataBind();
                connectionSelector.Items.Add("local");
            }
            if (Request.QueryString.Get("locked") == "1")
            {
                ChangeControlStatus(false);
            }
        }
Ejemplo n.º 12
0
        protected void viewIconLibFunc(object sender, EventArgs e)
        {
            Database db = new Database();
            DataTable dt;
            dt = db.executeQueryLocal("SELECT ID, location FROM IconLibrary");

            int sizeOfBox = 6;
            int currentBoxCount = 0;

            iconLibPanel.Controls.Clear();
            iconLibPanel.Controls.Add(new LiteralControl("<table class=\"boxPopupStyle2\" cellpadding=\"5\">\n"));
            if (dt.Rows.Count == 0)
            {
                iconLibPanel.Controls.Add(new LiteralControl("<tr><td class=\"tableTD\">All icons in the icon library are currently being used in the connection.</td></tr>\n"));
            }
            else
            {
                foreach (DataRow dr in dt.Rows)
                {
                    if (currentBoxCount == sizeOfBox)
                    {
                        iconLibPanel.Controls.Add(new LiteralControl("</tr>\n"));
                        currentBoxCount = 0;
                    }
                    if (currentBoxCount == 0)
                    {
                        iconLibPanel.Controls.Add(new LiteralControl("<tr>\n"));
                    }

                    iconLibPanel.Controls.Add(new LiteralControl("<td>"));
                    Image img = new Image();
                    img.ID = "imgLib_" + dr["ID"].ToString();
                    img.ImageUrl = dr["location"].ToString();
                    img.AlternateText = "Icon Cannot be Displayed";
                    img.ToolTip = dr["location"].ToString();
                    img.Height = 64;
                    img.Width = 64;

                    iconLibPanel.Controls.Add(img);
                    iconLibPanel.Controls.Add(new LiteralControl("</td>"));

                    currentBoxCount += 1;
                }
            }
            iconLibPanel.Controls.Add(new LiteralControl("</table>\n"));
            this.IconLibModalPopup.Show();
            //iconLibPanel
        }
Ejemplo n.º 13
0
        public static ArrayList getIcons(int connID)
        {
            ArrayList icons = new ArrayList();
            Database localDatabase = new Database();

            //Create icon query and populate table
            string query = "SELECT * FROM Icon WHERE connID=" + connID + " ORDER BY ID";
            DataTable table = null;

            try
            {
                table = localDatabase.executeQueryLocal(query);
            }
            catch (ODBC2KMLException ex)
            {
                ex.errorText = "There was an error getting icons for the connection";
                throw ex;
            }

            foreach (DataRow row in table.Rows)
            {
                //Create a new icon
                Icon newIcon = new Icon();

                //Create a new table to perform subqueries on
                DataTable newTable = new DataTable();

                //IconLibrary query
                string locQuery = "SELECT * FROM IconLibrary WHERE ID=" + ((int)row["iconLibraryID"]) + " ORDER BY ID";

                try
                {
                    newTable = localDatabase.executeQueryLocal(locQuery);
                }
                catch (ODBC2KMLException ex)
                {
                    ex.errorText = "There was an error populating the Icon Library";
                    throw ex;
                }

                foreach (DataRow nRow in newTable.Rows)
                {
                    //Set the location of the icon
                    newIcon.setLocation(nRow["location"].ToString());
                    newIcon.setId(nRow["ID"].ToString());
                    if ((Boolean)nRow["isLocal"] == false)
                    {
                        newIcon.setLocality(false);
                    }
                    else
                    {
                        newIcon.setLocality(true);
                    }
                }//End outer loop

                newTable.Clear();

                //IconCondition query
                string conQuery = "SELECT * FROM IconCondition WHERE iconID="
                    + ((int)row["ID"]) + " AND connID=" + connID;

                try
                {
                    newTable = localDatabase.executeQueryLocal(conQuery);
                }
                catch (ODBC2KMLException ex)
                {
                    ex.errorText = "There was a problem selecting icon conditions for icon " + (int)row["iconLibraryID"];
                    throw ex;
                }

                //Cycle through each condition
                foreach (DataRow nRow in newTable.Rows)
                {
                    //Create the condition and add its values
                    Condition condition = new Condition();

                    if (nRow["lowerBound"] != null)
                    {
                        condition.setLowerBound(nRow["lowerBound"].ToString());
                    }
                    else
                    {
                        condition.setLowerBound("");
                    }

                    if (nRow["upperBound"] != null)
                    {
                        condition.setUpperBound(nRow["upperBound"].ToString());
                    }
                    else
                    {
                        condition.setUpperBound("");
                    }

                    condition.setLowerOperator((int)nRow["lowerOperator"]);
                    condition.setUpperOperator((int)nRow["upperOperator"]);
                    condition.setTableName(nRow["tableName"].ToString());
                    condition.setFieldName(nRow["fieldName"].ToString());
                    condition.setId(Convert.ToInt16(nRow["ID"].ToString()));

                    //Add the condition to the icon array
                    newIcon.setConditions(condition);
                    //Free up condition memory
                    condition = null;
                }//End outer loop
                //Free up table memory
                newTable = null;

                icons.Add(newIcon);
                //Free up icon memory
                newIcon = null;

            }//End outer loop

            return icons;
        }
Ejemplo n.º 14
0
        /// <summary>
        /// This function purges all of the invalid conditions for the given Database information from the local database.
        /// </summary>
        /// <param name="purgeDT">DataTable --> List of tablename</param>
        /// <param name="columnToTableRelation">DataSet --> List of columns for each table name</param>
        /// <param name="temp">Database --> A temp database used to remove the icon conditions from local database</param>
        /// <returns>Boolean --> True if purge, false if no purge</returns>
        public String purgeInvalidIconConditionsFromDatabase(DataTable purgeDT, DataSet columnToTableRelation, Database temp)
        {
            String query = "";
            //Get the icon's conditions
            for (int count = 0; count < this.getConditions().Count; count++)
            {
                //If the condition is invalid, remove it from the database and connection object
                if (!(((Condition)this.getConditions()[count]).isValid(purgeDT, columnToTableRelation)))
                {
                    query = "DELETE FROM IconCondition WHERE ID=" + ((Condition)this.getConditions()[count]).getId();

                    try
                    {
                        temp.executeQueryLocal(query);
                        this.removeCondition(count);
                        count--;
                    }
                    catch (ODBC2KMLException ex)
                    {
                        ex.errorText = "There was an error deleting an icon condition";
                        throw ex;
                    }
                }
            }

            return query;
        }
Ejemplo n.º 15
0
        /// <summary>
        /// used for uploading icons from local computer
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public static String uploadClick(String fileSaveLoc, String relativeFileSaveLoc, FileUpload fileUpEx)
        {
            ArrayList validTypes = BuildTypeList();
            Boolean valid = false;
            //checks to make sure there is an uploaded file
            if ((fileUpEx.HasFile) && (!fileUpEx.FileName.Equals("")))
            {
                //checks for valid filetype
                foreach (String type in validTypes)
                {
                    if (fileUpEx.PostedFile.ContentType.Equals(type))
                    {
                        valid = true;
                    }
                }
                //checks for valid dimensions
                if (valid && ValidateFileDimensions(fileUpEx.PostedFile.InputStream))
                {
                    String filepath = fileUpEx.PostedFile.FileName;
                    String file_ext = System.IO.Path.GetExtension(filepath);
                    String filename = System.IO.Path.GetFileNameWithoutExtension(filepath);
                    String suffix = GetRandomString();
                    String file = filename + suffix + file_ext;
                    String relativeName = relativeFileSaveLoc + file;
                    //save the file to the server
                    try
                    {
                        fileUpEx.PostedFile.SaveAs(fileSaveLoc + file);
                    }
                    catch (DirectoryNotFoundException)
                    {
                        throw new ODBC2KMLException("Error saving file, please ensure " + fileSaveLoc + " exists on this machine");
                    }

                    Database DB = new Database();
                    try
                    {
                        DB.executeQueryLocal("INSERT INTO IconLibrary (location, isLocal) VALUES (\'" + relativeName + "\', 1)");
                    }
                    catch (ODBC2KMLException ex)
                    {
                        throw new ODBC2KMLException(ex.errorText);
                    }
                    return relativeName;
                }
                else if (!valid)
                {
                    String errorText = "Current File type = " + fileUpEx.PostedFile.ContentType + " File type not appropriate (only jpg, gif, tiff, png, bmp accepted)";
                    throw new ODBC2KMLException(errorText);
                }
                else
                {
                    throw new ODBC2KMLException("File dimensions too large (max 128 x 128)");
                }
            }
            else
            {
                throw new ODBC2KMLException("Please select a file to upload.");
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// used for uploading icons from remote sources
        /// if fetch is checked this function downloads the linked icon and saves its info to the db and saves the icon
        /// if fetch is not checked it just saves the linked icon's info to the db
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public static String URLsubmitClick(bool fetch, String URL, String fileSaveLoc, String relativeFileSaveLoc)
        {
            ArrayList validTypes = BuildTypeList2();

            Database DB = new Database();
            WebClient Client = new WebClient();

            //Create a request for the URL.
            if (URL.Equals(""))
                throw new ODBC2KMLException("Please enter a URL.");

            DataTable dt = DB.executeQueryLocal("SELECT * FROM IconLibrary WHERE location='" + URL + "'");
            if (dt.Rows.Count > 0)
                throw new ODBC2KMLException("URL Path already exists in Icon Library.");

            WebRequest request = WebRequest.Create(URL);
            request.Proxy = null;
            try
            {
                //Get the response.
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            }
            catch (Exception)
            {
                throw new ODBC2KMLException("Cannot connect to the URL you entered");
            }

            //below lines get information to check validity of icon and saves the icon temporarily
            String fileName = System.IO.Path.GetFileNameWithoutExtension(URL);
            String ext = System.IO.Path.GetExtension(URL);
            String suffix = GetRandomString();
            String name = fileSaveLoc + fileName + suffix + ext;

            //checks to see if fileType of icon is valid
            bool valid = false;
            foreach (String type in validTypes)
            {
                if (ext.Equals(type))
                {
                    valid = true;
                    break;
                }
            }

            if (valid)
            {
                try
                {
                    Client.DownloadFile(URL, name);
                }
                catch (WebException)
                {
                    throw new ODBC2KMLException("Error with temporary download, please ensure " + fileSaveLoc + " exists on this machine");
                }
                /*catch (ArgumentException)
                {
                    throw new ODBC2KMLException("No URL entered");
                }*/

                FileStream fs = File.OpenRead(name);
                bool validDim = ValidateFileDimensions(fs);
                fs.Close();
                if (fetch)
                {
                    String relativeName = relativeFileSaveLoc + fileName + suffix + ext;
                    //checks if icon has valid dimensions
                    if (validDim)
                    {
                        try
                        {
                            DB.executeQueryLocal("INSERT INTO IconLibrary (location, isLocal) VALUES (\'" + relativeName + "\', 1)");
                        }
                        catch (ODBC2KMLException ex)
                        {
                            throw new ODBC2KMLException(ex.errorText);
                        }
                    }
                    else
                    {
                        File.Delete(name);
                        throw new ODBC2KMLException("The file you linked to was to large (max 128 x 128)");
                    }
                    return relativeName;
                }
                else
                {
                    //checks if icon has valid dimensions
                    File.Delete(name);
                    if (validDim)
                    {
                        try
                        {
                            DB.executeQueryLocal("INSERT INTO IconLibrary (location, isLocal) VALUES (\'" + URL + "\', 0)");
                        }
                        catch (ODBC2KMLException ex)
                        {
                            throw new ODBC2KMLException(ex.errorText);
                        }
                    }
                    else
                    {
                        throw new ODBC2KMLException("The file you linked to was to large (max 128 x 128)");
                    }
                    return URL;
                }
            }
            else if (!valid)
            {
                throw new ODBC2KMLException("You linked to an invalid file type");
            }
            return "";
        }
Ejemplo n.º 17
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Database db = new Database();
            DataTable dt;
            Label title = new Label();
            string connID = Request["con"];
            string table = Request["tbl"];
            string tblQuery = "SELECT * FROM " + table;

            ConnInfo info = new ConnInfo();

            try
            {
                db = new Database();

                string query = "SELECT * FROM Connection WHERE ID=" + connID;
                dt = db.executeQueryLocal(query);
                if (dt.HasErrors)
                {
                    throw new ODBC2KMLException("There was a problem getting the connection information from the local database");
                }
            }
            catch (ODBC2KMLException ex)
            {
                ErrorHandler eh = new ErrorHandler(ex.conErrorText, errorPanel1);
                eh.displayError();
                return;
            }

            //Cycle through each row and column
            foreach (DataRow row in dt.Rows)
            {

                foreach (DataColumn col in dt.Columns)
                {
                    //Set all connInfo
                    switch (col.ColumnName)
                    {
                        case "name":
                            info.setConnectionName(row[col].ToString());
                            break;
                        case "dbName":
                            info.setDatabaseName(row[col].ToString());
                            break;
                        case "userName":
                            info.setUserName(row[col].ToString());
                            break;
                        case "password":
                            info.setPassword(row[col].ToString());
                            break;
                        case "port":
                            info.setPortNumber(row[col].ToString());
                            break;
                        case "address":
                            info.setServerAddress(row[col].ToString());
                            break;
                        case "type":
                            info.setDatabaseType(int.Parse(row[col].ToString()));
                            break;
                        case "protocol":
                            info.setOracleProtocol(row[col].ToString());
                            break;
                        case "serviceName":
                            info.setOracleServiceName(row[col].ToString());
                            break;
                        case "SID":
                            info.setOracleSID(row[col].ToString());
                            break;
                        default:
                            break;
                    }
                }
            }//End outer loop

            db.setConnInfo(info);
            try
            {
                dt = db.executeQueryRemote(tblQuery);
            }
            catch (ODBC2KMLException ex)
            {
                ErrorHandler eh = new ErrorHandler(ex.tblErrorText, errorPanel1);
                eh.displayError();
                return;
            }

            //resultsPanel.Visible = true;
            bool altTables = true;

            Page.Controls.Add(new LiteralControl("<span style=\"color: white; font-weight:bold; background-color:rgb(26,49,76);\">&nbsp;" + table + " Database Query Results</span>"));
            Page.Controls.Add(new LiteralControl("<div>"));

            Page.Controls.Add(new LiteralControl("<table cellpadding=\"5\" cellspacing=\"2\">"));

            Page.Controls.Add(new LiteralControl("<tr><td>"));
            Page.Controls.Add(new LiteralControl("<div>"));
            Page.Controls.Add(new LiteralControl("<table cellspacing=\"2\" cellpadding=\"2\" rules=\"all\">"));

            Page.Controls.Add(new LiteralControl("<tr class=\"titleConn\">"));
            foreach (DataColumn dc in dt.Columns)
            {
                Page.Controls.Add(new LiteralControl("<td><b>" + dc.ColumnName + "<br/></b></td>"));
            }
            Page.Controls.Add(new LiteralControl("</tr>"));
            foreach (DataRow dr in dt.Rows)
            {
                if (altTables)
                {
                    Page.Controls.Add(new LiteralControl("<tr class=\"evenConn\">"));
                    foreach (Object data in dr.ItemArray)
                    {
                        Page.Controls.Add(new LiteralControl("<td>" + data.ToString() + "</td>"));
                    }
                    Page.Controls.Add(new LiteralControl("</tr>"));
                }
                else
                {
                    Page.Controls.Add(new LiteralControl("<tr class=\"oddConn\">"));
                    foreach (Object data in dr.ItemArray)
                    {
                        Page.Controls.Add(new LiteralControl("<td>" + data.ToString() + "</td>"));
                    }
                    Page.Controls.Add(new LiteralControl("</tr>"));
                }

                altTables = !altTables;
            }

            Page.Controls.Add(new LiteralControl("</table>"));
            Page.Controls.Add(new LiteralControl("</td></tr>"));
            Page.Controls.Add(new LiteralControl("</div>"));
            Page.Controls.Add(new LiteralControl("</span>"));
        }
Ejemplo n.º 18
0
        protected void fillIconLibraryLists()
        {
            iconListAvailableToAdd.Clear();
            iconListAvailableToRemove.Clear();
            string conId = Request.QueryString.Get("ConnID");

            Database db = new Database();
            DataTable dt;

            try
            {
                dt = db.executeQueryLocal("SELECT ID, location, isLocal FROM IconLibrary AS IL WHERE (NOT EXISTS (SELECT ID, connID FROM Icon AS IC WHERE (connID = " + conId + " ) AND (iconLibraryID = IL.ID)))");
            }
            catch (ODBC2KMLException ex)
            {
                throw ex;
            }

            foreach (DataRow dr in dt.Rows)
            {
                Icon icon = new Icon();
                icon.setId(dr["ID"].ToString());
                icon.setLocation(dr["location"].ToString());
                icon.setLocality((bool)dr["isLocal"]);
                iconListAvailableToAdd.Add(icon);
            }

            Database db2 = new Database();
            DataTable dt2;
            try
            {
                dt2 = db2.executeQueryLocal("SELECT IconLibrary.ID, IconLibrary.location, IconLibrary.isLocal FROM IconLibrary,Icon Where IconLibrary.ID=Icon.iconLibraryID AND Icon.ConnID=" + conId);
            }
            catch (ODBC2KMLException ex)
            {
                throw ex;
            }

            foreach (DataRow dr2 in dt2.Rows)
            {
                string iconId = dr2["ID"].ToString();
                string iconLoc = dr2["location"].ToString();
                Icon icon = new Icon();
                icon.setId(iconId);
                icon.setLocation(iconLoc);
                icon.setLocality((bool)dr2["isLocal"]);
                iconListAvailableToRemove.Add(icon);
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Validates the connection name. Only use is to ensure the name is not
        /// an empty string.
        /// </summary>
        /// <param name="name">String --> Connection string to validate</param>
        /// <returns>Boolean --> true -> Valid, False -> Invalid</returns>
        public static Boolean validConnName(String name, int connID)
        {
            //Empty connection name
            if(name.Equals(""))
            {
                return false;
            }

            //Create database and execute query
            Database DB = new Database();
            String query = "SELECT * FROM Connection WHERE name='" + name + "' AND ID!=" + connID;

            DataTable DT = null;

            try
            {
                DT = DB.executeQueryLocal(query);
            }
            catch (ODBC2KMLException ex)
            {
                ex.errorText = "Error getting connection information";
                throw ex;
            }

            //If the row number isn't 0, return false
            if (DT.Rows.Count > 0)
                return false;

            //Valid name
            return true;
        }
Ejemplo n.º 20
0
        protected void addSingleIconToLib(String path)
        {
            Database db = new Database();
            DataTable dt;

            try
            {
                dt = db.executeQueryLocal("SELECT ID, location, isLocal FROM IconLibrary WHERE location=\'" + path + "\'");
            }
            catch (ODBC2KMLException ex)
            {
                throw ex;
            }

            foreach (DataRow dr in dt.Rows)
            {
                Icon icon = new Icon();
                icon.setId(dr["ID"].ToString());
                icon.setLocation(dr["location"].ToString());
                icon.setLocality((bool)dr["isLocal"]);
                iconListAvailableToAdd.Add(icon);
            }
            fillIconLibraryPopup();
            sessionSave();
        }
Ejemplo n.º 21
0
        public static ConnInfo getConnInfo(int connID)
        {
            ConnInfo connInfo = new ConnInfo();
            Database localDatabase = new Database();

            //Construct the connInfo query and retrieve the DataTable
            string query = "SELECT * FROM Connection WHERE ID=" + connID + " ORDER BY ID";
            DataTable table = null;

            try
            {
                table = localDatabase.executeQueryLocal(query);
            }
            catch (ODBC2KMLException ex)
            {
                ex.errorText = "Error getting connection information for the connection";
                throw ex;
            }

            //Cycle through each row and column
            foreach (DataRow row in table.Rows)
            {
                foreach (DataColumn col in table.Columns)
                {
                    //Set all connInfo
                    switch (col.ColumnName)
                    {
                        case "name":
                            connInfo.setConnectionName(row[col].ToString());
                            break;
                        case "dbName":
                            connInfo.setDatabaseName(row[col].ToString());
                            break;
                        case "userName":
                            connInfo.setUserName(row[col].ToString());
                            break;
                        case "password":
                            connInfo.setPassword(row[col].ToString());
                            break;
                        case "port":
                            connInfo.setPortNumber(row[col].ToString());
                            break;
                        case "address":
                            connInfo.setServerAddress(row[col].ToString());
                            break;
                        case "type":
                            connInfo.setDatabaseType((int)row[col]);
                            break;
                        case "protocol":
                            connInfo.setOracleProtocol(row[col].ToString());
                            break;
                        case "serviceName":
                            connInfo.setOracleServiceName(row[col].ToString());
                            break;
                        case "SID":
                            connInfo.setOracleSID(row[col].ToString());
                            break;
                        default:
                            break;
                    }
                }
            }//End outer loop

            return connInfo;
        }
Ejemplo n.º 22
0
        protected void createConnection(object sender, EventArgs e)
        {
            String ConnName = odbcNameE.Text.ToString();
            String ConnDBName = odbcDNameE.Text.ToString();
            String ConnDBAddress = odbcDatabaseE.Text.ToString();
            String ConnPortNum = odbcPNE.Text.ToString();
            String ConnUser = odbcUserE.Text.ToString();
            String ConnPWD = odbcPWE.Text.ToString();
            String ConnDBType = odbcDBType.SelectedValue.ToString();
            String oracleProtocol = odbcProtocol.Text.ToString();
            String oracleSName = odbcSName.Text.ToString();
            String oracleSID = odbcSID.Text.ToString();
            String DBTypeNum;
            odbcDBType.SelectedIndex = 0;

            if (ConnDBType.Equals("MySQL")){
                DBTypeNum = "0";
            }else if(ConnDBType.Equals("MSSQL")){
                DBTypeNum = "1";
            }else{
                DBTypeNum = "2";
            }

            if (DBTypeNum.Equals("2")){
                if (oracleSName.Equals("") && oracleSID.Equals("")){
                    ErrorHandler eh = new ErrorHandler("Either Service Name or Service ID must be completed!", errorPanel1);
                    this.NewConn1ModalPopUp.Hide();
                    eh.displayError();
                    return;
                }
                if (oracleProtocol.Equals(""))
                {
                    ErrorHandler eh = new ErrorHandler("Oracle protocol must be provided!", errorPanel1);
                    this.NewConn1ModalPopUp.Hide();
                    eh.displayError();
                    return;
                }
            }

            Database dbCheck = new Database();
            DataTable dtCheck = null;

            try
            {
                dtCheck = dbCheck.executeQueryLocal("SELECT name FROM Connection WHERE name=\'" + ConnName + "\'");
            }
            catch (ODBC2KMLException)
            {
                ErrorHandler eh = new ErrorHandler("There was an error getting the Connection's name", errorPanel1);
                this.NewConn1ModalPopUp.Hide();
                eh.displayError();
                return;
            }

            if (dtCheck.Rows.Count > 0)
            {
                ErrorHandler eh = new ErrorHandler("Connection name already in use!", errorPanel1);
                this.NewConn1ModalPopUp.Hide();
                eh.displayError();
                return;
            }
            if (ConnName.Equals(""))
            {
                ErrorHandler eh = new ErrorHandler("The connection must have a unique name!", errorPanel1);
                this.NewConn1ModalPopUp.Hide();
                eh.displayError();
                return;
            }else if (ConnDBName.Equals(""))
            {
                ErrorHandler eh = new ErrorHandler("The connection must have a database name!", errorPanel1);
                this.NewConn1ModalPopUp.Hide();
                eh.displayError();
                return;
            }else if (ConnDBAddress.Equals(""))
            {
                ErrorHandler eh = new ErrorHandler("The connection must have a database address!", errorPanel1);
                this.NewConn1ModalPopUp.Hide();
                eh.displayError();
                return;
            }else if (ConnPortNum.Equals(""))
            {
                ErrorHandler eh = new ErrorHandler("The connection must have a port number!", errorPanel1);
                this.NewConn1ModalPopUp.Hide();
                eh.displayError();
                return;
            }else if(ConnUser.Equals(""))
            {
                ErrorHandler eh = new ErrorHandler("The connection must have a user name!", errorPanel1);
                this.NewConn1ModalPopUp.Hide();
                eh.displayError();
                return;
            }else if (ConnPWD.Equals(""))
            {
                ErrorHandler eh = new ErrorHandler("The connection must have a password!", errorPanel1);
                this.NewConn1ModalPopUp.Hide();
                eh.displayError();
                return;
            }

            ConnInfo testConn = new ConnInfo();
            testConn.setConnectionName(ConnName);
            testConn.setDatabaseName(ConnDBName);
            testConn.setDatabaseType((int)Convert.ToInt32(DBTypeNum));
            testConn.setPassword(ConnPWD);
            testConn.setPortNumber(ConnPortNum);
            testConn.setServerAddress(ConnDBAddress);
            testConn.setUserName(ConnUser);
            if (DBTypeNum.Equals("2"))
            {
                testConn.setOracleProtocol(oracleProtocol);
                testConn.setOracleServiceName(oracleSName);
                testConn.setOracleSID(oracleSID);
            }

            try
            {
                Database dbTest = new Database(testConn);
                DataTable dtTest;
                if (DBTypeNum.Equals("0"))
                {
                    dtTest = dbTest.executeQueryRemote("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES");
                }
                else if (DBTypeNum.Equals("1"))
                {
                    dtTest = dbTest.executeQueryRemote("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES");
                }
                else
                {
                    dtTest = dbTest.executeQueryRemote("SELECT TABLE_NAME FROM user_tables");
                }

            }
            catch (ODBC2KMLException ex)
            {
                ErrorHandler eh = new ErrorHandler(ex.errorText, errorPanel1);
                this.NewConn1ModalPopUp.Hide();
                eh.displayError();
                return;
            }

            //Call Create DB with the DB Function
            Database db = new Database();
            DataTable dt;

            try
            {
                if (DBTypeNum.Equals("2"))
                {
                    db.executeQueryLocal("INSERT INTO Connection (name, dbName, userName, password, port, address, type, protocol, serviceName, SID) VALUES ('" + ConnName + "', '" + ConnDBName + "', '" + ConnUser + "', '" + ConnPWD + "', '" + ConnPortNum + "', '" + ConnDBAddress + "', '" + DBTypeNum + "', '" + oracleProtocol + "', '" + oracleSName + "', '" + oracleSID + "')");
                }
                else
                {
                    db.executeQueryLocal("INSERT INTO Connection (name, dbName, userName, password, port, address, type, protocol, serviceName, SID) VALUES ('" + ConnName + "', '" + ConnDBName + "', '" + ConnUser + "', '" + ConnPWD + "', '" + ConnPortNum + "', '" + ConnDBAddress + "', '" + DBTypeNum + "', '', '', '')");
                }
            }
            catch (ODBC2KMLException)
            {
                ErrorHandler eh = new ErrorHandler("There was an error saving the connection to the database.", errorPanel1);
                this.NewConn1ModalPopUp.Hide();
                eh.displayError();
                return;
            }

            this.NewConn1ModalPopUp.Hide();
            //Jump to the Modify page

            try
            {
                dt = db.executeQueryLocal("SELECT ID FROM CONNECTION WHERE name='" + ConnName + "' AND dbName='" + ConnDBName + "' AND userName='******' AND port='" + ConnPortNum + "' AND address='" + ConnDBAddress + "' AND type='" + DBTypeNum + "'");
            }
            catch (ODBC2KMLException)
            {
                ErrorHandler eh = new ErrorHandler("There was an error retreiving the new connection's connID.", errorPanel1);
                this.NewConn1ModalPopUp.Hide();
                eh.displayError();
                return;
            }

            foreach (DataRow dr in dt.Rows)
            {
                string connID = dr["ID"].ToString();

                Response.Redirect("ConnDetails.aspx?ConnID=" + connID + "&locked=false");
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// This function takes a connection object and generates all the associated KML for that connection.
        /// It works hand-in-hand with KMLGenerationLibrary, Styles, and Placemarks.
        /// 
        /// There is also a helper class used to prevent duplicate styles (HashStyleComparer).
        /// </summary>
        /// <param name="connection">Connection --> connection object for the connection that you wish to generate KML for</param>
        /// <returns>String --> A string that is the KML</returns>
        public string generateKMLFromConnection(Connection connection)
        {
            //if the mapping is invalid, throw an exception and don't try to continue
            if (!connection.mapping.isValid(connection.connInfo))
            {
                throw new ODBC2KMLException("There was an exception generating KML. Mapping is invalid.");
            }

            //Needed to generate KML, parameter is desired file name within KML file
            KMLGenerationLibrary kmlGenerator = new KMLGenerationLibrary(this.fileName);

            try
            {
                //Get mappings fromc onnection object
                Mapping map = connection.getMapping();

                //Create array list to hold places
                ArrayList placemarks = new ArrayList();
                //Create hashset to hold unique styles, takes HashStyleComparer which is a helper class
                HashSet<Style> styles = new HashSet<Style>(new HashStyleComparer());

                //Create the Icon array and grabs the icons for the connection
                ArrayList icons = new ArrayList();
                icons = connection.getIcons();

                //Create the overlay array and grab the overlays for the connection
                ArrayList overlays = new ArrayList();
                overlays = connection.getOverlays();

                //Retrieve description string
                String descString = connection.getDescription().getDesc();

                //Create an array to store new description values
                ArrayList descArray = new ArrayList();

                //Create data table to pass to parser
                DataTable remote = null;

                //Create database
                Database DB = new Database(connection.getConnInfo());

                //Grab the tablename out of mapping
                String tableName = map.getTableName();

                try
                {
                    if (connection.getConnInfo().getDatabaseType() == ConnInfo.MSSQL)
                    {
                        remote = DB.executeQueryRemote("SELECT * FROM " + tableName);
                    }
                    else if (connection.getConnInfo().getDatabaseType() == ConnInfo.MYSQL)
                    {
                        remote = DB.executeQueryRemote("SELECT * FROM " + tableName + ";");
                    }
                    else if (connection.getConnInfo().getDatabaseType() == ConnInfo.ORACLE)
                    {
                        remote = DB.executeQueryRemote("SELECT * FROM \"" + tableName + "\"");
                    }
                }
                catch
                {
                    throw new ODBC2KMLException("There was an exception generating KML. There was a problem retreiving data from the remote server");
                }

                //Parsed descriptions for rows
                descArray = Description.parseDesc(remote, descString, tableName);

                int counter = 0;
                //For each row in the table!!!
                foreach (DataRow remoteRow in remote.Rows)
                {
                    //Set placemark name
                    string placemarkName;
                    try
                    {
                        if (map.getPlacemarkFieldName() == null || map.getPlacemarkFieldName().Trim().Equals("") || map.getPlacemarkFieldName().Trim().Equals("No placemark name mapped"))
                        {
                            placemarkName = "";
                        }
                        else
                        {
                            placemarkName = (String)remoteRow[map.getPlacemarkFieldName()];

                        }
                    }
                    catch
                    {
                        throw new ODBC2KMLException("There was an exception generating KML. Error parsing placemark.");
                    }

                    //Foreach row set the description for each row
                    String rowDesc = descArray[counter].ToString();

                    //Declare the lat and long holders
                    Double rowLat = 0, rowLon = 0;

                    //Check to see how many columns there are
                    try
                    {
                        if (map.getFormat() != Mapping.SEPARATE)
                        {
                            //Select the column value
                            String column = "";
                            foreach (DataColumn remoteColumn in remote.Columns)
                            {
                                if (remoteColumn.ColumnName == map.getLatFieldName())
                                {
                                    column = remoteRow[remoteColumn].ToString();
                                }
                            }

                            //Create the array to hold the coordinates
                            double[] coordinates;

                            //Separate the coordinates
                            //Order == Latitude First
                            if (map.getFormat() == Mapping.LATFIRST)
                            {
                                coordinates = map.separate(column, Mapping.LATFIRST);
                                rowLat = coordinates[0];
                                rowLon = coordinates[1];
                            }
                            else //Order == Longitude first
                            {
                                coordinates = map.separate(column, Mapping.LONGFIRST);
                                rowLon = coordinates[0];
                                rowLat = coordinates[1];
                            }
                        }
                        else//Two separate columns
                        {
                            //Get coordinates
                            foreach (DataColumn remoteColumn in remote.Columns)
                            {
                                if (remoteColumn.ColumnName == map.getLatFieldName())
                                {
                                    rowLat = Double.Parse(remoteRow[remoteColumn].ToString());
                                }
                                else if (remoteColumn.ColumnName == map.getLongFieldName())
                                {
                                    rowLon = Double.Parse(remoteRow[remoteColumn].ToString());
                                }
                            }//End for each
                        }//End else
                    }
                    catch
                    {
                        throw new ODBC2KMLException("There was an exception generating KML. Error parsing lat/long rows.");
                    }

                    //Row's icon
                    Icon rowIcon = new Icon();
                    rowIcon.setLocation("");

                    //For each icon until the first one found, compare the icons
                    //conditions against the given row
                    Boolean breakLoop = false;
                    foreach (Icon i in icons)
                    {
                        foreach (Condition c in i.getConditions())
                        {
                            //See if the condition applies to the given row
                            if (c.evaluateCondition(remoteRow, c, tableName))
                            {
                                //Set temp icon to row icon and tell it to break out
                                rowIcon = new Icon(i);
                                breakLoop = true;
                            }

                            //Grabbed the first icon, break out
                            if (breakLoop)
                                break;
                        }//End inner for each

                        //Grabbed the first icon, break out
                        if (breakLoop)
                            break;
                    }//End outer for each

                    //Long unsigned int, needed to properly interpret colors
                    UInt64 color = 0;
                    foreach (Overlay o in overlays)
                    {
                        foreach (Condition c in o.getConditions())
                        {
                            //See if the condition applies
                            if (c.evaluateCondition(remoteRow, c, tableName))
                            {
                                if (color == 0)
                                {
                                    //Set the color to hex value
                                    color = 0xFF000000;
                                }
                                //Mix the colors, if multiple colors work
                                color = color | (Convert.ToUInt64(o.getColor(), 16));
                            }
                        }//End inner for each
                    }//End outer for each

                    //Create Style and placemark for this coordinate set
                    Style rowStyle = new Style();
                    Placemark rowPlacemark;

                    //if there is an icon, create the name of the style based on the icon name and color
                    if (rowIcon.getLocation() != "")
                    {
                        if (rowIcon.getLocality() == false)
                        {
                            //Create new style with external icon
                            rowStyle = new Style(rowIcon, color, (rowIcon.getLocation() + "_" + color.ToString("X")));
                            rowIcon.setLocation("");
                        }
                        else //If the icon is local, append server data
                        {
                            //Create the new style, with local icon
                            rowIcon.setLocation(this.serverPath + rowIcon.getLocation());
                            rowStyle = new Style(rowIcon, color, (rowIcon.getLocation() + "_" + color.ToString("X")));
                            rowIcon.setLocation("");
                        }
                    }
                    else if (rowIcon.getLocation() == "" && color != 0) //Create the style name based on the color
                    {
                        rowStyle = new Style(rowIcon, color, color.ToString("X"));
                    }
                    else //If rowstyle is null, ignore it
                    {
                        rowStyle = null;
                    }

                    //Create placemark and add it to array list
                    rowPlacemark = new Placemark(rowLat, rowLon, rowDesc, placemarkName);

                    placemarks.Add(rowPlacemark);

                    //If there is a row style, add it to the placemark and the array list
                    if (rowStyle != null)
                    {
                        rowPlacemark.setPlacemarkStyleName("#" + rowStyle.getStyleName());
                        styles.Add(rowStyle);
                    }
                    else
                    {
                        //Default value which won't add a style to this placemark in KML
                        rowPlacemark.setPlacemarkStyleName("");
                    }

                    //Increment counter for next row (associated with getting the row description)
                    counter++;

                }//End for each
                // }//End for each

                //Add each style to the KML
                foreach (Style s in styles)
                {
                    kmlGenerator.addStyle(s);
                }

                //Used to check if a look at has been added
                Boolean addLookAt = false;

                //Add each placemark to the KML
                foreach (Placemark p in placemarks)
                {
                    kmlGenerator.addPlacemark(p);
                    if (!addLookAt) //Add the first placemark as default lookat
                    {
                        kmlGenerator.addLookAt(p);
                        addLookAt = true;
                    }
                }
            }
            catch (ODBC2KMLException e) //If bad things happen pass it up to connection details
            {
                throw e;
            }

            //Return KML string
            return kmlGenerator.finalizeKML();
        }