Beispiel #1
0
        protected void grdSubmissions_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Sort")
            {
                this.SortBy        = e.CommandArgument.ToString();
                this.SortDirection = this.SortDirection == "ASC" ? "DESC" : "ASC";
                ShowList();
                return;
            }

            if (e.CommandName == "Select")
            {
                int           rowNum               = int.Parse(e.CommandArgument.ToString());
                int           responseId           = int.Parse(grdSubmissions.DataKeys[rowNum].Value.ToString());
                StringBuilder sb                   = new StringBuilder();
                Dictionary <string, string> values = FormBuilder_Response.GetResponseByResponseId(responseId);

                //DataRow row = dt.Rows[rowNum];
                sb.Append("<table class='submission-detail' cellpadding='5'>");
                foreach (string key in values.Keys)
                {
                    string strHeaderText = GetHeaderText(key);
                    string strValue      = (string)values[key];

                    sb.AppendFormat("<tr><td>{0}:</td><td><b>{1}</b></td>", strHeaderText, strValue);
                }


                sb.Append("</table>");
                divDetail.InnerHtml = sb.ToString();
                mvwSubmission.SetActiveView(vwDetail);
            }

            if (e.CommandName == "Delete")
            {
                int rowNum                      = int.Parse(e.CommandArgument.ToString());
                int responseId                  = int.Parse(grdSubmissions.DataKeys[rowNum].Value.ToString());
                FormBuilderDataContext dc       = new FormBuilderDataContext();
                FormBuilder_Response   response = (from r in dc.FormBuilder_Responses
                                                   where r.Id == responseId
                                                   select r).FirstOrDefault();

                if (response != null)
                {
                    response.Id = responseId;
                    dc.FormBuilder_Responses.DeleteOnSubmit(response);
                    dc.SubmitChanges();
                }
                ShowList();
            }
        }
Beispiel #2
0
        private DataTable GetDataTable()
        {
            DataTable dtResults = null;

            DateTime dtStartDate      = Convert.ToDateTime(txtStartDate.Text);
            DateTime dtEndDate        = Convert.ToDateTime(txtEndDate.Text).AddDays(1);
            FormBuilderDataContext dc = new FormBuilderDataContext();

            List <FormBuilder_FieldInput> lFieldInputs = (from fi in dc.FormBuilder_FieldInputs
                                                          from r in dc.FormBuilder_Responses
                                                          where r.ModuleId == this.ModuleId
                                                          where r.CreatedOn >= dtStartDate
                                                          where r.CreatedOn <= dtEndDate
                                                          where fi.ResponseId == r.Id
                                                          orderby fi.FormBuilder_Field.SortOrder
                                                          select fi).ToList();

            if (lFieldInputs.Count > 0)
            {
                DataTable dtFieldInputs = FormBuilder_Response.CreateDataTable(lFieldInputs, true);
                if (dtFieldInputs != null)
                {
                    dtResults = new DataTable();
                    foreach (DataColumn c in dtFieldInputs.Columns)
                    {
                        dtResults.Columns.Add(new DataColumn(c.ColumnName, c.DataType));
                    }

                    var referringUrl = dtResults.Columns.Add();
                    referringUrl.AllowDBNull = true;
                    referringUrl.ColumnName  = "ReferringUrl";
                    referringUrl.DataType    = typeof(string);

                    var landingUrl = dtResults.Columns.Add();
                    landingUrl.AllowDBNull = true;
                    landingUrl.ColumnName  = "LandingUrl";
                    landingUrl.DataType    = typeof(string);

                    var referrer = dtResults.Columns.Add();
                    referrer.AllowDBNull = true;
                    referrer.ColumnName  = "ReferringDomain";
                    referrer.DataType    = typeof(string);

                    var keywords = dtResults.Columns.Add();
                    keywords.AllowDBNull = true;
                    keywords.ColumnName  = "Keywords";
                    keywords.DataType    = typeof(string);

                    foreach (DataRow row in dtFieldInputs.Rows)
                    {
                        var newRow = dtResults.Rows.Add(row.ItemArray);

                        int responseId       = Convert.ToInt32(row["ResponseId"]);
                        var responseReferrer = dc.FormBuilder_ResponseReferrers.Where(r => r.ResponseId == responseId).FirstOrDefault();
                        if (responseReferrer != null)
                        {
                            newRow["ReferringUrl"]    = responseReferrer.referringUrl;
                            newRow["LandingUrl"]      = responseReferrer.landingUrl;
                            newRow["ReferringDomain"] = responseReferrer.domain;
                            newRow["Keywords"]        = responseReferrer.query;
                        }
                    }
                }
            }

            return(dtResults);
        }
        public static DataTable CreateDataTable(List <FormBuilder_FieldInput> fieldInputs, bool truncateLongStrings)
        {
            if (null == fieldInputs || fieldInputs.Count == 0)
            {
                return(null);
            }
            var dt = new DataTable();

            int nModuleId = fieldInputs[0].FormBuilder_Field.ModuleId;

            FormBuilderDataContext dc = new FormBuilderDataContext();
            var fields = from f in dc.FormBuilder_Fields
                         where f.ModuleId == nModuleId
                         select f;

            //standard fields
            dt.Columns.Add(new DataColumn("CreatedOn", typeof(DateTime)));

            var pageCount = 0;

            //form-specific fields
            foreach (FormBuilder_Field field in fields)
            {
                // Must guarantee unique column names in DataTable
                dt.Columns.Add(field.Name + "_" + field.Id);
                //check if this is a multipage form
                if (field.Type == (int)FormBuilder_Field.FieldType.PageHeader)
                {
                    pageCount++;
                }
            }

            var isMultiPage = pageCount > 0;

            if (isMultiPage)
            {
                dt.Columns.Add("IsComplete");
            }

            //standard fields
            dt.Columns.Add("CreatedBy");
            dt.Columns.Add("IPAddress");
            dt.Columns.Add("ResponseId");

            //keep track of responses that have been added already
            var responseIds = new List <int>();

            foreach (FormBuilder_FieldInput fieldInput in fieldInputs)
            {
                if (!responseIds.Contains(fieldInput.ResponseId))
                {
                    responseIds.Add(fieldInput.ResponseId);
                    //get all the inputs for this response.
                    var assocInputs = new List <FormBuilder_FieldInput>();
                    foreach (var fi in fieldInputs)
                    {
                        if (fi.ResponseId == fieldInput.ResponseId)
                        {
                            assocInputs.Add(fi);
                        }
                    }

                    //add the respective row.
                    DataRow dr = dt.NewRow();
                    FormBuilder_Response response = fieldInput.FormBuilder_Response;
                    if (isMultiPage)
                    {
                        dr["IsComplete"] = response.IsComplete ? "Yes" : "No";
                    }
                    dr["CreatedBy"] = response.CreatedBy;
                    dr["CreatedOn"] = response.CreatedOn;
                    dr["IPAddress"] = response.IPAddress;
                    foreach (FormBuilder_FieldInput i in assocInputs)
                    {
                        dr[i.FormBuilder_Field.Name + "_" + i.FormBuilder_Field.Id] =
                            (truncateLongStrings ? Truncate(i.InputValue) : i.InputValue);
                    }
                    dr["ResponseId"] = fieldInput.ResponseId;
                    dt.Rows.Add(dr);
                }
            }

            return(dt);
        }