|
|
@@ -1,8 +1,12 @@
|
|
1
|
|
-using RMYY_CallCenter_Api.Utility;
|
|
|
1
|
+using RMYY_CallCenter_Api.DB;
|
|
|
2
|
+using RMYY_CallCenter_Api.Utility;
|
|
2
|
3
|
using System;
|
|
3
|
4
|
using System.Collections.Generic;
|
|
4
|
5
|
using System.Data;
|
|
|
6
|
+using System.Data.SqlClient;
|
|
|
7
|
+using System.IO;
|
|
5
|
8
|
using System.Linq;
|
|
|
9
|
+using System.Text;
|
|
6
|
10
|
using System.Web;
|
|
7
|
11
|
using System.Web.Mvc;
|
|
8
|
12
|
|
|
|
@@ -19,10 +23,10 @@ namespace RMYY_CallCenter_Api.Controllers.System
|
|
19
|
23
|
/// </summary>
|
|
20
|
24
|
/// <returns></returns>
|
|
21
|
25
|
//[HttpGet]
|
|
22
|
|
- public ActionResult GetList(string key, int roleid = 0, int deptid = 0, int page = 1, int pagesize = 10)
|
|
|
26
|
+ public ActionResult GetList(string key,int isexport=0, int roleid = 0, int deptid = 0, int page = 1, int pagesize = 10)
|
|
23
|
27
|
{
|
|
24
|
28
|
DataTable dt = new DataTable();
|
|
25
|
|
- string sql = string.Empty;
|
|
|
29
|
+ string sql = " and F_DeleteFlag=0";
|
|
26
|
30
|
|
|
27
|
31
|
if (deptid > 0)
|
|
28
|
32
|
{
|
|
|
@@ -39,6 +43,24 @@ namespace RMYY_CallCenter_Api.Controllers.System
|
|
39
|
43
|
}
|
|
40
|
44
|
|
|
41
|
45
|
int recordCount = 0;
|
|
|
46
|
+
|
|
|
47
|
+ if (isexport == 1)
|
|
|
48
|
+ {
|
|
|
49
|
+ string sql1 = " 1=1" + sql;
|
|
|
50
|
+ dt =DbHelperSQL.Query(" select F_UserName,F_UserCode ,[dbo].[GetDepName](F_DeptId) deptname,[F_Sex],[F_Telephone],[F_WorkPhone] ,[F_HomeAddress] ,[F_Job] from T_Sys_UserAccount where '" + sql1+"'").Tables[0];
|
|
|
51
|
+ NPOIHelper npoi = new NPOIHelper();
|
|
|
52
|
+ if (npoi.ExportToExcel("用户信息", dt, col()) == "")
|
|
|
53
|
+ {
|
|
|
54
|
+ return Success("导出成功");
|
|
|
55
|
+ }
|
|
|
56
|
+ else
|
|
|
57
|
+ {
|
|
|
58
|
+ return Error("导出失败");
|
|
|
59
|
+ }
|
|
|
60
|
+ }
|
|
|
61
|
+
|
|
|
62
|
+
|
|
|
63
|
+
|
|
42
|
64
|
dt = Bll.PagerBll.GetListPager(
|
|
43
|
65
|
"T_Sys_UserAccount a with(nolock)",
|
|
44
|
66
|
"F_UserId",
|
|
|
@@ -58,7 +80,14 @@ namespace RMYY_CallCenter_Api.Controllers.System
|
|
58
|
80
|
|
|
59
|
81
|
return Content(obj.ToJson());
|
|
60
|
82
|
}
|
|
|
83
|
+ private string[] col()
|
|
|
84
|
+ {
|
|
|
85
|
+ string[] ccc = {
|
|
|
86
|
+ "姓名","工号","部门","性别","电话","单位电话","家庭住址","职务"
|
|
|
87
|
+ };
|
|
61
|
88
|
|
|
|
89
|
+ return ccc;
|
|
|
90
|
+ }
|
|
62
|
91
|
/// <summary>
|
|
63
|
92
|
/// 获取用户信息
|
|
64
|
93
|
/// </summary>
|
|
|
@@ -204,7 +233,7 @@ namespace RMYY_CallCenter_Api.Controllers.System
|
|
204
|
233
|
/// <param name="usercode"></param>
|
|
205
|
234
|
/// <param name="pwd"></param>
|
|
206
|
235
|
/// <returns></returns>
|
|
207
|
|
- public ActionResult ResetPwd(string usercode = "", string pwd = "")
|
|
|
236
|
+ public ActionResult ResetPwd(string oldpwd, string usercode = "", string pwd = "")
|
|
208
|
237
|
{
|
|
209
|
238
|
if (User!=null)
|
|
210
|
239
|
{
|
|
|
@@ -212,6 +241,13 @@ namespace RMYY_CallCenter_Api.Controllers.System
|
|
212
|
241
|
return Error("请输入密码");
|
|
213
|
242
|
var model = userbll.GetModel(usercode);
|
|
214
|
243
|
if (model == null) return Error("此用户不存在");
|
|
|
244
|
+
|
|
|
245
|
+ var oldmodel = userbll.GetModelList(" F_UserCode='" + usercode + "' and F_Password='" + oldpwd + "'");
|
|
|
246
|
+ if (oldmodel == null || oldmodel.Count == 0)
|
|
|
247
|
+ {
|
|
|
248
|
+ return Error("旧密码错误");
|
|
|
249
|
+
|
|
|
250
|
+ }
|
|
215
|
251
|
model.F_Password = pwd;
|
|
216
|
252
|
if (userbll.Update(model))
|
|
217
|
253
|
return Success("重置密码成功");
|
|
|
@@ -330,5 +366,286 @@ namespace RMYY_CallCenter_Api.Controllers.System
|
|
330
|
366
|
return Success("列表加载成功", result);
|
|
331
|
367
|
}
|
|
332
|
368
|
|
|
|
369
|
+ // 导入号码读取填入数据库
|
|
|
370
|
+ int vfileid = 0;
|
|
|
371
|
+ public ActionResult UserInput(int deptid)
|
|
|
372
|
+ {
|
|
|
373
|
+ DataTable dtres = new DataTable();
|
|
|
374
|
+ string errres = "";
|
|
|
375
|
+ int i = 0;
|
|
|
376
|
+ int count = 0;//导入成功的条数
|
|
|
377
|
+ string Excelsource = "";
|
|
|
378
|
+ int rcount = 0;
|
|
|
379
|
+ int ccount = 0;
|
|
|
380
|
+ StringBuilder strBuilder = null;
|
|
|
381
|
+
|
|
|
382
|
+ Excelsource = uploadexcel();
|
|
|
383
|
+ #region 将文件中的数据导入数据库
|
|
|
384
|
+
|
|
|
385
|
+ try
|
|
|
386
|
+ {
|
|
|
387
|
+
|
|
|
388
|
+ //************************将文件中的数据导入数据库*************************//
|
|
|
389
|
+ DataSet dt = ReadEcxel(Excelsource, 0);
|
|
|
390
|
+ try
|
|
|
391
|
+ {
|
|
|
392
|
+ List<Model.T_Sys_UserAccount> userlist = userbll.GetModelList(" F_DeleteFlag=0");
|
|
|
393
|
+
|
|
|
394
|
+ if (dt != null && dt.Tables[0].Rows.Count != 0)
|
|
|
395
|
+ {
|
|
|
396
|
+ rcount = dt.Tables[0].Rows.Count;
|
|
|
397
|
+ ccount = dt.Tables[0].Columns.Count;
|
|
|
398
|
+ strBuilder = new StringBuilder();//用于如果导入失败,删除已经导入过的
|
|
|
399
|
+
|
|
|
400
|
+ DataTable dtInputData = dt.Tables[0];//要导入的电话号码
|
|
|
401
|
+ List<string> sqlList = new List<string>();
|
|
|
402
|
+ List<string> lstsql = new List<string>();
|
|
|
403
|
+ int ilns = dt.Tables[0].Columns.Count;
|
|
|
404
|
+ DataSet dsnew = new DataSet();
|
|
|
405
|
+
|
|
|
406
|
+
|
|
|
407
|
+ #region MyRegion
|
|
|
408
|
+ using (SqlConnection coon = new SqlConnection(DbHelperSQL.connectionString))
|
|
|
409
|
+ {
|
|
|
410
|
+ try
|
|
|
411
|
+ {
|
|
|
412
|
+ coon.Open();
|
|
|
413
|
+ int colscount = dtInputData.Columns.Count;//列数
|
|
|
414
|
+ int rowscount = dtInputData.Rows.Count;//行数
|
|
|
415
|
+
|
|
|
416
|
+
|
|
|
417
|
+ Model.T_Sys_UserAccount modelusermport = new Model.T_Sys_UserAccount();
|
|
|
418
|
+ #region
|
|
|
419
|
+ modelusermport.F_CreateUser = User.F_UserCode;
|
|
|
420
|
+
|
|
|
421
|
+ modelusermport.F_CreateTime = DateTime.Now;
|
|
|
422
|
+ modelusermport.F_DeleteFlag = 0;
|
|
|
423
|
+ modelusermport.F_DeptId = deptid;
|
|
|
424
|
+ modelusermport.F_Password = "e10adc3949ba59abbe56e057f20f883e";
|
|
|
425
|
+
|
|
|
426
|
+ #endregion
|
|
|
427
|
+ if (rowscount > 0)
|
|
|
428
|
+ {
|
|
|
429
|
+ foreach (DataRow dr in dtInputData.Rows)
|
|
|
430
|
+ {
|
|
|
431
|
+ sqlList.Clear();
|
|
|
432
|
+ lstsql.Clear();
|
|
|
433
|
+ #region 导入表内容
|
|
|
434
|
+ //姓名 工号 电话 性别 单位电话 职务 家庭住址
|
|
|
435
|
+ modelusermport.F_UserName = dr[0].ToString();//姓名
|
|
|
436
|
+ string usercode= dr[1].ToString();//工号
|
|
|
437
|
+ Model.T_Sys_UserAccount oldusermodel = userlist.Find(t => t.F_UserCode == usercode);
|
|
|
438
|
+ if (oldusermodel == null)
|
|
|
439
|
+ {
|
|
|
440
|
+ modelusermport.F_UserCode = dr[1].ToString();//工号
|
|
|
441
|
+ }
|
|
|
442
|
+ else
|
|
|
443
|
+ {
|
|
|
444
|
+ continue;
|
|
|
445
|
+ }
|
|
|
446
|
+
|
|
|
447
|
+ modelusermport.F_Telephone= dr[2].ToString();//电话
|
|
|
448
|
+ modelusermport.F_Sex = dr[3].ToString();//性别
|
|
|
449
|
+
|
|
|
450
|
+ modelusermport.F_WorkPhone = dr[4].ToString();//单位电话
|
|
|
451
|
+
|
|
|
452
|
+ modelusermport.F_Job = dr[5].ToString();//职务
|
|
|
453
|
+ modelusermport.F_HomeAddress = dr[6].ToString();//家庭住址
|
|
|
454
|
+
|
|
|
455
|
+ #endregion
|
|
|
456
|
+ int rmw = userbll.Add(modelusermport);
|
|
|
457
|
+ if (rmw > 0)
|
|
|
458
|
+ {
|
|
|
459
|
+ count += 1;//导入成功,+1
|
|
|
460
|
+ }
|
|
|
461
|
+
|
|
|
462
|
+
|
|
|
463
|
+ }
|
|
|
464
|
+ dtres = dtInputData;
|
|
|
465
|
+
|
|
|
466
|
+ }
|
|
|
467
|
+ else
|
|
|
468
|
+ {
|
|
|
469
|
+ errres += "该文档的内容为空";
|
|
|
470
|
+ }
|
|
|
471
|
+ }
|
|
|
472
|
+ catch (Exception ex)
|
|
|
473
|
+ {
|
|
|
474
|
+ if (coon.State == ConnectionState.Open)
|
|
|
475
|
+ {
|
|
|
476
|
+ coon.Close();
|
|
|
477
|
+ }
|
|
|
478
|
+ i++;
|
|
|
479
|
+ errres += i.ToString() + ".导入出现异常,共导入" + count + "条数据,请从第" + (count + 2).ToString() + "行开始导入;\n";
|
|
|
480
|
+ if (strBuilder.Length > 0)
|
|
|
481
|
+ {
|
|
|
482
|
+ errres += "重复的工号为:" + strBuilder.ToString() + "\n";
|
|
|
483
|
+ }
|
|
|
484
|
+ }
|
|
|
485
|
+ finally
|
|
|
486
|
+ {
|
|
|
487
|
+ if (coon.State == ConnectionState.Open)
|
|
|
488
|
+ {
|
|
|
489
|
+ coon.Close();
|
|
|
490
|
+ }
|
|
|
491
|
+ }
|
|
|
492
|
+
|
|
|
493
|
+
|
|
|
494
|
+ }
|
|
|
495
|
+
|
|
|
496
|
+ #endregion
|
|
|
497
|
+
|
|
|
498
|
+ }
|
|
|
499
|
+ else
|
|
|
500
|
+ {
|
|
|
501
|
+ i++;
|
|
|
502
|
+ errres += i.ToString() + ".Excel中无数据;\n";
|
|
|
503
|
+ }
|
|
|
504
|
+
|
|
|
505
|
+ }
|
|
|
506
|
+ catch
|
|
|
507
|
+ {
|
|
|
508
|
+ i++;
|
|
|
509
|
+ errres += i.ToString() + ".导入出现异常,导入失败;\n";
|
|
|
510
|
+ }
|
|
|
511
|
+ finally
|
|
|
512
|
+ {
|
|
|
513
|
+ dt.Clear();
|
|
|
514
|
+ dt.Dispose();
|
|
|
515
|
+ }
|
|
|
516
|
+
|
|
|
517
|
+ }
|
|
|
518
|
+ catch
|
|
|
519
|
+ {
|
|
|
520
|
+ errres += i.ToString() + ".Excel格式不正确,系统错误,导入失败;\n";
|
|
|
521
|
+ }
|
|
|
522
|
+
|
|
|
523
|
+ #endregion
|
|
|
524
|
+ if (errres != "")
|
|
|
525
|
+ {
|
|
|
526
|
+ return Error("导入失败!错误信息:" + errres);
|
|
|
527
|
+ }
|
|
|
528
|
+ else
|
|
|
529
|
+ {
|
|
|
530
|
+ string info = "本文件有" + rcount.ToString() + "行" + ccount.ToString() + "列数据";
|
|
|
531
|
+ return Success("导入成功!" + info, vfileid);
|
|
|
532
|
+ }
|
|
|
533
|
+ }
|
|
|
534
|
+
|
|
|
535
|
+ private string uploadexcel()
|
|
|
536
|
+ {
|
|
|
537
|
+ string Excelsource = "";
|
|
|
538
|
+ try
|
|
|
539
|
+ {
|
|
|
540
|
+
|
|
|
541
|
+ HttpPostedFile _upfile = RequestString.GetFile("upFile");
|
|
|
542
|
+ if (_upfile != null)
|
|
|
543
|
+ {
|
|
|
544
|
+ string imgPath = "";
|
|
|
545
|
+
|
|
|
546
|
+ string newFileName = DateTime.Now.ToString("yyyyMMddHHmmss");
|
|
|
547
|
+ newFileName = newFileName + "_" + _upfile.FileName;
|
|
|
548
|
+ if (!Directory.Exists(Server.MapPath(this.Request.ApplicationPath + "\\ExcelData")))
|
|
|
549
|
+ {
|
|
|
550
|
+ Directory.CreateDirectory(Server.MapPath(this.Request.ApplicationPath + "\\ExcelData"));
|
|
|
551
|
+ }
|
|
|
552
|
+
|
|
|
553
|
+ imgPath = this.Request.ApplicationPath + "/ExcelData/" + newFileName.ToString();
|
|
|
554
|
+ string PhysicalPath = Server.MapPath(imgPath);
|
|
|
555
|
+ _upfile.SaveAs(PhysicalPath);
|
|
|
556
|
+
|
|
|
557
|
+ Excelsource = Server.MapPath(this.Request.ApplicationPath + "\\ExcelData\\") + newFileName.ToString();
|
|
|
558
|
+
|
|
|
559
|
+ Model.T_Sys_Accessories filesmodel = new Model.T_Sys_Accessories();
|
|
|
560
|
+
|
|
|
561
|
+
|
|
|
562
|
+ filesmodel.F_FileName = newFileName;
|
|
|
563
|
+
|
|
|
564
|
+ filesmodel.F_FileUrl = Excelsource;
|
|
|
565
|
+
|
|
|
566
|
+ filesmodel.F_FileType = _upfile.FileName.Substring(_upfile.FileName.LastIndexOf('.') + 1);
|
|
|
567
|
+ filesmodel.F_AddTime = DateTime.Now;
|
|
|
568
|
+ filesmodel.F_UserCode = User.F_UserCode;
|
|
|
569
|
+ Bll.T_Sys_Accessories bllfile = new Bll.T_Sys_Accessories();
|
|
|
570
|
+
|
|
|
571
|
+ vfileid = bllfile.Add(filesmodel);
|
|
|
572
|
+ }
|
|
|
573
|
+ }
|
|
|
574
|
+ catch (Exception ex) { }
|
|
|
575
|
+ return Excelsource;
|
|
|
576
|
+ }
|
|
|
577
|
+
|
|
|
578
|
+
|
|
|
579
|
+ private DataSet ReadEcxel(string FileName, int Rows)
|
|
|
580
|
+ {
|
|
|
581
|
+ return ToDataTable(FileName);
|
|
|
582
|
+ }
|
|
|
583
|
+ private DataSet ToDataTable(string filePath)
|
|
|
584
|
+ {
|
|
|
585
|
+ DataSet ds = new DataSet();
|
|
|
586
|
+ DataTable dt = null;
|
|
|
587
|
+
|
|
|
588
|
+ try
|
|
|
589
|
+ {
|
|
|
590
|
+ FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
|
|
|
591
|
+
|
|
|
592
|
+ NPOI.SS.UserModel.IWorkbook book = null;
|
|
|
593
|
+ if (filePath.IndexOf(".xlsx") > 0) // 2007版本
|
|
|
594
|
+ book = new NPOI.XSSF.UserModel.XSSFWorkbook(fs);
|
|
|
595
|
+ else if (filePath.IndexOf(".xls") > 0) // 2003版本
|
|
|
596
|
+ book = new NPOI.HSSF.UserModel.HSSFWorkbook(fs);
|
|
|
597
|
+
|
|
|
598
|
+
|
|
|
599
|
+ NPOI.SS.UserModel.ISheet sheet = book.GetSheetAt(0);
|
|
|
600
|
+
|
|
|
601
|
+
|
|
|
602
|
+ NPOI.SS.UserModel.IRow row = sheet.GetRow(0);
|
|
|
603
|
+
|
|
|
604
|
+
|
|
|
605
|
+ int firstCellNum = row.FirstCellNum;
|
|
|
606
|
+ int lastCellNum = row.LastCellNum;
|
|
|
607
|
+
|
|
|
608
|
+
|
|
|
609
|
+ dt = new DataTable(sheet.SheetName);
|
|
|
610
|
+
|
|
|
611
|
+ for (int i = firstCellNum; i < 12; i++)
|
|
|
612
|
+ {
|
|
|
613
|
+ if (row.GetCell(i) != null)
|
|
|
614
|
+ {
|
|
|
615
|
+ dt.Columns.Add(row.GetCell(i).ToString() + i.ToString(), typeof(string));
|
|
|
616
|
+ }
|
|
|
617
|
+ else
|
|
|
618
|
+ {
|
|
|
619
|
+ dt.Columns.Add(i.ToString(), typeof(string));
|
|
|
620
|
+ }
|
|
|
621
|
+ }
|
|
|
622
|
+
|
|
|
623
|
+ for (int i = 1; i <= sheet.LastRowNum; i++)
|
|
|
624
|
+ {
|
|
|
625
|
+ if (sheet.GetRow(i).GetCell(1) != null && sheet.GetRow(i).GetCell(1).ToString() != "")
|
|
|
626
|
+ {
|
|
|
627
|
+ DataRow newRow = dt.Rows.Add();
|
|
|
628
|
+ for (int j = firstCellNum; j < 12; j++)
|
|
|
629
|
+ {
|
|
|
630
|
+ if (sheet.GetRow(i).GetCell(j) != null)
|
|
|
631
|
+ {
|
|
|
632
|
+ newRow[j] = sheet.GetRow(i).GetCell(j).ToString();
|
|
|
633
|
+ }
|
|
|
634
|
+ else
|
|
|
635
|
+ {
|
|
|
636
|
+ newRow[j] = "";
|
|
|
637
|
+ }
|
|
|
638
|
+ }
|
|
|
639
|
+ }
|
|
|
640
|
+ }
|
|
|
641
|
+
|
|
|
642
|
+ ds.Tables.Add(dt);
|
|
|
643
|
+ }
|
|
|
644
|
+ catch (Exception ex)
|
|
|
645
|
+ {
|
|
|
646
|
+
|
|
|
647
|
+ }
|
|
|
648
|
+ return ds;
|
|
|
649
|
+ }
|
|
333
|
650
|
}
|
|
334
|
651
|
}
|