本文来源:网站建设-网站制作|网络营销专家慧云科技-抢滩登陆2009-6-2 20:21:20
private static string ReadConnectionString( string name )
{
XmlElem xmlnode = CommonConstDom.GetElem( "//connectionStrings/connString[@name=‘" + name + "‘]" );
if( xmlnode != null ) return xmlnode["value"];
return "";
}
public static bool WriteAdminPassword( string name, string newPwd )
{
XmlElem xeAdmin = CommonConstDom.GetElem( "//adminUsers/adminUser[@name=‘" + name + "‘]" );
if( xeAdmin == null ) return false;
if( !xeAdmin.SetAttr( "password", newPwd ) ) return false;
if( !CommonConstDom.Save() ) return false;
return true;
}
public static string ReadAdminPassword( string name )
{
XmlElem xmlnode = CommonConstDom.GetElem( "//adminUsers/adminUser[@name=‘" + name + "‘]" );
if( xmlnode != null ) return xmlnode["password"];
return "";
}
/// 创建一个独立的临时文件夹 (无异常)
/// 返回临时文件夹的磁盘路径
public static string CreateTmporary()
{
string uni, tempfd;
try {
for( int i = 0; i < 20; i++ ) {
uni = Todo.UniqueValue;
tempfd = TemporaryPath + uni + "\\";
if( !FolderDo.IsExists( tempfd ) ) {
FolderDo.Create( tempfd );
return tempfd;
}
}
return "";
}
catch( Exception ex ) {
Todo.DebugOut( "Create Tempory Folder Error: " + ex.Message );
return "";
}
}
private static Regex tNameRg = new Regex( "^sys_.*", RegexOptions.IgnoreCase );
///
/// 获取系统定义的栏目字段类型的 DataTable (无异常)
///
public static DataTable GetFieldType()
{
try {
DataTable dt = DataDo.CreateDataTableBy( "name,title" );
DataRow dr = null;
XmlNodeList xnList = CommonConstDom.GetNodes( "//dataFieldType/type" );//columnFieldType
string name = "", title = "";
foreach( XmlNode xn in xnList ) {
dr = dt.NewRow();
name = xn.Attributes["name"].Value;
title = xn.Attributes["title"].Value;
if( tNameRg.IsMatch( name ) )
continue;
dr["name"] = name;
dr["title"] = title;
dt.Rows.Add( dr );
}
return dt;
}
catch( Exception ex ) {
Todo.DebugOut( "获取字段类型出错: " + ex.Message );
return null;
}
}
///
/// 解压指定的压缩包文件 (无异常)
///
/// 操作是否成功
public static bool UncompressFile( string srcRarFile, string dstFolder )
{
try {
Process pp = Process.Start( UnrarToolFile, "x -w -o+ " + srcRarFile + " " + dstFolder );
pp.WaitForExit();
return true;
}
catch( Exception ex ) {
Todo.DebugOut( "Uncompress RarFile ‘" + srcRarFile + "‘ Error: " + ex.Message );
return false;
}
}
///
/// 压缩打包指定的文件夹中所有内容到压缩包中 (无异常)
///
/// 操作是否成功
public static bool CompressFolder( string srcFolder, string dstRarFile )
{
try {
Process pp = Process.Start( UnrarToolFile, "a -r -ep1 " + dstRarFile + " " + srcFolder );
pp.WaitForExit();
return true;
}
catch( Exception ex ) {
Todo.DebugOut( "Compress Folder ‘" + srcFolder + "‘ Error: " + ex.Message );
return false;
}
}
private static Regex vNameRg = new Regex( "^[_a-z0-9]{6,16}$" );
private static Regex vTitleRg = new Regex( @"^[a-zA-Z\u4e00-\u9fa5][-_a-zA-Z$.\(\)0-9\u4e00-\u9fa5]*$" );
private static Regex vFileNameRg = new Regex( "[\\/\\* \\>\\<\\?\\|\\:\\‘\\\"\\\\]" );
///
/// 验证 标识名
///
public static bool ValidateName( string value )
{
return vNameRg.IsMatch( value );
}
///
/// 验证 外部名称
///
public static bool ValidateTitle( string value )
{
return vTitleRg.IsMatch( value ) && (value.Length < 40);
}
///
/// 验证 文件/文件夹名
///
public static bool ValidateFileName( string value )
{
return !(vFileNameRg.IsMatch( value )) && (value.Length > 0) && (value.Length < 40);
}