Wednesday, January 22, 2014

ANDROID : Set Red Green and Blue BackGround Color Using SeekBar.

.xml

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/myScreen"
>

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="RED" />

    <SeekBar
        android:id="@+id/seekBar1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:max="255"
        android:progress="0" />

    <TextView
        android:id="@+id/countred"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="0" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="GREEN" />

    <SeekBar
        android:id="@+id/seekBar2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:max="255"
        android:progress="0" />

    <TextView
        android:id="@+id/countgreen"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="0" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="BLUE" />

    <SeekBar
        android:id="@+id/seekBar3"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:max="255"
        android:progress="0" />

    <TextView
        android:id="@+id/countblue"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="0" />

</LinearLayout>



.JAVA

 package com.bhavesh.colorchooser;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;


public class MainActivity extends Activity {

   
    SeekBar seekred,seekgreen,seekblue;
    LinearLayout layout1;
    TextView countred,countgreen,countblue;
  
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
      
        seekred=(SeekBar)findViewById(R.id.seekBar1);
        seekgreen=(SeekBar)findViewById(R.id.seekBar2);
        seekblue=(SeekBar)findViewById(R.id.seekBar3);
        layout1=(LinearLayout)findViewById(R.id.myScreen);
       
        countred=(TextView)findViewById(R.id.countred);
        countgreen=(TextView)findViewById(R.id.countgreen);
        countblue=(TextView)findViewById(R.id.countblue);
       
       
       
        seekred.setOnSeekBarChangeListener(ChangeColor);
        seekgreen.setOnSeekBarChangeListener(ChangeColor);
        seekblue.setOnSeekBarChangeListener(ChangeColor);
    }
       
    private OnSeekBarChangeListener ChangeColor=new OnSeekBarChangeListener() {
           
            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
               
               
            }
           
            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
               
               
            }
           
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress,
                    boolean fromUser) {
       
               
                int R,G,B;
               
                 R = seekred.getProgress();
                 G = seekgreen.getProgress();
                 B = seekblue.getProgress();
                 layout1.setBackgroundColor(0xff000000 + R * 0x10000 + G * 0x100 + B);
               
                 countred.setText(String.valueOf(R));
                 countgreen.setText(String.valueOf(G));
                 countblue.setText(String.valueOf(B));
               
               
            }
    };

   

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
       
       
       
       
       
    }
   
}

Insert Data Into Excel Sql Server 2008

INSERT INTO OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0';'Database=@myfile';,'SELECT *  FROM [@SheetName]')

Tuesday, January 21, 2014

LINQ on Datatable Find where all rows are empty ans remove asp.net

Just move the NOT (!) out one level. You want the items where "all rows are null" is not true, rather than where "all of the rows are not null" is true.
DataTable filteredRows = dt.Rows.Cast<DataRow>()
    .Where(row => !row.ItemArray.All(field => field is System.DBNull))
    .CopyToDataTable();

Monday, January 20, 2014

Loading, Editing, and Saving a Text File in HTML5 Using Javascript

<html>
<body>

<table>
 <tr><td>Text to Save:</td></tr>
 <tr>
  <td colspan="3">
   <textarea id="inputTextToSave" style="width:512px;height:256px"></textarea>
  </td>
 </tr>
 <tr>
  <td>Filename to Save As:</td>
  <td><input id="inputFileNameToSaveAs"></input></td>
  <td><button onclick="saveTextAsFile()">Save Text to File</button></td>
 </tr>
 <tr>
  <td>Select a File to Load:</td>
  <td><input type="file" id="fileToLoad"></td>
  <td><button onclick="loadFileAsText()">Load Selected File</button><td>
 </tr>
</table>

<script type='text/javascript'>

function saveTextAsFile()
{
 var textToWrite = document.getElementById("inputTextToSave").value;
 var textFileAsBlob = new Blob([textToWrite], {type:'text/plain'});
 var fileNameToSaveAs = document.getElementById("inputFileNameToSaveAs").value;

 var downloadLink = document.createElement("a");
 downloadLink.download = fileNameToSaveAs;
 downloadLink.innerHTML = "Download File";
 if (window.webkitURL != null)
 {
  // Chrome allows the link to be clicked
  // without actually adding it to the DOM.
  downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob);
 }
 else
 {
  // Firefox requires the link to be added to the DOM
  // before it can be clicked.
  downloadLink.href = window.URL.createObjectURL(textFileAsBlob);
  downloadLink.onclick = destroyClickedElement;
  downloadLink.style.display = "none";
  document.body.appendChild(downloadLink);
 }

 downloadLink.click();
}

function destroyClickedElement(event)
{
 document.body.removeChild(event.target);
}

function loadFileAsText()
{
 var fileToLoad = document.getElementById("fileToLoad").files[0];

 var fileReader = new FileReader();
 fileReader.onload = function(fileLoadedEvent) 
 {
  var textFromFileLoaded = fileLoadedEvent.target.result;
  document.getElementById("inputTextToSave").value = textFromFileLoaded;
 };
 fileReader.readAsText(fileToLoad, "UTF-8");
}

</script>

</body>
</html>

Simple way to export SQL Server data to Text Files

EXEC xp_cmdshell 'bcp "SELECT * FROM ACESRepView.Users.XmlData" queryout "d:\data.txt" -S "server name" -U username  -P  passwrd -c'

write text file in sql server 2008

DECLARE @cmd varchar(256), @var varchar(50)
SET @var = 'Hello world!' +CHAR(13)+CHAR(10)+ 'This is second line'
print @var
SET @cmd = 'echo>d:\myfile.txt ' + @var 
EXEC master..xp_cmdshell @cmd, no_output

Enable 'xp_cmdshell' SQL Server

-- To allow advanced options to be changed.
EXEC sp_configure 'show advanced options', 1
GO
-- To update the currently configured value for advanced options.
RECONFIGURE
GO
-- To enable the feature.
EXEC sp_configure 'xp_cmdshell', 1
GO
-- To update the currently configured value for this feature.
RECONFIGURE
GO

Opps Part 1 : Abstraction

  Abstraction in C# is a fundamental concept of object-oriented programming (OOP) that allows developers t...