Initial import

This commit is contained in:
Paul Schneider 2014-07-16 20:35:03 +02:00
commit 04804b89a9
279 changed files with 12945 additions and 0 deletions

View file

@ -0,0 +1,37 @@
using System;
using System.Xml.Serialization;
using System.ComponentModel.DataAnnotations;
namespace SalesCatalog.Model
{
public class Brand
{
public Brand ()
{
}
[Required]
public string Name { get; set; }
public string Slogan { get; set; }
public ProductImage Logo { get; set; }
public ProductCategory[] Categories { get; set; }
/// <summary>
/// Gets or sets the default form.
/// </summary>
/// <value>The default form.</value>
public SaleForm DefaultForm { get; set; }
public ProductCategory GetProductCategory(string reference)
{
return Array.Find<ProductCategory>(Categories, c => c.Reference == reference);
}
public ProductCategory GetProductCategoryByName(string catName)
{
return Array.Find<ProductCategory>(Categories, c => c.Name == catName);
}
}
}

View file

@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
namespace SalesCatalog.Model
{
/// <summary>
/// Catalog.
/// </summary>
public class Catalog {
/// <summary>
/// Gets or sets the brands.
/// </summary>
/// <value>The brands.</value>
public Brand[] Brands { get; set; }
public Brand GetBrand(string brandName)
{
return Array.Find<Brand>(Brands, b => b.Name == brandName);
}
public Brand AddBrand(string brandName,string slogan=null, ProductImage logo=null)
{
Brand[] oldbrs = (Brand[]) Brands.Clone ();
int oldl = Brands.Length;
Array.Resize<Brand>(ref oldbrs,oldl+1);
Brand b = new Brand ();
b.Name=brandName;
b.Slogan = slogan;
b.Logo = logo;
oldbrs [oldl] = b;
Brands=oldbrs;
return b;
}
public bool RemoveBrand(string brandName)
{
Brand b = this.GetBrand (brandName);
if (b == null)
return false;
//assert(Brands.Length>0);
List<Brand> nb = new List<Brand> (Brands);
nb.Remove (b);
Brands = nb.ToArray ();
return true;
}
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
}
}

View file

@ -0,0 +1,18 @@
using System;
namespace SalesCatalog.Model
{
public class CheckBox : FormInput
{
public CheckBox ()
{
}
public bool Value { get; set; }
public override string ToHtml ()
{
return string.Format ("<input type=\"checkbox\" id=\"{0}\" name=\"{1}\" {2}/>", Id,Name,Value?"checked":"");
}
}
}

View file

@ -0,0 +1,9 @@
using System;
namespace SalesCatalog.Model
{
public abstract class Currency: Unit
{
}
}

View file

@ -0,0 +1,34 @@
using System;
namespace SalesCatalog.Model
{
public class Euro : Currency
{
public Euro ()
{
}
public override string Name {
get {
return "Euro";
}
}
public override string Description {
get {
return "European currency";
}
}
public override bool MayConvertTo (Unit other)
{
return other.GetType().IsSubclassOf(typeof (Currency));
}
public override object ConvertTo (Unit dest, object value)
{
throw new NotImplementedException();
}
}
}

View file

@ -0,0 +1,18 @@
using System;
namespace SalesCatalog.Model
{
public class FilesInput : FormInput
{
public FilesInput ()
{
}
public override string ToHtml ()
{
return string.Format ("<input type=\"file\" id=\"{0}\" name=\"{0}\"/>", Id);
}
}
}

View file

@ -0,0 +1,10 @@
using System;
namespace SalesCatalog.Model
{
public abstract class FormElement
{
public abstract string ToHtml ();
}
}

View file

@ -0,0 +1,19 @@
using System;
namespace SalesCatalog.Model
{
public abstract class FormInput: FormElement
{
/// <summary>
/// Gets or sets the identifier, unique in its Form.
/// </summary>
/// <value>
/// The identifier.
/// </value>
public string Id { get; set; }
private string name=null;
public string Name { get { return name == null ? Id : name; } set { name = value; } }
}
}

View file

@ -0,0 +1,18 @@
using System;
namespace SalesCatalog.Model
{
public class Label:FormElement
{
public Label ()
{
}
string Text { get; set; }
string For { get; set ; }
public override string ToHtml ()
{
return string.Format ("<label for=\"{0}\">{1}</label>", For, Text);
}
}
}

View file

@ -0,0 +1,15 @@
using System;
using System.ComponentModel.DataAnnotations;
namespace SalesCatalog.Model
{
public class Link:Label
{
public Link ()
{
}
[Required]
public string Ref { get; set; }
}
}

View file

@ -0,0 +1,13 @@
using System;
namespace SalesCatalog.Model
{
public class Note:Text
{
public override string ToHtml ()
{
return string.Format("<quote>{0}</quote>",Val);
}
}
}

View file

@ -0,0 +1,19 @@
using System;
namespace SalesCatalog.Model
{
public class Option : FormElement
{
public Option ()
{
}
public string Value { get; set; }
public string Text { get; set; }
public override string ToHtml ()
{
return string.Format ("<option value=\"{0}\">{1}</option>\n",Value,Text);
}
}
}

View file

@ -0,0 +1,15 @@
using System;
namespace SalesCatalog.Model
{
public class Period
{
public Period ()
{
}
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
}
}

View file

@ -0,0 +1,27 @@
using System;
namespace SalesCatalog.Model
{
public class PhysicalProduct : Product
{
public PhysicalProduct ()
{
}
public Price UnitaryPrice { get; set; }
#region implemented abstract members of SalesCatalog.Model.Product
public override string[] GetSalesConditions ()
{
return new string [] { string.Format(
"Prix unitaire : {0} {1}",
UnitaryPrice.Quantity.ToString(),
UnitaryPrice.Unit.Name) };
}
#endregion
public override string ToString ()
{
return string.Format ("[PhysicalProduct: UnitaryPrice={0}]", UnitaryPrice);
}
}
}

View file

@ -0,0 +1,36 @@
using System;
namespace SalesCatalog.Model
{
public class Price: Scalar
{
public Price ()
{
}
decimal quantity;
#region implemented abstract members of SalesCatalog.Value
public override object Quantity {
get {
return quantity;
}
set {
quantity = (decimal) value;
}
}
Currency curr;
public override SalesCatalog.Model.Unit Unit {
get {
return curr;
}
set {
curr = (Currency)value;
}
}
#endregion
}
}

View file

@ -0,0 +1,37 @@
using System;
using System.ComponentModel.DataAnnotations;
namespace SalesCatalog.Model
{
/// <summary>
/// Product.
/// Crucial object in the catalog,
/// being at each origin of form display
/// its properties may be used to fill some form input values or other form element.
/// <c>in text values, within {} ex: {Name} : {Price} ({stockStatus}) ($description) </c>.
/// </summary>
public abstract class Product
{
/// <summary>
/// Gets or sets the product name.
/// </summary>
/// <value>The name.</value>
[Required]
[StringLength(1024)]
public string Name { get; set; }
/// <summary>
/// Gets or sets the product description.
/// </summary>
/// <value>The description.</value>
public string Description { get; set; }
public ProductImage[] Images { get; set; }
public SaleForm CommandForm { get; set; }
[Required]
[StringLength(255)]
public string Reference { get; set; }
public Period CommandValidityDates { get; set; }
public abstract string[] GetSalesConditions();
}
}

View file

@ -0,0 +1,23 @@
using System;
namespace SalesCatalog.Model
{
public class ProductCategory
{
public ProductCategory ()
{
}
public string Name { get; set; }
public string Reference { get; set; }
public Product[] Products { get; set; }
public Product GetProductByName (string productName)
{
return Array.Find<Product> (Products, p => p.Name == productName);
}
public Product GetProduct (string reference)
{
return Array.Find<Product> (Products, p => p.Reference == reference);
}
}
}

View file

@ -0,0 +1,23 @@
using System;
namespace SalesCatalog.Model
{
public class ProductImage: FormElement
{
#region implemented abstract members of FormElement
public override string ToHtml ()
{
return string.Format ("<img src=\"\" alt=\"\"/>", Src, Alt);
}
#endregion
public ProductImage ()
{
}
public string Src { get; set; }
public string Alt { get; set; }
}
}

View file

@ -0,0 +1,17 @@
using System;
namespace SalesCatalog.Model
{
public class RadioButton:FormInput
{
public RadioButton ()
{
}
public string Choice { get; set; }
public override string ToHtml ()
{
return string.Format ("<input type=\"radio\" id=\"{0}\" name=\"{1}\" value=\"{2}\"/><label for=\"{0}\">{2}</label>", Id,Name,Choice);
}
}
}

View file

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
namespace SalesCatalog.Model
{
public class SaleForm
{
public SaleForm ()
{
}
public string Action {
get;
set;
}
public FormElement[] Items { get; set; }
}
}

View file

@ -0,0 +1,14 @@
using System;
namespace SalesCatalog.Model
{
public abstract class Scalar
{
public Scalar ()
{
}
public abstract object Quantity { get; set; }
public abstract Unit Unit{ get; set; }
}
}

View file

@ -0,0 +1,20 @@
using System;
using System.Text;
using System.Web.Mvc;
namespace SalesCatalog.Model
{
public class SelectInput: FormInput
{
public Option[] Items;
public int SelectedIndex;
public override string ToHtml ()
{
StringBuilder sb = new StringBuilder ();
foreach (Option opt in Items)
sb.Append (opt.ToHtml());
return string.Format ("<select id=\"{0}\" name=\"{1}\">{2}</select>\n", Id,Name,sb.ToString());
}
}
}

View file

@ -0,0 +1,23 @@
using System;
namespace SalesCatalog.Model
{
public class SelectItem
{
public SelectItem(string t)
{
Value = t;
}
public string Value { get; set; }
public static implicit operator string(SelectItem t)
{
return t.Value;
}
public static implicit operator SelectItem(string t)
{
return new SelectItem(t);
}
}
}

View file

@ -0,0 +1,28 @@
using System;
namespace SalesCatalog.Model
{
public class Service : Product
{
public Service ()
{
}
public Price HourPrice { get; set; }
#region implemented abstract members of SalesCatalog.Model.Product
public override string [] GetSalesConditions ()
{
return new string [] { string.Format(
"Prix horaire de la prestation : {0} {1}",
HourPrice.Quantity.ToString(),
HourPrice.Unit.Name) } ;
}
#endregion
public override string ToString ()
{
return string.Format ("[Service: HourPrice={0}]", HourPrice);
}
}
}

View file

@ -0,0 +1,11 @@
using System;
namespace SalesCatalog.Model
{
public enum StockStatus
{
NoStock,
InStock
}
}

View file

@ -0,0 +1,18 @@
using System;
namespace SalesCatalog.Model
{
public class Text: FormElement
{
public string Val {
get;
set;
}
public override string ToHtml ()
{
return Val;
}
}
}

View file

@ -0,0 +1,46 @@
using System;
namespace SalesCatalog.Model
{
public class TextInput:FormInput
{
public TextInput ()
{
}
public TextInput (string txt)
{
text = txt;
}
string text = null;
public static implicit operator string(TextInput t)
{
return t.text;
}
public static implicit operator TextInput(string t)
{
return new TextInput(t);
}
public string DefaultValue {
get {
return text;
}
set {
text = (string) value;
}
}
private bool multiline = false;
public bool MultiLine { get { return multiline; } set { multiline = value; } }
public override string ToHtml ()
{
return MultiLine?
string.Format ("<textarea id=\"{0}\" name=\"{1}\">{2}</textarea>", Id,Name,DefaultValue)
: string.Format ("<input type=\"text\" id=\"{0}\" name=\"{1}\" value=\"{2}\"/>", Id,Name,DefaultValue);
}
}
}

View file

@ -0,0 +1,13 @@
using System;
namespace SalesCatalog.Model
{
public abstract class Unit
{
public abstract string Name { get; }
public abstract string Description { get; }
public abstract object ConvertTo (Unit dest, object value);
public abstract bool MayConvertTo (Unit other);
}
}