Tuesday, January 30, 2018

Merge Multiple DataTable into Single DataTable C#

In this tutorial I will show you how to merge different DataTable in one DataTable.

Suppose you have 2 DataTable

DataTable 1

HcodeDescription
BH01Hierarchy 1
BH02Hierarchy 2

DataTable 2

LinesIDLineNameSequence
L01Company1
L02Group10
L03Department4


Now after merging the two datatable you want the result to be like this.

HcodeDescriptionLinesIDLineNameSequence
BH01Hierarchy 1L01Company1
BH02Hierarchy 2L02Group10
L03Department4

To accomplish this structure use the following code


void AddColumns(DataTable dt)
        {

            foreach (DataColumn dc in dt.Columns)
            {
                NewDt.Columns.Add(dc.ColumnName);
            }
        }

        DataTable Merge(DataSet ds)
        {
            int maxRows = 0;
            foreach (DataTable dt in ds.Tables)
            {
                AddColumns(dt);
                if (maxRows < dt.Rows.Count)
                    maxRows = dt.Rows.Count;
            }
            for (int i = 0; i < maxRows; i++)
            {
                DataRow drToAdd = NewDt.NewRow();
                NewDt.Rows.Add(drToAdd);
            }

            int CurrentRow = 0;

            int parentcount = 0;
            foreach (DataTable dt in ds.Tables)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    int colcount = 0;
                    foreach (DataColumn dc in dt.Columns)
                    {
                        NewDt.Rows[CurrentRow][colcount + parentcount] = dr[dc];

                        colcount++;
                    }
                    CurrentRow++;
                }
                CurrentRow = 0;
                parentcount += dt.Columns.Count;
            }
            return NewDt;
        }

Just call the Merge method and pass your DataSet.

The Above code will work on multiple DataTable, so if you have more than 2 Datatable it will just work fine

I hope it was informative for you and I would like to Thank you for reading.

Sunday, January 21, 2018

Samsung Galaxy S7 Edge ROOT (Exynos ONLY)

You can easily Root your S7 Edge (Exynos) by following my instructions! Running Android version 7 (Nougat)

DISCLAIMER: I AM NOT RESPONSIBLE IF YOU DAMAGE OR BRICK YOUR PHONE. THIS THREAD IS CLEARLY FOR THE: SAMSUNG GALAX7 S7 EDGE (EXYNOS) SM-G935*. THIS IS THE METHOD OF HOW I ROOTED MY S7 EDGE AND I WANTED TO SHARE THIS METHOD WITH YOU.


WARNING: BEFORE STARTING TO ROOT YOUR PHONE MAKE SURE YOU HAVE AT LEAST 50% BATTERY. IF THE BATTERY RUNS OUT WHILE ROOTING YOUR PHONE, YOU WILL END UP DAMAGING YOUR PHONE

To Root your S7 Edge you will need:

1. Your Galaxy S7 Edge(Exynos SM-G935*).

2. Your Laptop/PC

3. Files that will be given below.

Instructions:

1. Make sure you Enable USB Debugging and OEM Unlock From Developer setting. (To Enable Developer options you need to: Open settings>Scroll down and Press "About phone">Then you need to press "Build number" 6-7 times Until you see a Box saying that you Enabled Developer Options. Now go back and above the "About phone is where Developer Options are located)

2. Then you need to Download Odin and TWRP:


Download ODIN

Download TWRP

3. After you downloaded all files on your Laptop/PC, you need to unzip Odin3_v3.10.6.zip anywhere you want.

4. Then you need to Enter Download mode by Turning off your S7 edge and pressing Home + Vol. Down + Power button until you see The S7 Edge logo.

5. After booting to Download mode. Connect your phone to the PC and Open Odin. You should see a small box saying ID:COM and below a blue Box saying "0:[COM*]". If you don't see that then you will need to download Samsung USB Drivers

USB Drivers

6. After connecting your Phone to your Computer, Press the "AP" Button and select the TWRP Zip you downloded.

7. After selecting TWRP Press the start button and wait until the process completes. Do NOT Unplug your phone until you see the box above The COM box saying PASS with green background.

8. Then your Phone should boot into Recovery. After that boot your phone normally

NOTE: AFTER FLASHING TWRP YOUR PHONE MAY NOT READ THE INTERNAL STORAGE AND YOU WONT BE ABLE TO BOOT YOUR PHONE OR INSTALLANYTHING FROM INTERNAL STORAGE. TO FIX THAT JUST GO TO YOUR RECOVERY>WIPE>ADVANCED WIPE> TYPE YES. 

ADVANCED WIPE WILL WIPE ANYTHING FROM YOUR INTERNAL STORAGE INCLUDING: PHOTOS,VIDEOS,APPS,CONTACTS AND ANYTHING THAT IS INSIDE THE INTERNAL STORAGE

[MAKE SURE TO BACKUP EVERYTHING.]

9. After successfully booting your phone. Download the root Links:

Super SU

dm-verity and forced encryption disabler: 

10. After that, you need to move these two files you just downloaded to your External SD Card.

11. Now boot to Recovery by turning off your phone and after that press the Power button + Home Button + Vol. Up button until you see S7 Edge logo.

12. After you booted to Recovery swipe the Allow Modifications. Then you will need to Go to Install>Select Storage>Micro SD Card>Select SuperSU Zip> Add more zips>no-verity zip.

13. Then slide to Install

14. After installation completes Click "Reboot system". 

NOTE: Your phone should take 5-6 minutes to boot. Do NOT Turn your phone Off Until it boots Up.

Now your S7 Edge Should be rooted Now.

IF YOU HAVE ANY QUESTIONS ABOUT HOW TO INSTALL OR IF YOU HAVE ANY PROBLEMS INSTALLING. FEEL FREE TO PM ME. Thank's.


Thursday, August 17, 2017

How Progress bar in Android

Hello,
        In this tutorial I will show you how to show Progress bar in your Android App, so that while performing a time consuming task such as fetching data from a URL, you can show progress Dialog.

In Order to show a Progress bar follow these steps

1. Add Progress bar in your XML Layout  

 <ProgressBar  
       android:id="@+id/toolbarProgressBar"  
       style="?android:attr/progressBarStyleLarge"  
       android:layout_width="match_parent"  
       android:layout_height="wrap_content"  
       android:layout_centerHorizontal="true"  
       android:layout_centerVertical="true"  
       android:visibility="gone" />  

2. Now to show the progress bar

  progressBar=(ProgressBar) findViewById(R.id.toolbarProgressBar);  
       progressBar.setVisibility(View.VISIBLE);  
       progressBar.animate();  


3. To Stop the Progress bar

  progressBar.setVisibility(View.GONE);  


I hope it was informative for you, and I would like to Thank you for reading.

Thursday, July 27, 2017

How to use ADB Pull And ADB Push

Hello,
        In this tutorial I will show you how to use ADB pull and ADB push commands.

If you have already setup environment Path variable than simple execute CMD, otherwise go to folder where ADB command is and execute Command Prompt from there.

For me ADB command is in folder

C:\Users\muhammad.taqi\AppData\Local\Android\Sdk\platform-tools

To view connected devices type

ADB devices

How to Push Files into your Android Device

adb push e:\myfile.txt /storage/emulated/0/myfolder/myfile.txt

How to Pull Files into your Android Device

 adb pull /storage/emulated/0/myfolder/myfile.txt

This will copy file from you android device to the folder where ADB command is present.

I hope it was informative for you and I would like to thank you for reading.

Thursday, April 14, 2016

OnFocusOut Event on EditText Android Studio

We can check if EditText control has focus on or not using the following event.


txtFrom.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange (View v, boolean hasFocus) {
                     // Do Code here
            }
        });

I hope it was inforamtive for you and I would like to Thank you for reading

Saturday, April 9, 2016

Send Data Back and forth between Two Activities Android Studio

Hello,

In this tutorial I will demonstrate how to send data back and forth between two activities.

Consider two Activities

1. Home Activity        (This is the Launcher Activity)
2. Detail Activity

Our goal is to send data from Home Activity to Detail Activity, use that received data, concatenate some extra string in it and than send it back to Home Activity via Button click event

Home Activity Code


private void SendDataToDetailActivity () {
        EditText fn = (EditText) findViewById(R.id.txtfname);
        Intent obj = new Intent(this, Details.class);
        obj.putExtra("Name", fn.getText().toString());
        startActivityForResult(obj, 100);
    }

Now override the onActivityResult Method
@Override
    protected void onActivityResult (int requestCode, int resultCode, Intent data) {
        if (requestCode == 100) {

            if (resultCode == RESULT_OK) {

                Toast.makeText(Home.this, data.getStringExtra("result"), Toast.LENGTH_SHORT).show();
            }
        }
    }

Now in detail Activity Define the method
private void GetDetails() {

        TextView txtF = (TextView) findViewById(R.id.txtName);
        String Name = getIntent().getStringExtra("Name");
        Student objS = new Student(Name);
        Name = objS.getName();
        String[] ss = Name.split("!");
        txtF.setText(Name);
    }
Now to send data back to Home Activity use the following Method
public void NavigateToBack (View view) {
        String Name = getIntent().getStringExtra("Name");
        Intent obj = getIntent().putExtra("result", Name + " You just received a Message from Another Activity");
        setResult(RESULT_OK, obj);
        finish();

    }
I hope that it was informative for you and I would like to Thank you for reading.

Monday, March 21, 2016

Verify MD5 and SHA-1 cryptographic hash values

Hello,
         Today in this tutorial I'm gonna show you how you can verify MD5 and SHA-1 code of a file which you have downloaded form the Internet.

It is very usefull to verify MD5 and SHA-1 code to make sure that the file you just downloaded is not corrupted and altered by any mean.

So in order to check MD5 and SHA-1 code you will need to download a utility called

File Checksum Integrity Verifier (FCIV)

Download From Here

After downloading Extract it in a folder where your download files are.

Now open up your folder which contain your downloaded file Press shift + right click and select open command window from here.

now type fciv [Your Full File name] without brackets.

Example lets say we have a file called taqi.jpg now to check the code for this file type

fciv taqi.jpg

I hope that it was informative for you and I would like to Thank you for reading.

Saturday, February 20, 2016

Implement Gestures in Android Phone Android Studio

Hello everyone today I will be showing you how to capture touch events in your Android application

For detecting gesture you will need to import few classes in your code so import the following classes


1:  import android.view.MotionEvent;  
2:  import android.view.GestureDetector;  
3:  import android.support.v4.view.GestureDetectorCompat;  

You will also need to implement the following Interfaces

1. GestureDetector.OnGestureListener

2. GestureDetector.OnDoubleTapListener

Like this

1:  public class MainActivity extends AppCompatActivity implements GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener {  
Now we will need to implement all methods for these interfaces so press Alt + Insert this will list all methods available to be implemented Click on OK In you onCreate Method paste the following code

1:  txtans=(TextView) findViewById(R.id.txtans);  
2:      gestureDetector = new GestureDetectorCompat(this,this);  

Now for all the implemented method change the return type to true from false
We will also need to implement one last method so again press Alt + Insert and select onTouchEvent

1:    public boolean onTouchEvent(MotionEvent event) {  
2:      this.gestureDetector.onTouchEvent(event);  
3:      return super.onTouchEvent(event);  
4:    }  

I hope that it was informative for you and I would like to Thank you for reading.

Sunday, February 14, 2016

Android Multiple Event Handling Java

In this tutorial I will show you how to handle multiple events in Java for Android Development.

We will use a button and use their onClick and OnLongClick events to change the value of TextView


1:    protected void onCreate(Bundle savedInstanceState) {  
2:      super.onCreate(savedInstanceState);  
3:      setContentView(R.layout.activity_main);  
4:      client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();  
5:      Button btn = (Button) findViewById(R.id.btnequal);  
6:      btn.setOnClickListener(new Button.OnClickListener(){  
7:        public void onClick(View v){  
8:          btnonClick();  
9:        }  
10:      });  
11:      btn.setOnLongClickListener(new Button.OnLongClickListener(){  
12:        public boolean onLongClick(View c){  
13:          longClick();  
14:          return true;  
15:        }  
16:      });  
17:    }  
18:    public void longClick(){  
19:      TextView txt = (TextView)findViewById( R.id.txtans) ;  
20:      txt.setText("That was a long click");  
21:    }  
22:  public void btnonClick(){  
23:    TextView txt = (TextView) findViewById(R.id.txtans);  
24:    txt.setText("Dont touch me");  
25:  }  


I hope that it was informative for you and I would like to Thank you for reading

Android Event Handling Java

Hello everyone, in this tutorial I will show you how to implement event handling in Java for Android Development.

The example I will provide will include two controls a button and a TextView.

When user click the the button the value of textView will change.



1:   protected void onCreate(Bundle savedInstanceState) {  
2:      super.onCreate(savedInstanceState);  
3:      setContentView(R.layout.activity_main);  
4:      client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();  
5:      Button btn = (Button) findViewById(R.id.btnequal);  
6:      btn.setOnClickListener(new Button.OnClickListener(){  
7:        public void onClick(View v){  
8:          btnonClick();  
9:        }  
10:      });  
11:    }  
12:  public void btnonClick(){  
13:    TextView txt = (TextView) findViewById(R.id.txtans);  
14:    txt.setText("Dont touch me");  
15:  }  


I hope that it was informative for you and I would like to Thank you for reading

Android Set Control Width Dynamically Android Studio Java

In this tutorial I will show you how to create a Control with Width that will be same on all device regardless of there screen size.

So doesn't matter if your screen size is 5' or 4' your control will adjust itself automatically according to the screen size.

1:      super.onCreate(savedInstanceState);  
2:      RelativeLayout PageLayout = new RelativeLayout(this);  
3:      RelativeLayout.LayoutParams txtLayout = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);  
4:      txtLayout.addRule(RelativeLayout.CENTER_HORIZONTAL);  
5:      txtLayout.addRule(RelativeLayout.CENTER_VERTICAL);  
6:      EditText txtLogin = new EditText(this);  
7:      Resources r = getResources();  
8:      int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,200,r.getDisplayMetrics());  
9:      txtLogin.setWidth(px);  
10:      PageLayout.addView(txtLogin,txtLayout);  
11:      setContentView(PageLayout);  
Note that instead of defining width 200 static we are converting this into pixel according to device screen see line no. 8

After we get the px value which is of type in we can pass this value to setWitdh method.

I hope that it was informative for you and I would like to Thank you for reading.

Android Create Dynamic UI (Multiple Controls)

In this tutorial I have created Dynamic UI using Java. There are 3 Controls A button which is at 
the center of the screen, just above this button there is a textField and at the left of the 
textfield there is a label.
1:      RelativeLayout PageLayout = new RelativeLayout(this);  
2:      RelativeLayout.LayoutParams btnLayout = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);  
3:      btnLayout.addRule(RelativeLayout.CENTER_HORIZONTAL);  
4:      btnLayout.addRule(RelativeLayout.CENTER_VERTICAL);  
5:      Button btn = new Button(this);  
6:      btn.setId(1);  
7:      btn.setText("Login");  
8:      RelativeLayout.LayoutParams txtLayout = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);  
9:      txtLayout.addRule(RelativeLayout.CENTER_HORIZONTAL);  
10:      txtLayout.addRule(RelativeLayout.ABOVE, btn.getId());  
11:      EditText txtLogin = new EditText(this);  
12:      txtLogin.setId(2);  
13:      txtLogin.setWidth(300);  
14:      RelativeLayout.LayoutParams lblLayout = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);  
15:      //lblLayout.addRule(RelativeLayout.RIGHT_OF, txtLogin.getId());  // to put it in right position of textbox  
16:      lblLayout.addRule(RelativeLayout.LEFT_OF, txtLogin.getId());  
17:      lblLayout.addRule(RelativeLayout.ALIGN_BASELINE, txtLogin.getId());  
18:      TextView lblID = new TextView(this);  
19:      lblID.setId(3);  
20:      lblID.setText("User Name");  
21:      PageLayout.addView(btn, btnLayout);  
22:      PageLayout.addView(txtLogin,txtLayout);  
23:      PageLayout.addView(lblID,lblLayout);  
24:      setContentView(PageLayout);  

Saturday, February 13, 2016

Android Create Dynamic UI using Java


1:  super.onCreate(savedInstanceState);  
2:  RelativeLayout.LayoutParams layout= new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);  
3:  layout.addRule(RelativeLayout.CENTER_HORIZONTAL);   // setting Height  
4:  layout.addRule(RelativeLayout.CENTER_VERTICAL);    // Setting Width   
5:  RelativeLayout myLayout = new RelativeLayout(this);  // using this for changing background colormyLayout.setBackgroundColor(Color.GREEN);      // setting background color to green  
6:  Button btn = new Button(this);  
7:  btn.setBackgroundColor(Color.BLUE);         // Defining Btn Background Color to Bluebtn.setText("Touch ME");              // Defining button textbtn.setLayoutParams(layout);  
8:  //ViewPropertyAnimator anim=btn.animate();  
9:  myLayout.addView(btn);  
10:  setContentView(myLayout);  


i hope that it was informative for you and I would like to thank you for reading.

Sunday, November 29, 2015

How to Filter Column Returned from Stored Procedure SQL

I was asked by my Team Lead a task about Stored Procedures in SQL Server, the requirement was like

We had a Stored Procedure which returns a Table and that table has about 80 columns. Now in some cases we only want some of the columns not all.

I was not allowed to alter the Stored Procedure in any way, so the only thing I could try is at the point of calling the SP.

So I had some research over this, and I found a SQL function named OPENROWSET

This Function accept three parameters

 1. Provider Name
 2. Connection String
 3. Stored Procedure to be executed

In order to make this method work we have to enable the ad hoc Query, so execute the following query.

EXEC sp_configure
  'show advanced options',
  1 RECONFIGURE

  go
 EXEC sp_configure
  'ad hoc distributed queries',
  1 RECONFIGURE 


Lets First create a table

go

CREATE TABLE test
  (
     id   INT,
     NAME VARCHAR(10),
     age  INT,
  ) 

Now we will create a Stored Procedure which will return a datatable of table Test

go

CREATE PROC Getdata
AS
  BEGIN
      SELECT *
      FROM   test
  END 


Now if we try to execute the above SP it will return all the columns contained in the Test table, in our case we only want ID and Name columns. So here's how we do it

SELECT id,
       NAME
FROM   OPENROWSET ('SQLOLEDB',
                   'Server=(local);TRUSTED_CONNECTION=YES;',
                   'EXEC master.dbo.Getdata') AS tbl 


This way you will get only ID and Name columns

I hope that This tutorial was informative for you and I would like to thank you for reading.

Monday, November 23, 2015

Difference between Interface and Abstract Class

Following are the differences between an Interface and a Abstract Class.

InterfaceAbstract Class
1Interface support multiple InheritanceAbstract class does not support multiple inheritance
2Interface doesn't contain Data Member Abstract class contains Data Memember
3Interface doesn't contain ConstructorAbstract class contains constructor
4An interface contain only incomplete member (signature of member)An Abstract class contain both Incomplete (Abstract) and Complete Members
5An Interface cannot have access modifiers by default everything is assumed as publicAn Abstract class can contain access modifiers for the subs functions properties
6Member of Interface can not be static Only Complete Member of Abstact class can be static




I hope it was informative for you and I would like to Thank you for reading.

Wednesday, August 5, 2015

There are still remote logins or linked logins for the server

Hello Everyone,

While trying to delete linked server from SQL you might encounter the error like

There are still remote logins or linked logins for the server

Like the error says you cannot delete a linked server, until all logins associated with that linked server are removed.

So first we will have to remove those logins and than we can safely remove that linked server

To Remove logins for a specific linked server use the following query

sp_droplinkedsrvlogin 'Your Linked Server Name',null

Execute the above procedure with your linked server name and it will remove all logins associated with it.

Now try to remove the linked server by following query

sp_dropserver 'Your Linked Server Name'

That's it your have successfully deleted linked Server

I hope it was informative for you and I would like to thank you for reading.

Wednesday, June 10, 2015

How to Completely hide windows Form

If you are thinking about how to completely hide your Windows Form Application, so that it will run silently in the background without anyone knowing about it.

To do that add the following code

        protected override void OnLoad(EventArgs e)
        {
            Visible = false;
            ShowInTaskbar = false;
            base.OnLoad(e);
        }

This code will completely hide your form at startup.

I hope it was informative for you and I would like to Thank you for reading.

Sunday, May 10, 2015

Add Leading Zero in Excel

If you want to add leading zero's in your excel column so that your value become like following

123 > 0123
9827 > 09827
0000 > 0000

1. Select the column on which you want to apply this setting, and click Ctrl + 1

This will open Format Cell's dialog box



2. For the Category Select Custom

Now lets assume you need to enter 01234

3. So in type column just type 000#, and click on OK

That's it now if you enter 01234 in that column excel will accept it, and will not remove leading zero
I hope it was informative for you and I would like to thank you for reading.

Sunday, May 3, 2015

IF NOT EXISTS For Sql Functions

You must have used IF NOT EXISTS for DML operation, but the same method doesn't work for sql function.

In this tutorial I'm gonna show you how to use IF NOT EXISTS to create a function if it is already not created.

Download .Sql file for this project from HERE
 
IF EXISTS (SELECT * FROM [dbo].[sysobjects]
           WHERE ID = object_id(N'[dbo].[myfunction]')
                 )
    DROP FUNCTION [dbo].[myfunction]
GO

create function myfunction()
 returns int
 as
   begin
       return 5+4;
   end   

The idea here is to check if the function exists, if it exists than we will first drop it, and after that we can create the function.

I hope it was informative for you and I would like to Thank you for reading.

Wednesday, April 15, 2015

Sql Stored Procedure



  • Syntax for creating Procedure
  • We can insert row using SP
  • W can delete rows using SP
  • We can change Data Type of any column using SP
  • We can drop same table of which we are executing the SP
  • Stored Procedure can accept parameters
  • Triggers will be called from SP
  • Trigger will be called  even if there were no action took place of Delete Sql statement written in SP
  • Create procedure must be the first line in the batch this is why we have to use GO keyword
Syntax for creating procedure without Parameter
GO

CREATE PROCEDURE Your Procedure Name
AS
  BEGIN
      SELECT *
      FROM   Your Table Name
  END


Syntax for creating procedure with Parameter

CREATE PROCEDURE Myproc1 @ID   INT, @name VARCHAR(20)
AS
    SELECT *   FROM   test1    

        WHERE  empid = @ID   AND NAME = @name