📄 importform.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.Pc.UIContactList.AddBuddy;
using Imps.Client.Utils;
using Imps.Common;
using Imps.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Xml;
public class ImportForm : XIMDialog
{
private bool _checkByFunction;
private IFrameworkWindow _frameworkWin;
private IImportContacts _importObject;
private string _importXMLContent = "";
private int? _initTargetGroupId;
private Dictionary<long, object> _items = new Dictionary<long, object>();
private ImportExportManager _manager;
private int _maxStep = 5;
private int _step = 1;
private int _totalChecked;
private int _totalUsers;
private XButton btnBrowse;
private XButton btnCancel;
private XButton btnNext;
private XButton btnPrevious;
private CheckBox checkBoxSelAll;
private CheckBox chkInviteStartService;
private ColumnHeader columnHeader1;
private ColumnHeader columnHeader2;
private ColumnHeader columnHeader3;
private ColumnHeader columnHeader4;
private ComboBox comboBoxGroup;
private IContainer components;
private int? groupID = null;
private int i;
private Label label1;
private XLabel labelName;
private HtmlLabel labelRealName1;
private XLabel lblDescription;
private XLabel lblImportContactName;
private XLabel lblSelectControls;
private XLabel lblSelectInfo;
private XLabel lblSelectPlugin;
private XLabel lblSelectSavePath;
private LinkLabel linkLabelHelp;
private ListBox listBoxResult;
private LinkLabel lnkAddNewGroup;
private List<XmlNode> lst;
private ListView lstContacts;
private ListBox lstPlugins;
private OpenFileDialog openFileDialog;
private PictureBox pbImportExport;
private Panel pnlContainer;
private Panel pnlMainContainer;
private Panel pnlStep1;
private Panel pnlStep2;
private Panel pnlStep3;
private Panel pnlStep4;
private Panel pnlStep5;
private ProgressBar progressBarExport;
private ProgressBar progressOutLook;
private TextBox textBoxMyName;
private TextBox txtFilePath;
private XLabel xLabel1;
private XLabel xLabel2;
private XLabel xLabel3;
private XLabel xLabelFind;
public ImportForm(IFrameworkWindow frameworkWin, ImportExportManager manager)
{
this.InitializeComponent();
this._frameworkWin = frameworkWin;
this._manager = manager;
this.initComponentRegion();
this.lstPlugins.DoubleClick += new EventHandler(this.lstPlugins_DoubleClick);
this.CurrentUser.ContactList.ContactGroupChanged += new EventHandler<ContactGroupChangedEventArgs>(this.ContactList_ContactGroupChanged);
this.CurrentUser.StatusChanged += new EventHandler<UserSatusChangedEventArgs>(this.CurrentUser_StatusChanged);
}
private void BindDatas(XmlDocument doc)
{
if ((this.lstContacts.Tag == null) || (this.lstContacts.Tag.ToString() != doc.InnerXml))
{
this.lstContacts.Tag = doc.InnerXml;
this.lstContacts.Items.Clear();
this._items.Clear();
this._totalUsers = 0;
this._totalChecked = 0;
List<ListViewItem> list = new List<ListViewItem>();
this._checkByFunction = true;
foreach (XmlNode node in doc.DocumentElement.ChildNodes)
{
string nodeValue = this.GetNodeValue(node, "FetionId");
string str2 = this.GetNodeValue(node, "MobileNo");
string str3 = this.GetNodeValue(node, "Name");
string str4 = this.GetNodeValue(node, "Nickname");
if ((!string.IsNullOrEmpty(nodeValue) || !string.IsNullOrEmpty(str2)) && ((this.CurrentUser.Sid.ToString() != nodeValue) && (this.CurrentUser.MobileNo != str2)))
{
if (str2 == "0")
{
str2 = string.Empty;
}
long mobileNo = 0L;
long result = 0L;
if (string.IsNullOrEmpty(str2) || ((ImpsHelper.TryParseMobileNoExtend(str2, out mobileNo) && (this.CurrentUser.ContactList.FindContactByMsisdnEx(mobileNo.ToString()) == null)) && !this._items.ContainsKey(mobileNo)))
{
if (!string.IsNullOrEmpty(nodeValue))
{
if (!long.TryParse(nodeValue, out result) || !ImpsHelper.IsSid(result))
{
continue;
}
IicUri uri = IicUri.CreateSidUri(result);
if ((this.CurrentUser.ContactList.Contacts.FindContact(uri) != null) || this._items.ContainsKey(result))
{
continue;
}
}
if (mobileNo != 0L)
{
this._items.Add(mobileNo, null);
}
else
{
if (result == 0L)
{
continue;
}
this._items.Add(result, null);
}
string[] items = new string[] { str3 ?? "", str4 ?? "", str2, nodeValue };
ListViewItem item = new ListViewItem(items);
item.Tag = node;
list.Add(item);
}
}
}
list.Sort(new ImportDatasCompare());
if (this.ImportObject.Type == ImportContactType.Outlook)
{
this.lstContacts.Columns[1].Width = 0;
this.lstContacts.Columns[3].Width = 0;
}
else if (this.ImportObject.Type == ImportContactType.VCard)
{
this.lstContacts.Columns[1].Width = 0;
this.lstContacts.Columns[3].Width = 0;
}
foreach (ListViewItem item2 in list)
{
this.lstContacts.Items.Add(item2);
this._totalUsers++;
}
this.FormatSelectInfo();
this._checkByFunction = false;
}
}
private void btnBrowse_Click(object sender, EventArgs e)
{
UiErrorHelper.HandEventSafely(this._frameworkWin, delegate {
this.openFileDialog.Filter = this.ImportObject.Filter;
if ((this.txtFilePath.Text != "") && File.Exists(this.txtFilePath.Text))
{
this.openFileDialog.FileName = this.txtFilePath.Text;
}
if (this.openFileDialog.ShowDialog(this) == DialogResult.OK)
{
this.txtFilePath.Text = this.openFileDialog.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)
{
this.DoPrevious();
}
private bool CanImport()
{
if (this.ImportObject.Type == ImportContactType.Outlook)
{
return true;
}
string text = this.txtFilePath.Text;
if (text == "")
{
return false;
}
if (text.IndexOf(@"\") == -1)
{
return false;
}
return File.Exists(text);
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
try
{
this._checkByFunction = true;
if (this.checkBoxSelAll.Checked)
{
foreach (ListViewItem item in this.lstContacts.Items)
{
if (!item.Checked)
{
if (this.AllowChecked > this._totalChecked)
{
this._totalChecked++;
item.Checked = true;
}
else
{
this._frameworkWin.UnifiedMessageBox.ShowInfo(this, string.Format("您最多只能选择{0}个联系人", this.AllowChecked.ToString()));
break;
}
}
item.Checked = true;
}
}
else
{
foreach (ListViewItem item2 in this.lstContacts.Items)
{
item2.Checked = false;
}
this._totalChecked = 0;
}
this._checkByFunction = false;
this.FormatSelectInfo();
this.btnNext.Enabled = this._totalChecked > 0;
}
catch
{
}
}
private void ContactList_ContactGroupChanged(object sender, ContactGroupChangedEventArgs e)
{
if (e.Type == ContactGroupEventType.Added)
{
this._initTargetGroupId = new int?(e.ContactGroup.Id);
}
else if ((e.Type == ContactGroupEventType.Deleted) && (e.ContactGroup.Id == this._initTargetGroupId))
{
this._initTargetGroupId = null;
}
this.initGroup();
}
private void CurrentUser_StatusChanged(object sender, UserSatusChangedEventArgs e)
{
if (e.NewStatus != UserAccountStatus.Logon)
{
base.Close();
}
}
protected override void Dispose(bool disposing)
{
if (disposing && (this.components != null))
{
this.components.Dispose();
}
base.Dispose(disposing);
}
private void DoImportContactFinish(Info info)
{
if (!base.IsDisposed)
{
base.Invoke(new ImportContactDelegate(this.DoImportContactFinishUI), new object[] { info });
}
}
private void DoImportContactFinishUI(Info info)
{
try
{
if (!base.IsDisposed)
{
string id = string.Empty;
if (info.DispalyName.Length == 0)
{
id = info.Id;
}
else if (info.IsMobileNo)
{
id = string.Format("{0}(手机号:{1})", info.DispalyName, info.Id);
}
else
{
id = string.Format("{0}(Fetion号:{1})", info.DispalyName, info.Id);
}
string str2 = string.Empty;
if (info.IsSuccessed)
{
str2 = "导入成功...";
}
else
{
str2 = string.Format("导入失败({0})...", info.FailedInfo);
}
this.listBoxResult.Items.Add(id + str2);
this.i++;
this.lblImportContactName.Text = string.Format("正在导入 {0} ({1}/{2})", id, this.i, this.lst.Count);
if (this.progressBarExport.Value <= this.progressBarExport.Maximum)
{
this.progressBarExport.Value++;
}
if (this.i < this.lst.Count)
{
this.ImportContact(this.lst[this.i]);
}
else
{
this.progressBarExport.Value = this.progressBarExport.Maximum;
this.lblImportContactName.Text = "导入完成";
this.btnPrevious.Enabled = false;
this.btnNext.Enabled = false;
this.btnCancel.Text = "关闭";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -