Esempio n. 1
0
        private void RunLoad()
        {
            OpenFileDialog openFile = new OpenFileDialog();

            openFile.DefaultExt       = ".xml";
            openFile.Filter           = "XML files|*.xml";
            openFile.InitialDirectory = SavedSearch.GetDefaultFolder();

            if (!System.IO.Directory.Exists(openFile.InitialDirectory))
            {
                System.IO.Directory.CreateDirectory(openFile.InitialDirectory);
            }

            DialogResult result = openFile.ShowDialog();

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                SavedSearch search = SavedSearch.Load(openFile.FileName);

                //m_entityClassComboBox.SelectedItem as EntityClass;

                if (search.EntityType == EntityClass.CO.EntityClassId)
                {
                    m_entityClassComboBox.SelectedItem = EntityClass.CO;
                }
                else if (search.EntityType == EntityClass.CUSTENT.EntityClassId)
                {
                    m_entityClassComboBox.SelectedItem = EntityClass.CUSTENT;
                }
                else if (search.EntityType == EntityClass.FILE.EntityClassId)
                {
                    m_entityClassComboBox.SelectedItem = EntityClass.FILE;
                }
                else if (search.EntityType == EntityClass.FLDR.EntityClassId)
                {
                    m_entityClassComboBox.SelectedItem = EntityClass.FLDR;
                }
                else if (search.EntityType == EntityClass.ITEM.EntityClassId)
                {
                    m_entityClassComboBox.SelectedItem = EntityClass.ITEM;
                }
                else
                {
                    throw new Exception("Unknown entity type");
                }

                m_criteriaListBox.Items.Clear();
                m_criteriaListBox.Items.AddRange(search.Conditions.ToArray());
            }
        }
Esempio n. 2
0
        private void RunSave()
        {
            SaveFileDialog saveFile = new SaveFileDialog();

            saveFile.DefaultExt       = ".xml";
            saveFile.Filter           = "XML files|*.xml";
            saveFile.InitialDirectory = SavedSearch.GetDefaultFolder();

            if (!System.IO.Directory.Exists(saveFile.InitialDirectory))
            {
                System.IO.Directory.CreateDirectory(saveFile.InitialDirectory);
            }

            DialogResult result = saveFile.ShowDialog();

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                SavedSearch search      = new SavedSearch();
                EntityClass entityClass = m_entityClassComboBox.SelectedItem as EntityClass;

                if (entityClass == null)
                {
                    MessageBox.Show("You must select an entity type.");
                    return;
                }

                search.EntityType = entityClass.EntityClassId;
                List <SrchCondItem> conditions = new List <SrchCondItem>();
                foreach (Object o in m_criteriaListBox.Items)
                {
                    SrchCondItem item = o as SrchCondItem;
                    if (item != null)
                    {
                        conditions.Add(item);
                    }
                }

                if (!conditions.Any())
                {
                    MessageBox.Show("You must have at least one search condition.");
                    return;
                }

                search.Conditions = conditions;

                search.Save(saveFile.FileName);
            }
        }
        public static SavedSearch Load(string fileName)
        {
            SavedSearch retVal = new SavedSearch();

            try
            {
                string xmlPath = Path.Combine(Util.GetAssemblyPath(), SAVED_SEARCH_FOLDER);
                xmlPath = Path.Combine(xmlPath, fileName);

                using (System.IO.StreamReader reader = new System.IO.StreamReader(xmlPath))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(SavedSearch));
                    retVal = (SavedSearch)serializer.Deserialize(reader);
                }
            }
            catch
            { }

            return(retVal);
        }