/// <summary> /// 获取市、县 /// </summary> /// <param name="code">省份编号</param> /// <returns></returns> public static string GetCity(string code) { string result = String.Empty; try { XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(xmlUrl); XmlNodeList xnl = xmldoc.SelectSingleNode("country").ChildNodes; string json = "["; foreach (XmlNode xn in xnl) { if (xn.Attributes["code"].Value == code) { XmlNodeList citylist = xn.ChildNodes; foreach (XmlNode city in citylist) { json += "{code" + ":" + city.Attributes["code"].Value + ",name:\"" + city.Attributes["name"].Value + "\"},"; } } } json = json.TrimEnd(',') + "]"; return(json.TrimEnd(',')); } catch (Exception ex) { //写入日志 TxtFileHelper.AppendLogTxt(ex.Message); throw ex; } }
/// <summary> /// 获取区 /// </summary> /// <param name="code">城市编号</param> /// <returns></returns> public static string GetArea(string code) { string result = String.Empty; try { XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(HttpContext.Current.Server.MapPath("~/App_Data/Address.xml")); XmlNodeList xnl = xmldoc.SelectSingleNode("country").ChildNodes; string json = "["; foreach (XmlNode xn in xnl) { XmlNodeList citylist = xn.ChildNodes; foreach (XmlNode city in citylist) { if (city.Attributes["code"].Value == code) { XmlNodeList arealist = city.ChildNodes; foreach (XmlNode area in arealist) { json += "{code" + ":" + area.Attributes["code"].Value + ",name:\"" + area.Attributes["name"].Value + "\"},"; } } } } json = json.TrimEnd(',') + "]"; return(json.TrimEnd(',')); } catch (Exception ex) { //写入日志 TxtFileHelper.AppendLogTxt(ex.Message); throw ex; } }
/// <summary> /// 获取省、市、区名称 /// </summary> /// <param name="code">省、市、区编号</param> /// <returns></returns> public static string[] GetNames(string codes) { string[] codeSp = codes.Split(','); string[] names = new string[codeSp.Length]; string result = String.Empty; try { XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(xmlUrl); XmlNodeList xnl = xmldoc.SelectSingleNode("country").ChildNodes; foreach (XmlNode xn in xnl) { if (xn.Attributes["code"].Value == codeSp[0]) { names[0] = xn.Attributes["name"].Value; XmlNodeList citylist = xn.ChildNodes; foreach (XmlNode city in citylist) { if (city.Attributes["code"].Value == codeSp[1]) { names[1] = city.Attributes["name"].Value; XmlNodeList arealist = city.ChildNodes; foreach (XmlNode area in arealist) { if (area.Attributes["code"].Value == codeSp[2]) { names[2] = area.Attributes["name"].Value; } } } } } } return(names); } catch (Exception ex) { //写入日志 TxtFileHelper.AppendLogTxt(ex.Message); throw ex; } }
/// <summary> /// /// </summary> /// <param name="title">标题</param> /// <param name="content">发送内容</param> /// <param name="toEmail">目标邮件,多邮件发送以“;”号隔开</param> /// <returns></returns> public static bool SendEmail(string title, string content, string toEmail, string fileName) { try { string fileUrl = HttpContext.Current.Server.MapPath("~/App_Data/WebSet/EmailSet.xml"); EmailSet es = MyXmlSerializer <EmailSet> .Get(fileUrl); MailAddress from = new MailAddress(es.EmailName); MailAddress reply = new MailAddress(es.EmailName); foreach (string add in toEmail.Split(';')) { MailAddress to = new MailAddress(add); MailMessage msg1 = new MailMessage(from, to); msg1.ReplyTo = reply; msg1.Subject = title; msg1.Body = content; msg1.BodyEncoding = System.Text.Encoding.UTF8; msg1.IsBodyHtml = true; //msg1.Sender = sender; if (!string.IsNullOrEmpty(fileName)) { Attachment attachment = new Attachment(fileName); msg1.Attachments.Add(attachment); } SmtpClient client = new SmtpClient(es.SMTP, es.Port.ToInt());//SMTP地址,"端口号" client.Credentials = new NetworkCredential(es.EmailName, es.EmailPwd); client.Send(msg1); } return(true); } catch (Exception ex) { //写入日志 TxtFileHelper.AppendLogTxt(ex.Message); return(false); } }