I am not sure how do the loop to save my details see below bolded... Can someone help ? PulseSurveyQuestions BuildClass() is where i loop through to get all the datat to save and then it passes to the save method...
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
PulseSurveyQuestions PSQ = BuildClass();
PSQ.saveSurveyAnswers(surveyType, sentID );
clear();
}
}
public PulseSurveyQuestions BuildClass()
{
PulseSurveyQuestions psq = new PulseSurveyQuestions();
psq.User = _user;
psq.Login = _login;
psq.Location = _location;
psq.Roll = _roll;
psq.Sup = _sup;
psq.SurveyType = surveyType;
psq.State = ddlState.SelectedValue;
if (ddlCity.SelectedValue != "Other")
{
psq.City = ddlCity.SelectedValue;
}
else
{
psq.City = txtOther.Text;
}
//pulls the controls from the place holder
foreach (Control ctl in ph1.Controls)
{
//looks to see if the control is a label
if (ctl is Label)
{
// create a label to hold the label in the control
//in order to save the info.
Label lbl = (Label)ctl;
psq.Question = lbl.Text;
psq.QuestID = lbl.ID;
}
if (ctl is TextBox)
{
TextBox txt = (TextBox)ctl;
if (txt.ID == "txtRblOther")
{
psq.OtherAnswer = txt.Text;
}
else
{
psq.Answer = txt.Text ;
}
}
if (ctl is RadioButtonList)
{
RadioButtonList rbl = (RadioButtonList)ctl;
if (rbl.SelectedItem == null)
{
psq.Answer = null;
}
else{
psq.Answer = rbl.SelectedItem.Text;
}
}
if (ctl is RadComboBox)
{
RadComboBox ddl = (RadComboBox)ctl;
psq.Answer = ddl.SelectedItem.Text;
}
}
return psq;
}
public void saveSurveyAnswers(string surveyType, int sentID)
{
Charter.ReportingBase.Database db = new Charter.ReportingBase.Database("EDCCConnectString");
//StringBuilder sb = new StringBuilder();
try
{
db.AddParameter("@QuestID", -1);
db.AddParameter("@AgentName", _user);
db.AddParameter("@AgentLogin", _login);
db.AddParameter("@AgentLoc", _location);
db.AddParameter("@AgentRoll", _roll);
db.AddParameter("@AgentSup", _sup);
db.AddParameter("@DateAnswered", _questionAnswerDate);
db.AddParameter("@SentID", sentID);
db.AddParameter("@CustState", _state);
db.AddParameter("@CustCity", _city);
db.AddParameter("@SurveyType", _surveyType);
int _pulseSurveyQuesID = int.Parse(db.ExecuteScalar("PLSS_SavePLSSquestionsMaster", CommandType.StoredProcedure, Charter.ReportingBase.Database.DbConnectionState.CloseOnExit).ToString());
// loop through to save details
db.AddParameter("@ID", -1);
db.AddParameter("@pulseSurveyMasterID", _pulseSurveyQuesID);
string[] QID = _questID.Split('~');
db.AddParameter("@QuestID", QID);
db.AddParameter("@Answer", _answer);
db.AddParameter("@OtherAnswer", _otherAnswer);
int _pulseSurveyDetailID = int.Parse(db.ExecuteScalar("PLSS_SavePLSSquestionsDetails", CommandType.StoredProcedure, Charter.ReportingBase.Database.DbConnectionState.CloseOnExit).ToString());
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}