Tuesday, 28 July 2015

Friday, 24 July 2015

Unit test your client-side JavaScript

 I don’t think that we have to discuss the importance of having tests. That’s not something that we add to the project in addition. That’s something that the project is based on. And because testing is so important we have bunch of tools in our disposal. We all know (I hope) how to test our back-end code. However, once we move to the front-end is a bit different. At the moment we are working on a big single page application and testing is one of our main focuses. In this article you will see how to unit test our client-side JavaScript.
Note: this article does not follow best practices working with AngularJS. The client-side code here is definitely not the best one. The idea is to show how jsdom may be used for testing browser apps. Here is an article that will guide you for better testing of AngularJS apps.

The example

In order to illustrate the problem and its solution we will create a simple AngularJS application. AngularJS because it is a popular framework and probably you are familiar with it. Originally the concepts described in this article were applied to a project that uses Ractive.js but it works for AngularJS and it will probably work for Ember.js or Backbone.js.
Let’s say that we have a menu and the last link there shows a form for registering a new user. The fields in the form have some validation mechanisms. The are mandatory and have requirements for a minimum number of letters. Overall the example looks like that:
Unit test your client-side JavaScript
We have a placeholder below the form that shows an error message.
Here is the code that we start with:
<!doctype html>
<html ng-app="app">
  <head>
    <link rel="stylesheet" href="./css/styles.css">
    <script src="./vendor/angular.min.js"></script>
    <script type="text/javascript">

      angular.module('app', [])
      .controller('Controller', function($scope) {})
      .directive('registerForm', function() {
        ...
      })
      .directive('appHeader', function() {
        ...
      });

    </script>
  </head>
  <body>
    <div ng-controller="Controller">
      <app-header></app-header>
    </div>
  </body>
</html>

 

Friday, 14 November 2014

How to Change version in solution file?

In this Article i teach you about how to change Version Higher to Lower and Lower to Higher Open Solution file (.Sln).

Follow Bellow Step.
1) Step Open Your Solution File In Text file.
if You don't able to open it just do like Write Click on Solution and Open with Text file and Change Version Appropriate same Like Bellow.







Thursday, 13 November 2014

How to Get Between String Using Substring() and LastIndexOf()


  
How to Get Between String Using Substring() and LastIndexOf()
             string name = "abcabc_1.aspx";         
            name = name.Substring(name.LastIndexOf("_") + 1, (name.LastIndexOf(".") - name.LastIndexOf("_") + 1));

WPF ADD UPDATE DELETE Example

 WPF Add Update Delete Example.

In this article I will teach you how to build a simple database application using WPF that can display data in GridView and can perform ADD, UPDATE and DELETE operations on SQL server database .

Bellow Screen Describe Example View.

 

Add Record


 







 



Edit Record

 

Delete Record

 

 Now We are start Behind code.

First when Page Initialize Your First Need to Fill Grid View and Combobox.

public MainWindow()
        {
            InitializeComponent();
            fillcombobox();
           
            filldatagrid();
        }

 

  void fillcombobox()
        {
            SqlConnection con = new SqlConnection(sqlstring);
            con.Open();
            string sqlquery = "select * from dsh_wpfCRUD_Country";
            SqlCommand cmd = new SqlCommand(sqlquery, con);
            SqlDataAdapter adp = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            adp.Fill(dt);

            combobox1.DataContext = dt;
          
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    combobox1.Items.Add(dt.Rows[i]["CountryName"].ToString());
                }
            }

            con.Close();
        }

 

   private void filldatagrid()
        {
            SqlConnection con = new SqlConnection(sqlstring);
            con.Open();
            string sqlquery = "select * from dsh_wpfCRUD";
            SqlCommand cmd = new SqlCommand(sqlquery, con);
            SqlDataAdapter adp = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            adp.Fill(dt);
            datagrid1.ItemsSource = dt.DefaultView;
            con.Close();
        }

  private void ComboBox_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
        {
            int cnname1 = combobox1.SelectedIndex;
            int cname2 = cnname1 + 1;
            SqlConnection con = new SqlConnection(sqlstring);
            con.Open();
            string sqlquery = "select * from dsh_wpfCRUD_State where CountryID='" + cname2 + "'";
            SqlCommand cmd = new SqlCommand(sqlquery, con);
            SqlDataReader sdr = cmd.ExecuteReader();
            combobox2.Items.Clear();
            if (sdr.Read())
            {
               
                combobox2.Items.Add(sdr[1].ToString());
            }
            con.Close();
        }

 

 

 private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            if (btnsubmit.Content == "Update")
            {

                SqlConnection con = new SqlConnection(sqlstring);
                con.Open();
                string sqlquery = "update dsh_wpfCRUD set name=@name,address=@address,gender=@gender,country=@country,state=@state,city=@city,contactno=@contactno where id='" + PK_ID + "'";
                SqlCommand cmd = new SqlCommand(sqlquery, con);
                cmd.Parameters.AddWithValue("@name", txtname.Text);
                cmd.Parameters.AddWithValue("@address", txtname.Text);
                string d1 = rdfemale.Content.ToString();
                string d2 = (Convert.ToBoolean(rdmale.IsChecked) ? rdmale.Content.ToString() : d1);
                cmd.Parameters.AddWithValue("@gender", d2);
                cmd.Parameters.AddWithValue("@country", combobox1.SelectedValue);
                cmd.Parameters.AddWithValue("@state", combobox2.SelectedValue);
                cmd.Parameters.AddWithValue("@city", txtcity.Text);
                cmd.Parameters.AddWithValue("@contactno", txtcontactno.Text);
                cmd.ExecuteNonQuery();
                filldatagrid();
                clearcontrol();
            }
            else
            {
                SqlConnection con = new SqlConnection(sqlstring);
                con.Open();
                string sqlquery = "insert into dsh_wpfCRUD (name,address,gender,country,state,city,contactno) values (@name,@address,@gender,@country,@state,@city,@contactno)";
                SqlCommand cmd = new SqlCommand(sqlquery, con);
                cmd.Parameters.AddWithValue("@name", txtname.Text);
                cmd.Parameters.AddWithValue("address", txtaddress.Text);
                string d1 = rdfemale.Content.ToString();
                string d2 = (Convert.ToBoolean(rdmale.IsChecked) ? rdmale.Content.ToString() : d1);
                cmd.Parameters.AddWithValue("@gender", d2);
                cmd.Parameters.AddWithValue("@country", combobox1.SelectedValue);
                cmd.Parameters.AddWithValue("@state", combobox2.SelectedValue);
                cmd.Parameters.AddWithValue("@city", txtcity.Text);
                cmd.Parameters.AddWithValue("@contactno", txtcontactno.Text);
                cmd.ExecuteNonQuery();
                filldatagrid();
                clearcontrol();
            }
        }

 

private void Button_Click_2(object sender, RoutedEventArgs e)
        {

            var id1 = (DataRowView)datagrid1.SelectedItem;
            PK_ID = Convert.ToInt32(id1.Row["id"].ToString());
            SqlConnection con = new SqlConnection(sqlstring);
            con.Open();
            string sqlquery = "select * from dsh_wpfCRUD where id='" + PK_ID + "' ";
            SqlCommand cmd = new SqlCommand(sqlquery, con);
            SqlDataAdapter adp = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable();
            adp.Fill(dt);

            if (dt.Rows.Count > 0)
            {
                txtname.Text = dt.Rows[0]["name"].ToString();
                txtaddress.Text = dt.Rows[0]["address"].ToString();
                if (dt.Rows[0]["gender"].ToString() == "Male")
                {
                    rdmale.IsChecked = true;
                }
                else
                {
                    rdfemale.IsChecked = true;
                }
                combobox1.SelectedValue = dt.Rows[0]["country"].ToString();
                combobox2.SelectedValue = dt.Rows[0]["state"].ToString();
                txtcity.Text = dt.Rows[0]["city"].ToString();
                txtcontactno.Text = dt.Rows[0]["contactno"].ToString();
            }

            btnsubmit.Content = "Update";
        }

 For One Row Delete.

  private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            var id1 = (DataRowView)datagrid1.SelectedItem;
            PK_ID = Convert.ToInt32(id1.Row["id"].ToString());

            SqlConnection con = new SqlConnection(sqlstring);
            con.Open();
            string sqlquery = "delete from dsh_wpfCRUD where id='" + PK_ID + "' ";
            SqlCommand cmd = new SqlCommand(sqlquery, con);
            cmd.ExecuteNonQuery();
            filldatagrid();
        }

Click here for Download.


 https://www.dropbox.com/s/a3xlpwfmngykj0u/WPF%20Demo.rar?dl=0

 

AngularJs6 using with Asp.net Core Web API 2

AngularJs6 using with Asp.net Core Web API 2 Steps 1) Create project using with command 2) Create services 3) Create routing 4) Modif...