标签:sheet clone idt dir fun method 引用 read number
1 <!-- 客户导入弹窗 --> 2 <div class="modal fade batch-import new-built" id="customerImpo" tabindex="-1" data-backdrop="static" data-keyboard="false"> 3 <div class="modal-dialog modal-margin modal-lg"> 4 <div class="modal-content batch-modal cus-batchimport"> 5 <div class="modal-header text-center"> 6 <h4 class="modal-title">导入客户信息</h4> 7 </div> 8 <input type="hidden" id="filePathCus" value="" /> 9 <div class="modal-body"> 10 <div class="wrap"> 11 <div class="batchflow cusbatchflow"> 12 <ul> 13 <li class="normal unload-firstep active"><cite>01</cite>上传文件</li> 14 <li class="normal unload-secstep"><cite>02</cite>执行导入</li> 15 <li class="unload-laststep"><cite>03</cite>完成</li> 16 </ul> 17 </div> 18 <div class="status_wrap firststep"> 19 <i class="icon icon_download upload"></i> 20 <span class="status_info" id="status_info2"> 21 填写导入客户的信息<br> 22 <span class="batchflow"> 23 <label class="checkbox-click" style="font-weight: normal"> 24 <span class="import-check-icon import-i-checked"></span> 25 <input type="checkbox" id="carinfo" name="name" style="display: none" /> 26 <a>VV平台客户信息导入-精简模板</a> 27 </label> 28 <a class="btn btn-sm batch-download pull-right" id="custdownload" href="~/DownloadFile/VV平台客户信息导入-精简模板.xls">下载</a> 29 </span> 30 31 </span> 32 </div> 33 <div class="status_wrap mt20 firststep"> 34 <i class="icon icon_upload download"></i> 35 <div class="status_info"> 36 上传填好的客户信息表 37 <span class="txtc9">( 仅支持.xls/.xlsx格式,且文件大小不能超过4M )</span> 38 <br> 39 <span class="batchflow" id="customerFileName"> 40 <input type="text" class="batchflow-input form-control" id="batchflow-cstinput"> 41 <input type="file" class="upload-input" id="preview" style="display: none;" /> 42 <button class="btn btn-sm see-buttom pull-right" id="btn-cuspreview">浏览</button> 43 </span> 44 <ul id="fileName"> 45 <li style="list-style: none;"> 46 <div style="display: none; height: 22px"> 47 <span class="name" style="height: 22px; display: inline-block"></span><span style="margin: 0 0 0 10px;" class="attsize"></span><span style="margin: 0 0 0 10px;" class="status">等待</span><i class="mpic-delete2 ch" style="font-size: 16px; cursor: pointer">x</i><div style="display: none; width: 100px; height: 11px; margin-top: 2px; padding: 0;" class="progress"> 48 <div class="bar" style="width: 0%;"></div> 49 </div> 50 </div> 51 <div class="cb"></div> 52 <div> 53 <form id="uploadFormCus" action="/sysmng/companylogo/uploadLogo.do?idoo=23508470.1482976115424CBD6A663D4677AF41DFC253DA5E57244&X-Progress-ID=23508470.1482976115424CBD6A663D4677AF41DFC253DA5E57244&from=import" method="post" style="margin: 0; padding: 0;" enctype="multipart/form-data"> 54 <div style="width: 70px; height: 22px; overflow: hidden;" class="upatt"> 55 <i class="mpic-att"></i><span style="position: relative; display: inline-block;"> 56 <span style="position: absolute; top: 0px; left: 0px; cursor: pointer; width: 50px; height: 20px; overflow: hidden; opacity: 0; z-index: 1; background-color: rgb(255, 255, 255);"> 57 <input class="mgtfile" id="Cusfile" name="logoFile" tabindex="-1" style="width: 200px; height: 200px; font-family: Times; font-size: 50px; right: 426px; cursor: pointer;" type="file"> 58 </span> 59 </span> 60 </div> 61 </form> 62 </div> 63 </li> 64 </ul> 65 </div> 66 </div> 67 <div class="status_wrap secondstep"> 68 <i class="icon icon_layer_success"></i> 69 <span class="status_info" id="Yes_Nums">本次可导入客户:</span> 70 </div> 71 <div class="status_wrap secondstep"> 72 <i class="icon icon_layer_warn"></i> 73 <span class="status_info" id="No_Nums">本次不可导入客户:</span> 74 </div> 75 <div class="status_wrap thirdstep"> 76 <i class="icon icon_layer_success success"></i> 77 <span class="status_info success-tip" style="font-size: 18px;">成功导入人数:<span id="importCusNum"></span>个 <a onclick="batchImport.showOrHidePwd(this)" href="javascript:void(0)">显示</a></span> 78 </div> 79 <div style="text-align: center"> 80 <a href="javascript:void(0)" id="btnSecoudCus" onclick="goIntoSecondStepCus($(this))" class="btn btn-white next first-a">下一步</a> 81 <a href="javascript:void(0)" id="btnThirdCus" onclick="goIntothirdStepCus($(this))" class="btn btn-white next second-a">下一步</a> 82 <a href="javascript:void(0)" onclick="goIntoFirstStepCus($(this));" class="aupimg second-a">返回重新上传</a> 83 <a href="javascript:void(0)" id="endBtnCus" onclick="initStepCus($(this));" class="btn btn-white next final">完成</a> 84 </div> 85 <div class="status_wrap secondstep"> 86 <h3 class="bulktit">不可导入的客户:</h3> 87 <table class="table-striped"> 88 <thead> 89 <tr> 90 <th></th> 91 <th>行数</th> 92 <th>编号</th> 93 <th>简称</th> 94 <th>错误提示</th> 95 </tr> 96 </thead> 97 <tbody id="CusErr"></tbody> 98 </table> 99 </div> 100 </div> 101 </div> 102 <div class="modal-footer"> 103 <button class="btn btn-default cancle" data-dismiss="modal" type="button">取消</button> 104 </div> 105 </div> 106 </div> 107 </div>
1 function batchImportInit() { 2 //initStepCus(); 3 $("#customerImpo").modal(‘show‘); 4 $("#btnSecoudCus").attr("disabled", true); 5 $("#batchflow-cstinput").val(""); 6 } 7 8 $(function () { 9 //触发预览按钮 10 $("#btn-cuspreview").click(function () { 11 $("#Cusfile").click(); 12 }); 13 14 $("#Cusfile").on("change", function () { 15 FileCustomerInfo(); 16 }); 17 }) 18 19 function FileCustomerInfo() { 20 var formData = new FormData($("#uploadFormCus")[0]); 21 $.ajax({ 22 type: "post", 23 url: "/CustomerMember/BulkInserCustomer", 24 dataType: "Json", 25 data: formData, 26 async: false, 27 cache: false, 28 contentType: false, 29 processData: false, 30 success: function (data) { 31 if (data.result == "1") { 32 layer.msg("上传成功", { title: "温馨提示", icon: 1 }); 33 if (data.result == "1") { 34 $("#btnSecoudCus").attr("disabled", false); 35 } 36 $("#filePathCus").val(data.Errmsg); 37 $("#batchflow-cstinput").val(data._fileName); 38 } else { 39 layer.msg(data.Errmsg, { title: "温馨提示", icon: 0 }); 40 } 41 }, 42 complete: function (xmlHttpRequest) { 43 ////上传完成后重新注册change事件 44 $("#Cusfile").replaceWith("<input class=‘mgtfile‘ id=‘Cusfile‘ name=‘logoFile‘ tabindex=‘-1‘ style=‘width: 200px; height: 200px; font-family: Times; font-size: 50px; right: 426px; cursor: pointer;‘ type=‘file‘>"); 45 $("#Cusfile").on("change", function () { 46 FileCustomerInfo(); 47 }); 48 49 50 } 51 }); 52 } 53 54 function goIntoFirstStepCus(object) { 55 $(object).hide(); 56 $(".cus-batchimport .first-a").css("display", "inline-block"); 57 $(".cus-batchimport .second-a").css("display", "none"); 58 $(".cus-batchimport .aupimg").css("display", "none"); 59 $(".cus-batchimport .final").css("display", "none"); 60 $(".cus-batchimport .cusbatchflow > ul >li").eq(0).addClass("active").siblings(".unload-secstep").removeClass("active1"); 61 $(".cus-batchimport .secondstep").hide(); 62 $(".cus-batchimport .unableimportemp").hide(); 63 $(".cus-batchimport .bulktit").hide(); 64 $(".cus-batchimport .firststep").show(); 65 $(".cus-batchimport .thirdstep").hide(); 66 67 $("#btnSecoudCus").attr("disabled", true); 68 } 69 70 function goIntoSecondStepCus(object) { 71 $("#batchflow-cstinput").val(""); 72 $(object).hide(); 73 $(".cus-batchimport .second-a").css("display", "inline-block"); 74 $(".cus-batchimport .aupimg").css("display", "block"); 75 $(".cus-batchimport .final").css("display", "none"); 76 $(".cusbatchflow > ul >li").eq(0).removeClass("active").siblings(".unload-secstep").addClass("active1"); 77 $(".cus-batchimport .secondstep").show(); 78 $(".cus-batchimport .unableimportemp").show(); 79 $(".cus-batchimport .bulktit").show(); 80 $(".cus-batchimport .firststep").hide(); 81 $(".cus-batchimport .thirdstep").hide(); 82 83 CheckCusInfo(); 84 $("#btnThirdCus").attr("disabled", true); 85 } 86 87 function goIntothirdStepCus(object) { 88 $(object).hide(); 89 $(object).siblings().css("display", "none"); 90 $(".cus-batchimport .final").css("display", "block"); 91 $(".cus-batchimport .cusbatchflow > ul >li").eq(1).removeClass("active1").siblings(".unload-laststep").addClass("active2"); 92 $(".cus-batchimport .secondstep").hide(); 93 $(".cus-batchimport .unableimportemp").hide(); 94 $(".cus-batchimport .bulktit").hide(); 95 $(".cus-batchimport .thirdstep").show(); 96 97 InsertCustomer(); 98 $("#endBtnCus").attr("disabled", true); 99 } 100 101 function initStepCus(object) { 102 $import = $(object).parents(".batch-import"); 103 $import.modal(‘hide‘); 104 goIntoFirstStepCus(object); 105 $import.find(".cusbatchflow > ul >li").eq(2).removeClass("active"); 106 resetFileInput($import.find(".mgtfile")); 107 108 ////上传完成后重新注册change事件 109 $("#Cusfile").replaceWith("<input class=‘mgtfile‘ id=‘Cusfile‘ name=‘logoFile‘ tabindex=‘-1‘ style=‘width: 200px; height: 200px; font-family: Times; font-size: 50px; right: 426px; cursor: pointer;‘ type=‘file‘>"); 110 $("#Cusfile").on("change", function () { 111 FileCustomerInfo(); 112 }); 113 } 114 //清空file 115 function resetFileInput(file) { 116 file.after(file.clone().val("")); 117 file.remove(); 118 } 119 //验证数据 120 function CheckCusInfo() { 121 var FilePath = $("#filePathCus").val(); 122 $.ajax({ 123 type: "post", 124 url: "/CustomerMember/CheckDataResult", 125 dataType: "Json", 126 data: { FilePath: FilePath }, 127 success: function (data) { 128 var KeBulk = data.CoopList.length; 129 var FouBulk = data.Help.length; 130 $("#Yes_Nums").text("本次可导入客户数:" + KeBulk + "名"); 131 $("#No_Nums").text("本次不可导入客户数:" + FouBulk + "名"); 132 if (KeBulk != 0) { $("#btnThirdCus").attr("disabled", false); } 133 if (KeBulk == 0) { layer.msg("可导入客户数为0,返回重新上传", { title: "温馨提示", icon: 0 }); } 134 135 var tbody = ""; 136 for (var i = 0; i < FouBulk; i++) { 137 var trs = "" 138 trs += "<tr><td></td>"; 139 trs += "<td><span title=‘" + data.Help[i].Row + "‘></span>" + data.Help[i].Row + "</td>"; 140 trs += "<td><span title=‘" + data.Help[i].TCNO + "‘></span>" + data.Help[i].TCNO + "</td>"; 141 trs += "<td><span title=‘" + data.Help[i].TCShortName + "‘></span>" + data.Help[i].TCShortName + "</td>"; 142 trs += " <td class=‘txtred breakall‘>" + data.Help[i].MrrEsg + "<br></td>"; 143 trs += "</tr>"; 144 tbody += trs; 145 } 146 $("#CusErr").html(""); 147 $("#CusErr").html(tbody); 148 } 149 }); 150 } 151 152 //插入数据 153 function InsertCustomer() { 154 $.ajax({ 155 type: "post", 156 url: "/CustomerMember/BulkInsertResult", 157 dataType: "Json", 158 data: null, 159 success: function (data) { 160 if (data.result != "0" && data.result != "-1") { 161 var num = parseInt(data.result); 162 $("#importCusNum").text(num); 163 $("#endBtnCus").attr("disabled", false); 164 } else { 165 layer.msg("导入异常,请重新导入", { title: "温馨提示", icon: 0 }); 166 } 167 } 168 }); 169 }
1 /// <summary> 2 /// 上传模板文件 3 /// </summary> 4 /// <returns></returns> 5 public ActionResult BulkInserCustomer() 6 { 7 HttpPostedFileBase fileData = Request.Files[0]; 8 if (fileData.ContentLength == 0) 9 { 10 return Json(new { result = 0, Errmsg = "请选择上传文件" }); 11 } 12 13 if (fileData.FileName != "VV平台客户人员信息导入-精简模板.xls") 14 { 15 return Json(new { result = 0, Errmsg = "文件有误" }); 16 } 17 18 string strExtension = Path.GetExtension(fileData.FileName).ToLower(); 19 20 if (strExtension == ".xls" || strExtension == ".xlsx") 21 { 22 double dFileSiz = fileData.ContentLength; 23 if (dFileSiz > 1024 * 1024 * 4) 24 { 25 return Json(new { result = 0, Errmsg = "文件过大" }); 26 } 27 28 string new_fileName = Guid.NewGuid().ToString() + "_" + Path.GetFileName(fileData.FileName); 29 30 //哈希码解决生成多个文件夹,提高上传效率 31 int hash_code = new_fileName.GetHashCode(); 32 int dir1 = hash_code & 0xf; 33 hash_code = hash_code >> 4; 34 int dir2 = hash_code & 0xf; 35 36 string targetFilePath = Path.Combine(Request.MapPath("~/UploadFile/BulkImport/"), dir1.ToString(), dir2.ToString()); 37 if (!Directory.Exists(targetFilePath))//文件夹不存在的时候创建 38 { 39 Directory.CreateDirectory(targetFilePath); 40 } 41 targetFilePath = Path.Combine(targetFilePath, new_fileName);//文件名与目录拼接 42 fileData.SaveAs(targetFilePath); 43 return Json(new { result = 1, Errmsg = targetFilePath, _fileName = fileData.FileName }); 44 45 } 46 return Json(new { result = 0, Errmsg = "文件格式错误" }); 47 } 48 49 private static List<TempMember> coopList; 50 51 public ActionResult CheckDataResult() 52 { 53 string fileName = Request["FilePath"]; 54 List<BuliImportHelp> help = null; 55 coopList = CTMBLL.CheckCustomerData(fileName, curCompanyId, curStaffLgAccID, ref help); 56 57 return Json(new { CoopList = coopList, Help = help }); 58 } 59 60 public ActionResult BulkInsertResult() 61 { 62 int result = 0; 63 result = CTMBLL.BulkCustomerInfo(coopList); 64 65 return Json(new { result = result }); 66 }
1 /// <summary> 2 /// 验证客户信息 3 /// </summary> 4 /// <param name="fileName"></param> 5 /// <param name="companyID"></param> 6 /// <param name="Uplist"></param> 7 /// <returns></returns> 8 public List<TempMember> CheckCustomerData(string fileName, long companyID, long TMAddUserId, ref List<BuliImportHelp> Uplist) 9 { 10 List<TempMember> list = new List<TempMember>(); 11 Uplist = new List<BuliImportHelp>(); 12 List<string> rTCNOTMPhone = new List<string>(); 13 14 IWorkbook workbook; 15 using (FileStream fsRead = File.OpenRead(fileName)) 16 { 17 workbook = new HSSFWorkbook(fsRead); 18 ISheet sheet = workbook.GetSheetAt(0); 19 20 for (int r = 2; r <= sheet.LastRowNum; r++) 21 { 22 IRow currentRow = sheet.GetRow(r); 23 24 Vehicle veModel = new Vehicle(); 25 BuliImportHelp upModel = new BuliImportHelp(); 26 27 if (currentRow == null) { break; } 28 29 string TCNO = currentRow.GetCell(0) == null ? "" : currentRow.GetCell(0).ToString().Trim(); 30 string TCShortName = currentRow.GetCell(1) == null ? "" : currentRow.GetCell(1).ToString().Trim(); 31 string TMName = currentRow.GetCell(2) == null ? "" : currentRow.GetCell(2).ToString().Trim(); 32 string TMPhone = currentRow.GetCell(3) == null ? "" : currentRow.GetCell(3).ToString().Trim(); 33 var TCID = TMDAL.GetTempCompanyID(TCNO, companyID); 34 if (TCNO == "" && TCShortName == "" && TMName == "" && TMPhone == "") { break; } 35 36 if (TCNO == "" || TCShortName == "" || TMName == "" || TMPhone == "") 37 { 38 BuliImportHelp BuHelp = new BuliImportHelp(); 39 BuHelp.Row = (r + 1).ToString(); 40 BuHelp.TCNO = TCNO; 41 BuHelp.TCShortName = TCShortName; 42 BuHelp.TMName = TMName; 43 BuHelp.TMPhone = TMPhone; 44 if (TCNO == "") { BuHelp.MrrEsg = "客户编号不能为空"; } 45 else if (TCShortName == "") { BuHelp.MrrEsg = "客户简称不能为空"; } 46 else if (TMName == "") { BuHelp.MrrEsg = "成员姓名不能为空"; } 47 else if (TMPhone == "") { BuHelp.MrrEsg = "成员电话不能为空"; } 48 Uplist.Add(BuHelp); 49 } 50 else if (!UtilityHelp.isCellPhoneNumber(TMPhone)) 51 { 52 BuliImportHelp BuHelp = new BuliImportHelp(); 53 BuHelp.Row = (r + 1).ToString(); 54 BuHelp.TCNO = TCNO; 55 BuHelp.TCShortName = TCShortName; 56 BuHelp.TMName = TMName; 57 BuHelp.TMPhone = TMPhone; 58 BuHelp.MrrEsg = "手机号码格式有误"; 59 Uplist.Add(BuHelp); 60 } 61 else 62 { 63 bool count = true; 64 if (rTCNOTMPhone.IndexOf(TCNO + TMPhone) != -1) 65 { 66 BuliImportHelp BuHelp = new BuliImportHelp(); 67 BuHelp.Row = (r + 1).ToString(); 68 BuHelp.TCNO = TCNO; 69 BuHelp.TCShortName = TCShortName; 70 BuHelp.TMName = TMName; 71 BuHelp.TMPhone = TMPhone; 72 BuHelp.MrrEsg = "导入模板中手机号码重复"; 73 Uplist.Add(BuHelp); 74 count = false; 75 } 76 else { rTCNOTMPhone.Add(TCNO + TMPhone); } 77 78 79 if (TCID == 0) 80 { 81 BuliImportHelp BuHelp = new BuliImportHelp(); 82 BuHelp.Row = (r + 1).ToString(); 83 BuHelp.TCNO = TCNO; 84 BuHelp.TCShortName = TCShortName; 85 BuHelp.TMName = TMName; 86 BuHelp.TMPhone = TMPhone; 87 BuHelp.MrrEsg = "客户编号不存在"; 88 Uplist.Add(BuHelp); 89 count = false; 90 } 91 //if (TMDAL.IsExistTMPhone(TCID, TMPhone) >= 1) 92 //{ 93 // BuliImportHelp BuHelp = new BuliImportHelp(); 94 // BuHelp.Row = (r + 1).ToString(); 95 // BuHelp.TCNO = TCNO; 96 // BuHelp.TCShortName = TCShortName; 97 // BuHelp.TMName = TMName; 98 // BuHelp.TMPhone = TMPhone; 99 // BuHelp.MrrEsg = "手机号码已存在"; 100 // Uplist.Add(BuHelp); 101 // count = false; 102 //} 103 if (count) 104 { 105 TempMember TM = new TempMember(); 106 TM.TMSerialNo = "";//编号生成 107 TM.TMAddUserId = TMAddUserId;//操作人登陆ID 108 TM.TMName = TMName;//客户成员姓名 109 TM.TMPhone = TMPhone;//客户成员手机号 110 TM.TMTCComID = TCID;//客户的公司ID 111 TM.TMAddTime = DateTime.Now;//客户成员加入日期 112 list.Add(TM); 113 } 114 } 115 } 116 } 117 return list; 118 } 119 120 /// <summary> 121 /// 批量导入客户信息 122 /// </summary> 123 /// <param name="listModel"></param> 124 /// <returns></returns> 125 public int BulkCustomerInfo(List<TempMember> listModel) 126 { 127 return TMDAL.BulkCustomerInfo(listModel); 128 }
1 /// <summary> 2 /// 根据客户编号获取客户公司ID 3 /// </summary> 4 /// <returns></returns> 5 public long GetTempCompanyID(string TCNO, long companyID) 6 { 7 string sql = @"SELECT TCID FROM TempCompany WHERE TCNO=@TCNO AND TCBelongComID = @companyID"; 8 try 9 { 10 using(IDbCon) 11 { 12 long TCID = IDbCon.ExecuteScalar<long>(sql, new { TCNO = TCNO, companyID = companyID }); 13 return TCID; 14 } 15 } 16 catch(Exception ex) 17 { 18 UtilityHelp.WriteLog(ex, ex.ToString()); 19 return 0; 20 } 21 } 22 23 /// <summary> 24 /// 是否存在该客户 25 /// </summary> 26 /// <param name="customerNum"></param> 27 /// <param name="customerAbbreviation"></param> 28 /// <param name="coopID"></param> 29 /// <returns></returns> 30 public int IsHaveCustomer(string TCNO, long companyID) 31 { 32 string sql = "SELECT COUNT(*) FROM TempCompany WHERE TCNO=@TCNO AND TCBelongType=1 AND TCBelongComID=@companyID"; 33 34 35 using (IDbCon) 36 { 37 try 38 { 39 return IDbCon.Query<int>(sql, new 40 { 41 TCNO = TCNO, 42 companyID = companyID 43 }).FirstOrDefault(); 44 } 45 catch (Exception ex) 46 { 47 UtilityHelp.WriteLog(ex, ex.ToString()); 48 return -1; 49 } 50 } 51 52 } 53 54 /// <summary> 55 /// 批量导入客户人员信息 56 /// </summary> 57 /// <param name="listModel"></param> 58 /// <returns></returns> 59 public int BulkCustomerInfo(List<TempMember> listModel) 60 { 61 string sql = @"INSERT INTO TempMember(TMSourceCome,TMAuditState,TMIsUsable,TMTCComID,TMSerialNo,TMName,TMSex,TMPhone,TMAddUserId,TMIsPhone,TMAddTime) 62 VALUES(2,1,1,@TMTCComID,@TMSerialNo,@TMName,1,@TMPhone,@TMAddUserId,‘FALSE‘,@TMAddTime)"; 63 64 int result = 0; 65 IDbConnection iDbcon = base.IDbCon; 66 if (iDbcon.State == ConnectionState.Closed) 67 { 68 iDbcon.Open(); 69 } 70 71 using (var trans = iDbcon.BeginTransaction()) 72 { 73 try 74 { 75 result = iDbcon.Execute(sql, listModel, trans, null, CommandType.Text); 76 if (result == listModel.Count()) 77 { 78 trans.Commit(); 79 return result; 80 } 81 else 82 { 83 trans.Rollback(); 84 return 0; 85 } 86 } 87 catch (Exception ex) 88 { 89 trans.Rollback(); 90 UtilityHelp.WriteLog(ex, ex.ToString()); 91 return -1; 92 } 93 finally 94 { 95 iDbcon.Close(); 96 } 97 } 98 99 }
using NPOI.SS.UserModel;
using NPOI.HSSF.UserModel;
1、NuGet搜索Npoi并安装
2、添加引用将包引用进来
标签:sheet clone idt dir fun method 引用 read number
原文地址:http://www.cnblogs.com/chizhida/p/7424020.html