예제 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            DataService ds = new DataService();

            GetApplicationSettings();

            ds.RequestData.Add("restrict_to_survey_id", Indicia_SurveyID.ToString());
            List<SurveyAttribute> attrs = ds.GetSurvey();

            foreach (SurveyAttribute attr in attrs)
            {
                HtmlGenericControl div = CreateIndiciaQuestion(attr);
                survey_pnl.Controls.Add(div);
            }
        }
예제 #2
0
        public void ProcessRequest(HttpContext context)
        {
            string searchTermParam = context.Request.QueryString["sTerm"];
            if (String.IsNullOrWhiteSpace(searchTermParam))
            {
                throw new ArgumentException("Expected query string search term parameter 'sTerm' not available", "sTerm");
            }

            List<TaxonSearchItem> SortedTaxonList;

            if (context.Cache["Indicia_TaxaSearch_" + searchTermParam] != null)
            {
                SortedTaxonList = (List<TaxonSearchItem>)context.Cache["Indicia_TaxaSearch_" + searchTermParam];
            }
            else
            {
                DataService ds = new DataService();

                string taxonListID = ConfigurationManager.AppSettings["Indicia_SpeciesPicker_TaxonListID"];
                if (String.IsNullOrEmpty(taxonListID))
                { throw new ConfigurationErrorsException("Application setting Indicia_SpeciesPicker_TaxonListID required"); }
                else
                {
                    int tempID;
                    int.TryParse(taxonListID, out tempID);
                    if (tempID <= 0)
                    { throw new ConfigurationErrorsException("Application setting Indicia_SpeciesPicker_TaxonListID must be a positive integer"); }
                }

                ds.RequestData.Add("taxon_list_id", taxonListID);
                ds.RequestData.Add("limit", "100");
                ds.RequestData.Add("q", "*" + searchTermParam);
                ds.RequestData.Add("qfield", "searchterm");
                ds.RequestData.Add("query", "{\"where\":[\"(simplified='t' or simplified is null) AND (preferred='t' or language_iso<>'lat')\"]}");

                List<TaxonSearchItem> TaxonList = ds.GetTaxaSearchList();
                SortedTaxonList = TaxonList.GroupBy(t => new { t.DefaultCommonName, t.PreferredTaxon }).Select(g => g.First()).OrderBy(o => o.DefaultCommonName).ToList();
                context.Cache.Add("Indicia_TaxaSearch_" + searchTermParam, SortedTaxonList, null, System.Web.Caching.Cache.NoAbsoluteExpiration, new TimeSpan(7, 0, 0, 0), System.Web.Caching.CacheItemPriority.BelowNormal, null);
            }
            context.Request.ContentType = "application/json";
            context.Response.Write(JsonConvert.SerializeObject(SortedTaxonList));
        }
예제 #3
0
        protected void submitSurvey_btn_Click(object sender, EventArgs e)
        {
            Sample m = new Sample();
            m.AddToFields("website_id", Indicia_WebsiteID);
            m.AddToFields("survey_id", Indicia_SurveyID);
            m.AddToFields("date", DateTime.Now.ToString("yyyy-MM-dd"));

            SubModel smOcc = new SubModel(SubModelType.occurrence);
            smOcc.AddToFields("website_id", Indicia_WebsiteID.ToString());
            SubModel smLoc = new SubModel(SubModelType.location);

            foreach (Control ctrl in survey_pnl.Controls) //these are the 'IndiciaQuestionWrap' divs
            {
                foreach (Control subCtrl in ctrl.Controls)
                {
                    IIndiciaAttributes t = subCtrl as IIndiciaAttributes;
                    if (t == null)
                    { continue; }

                    if (t.IndiciaAttributeJSONID.Contains("smpAttr"))
                    {
                        m.AddToFields(t.IndiciaAttributeJSONID, t.GetValue());
                    }

                    if (t.IndiciaAttributeJSONID.Contains("locAttr"))
                    {
                        smLoc.AddToFields(t.IndiciaAttributeJSONID, t.GetValue());
                    }

                    if (t.IndiciaAttributeJSONID.Contains("occAttr"))
                    {
                        smOcc.AddToFields(t.IndiciaAttributeJSONID, t.GetValue());
                    }
                }
            }

            if (smOcc.HasFields())
            {
                smOcc.AddToFields("taxa_taxon_list_id", "72"); //TODO: this should be implemeted via the species picker
                m.AddSubModel(smOcc);
            }
            if (smLoc.HasFields())
            {
                m.AddSubModel(smLoc);
            }

            // TODO: need to implement method of getting sample location from user. This is outside the scope of this project
            // One way would to implement a web map (OpenLayers, Google, Bing) and get the user to click on location.
            m.AddToFields("entered_sref", "TQ 27647 78433");
            m.AddToFields("entered_sref_system", "OSGB");

            DataService ds = new DataService();
            JavaScriptSerializer jss = new JavaScriptSerializer();
            ds.RequestData.Add("submission", jss.Serialize(m));

            try
            {
                ds.SaveData();
                submitSurveyResponse_ltl.Text = "Thank you, survey submitted";
            }
            catch (ArgumentException ex)
            {
                submitSurveyResponse_ltl.Text = ex.Message;
            }
        }
예제 #4
0
        private IndiciaDropDownList CreateDropDownList(SurveyAttribute attr)
        {
            Indicia.WebControls.IndiciaDropDownList ddl = new Indicia.WebControls.IndiciaDropDownList();
            DataService ds2 = new DataService();
            ds2.RequestData.Add("termlist_id", attr.TermlistId.ToString());
            List<TermItem> ddlData = ds2.GetTermList();

            ddl.DataSource = ddlData;
            ddl.DataTextField = "Term";
            ddl.DataValueField = "TermId";
            ddl.DataBind();
            return ddl;
        }