Friday 28 December 2012

login Page

create style.css with following code:

body{ margin:0; padding:0; font:normal 11px arial; color:#000;}
#container{ width:100%; }
.header{}
.logo{ padding:5px 10px;}
.headertape{ background:#40a3c0; height:25px;}
.logincontent{width:100%; margin:0 auto; margin:100px 0;}
.login{ border:1px solid #40a3c0; width:320px; height:170px; border-radius:10px;}
.signintitle{ background:#40a3c0; font-size:18px; color:#fff; padding:10px;  border-radius:10px 10px 0 0; text-align:left;}
.username{ padding:20px 0 10px 10px;}
.loginlbl{ color:#3c3c3c; padding:4px 0 5px 0; width:65px; float:left;}
.logintxt{ color:#3c3c3c; padding:0 2px; border:1px solid #40a3c0; width:227px; height:19px; float:left;}
.password{ padding:10px 0 10px 10px; clear:both;}
.submit{ width:320px; text-align:right; clear:both;}
.loginbtn{ background:#b9131a; font-size:12px; font-weight:bold; color:#fff; border:0; padding:3px 10px; border-radius:5px; margin:10px;}
.footer{ bottom:0; background:#ccdfe5; text-align:center; position:fixed; width:100%; padding:5px 0;}


AND

aspx with code of :

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="Sulekha.Order.Login" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div id="container">
        <div class="header">
            <div class="logo">
                <img src="images/logo.gif" alt="Sulekha" /></div>
            <div class="headertape">
                &nbsp;</div>
        </div>
        <div class="logincontent" align="center">
        <div class="login">
            <div class="signintitle">
                Sign In
            </div>
            <div class="username">
                <asp:Label ID="Label1" runat="server" Text="User Name" CssClass="loginlbl"></asp:Label>
                <asp:TextBox ID="username" runat="server" CssClass="logintxt"></asp:TextBox>
            </div>
            <div class="password">
                <asp:Label ID="Label2" runat="server" Text="Password" CssClass="loginlbl"></asp:Label>
                <asp:TextBox ID="password" runat="server" CssClass="logintxt" TextMode="Password"></asp:TextBox>
            </div>
            <div class="submit"><asp:Button ID="butsign" runat="server" OnClick="Button1_Click" Text="Sign in" CssClass="loginbtn" /></div>
        </div>
        </div>
    </div>
    <div class="footer">&copy; Copyright 2012</div>
    </form>
</body>
</html>

Code in c charp:

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.ComponentModel;
using System.Drawing;



namespace Sulekha.Order
{

    public partial class Login : System.Web.UI.Page
    {
       // public string accountname;


        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public 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://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_name";
                condition.Operator = ConditionOperator.Equal;
                condition.Values.Add(user);

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

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

                QueryExpression query = new QueryExpression("new_vendorlogindetails");
                query.ColumnSet.AddColumns("new_name", "new_password","new_vendoraccount");
                query.Criteria.AddFilter(filter1);
               

                EntityCollection queryresult = serviceProxy.RetrieveMultiple(query);

      
               

                if (queryresult.Entities.Count > 0)
                {
                    foreach (var a in queryresult.Entities)
                    {

                       // string usernn = a.Attributes["new_name"].ToString();

                        EntityReference vendoraccount = (EntityReference)a.Attributes["new_vendoraccount"];

                        //Guid accountids = vendoraccount.Id;
                        Session["accountname"] = vendoraccount.Name;                     
                       
                    }

                    Response.Redirect("Order_Details.aspx");

                   // 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>");
                }
                                
               

            }
        }
    }
}

Thursday 27 December 2012

search button in asp with crm data

protected void btnsearch_Click(object sender, EventArgs e)
        {
            string searchkeyword = TextBox1.Text;
            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");

            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 fetchquery = string.Empty;

                if (ddlsearch.SelectedItem.Value == "cun")
                {
                    fetchquery = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
"<entity name='salesorder'>" +
"<attribute name='customerid' />" +
"<attribute name='name' />" +
"<attribute name='new_actualpurchaseprice' />" +
"<attribute name='new_venderorderno' />" +
"<attribute name='new_venderorderstatus' />" +
"<attribute name='new_couponcode' />" +
"<attribute name='shipto_city' />" +
"<attribute name='shipto_telephone' />" +
"<attribute name='billto_telephone' />" +
"<attribute name='createdon' />" +
"<filter type='and'>" +
 "<condition attribute='customeridname' operator='like' value='" + searchkeyword + "' />" +
"</filter>" +
"</entity>" +
"</fetch>";

                }

                if (ddlsearch.SelectedItem.Value == "von")
                {

                    fetchquery = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
"<entity name='salesorder'>" +
"<attribute name='customerid' />" +
"<attribute name='name' />" +
"<attribute name='new_actualpurchaseprice' />" +
"<attribute name='new_venderorderno' />" +
"<attribute name='new_venderorderstatus' />" +
"<attribute name='new_couponcode' />" +
"<attribute name='shipto_city' />" +
"<attribute name='shipto_telephone' />" +
"<attribute name='billto_telephone' />" +
"<attribute name='createdon' />" +
"<filter type='and'>" +
"<condition attribute='new_venderorderno' operator='like' value='" + searchkeyword + "' />" +
"</filter>" +
"</entity>" +
"</fetch>";


                }
                if (ddlsearch.SelectedItem.Value == "son")
                {
                    fetchquery = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
"<entity name='salesorder'>" +
"<attribute name='customerid' />" +
"<attribute name='name' />" +
"<attribute name='new_actualpurchaseprice' />" +
"<attribute name='new_venderorderno' />" +
"<attribute name='new_venderorderstatus' />" +
"<attribute name='new_couponcode' />" +
"<attribute name='shipto_city' />" +
"<attribute name='shipto_telephone' />" +
"<attribute name='billto_telephone' />" +
"<attribute name='createdon' />" +
"<filter type='and'>" +
 "<condition attribute='new_couponcode' operator='like' value='" + searchkeyword + "' />" +
"</filter>" +
"</entity>" +
"</fetch>";

                }
                if (ddlsearch.SelectedItem.Value == "smn")
                {
                    fetchquery = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
"<entity name='salesorder'>" +
"<attribute name='customerid' />" +
"<attribute name='name' />" +
"<attribute name='new_actualpurchaseprice' />" +
"<attribute name='new_venderorderno' />" +
"<attribute name='new_venderorderstatus' />" +
"<attribute name='new_couponcode' />" +
"<attribute name='shipto_city' />" +
"<attribute name='shipto_telephone' />" +
"<attribute name='billto_telephone' />" +
"<attribute name='createdon' />" +
"<filter type='and'>" +
"<condition attribute='shipto_telephone' operator='like' value='" + searchkeyword + "' />" +
"</filter>" +
"</entity>" +
"</fetch>";
                }
                if (ddlsearch.SelectedItem.Value == "bmn")
                {
                    fetchquery = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
"<entity name='salesorder'>" +
"<attribute name='customerid' />" +
"<attribute name='name' />" +
"<attribute name='new_actualpurchaseprice' />" +
"<attribute name='new_venderorderno' />" +
"<attribute name='new_venderorderstatus' />" +
"<attribute name='new_couponcode' />" +
"<attribute name='shipto_city' />" +
"<attribute name='shipto_telephone' />" +
"<attribute name='billto_telephone' />" +
"<attribute name='createdon' />" +
"<filter type='and'>" +
"<condition attribute='billto_telephone' operator='like' value='" + searchkeyword + "' />" +
"</filter>" +
"</entity>" +
"</fetch>";
                }

                RetrieveMultipleRequest req = new RetrieveMultipleRequest();
                FetchExpression fetch = new FetchExpression(fetchquery);
                req.Query = fetch;
                RetrieveMultipleResponse resp = (RetrieveMultipleResponse)service.Execute(req);
                EntityCollection col = resp.EntityCollection;
                DataRow dr = dt.NewRow();

                string orderstate = null;
                foreach (var c in col.Entities)
                {


                    dr["Order No"] = c["new_couponcode"];

                    EntityReference customer = (EntityReference)c.Attributes["customerid"];
                    dr["Customer Name"] = customer.Name;

                    dr["Product Name"] = c["name"];
                    dr["Product Price"] = c["new_actualpurchaseprice"];

                    orderstate = c["new_venderorderstatus"].ToString();
                    dr["Order Status"] = orderstate; //c["new_venderorderstatus"].ToString();
                    dr["Shipped to City"] = c["shipto_city"];
                    Guid orderguid = (Guid)c.Attributes["salesorderid"];

                    dr["Order Id"] = orderguid;

                    string orderquery = "<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 fetch1 = new FetchExpression(orderquery);
                    EntityCollection salesorderinfo = serviceProxy.RetrieveMultiple(fetch1);

                    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"];

                            Money op = (Money)sorder.Attributes["new_ip_offerprice"];
                            dr["Offer Price"] = op.Value;
                        }
                        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"];

                            Money pp = (Money)sorder.Attributes["new_ip_payable"];
                            dr["Payable Price"] = pp.Value;

                        }
                        else
                        {
                            dr["Payable Price"] = "0"; //new Money { Value = 0 };
                        }


                    }



                }

                dt.Rows.Add(dr);

                ds.Tables.Add(dt);

                if (orderstate == "Order Approved")
                {
                    orderapproved.DataSource = ds;
                    orderapproved.DataBind();
                    TabPanel1.Visible = false;
                    TabPanel2.Visible = false;
                    TabPanel3.Visible = false;
                  
                }
                if (orderstate == "Accepted")
                {
                    orderaccepted.DataSource = ds;
                    orderaccepted.DataBind();
                    tbpnluser.Visible = false;
                    TabPanel1.Visible = false;
                    TabPanel3.Visible = false;

                }
                if (orderstate == "Shipped")
                {

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

                    tbpnluser.Visible = false;
                    TabPanel2.Visible = false;
                    TabPanel3.Visible = false;

                }
                if (orderstate == "Delivered")
                {
                    orderdelivered.DataSource = ds;
                    orderdelivered.DataBind();
                    tbpnluser.Visible = false;
                    TabPanel2.Visible = false;
                    TabPanel1.Visible = false;

                }

                if (orderstate != "Order Approved" && orderstate != "Accept" && orderstate != "Shipped" && orderstate != "Delivered")
                {
                    orderapproved.DataSource = ds;
                    orderapproved.DataBind();
                    TabPanel1.Visible = false;
                    TabPanel2.Visible = false;
                    TabPanel3.Visible = false;
                }


            }
        }

     

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

        }

     
       
    }
}