Пример #1
0
        public override bool Sync()
        {
            #region CAT_STCK types
            //Get all the cat stock types in app.config and sync them
            catStckTypes = new Dictionary <int, string>();
            bool keepGoing = false;
            int  i         = 1;
            do
            {
                string value = OptionsMercator.GetOptionValue(String.Format(formatCatStckType, i))?.ToString();
                keepGoing = !String.IsNullOrWhiteSpace(value);
                if (keepGoing)
                {
                    catStckTypes.Add(i, value.TrimEnd());
                }
                i++;
            } while (keepGoing);

            SyncCatStckTypes(catStckTypes);
            #endregion


            //Get Stock From Mercator where "Vente En Ligne" is setted
            using (SqlConnection connection = new SqlConnection(dataSettings.DataConnectionString))
            {
                connection.Open();
                //IEnumerable<CAT_STCK> catStckList = GetMercatorCATSTCK(connection);

                //Array of existing attSpecOp
                IDictionary <String, int> attSpecOp = GetAllNopSpecOpt();

                List <int> specsToKeep = new List <int>();

                //Sync options for every S_CAT{x}, x being the type id in catStckTypes
                foreach (var catStckTyp in catStckTypes)
                {
                    try
                    {
                        int nopId     = 0;
                        var cstResult = ParserJSon.ParseResultToJTokenList(WebService.Get(urlBuilder.FilterEq("Name", catStckTyp.Value).BuildQuery()));
                        if (cstResult.Length > 0)
                        {
                            nopId = (int)cstResult.First()["Id"];
                            SyncSpecAttOps(attSpecOp, specsToKeep, catStckTyp.Key, nopId);
                        }
                    }
                    catch (Exception e)
                    {
                        Program.log(e);
                    }
                }

                //Exclude scat that aren't in Mercator
                Delete(attSpecOp, specsToKeep);


                connection.Close();
            }
            return(true);
        }
Пример #2
0
        /// <summary>
        /// Create a Mercator Client
        /// </summary>
        /// <param name="c"></param>
        /// <param name="context"></param>
        /// <returns>Mercator client initiated with Nop client's values</returns>
        private SigCli createMClient(Customer c)
        {
            SigCli sigCli = new SigCli();

            sigCli.SetValueForField("C_NOM", c.Name);
            sigCli.SetValueForField("C_CLE1", c.Id);
            sigCli.SetValueForField("C_TYP_FORM", 1);
            sigCli.SetValueForField("C_ADRESSE", c.Address1.Street);
            sigCli.SetValueForField("C_ADRESSE2", c.Address1.Street2);
            string zipPostalCode = c.Address1.ZipPostalCode;

            if (zipPostalCode.Length > 9)
            {
                zipPostalCode = zipPostalCode.Substring(0, 9);
            }
            sigCli.SetValueForField("C_CODEP", zipPostalCode);
            sigCli.SetValueForField("C_VILLE", c.Address1.City);
            sigCli.SetValueForField("C_PAYS", c.Address1.Country);
            sigCli.SetValueForField("C_NUM_TEL", c.Address1.PhoneNumber);
            sigCli.SetValueForField("C_EMAIL", c.Email);
            sigCli.SetValueForField("C_REGIME", 1);
            sigCli.SetValueForField("C_NUM_TVA", c.Tva ?? "");
            sigCli.SetValueForField("C_TARIF", Convert.ToInt32(OptionsMercator.GetOptionValue("NOP_TARIF")));
            sigCli.SetValueForField("C_CREATION", c.CreatedOnUtc);
            sigCli.SetValueForField("C_MODIF", DateTime.Now);
            sigCli.SetValueForField("C_ID_WEB", c.Id);
            sigCli.SetValueForField("C_FROM_WEB", true);
            sigCli.Create();

            return(sigCli);
        }
Пример #3
0
 public StockSyncer() : base()
 {
     pic             = new Picture();
     OptionsMercator = new OptionsMercator();
     urlBuilder      = new UrlBuilder(ENTITY);
     //Category mapping
     Categories  = RFSSyncer.GetMapIdNopId();
     count       = 0;
     lastUpdate  = Convert.ToDecimal(OptionsMercator.GetOptionValue("NOP_MDFTAG"));
     whereClause = String.Format(WHERE_CLAUSE, lastUpdate);
 }
Пример #4
0
        public CommandeSyncer() : base()
        {
            urlBuilder = new UrlBuilder(ENTITY);

            OptionsMercator rep = new OptionsMercator();

            directory = rep.GetOptionValue("NOP_REP_M").ToString();

            OptionsMercator journalOption = new OptionsMercator();

            journal = journalOption.GetOptionValue("NOP_JOURN").ToString();
        }
Пример #5
0
        /// <summary>
        /// Link product to picture
        /// </summary>
        /// <param name="stock"></param>
        /// <returns></returns>
        public JArray Sync(STOCK stock, OptionsMercator om, int productId = 0)
        {
            this.om = om;

            JArray picturesLinks = new JArray();

            if (productId != 0)
            {
                //check if product already has picture
                JObject  productPicture = JObject.Parse(WebService.Get(new UrlBuilder("ProductPicture").FilterEq("ProductId", productId).BuildQuery()));
                JToken[] pp             = productPicture["value"].ToArray();

                foreach (JToken p in pp)
                {
                    //Product has picture
                    if ((int)p["ProductId"] == productId)
                    {
                        //Delete pictures
                        int pictureId = (int)p["PictureId"];
                        //Delete link
                        WebService.Delete(new UrlBuilder("ProductPicture").Id((int)p["Id"]).BuildQuery());
                        //Delete picture
                        WebService.Delete(urlBuilder.Id((int)p["PictureId"]).BuildQuery());
                    }
                }
            }


            //To do for every S_IMAGE
            SyncPic(stock.S_IMAGE1, picturesLinks, productId);
            //SyncPic(stock.S_IMAGE2, picturesLinks, productId);
            //SyncPic(stock.S_IMAGE3, picturesLinks, productId);
            //SyncPic(stock.S_IMAGE4, picturesLinks, productId);
            //SyncPic(stock.S_IMAGE5, picturesLinks, productId);
            //SyncPic(stock.S_IMAGE6, picturesLinks, productId);
            //SyncPic(stock.S_IMAGE7, picturesLinks, productId);
            //SyncPic(stock.S_IMAGE8, picturesLinks, productId);
            //SyncPic(stock.S_IMAGE9, picturesLinks, productId);
            //SyncPic(stock.S_IMAGE10, picturesLinks, productId);
            //SyncPic(stock.S_IMAGE11, picturesLinks, productId);
            //SyncPic(stock.S_IMAGE12, picturesLinks, productId);

            return(picturesLinks);
        }
Пример #6
0
        public Syncer()
        {
            dataSettings = DatabaseManager.LoadSettings();

            if (String.IsNullOrWhiteSpace(DBContextFactory.ConnectionString))
            {
                DBContextFactory.SetConnection(dataSettings.DataConnectionString);
            }

            if (dbContext == null)
            {
                dbContext = DBContextFactory.DBContext;
            }
            if (textInfo == null)
            {
                textInfo = new CultureInfo("fr-FR", false).TextInfo;
            }
            if (OptionsMercator == null)
            {
                OptionsMercator = new OptionsMercator();
            }
        }
Пример #7
0
        /// <summary>
        /// Parse CLI address to Nop Address in Json String
        /// </summary>
        /// <param name="c"></param>
        /// <returns></returns>
        public static JObject ParseAddressToJson(CLI c, OptionsMercator options)
        {
            //potentiel " dans champ : .Replace("\"", "\\\"")
            string belgique = options.GetOptionValue("NOP_PAYS").ToString();

            //Si pas de pays, on met belgique par défaut
            string countryId = (c.C_PAYS.TrimEnd() != "") ? GetCountryIdByName(c.C_PAYS.TrimEnd()) : GetCountryIdByName(belgique);

            JObject json = new JObject();

            json.Add("LastName", c.C_NOM.TrimEnd().Replace("\"", "\\\""));
            json.Add("Email", c.C_EMAIL.TrimEnd());
            json.Add("Company", c.C_NOM.TrimEnd().Replace("\"", "\\\""));
            json.Add("CountryId", countryId);
            json.Add("City", c.C_VILLE.TrimEnd());
            json.Add("Address1", c.C_ADRESSE.TrimEnd().Replace("\"", "\\\""));
            json.Add("Address2", c.C_ADRESSE2.TrimEnd().Replace("\"", "\\\""));
            json.Add("ZipPostalCode", c.C_CODEP.TrimEnd());
            json.Add("PhoneNumber", c.C_NUM_TEL.TrimEnd());
            //json.Add("MercatorId", c.C_ID.TrimEnd());

            return(json);
        }
Пример #8
0
        private void Form1_Load(object sender, EventArgs e)
        {
            OptionsMercator repMerc = new OptionsMercator();
            OptionsMercator journal = new OptionsMercator();

            string repMercValue = repMerc.GetOptionValue("NOP_REP_M")?.ToString();
            string journalValue = journal.GetOptionValue("NOP_JOURN")?.ToString();

            txtRepMercator.Text = repMercValue?.ToString()?.TrimEnd() ?? "";
            txtJournal.Text     = journalValue?.ToString()?.TrimEnd() ?? "";

            if (DatabaseManager.CheckTableExistence("WEB_API_CREDENTIALS"))
            {
                AuthParameters ap = AuthorizationController.GetAuthParams();

                if (ap != null)
                {
                    txtPublicToken.Text  = ap.PublicToken;
                    txtSecretToken.Text  = ap.SecretToken;
                    txtStoreAddress.Text = ap.StoreAddress;
                    txtUser.Text         = ap.ClientName;
                }
            }
        }
Пример #9
0
        public static bool Initiate(ProgressBar progressBar, Label progressText, InstallerDatas install)
        {
            try
            {
                InitiatePB(progressBar);

                //Tables
                if (!DatabaseManager.CheckTableExistence("ADRESSE_WEB"))
                {
                    Program.log("Inserting table \"ADRESSE_WEB\"");
                    ExecuteQuery(addressTableQuery);
                }

                if (!DatabaseManager.CheckTableExistence("PAYS"))
                {
                    Program.log("Inserting table \"PAYS\"");
                    UdpateLabelText(progressText, "Inserting table \"PAYS\"");
                    ExecuteQuery(paysTableQuery);
                }
                else
                {
                    pb.PerformStep();
                }

                if (!DatabaseManager.CheckTableExistence("WEB_API_CREDENTIALS"))
                {
                    Program.log("Inserting table \"WEB_API_CREDENTIALS\"");
                    UdpateLabelText(progressText, "Inserting table \"WEB_API_CREDENTIALS\"");
                    ExecuteQuery(webApiTableQuery);
                }
                else
                {
                    pb.PerformStep();
                }

                //Columns
                Program.log("Ajout de colonnes");
                UdpateLabelText(progressText, "Ajout de colonnes: Table PIEDS_V");
                ExecuteQuery(String.Format(addIntColumnToTable, "PIEDS_V", "ID_WEB"), timeout: 99999);
                UdpateLabelText(progressText, "Ajout de colonnes: Table STOCK");
                ExecuteQuery(String.Format(addIntColumnToTable, "STOCK", "S_MODIFTAG"), timeout: 99999);
                ExecuteQuery(String.Format(addBitColumnToTable, "STOCK", "S_WEB"), timeout: 99999);
                UdpateLabelText(progressText, "Ajout de colonnes: Table CLI");
                ExecuteQuery(String.Format(addBitColumnToTable, "CLI", "C_FROM_WEB"), timeout: 99999);
                ExecuteQuery(String.Format(addIntColumnToTable, "CLI", "C_ID_WEB"), timeout: 99999);
                UdpateLabelText(progressText, "Ajout de colonnes: Table CAT_STCK");
                ExecuteQuery(String.Format(addIntColumnToTable, "CAT_STCK", "ID_WEB"));

                //Insert
                Program.log("Ajout de données");
                UdpateLabelText(progressText, "Ajout des options");
                if (!ExecuteQuery(insertIntoOptions, true))
                {
                    Program.log("Inserting mdftag options failed");
                }
                if (!ExecuteQuery(insertRepMercIntoOptions, true))
                {
                    Program.log("Inserting rep_merc options failed");
                }
                if (!ExecuteQuery(insertJournalIntoOptions, true))
                {
                    Program.log("Inserting journal option failed");
                }
                if (!ExecuteQuery(insertMargeIntoOptions, true))
                {
                    Program.log("Inserting stock marge option failed");
                }
                if (!ExecuteQuery(insertCatStck1IntoOptions, true))
                {
                    Program.log("Inserting cat stck 1 option failed");
                }
                if (!ExecuteQuery(insertCatStck2IntoOptions, true))
                {
                    Program.log("Inserting cat stck 2 option failed");
                }
                if (!ExecuteQuery(insertCatStck3IntoOptions, true))
                {
                    Program.log("Inserting cat stck 3 option failed");
                }
                if (!ExecuteQuery(insertDefaultCountryIntoOptions, true))
                {
                    Program.log("Inserting default country option failed");
                }
                if (!ExecuteQuery(insertDefaultTarifIntoOptions, true))
                {
                    Program.log("Inserting default tarif option failed");
                }
                if (!ExecuteQuery(insertIDLivIntoOptions, true))
                {
                    Program.log("Inserting id liv option failed");
                }
                if (!ExecuteQuery(insertPays, true))
                {
                    Program.log("Inserting Pays values failed");
                }

                SaveAuthModelInDB(install);

                OptionsMercator repMerc = new OptionsMercator();
                OptionsMercator journal = new OptionsMercator();

                string repMercValue = repMerc.GetOptionValue("NOP_REP_M").ToString();
                string journalValue = journal.GetOptionValue("NOP_JOURN").ToString();

                if (install.RepMercator != repMercValue)
                {
                    repMerc.SetOptionValue("NOP_REP_M", install.RepMercator);
                }
                if (install.JournalMercator != journalValue)
                {
                    journal.SetOptionValue("NOP_JOURN", install.JournalMercator);
                }

                progressBar.PerformStep();
                Program.log("Install terminée");
                UdpateLabelText(progressText, "Installation terminée");
                progressBar.Value = progressBar.Maximum;

                return(true);
            }
            catch (Exception e)
            {
                Program.log(e.Message);
                Program.log(e.StackTrace);
                return(false);
            }
        }
Пример #10
0
 public DispoSyncer() : base()
 {
     urlBuilder      = new UrlBuilder("Product");
     OptionsMercator = new OptionsMercator();
 }
Пример #11
0
 //Return the picture repository
 public void SetRep(OptionsMercator om)
 {
     Rep = Convert.ToString(om.GetOptionValue("REP_BMP")) ?? "";
 }
Пример #12
0
        public override bool Sync()
        {
            //Get orders placed since last sync (based on Order's id) from Nop using Web Service

            using (Main Mercator = new Main(directory, null, ConfigurationManager.AppSettings["MercatorLogin"], ConfigurationManager.AppSettings["MercatorMdp"]))
            {
                //@"\\serveur\dossier_mercator"
                using (SqlConnection connection = new SqlConnection(dataSettings.DataConnectionString))
                {
                    try
                    {
                        connection.Open();

                        if (Mercator != null)
                        {
                            MercatorApi.Api.IsWeb = true;
                            string jsonCommandes = "";

                            jsonCommandes = WebService.Get(new UrlBuilder("GenericAttribute").And().FilterEq("KeyGroup", ENTITY).FilterEq("Key", KEY_SYNCED).FilterEq("Value", "0").BuildQuery());
                            //jsonCommandes = WebService.Get(WebServiceUrls.ORDER_UNSYNCED);

                            JToken[] commandes = ParserJSon.ParseResultToJTokenList(jsonCommandes);
                            if (commandes.Length == 0)
                            {
                                Program.WriteLine("Pas de nouvelles commandes");
                            }

                            foreach (JToken co in commandes)
                            {
                                try
                                {
                                    string orderResult = WebService.Get(urlBuilder
                                                                        .Id((int)co["EntityId"])
                                                                        .Expand("OrderItems")
                                                                        .BuildQuery());

                                    //JToken[] orderToken = ParserJSon.ParseResultToJTokenList(orderResult);
                                    JObject order = JObject.Parse(orderResult);

                                    //if (order.FirstOrDefault() != null)
                                    //{
                                    //    JToken c = orderToken.FirstOrDefault();
                                    if (((int)order["PaymentStatusId"] == 30 || (int)order["PaymentStatusId"] == 20) || (order["PaymentMethodSystemName"].ToString() == "Payments.CheckMoneyOrder"))
                                    {
                                        JObject syncMarker = new JObject();

                                        List <int> syncedOrderIds = new List <int>();

                                        var items = (order["OrderItems"]).ToArray();
                                        int id    = int.Parse(order["CustomerId"].ToString());
                                        //Get web client
                                        SigCli sigCli = new SigCli();
                                        bool   exists = sigCli.ReadWhere(String.Format("C_ID_WEB = '{0}'", id));

                                        if (!exists)
                                        {
                                            Program.log("Commande n°" + order["Id"].ToString() + " non synchronisée car le client " + id + " n'a pas été trouvé dans Mercator.");
                                        }
                                        else
                                        {
                                            //Get the journal in which the order has to be placed
                                            using (BillingEngine be = BillingEngine.InitNew(Billing.TypeVAEnum.V, 3, journal))
                                            {
                                                be.ApplyCustomerSupplier(sigCli.GetField("C_ID").Value.ToString());
                                                if (be.PIEDS != null)

                                                {
                                                    be.PIEDS["DATE"] = DateTime.Parse(order["CreatedOnUtc"].ToString());
                                                }
                                                else
                                                {
                                                    throw new Exception("An error occured - please check that the journal exists");
                                                }



                                                foreach (JToken i in items)
                                                {
                                                    //Get product ids by SKU (Nop's SKU = S_CLE_1)
                                                    JObject o   = JObject.Parse(WebService.Get(new UrlBuilder("Product").Id((int)i["ProductId"]).Select("Sku").BuildQuery()));
                                                    string  sku = o["Sku"].ToString();

                                                    int index = be.AppendLine();
                                                    //get from db stock using cle_1 then Add ID
                                                    be.InsertItem(sku, index, 1);

                                                    //Use price/vat used when the order was placed : might have been some changes in Mercator since then
                                                    be.LIGNES.Rows[index]["Q"]  = i["Quantity"].Value <Double>() /** condit*/;
                                                    be.LIGNES.Rows[index]["PU"] = i["UnitPriceExclTax"].Value <Decimal>();   /* * (1 + (i["Remise"].Value<Decimal>() / 100));*/
                                                }

                                                //Shipping tax
                                                //TODO: faire un doc avec les étapes de l'installation + vérifications à faire
                                                //TODO: Verif: Présence d'un article frais de livraison dans le Mercator cible
                                                if (Double.Parse(order["OrderShippingInclTax"].ToString()) > 0)
                                                {
                                                    string fraislivraisonId = OptionsMercator.GetOptionValue("NOP_LIV_ID").ToString();

                                                    SigStock sigStock      = new SigStock();
                                                    bool     fraisLivFound = sigStock.ReadWhere(String.Format("S_CLE1 = '{0}'", fraislivraisonId));

                                                    if (fraisLivFound)
                                                    {
                                                        int n = be.AppendLine();
                                                        be.InsertItem(sigStock.GetField("S_ID").Value.ToString(), n, 1);
                                                        be.LIGNES.Rows[n]["PU"]       = Double.Parse(order["OrderShippingInclTax"].ToString()) / 1.21;
                                                        be.LIGNES.Rows[n]["TAUX_TVA"] = 21;
                                                    }
                                                }

                                                //CODE PROMO SUR TOTAL COMMANDE
                                                //TODO:CODE PROMO - UNCOMMENT IF NECESSARY
                                                //if (Double.Parse(c["OrderDiscount"].ToString()) > 0)
                                                //{
                                                //    string codepromocommandecle1 = ConfigurationManager.AppSettings["CODEPROMOCOMMANDE"];
                                                //    SigStock sigStock = new SigStock();
                                                //    bool codePromoFound = sigStock.ReadWhere(String.Format("S_CLE1 = '{0}'", codepromocommandecle1));
                                                //    if (codePromoFound)
                                                //    {
                                                //        int n = be.AppendLine();
                                                //        be.InsertItem(sigStock.GetField("S_ID").Value.ToString().S_ID.TrimEnd(), n, 1);
                                                //        be.LIGNES.Rows[n]["PU"] = (Double.Parse(c["OrderDiscount"].ToString())) * -1;
                                                //        be.LIGNES.Rows[n]["TAUX_TVA"] = 0;
                                                //    }
                                                //}

                                                be.UpdateAmounts();

                                                #region payments

                                                //Check if order is paid : c["PaymentStatusId"] -> 10 pending, 30 paid
                                                if (order["PaymentStatusId"].ToString() == "10")
                                                {
                                                    switch (order["PaymentMethodSystemName"].ToString())
                                                    {
                                                    case PaymentMethods.NOP_VIREMENT: be.PIEDS["TYP_PAIEM1"] = PaymentMethods.M_VIREMENT; break;

                                                    case PaymentMethods.NOP_PAYPAL: be.PIEDS["TYP_PAIEM1"] = PaymentMethods.M_PAYPAL; break;

                                                    default:
                                                        be.PIEDS["TYP_PAIEM1"] = PaymentMethods.M_VIREMENT; break;
                                                    }
                                                }
                                                else if (order["PaymentStatusId"].ToString() == "30")
                                                {
                                                    double tot = Convert.ToDouble(be.PIEDS["TOT_TTC_DV"].ToString());

                                                    switch (order["PaymentMethodSystemName"].ToString())
                                                    {
                                                    case PaymentMethods.NOP_VIREMENT: be.PIEDS["TYP_PAIEM1"] = PaymentMethods.M_VIREMENT; break;

                                                    case PaymentMethods.NOP_PAYPAL: be.PIEDS["TYP_PAIEM1"] = PaymentMethods.M_PAYPAL; break;

                                                    default:
                                                        be.PIEDS["TYP_PAIEM1"] = PaymentMethods.M_VIREMENT; break;
                                                    }
                                                    //be.PIEDS["TYP_PAIEM1"] = 10;
                                                    be.PIEDS["TOT_PAIEM1"] = tot;
                                                    be.PIEDS["NET_DV"]     = tot;
                                                    be.PIEDS["NET_FB"]     = tot;
                                                }

                                                #endregion

                                                #region shipment
                                                if (order["PickUpInStore"].ToString() == "True")
                                                {
                                                    be.AppendLine();
                                                    int nAdresse = be.AppendLine();
                                                    be.LIGNES.Rows[nAdresse]["DESIGNATIO"] = "Retrait en magasin";
                                                }
                                                else
                                                {
                                                    Address billingA  = AddressConverter.ParseJsonToAddress(WebService.Get(new UrlBuilder("Address").Id((int)order["BillingAddressId"]).BuildQuery()));
                                                    Address shippingA = AddressConverter.ParseJsonToAddress(WebService.Get(new UrlBuilder("Address").Id((int)order["ShippingAddressId"]).BuildQuery()));
                                                    if (!billingA.Equals(shippingA))
                                                    {
                                                        //be.ApplyCliLiv("ID_CLI_LIV");
                                                        be.AppendLine();
                                                        int nAdresse = be.AppendLine();
                                                        be.LIGNES.Rows[nAdresse]["DESIGNATIO"] = "Adresse de livraison: ";
                                                        int nN = be.AppendLine();
                                                        be.LIGNES.Rows[nN]["DESIGNATIO"] = shippingA.FirstName + " " + shippingA.LastName;
                                                        int nA = be.AppendLine();
                                                        be.LIGNES.Rows[nA]["DESIGNATIO"] = shippingA.Street;
                                                        int nP = be.AppendLine();
                                                        be.LIGNES.Rows[nP]["DESIGNATIO"] = shippingA.ZipPostalCode;
                                                        int nV = be.AppendLine();
                                                        be.LIGNES.Rows[nV]["DESIGNATIO"] = String.Format("{0}, {1}", shippingA.City, shippingA.Country);
                                                        int nPh = be.AppendLine();
                                                        be.LIGNES.Rows[nPh]["DESIGNATIO"] = shippingA.PhoneNumber;

                                                        //TODO: Mode de livraison UPS + suppléments
                                                    }
                                                }

                                                #endregion



                                                #region CheckoutAttributes
                                                //Récupère les attributs de commandes associés à la commande et les affiches dans les lignes_v
                                                //if (order["CheckoutAttributeDescription"].ToString() != "" && order["CheckoutAttributeDescription"].ToString() != "null")
                                                //{
                                                //    Dictionary<string, string> attributes = extractAttributes(order["CheckoutAttributesXml"].ToString());

                                                //    if (attributes.ContainsKey(ATTRIBUT_COMM))
                                                //    {
                                                //        if (attributes[ATTRIBUT_COMM] != "")
                                                //        {
                                                //            be.AppendLine();
                                                //            int n = be.AppendLine();
                                                //            be.LIGNES.Rows[n]["DESIGNATIO"] = "Commentaires: ";

                                                //            string[] commLines = attributes[ATTRIBUT_COMM].Split(new string[] { "\r" }, StringSplitOptions.None);
                                                //            foreach (string s in commLines)
                                                //            {
                                                //                int nLine = be.AppendLine();
                                                //                be.LIGNES.Rows[nLine]["DESIGNATIO"] = s;
                                                //            }
                                                //        }
                                                //    }
                                                //}
                                                #endregion

                                                be.PIEDS["ID_WEB"]    = order["Id"].ToString();
                                                be.PIEDS["REFERENCE"] = REF_WEB;


                                                if (be.Save())
                                                {
                                                    be.Close();
                                                    syncMarker.Add("Value", "1");
                                                    //WebService.Patch(String.Format(WebServiceUrls.ORDER_ID, (int)c["Id"]), syncMarker.ToString());
                                                    WebService.Patch(String.Format(new UrlBuilder("GenericAttribute").Id((int)co["Id"]).BuildQuery()), syncMarker.ToString());
                                                }
                                                else
                                                {
                                                    //Erreur
                                                    return(false);
                                                }
                                            }
                                            //}
                                        }
                                    }
                                }
                                catch (Exception e)
                                {
                                    Program.log(e.Message);
                                    Program.log(e.StackTrace);
                                    return(false);
                                }
                            }

                            //****** UPDATE STATUS ********//
                            Program.WriteLine("Updating Nop Order status...");
                            string   ordersUncomplete = WebService.Get(urlBuilder.FilterEq("OrderStatusId", 20).BuildQuery());
                            JToken[] orders           = ParserJSon.ParseResultToJTokenList(ordersUncomplete);

                            if (orders.Count() > 0)
                            {
                                foreach (JToken o in orders)
                                {
                                    int    oId    = (int)o["Id"];
                                    PiedsV piedsV = new PiedsV();
                                    bool   exists = piedsV.Read(oId, "ID_WEB");

                                    if (exists)
                                    {
                                        JObject patch = new JObject();
                                        patch.Add("OrderStatusId", 30);
                                        if (Convert.ToInt32(piedsV.GetField("TYPE").Value) == 2)
                                        {
                                            patch.Add("PaymentStatusId", 30);
                                            patch.Add("ShippingStatusId", 30);
                                        }
                                        else
                                        if (Convert.ToInt32(piedsV.GetField("TYPE").Value) == 1)
                                        {
                                            patch.Add("OrderStatusId", 30);
                                            patch.Add("PaymentStatusId", 30);
                                            patch.Add("ShippingStatusId", 40);
                                        }

                                        WebService.Patch(urlBuilder.Id(oId).BuildQuery(), patch.ToString());
                                    }
                                }
                            }
                            Program.WriteLine("Updated");
                        }
                    }
                    catch (Exception e)
                    {
                        Program.log(e.Message);
                        Program.log(e.StackTrace);
                    }
                    finally
                    {
                        connection.Close();
                    }
                }
                //context.SaveChanges();

                return(true);
            }
        }
Пример #13
0
 public UrlsSyncer() : base()
 {
     OptionsMercator = new OptionsMercator();
     urlBuilder      = new UrlBuilder(ENTITY);
 }