Example #1
0
        public SurveyInfo GetSurveyInfo(int nSurveyID)
        {
            SurveyInfo info = new SurveyInfo();
            String     sql  = "SELECT * FROM dbo.TblSurvey WHERE fSurveyID = " + nSurveyID;

            using (SqlConnection con = new SqlConnection(DataSources.dbConSpecies))
            {
                con.Open();
                using (SqlCommand command = new SqlCommand(sql, con))
                {
                    using (SqlDataReader set = command.ExecuteReader())
                    {
                        if (!set.Read())
                        {
                            Response.Write("No surveys found");
                            Response.End();
                        }
                        info.fSurveyLabel   = (string)set["fSurveyLabel"];
                        info.fSurveyDesc    = (string)set["fSurveyName"];
                        info.fSurveyTypeRef = (int)set["fSurveyTypeRef"];
                        info.type           = GetSurveyTypeInfo(info.fSurveyTypeRef);
                    }
                }
            }
            return(info);
        }
Example #2
0
        public void SaveIndicators(int id, HttpRequest req, HttpResponse res)
        {
            SurveyInfo       info       = GetSurveyInfo(fSurveyID);
            List <Indicator> indicators = LoadIndicators(info.fSurveyTypeRef, id, false);

            foreach (Indicator indicator in indicators)
            {
                list.ExecuteSQL(String.Format("DELETE FROM TblEventIndicator WHERE fEventID={0} AND fIndicatorID={1}", id, indicator.id));

                String sql = "INSERT INTO TblEventIndicator (fEventID, fIndicatorID, fValue) VALUES (@fEventID, @fIndicatorID, @fValue)";
                using (SqlConnection con = new SqlConnection(DataSources.dbConSpecies))
                {
                    con.Open();
                    using (SqlCommand command = new SqlCommand(sql, con))
                    {
                        command.Parameters.AddWithValue("@fEventID", id);
                        command.Parameters.AddWithValue("@fIndicatorID", indicator.id);
                        command.Parameters.AddWithValue("@fValue", Request["ff" + indicator.id]);
                        command.ExecuteNonQuery();
                    }
                }
            }
        }
Example #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string survey = Request["sv"];

            if (survey == null || survey == "")
            {
                if (Session["fSurveyID"] != null)
                {
                    survey = Session["fSurveyID"].ToString();
                }
                if (survey == null || survey == "")
                {
                    survey = GetFirstSurveyID();
                }
            }
            fSurveyID            = int.Parse(survey);
            Session["fSurveyID"] = survey;

            level2Names = GetLevel2Names(fSurveyID);
            stations    = GetStations();



            SurveyInfo info = GetSurveyInfo(fSurveyID);


            String query  = "";
            String filter = Request["filter"];

            if (filter != null && filter != "")
            {
                String[] filters = filter.Split('|');
                foreach (String f in filters)
                {
                    String[] ftr  = f.Split('=');
                    String   name = ftr[0];
                    String   val  = ftr[1].Replace("'", "''");
                    if (val != "" && val != "All")
                    {
                        if (query != "")
                        {
                            query += " AND ";
                        }
                        switch (name)
                        {
                        case "level2":
                            query += "fLevel2Name = '" + val + "'";
                            break;

                        case "level3":
                            query += "fLevel3Name = '" + val + "'";
                            break;

                        case "station":
                            if (double.Parse(val) > 0)
                            {
                                double max = double.Parse(val) * 100;
                                double min = max - 100;
                                query += "fDepth  >= " + min + " AND fDepth <= " + max;
                            }
                            break;

                        case "date1":
                            query += "fStartDate >= '" + val + "'";
                            break;

                        case "date2":
                            query += "fStartDate <= '" + val + "'";
                            break;
                        }
                    }
                }
            }



            list         = new GenericList(Context);
            list.type    = "Event";
            list.table   = "TblEvent";
            list.idField = "fEventID";

            list.fields.Add(new Field("fSurveyID", "SurveyID", FieldType.Constant, 0, 0, fSurveyID.ToString()));


            if (info.type.fSurveyLevel2Name.Length > 0)
            {
                list.fields.Add(new Field("fLevel2Name", info.type.fSurveyLevel2Name, FieldType.String, 80, 100));
                level2Name = info.type.fSurveyLevel2Name;
            }

            if (info.type.fSurveyLevel3Name.Length > 0)
            {
                list.fields.Add(new Field("fLevel3Name", info.type.fSurveyLevel3Name, FieldType.String, 80, 100));
                level3Name = info.type.fSurveyLevel3Name;
            }

            list.fields.Add(new Field("fEventName", "Event", FieldType.String, 80, 100));

            Field station = new Field("fStationID", "Station", FieldType.Combo, 50, 50);

            station.lookUpTable     = "TblStation";
            station.lookUpFieldID   = "fStationID";
            station.lookUpFieldName = "fStationName";
            station.lookUpFilter    = "fSystem = 0";
            list.fields.Add(station);

            list.fields.Add(new Field("fStartDate", "Date", FieldType.Date, 80, 0));

            list.fields.Add(new Field("fDepth", "Depth", FieldType.String, 80, 0));
            list.fields.Add(new Field("fDuration", "Duration", FieldType.String, 80, 0));
            list.exportButton = true;



            list.dataSavedEvent   = SaveIndicators;
            list.customEditDialog = true;
            list.listFilter       = "fSystemEvent = 0 AND fSurveyID = " + fSurveyID;
            if (query != "")
            {
                list.listFilter += " AND " + query;
            }

            list.showAllButton = true;

            list.InitList(Context);
        }
Example #4
0
        public void WriteForm()
        {
            int nSurveyID = int.Parse(Request["survey"]);
            int nEventID  = int.Parse(Request["id"]);

            events     e             = new events();
            SurveyInfo info          = e.GetSurveyInfo(nSurveyID);
            int        nSurveyTypeID = info.fSurveyTypeRef;

            List <Indicator> list = e.LoadIndicators(nSurveyTypeID, nEventID, true);

            for (int i = 0; i < list.Count; i++)
            {
                Indicator indicator = list[i];

                Response.Write("<table style='width: 100%'>");
                Response.Write("<tr>");
                Response.Write("<td colspan=2>");
                Response.Write("<strong>" + indicator.name + "</strong>");
                Response.Write("</td>");
                Response.Write("</tr>");

                Response.Write("<tr>");
                Response.Write("<td>");
                Response.Write("<input id='ff" + indicator.id + "' class='form-control' type='text' value='" + Server.HtmlEncode(indicator.value) + "' />");
                Response.Write("</td>");

                Response.Write("<td style='width: 60px;'>");
                Response.Write("&nbsp;" + indicator.abbr);
                Response.Write("</td>");

                Response.Write("</tr>");

                Response.Write("<tr>");
                Response.Write("<td colspan=2>");
                Response.Write("&nbsp;");
                Response.Write("</td>");
                Response.Write("</tr>");


                Response.Write("</table>");
            }

            Response.Write("\n\n<script>\n");
            Response.Write("var indicators = [\n");
            for (int i = 0; i < list.Count; i++)
            {
                Indicator indicator = list[i];
                if (i > 0)
                {
                    Response.Write(", ");
                }
                Response.Write("{");
                Response.Write("'id': " + indicator.id);
                Response.Write("}\n");
            }

            Response.Write("];\n\n");


            Response.Write("</script>\n\n");
        }