Add Outlook Inspired and Stock Market demos

This commit is contained in:
maxerokh
2018-12-13 18:49:44 +03:00
parent b5cab35919
commit 2e45b5d38f
833 changed files with 124450 additions and 47 deletions

View File

@@ -0,0 +1,56 @@
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using DevExpress.Common;
using DevExpress.DataAnnotations;
namespace DevExpress.DevAV {
[NotMapped]
public partial class Address : IDataErrorInfo {
[Display(Name = "Address")]
public string Line { get; set; }
public string City { get; set; }
public StateEnum State { get; set; }
[ZipCode, Display(Name = "Zip code")]
public string ZipCode { get; set; }
public double Latitude { get; set; }
public double Longitude { get; set; }
public string CityLine {
get { return GetCityLine(City, State, ZipCode); }
}
public override string ToString() {
return string.Format("{0}, {1}", Line, CityLine);
}
#region IDataErrorInfo
string IDataErrorInfo.Error { get { return null; } }
string IDataErrorInfo.this[string columnName] {
get { return IDataErrorInfoHelper.GetErrorText(this, columnName); }
}
#endregion
internal static string GetCityLine(string city, StateEnum state, string zipCode) {
return string.Format("{0}, {1} {2}", city, state, zipCode);
}
}
public static class AddressHelper {
public static Address DevAVHomeOffice { get { return devAVHomeOffice; } }
static Address devAVHomeOffice = new Address {
City = "Glendale",
Line = "505 N. Brand Blvd",
State = StateEnum.CA,
ZipCode = "91203",
Latitude = 34.1532866,
Longitude = -118.2555815
};
public static void UpdateAddress(Address address, string line, string city, StateEnum state, string zipCode, double latitude, double longtitude){
address.Line = line;
address.City = city;
address.State = state;
address.ZipCode = zipCode;
address.Latitude = latitude;
address.Longitude = longtitude;
}
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DevExpress.DevAV {
public class TaskAttachedFile : DatabaseObject {
public virtual EmployeeTask EmployeeTask { get; set; }
public long? EmployeeTaskId { get; set; }
public string Name { get; set; }
public byte[] Content { get; set; }
}
}

View File

@@ -0,0 +1,37 @@
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Reflection;
namespace DevExpress.Common {
public static class IDataErrorInfoHelper {
public static string GetErrorText(object owner, string propertyName) {
string[] path = propertyName.Split('.');
if(path.Length > 1)
return GetErrorText(owner, path);
PropertyInfo propertyInfo = owner.GetType().GetProperty(propertyName);
if (propertyInfo == null) return null;
object propertyValue = propertyInfo.GetValue(owner, null);
ValidationContext validationContext = new ValidationContext(owner, null, null) { MemberName = propertyName };
string[] errors = propertyInfo
.GetCustomAttributes(false)
.OfType<ValidationAttribute>()
.Select(x => x.GetValidationResult(propertyValue, validationContext))
.Where(x => x != null)
.Select(x => x.ErrorMessage)
.Where(x => !string.IsNullOrEmpty(x))
.ToArray();
return string.Join(" ", errors);
}
static string GetErrorText(object owner, string[] path) {
string nestedPropertyName = string.Join(".", path.Skip(1));
string propertyName = path[0];
PropertyInfo propertyInfo = owner.GetType().GetProperty(propertyName);
if(propertyInfo == null)
return null;
object propertyValue = propertyInfo.GetValue(owner, null);
IDataErrorInfo nestedDataErrorInfo = propertyValue as IDataErrorInfo;
return nestedDataErrorInfo == null ? string.Empty : nestedDataErrorInfo[nestedPropertyName];
}
}
}

View File

@@ -0,0 +1,77 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Reflection.Emit;
using System.Resources;
using System.Security;
using System.Text;
using System.Text.RegularExpressions;
// This demo targets .NET Framework 4.0. A number of validation attributes that exist in .NET Framework 4.5 cannot be used.
// That is why we have created our own counterparts of these attributes for this demo.
// If your application targets .NET Framework 4.5, use default validation attributes.
// If your application targets .NET Framework 4.0, you can copy and use these attributes or use DevExpress Validation Fluent API instead.
namespace DevExpress.DataAnnotations {
public abstract class RegexAttributeBase : DataTypeAttribute {
protected const RegexOptions DefaultRegexOptions = RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase;
readonly Regex regex;
public RegexAttributeBase(string regex, string defaultErrorMessage, DataType dataType)
: this(new Regex(regex, DefaultRegexOptions), defaultErrorMessage, dataType) {
}
public RegexAttributeBase(Regex regex, string defaultErrorMessage, DataType dataType)
: base(dataType) {
this.regex = (Regex)regex;
this.ErrorMessage = defaultErrorMessage;
}
public sealed override bool IsValid(object value) {
if(value == null)
return true;
string input = value as string;
return input != null && regex.Match(input).Length > 0;
}
}
public sealed class ZipCodeAttribute : RegexAttributeBase {
static Regex regex = new Regex(@"^[0-9][0-9][0-9][0-9][0-9]$", DefaultRegexOptions);
const string Message = "The {0} field is not a valid ZIP code.";
public ZipCodeAttribute()
: base(regex, Message, DataType.Url) {
}
}
public sealed class CreditCardAttribute : DataTypeAttribute {
const string Message = "The {0} field is not a valid credit card number.";
public CreditCardAttribute()
: base(DataType.Custom) {
this.ErrorMessage = Message;
}
public override bool IsValid(object value) {
if(value == null)
return true;
string stringValue = value as string;
if(stringValue == null)
return false;
stringValue = stringValue.Replace("-", "").Replace(" ", "");
int number = 0;
bool oddEvenFlag = false;
foreach(char ch in stringValue.Reverse()) {
if(ch < '0' || ch > '9')
return false;
int digitValue = (ch - '0') * (oddEvenFlag ? 2 : 1);
oddEvenFlag = !oddEvenFlag;
while(digitValue > 0) {
number += digitValue % 10;
digitValue = digitValue / 10;
}
}
return (number % 10) == 0;
}
}
}

View File

@@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Text;
namespace DevExpress.DevAV
{
public class DevAVByteImageConverter
{
public static Image FromByteArray(byte[] b)
{
if (b == null || b.Length == 0) return null;
Image i = null;
if (b.Length > 78)
{
if (b[0] == 0x15 && b[1] == 0x1c) //check signature
i = FromByteArray(b, 78);
}
if (i == null)
i = FromByteArray(b, 0);
return i;
}
protected static Image FromByteArray(byte[] b, int offset)
{
if (b == null || b.Length - offset <= 0) return null;
Image tempI = null;
System.IO.MemoryStream s = new System.IO.MemoryStream(b, offset, (int)b.Length - offset);
try
{
tempI = ImageFromStream(s);
}
catch { }
//s.Close();
return tempI;
}
static Image ImageFromStream(Stream stream)
{
if (Object.ReferenceEquals(stream, null))
return null;
//if (!IsWin7 || !IsUnmanagedCodeGranted)
// return Image.FromStream(stream);
//else
return Image.FromStream(stream, false, false);
}
static bool IsWin7 {
get {
Version version = Environment.OSVersion.Version;
return (version.Major == 6 && version.Minor >= 1) || version.Major > 6;
}
}
}
}

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Drawing;
using System.Linq;
using System.Runtime.Serialization;
namespace DevExpress.DevAV {
public class Crest : DatabaseObject {
public string CityName { get; set; }
public byte[] SmallImage { get; set; }
public byte[] LargeImage { get; set; }
public virtual ICollection<CustomerStore> CustomerStores { get; set; }
Image img;
public Image LargeImageEx {
get {
if (img == null)
if (LargeImage == null)
return null; //ResourceImageHelper.CreateImageFromResourcesEx("DevExpress.DevAV.Resources.Unknown-user.png", typeof(Employee).Assembly);
else
img = DevAVByteImageConverter.FromByteArray(LargeImage);
return img;
}
}
}
}

View File

@@ -0,0 +1,107 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Drawing;
namespace DevExpress.DevAV {
public enum CustomerStatus {
Active,
Suspended
}
public partial class Customer : DatabaseObject {
public Customer() {
Employees = new List<CustomerEmployee>();
Orders = new List<Order>();
_homeOffice = new Address();
_billingAddress = new Address();
}
[Required]
public string Name { get; set; }
Address _homeOffice;
[NotMapped]
public Address HomeOffice {
get {
AddressHelper.UpdateAddress(_homeOffice, HomeOffice_Line, HomeOffice_City, HomeOffice_State, HomeOffice_ZipCode, HomeOffice_Latitude, HomeOffice_Longitude);
return _homeOffice;
}
set {
AddressHelper.UpdateAddress(_homeOffice, value.Line, value.City, value.State, value.ZipCode, value.Latitude, value.Longitude);
HomeOffice_Line = _homeOffice.Line;
HomeOffice_City = _homeOffice.City;
HomeOffice_State = _homeOffice.State;
HomeOffice_ZipCode = _homeOffice.ZipCode;
HomeOffice_Latitude = _homeOffice.Latitude;
HomeOffice_Longitude = _homeOffice.Longitude;
}
}
Address _billingAddress;
[NotMapped]
public Address BillingAddress {
get {
AddressHelper.UpdateAddress(_billingAddress, BillingAddress_Line, BillingAddress_City, BillingAddress_State, BillingAddress_ZipCode, BillingAddress_Latitude, BillingAddress_Longitude);
return _billingAddress;
}
set {
AddressHelper.UpdateAddress(_billingAddress, value.Line, value.City, value.State, value.ZipCode, value.Latitude, value.Longitude);
BillingAddress_Line = _billingAddress.Line;
BillingAddress_City = _billingAddress.City;
BillingAddress_State = _billingAddress.State;
BillingAddress_ZipCode = _billingAddress.ZipCode;
BillingAddress_Latitude = _billingAddress.Latitude;
BillingAddress_Longitude = _billingAddress.Longitude;
}
}
#region EFCore
public string HomeOffice_Line { get; set; }
public string HomeOffice_City { get; set; }
public StateEnum HomeOffice_State { get; set; }
public string HomeOffice_ZipCode { get; set; }
public double HomeOffice_Latitude { get; set; }
public double HomeOffice_Longitude { get; set; }
public string BillingAddress_Line { get; set; }
public string BillingAddress_City { get; set; }
public StateEnum BillingAddress_State { get; set; }
public string BillingAddress_ZipCode { get; set; }
public double BillingAddress_Latitude { get; set; }
public double BillingAddress_Longitude { get; set; }
#endregion
public virtual List<CustomerEmployee> Employees { get; set; }
[Phone]
public string Phone { get; set; }
[Phone]
public string Fax { get; set; }
[Url]
public string Website { get; set; }
[DataType(DataType.Currency)]
public decimal AnnualRevenue { get; set; }
[Display(Name = "Total Stores")]
public int TotalStores { get; set; }
[Display(Name = "Total Employees")]
public int TotalEmployees { get; set; }
public CustomerStatus Status { get; set; }
[InverseProperty("Customer")]
public virtual List<Order> Orders { get; set; }
[InverseProperty("Customer")]
public virtual List<Quote> Quotes { get; set; }
[InverseProperty("Customer")]
public virtual List<CustomerStore> CustomerStores { get; set; }
public virtual string Profile { get; set; }
public byte[] Logo { get; set; }
Image img = null;
public Image Image {
get {
if(img == null)
img = CreateImage(Logo);
return img;
}
}
internal static Image CreateImage(byte[] data) {
if (data == null)
return null;// ResourceImageHelper.CreateImageFromResourcesEx("DevExpress.DevAV.Resources.Unknown-user.png", typeof(Employee).Assembly);
else
return DevAVByteImageConverter.FromByteArray(data);
}
}
}

View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Runtime.Serialization;
namespace DevExpress.DevAV {
public class CustomerCommunication : DatabaseObject {
public virtual Employee Employee { get; set; }
public long? EmployeeId { get; set; }
public virtual CustomerEmployee CustomerEmployee { get; set; }
public long? CustomerEmployeeId { get; set; }
public DateTime Date { get; set; }
public string Type { get; set; }
public string Purpose { get; set; }
}
}

View File

@@ -0,0 +1,53 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Drawing;
using System.Runtime.Serialization;
using DevExpress.DataAnnotations;
using System.Collections.Generic;
namespace DevExpress.DevAV {
public class CustomerEmployee : DatabaseObject {
[Required, Display(Name = "First Name")]
public string FirstName { get; set; }
[Required, Display(Name = "Last Name")]
public string LastName { get; set; }
[Display(Name = "Full Name")]
public string FullName { get; set; }
public PersonPrefix Prefix { get; set; }
[Required, Phone, Display(Name = "Mobile Phone")]
public string MobilePhone { get; set; }
[Required, EmailAddress]
public string Email { get; set; }
public virtual Picture Picture { get; set; }
public long? PictureId { get; set; }
public virtual Customer Customer { get; set; }
public long? CustomerId { get; set; }
public virtual CustomerStore CustomerStore { get; set; }
public long? CustomerStoreId { get; set; }
public string Position { get; set; }
public bool IsPurchaseAuthority { get; set; }
public virtual ICollection<CustomerCommunication> CustomerCommunications { get; set; }
public Address Address {
get { return (CustomerStore != null) ? CustomerStore.Address : null; }
set { }
}
public virtual ICollection<EmployeeTask> EmployeeTasks { get; set; }
Image _photo = null;
[NotMapped]
public Image Photo {
get {
if(_photo == null)
_photo = Picture.CreateImage();
return _photo;
}
set {
_photo = value;
Picture = PictureExtension.FromImage(value);
}
}
public override string ToString() {
return FullName;
}
}
}

View File

@@ -0,0 +1,89 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Drawing;
using System.Linq;
using System.ComponentModel.DataAnnotations;
namespace DevExpress.DevAV {
public class CustomerStore : DatabaseObject {
public CustomerStore() {
_address = new Address();
}
public virtual Customer Customer { get; set; }
public long? CustomerId { get; set; }
Address _address;
[NotMapped]
public Address Address {
get {
AddressHelper.UpdateAddress(_address, Address_Line, Address_City, Address_State, Address_ZipCode, Address_Latitude, Address_Longitude);
return _address;
}
set {
AddressHelper.UpdateAddress(_address, value.Line, value.City, value.State, value.ZipCode, value.Latitude, value.Longitude);
Address_Line = _address.Line;
Address_City = _address.City;
Address_State = _address.State;
Address_ZipCode = _address.ZipCode;
Address_Latitude = _address.Latitude;
Address_Longitude = _address.Longitude;
}
}
#region EFCore
public string Address_Line { get; set; }
public string Address_City { get; set; }
public StateEnum Address_State { get; set; }
public string Address_ZipCode { get; set; }
public double Address_Latitude { get; set; }
public double Address_Longitude { get; set; }
#endregion
public string Phone { get; set; }
public string Fax { get; set; }
public int TotalEmployees { get; set; }
public int SquereFootage { get; set; }
[DataType(DataType.Currency)]
public decimal AnnualSales { get; set; }
public virtual Crest Crest { get; set; }
public long? CrestId { get; set; }
public string Location { get; set; }
public string City { get { return Address == null ? "" : Address.City; } }
public StateEnum State { get { return Address == null ? StateEnum.CA : Address.State; } }
public virtual ICollection<CustomerEmployee> CustomerEmployees { get; set; }
public virtual ICollection<Order> Orders { get; set; }
public virtual ICollection<Quote> Quotes { get; set; }
public string CustomerName {
get { return (Customer != null) ? Customer.Name : null; }
}
public string AddressLine {
get { return (Address != null) ? Address.ToString() : null; }
}
public string AddressLines {
get { return (Address != null) ? string.Format("{0}\r\n{1} {2}", Address.Line, Address.State, Address.ZipCode) : null; }
}
public string CrestCity {
get { return (Crest != null) ? Crest.CityName : null; }
}
Image smallImg;
public Image CrestSmallImage {
get {
if(smallImg == null && Crest != null)
smallImg = CreateImage(Crest.SmallImage);
return smallImg;
}
}
Image largeImg;
public Image CrestLargeImage {
get {
if(largeImg == null && Crest != null)
largeImg = CreateImage(Crest.LargeImage);
return largeImg;
}
}
Image CreateImage(byte[] data) {
if (data == null)
return null;// ResourceImageHelper.CreateImageFromResourcesEx("DevExpress.DevAV.Resources.Unknown-user.png", typeof(Employee).Assembly);
else
return DevAVByteImageConverter.FromByteArray(data);
}
}
}

View File

@@ -0,0 +1,19 @@
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Runtime.Serialization;
using DevExpress.Common;
namespace DevExpress.DevAV {
public abstract class DatabaseObject : IDataErrorInfo {
[Key]
public long Id { get; set; }
#region IDataErrorInfo
string IDataErrorInfo.Error { get { return null; } }
string IDataErrorInfo.this[string columnName] {
get { return IDataErrorInfoHelper.GetErrorText(this, columnName); }
}
#endregion
}
}

View File

@@ -0,0 +1,130 @@
using Microsoft.EntityFrameworkCore;
using System;
namespace DevExpress.DevAV
{
public class DevAVDb : DbContext {
public DevAVDb(string connectionStringOrName) {
connectionString = connectionStringOrName;
}
string connectionString = @"Data Source=C:\Work\OutlookWpf\Data\devav.sqlite3";
public DevAVDb() : base()
{
}
protected override void OnConfiguring(DbContextOptionsBuilder optionbuilder)
{
optionbuilder.UseLazyLoadingProxies().UseSqlite(connectionString);
}
public DbSet<Customer> Customers { get; set; }
public DbSet<Employee> Employees { get; set; }
public DbSet<Product> Products { get; set; }
public DbSet<EmployeeTask> Tasks { get; set; }
public DbSet<Crest> Crests { get; set; }
public DbSet<CustomerCommunication> Communications { get; set; }
public DbSet<CustomerStore> CustomerStores { get; set; }
public DbSet<Order> Orders { get; set; }
public DbSet<OrderItem> OrderItems { get; set; }
public DbSet<Probation> Probations { get; set; }
public DbSet<ProductCatalog> ProductCatalogs { get; set; }
public DbSet<ProductImage> ProductImages { get; set; }
public DbSet<Quote> Quotes { get; set; }
public DbSet<QuoteItem> QuoteItems { get; set; }
public DbSet<State> States { get; set; }
public DbSet<CustomerEmployee> CustomerEmployees { get; set; }
public DbSet<Evaluation> Evaluations { get; set; }
public DbSet<Picture> Pictures { get; set; }
public DbSet<TaskAttachedFile> AttachedFiles { get; set; }
public DbSet<DatabaseVersion> Version { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder) {
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Employee>()
.HasOne(x => x.Picture)
.WithMany(x => x.Employees);
modelBuilder.Entity<Employee>()
.HasOne(x => x.ProbationReason)
.WithMany(x => x.Employees)
.HasForeignKey(x => x.ProbationReason_Id);
modelBuilder.Entity<Evaluation>()
.HasOne(x => x.CreatedBy)
.WithMany(x => x.EvaluationsCreatedBy);
modelBuilder.Entity<CustomerEmployee>()
.HasOne(x => x.CustomerStore)
.WithMany(x => x.CustomerEmployees);
modelBuilder.Entity<CustomerEmployee>()
.HasOne(x => x.Picture)
.WithMany(x => x.CustomerEmployees);
modelBuilder.Entity<CustomerStore>()
.HasOne(x => x.Crest)
.WithMany(x => x.CustomerStores);
modelBuilder.Entity<Order>()
.HasOne(x => x.Employee)
.WithMany(x => x.Orders);
modelBuilder.Entity<Order>()
.HasOne(x => x.Store)
.WithMany(x => x.Orders);
modelBuilder.Entity<Product>()
.HasOne(x => x.Engineer)
.WithMany(x => x.Products);
modelBuilder.Entity<Product>()
.HasOne(x => x.PrimaryImage)
.WithMany(x => x.Products);
modelBuilder.Entity<Product>()
.HasOne(x => x.Support)
.WithMany(x => x.SupportedProducts);
modelBuilder.Entity<ProductImage>()
.HasOne(x => x.Picture)
.WithMany(x => x.ProductImages);
modelBuilder.Entity<Quote>()
.HasOne(x => x.CustomerStore)
.WithMany(x => x.Quotes);
modelBuilder.Entity<Quote>()
.HasOne(x => x.Employee)
.WithMany(x => x.Quotes);
modelBuilder.Entity<QuoteItem>()
.HasOne(x => x.Product)
.WithMany(x => x.QuoteItems);
modelBuilder.Entity<CustomerCommunication>()
.HasOne(x => x.CustomerEmployee)
.WithMany(x => x.CustomerCommunications);
modelBuilder.Entity<CustomerCommunication>()
.HasOne(x => x.Employee)
.WithMany(x => x.Employees);
modelBuilder.Entity<Employee>()
.Ignore(x => x.AssignedEmployeeTasks);
modelBuilder.Entity<EmployeeTask>()
.Ignore(x => x.AssignedEmployees);
modelBuilder.Entity<Employee>()
.Ignore(x => x.AssignedTasks);
modelBuilder.Entity<Employee>()
.Ignore(x => x.OwnedTasks);
modelBuilder.Entity<Employee>()
.Ignore(x => x.Employees);
}
}
public class DatabaseVersion : DatabaseObject {
public DateTime Date { get; set; }
}
}

View File

@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.0.0-preview.18572.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.0.0-preview.18572.1" />
<PackageReference Include="System.Drawing.Common" Version="4.5.1" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28315.86
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DevExpress.DevAV", "DevExpress.DevAV.csproj", "{76AE4911-338A-43CA-81B9-C043FBB3B31E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{76AE4911-338A-43CA-81B9-C043FBB3B31E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{76AE4911-338A-43CA-81B9-C043FBB3B31E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{76AE4911-338A-43CA-81B9-C043FBB3B31E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{76AE4911-338A-43CA-81B9-C043FBB3B31E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3FA2356F-A04A-43E2-9503-EFCD1578EB97}
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,163 @@
using DevExpress.DataAnnotations;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Drawing;
using System.Runtime.Serialization;
namespace DevExpress.DevAV {
public enum EmployeeStatus {
[Display(Name = "Salaried")]
Salaried,
[Display(Name = "Commission")]
Commission,
[Display(Name = "Contract")]
Contract,
[Display(Name = "Terminated")]
Terminated,
[Display(Name = "On Leave")]
OnLeave
}
public enum EmployeeDepartment {
[Display(Name = "Sales")]
Sales = 1,
[Display(Name = "Support")]
Support,
[Display(Name = "Shipping")]
Shipping,
[Display(Name = "Engineering")]
Engineering,
[Display(Name = "Human Resources")]
HumanResources,
[Display(Name = "Management")]
Management,
[Display(Name = "IT")]
IT
}
public enum PersonPrefix {
Dr,
Mr,
Ms,
Miss,
Mrs
}
public partial class Employee : DatabaseObject {
public Employee() {
AssignedTasks = new List<EmployeeTask>();
OwnedTasks = new List<EmployeeTask>();
_address = new Address();
AssignedEmployeeTasks = new List<EmployeeTask>();
}
[InverseProperty("AssignedEmployees")]
public virtual List<EmployeeTask> AssignedEmployeeTasks { get; set; }
public EmployeeDepartment Department { get; set; }
[Required]
public string Title { get; set; }
public EmployeeStatus Status { get; set; }
[Display(Name = "Hire Date")]
public DateTime? HireDate { get; set; }
[InverseProperty("AssignedEmployee")]
public virtual List<EmployeeTask> AssignedTasks { get; set; }
[InverseProperty("Owner")]
public virtual List<EmployeeTask> OwnedTasks { get; set; }
[InverseProperty("Employee")]
public virtual List<Evaluation> Evaluations { get; set; }
public string PersonalProfile { get; set; }
public long? ProbationReason_Id { get; set; }
public virtual Probation ProbationReason { get; set; }
[Required, Display(Name = "First Name")]
public string FirstName { get; set; }
[Required, Display(Name = "Last Name")]
public string LastName { get; set; }
[Display(Name = "Full Name")]
public string FullName { get; set; }
public PersonPrefix Prefix { get; set; }
[Phone, Display(Name = "Home Phone")]
public string HomePhone { get; set; }
[Required, Phone, Display(Name = "Mobile Phone")]
public string MobilePhone { get; set; }
[Required, EmailAddress]
public string Email { get; set; }
public string Skype { get; set; }
[Display(Name = "Birth Date")]
public DateTime? BirthDate { get; set; }
public virtual Picture Picture { get; set; }
public long? PictureId { get; set; }
Address _address;
[NotMapped]
public Address Address { get {
AddressHelper.UpdateAddress(_address, Address_Line, Address_City, Address_State, Address_ZipCode, Address_Latitude, Address_Longitude);
return _address;
}
set {
AddressHelper.UpdateAddress(_address, value.Line, value.City, value.State, value.ZipCode, value.Latitude, value.Longitude);
Address_Line = _address.Line;
Address_City = _address.City;
Address_State = _address.State;
Address_ZipCode = _address.ZipCode;
Address_Latitude = _address.Latitude;
Address_Longitude = _address.Longitude;
}
}
#region EFCore
public string Address_Line { get; set; }
public string Address_City { get; set; }
public StateEnum Address_State { get; set; }
public string Address_ZipCode { get; set; }
public double Address_Latitude { get; set; }
public double Address_Longitude { get; set; }
#endregion
Image _photo = null;
[NotMapped]
public Image Photo {
get {
if(_photo == null)
_photo = Picture.CreateImage();
return _photo;
}
set {
if(_photo == value) return;
if(_photo != null)
_photo.Dispose();
_photo = value;
Picture = PictureExtension.FromImage(value);
}
}
bool unsetFullName = false;
public virtual ICollection<Evaluation> EvaluationsCreatedBy { get; set; }
public virtual ICollection<Order> Orders { get; set; }
public virtual ICollection<Product> Products { get; set; }
public virtual ICollection<Product> SupportedProducts { get; set; }
public virtual ICollection<Quote> Quotes { get; set; }
public virtual ICollection<CustomerCommunication> Employees { get; set; }
[NotMapped, Display(Name = "Full Name")]
public string FullNameBindable {
get {
return string.IsNullOrEmpty(FullName) || unsetFullName ? GetFullName() : FullName;
}
set {
unsetFullName = string.IsNullOrEmpty(value);
if(unsetFullName)
FullName = GetFullName();
else
FullName = value;
}
}
public void ResetBindable() {
if(_photo != null)
_photo.Dispose();
_photo = null;
unsetFullName = false;
}
string GetFullName() {
return string.Format("{0} {1}", FirstName, LastName);
}
public override string ToString() {
return FullName;
}
}
}

View File

@@ -0,0 +1 @@
ABCDEFGHIJKLMNOPQRSTUVWXYZ

View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Runtime.Serialization;
namespace DevExpress.DevAV {
public enum EvaluationRating {
Unset,
Good,
Average,
Poor
}
public partial class Evaluation : DatabaseObject {
public virtual Employee CreatedBy { get; set; }
public long? CreatedById { get; set; }
public DateTime CreatedOn { get; set; }
public virtual Employee Employee { get; set; }
public long? EmployeeId { get; set; }
public string Subject { get; set; }
public string Details { get; set; }
public virtual EvaluationRating Rating { get; set; }
}
}

View File

@@ -0,0 +1,98 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DevExpress.DevAV {
public enum OrderShipMethod {
[Display(Name = "Ground")]
Ground,
[Display(Name = "Air")]
Air
}
public enum ShipmentCourier {
None,
[Display(Name = "FedEx")]
FedEx,
[Display(Name = "UPS")]
UPS,
[Display(Name = "DHL")]
DHL
}
public enum ShipmentStatus {
[Display(Name = "Awaiting")]
Awaiting,
[Display(Name = "Transit")]
Transit,
[Display(Name = "Received")]
Received
}
public enum PaymentStatus {
[Display(Name = "Unpaid")]
Unpaid,
[Display(Name = "Paid in full")]
PaidInFull,
[Display(Name = "Refund in full")]
RefundInFull,
[Display(Name = "")]
Other
}
//
public class Order : DatabaseObject {
public Order() {
OrderItems = new List<OrderItem>();
}
public string InvoiceNumber { get; set; }
public virtual Customer Customer { get; set; }
public long? CustomerId { get; set; }
public virtual CustomerStore Store { get; set; }
public long? StoreId { get; set; }
public string PONumber { get; set; }
public virtual Employee Employee { get; set; }
public long? EmployeeId { get; set; }
public DateTime OrderDate { get; set; }
[DataType(DataType.Currency)]
public decimal SaleAmount { get; set; }
[DataType(DataType.Currency)]
public decimal ShippingAmount { get; set; }
[DataType(DataType.Currency)]
public decimal TotalAmount { get; set; }
public DateTime? ShipDate { get; set; }
public OrderShipMethod ShipMethod { get; set; }
public string OrderTerms { get; set; }
public virtual List<OrderItem> OrderItems { get; set; }
public ShipmentCourier ShipmentCourier { get; set; }
public string ShipmentCourierId { get; set; }
public ShipmentStatus ShipmentStatus { get; set; }
public string Comments { get; set; }
// Payment/Refund
[DataType(DataType.Currency)]
public decimal RefundTotal { get; set; }
[DataType(DataType.Currency)]
public decimal PaymentTotal { get; set; }
[NotMapped]
public PaymentStatus PaymentStatus {
get {
if(PaymentTotal == decimal.Zero && RefundTotal == decimal.Zero)
return DevAV.PaymentStatus.Unpaid;
if(RefundTotal == TotalAmount)
return DevAV.PaymentStatus.RefundInFull;
if(PaymentTotal == TotalAmount)
return DevAV.PaymentStatus.PaidInFull;
return DevAV.PaymentStatus.Other;
}
}
[NotMapped]
public double ActualWeight {
get {
var weight = 0.0;
if(OrderItems != null)
foreach(var item in OrderItems)
if(item.Product != null)
weight += item.Product.Weight * item.ProductUnits;
return weight;
}
}
}
}

View File

@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Runtime.Serialization;
namespace DevExpress.DevAV {
public class OrderItem : DatabaseObject {
public virtual Order Order { get; set; }
public long? OrderId { get; set; }
public virtual Product Product { get; set; }
public long? ProductId { get; set; }
public int ProductUnits { get; set; }
[DataType(DataType.Currency)]
public decimal ProductPrice { get; set; }
[DataType(DataType.Currency)]
public decimal Discount { get; set; }
[DataType(DataType.Currency)]
public decimal Total { get; set; }
}
}

View File

@@ -0,0 +1 @@


View File

@@ -0,0 +1,33 @@
using System.Drawing;
using System.Collections.Generic;
namespace DevExpress.DevAV {
public class Picture : DatabaseObject {
public byte[] Data { get; set; }
public virtual ICollection<Employee> Employees { get; set; }
public virtual ICollection<CustomerEmployee> CustomerEmployees { get; set; }
public virtual ICollection<Product> Products { get; set; }
public virtual ICollection<ProductImage> ProductImages { get; set; }
}
static class PictureExtension {
public const string DefaultPic = DefaultUserPic;
public const string DefaultUserPic = "DevExpress.DevAV.Resources.Unknown-user.png";
internal static Image CreateImage(this Picture picture, string defaultImage = null) {
if (picture == null)
{
return null;
//if (string.IsNullOrEmpty(defaultImage))
// defaultImage = DefaultPic;
//return ResourceImageHelper.CreateImageFromResourcesEx(defaultImage, typeof(Picture).Assembly);
}
else return DevAVByteImageConverter.FromByteArray(picture.Data);
}
internal static Picture FromImage(Image image) {
return null;
//return (image == null) ? null : new Picture()
//{
// Data = DevAVByteImageConverter.ToByteArray(image, image.RawFormat)
//};
}
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Runtime.Serialization;
namespace DevExpress.DevAV {
public class Probation : DatabaseObject {
public string Reason { get; set; }
public virtual ICollection<Employee> Employees { get; set; }
}
}

View File

@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Drawing;
using System.IO;
namespace DevExpress.DevAV {
public enum ProductCategory {
[Display(Name = "Automation")]
Automation,
[Display(Name = "Monitors")]
Monitors,
[Display(Name = "Projectors")]
Projectors,
[Display(Name = "Televisions")]
Televisions,
[Display(Name = "Video Players")]
VideoPlayers,
}
public class Product : DatabaseObject {
public string Name { get; set; }
public string Description { get; set; }
public DateTime ProductionStart { get; set; }
public bool Available { get; set; }
public byte[] Image { get; set; }
public virtual Employee Support { get; set; }
public long? SupportId { get; set; }
public virtual Employee Engineer { get; set; }
public long? EngineerId { get; set; }
public int? CurrentInventory { get; set; }
public int Backorder { get; set; }
public int Manufacturing { get; set; }
public byte[] Barcode { get; set; }
public virtual Picture PrimaryImage { get; set; }
public long? PrimaryImageId { get; set; }
[DataType(DataType.Currency)]
public decimal Cost { get; set; }
[DataType(DataType.Currency)]
public decimal SalePrice { get; set; }
[DataType(DataType.Currency)]
public decimal RetailPrice { get; set; }
public double Weight { get; set; }
public double ConsumerRating { get; set; }
public ProductCategory Category { get; set; }
[InverseProperty("Product")]
public virtual List<ProductCatalog> Catalog { get; set; }
[InverseProperty("Product")]
public virtual List<OrderItem> OrderItems { get; set; }
public virtual List<ProductImage> Images { get; set; }
public virtual ICollection<QuoteItem> QuoteItems { get; set; }
public Stream Brochure {
get {
if(Catalog != null && Catalog.Count > 0)
return Catalog[0].PdfStream;
return null;
}
}
Image img;
public Image ProductImage {
get {
if(img == null && PrimaryImage != null)
img = CreateImage(PrimaryImage.Data);
return img;
}
}
Image CreateImage(byte[] data) {
if (data == null)
return null;// ResourceImageHelper.CreateImageFromResourcesEx("DevExpress.DevAV.Resources.Unknown-user.png", typeof(Employee).Assembly);
else
return DevAVByteImageConverter.FromByteArray(data);
}
}
}

View File

@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.IO;
using System.Linq;
using System.Runtime.Serialization;
namespace DevExpress.DevAV {
public class ProductCatalog : DatabaseObject {
public virtual Product Product { get; set; }
public long? ProductId { get; set; }
public byte[] PDF { get; set; }
Stream _pdfStream;
public Stream PdfStream {
get {
if (_pdfStream == null)
_pdfStream = new MemoryStream(PDF);
return _pdfStream;
}
}
}
}

View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Runtime.Serialization;
namespace DevExpress.DevAV {
public class ProductImage : DatabaseObject {
public virtual Picture Picture { get; set; }
public long? PictureId { get; set; }
public virtual Product Product { get; set; }
public long? ProductId { get; set; }
}
}

View File

@@ -0,0 +1,583 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Drawing;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace DevExpress.DevAV {
public class SaleSummaryInfo {
public DateTime OrderDate { get; set; }
public string InvoiceNumber { get; set; }
public int ProductUnits { get; set; }
public decimal ProductPrice { get; set; }
public decimal Discount { get; set; }
public decimal Total { get; set; }
public ProductCategory ProductCategory { get; set; }
public long StoreId { get; set; }
public string StoreCity { get; set; }
public string StoreCustomerName { get; set; }
}
public class SaleAnalisysInfo {
public DateTime OrderDate { get; set; }
public decimal ProductCost { get; set; }
public int ProductUnits { get; set; }
public decimal Total { get; set; }
}
public class CustomerSaleDetailOrderItemInfo {
public long OrderId { get; set; }
public DateTime OrderDate { get; set; }
public string InvoiceNumber { get; set; }
public ProductCategory ProductCategory { get; set; }
public string PONumber { get; set; }
public long StoreId { get; set; }
public string StoreCity { get; set; }
public string EmployeeFullName { get; set; }
public decimal ShippingAmount { get; set; }
public decimal TotalAmount { get; set; }
public string CustomerName { get; set; }
public string CustomerPhone { get; set; }
public string CustomerFax { get; set; }
public byte[] CustomerLogo { get; set; }
Image img = null;
public Image CustomerImage { get { return img ?? (img = Customer.CreateImage(CustomerLogo)); } }
public decimal Discount { get; set; }
public int ProductUnits { get; set; }
public decimal ProductPrice { get; set; }
public decimal Total { get; set; }
public string CustomerHomeOfficeLine { get; set; }
public string CustomerHomeOfficeCity { get; set; }
public StateEnum CustomerHomeOfficeState { get; set; }
public string CustomerHomeOfficeZipCode { get; set; }
public string CustomerHomeOfficeCityLine { get { return Address.GetCityLine(CustomerHomeOfficeCity, CustomerHomeOfficeState, CustomerHomeOfficeZipCode); } }
public string CustomerBillingAddressLine { get; set; }
public string CustomerBillingAddressCity { get; set; }
public StateEnum CustomerBillingAddressState { get; set; }
public string CustomerBillingAddressZipCode { get; set; }
public string CustomerBillingAddressCityLine { get { return Address.GetCityLine(CustomerBillingAddressCity, CustomerBillingAddressState, CustomerBillingAddressZipCode); } }
}
public class CustomerSaleDetailOrderInfo {
public CustomerSaleDetailOrderItemInfo[] OrderItems { get; set; }
public long OrderId { get; set; }
public ProductCategory ProductCategory { get; set; }
public DateTime OrderDate { get; set; }
public string InvoiceNumber { get; set; }
public string PONumber { get; set; }
public long StoreId { get; set; }
public string StoreCity { get; set; }
public string EmployeeFullName { get; set; }
public string CustomerName { get; set; }
public string CustomerPhone { get; set; }
public string CustomerFax { get; set; }
public Image CustomerImage { get; set; }
public decimal ShippingAmount { get; set; }
public decimal TotalAmount { get; set; }
public string CustomerHomeOfficeLine { get; set; }
public string CustomerHomeOfficeCityLine { get; set; }
public string CustomerBillingAddressLine { get; set; }
public string CustomerBillingAddressCityLine { get; set; }
}
public class QuoteInfo {
public long Id { get; set; }
public StateEnum State { get; set; }
public string City { get; set; }
public DateTime Date { get; set; }
public decimal Total { get; set; }
public double Opportunity { get; set; }
public decimal MoneyOpportunity { get { return Total * (decimal)Opportunity; } }
public decimal Percentage { get { return 100M * (decimal)Opportunity; } }
}
public class OrderInfo {
public string InvoiceNumber { get; set; }
public DateTime OrderDate { get; set; }
public string Company { get; set; }
public string Store { get; set; }
public decimal TotalAmount { get; set; }
}
public class SalesProductInfo {
public string Name { get; set; }
public decimal Value { get; set; }
}
public class SalesInfo {
public string Caption { get; set; }
public List<SalesProductInfo> ListProductInfo { get; set; }
public DateTime time { get; set; }
public SalesInfo() {
ListProductInfo = new List<SalesProductInfo>();
}
}
public class ProductInfoWithSales {
public long Id { get; set; }
public string Name { get; set; }
public decimal Cost { get; set; }
public decimal SalePrice { get; set; }
public decimal RetailPrice { get; set; }
public int? CurrentInventory { get; set; }
public int Backorder { get; set; }
public IEnumerable<double> MonthlySales { get; set; }
public decimal? TotalSales { get; set; }
}
public class CustomerInfoWithSales {
public long Id { get; set; }
public string Name { get; set; }
public string HomeOfficeLine { get; set; }
public string HomeOfficeCity { get; set; }
public StateEnum HomeOfficeState { get; set; }
public string HomeOfficeZipCode { get; set; }
public string Phone { get; set; }
public string Fax { get; set; }
public decimal? TotalSales { get; set; }
Lazy<IEnumerable<CustomerStore>> customerStores;
public IEnumerable<CustomerStore> CustomerStores { get { return customerStores.Value; } }
Lazy<IEnumerable<CustomerEmployee>> customerEmployees;
public IEnumerable<CustomerEmployee> Employees { get { return customerEmployees.Value; } }
public IEnumerable<decimal> MonthlySales { get; private set; }
public void Init(Func<IEnumerable<CustomerStore>> getStores, Func<IEnumerable<CustomerEmployee>> getEmployees, IEnumerable<decimal> monthlySales) {
this.customerStores = new Lazy<IEnumerable<CustomerStore>>(getStores);
this.customerEmployees = new Lazy<IEnumerable<CustomerEmployee>>(getEmployees);
this.MonthlySales = monthlySales;
}
}
public class MapItem {
public Address Address { get; set; }
public Customer Customer { get; set; }
public Product Product { get; set; }
public decimal Total { get; set; }
public string City { get { return Address.City; } }
public double Latitude { get { return Address.Latitude; } }
public double Longitude { get { return Address.Longitude; } }
public string CustomerName { get { return Customer.Name; } }
public string ProductName { get { return Product.Name; } }
public ProductCategory ProductCategory { get { return Product.Category; } }
}
public class QuoteMapItem {
public Address Address { get; set; }
public Stage Stage { get; set; }
public DateTime Date { get; set; }
public string City { get { return Address.City; } }
public double Latitude { get { return Address.Latitude; } }
public double Longitude { get { return Address.Longitude; } }
public string Name { get { return Enum.GetName(typeof(Stage), Stage); } }
public int Index { get { return (int)Stage; } }
public decimal Value { get; set; }
}
public enum Stage {
High,
Medium,
Low,
Unlikely,
Summary
}
public class SalesSummaryItem {
public ProductCategory Category { get; set; }
public decimal Sales { get; set; }
}
public class QuoteSummaryItem {
public string StageName { get; set; }
public decimal Summary { get; set; }
}
public class CostAverageItem {
public ProductCategory Category { get; set; }
public decimal Cost { get; set; }
}
public static class QueriesHelper {
public static IQueryable<Order> ActualOrders(this IQueryable<Order> orders) {
var actualDateTime = DateTime.Now.AddHours(0.5);
return orders.Where(x => x.OrderDate <= actualDateTime);
}
public static IQueryable<Quote> ActualQuotes(this IQueryable<Quote> quotes) {
var actualDateTime = DateTime.Now.AddHours(0.5);
return quotes.Where(x => x.Date <= actualDateTime);
}
public static IQueryable<QuoteInfo> GetQuoteInfo(IQueryable<Quote> quotes) {
return quotes.ActualQuotes().Select(x => new QuoteInfo {
Id = x.Id,
State = x.CustomerStore.Address.State,
City = x.CustomerStore.Address.City,
Date = x.Date,
Total = x.Total,
Opportunity = x.Opportunity,
});
}
public static decimal CustomSum<T>(this IEnumerable<T> query, Expression<Func<T, decimal>> selector) {
return query.AsQueryable<T>().Select(selector).DefaultIfEmpty(0).Sum();
}
public static IEnumerable<CustomerSaleDetailOrderInfo> GetCustomerSaleDetails(long customerId, IQueryable<OrderItem> orderItems) {
List<CustomerSaleDetailOrderItemInfo> detailInfo = GetCustomerSaleOrderItemDetails(customerId, orderItems);
return detailInfo
.GroupBy(x => x.OrderId)
.Select(x => new CustomerSaleDetailOrderInfo() {
OrderId = x.Key,
OrderItems = x.ToArray(),
ProductCategory = x.First().ProductCategory,
OrderDate = x.First().OrderDate,
InvoiceNumber = x.First().InvoiceNumber,
PONumber = x.First().PONumber,
StoreCity = x.First().StoreCity,
StoreId = x.First().StoreId,
EmployeeFullName = x.First().EmployeeFullName,
CustomerName = x.First().CustomerName,
CustomerPhone = x.First().CustomerPhone,
CustomerFax = x.First().CustomerFax,
CustomerImage = x.First().CustomerImage,
ShippingAmount = x.First().ShippingAmount,
TotalAmount = x.First().TotalAmount,
CustomerHomeOfficeLine = x.First().CustomerHomeOfficeLine,
CustomerHomeOfficeCityLine = x.First().CustomerHomeOfficeCityLine,
CustomerBillingAddressLine = x.First().CustomerBillingAddressLine,
CustomerBillingAddressCityLine = x.First().CustomerBillingAddressCityLine
}).ToArray();
}
public static List<CustomerSaleDetailOrderItemInfo> GetCustomerSaleOrderItemDetails(long customerId, IQueryable<OrderItem> orderItems) {
return orderItems
.Where(x => x.Order.CustomerId == customerId)
.Select(x => new CustomerSaleDetailOrderItemInfo() {
ProductCategory = x.Product.Category,
OrderDate = x.Order.OrderDate,
OrderId = x.OrderId.Value,
InvoiceNumber = x.Order.InvoiceNumber,
PONumber = x.Order.PONumber,
StoreId = x.Order.Store.Id,
StoreCity = x.Order.Store.Address.City,
EmployeeFullName = x.Order.Employee.FullName,
CustomerName = x.Order.Customer.Name,
CustomerPhone = x.Order.Customer.Phone,
CustomerFax = x.Order.Customer.Fax,
CustomerLogo = x.Order.Customer.Logo,
CustomerHomeOfficeLine = x.Order.Customer.HomeOffice.Line,
CustomerHomeOfficeCity = x.Order.Customer.HomeOffice.City,
CustomerHomeOfficeZipCode = x.Order.Customer.HomeOffice.ZipCode,
CustomerHomeOfficeState = x.Order.Customer.HomeOffice.State,
CustomerBillingAddressLine = x.Order.Customer.BillingAddress.Line,
CustomerBillingAddressCity = x.Order.Customer.BillingAddress.City,
CustomerBillingAddressZipCode = x.Order.Customer.BillingAddress.ZipCode,
CustomerBillingAddressState = x.Order.Customer.BillingAddress.State,
Total = x.Total,
TotalAmount = x.Order.TotalAmount,
Discount = x.Discount,
ProductUnits = x.ProductUnits,
ProductPrice = x.ProductPrice,
ShippingAmount = x.Order.ShippingAmount,
}).ToList();
}
public static IEnumerable<SaleSummaryInfo> GetSaleSummaries(IQueryable<OrderItem> orderItems) {
return orderItems.Select(x => new SaleSummaryInfo() {
OrderDate = x.Order.OrderDate,
InvoiceNumber = x.Order.InvoiceNumber,
ProductUnits = x.ProductUnits,
ProductPrice = x.ProductPrice,
Discount = x.Discount,
Total = x.Total,
ProductCategory = x.Product.Category,
StoreId = x.Order.Store.Id,
StoreCity = x.Order.Store.Address.City,
StoreCustomerName = x.Order.Store.Customer.Name,
}).ToList();
}
public static IEnumerable<SaleAnalisysInfo> GetSaleAnalysis(IQueryable<OrderItem> orderItems) {
return orderItems.Select(x => new SaleAnalisysInfo() {
OrderDate = x.Order.OrderDate,
ProductCost = x.Product.Cost,
ProductUnits = x.ProductUnits,
Total = x.Total,
}).ToList();
}
public static IEnumerable<string> GetStateNames(IQueryable<State> queryableStates, IEnumerable<StateEnum> states) {
return
from ss in queryableStates
join s in states on ss.ShortName equals s
select ss.LongName;
}
public static IList<OrderInfo> GetOrderInfo(IQueryable<Order> orders) {
return orders.ActualOrders().Select(x => new OrderInfo {
InvoiceNumber = x.InvoiceNumber,
OrderDate = x.OrderDate,
Company = x.Customer.Name,
//Store = x.Customer.HomeOffice.City,
TotalAmount = x.TotalAmount,
}).ToList();
}
public static List<Order> GetAverageOrders(IQueryable<Order> orders, int NumberOfPoints) {
DateTime startDate = orders.Min(q => q.OrderDate);
DateTime endDate = orders.Max(q => q.OrderDate);
int daysPerGroup = Math.Max(1, (endDate - startDate).Days / NumberOfPoints);
var constDate = new DateTime(1990, 1, 1);
List<decimal> groups = orders
.Select(x => new { OrderDate = x.OrderDate, TotalAmount = x.TotalAmount })
.ToList()
.GroupBy(q => (q.OrderDate - constDate).Days / daysPerGroup)
.Select(g => g.Average(q => q.TotalAmount))
.ToList();
DateTime currentDate = startDate;
List<Order> averageOrders = new List<Order>();
foreach(decimal total in groups) {
averageOrders.Add(new Order { OrderDate = currentDate, TotalAmount = total });
currentDate = currentDate.AddDays(daysPerGroup);
}
return averageOrders;
}
public static List<Quote> GetAverageQuotes(IQueryable<Quote> quotes, int NumberOfPoints) {
var startDate = quotes.Min(q => q.Date);
var endDate = quotes.Max(q => q.Date);
int daysPerGroup = Math.Max(1, (endDate - startDate).Days / NumberOfPoints);
var constDate = new DateTime(1990, 1, 1);
List<decimal> groups = quotes
.Select(x => new { Date = x.Date, Total = x.Total })
.ToList()
.GroupBy(q => (q.Date - constDate).Days / daysPerGroup)
.Select(g => g.Average(q => q.Total))
.ToList();
DateTime currentDate = startDate;
List<Quote> averageQuotes = new List<Quote>();
foreach(decimal total in groups) {
averageQuotes.Add(new Quote { Date = currentDate, Total = total });
currentDate = currentDate.AddDays(daysPerGroup);
}
return averageQuotes;
}
public static List<SalesInfo> GetSales(IQueryable<OrderItem> orderItems) {
var result = orderItems
.Select(x => new { OrderDate = x.Order.OrderDate, ProductCategory = x.Product.Category, Total = x.Total })
.OrderBy(x => x.OrderDate)
.ToList()
.GroupBy(x => x.OrderDate.Year)
.Select(x => new SalesInfo() {
time = new DateTime(x.Key, 1, 1),
Caption = "Sales (FY" + x.Key + ")",
ListProductInfo = x
.GroupBy(y => y.ProductCategory)
.Select(y => new SalesProductInfo() {
Name = y.Key.ToString(),
Value = y.Sum(z => z.Total)
})
.ToList()
}).ToList();
return result;
}
public static IQueryable<ProductInfoWithSales> GetProductInfoWithSales(IQueryable<Product> products) {
return products.Select(x => new ProductInfoWithSales {
Id = x.Id,
Name = x.Name,
Cost = x.Cost,
RetailPrice = x.RetailPrice,
SalePrice = x.SalePrice,
CurrentInventory = x.CurrentInventory,
Backorder = x.Backorder,
TotalSales = x.OrderItems.Sum(orderItem => orderItem.Total)
});
}
public static void UpdateMonthlySales(IQueryable<OrderItem> orderItems, IEnumerable<ProductInfoWithSales> products) {
foreach(var productInfo in products) {
var sales = orderItems
.Where(x => x.Product.Id == productInfo.Id)
.GroupBy(x => x.Order.OrderDate.Month)
.Select(x => new { Month = x.Key, Sum = (double)x.Sum(i => i.Total) }).ToArray();
double[] monthlySales = new double[12];
for(int i = 0; i < sales.Length; i++)
monthlySales[sales[i].Month - 1] = sales[i].Sum;
productInfo.MonthlySales = monthlySales;
}
}
public static IQueryable<CustomerInfoWithSales> GetCustomerInfoWithSales(IQueryable<Customer> customers) {
return customers.Select(x => new CustomerInfoWithSales {
Id = x.Id,
Name = x.Name,
HomeOfficeLine = x.HomeOffice.Line,
HomeOfficeCity = x.HomeOffice.City,
HomeOfficeState = x.HomeOffice.State,
HomeOfficeZipCode = x.HomeOffice.ZipCode,
Phone = x.Phone,
Fax = x.Fax,
TotalSales = x.Orders.Sum(orderItem => orderItem.TotalAmount)
});
}
public static void UpdateCustomerInfoWithSales(IEnumerable<CustomerInfoWithSales> entities, IQueryable<CustomerStore> stores, IQueryable<CustomerEmployee> employees, IQueryable<Order> orders) {
foreach(var item in entities) {
item.Init(
() => stores.Where(x => x.CustomerId == item.Id).ToArray(),
() => employees.Where(x => x.CustomerId == item.Id).ToArray(),
orders.Where(x => x.CustomerId == item.Id).GroupBy(o => o.OrderDate.Month).Select(g => g.Sum(i => i.TotalAmount)).ToArray()
);
}
}
public static IQueryable<Order> GetOrdersForPeriod(IQueryable<Order> orders, Period period, DateTime dateTime = new DateTime()) {
switch(period) {
case Period.ThisYear:
return orders.Where(o => o.OrderDate.Year == DateTime.Now.Year);
case Period.ThisMonth:
return orders.Where(o => o.OrderDate.Month == DateTime.Now.Month && o.OrderDate.Year == DateTime.Now.Year);
case Period.FixedDate:
return orders.Where(o => o.OrderDate.Month == dateTime.Month && o.OrderDate.Year == dateTime.Year
&& o.OrderDate.Day == dateTime.Day);
}
return orders;
}
public static IQueryable<Order> GetCustomerOrdersForPeriod(IQueryable<Order> orders, Period period, long customerId) {
return GetOrdersForPeriod(orders.Where(o => o.CustomerId == customerId), period);
}
public static IQueryable<OrderItem> GetOrderItemsForPeriod(IQueryable<OrderItem> orderItems, Period period, DateTime dateTime = new DateTime()) {
return orderItems.Where(GetOrderItemsForPeriodFilter(period, dateTime));
}
public static Expression<Func<OrderItem, bool>> GetOrderItemsForPeriodFilter(Period period, DateTime dateTime = new DateTime()) {
switch(period) {
case Period.ThisYear:
return x => x.Order.OrderDate.Year == DateTime.Now.Year;
case Period.ThisMonth:
return x => x.Order.OrderDate.Month == DateTime.Now.Month && x.Order.OrderDate.Year == DateTime.Now.Year;
case Period.FixedDate:
return x => x.Order.OrderDate.Month == dateTime.Month && x.Order.OrderDate.Year == dateTime.Year
&& x.Order.OrderDate.Day == dateTime.Day;
}
return x => true;
}
public static IEnumerable<CustomerStore> GetSalesStoresForPeriod(IQueryable<Order> orders, Period period = Period.Lifetime) {
return QueriesHelper.GetOrdersForPeriod(orders, period).GroupBy(o => o.Store).Select(g => g.Key).Distinct();
}
public static IEnumerable<MapItem> GetSaleMapItemsByCity(IQueryable<OrderItem> orderItems, long productId, string city, Period period = Period.Lifetime) {
return GetSaleMapItems(orderItems.Where(x => x.Order.Store.Address.City == city), productId, period);
}
public static IEnumerable<MapItem> GetSaleMapItems(IQueryable<OrderItem> orderItems, long productId, Period period = Period.Lifetime) {
return GetSaleMapItemsCore(orderItems.Where(QueriesHelper.GetOrderItemsForPeriodFilter(period)).Where(x => x.ProductId == productId));
}
public static IEnumerable<MapItem> GetSaleMapItemsByCustomer(IQueryable<OrderItem> orderItems, long customerId, Period period = Period.Lifetime) {
return GetSaleMapItemsCore(orderItems.Where(x => x.Order.CustomerId == customerId).Where(QueriesHelper.GetOrderItemsForPeriodFilter(period)));
}
public static IEnumerable<MapItem> GetSaleMapItemsByCustomerAndCity(IQueryable<OrderItem> orderItems, long customerId, string city, Period period = Period.Lifetime) {
return GetSaleMapItemsByCustomer(orderItems.Where(x => x.Order.Store.Address.City == city), customerId, period);
}
static IEnumerable<MapItem> GetSaleMapItemsCore(IQueryable<OrderItem> orderItems) {
return orderItems
.Select(x => new MapItem {
Customer = x.Order.Customer,
Product = x.Product,
Total = x.Total,
Address = x.Order.Store.Address
});
}
public static IEnumerable<SalesSummaryItem> GetSalesSummaryItems(IQueryable<OrderItem> orderItems, Period period, DateTime dateTime = new DateTime()) {
return GetOrderItemsForPeriod(orderItems, period, dateTime)
.GroupBy(oi => oi.Product.Category)
.Select(g => new SalesSummaryItem { Category = g.Key, Sales = g.Sum(oi => oi.Total) })
.ToList();
}
public static IEnumerable<CostAverageItem> GetCostAverageItems(IQueryable<OrderItem> orderItems, Period period, DateTime dateTime = new DateTime()) {
return GetOrderItemsForPeriod(orderItems, period, dateTime)
.GroupBy(oi => oi.Product.Category)
.Select(g => new CostAverageItem { Category = g.Key, Cost = g.Average(oi => oi.ProductPrice) })
.ToList();
}
public static IEnumerable<CustomerStore> GetDistinctStoresForPeriod(IQueryable<Order> orders, long customerId, Period period = Period.Lifetime) {
return QueriesHelper.GetCustomerOrdersForPeriod(orders, period, customerId).GroupBy(o => o.Store).Select(g => g.Key).Distinct();
}
public static decimal GetQuotesTotal(IQueryable<Quote> quotes, CustomerStore store, DateTime begin, DateTime end) {
return quotes.Where(x => x.CustomerStoreId == store.Id && x.Date >= begin && x.Date <= end).CustomSum(x => x.Total);
}
public static IEnumerable<QuoteSummaryItem> GetSummaryOpportunities(IQueryable<Quote> quotes) {
yield return GetSummaryItem(quotes, Stage.High);
yield return GetSummaryItem(quotes, Stage.Medium);
yield return GetSummaryItem(quotes, Stage.Low);
yield return GetSummaryItem(quotes, Stage.Unlikely);
}
public static IEnumerable<QuoteMapItem> GetOpportunities(IQueryable<Quote> quotes, IQueryable<Customer> customers, Stage stage) {
string name = Enum.GetName(typeof(Stage), stage);
return from q in GetQuotes(quotes, stage)
join c in customers on q.CustomerId equals c.Id
select new QuoteMapItem { Stage = stage, Address = q.CustomerStore.Address, Value = q.Total, Date = q.Date };
}
public static IEnumerable<QuoteMapItem> GetOpportunities(IQueryable<Quote> quotes) {
yield return GetOpportunity(quotes, Stage.High);
yield return GetOpportunity(quotes, Stage.Medium);
yield return GetOpportunity(quotes, Stage.Low);
yield return GetOpportunity(quotes, Stage.Unlikely);
}
static QuoteMapItem GetOpportunity(IQueryable<Quote> quotes, Stage stage) {
return new QuoteMapItem {
Stage = stage,
Value = GetQuotes(quotes, stage).CustomSum(q => q.Total)
};
}
public static decimal GetOpportunity(IQueryable<Quote> quotes, Stage stage, string city) {
return GetQuotes(quotes, stage).Where(q => q.CustomerStore.Address.City == city).CustomSum(q => q.Total);
}
public static IEnumerable<CustomerStore> GetCustomerStore(IQueryable<CustomerStore> stores, IQueryable<Quote> quotes, Stage stage) {
return from q in GetQuotes(quotes, stage)
join s in stores on q.CustomerStoreId equals s.Id
select s;
}
public static IEnumerable<OrderItem> GetRevenueReportItems(IQueryable<OrderItem> orderItems) {
bool hasItemsInCurrentMonth = orderItems.Where(x => x.Order.OrderDate.Month == DateTime.Now.Month && x.Order.OrderDate.Year == DateTime.Now.Year).Any();
var dateOfLastOrder = orderItems.Max(x => x.Order.OrderDate);
var revenueMonth = hasItemsInCurrentMonth ? DateTime.Now.Month : dateOfLastOrder.Month;
var revenueYear = hasItemsInCurrentMonth ? DateTime.Now.Year : dateOfLastOrder.Year;
return orderItems.Where(x => x.Order.OrderDate.Month == revenueMonth && x.Order.OrderDate.Year == revenueYear).ToList();
}
public static IEnumerable<OrderItem> GetRevenueAnalysisReportItems(IQueryable<OrderItem> orderItems, long storeId) {
return orderItems.Where(x => x.Order.StoreId.Value == storeId).ToList();
}
static QuoteSummaryItem GetSummaryItem(IQueryable<Quote> quotes, Stage stage) {
var query = GetQuotes(quotes, stage);
return new QuoteSummaryItem {
StageName = stage.ToString(),
Summary = !query.Any() ? 0 : query.CustomSum(q => q.Total)
};
}
static IQueryable<Quote> GetQuotes(IQueryable<Quote> quotes, Stage stage) {
double min, max;
switch(stage) {
case Stage.High:
max = 1.0;
min = 0.6;
break;
case Stage.Medium:
min = 0.3;
max = 0.6;
break;
case Stage.Low:
min = 0.12;
max = 0.3;
break;
case Stage.Summary:
min = 0.0;
max = 1.0;
break;
default:
min = 0.0;
max = 0.12;
break;
}
return quotes.Where(q => q.Opportunity > min && q.Opportunity < max);
}
}
public enum Period {
[Display(Name = "Lifetime")]
Lifetime,
[Display(Name = "This Year")]
ThisYear,
[Display(Name = "This Month")]
ThisMonth,
[Display(Name = "Fixed Date")]
FixedDate
}
}

View File

@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Runtime.Serialization;
namespace DevExpress.DevAV {
public class Quote : DatabaseObject {
public string Number { get; set; }
public virtual Customer Customer { get; set; }
public long? CustomerId { get; set; }
public virtual CustomerStore CustomerStore { get; set; }
public long? CustomerStoreId { get; set; }
public virtual Employee Employee { get; set; }
public long? EmployeeId { get; set; }
public virtual DateTime Date { get; set; }
[DataType(DataType.Currency)]
public decimal SubTotal { get; set; }
[DataType(DataType.Currency)]
public decimal ShippingAmount { get; set; }
[DataType(DataType.Currency)]
public decimal Total { get; set; }
public double Opportunity { get; set; }
public virtual List<QuoteItem> QuoteItems { get; set; }
}
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Runtime.Serialization;
namespace DevExpress.DevAV {
public class QuoteItem : DatabaseObject {
public virtual Quote Quote { get; set; }
public long? QuoteId { get; set; }
public virtual Product Product { get; set; }
public long? ProductId { get; set; }
public int ProductUnits { get; set; }
[DataType(DataType.Currency)]
public decimal ProductPrice { get; set; }
[DataType(DataType.Currency)]
public decimal Discount { get; set; }
[DataType(DataType.Currency)]
public decimal Total { get; set; }
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
namespace DevExpress.DevAV {
public class State {
[Key]
public StateEnum ShortName { get; set; }
public string LongName { get; set; }
public byte[] Flag48px { get; set; }
public byte[] Flag24px { get; set; }
}
}

View File

@@ -0,0 +1,57 @@
using System;
namespace DevExpress.DevAV {
public enum StateEnum {
CA,
AR,
AL,
AK,
AZ,
CO,
CT,
DE,
DC,
FL,
GA,
HI,
ID,
IL,
IN,
IA,
KS,
KY,
LA,
ME,
MD,
MA,
MI,
MN,
MS,
MO,
MT,
NE,
NV,
NH,
NJ,
NM,
NY,
NC,
OH,
OK,
OR,
PA,
RI,
SC,
SD,
TN,
TX,
UT,
VT,
VA,
WA,
WV,
WI,
WY,
ND
}
}

View File

@@ -0,0 +1,97 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.IO;
using System.Runtime.Serialization;
//using System.Windows.Media;
using System.Linq;
namespace DevExpress.DevAV {
public enum EmployeeTaskStatus {
[Display(Name = "Not Started")]
NotStarted,
[Display(Name = "Completed")]
Completed,
[Display(Name = "In Progress")]
InProgress,
[Display(Name = "Need Assistance")]
NeedAssistance,
[Display(Name = "Deferred")]
Deferred
}
public enum EmployeeTaskPriority {
Low,
Normal,
High,
Urgent
}
public enum EmployeeTaskFollowUp {
[Display(Name = "Today")]
Today,
[Display(Name = "Tomorrow")]
Tomorrow,
[Display(Name = "This Week")]
ThisWeek,
[Display(Name = "Next Week")]
NextWeek,
[Display(Name = "No Date")]
NoDate,
[Display(Name = "Custom")]
Custom
}
public class EmployeeTask : DatabaseObject {
public EmployeeTask() {
AssignedEmployees = new List<Employee>();
}
public virtual List<Employee> AssignedEmployees { get; set; }
[Required]
public string Subject { get; set; }
public string Description { get; set; }
public string RtfTextDescription { get; set; }
public DateTime? StartDate { get; set; }
public DateTime? DueDate { get; set; }
public EmployeeTaskStatus Status { get; set; }
public EmployeeTaskPriority Priority { get; set; }
public int Completion { get; set; }
public bool Reminder { get; set; }
public DateTime? ReminderDateTime { get; set; }
public virtual Employee AssignedEmployee { get; set; }
public long? AssignedEmployeeId { get; set; }
public virtual Employee Owner { get; set; }
public long? OwnerId { get; set; }
public virtual CustomerEmployee CustomerEmployee { get; set; }
public long? CustomerEmployeeId { get; set; }
public EmployeeTaskFollowUp FollowUp { get; set; }
public bool Private { get; set; }
public string Category { get; set; }
public virtual List<TaskAttachedFile> AttachedFiles { get; set; }
public bool AttachedCollectionsChanged { get; set; }
public override string ToString() {
return string.Format("{0} - {1}, due {2}, {3},\r\nOwner: {4}", Subject, Description, DueDate, Status, Owner);
}
public bool Overdue {
get {
if(Status == EmployeeTaskStatus.Completed || !DueDate.HasValue) return false;
DateTime dDate = DueDate.Value.Date.AddDays(1);
if(DateTime.Now >= dDate) return true;
return false;
}
}
public int AttachedFilesCount {
get {
return (AttachedFiles == null) ? 0 : AttachedFiles.Count;
}
}
public string AssignedEmployeesFullList {
get {
if(AssignedEmployees == null)
return "";
return string.Join(", ", AssignedEmployees.Select(x => x.FullName));
}
}
}
}