Esempio n. 1
0
        private void AddDisplayPanel(Form formToDisplay, string title)
        {
            ResetDisplayPanel();
            if (CsomBase.CurrentUser == null)
            {
                if (!HandleLogin())
                {
                    return;
                }
            }
            LBL_MainText.Text = title;
            LBL_MainText.Show();

            FlowLayoutPanel existingPanel = _panelCache.FirstOrDefault(p => p.Name == formToDisplay.Name);

            if (existingPanel != null)
            {
                existingPanel.Controls[0].Visible = true;
                existingPanel.Visible             = true;
                Log.WriteVerbose(new SourceInfo(), "Found pre-loaded form:{0}", formToDisplay.Name);
            }
            else
            {
                Log.WriteVerbose(new SourceInfo(), "No existing form:{0}. Creating a new panel and loading the form.", formToDisplay.Name);
                existingPanel = new FlowLayoutPanel
                {
                    Name     = formToDisplay.Name,
                    Dock     = DockStyle.Fill,
                    Anchor   = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top,
                    AutoSize = true
                };
                existingPanel.Resize         += FlowLayoutPanel_Resize;
                existingPanel.Tag             = "DisplayForm";
                formToDisplay.TopLevel        = false;
                formToDisplay.StartPosition   = FormStartPosition.Manual;
                formToDisplay.FormBorderStyle = FormBorderStyle.None;
                formToDisplay.Padding         = new Padding(0, 0, 13, 8);
                TLP_Main.Controls.Add(existingPanel, 0, 2);
                formToDisplay.Show();
                existingPanel.Controls.Add(formToDisplay);
                FlowLayoutPanel_Resize(existingPanel, null);
                existingPanel.Focus();
                _panelCache.Add(existingPanel);
            }
        }
Esempio n. 2
0
        private bool HandleLogin()
        {
            bool loginSucess = false;

            LBL_MainText.Hide();
            foreach (Control ctrl in TLP_Main.Controls)
            {
                if (!(ctrl is FlowLayoutPanel) || ctrl.Tag == null || ctrl.Tag.ToString() != "DisplayForm")
                {
                    continue;
                }
                FlowLayoutPanel flp = ctrl as FlowLayoutPanel;
                Log.WriteVerbose(new SourceInfo(), "Clearing Panel:{0} and its controls", flp.Name);
                flp.Controls.Clear();
                _panelCache.Remove(ctrl as FlowLayoutPanel);
                TLP_Main.Controls.Remove(ctrl);
            }

            CsomBase.ClearCsomObjects();
            ResetDisplayPanel();
            using (LoginPage lgf = new LoginPage())
            {
                lgf.StartPosition = FormStartPosition.CenterParent;
                DialogResult dr = lgf.ShowDialog(this);
                if (dr != DialogResult.Cancel)
                {
                    Log.WriteVerbose(new SourceInfo(), "Login successful. Displaying user properties on the main form header.");
                    TB_DisplayName.Text = CsomBase.CurrentUser.Title;
                    TB_UserName.Text    = CsomBase.CurrentUser.LoginName;
                    TB_Email.Text       = CsomBase.CurrentUser.Email;
                    TB_Url.Text         = CsomBase.CurrentUser.Context.Url;
                    loginSucess         = true;
                }
                else
                {
                    Log.WriteVerbose(new SourceInfo(), "Login failed.");
                }
            }
            return(loginSucess);
        }