Code
#region 验证电话号码
/// <summary>
/// 验证电话号码
/// </summary>
/// <param name="P_str_phone"></param>
/// <returns></returns>
public bool validatePhone(string P_str_phone)
{
return Regex.IsMatch(P_str_phone, @"\d{3,4}-\d{7,8}");
}
#endregion
#region 验证数字
/// <summary>
/// 验证数字
/// </summary>
/// <param name="P_str_num"></param>
/// <returns></returns>
public bool validateNum(string P_str_num)
{
return Regex.IsMatch(P_str_num, "^[0-9]*$");
}
#endregion
#region 验证传真
/// <summary>
/// 验证传真
/// </summary>
/// <param name="P_str_fax"></param>
/// <returns></returns>
public bool validateFax(string P_str_fax)
{
return Regex.IsMatch(P_str_fax, @"86-\d{3,4}-\d{7,8}");
}
#endregion
#region 验证邮政编码
/// <summary>
/// 验证邮政编码
/// </summary>
/// <param name="P_str_postcode"></param>
/// <returns></returns>
public bool validatePostCode(string P_str_postcode)
{
return Regex.IsMatch(P_str_postcode, @"\d{6}");
}
#endregion
#region 验证电子邮件
/// <summary>
/// 验证电子邮件
/// </summary>
/// <param name="P_str_email"></param>
/// <returns></returns>
public bool validateEmail(string P_str_email)
{
return Regex.IsMatch(P_str_email, @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
}
#endregion
#region 验证网址
/// <summary>
/// 验证网址
/// </summary>
/// <param name="P_str_naddress"></param>
/// <returns></returns>
public bool validateNAddress(string P_str_naddress)
{
return Regex.IsMatch(P_str_naddress, @"http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?");
}
#endregion
#region 绑定报表
/// <summary>
/// 绑定报表
/// </summary>
/// <param name="P_str_creportName">报表名</param>
/// <param name="P_str_sql">SQL 语句</param>
/// <returns></returns>
public ReportDocument CrystalReports(string P_str_creportName, string P_str_sql)
{
ReportDocument reportDocument = new ReportDocument();
string P_str_creportPath = Application.StartupPath.Substring(0, Application.StartupPath.Substring(0,
Application.StartupPath.LastIndexOf("\\")).LastIndexOf("\\"));
P_str_creportPath+= @"\\SumManage\CReportFile\" + P_str_creportName;
reportDocument.Load(P_str_creportPath);
reportDocument.DataDefinition.RecordSelectionFormula = P_str_sql;
return reportDocument;
}
#endregion
#region 自动编号
/// <summary>
/// 自动编号
/// </summary>
/// <param name="P_str_sqlstr">语句</param>
/// <param name="P_str_table">表名</param>
/// <param name="P_str_tbColumn">表字段名</param>
/// <param name="P_str_codeIndex">编号前字符</param>
/// <param name="P_str_codeNum">编号后数字</param>
/// <param name="txt">控件名</param>
public void autoNum(string P_str_sqlstr, string P_str_table, string P_str_tbColumn, string P_str_codeIndex, string P_str_codeNum, TextBox txt)
{
string P_str_Code = "";
int P_int_Code = 0;
DataSet myds = boperate.getds(P_str_sqlstr, P_str_table);
if (myds.Tables[0].Rows.Count == 0)
{
txt.Text = P_str_codeIndex + P_str_codeNum;
}
else
{
P_str_Code = Convert.ToString(myds.Tables[0].Rows[myds.Tables[0].Rows.Count - 1][P_str_tbColumn]);
P_int_Code = Convert.ToInt32(P_str_Code.Substring(2, 7)) + 1;
P_str_Code = P_str_codeIndex + P_int_Code.ToString();
txt.Text = P_str_Code;
}
}
#endregion
#region 绑定ComboBox 控件
/// <summary>
/// 绑定ComboBox 控件
/// </summary>
/// <param name="P_str_sqlstr">sql语句</param>
/// <param name="P_str_table">表名</param>
/// <param name="P_str_tbMember">表字段名</param>
/// <param name="cbox">combobox控件名</param>
public void cboxBind(string P_str_sqlstr, string P_str_table, string P_str_tbMember, ComboBox cbox)
{
DataSet myds = boperate.getds(P_str_sqlstr, P_str_table);
cbox.DataSource = myds.Tables[P_str_table];
cbox.DisplayMember = P_str_tbMember;
}
#endregion
#region 验证电话号码
/// <summary>
/// 验证电话号码
/// </summary>
/// <param name="P_str_phone"></param>
/// <returns></returns>
public bool validatePhone(string P_str_phone)
{
return Regex.IsMatch(P_str_phone, @"\d{3,4}-\d{7,8}");
}
#endregion
#region 验证数字
/// <summary>
/// 验证数字
/// </summary>
/// <param name="P_str_num"></param>
/// <returns></returns>
public bool validateNum(string P_str_num)
{
return Regex.IsMatch(P_str_num, "^[0-9]*$");
}
#endregion
#region 验证传真
/// <summary>
/// 验证传真
/// </summary>
/// <param name="P_str_fax"></param>
/// <returns></returns>
public bool validateFax(string P_str_fax)
{
return Regex.IsMatch(P_str_fax, @"86-\d{3,4}-\d{7,8}");
}
#endregion
#region 验证邮政编码
/// <summary>
/// 验证邮政编码
/// </summary>
/// <param name="P_str_postcode"></param>
/// <returns></returns>
public bool validatePostCode(string P_str_postcode)
{
return Regex.IsMatch(P_str_postcode, @"\d{6}");
}
#endregion
#region 验证电子邮件
/// <summary>
/// 验证电子邮件
/// </summary>
/// <param name="P_str_email"></param>
/// <returns></returns>
public bool validateEmail(string P_str_email)
{
return Regex.IsMatch(P_str_email, @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
}
#endregion
#region 验证网址
/// <summary>
/// 验证网址
/// </summary>
/// <param name="P_str_naddress"></param>
/// <returns></returns>
public bool validateNAddress(string P_str_naddress)
{
return Regex.IsMatch(P_str_naddress, @"http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?");
}
#endregion
#region 绑定报表
/// <summary>
/// 绑定报表
/// </summary>
/// <param name="P_str_creportName">报表名</param>
/// <param name="P_str_sql">SQL 语句</param>
/// <returns></returns>
public ReportDocument CrystalReports(string P_str_creportName, string P_str_sql)
{
ReportDocument reportDocument = new ReportDocument();
string P_str_creportPath = Application.StartupPath.Substring(0, Application.StartupPath.Substring(0,
Application.StartupPath.LastIndexOf("\\")).LastIndexOf("\\"));
P_str_creportPath+= @"\\SumManage\CReportFile\" + P_str_creportName;
reportDocument.Load(P_str_creportPath);
reportDocument.DataDefinition.RecordSelectionFormula = P_str_sql;
return reportDocument;
}
#endregion
#region 自动编号
/// <summary>
/// 自动编号
/// </summary>
/// <param name="P_str_sqlstr">语句</param>
/// <param name="P_str_table">表名</param>
/// <param name="P_str_tbColumn">表字段名</param>
/// <param name="P_str_codeIndex">编号前字符</param>
/// <param name="P_str_codeNum">编号后数字</param>
/// <param name="txt">控件名</param>
public void autoNum(string P_str_sqlstr, string P_str_table, string P_str_tbColumn, string P_str_codeIndex, string P_str_codeNum, TextBox txt)
{
string P_str_Code = "";
int P_int_Code = 0;
DataSet myds = boperate.getds(P_str_sqlstr, P_str_table);
if (myds.Tables[0].Rows.Count == 0)
{
txt.Text = P_str_codeIndex + P_str_codeNum;
}
else
{
P_str_Code = Convert.ToString(myds.Tables[0].Rows[myds.Tables[0].Rows.Count - 1][P_str_tbColumn]);
P_int_Code = Convert.ToInt32(P_str_Code.Substring(2, 7)) + 1;
P_str_Code = P_str_codeIndex + P_int_Code.ToString();
txt.Text = P_str_Code;
}
}
#endregion
#region 绑定ComboBox 控件
/// <summary>
/// 绑定ComboBox 控件
/// </summary>
/// <param name="P_str_sqlstr">sql语句</param>
/// <param name="P_str_table">表名</param>
/// <param name="P_str_tbMember">表字段名</param>
/// <param name="cbox">combobox控件名</param>
public void cboxBind(string P_str_sqlstr, string P_str_table, string P_str_tbMember, ComboBox cbox)
{
DataSet myds = boperate.getds(P_str_sqlstr, P_str_table);
cbox.DataSource = myds.Tables[P_str_table];
cbox.DisplayMember = P_str_tbMember;
}
#endregion