14 Mart 2013 Perşembe

radgrid - export

It is fairly easy to export a radgrid content in various formats.
here is sample code:

<telerik:RadGrid ID="GridRaporListe" AllowFilteringByColumn="true" AutoGenerateColumns="false"
PageSize="10000" AllowPaging="True" AllowSorting="True" runat="server" ShowGroupPanel="false"
OnItemCreated="GridRaporListe_ItemCreated" AllowMultiRowSelection="true" ClientSettings-AllowColumnHide="True"
ClientSettings-AllowColumnsReorder="True">
<ClientSettings EnableRowHoverStyle="true">
<Selecting AllowRowSelect="False"></Selecting>
</ClientSettings>
<PagerStyle Mode="NextPrevAndNumeric" />
<GroupingSettings CaseSensitive="false" />
<MasterTableView TableLayout="Fixed" DataKeyNames="ID" CommandItemDisplay="TopAndBottom">
<CommandItemSettings ShowExportToExcelButton="true" ShowExportToPdfButton="true"
ShowExportToWordButton="true" ShowExportToCsvButton="true" ShowRefreshButton="false"
ShowAddNewRecordButton="false"></CommandItemSettings>
<Columns>
<telerik:GridBoundColumn HeaderText="OgretimYili" DataField="OgretimYili" UniqueName="OgretimYili"
SortExpression="OgretimYili" HeaderStyle-Width="100px" />
<telerik:GridBoundColumn HeaderText="Donem" DataField="Donem" UniqueName="Donem"
SortExpression="Donem" HeaderStyle-Width="100px" />
</Columns>
</MasterTableView>
<ExportSettings FileName="Rapor">
<Excel Format="Html"></Excel>
</ExportSettings>
<ClientSettings AllowDragToGroup="true">
</ClientSettings>
</telerik:RadGrid>


7 Mart 2013 Perşembe

allow postgresql connection without password

I am trying to run a thesis project on my local environment. In order to achieve this, i installed postgresql (v9.2) and have to connect it with my computer's user name and no password! (it is not possible to change the code in jar file and the configuration file is missing!) To accomplish this:
- i added a login role (by using pgAdmin GUI) with my computer's name and defined it with no password
- i edited pg_hba.conf file as follows:

host    all     all    127.0.0.1/32  md5trust




18 Şubat 2013 Pazartesi

pictureBox usage (Telerik reports)

http://www.telerik.com/help/reporting/report-items-picture-box.html  explains how to use a pictureBox component pretty well. In my case, the photograph of the user is loaded to the pictureBox component dynamically. In order to accomplish this the first step is reading the photo from the photograph database:

1:  public static MemoryStream connectDbGetPhoto(string queryParam)  
2:      {  
3:        // open a connection to the database  
4:        SqlConnection dbCon = new SqlConnection(ConfigurationManager.ConnectionStrings[SauConstants.PHOTO_DATABASE].ConnectionString);  
5:        try  
6:        {  
7:          dbCon.Open();   
9:          StringBuilder query = new StringBuilder(" SELECT Resim from Resimler WHERE UserId = " + queryParam);  
10:          SqlDataAdapter adapter = new SqlDataAdapter(query.ToString(), dbCon);  
11:          DataSet ds = new DataSet();  
12:          adapter.Fill(ds);  
13:          DataTable dt = new DataTable();  
14:          dt = ds.Tables[0];  
15:          byte[] barrImg = (byte[])dt.Rows[0]["Resim"];  
16:          MemoryStream mstream = new MemoryStream(barrImg);  
17:          return mstream;  
18:        }  
19:        catch (Exception e)  
20:        {  
21:          return null;  
22:        }  
23:        finally  
24:        {  
25:          dbCon.Close();  
26:        }  
27:      }  

Then the image is loaded to PictureBox component as follows:

1:  MemoryStream resim = connectDbGetPhoto(user.ID.ToString());  
2:  this.picResim.Value = Image.FromStream(resim);  

However, if the loaded photograph is too big for the pictureBox, layout problems arise as in http://www.programmersheaven.com/mb/VBasic/322240/322240/display-whole-picture-in-picture-box-or-formplease-help/  To solve this problem:

1:  this.picResim.Sizing = ImageSizeMode.ScaleProportional;  

By the way, i use http://codeformatter.blogspot.com/ for a while to format my source code and i strongly recommend it!!

13 Şubat 2013 Çarşamba

workaround for error "The version of SQL Server in use does not support datatype 'datetime2' "

http://stackoverflow.com/questions/316422/using-sql-server-2008-and-sql-server-2005-and-date-time
explains the error pretty well.
In short, the workaround is opening the .edmx file with notepad, searching for phrase ProviderManifestToken and replacing 2008 with 2005..

ProviderManifestToken="2005"

11 Ocak 2013 Cuma

RadGrid: format double with eval

In order to format double with eval :
 <telerik:GridTemplateColumn HeaderText="Ortalama" DataField="Ortalama" UniqueName="Ortalama"  
                         SortExpression="Ortalama" HeaderStyle-Width="80px" >  
                         <ItemTemplate>  
                           <%# String.Format("{0:f2}", DataBinder.Eval(Container.DataItem, "Ortalama"))%>  
                         </ItemTemplate>  
                       </telerik:GridTemplateColumn>  
the solution is from: http://stackoverflow.com/questions/5168592/force-a-string-to-2-decimal-places