Browse Source

添加客户信息导入

mengjie 8 years ago
parent
commit
c62fe82189

+ 15 - 0
codegit/CallCenterApi/CallCenterApi.BLL/T_Cus_CustomerBase.cs

@@ -147,7 +147,22 @@ namespace CallCenterApi.BLL
147 147
         //{
148 148
         //return dal.GetList(PageSize,PageIndex,strWhere);
149 149
         //}
150
+        /// <summary>
151
+        /// 是否存在该记录
152
+        /// </summary>
153
+        public bool PhoneExists(string F_Mobile)
154
+        {
155
+            return dal.PhoneExists(F_Mobile);
156
+        }
150 157
 
158
+        /// <summary>
159
+        /// 删除一条数据
160
+        /// </summary>
161
+        public bool PhoneDelete(string F_Mobile)
162
+        {
163
+
164
+            return dal.PhoneDelete(F_Mobile);
165
+        }
151 166
         #endregion  BasicMethod
152 167
         #region  ExtensionMethod
153 168
 

+ 124 - 0
codegit/CallCenterApi/CallCenterApi.BLL/T_Cus_CustomerExport.cs

@@ -0,0 +1,124 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Data;
4
+using System.Linq;
5
+using System.Text;
6
+using System.Threading.Tasks;
7
+
8
+namespace CallCenterApi.BLL
9
+{
10
+    /// <summary>
11
+	/// T_Cus_CustomerBase
12
+	/// </summary>
13
+	public partial class T_Cus_CustomerExport
14
+    {
15
+        private readonly CallCenterApi.DAL.T_Cus_CustomerExport dal = new CallCenterApi.DAL.T_Cus_CustomerExport();
16
+        public T_Cus_CustomerExport()
17
+        { }
18
+        #region  BasicMethod
19
+        /// <summary>
20
+        /// 增加一条数据
21
+        /// </summary>
22
+        public int Add(CallCenterApi.Model.T_Cus_CustomerExport model)
23
+        {
24
+            return dal.Add(model);
25
+        }
26
+
27
+        /// <summary>
28
+        /// 删除一条数据
29
+        /// </summary>
30
+        public bool Delete(int F_FileID)
31
+        {
32
+
33
+            return dal.Delete(F_FileID);
34
+        }
35
+        /// <summary>
36
+        /// 删除一条数据
37
+        /// </summary>
38
+        public bool DeleteList(string F_FileIDlist)
39
+        {
40
+            return dal.DeleteList(F_FileIDlist);
41
+        }
42
+
43
+        /// <summary>
44
+        /// 得到一个对象实体
45
+        /// </summary>
46
+        public CallCenterApi.Model.T_Cus_CustomerExport GetModel(int F_FileID)
47
+        {
48
+
49
+            return dal.GetModel(F_FileID);
50
+        }
51
+
52
+        /// <summary>
53
+        /// 获得数据列表
54
+        /// </summary>
55
+        public DataSet GetList(string strWhere)
56
+        {
57
+            return dal.GetList(strWhere);
58
+        }
59
+        /// <summary>
60
+        /// 获得前几行数据
61
+        /// </summary>
62
+        public DataSet GetList(int Top, string strWhere, string filedOrder)
63
+        {
64
+            return dal.GetList(Top, strWhere, filedOrder);
65
+        }
66
+        /// <summary>
67
+        /// 获得数据列表
68
+        /// </summary>
69
+        public List<CallCenterApi.Model.T_Cus_CustomerExport> GetModelList(string strWhere)
70
+        {
71
+            DataSet ds = dal.GetList(strWhere);
72
+            return DataTableToList(ds.Tables[0]);
73
+        }
74
+        /// <summary>
75
+        /// 获得数据列表
76
+        /// </summary>
77
+        public List<CallCenterApi.Model.T_Cus_CustomerExport> DataTableToList(DataTable dt)
78
+        {
79
+            List<CallCenterApi.Model.T_Cus_CustomerExport> modelList = new List<CallCenterApi.Model.T_Cus_CustomerExport>();
80
+            int rowsCount = dt.Rows.Count;
81
+            if (rowsCount > 0)
82
+            {
83
+                CallCenterApi.Model.T_Cus_CustomerExport model;
84
+                for (int n = 0; n < rowsCount; n++)
85
+                {
86
+                    model = dal.DataRowToModel(dt.Rows[n]);
87
+                    if (model != null)
88
+                    {
89
+                        modelList.Add(model);
90
+                    }
91
+                }
92
+            }
93
+            return modelList;
94
+        }
95
+
96
+        /// <summary>
97
+        /// 获得数据列表
98
+        /// </summary>
99
+        public DataSet GetAllList()
100
+        {
101
+            return GetList("");
102
+        }
103
+
104
+        /// <summary>
105
+        /// 分页获取数据列表
106
+        /// </summary>
107
+        public int GetRecordCount(string strWhere)
108
+        {
109
+            return dal.GetRecordCount(strWhere);
110
+        }
111
+        /// <summary>
112
+        /// 分页获取数据列表
113
+        /// </summary>
114
+        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
115
+        {
116
+            return dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
117
+        }
118
+
119
+        #endregion  BasicMethod
120
+        #region  ExtensionMethod
121
+
122
+        #endregion  ExtensionMethod
123
+    }
124
+}

+ 52 - 1
codegit/CallCenterApi/CallCenterApi.DAL/T_Cus_CustomerBase.cs

@@ -126,7 +126,7 @@ namespace CallCenterApi.DAL
126 126
                     new SqlParameter("@F_RelationShipClassID", SqlDbType.Int,4),
127 127
                     new SqlParameter("@F_CityID", SqlDbType.Int,4),
128 128
                     new SqlParameter("@F_AutoFlag", SqlDbType.SmallInt,2),
129
-                    new SqlParameter("@F_Result", SqlDbType.NVarChar,20)
129
+                    new SqlParameter("@F_Result", SqlDbType.NVarChar,100)
130 130
             };
131 131
             parameters[0].Value = model.F_CustomerName;
132 132
             parameters[1].Value = model.F_CustomerCode;
@@ -815,6 +815,15 @@ namespace CallCenterApi.DAL
815 815
                 {
816 816
                     model.F_CityID = int.Parse(row["F_CityID"].ToString());
817 817
                 }
818
+                //2017-11-2
819
+                if (row["F_AutoFlag"] != null && row["F_AutoFlag"].ToString() != "")
820
+                {
821
+                    model.F_AutoFlag = int.Parse(row["F_AutoFlag"].ToString());
822
+                }
823
+                if (row["F_Result"] != null)
824
+                {
825
+                    model.F_Result = row["F_Result"].ToString();
826
+                }
818 827
             }
819 828
             return model;
820 829
         }
@@ -927,6 +936,48 @@ namespace CallCenterApi.DAL
927 936
 			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
928 937
 		}*/
929 938
 
939
+        //2017-11-2
940
+        /// <summary>
941
+        /// 是否存在该记录
942
+        /// </summary>
943
+        public bool PhoneExists(string  F_Mobile)
944
+        {
945
+            StringBuilder strSql = new StringBuilder();
946
+            strSql.Append("select count(1) from T_Cus_CustomerBase");
947
+            strSql.Append(" where F_Mobile=@F_Mobile");
948
+            SqlParameter[] parameters = {
949
+                    new SqlParameter("@F_Mobile", SqlDbType.NVarChar,100)
950
+            };
951
+            parameters[0].Value = F_Mobile;
952
+
953
+            return DbHelperSQL.Exists(strSql.ToString(), parameters);
954
+        }
955
+
956
+        /// <summary>
957
+        /// 根据手机号删除一条数据
958
+        /// </summary>
959
+        public bool PhoneDelete(string F_Mobile)
960
+        {
961
+
962
+            StringBuilder strSql = new StringBuilder();
963
+            //strSql.Append("delete from T_Cus_CustomerBase ");
964
+            strSql.Append("update T_Cus_CustomerBase set F_DeleteFlag=1");
965
+            strSql.Append(" where F_Mobile=@F_Mobile");
966
+            SqlParameter[] parameters = {
967
+                    new SqlParameter("@F_Mobile", SqlDbType.NVarChar,100)
968
+            };
969
+            parameters[0].Value = F_Mobile;
970
+
971
+            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
972
+            if (rows > 0)
973
+            {
974
+                return true;
975
+            }
976
+            else
977
+            {
978
+                return false;
979
+            }
980
+        }
930 981
         #endregion  BasicMethod
931 982
         #region  ExtensionMethod
932 983
 

+ 279 - 0
codegit/CallCenterApi/CallCenterApi.DAL/T_Cus_CustomerExport.cs

@@ -0,0 +1,279 @@
1
+using CallCenterApi.DB;
2
+using System;
3
+using System.Collections.Generic;
4
+using System.Data;
5
+using System.Data.SqlClient;
6
+using System.Linq;
7
+using System.Text;
8
+using System.Threading.Tasks;
9
+
10
+namespace CallCenterApi.DAL
11
+{
12
+    /// <summary>
13
+	/// 数据访问类:T_Cus_CustomerExport
14
+	/// </summary>
15
+	public partial class T_Cus_CustomerExport
16
+    {
17
+        public T_Cus_CustomerExport()
18
+        { }
19
+        #region  BasicMethod
20
+
21
+        /// <summary>
22
+        /// 增加一条数据
23
+        /// </summary>
24
+        public int Add(CallCenterApi.Model.T_Cus_CustomerExport model)
25
+        {
26
+            StringBuilder strSql = new StringBuilder();
27
+            strSql.Append("insert into T_Cus_CustomerExport(");
28
+            strSql.Append("F_TypeGroup,F_FileOldName,F_FileNewName,F_FilePath,F_FileFix,F_FileType,F_FileSize,F_InputUserCode,F_InputUserID,F_InputDate)");
29
+            strSql.Append(" values (");
30
+            strSql.Append("@F_TypeGroup,@F_FileOldName,@F_FileNewName,@F_FilePath,@F_FileFix,@F_FileType,@F_FileSize,@F_InputUserCode,@F_InputUserID,@F_InputDate)");
31
+            strSql.Append(";select @@IDENTITY");
32
+            SqlParameter[] parameters = {
33
+                    new SqlParameter("@F_TypeGroup", SqlDbType.Int,4),
34
+                    new SqlParameter("@F_FileOldName", SqlDbType.NVarChar,500),
35
+                    new SqlParameter("@F_FileNewName", SqlDbType.NVarChar,500),
36
+                    new SqlParameter("@F_FilePath", SqlDbType.NText),
37
+                    new SqlParameter("@F_FileFix", SqlDbType.NVarChar,50),
38
+                    new SqlParameter("@F_FileType", SqlDbType.Int,4),
39
+                    new SqlParameter("@F_FileSize", SqlDbType.Int,4),
40
+                    new SqlParameter("@F_InputUserCode", SqlDbType.NVarChar,50),
41
+                    new SqlParameter("@F_InputUserID", SqlDbType.Int,4),
42
+                    new SqlParameter("@F_InputDate", SqlDbType.DateTime)};
43
+            parameters[0].Value = model.F_TypeGroup;
44
+            parameters[1].Value = model.F_FileOldName;
45
+            parameters[2].Value = model.F_FileNewName;
46
+            parameters[3].Value = model.F_FilePath;
47
+            parameters[4].Value = model.F_FileFix;
48
+            parameters[5].Value = model.F_FileType;
49
+            parameters[6].Value = model.F_FileSize;
50
+            parameters[7].Value = model.F_InputUserCode;
51
+            parameters[8].Value = model.F_InputUserID;
52
+            parameters[9].Value = model.F_InputDate;
53
+
54
+            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);
55
+            if (obj == null)
56
+            {
57
+                return 0;
58
+            }
59
+            else
60
+            {
61
+                return Convert.ToInt32(obj);
62
+            }
63
+        }
64
+        /// <summary>
65
+        /// 删除一条数据
66
+        /// </summary>
67
+        public bool Delete(int F_FileID)
68
+        {
69
+
70
+            StringBuilder strSql = new StringBuilder();
71
+            strSql.Append("delete from T_Cus_CustomerExport ");
72
+            strSql.Append(" where F_FileID=@F_FileID");
73
+            SqlParameter[] parameters = {
74
+                    new SqlParameter("@F_FileID", SqlDbType.Int,4)
75
+            };
76
+            parameters[0].Value = F_FileID;
77
+
78
+            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
79
+            if (rows > 0)
80
+            {
81
+                return true;
82
+            }
83
+            else
84
+            {
85
+                return false;
86
+            }
87
+        }
88
+        /// <summary>
89
+        /// 批量删除数据
90
+        /// </summary>
91
+        public bool DeleteList(string F_FileIDlist)
92
+        {
93
+            StringBuilder strSql = new StringBuilder();
94
+            strSql.Append("delete from T_Cus_CustomerExport ");
95
+            strSql.Append(" where F_FileID in (" + F_FileIDlist + ")  ");
96
+            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
97
+            if (rows > 0)
98
+            {
99
+                return true;
100
+            }
101
+            else
102
+            {
103
+                return false;
104
+            }
105
+        }
106
+
107
+
108
+        /// <summary>
109
+        /// 得到一个对象实体
110
+        /// </summary>
111
+        public CallCenterApi.Model.T_Cus_CustomerExport GetModel(int F_FileID)
112
+        {
113
+
114
+            StringBuilder strSql = new StringBuilder();
115
+            strSql.Append("select  top 1 F_FileID,F_TypeGroup,F_FileOldName,F_FileNewName,F_FilePath,F_FileFix,F_FileType,F_FileSize,F_InputUserCode,F_InputUserID,F_InputDate from T_Cus_CustomerExport ");
116
+            strSql.Append(" where F_FileID=@F_FileID");
117
+            SqlParameter[] parameters = {
118
+                    new SqlParameter("@F_FileID", SqlDbType.Int,4)
119
+            };
120
+            parameters[0].Value = F_FileID;
121
+
122
+            CallCenterApi.Model.T_Cus_CustomerExport model = new CallCenterApi.Model.T_Cus_CustomerExport();
123
+            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
124
+            if (ds.Tables[0].Rows.Count > 0)
125
+            {
126
+                return DataRowToModel(ds.Tables[0].Rows[0]);
127
+            }
128
+            else
129
+            {
130
+                return null;
131
+            }
132
+        }
133
+
134
+
135
+        /// <summary>
136
+        /// 得到一个对象实体
137
+        /// </summary>
138
+        public CallCenterApi.Model.T_Cus_CustomerExport DataRowToModel(DataRow row)
139
+        {
140
+            CallCenterApi.Model.T_Cus_CustomerExport model = new CallCenterApi.Model.T_Cus_CustomerExport();
141
+            if (row != null)
142
+            {
143
+                if (row["F_FileID"] != null && row["F_FileID"].ToString() != "")
144
+                {
145
+                    model.F_FileID = int.Parse(row["F_FileID"].ToString());
146
+                }
147
+                if (row["F_TypeGroup"] != null && row["F_TypeGroup"].ToString() != "")
148
+                {
149
+                    model.F_TypeGroup = int.Parse(row["F_TypeGroup"].ToString());
150
+                }
151
+                if (row["F_FileOldName"] != null)
152
+                {
153
+                    model.F_FileOldName = row["F_FileOldName"].ToString();
154
+                }
155
+                if (row["F_FileNewName"] != null)
156
+                {
157
+                    model.F_FileNewName = row["F_FileNewName"].ToString();
158
+                }
159
+                if (row["F_FilePath"] != null)
160
+                {
161
+                    model.F_FilePath = row["F_FilePath"].ToString();
162
+                }
163
+                if (row["F_FileFix"] != null)
164
+                {
165
+                    model.F_FileFix = row["F_FileFix"].ToString();
166
+                }
167
+                if (row["F_FileType"] != null && row["F_FileType"].ToString() != "")
168
+                {
169
+                    model.F_FileType = int.Parse(row["F_FileType"].ToString());
170
+                }
171
+                if (row["F_FileSize"] != null && row["F_FileSize"].ToString() != "")
172
+                {
173
+                    model.F_FileSize = int.Parse(row["F_FileSize"].ToString());
174
+                }
175
+                if (row["F_InputUserCode"] != null)
176
+                {
177
+                    model.F_InputUserCode = row["F_InputUserCode"].ToString();
178
+                }
179
+                if (row["F_InputUserID"] != null && row["F_InputUserID"].ToString() != "")
180
+                {
181
+                    model.F_InputUserID = int.Parse(row["F_InputUserID"].ToString());
182
+                }
183
+                if (row["F_InputDate"] != null && row["F_InputDate"].ToString() != "")
184
+                {
185
+                    model.F_InputDate = DateTime.Parse(row["F_InputDate"].ToString());
186
+                }
187
+            }
188
+            return model;
189
+        }
190
+
191
+        /// <summary>
192
+        /// 获得数据列表
193
+        /// </summary>
194
+        public DataSet GetList(string strWhere)
195
+        {
196
+            StringBuilder strSql = new StringBuilder();
197
+            strSql.Append("select F_FileID,F_TypeGroup,F_FileOldName,F_FileNewName,F_FilePath,F_FileFix,F_FileType,F_FileSize,F_InputUserCode,F_InputUserID,F_InputDate ");
198
+            strSql.Append(" FROM T_Cus_CustomerExport ");
199
+            if (strWhere.Trim() != "")
200
+            {
201
+                strSql.Append(" where " + strWhere);
202
+            }
203
+            return DbHelperSQL.Query(strSql.ToString());
204
+        }
205
+
206
+        /// <summary>
207
+        /// 获得前几行数据
208
+        /// </summary>
209
+        public DataSet GetList(int Top, string strWhere, string filedOrder)
210
+        {
211
+            StringBuilder strSql = new StringBuilder();
212
+            strSql.Append("select ");
213
+            if (Top > 0)
214
+            {
215
+                strSql.Append(" top " + Top.ToString());
216
+            }
217
+            strSql.Append(" F_FileID,F_TypeGroup,F_FileOldName,F_FileNewName,F_FilePath,F_FileFix,F_FileType,F_FileSize,F_InputUserCode,F_InputUserID,F_InputDate ");
218
+            strSql.Append(" FROM T_Cus_CustomerExport ");
219
+            if (strWhere.Trim() != "")
220
+            {
221
+                strSql.Append(" where " + strWhere);
222
+            }
223
+            strSql.Append(" order by " + filedOrder);
224
+            return DbHelperSQL.Query(strSql.ToString());
225
+        }
226
+
227
+        /// <summary>
228
+        /// 获取记录总数
229
+        /// </summary>
230
+        public int GetRecordCount(string strWhere)
231
+        {
232
+            StringBuilder strSql = new StringBuilder();
233
+            strSql.Append("select count(1) FROM T_Cus_CustomerExport ");
234
+            if (strWhere.Trim() != "")
235
+            {
236
+                strSql.Append(" where " + strWhere);
237
+            }
238
+            object obj = DbHelperSQL.GetSingle(strSql.ToString());
239
+            if (obj == null)
240
+            {
241
+                return 0;
242
+            }
243
+            else
244
+            {
245
+                return Convert.ToInt32(obj);
246
+            }
247
+        }
248
+        /// <summary>
249
+        /// 分页获取数据列表
250
+        /// </summary>
251
+        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
252
+        {
253
+            StringBuilder strSql = new StringBuilder();
254
+            strSql.Append("SELECT * FROM ( ");
255
+            strSql.Append(" SELECT ROW_NUMBER() OVER (");
256
+            if (!string.IsNullOrEmpty(orderby.Trim()))
257
+            {
258
+                strSql.Append("order by T." + orderby);
259
+            }
260
+            else
261
+            {
262
+                strSql.Append("order by T.F_FileID desc");
263
+            }
264
+            strSql.Append(")AS Row, T.*  from T_Cus_CustomerExport T ");
265
+            if (!string.IsNullOrEmpty(strWhere.Trim()))
266
+            {
267
+                strSql.Append(" WHERE " + strWhere);
268
+            }
269
+            strSql.Append(" ) TT");
270
+            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
271
+            return DbHelperSQL.Query(strSql.ToString());
272
+        }
273
+
274
+        #endregion  BasicMethod
275
+        #region  ExtensionMethod
276
+
277
+        #endregion  ExtensionMethod
278
+    }
279
+}

+ 289 - 0
codegit/CallCenterApi/CallCenterApi.Interface/CallCenterApi.Interface/Controllers/customer/CustomerController.cs

@@ -9,6 +9,8 @@ using System.Data;
9 9
 using CallCenter.Utility;
10 10
 using CallCenterApi.Common;
11 11
 using CallCenterApi.DB;
12
+using System.IO;
13
+using System.Data.SqlClient;
12 14
 
13 15
 namespace CallCenterApi.Interface.Controllers.customer
14 16
 {
@@ -252,5 +254,292 @@ namespace CallCenterApi.Interface.Controllers.customer
252 254
             }
253 255
             return res;
254 256
         }
257
+
258
+        //2017-11-2 导入客户信息
259
+        int vfileid = 0;
260
+        // 导入客户信息读取填入数据库
261
+        public ActionResult CustomerInput()
262
+        {
263
+            ActionResult res = NoToken("未知错误,请重新登录");
264
+            if (Request.IsAuthenticated)
265
+            {
266
+                DataTable dtres = new DataTable();
267
+                string errres = "";
268
+                int i = 0;
269
+                int count = 0;//导入成功的条数
270
+                string Excelsource = "";
271
+                int rcount = 0;
272
+                int ccount = 0;
273
+                System.Text.StringBuilder strBuilder = null;
274
+                //Excelsource = Server.MapPath(this.Request.ApplicationPath + "\\ExcelData\\") + filename.ToString();
275
+                Excelsource = uploadexcel();
276
+                #region 将文件中的数据导入数据库
277
+
278
+                try
279
+                {
280
+
281
+                    //************************将文件中的数据导入数据库*************************//
282
+                    DataSet dt = ReadEcxel(Excelsource, 0);
283
+                    try
284
+                    {
285
+                        if (dt != null && dt.Tables[0].Rows.Count != 0)
286
+                        {
287
+                            rcount = dt.Tables[0].Rows.Count;
288
+                            ccount = dt.Tables[0].Columns.Count;
289
+                            strBuilder = new System.Text.StringBuilder();//用于如果导入失败,删除已经导入过的
290
+
291
+                            DataTable dtInputData = dt.Tables[0];//要导入的电话号码
292
+                            List<string> sqlList = new List<string>();
293
+                            List<string> lstsql = new List<string>();
294
+                            int ilns = dt.Tables[0].Columns.Count;
295
+                            DataSet dsnew = new DataSet();
296
+
297
+
298
+                            #region MyRegion
299
+                            using (SqlConnection coon = new SqlConnection(DbHelperSQL.connectionString))
300
+                            {
301
+                                try
302
+                                {
303
+                                    coon.Open();
304
+                                    int colscount = dtInputData.Columns.Count;//列数
305
+                                    int rowscount = dtInputData.Rows.Count;//行数
306
+                                    Model.T_Cus_CustomerBase modelcus = new Model.T_Cus_CustomerBase();
307
+                                    
308
+                                    if (rowscount > 0)
309
+                                    {
310
+                                        foreach (DataRow dr in dtInputData.Rows)
311
+                                        {
312
+                                            sqlList.Clear();
313
+                                            lstsql.Clear();
314
+                                            if (dr[2].ToString() != "")
315
+                                            {
316
+                                                string dddddd = dr[2].ToString();
317
+                                                #region 导入表内容
318
+                                                #region 保存字段
319
+                                                modelcus.F_CustomerName = dr[0].ToString();//姓名
320
+                                                modelcus.F_Mobile= dr[1].ToString();//手机号
321
+                                                modelcus.F_Address = dr[2].ToString();//地址
322
+                                                //modelcus.F_Address = dr[3].ToString();//地址
323
+                                                                                      //if (dr[3].ToString() != "")
324
+                                                                                      //{
325
+                                                modelcus.F_AutoFlag = Convert.ToInt32(dr[3]);//自动标记
326
+                                                   // modelcus.F_AutoFlag = Utils.StrToInt(RequestString.GetFormString(dr[3].ToString()), 0);//Convert.ToInt32(dr[3].ToString());//自动标记
327
+                                                //}
328
+                                                modelcus.F_Result = dr[4].ToString();//结果统计
329
+                                                #endregion 保存
330
+                                               
331
+                                                
332
+                                                //先判断是否有此号码,若有则将删除标志置为1再添加新信息
333
+                                                if (new BLL.T_Cus_CustomerBase().PhoneExists(modelcus.F_Mobile))//存在则删除
334
+                                                {
335
+                                                    new BLL.T_Cus_CustomerBase().PhoneDelete(modelcus.F_Mobile);
336
+                                                }
337
+                                                int rmw = new BLL.T_Cus_CustomerBase().Add(modelcus);
338
+                                                if (rmw > 0)
339
+                                                {
340
+                                                    count += 1;//导入成功,+1
341
+                                                }
342
+                                                #endregion
343
+                                                //int rmw = new BLL.T_Vis_Telphone().Add(modelPhoneImport);
344
+
345
+                                            }
346
+
347
+                                        }
348
+                                        dtres = dtInputData;
349
+
350
+                                    }
351
+                                    else
352
+                                    {
353
+                                        errres += "该文档的内容为空";
354
+                                    }
355
+                                }
356
+                                catch (Exception ex)
357
+                                {
358
+                                    if (coon.State == ConnectionState.Open)
359
+                                    {
360
+                                        coon.Close();
361
+                                    }
362
+                                    i++;
363
+                                    errres += i.ToString() + ".导入出现异常,共导入" + count + "条数据,请从第" + (count + 2).ToString() + "行开始导入;\n";
364
+                                    if (strBuilder.Length > 0)
365
+                                    {
366
+                                        errres += "重复的号码为:" + strBuilder.ToString() + "\n";
367
+                                    }
368
+                                }
369
+                                finally
370
+                                {
371
+                                    if (coon.State == ConnectionState.Open)
372
+                                    {
373
+                                        coon.Close();
374
+                                    }
375
+                                }
376
+
377
+
378
+                            }//****************using*********
379
+
380
+                            #endregion
381
+
382
+                        }
383
+                        else
384
+                        {
385
+                            i++;
386
+                            errres += i.ToString() + ".Excel中无数据;\n";
387
+                        }
388
+
389
+                    }
390
+                    catch
391
+                    {
392
+                        i++;
393
+                        errres += i.ToString() + ".导入出现异常,导入失败;\n";
394
+                    }
395
+                    finally
396
+                    {
397
+                        dt.Clear();
398
+                        dt.Dispose();
399
+                    }
400
+
401
+                }
402
+                catch
403
+                {
404
+                    errres += i.ToString() + ".Excel格式不正确,系统错误,导入失败;\n";
405
+                }
406
+
407
+                #endregion
408
+                if (errres != "")
409
+                {
410
+                    res = Error("导入失败!错误信息:" + errres);
411
+                }
412
+                else
413
+                {
414
+                    string info = "本文件有" + rcount.ToString() + "行" + ccount.ToString() + "列数据";
415
+                    res = Success("导入成功!" + info, vfileid);
416
+                }
417
+            }
418
+
419
+            return res;
420
+        }
421
+        #region 上传文件
422
+        private string uploadexcel()
423
+        {
424
+            string Excelsource = "";
425
+            try
426
+            {
427
+                //HttpFileCollection hfc = System.Web.HttpContext.Current.Request.Files;
428
+                HttpPostedFile _upfile = RequestString.GetFile("upFile");
429
+                if (_upfile != null)
430
+                {
431
+                    string imgPath = "";
432
+
433
+                    string newFileName = DateTime.Now.ToString("yyyyMMddHHmmss");
434
+                    newFileName = newFileName + "_" + _upfile.FileName;
435
+                    if (!Directory.Exists(Server.MapPath(this.Request.ApplicationPath + "\\ExcelData")))
436
+                    {
437
+                        Directory.CreateDirectory(Server.MapPath(this.Request.ApplicationPath + "\\ExcelData"));
438
+                    }
439
+
440
+                    imgPath = this.Request.ApplicationPath + "/ExcelData/" + newFileName.ToString();
441
+                    string PhysicalPath = Server.MapPath(imgPath);
442
+                    _upfile.SaveAs(PhysicalPath);
443
+
444
+                    Excelsource = Server.MapPath(this.Request.ApplicationPath + "\\ExcelData\\") + newFileName.ToString();
445
+
446
+                    Model.T_Cus_CustomerExport filesmodel = new Model.T_Cus_CustomerExport();
447
+                    filesmodel.F_FileNewName = newFileName;
448
+                    filesmodel.F_FileOldName = _upfile.FileName;
449
+                    filesmodel.F_FilePath = Excelsource;
450
+                    filesmodel.F_FileType = 1;
451
+                    filesmodel.F_TypeGroup = 0;
452
+                    filesmodel.F_FileFix = _upfile.FileName.Substring(_upfile.FileName.LastIndexOf('.') + 1);
453
+                    filesmodel.F_InputDate = DateTime.Now;
454
+                    filesmodel.F_InputUserCode = CurrentUser.UserData.F_UserCode;
455
+                    filesmodel.F_InputUserID = CurrentUser.UserData.F_UserId;
456
+
457
+                    vfileid = new BLL.T_Cus_CustomerExport().Add(filesmodel);
458
+                }
459
+            }
460
+            catch (Exception ex) { }
461
+            return Excelsource;
462
+        }
463
+        #endregion
464
+
465
+        #region 读取Excel文件,返一个DataTable
466
+        private DataSet ReadEcxel(string FileName, int Rows)
467
+        {
468
+            return ToDataTable(FileName);
469
+        }
470
+
471
+        /// <summary>
472
+        /// 读取Excel文件到DataSet中
473
+        /// </summary>
474
+        /// <param name="filePath">文件路径</param>
475
+        /// <returns></returns>
476
+        private DataSet ToDataTable(string filePath)
477
+        {
478
+            DataSet ds = new DataSet();
479
+            DataTable dt = null;
480
+
481
+            try
482
+            {
483
+                FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
484
+
485
+                NPOI.SS.UserModel.IWorkbook book = null;
486
+                if (filePath.IndexOf(".xlsx") > 0) // 2007版本
487
+                    book = new NPOI.XSSF.UserModel.XSSFWorkbook(fs);
488
+                else if (filePath.IndexOf(".xls") > 0) // 2003版本
489
+                    book = new NPOI.HSSF.UserModel.HSSFWorkbook(fs);
490
+                //NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook(fs);
491
+
492
+                NPOI.SS.UserModel.ISheet sheet = book.GetSheetAt(0);
493
+
494
+
495
+                NPOI.SS.UserModel.IRow row = sheet.GetRow(0);
496
+
497
+
498
+                int firstCellNum = row.FirstCellNum;
499
+                int lastCellNum = row.LastCellNum;
500
+                //if (firstCellNum == lastCellNum) continue;
501
+
502
+                dt = new DataTable(sheet.SheetName);
503
+                //for (int i = firstCellNum; i < lastCellNum; i++)
504
+                for (int i = firstCellNum; i < 50; i++)
505
+                {
506
+                    if (row.GetCell(i) != null)
507
+                    {
508
+                        dt.Columns.Add(row.GetCell(i).ToString() + i.ToString(), typeof(string));
509
+                    }
510
+                    else
511
+                    {
512
+                        dt.Columns.Add(i.ToString(), typeof(string));
513
+                    }
514
+                }
515
+
516
+                for (int i = 1; i <= sheet.LastRowNum; i++)
517
+                {
518
+                    if (sheet.GetRow(i).GetCell(2) != null && sheet.GetRow(i).GetCell(2).ToString() != "")
519
+                    {
520
+                        DataRow newRow = dt.Rows.Add();
521
+                        for (int j = firstCellNum; j < 50; j++)
522
+                        {
523
+                            if (sheet.GetRow(i).GetCell(j) != null)
524
+                            {
525
+                                newRow[j] = sheet.GetRow(i).GetCell(j).ToString();
526
+                            }
527
+                            else
528
+                            {
529
+                                newRow[j] = "";
530
+                            }
531
+                        }
532
+                    }
533
+                }
534
+
535
+                ds.Tables.Add(dt);
536
+            }
537
+            catch (Exception ex)
538
+            {
539
+                //SysLog.WriteLog(ex);
540
+            }
541
+            return ds;
542
+        }
543
+        #endregion
255 544
     }
256 545
 }

+ 121 - 0
codegit/CallCenterApi/CallCenterApi.Model/T_Cus_CustomerExport.cs

@@ -0,0 +1,121 @@
1
+using System;
2
+using System.Collections.Generic;
3
+using System.Linq;
4
+using System.Text;
5
+using System.Threading.Tasks;
6
+
7
+namespace CallCenterApi.Model
8
+{
9
+    /// <summary>
10
+	/// T_Cus_CustomerExport:实体类(属性说明自动提取数据库字段的描述信息)
11
+	/// </summary>
12
+	[Serializable]
13
+    public partial class T_Cus_CustomerExport
14
+    {
15
+        public T_Cus_CustomerExport()
16
+        { }
17
+        #region Model
18
+        private int _f_fileid;
19
+        private int? _f_typegroup;
20
+        private string _f_fileoldname;
21
+        private string _f_filenewname;
22
+        private string _f_filepath;
23
+        private string _f_filefix;
24
+        private int? _f_filetype;
25
+        private int? _f_filesize;
26
+        private string _f_inputusercode;
27
+        private int? _f_inputuserid;
28
+        private DateTime? _f_inputdate;
29
+        /// <summary>
30
+        /// 文件ID
31
+        /// </summary>
32
+        public int F_FileID
33
+        {
34
+            set { _f_fileid = value; }
35
+            get { return _f_fileid; }
36
+        }
37
+        /// <summary>
38
+        /// 所属的组别:0 95005,1 电销
39
+        /// </summary>
40
+        public int? F_TypeGroup
41
+        {
42
+            set { _f_typegroup = value; }
43
+            get { return _f_typegroup; }
44
+        }
45
+        /// <summary>
46
+        /// 文件名称
47
+        /// </summary>
48
+        public string F_FileOldName
49
+        {
50
+            set { _f_fileoldname = value; }
51
+            get { return _f_fileoldname; }
52
+        }
53
+        /// <summary>
54
+        /// 文件新名称
55
+        /// </summary>
56
+        public string F_FileNewName
57
+        {
58
+            set { _f_filenewname = value; }
59
+            get { return _f_filenewname; }
60
+        }
61
+        /// <summary>
62
+        /// 文件路径
63
+        /// </summary>
64
+        public string F_FilePath
65
+        {
66
+            set { _f_filepath = value; }
67
+            get { return _f_filepath; }
68
+        }
69
+        /// <summary>
70
+        /// 文件前缀
71
+        /// </summary>
72
+        public string F_FileFix
73
+        {
74
+            set { _f_filefix = value; }
75
+            get { return _f_filefix; }
76
+        }
77
+        /// <summary>
78
+        /// 文件类型:电销:0 老客户,1 新客户
79
+        /// </summary>
80
+        public int? F_FileType
81
+        {
82
+            set { _f_filetype = value; }
83
+            get { return _f_filetype; }
84
+        }
85
+        /// <summary>
86
+        /// 文件大小
87
+        /// </summary>
88
+        public int? F_FileSize
89
+        {
90
+            set { _f_filesize = value; }
91
+            get { return _f_filesize; }
92
+        }
93
+        /// <summary>
94
+        /// 
95
+        /// </summary>
96
+        public string F_InputUserCode
97
+        {
98
+            set { _f_inputusercode = value; }
99
+            get { return _f_inputusercode; }
100
+        }
101
+        /// <summary>
102
+        /// 
103
+        /// </summary>
104
+        public int? F_InputUserID
105
+        {
106
+            set { _f_inputuserid = value; }
107
+            get { return _f_inputuserid; }
108
+        }
109
+        /// <summary>
110
+        /// 
111
+        /// </summary>
112
+        public DateTime? F_InputDate
113
+        {
114
+            set { _f_inputdate = value; }
115
+            get { return _f_inputdate; }
116
+        }
117
+        #endregion Model
118
+
119
+
120
+    }
121
+}