Click here to Skip to main content
15,914,608 members
Home / Discussions / C#
   

C#

 
AnswerRe: Not Getting Data Back From Stored Proc Call Pin
KaptinKrunch5-Nov-08 10:42
KaptinKrunch5-Nov-08 10:42 
AnswerRe: Not Getting Data Back From Stored Proc Call Pin
Ashfield5-Nov-08 21:26
Ashfield5-Nov-08 21:26 
Questionwaiting for multiple threads Pin
invictus35-Nov-08 10:24
invictus35-Nov-08 10:24 
AnswerRe: waiting for multiple threads Pin
Nicholas Butler5-Nov-08 11:35
sitebuilderNicholas Butler5-Nov-08 11:35 
QuestionAccessing a static variable Pin
Member 41431915-Nov-08 8:46
Member 41431915-Nov-08 8:46 
AnswerRe: Accessing a static variable Pin
User 66585-Nov-08 9:41
User 66585-Nov-08 9:41 
GeneralRe: Accessing a static variable Pin
Member 41431915-Nov-08 10:25
Member 41431915-Nov-08 10:25 
QuestionHow to compare custom objects in a Dictionary<> Pin
ret76795-Nov-08 8:24
ret76795-Nov-08 8:24 
I have two databases (I'll call them (A) and (B) for this discussion) that keep Customer information. (A) uses a system generated integer for the unique record ID and (B) uses its Company_Code and Customer_Code data fields as its unique record ID. I can change the database structure for (A) but not (B). I added Company_Code and Customer_Code fields to (A) so I can relate (A) and (B) customer records. If i'm working in a child record in (A) I know the interger for the customer, but I have to query the parent for the (B) key when I need information from (B). If i'm working in (B) I know the Company_Code, Customer_Code, but again, I have to query (A) parent record to get the correct integer value if I need information from (A). So I came up with the following solution that I need help with. (I should mention I'm a newbie programmer and would gladly consider other solutions)

1. I created a simple class:

public class CustomerIDPair: IComparer<CustomerIDPair>, IComparable<CustomerIDPair>
{
    private string _company_Code = string.Empty;
    private string _customer_Code = string.Empty;

    public CustomerIDPair()
    {
        //
    }

    public CustomerIDPair(string Company_Code, string Customer_Code)
    {
        _company_Code = Company_Code;
        _customer_Code = Customer_Code;
    }

    public string Company_Code
    {
        get { return _company_Code; }
        set { _company_Code = value; }
    }

    public string Customer_Code
    {
        get { return _customer_Code; }
        set { _customer_Code = value; }
    }

    public override string ToString()
    {
        return _company_Code.Trim() + ", " + _customer_Code.Trim();
    }

    #region IComparer<CustomerIDPair> Members

    public int Compare(CustomerIDPair x, CustomerIDPair y)
    {
        string strX = x.Company_Code.Trim().PadLeft(3) + x.Customer_Code.Trim().PadLeft(10);
        string strY = y.Company_Code.Trim().PadLeft(3) + y.Customer_Code.Trim().PadLeft(10);
        return string.Compare(strX, strY, true);
    }

    #endregion

    #region IComparable<CustomerIDPair> Members

    public int CompareTo(CustomerIDPair other)
    {
        string strX = this.Company_Code.Trim().PadLeft(3) + this.Customer_Code.Trim().PadLeft(10);
        string strY = other.Company_Code.Trim().PadLeft(3) + other.Customer_Code.Trim().PadLeft(10);
        return string.Compare(strX, strY, true);
    }

    #endregion
}


2. I created 2 Dictionarys 'AtoB<int, CustomerIDPair>' and 'BtoA<CustomerIDPair, int>', then populated them from A on application startup

Assume there is a customer that is identified in A as 14, and identifed as "EZE","TLC" in B

So:
AtoB[14] correctly evalates to a CustomerIDPair from with I can retrieve the company_Code and customer_Code.

But:

CustomerIDPair custID = new CustomerIDPair("EZE","TLC");
int test = BtoA[custId];


raises a KeyNotFoundException

Does anyone have any ideas how to make this work?
Thanks in advance
Russ
AnswerRe: How to compare custom objects in a Dictionary&lt;&gt; Pin
User 66585-Nov-08 9:50
User 66585-Nov-08 9:50 
GeneralRe: How to compare custom objects in a Dictionary&lt;&gt; Pin
ret76796-Nov-08 5:27
ret76796-Nov-08 5:27 
GeneralRe: How to compare custom objects in a Dictionary&lt;&gt; Pin
User 66586-Nov-08 10:25
User 66586-Nov-08 10:25 
Questiondeleting data from a database Pin
postonoh5-Nov-08 7:25
postonoh5-Nov-08 7:25 
QuestionRe: deleting data from a database Pin
Le centriste5-Nov-08 8:33
Le centriste5-Nov-08 8:33 
GeneralRe: deleting data from a database Pin
Guffa5-Nov-08 9:17
Guffa5-Nov-08 9:17 
GeneralRe: deleting data from a database Pin
Le centriste5-Nov-08 9:35
Le centriste5-Nov-08 9:35 
AnswerRe: deleting data from a database Pin
Guffa5-Nov-08 9:37
Guffa5-Nov-08 9:37 
GeneralRe: deleting data from a database Pin
postonoh5-Nov-08 9:42
postonoh5-Nov-08 9:42 
QuestionGetting application Icon Pin
Dirso5-Nov-08 7:16
Dirso5-Nov-08 7:16 
AnswerRe: Getting application Icon Pin
Colin Angus Mackay5-Nov-08 7:22
Colin Angus Mackay5-Nov-08 7:22 
GeneralRe: Getting application Icon Pin
Dirso5-Nov-08 7:35
Dirso5-Nov-08 7:35 
AnswerRe: Getting application Icon Pin
Henry Minute5-Nov-08 9:50
Henry Minute5-Nov-08 9:50 
GeneralRe: Getting application Icon Pin
Dirso5-Nov-08 10:54
Dirso5-Nov-08 10:54 
QuestionOpen Button Click Event Pin
boiDev5-Nov-08 7:15
boiDev5-Nov-08 7:15 
AnswerRe: Open Button Click Event Pin
Colin Angus Mackay5-Nov-08 7:24
Colin Angus Mackay5-Nov-08 7:24 
AnswerRe: Open Button Click Event Pin
nelsonpaixao5-Nov-08 14:07
nelsonpaixao5-Nov-08 14:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.