/// <summary>
        /// 处理SQLParameter
        /// </summary>
        /// <param name="s">SQL字符串</param>
        /// <param name="o">参数对象</param>
        /// <param name="t">表Type</param>
        /// <returns>Common.Net.CreateParameter</returns>
        public static Common.Net.CreateParameter GetSQLParameter <EntityObject>(string s, object[] o, Type t)
        {
            try
            {
                Common.Net.CreateParameter _C    = new Common.Net.CreateParameter();
                string         propertyKey       = t.Name;
                PropertyInfo[] propertyAttribute = null;
                //缓存propertyAttribute
                if (EntityBaseDataCache.propertyAttributeCache.ContainsKey(propertyKey))
                {
                    propertyAttribute = EntityBaseDataCache.propertyAttributeCache[propertyKey];
                }
                else
                {
                    propertyAttribute = t.GetProperties();
                    EntityBaseDataCache.propertyAttributeCache[propertyKey] = propertyAttribute;
                }

                Regex           _R  = new Regex(@"@[_a-zA-Z][_a-zA-Z\d]*");
                MatchCollection _mc = _R.Matches(DealSQL <EntityObject>(s));
                if (_mc.Count > o.Length)
                {
                    throw new Exception("Parameter参数不正确");
                }

                int i = 0;
                foreach (Match m in _mc)
                {
                    string c = m.Value.ToString2();

                    bool isBP = false;
                    foreach (PropertyInfo pi in propertyAttribute)
                    {
                        string K = c.Replace("@", "").ToLower().Replace(pi.Name.ToLower(), "");
                        if (K == "" || K.isInt())
                        {
                            ColumnAttribute[] cas = pi.GetCustomAttributes(typeof(ColumnAttribute), false) as ColumnAttribute[];
                            if (cas.Length > 0)
                            {
                                ColumnAttribute ca = cas[0];
                                _C.CanShu.Add(c, ca.Type, o[i].ToString2());
                                isBP = true;
                            }
                            break;
                        }
                    }
                    if (!isBP)//匹配不成功的都默认为 NVarChar
                    {
                        _C.CanShu.Add(c, SqlDbType.NVarChar, o[i].ToString2());
                    }
                    i++;
                }
                return(_C);
            }
            catch { throw new Exception("处理Parameter参数错误"); }
        }
 /// <summary>
 /// 查看记录是否存在
 /// </summary>
 /// <param name="KeyNames">字段名数组</param>
 /// <param name="_SqlDbTypes">字段类型数组</param>
 /// <param name="Values">字段值数组</param>
 /// <returns>bool</returns>
 public static bool Exists(string[] KeyNames, System.Data.SqlDbType[] _SqlDbTypes, object[] Values)
 {
     System.Collections.ArrayList SqlWhere = new System.Collections.ArrayList();
     Common.Net.CreateParameter   _C       = new Common.Net.CreateParameter();
     for (int i = 0; i < KeyNames.Length; i++)
     {
         _C.CanShu.Add("@" + KeyNames[i], _SqlDbTypes[i], Values[i]);
         SqlWhere.Add(string.Format(" {0}=@{0} ", KeyNames[i]));
     }
     return(Exists(SqlWhere.JArrayListToString(" and ", true), _C.Re_SqlParameter()));
 }
Example #3
0
        public static Admin getAdminByAdminID(string AdminID)
        {
            try
            {
                Common.Net.CreateParameter _C = new Common.Net.CreateParameter();
                _C.CanShu.Add("@AdminID", System.Data.SqlDbType.NVarChar, AdminID);
                List <Admin> m_AdminList = Orm.EntityCore <Admin> .GetModelList("AdminID=@AdminID", _C.Re_SqlParameter()).List;

                if (m_AdminList.Count == 0)
                {
                    return(null);
                }
                else
                {
                    return(m_AdminList[0]);
                }
            }
            catch
            {
                //Exception.MyExceptionLog.AddLogError("获取后体帐号model失败, Admin - getAdminByAdminID");
                return(null);
            }
        }