예제 #1
0
        protected void btnPreview_Click(object sender, EventArgs e)
        {
            DataValidation dv       = new DataValidation();
            string         sPath    = dv.CurrentDir(true);
            int            iQuoteID = Convert.ToInt32(Session["QuoteID"]);
            bool           bOEM     = lblOEM.Visible;
            bool           bOEMEmail;

            SaveQuote();

            // Make sure all required fields, including all item Submittal Notes, are entered.
            string sErrorMsg = q.SubmittalRequire(iQuoteID);

            lblErrorMsg.Text = sErrorMsg;
            if (sErrorMsg != "")
            {
                return;
            }

            if (q.CreatePDF(iQuoteID, false, bOEM, false, true, out bOEMEmail) == false)
            {
                return;
            }

            string sURL = q.QuotePDFUrl(iQuoteID, false, true);

            // Hard-coding to production since we don't seem to have access rights to QA.
            // **************************************************************************
            string sPathFull = "";

            if (Convert.ToBoolean(WebConfigurationManager.AppSettings["LocalMachine"]) == true)
            {
                sPathFull = WebConfigurationManager.AppSettings["LocalWebSiteUrl"] + sURL;
            }
            else
            {
                sPathFull = "https://MGMQuotation.MGMTransformer.com//MGMQuotation//pdfs//" + sURL;// +
            }
            // **************************************************************************

            // Open PDF in another browser.
            ResponseHelper.Redirect(sPathFull, "_blank", "");

            System.Diagnostics.Process.Start(sPathFull);
        }
예제 #2
0
        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("");
        }