You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
3.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace BP.DA
{
public class AtPara
{
public AtPara()
{
}
/// <summary>
/// 执行一个para
/// </summary>
/// <param name="para"></param>
public AtPara(string para)
{
if (para == null)
return;
string[] strs = para.Split('@');
foreach (string str in strs)
{
if (DataType.IsNullOrEmpty(str) == true)
continue;
string[] mystr = str.Split('=');
if (mystr.Length == 2)
{
this.SetVal(mystr[0], mystr[1]);
}
else
{
string v = "";
for (int i = 1; i < mystr.Length; i++)
{
if (i == 1)
v += mystr[i];
else
v += "=" + mystr[i];
}
this.SetVal(mystr[0], v);
}
}
}
public void SetVal(string key, string val)
{
if (this.HisHT.ContainsKey(key) == true)
this.HisHT[key] = val;
else
this.HisHT.Add(key, val);
}
public string GetValStrByKey(string key)
{
string str = this.HisHT[key] as string;
if (str == null)
return "";
return str;
}
public bool GetValBoolenByKey(string key)
{
if (this.GetValIntByKey(key) == 0)
return false;
return true;
}
public bool GetValBoolenByKey(string key, bool isNullAsVal)
{
string str = this.GetValStrByKey(key);
if (DataType.IsNullOrEmpty(str) == true)
return isNullAsVal;
if (str.Equals("0") == true)
return false;
return true;
}
public float GetValFloatByKey(string key, float isNullAsVal = 0)
{
try
{
return float.Parse(this.GetValStrByKey(key));
}
catch
{
return isNullAsVal;
}
}
public int GetValIntByKey(string key, int isNullAsVal = 0)
{
string str = this.GetValStrByKey(key);
if (str == "undefined" || DataType.IsNullOrEmpty(str))
return isNullAsVal;
return int.Parse(str);
}
public Int64 GetValInt64ByKey(string key)
{
try
{
return Int64.Parse(this.GetValStrByKey(key));
}
catch
{
return 0;
}
}
private Hashtable _HisHT = null;
public Hashtable HisHT
{
get
{
if (_HisHT == null)
_HisHT = new Hashtable();
return _HisHT;
}
}
public string GenerAtParaStrs()
{
string s = "";
foreach (string key in this.HisHT.Keys)
{
s += "@" + key + "=" + this._HisHT[key].ToString();
}
return s;
}
}
}