using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Text;
using System.Data;
using System.Net;
using System.Net.Mail;
namespace Methods1
{
///
///Methods 的摘要说明
///
///
public class Methods1
{
public Methods1()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
///
/// 获取自动编号(订单号 spnumber)
///
/// 时间编号
public static string s()
{
int t = 1;
string str = DateTime.Now.ToString("yyMMddhhmmss") + t.ToString("000");
return str;
}
public static string s2()
{
int t = 2;
string str = DateTime.Now.ToString("yyMMddhhmmss") + t.ToString("000");
return str;
}
public static string s3()
{
int t = 3;
string str = DateTime.Now.ToString("yyMMddhhmmss") + t.ToString("000");
return str;
}
///
/// 时间编号/文化小类编号
///
///
public static string s4()
{
int t = 4;
string str = DateTime.Now.ToString("yyMMddhhmmss") + t.ToString("000");
return str;
}
//会员号
public static string Numbers()
{
int t = 1;
string str = t.ToString("VIP")+DateTime.Now.ToString("yyMMddhhmmss");
return str;
}
///
/// 批次号/文化类别编号
///
///
public static string Pnote()
{
int t = 1;
string str = t.ToString("Pw") + DateTime.Now.ToString("yyMMddhhmmss");
return str;
}
#region MD5加密函数
///
/// MD5加密函数
///
/// 加密字符串
/// 加密位数(16,32)
/// 加密过的字符串
public static string Md5(string str, int code)
{
if (code == 16) //16位MD5加密(取32位加密的9~25字符)
{
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, System.Web.Configuration.FormsAuthPasswordFormat.MD5.ToString()).ToLower().Substring(8, 16);
}
if (code == 32) //32位加密
{
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, System.Web.Configuration.FormsAuthPasswordFormat.MD5.ToString()).ToLower();
}
return "00000000000000000000000000000000";
}
#endregion
#region
///
/// 弹出提示信息
///
///
///
public static void Alert(Page objPage, string message)
{
string key = "AlertMessage";
string script = string.Format("alert('{0}')", message);
objPage.ClientScript.RegisterStartupScript(typeof(Page), key, script, true);
}
public static void Alert(Page objPage, string message, string url)
{
string key = "AlertMessage";
string script = String.Format("alert('{0}');window.location='{1}';", message, url);
objPage.ClientScript.RegisterStartupScript(typeof(Page), key, script, true);
}
#endregion
///
/// 显示消息提示对话框,并进行页面跳转
///
/// 当前页面指针,一般为this
/// 提示信息
/// 跳转的目标URL
public static void ShowAndRedirect(System.Web.UI.Page page, String msg, String url)
{
StringBuilder Builder = new StringBuilder();
Builder.Append("");
page.ClientScript.RegisterStartupScript(page.GetType(), "message", Builder.ToString());
}
#region MsgBox
///
/// 显示“确定”,点击以后就转到预设网址的提示框
///
/// 提示信息
/// “确定”以后要转到预设网址
/// 提示框JS
public static void MsgBox(string strMsg, string URL)
{
string StrScript;
StrScript = ("");
System.Web.HttpContext.Current.Response.Write(StrScript);
}
#endregion
#region 读取最大的Id
///
/// 获取最大的Id
///
///
public string MaxId()
{
string NewId = null;
string Sqlstr = "select* from Baoxiu order by Id desc";
//SqlCommand com = new SqlCommand(Sqlstr, con);
//com.Connection.Open();
//SqlDataReader sdr = com.ExecuteReader(CommandBehavior.CloseConnection);
//sdr.Read();
string Id;
DataTable dt = DBH.DBHelper.GetDataSet(Sqlstr);
if (dt.Rows.Count > 0)
{
Id = dt.Rows[0]["id"].ToString();
}
else
{
Id = "";
}
///获取日期编号
string Date = Id.Substring(2, 8);
///获取后四位流水号
string str = Id.Substring(Id.Length - 4, 4);
if (Id.Substring(2, 8) != DateTime.Now.ToString("yyyyMMdd"))
{
Date = DateTime.Now.ToString("yyyyMMdd");
string liushui = (Convert.ToInt32("0000") + 1).ToString().PadLeft(4, '0');
NewId = "Bx" + Date + liushui;
}
else
{
int liushui = Convert.ToInt32(str) + 1;
NewId = "Bx" + Date + liushui.ToString().PadLeft(4, '0');
}
return NewId;
}
#endregion
//加到类的定义部分
private static string[] cstr = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
private static string[] wstr = { "", "", "拾", "佰", "仟", "萬", "拾", "佰", "仟", "億", "拾", "佰", "仟" };
//数字必须在12位整数以内的字符串
//调用方式如:Label1.Text=ConvertInt("数字字符串");
public static string ConvertInt(string str)
{
int len = str.Length;
int i;
string tmpstr, rstr;
rstr = "";
for (i = 1; i <= len; i++)
{
tmpstr = str.Substring(len - i, 1);
rstr = string.Concat(cstr[Int32.Parse(tmpstr)] + wstr[i], rstr);
}
rstr = rstr.Replace("拾零", "拾");
rstr = rstr.Replace("零拾", "零");
rstr = rstr.Replace("零佰", "零");
rstr = rstr.Replace("零仟", "零");
rstr = rstr.Replace("零萬", "萬");
for (i = 1; i <= 6; i++)
rstr = rstr.Replace("零零", "零");
rstr = rstr.Replace("零萬", "零");
rstr = rstr.Replace("零億", "億");
rstr = rstr.Replace("零零", "零");
rstr += "圆整";
return rstr;
}
#region
///
/// 发送给一个收件人
///
/// 收件人地址
/// 标题
/// 内容
///
public static string SendMail1(string sMail, string Subject, string Body)
{
string result;
SmtpClient mail = new SmtpClient();
//发送方式
mail.DeliveryMethod = SmtpDeliveryMethod.Network;
//smtp服务器
mail.Host = "smtp.163.com";
//用户名凭证
mail.Credentials = new System.Net.NetworkCredential("cinowo123", "cinowo123456");
//邮件信息
MailMessage message = new MailMessage();
//发件人
message.From = new MailAddress("cinowo123@163.com");
//收件人
message.To.Add(sMail);
//主题
message.Subject = Subject;
//内容
message.Body = Body;
//正文编码
message.BodyEncoding = System.Text.Encoding.UTF8;
//设置为HTML格式
message.IsBodyHtml = true;
//优先级
message.Priority = MailPriority.High;
try
{
mail.Send(message);
result = "发送成功";
return result;
}
catch (Exception e)
{
result = e.ToString();
}
return result;
}
#endregion
}
}