Thursday, 28 April 2016

MALWARE CLICKEU.TRACTIONIZE.COM

BASIC PLUGIN STEPS IN MS CRM 2013

BASIC PLUGIN STEPS IN MS CRM 2011/2013/2015/2016

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;

namespace LeadRecordw
{
    public class Class1
    {

        public static void Read()
        {
            Entity account = new Entity("account");
            Entity cass = new Entity("incident");
            Entity account2 = new Entity();
            account2.LogicalName = "account";



            // read the values from the entity (any entity which is defined)
            // read means, retrieve the entity's fields name values from the entity is called as "reading" the values 
            account.Attributes.ContainsKey("name");
            string accname = account["name"].ToString();

            DateTime date = (DateTime)account["createdon"];
            DateTime date2 = Convert.ToDateTime(account2["createdon"]);

            string accname1 = account2["name"].ToString();
            //optionset
            OptionSetValue optname = (OptionSetValue)account["new_accounttype"];
            //lookup
            EntityReference Parentaccount = (EntityReference)account["parentaccountid"];
            string parentname = Parentaccount.LogicalName;
            Guid parentid = Parentaccount.Id;

            int age = (int)account["new_age"];

            int age2 = Convert.ToInt32(account["new_age"]);

        }

        public static void Write()
        {

            Entity contact = new Entity("contact");
            contact["name"] = "abc";
            contact["new_age"] = 68;
            DateTime aa = new DateTime(1999, 12, 09);
            contact["createdon"] = aa;

            contact["createdon"] = new DateTime(1999, 12, 09);

            OptionSetValue ad = new OptionSetValue(12);
            contact["new_accounttype"] = ad;
        }


        public static void Main()
        {
            Entity account = new Entity("account");

            string accname = account["accountname"].ToString();

            Entity csd = new Entity("incident");
            csd["incidentname"] = accname;

        }



        public static void read1()
        {
            Entity lead = new Entity("lead");
            Entity lead1 = new Entity();
            lead1.LogicalName = "lead";

            string sub = lead1["subject"].ToString();
            string name = lead1["fullname"].ToString();
            string jobtitle = lead1["jobtitle"].ToString();
            int businessphone = Convert.ToInt32(lead1["telephone1"]);
            int mobilephone = Convert.ToInt32(lead1["mobilephone"]);

            EntityReference parentaccountoflead = (EntityReference)lead1["parentaccountid"];
            string parentaccount = lead1.LogicalName;
            Guid parentid = lead1.Id;

            string email = lead1["email"].ToString();

            EntityReference parentcontact = (EntityReference)lead1["parentcontactid"];
            string parentcont = lead1.LogicalName;
            Guid parentsid = lead1.Id;

            string companyname = lead1["companyname"].ToString();
            string websiteurl = lead1["websiteurl"].ToString();
            string address = lead1["address1_composite"].ToString();
            string description = lead1["description"].ToString();

            int annualrevenue = Convert.ToInt32(lead1["revenue"]);
            int numbofemployyee = Convert.ToInt32(lead1["numberofemployees"]);
            OptionSetValue industry = (OptionSetValue)lead1["industrycode"];
            string SIC = lead1["SIC"].ToString();

            EntityReference currency = (EntityReference)lead1["transcationcurrencyid"];
            string curren = lead1.LogicalName;
            Guid currenid = lead1.Id;
        }


        public static void Write2()
        {
            Entity contact = new Entity("contact");
            contact["fullname"] = "malla";
            contact["jobtitle"] = "MANAGER";

            // here retrieve values from account entity then assign to contact entity fields.

            Entity account = new Entity("account");
            string accname = account["name"].ToString();

            Entity contat = new Entity("contact");
            contat["name"] = accname;
            //contact["fullname"] = accname;

            DateTime date = new DateTime(2001, 12, 12);
            contat["new_date"] = date;

            OptionSetValue acctype = new OptionSetValue(2);
            account["new_accounttype"] = acctype;
        }


        public static void Main1()
        {
            // here iam assigning the contact field name companyname = lead field name parent account for lead 
            Entity contact = new Entity("contact");
            EntityReference compname = (EntityReference)contact["parentcustomerid"];
            string companyname = contact.LogicalName;
            Guid companyid = contact.Id;

            Entity lead = new Entity("lead");
            lead["parentaccountid"] = contact.Id;
        }

        public static void Read1()
        {
            Entity annotation = new Entity("annotation");
            // annotation["createdby"] = "mallareddy";

            Entity cad = new Entity();
            cad.LogicalName = "incident";

            DateTime date = (DateTime)cad["new_date"];

            Entity cad1 = new Entity("incident");
            int casid = Convert.ToInt32(cad1["caseid"]);
            string casename = cad1["casename"].ToString();

            OptionSetValue caseoption = (OptionSetValue)cad1["caseoption"];

            EntityReference caserefer = (EntityReference)cad1["casereference"];
            string casefer = cad1.LogicalName;
            Guid caseferid = cad1.Id;

        }

        public static void Write3()
        {
            Entity account = new Entity("account");
            account["name"] = "kashmir";
            account["address1"] = "london";

            OptionSetValue ad = new OptionSetValue(2);
            account["new_accountype"] = ad;

            DateTime dat = new DateTime(2011, 12, 11);
            account["createdon"] = dat;

        }

        public static void Main3()
        {
            Entity contact = new Entity("contact");
            string companyname = contact["companyname"].ToString();

            Entity cass = new Entity("incident");
            cass["casename"] = companyname;

        }
        public static void Read4()
        {
            Entity contact = new Entity("contact");
            Entity csd = new Entity();
            csd.LogicalName = "incident";

            Entity activity = new Entity();
            activity.LogicalName = "activity";


            Entity account = new Entity();
            string accname = account["accountname"].ToString();
            int accno = Convert.ToInt32(account["accountnumber"]);
            DateTime date = (DateTime)account["new_date"];
            EntityReference companyname = (EntityReference)account["companynameid"];
            OptionSetValue region = (OptionSetValue)account["new_region"];
            bool gender = (bool)account["new_gender"];

            EntityReference parentaccount = (EntityReference)account["parentaccountid"];
            string parentaccountname = account.LogicalName;
            Guid parentaccountid = account.Id;
        }

        public static void Write6()
        {
            Entity acc = new Entity("account");
            acc["accountname"] = "Malla reddy";
            acc["phone"] = 1234555;
            acc["new_weburl"] = "www.excitech.co.uk";

            Guid parentcusromerid = new Guid();
            EntityReference accparentid = new EntityReference();
            accparentid.Id = parentcusromerid;
            accparentid.LogicalName = "account";
            acc["parentaccountid"] = accparentid;




            OptionSetValue region = new OptionSetValue(5);
            acc["new_region"] = region;

            DateTime dat = new DateTime(2001, 12, 03);
            acc["new_date"] = dat;

        }

        public static void Main5()
        {
            Entity account1 = new Entity("account");
            DateTime createdon = (DateTime)account1["createdon"];

            Entity lead = new Entity("lead");
            lead["datecreatedlead"] = createdon;


            string accname = account1["accountname"].ToString();
            lead["leadname"] = accname;

            int accountnumber = Convert.ToInt32(account1["accountnumber"]);
            lead["leadnumber"] = accountnumber;
            //or
            lead["leadnumber"] = Convert.ToInt32(account1["accountnumber"]);

        }
        public static void Retrieve(Guid id, IOrganizationService service)
        {
            Entity account = service.Retrieve("account", id, new Microsoft.Xrm.Sdk.Query.ColumnSet("accountname"));
            string accname = account["accountname"].ToString();

            Entity account1 = service.Retrieve("account", id, new Microsoft.Xrm.Sdk.Query.ColumnSet("telephone1"));
            int phone = Convert.ToInt32(account["telephone1"]);

            Entity account2 = service.Retrieve("account", id, new Microsoft.Xrm.Sdk.Query.ColumnSet("fax"));
            int fax1 = Convert.ToInt32(account["fax"]);

            Entity account3 = service.Retrieve("account", id, new Microsoft.Xrm.Sdk.Query.ColumnSet("address1_addresstypecode"));
            OptionSetValue address = (OptionSetValue)account["address1_addresstypecode"];

            Entity account4 = service.Retrieve("account", id, new Microsoft.Xrm.Sdk.Query.ColumnSet("createdon"));
            DateTime createdon1 = (DateTime)account["createdon"];

            Entity account5 = service.Retrieve("account", id, new Microsoft.Xrm.Sdk.Query.ColumnSet("parentaccountid"));

            EntityReference parentaccount = (EntityReference)account["parentaccountid"];
            string parentacc = account.LogicalName;
            Guid parentaccid = account.Id;

            Entity account6 = service.Retrieve("account", id, new Microsoft.Xrm.Sdk.Query.ColumnSet("new_employeesworking"));
            OptionSetValue employeeworking = (OptionSetValue)account["new_employeesworking"];

            //--------------------------------------------------------------------------------------------------

            Entity account7 = service.Retrieve("account", id, new Microsoft.Xrm.Sdk.Query.ColumnSet("new_name", "new_age", "emailaddress1"));
            string accountname = account7["new_name"].ToString();
            int accage = Convert.ToInt32(account7["new_age"]);
            string email = account7["emailaddress1"].ToString();


            Entity account8 = service.Retrieve("account", id, new Microsoft.Xrm.Sdk.Query.ColumnSet("new_age", "new_bitfield", "new_existingcustomer"));
            int accountage = Convert.ToInt32(account8["new_age"]);
            OptionSetValue bitfield = (OptionSetValue)account8["new_bitfield"];
            OptionSetValue existingcustomer = (OptionSetValue)account8["new_existingcustomer"];


            Entity account9 = service.Retrieve("account", id, new Microsoft.Xrm.Sdk.Query.ColumnSet("new_accounttype", "address1_line1", "new_employeesworking", "new_lastmodifiedby"));
            OptionSetValue acctype = (OptionSetValue)account9["new_accounttype"];
            string addressline = account9["address1_line1"].ToString();
            OptionSetValue employeeworking1 = (OptionSetValue)account9["new_employeesworking"];
            DateTime lastmodifiedby = (DateTime)account9["new_lastmodifiedby"];


        }

        public static void read3()
        {
            Entity lead1 = new Entity("lead");

            Entity lead = new Entity();
            lead.LogicalName = "lead";

            string subject = lead["subject"].ToString();
            string fullname = lead["fullname"].ToString();
            string jobtitle = lead["jobtitle"].ToString();
            int businessphone = Convert.ToInt32(lead["telephone1"]);

            int mobilephone = Convert.ToInt32(lead["mobilephone"]);
            EntityReference parentaccountforlead = (EntityReference)lead["parentaccountid"];
            string email = lead["email"].ToString();

            EntityReference parentcontactforlead = (EntityReference)lead["parentcontactid"];
            string parentcontactname = lead.LogicalName;
            Guid parentcontactid = lead.Id;

            string company = lead["companyname"].ToString();
            string website = lead["websiteurl"].ToString();
            string Address1 = lead["address1_composite"].ToString();

            string description = lead["description"].ToString();

            OptionSetValue industry = (OptionSetValue)lead["industrycode"];
            int annualrevenue = Convert.ToInt32(lead["revenue"]);// currency data type??
            int noofemployees = Convert.ToInt32(lead["numberofemployees"]);

            string SIC = lead["sic"].ToString();

            EntityReference currency = (EntityReference)lead["transcationcurrencyid"];
        }

        public static void Write3()
        {
            Entity contract = new Entity("contract");
            contract["contractnumber"] = 12333333;
            contract["title"] = "BSSYSTEMS";

            //EntityReference accparentid = new EntityReference();
            //accparentid.Id = parentcusromerid;
            //accparentid.LogicalName = "account";
            //acc["parentaccountid"] = accparentid;

            EntityReference customer = new EntityReference();
            customer.LogicalName = "contract";
            contract["customerid"] = customer;  // doubt how to assign values of entity reference

            EntityReference contractaddress = new EntityReference();
            contract.LogicalName = "contract";
            contract["serviceaddress"] = contractaddress; // ??

            DateTime contractstartdate = new DateTime(1988, 12, 09);
            contract["activeon"] = contractstartdate;


            DateTime contractenddate = new DateTime(1999, 12, 12);
            contract["expireson"] = contractenddate;

            contract["duration"] = 12;
        }

        public static void Main5()
        {
            Entity account = new Entity("account");
            string accountnames = account["accountname"].ToString();

            Entity contract = new Entity("contract");
            contract["title"] = accountnames;

        }

        public static void Retreive(Guid id, IOrganizationService service)
        {
            Entity leaddetails = service.Retrieve("leaddetails", id, new Microsoft.Xrm.Sdk.Query.ColumnSet(true));
        }

        public static void RetreiveMuliple(IOrganizationService service)
        {
            QueryExpression query = new QueryExpression();

            query.EntityName = "lead";
            query.ColumnSet = new ColumnSet(true);
            query.Criteria.Conditions.Add(new ConditionExpression("emailaddress1", ConditionOperator.Equal, "malla@gmail.com"));
            query.Criteria.Conditions.Add(new ConditionExpression("fullname", ConditionOperator.Equal, "malla"));

            EntityCollection leadrecords = service.RetrieveMultiple(query);

            foreach (Entity lead in leadrecords.Entities)
            {
                string email = lead["subject"].ToString();
                Console.WriteLine(email);
            }
        }

        public static void RetreiveMultiple(IOrganizationService service)
        {
            QueryExpression query1 = new QueryExpression();

            query1.EntityName = "contact";
            query1.ColumnSet = new ColumnSet(true);
            query1.Criteria.Conditions.Add(new ConditionExpression("fullname", ConditionOperator.EndsWith, "das"));
            query1.Criteria.Conditions.Add(new ConditionExpression("telephone1", ConditionOperator.EndsWith, "22"));

            EntityCollection contactrecords = service.RetrieveMultiple(query1);

            foreach (Entity contact in contactrecords.Entities)
            {
                string fullname = contact["fullname"].ToString();
                Console.WriteLine(fullname);
            }
        }

        public static void RetreiveMultiple(IOrganizationService service)
        {
            QueryExpression query2 = new QueryExpression();
            
            query2.EntityName = "account";
            query2.ColumnSet = new ColumnSet(true);
            query2.Criteria.Conditions.Add(new ConditionExpression("name", ConditionOperator.DoesNotEndWith, "hsjs"));
            query2.Criteria.Conditions.Add(new ConditionExpression("telephone1", ConditionOperator.DoesNotEndWith, "3222"));

            EntityCollection accountrecord = service.RetrieveMultiple(query2);
            foreach (Entity account in accountrecord.Entities)
            {
                string name = account["name"].ToString();
                Console.WriteLine(name);
            }

        }

        public static void RetreiveMultiplesss(IOrganizationService service)
        {
            QueryExpression query3 = new QueryExpression();
            query3.EntityName = "new_leaddetails";
            query3.ColumnSet = new ColumnSet(true);
            query3.Criteria.Conditions.Add(new ConditionExpression("new_name", ConditionOperator.DoesNotContain, "his"));
            query3.Criteria.Conditions.Add(new ConditionExpression("new_age", ConditionOperator.DoesNotContain, "12"));
            query3.Criteria.Conditions.Add(new ConditionExpression("new_email", ConditionOperator.DoesNotContain, "mll@gmail.com"));
            query3.Criteria.Conditions.Add(new ConditionExpression("new_dob", ConditionOperator.DoesNotContain, "23"));
            query3.Criteria.Conditions.Add(new ConditionExpression("new_rating", ConditionOperator.DoesNotContain, "coolest"));
            query3.Criteria.Conditions.Add(new ConditionExpression("new_connection", ConditionOperator.DoesNotContain, "sample"));
            query3.Criteria.Conditions.Add(new ConditionExpression("new_account", ConditionOperator.DoesNotContain, "simple"));

            EntityCollection leaddetailsrecord = service.RetrieveMultiple(query3);
            foreach (Entity leaddetail in leaddetailsrecord.Entities)
            {
                int name = Convert.ToInt32(leaddetail["new_age"]);
                Console.WriteLine(name);
            }

        }

        public static void RetreiveMultipleA(IOrganizationService service)
        {
            QueryExpression query4 = new QueryExpression();
            query4.EntityName = "opportunity";
            query4.ColumnSet = new ColumnSet("purchaseprocess");
            query4.Criteria.Conditions.Add(new ConditionExpression("purchaseprocess", ConditionOperator.DoesNotContain, "kls"));

            EntityCollection Opportunity = service.RetrieveMultiple(query4);
            foreach (Entity opportunity in Opportunity.Entities)
            {
                OptionSetValue purchaseprocess = (OptionSetValue)opportunity["purchaseprocess"];
                Console.WriteLine(purchaseprocess);
            }
        }
    }
}