Friday, 21 December 2012

getting selected row id and read the data.


Getting the selected item:

protected void approvalsubmit_Click(object sender, EventArgs e)
        {      

           
            foreach (GridViewRow gvrow in orderapproved.Rows)
            {
                //CheckBox chkChild = (CheckBox)gvrow.FindControl("chkChild");
                CheckBox chkChild = (CheckBox)gvrow.FindControl("chkChild");

               
                if (chkChild.Checked == true)
                {
                    string skucode = gvrow.Cells[10].Text;
                    Guid chid = new Guid();//Guid.Empty();
                    chid = new Guid(skucode);


                    ColumnSet colu = new ColumnSet(true);
                    var orderdetails = service.Retrieve("salesorder", chid, colu);
                    orderdetails["new_venderorderstatus"] = "Accepted";
                    service.Update(orderdetails);
                  
                }

            }


for pagination:
give the coding in c # :
 protected void ordershipped_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {

            ordershipped.PageIndex = e.NewPageIndex;
            ordershipped.DataBind();
           
         
        }

<asp:GridView ID="ordershipped" runat="server" AllowPaging="True" 
        OnPageIndexChanging="ordershipped_PageIndexChanging">

getting radgrid data:

foreach (Telerik.Web.UI.GridDataItem dataItem in grdCUGPublic0.MasterTableView.Items)// grd.MasterTableView.Items)
            {
                if (((CheckBox)dataItem.FindControl("Chk1")).Checked == true)
                {
                    // Int32 ID = (Int32)dataItem.GetDataKeyValue("ID");
                    Int32 ID = Convert.ToInt32(dataItem.GetDataKeyValue("Mobile Number"));
                    //return ID;
                }
            }


Tuesday, 18 December 2012

retrieve data from crm 2011 and show in gridview


Showing the data in Gridview.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Services;
using System.ServiceModel.Description;
using System.Net;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Xrm.Sdk.Query;
using System.Configuration;
using Sulekha.Order.CrmSdk;
using System.Linq.Expressions;
using Xrm;
using System.Collections.ObjectModel;
using System.Collections;
using System.Collections.Specialized;


namespace Sulekha.Order
{
    public partial class Order_Details : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Order_Accepted();
          
        }


        protected void Order_Accepted()
        {

            ClientCredentials credentials = new ClientCredentials();
            credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
            Uri OrganizationUri = new Uri("http://smdev-crm/SulekhaCRM/XRMServices/2011/Organization.svc");
            Uri HomeRealmUri = null;
            using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, credentials, null))
            {
                Microsoft.Xrm.Sdk.IOrganizationService service = (Microsoft.Xrm.Sdk.IOrganizationService)serviceProxy;




                ConditionExpression condition = new ConditionExpression();
                condition.AttributeName = "new_vendername";
                condition.Operator = ConditionOperator.Equal;
                condition.Values.Add("NXTEL");
              
                FilterExpression filter1 = new FilterExpression();               
                filter1.Conditions.Add(condition);
              

                QueryExpression query = new QueryExpression("salesorder");
               
                query.ColumnSet.AddColumns("ordernumber", "customerid", "name","new_category","new_actualpurchaseprice","shipto_city","statuscode");

                query.Criteria.AddFilter(filter1);


               

                EntityCollection result1 = serviceProxy.RetrieveMultiple(query);               

                DataSet ds = new DataSet();
                DataTable dt = new DataTable();
                dt.Columns.Add("Order No");
                dt.Columns.Add("Customer Name");
                dt.Columns.Add("Product Name");
                dt.Columns.Add("Product Category");
                dt.Columns.Add("Product Price");
                dt.Columns.Add("Order Status");
                dt.Columns.Add("Shipped to City");

                foreach (Entity entities in result1.Entities)
                {
                                   

                       
                        DataRow dr = dt.NewRow();
                        dr["Order No"] = entities.Attributes["ordernumber"].ToString(); //so.OrderNumber;
                        EntityReference var1 = (EntityReference)entities.Attributes["customerid"];
                        dr["Customer Name"] = var1.Name;
                        dr["Product Name"] = entities.Attributes["name"].ToString();
                        dr["Product Category"] = entities.Attributes["new_category"].ToString();
                        dr["Product Price"] = entities.Attributes["new_actualpurchaseprice"].ToString();
OptionSetValue osv = (OptionSetValue)entities.Attributes["statuscode"];
                        if (osv.Value == 1)
                        {
                            dr["Order Status"] = "New";
                        }
                        if (osv.Value == 2)
                        {
                            dr["Order Status"] = "Pending";
                        }


                        //dr["Order Status"] = osv.Value;
                        //dr["Order Status"] = entities.Attributes["statuscode"].ToString();
                        dr["Shipped to City"] = entities.Attributes["shipto_city"].ToString();

                        dt.Rows.Add(dr);
                 

                }

                ds.Tables.Add(dt);

                ordergrid.DataSource = ds;
                ordergrid.DataBind();
               

            }

        }
       
    }
}

using the session variables:

Session["accountname"]=var1.name; // in first asp.net
 string vendor = Session["accountname"].ToString(); //in second asp.net.

Response.redirect("second.aspx");

asp.net with jquery

using queryexpression in c# to retreieve data

to retrieve data from crm  2011
we can use queryexpression.
first create condition expression.
then filter expression.
then query expression.

this code for login credential checking in crm 2011.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.ServiceModel.Description;
using System.Net;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Xrm.Sdk.Query;
using System.Configuration;
using Sulekha.Order.CrmSdk;
using System.Linq.Expressions;
using Xrm;
using System.Data.SqlClient;
using System.Configuration;


namespace Sulekha.Order
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            //SqlConnection con = new

            Entity contacts = new Entity("contact");


            string user = username.Text.ToString();
            string pass = password.Text.ToString();

           
       

            ClientCredentials credentials = new ClientCredentials();
            credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
            Uri OrganizationUri = new Uri("http://crmserver/databaseCRM/XRMServices/2011/Organization.svc");
            Uri HomeRealmUri = null;
            using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, credentials, null))
            {
                Microsoft.Xrm.Sdk.IOrganizationService service = (Microsoft.Xrm.Sdk.IOrganizationService)serviceProxy;

              


                ConditionExpression condition = new ConditionExpression();
                condition.AttributeName = "firstname";
                condition.Operator = ConditionOperator.Equal;
                condition.Values.Add(user);

                ConditionExpression condition1 = new ConditionExpression();
                condition1.AttributeName = "lastname";
                condition1.Operator = ConditionOperator.Equal;
                condition1.Values.Add(pass);

                FilterExpression filter1 = new FilterExpression();
                filter1.Conditions.Add(condition);
                filter1.Conditions.Add(condition1);

                QueryExpression query = new QueryExpression("contact");
                query.ColumnSet.AddColumns("firstname", "lastname");
                query.Criteria.AddFilter(filter1);
               

                EntityCollection result1 = serviceProxy.RetrieveMultiple(query);

                if (result1.Entities.Count > 0)
                {
                    ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('valid Username and Password')</script>");

                }
                else
                {
                    ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('invalid Username and Password')</script>");
                }                  



            
               

            }
        }
    }
}

ref :

http://mileyja.blogspot.in/2011/07/convert-queryexpression-to-fetchxml.html

http://stackoverflow.com/questions/8669611/how-to-write-queryexpression-for-following-query

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


OptionSetValue osv = (OptionSetValue)entities.Attributes["statuscode"];
                        if (osv.Value == 1)
                        {
                            dr["Order Status"] = "New";
                        }
                        if (osv.Value == 2)
                        {
                            dr["Order Status"] = "Pending";
                        }


                        //dr["Order Status"] = osv.Value;
for optional set value

Thursday, 6 December 2012

plugin using by Developer tool kit

Developer tool kit :
sdk-- tools-- developer toolkit.

we need to install the developer toolkit.
for this first we can install WIF
http://support.microsoft.com/kb/974405
we can download and install.
after that install the developer tool kit.

open the Visual Studio you will get the Dynamic crm tab.
choose the new visual studio solution template.
give the name and click on ok.
you will get the connection:
give the server name. (crmsever).
choose http or https.
default credentials.
then  select the organization and solution.
click ok.
automatically it will show the crm
right click on entity and create wrapper class ( early bound).
it will come as entity.cs near by plugin.cs.
use the namespace in using area.
select the entity where we need to create plugin.
right click and select the create plugin option.
there we need to give the plugin message.
give the signing.
click on project and deploy.

sample code :


IPluginExecutionContext context = localContext.PluginExecutionContext;
            IOrganizationService service = localContext.OrganizationService;
            var orgServiceContext = new OrganizationServiceContext(service);

            if (context.InputParameters.Contains("Target") &&
                             context.InputParameters["Target"] is Entity)
            {
                // Obtain the target entity from the input parmameters.
                Entity entity = (Entity)context.InputParameters["Target"];
                // TODO: Implement your custom Plug-in business logic.
                var newCooldrink = entity.ToEntity<new_cooldrink>();
                newCooldrink.new_productcount = 50;
            }

ref:
http://akilanaki.blogspot.in/2012/09/crm-2011-plugin-tips.html
http://blog.thinketg.com/blog/ben-klopfer/how-to-deploying-plugins-with-the-microsoft-dynamics-crm-2011-developer-toolkit-tutorial
http://blogs.msdn.com/b/crm/archive/2011/01/11/a-better-way-to-learn-linq-to-crm-linqpad-plugin-for-ms-crm-2011-is-available.aspx

Friday, 30 November 2012

check box in SSRS

Senario:

based on the two optional set or optional set values we need to show
check boxes in the SSRS.

for this Refer :
http://kkryczka.wordpress.com/2010/12/09/how-to-display-checkbox-on-report/

http://www.mindfiresolutions.com/Including-Checkbox-in-SQL-Server-Reporting-1163.php

http://blog.hoegaerden.be/2012/08/04/displaying-checkboxes-in-an-ssrs-report/

First create a  report.
in that select the two optional set

Ex : Stock Available or Stock Not Available.

change the Font to "wingdings".
then go to the expression:

=iif(First(Fields!new_stockavilability.Value, "DataSet1")= false,chr(0254),chr(0168))

if it is the Optional set:

=iif(First(Fields!new_regionof.Value, "DataSet1")=100000002,chr(0254),chr(0168))

then you will get the check boxes in report.

Tuesday, 20 November 2012

Check box Onclick Event in crm 2011


Senario:

we are using the checkboxes in crm 2011.
doing some customizations based on the checkboxes.
but the problem is :
After clicking on the checkbox, you need to click outside the box then only function will execute.

for overcome this problem:

just we need to give the one extra function in onload event.

ex ;
my check box field is : new_stockdelivered

then the function in onload event is :


function onload()
{
crmForm.all.new_stockdelivered.onclick = function()
{
    crmForm.all.new_stockdelivered.FireOnChange();
}
}

for suppose :
i have two fields :
new_stockdelivered and new_stockdelivereddate.
if you check on stock delivered then only date will be enable.

first give the onchange function :


function stockdate()
{
var myAttribute = "new_stockdelivered";
var myControl = Xrm.Page.ui.controls.get(myAttribute);
var detailamt= myControl.getAttribute().getValue();
if(detailamt==true)
{
Xrm.Page.getControl("new_stockdelivereddate").setDisabled(false);
}
else
{
Xrm.Page.getControl("new_stockdelivereddate").setDisabled(true);
}
}

it is in onchange event and onload event.

and extra in onload event :


function onload()
{
crmForm.all.new_stockdelivered.onclick = function()
{
    crmForm.all.new_stockdelivered.FireOnChange();
}
}

it will give immediate effect after click on the checkbox