我想为这些字符串创建一个表并通过电子邮件发送它的问题是这些字符串是可能有多个值的数组,我不能在字符串中使用循环。
所以请帮我解决一下
先谢谢
string CusID = Request["CusID"];
string[] Name = Request["Name"].Split(char.Parse(","));
string[] Code = Request["Code"].Split(char.Parse(","));
string SellDate = Request["SellDate"];
string[] SellQuantity = Request["SellQuantity"].Split(char.Parse(","));
string[] SellPrice = Request["SellPrice"].Split(char.Parse(","));
string[] Paid = Request["Paid"].Split(char.Parse(","));
string[] Status = Request["Status"].Split(char.Parse(","));
string[] Discount = Request["Discount"].Split(char.Parse(","));
for (int i = 0; i < Name.Length; i++)
{
var totalprice = Convert.ToInt32(SellQuantity[i]) * (Convert.ToInt32(SellPrice[i]) - Convert.ToInt32(Discount[i]));
var insert = db.Database.ExecuteSqlCommand(@"insert into Details(CusID,Name,Code,SellDate,SellQuantity,SellPrice,Paid,[Status],Discount)
Values({0},{1},{2},{3},{4},{5},{6},{8},{9})", CusID, Name[i], Code[i], SellDate, SellQuantity[i], SellPrice[i], Paid[i], totalprice, Status[i],Discount[i]);
}
try
{
MailMessage mail = new MailMessage();
mail.To.Add("aspmvcmail@gmail.com");
mail.From = new MailAddress("abcdefghijklm@gmail.com");
mail.Subject = "hi "+DateTime.Now;
string Body = // store table in this string
mail.Body = Body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com"; //SMTP Server Address of gmail
smtp.Port = 587;
smtp.Credentials = new System.Net.NetworkCredential("abcdefghijklm@gmail.com", "**********");
// Smtp Email ID and Password For authentication
smtp.EnableSsl = true;
smtp.Send(mail);
return Json("Your Message Send Successfully.", JsonRequestBehavior.AllowGet);
}
catch
{
return Json("Error............", JsonRequestBehavior.AllowGet);
}