ComplianceServer/oldcode/TEST1/ResIdToMobile.cs

133 lines
4.6 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Windows.Forms;
using WX.CRM.BLL.Res;
using WX.CRM.BLL.Util;
using WX.CRM.Common;
using WX.CRM.Model.Entity;
namespace TEST1
{
public partial class ResIdToMobile : Form
{
public ResIdToMobile()
{
InitializeComponent();
}
private void ResIdToMobile_Load(object sender, EventArgs e)
{
}
private void importTxt_Click(object sender, EventArgs e)
{
//初始化一个OpenFileDialog类
OpenFileDialog fileDialog = new OpenFileDialog();
//判断用户是否正确的选择了文件
if (fileDialog.ShowDialog() == DialogResult.OK)
{
//获取用户选择文件的后缀名
string extension = Path.GetExtension(fileDialog.FileName);
if (extension.ToLower() != ".txt")
{
MessageBox.Show("只能导入txt的文件", "警告信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
//声明允许的后缀名
string clientid = Utility.GetSettingByKey("CRMClientKey");
WX.CRM.IBLL.Util.ISecurityHelper sHelper = new SecurityHelper();
StreamReader sr = new StreamReader(fileDialog.FileName, Encoding.Default);
String line;
StreamReader sr2 = new StreamReader(fileDialog.FileName, Encoding.Default);
List<MobileInfo> mobileList = new List<MobileInfo>();
Dictionary<string, string> dic = new Dictionary<string, string>();
RESMOBILE_BL mobilebl = new RESMOBILE_BL();
int total = 0;
int readTotal = 0;
while ((line = sr.ReadLine()) != null)
{
string resid = line.ToString();
if (string.IsNullOrWhiteSpace(resid))
{
continue;
}
readTotal++;
}
if (readTotal == 0)
{
MessageBox.Show("选择的文件没有内容,请重新选择", "警告信息", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
this.progressBar1.Minimum = 0;
this.progressBar1.Maximum = readTotal;
this.progressBar1.Value = 0;
while ((line = sr2.ReadLine()) != null)
{
string resid = line.ToString();
//string phone = Utility.GetMobile(line.ToString());
if (string.IsNullOrWhiteSpace(resid))
{
continue;
}
try
{
var mobileInfo = mobilebl.GetNumberAndNameByResId(resid);//手机号解密
if (!dic.ContainsKey(mobileInfo.Mobile))
{
mobileList.Add(mobileInfo);
dic.Add(mobileInfo.Mobile, mobileInfo.Mobile);
total++;
}
progressBar1.Value++;
}
catch (Exception ex)
{
LogHelper.Error(ex);
}
}
this.progressBar2.Minimum = 0;
this.progressBar2.Maximum = total;
this.progressBar2.Value = 0;
SaveFileDialog saveFile1 = new SaveFileDialog();
saveFile1.Filter = "文本文件(.csv)|*.csv";
saveFile1.FilterIndex = 1;
if (saveFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK && saveFile1.FileName.Length > 0)
{
System.IO.StreamWriter sw = new System.IO.StreamWriter(saveFile1.FileName, false);
try
{
foreach (var item in mobileList)
{
sw.WriteLine(item.Mobile + "," + item.Name); //只要这里改一下要输出的内容就可以了
this.progressBar2.Value++;
}
}
catch
{
throw;
}
finally
{
sw.Close();
}
}
}
}
}
}