Browse Source

NEW Interrogation de l'index SolR du référentiel pour bien initialiser la liste de choix pour le code postal

julien.legrand 8 years ago
parent
commit
d57f9bb90f

+ 10 - 0
CD67.FicheCollege.MVC/CD67.FicheCollege.MVC.csproj

@@ -165,6 +165,7 @@
     <Compile Include="Global.asax.cs">
       <DependentUpon>Global.asax</DependentUpon>
     </Compile>
+    <Compile Include="Internal\Referentiel.cs" />
     <Compile Include="Internal\FlashMessageExtensions.cs" />
     <Compile Include="Internal\MvcHtmlHelpers.cs" />
     <Compile Include="Internal\Navigation.cs" />
@@ -174,6 +175,11 @@
     <Compile Include="Models\ModeAcces.cs" />
     <Compile Include="Models\UtilisateurConnecte.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="Properties\Settings.Designer.cs">
+      <AutoGen>True</AutoGen>
+      <DesignTimeSharedInput>True</DesignTimeSharedInput>
+      <DependentUpon>Settings.settings</DependentUpon>
+    </Compile>
   </ItemGroup>
   <ItemGroup>
     <Compile Include="App_Start\FilterConfig.cs" />
@@ -254,6 +260,10 @@
     <Content Include="Scripts\cd67-Menu.js" />
     <Content Include="Content\cd67-custom.less" />
     <Content Include="Content\cd67-model.less" />
+    <None Include="Properties\Settings.settings">
+      <Generator>SettingsSingleFileGenerator</Generator>
+      <LastGenOutput>Settings.Designer.cs</LastGenOutput>
+    </None>
     <None Include="Scripts\jquery-3.2.1.intellisense.js" />
     <Content Include="Scripts\cd67-picker.js" />
     <Content Include="Scripts\colorbox\i18n\jquery.colorbox-ar.js" />

+ 1 - 1
CD67.FicheCollege.MVC/Controllers/CollegesController.cs

@@ -132,7 +132,7 @@ namespace CD67.FicheCollege.MVC.Controllers
                 SelectList listeTypeCollege = new SelectList(typeCollegeFactory.getAll("Ordre"), "Id", "Libelle", entity.TypeCollege_Id);
                 listes.Add("TypeCollege_Id", listeTypeCollege);
 
-                SelectList listeCodesPostaux = new SelectList(new List<string>() { entity.Code_Postal });
+                SelectList listeCodesPostaux = new SelectList(Internal.Referentiel.GetCodesPostaux(entity.Commune_Insee), entity.Code_Postal);
                 listes.Add("Code_Postal", listeCodesPostaux);
             }
 

+ 40 - 0
CD67.FicheCollege.MVC/Internal/Referentiel.cs

@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Web;
+using System.Xml;
+
+namespace CD67.FicheCollege.MVC.Internal
+{
+    public class Referentiel
+    {
+        /// <summary>
+        /// Fonction qui interroge l'index SolR du référentiel commune pour retourner les codes postaux par communes
+        /// </summary>
+        /// <param name="Insee">Code Insee de la commune souhaitée</param>
+        /// <returns>Liste des codes postaux possibles</returns>
+        public static List<string> GetCodesPostaux(string Insee)
+        {
+            //cas de sortie immédiat
+            if (Insee == null) return new List<string>();
+
+            var m_strFilePath = String.Format(Properties.Settings.Default.GetCodesPostaux_URL, Insee);
+            string xmlStr;
+            using (var wc = new WebClient())
+            {
+                xmlStr = wc.DownloadString(m_strFilePath);
+            }
+            var xmlDoc = new XmlDocument();
+            xmlDoc.LoadXml(xmlStr);
+
+            //Recherche des données
+            List<string> result = new List<string>();
+            foreach (XmlNode item in xmlDoc.GetElementsByTagName("str"))
+            {
+                result.Add(item.InnerText);
+            }
+            return result;
+        }
+    }
+}

+ 36 - 0
CD67.FicheCollege.MVC/Properties/Settings.Designer.cs

@@ -0,0 +1,36 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+//     Ce code a été généré par un outil.
+//     Version du runtime :4.0.30319.42000
+//
+//     Les modifications apportées à ce fichier peuvent provoquer un comportement incorrect et seront perdues si
+//     le code est régénéré.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace CD67.FicheCollege.MVC.Properties {
+    
+    
+    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
+    internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
+        
+        private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
+        
+        public static Settings Default {
+            get {
+                return defaultInstance;
+            }
+        }
+        
+        [global::System.Configuration.ApplicationScopedSettingAttribute()]
+        [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+        [global::System.Configuration.DefaultSettingValueAttribute("http://lunr4:8080/solr/referentiel-communes/select?q=id%3A{0}&fl=code_postal&wt=x" +
+            "ml&indent=true&hl=false&omitHeader=true")]
+        public string GetCodesPostaux_URL {
+            get {
+                return ((string)(this["GetCodesPostaux_URL"]));
+            }
+        }
+    }
+}

+ 9 - 0
CD67.FicheCollege.MVC/Properties/Settings.settings

@@ -0,0 +1,9 @@
+<?xml version='1.0' encoding='utf-8'?>
+<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="CD67.FicheCollege.MVC.Properties" GeneratedClassName="Settings">
+  <Profiles />
+  <Settings>
+    <Setting Name="GetCodesPostaux_URL" Type="System.String" Scope="Application">
+      <Value Profile="(Default)">http://lunr4:8080/solr/referentiel-communes/select?q=id%3A{0}&amp;fl=code_postal&amp;wt=xml&amp;indent=true&amp;hl=false&amp;omitHeader=true</Value>
+    </Setting>
+  </Settings>
+</SettingsFile>

+ 1 - 1
CD67.FicheCollege.MVC/Views/Colleges/Edit.cshtml

@@ -102,7 +102,7 @@
             <div class="form-group">
                 @Html.LabelFor(model => contenu.Code_Postal, htmlAttributes: new { @class = "control-label col-md-2" })
                 <div class="col-md-10">
-                    Code(s) postal(aux) associé(s) à la commune <span id="CP-warning" class="text-danger" style="display:none">(attention, plusieurs choix possibles)</span> : <input id="code_postaux" data-picker="commune.code_postal" value="@contenu.Code_Postal" class="disabled-input-as-label" />
+                    Code(s) postal(aux) associé(s) à la commune <span id="CP-warning" class="text-danger" style="@if (Model.Listes["Code_Postal"].Count() == 1) { <text>display: none;</text> }">(attention, plusieurs choix possibles)</span> : <input id="code_postaux" data-picker="commune.code_postal" value="@String.Join(",", Model.Listes["Code_Postal"].Select(i => i.Text))" class="disabled-input-as-label" />
                     <br />
                     @Html.DropDownListFor(model => contenu.Code_Postal, Model.Listes["Code_Postal"], htmlAttributes: new { @class = "form-control" })
                     @Html.ValidationMessageFor(model => contenu.Code_Postal, "", new { @class = "text-danger" })

+ 12 - 1
CD67.FicheCollege.MVC/Web.config

@@ -9,7 +9,11 @@
     
   
   <section name="dotless" type="dotless.Core.configuration.DotlessConfigurationSectionHandler, dotless.Core" />
-  <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
+  <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
+    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
+      <section name="CD67.FicheCollege.MVC.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
+    </sectionGroup>
+                                                                                                                      </configSections>
   <connectionStrings>
     <add name="Entities" connectionString="metadata=res://*/EntityModel.csdl|res://*/EntityModel.ssdl|res://*/EntityModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=T-MSSQL-02\SQLSTD2K14;initial catalog=FicheCollege;persist security info=True;user id=FicheCollege_admin;password=bk9JFwqSwYw7mEPiOhnu;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
   </connectionStrings>
@@ -120,4 +124,11 @@
     </assemblyBinding>
   </runtime>
   <dotless minifyCss="false" cache="true" web="false" strictMath="false" />
+  <applicationSettings>
+    <CD67.FicheCollege.MVC.Properties.Settings>
+      <setting name="GetCodesPostaux_URL" serializeAs="String">
+        <value>http://lunr4:8080/solr/referentiel-communes/select?q=id%3A{0}&amp;fl=code_postal&amp;wt=xml&amp;indent=true&amp;hl=false&amp;omitHeader=true</value>
+      </setting>
+    </CD67.FicheCollege.MVC.Properties.Settings>
+  </applicationSettings>
 </configuration>