202 lines
7.1 KiB
C#
202 lines
7.1 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Data;
|
|||
|
|
|
|||
|
|
namespace DatabaseExport.ISO
|
|||
|
|
{
|
|||
|
|
[Serializable()]
|
|||
|
|
public class CustomerDetails //: ISerializableFile
|
|||
|
|
{
|
|||
|
|
private enum Fields
|
|||
|
|
{
|
|||
|
|
Name,
|
|||
|
|
CustomerName,
|
|||
|
|
CustomerTestRefNumber,
|
|||
|
|
ProjectRefNumber,
|
|||
|
|
CustomerOrderNumber,
|
|||
|
|
CustomerCostUnit,
|
|||
|
|
LocalOnly,
|
|||
|
|
LastModified,
|
|||
|
|
LastModifiedBy,
|
|||
|
|
Version
|
|||
|
|
}
|
|||
|
|
public Dictionary<string, string> GetValues()
|
|||
|
|
{
|
|||
|
|
var elementNameValuePairs = new Dictionary<string, string>();
|
|||
|
|
|
|||
|
|
elementNameValuePairs[Fields.Name.ToString()] = Name;
|
|||
|
|
elementNameValuePairs[Fields.CustomerName.ToString()] = CustomerName;
|
|||
|
|
elementNameValuePairs[Fields.CustomerTestRefNumber.ToString()] = CustomerTestRefNumber;
|
|||
|
|
elementNameValuePairs[Fields.ProjectRefNumber.ToString()] = ProjectRefNumber;
|
|||
|
|
elementNameValuePairs[Fields.CustomerOrderNumber.ToString()] = CustomerOrderNumber;
|
|||
|
|
elementNameValuePairs[Fields.CustomerCostUnit.ToString()] = CustomerCostUnit;
|
|||
|
|
elementNameValuePairs[Fields.LocalOnly.ToString()] = LocalOnly.ToString();
|
|||
|
|
elementNameValuePairs[Fields.LastModified.ToString()] = LastModified.ToString(System.Globalization.CultureInfo.InvariantCulture);
|
|||
|
|
elementNameValuePairs[Fields.LastModifiedBy.ToString()] = LastModifiedBy;
|
|||
|
|
elementNameValuePairs[Fields.Version.ToString()] = Version.ToString(System.Globalization.CultureInfo.InvariantCulture);
|
|||
|
|
|
|||
|
|
return elementNameValuePairs;
|
|||
|
|
}
|
|||
|
|
private string _customerName = string.Empty;
|
|||
|
|
public string CustomerName
|
|||
|
|
{
|
|||
|
|
get => _customerName;
|
|||
|
|
set => _customerName = value;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private string _customerTestRefNumber = string.Empty;
|
|||
|
|
public string CustomerTestRefNumber
|
|||
|
|
{
|
|||
|
|
get => _customerTestRefNumber;
|
|||
|
|
set => _customerTestRefNumber = value;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private string _projectRefNumber = "NOVALUE";
|
|||
|
|
public string ProjectRefNumber
|
|||
|
|
{
|
|||
|
|
get => _projectRefNumber;
|
|||
|
|
set
|
|||
|
|
{
|
|||
|
|
if (value != string.Empty)
|
|||
|
|
{
|
|||
|
|
_projectRefNumber = value;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private string _customerOrderNumber = "NOVALUE";
|
|||
|
|
public string CustomerOrderNumber
|
|||
|
|
{
|
|||
|
|
get => _customerOrderNumber;
|
|||
|
|
set
|
|||
|
|
{
|
|||
|
|
if (value != string.Empty)
|
|||
|
|
{
|
|||
|
|
_customerOrderNumber = value;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private string _customerCostUnit = "NOVALUE";
|
|||
|
|
public string CustomerCostUnit
|
|||
|
|
{
|
|||
|
|
get => _customerCostUnit;
|
|||
|
|
set
|
|||
|
|
{
|
|||
|
|
if (value != string.Empty)
|
|||
|
|
{
|
|||
|
|
_customerCostUnit = value;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
private bool _localOnly = false;
|
|||
|
|
public bool LocalOnly
|
|||
|
|
{
|
|||
|
|
get => _localOnly;
|
|||
|
|
set => _localOnly = value;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private string _name = "";
|
|||
|
|
public string Name
|
|||
|
|
{
|
|||
|
|
get => _name;
|
|||
|
|
set => _name = value;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private DateTime _lastModified;
|
|||
|
|
public DateTime LastModified
|
|||
|
|
{
|
|||
|
|
get => _lastModified;
|
|||
|
|
set => _lastModified = value;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private string _lastModifiedBy;
|
|||
|
|
public string LastModifiedBy
|
|||
|
|
{
|
|||
|
|
get => _lastModifiedBy;
|
|||
|
|
set => _lastModifiedBy = value;
|
|||
|
|
}
|
|||
|
|
private int _version = 1;
|
|||
|
|
public int Version
|
|||
|
|
{
|
|||
|
|
get => _version;
|
|||
|
|
set => _version = value;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public CustomerDetails()
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
public CustomerDetails(DataRow dr)
|
|||
|
|
{
|
|||
|
|
_name = (string)dr["Name"];
|
|||
|
|
CustomerName = (string)dr["CustomerName"];
|
|||
|
|
CustomerTestRefNumber = (string)dr["CustomerTestRefNumber"];
|
|||
|
|
ProjectRefNumber = (string)dr["ProjectRefNumber"];
|
|||
|
|
CustomerOrderNumber = (string)dr["CustomerOrderNumber"];
|
|||
|
|
CustomerCostUnit = (string)dr["CustomerCostUnit"];
|
|||
|
|
_localOnly = Convert.ToBoolean(dr["LocalOnly"]);
|
|||
|
|
_lastModified = Convert.ToDateTime(dr["LastModified"]);
|
|||
|
|
_lastModifiedBy = (string)dr["LastModifiedBy"];
|
|||
|
|
_version = Convert.ToInt32(dr["Version"]);
|
|||
|
|
}
|
|||
|
|
public CustomerDetails(CustomerDetails copy)
|
|||
|
|
{
|
|||
|
|
_name = copy.Name;
|
|||
|
|
CustomerName = copy.CustomerName;
|
|||
|
|
CustomerTestRefNumber = copy.CustomerTestRefNumber;
|
|||
|
|
ProjectRefNumber = copy.ProjectRefNumber;
|
|||
|
|
CustomerOrderNumber = copy.CustomerOrderNumber;
|
|||
|
|
CustomerCostUnit = copy.CustomerCostUnit;
|
|||
|
|
_localOnly = copy.LocalOnly;
|
|||
|
|
_lastModified = copy.LastModified;
|
|||
|
|
_lastModifiedBy = copy.LastModifiedBy;
|
|||
|
|
_version = copy.Version;
|
|||
|
|
}
|
|||
|
|
public static CustomerDetails[] GetAllCustomerDetails()
|
|||
|
|
{
|
|||
|
|
var list = new List<CustomerDetails>();
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
using (var sql = DbOperations.GetCommand())
|
|||
|
|
{
|
|||
|
|
/* always optimize sql statement! */
|
|||
|
|
sql.CommandText = @"SELECT Name" +
|
|||
|
|
",CustomerName" +
|
|||
|
|
",CustomerTestRefNumber" +
|
|||
|
|
",ProjectRefNumber" +
|
|||
|
|
",CustomerOrderNumber" +
|
|||
|
|
",CustomerCostUnit" +
|
|||
|
|
",LocalOnly" +
|
|||
|
|
",LastModified" +
|
|||
|
|
",LastModifiedBy" +
|
|||
|
|
",Version " +
|
|||
|
|
"from [tblCustomerDetails]";
|
|||
|
|
|
|||
|
|
using (var ds = DbOperations.Connection.QueryDataSet(sql))
|
|||
|
|
{
|
|||
|
|
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
|
|||
|
|
{
|
|||
|
|
foreach (DataRow dr in ds.Tables[0].Rows)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
list.Add(new CustomerDetails(dr));
|
|||
|
|
}
|
|||
|
|
catch (Exception)
|
|||
|
|
{
|
|||
|
|
//DTS.Utilities.Logging.APILogger.Log("failed to get customer details", ex);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception)
|
|||
|
|
{
|
|||
|
|
//DTS.Utilities.Logging.APILogger.Log("Failed to retrieve customer details", ex);
|
|||
|
|
}
|
|||
|
|
return list.ToArray();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|