Wednesday, 26 December 2012

dynamic textboxes in c sharp


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;
using System.ComponentModel;
using System.Drawing;
using System.Web.UI.WebControls;
//using System.Web;
using System.Web.UI;
//using System.Web.UI.WebControls

namespace Sulekha.Order
{
    public partial class acceptpopup : System.Web.UI.Page
    {
       

        protected void Page_Load(object sender, EventArgs e)
        {
            dynamictextboxes();

           
        }

        protected void dynamictextboxes()
        {
            //string noofloop = Session["countnum1"].ToString();

            string selectedsession = Convert.ToString(Session["stringbuild"]);

            string[] seperateditems = selectedsession.Split('#');

            int selectedcount = selectedsession.Length;

            foreach (string needtoseperate in seperateditems)
            {

                string commaseperated = needtoseperate;

                string skuids = (commaseperated.Split(','))[0];
                string guidss = (commaseperated.Split(','))[1];

                //Console.Write("these info for :", skuids);
               

               

                Label lcpn = new Label();
                TextBox tcpn = new TextBox();

                lcpn.Text = " Courier Parnter Name " +" "+"for"+" "+ skuids; //gui.ToString();
                tcpn.ID = "cpn" + guidss;
                //Response.Write("This information for the coupoun number : " + skuids);
                panel1.Controls.Add(lcpn);

                panel1.Controls.Add(tcpn);
                panel1.Controls.Add(new LiteralControl("<br/>"));

                Label lawb = new Label();
                TextBox tawb = new TextBox();

                lawb.Text = " Airway Bill No " + " " + "for" +" " +skuids; //gui.ToString();
                tawb.ID = "awb" + guidss;
                //Response.Write("This information for the coupoun number : " + skuids);
                panel1.Controls.Add(lawb);

                panel1.Controls.Add(tawb);
                panel1.Controls.Add(new LiteralControl("<br/>"));

                Label lvno = new Label();
                TextBox tvno = new TextBox();

               lvno.Text = " Vendor Order Number" + " " + "for" +" " +skuids; //gui.ToString();
                tvno.ID = "vno" + guidss;
                //Response.Write("This information for the coupoun number : " + skuids);
                panel1.Controls.Add(lvno);

                panel1.Controls.Add(tvno);

               
                panel1.Controls.Add(new LiteralControl("<br/>"));

            }         
           

        }

        protected void acceptpopupsubmit_Click(object sender, EventArgs e)
        {

            foreach (Control ctl in panel1.Controls)
            {

                TextBox txts = ctl as TextBox;

                if (txts != null)
                {
                    string txtids = txts.ID;
                    string tdata = txts.Text;

                    string rawid = txtids.Substring(5);

                    Guid orderguids = new Guid();
                    orderguids = new Guid(rawid);

                    string prenameoftxt = txtids.Substring(0, 3);
                   

                    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 (Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy serviceProxy = new Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy(OrganizationUri, HomeRealmUri, credentials, null))
                    {
                        Microsoft.Xrm.Sdk.IOrganizationService service = (Microsoft.Xrm.Sdk.IOrganizationService)serviceProxy;
                     
                        ColumnSet colns = new ColumnSet(true);
                        var orderdetails = service.Retrieve("salesorder", orderguids, colns);
                        orderdetails["new_venderorderstatus"] = "Shipped";
                        if (prenameoftxt == "cpn")
                        {
                            orderdetails["new_courierpartnername"] = txts.Text;
                        }

                        if (prenameoftxt == "awb")
                        {
                            orderdetails["new_airwaybillno"] = txts.Text;
                        }
                        if (prenameoftxt == "vno")
                        {
                            orderdetails["new_venderorderno"] = txts.Text;
                        }

                        service.Update(orderdetails);

                    }

                }
            }

        }


       

    }
}

order details

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;
using System.ComponentModel;
using System.Drawing;
using System.Web.UI.WebControls;
//using System.Windows.Forms;



namespace Sulekha.Order
{
    public partial class Order_Details : System.Web.UI.Page
    {
        // Login logs = new Login();

        ClientCredentials credentials = new ClientCredentials();
       
           // credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;
            Uri OrganizationUri = new Uri("http://smdev-crm/SulekhaCRM/XRMServices/2011/Organization.svc");
            Uri HomeRealmUri = null;

        //Microsoft.Xrm.Sdk.IOrganizationService service = (Microsoft.Xrm.Sdk.IOrganizationService)serviceProxy;
        IOrganizationService service;
      
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Order_Approved();
                Order_Accepted();
                Order_Shipped();
            }

           
          
        }

        [WebMethod]
        protected void Order_Approved()
        {

            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;


                string vendor = Session["accountname"].ToString();

                ConditionExpression condition = new ConditionExpression();
                condition.AttributeName = "new_vendername";
                condition.Operator = ConditionOperator.Equal;
                condition.Values.Add(vendor);

                ConditionExpression condition1 = new ConditionExpression();
                condition1.AttributeName = "new_venderorderstatus";
                condition1.Operator = ConditionOperator.Equal;
                condition1.Values.Add("Order Approved");
              
                FilterExpression filter1 = new FilterExpression();
                filter1.FilterOperator = LogicalOperator.And;
                filter1.Conditions.Add(condition);
                filter1.Conditions.Add(condition1);
               // filter1.Conditions = new ConditionExpression[] { condition, condition1 };
              

                QueryExpression query = new QueryExpression("salesorder");

                query.ColumnSet.AddColumns("new_couponcode", "customerid", "name", "new_category", "new_actualpurchaseprice", "shipto_city","statuscode", "new_venderorderstatus","shipto_postalcode","salesorderid");

                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");
                dt.Columns.Add("SKU");
                dt.Columns.Add("Offer Price");
                dt.Columns.Add("Payable Price");
                dt.Columns.Add("Order Id");
                foreach (Entity entities in result1.Entities)
                {                                

                       
                        DataRow dr = dt.NewRow();
                        dr["Order No"] = entities.Attributes["new_couponcode"].ToString(); //so.OrderNumber;
                        EntityReference customer = (EntityReference)entities.Attributes["customerid"];
                        dr["Customer Name"] = customer.Name;
                        string productname = entities.Attributes["name"].ToString();
                        string alteredproductname = productname.Substring(12);
                        dr["Product Name"] = alteredproductname;                       
                        //dr["Product Category"] = entities.Attributes["new_category"].ToString();
                        dr["Product Price"] = entities.Attributes["new_actualpurchaseprice"].ToString();                 


                        dr["Order Status"] = entities.Attributes["new_venderorderstatus"].ToString();
                        string scity = entities.Attributes["shipto_city"].ToString();
                        string spin = entities.Attributes["shipto_postalcode"].ToString();
                        dr["Shipped to City"] = scity + "-" + spin;

                        //EntityReference orderguid = (EntityReference)entities.Attributes["salesorderid"];
                        Guid orderguid = (Guid)entities.Attributes["salesorderid"];
                        dr["Order Id"] = orderguid;

                        string fetchquery = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
 "<entity name='salesorderdetail'>" +
   "<attribute name='new_skuid' />" +
   "<attribute name='new_ip_offerprice' />" +
   "<attribute name='new_ip_payable' />" +
  
   "<attribute name='createdon' />" +  
   "<filter type='and'>" +
     "<condition attribute='salesorderid' operator='eq' uitype='salesorder' value='" + orderguid + "' />" +
   "</filter>" +
 "</entity>" +
"</fetch>";

                        FetchExpression fetch = new FetchExpression(fetchquery);
                        EntityCollection salesorderinfo = serviceProxy.RetrieveMultiple(fetch);

                        foreach (Entity sorder in salesorderinfo.Entities)
                        {

                            dr["SKU"] = sorder.Attributes["new_skuid"].ToString();
                            if (sorder.Attributes.Keys.Contains("new_ip_offerprice") == true)
                            {
                                dr["Offer Price"] = (Money)sorder.Attributes["new_ip_offerprice"];
                            }
                            else
                            {
                                dr["Offer Price"] = "0"; //new Money { Value = 0 };
                            }

                            if (sorder.Attributes.Keys.Contains("new_ip_payable") == true)
                            {
                                dr["Payable Price"] = (Money)sorder.Attributes["new_ip_payable"];
                            }
                            else
                            {
                                dr["Payable Price"] = "0"; //new Money { Value = 0 };
                            }

                           
                        }
                        

                        //ColumnSet cols = new ColumnSet(true);
                        //var orderdetailinfo = service.Retrieve("salesorderdetail", orderguid, cols);

                        //dr["SKU"] = orderdetailinfo.Attributes["new_skuid"];
                        //dr["Offer Price"] = orderdetailinfo.Attributes["new_ip_offerprice"];
                        //dr["Payable Price"] = orderdetailinfo.Attributes["new_ip_payable"];


                        dt.Rows.Add(dr);
                 

                }

                ds.Tables.Add(dt);

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

                //orderapproved.HeaderRow.Cells[10].Visible = true;
                if (result1.Entities.Count > 0)
                {
                    orderapproved.HeaderRow.Cells[10].Visible = false;
                    foreach (GridViewRow gvr in orderapproved.Rows)
                    {
                        gvr.Cells[10].Visible = false;
                    }
                }
               

            }

        }

        [WebMethod]
        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;


                string vendor = Session["accountname"].ToString();

                ConditionExpression condition = new ConditionExpression();
                condition.AttributeName = "new_vendername";
                condition.Operator = ConditionOperator.Equal;
                condition.Values.Add(vendor);

                ConditionExpression condition1 = new ConditionExpression();
                condition1.AttributeName = "new_venderorderstatus";
                condition1.Operator = ConditionOperator.Equal;
                condition1.Values.Add("Accepted");

                FilterExpression filter1 = new FilterExpression();
                filter1.FilterOperator = LogicalOperator.And;
                filter1.Conditions.Add(condition);
                filter1.Conditions.Add(condition1);
                // filter1.Conditions = new ConditionExpression[] { condition, condition1 };


                QueryExpression query = new QueryExpression("salesorder");

                query.ColumnSet.AddColumns("new_couponcode", "customerid", "name", "new_category", "new_actualpurchaseprice", "shipto_city", "statuscode", "new_venderorderstatus", "shipto_postalcode","salesorderid");

                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");
                dt.Columns.Add("SKU");
                dt.Columns.Add("Offer Price");
                dt.Columns.Add("Payable Price");
                dt.Columns.Add("Order Id");

                foreach (Entity entities in result1.Entities)
                {


                    DataRow dr = dt.NewRow();
                    dr["Order No"] = entities.Attributes["new_couponcode"].ToString();

                   
                    EntityReference var1 = (EntityReference)entities.Attributes["customerid"];
                    dr["Customer Name"] = var1.Name;

                   
                    string productname = entities.Attributes["name"].ToString();
                    string alteredproductname = productname.Substring(12);
                    dr["Product Name"] = alteredproductname;
                   // dr["Product Category"] = entities.Attributes["new_category"].ToString();
                    dr["Product Price"] = entities.Attributes["new_actualpurchaseprice"].ToString();                 


                    dr["Order Status"] = entities.Attributes["new_venderorderstatus"].ToString();

                    string scity = entities.Attributes["shipto_city"].ToString();
                    string spin = entities.Attributes["shipto_postalcode"].ToString();


                    dr["Shipped to City"] = scity + "-" + spin;

                    Guid orderguid = (Guid)entities.Attributes["salesorderid"];

                    dr["Order Id"] = orderguid;

                    string fetchquery = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
"<entity name='salesorderdetail'>" +
"<attribute name='new_skuid' />" +
"<attribute name='new_ip_offerprice' />" +
"<attribute name='new_ip_payable' />" +

"<attribute name='createdon' />" +
"<filter type='and'>" +
 "<condition attribute='salesorderid' operator='eq' uitype='salesorder' value='" + orderguid + "' />" +
"</filter>" +
"</entity>" +
"</fetch>";

                    FetchExpression fetch = new FetchExpression(fetchquery);
                    EntityCollection salesorderinfo = serviceProxy.RetrieveMultiple(fetch);

                    foreach (Entity sorder in salesorderinfo.Entities)
                    {

                        dr["SKU"] = sorder.Attributes["new_skuid"].ToString();
                        if (sorder.Attributes.Keys.Contains("new_ip_offerprice") == true)
                        {
                            dr["Offer Price"] = (Money)sorder.Attributes["new_ip_offerprice"];
                        }
                        else
                        {
                            dr["Offer Price"] = "0"; //new Money { Value = 0 };
                        }

                        if (sorder.Attributes.Keys.Contains("new_ip_payable") == true)
                        {
                            dr["Payable Price"] = (Money)sorder.Attributes["new_ip_payable"];
                        }
                        else
                        {
                            dr["Payable Price"] = "0"; //new Money { Value = 0 };
                        }


                    }

                    dt.Rows.Add(dr);


                }

                ds.Tables.Add(dt);

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

                if (result1.Entities.Count>0)
                {

                    orderaccepted.HeaderRow.Cells[10].Visible = false;
                    foreach (GridViewRow gvr in orderaccepted.Rows)
                    {
                        gvr.Cells[10].Visible = false;

                    }              


                }

            }

        }


        [WebMethod]
        protected void Order_Shipped()
        {

            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;


                string vendor = Session["accountname"].ToString();

                ConditionExpression condition = new ConditionExpression();
                condition.AttributeName = "new_vendername";
                condition.Operator = ConditionOperator.Equal;
                condition.Values.Add(vendor);

                ConditionExpression condition1 = new ConditionExpression();
                condition1.AttributeName = "new_venderorderstatus";
                condition1.Operator = ConditionOperator.Equal;
                condition1.Values.Add("Shipped");

                FilterExpression filter1 = new FilterExpression();
                filter1.FilterOperator = LogicalOperator.And;
                filter1.Conditions.Add(condition);
                filter1.Conditions.Add(condition1);
                // filter1.Conditions = new ConditionExpression[] { condition, condition1 };


                QueryExpression query = new QueryExpression("salesorder");

                query.ColumnSet.AddColumns("new_couponcode", "customerid", "name", "new_category", "new_actualpurchaseprice", "shipto_city", "statuscode", "new_venderorderstatus", "shipto_postalcode","salesorderid");

                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");
                dt.Columns.Add("SKU");
                dt.Columns.Add("Offer Price");
                dt.Columns.Add("Payable Price");
                dt.Columns.Add("Order Id");
                foreach (Entity entities in result1.Entities)
                {


                    DataRow dr = dt.NewRow();
                    dr["Order No"] = entities.Attributes["new_couponcode"].ToString(); //so.OrderNumber;
                    EntityReference var1 = (EntityReference)entities.Attributes["customerid"];
                    dr["Customer Name"] = var1.Name;

                    string productname = entities.Attributes["name"].ToString();
                    string alteredproductname = productname.Substring(12);
                    dr["Product Name"] = alteredproductname;                 
                   // dr["Product Category"] = entities.Attributes["new_category"].ToString();
                    dr["Product Price"] = entities.Attributes["new_actualpurchaseprice"].ToString();            


                    dr["Order Status"] = entities.Attributes["new_venderorderstatus"].ToString();
                    string scity = entities.Attributes["shipto_city"].ToString();
                    string spin = entities.Attributes["shipto_postalcode"].ToString();
                    dr["Shipped to City"] = scity + "-" + spin;

                    Guid orderguid = (Guid)entities.Attributes["salesorderid"];

                    string fetchquery = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
"<entity name='salesorderdetail'>" +
"<attribute name='new_skuid' />" +
"<attribute name='new_ip_offerprice' />" +
"<attribute name='new_ip_payable' />" +

"<attribute name='createdon' />" +
"<filter type='and'>" +
 "<condition attribute='salesorderid' operator='eq' uitype='salesorder' value='" + orderguid + "' />" +
"</filter>" +
"</entity>" +
"</fetch>";

                    FetchExpression fetch = new FetchExpression(fetchquery);
                    EntityCollection salesorderinfo = serviceProxy.RetrieveMultiple(fetch);

                    foreach (Entity sorder in salesorderinfo.Entities)
                    {

                        dr["SKU"] = sorder.Attributes["new_skuid"].ToString();
                        if (sorder.Attributes.Keys.Contains("new_ip_offerprice") == true)
                        {
                            dr["Offer Price"] = (Money)sorder.Attributes["new_ip_offerprice"];
                        }
                        else
                        {
                            dr["Offer Price"] = "0"; //new Money { Value = 0 };
                        }

                        if (sorder.Attributes.Keys.Contains("new_ip_payable") == true)
                        {
                            dr["Payable Price"] = (Money)sorder.Attributes["new_ip_payable"];
                        }
                        else
                        {
                            dr["Payable Price"] = "0"; //new Money { Value = 0 };
                        }


                    }

                    dt.Rows.Add(dr);


                }

                ds.Tables.Add(dt);

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

                if (result1.Entities.Count > 0)
                {
                    ordershipped.HeaderRow.Cells[10].Visible = false;

                    foreach (GridViewRow gvr in ordershipped.Rows)
                    {
                        gvr.Cells[10].Visible = false;

                    }
                }
               
            }

        }

        protected void ordershipped_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {

            ordershipped.PageIndex = e.NewPageIndex;
            Order_Shipped();
            ordershipped.DataBind();
            ordershipped.HeaderRow.Cells[10].Visible = false;

            foreach (GridViewRow gvr in ordershipped.Rows)
            {
                gvr.Cells[10].Visible = false;

            }
           
         
        }
        protected void orderapproved_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {

            orderapproved.PageIndex = e.NewPageIndex;
            Order_Approved();           
            orderapproved.DataBind();
            orderapproved.HeaderRow.Cells[10].Visible = false;
            foreach (GridViewRow gvr in orderapproved.Rows)
            {
                gvr.Cells[10].Visible = false;
            }


        }
        protected void orderaccepted_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {

            orderaccepted.PageIndex = e.NewPageIndex;
            Order_Accepted();
            orderaccepted.DataBind();
            orderaccepted.HeaderRow.Cells[10].Visible = false;
            foreach (GridViewRow gvr in orderaccepted.Rows)
            {
                gvr.Cells[10].Visible = false;

            }    

        }

        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);

                    using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, credentials, null))
                    {
                        Microsoft.Xrm.Sdk.IOrganizationService service = (Microsoft.Xrm.Sdk.IOrganizationService)serviceProxy;
                        ColumnSet colu = new ColumnSet("new_venderorderstatus");
                        var orderdetails = service.Retrieve("salesorder", chid, colu);
                        orderdetails["new_venderorderstatus"] = "Accepted";
                        service.Update(orderdetails);

                    }
                }

            }

           
            }

        protected void approvalnostock_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 ordercode = gvrow.Cells[10].Text;
                    Guid chid = new Guid();//Guid.Empty();
                    chid = new Guid(ordercode);

                    string skucode = gvrow.Cells[7].Text;

                    using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, credentials, null))
                    {
                        Microsoft.Xrm.Sdk.IOrganizationService service = (Microsoft.Xrm.Sdk.IOrganizationService)serviceProxy;
                        ColumnSet colu = new ColumnSet("new_venderorderstatus");
                        var orderdetails = service.Retrieve("salesorder", chid, colu);
                        orderdetails["new_venderorderstatus"] = "No Stock";
                        service.Update(orderdetails);

                        ConditionExpression condition = new ConditionExpression();
                        condition.AttributeName = "new_vendorsku";
                        condition.Operator = ConditionOperator.Equal;
                        condition.Values.Add(skucode);                       

                        FilterExpression filter1 = new FilterExpression();
                        //filter1.FilterOperator = LogicalOperator.And;
                        filter1.Conditions.Add(condition);
                       // filter1.Conditions.Add(condition1);

                        QueryExpression query = new QueryExpression("new_deal");
                        query.ColumnSet.AddColumns("new_dealstatus", "new_dealid", "new_vendorsku");
                        query.Criteria.AddFilter(filter1);


                        EntityCollection queryresult = serviceProxy.RetrieveMultiple(query);

                        Entity deal = new Entity();
                        deal.LogicalName = "new_deal";

                        foreach (var c in queryresult.Entities)
                        {

                            deal["new_dealstatus"] = "100000012";
                            deal.Id = c.Id;
                            deal.LogicalName = c.LogicalName;
                            service.Update(deal);

                        }


                    }
                }

            }

        }

        protected void shippingdeliverd_Click(object sender, EventArgs e)
        {


        }

        protected void noshipping_Click(object sender, EventArgs e)
        {

        }

        protected void acceptshipping_Click(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();
            foreach (GridViewRow gvrow in orderaccepted.Rows)
            {
                CheckBox chkChild = (CheckBox)gvrow.FindControl("chkChild1");

                if (chkChild.Checked)
                {
                    string skucode = gvrow.Cells[1].Text;
                    string ordId = gvrow.Cells[10].Text;
                    sb.Append(skucode + "," + ordId + "#");
                }
            }

            string sbstring = sb.ToString().Substring(0, sb.ToString().Length - 1);
            Session["stringbuild"] = sbstring;
            Response.Redirect("acceptpopup.aspx");
        }

        protected void acceptnostock_Click(object sender, EventArgs e)
        {

        }

     
       
    }
}

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