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 registration : System.Web.UI.Page
{
    DataOperation dOper = new DataOperation();
    double amount = 0;
    string bookingType = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            PopNoofPersion();
            PopEmptyGrid();
            PopAmount();
        }
    }
    public void PopNoofPersion()
    {
        for (int i = 1; i <= 50; i++)
        {
           
            ddlPerson.Items.Add(new ListItem(i.ToString(), i.ToString()));
            //ddlPerson.SelectedValue = "5";
        }
    }

    public void PopEmptyGrid()
    {
        DataTable dt = dOper.return_dt("select * from tbl_empty_grid where sln <='" + ddlPerson.SelectedValue + "' order by sln");
        rpParticipant.DataSource = dt;
        rpParticipant.DataBind();
    }

    protected void ddlPerson_SelectedIndexChanged(object sender, EventArgs e)
    {
        PopEmptyGrid();
        PopAmount();
    }
   
    public void btnSumit_Click(object sender, EventArgs e)
    {
        if(ddlPerson.SelectedValue == "0")
        {
            litMsg.Text = "Please select a valid no. of person!";
            ddlPerson.Focus();
            return;
        }
        PopAmount();

        foreach (RepeaterItem ri in rpParticipant.Items)
        {
            HiddenField hdfchecked = (HiddenField)ri.FindControl("hdfchecked");
            TextBox rptxtName = (TextBox)ri.FindControl("rptxtName");
            TextBox rptxtDesignation = (TextBox)ri.FindControl("rptxtDesignation");
            TextBox rptxtEmail = (TextBox)ri.FindControl("rptxtEmail");
            TextBox rptxtMobile = (TextBox)ri.FindControl("rptxtMobile");
            
            if (rptxtName.Text.Trim() == "")
            {
                litMsg.Text = "Name is Mandatroy!";
                rptxtName.Focus();
                return;
            }
            if (rptxtDesignation.Text.Trim() == "")
            {
                litMsg.Text = "Designation is Mandatroy!";
                rptxtDesignation.Focus();
                return;
            }
            if (rptxtEmail.Text.Trim() == "")
            {
                litMsg.Text = "Email is Mandatroy!";
                rptxtEmail.Focus();
                return;
            }
            if (rptxtMobile.Text.Trim() == "")
            {
                litMsg.Text = "Mobile No. is Mandatroy!";
                rptxtMobile.Focus();
                return;
            }
        }

        if(txtFirstName.Text.Trim() == "")
        {
            litMsg.Text = "First name is Mandatroy!";
            txtFirstName.Focus();
            return;
        }
        if (txtLastName.Text.Trim() == "")
        {
            litMsg.Text = "Last name is Mandatroy!";
            txtLastName.Focus();
            return;
        }
        if (txtDesignation.Text.Trim() == "")
        {
            litMsg.Text = "Designation is Mandatroy!";
            txtDesignation.Focus();
            return;
        }
        if (txtMobile.Text.Trim() == "")
        {
            litMsg.Text = "Mobile is Mandatroy!";
            txtMobile.Focus();
            return;
        }
        if (txtEmail.Text.Trim() == "")
        {
            litMsg.Text = "Email is Mandatroy!";
            txtEmail.Focus();
            return;
        }
        if (txtOrganization.Text.Trim() == "")
        {
            litMsg.Text = "Organization is Mandatroy!";
            txtOrganization.Focus();
            return;
        }
        if (txtGst.Text.Trim() == "")
        {
            litMsg.Text = "GST No. is Mandatroy!";
            txtGst.Focus();
            return;
        }
        if (txtpanNo.Text.Trim() == "")
        {
            litMsg.Text = "PAN No. is Mandatroy!";
            txtpanNo.Focus();
            return;
        }

        string MemberID = System.DateTime.Now.ToString("yyyyMMddHHmmssffffff");
        foreach (RepeaterItem ri in rpParticipant.Items)
        {
            TextBox rptxtName = (TextBox)ri.FindControl("rptxtName");
            TextBox rptxtDesignation = (TextBox)ri.FindControl("rptxtDesignation");
            TextBox rptxtEmail = (TextBox)ri.FindControl("rptxtEmail");
            TextBox rptxtMobile = (TextBox)ri.FindControl("rptxtMobile");
            if (rptxtName.Text.Trim() != "" && rptxtDesignation.Text.Trim() != "" && rptxtEmail.Text.Trim() != "" && rptxtEmail.Text.Trim() != "" && rptxtMobile.Text.Trim() != "")
            {
                dOper.sqlExec("insert into tbl_reg_participant_person(Member_id,name,designation,email,mobile,action_on) values('" + MemberID + "','" + rptxtName.Text.Replace("'", "`").Trim() + "','" + rptxtDesignation.Text.Replace("'", "`").Trim() + "','" + rptxtEmail.Text.Replace("'", "`").Trim() + "','" + rptxtMobile.Text.Replace("'", "`").Trim() + "','" + System.DateTime.Now.ToString("dd-MMM-yyyy HH:mm:ss") + "')");
            }
        }
        dOper.sqlExec("insert into tbl_registration_form(Member_id,memberType,booking_type,booking_amt,person_no,first_name,last_name,designation,mobile,email,organization,gst_no,pan_no,action_on)values('" + MemberID + "','','','" + lblTotalRegFee.Text + "','" + ddlPerson.SelectedValue + "','" + txtFirstName.Text.Replace("'", "`").Trim() + "','" + txtLastName.Text.Replace("'", "`").Trim() + "','" + txtDesignation.Text.Replace("'", "`").Trim() + "','" + txtMobile.Text.Replace("'", "`").Trim() + "','" + txtEmail.Text.Replace("'", "`").Trim() + "','" + txtOrganization.Text.Replace("'", "`").Trim() + "','" + txtGst.Text.Replace("'", "`").Trim() + "','" + txtpanNo.Text.Replace("'", "`").Trim() + "','" + System.DateTime.Now.ToString("dd-MMM-yyyy HH:mm:ss") + "')");
        litMsg.Text = "Submitted successfully!";
    }
    public void PopAmount()
    {
        double total_amt = 0;
        int total_person = Convert.ToInt16(ddlPerson.SelectedValue);
        if (total_person <= 5)
        {
            total_amt = total_amt + (2000 * total_person);
        }
        else if (total_person <= 10)
        {
            total_amt = total_amt + (2000 * 5);
            total_amt = total_amt + (1500 * (total_person - 5));
        }
        else if (total_person > 10)
        {
            total_amt = total_amt + (2000 * 5);
            total_amt = total_amt + (1500 * 5);
            total_amt = total_amt + (1000 * (total_person - 10));
        }
        
        lblTotalRegFee.Text= total_amt.ToString("0.00");
    }
   
   
}