Пример #1
0
        /// <summary>
        /// Open contacts file.
        /// </summary>
        private void OpenContactsFile()
        {
            GlobalObjUI.ContactsFilePath = "";

            // New dialog for select contacts file
            string selectedFile = QFileDialog.GetOpenFileName(this,
                                                              GlobalObjUI.LMan.GetString("openfileact"),
                                                              null,
                                                              "monosim files *.monosim (*.monosim)");

            if (string.IsNullOrEmpty(selectedFile))
            {
                return;
            }

            // path of a right file returned
            GlobalObjUI.ContactsFilePath = selectedFile;

            // Update gui
            UpdateFileControls(false);

            // Clear ListView
            mainwindow_Ui.LstFileContacts.Clear();
            MainClass.QtWait();

            try
            {
                GlobalObjUI.FileContacts = new Contacts();
                StreamReader sr       = new StreamReader(GlobalObjUI.ContactsFilePath);
                string       descRow  = sr.ReadLine();
                string       phoneRow = "";
                while (!sr.EndOfStream)
                {
                    phoneRow = sr.ReadLine();
                    // check for right values
                    if (descRow.Trim() != "" && phoneRow.Trim() != "")
                    {
                        GlobalObjUI.FileContacts.SimContacts.Add(new Contact(descRow, phoneRow));
                    }

                    // read new contact description
                    descRow = sr.ReadLine();
                }
                sr.Close();
                sr.Dispose();
                sr = null;
            }
            catch (Exception Ex)
            {
                log.Error("MainWindowClass::OpenContactsFile: " + Ex.Message + "\r\n" + Ex.StackTrace);
                MainClass.ShowMessage(this, "ERROR", Ex.Message, MainClass.MessageType.Error);
                return;
            }

            // loop to append data readed from file
            List <string> rowContent = null;

            foreach (Contact cnt in GlobalObjUI.FileContacts.SimContacts)
            {
                rowContent = new List <string>();
                rowContent.Add(" ");
                rowContent.Add(cnt.Description);
                rowContent.Add(cnt.PhoneNumber);
                new QTreeWidgetItem(mainwindow_Ui.LstFileContacts, rowContent);
            }

            UpdateFileControls(true);
        }