I'm taking my first steps into oop, which entails gutting my application and reworking it all to be 3-tiered and object oriented. Sigh. I've got a submission object, which should contain a customer object (as well as a broker and coverage object); I want to store some datareader results from the db in the fields of each of the contained objects, but when I try to call up the Customer object with a new submission object, I get nothing. VS doesn't recognize that Submission contains a Customer object. I'm obviously missing some crucial points, so with that in mind, ideas? Code below.
//This is the Submission class here
public class Submission
{
public int SubmissionId {get;set;}
public int Status { get; set; }
public string StatusComment { get; set; }
public class Customer
{
//public Customer() { }
public int CustId { get; set; }
public string CustName { get; set; }
public string CustAddress { get; set; }
public string CustState { get; set; }
public string CustCity { get; set; }
public int CustZip { get; set; }
public int SicNaic { get; set; }
}
public object Customer();
}
//These lines throw an error:
Cannot reference a type through an expression. VS doesn't recognize the call to the Customer object inside Submission by TempSubmission.Customer.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
/// This query should selects the relevant data for a gridview on the presentation layer and stores in a list.
/// Don't quite know how to bind it to the gridview yet, but that's a different question.
public class SubmissionDatabaseService
{
public List<Submission> GetAllSubmissions()
{
string Searchstring = "SELECT Submission.SubmissionId, Customer.CustName, Customer.CustCity, Customer.CustState, Broker.BroName, Broker.BroState, Broker.EntityType, Submission.Coverage, Status.Status FROM Submission INNER JOIN Broker ON Broker.BroId = Submission.BroId INNER JOIN Customer ON Customer.CustId = Submission.CustId INNER JOIN Status ON Status.StatusId = Submission.StatusId";
string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(connectionString);
SqlDataReader dr = null;
try
{
conn.Open();
SqlCommand Searchcmd = new SqlCommand(Searchstring, conn);
dr = Searchcmd.ExecuteReader();
List <Submission> lstSubmission;
Submission tempSubmission;
while (dr.Read())
{
tempSubmission = new Submission();
tempSubmission.SubmissionId = dr.GetInt32(0);
tempSubmission.Customer.CustName = dr.GetString(1);
tempSubmission.Customer.CustCity = dr.GetString(2);
tempSubmission.Customer.CustState = dr.GetString(3);
tempSubmission.Broker.BroName = dr.GetString(4);
tempSubmission.Broker.BroState = dr.GetString(5);
tempSubmission.Broker.EntityType = dr.GetString(6);
tempSubmission.SubmissionCoverage.Coverage = dr.GetInt32(7);
tempSubmission.Status = dr.GetInt32(8);
//Add rest of the fields
lstSubmission.Add(tempSubmission);
}
}
return lstSubmission;
}
}