Click here to Skip to main content
15,886,919 members
Home / Discussions / C#
   

C#

 
AnswerRe: Ethernet Port C# Pin
Richard MacCutchan7-May-13 2:51
mveRichard MacCutchan7-May-13 2:51 
QuestionSaving objects with Cross-reference Pin
larsp7777-May-13 1:35
larsp7777-May-13 1:35 
AnswerRe: Saving objects with Cross-reference Pin
Eddy Vluggen7-May-13 9:22
professionalEddy Vluggen7-May-13 9:22 
GeneralRe: Saving objects with Cross-reference Pin
larsp7777-May-13 12:14
larsp7777-May-13 12:14 
GeneralRe: Saving objects with Cross-reference Pin
Bernhard Hiller7-May-13 22:56
Bernhard Hiller7-May-13 22:56 
GeneralRe: Saving objects with Cross-reference Pin
larsp7778-May-13 2:24
larsp7778-May-13 2:24 
GeneralRe: Saving objects with Cross-reference Pin
Eddy Vluggen8-May-13 6:53
professionalEddy Vluggen8-May-13 6:53 
GeneralRe: Saving objects with Cross-reference Pin
larsp7779-May-13 20:19
larsp7779-May-13 20:19 
Well, you set the unique number when you register a book (Bok) or a customer (kund).

It's not a Commercial application.

C#
Book:

 [Serializable()]
    public class Bok : ISerializable

  {
        protected int isbn = 0;
        protected string titel = null;
        protected string author;
        protected int price;
        protected String isType = null;
        protected Kund biblioteksKund = null;

        //egenskaper (properties). Används för att förhindra åtkomst till privata variabler.
        public int ISBN
        {
            get
            {
                return isbn;
            }
            set
            {
                isbn = value;
            }
        }

        public string Titel
        {
            get
            {
                return titel;
            }
            set
            {
                titel = value;
            }
        }

        public string Author
        {
            get
            {
                return author;
            }
            set
            {
                author = value;
            }
        }

        public int Price
        {
            get
            {
                return price;
            }
            set
            {
                price = value;
            }
        }

        public String IsType
        {
            get
            {
                return isType;
            }
            set
            {
                isType = value;
            }
        }
        
        public Kund BiblioteksKund
        {
            get
            {
                return biblioteksKund;
            }
            set
            {
                biblioteksKund = value;
            }
        }


        //Konstruktor (constructor) Metod som körs när objektet skapas. Denna körs om det inte finns parametrar.
        public Bok() 
        {
        }

        //Konstruktor med parametrar
        public Bok(int isbn, string titel, string author, int price, SerializationInfo info, StreamingContext ctxt)
        {
            ISBN = isbn;
            Author = author;
            Titel = titel;
            Price = price;
            biblioteksKund = new Kund();
            this.isbn = (int)info.GetValue("ISBN", typeof(int));
            this.author = (string)info.GetValue("Author", typeof(string));
            this.titel = (string)info.GetValue("Titel", typeof(string));
            this.price = (int)info.GetValue("Price", typeof(int));
            this.biblioteksKund = (Kund)info.GetValue("Kund", typeof(Kund));
         }

        public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
        {
            info.AddValue("ISBN", this.isbn);
            info.AddValue("Author", this.author);
            info.AddValue("Titel", this.titel);
            info.AddValue("Price", this.price);
            info.AddValue("BiblioteksKund", this.biblioteksKund);
        }
 

        //Metod som skriver ut våra variabler.
        public virtual void skrivUt()
        {
            Console.WriteLine("Författare: {0}", Author);
            Console.WriteLine("Titel: {0}", Titel);
            Console.WriteLine("Pris: {0}", Price);
        }

       public virtual String getInfo()
        {
           return null;
        }

        public String getStatus()
        {
            if (BiblioteksKund != null)
                return ("Utlånad till: " + BiblioteksKund.Name);
            else
                return ("Ej utlånad");
        }
    }
}



C#
Customer:

[Serializable()]
    public class Kund : ISerializable

    {
        private int personNr = 0;
        private string name;
        private List<Bok> loan = new List<Bok>(); 
            


        //egenskaper (properties). Används för att förhindra åtkomst till privata variabler.
        public int PersonNr
        {
            get
            {
                return personNr;
            }
            set
            {
                personNr = value;
            }
        }

        public string Name
        {
            get
            {
                return name;
            }
            set
             {
                name = value;
            }
        }

        public List<Bok> Loan
        {
              get
            {
                return loan;
            }

           // set
            //{
             //  loan = value;
            //}
       }

       

        //Konstruktor (constructor) Metod som körs när objektet skapas. Denna körs om det inte finns parametrar.
        public Kund()
        {
        }

        //Konstruktor med parametrar
        public Kund(int personNr, string name)
        {
            PersonNr = personNr;
            Name = name;
           
        }

        public Kund(SerializationInfo info, StreamingContext ctxt)
        {
            this.personNr = (int)info.GetValue("PersonNr", typeof(int));
            this.name = (string)info.GetValue("Name", typeof(string));
        }

        public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
        {
            info.AddValue("PersonNr", this.personNr);
            info.AddValue("Name", this.name);
        }
 
        //Metod som skriver ut våra variabler.
        public virtual void skrivUt()
        {
            Console.WriteLine("Personnr: {0}", PersonNr);
            Console.WriteLine("Namn: {0}", Name);
        }
    }

GeneralRe: Saving objects with Cross-reference Pin
Eddy Vluggen11-May-13 9:40
professionalEddy Vluggen11-May-13 9:40 
GeneralRe: Saving objects with Cross-reference Pin
larsp77711-May-13 10:57
larsp77711-May-13 10:57 
AnswerRe: Saving objects with Cross-reference Pin
Eddy Vluggen11-May-13 11:02
professionalEddy Vluggen11-May-13 11:02 
GeneralRe: Saving objects with Cross-reference Pin
larsp77711-May-13 11:12
larsp77711-May-13 11:12 
GeneralRe: Saving objects with Cross-reference Pin
Eddy Vluggen11-May-13 22:08
professionalEddy Vluggen11-May-13 22:08 
GeneralRe: Saving objects with Cross-reference Pin
larsp77711-May-13 22:18
larsp77711-May-13 22:18 
GeneralRe: Saving objects with Cross-reference Pin
Eddy Vluggen11-May-13 22:36
professionalEddy Vluggen11-May-13 22:36 
GeneralRe: Saving objects with Cross-reference Pin
larsp77711-May-13 22:59
larsp77711-May-13 22:59 
GeneralRe: Saving objects with Cross-reference Pin
Eddy Vluggen11-May-13 23:17
professionalEddy Vluggen11-May-13 23:17 
GeneralRe: Saving objects with Cross-reference Pin
larsp77711-May-13 23:21
larsp77711-May-13 23:21 
QuestionRe: Saving objects with Cross-reference Pin
Eddy Vluggen12-May-13 1:10
professionalEddy Vluggen12-May-13 1:10 
AnswerRe: Saving objects with Cross-reference Pin
larsp77712-May-13 2:09
larsp77712-May-13 2:09 
AnswerRe: Saving objects with Cross-reference Pin
Eddy Vluggen13-May-13 0:32
professionalEddy Vluggen13-May-13 0:32 
GeneralRe: Saving objects with Cross-reference Pin
larsp77713-May-13 0:34
larsp77713-May-13 0:34 
GeneralRe: Saving objects with Cross-reference Pin
Eddy Vluggen13-May-13 5:08
professionalEddy Vluggen13-May-13 5:08 
AnswerRe: Saving objects with Cross-reference Pin
Anna King8-May-13 3:24
professionalAnna King8-May-13 3:24 
GeneralRe: Saving objects with Cross-reference Pin
larsp7778-May-13 4:21
larsp7778-May-13 4:21 

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.