From 4bb83ce552c0fa849543f4ca0c82428c4fabf86e Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sat, 9 May 2015 16:42:33 +0200 Subject: [PATCH] * DataManager.cs: * InitDb.aspx: * Created.aspx: * DataAccess.cs: * AdminController.cs: Refactoring * App.master: * NoLogin.master: Fixes not wanted differences between NoLogin and App master pages * instdbws.sql: Fixes an useless ownership attribution. --- web/Admin/DataManager.cs | 14 +++++-- web/Controllers/AdminController.cs | 6 +-- web/Models/App.master | 6 +-- web/Models/NoLogin.master | 64 +++++++++++++++++------------- web/Views/Admin/Created.aspx | 10 +++-- web/Views/Admin/InitDb.aspx | 2 +- web/instdbws.sql | 3 +- yavscModel/Admin/DataAccess.cs | 6 +-- 8 files changed, 63 insertions(+), 48 deletions(-) diff --git a/web/Admin/DataManager.cs b/web/Admin/DataManager.cs index 76d33937..fb994200 100644 --- a/web/Admin/DataManager.cs +++ b/web/Admin/DataManager.cs @@ -4,6 +4,7 @@ using System.IO; using Yavsc.Model.Admin; using Npgsql.Web.Blog; using System.Resources; +using System.Reflection; namespace Yavsc.Admin { @@ -91,11 +92,12 @@ namespace Yavsc.Admin string sql; try { - using (Stream sqlStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Yavsc.instdbws.sql")) + Assembly a = System.Reflection.Assembly.GetExecutingAssembly(); + using (Stream sqlStream = a.GetManifestResourceStream("Yavsc.instdbws.sql")) { - using (StreamReader srdr = new StreamReader (sqlStream)) { + try { using (StreamReader srdr = new StreamReader (sqlStream)) { sql = srdr.ReadToEnd (); - using (var cnx = new Npgsql.NpgsqlConnection (da.ConnectionString())) { + using (var cnx = new Npgsql.NpgsqlConnection (da.ConnectionString)) { using (var cmd = cnx.CreateCommand ()) { cmd.CommandText = sql; cnx.Open(); @@ -103,6 +105,12 @@ namespace Yavsc.Admin cnx.Close(); } } + } } catch (Exception exg) { + res.ExitCode = 1; + res.Error = + string.Format ("Exception of type {0} occred retrieving the script", + exg.GetType ().Name); + res.Message = exg.Message; } } } diff --git a/web/Controllers/AdminController.cs b/web/Controllers/AdminController.cs index 0e667e71..48913639 100644 --- a/web/Controllers/AdminController.cs +++ b/web/Controllers/AdminController.cs @@ -11,7 +11,6 @@ using Yavsc.Admin; using System.IO; using Yavsc.Model; - namespace Yavsc.Controllers { /// @@ -40,11 +39,10 @@ namespace Yavsc.Controllers { if (doInit=="on") { if (ModelState.IsValid) { - // TODO BETTER datac.BackupPrefix = Server.MapPath (datac.BackupPrefix); DataManager mgr = new DataManager (datac); - TaskOutput t = mgr.CreateDb (); - return View ("Created", t); + TaskOutput tcdb = mgr.CreateDb (); + return View ("Created", tcdb); } } return View (); diff --git a/web/Models/App.master b/web/Models/App.master index 54b3a9ca..06b8e660 100644 --- a/web/Models/App.master +++ b/web/Models/App.master @@ -34,8 +34,8 @@ ViewState["orgtitle"] = T.GetString(Page.Title); - - + + -
+
<%= Html.ActionLink("Contact","Contact","Home",null, new { @class="footerlink" }) %>
<% foreach ( string link in Yavsc.ThanksHelper.Links()) { %> diff --git a/web/Models/NoLogin.master b/web/Models/NoLogin.master index 3078398e..f3c1c9eb 100644 --- a/web/Models/NoLogin.master +++ b/web/Models/NoLogin.master @@ -1,18 +1,18 @@ <%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %> - - - <% ViewState["orgtitle"] = T.GetString(Page.Title); %> - <% Page.Title = ViewState["orgtitle"] + " - " + YavscHelpers.SiteName; %> - +<% +ViewState["orgtitle"] = T.GetString(Page.Title); + Page.Title = ViewState["orgtitle"] + " - " + YavscHelpers.SiteName; + %> - - + + - - + + + @@ -22,32 +22,40 @@

<%=ViewState["orgtitle"]%> - "><%= YavscHelpers.SiteName %>

-
- -<% if (ViewData["Error"]!=null) { %> -
-<%= Html.Encode(ViewData["Error"]) %> -
-<% } %> -<% if (ViewData["Message"]!=null) { %> -
-<%= Html.Encode(ViewData["Message"]) %> -
-<% } %> - + <% + if (ViewData["Error"]!=null) { + %>
<%= Html.Encode(ViewData["Error"]) %> +
<% } + if (ViewData["Message"]!=null) { + %>
<%= Html.Encode(ViewData["Message"]) %>
<% } + %> +
- -
- <% foreach ( string link in Yavsc.ThanksHelper.Links()) { %> + + + +
+
+ <%= Html.ActionLink("Contact","Contact","Home",null, new { @class="footerlink" }) %>
+ <% foreach ( string link in Yavsc.ThanksHelper.Links()) { %> <%= link %> <% } %>
+ diff --git a/web/Views/Admin/Created.aspx b/web/Views/Admin/Created.aspx index df0b544e..58ad700d 100644 --- a/web/Views/Admin/Created.aspx +++ b/web/Views/Admin/Created.aspx @@ -1,8 +1,12 @@ -<%@ Page Title="Db init" Language="C#" MasterPageFile="~/Models/App.master" Inherits="System.Web.Mvc.ViewPage" %> - +<%@ Page Title="Db init" Language="C#" MasterPageFile="~/Models/NoLogin.master" Inherits="System.Web.Mvc.ViewPage" %> +

Initialisation de la base de données

Error message

<%= Html.Encode(Model.Error) %>

Message

<%= Html.Encode(Model.Message) %>

Exit Code

<%= Html.Encode(Model.ExitCode) %>
- +
Acces à la base de donnée +<%= Html.Encode(Model.Dbname) %>
+<%= Html.Encode(Model.Dbuser) %>
+<%= Html.Encode(Model.Password[0]) %> ... You should already know it.
+<%= Html.Encode(Model.Host) %>:<%= Model.Port %> diff --git a/web/Views/Admin/InitDb.aspx b/web/Views/Admin/InitDb.aspx index 2a1f1655..eab5db87 100644 --- a/web/Views/Admin/InitDb.aspx +++ b/web/Views/Admin/InitDb.aspx @@ -17,7 +17,7 @@ <%= Html.LabelFor(model => model.Password) %>: <%= Html.Password( "Password" ) %> <%= Html.ValidationMessage("Password", "*") %>
- + <% } %> diff --git a/web/instdbws.sql b/web/instdbws.sql index a3f41dc9..57f2b4a8 100644 --- a/web/instdbws.sql +++ b/web/instdbws.sql @@ -217,8 +217,7 @@ CREATE TABLE commandes WITH ( OIDS=FALSE ); -ALTER TABLE commandes - OWNER TO yavsc; + COMMENT ON COLUMN commandes.id IS 'Identifiant unique de commande e, cours'; COMMENT ON COLUMN commandes.validation IS 'Date de validation'; COMMENT ON COLUMN commandes.prdref IS 'Product reference from the unique valid catalog at the validation date'; diff --git a/yavscModel/Admin/DataAccess.cs b/yavscModel/Admin/DataAccess.cs index 7239c875..4f9eca4c 100644 --- a/yavscModel/Admin/DataAccess.cs +++ b/yavscModel/Admin/DataAccess.cs @@ -100,10 +100,8 @@ namespace Yavsc.Model.Admin /// Connections the string. ///
/// The string. - public string ConnectionString() { - return string.Format ("Server={0};Port={1};Database={2};User Id={3};Password={4};Encoding=Unicode;", - Host,Port,Dbuser,Password); - } + public string ConnectionString { get { return string.Format ("Server={0};Port={1};Database={2};User Id={3};Password={4};Encoding=Unicode;", + Host, Port, Dbname, Dbuser, Password); } } } }