Exemplo n.º 1
0
        /// <summary>
        /// Loads the contact records from CSV file.
        /// </summary>
        public override Dictionary <string, ContactRecord> LoadContactRecords()
        {
            var _contacts = new Dictionary <string, ContactRecord>();

            if (!File.Exists(_contactsFileName))
            {
                FlushContactRecords(_contacts);
            }

            using (var reader = new StreamReader(_contactsFileName))
            {
                _csvHeader = reader.ReadLine();
                while (!reader.EndOfStream)
                {
                    var contact = new ContactRecord();
                    var values  = reader.ReadLine().Split(',');
                    NextID                = Math.Max(Convert.ToInt32(values[0]), NextID);
                    contact.Id            = values[0];
                    contact.FirstName     = values[1];
                    contact.LastName      = values[2];
                    contact.Email         = values[3];
                    contact.PhoneNo       = values[4];
                    contact.Comment       = values[5];
                    _contacts[contact.Id] = contact;
                }
            }

            return(_contacts);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Loads the contact records from permanent store.
        /// </summary>
        /// <returns>The contact records.</returns>
        public override Dictionary <string, ContactRecord> LoadContactRecords()
        {
            var contacts = new Dictionary <string, ContactRecord>();

            using (var dbConnection = new SqliteConnection(sqlConnectionString)) {
                dbConnection.Open();
                using (var dbCommand = dbConnection.CreateCommand())
                {
                    dbCommand.CommandText = sqlReadAllContacts;;
                    using (var dbReader = dbCommand.ExecuteReader())
                    {
                        while (dbReader.Read())
                        {
                            var contact = new ContactRecord();
                            contact.Id           = dbReader.GetInt32(0).ToString();
                            contact.FirstName    = dbReader.GetString(1);
                            contact.LastName     = dbReader.GetString(2);
                            contact.PhoneNo      = dbReader.GetString(3);
                            contact.Email        = dbReader.GetString(4);
                            contact.Comment      = dbReader.GetString(5);
                            contacts[contact.Id] = contact;
                            NextID = Math.Max(Convert.ToInt32(contact.Id), NextID);
                        }
                    }
                }
            }
            return(contacts);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:ContactsDB.ContactDBDialog"/> class.
        /// </summary>
        /// <param name="contact">Contact.</param>
        /// <param name="editable">If set to <c>true</c> editable.</param>
        public ContactDBDialog(ContactRecord contact, bool editable)
        {
            Build();

            // For non empty contact record lock last name from change and lock others
            // depending if its an update or read.

            if (contact.LastName != String.Empty)
            {
                lastNameEntry.IsEditable = false;
            }
            firstNameEntry.IsEditable = editable;
            phoneNoEntry.IsEditable = editable;
            emailEntry.IsEditable = editable;
            commentsTextView.Sensitive = editable;
            idEntry.IsEditable = false;

            // Copy contact detailt to dialog and display

            lastNameEntry.Text = contact.LastName;
            firstNameEntry.Text =  contact.FirstName;
            phoneNoEntry.Text = contact.PhoneNo;
            emailEntry.Text = contact.Email;
            commentsTextView.Buffer.Text = contact.Comment;
            idEntry.Text = contact.Id;

            _contact = contact;
            
            this.ShowAll();

        }
Exemplo n.º 4
0
 /// <summary>
 /// Deletes a contact record.
 /// </summary>
 /// <param name="contact">Contact.</param>
 public override void DeleteContactRecord(ContactRecord contact)
 {
     using (var dbConnection = new SqliteConnection(sqlConnectionString))
     {
         dbConnection.Open();
         using (var dbCommand = dbConnection.CreateCommand())
         {
             dbCommand.CommandText = sqlDeleteContact;
             dbCommand.Prepare();
             dbCommand.Parameters.AddWithValue("@Id", contact.Id);
             dbCommand.ExecuteNonQuery();
         }
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// Writes a contact record.
 /// </summary>
 /// <param name="contact">Contact.</param>
 public override void WriteContactRecord(ContactRecord contact)
 {
     using (var dbConnection = new SqliteConnection(sqlConnectionString))
     {
         dbConnection.Open();
         using (var dbCommand = dbConnection.CreateCommand())
         {
             dbCommand.CommandText = sqlCreateContact;
             dbCommand.Prepare();
             dbCommand.Parameters.AddWithValue("@FirstName", contact.FirstName);
             dbCommand.Parameters.AddWithValue("@LastName", contact.LastName);
             dbCommand.Parameters.AddWithValue("@PhoneNo", contact.PhoneNo);
             dbCommand.Parameters.AddWithValue("@Email", contact.Email);
             dbCommand.Parameters.AddWithValue("@Comment", contact.Comment);
             dbCommand.ExecuteNonQuery();
         }
     }
 }