コード例 #1
0
        public void TestMethod1()
        {
            AddressBook.DataLayer data = new AddressBook.DataLayer();
            data.InsertPerson("michal", "Imlauf", 12, 13);
            data.InsertAddres("A", "B", 53701, 29);


            // data.UpdateAddress(22,"C","E",000);
            //data.UpdatePerson(28,"A","C",17,18);
            BindingList <Person> persons = new BindingList <Person>();

            persons    = data.SelectAllPersons(persons);
            persons[0] = data.SelectAdresses(persons[0]);
            // data.DeleteAdress(1);
            // data.DeletePerson(1);
        }
コード例 #2
0
ファイル: ObjectLayer.cs プロジェクト: ARLM-Attic/sudoku-imli
        /// <summary>
        /// Addding a person to list and passing persons info to database
        /// </summary>
        /// <param name="name">Name of person</param>
        /// <param name="surname">Surname of person</param>
        /// <param name="ic">Identification number of company</param>
        /// <param name="dic">Identification number of company for tax purposes</param>
        /// <returns>Error message if input is incorrect</returns>
        public string AddPerson(string name, string surname, string ic, string dic)
        {
            int    tempIc, tempDic;
            string result = CheckPersonParameters(name, surname, ic, dic); //checking if persons informations are valid

            if (result != "")
            {
                return(result);              //if they arent valid, return error message
            }
            //parsing dic and ic
            Int32.TryParse(ic, out tempIc);
            Int32.TryParse(dic, out tempDic);

            //creating new instance of person with given information
            Person tempPerson = new Person(name, surname, tempIc, tempDic);

            //loading information about ic
            tempPerson = loadIcInfo(tempPerson);

            try //trying to insert person and icinfo into database
            {
                int id   = data.InsertPerson(tempPerson.Name, tempPerson.Surname, tempPerson.IC, tempPerson.DIC);
                int icId = data.InsertIco(tempPerson.ICInfo.CompanyName, tempPerson.ICInfo.DateCreated,
                                          tempPerson.ICInfo.DateValid, tempPerson.PersonID);
                if (id == 0)
                {
                    Log("Unable to Insert Person into database");         //if Insertperson returns 0, it means that person wasnt inserted so we log it
                }
                else if (icId == 0)
                {
                    Log("Unable to Insert IC into database");               //same as above, but for IcInfo
                }
                else //if everything went fine, we add ids of inserted person/icinfo to the person object
                {
                    tempPerson.PersonID    = id;
                    tempPerson.ICInfo.icID = icId;
                    _persons.Add(tempPerson); //as last thing we insert person object into bindinglist
                }
            }
            catch (Exception except)
            {
                Log(except.ToString());
            }

            return("");
        }