Friday, April 20, 2012

CRM 2011- Plugin and Workflow

WCF:Introduction

WCF:
inter-operating between different software applications, running on a variety of platforms and/or frameworks
Previously we are using web service now we are using WCF.

For more Details click here
http://wcftutorial.net/

Why to use WCF.

1)If you are running two application on different platforms

eg java and asp.net

the to communication between them we need a common format



2)WCF support multiple protocols like web service support only http protocol
eg:net-tcp

For more details

http://msdn.microsoft.com/en-us/library/ms731079.aspx

http://msdn.microsoft.com/en-us/library/ms734712.aspx
http://www.codeproject.com/KB/WCF/WCF_Basics.aspx

http://www.codeproject.com/KB/WCF/WCFServiceSample.aspx
http://msdn.microsoft.com/en-us/library/ee958158%28v=MSDN.10%29.aspx
http://www.codeproject.com/KB/WCF/WCF_Web_Service_Remoting.aspx
http://social.msdn.microsoft.com/forums/en-US/wcf/thread/1c4932a3-afa7-4ce9-951f-42a713d2424c/
http://www.codeproject.com/KB/WCF/wcf_bohansen.aspx
http://danielvanwyk.wordpress.com/2010/04/30/create-host-and-consume-a-wcf-service-using-the-wcf-service-library-template-in-visual-studio-2008/
http://stackoverflow.com/questions/1658455/invalid-operation-exception
http://msdn.microsoft.com/en-us/magazine/cc163412.aspx
http://msdn.microsoft.com/en-us/library/ms731734.aspx

metadata exchange options in wcf:
http://blog.binarymist.net/category/microsoft/windows-communication-foundation-wcf/
http://msdn.microsoft.com/en-us/library/system.servicemodel.description.servicemetadatabehavior.httpgetenabled.aspx

ADO.NET - Dataset vs DataReader (Sample Program)

Using dataset:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private SqlConnection cn;
        private SqlCommand cmd1, cmd2, cmd3,cmd4;

        private void Form1_Load(object sender, EventArgs e)
        {
            cn = new SqlConnection("server=MUHIL-PC;database=student;uid=sa;pwd=focus1");

            cn.Open();
        }
//SELECT
        private void button1_Click(object sender, EventArgs e)
        {
           // cmd1 = new SqlCommand("select * from stud", cn);
           // SqlDataReader dr = cmd1.ExecuteReader();
           // listBox1.Items.Clear();                 
           // while (dr.Read())
            //{
             //listBox1.Items.Add (dr[0].ToString ()+":"+dr[1].ToString ()+":"+dr[2].ToString ()); 
             
           // }
            //dr.Close();
            SqlDataAdapter da = new SqlDataAdapter("select * from stud", cn);
            DataSet ds=new DataSet();
            da.Fill(ds,"stud");
            dataGridView1.DataSource=ds.Tables["stud"];
            dataGridView1.Show();
          }
//INSERT
        private void button2_Click(object sender, EventArgs e)
        {
            cmd2= new SqlCommand("insert into stud values("+textBox1.Text+",'"+textBox2.Text+"',"+textBox3.Text+")",cn);
            cmd2.ExecuteNonQuery();
           
        }
//DELETE
        private void button3_Click(object sender, EventArgs e)
        {
            cmd3 = new SqlCommand("delete from stud where sid= "+ textBox1.Text, cn);
            cmd3.ExecuteNonQuery();
        }
//UPDATE
        private void button4_Click(object sender, EventArgs e)
        {
            cmd4 = new SqlCommand("update stud set sname='"+textBox2.Text+"',ph="+textBox3.Text+" where sid="+textBox1.Text, cn);
            cmd4.ExecuteNonQuery();
        }
}
}

using DataReader:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private SqlConnection cn;
        private SqlCommand cmd1, cmd2, cmd3,cmd4;

        private void Form1_Load(object sender, EventArgs e)
        {
            cn = new SqlConnection("server=MUHIL-PC;database=student;uid=sa;pwd=focus1");
            cn.Open();
        }
//SELECT
        private void button1_Click(object sender, EventArgs e)
        {
            cmd1 = new SqlCommand("select * from stud", cn);
            SqlDataReader dr = cmd1.ExecuteReader();
            listBox1.Items.Clear();
            while (dr.Read())
            {
             listBox1.Items.Add (dr[0].ToString ()+":"+dr[1].ToString ()+":"+dr[2].ToString ()); 
            }
            dr.Close();
        }
//INSERT
        private void button2_Click(object sender, EventArgs e)
        {
            cmd2= new SqlCommand("insert into stud values("+textBox1.Text+",'"+textBox2.Text+"',"+textBox3.Text+")",cn);
            cmd2.ExecuteNonQuery();
          }
//DELETE 
        private void button3_Click(object sender, EventArgs e)
        {
            cmd3 = new SqlCommand("delete from stud where sid= "+ textBox1.Text, cn);
            cmd3.ExecuteNonQuery();
        }
//UPDATE
        private void button4_Click(object sender, EventArgs e)
        {
            cmd4 = new SqlCommand("update stud set sname='"+textBox2.Text+"',ph="+textBox3.Text+" where sid="+textBox1.Text, cn);
            cmd4.ExecuteNonQuery();
        }   
}
}




WPF data binding

Prism - Get Started with the Prism

Customer Care Accelerator (CCA) Reference URL


installing:


UIIDebugger:


CCA r2:


Hosting a web application in CCA:

Bing Search:

HAT:


URL Addressable Forms

how-do-i-host-a-web-popup-in-another-tab:



how-to-override-the-crm-2011-popup-alert-in-cca-when-redirecting-a-popup-update:


uii templates for visual studio:

hosting WPF content in CCA

discussions:
http://crmcca.codeplex.com/discussions



creating new associated record:(create form)
URL: http://<crmserver>/<org>/CS/cases/edit.aspx
QueryString: _CreateFromType=2&_CreateFromId=%CustomerID%


Updating record:(update form)
URL:http://crmserver>/<org>/SFA/conts/edit.aspx
QueryString:  id=%CustomerID%

configure this in Default UII action

for more details:
Showing CRM data using CustomerID from context
  http://blogs.msdn.com/b/mbarbour/archive/2010/05/13/showing-crm-data-in-the-customer-care-accelerator.aspx

associted views
URL:http://crmserver>/<org>/userdefined/areas.aspx
QueryString: oId=%CustomerID% &oType=2&pagemode=iframe&security=852023&tabSet=areaService

http://myencounterwithcrm.wordpress.com/category/crm-2011/associated-view/

WPF- Simple Model-View-ViewModel(MVVM) project –Step by step


WPF- Simple Model-View-ViewModel(MVVM) project –Step by step

Model-View-ViewModel(MVVM) is a pattern to create the loosely coupled the user interface and logic.
1. Create the new wpf application in visual studio
2. Go to the solution Explorer and create 3 folders named Model, View, ViewModel (Right click the project to add ->New Folder)
3. Cut and paste the APP.xaml and MainWindow.xaml into view folder; now your solution explorer will look like the following
4. Now add 3 class files to viewmodel folder and rename it.
5. in “ViewModelBaseClass.cs” ,Copy and paste the following code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace SimpleWpfMvvmProject.ViewModel
{
    class ViewModelBaseClass:INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        public void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}

6. In “RelayCommandClass.cs”, Copy and paste the following code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;

namespace SimpleWpfMvvmProject.ViewModel
{
    class RelayCommandClass:ICommand
    {
        Action<object> action;
        public RelayCommandClass(Action<object> _action)
        {
            action = _action;
        }

        public bool CanExecute(object parameter)
        {
            return true;
            //throw new NotImplementedException();
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            action(parameter);
            //throw new NotImplementedException();
        }
    }
}

Model:
7. Add a class files in Model folder and name it as “ModelClass.cs” With the following code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SimpleWpfMvvmProject.Model
{
    class ModelClass
    {
        private string myVar;

        public string MyProperty
        {
            get { return myVar; }
            set { myVar = value; }
        }
        public ModelClass()
        {
            MyProperty = "aki";
        }
    }
}
ViewModel:
8. in “MainWindowlogicClass.cs” file and add the following code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.Windows;

namespace SimpleWpfMvvmProject.ViewModel
{
    class MainWindowLogicClass:ViewModelBaseClass
    {
        Model.ModelClass modelClass;
        public MainWindowLogicClass()
        {
            modelClass = new Model.ModelClass();
            ButtonCommand = new RelayCommandClass(new Action<object>(Display));
        }

        private ICommand buttonCommand;

        public ICommand ButtonCommand
        {
            get { return buttonCommand; }
            set { buttonCommand = value; }
        }

        public void Display(object obj)
        {
            MessageBox.Show("hi "+ obj.ToString());
        }

      

        public string MyProperty
        {
            get { return modelClass.MyProperty; }
            set
            {
                modelClass.MyProperty = value; OnPropertyChanged("MyProperty");
            }
        }
       

    }
}
View:


9. go to APP.xaml ,remove startupuri=”MainWindow.xaml” in designer view ;in code view add the following code
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;

namespace SimpleWpfMvvmProject
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            MainWindow mw = new MainWindow();
            ViewModel.MainWindowLogicClass vm = new ViewModel.MainWindowLogicClass();
            mw.DataContext = vm;
            mw.Show();
        }
       
    }
}

10. go to MainWindow.xaml and add the following code

<Window x:Class="SimpleWpfMvvmProject.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
   
    <Grid>
        <TextBox Height="23" HorizontalAlignment="Left" Margin="183,67,0,0" Name="textBox1" VerticalAlignment="Top" Width="120" Text="{Binding MyProperty}" />
        <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="219,131,0,0" Name="button1" VerticalAlignment="Top" Width="75" Command="{Binding ButtonCommand}" CommandParameter="akilan"  />
    </Grid>
</Window>


Now Run the application.it will run.
in future if u will do any modification in user interface,it will not affect the logic.