Tuesday, December 25, 2012

overlaping two date periods

to return an action with start and end date in case overlapped with a given date range

"( (@ActionDateFrom is null) or (@ActionDateFrom !> TruncateTime(it.Action1.ActionEndDate)))

and ( (@ActionDateTo is null) or (@ActionDateTo !< TruncateTime(it.Action1.ActionStartDate)))"

Monday, December 3, 2012

use EntityFrame work from aspx page

to use EntityFramework objects from the aspx page,
you have to:

  1. add System.Entity.Data Dll to the references of the project
  2. add your EntityFramework Dll to the references  if there is one
  3. use "using" in code behind
  4. and finally add the following section to your web.config file
<system.web>
    <compilation debug="true" targetFramework="4.0" >
      <assemblies>
        <add assembly="System.Data.Entity, Version=3.5.0.0, Culture=neutral,
        PublicKeyToken=b77a5c561934e089"/>
      </assemblies
    </compilation>
..............
</system.web>  

Access data directly from EntityDataSource


At a client I recently found myself wondering how one can access the data an EntityDataSource returns.
For most applications this scenario does not come up, but I was now curious so I couldn’t just let it go.
I should point out right away that the easiest way to get at the data is to hook the “Selected” event of the EntityDataSource, then you can get the data like this:
protected void EntityDataSource1_Selected(object sender, EntityDataSourceSelectedEventArgs e)
 {
        List<Category> a = e.Results.Cast<Category>().ToList();
        string s = a[1].CategoryName;

 }
(supposing you have an entity/table named Category).
Now that is all fine, but how do you trigger the data to be fetched (execute the Select command) without involving a data bound control like a GridView.
The key lies in being able to cast an EntityDataSource as an IDataSource, and then executing “GetView” from that interface to return a DataSourceView, which can then be made to return a strongly typed list of entities.
The use of the EntityDataSourceReader is as follows:
EntityDataSourceReader<Category> dataReader = new EntityDataSourceReader<Category>(EntityDataSource1);
List<Category> list =  dataReader.GetData();

Refference:
  • http://www.williamkent.net/archive/2011/03/03/programmatically-accessing-data-from-an-entitydatasource.aspx

Wednesday, October 17, 2012

sending XML message inside SOAP Body

 


<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <SubmitRequest xmlns="http://victorylink.com/">
      <message><![CDATA["<?xml version='1.0' encoding='utf-8'?><Requests><Request><Mobile>0100524525478888182</Mobile><PinCode>0326</PinCode></Request></Requests>"]]></message>
    </SubmitRequest>
  </soap:Body>
</soap:Envelope>

Tuesday, October 9, 2012

Write to Event log using c#

using System;
using System.Diagnostics;

namespace WriteToAnEventLog_csharp
{
/// Summary description for Class1.
class Class1
{
static void Main(string[] args)
{
string sSource;
string sLog;
string sEvent;

sSource = "dotNET Sample App";
sLog = "Application";
sEvent = "Sample Event";

if (!EventLog.SourceExists(sSource))
EventLog.CreateEventSource(sSource,sLog);

EventLog.WriteEntry(sSource,sEvent);
EventLog.WriteEntry(sSource, sEvent,
EventLogEntryType.Warning, 234);
}
}
}