Tuesday, September 27, 2011

Android: Load image from web


public Bitmap getRemoteImage(final URL aURL) {
      try {
            final URLConnection conn = aURL.openConnection();
            conn.connect();
            final BufferedInputStream bis = new BufferedInputStream(conn.getInputStream());
            final Bitmap bm = BitmapFactory.decodeStream(bis);
            bis.close();
            return bm;
      } catch (IOException e) {
            [...]
      }
      return null;
}

Tuesday, September 20, 2011

DataTable sorting

Sort a DataTable is a very simple activity:


[VB.Net]
dt.DefaultView.Sort = "ColumnName"  'normal DataTable 

ds.Tables("TableName").DefaultView.Sort = "ColumnName"  'DataTable in DataSet


[C#]
dt.DefaultView.Sort = "ColumnName"  'normal DataTable

ds.Tables["TableName"].DefaultView.Sort = "ColumnName"  'DataTable in DataSet


With this snippet you don't "physically" order the content of the DataTable but it's default view. But for data visualization purpose and other the result is the same.
Using this DataTable, for example, as datasource for a GridView the list will be sorted based of the used criteria (ColumName).

UpdateProgress dinamically centered



<script language="JavaScript" type="text/javascript">
        function adjustDivs() {           
            internal= document.getElementById('divCalculateInt');
            external= document.getElementById('divCalculate');
            dfs = interno.style;
           
            dfs.left = (external.innerWidth - internal.offsetWidth) / 2;
        }

        window.onload = adjustDivs;
        window.onresize = adjustDivs;
        window.onscroll = adjustDivs;
<script>

<asp:UpdatePanel ID="updXXX" runat="server">
<ContentTemplate>
       […]
<ContentTemplate>
<asp:UpdatePanel>

<asp:UpdateProgress ID="updprogXXX" runat="server" AssociatedUpdatePanelID="updXXX" DisplayAfter="150">
<ProgressTemplate>
             <div id="divCalculate" align="center" style="top: 200px; position: absolute; top:0; bottom:0; right:0; left:0;background-color:rgba(0,0,0,0.5)">
                    <div id="divCalculateInt" align="center" style="border: solid 1px #000000; background: #FFFFFF;padding: 5px; width: 320px; height: 50px;margin-top:300px">
                        <asp:Label runat="server" ID="lblLoading2" Text="Computing in progress..."><asp:Label>
                        <asp:Image ID="imgLoading" runat="server" ImageAlign="left" SkinID="imgLoadingBar" /><br /><br />
                        <asp:Label runat="server" ID="lblLoadingInfo" Text="This operation may last some minutes" Font-Size="X-Small" >asp:Label>
                    <div>
                <div>               
        <ProgressTemplate>
<asp:UpdateProgress>

Wednesday, May 4, 2011

Using C# and VB.net togheter in Asp.net

To use in the same Asp.net Web Application classes written in different languages, such C# and VB.net, you have to do this steps:

Create in the App_Code folder two subfolder, called for example VB and CS:

App_Code
->VB
->CS

Next, add in the web.config this lines:
<system.web>
[...]
<compilation>
<codeSubDirectories>
<
add directoryName="CS"/>
<add directoryName="VB"/>
codeSubDirectories>
[...]
compilation>
system.web>

And voila, its done!

PS: obviously, you have to put all vb.net classes in a folder and all the c# classes in the other folder...

Monday, December 6, 2010

SQL Server 2008 Log File Shrink for all databases on a server

After my previous post (24 june 2009), in which I proposed a script to Shrink log Files for all DB in a SQL Server 2005 machine, now you've got a script to do the same thing on SQL Server 2008 servera:

EXECUTE sp_msforeachdb
'USE ?;

Alter Database ? Set Recovery Simple;
Alter Database ? Set Recovery Full;

DECLARE @LogLogicalName nvarchar(100);
SELECT @LogLogicalName = file_name(2);

dbcc shrinkfile(@LogLogicalName, 1);

dbcc shrinkfile(@LogLogicalName, 1);

dbcc shrinkfile(@LogLogicalName, 1);

dbcc shrinkfile(@LogLogicalName, 1);'