www.pudn.com > Fetion.rar > BeInvitedForm.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.Resource; 
    using Imps.Client.Utils; 
    using Imps.Common; 
    using Imps.Utils; 
    using System; 
    using System.ComponentModel; 
    using System.Drawing; 
    using System.Windows.Forms; 
 
    public class BeInvitedForm : XIMDialog 
    { 
        private IFrameworkWindow _framework; 
        private PersonalGroup _inviteGroup; 
        private Imps.Client.Core.Contact _inviter; 
        private IContainer components; 
        private HtmlLabel lblInviteInfo; 
        private AsyncBizOperation op; 
        private PictureBox picPortrait; 
        private Panel pnlMain; 
        private Panel pnlPortrait; 
        private XButton xbtnCancel; 
        private XButton xbtnJoin; 
 
        public BeInvitedForm(IFrameworkWindow wnd, PersonalGroup group, Imps.Client.Core.Contact inviter) 
        { 
            this._framework = wnd; 
            this._inviteGroup = group; 
            this._inviter = inviter; 
            this.InitializeComponent(); 
            base.Controls.SetChildIndex(this.pnlMain, 0); 
            this.picPortrait.Image = ImpsPortrait.GetDefaultGroupPortrait(0x60, 0x60); 
            this.UpdateInfo(group, inviter); 
            this.lblInviteInfo.LabelLinkClick += new EventHandler(this.lblInviteInfo_LabelLinkClick); 
            this._inviteGroup.GroupInfo.PropertiesChanged += new EventHandler(this.GroupInfo_PropertiesChanged); 
            this._framework.AccountManager.CurrentUser.StatusChanged += new EventHandler(this.CurrentUser_StatusChanged); 
        } 
 
        private void BeInvitedForm_FormClosed(object sender, FormClosedEventArgs e) 
        { 
            try 
            { 
                this._inviteGroup.GroupInfo.PropertiesChanged -= new EventHandler(this.GroupInfo_PropertiesChanged); 
                this._framework.AccountManager.CurrentUser.StatusChanged -= new EventHandler(this.CurrentUser_StatusChanged); 
            } 
            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 GroupInfo_PropertiesChanged(object sender, PropertiesChangedEventArgs e) 
        { 
            try 
            { 
                this.picPortrait.Image = (Image) this._inviteGroup.GroupInfo.Portrait; 
            } 
            catch (Exception exception) 
            { 
                ClientLogger.WriteException(exception); 
            } 
        } 
 
        private void InitializeComponent() 
        { 
            this.pnlMain = new Panel(); 
            this.lblInviteInfo = new HtmlLabel(); 
            this.pnlPortrait = new Panel(); 
            this.picPortrait = new PictureBox(); 
            this.xbtnJoin = new XButton(); 
            this.xbtnCancel = new XButton(); 
            this.pnlMain.SuspendLayout(); 
            this.pnlPortrait.SuspendLayout(); 
            ((ISupportInitialize) this.picPortrait).BeginInit(); 
            base.SuspendLayout(); 
            this.pnlMain.BackColor = Color.Transparent; 
            this.pnlMain.Controls.Add(this.lblInviteInfo); 
            this.pnlMain.Controls.Add(this.pnlPortrait); 
            this.pnlMain.Location = new System.Drawing.Point(5, 3); 
            this.pnlMain.Name = "pnlMain"; 
            this.pnlMain.Size = new Size(0x189, 0x8b); 
            this.pnlMain.TabIndex = 0; 
            this.lblInviteInfo.LinkColor = Color.Blue; 
            this.lblInviteInfo.Location = new System.Drawing.Point(0x5f, 0x2f); 
            this.lblInviteInfo.Name = "lblInviteInfo"; 
            this.lblInviteInfo.ShowBackgroundImage = false; 
            this.lblInviteInfo.Size = new Size(0x11f, 0x27); 
            this.lblInviteInfo.TabIndex = 1; 
            this.lblInviteInfo.Text = "邀请加入"; 
            this.pnlPortrait.BackColor = Color.Silver; 
            this.pnlPortrait.Controls.Add(this.picPortrait); 
            this.pnlPortrait.Location = new System.Drawing.Point(15, 0x22); 
            this.pnlPortrait.Name = "pnlPortrait"; 
            this.pnlPortrait.Padding = new Padding(1); 
            this.pnlPortrait.Size = new Size(0x40, 0x40); 
            this.pnlPortrait.TabIndex = 0; 
            this.picPortrait.BackColor = Color.White; 
            this.picPortrait.Dock = DockStyle.Fill; 
            this.picPortrait.Location = new System.Drawing.Point(1, 1); 
            this.picPortrait.Name = "picPortrait"; 
            this.picPortrait.Size = new Size(0x3e, 0x3e); 
            this.picPortrait.SizeMode = PictureBoxSizeMode.StretchImage; 
            this.picPortrait.TabIndex = 1; 
            this.picPortrait.TabStop = false; 
            this.xbtnJoin.AutoArrangementX = true; 
            this.xbtnJoin.AutoSizeToImage = false; 
            this.xbtnJoin.BackColor = Color.Transparent; 
            this.xbtnJoin.BackgroundImageDisable = null; 
            this.xbtnJoin.BackgroundImageDown = null; 
            this.xbtnJoin.BackgroundImageHover = null; 
            this.xbtnJoin.ChangeSkin = true; 
            this.xbtnJoin.Location = new System.Drawing.Point(0xf2, 0x94); 
            this.xbtnJoin.Name = "xbtnJoin"; 
            this.xbtnJoin.Size = new Size(0x4b, 0x17); 
            this.xbtnJoin.TabIndex = 1; 
            this.xbtnJoin.Text = "加入"; 
            this.xbtnJoin.UseVisualStyleBackColor = false; 
            this.xbtnJoin.Click += new EventHandler(this.xbtnJoin_Click); 
            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(0x143, 0x94); 
            this.xbtnCancel.Name = "xbtnCancel"; 
            this.xbtnCancel.Size = new Size(0x4b, 0x17); 
            this.xbtnCancel.TabIndex = 2; 
            this.xbtnCancel.Text = "取消"; 
            this.xbtnCancel.UseVisualStyleBackColor = false; 
            this.xbtnCancel.Click += new EventHandler(this.xbtnCancel_Click); 
            base.AutoScaleDimensions = new SizeF(6f, 13f); 
            base.AutoScaleMode = AutoScaleMode.Font; 
            base.BaseHeight = 0xb6; 
            base.BaseWidth = 0x195; 
            base.CancelButton = this.xbtnCancel; 
            base.ClientSize = new Size(0x195, 0xb6); 
            base.Controls.Add(this.xbtnCancel); 
            base.Controls.Add(this.xbtnJoin); 
            base.Controls.Add(this.pnlMain); 
            base.DisplayLocation = new System.Drawing.Point(15, 15); 
            base.DisplaySize = new Size(0x195, 0xb6); 
            base.Name = "BeInvitedForm"; 
            base.Padding = new Padding(4, 0, 4, 0x2b); 
            base.Text = "邀请加入群"; 
            base.FormClosed += new FormClosedEventHandler(this.BeInvitedForm_FormClosed); 
            this.pnlMain.ResumeLayout(false); 
            this.pnlPortrait.ResumeLayout(false); 
            ((ISupportInitialize) this.picPortrait).EndInit(); 
            base.ResumeLayout(false); 
        } 
 
        private void lblInviteInfo_LabelLinkClick(object sender, LabelLinkClickEventArgs e) 
        { 
            try 
            { 
                if (!string.IsNullOrEmpty(e.Url)) 
                { 
                    IicUri uri = new IicUri(e.Url); 
                    if (uri.IsContact) 
                    { 
                        this._framework.ContactManager.ShowContactDetail(this, uri.Raw); 
                    } 
                    else if ((uri.Type == IicUriType.PersonalGroup) && (this._inviteGroup != null)) 
                    { 
                        ApplyForJoinForm form = new ApplyForJoinForm(this._framework, this._inviteGroup, true); 
                        ControlHelper.ShowDialogCenterOnParent(form, this, true); 
                    } 
                } 
            } 
            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 
            { 
                base.Close(); 
            } 
            catch (Exception exception) 
            { 
                ClientLogger.WriteException(exception); 
            } 
        } 
 
        private void UpdateInfo(PersonalGroup group, Imps.Client.Core.Contact inviteContact) 
        { 
            string str = StringHelper.EncodString(StringHelper.GetPaddingStringEndEllipsis(group.GroupInfo.Name.Value, 11)); 
            string str2 = StringHelper.EncodString(StringHelper.GetPaddingStringEndEllipsis(inviteContact.DisplayName, 11)); 
            string str3 = string.Format("{1}({2})", group.Uri.Raw, str, group.Uri.Id); 
            string str4 = string.Format("{1}({2})", inviteContact.Uri.Raw, str2, inviteContact.Uri.Id); 
            this.lblInviteInfo.Text = string.Format("{0}邀请您加入群 {1}!", str4, str3); 
        } 
 
        private void xbtnCancel_Click(object sender, EventArgs e) 
        { 
            base.Close(); 
        } 
 
        private void xbtnJoin_Click(object sender, EventArgs e) 
        { 
            try 
            { 
                this.xbtnJoin.Enabled = false; 
                this.op = new AsyncBizOperation(); 
                this._framework.AccountManager.CurrentUser.PersonalGroupManager.AsyncHandleGroupInvite(this._inviteGroup.Uri.Raw, true, this.op); 
                this.op.Successed += new EventHandler(this.op_Successed); 
                this.op.ImpsError += new EventHandler(this.op_ImpsError); 
            } 
            catch (Exception exception) 
            { 
                ClientLogger.WriteException(exception); 
            } 
        } 
    } 
}