using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using DataOper;

public partial class app_feedback : System.Web.UI.Page
{
    DataOperation dOper = new DataOperation();
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (rdoAns1.SelectedValue == "")
        {
            rdoAns1.Focus();
            return;
        }
        if (rdoAns2.SelectedValue == "")
        {
            rdoAns2.Focus();
            return;
        }
        if (txtAns3.Text.Trim() == "")
        {
            txtAns3.Focus();
            return;
        }
        if (txtAns4.Text.Trim() == "")
        {
            txtAns4.Focus();
            return;
        }
        if (txtAns5.Text.Trim() == "")
        {
            txtAns5.Focus();
            return;
        }
        if (rdoAns6.SelectedValue == "")
        {
            rdoAns6.Focus();
            return;
        }
        if (rdoAns6.SelectedValue == "Other" && txtAns6_Other.Text.Trim() == "")
        {
            txtAns6_Other.Focus();
            return;
        }
        if (txtName.Text.Trim() == "")
        {
            txtName.Focus();
            return;
        }
        if (txtDesignation.Text.Trim() == "")
        {
            txtDesignation.Focus();
            return;
        }
        if (txtOrganisation.Text.Trim() == "")
        {
            txtOrganisation.Focus();
            return;
        }
        if (txtMobile.Text.Trim() == "")
        {
            txtMobile.Focus();
            return;
        }
        if (txtMobile.Text.Trim().Length != 10)
        {
            txtMobile.Focus();
            return;
        }
        if (txtEmail.Text.Trim() == "")
        {
            txtEmail.Focus();
            return;
        }

        string feedback_id = "F" + System.DateTime.Now.ToString("yyMMddHHmmssfffff") + txtName.Text.Substring(0, 1).ToUpper();
        dOper.sqlExec("insert into app_feedback(feedback_id,feedback_date,name,designation,organisation,mobile,email)values('" + feedback_id + "','" + System.DateTime.Now.ToString("dd-MMM-yyyy HH:mm:ss") + "','" + txtName.Text.Replace("'", "`").Trim() + "','" + txtDesignation.Text.Replace("'", "`").Trim() + "','" + txtOrganisation.Text.Replace("'", "`").Trim() + "','" + txtMobile.Text.Replace("'", "`").Trim() + "','" + txtEmail.Text.Replace("'", "`").Trim() + "')");
        
        //Question
        dOper.sqlExec("insert into app_feedback_ques(feedback_id,question,answer)values('" + feedback_id + "','" + lblQues1.Text.Replace("'", "`").Trim() + "','" + rdoAns1.SelectedValue.Replace("'", "`").Trim() + "')");
        dOper.sqlExec("insert into app_feedback_ques(feedback_id,question,answer)values('" + feedback_id + "','" + lblQues2.Text.Replace("'", "`").Trim() + "','" + rdoAns2.SelectedValue.Replace("'", "`").Trim() + "')");
        dOper.sqlExec("insert into app_feedback_ques(feedback_id,question,answer)values('" + feedback_id + "','" + lblQues3.Text.Replace("'", "`").Trim() + "','" + txtAns3.Text.Replace("'", "`").Trim() + "')");
        dOper.sqlExec("insert into app_feedback_ques(feedback_id,question,answer)values('" + feedback_id + "','" + lblQues4.Text.Replace("'", "`").Trim() + "','" + txtAns4.Text.Replace("'", "`").Trim() + "')");
        dOper.sqlExec("insert into app_feedback_ques(feedback_id,question,answer)values('" + feedback_id + "','" + lblQues5.Text.Replace("'", "`").Trim() + "','" + txtAns5.Text.Replace("'", "`").Trim() + "')");
        dOper.sqlExec("insert into app_feedback_ques(feedback_id,question,answer)values('" + feedback_id + "','" + lblQues6.Text.Replace("'", "`").Trim() + "','" + rdoAns6.SelectedValue.Replace("Other", "").Trim() + txtAns6_Other.Text.Replace("'", "`").Trim() + "')");

        Response.Redirect("thankyou.html");
    }
    protected void rdoAns6_SelectedIndexChanged(object sender, EventArgs e)
    {
        txtAns6_Other.Enabled = false;
        txtAns6_Other.Text = "";
        if (rdoAns6.SelectedValue == "Other")
        {
            txtAns6_Other.Enabled = true;
            txtAns6_Other.Focus();
            return;
        }

        rdoAns6.Focus();
    }
}