I have a datagridview that is dropped in from the toolbox (VS2015). I need to select identical rows based on the Sales Order column and send an email:
So; if I select a row based on the unique identifier (Line Item), I would like to find all rows that have the same Sales Order number and email the information in those rows. As you can see, there can be one Row with no matching Sales Order or there can be several. What I sould like is a suggestion on code to select the multiple (similar) rows and suggestion on how to add all that information in email. I have some code snippets to do one single selection:
private void salesOrdersDataGridView_CellContentClick(object sender,
DataGridViewCellEventArgs e)
{
if (e.RowIndex > -1)
{
DataGridViewRow row = salesOrdersDataGridView.Rows[e.RowIndex];
string cpn = "";
cpn = salesOrdersDataGridView.Rows[e.RowIndex].Cells["cpn"].Value.ToString();
lblCpn.Text = cpn;
lblCpn.Visible = true;
string ordnum = "";
ordnum = salesOrdersDataGridView.Rows[e.RowIndex].Cells["SalesOrder"].Value.ToString();
lblOrder.Text = ordnum;
lblOrder.Visible = true;
string pnum = "";
pnum = salesOrdersDataGridView.Rows[e.RowIndex].Cells["partno"].Value.ToString();
lblPN.Text = pnum;
lblPN.Visible = true;
lblPN.ForeColor = Color.FromArgb(0, 192, 0);
string desc = "";
desc = salesOrdersDataGridView.Rows[e.RowIndex].Cells["descript"].Value.ToString();
lblDesc.Text = desc;
lblDesc.Visible = true;
string quant = "";
quant = salesOrdersDataGridView.Rows[e.RowIndex].Cells["qty"].Value.ToString();
lblQty.Text = quant;
lblQty.Visible = true;
string cpo = "";
cpo = salesOrdersDataGridView.Rows[e.RowIndex].Cells["cpo"].Value.ToString();
lblPO.Text = cpo;
lblPO.Visible = true;
string rev = "";
rev = salesOrdersDataGridView.Rows[e.RowIndex].Cells["crev"].Value.ToString();
lblRev.Text = rev;
lblRev.Visible = true;
lblRev.ForeColor = Color.FromArgb(0, 192, 0);
DateTime shp = DateTime.Parse(salesOrdersDataGridView.Rows[e.RowIndex].Cells["shipDate"].Value.ToString());
lblshp.Text = shp.ToString("MM/dd/yyyy");
lblshp.Visible = true;
string eml = "";
eml = salesOrdersDataGridView.Rows[e.RowIndex].Cells["email"].Value.ToString();
lblEmail.Text = eml;
lblEmail.Visible = true;
As you can see, I am writing to labels (this is so the user can verify the information. I then add that to email (Outlook):
private void btnAck_Click(object sender, EventArgs e)
{
try
{
//Must add Outlook Reference Object Library
Outlook.Application _app = new Outlook.Application();
Outlook.MailItem mail = (Outlook.MailItem)_app.CreateItem(Outlook.OlItemType.olMailItem);
mail.To = lblEmail.Text;
mail.BCC = ";[email protected]";
mail.Subject = "Order Acknowledgement for your PO " + lblPO.Text;
mail.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
mail.HTMLBody = "<HTML><BODY>";
mail.HTMLBody += "Thank you for your order!" + "<br />" + "<br />" + "Touchstone Order Number: " + lblOrder.Text +
"<br />" + " Part Number: " + lblPN.Text + "<br />" + "Description:" + lblDesc.Text + "<br />" + "Customer Part Number: " + " " +
lblCpn.Text + "-" + " Revision: " + lblRev.Text + "<br />" + "Expected Ship Date: " + lblshp.Text +
"<br />" + "Quantity: " + lblQty.Text + "<br />" + "<br />" + "Regards," + "<br />" +
"<br />" + "Customer Service" + "<br />" + "Touchstone Technology, Inc." + "<br />" + "address." +
"<br />" + "more address" + "<br />" + "Phone: phone number";
mail.HTMLBody += "<p>Web: <a href='http://www.web'>web</a></p></body></html>";
mail.Display(true);
// mail.Send();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
I stripped out what I though was not necessary - please feel free to ask any questions as I am not sure how to clarify what I need. Thanks for the usual quick responses and help