tijian_tieying/web/dccdc/Controllers/Charge4Controller.cs
2025-02-20 12:14:39 +08:00

1243 lines
61 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using dccdc.BLL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using dccdc.DAL;
using dccdc.Models;
using static dccdc.Controllers.DictionariesController;
using static dccdc.Controllers.QueryStatisticsController;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Core;
using Aliyun.Acs.Dysmsapi.Model.V20170525;
using System.Reflection;
using Aliyun.Acs.Core.Exceptions;
using dccdc.Models.DTO;
using System.IO;
using NPOI.HSSF.UserModel;
using NPOI.HPSF;
using NPOI.HSSF.Util;
using NPOI.POIFS.FileSystem;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System.Net;
using System.Security.Cryptography;
using System.Text;
namespace dccdc.Controllers
{
public class Charge4Controller : Controller
{
public ActionResult ymzs()
{
return View();
}
public ActionResult tfsq()
{
return View();
}
public ActionResult YMDJJL()
{
return View();
}
public ActionResult getJFDJ(string xm)
{
var bll = new YMDJBll();
var result = bll.getJFDJ(xm);
return Json(new { Rows = result });
}
public ActionResult getTFDJ(string xm)
{
var bll = new YMDJBll();
var result = bll.getTFDJ(xm);
return Json(new { Rows = result });
}
public ActionResult saveTFSQ(string id)
{
var bll = new ymzsBll();
OperationResult or = bll.tfsq(id, Session["loginUser"] as Models.ERPUser);
return Json(new { State = or.State, Message = or.Message });
}
public ActionResult ZSYM(string id)
{
var bll = new ymzsBll();
OperationResult or = bll.zsym(id, Session["loginUser"] as Models.ERPUser);
return Json(new { State = or.State, Message = or.Message });
}
public ActionResult delDj(string id)
{
var bll = new YMDJBll();
OperationResult or = bll.delDj(Session["loginUser"] as Models.ERPUser, id);
return Json(new { State = or.State, Message = or.Message });
}
public ActionResult getYMDJMX(string ymdjbid)
{
var bll = new YMDJMXBll();
var result = bll.getMX(ymdjbid);
return Json(new { Rows = result });
}
// GET: Charge2
public ActionResult Index()
{
ViewBag.jfbmD = new SelectList(new ERPBuMenBll().GetAllList(""), "bumenname", "bumenname", (Session["loginUser"] as Models.ERPUser).Department);
ViewBag.jffs = new SelectList(new List<Droplist> { new Droplist { Value = "现金", Title = "现金" }, new Droplist { Value = "转账", Title = "转账" } }, "Value", "Title");
ViewBag.rylb = new SelectList(new List<Droplist> { new Droplist { Value = "儿童", Title = "儿童" }, new Droplist { Value = "成人", Title = "成人" } }, "Value", "Title", "儿童");
return View();
}
public String GetYmyyjl(string id)
{
var bll = new YMDJMXBll();
var result = bll.getYmyyjl(id);
return Newtonsoft.Json.JsonConvert.SerializeObject(result, new Newtonsoft.Json.JsonSerializerSettings { DateFormatString = "yyyy-MM-dd" });
}
public String GetJzymTmdy(string id)
{
var bll = new YMDJMXBll();
var result = bll.GetJzymTmdy(id);
return Newtonsoft.Json.JsonConvert.SerializeObject(result, new Newtonsoft.Json.JsonSerializerSettings { DateFormatString = "yyyy-MM-dd" });
}
public String GetYmsList(string ymList)
{
var bll = new YMDJMXBll();
var result = bll.GetYmsList(ymList);
return Newtonsoft.Json.JsonConvert.SerializeObject(result, new Newtonsoft.Json.JsonSerializerSettings { DateFormatString = "yyyy-MM-dd" });
}
public String GetYmjzlcList(string jdid)
{
var bll = new YMDJMXBll();
var result = bll.GetYmjzlcList(jdid);
return Newtonsoft.Json.JsonConvert.SerializeObject(result, new Newtonsoft.Json.JsonSerializerSettings { DateFormatString = "yyyy-MM-dd" });
}
public ActionResult getCharge(string start, string end, string tm)
{
if (string.IsNullOrEmpty(start) || string.IsNullOrEmpty(end))
return Json(null);
var bll = new chargeBll();
var result = bll.GetAllList3(start, end, tm, (Session["loginUser"] as Models.ERPUser).TrueName);
return Json(new { Rows = result });
}
#region
public ActionResult Ymtj()
{
return View();
}
public ActionResult Ymtj2()
{
return View();
}
[AllowAnonymous]
public string getYmtjList(string rq, string xm, string alluser = "false")
{
if (string.IsNullOrEmpty(rq))
return null;
return Newtonsoft.Json.JsonConvert.SerializeObject(new BLL.chargeBll().getYmList(rq.Split('|')[0].ToString(), rq.Split('|')[1].ToString(), xm));
}
public string getYmtj(string start, string end, string alluser = "false")
{
if (string.IsNullOrEmpty(start) || string.IsNullOrEmpty(end))
return "";
var bll = new chargeBll();
DataTable dt = new DataTable();
dt.Columns.Add("ymname1", typeof(string));
dt.Columns.Add("sl1", typeof(string));
dt.Columns.Add("je1", typeof(string));
dt.Columns.Add("ymname2", typeof(string));
dt.Columns.Add("sl2", typeof(string));
dt.Columns.Add("je2", typeof(string));
var result = bll.getYmList(start, end, alluser == "true" ? "" : (Session["loginUser"] as Models.ERPUser).TrueName);
int i = 1;
if (result != null)
{
DataRow dr = dt.NewRow();
foreach (var r in result)
{
if (i % 2 != 0)
{
dr["ymname1"] = r.name;
dr["sl1"] = r.sl;
dr["je1"] = r.je;
if (result.Count() == i)
{
dr["ymname2"] = "";
dr["sl2"] = "";
dr["je2"] = "";
dt.Rows.Add(dr.ItemArray);
}
}
else
{
dr["ymname2"] = r.name;
dr["sl2"] = r.sl;
dr["je2"] = r.je;
dt.Rows.Add(dr.ItemArray);
}
i++;
}
}
List<cols> cls = new List<cols>();
cls.Add(new cols { name = "ymname1", display = "疫苗名称", width = 120 });
cls.Add(new cols { name = "sl1", display = "数量", width = 120 });
cls.Add(new cols { name = "je1", display = "金额", width = 120 });
cls.Add(new cols { name = "ymname2", display = "疫苗名称", width = 120 });
cls.Add(new cols { name = "sl2", display = "数量", width = 120 });
cls.Add(new cols { name = "je2", display = "金额", width = 120 });
var data = new { Rows = dt };
return Newtonsoft.Json.JsonConvert.SerializeObject(new { columns = cls, data = data });
}
#endregion
public ActionResult getSFXMData(string id, string sfxm)
{
var bll = new vaccineBll();
var result = bll.getAllList(sfxm);
return Json(new { Rows = result });
}
public JsonResult opSave(string jfdw, string register_num, string jfbm, string jffs, string ysje, string items, string jmsq, string jdbm, string ertbm)
{
if (string.IsNullOrEmpty(jfdw) || string.IsNullOrEmpty(items))
return Json(new { count = 0 });
var bll = new chargeBll();
var result = bll.opSave1(jfdw, register_num, jfbm, jffs, ysje, items, Session["loginUser"] as Models.ERPUser, "疫苗收费", jmsq, jdbm, ertbm);// Session["loginUser"] as Models.ERPUser
return Json(result);
}
public JsonResult getJZMYTM(string id)
{
var bll = new BLL.JiezhongmianyitiaomaModelBll();
List<Models.JiezhongmianyitiaomaModel> ctList = bll.getList(id);
if (ctList.Count > 0)
{
return Json(new { obj = ctList[0] });
}
else
{
return Json(new { obj = "" });
}
}
public JsonResult getFJX(string id)
{
var bll = new BLL.ChargeProjectMaintainBll();
List<Models.ChargeProjectMaintainModel> ctList = bll.getAddList(id);
return Json(ctList);
}
#region
public ActionResult Jmyy(string ertbm)
{
ViewData["vaccine"] = new SelectList(new BLL.vaccineBll().getAllList(""), "id", "name");
ViewData["ymjd"] = new SelectList(new BLL.ym_jzlcBll().getAllYMJDList(), "id", "name");
ViewBag.ertbm = ertbm;
var bll = new BLL.ym_jzlcBll();
var list = bll.getAllListByErtbm(ertbm);
ym_jzlcjl jl = bll.getYmjzlcjlByErtbm(ertbm);
ym_jzlc lc = bll.getYmjzlcByErtbm(jl.jdid.ToString());
DateTime dt1 = Convert.ToDateTime(jl.jzsj).AddDays(lc.jgts);
ViewBag.yysj = dt1;
ViewData["list"] = list;
return View();
}
public String GetAllYmJzlc(string ertbm)
{
var bll = new BLL.ym_jzlcBll();
var list = bll.getAllJzlcList(ertbm);
return Newtonsoft.Json.JsonConvert.SerializeObject(new { Rows = list });
}
public JsonResult SaveYmyy(string ertbm, string yysj, string jdid, string yms)
{
ym_yyjl ymyy = new ym_yyjl();
ymyy.ertbm = ertbm;
ymyy.yysj = Convert.ToDateTime(yysj);
ymyy.jdid = Convert.ToInt32(jdid);
ymyy.ymList = yms.TrimStart(new char[] { ',' }).TrimEnd(new char[] { ',' });
var bll = new chargeBll();
var result = bll.saveYmyy(ymyy);
return Json(result);
}
#endregion
/// <summary>
/// 减免申请
/// </summary>
/// <returns></returns>
public ActionResult Jmsq(string chargeid)
{
ViewBag.chargeid = chargeid;
return View();
}
/// <summary>
///
/// </summary>
/// <param name="chargeid"></param>
/// <param name="jmlx"></param>
/// <returns></returns>
public JsonResult JmsqsfxmData(string chargeid, string jmlx)
{
charge_detailBll bll = new charge_detailBll();
List<charge_detailModel> al = bll.GetModelsBychargeId(chargeid, jmlx);
return Json(new { Rows = al });
//根据疫苗ID获取收费项目 (根据减免类型查询不同收费项目)
}
/// <summary>
/// 减免审核界面
/// </summary>
/// <returns></returns>
public ActionResult JmsqListResult()
{
ViewBag.lx = new SelectList(new List<Droplist> { new Droplist { Value = "0", Title = "审核中" }, new Droplist { Value = "1", Title = "通过" }, new Droplist { Value = "2", Title = "未通过" } }, "Value", "Title");
return View();
}
/// <summary>
/// 获取减免申请列表
/// </summary>
/// <returns></returns>
public JsonResult GetJmsqList(string lx, string xm, string sqsjb, string sqsje, string all)
{
DateTime dte;
if (DateTime.TryParse(sqsje, out dte))
{
sqsje = (dte.AddDays(1)).ToString("yyyy-MM-dd");
}
JmsqBll bll = new JmsqBll();
//此处参数配置根据管理员可查询不同减免类型数据先写死
BLL.Common combll = new BLL.Common();
string jffjid = combll.getParm_Value("jmfjid", "1", "可减免附件项的用户ID");
string jfqbid = combll.getParm_Value("jmqbid", "1", "可减免全部项的用户ID");
if (all == "true")
{
return Json(new { Rows = bll.GetJmsqList(lx, "-1", xm, sqsjb, sqsje) });
}
var user = Session["loginUser"] as Models.ERPUser;
if (user.ID.ToString() == jfqbid)
{
string jmlx = "-1";
return Json(new { Rows = bll.GetJmsqList(lx, jmlx, xm, sqsjb, sqsje) });
}
else if (user.ID.ToString() == jffjid)
{
string jmlx = "0";
return Json(new { Rows = bll.GetJmsqList(lx, jmlx, xm, sqsjb, sqsje) });
}
else
{
return Json(new { Rows = new List<JmsqModel>() });
}
}
public JsonResult expJMJL(string lx, string xm, string sqsjb, string sqsje, string all)
{
DateTime dte;
if (DateTime.TryParse(sqsje, out dte))
{
sqsje = (dte.AddDays(1)).ToString("yyyy-MM-dd");
}
JmsqBll bll = new JmsqBll();
//此处参数配置根据管理员可查询不同减免类型数据先写死
BLL.Common combll = new BLL.Common();
string jffjid = combll.getParm_Value("jmfjid", "1", "可减免附件项的用户ID");
string jfqbid = combll.getParm_Value("jmqbid", "1", "可减免全部项的用户ID");
DataTable expdt;
if (all == "true")
{
expdt = bll.expJMJL(lx, "-1", xm, sqsjb, sqsje);
}
var user = Session["loginUser"] as Models.ERPUser;
if (user.ID.ToString() == jfqbid)
{
string jmlx = "-1";
expdt = bll.expJMJL(lx, jmlx, xm, sqsjb, sqsje);
}
else if (user.ID.ToString() == jffjid)
{
string jmlx = "0";
expdt = bll.expJMJL(lx, jmlx, xm, sqsjb, sqsje);
}
else
{
return Json(new { State = 0, Message = "没有导出的数据" });
}
string path = Server.MapPath("~/export");
if (!System.IO.Directory.Exists(path))
{
System.IO.Directory.CreateDirectory(path);
}
string fn = Guid.NewGuid().ToString("N") + ".xlsx";
path += "\\" + fn;
if (expdt == null)
{
return Json(new { State = 0, Message = "没有要导出的数据!" });
}
try
{
xiaoy.Excel.ExcelFile.SetData(expdt, path, xiaoy.Excel.ExcelVersion.Excel12, xiaoy.Excel.HDRType.Yes);
return Json(new { State = 1, Message = Url.Content("~/export/" + fn) });
}
catch (Exception ex)
{
return Json(new { State = 0, Message = ex.Message });
}
}
public ActionResult JmmxResult(string jmid)
{
ViewBag.jmid = jmid;
return View();
}
public JsonResult GetJmmxList(string jmsqid)
{
JmmxBll bll = new JmmxBll();
List<JmmxModel> models = bll.GetJmmxList(jmsqid);
List<JmmxVModel> vmmodels = new List<JmmxVModel>();
ChargeProjectMaintainBll bll1 = new ChargeProjectMaintainBll();
List<ChargeProjectMaintainModel> sfxmal = bll1.GetAllList("", "是");
foreach (var m in models)
{
JmmxVModel m1 = new JmmxVModel
{
sfxm = sfxmal.First(i => i.id.ToString() == m.sfxmid).charge_project_name,
jmdj = Convert.ToDouble(m.jmdj),
sfxmid = Convert.ToInt32(m.sfxmid),
jmsl = m.jmsl
};
vmmodels.Add(m1);
}
return Json(new { Rows = vmmodels });
}
public JsonResult UpdateJmsqLx(string jmsqid, string lx)
{
JmsqBll bll = new JmsqBll();
var erpUser = Session["loginUser"] as Models.ERPUser;
Models.DTO.ymshjg f = bll.UpdateJmsq(jmsqid, lx, erpUser);
if (f.jz != "")
{
var commonbll = new BLL.Common();
string yddx = commonbll.getParm_Value("qyyddx", "false", "是否启用移动短信");
f.sp = erpUser.TrueName;
if (yddx == "false")
{
string AccessKeyID = commonbll.getParm_Value("AccessKeyID", "LTAIWq3410bmP7hi", "阿里AccessKeyID");
string AccessKeySecret = commonbll.getParm_Value("AccessKeySecret", "F953Ru3uZN2ZbS5741zvO9OvHrthNV", "阿里AccessKeySecret");
string qm = commonbll.getParm_Value("aldxqm", "三才网络", "短信签名");
string dxmb = commonbll.getParm_Value("aldxtzmb", "SMS_91930060", "短信模版");
//string smsurl = System.Configuration.ConfigurationManager.AppSettings["smsurl"];
//string yznr = "你好,欢迎你注册天瑞体检中心会员,你的验证码是:" + yzm.smscode + "。有效期10分钟。回TD退订【天瑞体检】";
//var zysms = new zyer.smsservice.SmsServiceSoapClient("SmsServiceSoap");
//var smsjg = zysms.SendEx(username, userpassword, "808", sjh, "", yznr);
//var fz = Session["FenZhan"] as Model.FenZhan;
//Common.SendMsg.Send(sjh, yznr, fz.id);
String product = "Dysmsapi";//短信API产品名称
String domain = "dysmsapi.aliyuncs.com";//短信API产品域名
String accessKeyId = AccessKeyID;//你的accessKeyId
String accessKeySecret = AccessKeySecret;//你的accessKeySecret
IClientProfile profile = DefaultProfile.GetProfile("cn-hangzhou", accessKeyId, accessKeySecret);
//IAcsClient client = new DefaultAcsClient(profile);
// SingleSendSmsRequest request = new SingleSendSmsRequest();
DefaultProfile.AddEndpoint("cn-hangzhou", "cn-hangzhou", product, domain);
IAcsClient acsClient = new DefaultAcsClient(profile);
SendSmsRequest request = new SendSmsRequest();
try
{
//必填:待发送手机号。支持以逗号分隔的形式进行批量调用批量上限为20个手机号码,批量调用相对于单条调用及时性稍有延迟,验证码类型的短信推荐使用单条调用的方式
request.PhoneNumbers = commonbll.getParm_Value("ymjmdxtz", "18653582965", "疫苗减免通知手机");
//必填:短信签名-可在短信控制台中找到
request.SignName = qm;
//必填:短信模板-可在短信控制台中找到
request.TemplateCode = dxmb;
//可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
request.TemplateParam = Newtonsoft.Json.JsonConvert.SerializeObject(f);
//可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
//request.OutId = "21212121211";
//请求失败这里会抛ClientException异常
SendSmsResponse sendSmsResponse = acsClient.GetAcsResponse(request);
//System.Console.WriteLine(sendSmsResponse.Message);
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(sendSmsResponse.Message);
}
catch (ServerException e)
{
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(e.Message + e.RequestId);
//System.Console.WriteLine("Hello World!");
//return Json(new { State = 0, Message = e.Message});
}
catch (ClientException e)
{
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(e.Message + e.RequestId);
//return Json(new { State = 0, Message = e.Message});
}
}
else
{
//http://112.35.1.155:1992/sms/norsubmit
string ydhttp = commonbll.getParm_Value("ydhttp", "http://112.35.1.155:1992/sms/tmpsubmit", "移动短信地址");
var req = new Models.duanxin.msend();
req.ecName = commonbll.getParm_Value("yddxqymc", "德州市德城区疾病预防控制中心", "企业名称");
req.apId = commonbll.getParm_Value("yddxapId", "jkoa", "接口账号用户名");
req.mobiles = commonbll.getParm_Value("ymjmdxtz", "18653582965", "疫苗减免通知手机");
req.sign = commonbll.getParm_Value("yddxsign", "d37CYmrbG", "签名编码");
//req.content = "由" + f.sp + "审批的疫苗缴费减免已生效;接种者" + f.jz + "应缴费" + f.yj + "实际缴费" + f.sj;
req.templateId = "44b9ed56aebc4b8fb4014f7c4c0ff00d";
req.addSerial = "";
string[] parms = new string[4];
parms[0] = f.sp;
parms[1] = f.jz;
parms[2] = f.yj;
parms[3] = f.sj;
req.parms = Newtonsoft.Json.JsonConvert.SerializeObject(parms);
var md5 = MD5.Create();
//secretKey
var bs = md5.ComputeHash(Encoding.UTF8.GetBytes(req.ecName + req.apId + commonbll.getParm_Value("yddxsecretKey", "a7551898", "短信接口密码") + req.templateId + req.mobiles + req.parms + req.sign));
var sb = new StringBuilder();
foreach (byte b in bs)
{
sb.Append(b.ToString("x2"));
}
req.mac = sb.ToString().ToLower();
WebClient wc = new WebClient();
string upstr = Newtonsoft.Json.JsonConvert.SerializeObject(req);
upstr = upstr.Replace("parms", "params");
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(upstr);
//new {params }
//upstr.Insert(upstr.Length-1,",")
byte[] resp = wc.UploadData(ydhttp, System.Text.Encoding.UTF8.GetBytes(Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(upstr))));
var nres = Newtonsoft.Json.JsonConvert.DeserializeObject<Models.duanxin.nrecive>(System.Text.Encoding.UTF8.GetString(resp));
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(System.Text.Encoding.UTF8.GetString(resp));
}
}
return Json(new { State = 1, Message = "操作成功!" },JsonRequestBehavior.AllowGet);
}
public JsonResult jmsqAdd(string chargeid, string jmlx, string ids)
{
JmsqDal dal = new JmsqDal();
charge_detailBll bll = new charge_detailBll();
List<JmmxModel> al = new List<JmmxModel>();
List<charge_detailModel> chargeDetailModels = bll.GetModelsBychargeId(chargeid, jmlx, ids);
chargeBll chbll = new chargeBll();
var chm = chbll.getModel(chargeid);
YMDJBll ymbll = new YMDJBll();
var ymdjm = ymbll.getDJByChargeID(chargeid);
var erpUser = Session["loginUser"] as Models.ERPUser;
if (erpUser != null)
{
JmsqModel model = new JmsqModel
{
lx = 0,
jmlx = Convert.ToInt32(jmlx),
sqrid = erpUser.ID,
sqrxm = erpUser.TrueName,
sqsj = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
xm = chm.person,
ymdjid = ymdjm.id.ToString()
};
foreach (charge_detailModel m in chargeDetailModels)
{
JmmxModel m1 = new JmmxModel
{
jmdj = m.money,
jmsl = m.count,
jmsqid = 1,
sfxmid = m.projectid,
detailid = m.id
};
al.Add(m1);
}
bool f = dal.Add(model, al);
}
return Json(new { State = 1, Message = "申请成功!" });
}
public ActionResult YMZSJL()
{
return View();
}
public JsonResult getYMZSJL(int page, int pagesize, ymzscxm cx)
{
var bll = new BLL.ymzsBll();
int count = bll.getZSCount(cx);
var list = bll.getZSList(page, pagesize, cx);
return Json(new { Total = count, Rows = list });
}
public JsonResult getYMDJJL(int page, int pagesize, string zsr, string djr, string djsjb, string djsje)
{
var bll = new BLL.YMDJBll();
int count = bll.getDJCount(zsr, djr, djsjb, djsje);
var list = bll.getDJList(page, pagesize, zsr, djr, djsjb, djsje);
return Json(new { Total = count, Rows = list });
}
public ActionResult ymjmshjl()
{
ViewBag.lx = new SelectList(new List<Droplist> { new Droplist { Value = "0", Title = "审核中" }, new Droplist { Value = "1", Title = "通过" }, new Droplist { Value = "2", Title = "未通过" } }, "Value", "Title");
return View();
}
public JsonResult delJMSQ(int id)
{
var erpUser = Session["loginUser"] as Models.ERPUser;
return Json(new BLL.JmsqBll().delJMSQ(id, erpUser));
}
//儿童疫苗导入
public ActionResult etdr()
{
return View();
}
public string impETDR(string drsj)
{
if (Request.Files.Count == 0)
{
return Newtonsoft.Json.JsonConvert.SerializeObject(new { State = 0, Message = "没有要处理的文件" });
}
else
{
try
{
string path = Server.MapPath("~/exec/");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
path = path + Guid.NewGuid().ToString("N") + Request.Files[0].FileName.Substring(Request.Files[0].FileName.LastIndexOf("."));
Request.Files[0].SaveAs(path);
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
HSSFWorkbook workbook = null;
workbook = new HSSFWorkbook(fs);
HSSFSheet sheet = workbook.GetSheetAt(0) as HSSFSheet;
//var bll = new BLL.JiezhongmianyitiaomaModelBll();
List<JiezhongmianyitiaomaModel> ymtl = new List<JiezhongmianyitiaomaModel>();
List<string> cols = new List<string>();
IRow row1 = sheet.GetRow(0);
for (int i = 0; i < row1.LastCellNum; i++)
{
cols.Add(row1.GetCell(i).StringCellValue);
}
var bll = new JiezhongmianyitiaomaModelBll();
for (int i = 1; i <= sheet.LastRowNum; i++)
{
string barcode = "";
//string username = "";
string csrq = "";
string sex = "";
//string sjh = "";
barcode = sheet.GetRow(i).GetCell(cols.IndexOf("受种者编号")).StringCellValue;
csrq = sheet.GetRow(i).GetCell(cols.IndexOf("出生日期")).StringCellValue;
sex = sheet.GetRow(i).GetCell(cols.IndexOf("性别")).StringCellValue;
HSSFRichTextString username = sheet.GetRow(i).GetCell(cols.IndexOf("受种者姓名")).RichStringCellValue as HSSFRichTextString;
HSSFRichTextString sjh = sheet.GetRow(i).GetCell(cols.IndexOf("移动电话")).RichStringCellValue as HSSFRichTextString;
string strusername = "";
int endl = username.String.Length;
for (int j = username.NumFormattingRuns - 1; j >= 0; j--)
{
IFont f = workbook.GetFontAt(username.GetFontOfFormattingRun(j));
if (f.FontHeightInPoints > 5)
{
strusername = strusername.Insert(0, username.String.Substring(username.GetIndexOfFormattingRun(j), endl - username.GetIndexOfFormattingRun(j)));
}
endl = username.GetIndexOfFormattingRun(j);
}
if ((sheet.GetRow(i).GetCell(cols.IndexOf("受种者姓名")) as HSSFCell).CellStyle.GetFont(workbook).FontHeightInPoints > 5)
{
strusername = strusername.Insert(0, username.String.Substring(0, endl));
}
string strsjh = "";
endl = sjh.String.Length;
for (int j = sjh.NumFormattingRuns - 1; j >= 0; j--)
{
IFont f = workbook.GetFontAt(sjh.GetFontOfFormattingRun(j));
if (f.FontHeightInPoints > 5)
{
strsjh = strsjh.Insert(0, sjh.String.Substring(sjh.GetIndexOfFormattingRun(j), endl - sjh.GetIndexOfFormattingRun(j)));
}
endl = sjh.GetIndexOfFormattingRun(j);
}
if ((sheet.GetRow(i).GetCell(cols.IndexOf("移动电话")) as HSSFCell).CellStyle.GetFont(workbook).FontHeightInPoints > 5)
{
strsjh = strsjh.Insert(0, sjh.String.Substring(0, endl));
}
var m = new Models.JiezhongmianyitiaomaModel
{
barcode = barcode,
username = strusername.Replace("身份证", ""),
csrq = DateTime.Parse(csrq),
sex = sex,
sjh = strsjh
};
bll.save(m);
//ymtl.Add(m);
}
return Newtonsoft.Json.JsonConvert.SerializeObject(new { State = 1, Message = "导入成功!" });
}
catch (Exception ex)
{
return Newtonsoft.Json.JsonConvert.SerializeObject(new { State = 0, Message = ex.Message });
}
}
}
#region
//public ActionResult Jmyy(string ertbm)
//{
// ViewData["vaccine"] = new SelectList(new BLL.vaccineBll().getAllList(""), "id", "name");
// ViewData["ymjd"] = new SelectList(new BLL.ym_jzlcBll().getAllYMJDList(), "id", "name");
// ViewBag.ertbm = ertbm;
// var bll = new BLL.ym_jzlcBll();
// var list = bll.getAllListByErtbm(ertbm);
// ym_jzlcjl jl = bll.getYmjzlcjlByErtbm(ertbm);
// ym_jzlc lc = bll.getYmjzlcByErtbm(jl.jdid.ToString());
// DateTime dt1 = DateTime.Now;
// if (lc == null)
// {
// }
// else
// {
// dt1 = Convert.ToDateTime(jl.jzsj).AddDays(lc.jgts);
// }
// ViewBag.yysj = dt1.ToString("yyyy-MM-dd");
// ViewData["list"] = list;
// return View();
//}
//public String GetAllYmJzlc(string ertbm)
//{
// var bll = new BLL.ym_jzlcBll();
// var list = bll.getAllJzlcList(ertbm);
// return Newtonsoft.Json.JsonConvert.SerializeObject(new { Rows = list });
//}
//public JsonResult SaveYmyy(string ertbm, string yysj, string jdid, string yms)
//{
// ym_yyjl ymyy = new ym_yyjl();
// ymyy.ertbm = ertbm;
// ymyy.yysj = Convert.ToDateTime(yysj);
// ymyy.jdid = Convert.ToInt32(jdid);
// ymyy.ymList = yms.TrimStart(new char[] { ',' }).TrimEnd(new char[] { ',' });
// var bll = new chargeBll();
// var result = bll.saveYmyy(ymyy);
// if (result.State == 1)
// {
// var yyxx = bll.getyyxx(result.Tag);
// var yyymlist = bll.getyyymlist(result.Tag);
// if (yyymlist == null || yyymlist.Count == 0)
// {
// }
// else
// {
// string ymmc = " ";
// yyymlist.ForEach(p => {
// ymmc += p.lcmc + ",";
// });
// ymmc= ymmc.TrimEnd(',');
// ymmc += " ";
// var wxlist = bll.getbdxx(result.Tag);
// var etxx = bll.getetxx(result.Tag);
// if (wxlist == null || wxlist.Count == 0)
// {
// if (etxx != null&&!string.IsNullOrEmpty(etxx.sjh))
// {
// var commonbll = new BLL.Common();
// string AccessKeyID = commonbll.getParm_Value("AccessKeyID", "LTAIWq3410bmP7hi", "阿里AccessKeyID");
// string AccessKeySecret = commonbll.getParm_Value("AccessKeySecret", "F953Ru3uZN2ZbS5741zvO9OvHrthNV", "阿里AccessKeySecret");
// string qm = commonbll.getParm_Value("aldxqm", "三才网络", "短信签名");
// string dxmb = commonbll.getParm_Value("aldxyymb", "SMS_136160758", "疫苗预约成功短信模版");
// //string smsurl = System.Configuration.ConfigurationManager.AppSettings["smsurl"];
// //string yznr = "你好,欢迎你注册天瑞体检中心会员,你的验证码是:" + yzm.smscode + "。有效期10分钟。回TD退订【天瑞体检】";
// //var zysms = new zyer.smsservice.SmsServiceSoapClient("SmsServiceSoap");
// //var smsjg = zysms.SendEx(username, userpassword, "808", sjh, "", yznr);
// //var fz = Session["FenZhan"] as Model.FenZhan;
// //Common.SendMsg.Send(sjh, yznr, fz.id);
// String product = "Dysmsapi";//短信API产品名称
// String domain = "dysmsapi.aliyuncs.com";//短信API产品域名
// String accessKeyId = AccessKeyID;//你的accessKeyId
// String accessKeySecret = AccessKeySecret;//你的accessKeySecret
// IClientProfile profile = DefaultProfile.GetProfile("cn-hangzhou", accessKeyId, accessKeySecret);
// //IAcsClient client = new DefaultAcsClient(profile);
// // SingleSendSmsRequest request = new SingleSendSmsRequest();
// DefaultProfile.AddEndpoint("cn-hangzhou", "cn-hangzhou", product, domain);
// IAcsClient acsClient = new DefaultAcsClient(profile);
// SendSmsRequest request = new SendSmsRequest();
// try
// {
// //必填:待发送手机号。支持以逗号分隔的形式进行批量调用批量上限为20个手机号码,批量调用相对于单条调用及时性稍有延迟,验证码类型的短信推荐使用单条调用的方式
// request.PhoneNumbers =etxx.sjh;
// //必填:短信签名-可在短信控制台中找到
// request.SignName = qm;
// //必填:短信模板-可在短信控制台中找到
// request.TemplateCode = dxmb;
// //可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
// request.TemplateParam = Newtonsoft.Json.JsonConvert.SerializeObject(new { jzrq=yyxx.yysj.ToString("yyyy-MM-dd"), ymmc=ymmc });
// //可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
// //request.OutId = "21212121211";
// //请求失败这里会抛ClientException异常
// SendSmsResponse sendSmsResponse = acsClient.GetAcsResponse(request);
// //System.Console.WriteLine(sendSmsResponse.Message);
// log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(sendSmsResponse.Message);
// }
// catch (ServerException e)
// {
// log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(e.Message + e.RequestId);
// //System.Console.WriteLine("Hello World!");
// //return Json(new { State = 0, Message = e.Message});
// }
// catch (ClientException e)
// {
// log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(e.Message + e.RequestId);
// //return Json(new { State = 0, Message = e.Message});
// }
// }
// }
// else
// {
// try
// {
// wxlist.ForEach(wx =>
// {
// var data = new
// {
// touser = wx.openid,
// template_id = "60jRADxdFNgDQQZSRh1dH4FyRFM_Im-jbKjWUwyMJqY",
// data = new
// {
// first = new { value = "您的宝宝应在" + yyxx.yysj.ToString("yyyy-MM-dd") + "接种以下疫苗。", color = "#173177" },
// keyword1 = new { value = etxx.username, color = "#173177" },
// keyword2 = new { value = yyxx.yysj.ToString("yyyy-MM-dd"), color = "#173177" },
// keyword3 = new { value = ymmc, color = "#173177" },
// remark = new { value = "请及时前往指定接种门诊进行接种。", color = "#173177" },
// }
// };
// WebClient wc = new WebClient();
// wc.UploadData("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + Common.Global.getAccessTokenYM.access_token, System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(data)));
// });
// }
// catch(Exception ex)
// {
// log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(ex.Message);
// }
// }
// }
// }
// return Json(result);
//}
#endregion
#region
//public String GetYmyyjl(string id)
//{
// var bll = new YMDJMXBll();
// var result = bll.getYmyyjl(id);
// return Newtonsoft.Json.JsonConvert.SerializeObject(result, new Newtonsoft.Json.JsonSerializerSettings { DateFormatString = "yyyy-MM-dd" });
//}
//public String GetYmsList(string ymList)
//{
// var bll = new YMDJMXBll();
// var result = bll.GetYmsList(ymList);
// return Newtonsoft.Json.JsonConvert.SerializeObject(result, new Newtonsoft.Json.JsonSerializerSettings { DateFormatString = "yyyy-MM-dd" });
//}
//public String GetJzymTmdy(string id)
//{
// var bll = new YMDJMXBll();
// var result = bll.GetJzymTmdy(id);
// return Newtonsoft.Json.JsonConvert.SerializeObject(result, new Newtonsoft.Json.JsonSerializerSettings { DateFormatString = "yyyy-MM-dd" });
//}
//public String GetYmjzlcList(string jdid)
//{
// var bll = new YMDJMXBll();
// var result = bll.GetYmjzlcList(jdid);
// return Newtonsoft.Json.JsonConvert.SerializeObject(result, new Newtonsoft.Json.JsonSerializerSettings { DateFormatString = "yyyy-MM-dd" });
//}
#endregion
#region
public ActionResult dunxinqunfa()
{
return View();
}
public JsonResult senddx(string sjhs, string ymmc)
{
var commonbll = new BLL.Common();
string yddx = commonbll.getParm_Value("qyyddx", "false", "是否启用移动短信");
if (yddx == "false")
{
int t = 0;
string AccessKeyID = commonbll.getParm_Value("AccessKeyID", "LTAIWq3410bmP7hi", "阿里AccessKeyID");
string AccessKeySecret = commonbll.getParm_Value("AccessKeySecret", "F953Ru3uZN2ZbS5741zvO9OvHrthNV", "阿里AccessKeySecret");
string qm = commonbll.getParm_Value("aldxqm", "三才网络", "短信签名");
string dxmb = commonbll.getParm_Value("aldxtzmbbz", "SMS_136170955", "漏种催补种模板");
//string smsurl = System.Configuration.ConfigurationManager.AppSettings["smsurl"];
//string yznr = "你好,欢迎你注册天瑞体检中心会员,你的验证码是:" + yzm.smscode + "。有效期10分钟。回TD退订【天瑞体检】";
//var zysms = new zyer.smsservice.SmsServiceSoapClient("SmsServiceSoap");
//var smsjg = zysms.SendEx(username, userpassword, "808", sjh, "", yznr);
//var fz = Session["FenZhan"] as Model.FenZhan;
//Common.SendMsg.Send(sjh, yznr, fz.id);
String product = "Dysmsapi";//短信API产品名称
String domain = "dysmsapi.aliyuncs.com";//短信API产品域名
String accessKeyId = AccessKeyID;//你的accessKeyId
String accessKeySecret = AccessKeySecret;//你的accessKeySecret
IClientProfile profile = DefaultProfile.GetProfile("cn-hangzhou", accessKeyId, accessKeySecret);
//IAcsClient client = new DefaultAcsClient(profile);
// SingleSendSmsRequest request = new SingleSendSmsRequest();
DefaultProfile.AddEndpoint("cn-hangzhou", "cn-hangzhou", product, domain);
IAcsClient acsClient = new DefaultAcsClient(profile);
SendSmsRequest request = new SendSmsRequest();
try
{
string[] hms = sjhs.Split('|');
foreach (var hm in hms)
{
if (string.IsNullOrEmpty(hm))
continue;
//必填:待发送手机号。支持以逗号分隔的形式进行批量调用批量上限为20个手机号码,批量调用相对于单条调用及时性稍有延迟,验证码类型的短信推荐使用单条调用的方式
request.PhoneNumbers = hm;
//必填:短信签名-可在短信控制台中找到
request.SignName = qm;
//必填:短信模板-可在短信控制台中找到
request.TemplateCode = dxmb;
//可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
request.TemplateParam = Newtonsoft.Json.JsonConvert.SerializeObject(new { ymmc = ymmc });
//可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
//request.OutId = "21212121211";
//请求失败这里会抛ClientException异常
SendSmsResponse sendSmsResponse = acsClient.GetAcsResponse(request);
//System.Console.WriteLine(sendSmsResponse.Message);
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(sendSmsResponse.Message);
t++;
}
}
catch (ServerException e)
{
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(e.Message + e.RequestId);
//System.Console.WriteLine("Hello World!");
//return Json(new { State = 0, Message = e.Message});
}
catch (ClientException e)
{
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(e.Message + e.RequestId);
//return Json(new { State = 0, Message = e.Message});
}
return Json(new { State = 1, Message = "成功发送条" + t + "通知短信" });
}
else
{
int t = 0;
//http://112.35.1.155:1992/sms/norsubmit
string ydhttp = commonbll.getParm_Value("ydhttp", "http://112.35.1.155:1992/sms/tmpsubmit", "移动短信地址");
var req = new Models.duanxin.msend();
WebClient wc = new WebClient();
string[] hms = sjhs.Split('|');
foreach (var hm in hms)
{
if (string.IsNullOrEmpty(hm))
continue;
req.ecName = commonbll.getParm_Value("yddxqymc", "德州市德城区疾病预防控制中心", "企业名称");
req.apId = commonbll.getParm_Value("yddxapId", "jkoa", "接口账号用户名");
req.mobiles = hm;
req.sign = commonbll.getParm_Value("yddxsign", "d37CYmrbG", "签名编码");
//req.content = "您的宝宝还未接种" + ymmc + ",请尽快带宝宝到接种门诊进行补种。微信关注“德城区疾病预防控制中心”即可预约接种。";
req.templateId = "cbb76eac353842aaaa8bceeb074237a4";
req.addSerial = "";
string[] parms = new string[1];
parms[0] = ymmc;
req.parms = Newtonsoft.Json.JsonConvert.SerializeObject(parms);
var md5 = MD5.Create();
//secretKey
var bs = md5.ComputeHash(Encoding.UTF8.GetBytes(req.ecName + req.apId + commonbll.getParm_Value("yddxsecretKey", "a7551898", "短信接口密码") + req.templateId + req.mobiles + req.parms + req.sign));
var sb = new StringBuilder();
foreach (byte b in bs)
{
sb.Append(b.ToString("x2"));
}
req.mac = sb.ToString().ToLower();
string upstr = Newtonsoft.Json.JsonConvert.SerializeObject(req);
upstr = upstr.Replace("parms", "params");
byte[] resp = wc.UploadData(ydhttp, System.Text.Encoding.UTF8.GetBytes(Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(upstr))));
var nres = Newtonsoft.Json.JsonConvert.DeserializeObject<Models.duanxin.nrecive>(System.Text.Encoding.UTF8.GetString(resp));
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(System.Text.Encoding.UTF8.GetString(resp));
t++;
}
return Json(new { State = 1, Message = "成功发送条" + t + "通知短信" });
}
}
public JsonResult senddx2(string sjhs, string dxnr)
{
var commonbll = new BLL.Common();
string yddx = commonbll.getParm_Value("qyyddx", "false", "是否启用移动短信");
if (yddx == "false")
{
int t = 0;
string AccessKeyID = commonbll.getParm_Value("AccessKeyID", "LTAIWq3410bmP7hi", "阿里AccessKeyID");
string AccessKeySecret = commonbll.getParm_Value("AccessKeySecret", "F953Ru3uZN2ZbS5741zvO9OvHrthNV", "阿里AccessKeySecret");
string qm = commonbll.getParm_Value("aldxqm", "三才网络", "短信签名");
string dxmb = commonbll.getParm_Value("aldxtzmbbz", "SMS_136170955", "漏种催补种模板");
//string smsurl = System.Configuration.ConfigurationManager.AppSettings["smsurl"];
//string yznr = "你好,欢迎你注册天瑞体检中心会员,你的验证码是:" + yzm.smscode + "。有效期10分钟。回TD退订【天瑞体检】";
//var zysms = new zyer.smsservice.SmsServiceSoapClient("SmsServiceSoap");
//var smsjg = zysms.SendEx(username, userpassword, "808", sjh, "", yznr);
//var fz = Session["FenZhan"] as Model.FenZhan;
//Common.SendMsg.Send(sjh, yznr, fz.id);
String product = "Dysmsapi";//短信API产品名称
String domain = "dysmsapi.aliyuncs.com";//短信API产品域名
String accessKeyId = AccessKeyID;//你的accessKeyId
String accessKeySecret = AccessKeySecret;//你的accessKeySecret
IClientProfile profile = DefaultProfile.GetProfile("cn-hangzhou", accessKeyId, accessKeySecret);
//IAcsClient client = new DefaultAcsClient(profile);
// SingleSendSmsRequest request = new SingleSendSmsRequest();
DefaultProfile.AddEndpoint("cn-hangzhou", "cn-hangzhou", product, domain);
IAcsClient acsClient = new DefaultAcsClient(profile);
SendSmsRequest request = new SendSmsRequest();
try
{
string[] hms = sjhs.Split('|');
foreach (var hm in hms)
{
if (string.IsNullOrEmpty(hm))
continue;
//必填:待发送手机号。支持以逗号分隔的形式进行批量调用批量上限为20个手机号码,批量调用相对于单条调用及时性稍有延迟,验证码类型的短信推荐使用单条调用的方式
request.PhoneNumbers = hm;
//必填:短信签名-可在短信控制台中找到
request.SignName = qm;
//必填:短信模板-可在短信控制台中找到
request.TemplateCode = dxmb;
//可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
request.TemplateParam = Newtonsoft.Json.JsonConvert.SerializeObject(new { ymmc = "" });
//可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
//request.OutId = "21212121211";
//请求失败这里会抛ClientException异常
SendSmsResponse sendSmsResponse = acsClient.GetAcsResponse(request);
//System.Console.WriteLine(sendSmsResponse.Message);
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(sendSmsResponse.Message);
t++;
}
}
catch (ServerException e)
{
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(e.Message + e.RequestId);
}
catch (ClientException e)
{
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(e.Message + e.RequestId);
}
return Json(new { State = 1, Message = "成功发送条" + t + "通知短信" });
}
else
{
int t = 0;
//http://112.35.1.155:1992/sms/norsubmit
string ydhttp = commonbll.getParm_Value("ydhttp", "http://112.35.1.155:1992/sms/tmpsubmit", "移动短信地址");
ydhttp = "http://112.35.1.155:1992/sms/norsubmit";
var req = new Models.duanxin.msend();
WebClient wc = new WebClient();
string[] hms = sjhs.Split('|');
foreach (var hm in hms)
{
if (string.IsNullOrEmpty(hm))
continue;
req.ecName = commonbll.getParm_Value("yddxqymc", "德州市德城区疾病预防控制中心", "企业名称");
req.apId = commonbll.getParm_Value("yddxapId", "jkoa", "接口账号用户名");
req.mobiles = hm;
req.sign = commonbll.getParm_Value("yddxsign", "d37CYmrbG", "签名编码");
//req.content = "您的宝宝还未接种" + ymmc + ",请尽快带宝宝到接种门诊进行补种。微信关注“德城区疾病预防控制中心”即可预约接种。";
req.content = dxnr;
req.addSerial = "";
var md5 = MD5.Create();
//secretKey
var bs = md5.ComputeHash(Encoding.UTF8.GetBytes(req.ecName + req.apId + commonbll.getParm_Value("yddxsecretKey", "a7551898", "短信接口密码") + req.mobiles + req.content + req.sign + req.addSerial));
var sb = new StringBuilder();
foreach (byte b in bs)
{
sb.Append(b.ToString("x2"));
}
req.mac = sb.ToString().ToLower();
byte[] resp = wc.UploadData(ydhttp, System.Text.Encoding.UTF8.GetBytes(Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(req)))));
var nres = Newtonsoft.Json.JsonConvert.DeserializeObject<Models.duanxin.nrecive>(System.Text.Encoding.UTF8.GetString(resp));
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType).Info(System.Text.Encoding.UTF8.GetString(resp));
t++;
}
return Json(new { State = 1, Message = "成功发送条" + t + "通知短信" });
}
}
public string uploadsjh()
{
if (Request.Files.Count == 0)
{
return Newtonsoft.Json.JsonConvert.SerializeObject(new { State = 0, Message = "没有要处理的文件" });
}
else
{
try
{
string path = Server.MapPath("~/exec/");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
path = path + Guid.NewGuid().ToString("N") + Request.Files[0].FileName.Substring(Request.Files[0].FileName.LastIndexOf("."));
Request.Files[0].SaveAs(path);
//DataTable[] dts = xiaoy.Excel.ExcelFile.GetData(path, xiaoy.Excel.ExcelVersion.Excel12, xiaoy.Excel.HDRType.Yes, false);
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
HSSFWorkbook workbook = null;
workbook = new HSSFWorkbook(fs);
HSSFSheet sheet = workbook.GetSheetAt(0) as HSSFSheet;
//var bll = new BLL.JiezhongmianyitiaomaModelBll();
List<JiezhongmianyitiaomaModel> ymtl = new List<JiezhongmianyitiaomaModel>();
List<string> cols = new List<string>();
IRow row1 = sheet.GetRow(0);
for (int i = 0; i < row1.LastCellNum; i++)
{
cols.Add(row1.GetCell(i).StringCellValue);
}
for (int i = 1; i <= sheet.LastRowNum; i++)
{
string barcode = "";
//string username = "";
string csrq = "";
string sex = "";
//string sjh = "";
barcode = sheet.GetRow(i).GetCell(cols.IndexOf("受种者编号")).StringCellValue;
csrq = sheet.GetRow(i).GetCell(cols.IndexOf("出生日期")).StringCellValue;
sex = sheet.GetRow(i).GetCell(cols.IndexOf("性别")).StringCellValue;
HSSFRichTextString username = sheet.GetRow(i).GetCell(cols.IndexOf("受种者姓名")).RichStringCellValue as HSSFRichTextString;
HSSFRichTextString sjh = sheet.GetRow(i).GetCell(cols.IndexOf("移动电话")).RichStringCellValue as HSSFRichTextString;
string strusername = "";
int endl = username.String.Length;
for (int j = username.NumFormattingRuns - 1; j >= 0; j--)
{
IFont f = workbook.GetFontAt(username.GetFontOfFormattingRun(j));
if (f.FontHeightInPoints > 5)
{
strusername = strusername.Insert(0, username.String.Substring(username.GetIndexOfFormattingRun(j), endl - username.GetIndexOfFormattingRun(j)));
}
endl = username.GetIndexOfFormattingRun(j);
}
if ((sheet.GetRow(i).GetCell(cols.IndexOf("受种者姓名")) as HSSFCell).CellStyle.GetFont(workbook).FontHeightInPoints > 5)
{
strusername = strusername.Insert(0, username.String.Substring(0, endl));
}
string strsjh = "";
endl = sjh.String.Length;
for (int j = sjh.NumFormattingRuns - 1; j >= 0; j--)
{
IFont f = workbook.GetFontAt(sjh.GetFontOfFormattingRun(j));
if (f.FontHeightInPoints > 5)
{
strsjh = strsjh.Insert(0, sjh.String.Substring(sjh.GetIndexOfFormattingRun(j), endl - sjh.GetIndexOfFormattingRun(j)));
}
endl = sjh.GetIndexOfFormattingRun(j);
}
if ((sheet.GetRow(i).GetCell(cols.IndexOf("移动电话")) as HSSFCell).CellStyle.GetFont(workbook).FontHeightInPoints > 5)
{
strsjh = strsjh.Insert(0, sjh.String.Substring(0, endl));
}
var m = new Models.JiezhongmianyitiaomaModel
{
barcode = barcode,
username = strusername,
csrq = DateTime.Parse(csrq),
sex = sex,
sjh = strsjh
};
//bll.save(m);
ymtl.Add(m);
}
return Newtonsoft.Json.JsonConvert.SerializeObject(new { State = 1, Message = new { Rows = ymtl } });
}
catch (Exception ex)
{
return Newtonsoft.Json.JsonConvert.SerializeObject(new { State = 0, Message = ex.Message });
}
}
}
#endregion
}
}