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 System.Data.SqlClient; using System.IO; using System.Net; using System.Net.Mail; namespace PS { public partial class AdminHome : System.Web.UI.Page { public SqlConnection cn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Bala\MyStuffs\system\PS\PS\App_Data\Database1.mdf;Integrated Security=True;User Instance=True"); protected void Page_Load(object sender, EventArgs e) { } protected void GridView1_SelectedIndexChanged(object sender, System.EventArgs e) { GridViewRow row = GridView1.SelectedRow; lblFeedbackNo.Text = row.Cells[1].Text; txtComment.Text = row.Cells[2].Text; Panel1.Visible = true; GridView1.Visible = false; } protected void btnSubmit_Click(object sender, EventArgs e) { string aTo = null; string aFrom = "ps_fyp@outlook.com"; string aSubject = "WPEHMS Reply Message"; string aMsg = "Dear Student," + Environment.NewLine + txtReply.Text + Environment.NewLine + Environment.NewLine + Environment.NewLine + "Regards, " + Environment.NewLine + "WPEHMS"; if (string.IsNullOrEmpty(txtReply.Text)) { lblValidation.Visible = true; } else { //------------------------------------------------------ Get email from database ------------------------------------------------------- SqlCommand cmd = new SqlCommand("SELECT fdk_Email From tblFeedback Where fdk_No ='" + lblFeedbackNo.Text + "'",cn); cn.Open(); aTo=(string)cmd.ExecuteScalar(); cn.Close(); //------------------------------------------------- Email service (hotmail) ------------------------------------------------------------- string mMailServer = "smtp.live.com"; //this is the name of mail server that email is sent to int mPort = 587; //port of mail server "use a value of 0 if none need be specified MailMessage message = new MailMessage(); message.From = new MailAddress(aFrom); message.Subject = aSubject; message.Body = aMsg; message.To.Add(aTo); message.IsBodyHtml = false; message.Priority = MailPriority.Normal; SmtpClient oSMTP = new SmtpClient(mMailServer, mPort); // creates instance of mail client var _with1 = oSMTP; _with1.EnableSsl = true; _with1.DeliveryMethod = SmtpDeliveryMethod.Network; _with1.Credentials = new NetworkCredential("ps_fyp@outlook.com", "Thepassword"); try { oSMTP.Send(message); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } // //------------------------------------------------ Store replied data into database ----------------------------------------------------- //string theStatus = "Replied"; SqlCommand cmd1 = new SqlCommand("UPDATE tblFeedback " + "SET staff_ID = '" + Session["idcode"] + "', fdk_Reply= '" + txtReply.Text + "' WHERE fdk_No = '" + lblFeedbackNo.Text + "'",cn); cn.Open(); cmd1.ExecuteNonQuery(); cn.Close(); System.Windows.Forms.MessageBox.Show("Reply Sent Successful"); Panel1.Visible = false; GridView1.DataBind(); GridView1.Visible = true; } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)