Esempio n. 1
0
        public static void UpdateFuncAssign(string Form, string Control, string active)
        {
            try
            {
                Form form = Application.OpenForms[Form];

                if (form == null)
                {
                    return;
                }

                if (form.InvokeRequired)
                {
                    UpdateFuncEnable_D ph = new UpdateFuncEnable_D(UpdateFuncAssign);
                    form.BeginInvoke(ph, Form, Control, active);
                }
                else
                {
                    Control control = form.Controls.Find(Control, true).FirstOrDefault() as Control;
                    if (control != null)
                    {
                        switch (active)
                        {
                        case "Y":
                            control.Enabled = true;
                            break;

                        case "N":
                            control.Enabled = false;
                            break;
                        }
                    }
                }
            }
            catch
            {
                logger.Error("UpdateFuncAssign: Update fail.");
            }
        }
Esempio n. 2
0
        public static void UpdateFuncAssign(string Form, string Control, string active)
        {
            try
            {
                Form form = Application.OpenForms[Form];

                if (form == null)
                {
                    return;
                }

                if (form.InvokeRequired)
                {
                    UpdateFuncEnable_D ph = new UpdateFuncEnable_D(UpdateFuncAssign);
                    form.BeginInvoke(ph, Form, Control, active);
                }
                else
                {
                    //20190531 Add tab controller 移除頁面功能
                    if (Control.IndexOf(".") > 0)
                    {
                        string     tabCtrlName = Control.Substring(0, Control.IndexOf("."));
                        TabControl control     = form.Controls.Find(tabCtrlName, true).FirstOrDefault() as TabControl;
                        string     tabPageName = Control.Substring(Control.IndexOf(".") + 1);
                        tabPages.TryGetValue(tabPageName, out TabPage foo);
                        if (control != null && foo != null)
                        {
                            switch (active)
                            {
                            case "Y":
                                if (!control.Contains(foo))
                                {
                                    control.TabPages.Add(foo);
                                }
                                break;

                            case "N":
                                if (control.Contains(foo))
                                {
                                    control.TabPages.Remove(foo);
                                }
                                break;
                            }
                        }
                        else
                        {
                            MessageBox.Show("Control not found. Form:" + Form + " Control:" + tabPageName + " active" + active);
                        }
                    }
                    else
                    {
                        Control control = form.Controls.Find(Control, true).FirstOrDefault() as Control;
                        if (control != null)
                        {
                            switch (active)
                            {
                            case "Y":
                                control.Enabled = true;
                                break;

                            case "N":
                                control.Enabled = false;
                                break;
                            }
                        }
                        else
                        {
                            MessageBox.Show("Control not found. Form:" + Form + " Control:" + Control + " active" + active);
                        }
                    }
                }
            }
            catch
            {
                logger.Error("UpdateFuncAssign: Update fail. Form:" + Form + " Control:" + Control + " active" + active);
            }
        }