using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net;
using System.Net.Mail;
using System.Drawing;
using System.Text;
using System.Data.SqlClient;

public partial class Query : System.Web.UI.Page
{
    string MobileNumber;
    string Registeredname;
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (Session["LOGINID"].Equals(null))
            {
                Response.Redirect("../login.aspx");
            }
        }
        catch (Exception ex)
        {
            throw (ex);
        }  
    }
    protected void BtnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            Getmobilenumber();
            sendmail();
        }
        catch (Exception ex)
        {
            throw (ex);
        }  
    }
    private void Getmobilenumber()
    {
        SqlParameter[] get_user_details = new SqlParameter[]
        {
            new SqlParameter("@LoginID",Session["Loginid"].ToString()), 
        };
        SqlDataReader dr = SqlHelper.ExecuteReader(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "UDP_USERDETAILS", get_user_details);
        if (dr.Read())
        {
           MobileNumber = Convert.ToString(dr["MobileNo"]);
           Registeredname= Convert.ToString(dr["firstname"]);
        }
        dr.Close();
    }
    private void sendmail()
    {
        try
        {
            MailMessage message = new MailMessage();
            message.Body = mailmsgmobile();
            message.IsBodyHtml = true;
            message.To.Add(Session["helpdeskemailid"].ToString());
            message.Bcc.Add("Sachin.egen@gmail.com");
            //message.To.Add("mkg.egen@gmail.com");
            //message.Bcc.Add("neeraj.egen@gmail.com");
            message.From = new System.Net.Mail.MailAddress("enquiry@egenservices.com");
            message.Subject = Session["CompanyName"] + "Partner Query";
            message.Priority = MailPriority.High;
            SmtpClient SmtpMail = new SmtpClient();
            {
                SmtpMail.Host = "smtp.gmail.com";
                SmtpMail.Port = 587;
                SmtpMail.EnableSsl = true;
                SmtpMail.UseDefaultCredentials = true;
                SmtpMail.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                SmtpMail.Credentials = new System.Net.NetworkCredential("venusutilityservices@gmail.com", "Bikash@123");
                SmtpMail.Send(message);
            }
            message = null;
            DDLTypQuery.SelectedIndex = 0;
            ddlServiceName.SelectedIndex = 0;
            txtTranID.Text = "";
            LstBoxQuryDescription.Text = "";
            lblerror.Text = "Your query has been submitted sucessfully. You will get response on your registered e-mail id within 24 hours.";
            lblerror.ForeColor = Color.Blue;
        }
        catch (Exception ex)
        {
            lblerror.Text = "Send Email Failed.<br>" + ex.Message;
            lblerror.ForeColor = Color.Red;
        }
    }
    private string mailmsgmobile()
    {
        StringBuilder strHTML = new StringBuilder();
        strHTML.Append("<table width=70% style='font-family:Trebuchet MS'>");
        strHTML.Append("<tr><td width=100%>" + Session["CompanyName"] + ", Partner Query.</td></tr>");
        strHTML.Append("<tr><td width=20% align=left>Service Name</b></td><td width=70% align=left>" + ddlServiceName.SelectedItem.Text.Trim() + "</td></tr>");
        strHTML.Append("<tr><td width=20% align=left>Date</b></td><td width=70% align=left>" + DateTime.Now + "</td></tr>");
        strHTML.Append("<tr><td width=20% align=left>User Id</b></td><td width=70% align=left>" + Session["USERNAME"].ToString() + "</td></tr>");
        strHTML.Append("<tr><td width=20% align=left>User Name</b></td><td width=70% align=left>" +Registeredname.ToString() + "</td></tr>");
        strHTML.Append("<tr><td width=20% align=left>User Mobile Number</b></td><td width=70% align=left>" + MobileNumber.ToString() + "</td></tr>");
        strHTML.Append("<tr><td width=20% align=left>Email Id</b></td><td width=70% align=left>" + Session["EMAILID"].ToString() + "</td></tr>");
        strHTML.Append("<tr><td width=20% align=left>Problem In</b></td><td width=70% align=left>" + DDLTypQuery.SelectedItem.Text.Trim() + "</td></tr>");
        strHTML.Append("<tr><td width=20% align=left>Transaction ID</b></td><td width=70% align=left>" + txtTranID.Text.Trim() + "</td></tr>");
        strHTML.Append("<tr><td width=20% align=left>Query Description</b></td><td width=70% align=left>" + LstBoxQuryDescription.Text.Trim() + "</td></tr>");
        strHTML.Append("</table>");
        return strHTML.ToString();
    }
}
