| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862 |
-
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using CallCenterApi.Interface.Controllers.Base;
- using System.Data;
- using CallCenter.Utility;
- using System.Configuration;
- using Top.Api;
- using Top.Api.Request;
- using Top.Api.Response;
- using CallCenterApi.Common;
- using System.Net;
- using System.Text;
- using Newtonsoft.Json;
- using System.Xml;
- using System.IO;
- namespace CallCenterApi.Interface.Controllers
- {
- public class SMSController : BaseController
- {
- #region 接收短信
- string url = "http://47.92.26.244/sms.aspx?";
- string account = "yhyy"; string password = "yhyy190903";
- /// <summary>
- /// 发送短信
- /// </summary>
- /// <param name="mobile"></param>
- /// <param name="time"></param>
- /// <param name="timeslot"></param>
- /// <param name="department"></param>
- /// <param name="doctor"></param>
- /// <param name="floor"></param>
- /// <param name="name"></param>
- /// <param name="content"></param>
- /// <param name="type"></param>
- /// <returns></returns>
- public ActionResult SendSMS(string mobile, string time, string timeslot, string department, string doctor, string floor, string sendTime, string name, string content, int MBID, int sendWay = 0)
- {
- WebClient web = new WebClient();
- web.Encoding = Encoding.UTF8;
- content += "【郑州颐和医院】";
- url += "action=send&userid=&account=" + account.Trim() + "&password=" + password.Trim() + "&mobile=" + mobile.Trim() + "&content=" + content.Trim() + "& sendTime=" + sendTime.Trim() + "& extno=";
- string Dataaa = web.DownloadString(url);//这一句话就能请求到数据了
- var result = new CreateOrderReturnResult();
- try
- {
- DataSet ds = new DataSet();
- StringReader stream = new StringReader(Dataaa);//读取字符串为数据量
- XmlTextReader reader = new XmlTextReader(stream);//对XML的数据流的只进只读访问
- ds.ReadXml(reader);//吧数据读入DataSet
- DataTable dt = ds.Tables["returnsms"];
- result.state = "success";
- result.message = "发送成功";
- result.data = new SmS();
- if (dt.Rows.Count > 0)
- {
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- DataRow dr = ds.Tables[0].Rows[i];
- result.data.returnstatus = dr["returnstatus"].ToString();
- result.data.message = dr["message"].ToString();
- result.data.remainpoint = dr["remainpoint"].ToString();
- result.data.taskID = dr["taskID"].ToString();
- result.data.successCounts = dr["successCounts"].ToString();
- }
- }
- int IsSend = 0;
- if (result.data.returnstatus == "Success")
- {
- IsSend = 1;
- }
- DateTime DSSendTime = DateTime.Now;
- if (!string.IsNullOrEmpty(sendTime.Trim()))
- {
- DSSendTime = DateTime.Parse(sendTime.Trim());
- }
- AddSMSList(sendWay, DSSendTime, DSSendTime, IsSend, mobile, content, MBID);
- if (result.data.returnstatus != "Success")
- {
- return Error(result.data.message);
- }
- }
- catch (Exception ex)
- {
- return Error(ex.Message);
- }
- return Content(result.ToJson());
- }
-
- public class CreateOrderReturnResult
- {
- public string state { get; set; }
- public string message { get; set; }
- public SmS data { get; set; }
- }
- public class SmS
- {
- public string returnstatus;
- public string message;
- public string remainpoint;
- public string taskID;
- public string successCounts;
- }
-
- /// <summary>
- /// 新增短信模板
- /// </summary>
- /// <param name="name"></param>
- /// <param name="cont"></param>
- /// <param name="mName"></param>
- /// <returns></returns>
- public ActionResult AddTemplate(string name, string cont)
- {
- int userId = CurrentUser.UserData.F_UserId;
- if (userId != 0)
- {
- Model.T_SMS_Template dModel = new Model.T_SMS_Template();
- Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
- string MID = ""; string MName = "";
- if (ua != null)
- {
- MID = ua.F_UserCode;
- MName = ua.F_UserName;
- }
- dModel.Detail = cont.Trim();
- dModel.Name = name.Trim();
- dModel.MID = MID.Trim();
- dModel.MName = MName.Trim();
- dModel.CreateDate = DateTime.Now;
- dModel.IsEnable = 0;
- int b = new BLL.T_SMS_Template().Add(dModel);
- if (b > 0)
- {
- return Success("添加成功");
- }
- else
- {
- return Success("添加失败");
- }
- }
- else
- return Error("无操作权限!");
- }
- /// <summary>
- /// 修改短信模板
- /// </summary>
- /// <param name="name"></param>
- /// <param name="cont"></param>
- /// <param name="mName"></param>
- /// <returns></returns>
- public ActionResult UpdateTemplate(int id, string name, string cont)
- {
- int userId = CurrentUser.UserData.F_UserId;
- if (userId != 0)
- {
- if (id <= 0)
- return Error("参数错误!");
- var model = new BLL.T_SMS_Template().GetModel(id);
- if (model == null)
- return Error("查询不到此模板!");
- Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
- string MID = ""; string MName = "";
- if (ua != null)
- {
- MID = ua.F_UserCode;
- MName = ua.F_UserName;
- }
- model.Detail = cont.Trim();
- model.Name = name.Trim();
- model.MID = MID.Trim();
- model.MName = MName.Trim();
- model.CreateDate = DateTime.Now;
- model.IsEnable = 0;
- if (new BLL.T_SMS_Template().Update(model))
- {
- return Success("修改成功");
- }
- else
- {
- return Error("修改失败");
- }
- }
- else
- return Error("无操作权限!");
- }
- /// <summary>
- /// 删除短信模板
- /// </summary>
- /// <param name="ids"></param>
- /// <returns></returns>
- public ActionResult DelTemplate(string[] ids)
- {
- int userId = CurrentUser.UserData.F_UserId;
- if (userId != 0)
- {
- if (ids != null && ids.Length > 0)
- {
- bool res = true;
- string idd = " ";
- foreach (string str in ids)
- {
- idd += str + ",";
- }
- if (!string.IsNullOrEmpty(idd.Trim()))
- {
- if (new BLL.T_SMS_Template().DeleteList(idd.TrimEnd(',')))
- {
- if (new BLL.T_SMS_Template().DeleteList(idd.TrimEnd(',')))
- {
- return Success("设置成功");
- }
- else
- {
- return Error("设置失败");
- }
- }
- else
- {
- return Error("设置失败");
- }
- }
- else
- {
- return Error("请选择工单");
- }
- }
- else
- {
- return Error("获取参数失败");
- }
- }
- else
- {
- return Error("无操作权限!");
- }
- }
- /// <summary>
- /// 删除短信记录列表
- /// </summary>
- /// <param name="ids"></param>
- /// <returns></returns>
- public ActionResult DelSMSList(string[] ids)
- {
- int userId = CurrentUser.UserData.F_UserId;
- if (userId != 0)
- {
- if (ids != null && ids.Length > 0)
- {
- bool res = true;
- string idd = " ";
- foreach (string str in ids)
- {
- idd += str + ",";
- }
- if (!string.IsNullOrEmpty(idd.Trim()))
- {
- if (new BLL.T_SMS_List().DeleteList(idd.TrimEnd(',')))
- {
- if (new BLL.T_SMS_List().DeleteList(idd.TrimEnd(',')))
- {
- return Success("设置成功");
- }
- else
- {
- return Error("设置失败");
- }
- }
- else
- {
- return Error("设置失败");
- }
- }
- else
- {
- return Error("请选择工单");
- }
- }
- else
- {
- return Error("获取参数失败");
- }
- }
- else
- {
- return Error("无操作权限!");
- }
- }
- /// <summary>
- /// 获取短信模板列表
- /// </summary>
- /// <returns></returns>
- public ActionResult GetTemplateList(string name, string keywords,int page=1,int pagesize=5)
- {
- int userId = CurrentUser.UserData.F_UserId;
- if (userId != 0)
- {
- DataTable dt = new DataTable();
- string sql = $" and IsEnable=0";
- if (!string.IsNullOrWhiteSpace(keywords))//关键字搜索
- sql += $" and ( Detail like '%" + keywords.Trim() + "%'or Name like '%" + keywords.Trim() + "%' or MName like '%" + keywords.Trim() + "%' ) ";
- if (!string.IsNullOrWhiteSpace(name))//
- sql += $" and Name like '%" + name.Trim() + "%'";
- // var modellist = new BLL.T_SMS_Template().GetModelList(sql);
-
- int recordCount = 0;
- dt = BLL.PagerBLL.GetListPager(
- "T_SMS_Template",
- "T_SMS_Template.ID",
- "*",
- sql,
- "ORDER BY T_SMS_Template.ID desc",
- pagesize,
- page,
- true,
- out recordCount);
- List<Model.T_SMS_Template> modlelist = new BLL.T_SMS_Template().DataTableToList(dt);
- var obj = new
- {
- state = "success",
- message = "成功",
- rows = modlelist,
- total = recordCount
- };
- return Content(obj.ToJson());
- }
- else
- return Error("无操作权限!");
- }
- /// <summary>
- /// 获取模板详情
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public ActionResult GetContentTemp(string name)
- {
- int userId = CurrentUser.UserData.F_UserId;
- if (userId != 0)
- {
- Model.T_SMS_Template dModel = new Model.T_SMS_Template();
- if (string.IsNullOrEmpty(name.Trim()))
- return Error("短信类型不能为空!");
- var model = new BLL.T_SMS_Template().GetModelList($"Name like '%" + name.Trim() + "%'").FirstOrDefault();
- if (model == null)
- return Error("查询不到此模板!");
- return Success("获取成功", model);
- }
- else
- return Error("无操作权限!");
- }
- /// <summary>
- /// 获取模板详情
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public ActionResult GetDetailsTemp(int id)
- {
- int userId = CurrentUser.UserData.F_UserId;
- if (userId != 0)
- {
- Model.T_SMS_Template dModel = new Model.T_SMS_Template();
- if (id <= 0)
- return Error("参数错误!");
- var model = new BLL.T_SMS_Template().GetModel(id);
- if (model == null)
- return Error("查询不到此模板!");
- return Success("获取成功", model);
- }
- else
- return Error("无操作权限!");
- }
- /// <summary>
- /// 导入excel
- /// </summary>
- public ActionResult ImportExcel()
- {
- int userId = CurrentUser.UserData.F_UserId;
- if (userId != 0)
- {
- string usercode = CurrentUser.UserData.F_UserCode;
- string ip = DTRequest.GetIP();
- if (!string.IsNullOrWhiteSpace(usercode))
- {
- HttpPostedFile _upFile = RequestString.GetFile("upFile");
- if (_upFile != null)
- {
- int headrow = 0;
- #region 上传文件
- string filepath = "";
- string datepath = DateTime.Now.ToString("yyyyMMddHHMMss");
- string aLastName = Path.GetExtension(_upFile.FileName);
- string oriname = Path.GetFileNameWithoutExtension(_upFile.FileName);
- if (aLastName != ".xls" && aLastName != ".xlsx")
- {
- return Error("文件类型错误,请选择Excel文件");
- }
- string newpath = datepath + "_" + _upFile.FileName;
- if (!Directory.Exists(Server.MapPath(this.Request.ApplicationPath + "\\ExcelData")))
- {
- Directory.CreateDirectory(Server.MapPath(this.Request.ApplicationPath + "\\ExcelData"));
- }
- filepath = this.Request.ApplicationPath + "/ExcelData/" + newpath;
- string PhysicalPath = Server.MapPath(filepath);
- _upFile.SaveAs(PhysicalPath);
- #endregion
- #region 添加附件日志
- Model.T_Sys_Accessories model_T_Sys_Accessories = new Model.T_Sys_Accessories();
- model_T_Sys_Accessories.F_AddTime = DateTime.Now;//上传时间
- model_T_Sys_Accessories.F_FileName = newpath;//附件名称
- model_T_Sys_Accessories.F_FileType = aLastName;//附件类型
- model_T_Sys_Accessories.F_FileUrl = filepath;//附件地址
- model_T_Sys_Accessories.F_UserCode = usercode;//上传人
- int fid = new BLL.T_Sys_Accessories().Add(model_T_Sys_Accessories);
- #endregion
- NPOIHelper np = new NPOIHelper();
- DataTable dt = np.ExcelToTable(_upFile, headrow);
- string msg = string.Empty;
- if (dt == null || dt.Rows.Count == 0)
- return Error("文件没有数据");
- else
- {
- Model.T_SMS_Template dModel = new Model.T_SMS_Template();
- Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
- string MID = ""; string MName = "";
- if (ua != null)
- {
- MID = ua.F_UserCode;
- MName = ua.F_UserName;
- }
- dModel.MID = MID.Trim();
- dModel.MName = MName.Trim();
- dModel.CreateDate = DateTime.Now;
- dModel.IsEnable = 0;
- foreach (DataRow dr in dt.Rows)
- {
- #region 数据入库
- headrow = headrow + 1;
- if (dr["短信类型"].ToString() != "")
- {
- if (!getunique( dr["短信类型"].ToString()))
- {
- dModel.Name = dr["短信类型"].ToString();
- dModel.Detail = dr["短信内容"].ToString();
- var res = new BLL.T_SMS_Template().Add(dModel);
- if (res < 0)
- {
- msg = msg + "第" + headrow + "行,导入失败<br>";
- }
- }
- else
- {
- msg = msg + "第" + headrow + "行,短信类型重复,未导入<br>";
- }
- }
- else
- msg = msg + "第" + headrow + "行,短信类型为空或格式不正确,未导入<br>";
- #endregion
- }
- if (string.IsNullOrEmpty(msg))
- return Success("导入成功 ");
- else
- return Error(msg);
- }
- }
- return Error("数据源上传失败");
- }
- }
- return Error("用户登录失败,请重新登录");
- }
- /// <summary>
- /// 验证短信类型是否唯一
- /// </summary>
- private bool getunique( string Name)
- {
- var sql = " IsEnable=0 ";
- sql += "and (Name='" + Name + "')";
- var count = new BLL.T_SMS_Template().GetModelList(sql).Count();
- return count > 0;
- }
- /// <summary>
- /// 新增短信记录
- /// </summary>
- /// <returns></returns>
- public bool AddSMSList(int SendWay, DateTime DSSendTime, DateTime SendTime, int IsSend,
- string Telephone, string Detail, int MBID)
- {
- int userId = CurrentUser.UserData.F_UserId;
- Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
- string MID = ""; string MName = "";
- if (ua != null)
- {
- MID = ua.F_UserCode;
- MName = ua.F_UserName;
- }
- Model.T_SMS_List dModel = new Model.T_SMS_List();
- dModel.SendWay = SendWay;
- dModel.DSSendTime = DSSendTime;
- dModel.SendTime = SendTime;
- dModel.IsSend = IsSend;
- dModel.Telephone = Telephone;
- dModel.Detail = Detail;
- dModel.MBID = MBID;
- dModel.MID = MID;
- dModel.MName = MName;
- dModel.F_IsDelete = 0;
- dModel.CreateDate = DateTime.Now;
- int b = new BLL.T_SMS_List().Add(dModel);
- if (b > 0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- /// <summary>
- /// 导出短信记录
- /// </summary>
- /// <param name="stime"></param>
- /// <param name="endtime"></param>
- /// <returns></returns>
- public ActionResult ExitTypelist(string name, string phone, string creatname, int SendWay=-1, int IsSend=-1)
- {
- DataTable dt = new DataTable();
- string sql = $" F_IsDelete=0";
- if (!string.IsNullOrEmpty(name))
- {
- var model = new BLL.T_SMS_Template().GetModelList($"Name like '%" + name.Trim() + "%'").FirstOrDefault();
- if (model!=null )
- {
- sql += " and MBID=" + model.ID ;
- }
- }
- if (!string.IsNullOrEmpty(phone))
- sql += " and Telephone=" + phone;
- if (SendWay>=0)
- sql += " and SendWay=" + SendWay;
- if (IsSend >= 0)
- sql += " and IsSend=" + IsSend;
- if (!string.IsNullOrEmpty(creatname))
- sql += $" and ( MID like '%" + creatname.Trim() + "%'or MName like '%" + creatname.Trim() + "%') ";
- dt.Columns.Add("编号");
- dt.Columns.Add("接收号码");
- dt.Columns.Add("发送内容");
- dt.Columns.Add("发送方式");
- dt.Columns.Add("发送状态");
- dt.Columns.Add("发送时间");
- dt.Columns.Add("短信类型");
- dt.Columns.Add("发送人");
- var itemlist = new BLL.T_SMS_List().GetModelList(sql);
- foreach (var it in itemlist)
- {
- DataRow drNew = dt.NewRow();
- drNew["编号"] =it .ID ;
- drNew["接收号码"] = it.Telephone ;
- drNew["发送内容"] = it.Detail ;
- if (it .SendWay==0 )
- drNew["发送方式"] = "立即发送";
- else
- drNew["发送方式"] = "定时发送";
- drNew["发送时间"] = it.SendTime ;
- if (it.IsSend==1)
- drNew["发送状态"] = "已发送";
- else
- drNew["发送状态"] = "未发送";
- if (it.MBID>0)
- {
- var model = new BLL.T_SMS_Template().GetModel(int.Parse(it.MBID.ToString()));
- if (model != null)
- {
- drNew["短信类型"]= model.Name ;
- }
- }
- drNew["发送人"] =it .MID +"("+it.MName +")";
- dt.Rows.Add(drNew);
- }
- NPOIHelper npoi = new NPOIHelper();
- if (npoi.ExportToExcel("短信记录", dt) == "")
- {
- return Success("导出成功");
- }
- else
- {
- return Error("导出失败");
- }
- }
- /// <summary>
- /// 修改短信记录列表
- /// </summary>
- /// <returns></returns>
- public ActionResult UpdateSMSList(int id, int SendWay, DateTime DSSendTime, DateTime SendTime, int IsSend,
- string Telephone, string Detail, int MBID, DateTime CreateDate)
- {
- int userId = CurrentUser.UserData.F_UserId;
- if (userId != 0)
- {
- if (id <= 0)
- return Error("参数错误!");
- var model = new BLL.T_SMS_List().GetModel(id);
- if (model == null)
- return Error("查询不到此模板!");
- Model.T_Sys_UserAccount ua = new BLL.T_Sys_UserAccount().GetModel(userId);
- string MID = ""; string MName = "";
- if (ua != null)
- {
- MID = ua.F_UserCode;
- MName = ua.F_UserName;
- }
- model.SendWay = SendWay;
- model.DSSendTime = DSSendTime;
- model.SendTime = SendTime;
- model.IsSend = IsSend;
- model.Telephone = Telephone;
- model.Detail = Detail;
- model.MBID = MBID;
- model.MID = MID;
- model.MName = MName;
- model.CreateDate = DateTime.Now;
- bool b = new BLL.T_SMS_List().Update(model);
- if (b)
- {
- return Success("修改成功");
- }
- else
- {
- return Error("修改失败");
- }
- }
- else
- return Error("无操作权限");
- }
- /// <summary>
- /// 获取短信记录列表
- /// </summary>
- /// <returns></returns>
- public ActionResult GetSMSList(string name, string phone, string creatname ,int SendWay=-1, int IsSend=-1, int page = 1, int pagesize = 10)
- {
- DataTable dt = new DataTable();
- int userId = CurrentUser.UserData.F_UserId;
- if (userId != 0)
- {
-
- string sql = $"and F_IsDelete=0";
- if (!string.IsNullOrEmpty(name))
- {
- var model = new BLL.T_SMS_Template().GetModelList($"Name like '%" + name.Trim() + "%'").FirstOrDefault();
- if (model != null)
- {
- sql += " and MBID=" + model.ID;
- }
- }
- if (!string.IsNullOrEmpty(phone))
- sql += " and Telephone like'%" + phone+"%'";
- if (SendWay >= 0)
- sql += " and SendWay=" + SendWay;
- if (IsSend >= 0)
- sql += " and IsSend=" + IsSend;
- if (!string.IsNullOrEmpty(creatname))
- sql += $" and ( MID like '%" + creatname.Trim() + "%'or MName like '%" + creatname.Trim() + "%') ";
- int recordCount = 0;
- if (!string.IsNullOrWhiteSpace(sql))
- {
- dt = BLL.PagerBLL.GetListPager(
- "T_SMS_List",
- "T_SMS_List.ID",
- "*",
- sql,
- "ORDER BY T_SMS_List.ID desc",
- pagesize,
- page,
- true,
- out recordCount);
- }
- var modlelist = new BLL.T_SMS_List().DataTableToList(dt);
- //var modellist = new BLL.T_SMS_List().GetModelList(sql);
- var obj = new
- {
- state = "success",
- message = "成功",
- rows = ModeltoSMSList( modlelist),
- total= recordCount
- };
- return Content(obj.ToJson());
- }
- else
- return Error("无操作权限");
- }
- public List<SMSList> ModeltoSMSList(List <Model .T_SMS_List> list)
- {
- List<SMSList> modellist = new List<SMSList>();
- foreach (var it in list)
- {
- SMSList model = new SMSList();
- model.ID = it.ID;
- if (it.SendWay == 0)
- model.SendWay = "立即发送";
- else
- model.SendWay = "定时发送";
- model.DSSendTime = it.DSSendTime.ToString ();
- model.SendTime = it.SendTime.ToString();
- if (it.IsSend == 0)
- model.IsSend = "未发送";
- else
- model.IsSend = "已发送";
- model.Telephone = it.Telephone;
- model.Detail = it.Detail;
- if (it.MBID>0)
- {
- var MID = new BLL.T_SMS_Template().GetModel(int.Parse(it.MBID.ToString()));
- if (MID != null)
- model.MBDetail = MID.Name;
- }
- model.MID = it.MID;
- model.MName = it.MName;
- model.CreateDate = it.CreateDate.ToString ();
- modellist.Add(model);
- }
- return modellist;
- }
- /// <summary>
- /// 导入号码
- /// </summary>
- /// <returns></returns>
- public ActionResult ImportSend()
- {
- int userId = CurrentUser.UserData.F_UserId;
- if (userId != 0)
- {
- string usercode = CurrentUser.UserData.F_UserCode;
- string ip = DTRequest.GetIP();
- if (!string.IsNullOrWhiteSpace(usercode))
- {
- HttpPostedFile _upFile = RequestString.GetFile("upFile");
- if (_upFile != null)
- {
- int headrow = 0;
- #region 上传文件
- string filepath = "";
- string datepath = DateTime.Now.ToString("yyyyMMddHHMMss");
- string aLastName = Path.GetExtension(_upFile.FileName);
- string oriname = Path.GetFileNameWithoutExtension(_upFile.FileName);
- if (aLastName != ".xls" && aLastName != ".xlsx")
- {
- return Error("文件类型错误,请选择Excel文件");
- }
- string newpath = datepath + "_" + _upFile.FileName;
- if (!Directory.Exists(Server.MapPath(this.Request.ApplicationPath + "\\ExcelData")))
- {
- Directory.CreateDirectory(Server.MapPath(this.Request.ApplicationPath + "\\ExcelData"));
- }
- filepath = this.Request.ApplicationPath + "/ExcelData/" + newpath;
- string PhysicalPath = Server.MapPath(filepath);
- _upFile.SaveAs(PhysicalPath);
- #endregion
- #region 添加附件日志
- Model.T_Sys_Accessories model_T_Sys_Accessories = new Model.T_Sys_Accessories();
- model_T_Sys_Accessories.F_AddTime = DateTime.Now;//上传时间
- model_T_Sys_Accessories.F_FileName = newpath;//附件名称
- model_T_Sys_Accessories.F_FileType = aLastName;//附件类型
- model_T_Sys_Accessories.F_FileUrl = filepath;//附件地址
- model_T_Sys_Accessories.F_UserCode = usercode;//上传人
- int fid = new BLL.T_Sys_Accessories().Add(model_T_Sys_Accessories);
- #endregion
- NPOIHelper np = new NPOIHelper();
- DataTable dt = np.ExcelToTable(_upFile, headrow);
- string msg = string.Empty;
- string tels= string.Empty;
- if (dt == null || dt.Rows.Count == 0)
- return Error("文件没有数据");
- else
- {
- foreach (DataRow dr in dt.Rows)
- {
- #region 数据入库
- headrow = headrow + 1;
- if (dr["号码"].ToString() != "")
- {
- if (string.IsNullOrEmpty(tels))
- {
- tels = dr["号码"].ToString();
- }
- else
- {
- tels = tels + "," + dr["号码"].ToString();
- }
- }
- else
- msg = msg + "第" + headrow + "行,号码为空或格式不正确,未导入<br>";
- #endregion
- }
- if (string.IsNullOrEmpty(msg))
- return Success("获取成功 ", tels);
- else
- return Error(msg);
- }
- }
- return Error("数据源上传失败");
- }
- }
- return Error("用户登录失败,请重新登录");
- }
- #endregion
- public class SMSList
- {
- public int ID;
- public string SendWay;
- public string DSSendTime;
- public string SendTime;
- public string IsSend;
- public string Telephone;
- public string Detail;
- public string MBDetail;
- public string MID;
- public string MName;
- public string CreateDate;
- }
- }
-
- }
|