2010
04.23

In the general case it’s true that there isn’t a built-in reject changes method in the entity framework. The following function can undo or discard the changes:

public void DiscardChanges(IEntityWithKey entity)
{
ObjectStateEntry entry = ctxt.ObjectStateManager.GetObjectStateEntry(entity.EntityKey);
for (int i = 0; i < entry.OriginalValues.FieldCount; i++)
{
entry.CurrentValues.SetValue(i, entry.OriginalValues[i]);
}
entry.AcceptChanges();
}
| More
VN:F [1.6.7_924]
Rating: 0.0/10 (0 votes cast)
VN:F [1.6.7_924]
Rating: 0 (from 0 votes)

Post to Twitter

2010
02.28

The DataGridView control provides several column types, enabling your users to enter and edit values in a variety of ways. If these column types do not meet your data-entry needs, however, you can create your own column types with cells that host controls of your choosing. To do this, you must define classes that derive from DataGridViewColumn and DataGridViewCell. You must also define a class that derives from Control and implements the IDataGridViewEditingControl interface.

The following code example shows how to create a calendar column. The cells of this column display dates in ordinary text box cells, but when the user edits a cell, a DateTimePicker control appears. In order to avoid having to implement text box display functionality again, the CalendarCell class derives from the DataGridViewTextBoxCell class rather than inheriting the DataGridViewCell class directly.

NoteNote:
When you derive from DataGridViewCell or DataGridViewColumn and add new properties to the derived class, be sure to override the Clone method to copy the new properties during cloning operations. You should also call the base class’s Clone method so that the properties of the base class are copied to the new cell or column.

Example

C#
using System;
using System.Windows.Forms;
public class CalendarColumn : DataGridViewColumn
{
    public CalendarColumn() : base(new CalendarCell())
    {
    }
    public override DataGridViewCell CellTemplate
    {
        get
        {
            return base.CellTemplate;
        }
        set
        {
            // Ensure that the cell used for the template is a CalendarCell.
            if (value != null &&
                !value.GetType().IsAssignableFrom(typeof(CalendarCell)))
            {
                throw new InvalidCastException("Must be a CalendarCell");
            }
            base.CellTemplate = value;
        }
    }
}
public class CalendarCell : DataGridViewTextBoxCell
{
    public CalendarCell()
        : base()
    {
        // Use the short date format.
        this.Style.Format = "d";
    }
    public override void InitializeEditingControl(int rowIndex, object
        initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
    {
        // Set the value of the editing control to the current cell value.
        base.InitializeEditingControl(rowIndex, initialFormattedValue,
            dataGridViewCellStyle);
        CalendarEditingControl ctl =
            DataGridView.EditingControl as CalendarEditingControl;
        ctl.Value = (DateTime)this.Value;
    }
    public override Type EditType
    {
        get
        {
            // Return the type of the editing contol that CalendarCell uses.
            return typeof(CalendarEditingControl);
        }
    }
    public override Type ValueType
    {
        get
        {
            // Return the type of the value that CalendarCell contains.
            return typeof(DateTime);
        }
    }
    public override object DefaultNewRowValue
    {
        get
        {
            // Use the current date and time as the default value.
            return DateTime.Now;
        }
    }
}
class CalendarEditingControl : DateTimePicker, IDataGridViewEditingControl
{
    DataGridView dataGridView;
    private bool valueChanged = false;
    int rowIndex;
    public CalendarEditingControl()
    {
        this.Format = DateTimePickerFormat.Short;
    }
    // Implements the IDataGridViewEditingControl.EditingControlFormattedValue 
    // property.
    public object EditingControlFormattedValue
    {
        get
        {
            return this.Value.ToShortDateString();
        }
        set
        {
            if (value is String)
            {
                this.Value = DateTime.Parse((String)value);
            }
        }
    }
    // Implements the 
    // IDataGridViewEditingControl.GetEditingControlFormattedValue method.
    public object GetEditingControlFormattedValue(
        DataGridViewDataErrorContexts context)
    {
        return EditingControlFormattedValue;
    }
    // Implements the 
    // IDataGridViewEditingControl.ApplyCellStyleToEditingControl method.
    public void ApplyCellStyleToEditingControl(
        DataGridViewCellStyle dataGridViewCellStyle)
    {
        this.Font = dataGridViewCellStyle.Font;
        this.CalendarForeColor = dataGridViewCellStyle.ForeColor;
        this.CalendarMonthBackground = dataGridViewCellStyle.BackColor;
    }
    // Implements the IDataGridViewEditingControl.EditingControlRowIndex 
    // property.
    public int EditingControlRowIndex
    {
        get
        {
            return rowIndex;
        }
        set
        {
            rowIndex = value;
        }
    }
    // Implements the IDataGridViewEditingControl.EditingControlWantsInputKey 
    // method.
    public bool EditingControlWantsInputKey(
        Keys key, bool dataGridViewWantsInputKey)
    {
        // Let the DateTimePicker handle the keys listed.
        switch (key & Keys.KeyCode)
        {
            case Keys.Left:
            case Keys.Up:
            case Keys.Down:
            case Keys.Right:
            case Keys.Home:
            case Keys.End:
            case Keys.PageDown:
            case Keys.PageUp:
                return true;
            default:
                return !dataGridViewWantsInputKey;
        }
    }
    // Implements the IDataGridViewEditingControl.PrepareEditingControlForEdit 
    // method.
    public void PrepareEditingControlForEdit(bool selectAll)
    {
        // No preparation needs to be done.
    }
    // Implements the IDataGridViewEditingControl
    // .RepositionEditingControlOnValueChange property.
    public bool RepositionEditingControlOnValueChange
    {
        get
        {
            return false;
        }
    }
    // Implements the IDataGridViewEditingControl
    // .EditingControlDataGridView property.
    public DataGridView EditingControlDataGridView
    {
        get
        {
            return dataGridView;
        }
        set
        {
            dataGridView = value;
        }
    }
    // Implements the IDataGridViewEditingControl
    // .EditingControlValueChanged property.
    public bool EditingControlValueChanged
    {
        get
        {
            return valueChanged;
        }
        set
        {
            valueChanged = value;
        }
    }
    // Implements the IDataGridViewEditingControl
    // .EditingPanelCursor property.
    public Cursor EditingPanelCursor
    {
        get
        {
            return base.Cursor;
        }
    }
    protected override void OnValueChanged(EventArgs eventargs)
    {
        // Notify the DataGridView that the contents of the cell
        // have changed.
        valueChanged = true;
        this.EditingControlDataGridView.NotifyCurrentCellDirty(true);
        base.OnValueChanged(eventargs);
    }
}
public class Form1 : Form
{
    private DataGridView dataGridView1 = new DataGridView();
    [STAThreadAttribute()]
    public static void Main()
    {
        Application.Run(new Form1());
    }
    public Form1()
    {
        this.dataGridView1.Dock = DockStyle.Fill;
        this.Controls.Add(this.dataGridView1);
        this.Load += new EventHandler(Form1_Load);
        this.Text = "DataGridView calendar column demo";
    }
    private void Form1_Load(object sender, EventArgs e)
    {
        CalendarColumn col = new CalendarColumn();
        this.dataGridView1.Columns.Add(col);
        this.dataGridView1.RowCount = 5;
        foreach (DataGridViewRow row in this.dataGridView1.Rows)
        {
            row.Cells[0].Value = DateTime.Now;
        }
    }
}

Ref: http://msdn.microsoft.com/en-us/library/7tas5c80.aspx

| More
VN:F [1.6.7_924]
Rating: 0.0/10 (0 votes cast)
VN:F [1.6.7_924]
Rating: 0 (from 0 votes)

Post to Twitter

2010
02.25
Literals (Entity SQL)

This topic describes Entity SQL support for literals.

Null

The null literal is used to represent the value null for any type. A null literal is compatible with any type.

Typed nulls can be created by a cast over a null literal. For more information, see CAST (Entity SQL).

For rules about where free floating null literals can be used, see Null Literals and Type Inference (Entity SQL).

Boolean

Boolean literals are represented by the keywords true and false.

Integer

Integer literals can be of type Int32 or Int64. An Int32 literal is a series of numeric characters. An Int64 literal is series of numeric characters followed by an uppercase L.

Decimal

A fixed-point number (decimal) is a series of numeric characters, a dot (.) and another series of numeric characters followed by an uppercase “M”.

Float, Double

A double-precision floating point number is a series of numeric characters, a dot (.) and another series of numeric characters possibly followed by an exponent. A single-precisions floating point number (or float) is a double-precision floating point number syntax followed by the lowercase f.

String

A string is a series of characters enclosed in quote marks. Quotes can be either both single-quotes (') or both double-quotes (”). Character string literals can be either Unicode or non-Unicode. To declare a character string literal as Unicode, prefix the literal with an uppercase “N”. The default is non-Unicode character string literals. There can be no spaces between the N and the string literal payload, and the N must be uppercase.

'hello' -- non-Unicode character string literal
N'hello' -- Unicode character string literal
"x"
N"This is a string!"
'so is THIS'

DateTime

A datetime literal is independent of locale and is composed of a date part and a time part. Both date and time parts are mandatory and there are no default values.

The date part must have the format: YYYY-MM-DD, where YYYY is a four digit year value between 0001 and 9999, MM is the month between 1 and 12 and DD is the day value that is valid for the given month MM.

The time part must have the format: HH:MM[:SS[.fffffff]], where HH is the hour value between 0 and 23, MM is the minute value between 0 and 59, SS is the second value between 0 and 59 and fffffff is the fractional second value between 0 and 9999999. All value ranges are inclusive. Fractional seconds are optional. Seconds are optional unless fractional seconds are specified; in this case, seconds are required. When seconds or fractional seconds are not specified, the default value of zero will be used instead.

There can be any number of spaces between the DATETIME symbol and the literal payload, but no new lines.

DATETIME'2006-10-1 23:11'
DATETIME'2006-12-25 01:01:00.0000000' -- same as DATETIME'2006-12-25 01:01'

Time

A time literal is independent of locale and composed of a time part only. The time part is mandatory and there is no default value. It must have the format HH:MM[:SS[.fffffff]], where HH is the hour value between 0 and 23, MM is the minute value between 0 and 59, SS is the second value between 0 and 59, and fffffff is the second fraction value between 0 and 9999999. All value ranges are inclusive. Fractional seconds are optional. Seconds are optional unless fractional seconds are specified; in this case, seconds are required. When seconds or fractions are not specified, the default value of zero will be used instead.

There can be any number of spaces between the TIME symbol and the literal payload, but no new lines.

TIME‘23:11’
TIME‘01:01:00.1234567’

DateTimeOffset

A datetimeoffset literal is independent of locale and composed of a date part, a time part, and an offset part. All date, time, and offset parts are mandatory and there are no default values. The date part must have the format YYYY-MM-DD, where YYYY is a four digit year value between 0001 and 9999, MM is the month between 1 and 12, and DD is the day value that is valid for the given month. The time part must have the format HH:MM[:SS[.fffffff]], where HH is the hour value between 0 and 23, MM is the minute value between 0 and 59, SS is the second value between 0 and 59, and fffffff is the fractional second value between 0 and 9999999. All value ranges are inclusive. Fractional seconds are optional. Seconds are optional unless fractional seconds are specified; in this case, seconds are required. When seconds or fractions are not specified, the default value of zero will be used instead. The offset part must have the format {+|-}HH:MM, where HH and MM have the same meaning as in the time part. The range of the offset, however, must be between -14:00 and + 14:00

There can be any number of spaces between the DATETIMEOFFSET symbol and the literal payload, but no new lines.

DATETIMEOFFSET‘2006-10-1 23:11 +02:00’
DATETIMEOFFSET‘2006-12-25 01:01:00.0000000 -08:30’
NoteNote
A valid Entity SQL literal value can fall outside the supported ranges for CLR or the data source. This might result in an exception

Binary

A binary string literal is a sequence of hexadecimal digits delimited by single quotes following the keyword binary or the shortcut symbol X. Note that as a keyword, binary is case insensitive. Also, zero or more spaces are allowed between the keyword binary and the binary string value.

The shortcut symbol X must be uppercase and cannot have any spaces between the symbol X and the binary string. Hexadecimal characters are also case insensitive. If the literal is composed of an odd number of hexadecimal digits, the literal will be aligned to the next even hexadecimal digit by prefixing the literal with a hexadecimal zero digit. There is no formal limit on the size of the binary string.

There can be no spaces between the X symbol and the string literal payload, and X must be uppercase. There can be any number of spaces between the BINARY symbol and the literal payload, but no new lines.

Binary'00ffaabb'
X'ABCabc'
BINARY    '0f0f0f0F0F0F0F0F0F0F'
X'' –- empty binary string

Guid

A GUID literal represents a globally unique identifier. It is a sequence formed by the keyword GUID followed by hexadecimal digits in the form known as registry format: 8-4-4-4-12 enclosed in single quotes. Hexadecimal digits are case insensitive.

There can be any number of spaces between the GUID symbol and the literal payload, but no new lines.

Guid'1afc7f5c-ffa0-4741-81cf-f12eAAb822bf'
GUID  '1AFC7F5C-FFA0-4741-81CF-F12EAAB822BF'

Ref: http://msdn.microsoft.com/en-us/library/bb399176.aspx

| More
VN:F [1.6.7_924]
Rating: 0.0/10 (0 votes cast)
VN:F [1.6.7_924]
Rating: 0 (from 0 votes)

Post to Twitter

2010
02.08

Unlike most projects you create in Visual Studio, Windows Service projects cannot be run directly from the development environment by pressing F5. This is because the service in the project must be installed before the project can run.

You can quickly install your service application by using a command-line utility called InstallUtil.exe. You can also create a setup project that contains your project’s output and create a custom action with it that will run the installers associated with the project and install your service. For an example, see Walkthrough: Creating a Windows Service Application in the Component Designer. For more information on setup projects, see Setup Projects. For more information on custom actions, see Walkthrough: Creating a Custom Action.

To install your service manually

  1. Access the directory in which your project’s compiled executable file is located.
  2. Run InstallUtil.exe from the command line with your project’s output as a parameter. Enter the following code on the command line:
    installutil yourproject.exe

To uninstall your service manually

Run InstallUtil.exe from the command line with your project’s output as a parameter. Enter the following code on the command line:

installutil /u yourproject.exe
NoteTip
You can launch Server Explorer and verify that your service has been installed or uninstalled. For more information, see How to: Access and Initialize Server Explorer/Database Explorer.

Ref: http://msdn.microsoft.com/en-us/library/sd8zc8ha%28VS.80%29.aspx

| More
VN:F [1.6.7_924]
Rating: 0.0/10 (0 votes cast)
VN:F [1.6.7_924]
Rating: 0 (from 0 votes)

Post to Twitter

2010
02.02

Entity Framework Toolkits & Extensions

Source code libraries and design time tools that extend the reach and augment the development experience of the Entity Framework.

EF Extensions Compatible with .NET Framework 3.5 SP1 and Visual Studio 2008 SP1 (Visual Basic and C# versions available)
The ADO.NET Entity Framework Extensions library includes utilities that make querying stored procedures, creating typed results from DB data readers and state tracking external data much easier in the Entity Framework. A sample application demonstrates several patterns using these utilities, including stored procedures with multiple result sets, materialization of CLR types, and registering entities in the Entity Framework state manager.

eSqlBlast (Entity SQL Tools and Samples Page) Compatible with .NET Framework 3.5 SP1 and Visual Studio 2008 SP1
eSqlBlast aids authoring, executing, and visualizing ad-hoc Entity SQL queries against arbitrary EDM models. The tools of the eSqlBlast suite may be used interactively, from the command line, or embedded in other programs. The eSqlBlast suite also contains XSL transformation scripts for rendering CSDL and its own raw XML format.

Entity Framework Lazy Loading Compatible with .NET Framework 3.5 SP1 and Visual Studio 2008 SP1 (Visual Basic and C# versions available)
This sample shows how to use code generation to add support for transparent lazy loading to Entity Framework. It includes code generator (EFLazyClassGen), supporting library (Microsoft.Data.EFLazyLoading) and sample test applications.

EdmGen2.exe Compatible with .NET Framework 3.5 SP1 and Visal Studio 2008 SP1
EdmGen2 is a command-line tool for the Microsoft ADO.NET Entity Framework that is able to read and write the EDMX file format, as well as translate between EDMX and CSDL, SSDL & MSL file formats.

Persistence Ignorance (POCO) Adapter for Entity Framework V1 Compatible with .NET Framework 3.5 SP1 and Visual Studio 2008 SP1 (Visual Basic and C# versions available)
EF POCO Adapter enables Plain Old CLR Objects (POCOs) to be tracked using released version of Entity Framework V1 using automatically generated adapter objects. It consist of a code generator, supporting library and a test suite and examples.

Tracing and Caching Provider Wrappers for Entity Framework Compatible with .NET Framework 3.5 SP1, Visual Studio 2008 SP1 and Visual Studio 2010 Beta1
Demonstrates how to implement wrapping providers which add interesting functionality (caching and tracing) to an EF application.

ADO.NET Entity Data Model Designer Extension Starter Kit Compatible with Visual Studio 2010 Beta 2
The ADO.NET Entity Data Model Designer Extension Starter Kit is a Visual Studio project template that helps you understand how to extend the functionality of the ADO.NET Entity Data Model Tools. The project template provides you with a custom Visual Studio project type (ADO.NET Entity Designer Extension Starter Kit) that uses classes in the Microsoft.Data.Entity.Design.Extensibility namespace to build a Visual Studio extension that you can deploy and test.

Entity Framework Samples

Sample source code and projects showing how specific tasks can be completed using the Entity Framework.

Hands-on-Lab: Using the Entity Framework in .NET 4 and Visual Studio 2010 Compatible with Visual Studio 2010 Beta 2
Complete manual and sample code from the PDC 2009 Hands-on-Lab for ADO.NET Entity Framework. Downloadable in PDF and XPS formats.

Sample Entity Framework Provider for Oracle Compatible with .NET Framework 3.5 SP1 and Visual Studio 2008 SP1
This Sample Provider works with Oracle 10g by wrapping System.Data.OracleClient APIs. It uses the same technique as Entity Framework Sample Provider which wraps System.Data.SqlClient. Sample Entity Framework Provider for Oracle is compatible with Entity Framework released as part of .NET Framework 3.5 SP1. Its goal is to showcase some techniques that provider writers targeting database engines other than SQL Server can use. This is just a sample and its use in a production environment is strongly discouraged.

Entity Framework Documentation Samples Compatible with .NET Framework 3.5 SP1 and Visual Studio 2008 SP1
The ADO.NET Entity Framework samples that accompany the Entity Framework documentation on MSDN. This is the download location for the CourseManager project that you create when you complete the Entity Framework quickstart. You will also find other Entity Data Model tools walkthrough projects as well as the samples described in the Entity Framework documenation.

Entity Framework Sample Provider Compatible with .NET Framework 3.5 SP1 and Visual Studio 2008 SP1
The Sample Provider wraps System.Data.SqlClient and demonstrates the new functionality an ADO.NET Provider needs to implement in order to support the ADO.NET Entity Framework

    • Provider Manifest
    • EDM Mapping for Schema Information
    • SQL Generation

Entity Framework Query Samples Compatible with Visual Studio 2008 SP1 (Visual Basic and C# versions available), and Visual Studio 2010 Beta 2
The Entity Framework Query Samples is a small Windows Forms program that contains several basic Entity SQL and LINQ to Entities queries against that NorthwindEF Entity Data Model (based on a modified version of Northwind).
Its goal is to help you learn the features of the two query languages supported by EF and visualize how the results and the translated store query look like.

Entity Data Model Metadata Samples Compatible with .NET Framework 3.5 SP1 and Visual Studio 2008 SP1
EDM Metadata Samples is a small web application that you can use to explore Entity Framework’s metadata API and the Entity Data Model.

Sample EDMX Code Generator
The goal of the Sample EDMX Code Generator is to provide you with enough insight into how the ADO.NET Entity Designer generates code in Visual Studio and hopefully give you a head start with some sample source code.

SketchPad
A simple drawing editor that allows you to create elementary geometric shapes–lines and circles–and model them as entities using either the Entity Framework or LINQ to SQL. Think of it as a ‘Notepad for Shapes’–you can create, read, and delete shapes, and use the built-in spatial index to search for entities by attribute value. A command-line argument allows you to switch between the Entity Framework and LINQ to SQL runtime for the model.

LINQ to SQL Samples

TPT Inheritance with LINQ to SQL
This sample demonstrates a technique for implementing the TPT (Table per Type) object mapping model in a LINQ to SQL context.

SketchPad
A simple drawing editor that allows you to create elementary geometric shapes–lines and circles–and model them as entities using either the Entity Framework or LINQ to SQL. Think of it as a ‘Notepad for Shapes’–you can create, read, and delete shapes, and use the built-in spatial index to search for entities by attribute value. A command-line argument allows you to switch between the Entity Framework and LINQ to SQL runtime for the model.

Entity Framework Learning Tools

Tools that help you in learning Entity Framework concepts.

EF Mapping Helper
Entity Framework mapping helper lets you create sample mapping files for the set of scenarios you are interested in. It’s a great tool for a deeper understanding for how schema files are defined for complex mapping scenarios in Entity Framework.

Ref: http://code.msdn.microsoft.com/adonetefx/

| More
VN:F [1.6.7_924]
Rating: 0.0/10 (0 votes cast)
VN:F [1.6.7_924]
Rating: 0 (from 0 votes)

Post to Twitter

2009
12.15

How to render modules in Joomla

<?php

jimport('joomla.application.module.helper');
// get all modules in specific position
$modules = JModuleHelper::getModules('position');
$module = $modules[0];
// get a module
$module = JModuleHelper::getModule( 'module_name', 'module_title' );
$attribs['style'] = 'xhtml';
$html  = $module->renderModule($module, $attribs);   // 2nd parameter is optional
?>
| More
VN:F [1.6.7_924]
Rating: 5.0/10 (1 vote cast)
VN:F [1.6.7_924]
Rating: 0 (from 0 votes)

Post to Twitter

2009
11.14

Free flv player

JW FLV Media player the world’s most popular open source player. It supports FLV, MP3, MP4 & AAC; it’s Plugin-extensible;. Module for Joomla, Drupal, Wordpress is also available

http://www.longtailvideo.com/cms/#OVP

| More
VN:F [1.6.7_924]
Rating: 0.0/10 (0 votes cast)
VN:F [1.6.7_924]
Rating: 0 (from 0 votes)

Post to Twitter

2009
11.14

Accessible objects in module

Following objects are directly accessible in Joomla Modules:

  • $params (JParameter)
  • $module (Database object from the module table)
| More
VN:F [1.6.7_924]
Rating: 0.0/10 (0 votes cast)
VN:F [1.6.7_924]
Rating: 0 (from 0 votes)

Post to Twitter

2009
10.29

Bangla Unicode Converter

I was looking for an unicode bangla converter. I found following converters to convert normal bangla text to unicode text:

And some other desktop, but none of them can convert formatted text like word document or html formatted bangla text. So I have decided to write a web application which can convert html formatted bangla text. Check the converter here:

http://bangla-unicode-converter.technovilla.net/

| More
VN:F [1.6.7_924]
Rating: 0.0/10 (0 votes cast)
VN:F [1.6.7_924]
Rating: 0 (from 0 votes)

Post to Twitter

2009
10.01

Linux command: chmod

chmod [OPTION]… MODE[,MODE]… FILE
chmod [OPTION]… OCTAL-MODE FILE
chmod [OPTION]… –reference=RFILE FILE… 

To change files, folders permission recursively use “-R” option.

Example: chmod 755 * -R

| More
VN:F [1.6.7_924]
Rating: 0.0/10 (0 votes cast)
VN:F [1.6.7_924]
Rating: -1 (from 1 vote)

Post to Twitter