public ActionResult Survey(FormCollection frm) { SurveyBL _surBL = new SurveyBL(); decimal surveyId = 1; // Make sure you get the Survey Id from the table or session List <SurveyQuestionModel> lstQuestions = _surBL.getQuestions(surveyId); List <SurveyTakenModel> lst = new List <SurveyTakenModel>(); var starsId = Session["StarsIdProfile"].ToString(); var pacode = Session["w_pacode"].ToString(); var wslx = Session["w_user"].ToString(); for (int i = 0; i <= frm.Count - 1; i++) { string type = ""; //string test1 = frm.GetValue(Convert.ToString(frm[i])).AttemptedValue; // string[] arr1 = frm.GetValues(i); foreach (var item in lstQuestions) { if (item.QUESTION_ID == Convert.ToDecimal(frm.GetKey(i))) { type = item.QUESTION_TYPE; break; } } if (type == "FI") { string[] arr = frm.GetValue(Convert.ToString(frm.GetKey(i))).AttemptedValue.Split(','); lst.Add(new SurveyTakenModel() { STARS_ID = starsId, SURVEY_ID = surveyId, QUESTION_ID = Convert.ToDecimal(frm.GetKey(i).ToString()), ANSWER_ID = 1, ANSWER_MSG = arr[0].ToString(), CREATED_BY = wslx }); } else if (type == "MS") { string[] arr = frm.GetValue(Convert.ToString(frm.GetKey(i))).AttemptedValue.Split(','); if (arr.Count() > 0) { for (int j = 0; j <= arr.Count() - 1; j = j + 2) { lst.Add(new SurveyTakenModel() { STARS_ID = starsId, SURVEY_ID = surveyId, QUESTION_ID = Convert.ToDecimal(arr[j].ToString()), ANSWER_ID = Convert.ToDecimal(arr[j + 1].ToString()), ANSWER_MSG = string.Empty, CREATED_BY = wslx }); } } } else { string[] arr = frm.GetValue(Convert.ToString(frm.GetKey(i))).AttemptedValue.Split(','); lst.Add(new SurveyTakenModel() { STARS_ID = starsId, SURVEY_ID = surveyId, QUESTION_ID = Convert.ToDecimal(arr[0].ToString()), ANSWER_ID = Convert.ToDecimal(arr[1].ToString()), ANSWER_MSG = string.Empty, CREATED_BY = wslx }); } } SurveyCompledModel _surveyModel = new SurveyCompledModel(); _surveyModel.COMPLETED_DATE = DateTime.Now; _surveyModel.PA_CODE = pacode; _surveyModel.STARS_ID = starsId; _surveyModel.SURVEY_ID = surveyId; _surveyModel.CREATED_DATE = DateTime.Now; _surveyModel.CREATED_BY = wslx; if (_surBL.SaveSurvey(lst, _surveyModel)) { return(RedirectToAction("Confirmation", "Resources")); } return(RedirectToAction("Survey", "Resources")); //return RedirectToAction("Welcome", "LBC"); }
private void BindDetails() { string clientID = string.Empty; clientID = new SurveyBL().GetPortalClientId().ToString(); DataSet objDataSet = new SurveyBL().SurveyDisplay(clientID, Convert.ToDateTime(lblfirstdate.Text), Convert.ToDateTime(lblLastDate.Text)); PlaceSurveyQuestions.Controls.Clear(); for (int i = 0; i < objDataSet.Tables[1].Rows.Count; i++) { HtmlGenericControl Div = new HtmlGenericControl("DIV"); Div.ID = "Survey_" + i; Div.Attributes.Add("class", "testMain"); HtmlGenericControl createDiv = new HtmlGenericControl("DIV"); int QID = Convert.ToInt32(objDataSet.Tables[1].Rows[i]["QID"].ToString()); createDiv.ID = "Q" + QID; createDiv.Attributes.Add("class", "Question_heading"); createDiv.InnerHtml = "<strong>" + objDataSet.Tables[1].Rows[i]["QText"].ToString() + "</strong>"; HtmlGenericControl answersDiv = new HtmlGenericControl("DIV"); answersDiv.ID = "A" + objDataSet.Tables[1].Rows[i]["QID"].ToString(); answersDiv.Attributes.Add("class", "Answer"); answersDiv.InnerHtml = "Answered : " + objDataSet.Tables[1].Rows[i]["Answered"].ToString() + " Skipped : " + objDataSet.Tables[1].Rows[i]["Skipped"].ToString(); if (objDataSet.Tables[1].Rows[i]["QTypeID"].ToString() != "5" && objDataSet.Tables[1].Rows[i]["QTypeID"].ToString() != "4") { Div.Controls.Add(createDiv); Div.Controls.Add(answersDiv); if (objDataSet.Tables[2].Rows.Count > 0) { DataTable tblFiltered = objDataSet.Tables[2].AsEnumerable() .Where(r => r.Field <int>("QID") == QID) .CopyToDataTable(); int val; var maxVal = tblFiltered.AsEnumerable() .Where(rw => int.TryParse(rw["value"].ToString(), out val)) .Select(rw => Convert.ToInt32(rw["value"])).Max(); if (tblFiltered.Rows.Count > 0) { HtmlGenericControl DIVBar = new HtmlGenericControl("DIVBar"); decimal sum = Convert.ToDecimal(tblFiltered.Compute("SUM(vcounts)", string.Empty)); decimal WeightedAvg; try { WeightedAvg = (sum / Convert.ToDecimal(tblFiltered.Rows[0]["Total"])); } catch { WeightedAvg = 0; } DataTable dtCount = new DataTable(); dtCount.Columns.Add("Count", typeof(decimal)); dtCount.Rows.Add(string.Format("{0:0.00}", WeightedAvg)); RadHtmlChart objBarChart = new RadHtmlChart(); objBarChart.ID = "rdAnsweredCount" + QID; objBarChart.Height = Unit.Pixel(100); BarSeries objBarSeries = new BarSeries(); objBarSeries.Stacked = false; objBarSeries.DataFieldY = "Count"; objBarSeries.LabelsAppearance.Visible = true; objBarChart.Appearance.FillStyle.BackgroundColor = System.Drawing.Color.White; objBarChart.Legend.Appearance.Visible = false; objBarChart.PlotArea.YAxis.MaxValue = maxVal; objBarChart.PlotArea.XAxis.MinorGridLines.Visible = false; objBarChart.PlotArea.XAxis.MajorGridLines.Visible = false; objBarChart.PlotArea.XAxis.MajorTickType = Telerik.Web.UI.HtmlChart.TickType.None; objBarChart.PlotArea.XAxis.MinorTickType = Telerik.Web.UI.HtmlChart.TickType.Outside; objBarChart.PlotArea.XAxis.Reversed = true; objBarChart.PlotArea.YAxis.Step = 1; objBarChart.PlotArea.YAxis.TitleAppearance.Text = string.Empty; objBarChart.PlotArea.YAxis.MinorGridLines.Visible = false; objBarChart.PlotArea.YAxis.MajorGridLines.Visible = false; objBarChart.PlotArea.YAxis.Reversed = false; objBarChart.PlotArea.Series.Add(objBarSeries); objBarChart.DataSource = dtCount; objBarChart.DataBind(); DIVBar.Controls.Add(objBarChart); Div.Controls.Add(DIVBar); HtmlTable htTable = new HtmlTable(); htTable.Align = "center"; htTable.Border = 0; htTable.Width = "80%"; htTable.CellPadding = 0; htTable.CellSpacing = 0; HtmlTableRow htRow = new HtmlTableRow(); for (int h = 0; h < tblFiltered.Rows.Count; h++) { HtmlTableCell htCell = new HtmlTableCell(); Literal lt = new Literal(); lt.ID = QID + "_" + h; lt.Text = "<div class='Tbheader'>" + tblFiltered.Rows[h]["answertext"].ToString() + "</div><div class='Tbheader1'>" + tblFiltered.Rows[h]["value"].ToString() + "</div>" + "<div class='Tbcell'>" + tblFiltered.Rows[h]["Percentage"].ToString() + " % <br>" + tblFiltered.Rows[h]["Answercounts"].ToString() + "</div>"; htCell.Controls.Add(lt); htRow.Cells.Add(htCell); } HtmlTableCell htTotal = new HtmlTableCell(); Literal ltTotal = new Literal(); ltTotal.ID = QID + "_Total"; ltTotal.Text = "<div class='Tbheader'>Total</div><div class='Tbheader1'> " + "</div>" + "<div class='Tbcell'>" + tblFiltered.Rows[0]["Total"] + "<br> </div>"; htTotal.Controls.Add(ltTotal); htRow.Cells.Add(htTotal); HtmlTableCell htWeight = new HtmlTableCell(); Literal ltWeight = new Literal(); ltWeight.ID = QID + "_Weight"; ltWeight.Text = "<div class='Tbheader'>Weighted Averages</div><div class='Tbheader1'> " + "</div>" + "<div class='Tbcell'>" + string.Format("{0:0.00}", WeightedAvg) + "<br> </div>"; htWeight.Controls.Add(ltWeight); htRow.Cells.Add(htWeight); htTable.Rows.Add(htRow); Div.Controls.Add(htTable); } } } else { Div.Controls.Add(createDiv); Div.Controls.Add(answersDiv); if (objDataSet.Tables[3].Rows.Count > 0) { DataTable tblFiltered = objDataSet.Tables[3].AsEnumerable() .Where(r => r.Field <int>("QID") == QID) .CopyToDataTable(); //HtmlGenericControl divAN = new HtmlGenericControl("DIVAN"); // divAN.Attributes.Add("class", "Pcontent"); HtmlTable htTable = new HtmlTable(); htTable.Attributes.Add("class", "Pcontent"); htTable.Align = "center"; htTable.Border = 0; htTable.Width = "80%"; htTable.CellPadding = 0; htTable.CellSpacing = 0; //HtmlGenericControl div = new HtmlGenericControl(); //div.Attributes.Add("class", "listitem"); for (int j = 0; j < tblFiltered.Rows.Count; j++) { HtmlTableRow htRow = new HtmlTableRow(); HtmlTableCell htCell = new HtmlTableCell(); Literal ltAnswers = new Literal(); ltAnswers.ID = QID + "_" + j; ltAnswers.Text = "<div class='Tbcell1'>" + tblFiltered.Rows[j]["Response"].ToString() + "</br>" + tblFiltered.Rows[j]["Name"].ToString() + " " + tblFiltered.Rows[j]["CreatedDate"].ToString() + "</div>"; htCell.Controls.Add(ltAnswers); htRow.Controls.Add(htCell); htTable.Controls.Add(htRow); //div.Controls.Add(div1); } // divAN.Controls.Add(htTable); Div.Controls.Add(htTable); } } PlaceSurveyQuestions.Controls.Add(Div); } }
// GET api/<controller>/5 public Survey Get(int id) { return(SurveyBL.GetById(id)); }
public void GenerateReport() { DateTime firstDate = Convert.ToDateTime(lblfirstdate.Text); DateTime lastDate = Convert.ToDateTime(lblLastDate.Text); DataSet objResponse = new SurveyBL().SurveyDetails(firstDate.ToShortDateString(), lastDate.ToShortDateString(), hdnClientId.Value); DataTable dtSurvey = new DataTable(); dtSurvey.Columns.Add("Id", typeof(string)); dtSurvey.Columns.Add("AId", typeof(string)); dtSurvey.Columns.Add("Name", typeof(string)); dtSurvey.Columns.Add("From", typeof(string)); dtSurvey.Columns.Add("Golive", typeof(string)); for (int i = 0; i < objResponse.Tables[0].Rows.Count; i++) { dtSurvey.Rows.Add(-1, -1, "<strong>" + objResponse.Tables[0].Rows[i]["Name"].ToString() + "</strong>", "<strong>" + objResponse.Tables[0].Rows[i]["RatingFrom"].ToString() + "</strong>", "<strong>" + objResponse.Tables[0].Rows[i]["RatingGolive"].ToString() + "</strong>"); } DataTable dtSurveyCounts = new DataTable(); dtSurveyCounts.Columns.Add("Qid", typeof(string)); dtSurveyCounts.Columns.Add("QText", typeof(string)); dtSurveyCounts.Columns.Add("AnswerID", typeof(string)); dtSurveyCounts.Columns.Add("AText", typeof(string)); dtSurveyCounts.Columns.Add("FP", typeof(string)); dtSurveyCounts.Columns.Add("GP", typeof(string)); for (int k = 0; k < objResponse.Tables[2].Rows.Count; k++) { if (objResponse.Tables[1].Rows[k]["qid"].ToString() == objResponse.Tables[2].Rows[k]["qid"].ToString()) { dtSurveyCounts.Rows.Add(objResponse.Tables[1].Rows[k]["qid"].ToString(), objResponse.Tables[1].Rows[k]["Qtext"].ToString(), objResponse.Tables[1].Rows[k]["AnswerID"].ToString(), objResponse.Tables[1].Rows[k]["answertext"].ToString(), objResponse.Tables[1].Rows[k]["Percentage"].ToString(), objResponse.Tables[2].Rows[k]["Percentage"].ToString()); } } for (int j = 0; j < dtSurveyCounts.Rows.Count; j++) { string Qid = dtSurveyCounts.Rows[j]["Qid"].ToString(); bool Qidexists = dtSurvey.Select().ToList().Exists(row => row["Id"].ToString() == Qid); string qtext = "Q" + Qid + ". " + dtSurveyCounts.Rows[j]["QText"].ToString(); bool qtextexists = dtSurvey.Select().ToList().Exists(row => row["Name"].ToString() == qtext); if (!Qidexists && !qtextexists) { dtSurvey.Rows.Add(Qid, 0, "<strong>" + qtext + "</strong>", string.Empty, string.Empty); dtSurvey.Rows.Add(Qid, dtSurveyCounts.Rows[j]["AnswerID"].ToString(), dtSurveyCounts.Rows[j]["AText"].ToString(), dtSurveyCounts.Rows[j]["FP"].ToString() + "%", dtSurveyCounts.Rows[j]["GP"].ToString() + "%"); } else { bool Qidexists1 = dtSurvey.Select().ToList().Exists(row => row["Id"].ToString() == dtSurveyCounts.Rows[j]["Qid"].ToString()); bool Aidexists1 = dtSurvey.Select().ToList().Exists(row => row["AId"].ToString() == dtSurveyCounts.Rows[j]["AnswerID"].ToString()); if (Qidexists1 && !Aidexists1) { dtSurvey.Rows.Add(Qid, dtSurveyCounts.Rows[j]["AnswerID"].ToString(), dtSurveyCounts.Rows[j]["AText"].ToString(), dtSurveyCounts.Rows[j]["FP"].ToString() + "%", dtSurveyCounts.Rows[j]["GP"].ToString() + "%"); } } } gvResponses.DataSource = dtSurvey; gvResponses.DataBind(); FileInfo rptFileName = new FileInfo(Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["Reports"].ToString()) + @"Survey details_" + firstDate.ToString("MM/dd/yyyy").Replace("/", "-").Replace(":", "-") + ".xls"); // If any file exists in this directory having name 'Sample1.xlsx', then delete it if (rptFileName.Exists) { rptFileName.Delete(); // ensures we create a new workbook rptFileName = new FileInfo(Server.MapPath(System.Configuration.ConfigurationManager.AppSettings["Reports"].ToString()) + @"\Survey details from_" + firstDate.ToString("MM/dd/yyyy").Replace("/", "-").Replace(":", "-") + ".xls"); } // this.DeleteHistoricFiles(); ExcelSheetGenerator objExcel = new ExcelSheetGenerator(); objExcel.GenerateReport(dtSurvey, rptFileName, "Surveydetails", "UserName"); Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + " Survey details Report From -" + firstDate.ToString("MM/dd/yyyy").Replace("/", "-").Replace(":", "-") + " " + lastDate.ToString("MM/dd/yyyy").Replace("/", "-").Replace(":", "-") + "" + ".xlsx"); Response.TransmitFile(rptFileName.ToString()); Response.End(); }
// GET api/<controller> public List <Survey> Get() { return(SurveyBL.GetAll()); }
public HttpResponseMessage RemoveSurvey(SekerCotert survey) { SurveyBL.RemoveSurvey(survey); return(Request.CreateResponse(HttpStatusCode.OK, true)); }
public HttpResponseMessage UpdateCountAnswer(SekerPerut survey) { SurveyBL.UpdateCountAnswer(survey); return(Request.CreateResponse(HttpStatusCode.OK, true)); }
public HttpResponseMessage ChangeStatus(SekerCotert survey) { SurveyBL.ChangeStatus(survey); return(Request.CreateResponse(HttpStatusCode.OK, true)); }
public HttpResponseMessage GetAllSurvey(int buildingId) { List <SekerCotert> surveys = SurveyBL.GetSurveyByBuildingId(buildingId); return(Request.CreateResponse(HttpStatusCode.OK, surveys)); }