/// <summary> /// Logs that this user opened Rep Portal. /// </summary> /// <param name="sUserName"></param> protected void WriteToLog(string sUserName) { string sSql = "INSERT INTO LogUserActivity(UserName) " + Environment.NewLine + "VALUES ('" + sUserName + "')"; DataLinkCon dlc = DataLinkCon.mgmuser; DataLink.Update(sSql, dlc); }
/// <summary> /// Write a message to the error log: mgmuser.LogError /// </summary> /// <param name="sErrorMsg"></param> public static void Write(string sErrorMsg) { sErrorMsg = sErrorMsg.Replace("'", "''"); string sQuery = "INSERT INTO LogErrors(ErrorMsg) VALUES('" + sErrorMsg + "')"; DataLink.Update(sQuery, DataLinkCon.mgmuser); }
private string SendSQLMail(string sPDF, bool bNoPrice, bool bSubmittal) { using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["mgmdb"].ToString())) { SqlCommand cmd = new SqlCommand("usp_Email_Send_20190117", con); try { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@quote_id", QuoteId); cmd.Parameters.AddWithValue("@to_name", txtToName.Text.ToString()); cmd.Parameters.AddWithValue("@to_email", txtToEmail.Text.ToString()); cmd.Parameters.AddWithValue("@cc_name", txtCCName.Text.ToString()); cmd.Parameters.AddWithValue("@cc_email", txtCCEmail.Text.ToString()); cmd.Parameters.AddWithValue("@subj", txtSubject.Text.ToString()); cmd.Parameters.AddWithValue("@body_text", txtBody.Text.ToString()); cmd.Parameters.AddWithValue("@attach", sPDF); cmd.Parameters.AddWithValue("@send", 1); cmd.Parameters.AddWithValue("@is_no_price", bNoPrice); cmd.Parameters.AddWithValue("@is_submittal", bSubmittal); con.Open(); int numrows = cmd.ExecuteNonQuery(); } catch (SqlException ex) { DataLink.Update("insert into EMailPendingLog (Attempts,DateTimeAdded,DateTimeVerified,EmailTypeCode,ErrorText,QuoteEmailID,[Status],UserEmail,UserName) values (" + "1,GetDate(),null,'Email Screen','" + ex.Message + "',-1,',0,'" + HttpContext.Current.Session["Email"].ToString() + "','" + HttpContext.Current.Session["UserName"].ToString() + "')", DataLinkCon.mgmuser); return("Failed to create log entry."); } finally { cmd.Dispose(); con.Close(); } DataLink.Update("insert into EMailPendingLog (Attempts,DateTimeAdded,DateTimeVerified,EmailTypeCode,ErrorText,QuoteEmailID,[Status],UserEmail,UserName) values (" + "1,GetDate(),GetDate(),'Email Screen',''," + Utility.GetQuoteEmailID(QuoteId) + ",1,'" + HttpContext.Current.Session["Email"].ToString() + "','" + HttpContext.Current.Session["UserName"] + "')", DataLinkCon.mgmuser); } return(""); }
protected string Save(bool bNoPrice) { bool bRetValue = false; bool bSubmittal = rblQuoteOrSubmittal.SelectedValue == "1" ? true : false; string sUserName = Session["UserName"].ToString(); string sUserEmail = Session["Email"].ToString(); bool bOEMSuccess = false; MailAddress from = null; QuoteId = Convert.ToInt32(Request.QueryString["QuoteID"]); Quotes q = new Quotes(); int iQuoteID = QuoteId; if (bSubmittal == true) { if (q.SubmittalValid(iQuoteID) == false) { return("Submittal not set up."); } } bool bSuccess = false; if (bNoPrice == true || bSubmittal == true) { bSuccess = q.CreatePDF(iQuoteID, bNoPrice, false, true, bSubmittal, out bOEMSuccess); // Don't continue if unsuccessful either in generating a PDF or Word document. if (!bSuccess || !bOEMSuccess) { return("Unable to create PDF."); } } string sPDF = GetPDFPath(bNoPrice, bSubmittal); if (Convert.ToBoolean(WebConfigurationManager.AppSettings["UseSQLMail"])) { SendSQLMail(sPDF, bNoPrice, bSubmittal); } if (Convert.ToBoolean(WebConfigurationManager.AppSettings["UseSMTPMail"])) { using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["mgmdb"].ToString())) { SqlCommand cmd = new SqlCommand("usp_Email_Send_20190117", con); try { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@quote_id", QuoteId); cmd.Parameters.AddWithValue("@to_name", txtToName.Text.ToString()); cmd.Parameters.AddWithValue("@to_email", txtToEmail.Text.ToString()); cmd.Parameters.AddWithValue("@cc_name", txtCCName.Text.ToString()); cmd.Parameters.AddWithValue("@cc_email", txtCCEmail.Text.ToString()); cmd.Parameters.AddWithValue("@subj", txtSubject.Text.ToString()); cmd.Parameters.AddWithValue("@body_text", txtBody.Text.ToString()); cmd.Parameters.AddWithValue("@attach", sPDF); cmd.Parameters.AddWithValue("@send", 0); cmd.Parameters.AddWithValue("@is_no_price", bNoPrice); cmd.Parameters.AddWithValue("@is_submittal", bSubmittal); con.Open(); int numrows = cmd.ExecuteNonQuery(); } catch (SqlException ex) { System.Console.WriteLine("Exception: " + ex.ToString()); return("Unable to send email."); } finally { bRetValue = true; cmd.Dispose(); con.Close(); } if (bRetValue) { try { if (!Convert.ToBoolean(WebConfigurationManager.AppSettings["UpdateEmailTablesOnly"])) { SmtpClient client = new SmtpClient(WebConfigurationManager.AppSettings["ExchangeServerIPAddress"]); client.UseDefaultCredentials = true; MailAddress to = new MailAddress(Session["Email"].ToString(), Session["RepName"].ToString(), System.Text.Encoding.UTF8); if (Session["Internal"].ToString() == "1") { from = new MailAddress(Session["Email"].ToString(), "MGM Quote System", System.Text.Encoding.UTF8); } else { from = new MailAddress("*****@*****.**", "MGM Quote System", System.Text.Encoding.UTF8); } MailMessage message = new MailMessage(from, to); message.Body = txtBody.Text.ToString(); message.BodyEncoding = System.Text.Encoding.UTF8; message.Subject = txtSubject.Text.ToString(); message.SubjectEncoding = System.Text.Encoding.UTF8; if (string.IsNullOrWhiteSpace(sPDF) == false) { message.Attachments.Add(new Attachment(sPDF)); } foreach (string sEmail in txtCCEmail.Text.Split(';')) { if (Utility.IsValidEmail(sEmail)) { message.CC.Add(sEmail); } } if (Utility.IsValidEmail(txtToEmail.Text.ToString())) { message.CC.Add(txtToEmail.Text.ToString()); } client.Send(message); message.Dispose(); } DataLink.Update("insert into EMailPendingLog (Attempts,DateTimeAdded,DateTimeVerified,EmailTypeCode,ErrorText,QuoteEmailID,[Status],UserEmail,UserName) values (" + "1,GetDate(),GetDate(),'Email Screen',''," + Utility.GetQuoteEmailID(QuoteId) + ",1,'" + HttpContext.Current.Session["Email"].ToString() + "','" + HttpContext.Current.Session["UserName"] + "')", DataLinkCon.mgmuser); } catch (Exception ex) { DataLink.Update("insert into EMailPendingLog (Attempts,DateTimeAdded,DateTimeVerified,EmailTypeCode,ErrorText,QuoteEmailID,[Status],UserEmail,UserName) values (" + "1,GetDate(),null,'Email Screen','" + ex.Message + "',-1,',0,'" + HttpContext.Current.Session["Email"].ToString() + "','" + HttpContext.Current.Session["UserName"].ToString() + "')", DataLinkCon.mgmuser); return(ex.Message + Environment.NewLine + "Failed to create log entry."); } } } } return(""); }