Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Web.Services;
- using Microsoft.Xrm.Sdk;
- using Microsoft.Xrm.Tooling.Connector;
- using WebServiceCrm.Properties;
- using Microsoft.Xrm.Sdk.Query;
- using System.Net;
- //using CrmEarlyBound;
- using Microsoft.Crm.Sdk.Messages;
- namespace WebServiceCrm
- {
- //System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
- [WebService(Namespace = "WebServiceCrm")]
- [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
- [System.ComponentModel.ToolboxItem(false)]
- public class WebService : System.Web.Services.WebService
- {
- /*static public OrganizationServiceProxy _serviceProxy;
- static public string connectionString = @"AuthType = Office365; Url=" + Settings.Default.url + "; Username=" + Settings.Default.utilisateur + "; Password=" + Settings.Default.mdp + "";
- static public CrmServiceClient conn = new CrmServiceClient(connectionString);
- static public IOrganizationService _service = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;
- */
- [WebMethod]
- public String Devis(string initiateur, string customerRefERP, int revision, int status, float amount, string nomTarif, string description, string pdf, string division, string contractNumber, DateTime dateCommande, DateTime dateSoumission)
- {
- ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
- string connectionString = @"AuthType = Office365; Url=" + Settings.Default.url + "; Username=" + Settings.Default.utilisateur + "; Password=" + Settings.Default.mdp + "";
- CrmServiceClient conn = new CrmServiceClient(connectionString);
- IOrganizationService _service = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;
- // CONTROLE ARGUMENTS REQUETE
- if (revision < 0)
- {
- return "NOK - REVISION MUST BE GREATER THAN 0";
- }
- if (string.IsNullOrEmpty(initiateur) || (initiateur.Length > 55))
- {
- return "NOK - INITIATEUR MUST BE NOT NULL AND LOWER THAN 55 CHARACTERS";
- }
- if ((status != 1) && (status != 2))
- {
- return "NOK - STATUS MUST BE EQUAL TO 1 FOR SEND TO THE CUSTOMER OR 2 FOR WON";
- }
- if (float.IsNaN(amount))
- {
- return "NOK - AMOUNT MUST BE NOT NULL";
- }
- if (string.IsNullOrEmpty(nomTarif))
- {
- return "NOK - TARIF MUST BE NOT NULL";
- }
- if (string.IsNullOrEmpty(customerRefERP))
- {
- return "NOK - REF ERP MUST BE NOT NULL";
- }
- if (description.Length > 1999)
- {
- return "NOK - DESCRIPTION MUST BE LOWER THAN 2000 CHARACTERS";
- }
- if ((status == 2) && string.IsNullOrEmpty(dateCommande.ToString()))
- {
- return "NOK - STATUS IS WON AND ORDER DATE IS NON-EXISTENT";
- }
- if (string.IsNullOrEmpty(contractNumber))
- {
- return "NOK – CONTRACT NUMBER IS NON-EXISTENT";
- }
- if (string.IsNullOrEmpty(division))
- {
- return "NOK – BUSINESS UNIT IS NON-EXISTENT";
- }
- // CREATION D'UNE ENTITE DEVIS
- Quote devis = new Quote();
- string[] quoteFields = { "quoteid", "new_numerodevisifs", "new_numerodevisdefit", "statecode" };
- Entity devisUp = GetInfo(_service, "quote", quoteFields, "name", (customerRefERP + " - " + contractNumber + " - " + revision));
- if (!string.IsNullOrEmpty(devisUp.LogicalName))
- {
- devis = devisUp.ToEntity<Quote>();
- }
- // OPPORTUNITE
- string[] quoteFieldsOpportunity = { "opportunityid", "ownerid", "new_link_ifs" };
- Entity opportunity = GetInfoOpp(_service, "opportunity", quoteFieldsOpportunity, "new_ifsid", contractNumber);
- if (string.IsNullOrEmpty(opportunity.LogicalName))
- {
- return "NOK _ OPPORTUNITY WITH ID_IFS DON'T FIND";
- }
- Opportunity opp = new Opportunity();
- opp = opportunity.ToEntity<Opportunity>();
- if (!string.IsNullOrEmpty(opportunity.LogicalName))
- {
- devis.OpportunityId = new EntityReference("opportunity", opportunity.Id);
- devis.OwnerId = new EntityReference("systemuser", opp.OwnerId.Id);
- }
- // Name
- devis.Name = customerRefERP + " - " + contractNumber + " - " + revision;
- devis.new_numerodevisifs = customerRefERP + " - " + contractNumber + " - " + revision;
- devis.new_numerodevisdefit = customerRefERP + " - " + contractNumber + " - " + revision;
- //Numero Chrono , compteur de devis
- string[] chronoFields = { "new_valeur" };
- Entity InfoChrono = GetInfo(_service, "new_compteur", chronoFields, "new_name", "ChronosDevisIFS");
- new_compteur Chrono = InfoChrono.ToEntity<new_compteur>();
- System.DateTime moment = System.DateTime.Now;
- String year = moment.Year.ToString();
- // PDF
- if (!string.IsNullOrEmpty(pdf))
- {
- byte[] decodePDF = Convert.FromBase64String(pdf);
- string filePath = @"\SiteIIS\data\" + devis.Name + ".pdf";
- using (var pdfFile = new System.IO.FileStream(filePath, System.IO.FileMode.Create))
- {
- pdfFile.Write(decodePDF, 0, decodePDF.Length);
- pdfFile.Flush();
- }
- }
- // Description
- if (!string.IsNullOrEmpty(description))
- {
- devis.Description = description;
- }
- else
- {
- devis.Description = "";
- }
- // DATE
- DateTime minDate = new DateTime();
- minDate = DateTime.MinValue;
- // throw new Exception("DATE MINI : ______" + minDate.ToString());
- int compareDateSoumission = DateTime.Compare(dateSoumission, minDate);
- int compareDateCommande = DateTime.Compare(dateCommande, minDate);
- if (compareDateSoumission > 0)
- {
- devis.new_Datedenvoidudevis = dateSoumission;
- }
- if (compareDateCommande > 0)
- {
- devis.new_datedecommande = dateCommande;
- }
- // Tarif 2019
- if (!string.IsNullOrEmpty(nomTarif))
- {
- string[] nomTarifField = { "pricelevelid" };
- Entity idTarif = GetInfo(_service, "pricelevel", nomTarifField, "name", nomTarif);
- devis.PriceLevelId = new EntityReference("pricelevel", idTarif.Id);
- }
- // Price EURO
- string[] euroFields = { "transactioncurrencyid" };
- Entity price = GetInfo(_service, "transactioncurrency", euroFields, "isocurrencycode", "EUR");
- TransactionCurrency currencyId = price.ToEntity<TransactionCurrency>();
- devis.TransactionCurrencyId = new EntityReference("transactioncurrency", currencyId.Id);
- // Montant
- devis.new_prixdevente = new Money((decimal)amount);
- // Initiateur
- /*if (!string.IsNullOrEmpty(initiateur)) {
- string[] ownerFields = { "systemuserid" };
- Entity initiateurEntity = GetInfo(_service, "systemuser", ownerFields, "fullname", initiateur);
- if (!string.IsNullOrEmpty(initiateurEntity.Id.ToString()))
- {
- devis.OwnerId = new EntityReference("systemuser", initiateurEntity.Id);
- }
- }*/
- // check division
- String[] RecupChamps = { "new_referenceerpcompteid", "new_compte", "owningbusinessunit", "new_name" };
- String[] businessChamps = { "businessunitid" };
- Entity divisionId = GetInfo(_service, "businessunit", businessChamps, "divisionname", division);
- Guid businessId = new Guid();
- businessId = divisionId.Id;
- EntityCollection compteId = GetInfoBis(_service, "new_referenceerpcompte", RecupChamps, "new_name", customerRefERP, "new_division", businessId.ToString());
- int nbCompte = 0;
- foreach (new_referenceerpcompte refCompteId in compteId.Entities)
- {
- nbCompte++;
- }
- if (nbCompte == 1)
- {
- foreach (new_referenceerpcompte refCompteId in compteId.Entities)
- {
- // Account Name
- devis.CustomerId = new EntityReference("account", refCompteId.new_Compte.Id);
- }
- }
- else if (nbCompte < 1)
- {
- return "NOK – THERE IS NO ACCOUNT FOR THIS CUSTOMER ERP REFERENCES";
- }
- else
- {
- return "NOK – THERE IS TWO ACCOUNT OR MORE WITH THE SAME CUSTOMER ERP REFERENCES";
- }
- //LIGNE PROJET INSTALLATEUR
- string[] quoteFieldsProjet = { "new_installateurdunprojetid" };
- Entity ligneProjet = GetInfoTer(_service, "new_installateurdunprojet", quoteFieldsProjet, "new_opportunit", opportunity.Id.ToString(), "new_installateur", devis.CustomerId.Id.ToString());
- if (!string.IsNullOrEmpty(ligneProjet.LogicalName))
- {
- devis.new_projetinstallateur = new EntityReference("new_installateurdunprojet", ligneProjet.Id);
- }
- //foreach (new_referenceerpcompte refCompteId in compteId.Entities)
- //{
- // if (!string.IsNullOrEmpty(refCompteId.Id.ToString()))
- // {
- // Entity divisionInfo = GetInfo(_service, "businessunit", "name", "businessunitid", refCompteId.new_division.Id.ToString());
- // BusinessUnit divisionName = divisionInfo.ToEntity<BusinessUnit>();
- // DIVISION : 13630d5a-755e-e811-8144-70106fa7c0e1 === "DEF FRANCE DIROP COMPTE SPÉCIFIQUES"
- //if (refCompteId.new_division.Id.ToString() == "13630d5a-755e-e811-8144-70106fa7c0e1")
- // if ( divisionName.Name.ToString().Contains(division))
- //if (divisionName.Name.ToString().Contains("DEF FR"))
- //{
- // devis.CustomerId = new EntityReference("account", refCompteId.new_Compte.Id);
- //}
- //}
- //}
- if (devis.Id == new Guid())
- {
- // Numéro du devis
- //devis.new_numerodevisdefit = "IFS-" + year.Substring(2, 2) + "-" + Chrono.new_valeur.ToString() + "-" + revision;
- //devis.new_numerodevisifs = (contractNumber + "-" + revision);
- // Incrémentation du compteur de devis
- Chrono.new_valeur = (int.Parse(Chrono.new_valeur) + 1).ToString();
- _service.Update(Chrono);
- // Status
- devis.StateCode = QuoteState.Draft;
- devis.StatusCode = new OptionSetValue(1);
- // ID DU DEVIS CREEE
- Guid idDevis = new Guid();
- idDevis = _service.Create(devis);
- /*String[] newQuoteField = { "quoteid" };
- Entity RecupNewDevis = GetInfo(_service, "quote", newQuoteField, "quoteid", idDevis.ToString());
- Quote devisRecup = RecupNewDevis.ToEntity<Quote>();*/
- devis.Id = idDevis;
- //PIECE JOINT ADD BASE64 PDF BORDEREAU
- if (!string.IsNullOrEmpty(pdf))
- {
- Annotation note = new Annotation();
- // ASSOCIATION AU DEVIS
- note.ObjectTypeCode = "quote";
- note.ObjectId = new EntityReference("quote", devis.Id);
- // ASSOCIATION DU PDF
- note.NoteText = "Fichier PDF";
- if (status == 1)
- {
- note.Subject = "Bordereau généré à la creation du devis";
- }
- else
- {
- note.Subject = "Bordereau généré à la cloture du devis";
- }
- note.FileName = devis.Name + ".pdf";
- note.MimeType = "application/pdf";
- note.DocumentBody = pdf;
- _service.Create(note);
- }
- // Passage du devis créé en Actif
- devis.StateCode = QuoteState.Active;
- devis.StatusCode = new OptionSetValue(3);
- _service.Update(devis);
- if (status == 2)
- {
- // Passage du devis créé en Conclue
- WinQuoteRequest winQuoteRequest = new WinQuoteRequest();
- Entity quoteClose = new Entity("quoteclose");
- quoteClose.Attributes["quoteid"] = new EntityReference("quote", devis.Id);
- quoteClose.Attributes["subject"] = "Quote Close" + DateTime.Now.ToString();
- winQuoteRequest.QuoteClose = quoteClose;
- winQuoteRequest.Status = new OptionSetValue(-1);
- _service.Execute(winQuoteRequest);
- return "OK - QUOTE NAME WON AND CLOSED: " + devis.Name;
- }
- return "OK _ QUOTE NAME : " + devis.Name;
- }
- else
- {
- if ((status == 1) || (devis.StateCode.ToString() != "Active"))
- {
- return "NOK _ QUOTE ALREADY EXIST AND IT IS CLOSED, PLEASE CREATE NEW REVISION";
- }
- _service.Update(devis);
- // CHECK LES
- if (!string.IsNullOrEmpty(pdf))
- {
- Annotation note = new Annotation();
- // ASSOCIATION AU DEVIS
- note.ObjectTypeCode = "quote";
- note.ObjectId = new EntityReference("quote", devis.Id);
- // ASSOCIATION DU PDF
- note.NoteText = "Fichier PDF";
- note.Subject = "Bordereau généré à la cloture du devis";
- note.FileName = devis.Name + ".pdf";
- note.MimeType = "application/pdf";
- note.DocumentBody = pdf;
- _service.Create(note);
- }
- // Passage du devis Actif en Conclus
- WinQuoteRequest winQuoteRequest = new WinQuoteRequest();
- Entity quoteClose = new Entity("quoteclose");
- quoteClose.Attributes["quoteid"] = new EntityReference("quote", devis.Id);
- quoteClose.Attributes["subject"] = "Quote Close" + DateTime.Now.ToString();
- winQuoteRequest.QuoteClose = quoteClose;
- winQuoteRequest.Status = new OptionSetValue(-1);
- _service.Execute(winQuoteRequest);
- return "OK - QUOTE NAME WON AND CLOSED: " + devis.Name;
- }
- // Creation Annotation avec pièce jointe
- /*if (!string.IsNullOrEmpty(pdf) && (status == 1)) {
- Annotation note = new Annotation();
- // ASSOCIATION AU DEVIS
- note.ObjectTypeCode = "quote";
- note.ObjectId = new EntityReference("quote", devis.Id);
- // ASSOCIATION DU PDF
- note.NoteText = "Fichier pdf bis";
- note.Subject = "sujet de la pièce jointe";
- note.FileName = devis.Name + ".pdf";
- note.MimeType = "application/pdf";
- note.DocumentBody = pdf;
- _service.Create(note);
- return "OK - QUOTE NAME: " + devis.Name;
- } */
- }
- [WebMethod]
- public String Compte(string nomCompte, string numeroCompte, int typeRelation, string remise, string initiateur, string adresse1, string adresse2, string ville, string codePostal, string region, string pays, string tel, string siteWeb, string fax, string email, string nomTarif, string paymentTermsCode, string shippingMethodCode, string referenceUnique, string division, bool statut)
- {
- ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
- string connectionString = @"AuthType = Office365; Url=" + Settings.Default.url + "; Username=" + Settings.Default.utilisateur + "; Password=" + Settings.Default.mdp + "";
- CrmServiceClient conn = new CrmServiceClient(connectionString);
- IOrganizationService _service = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;
- int condition = 0;
- // CONTROLE INPUT DATA
- if (nomCompte.Length > 100)
- {
- return "NOK _ Account name would be less than 100 char";
- }
- if (numeroCompte.Length > 25)
- {
- return "NOK _ ACCOUNT NUMBER would be less than 25 char";
- }
- if ((typeRelation < 1) || (typeRelation > 6))
- {
- return "NOK _ RELATION TYPE would be less than 6 char";
- }
- if (ville.Length < 1)
- {
- return "NOK _ CITY cannot be null";
- }
- if (ville.Length > 110)
- {
- return "NOK _ CITY would be less than 110 char";
- }
- if (pays.Length != 2)
- {
- return "NOK _ COUNTRY FORMAT would be ISO format , only 2 char ";
- }
- if ((initiateur.Length < 5) || (initiateur.Length > 75))
- {
- return "NOK _ OWNER would be less than 75 char";
- }
- if ((nomTarif.Length < 3) || (nomTarif.Length > 10))
- {
- return "NOK _ WRONG TARIF (exemple : '2019')";
- }
- // SIRET
- //if (referenceUnique.Length != 14 )
- //{
- // return " NOK - WRONG SIRET FORMAT (less than 14 char)";
- //}
- // DIVISION
- //
- Account compte = new Account();
- Entity compteTempo = new Entity();
- compteTempo = getReferenceCompteByCle(_service, referenceUnique);
- if (!string.IsNullOrEmpty(compteTempo.Id.ToString()))
- {
- compte = compteTempo.ToEntity<Account>();
- }
- BusinessUnit ReferenceActuelle = new BusinessUnit();
- Entity referenceActuelleTempo = new Entity();
- String[] businessUnitField = { "businessunitid" };
- referenceActuelleTempo = GetInfo(_service, "businessunit", businessUnitField, "name", division);
- if (!string.IsNullOrEmpty(referenceActuelleTempo.Id.ToString()))
- {
- ReferenceActuelle = referenceActuelleTempo.ToEntity<BusinessUnit>();
- }
- else
- {
- return "NOK _ DIVISION doesn't not exist";
- }
- if (string.IsNullOrEmpty(compte.Name))
- {
- // Creation
- condition = 1;
- compte.StateCode = AccountState.Active;
- compte.StatusCode = new OptionSetValue(1);
- }
- else
- {
- if (compte.CustomerTypeCode.Value == 3 || compte.CustomerTypeCode.Value == 4)
- {
- if (!string.IsNullOrEmpty(compte.new_societereferente.ToString()) && compte.new_societereferente.Id == ReferenceActuelle.Id)
- {
- // update
- condition = 2;
- }
- else
- {
- // creation ref ERP
- condition = 3;
- }
- }
- else
- {
- // transformation client
- condition = 4;
- }
- }
- /*********** PREPARATION CREATION / MISE A JOUR COMPTE ****************/
- if (!string.IsNullOrEmpty(referenceUnique))
- {
- //Nom du compte
- if (!string.IsNullOrEmpty(nomCompte))
- {
- compte.Name = nomCompte;
- }
- //Remise
- if (!string.IsNullOrEmpty(remise))
- {
- String[] discountField = { "ac_remiseclientid" };
- Entity remiseEntity = GetInfo(_service, "ac_remiseclient", discountField, "ac_name", remise);
- if (!string.IsNullOrEmpty(remiseEntity.Id.ToString()))
- {
- compte.ac_RemiseId = new EntityReference("ac_remiseclient", remiseEntity.Id);
- }
- }
- //Initiateur
- if (!string.IsNullOrEmpty(initiateur))
- {
- String[] userIdField = { "systemuserid" };
- Entity initiateurEntity = GetInfo(_service, "systemuser", userIdField, "fullname", initiateur);
- //Entity initiateurEntity = GetInfo(_service, "team", "teamid", "name", initiateur);
- if (!string.IsNullOrEmpty(initiateurEntity.Id.ToString()))
- {
- //compte.OwnerId = new EntityReference("team", initiateurEntity.Id);
- compte.OwnerId = new EntityReference("systemuser", initiateurEntity.Id);
- }
- }
- //Telephone
- compte.Telephone1 = tel;
- //Site web
- compte.WebSiteURL = siteWeb;
- //Fax
- compte.Fax = fax;
- //Email
- compte.asd_eMailenvoiAR = email;
- //Adresse1
- compte.Address1_Line1 = adresse1;
- //Adresse 2
- compte.Address1_Line2 = adresse2;
- //Pays
- new_country_list Paystempo = new new_country_list();
- if (!string.IsNullOrEmpty(pays))
- {
- if (pays.Length == 2)
- {
- String[] countryField = { "new_country_listid", "new_typedecleunique" };
- Entity PaysEntity = GetInfo(_service, "new_country_list", countryField, "new_codepays", pays);
- //Entity initiateurEntity = GetInfo(_service, "team", "teamid", "name", initiateur);
- if (!string.IsNullOrEmpty(PaysEntity.Id.ToString()))
- {
- Paystempo = PaysEntity.ToEntity<new_country_list>();
- compte.new_PaysIndicatif = new EntityReference("new_country_list", PaysEntity.Id);
- compte.Address1_Country = pays;
- }
- else
- {
- return "NOK – COUNTRY NOT FOUND";
- }
- }
- else
- {
- return "NOK – COUNTRY FIELD IS NOT IN ISO FORMAT";
- }
- }
- //REFERENCE UNIQUE
- if (condition == 1)
- {
- if (Paystempo.Contains("new_typedecleunique"))
- {
- if (Paystempo.new_typedecleunique.Value == 100000001)
- {
- compte.asd_TVAintracom = referenceUnique;
- compte.new_cleunique = referenceUnique;
- }
- else if (Paystempo.new_typedecleunique.Value == 100000000)
- {
- compte.exp_siret = referenceUnique;
- compte.new_cleunique = referenceUnique;
- }
- else if (Paystempo.new_typedecleunique.Value == 100000002)
- {
- compte.new_taxnumber = referenceUnique;
- compte.new_cleunique = referenceUnique;
- }
- else if (Paystempo.new_typedecleunique.Value == 100000003)
- {
- compte.new_uniformsocialcreditcode = referenceUnique;
- compte.new_cleunique = referenceUnique;
- }
- else if (Paystempo.new_typedecleunique.Value == 100000004)
- {
- compte.new_rci = referenceUnique;
- compte.new_cleunique = referenceUnique;
- }
- }
- else
- {
- compte.new_cleuniquenoncatgoriser = referenceUnique;
- }
- }
- if (condition == 1 || condition == 4)
- {
- compte.new_societereferente = new EntityReference("businessunit", ReferenceActuelle.Id);
- }
- //Ville
- if (!string.IsNullOrEmpty(ville))
- {
- compte.Address1_City = ville;
- }
- //Region
- compte.Address1_StateOrProvince = region;
- //Code Postal
- compte.Address1_PostalCode = codePostal;
- //Type de relation
- if (!string.IsNullOrEmpty(typeRelation.ToString()))
- {
- compte.CustomerTypeCode = new OptionSetValue(typeRelation);
- }
- //Condition de paiement
- if (!string.IsNullOrEmpty(paymentTermsCode.ToString()))
- {
- compte.PaymentTermsCode = new OptionSetValue(Convert.ToInt32(paymentTermsCode));
- }
- //mode de livraison
- if (!string.IsNullOrEmpty(shippingMethodCode.ToString()))
- {
- compte.Address1_FreightTermsCode = new OptionSetValue(Convert.ToInt32(shippingMethodCode));
- }
- if (!string.IsNullOrEmpty(nomTarif))
- {
- //LIAISON TARIF
- String[] tarifField = { "pricelevelid" };
- Entity idTarif = GetInfo(_service, "pricelevel", tarifField, "name", nomTarif);
- compte.DefaultPriceLevelId = new EntityReference("pricelevel", idTarif.Id);
- }
- else
- {
- compte.DefaultPriceLevelId = null;
- }
- /*********** FIN PREPARATION MISE A JOUR COMPTE ****************/
- if (condition == 1)
- {
- if (!statut)
- {
- // CREATION COMPTE
- Guid guidCompte = _service.Create(compte);
- // CREATION REF ERP
- new_referenceerpcompte referenceERP = new new_referenceerpcompte();
- String[] userField = { "systemuserid" };
- Entity initiateurEntity2 = GetInfo(_service, "systemuser", userField, "fullname", initiateur);
- referenceERP.OwnerId = new EntityReference("systemuser", initiateurEntity2.Id);
- //Entity divisionEntity = GetInfo(_service, "businessunit", "businessunitid", "name", division);
- String[] businessField = { "businessunitid" };
- Entity divisionEntity = GetInfo(_service, "businessunit", businessField, "divisionname", division);
- referenceERP.new_division = new EntityReference("team", divisionEntity.Id);
- referenceERP.new_name = numeroCompte;
- referenceERP.new_Ref_defaut = true;
- referenceERP.new_Compte = new EntityReference("account", guidCompte);
- referenceERP.new_bloque = false;
- _service.Create(referenceERP);
- return "OK - CREATION ACCOUNT";
- }
- else
- {
- return "OK – BLOQUED ACCOUNT, NOT CREATED";
- }
- }
- else if (condition == 2)
- {
- if (statut)
- {
- EntityCollection tableauRefErpTampon = getAllRefErpByIdCompte(_service, compte.Id);
- int nb = 0;
- foreach (new_referenceerpcompte referp in tableauRefErpTampon.Entities)
- {
- if (referp.new_division.Id == compte.new_societereferente.Id)
- {
- referp.new_bloque = true;
- _service.Update(referp);
- }
- else if ((nb < 2) && (referp.new_division.Id != compte.new_societereferente.Id))
- {
- // throw new Exception(compte.new_societereferente.Id.ToString() + " referp.newDiv" + referp.new_division.Id.ToString() );
- compte.new_societereferente.Id = referp.new_division.Id;
- }
- nb++;
- } // Cannot insert duplicate key
- if (nb <= 1)
- {
- compte.CustomerTypeCode = new OptionSetValue(1);
- compte.StateCode = AccountState.Inactive;
- compte.StatusCode = new OptionSetValue(2);
- compte.new_societereferente = null;
- }
- }
- // MODIF COMPTE
- _service.Update(compte);
- return "OK – MODIFICATION ACCOUNT";
- }
- else if (condition == 3)
- {
- //VERIF REF ERP
- new_referenceerpcompte referenceERP = new new_referenceerpcompte();
- referenceERP = getReferenceERPCompte(_service, compte.Id, ReferenceActuelle.Id).ToEntity<new_referenceerpcompte>();
- // compte bloque ?
- // if (statut) { referenceERP.new_bloque = statut; }
- // else { referenceERP.new_bloque = false; }
- if (string.IsNullOrEmpty(referenceERP.new_name))
- {
- if (!statut)
- {
- // CREATE REF ERP
- String[] refERPField = { "systemuserid" };
- Entity initiateurEntity2 = GetInfo(_service, "systemuser", refERPField, "fullname", initiateur);
- referenceERP.OwnerId = new EntityReference("systemuser", initiateurEntity2.Id);
- String[] businessIdPField = { "businessunitid" };
- Entity divisionEntity = GetInfo(_service, "businessunit", businessIdPField, "divisionname", division);
- referenceERP.new_division = new EntityReference("team", divisionEntity.Id);
- referenceERP.new_name = numeroCompte;
- referenceERP.new_Ref_defaut = false;
- referenceERP.new_Compte = new EntityReference("account", compte.Id);
- _service.Create(referenceERP);
- return "OK - CREATION REF ERP";
- }
- else
- {
- return "OK - BLOCKED ACCOUNT REF ERP, NOT CREATED";
- }
- }
- else if (referenceERP.new_bloque != statut)
- {
- referenceERP.new_bloque = statut;
- _service.Update(referenceERP);
- return "OK - MODIF REF ERP";
- }
- else
- {
- return "OK - REF ERP UNCHANGED";
- }
- }
- else if (condition == 4)
- {
- if (!statut)
- {
- // UNLOCK CLIENT
- if (compte.StateCode.ToString() == "Inactive")
- {
- compte.StateCode = AccountState.Active;
- compte.StatusCode = new OptionSetValue(1);
- }
- //TRANFORMATION EN CLIENT + MAJ
- _service.Update(compte);
- //VERIF REF ERP
- new_referenceerpcompte referenceERP = new new_referenceerpcompte();
- referenceERP = getReferenceERPCompte(_service, compte.Id, ReferenceActuelle.Id).ToEntity<new_referenceerpcompte>();
- if (string.IsNullOrEmpty(referenceERP.new_name))
- {
- // CREATE REF ERP
- String[] sysUserField = { "systemuserid" };
- Entity initiateurEntity2 = GetInfo(_service, "systemuser", sysUserField, "fullname", initiateur);
- referenceERP.OwnerId = new EntityReference("systemuser", initiateurEntity2.Id);
- String[] businessField = { "businessunitid" };
- Entity divisionEntity = GetInfo(_service, "businessunit", businessField, "divisionname", division);
- referenceERP.new_division = new EntityReference("team", divisionEntity.Id);
- referenceERP.new_name = numeroCompte;
- referenceERP.new_Ref_defaut = true;
- referenceERP.new_Compte = new EntityReference("account", compte.Id);
- // COMPTE BLOQUE ?
- // if (statut) { referenceERP.new_bloque = statut; }
- // else { referenceERP.new_bloque = false; }
- _service.Create(referenceERP);
- }
- // // COMPTE BLOQUE ?
- // if (statut) { referenceERP.new_bloque = statut; }
- // else { referenceERP.new_bloque = false; }
- // _service.Update(referenceERP);
- if (typeRelation == 1)
- {
- return " OK - PROSPECT UPDATED";
- }
- return "OK - TRANFORMATION PROSPECT TO ACCOUNT";
- }
- else
- {
- return "OK -BLOQUED ACCOUNT, NO TRANFORMED TO ACCOUNT";
- }
- }
- else
- {
- return "NOK - MISSING MENDATORY FIELD";
- }
- }
- return "NOK - MISSING CLE UNIQUE (SIRET, TAX NUMBER, TVA INTRACOM, …)";
- }
- [WebMethod]
- public string Produit(string nomProduit, string idProduit, string groupUnit, string defaultUnit, string defaultTarif, string division, decimal prixCession, int categorieMateriel, string classification, string itemCategoryCode, string productGroupCode, string descriptionLongue, string metier, int bloquer)
- {
- ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
- string connectionString = @"AuthType = Office365; Url=" + Settings.Default.url + "; Username=" + Settings.Default.utilisateur + "; Password=" + Settings.Default.mdp + "";
- CrmServiceClient conn = new CrmServiceClient(connectionString);
- IOrganizationService _service = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;
- Product produit = new Product();
- produit = GetProduit(_service, idProduit).ToEntity<Product>();
- if (!string.IsNullOrEmpty(idProduit))
- {
- //Nom du produit
- if (!string.IsNullOrEmpty(nomProduit))
- {
- produit.Name = nomProduit;
- }
- // 1 => PRODUIT
- produit.ProductStructure = new OptionSetValue(1);
- // Nombre de chiffre après la virgule => dans notre cas toujours 2
- produit.QuantityDecimal = 2;
- //PRIX DE CESSION
- if (!string.IsNullOrEmpty(prixCession.ToString()))
- {
- produit.ac_Prixdecession = new Money(prixCession);
- }
- else
- {
- produit.ac_Prixdecession = new Money(0);
- }
- //Groupe d'unité
- if (!string.IsNullOrEmpty(groupUnit))
- {
- String[] teamField = { "uomscheduleid" };
- Entity GroupeUnite = GetInfo(_service, "uomschedule", teamField, "name", groupUnit);
- if (!string.IsNullOrEmpty(GroupeUnite.Id.ToString()))
- {
- produit.DefaultUoMScheduleId = new EntityReference("uomschedule", GroupeUnite.Id);
- }
- }
- //Unité par défaut
- if (!string.IsNullOrEmpty(defaultUnit))
- {
- String[] teamField = { "uomid" };
- Entity DefautUnit = GetInfo(_service, "uom", teamField, "name", defaultUnit);
- if (!string.IsNullOrEmpty(DefautUnit.Id.ToString()))
- {
- produit.DefaultUoMId = new EntityReference("uom", DefautUnit.Id);
- }
- }
- //Division
- if (!string.IsNullOrEmpty(division))
- {
- String[] businessField = { "businessunitid" };
- Entity Division = GetInfo(_service, "businessunit", businessField, "name", division);
- if (!string.IsNullOrEmpty(Division.Id.ToString()))
- {
- produit.ac_Division = new EntityReference("businessunit", Division.Id);
- }
- }
- //Catégorie
- if (!string.IsNullOrEmpty(categorieMateriel.ToString()))
- {
- produit.ac_Categorie = new OptionSetValue(categorieMateriel);
- }
- //itemCategoryCode
- if (!string.IsNullOrEmpty(itemCategoryCode.ToString()))
- {
- produit.new_ItemCategoryCode = new OptionSetValue(Convert.ToInt32(itemCategoryCode));
- }
- //productGroupCode
- if (!string.IsNullOrEmpty(productGroupCode.ToString()))
- {
- produit.new_ProductGroupCode = new OptionSetValue(Convert.ToInt32(productGroupCode));
- }
- //Classification
- if (!string.IsNullOrEmpty(classification.ToString()))
- {
- produit.new_classification = classification;
- }
- //Description Longue
- if (!string.IsNullOrEmpty(descriptionLongue.ToString()))
- {
- produit.Description = descriptionLongue;
- }
- //metier
- /*if (!string.IsNullOrEmpty(metier.ToString()))
- {
- produit.new_metier = new OptionSetValue(Convert.ToInt32(metier));
- }*/
- //bloquer 0 = non et 1 = oui
- /*if (bloquer == 0)
- {
- produit.StateCode = ProductState.Active;
- produit.StatusCode = new OptionSetValue(1);
- }
- else
- {
- produit.StateCode = ProductState.Inactive;
- produit.StatusCode = new OptionSetValue(2);
- }*/
- //produit.new_blocked = Convert.ToBoolean(bloquer);
- //CREATION OU MODIFICATION
- if (string.IsNullOrEmpty(produit.ProductNumber))
- {
- produit.ProductNumber = idProduit;
- _service.Create(produit);
- Product produit2 = new Product();
- produit2 = GetProduit(_service, idProduit).ToEntity<Product>();
- //Tarifs par défaut
- if (!string.IsNullOrEmpty(defaultTarif))
- {
- String[] priceField = { "pricelevelid" };
- Entity DefautTarif = GetInfo(_service, "pricelevel", priceField, "name", defaultTarif);
- if (!string.IsNullOrEmpty(DefautTarif.Id.ToString()))
- {
- produit2.PriceLevelId = new EntityReference("pricelevel", DefautTarif.Id);
- }
- }
- //produit2.StateCode = ProductState.Active;
- _service.Update(produit2);
- /*if (!string.IsNullOrEmpty(defaultTarif))
- {
- Tarif(defaultTarif, idProduit, "unité principale", 1, 1, 0 );
- Tarif("2017", idProduit, "unité principale", 1, 1, 0);
- return "CREATION - OK + LIGNE TARIFAIRE 0 - OK";
- }*/
- return "CREATION - OK";
- }
- else
- {
- _service.Update(produit);
- //throw new Exception("CRM TARIF === "+ CRMtarif.Id.ToString());
- /* if (!string.IsNullOrEmpty(defaultTarif))
- {
- //LIAISON TARIF
- Entity idTarif = GetInfo(_service, "pricelevel", "pricelevelid", "name", defaultTarif);
- Entity LigneTarifaire = GetElementTarifaire(_service, produit.Id, idTarif.Id);
- if (!string.IsNullOrEmpty(LigneTarifaire.Id.ToString()))
- {
- Tarif(defaultTarif, idProduit, "unité principale", 1, 1, 0);
- }
- //LIAISON TARIF
- Entity idTarif3 = GetInfo(_service, "pricelevel", "pricelevelid", "name", "2017");
- Entity LigneTarifaire3 = GetElementTarifaire(_service, produit.Id, idTarif3.Id);
- if (!string.IsNullOrEmpty(LigneTarifaire3.Id.ToString()))
- {
- Tarif("2017", idProduit, "unité principale", 1, 1, 0);
- }
- return "MODIFICATION - OK + LIGNE TARIFAIRE 0 - OK";
- }*/
- return "MODIFICATION - OK";
- }
- }
- else
- {
- return "Numéro de produit - NOK";
- }
- }
- [WebMethod]
- public string Tarif(string nomTarif, string numeroProduit, string unite, int optionQuantiteVente, int modeTarification, decimal montant)
- {
- ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
- string connectionString = @"AuthType = Office365; Url=" + Settings.Default.url + "; Username=" + Settings.Default.utilisateur + "; Password=" + Settings.Default.mdp + "";
- CrmServiceClient conn = new CrmServiceClient(connectionString);
- IOrganizationService _service = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;
- //LIAISON TARIF
- String[] tarifField = { "pricelevelid" };
- Entity idTarif = GetInfo(_service, "pricelevel", tarifField, "name", nomTarif);
- //LIAISON PRODUIT
- String[] productField = { "productid" };
- Entity idProduit = GetInfo(_service, "product", productField, "productnumber", numeroProduit);
- ProductPriceLevel tarifProduit = new ProductPriceLevel();
- Entity tarifProduitTemp = new Entity();
- tarifProduitTemp = GetElementTarifaire(_service, idProduit.Id, idTarif.Id);
- if (tarifProduitTemp is ProductPriceLevel)
- {
- tarifProduit = tarifProduitTemp.ToEntity<ProductPriceLevel>();
- }
- if (!string.IsNullOrEmpty(nomTarif) && !string.IsNullOrEmpty(numeroProduit) && !string.IsNullOrEmpty(montant.ToString()))
- {
- //LIAISON UNITE
- String[] unitField = { "uomid" };
- Entity idUnite = GetInfo(_service, "uom", unitField, "name", unite);
- tarifProduit.UoMId = new EntityReference("uom", idUnite.Id);
- //Option de quantité de vente
- if (!string.IsNullOrEmpty(optionQuantiteVente.ToString()))
- {
- tarifProduit.QuantitySellingCode = new OptionSetValue(optionQuantiteVente);
- }
- //Mode de tarification
- if (!string.IsNullOrEmpty(modeTarification.ToString()))
- {
- tarifProduit.PricingMethodCode = new OptionSetValue(modeTarification);
- }
- //Montant
- tarifProduit.Amount = new Money(montant);
- //CREATION OU MODIFICATION
- if (tarifProduit.PriceLevelId is EntityReference && tarifProduit.ProductId is EntityReference)
- {
- _service.Update(tarifProduit);
- return "MODIFICATION - OK";
- }
- else
- {
- tarifProduit.PriceLevelId = new EntityReference("pricelevel", idTarif.Id);
- tarifProduit.ProductId = new EntityReference("product", idProduit.Id);
- _service.Create(tarifProduit);
- return "CREATION - OK";
- }
- }
- else
- {
- return "Numéro de produit - NOK";
- }
- }
- /*[WebMethod]
- public String Batiment(string nomBatiment, string numeroBatiment, string initiateur, string adresse1, string adresse2, string ville, string codePostal, string region, string pays, string numeroCompte, string division)
- {
- ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
- string connectionString = @"AuthType = Office365; Url=" + Settings.Default.url + "; Username=" + Settings.Default.utilisateur + "; Password=" + Settings.Default.mdp + "";
- CrmServiceClient conn = new CrmServiceClient(connectionString);
- IOrganizationService _service = (IOrganizationService)conn.OrganizationWebProxyClient != null ? (IOrganizationService)conn.OrganizationWebProxyClient : (IOrganizationService)conn.OrganizationServiceProxy;
- int condition = 0;
- new_referenceerpbatiment referenceERP = new new_referenceerpbatiment();
- referenceERP = GetReferenceERPBatiment(_service, numeroBatiment).ToEntity<new_referenceerpbatiment>();
- //throw new Exception(referenceERP.Id.ToString());
- new_site batiment = new new_site();
- //if (!string.IsNullOrEmpty(referenceERP.new_Compte.Id.ToString()))
- if (referenceERP.GetAttributeValue<EntityReference>("new_batiment") != null)
- {
- ColumnSet columns = new ColumnSet(new String[] { "new_name", "new_siteid" });
- batiment = (new_site)_service.Retrieve("new_site", referenceERP.new_Batiment.Id, columns);
- }
- if (!string.IsNullOrEmpty(batiment.new_name))
- {
- condition = 3;
- }
- else
- {
- batiment = GetBatiment(_service, nomBatiment).ToEntity<new_site>();
- if (!string.IsNullOrEmpty(batiment.new_name))
- {
- condition = 2;
- }
- else
- {
- condition = 1;
- }
- }
- if (!string.IsNullOrEmpty(numeroBatiment))
- {
- ///////////////// PREPARATION CREATION / MISE A JOUR BATIMENT //////////////////
- //Nom du compte
- if (!string.IsNullOrEmpty(nomBatiment))
- {
- batiment.new_name = nomBatiment;
- }
- //Initiateur
- if (!string.IsNullOrEmpty(initiateur))
- {
- //Entity initiateurEntity = GetInfo(_service, "team", "teamid", "name", initiateur);
- Entity initiateurEntity = GetInfo(_service, "systemuser", "systemuserid", "fullname", initiateur);
- if (!string.IsNullOrEmpty(initiateurEntity.Id.ToString()))
- {
- //batiment.OwnerId = new EntityReference("team", initiateurEntity.Id);
- batiment.OwnerId = new EntityReference("systemuser", initiateurEntity.Id);
- }
- }
- //Adresse1
- batiment.new_AdresseRue1 = adresse1;
- //Adresse 2
- batiment.new_AdresseRue2 = adresse2;
- //Ville
- batiment.new_AdresseVille = ville;
- //Pays
- batiment.new_AdressePays = pays;
- //Code Postal
- batiment.new_AdresseCodepostal = codePostal;
- //Compte
- new_referenceerpcompte referenceERPCompte = new new_referenceerpcompte();
- referenceERPCompte = GetReferenceERPCompte(_service, numeroCompte).ToEntity<new_referenceerpcompte>();
- batiment.new_Compteexploitant = referenceERPCompte.new_Compte;
- ///////////////// FIN PREPARATION MISE A JOUR BATIMENT /////////////////
- // 3 condition :
- //Entity initiateurEntity2 = GetInfo(_service, "team", "teamid", "name", initiateur);
- Entity initiateurEntity2 = GetInfo(_service, "systemuser", "systemuserid", "fullname", initiateur);
- //referenceERP.OwnerId = new EntityReference("team", initiateurEntity2.Id);
- referenceERP.OwnerId = new EntityReference("systemuser", initiateurEntity2.Id);
- Entity divisionEntity = GetInfo(_service, "businessunit", "businessunitid", "divisionname", division);
- referenceERP.new_Division = new EntityReference("team", divisionEntity.Id);
- referenceERP.new_Ref_defaut = true;
- // 1. Compte existe et ligne ref erp aussi
- if (condition == 3)
- {
- _service.Update(batiment);
- return "MODIFICATION BATIMENT - OK";
- }
- // 2. Compte existe mais pas la ligne REF ERP
- else if (condition == 2)
- {
- referenceERP.new_Batiment = batiment.ToEntityReference();
- referenceERP.new_name = numeroBatiment;
- _service.Create(referenceERP);
- _service.Update(batiment);
- return "MODIFICATION BATIMENT - OK + CREATION REF ERP - OK";
- //3. Le compte n'existe pas et donc la ligne REF ERP non plus !
- }
- else if (condition == 1)
- {
- Guid guidCompte = _service.Create(batiment);
- ColumnSet cols = new ColumnSet(new String[] { "new_name", "new_siteid" });
- new_site RetrievedBatiment = (new_site)_service.Retrieve("new_site", guidCompte, cols);
- referenceERP.new_Batiment = new EntityReference("new_site", RetrievedBatiment.Id);
- referenceERP.new_name = numeroBatiment;
- _service.Create(referenceERP);
- return "CREATION - OK";
- }
- else
- {
- return "ERROR";
- }
- }
- else
- {
- return "Numéro de batiment vide";
- }
- }*/
- static Entity GetInfo(IOrganizationService Service, string nomTable, string[] ChampRecup, string champCondition, string variableCondition)
- {
- QueryExpression query = new QueryExpression();
- query.ColumnSet = new ColumnSet(ChampRecup);
- query.EntityName = nomTable;
- FilterExpression Fe = new FilterExpression();
- ConditionExpression Ce = new ConditionExpression();
- Ce.AttributeName = champCondition;
- Ce.Operator = ConditionOperator.Equal;
- Ce.Values.Add(variableCondition);
- Fe.AddCondition(Ce);
- query.Criteria.AddFilter(Fe);
- try
- {
- EntityCollection retrieve = Service.RetrieveMultiple(query);
- return retrieve[0];
- }
- catch (Exception ex)
- {
- //throw new Exception(ex.Message);
- Entity entity = new Entity();
- return entity;
- }
- }
- static Entity GetInfoOpp(IOrganizationService Service, string nomTable, string[] ChampRecup, string champCondition, string variableCondition)
- {
- QueryExpression query = new QueryExpression();
- query.ColumnSet = new ColumnSet(ChampRecup);
- query.EntityName = nomTable;
- FilterExpression Fe = new FilterExpression();
- ConditionExpression Ce = new ConditionExpression();
- Ce.AttributeName = champCondition;
- Ce.Operator = ConditionOperator.Equal;
- Ce.Values.Add(variableCondition);
- Fe.AddCondition(Ce);
- query.Criteria.AddFilter(Fe);
- try
- {
- EntityCollection retrieve = Service.RetrieveMultiple(query);
- return retrieve[0];
- }
- catch (Exception)
- {
- // throw new Exception("NOK _ OPPORTUNITY WITH ID_IFS DON'T FIND");
- Entity entity = new Entity();
- return entity;
- }
- }
- static EntityCollection GetInfoBis(IOrganizationService Service, string nomTable, string[] ChampRecup, string champCondition1, string variableCondition1, string champCondition2, string variableCondition2)
- {
- QueryExpression query = new QueryExpression();
- query.ColumnSet = new ColumnSet(ChampRecup);
- query.EntityName = nomTable;
- FilterExpression Fe = new FilterExpression(LogicalOperator.And);
- ConditionExpression Ce = new ConditionExpression();
- Ce.AttributeName = champCondition1;
- Ce.Operator = ConditionOperator.Equal;
- Ce.Values.Add(variableCondition1);
- Fe.AddCondition(Ce);
- ConditionExpression Ce2 = new ConditionExpression();
- Ce2.AttributeName = champCondition2;
- Ce2.Operator = ConditionOperator.Equal;
- Ce2.Values.Add(variableCondition2);
- Fe.AddCondition(Ce2);
- query.Criteria.AddFilter(Fe);
- try
- {
- EntityCollection retrieve = Service.RetrieveMultiple(query);
- return retrieve;
- }
- catch (Exception ex)
- {
- ///throw new Exception(ex.Message);
- EntityCollection entity = new EntityCollection();
- return entity;
- }
- }
- static Entity GetInfoTer(IOrganizationService Service, string nomTable, string[] ChampRecup, string champCondition1, string variableCondition1, string champCondition2, string variableCondition2)
- {
- QueryExpression query = new QueryExpression();
- query.ColumnSet = new ColumnSet(ChampRecup);
- query.EntityName = nomTable;
- FilterExpression Fe = new FilterExpression(LogicalOperator.And);
- ConditionExpression Ce = new ConditionExpression();
- Ce.AttributeName = champCondition1;
- Ce.Operator = ConditionOperator.Equal;
- Ce.Values.Add(variableCondition1);
- Fe.AddCondition(Ce);
- ConditionExpression Ce2 = new ConditionExpression();
- Ce2.AttributeName = champCondition2;
- Ce2.Operator = ConditionOperator.Equal;
- Ce2.Values.Add(variableCondition2);
- Fe.AddCondition(Ce2);
- query.Criteria.AddFilter(Fe);
- try
- {
- EntityCollection retrieve = Service.RetrieveMultiple(query);
- return retrieve[0];
- }
- catch (Exception ex)
- {
- //throw new Exception(ex.Message);
- Entity entity = new Entity();
- return entity;
- }
- }
- static EntityCollection GetDivisions(IOrganizationService Service, string nomTable, string ChampRecup, string champCondition, string variableCondition)
- {
- QueryExpression query = new QueryExpression();
- query.ColumnSet = new ColumnSet(ChampRecup);
- query.EntityName = nomTable;
- FilterExpression Fe = new FilterExpression();
- ConditionExpression Ce = new ConditionExpression();
- Ce.AttributeName = champCondition;
- Ce.Operator = ConditionOperator.Equal;
- Ce.Values.Add(variableCondition);
- Fe.AddCondition(Ce);
- query.Criteria.AddFilter(Fe);
- try
- {
- EntityCollection retrieve = Service.RetrieveMultiple(query);
- return retrieve;
- }
- catch (Exception)
- {
- //throw new Exception(ex.Message);
- EntityCollection entity = new EntityCollection();
- return entity;
- }
- }
- static Entity GetElementTarifaire(IOrganizationService Service, Guid idProduit, Guid idTarif)
- {
- QueryExpression query = new QueryExpression();
- query.ColumnSet = new ColumnSet("productpricelevelid", "productid", "pricelevelid");
- query.EntityName = "productpricelevel";
- FilterExpression Fe = new FilterExpression(LogicalOperator.And);
- ConditionExpression Ce = new ConditionExpression();
- Ce.AttributeName = "productid";
- Ce.Operator = ConditionOperator.Equal;
- Ce.Values.Add(idProduit);
- Fe.AddCondition(Ce);
- ConditionExpression Ce2 = new ConditionExpression();
- Ce2.AttributeName = "pricelevelid";
- Ce2.Operator = ConditionOperator.Equal;
- Ce2.Values.Add(idTarif);
- Fe.AddCondition(Ce2);
- query.Criteria.AddFilter(Fe);
- try
- {
- EntityCollection retrieve = Service.RetrieveMultiple(query);
- return retrieve[0];
- }
- catch (Exception)
- {
- //throw new Exception(ex.Message);
- Entity entity = new Entity();
- return entity;
- }
- }
- static Entity GetCompte(IOrganizationService Service, string nomCompte)
- {
- QueryExpression query = new QueryExpression();
- query.ColumnSet = new ColumnSet("name");
- query.EntityName = "account";
- FilterExpression Fe = new FilterExpression();
- ConditionExpression Ce = new ConditionExpression();
- Ce.AttributeName = "name";
- Ce.Operator = ConditionOperator.Equal;
- Ce.Values.Add(nomCompte);
- Fe.AddCondition(Ce);
- query.Criteria.AddFilter(Fe);
- try
- {
- EntityCollection retrieve = Service.RetrieveMultiple(query);
- return retrieve[0];
- }
- catch (Exception)
- {
- //throw new Exception(ex.Message);
- Account entity = new Account();
- entity.asd_Ncompte = "";
- throw new Exception("retour catch");
- //return entity;
- }
- }
- static Entity GetBatiment(IOrganizationService Service, string nomBatiment)
- {
- QueryExpression query = new QueryExpression();
- query.ColumnSet = new ColumnSet("new_name");
- query.EntityName = "new_site";
- FilterExpression Fe = new FilterExpression();
- ConditionExpression Ce = new ConditionExpression();
- Ce.AttributeName = "new_name";
- Ce.Operator = ConditionOperator.Equal;
- Ce.Values.Add(nomBatiment);
- Fe.AddCondition(Ce);
- query.Criteria.AddFilter(Fe);
- try
- {
- EntityCollection retrieve = Service.RetrieveMultiple(query);
- return retrieve[0];
- }
- catch (Exception)
- {
- //throw new Exception(ex.Message);
- new_site entity = new new_site();
- //entity.asd_Ncompte = "";
- return entity;
- }
- }
- static Entity GetProduit(IOrganizationService Service, string idProduit)
- {
- QueryExpression query = new QueryExpression();
- query.ColumnSet = new ColumnSet("productnumber");
- query.EntityName = "product";
- FilterExpression Fe = new FilterExpression();
- ConditionExpression Ce = new ConditionExpression();
- Ce.AttributeName = "productnumber";
- Ce.Operator = ConditionOperator.Equal;
- Ce.Values.Add(idProduit);
- Fe.AddCondition(Ce);
- query.Criteria.AddFilter(Fe);
- try
- {
- EntityCollection retrieve = Service.RetrieveMultiple(query);
- return retrieve[0];
- }
- catch (Exception)
- {
- //throw new Exception(ex.Message);
- Product entity = new Product();
- entity.ProductNumber = "";
- return entity;
- }
- }
- /////////////////////////////////////////////////////////////////////////////////////////////////////
- private static EntityCollection getAllRefErpByIdCompte(IOrganizationService _service, Guid compteId)
- {
- // throw new Exception(compteId.ToString());
- QueryExpression query = new QueryExpression();
- query.ColumnSet = new ColumnSet("new_referenceerpcompteid", "new_compte", "createdon", "new_bloque", "new_division");
- query.EntityName = "new_referenceerpcompte";
- FilterExpression Fe = new FilterExpression();
- ConditionExpression Ce = new ConditionExpression();
- Ce.AttributeName = "new_compte";
- Ce.Operator = ConditionOperator.Equal;
- Ce.Values.Add(compteId);
- Fe.AddCondition(Ce);
- ConditionExpression CeBis = new ConditionExpression();
- CeBis.AttributeName = "new_bloque";
- CeBis.Operator = ConditionOperator.Equal;
- CeBis.Values.Add(false);
- Fe.AddCondition(CeBis);
- query.Orders.Add(new OrderExpression("createdon", OrderType.Ascending));
- query.Criteria.AddFilter(Fe);
- try
- {
- EntityCollection retrieve = _service.RetrieveMultiple(query);
- return retrieve;
- }
- catch
- {
- EntityCollection entity = new EntityCollection();
- return entity;
- }
- // retrieve = retrieve.OrderBy(x => x.CreatedOn).ToList();
- //
- // throw new Exception(retrieve[0]);
- // Last one ???
- // if (retrieve.GetLength() > 1 && statut)
- // {
- // return GetTest(Service, retrieve)
- // } else
- // {
- // return retrieve[0];
- // }
- // DOC MICROSOFT
- //
- // using (ServiceContext svcContext = new ServiceContext(_serviceProxy))
- // {
- // var query_orderbylookup = from a in svcContext.AccountSet
- // where a.Address1_Name == "Contoso Pharmaceuticals"
- // orderby a.PrimaryContactId
- // select new
- // {
- // a.Name,
- // a.Address1_City
- // };
- // foreach (var a in query_orderbylookup)
- // {
- // System.Console.WriteLine(a.Name + " " + a.Address1_City);
- // }
- // }
- }
- /////////////////////////////////////////////////////////////////////////////////////////////////////
- static Entity getReferenceERPCompte(IOrganizationService Service, Guid compteId, Guid divisionId)
- {
- QueryExpression query = new QueryExpression();
- query.ColumnSet = new ColumnSet("new_compte", "new_referenceerpcompteid", "new_name", "new_bloque");
- query.EntityName = "new_referenceerpcompte";
- FilterExpression Fe = new FilterExpression(LogicalOperator.And);
- ConditionExpression Ce1 = new ConditionExpression();
- Ce1.AttributeName = "new_compte";
- Ce1.Operator = ConditionOperator.Equal;
- Ce1.Values.Add(compteId);
- Fe.AddCondition(Ce1);
- ConditionExpression Ce2 = new ConditionExpression();
- Ce2.AttributeName = "new_division";
- Ce2.Operator = ConditionOperator.Equal;
- Ce2.Values.Add(divisionId);
- Fe.AddCondition(Ce2);
- query.Criteria.AddFilter(Fe);
- try
- {
- EntityCollection retrieve = Service.RetrieveMultiple(query);
- return retrieve[0];
- }
- catch (Exception)
- {
- //throw new Exception(ex.Message);
- new_referenceerpcompte entity = new new_referenceerpcompte();
- //entity.new_Compte = new EntityReference("Account", null); ;
- return entity;
- }
- }
- static Entity getReferenceCompteByCle(IOrganizationService _service, string cleUnique)
- {
- QueryExpression query = new QueryExpression();
- query.ColumnSet = new ColumnSet("accountid", "name", "new_societereferente", "customertypecode", "statuscode", "statecode");
- query.EntityName = "account";
- FilterExpression Fe = new FilterExpression();
- ConditionExpression Ce = new ConditionExpression();
- Ce.AttributeName = "new_cleunique";
- Ce.Operator = ConditionOperator.Equal;
- Ce.Values.Add(cleUnique);
- Fe.AddCondition(Ce);
- query.Criteria.AddFilter(Fe);
- try
- {
- EntityCollection retrieve = _service.RetrieveMultiple(query);
- return retrieve[0];
- }
- catch (Exception)
- {
- //throw new Exception(ex.Message);
- Account entity = new Account();
- //entity.new_Compte = new EntityReference("Account", null); ;
- return entity;
- }
- }
- /*static Entity GetReferenceERPBatiment(IOrganizationService Service, string NoBatiment)
- {
- QueryExpression query = new QueryExpression();
- query.ColumnSet = new ColumnSet("new_batiment", "new_referenceerpbatimentid", "new_name");
- query.EntityName = "new_referenceerpbatiment";
- FilterExpression Fe = new FilterExpression();
- ConditionExpression Ce = new ConditionExpression();
- Ce.AttributeName = "new_name";
- Ce.Operator = ConditionOperator.Equal;
- Ce.Values.Add(NoBatiment);
- Fe.AddCondition(Ce);
- query.Criteria.AddFilter(Fe);
- try
- {
- EntityCollection retrieve = Service.RetrieveMultiple(query);
- return retrieve[0];
- }
- catch (Exception)
- {
- //throw new Exception(ex.Message);
- new_referenceerpbatiment entity = new new_referenceerpbatiment();
- ///entity.new_Compte = new EntityReference("Account", null); ;
- return entity;
- }
- }*/
- static EntityCollection GetActivities(IOrganizationService Service, String Condition1, Guid Valeur1)
- {
- QueryExpression query = new QueryExpression();
- query.ColumnSet = new ColumnSet("regardingobjectid", "activitytypecode", "activityid");
- query.EntityName = "activitypointer";
- FilterExpression Fe = new FilterExpression(LogicalOperator.And);
- ConditionExpression Ce = new ConditionExpression();
- Ce.AttributeName = "regardingobjectid";
- Ce.Operator = ConditionOperator.Equal;
- Ce.Values.Add(Valeur1);
- Fe.AddCondition(Ce);
- query.Criteria.AddFilter(Fe);
- try
- {
- EntityCollection retrieve = Service.RetrieveMultiple(query);
- return retrieve;
- }
- catch (Exception ex)
- {
- throw new Exception(ex.Message);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement