public void UpdateResolutions(ResolutionCollection resolutions)
        {
            const string updateQuery = @"
				UPDATE
					[Cerberus.TemplateEngine.Resolution]
				SET
					Width = @Width{0}
				WHERE
					ResolutionId = @ResolutionId{0}"                    ;

            var command = SqlDbAccess.CreateTextCommand();

            var sb      = new StringBuilder();
            var counter = 0;

            foreach (var resolution in resolutions)
            {
                sb.AppendFormat(updateQuery, counter);

                SqlDbAccess.AddParameter(command, string.Format("@ResolutionId{0}", counter), SqlDbType.Int, resolution.Id);
                SqlDbAccess.AddParameter(command, string.Format("@Width{0}", counter), SqlDbType.Int, resolution.ResolutionValue);

                this.UpdateResolutionValues(resolution.Id, resolution.TemplateControlVisualProperties);

                counter++;
            }

            command.CommandText = sb.ToString();

            SqlDbAccess.ExecuteNonQuery(command);
        }
        public void AddResolutions(int templateId, ResolutionCollection resolutions)
        {
            var command = SqlDbAccess.CreateTextCommand();

            command.CommandText = @"
				INSERT INTO 
					[Cerberus.TemplateEngine.Resolution]
					(
						TemplateId,
						Width						
					)
				VALUES
					(
						@TemplateId,
						@Width
					);
				SELECT CAST(SCOPE_IDENTITY() AS INT);"                ;

            SqlDbAccess.AddParameter(command, "@TemplateId", SqlDbType.Int, templateId);

            var widthParameter = SqlDbAccess.AddParameter(command, "@Width", SqlDbType.Int, 0);

            foreach (var resolution in resolutions)
            {
                widthParameter.Value = resolution.ResolutionValue;

                resolution.Id = SqlDbAccess.ExecuteScalar <int>(command);
                this.UpdateResolutionValues(resolution.Id, resolution.TemplateControlVisualProperties);
            }
        }
        public ResolutionCollection GetResolutions(int templateId)
        {
            var command = SqlDbAccess.CreateTextCommand();

            command.CommandText = @"
				SELECT
					R.ResolutionId,
					R.Width,
					TCR.TemplateControlId,
					TCR.VisualProperties
				FROM 
					[Cerberus.TemplateEngine.Resolution] R
					LEFT JOIN [Cerberus.TemplateEngine.TemplateControlResolution] TCR ON R.ResolutionId=TCR.ResolutionId
				WHERE
					R.TemplateId = @TemplateId
				ORDER BY
					R.Width ASC"                    ;

            SqlDbAccess.AddParameter(command, "@TemplateId", SqlDbType.Int, templateId);

            return(ResolutionCollection.CreateFromData(SqlDbAccess.ExecuteSelect(command)));
        }
예제 #4
0
        internal static ResolutionCollection CreateFromData(DataTable data)
        {
            var list = new ResolutionCollection();

            var        lastResolutionId    = 0;
            var        currentResolutionId = 0;
            var        templateControlId   = 0;
            var        visualProperties    = string.Empty;
            Resolution resolution          = null;

            foreach (DataRow row in data.Rows)
            {
                currentResolutionId = Convert.ToInt32(row["ResolutionId"]);

                if (lastResolutionId != currentResolutionId)
                {
                    resolution = new Resolution
                    {
                        Id = currentResolutionId,
                        ResolutionValue = Convert.ToInt32(row["Width"])
                    };

                    list.Add(resolution);

                    lastResolutionId = currentResolutionId;
                }

                if (!row.IsNull("TemplateControlId"))
                {
                    templateControlId = Convert.ToInt32(row["TemplateControlId"]);
                    visualProperties  = row["VisualProperties"].ToString();

                    resolution.TemplateControlVisualProperties.Add(templateControlId, visualProperties);
                }
            }

            return(list);
        }