Exemplo n.º 1
0
        /// <summary>
        /// 编辑hosts源点击
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnEditSource_Click(object sender, EventArgs e)
        {
            var source = lstSource.SelectedItem as HostsSource;

            if (source != null)
            {
                var form = new SourceEditForm
                {
                    Source = source,
                    Text   = @"添加Hosts源"
                };
                var re = form.ShowDialog();
                switch (re)
                {
                case DialogResult.OK:
                    try
                    {
                        //source = form.Source;
                        var n = HostsSourceManager.Instance.UpdateHostsSource(source);
                        if (n > 0)
                        {
                            LoadHostSource(source.Id);
                        }
                        else
                        {
                            Message("修改失败");
                        }
                    }
                    catch (ItemNotFoundException)
                    {
                        Message("找不到要修改的对象");
                    }
                    break;

                case DialogResult.Cancel:

                    break;
                }
            }
            lstSource.Focus();
            EnableControl(sender);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 添加hosts源点击
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddSource_Click(object sender, EventArgs e)
        {
            var form = new SourceEditForm();

            form.Text = @"添加Hosts源";
            var re = form.ShowDialog();

            switch (re)
            {
            case DialogResult.OK:
                try
                {
                    var source = form.Source;
                    var n      = HostsSourceManager.Instance.AddHostSource(source);
                    if (n != null)
                    {
                        LoadHostSource(n.Id);
                    }
                    else
                    {
                        Message("添加失败");
                    }
                }
                catch (ItemAlreadyExitedException)
                {
                    Message("相同Url的已存在");
                }
                catch (ItemOperationFaildException)
                {
                    Message("添加失败");
                }
                break;

            case DialogResult.Cancel:

                break;
            }
            lstSource.Focus();
            EnableControl(sender);
        }