我基于 SQL 图表创建了两个 C# 类联系人和客户(见图)只是我想看看我是否做得对,我需要一些建议吗?向下数据库图和类客户和联系人
Customer Class
public class Customer
{
public int CustomerID { get; set; }
public string Title { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Postion { get; set; }
public Char Gender { get; set; }
public DateTime BecomeCustomer { get; set; }
public DateTime ModifiedDate { get; set; }
public Customer() { }
public static bool AddNewCustomer_Contact(Customer cust,Contacts cont)
{
try
{
// get a configured DbCommand object
DbCommand comm = GenericDataAccess.CreateCommand();
//Set the store Proc name
comm.CommandText = "AddNewCustomer_Contact";
//create new parameter @Title
DbParameter param = comm.CreateParameter();
param = comm.CreateParameter();
param.ParameterName = "@Title";
param.Value = cust.Title;
param.DbType = DbType.StringFixedLength;
comm.Parameters.Add(param);
//create new parameter @FirstName
param = comm.CreateParameter();
param.ParameterName = "@FirstName ";
param.Value = cust.FirstName;
param.DbType = DbType.StringFixedLength;
comm.Parameters.Add(param);
//create new parameter @LastName
param = comm.CreateParameter();
param.ParameterName = "@LastName";
param.Value = cust.LastName;
param.DbType = DbType.StringFixedLength;
comm.Parameters.Add(param);
//create new parameter @Postion
param = comm.CreateParameter();
param.ParameterName = "@Postion ";
param.Value = cust.Postion;
param.DbType = DbType.StringFixedLength;
comm.Parameters.Add(param);
//create new parameter @BecomeCustomer
param = comm.CreateParameter();
param.ParameterName = "@BecomeCustomer";
param.Value = DateTime.Now;
param.DbType = DbType.DateTime;
comm.Parameters.Add(param);
//create new parameter @Gender
param = comm.CreateParameter();
param.ParameterName = "@Gender";
param.Value = cust.Gender;
param.DbType = DbType.String;
comm.Parameters.Add(param);
//create new parameter @ModifiedDate
param = comm.CreateParameter();
param.ParameterName = "@ModifiedDate";
param.Value = DateTime.Now;
param.DbType = DbType.StringFixedLength;
comm.Parameters.Add(param);
//create new parameter @LabelContactTypeID
param = comm.CreateParameter();
param.ParameterName = "@LabelContactTypeID";
param.Value = cont.LabelContactTypeID;
param.DbType = DbType.StringFixedLength;
comm.Parameters.Add(param);
//create new parameter @ContactDetails
param = comm.CreateParameter();
param.ParameterName = "@ContactDetails";
param.Value = cont.ContactDetail;
param.DbType = DbType.StringFixedLength;
comm.Parameters.Add(param);
//create new parameter @Status
param = comm.CreateParameter();
param.ParameterName = "@Status";
param.Value = cont.Status;
param.DbType = DbType.StringFixedLength;
comm.Parameters.Add(param);
//create new parameter @Notes
param = comm.CreateParameter();
param.ParameterName = "@Notes";
param.Value = cont.Notes;
param.DbType = DbType.StringFixedLength;
comm.Parameters.Add(param);
return (GenericDataAccess.ExecuteNonQuery(comm) != -1);
}
catch
{
return false;
}
}
}
Contact Class
public class Contacts
{
public int ContactsID { get; set; }
public int CustomerID { get;set; }
public string ContactDetail { get; set; }
public bool Status { get; set; }
public int LabelContactTypeID { get; set; }
public string Notes { get; set; }
}