www.pudn.com > Fetion.rar > GroupInviteForm.cs


namespace Imps.Client.Pc 
{ 
    using Imps.Client; 
    using Imps.Client.Core; 
    using Imps.Client.Pc.BizControls; 
    using Imps.Client.Pc.Controls; 
    using Imps.Client.Utils; 
    using Imps.Common; 
    using Imps.Utils; 
    using System; 
    using System.Collections.Generic; 
    using System.ComponentModel; 
    using System.Drawing; 
    using System.Windows.Forms; 
 
    public class GroupInviteForm : XIMDialog 
    { 
        private IFrameworkWindow _framework; 
        private InviteControl _inviteControl; 
        private PersonalGroup _inviteGroup; 
        private IContainer components; 
        private HtmlLabel lblInfo; 
        private AsyncBizOperation op; 
        private Panel pnlInvite; 
        private Panel pnlMain; 
        private XButton xbtnCancel; 
        private XButton xbtnSend; 
 
        public GroupInviteForm(IFrameworkWindow wnd, List selectedContacts, PersonalGroup group) 
        { 
            this.InitializeComponent(); 
            base.Controls.SetChildIndex(this.pnlMain, 0); 
            this._framework = wnd; 
            this._inviteGroup = group; 
            this.CurrentUser.StatusChanged += new EventHandler(this.CurrentUser_StatusChanged); 
            string str = StringHelper.EncodString(StringHelper.GetPaddingStringEndEllipsis(group.GroupInfo.Name.Value, 11)); 
            this.lblInfo.Text = string.Format("欢迎邀请您的好友加入群{1}({2})。用户未开通飞信服务,或使用旧版本客户端收不到邀请!", group.Uri.Raw, str, group.Uri.Id); 
            this.lblInfo.LabelLinkClick += new EventHandler(this.lblInfo_LabelLinkClick); 
            this._inviteControl = new InviteControl(wnd, selectedContacts, null, SelectContactsType.InviteJoinGroup); 
            int maxJoinGroupInviteCount = this.CurrentUser.Configuration.SystemSetting.GroupMsgSetting.MaxJoinGroupInviteCount; 
            this._inviteControl.Message = ""; 
            this._inviteControl.MaxSelectedCount = maxJoinGroupInviteCount; 
            this._inviteControl.Dock = DockStyle.Fill; 
            this._inviteControl.MessageLabelHeight = 1; 
            this._inviteControl.SearchTextboxAtTop = true; 
            this.pnlInvite.Controls.Add(this._inviteControl); 
            if ((this._inviteControl.SelectedContacts != null) && (this._inviteControl.SelectedContacts.Count > 0)) 
            { 
                this.xbtnSend.Enabled = true; 
            } 
            else 
            { 
                this.xbtnSend.Enabled = false; 
            } 
            this._inviteControl.SelectedContactsChanged += new EventHandler(this._inviteControl_SelectedContactsChanged); 
        } 
 
        private void _inviteControl_SelectedContactsChanged(object sender, EventArgs e) 
        { 
            try 
            { 
                if (((sender as InviteControl).SelectedContacts != null) && ((sender as InviteControl).SelectedContacts.Count > 0)) 
                { 
                    this.xbtnSend.Enabled = true; 
                } 
                else 
                { 
                    this.xbtnSend.Enabled = false; 
                } 
            } 
            catch (Exception exception) 
            { 
                ClientLogger.WriteException(exception); 
            } 
        } 
 
        private void CurrentUser_StatusChanged(object sender, UserSatusChangedEventArgs e) 
        { 
            try 
            { 
                if (e.NewStatus != UserAccountStatus.Logon) 
                { 
                    base.Close(); 
                } 
            } 
            catch (Exception exception) 
            { 
                ClientLogger.WriteException(exception); 
            } 
        } 
 
        protected override void Dispose(bool disposing) 
        { 
            if (disposing && (this.components != null)) 
            { 
                this.components.Dispose(); 
            } 
            base.Dispose(disposing); 
        } 
 
        private void InitializeComponent() 
        { 
            this.pnlMain = new Panel(); 
            this.pnlInvite = new Panel(); 
            this.lblInfo = new HtmlLabel(); 
            this.xbtnCancel = new XButton(); 
            this.xbtnSend = new XButton(); 
            this.pnlMain.SuspendLayout(); 
            base.SuspendLayout(); 
            this.pnlMain.BackColor = Color.Transparent; 
            this.pnlMain.Controls.Add(this.pnlInvite); 
            this.pnlMain.Controls.Add(this.lblInfo); 
            this.pnlMain.Location = new System.Drawing.Point(7, 3); 
            this.pnlMain.Name = "pnlMain"; 
            this.pnlMain.Size = new Size(0x13b, 0x1f5); 
            this.pnlMain.TabIndex = 0; 
            this.pnlInvite.Location = new System.Drawing.Point(11, 0x34); 
            this.pnlInvite.Name = "pnlInvite"; 
            this.pnlInvite.Size = new Size(0x125, 440); 
            this.pnlInvite.TabIndex = 2; 
            this.lblInfo.LinkColor = Color.Blue; 
            this.lblInfo.Location = new System.Drawing.Point(11, 8); 
            this.lblInfo.Name = "lblInfo"; 
            this.lblInfo.ShowBackgroundImage = false; 
            this.lblInfo.Size = new Size(0x125, 0x27); 
            this.lblInfo.TabIndex = 1; 
            this.lblInfo.Text = "欢迎邀请您的好友加入群。"; 
            this.xbtnCancel.AutoArrangementX = true; 
            this.xbtnCancel.AutoSizeToImage = false; 
            this.xbtnCancel.BackColor = Color.Transparent; 
            this.xbtnCancel.BackgroundImageDisable = null; 
            this.xbtnCancel.BackgroundImageDown = null; 
            this.xbtnCancel.BackgroundImageHover = null; 
            this.xbtnCancel.ChangeSkin = true; 
            this.xbtnCancel.DialogResult = DialogResult.Cancel; 
            this.xbtnCancel.Location = new System.Drawing.Point(0xf7, 510); 
            this.xbtnCancel.Name = "xbtnCancel"; 
            this.xbtnCancel.Size = new Size(0x4b, 0x17); 
            this.xbtnCancel.TabIndex = 4; 
            this.xbtnCancel.Text = "取消"; 
            this.xbtnCancel.UseVisualStyleBackColor = false; 
            this.xbtnCancel.Click += new EventHandler(this.xbtnCancel_Click); 
            this.xbtnSend.AutoArrangementX = true; 
            this.xbtnSend.AutoSizeToImage = false; 
            this.xbtnSend.BackColor = Color.Transparent; 
            this.xbtnSend.BackgroundImageDisable = null; 
            this.xbtnSend.BackgroundImageDown = null; 
            this.xbtnSend.BackgroundImageHover = null; 
            this.xbtnSend.ChangeSkin = true; 
            this.xbtnSend.Location = new System.Drawing.Point(0xa4, 510); 
            this.xbtnSend.Name = "xbtnSend"; 
            this.xbtnSend.Size = new Size(0x4b, 0x17); 
            this.xbtnSend.TabIndex = 3; 
            this.xbtnSend.Text = "确定"; 
            this.xbtnSend.UseVisualStyleBackColor = false; 
            this.xbtnSend.Click += new EventHandler(this.xbtnSend_Click); 
            base.AutoScaleDimensions = new SizeF(6f, 13f); 
            base.AutoScaleMode = AutoScaleMode.Font; 
            base.BaseHeight = 0x21d; 
            base.BaseWidth = 0x153; 
            base.ClientSize = new Size(0x153, 0x21d); 
            base.Controls.Add(this.xbtnCancel); 
            base.Controls.Add(this.pnlMain); 
            base.Controls.Add(this.xbtnSend); 
            base.DisplayLocation = new System.Drawing.Point(15, 15); 
            base.DisplaySize = new Size(0x153, 0x21d); 
            base.Name = "GroupInviteForm"; 
            base.Padding = new Padding(4, 0, 4, 0x2b); 
            base.Text = "邀请飞信好友加入群"; 
            base.CancelButton = this.xbtnCancel; 
            this.pnlMain.ResumeLayout(false); 
            base.ResumeLayout(false); 
        } 
 
        private void lblInfo_LabelLinkClick(object sender, LabelLinkClickEventArgs e) 
        { 
            try 
            { 
                if (!string.IsNullOrEmpty(e.Url)) 
                { 
                    IicUri uri = new IicUri(e.Url); 
                    PersonalGroup group = this.CurrentUser.PersonalGroups[uri]; 
                    if (group != null) 
                    { 
                        this._framework.PersonalGroupManager.ShowGroupSetting(this, group, GroupOption.Normal); 
                    } 
                } 
            } 
            catch (Exception exception) 
            { 
                ClientLogger.WriteException(exception); 
            } 
        } 
 
        private void op_ImpsError(object sender, ImpsErrorEventArgs e) 
        { 
            try 
            { 
                this._framework.UnifiedMessageBox.ShowError(e.Summary); 
                base.Close(); 
            } 
            catch (Exception exception) 
            { 
                ClientLogger.WriteException(exception); 
            } 
        } 
 
        private void op_Successed(object sender, EventArgs e) 
        { 
            try 
            { 
                this._framework.UnifiedMessageBox.ShowInfo(string.Format("邀请飞信好友加入群{0}({1})已经发送成功!", this._inviteGroup.GroupInfo.Name.Value, this._inviteGroup.Uri.Id)); 
                base.Close(); 
            } 
            catch (Exception exception) 
            { 
                ClientLogger.WriteException(exception); 
            } 
        } 
 
        private void xbtnCancel_Click(object sender, EventArgs e) 
        { 
            base.Close(); 
        } 
 
        private void xbtnSend_Click(object sender, EventArgs e) 
        { 
            try 
            { 
                if (this._inviteControl.SelectedContacts.Count <= 0) 
                { 
                    this._framework.UnifiedMessageBox.ShowError("请至少选择一个联系人!"); 
                } 
                else 
                { 
                    this.op = new AsyncBizOperation(); 
                    this.op.ImpsError += new EventHandler(this.op_ImpsError); 
                    this.op.Successed += new EventHandler(this.op_Successed); 
                    this.CurrentUser.PersonalGroupManager.AsyncInviteFriends(this._inviteControl.SelectedContacts, this._inviteGroup, this.op); 
                    this.xbtnSend.Enabled = false; 
                } 
            } 
            catch (Exception exception) 
            { 
                ClientLogger.WriteException(exception); 
            } 
        } 
 
        private User CurrentUser 
        { 
            get 
            { 
                return this._framework.AccountManager.CurrentUser; 
            } 
        } 
    } 
}