Beispiel #1
0
        /// <summary>
        /// 上传图片文件到数据库
        /// </summary>
        /// <param name="assemblyName"></param>
        /// <param name="className"></param>
        /// <param name="imageContent"></param>
        /// <param name="imageColumnName"></param>
        /// <param name="key"></param>
        /// <param name="loginUser"></param>
        /// <returns></returns>
        public static object SaveImageToDatabase(string assemblyName, string className, byte[] imageContent, string extensionName, string key, string loginUser)
        {
            ///构建参数
            object[] param = new object[] { imageContent, extensionName, key, loginUser };
            ///实例化BLL对象
            object classObject = DataCommon.GetClassObject(assemblyName, className);
            ///
            MethodInfo met = classObject.GetType().GetMethod("UpdateImage");

            ///执行函数
            return(met.Invoke(classObject, param));
        }
Beispiel #2
0
        /// <summary>
        /// 从数据库读取图片
        /// </summary>
        /// <param name="assemblyName"></param>
        /// <param name="className"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static object ReadImageFromDatabase(string assemblyName, string className, string key)
        {
            ///构建参数
            object[] param = new object[] { key };
            ///实例化BLL对象
            object classObject = DataCommon.GetClassObject(assemblyName, className);
            ///
            MethodInfo met = classObject.GetType().GetMethod("ReadImage");

            ///执行函数
            return(met.Invoke(classObject, param));
        }
Beispiel #3
0
        /// <summary>
        /// 上传文件完成后执行的后台函数
        /// </summary>
        /// <param name="assemblyName"></param>
        /// <param name="className"></param>
        /// <param name="key"></param>
        /// <param name="loginUser"></param>
        /// <returns></returns>
        public static object UploadFileFinished(string assemblyName, string className, string methodName, string key, string loginUser)
        {
            ///构建参数
            object[] param = new object[] { key, loginUser };
            ///实例化BLL对象
            object classObject = DataCommon.GetClassObject(assemblyName, className);
            ///查找UploadFileFinished函数
            MethodInfo met = classObject.GetType().GetMethod(methodName);

            ///执行函数
            return(met.Invoke(classObject, param));
        }
Beispiel #4
0
        /// <summary>
        /// 获取BLL对象
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static object GetBusinessObject(HttpContext context)
        {
            string entityName = GetEntityName(context);

            if (string.IsNullOrEmpty(entityName))
            {
                entityName = context.Request["ENTITY_NAME"];
            }
            string moduleName = GetModuleName(context);

            return(DataCommon.GetClassObject("BLL." + moduleName, entityName + "BLL"));
        }
Beispiel #5
0
        /// <summary>
        /// 获取数据对象
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static object GetEntityObject(HttpContext context)
        {
            string entityName = GetEntityName(context);

            if (string.IsNullOrEmpty(entityName))
            {
                entityName = context.Request["ENTITY_NAME"];
            }
            string moduleName = GetModuleName(context);
            object obj        = DataCommon.GetClassObject("DM." + moduleName, entityName + "Info");

            return(GetObject(context, obj));
        }
Beispiel #6
0
 private void LoadHandler()
 {
     ///加载路由
     handlers = new HandlerBLL().GetHandlers();
     foreach (var handler in handlers)
     {
         handler.ClassObject = DataCommon.GetClassObject(handler.AssemblyName, handler.ClassName);
         if (handler.ClassObject == null)
         {
             continue;
         }
         handler.Method = handler.ClassObject.GetType().GetMethod(handler.ServerMethodName);
     }
 }
Beispiel #7
0
        /// <summary>
        /// 获取更新字段集合
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static List <CommonField> GetCommonFields(HttpContext context)
        {
            string entityName      = GetEntityName(context);
            string enityNameFromUI = context.Request["ENTITY_NAME"];

            if (enityNameFromUI.IndexOf("_") != -1)
            {
                enityNameFromUI = enityNameFromUI.Substring(0, enityNameFromUI.IndexOf("_"));
            }
            if (enityNameFromUI.Contains(entityName))
            {
                entityName = enityNameFromUI;
            }
            string             moduleName      = GetModuleName(context);
            object             obj             = DataCommon.GetClassObject("DM." + moduleName, entityName + "Info");
            List <CommonField> commonfieldlist = new List <CommonField>();

            ///此处因为Keys中最后一项是method、key参数,所以需要向前移两位
            for (int i = 0; i < context.Request.Form.AllKeys.Length; i++)
            {
                string propName = context.Request.Form.AllKeys[i];
                if (propName.ToLower() == "method")
                {
                    break;
                }
                string       propValue = context.Request[propName];
                PropertyInfo p         = obj.GetType().GetProperty(propName);
                if (p == null)
                {
                    continue;
                }
                #region FIELD_NAME
                string fieldName = propName.Substring(0, 1).ToUpper();
                for (int j = 1; j < propName.Length; j++)
                {
                    if (propName[j] >= 'a' && propName[j] <= 'z')
                    {
                        fieldName += propName[j].ToString().ToUpper();
                    }
                    else if (propName[j] >= 'A' && propName[j] <= 'Z')
                    {
                        fieldName += "_" + propName[j].ToString().ToUpper();
                    }
                    else
                    {
                        fieldName += propName[j].ToString();
                    }
                }
                #endregion
                CommonField commonfield = new CommonField();
                commonfield.FieldName  = fieldName;
                commonfield.PropName   = propName;
                commonfield.FieldValue = propValue;
                commonfield.DataType   = p.PropertyType.Name;
                if (commonfield.DataType.ToLower() == "nullable`1")
                {
                    if (p.PropertyType.FullName.ToLower().Contains("system.int32"))
                    {
                        commonfield.DataType = "int32?";
                    }
                    if (p.PropertyType.FullName.ToLower().Contains("system.int64"))
                    {
                        commonfield.DataType = "int64?";
                    }
                    if (p.PropertyType.FullName.ToLower().Contains("system.boolean"))
                    {
                        commonfield.DataType = "boolean?";
                    }
                    if (p.PropertyType.FullName.ToLower().Contains("system.decimal"))
                    {
                        commonfield.DataType = "decimal?";
                    }
                    if (p.PropertyType.FullName.ToLower().Contains("system.guid"))
                    {
                        commonfield.DataType = "guid?";
                    }
                    if (p.PropertyType.FullName.ToLower().Contains("system.datetime"))
                    {
                        commonfield.DataType = "datetime?";
                    }
                }
                commonfieldlist.Add(commonfield);
            }
            return(commonfieldlist);
        }
Beispiel #8
0
        /// <summary>
        /// 获取UPDATE字段的SQL语句
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public static string GetUpdateFields(HttpContext context)
        {
            string entityName      = GetEntityName(context);
            string enityNameFromUI = context.Request["ENTITY_NAME"];

            if (enityNameFromUI.IndexOf("_") != -1)
            {
                enityNameFromUI = enityNameFromUI.Substring(0, enityNameFromUI.IndexOf("_"));
            }
            if (enityNameFromUI.Contains(entityName))
            {
                entityName = enityNameFromUI;
            }
            string moduleName = GetModuleName(context);
            object obj        = DataCommon.GetClassObject("DM." + moduleName, entityName + "Info");
            string fields     = string.Empty;

            ///此处因为Keys中最后一项是method、key参数,所以需要向前移两位
            for (int i = 0; i < context.Request.Form.AllKeys.Length; i++)
            {
                string propName = context.Request.Form.AllKeys[i];
                if (propName.ToLower() == "method")
                {
                    break;
                }
                string       propValue = context.Request[propName];
                PropertyInfo p         = obj.GetType().GetProperty(propName);
                if (p == null)
                {
                    continue;
                }
                string fieldName = propName.Substring(0, 1).ToUpper();
                for (int j = 1; j < propName.Length; j++)
                {
                    if (propName[j] >= 'a' && propName[j] <= 'z')
                    {
                        fieldName += propName[j].ToString().ToUpper();
                    }
                    else if (propName[j] >= 'A' && propName[j] <= 'Z')
                    {
                        fieldName += "_" + propName[j].ToString().ToUpper();
                    }
                    else
                    {
                        fieldName += propName[j].ToString();
                    }
                }
                switch (p.PropertyType.Name.ToLower())
                {
                case "guid":
                    fields += ",[" + fieldName + "] = N'" + (string.IsNullOrEmpty(propValue) ? Guid.Empty : Guid.Parse(propValue)) + "' "; break;

                case "string":
                    ///需要将单引号转换为双引号
                    fields += ",[" + fieldName + "] = N'" + propValue.Replace("'", "''") + "' "; break;

                case "datetime":
                    fields += ",[" + fieldName + "] = N'" + (string.IsNullOrEmpty(propValue) ? DateTime.Parse("1900-01-01") : DateTime.Parse(propValue)) + "' "; break;

                case "nullable`1":
                    if (string.IsNullOrEmpty(propValue))
                    {
                        fields += ",[" + fieldName + "] = null ";
                        break;
                    }
                    if (p.PropertyType.FullName.ToLower().Contains("system.int32"))
                    {
                        fields += ",[" + fieldName + "] = " + int.Parse(propValue) + " ";
                    }
                    if (p.PropertyType.FullName.ToLower().Contains("system.int64"))
                    {
                        fields += ",[" + fieldName + "] = " + int.Parse(propValue) + " ";
                    }
                    if (p.PropertyType.FullName.ToLower().Contains("system.boolean"))
                    {
                        fields += ",[" + fieldName + "] = " + (propValue.ToLower() == "30" ? 1 : 0) + " ";
                    }
                    if (p.PropertyType.FullName.ToLower().Contains("system.decimal"))
                    {
                        fields += ",[" + fieldName + "] = " + decimal.Parse(propValue) + " ";
                    }
                    if (p.PropertyType.FullName.ToLower().Contains("system.guid"))
                    {
                        fields += ",[" + fieldName + "] = N'" + Guid.Parse(propValue) + "' ";
                    }
                    if (p.PropertyType.FullName.ToLower().Contains("system.datetime"))
                    {
                        fields += ",[" + fieldName + "] = N'" + DateTime.Parse(propValue) + "' ";
                    }
                    break;

                case "int32":
                case "int64":
                    fields += ",[" + fieldName + "] = " + (string.IsNullOrEmpty(propValue) ? 0 : int.Parse(propValue)) + " "; break;

                case "bool":
                    fields += ",[" + fieldName + "] = " + (propValue.ToLower() == "30" ? 1 : 0) + " "; break;

                case "decimal":
                    fields += ",[" + fieldName + "] = " + (string.IsNullOrEmpty(propValue) ? 0 : decimal.Parse(propValue)) + " "; break;
                }
            }
            ///修改人
            PropertyInfo pModify = obj.GetType().GetProperty("ModifyUser");

            if (pModify != null)
            {
                fields += ",[MODIFY_USER] = N'" + HandlerCommon.LoginUser + "' ";
            }
            pModify = obj.GetType().GetProperty("UpdateUser");
            if (pModify != null)
            {
                fields += ",[UPDATE_USER] = N'" + HandlerCommon.LoginUser + "' ";
            }
            ///修改时间
            pModify = obj.GetType().GetProperty("ModifyDate");
            if (pModify != null)
            {
                fields += ",[MODIFY_DATE] = GETDATE() ";
            }
            pModify = obj.GetType().GetProperty("UpdateDate");
            if (pModify != null)
            {
                fields += ",[UPDATE_DATE] = GETDATE() ";
            }
            ///

            return(fields);
        }