MDSoft Weblog Mauro Destro software blog

This is my personal blog, here you find something about .NET, SCADA software I use and games in flash

09 Banner GIF

Best-sellers at Shop@US

maurodx aprile 1st, 2009

Use Web Caching to Make Your Web Site Faster

WebReference News febbraio 8th, 2010

Get an overview of how the multiple levels of web caching behave and how you can use them to make your site faster.

Calling control from generic form

CodeKeep C# Feed febbraio 8th, 2010

Description: Calling control from generic form

Link: http://www.codekeep.net/snippets/cb7ac992-50db-4221-9cdd-9cbac2b90ed0.aspx

            AdminControl control = new AdminControl(drciUpdateAddin);
            Base.GenericForm form = new Base.GenericForm(control);
            control.buttonCancel.Click += form.Cancel_Clicked;
            control.buttonSave.Click += form.Save_Clicked;
            form.Text = "Edit Settings";
            if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                buttonSave.IsEnabled = true;
                unsavedChanges = true;
            }

Enumerate Enum flags

CodeKeep C# Feed febbraio 8th, 2010

Description: produces a list of the selected flags in an enum that was built using [Flags]

Link: http://www.codekeep.net/snippets/fe6791e0-b62a-4bae-8b4a-33e2eca8d1e1.aspx

    /// <summary>
    /// Gets all combined items from an enum value.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <param name="value">The value.</param>
    /// <returns></returns>
    public static IEnumerable<T> GetAllSelectedItems<T>(this Enum value)
    {
        int valueAsInt = Convert.ToInt32(value, CultureInfo.InvariantCulture);

        foreach (object item in Enum.GetValues(typeof(T)))
        {
            int itemAsInt = Convert.ToInt32(item, CultureInfo.InvariantCulture);

            if (itemAsInt == (valueAsInt & itemAsInt))
            {
                yield return (T)item;
            }
        }
    }

Linq Orderby nullable DateTime

CodeKeep C# Feed febbraio 8th, 2010

Description: 2 good ways that seem to translate in Linq-to-sql

Link: http://www.codekeep.net/snippets/b57eec0f-c48d-43ed-9871-85a1ac67423f.aspx

orderby x.AddedDate ?? DateTime.MaxValue descending;

option 2:

orderby x.AddedDate.HasValue descending
          orderby x.AddedDate descending;

Dynamic Query

CodeKeep C# Feed febbraio 8th, 2010

Description: Based on Parameters

Link: http://www.codekeep.net/snippets/92585ea0-3113-403c-9a28-792aec8d1fae.aspx

        public List<ProjectMember> GetAll(Customer info)
        {
            var query = (from x in base.Db.Customers
                         select x);

            if(info.CustomerGroup != 0 )
            {
                query = query.Where(x => x.CustomerGroup == info.CustomerGroup);
            }
          
            return query.ToList();
        }

Next »