Exemplo n.º 1
0
        private static Dictionary <string, EntitySchema> GetTableSchemas(Select select)
        {
            select.CheckArgumentNull(nameof(select));
            bool SchemaNameIsNotEmpty(QuerySourceExpression expression) => expression.SchemaName.IsNotNullOrEmpty();

            EntitySchemaManager esm = select.UserConnection.EntitySchemaManager;
            var sourceExpressions   = new List <QuerySourceExpression> {
                select.SourceExpression
            }
            .Concat(select.Joins.Select(join => join.SourceExpression).Where(SchemaNameIsNotEmpty));

            return(sourceExpressions
                   .ToDictionary(sourceExpression => sourceExpression.Alias ?? sourceExpression.SchemaName,
                                 sourceExpression => esm.FindInstanceByName(sourceExpression.SchemaName)));
        }
Exemplo n.º 2
0
        /// <summary>
        /// ######### ########### ## ###### "##### # ######" # ############ ###### ####### ###### ## ###########
        /// # ######## HtmlEdit ## #######
        /// </summary>
        /// <param name="userConnection">UserConnection ######## ############</param>
        /// <param name="htmlEdit">######## HtmlEdit</param>
        /// <param name="entitySchema">##### #######, # ####### ######### ###########</param>
        /// <param name="entityId">UId #######, # ####### ######### ###########</param>
        public static void SaveAndInsertImage(UserConnection userConnection, HtmlEdit htmlEdit, EntitySchema entitySchema, Guid entityId)
        {
            // ######### ####### #####
            if (Page.Request.Files.Count == 0)
            {
                return;
            }

            // ######## ##### ###### "##### # ######", #### ##### ##### ### - ###### ## ######
            EntitySchemaManager esm       = userConnection.EntitySchemaManager;
            string       fileSchemaName   = entitySchema.Name + "File";
            EntitySchema fileEntitySchema = esm.FindInstanceByName(fileSchemaName);

            if (fileEntitySchema == null)
            {
                return;
            }

            string         fileFieldName = htmlEdit.ClientID + "_loadedImage-file";
            HttpPostedFile file          = Page.Request.Files[fileFieldName];
            string         fileName      = file.FileName;

            if (string.IsNullOrEmpty(fileName))
            {
                return;
            }
            // ######## ###### #### ### ###### #####
            Stream fileStream = file.InputStream;

            fileStream.Position = 0;
            long fileSize = fileStream.Length;
            var  fileData = new byte[fileStream.Length];

            fileStream.Read(fileData, 0, fileData.Length);

            var img = Image.FromStream(fileStream);

            if (GraphicUtilities.GetImageFormat(img.RawFormat) == null)
            {
                var warning       = GetLocalizableStringValue(userConnection, "Warning");
                var fileTypeError = GetLocalizableStringValue(userConnection, "FileTypeError");

                const string messageCallback = @" function() {{}} ";

                string showMessageScript = ClientScriptUtilities.GetMessageScript(warning, fileTypeError,
                                                                                  MessageBoxButtons.Ok, MessageBoxIcon.Information, messageCallback);
                ScriptManager.AddScript(showMessageScript);
                return;
            }

            // crea Entity ### ###### ##### # ######### ##
            var fileUId        = Guid.NewGuid();
            var fileRepository = ClassFactory.Get <FileRepository>(
                new ConstructorArgument("userConnection", userConnection));
            var fileEntityInfo = new FileEntityUploadInfo(fileSchemaName, fileUId, fileName);

            fileEntityInfo.ParentColumnName  = entitySchema.Name;
            fileEntityInfo.ParentColumnValue = entityId;
            fileEntityInfo.TotalFileLength   = fileData.Length;
            fileEntityInfo.Content           = new MemoryStream(fileData);
            fileRepository.UploadFile(fileEntityInfo);

            // ####### ###### ControlImage # ############## ###
            var controlImage = new ControlImage {
                // ###### ##### ###########. # ###### ###### ## Entity
                Source = ControlImageSource.EntityColumn,
                // ## ##### EntitySchema-# ##### ######## Entity
                SchemaUId = fileEntitySchema.UId,
                // ######### ####### (ID ######)
                EntityPrimaryColumnValue = fileUId,
                // ####### ## ####### ##### ######## ######. #### ###### #### UsePrimaryImageColumn, ######### ## ###########
                EntitySchemaColumnUId = fileEntitySchema.Columns.GetByName("Data").UId,
                UsePrimaryImageColumn = false
            };

            // ### ##### ######## ########## ###### ControlImage ###### ######## ##########.
            // ######### ###### ### ##### ##### ########### # ######### #######.
            // ## ###### ###### ## ###### ############## ############# ###### # ######## ### ## ######
            string controlImageValue = Json.Serialize(controlImage, new ControlImageJsonConverter());

            ScriptManager.AddScript(string.Format("{0}.insertImage({1})", htmlEdit.ClientID, controlImageValue));
        }