Exemplo n.º 1
0
        private void LoadDetailView(object sender, OpenRowEventArgs e)
        {
            // Exit if the id column is not defined.
            if (string.IsNullOrEmpty(m_searchDetail.IdColumn))
            {
                return;
            }

            object id = e.DataRow[m_searchDetail.IdColumn];

            //try
            //{
            Object obj;

            if (typeof(T).BaseType == typeof(VPLiteObject) |
                typeof(T).BaseType == typeof(VPObject) |
                typeof(T).BaseType == typeof(ContractBase) |
                typeof(T).BaseType == typeof(Area))
            {
                IUnitOfWork unitOfWork;
                if (m_searchDetail.Session != null)
                {
                    unitOfWork = m_searchDetail.Session;
                }
                else
                {
                    unitOfWork = Scout.Core.Data.GetUnitOfWork();
                }

                m_output = unitOfWork.GetObjectByKey <T>(id);

                // Call output delegate if the caller only wants output.
                if (m_searchDetail.OutputOnly)
                {
                    m_searchDetail.OnSelection(m_output);
                    m_searchForm.Close();
                    return;
                }

                obj = Activator.CreateInstance(m_searchDetail.EditFormType, new object[] { m_output });
            }
            else
            {
                obj = Activator.CreateInstance(m_searchDetail.EditFormType,
                                               new object[] { RobotRepository.GetObjectByKey <T>(id) });
            }

            Form form = obj as Form;

            if (form != null)
            {
                form.MdiParent   = m_searchDetail.MdiParent;
                form.WindowState = FormWindowState.Normal;
                form.Show();
            }
        }
Exemplo n.º 2
0
    private void SetCsvForm(CsvForm csvForm)
    {
        m_CsvForm = csvForm;
        UpdateFormText();

        // 所有Csv窗口都被关闭
        if (m_CsvForm == null)
        {
            if (m_GotoForm != null && !m_GotoForm.IsDisposed)
            {
                m_GotoForm.Close();
            }
            if (m_SearchForm != null && !m_SearchForm.IsDisposed)
            {
                m_SearchForm.Close();
            }
        }
    }
Exemplo n.º 3
0
 public static void SearchView()
 {
     SearchForm?.Close();
     SearchForm = new SearchForm();
     SearchForm.Show();
 }
Exemplo n.º 4
0
        private void OnSearchExecute(object sender, EventArgs e)
        {
            //Perform search in all open databases
            m_dDBGroups = new Dictionary <PwDatabase, PwGroup>();
            PwGroup           g       = null;
            List <PwDatabase> lOpenDB = m_host.MainWindow.DocumentManager.GetOpenDatabases();

            m_btnOK.Click -= OnSearchExecute;
            List <string> lMsg = new List <string>();

            foreach (PwDatabase db in lOpenDB)
            {
                lMsg.Clear();
                lMsg.Add("DB: " + db.IOConnectionInfo.Path);
                if ((m_sf != null) && (m_sf.SearchResultsGroup != null) && (m_sf.SearchResultsGroup.Entries != null))
                {
                    lMsg.Add("Previos search results cleared: " + true.ToString());
                    m_sf.SearchResultsGroup.Entries.Clear();
                }
                m_sf.InitEx(db, db.RootGroup);
                FindInfo fi = SearchHelp.FindList.Find(x => x.Name == SearchHelp.SearchForm);
                if (fi.StandardEventHandlers.Count > 0)
                {
                    using (MonoWorkaroundDialogResult mwaDR = new MonoWorkaroundDialogResult(sender))
                    {
                        foreach (Delegate onclick in fi.StandardEventHandlers)
                        {
                            lMsg.Add("Calling method: " + onclick.Method.Name + " - " + onclick.Method.ReflectedType.Name);
                            onclick.DynamicInvoke(new object[] { sender, e });
                        }
                    }
                }
                else
                {
                    lMsg.Add("Calling standard method");
                    m_btnOK.PerformClick();
                }
                if ((m_sf.SearchResultsGroup == null) || (m_sf.SearchResultsGroup.Entries == null))
                {
                    lMsg.Add("Found entries: 0");
                }
                else
                {
                    lMsg.Add("Found entries: " + m_sf.SearchResultsGroup.Entries.UCount.ToString());
                }

                //Do NOT use m_sf.SearchResultsGroup.CloneDeep
                //It makes the virtual SearchResultsGroup the
                //parent group of the found entries
                if (g == null)
                {
                    g = new PwGroup(true, true, m_sf.SearchResultsGroup.Name, m_sf.SearchResultsGroup.IconId);
                }
                foreach (PwEntry pe in m_sf.SearchResultsGroup.Entries)
                {
                    g.AddEntry(pe, false);
                }
                PluginDebug.AddInfo("Executing search", 0, lMsg.ToArray());
            }

            //Don't continue if not even a single entry was found
            if ((g == null) || (g.GetEntriesCount(true) == 0))
            {
                if (m_sf.DialogResult == DialogResult.None)
                {
                    m_sf.DialogResult = DialogResult.OK;
                }
                return;
            }
            //Prepare ImageList (CustomIcons can be different per database)
            ImageList il  = new ImageList();
            ImageList il2 = (ImageList)Tools.GetField("m_ilCurrentIcons", m_host.MainWindow);

            foreach (Image img in il2.Images)
            {
                il.Images.Add(img);
            }
            Dictionary <PwEntry, int> dEntryIconIndex = new Dictionary <PwEntry, int>();
            PwDatabase dbFirst     = null;
            bool       bMultipleDB = false;

            foreach (PwEntry pe in g.Entries)
            {
                PwDatabase db = m_host.MainWindow.DocumentManager.FindContainerOf(pe);
                if (db == null)
                {
                    PluginDebug.AddError("Could not get database for entry", 0, pe.Uuid.ToHexString());
                    continue;
                }
                if (!m_dDBGroups.ContainsKey(db))
                {
                    m_dDBGroups[db] = new PwGroup(true, false, SearchHelp.GetDBName(pe), PwIcon.Folder)
                    {
                        IsVirtual = true
                    }
                }
                ;
                m_dDBGroups[db].AddEntry(pe, false);
                if (dbFirst == null)
                {
                    dbFirst = db;
                }
                bMultipleDB |= db != dbFirst;
                if (!pe.CustomIconUuid.Equals(PwUuid.Zero))
                {
                    il.Images.Add(db.GetCustomIcon(pe.CustomIconUuid, DpiUtil.ScaleIntX(16), DpiUtil.ScaleIntY(16)));
                    dEntryIconIndex[pe] = dEntryIconIndex.Count - 1;
                }
                else
                {
                    dEntryIconIndex[pe] = (int)pe.IconId;
                }
            }

            //If all found entries are contained in the same database
            //simply activate this database (might not be active yet) and return
            if (!bMultipleDB)
            {
                PwGroup pgSF = (PwGroup)Tools.GetField("m_pgResultsGroup", m_sf);
                if (pgSF != null)
                {
                    //clear list of found entries
                    //otherwise duplicates might be shown if last searched db is the only one that is to be shown
                    pgSF.Entries.Clear();
                    pgSF.Entries.Add(g.Entries);
                }
                else                 //KeePass 2.47
                {
                    pgSF           = new PwGroup(true, true, g.Name, g.IconId);
                    pgSF.IsVirtual = true;
                    pgSF.Entries.Add(g.Entries);
                }
                PluginDebug.AddInfo("Found " + pgSF.Entries.UCount.ToString() + " entries in 1 database");
                m_host.MainWindow.UpdateUI(false, m_host.MainWindow.DocumentManager.FindDocument(dbFirst), true, pgSF, false, null, false);
                il.Dispose();
                m_sf.SearchResultsGroup.Entries.Clear();
                m_sf.SearchResultsGroup.Entries.Add(pgSF.Entries);
                m_sf.DialogResult = DialogResult.OK;
                return;
            }

            //We found entries from at least 2 databases
            //Show the results in ListViewForm and close SearchForm
            try
            {
                PluginDebug.AddInfo("Found " + g.Entries.UCount.ToString() + " entries in multiple database");
                m_sf.DialogResult = DialogResult.Abort;
                m_sf.Visible      = false;
                m_sf.Close();
            }
            catch (Exception ex)
            {
                PluginDebug.AddError("Error closing searchform", new string[] { ex.Message });
            }

            m_aStandardLvInit = InitListViewMain;
            List <object> l = GetFoundEntriesList(g, dEntryIconIndex);

            ListViewForm dlg       = new ListViewForm();
            int          iCount    = l.FindAll(x => (x as ListViewItem) != null).Count;
            string       sSubTitle = iCount == 1 ? KPRes.SearchEntriesFound1 : KPRes.SearchEntriesFound;

            sSubTitle = sSubTitle.Replace("{PARAM}", iCount.ToString());
            dlg.InitEx(KPRes.Search, sSubTitle, null, null, l, il, InitListView);
            ShowMultiDBInfo(true);
            PluginDebug.AddInfo("Multi-DB results: Show", 0);
            if (dlg.ShowDialog(m_host.MainWindow) != DialogResult.OK)
            {
                PluginDebug.AddInfo("Multi-DB results: Shown", 0);
                UIUtil.DestroyForm(dlg);
                return;
            }
            PluginDebug.AddInfo("Multi-DB results: Show and navigate", 0);
            il.Dispose();
            NavigateToSelectedEntry(dlg, true);
            PluginDebug.AddInfo("Multi-DB results: Dispose form", 0);
            UIUtil.DestroyForm(dlg);
            PluginDebug.AddInfo("Multi-DB results: Disposed form", 0);
        }