url处理类(备注)
时间:2011-01-10 来源:卑鄙De小贝
public int intT_Companyid(string F_Domain) {
return Re("select * from T_Companyid where F_Domain = '" + F_Domain + "'");
}
public static int Re(string Sql_Str) {
int i_ = 0;
SqlCommand mycom = new SqlCommand();
SqlConnection mycon = new SqlConnection(connectionString);
mycom.Connection = mycon;
mycon.Open();
Sql_Str = xiugaiSqlStr(Sql_Str);
mycom.CommandText = Sql_Str;
SqlDataReader myDr = mycom.ExecuteReader();
while (myDr.Read()) {
i_++;
}
mycon.Close();
return i_;
}
public static string xiugaiSqlStr(string sqlstr) {
denglu mydenglu = new denglu();
if (!sqlstr.Contains("T_Companyid") && !sqlstr.Contains("T_City") && !sqlstr.Contains("T_Provincial") && !sqlstr.Contains("T_TreeView")) {
if ((sqlstr.Contains("where") || sqlstr.Contains("Where") || sqlstr.Contains("WHERE")) && !sqlstr.Contains("insert")) {
if (sqlstr.Contains(" order")) {
int i = sqlstr.IndexOf(" order");
string str1 = "";
string str2 = " and F_Companyid = " + mydenglu.commderid() + " ";
string str3 = "";
for (int i_ = 0; i_ < i; i_++) {
str1 += sqlstr[i_].ToString();
}
for (int i_ = i; i_ < sqlstr.Length; i_++) {
str3 += sqlstr[i_].ToString();
}
sqlstr = str1 + str2 + str3;
}
else {
sqlstr += " and F_Companyid = " + mydenglu.commderid() + " ";
}
}
else {
if (sqlstr.Contains(" order")) {
int i = sqlstr.IndexOf(" order");
string str1 = "";
string str2 = " where F_Companyid = " + mydenglu.commderid() + " ";
string str3 = "";
for (int i_ = 0; i_ < i; i_++) {
str1 += sqlstr[i_].ToString();
}
for (int i_ = i; i_ < sqlstr.Length; i_++) {
str3 += sqlstr[i_].ToString();
}
sqlstr = str1 + str2 + str3;
}
else {
if (!sqlstr.Contains("insert")) {
sqlstr += " where F_Companyid = " + mydenglu.commderid() + " ";
}
}
}
if (sqlstr.Contains("insert")) {
string[] sqlstr1 = sqlstr.Split(')');
sqlstr = "";
sqlstr = sqlstr1[0].ToString() + ",F_Companyid)";
for (int i = 1; i < sqlstr1.Length; i++) {
if (i == sqlstr1.Length - 2) {
sqlstr += sqlstr1[i].ToString() + ",1)";
}
else {
sqlstr += sqlstr1[i].ToString() + ")";
}
}
sqlstr = sqlstr.Substring(0, sqlstr.Length - 1);
}
}//order
return sqlstr;
}
数据库
相关阅读 更多 +