Edition du devis fonctionnelle

vnext
Paul Schneider 10 years ago
parent f157c6edb9
commit 2ac2338939
22 changed files with 347 additions and 74 deletions

@ -66,11 +66,6 @@ namespace WorkFlowProvider
throw new NotImplementedException ();
}
public void UpdateWritting (Writting wr)
{
throw new NotImplementedException ();
}
public void SetWrittingStatus (long wrtid, int status, string username)
{
throw new NotImplementedException ();
@ -198,6 +193,30 @@ namespace WorkFlowProvider
}
}
public void UpdateWritting (Writting wr)
{
using (NpgsqlConnection cnx = CreateConnection ()) {
using (NpgsqlCommand cmd = cnx.CreateCommand ()) {
cmd.CommandText =
"update writtings set " +
"description = @desc, " +
"ucost = @ucost, " +
"count = @count, " +
"productid = @prdid " +
"where _id = @wrid";
cmd.Parameters.Add ("@wrid", wr.Id);
cmd.Parameters.Add ("@desc", wr.Description);
cmd.Parameters.Add ("@ucost", wr.UnitaryCost);
cmd.Parameters.Add ("@prdid", wr.ProductReference);
cmd.Parameters.Add ("@count", wr.Count);
cnx.Open ();
cmd.ExecuteNonQuery ();
cnx.Close ();
}
}
}
public void SetTitle (long estid, string newTitle)
{
using (NpgsqlConnection cnx = CreateConnection ()) {

@ -9,6 +9,7 @@
<OutputType>Library</OutputType>
<RootNamespace>WorkFlowProvider</RootNamespace>
<AssemblyName>WorkFlowProvider</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>

@ -24,6 +24,7 @@ namespace Yavsc.Controllers
public ActionResult Estimate(Estimate model,string submit)
{
if (ModelState.IsValid) {
ViewData ["WebApiUrl"] = "http://"+ Request.Url.Authority + "/api/WorkFlow";
string username = HttpContext.User.Identity.Name;
if (model.Id > 0) {
Estimate f = WorkFlowManager.GetEstimate (model.Id);
@ -31,7 +32,6 @@ namespace Yavsc.Controllers
ModelState.AddModelError ("Id", "Wrong Id");
return View (model);
}
if (username != f.Owner)
if (!Roles.IsUserInRole ("FrontOffice"))
throw new UnauthorizedAccessException ("You're not allowed to view/modify this estimate");

@ -11,7 +11,6 @@ using System.Web.Security;
namespace Yavsc.ApiControllers
{
//[HttpControllerConfiguration(ActionValueBinder=typeof(Basic.MvcActionValueBinder))]
public class WorkFlowController : ApiController
{
string adminRoleName="Admin";
@ -39,10 +38,13 @@ namespace Yavsc.ApiControllers
{
WorkFlowManager.DropWritting (wrid);
}
[HttpGet]
[Authorize]
public void UpdateWritting(Writting wr)
[AcceptVerbs("POST")]
public void UpdateWritting([FromBody] Writting wr)
{
if (!ModelState.IsValid)
throw new Exception ("Modèle invalide");
WorkFlowManager.UpdateWritting (wr);
}
@ -62,12 +64,13 @@ namespace Yavsc.ApiControllers
return new { test=string.Format("Hello {0}!",username) };
}
[HttpGet]
[HttpPost]
[AcceptVerbs("POST")]
[Authorize]
public long Write (long estid, string desc, decimal ucost, int count, string productid) {
public long Write ([FromUri] long estid, [FromBody] Writting wr) {
// TODO ensure estid owner matches the current one
return WorkFlowManager.Write(estid, desc, ucost, count, productid);
return WorkFlowManager.Write(estid, wr.Description,
wr.UnitaryCost, wr.Count, wr.ProductReference);
}
}
}

@ -16,6 +16,10 @@ namespace Yavsc
{
routes.IgnoreRoute ("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute ("js/{*pathInfo}");
routes.IgnoreRoute ("Theme/{*pathInfo}");
routes.IgnoreRoute ("css/{*pathInfo}");
routes.IgnoreRoute ("images/{*pathInfo}");
routes.MapRoute (
"Blog",

@ -5,9 +5,11 @@
<% Page.Title += " - "+YavscHelpers.SiteName; %>
</asp:ContentPlaceHolder>
<head runat="server">
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
<meta name="viewport" content="width=device-width" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" href="/style.css"/>
<link rel="stylesheet" href="/Theme/style.css"/>
<link rel="icon" type="image/png" href="/favicon.png" />
<link href='http://fonts.googleapis.com/css?family=Dancing+Script:400,700' rel='stylesheet' type='text/css'/>

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 B

@ -0,0 +1,39 @@
/* tables */
table.tablesorter {
font-family:arial;
background-color: #CDCDCD;
margin:10px 0pt 15px;
font-size: 8pt;
width: 100%;
text-align: left;
}
table.tablesorter thead tr th, table.tablesorter tfoot tr th {
background-color: #e6EEEE;
border: 1px solid #FFF;
font-size: 8pt;
padding: 4px;
}
table.tablesorter thead tr .header {
background-image: url(bg.gif);
background-repeat: no-repeat;
background-position: center right;
cursor: pointer;
}
table.tablesorter tbody td {
color: #3D3D3D;
padding: 4px;
background-color: #FFF;
vertical-align: top;
}
table.tablesorter tbody tr.odd td {
background-color:#F0F0F6;
}
table.tablesorter thead tr .headerSortUp {
background-image: url(/Theme/blue/asc.gif);
}
table.tablesorter thead tr .headerSortDown {
background-image: url(/Theme/blue/desc.gif);
}
table.tablesorter thead tr .headerSortDown, table.tablesorter thead tr .headerSortUp {
background-color: #8dbdd8;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 B

@ -0,0 +1,41 @@
/* tables */
table.tablesorter {
font-family:arial;
background-color: #333;
margin:10px 0pt 15px;
font-size: 8pt;
width: 100%;
text-align: left;
}
table.tablesorter thead tr th, table.tablesorter tfoot tr th {
background-color: rgba(0,0,0,0.5);
border: 1px solid #206;
font-size: 8pt;
padding: 4px;
}
table.tablesorter thead tr .header {
background-image: url(bg.gif);
background-repeat: no-repeat;
background-position: center right;
cursor: pointer;
}
table.tablesorter tbody td {
color: #ffa;
padding: 4px;
vertical-align: top;
background-color: #002;
}
table.tablesorter .odd td {
background-color: #004;
}
table.tablesorter thead tr .headerSortUp {
background-image: url(/Theme/dark/asc.gif);
}
table.tablesorter thead tr .headerSortDown {
background-image: url(/Theme/dark/desc.gif);
}
table.tablesorter thead tr .headerSortDown, table.tablesorter thead tr .headerSortUp {
background-color: #123;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

@ -0,0 +1,39 @@
table.tablesorter {
font-size: 12px;
background-color: #4D4D4D;
width: 1024px;
border: 1px solid #000;
}
table.tablesorter th {
text-align: left;
padding: 5px;
background-color: #6E6E6E;
}
table.tablesorter td {
color: #FFF;
padding: 5px;
}
table.tablesorter .even {
background-color: #3D3D3D;
}
table.tablesorter .odd {
background-color: #6E6E6E;
}
table.tablesorter .header {
background-image: url(bg.png);
background-repeat: no-repeat;
border-left: 1px solid #FFF;
border-right: 1px solid #000;
border-top: 1px solid #FFF;
padding-left: 30px;
padding-top: 8px;
height: auto;
}
table.tablesorter .headerSortUp {
background-image: url(/Theme/green/asc.png);
background-repeat: no-repeat;
}
table.tablesorter .headerSortDown {
background-image: url(/Theme/green/desc.png);
background-repeat: no-repeat;
}

@ -1,8 +1,14 @@
<%@ Page Title="Devis" Language="C#" Inherits="System.Web.Mvc.ViewPage<Estimate>" MasterPageFile="~/Models/App.master" %>
<asp:Content ContentPlaceHolderID="MainContent" ID="MainContentContent" runat="server">
<asp:Content ContentPlaceHolderID="head" ID="head1" runat="server" >
<script type="text/javascript" src="/js/jquery-latest.js"></script>
<script type="text/javascript" src="/js/jquery.tablesorter.js"></script>
<link rel="stylesheet" href="/Theme/dark/style.css" type="text/css" media="print, projection, screen" />
</asp:Content>
<asp:Content ContentPlaceHolderID="MainContent" ID="MainContentContent" runat="server">
<%= Html.ValidationSummary("Devis") %>
<% using (Html.BeginForm("Estimate","FrontOffice")) { %>
<%= Html.LabelFor(model => model.Title) %>:<%= Html.TextBox( "Title" ) %>
@ -22,25 +28,14 @@
<% } else { %>
<input type="submit" name="submit" value="Update"/>
<script type="text/javascript" >
<% } %>
$(document).ready(function()
{
$("#myTable").tablesorter( {sortList: [[0,0], [1,0]]} );
}
);
</script>
<% } %>
<% if (Model.Lines ==null || Model.Lines.Length == 0) { %>
<i>Pas de ligne.</i>
<%
} else { %>
<table class="tablesorter">
<thead>
<tr>
<th>Id</th>
<th>Description</th>
<th>Product Reference</th>
<th>Count</th>
@ -48,9 +43,10 @@
</tr>
</thead>
<tbody id="wrts">
<% foreach (Writting wr in Model.Lines) { %>
<tr>
<td><%=wr.Id%></td>
<% int lc=0;
if (Model.Lines!=null)
foreach (Writting wr in Model.Lines) { lc++; %>
<tr class="<%= (lc%2==0)?"odd ":"" %>row" id="wr<%=wr.Id%>">
<td><%=wr.Description%></td>
<td><%=wr.ProductReference%></td>
<td><%=wr.Count%></td>
@ -60,12 +56,13 @@
</tbody>
</table>
<% } %>
<% } %>
<% } %>
</asp:Content>
<asp:Content ContentPlaceHolderID="MASContent" ID="MASContent1" runat="server">
<script type="text/javascript" >
function ShowHideBtn(btn,id)
@ -78,63 +75,140 @@
</script>
<form id="writeform">
<input type="button" onclick="ShowHideBtn(this,'writearea');" value="+"/>
<input type="button" id="btndtl" value="+"/>
<div id="writearea" style="display:none;">
<input type="hidden" name="estid" id="estid" value="<%=Model.Id%>"/>
<label for="desc">Description:</label>
<input type="text" name="desc" id="desc" />
<label for="ucost">Prix unitaire:</label>
<input type="number" name="ucost" id="ucost"/>
<label for="count">Quantité:</label>
<input type="number" name="count" id="count"/>
<label for="productid">Référence du produit:</label>
<input type="text" name="productid" id="productid"/>
<input type="button" name="btnapply" id="btnapply" value="Écrire"/>
<label for="Description">Description:</label>
<input type="text" name="Description" id="Description" />
<label for="UnitaryCost">Prix unitaire:</label>
<input type="number" name="UnitaryCost" id="UnitaryCost"/>
<label for="Count">Quantité:</label>
<input type="number" name="Count" id="Count"/>
<label for="ProductReference">Référence du produit:</label>
<input type="text" name="ProductReference" id="ProductReference"/>
<input type="button" name="btnmodify" id="btnmodify" value="Modifier"/>
<input type="button" name="btncreate" id="btncreate" value="Écrire"/>
<input type="button" name="btndrop" id="btndrop" value="Supprimer"/>
<input type="hidden" name="wrid" id="wrid" />
<tt id="dbgv"></tt>
<input type="button" name="btnview" id="btnview" value="View Values"/>
<tt id="msg" class="message"></tt>
<style>
.row { cursor:pointer; }
table.tablesorter td:hover { background-color: rgb(64,0,0); }
.hidden { display:none; }
</style>
<script>
jQuery.support.cors = false;
jQuery.support.cors = true;
function GetWritting () {
var estid = parseInt($("#estid").val());
var ucost = Number($("#ucost").val());
var count = parseInt($("#count").val());
var desc = $("#desc").val();
var productid = $("#productid").val();
return {
estid:estid,
desc:desc,
ucost:ucost,
count:count,
productid:productid
Id: Number($("#wrid").val()),
UnitaryCost: Number($("#UnitaryCost").val()),
Count: parseInt($("#Count").val()),
ProductReference: $("#ProductReference").val(),
Description: $("#Description").val()
};
}
function wredit(pwrid)
{
$("#wrid").val(pwrid);
if (pwrid>0) {
$("#btncreate").addClass("hidden");
$("#btnmodify").removeClass("hidden");
$("#btndrop").removeClass("hidden");
} else {
$("#btncreate").removeClass("hidden");
$("#btnmodify").addClass("hidden");
$("#btndrop").addClass("hidden");
}
}
$(document).ready(function () {
// bug at no row: $(".tablesorter").tablesorter( {sortList: [[0,0], [1,0]]} );
$("#btnapply").click(function () {
function delRow() {
$.ajax({
url: "http://localhost:8080/api/WorkFlow/Write",
url: "<%=ViewData["WebApiUrl"]+"/DropWritting"%>",
type: "Get",
dataType: "json",
data: GetWritting(),
data: { wrid: wrid.value },
contentType: 'application/json; charset=utf-8',
success: function (data) {
$("#wrid").val(data);
success: function () {
var tr = document.getElementById("wr"+wrid.value);
$("#wr"+wrid.value).remove();
$("#wrid").val(0);
$("#ucost").val(0);
$("#Count").val(0);
$("#Description").val();
$("#ProductReference").val();
wredit(0);
},
error: function (xhr, ajaxOptions, thrownError) {
$("#dbgv").text(xhr.status+" : "+xhr.responseText);
$("#msg").text(xhr.status+" : "+xhr.responseText);}
});
}
function setRow() {
var wrt = GetWritting();
$.ajax({
url: "<%=ViewData["WebApiUrl"]+"/UpdateWritting"%>",
type: "POST",
data: JSON.stringify(wrt),
contentType: 'application/json; charset=utf-8',
success: function () {
var cells = document.getElementById("wr"+wrt.Id).getElementsByTagName("TD");
cells[0].innerHTML=wrt.Description;
cells[1].innerHTML=wrt.ProductReference;
cells[2].innerHTML=wrt.UnitaryCost;
cells[3].innerHTML=wrt.Count;
},
error: function (xhr, ajaxOptions, thrownError) {
$("#msg").text(xhr.status+" : "+xhr.responseText);}
});
}
//data: {estid: estid, wr: { Id: 0, UnitaryCost: wrt.UnitaryCost, Count: wrt.Count, ProductReference: wrt.ProductReference, Description: wrt.Description}},
function addRow(){
var wrt = GetWritting();
var estid = parseInt($("#Id").val());
$.ajax({
url: "<%=ViewData["WebApiUrl"]+"/Write"%>/?estid="+estid,
type: "POST",
traditional: false,
data: JSON.stringify(wrt),
contentType: 'application/json; charset=utf-8',
success: function (data) {
wrt.Id = Number(data);
wredit(wrt.Id);
$("<tr class=\"row\" id=\"wr"+wrt.Id+"\"><td>"+wrt.Description+"</td><td>"+wrt.ProductReference+"</td><td>"+wrt.Count+"</td><td>"+wrt.UnitaryCost+"</td></tr>").appendTo("#wrts")
},
error: function (xhr, ajaxOptions, thrownError) {
$("#msg").text(xhr.status+" : "+xhr.responseText);}
});
$("#btnview").click(function () {
$("#dbgv").text(JSON.stringify(GetWritting()));
}
$("#btncreate").click(addRow);
$("#btnmodify").click(setRow);
$("#btndrop").click(delRow);
function ShowDtl(val)
{
document.getElementById("writearea").style.display = val ? "block" : "none";
document.getElementById("btndtl").value = val ? "-" : "+";
}
$("#btndtl").click(function(){ShowDtl(document.getElementById("writearea").style.display != "block");});
$(".row").click(function (e) {
ShowDtl(true);
var cells = e.delegateTarget.getElementsByTagName("TD");
var wrid = Number(e.delegateTarget.id.substr(2));
wredit(wrid);
$("#Description").val(cells[0].innerHTML);
$("#ProductReference").val(cells[1].innerHTML);
$("#Count").val(cells[2].innerHTML);
$("#UnitaryCost").val(Number(cells[3].innerHTML.replace(",",".")));
});
});
</script>

@ -25,6 +25,11 @@
</AspNet>
<AssemblyName>Yavsc</AssemblyName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<CustomCommands>
<CustomCommands>
<Command type="BeforeExecute" />
</CustomCommands>
</CustomCommands>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
@ -107,6 +112,10 @@
<Folder Include="Views\WorkFlow\" />
<Folder Include="Views\Admin\" />
<Folder Include="js\" />
<Folder Include="Theme\" />
<Folder Include="Theme\green\" />
<Folder Include="Theme\blue\" />
<Folder Include="Theme\dark\" />
</ItemGroup>
<ItemGroup>
<Compile Include="Controllers\HomeController.cs" />
@ -145,7 +154,6 @@
<Content Include="Views\Home\Index.aspx" />
<Content Include="Web.config" />
<Content Include="Global.asax" />
<Content Include="style.css" />
<Content Include="Models\App.master" />
<Content Include="Views\Account\Register.aspx" />
<Content Include="Views\Account\ChangePassword.aspx" />
@ -204,6 +212,19 @@
<Content Include="js\jquery.tablesorter.min.js" />
<Content Include="js\jquery-latest.js" />
<Content Include="Views\FrontOffice\Write.aspx" />
<Content Include="Theme\style.css" />
<Content Include="Theme\green\asc.png" />
<Content Include="Theme\green\bg.png" />
<Content Include="Theme\green\desc.png" />
<Content Include="Theme\green\style.css" />
<Content Include="Theme\blue\asc.gif" />
<Content Include="Theme\blue\bg.gif" />
<Content Include="Theme\blue\desc.gif" />
<Content Include="Theme\blue\style.css" />
<Content Include="Theme\dark\asc.gif" />
<Content Include="Theme\dark\bg.gif" />
<Content Include="Theme\dark\desc.gif" />
<Content Include="Theme\dark\style.css" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />

@ -1,13 +1,43 @@
using System;
using System.ComponentModel.DataAnnotations;
namespace Yavsc.Model.WorkFlow
{
/// <summary>
/// A Writting.
/// Une ligne d'écriture dans un devis ou une facture
/// </summary>
public class Writting
{
/// <summary>
/// Gets or sets the identifier.
/// </summary>
/// <value>The identifier.</value>
public long Id { get; set; }
/// <summary>
/// Gets or sets the unitary cost, per unit, or per hour ...
/// Who knows?
/// </summary>
/// <value>The unitary cost.</value>
[Required()]
public decimal UnitaryCost { get; set; }
/// <summary>
/// Gets or sets the count.
/// </summary>
/// <value>The count.</value>
[Required()]
public int Count { get; set; }
/// <summary>
/// Gets or sets the product reference.
/// </summary>
/// <value>The product reference.</value>
[Required()]
public string ProductReference { get; set; }
/// <summary>
/// Gets or sets the description.
/// </summary>
/// <value>The description.</value>
[Required()]
public string Description { get; set; }
}
}

Loading…