159 lines
5.7 KiB
C#
159 lines
5.7 KiB
C#
//
|
|
// Class: Customer
|
|
// Current CLR: 4.0.30319.34209
|
|
// System: Microsoft Visual Studio 10.0
|
|
// Author: dani
|
|
// Created: 5/9/2015 4:56:38 PM
|
|
//
|
|
// Copyright (c) 2015 Informatikbüro Daniel Schick. All rights reserved.
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
|
|
namespace bsmd.database
|
|
{
|
|
/// <summary>
|
|
/// EU-NOAD: "Agency" Einträge werden in dieser Klasse/Tabelle gespeichert
|
|
/// TODO: Späterer Abgleich mit Wetris
|
|
/// </summary>
|
|
public class Customer : DatabaseEntity
|
|
{
|
|
|
|
public Customer()
|
|
{
|
|
this.tablename = "[dbo].[Customer]";
|
|
}
|
|
|
|
#region Properties
|
|
|
|
[MaxLength(100)]
|
|
[ENI2Validation]
|
|
public string Name { get; set; }
|
|
|
|
[MaxLength(50)]
|
|
[ENI2Validation]
|
|
public string Phone { get; set; }
|
|
|
|
[MaxLength(100)]
|
|
[ENI2Validation]
|
|
public string Email { get; set; }
|
|
|
|
[MaxLength(50)]
|
|
[ENI2Validation]
|
|
public string ContactFirstName { get; set; }
|
|
|
|
[MaxLength(50)]
|
|
[ENI2Validation]
|
|
public string ContactLastName { get; set; }
|
|
|
|
[MaxLength(50)]
|
|
[ENI2Validation]
|
|
public string StreetAndNumber { get; set; }
|
|
|
|
[MaxLength(50)]
|
|
[ENI2Validation]
|
|
public string PostalCode { get; set; }
|
|
|
|
[MaxLength(50)]
|
|
[ENI2Validation]
|
|
public string City { get; set; }
|
|
|
|
[MaxLength(50)]
|
|
[ENI2Validation]
|
|
public string Country { get; set; }
|
|
|
|
[MaxLength(50)]
|
|
[ENI2Validation]
|
|
public string CustomerNumber { get; set; }
|
|
|
|
#endregion
|
|
|
|
public override string ToString()
|
|
{
|
|
return this.Name;
|
|
}
|
|
|
|
#region DatabaseEntity implementation
|
|
|
|
public override void PrepareSave(System.Data.IDbCommand cmd)
|
|
{
|
|
SqlCommand scmd = cmd as SqlCommand;
|
|
|
|
scmd.Parameters.AddWithNullableValue("@NAME", this.Name);
|
|
scmd.Parameters.AddWithNullableValue("@PHONE", this.Phone);
|
|
scmd.Parameters.AddWithNullableValue("@EMAIL", this.Email);
|
|
scmd.Parameters.AddWithNullableValue("@CFNAME", this.ContactFirstName);
|
|
scmd.Parameters.AddWithNullableValue("@CLNAME", this.ContactLastName);
|
|
scmd.Parameters.AddWithNullableValue("@STREET", this.StreetAndNumber);
|
|
scmd.Parameters.AddWithNullableValue("@POSTALCODE", this.PostalCode);
|
|
scmd.Parameters.AddWithNullableValue("@CITY", this.City);
|
|
scmd.Parameters.AddWithNullableValue("@COUNTRY", this.Country);
|
|
scmd.Parameters.AddWithNullableValue("@NUMBER", this.CustomerNumber);
|
|
|
|
if (this.IsNew)
|
|
{
|
|
this.CreateId();
|
|
scmd.Parameters.AddWithValue("@ID", this.Id);
|
|
scmd.CommandText = string.Format("INSERT INTO {0} (Id, Name, Phone, Email, ContactFirstName, ContactLastName, " +
|
|
"StreetAndNumber, PostalCode, City, Country, CustomerNumber) VALUES (@ID, @NAME, @PHONE, @EMAIL, @CFNAME, " +
|
|
"@CLNAME, @STREET, @POSTALCODE, @CITY, @COUNTRY, @NUMBER)", this.Tablename);
|
|
}
|
|
else
|
|
{
|
|
scmd.Parameters.AddWithValue("@ID", this.Id);
|
|
scmd.CommandText = string.Format("UPDATE {0} SET Name = @NAME, Phone = @Phone, Email = @EMAIL, " +
|
|
"ContactFirstName = @CFNAME, ContactLastName = @CLNAME, StreetAndNumber = @STREET, PostalCode = @POSTALCODE, " +
|
|
"City = @CITY, Country = @COUNTRY, CustomerNumber = @NUMBER WHERE Id = @ID", this.Tablename);
|
|
}
|
|
}
|
|
|
|
public override void PrepareLoadCommand(System.Data.IDbCommand cmd, Message.LoadFilter filter, params object[] criteria)
|
|
{
|
|
string query = string.Format("SELECT Id, Name, Phone, Email, ContactFirstName, ContactLastName, StreetAndNumber, " +
|
|
"PostalCode, City, Country, CustomerNumber FROM {0} ", this.Tablename);
|
|
|
|
switch (filter)
|
|
{
|
|
case Message.LoadFilter.BY_ID:
|
|
query += " WHERE Id = @ID";
|
|
((SqlCommand)cmd).Parameters.AddWithValue("@ID", criteria[0]);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
cmd.CommandText = query;
|
|
}
|
|
|
|
public override List<DatabaseEntity> LoadList(System.Data.IDataReader reader)
|
|
{
|
|
List<DatabaseEntity> result = new List<DatabaseEntity>();
|
|
while (reader.Read())
|
|
{
|
|
Customer c = new Customer();
|
|
|
|
c.id = reader.GetGuid(0);
|
|
if (!reader.IsDBNull(1)) c.Name = reader.GetString(1);
|
|
if (!reader.IsDBNull(2)) c.Phone = reader.GetString(2);
|
|
if (!reader.IsDBNull(3)) c.Email = reader.GetString(3);
|
|
if (!reader.IsDBNull(4)) c.ContactFirstName = reader.GetString(4);
|
|
if (!reader.IsDBNull(5)) c.ContactLastName = reader.GetString(5);
|
|
if (!reader.IsDBNull(6)) c.StreetAndNumber = reader.GetString(6);
|
|
if (!reader.IsDBNull(7)) c.PostalCode = reader.GetString(7);
|
|
if (!reader.IsDBNull(8)) c.City = reader.GetString(8);
|
|
if (!reader.IsDBNull(9)) c.Country = reader.GetString(9);
|
|
if (!reader.IsDBNull(10)) c.CustomerNumber = reader.GetString(10);
|
|
|
|
result.Add(c);
|
|
}
|
|
reader.Close();
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|