Exemple #1
0
        //删除对象
        public static string Delete(string TableName, string KeyName, string KeyValue, bool IsAdmin)
        {
            PropertyInfo  property = null;
            List <string> ids      = new List <string>();

            if (KeyValue != "")
            {
                ids = StringTool.SplitStringList(KeyValue, ",");
            }
            else
            {
                if (HttpContext.Current.Request[KeyName] != null)//提交了主键的相关值
                {
                    ids = StringTool.SplitStringList(RequestTool.GetFormString(KeyName), ",");
                }
                else
                {
                    return("参数不足");
                }
            }
            if (!string.IsNullOrEmpty(TableName) && ids.Count > 0)
            {
                Type       modelType  = BLLBase.GetObjectType(TableName);
                Type       bllType    = BLLBase.GetBLLObjectType(TableName);
                MethodInfo methodInfo = bllType.GetMethod("Delete");
                object     Newobj     = Activator.CreateInstance(bllType);
                if (methodInfo != null)
                {
                    object objid = null;
                    foreach (string id in ids)
                    {
                        property = modelType.GetProperty(KeyName);
                        if (property != null)
                        {
                            objid = GetTypeValue(property.PropertyType.Name, Convert.ToString(id));
                            //if (TableName != "CZ_Log" && IsAdmin)
                            //LOG.Instance.AddLog(TableName, id, "删除", "", Ref, 0);//添加操作记录
                        }
                        object[] paras   = new object[] { objid };
                        var      execute = methodInfo.Invoke(Newobj, paras);
                    }
                }
            }
            else
            {
                return("参数不足");
            }
            return("OK");
        }