/// <summary> /// Send email to the current client to confirm the items in the current order, and the deliver date /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnConfirmOrder_Click(object sender, EventArgs e) { DropDownList _ddlThisContact = (DropDownList)dvOrderHeader.FindControl("ddlContacts"); ContactDetails.ContactEmailDetails _thisContact = GetContactsEmailDetails(_ddlThisContact.SelectedItem.Value); if (_thisContact != null) { EmailCls _email = new EmailCls(); DropDownList _ddlDeliveryBy = (DropDownList)dvOrderHeader.FindControl("ddlToBeDeliveredBy"); // who is delivering this Label _lblDeliveryDate = (Label)dvOrderHeader.FindControl("lblRequiredByDate"); // date it will be dispatched / delivered" if (_thisContact.EmailAddress != "") { _email.SetEmailFromTo(CONST_FROMEMAIL, _thisContact.EmailAddress); if (_thisContact.altEmailAddress != "") { _email.SetEmailCC(_thisContact.altEmailAddress); } } else if (_thisContact.altEmailAddress != "") { _email.SetEmailFromTo(CONST_FROMEMAIL, _thisContact.altEmailAddress); } else { return; // no email address so quit } // send a BCC to orders to confirm _email.SetEmailBCC(CONST_FROMEMAIL); // set subject and body _email.SetEmailSubject("Order Confirmation"); _email.AddStrAndNewLineToBody("Dear " + ((_thisContact.FirstName != "") ? _thisContact.FirstName : ((_thisContact.altFirstName != "") ? _thisContact.altFirstName : "Coffee Lover")) + ",<br />"); _email.AddStrAndNewLineToBody("We confirm the following order for " + _ddlThisContact.SelectedItem.Text + ":"); _email.AddToBody("<ul>"); foreach (GridViewRow _gv in gvOrderLines.Rows) { DropDownList _gvItemDesc = (DropDownList)_gv.FindControl("ddlItemDesc"); Label _gvItemQty = (Label)_gv.FindControl("lblQuantityOrdered"); DropDownList _gvItemPackaging = (DropDownList)_gv.FindControl("ddlPackaging"); // need to check for serivce / note and add the note using the same logic as we have for the delivery sheet if (_gvItemPackaging.SelectedIndex == 0) { _email.AddFormatToBody("<li>{0} x {1}</li>", _gvItemQty.Text, _gvItemDesc.SelectedItem.Text); } else { _email.AddFormatToBody("<li>{0} x {1} - Preperation note: {2}</li>", _gvItemQty.Text, _gvItemDesc.SelectedItem.Text, _gvItemPackaging.SelectedItem.Text); } } _email.AddStrAndNewLineToBody("</ul>"); if (_ddlDeliveryBy.SelectedItem.Text == CONST_DELIVERYTYPEISCOLLECTION) { _email.AddStrAndNewLineToBody("Will be ready for collection on: " + _lblDeliveryDate.Text); } else if (_ddlDeliveryBy.SelectedItem.Text == CONST_DELIVERYTYPEISCOURIER) { _email.AddStrAndNewLineToBody("Will be dispatched on: " + _lblDeliveryDate.Text + "."); } else { _email.AddStrAndNewLineToBody("Will be delivered on: " + _lblDeliveryDate.Text + "."); } // Add a footer _email.AddStrAndNewLineToBody("<br />Sent automatically by Quaffee's order and tracking System.<br /><br />Sincerely Quaffee Team ([email protected])"); if (_email.SendEmail()) { ltrlStatus.Text = "Email Sent to: " + _thisContact.EmailAddress; } else { ltrlStatus.Text = "Email was not sent!"; } } }
private QOnT.App_Code.ContactDetails.ContactEmailDetails GetContactsEmailDetails(string pContactsID) { ContactDetails.ContactEmailDetails _contactEmailDetails = null; string _ErrorStr = "connection not openned"; OleDbConnection _conn = null; OpenTrackerOleDBConnection(ref _conn); if (_conn != null) { // add parameters in the order they appear in the update command OleDbCommand _cmd = new OleDbCommand(CONST_SQLGETCONTACTEMAILDETAILS, _conn); _cmd.Parameters.Add(new OleDbParameter { Value = pContactsID }); try { _conn.Open(); OleDbDataReader _drEmailDetails = _cmd.ExecuteReader(); if (_drEmailDetails.Read()) { _contactEmailDetails = new ContactDetails.ContactEmailDetails(); if (_drEmailDetails["ContactFirstName"] != null) { _contactEmailDetails.FirstName = _drEmailDetails["ContactFirstName"].ToString(); } if (_drEmailDetails["ContactLastName"] != null) { _contactEmailDetails.LastName = _drEmailDetails["ContactLastName"].ToString(); } if (_drEmailDetails["EmailAddress"] != null) { _contactEmailDetails.EmailAddress = _drEmailDetails["EmailAddress"].ToString(); } if (_drEmailDetails["ContactAltFirstName"] != null) { _contactEmailDetails.altFirstName = _drEmailDetails["ContactAltFirstName"].ToString(); } if (_drEmailDetails["ContactAltLastName"] != null) { _contactEmailDetails.altLastName = _drEmailDetails["ContactAltLastName"].ToString(); } if (_drEmailDetails["AltEmailAddress"] != null) { _contactEmailDetails.altEmailAddress = _drEmailDetails["AltEmailAddress"].ToString(); } } } catch (OleDbException oleDbErr) { // Handle exception. _ErrorStr = "Error: " + oleDbErr.Message; } finally { _conn.Close(); } return(_contactEmailDetails); } else { ltrlStatus.Text = _ErrorStr; return(_contactEmailDetails); } }