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

📄 exportform.cs

📁 破解的飞信源代码
💻 CS
📖 第 1 页 / 共 3 页
字号:
namespace Imps.Client.Pc
{
    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.Diagnostics;
    using System.Drawing;
    using System.IO;
    using System.Text;
    using System.Windows.Forms;

    public class ExportForm : XIMDialog
    {
        private bool _finished;
        private IFrameworkWindow _frameworkWin;
        private ImportExportManager _manager;
        private int _maxStep = 2;
        private int _step = 1;
        private XButton btnBrowse;
        private XButton btnCancel;
        private XButton btnNext;
        private XButton btnPrevious;
        private bool bUsed;
        private IContainer components;
        private GroupBox groupBox1;
        private Label labelOK;
        private XLabel lblDescription;
        private XLabel lblSelectControls;
        private XLabel lblSelectPlugin;
        private XLabel lblSelectSavePath;
        private LinkLabel linkLabel1;
        private ListBox lstPlugins;
        private Panel panelOK;
        private PictureBox pbExportImport;
        private PictureBox pbOK;
        private Panel pnlContainer;
        private Panel pnlMain;
        private Panel pnlStep1;
        private Panel pnlStep2;
        private Panel pnlStep4;
        private ProgressBar progressBarExport;
        private SaveFileDialog saveFileDialog;
        private TreeView treeContacts;
        private TextBox txtFilePath;
        private XLabel xLabel1;

        public ExportForm(IFrameworkWindow frameworkWin, ImportExportManager manager)
        {
            this.InitializeComponent();
            this._frameworkWin = frameworkWin;
            this._manager = manager;
            this.initComponentRegion();
            this.lstPlugins.DoubleClick += new EventHandler(this.lstPlugins_DoubleClick);
        }

        private void BindGroupContacts()
        {
            lock (this._frameworkWin.AccountManager.CurrentUser.ContactList.Groups.SyncRoot)
            {
                using (IEnumerator<ContactGroupBase> enumerator = this._frameworkWin.AccountManager.CurrentUser.ContactList.Groups.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        ContactGroup group = (ContactGroup) enumerator.get_Current();
                        if (group.Id != -1)
                        {
                            TreeNode node = new TreeNode(group.Name);
                            node.set_Name(group.Id.ToString());
                            node.Checked = true;
                            node.Tag = group;
                            this.treeContacts.Nodes.Add(node);
                            List<Contact> listContacts = group.Contacts.ListContacts;
                            listContacts.Sort(new ContactCompare());
                            List<Contact>.Enumerator enumerator2 = listContacts.GetEnumerator();
                            try
                            {
                                while (enumerator2.MoveNext())
                                {
                                    Contact contact = enumerator2.get_Current();
                                    if (!(contact is ChatFriend))
                                    {
                                        TreeNode node2 = new TreeNode(contact.DisplayName);
                                        node2.set_Name(contact.Uri.Raw);
                                        node2.Checked = true;
                                        node2.Tag = contact;
                                        node.Nodes.Add(node2);
                                    }
                                }
                                continue;
                            }
                            finally
                            {
                                enumerator2.Dispose();
                            }
                        }
                    }
                }
            }
        }

        private void BindNoneGroupContacts()
        {
            lock (this._frameworkWin.AccountManager.CurrentUser.ContactList.Contacts.SyncRoot)
            {
                using (IEnumerator<Contact> enumerator = this._frameworkWin.AccountManager.CurrentUser.ContactList.Contacts.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        Contact contact = enumerator.get_Current();
                        if (contact.BelongToGroups.get_Count() == 0)
                        {
                            TreeNode node = new TreeNode(contact.DisplayName);
                            node.set_Name(contact.Uri.Raw);
                            node.Checked = true;
                            node.Tag = contact;
                            this.treeContacts.Nodes.Add(node);
                        }
                    }
                }
            }
        }

        private void btnBrowse_Click(object sender, EventArgs e)
        {
            UiErrorHelper.HandEventSafely(this._frameworkWin, delegate {
                this.saveFileDialog.Filter = ((this.lstPlugins.SelectedItem as ImportExportManager.ImportExportPlugin).ImportExportObject as IExportContacts).Filter;
                this.saveFileDialog.FileName = string.Empty;
                if ((this.txtFilePath.Text != "") && File.Exists(this.txtFilePath.Text))
                {
                    this.saveFileDialog.FileName = this.txtFilePath.Text;
                }
                if (this.saveFileDialog.ShowDialog(this) == DialogResult.OK)
                {
                    this.txtFilePath.Text = this.saveFileDialog.FileName;
                }
            });
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            this.DoNext();
        }

        private void btnPrevious_Click(object sender, EventArgs e)
        {
            UiErrorHelper.HandEventSafely(this._frameworkWin, delegate {
                this._step--;
                this.FormatForm();
            });
        }

        private bool CanExport()
        {
            string path = this.txtFilePath.Text;
            if (path == "")
            {
                return false;
            }
            if (path.IndexOf(@"\") == -1)
            {
                return false;
            }
            if (!path.ToUpper().EndsWith(".CSV") && !path.ToUpper().EndsWith(".FCL"))
            {
                return false;
            }
            if (Directory.Exists(path))
            {
                return false;
            }
            return Directory.Exists(path.Substring(0, path.LastIndexOf(@"\")));
        }

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

        private void DoNext()
        {
            UiErrorHelper.HandEventSafely(this._frameworkWin, delegate {
                if (this._step != this._maxStep)
                {
                    if ((this._step == 1) && (this.GetSelectedContacts().get_Count() == 0))
                    {
                        this._frameworkWin.UnifiedMessageBox.ShowInfo(this, "至少选择一个联系人!");
                    }
                    else
                    {
                        this._step++;
                        this.FormatForm();
                    }
                }
                else if (this._finished)
                {
                    base.Close();
                }
                else
                {
                    this.Export();
                }
            });
        }

        private void Export()
        {
            try
            {
                List<Contact> selectedContacts = this.GetSelectedContacts();
                this.progressBarExport.Maximum = selectedContacts.get_Count();
                if (this.CanExport())
                {
                    this.progressBarExport.Visible = true;
                    StringBuilder builder = new StringBuilder();
                    builder.Append("<Contacts>\r\n");
                    List<Contact>.Enumerator enumerator = selectedContacts.GetEnumerator();
                    try
                    {
                        while (enumerator.MoveNext())
                        {
                            Contact contact = enumerator.get_Current();
                            builder.Append("<Contact>");
                            if ((contact.Type & ContactType.NonFederation) != ContactType.None)
                            {
                                builder.Append(string.Format("<FetionId>{0}</FetionId>", (contact.Type == ContactType.MobileBuddy) ? string.Empty : contact.Uri.Sid.ToString()));
                                string mobileNo = contact.PersonalInfo.MobileNo;
                                if (string.IsNullOrEmpty(mobileNo))
                                {
                                    mobileNo = contact.PersonalInfo.MobileNoUserSet;
                                }
                                builder.Append(string.Format("<MobileNo>{0}</MobileNo>", mobileNo));
                            }
                            builder.Append(string.Format("<Name>{0}</Name>", StringHelper.EncodString((string) contact.PersonalInfo.Name)));
                            builder.Append(string.Format("<Nickname>{0}</Nickname>", StringHelper.EncodString((string) contact.PersonalInfo.Nickname)));
                            builder.Append("</Contact>\r\n");
                            this.progressBarExport.Value++;

⌨️ 快捷键说明

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