Esempio n. 1
0
        public void InitListView()
        {
            //init ListView control
            listView_ProcessRights.Clear();             //clear control
            //create column header for ListView
            listView_ProcessRights.Columns.Add("#", 20, System.Windows.Forms.HorizontalAlignment.Left);
            listView_ProcessRights.Columns.Add("Process Name", 350, System.Windows.Forms.HorizontalAlignment.Left);
            listView_ProcessRights.Columns.Add("Process Id", 100, System.Windows.Forms.HorizontalAlignment.Left);
            listView_ProcessRights.Columns.Add("Access Rights", 150, System.Windows.Forms.HorizontalAlignment.Left);

            foreach (ProcessRight processRight in processRights.Values)
            {
                string[] itemStr = new string[listView_ProcessRights.Columns.Count];
                itemStr[0] = listView_ProcessRights.Items.Count.ToString();
                itemStr[1] = processRight.ProcessName;
                itemStr[2] = processRight.ProcessId.ToString();
                itemStr[3] = processRight.AccessFlag.ToString();

                ListViewItem item = new ListViewItem(itemStr, 0);
                item.Tag = processRight;
                listView_ProcessRights.Items.Add(item);

                selectedProcessRight = processRight;
            }
        }
Esempio n. 2
0
        private void button_SaveProcessRight_Click(object sender, EventArgs e)
        {
            if (textBox_ProcessName.Text.Trim().Length == 0 && (textBox_ProcessId.Text.Length == 0 || textBox_ProcessId.Text == "0"))
            {
                MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
                MessageBox.Show("The process name and process Id can't be empty.", "Save settings", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            string[] processList = textBox_ProcessName.Text.ToLower().Split(new char[] { ';' });
            uint     accessFlag  = uint.Parse(textBox_AccessFlag.Text);

            if (processList.Length > 0)
            {
                foreach (string processName in processList)
                {
                    if (processName.Trim().Length > 0)
                    {
                        processRights.Remove(processName);
                        ProcessRight processRight = new ProcessRight();
                        processRight.ProcessName = processName;
                        processRight.ProcessId   = 0;
                        processRight.AccessFlag  = accessFlag;

                        processRights.Add(processName, processRight);
                    }
                }
            }

            string[] processIdList = textBox_ProcessId.Text.Split(new char[] { ';' });
            if (processIdList.Length > 0)
            {
                foreach (string processId in processIdList)
                {
                    uint pid = 0;

                    if (uint.TryParse(processId, out pid) && pid > 0)
                    {
                        processRights.Remove(processId);

                        ProcessRight processRight = new ProcessRight();
                        processRight.ProcessName = "";
                        processRight.ProcessId   = uint.Parse(processId);
                        processRight.AccessFlag  = accessFlag;

                        processRights.Add(processId, processRight);
                    }
                }
            }

            InitListView();
        }
Esempio n. 3
0
        private void listView_ProcessRights_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listView_ProcessRights.SelectedItems.Count > 0)
            {
                ProcessRight processRight = (ProcessRight)listView_ProcessRights.SelectedItems[0].Tag;

                textBox_AccessFlag.Text  = processRight.AccessFlag.ToString();
                textBox_ProcessName.Text = processRight.ProcessName;
                textBox_ProcessId.Text   = processRight.ProcessId.ToString();

                SetCheckBoxValue();
            }
        }
Esempio n. 4
0
        private void button_Delete_Click(object sender, EventArgs e)
        {
            if (listView_ProcessRights.SelectedItems.Count == 0)
            {
                MessageBoxHelper.PrepToCenterMessageBoxOnForm(this);
                MessageBox.Show("There are no process selected.", "Delete process", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            ProcessRight processRight = (ProcessRight)listView_ProcessRights.SelectedItems[0].Tag;

            if (processRight.ProcessId > 0)
            {
                processRights.Remove(processRight.ProcessId.ToString());
            }
            else
            {
                processRights.Remove(processRight.ProcessName.ToString());
            }

            InitListView();
        }
Esempio n. 5
0
        public Form_ProcessRights(ref FilterRule filterRule)
        {
            InitializeComponent();
            currentFilterRule = filterRule;

            StartPosition = FormStartPosition.CenterParent;

            string[] processRightList = filterRule.ProcessRights.ToLower().Split(new char[] { ';' });
            if (processRightList.Length > 0)
            {
                foreach (string processRightStr in processRightList)
                {
                    if (processRightStr.Trim().Length > 0)
                    {
                        string processName = processRightStr.Substring(0, processRightStr.IndexOf('!'));
                        uint   accessFlag  = uint.Parse(processRightStr.Substring(processRightStr.IndexOf('!') + 1));

                        if (!processRights.ContainsKey(processName))
                        {
                            ProcessRight processRight = new ProcessRight();
                            processRight.ProcessName = processName;
                            processRight.ProcessId   = 0;
                            processRight.AccessFlag  = accessFlag;

                            processRights.Add(processName, processRight);
                        }

                        textBox_ProcessName.Text = processName;
                        textBox_AccessFlag.Text  = accessFlag.ToString();
                    }
                }
            }

            string[] processIdList = filterRule.ProcessIdRights.Split(new char[] { ';' });
            if (processIdList.Length > 0)
            {
                foreach (string processIdRightStr in processIdList)
                {
                    if (processIdRightStr.Trim().Length > 0)
                    {
                        string processId  = processIdRightStr.Substring(0, processIdRightStr.IndexOf('!'));
                        uint   accessFlag = uint.Parse(processIdRightStr.Substring(processIdRightStr.IndexOf('!') + 1));

                        if (!processRights.ContainsKey(processId))
                        {
                            ProcessRight processRight = new ProcessRight();
                            processRight.ProcessName = "";
                            processRight.ProcessId   = uint.Parse(processId);
                            processRight.AccessFlag  = accessFlag;

                            processRights.Add(processId, processRight);
                        }

                        textBox_ProcessId.Text  = processId;
                        textBox_AccessFlag.Text = accessFlag.ToString();
                    }
                }
            }

            InitListView();
            SetCheckBoxValue();
        }