⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 psblacklist.cs

📁 飞信的收发使用csharp进行开发
💻 CS
字号:
namespace Imps.Client.Pc.Options
{
    using Imps.Client.Core;
    using Imps.Client.Pc;
    using Imps.Client.Pc.BizControls;
    using Imps.Client.Pc.Controls;
    using Imps.Client.Resource;
    using Imps.Common;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;

    public class PsBlackList : OptionsControlBase
    {
        private List<Imps.Client.Core.Contact> _contacts;
        private IFrameworkWindow _iFrameworkWindow;
        private XButton btnRemove;
        private IContainer components;
        private XLabel lbBlackList;
        private XLabel lbBlackListTips;
        private listbox_widget_t<headicon> lsBlackList;
        private int selIndex;

        public PsBlackList() : this(null)
        {
        }

        public PsBlackList(IFrameworkWindow frmWnd)
        {
            this._iFrameworkWindow = frmWnd;
            this.InitializeComponent();
            headiconlist_drawer _drawer = new headiconlist_drawer();
            _drawer.stretch_textarea = true;
            _drawer.noicon_string_alignment = StringAlignment.Near;
            _drawer.item_height = 20;
            this.lsBlackList.drawer = _drawer;
            this.LoadResource();
            this.lsBlackList.Items.Clear();
        }

        private void BlackList_Changed(object sender, EventArgs e)
        {
            this.displayBlackList();
        }

        private void btnRemove_Click(object sender, EventArgs e)
        {
            try
            {
                int selectedIndex = this.lsBlackList.SelectedIndex;
                if ((selectedIndex > -1) && (this._contacts != null))
                {
                    this.selIndex = selectedIndex;
                    Imps.Client.Core.Contact contact = this._contacts[this.lsBlackList.SelectedIndex];
                    AsyncBizOperation op = new AsyncBizOperation();
                    this._user.ContactList.AsyncRemoveFromBlackList(new string[] { contact.Uri.Raw }, op);
                }
            }
            catch
            {
            }
        }

        private void ClearContacts()
        {
            if (this._contacts != null)
            {
                foreach (Imps.Client.Core.Contact contact in this._contacts)
                {
                    contact.PersonalInfo.PropertiesChanged -= new EventHandler<PropertiesChangedEventArgs>(this.PersonalInfo_PropertiesChanged);
                }
                this._contacts = null;
            }
        }

        public override bool ControlLoad()
        {
            this._user.BlackList.Changed += new EventHandler(this.BlackList_Changed);
            return true;
        }

        public override bool ControlUnload()
        {
            this._user.BlackList.Changed -= new EventHandler(this.BlackList_Changed);
            this.ClearContacts();
            return base.ControlUnload();
        }

        private void displayBlackList()
        {
            this.lsBlackList.Items.Clear();
            this.ClearContacts();
            this._contacts = new List<Imps.Client.Core.Contact>();
            Imps.Client.Core.ContactCollection contacts = new Imps.Client.Core.ContactCollection();
            lock (this._user.BlackList.SyncRoot)
            {
                foreach (IicUri uri in this._user.BlackList)
                {
                    Imps.Client.Core.Contact item = this._user.ContactList.FindOrCreateContact(uri.Raw, new AsyncBizOperation(), false);
                    item.PersonalInfo.PropertiesChanged += new EventHandler<PropertiesChangedEventArgs>(this.PersonalInfo_PropertiesChanged);
                    this._contacts.Add(item);
                    contacts.Add(item);
                }
            }
            AsyncBizOperation op = new AsyncBizOperation();
            op.IsImpsErrorHandled = true;
            this._user.ContactList.AsyncGetContactsInfo(contacts, op, null, false, new string[] { "nickname" });
            this.lsBlackList.BeginUpdate();
            if (this._contacts != null)
            {
                foreach (Imps.Client.Core.Contact contact2 in this._contacts)
                {
                    string text = this.getDisplayString(contact2);
                    this.lsBlackList.add(new headicon(null, text, text));
                }
            }
            this.lsBlackList.EndUpdate();
            if (this.selIndex > 0)
            {
                this.lsBlackList.SelectedIndex = --this.selIndex;
            }
            else if (this.lsBlackList.Items.Count > 0)
            {
                this.lsBlackList.SelectedIndex = 0;
            }
            this.btnRemove.Enabled = this.lsBlackList.Items.Count > 0;
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private string getDisplayString(Imps.Client.Core.Contact contact)
        {
            if (contact.Type != ContactType.Stranger)
            {
                if (contact.Type == ContactType.Buddy)
                {
                    return (contact.DisplayName + string.Format(StringTable.BlackList.BuddyTitle, contact.Uri.Sid));
                }
                if (contact.Type == ContactType.MobileBuddy)
                {
                    return (contact.DisplayName + string.Format(StringTable.BlackList.MobileBuddyTitle, contact.PersonalInfo.MobileNo));
                }
                if (contact.Type == ContactType.Vodafone)
                {
                    return (contact.DisplayName + string.Format(StringTable.BlackList.VodafoneTitle, contact.Uri.Id));
                }
            }
            else
            {
                if (contact.Uri.IsImpsContactUri)
                {
                    if (contact.Uri.Belongs(IicUriType.ImpsContactSip))
                    {
                        return (contact.DisplayName + string.Format(StringTable.BlackList.ImpsContactTitle, contact.Uri.Sid));
                    }
                    return (contact.DisplayName + string.Format(StringTable.BlackList.MobileTitle, contact.Uri.MobileNo));
                }
                if (contact.Uri.IsVodafoneUri)
                {
                    return (contact.DisplayName + string.Format(StringTable.BlackList.VodafoneTitle, contact.Uri.Id));
                }
            }
            return (contact.DisplayName + string.Format(StringTable.BlackList.ContactTitle, contact.Uri.Id));
        }

        private void InitializeComponent()
        {
            headiconlist_drawer _drawer = new headiconlist_drawer();
            this.lbBlackList = new XLabel();
            this.lbBlackListTips = new XLabel();
            this.btnRemove = new XButton();
            this.lsBlackList = new listbox_widget_t<headicon>();
            XLabel label = new XLabel();
            base.SuspendLayout();
            label.AutoEllipsis = false;
            label.BorderColor = Color.Black;
            label.BorderStyle = BorderStyle.Fixed3D;
            label.ButtonBorderStyle = ButtonBorderStyle.Solid;
            label.Location = new Point(0x34, 15);
            label.Name = "lbLine";
            label.Size = new Size(320, 2);
            label.TabIndex = 7;
            label.TextAlign = ContentAlignment.TopLeft;
            label.UseMnemonic = false;
            this.lbBlackList.AutoEllipsis = false;
            this.lbBlackList.AutoSize = true;
            this.lbBlackList.BorderColor = Color.Black;
            this.lbBlackList.BorderStyle = BorderStyle.None;
            this.lbBlackList.ButtonBorderStyle = ButtonBorderStyle.Solid;
            this.lbBlackList.Location = new Point(5, 9);
            this.lbBlackList.Name = "lbBlackList";
            this.lbBlackList.Size = new Size(0x2b, 14);
            this.lbBlackList.TabIndex = 0;
            this.lbBlackList.Text = "黑名单";
            this.lbBlackList.TextAlign = ContentAlignment.TopLeft;
            this.lbBlackList.UseMnemonic = false;
            this.lbBlackListTips.AutoEllipsis = false;
            this.lbBlackListTips.BorderColor = Color.Black;
            this.lbBlackListTips.BorderStyle = BorderStyle.None;
            this.lbBlackListTips.ButtonBorderStyle = ButtonBorderStyle.Solid;
            this.lbBlackListTips.Location = new Point(0x13, 0x1d);
            this.lbBlackListTips.Name = "lbBlackListTips";
            this.lbBlackListTips.Size = new Size(300, 0x29);
            this.lbBlackListTips.TabIndex = 1;
            this.lbBlackListTips.Text = "下列黑名单中的人不能看到您的在线状态,且不能向您发送消息。";
            this.lbBlackListTips.TextAlign = ContentAlignment.TopLeft;
            this.lbBlackListTips.UseMnemonic = false;
            this.btnRemove.Location = new Point(0x117, 0x3d);
            this.btnRemove.Name = "btnRemove";
            this.btnRemove.Size = new Size(0x4b, 0x17);
            this.btnRemove.TabIndex = 3;
            this.btnRemove.Text = "移出黑名单";
            this.btnRemove.Click += new EventHandler(this.btnRemove_Click);
            _drawer.border_color = Color.Gray;
            _drawer.drawmode = DrawMode.OwnerDrawVariable;
            _drawer.font = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0x86);
            _drawer.item_height = 0x1a;
            _drawer.noicon_string_alignment = StringAlignment.Center;
            _drawer.show_focus = true;
            _drawer.stretch_textarea = false;
            this.lsBlackList.drawer = _drawer;
            this.lsBlackList.DrawMode = DrawMode.OwnerDrawVariable;
            this.lsBlackList.FormattingEnabled = true;
            this.lsBlackList.Location = new Point(0x15, 0x3d);
            this.lsBlackList.Name = "lsBlackList";
            this.lsBlackList.Size = new Size(0xfc, 0x170);
            this.lsBlackList.TabIndex = 8;
            this.lsBlackList.BorderStyle = BorderStyle.FixedSingle;
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.Controls.Add(this.lsBlackList);
            base.Controls.Add(this.lbBlackList);
            base.Controls.Add(label);
            base.Controls.Add(this.btnRemove);
            base.Controls.Add(this.lbBlackListTips);
            base.Name = "PsBlackList";
            base.Size = new Size(0x16b, 0x1b1);
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        private void LoadResource()
        {
        }

        private void PersonalInfo_PropertiesChanged(object sender, PropertiesChangedEventArgs e)
        {
            Imps.Client.Core.ContactInfo info = sender as Imps.Client.Core.ContactInfo;
            if (((info != null) && (this._contacts != null)) && e.ContainsAnyOfProperties(new string[] { "name", "nickname" }))
            {
                Imps.Client.Core.Contact owner = info.Owner;
                int index = this._contacts.IndexOf(owner);
                if (index != -1)
                {
                    ((headicon) this.lsBlackList.Items[index]).text = this.getDisplayString(owner);
                }
            }
        }

        public override bool UpdateData(bool update)
        {
            if (!update)
            {
                this.displayBlackList();
                this.btnRemove.Enabled = this.lsBlackList.Items.Count > 0;
            }
            base.Modified = false;
            return true;
        }

        private Imps.Client.Core.User _user
        {
            get
            {
                return this._iFrameworkWindow.AccountManager.CurrentUser;
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -