Files
zszq-trs/YLErpWeb/Views/trade/tradeVolUpload.cshtml
T
2024-05-09 14:06:26 +08:00

110 lines
4.2 KiB
Plaintext

@model trade
@{
ViewBag.Title = "计算管理 | 行权批量执行";
Layout = "~/Views/Shared/_InfoLayout.cshtml";
}
@section JS
{
<script type="text/javascript">
function upload() {
if ($("#openFile").val() === "" || $("#openFile").val() == null || $("#openFile").val() === "undefined") {
showmiddlemessage("请选择要导入的文件!");
return false;
}
var fileName = $("#openFile").val();
var ext, idx;
if (fileName == '') {
main.alert("请选择需要上传的文件!");
return false;
} else {
idx = fileName.lastIndexOf(".");
if (idx != -1) {
ext = fileName.substr(idx + 1).toUpperCase();
ext = ext.toLowerCase();
// alert("ext="+ext);
if (ext != 'xlsx') {
main.alert("只能上传.xlsx类型的文件!");
return false;
}
} else {
main.alert("只能上传.xlsx类型的文件!");
return false;
}
}
main.confirm("确定导入?", function () {
var formData = new FormData($('form')[0]);
$.ajax({
url: '/trade/UploadTradeVolExcel', //server script to process data
type: 'POST',
xhr: function () { // custom xhr
myXhr = $.ajaxSettings.xhr();
if (myXhr.upload) { // check if upload property exists
myXhr.upload.addEventListener('progress', progressHandlingFunction, false); // for handling the progress of the upload
}
return myXhr;
},
beforeSend: function () {
main.waitMe("show");
},
success: function (data) {
try {
if (data.success) {
(parent || window).main.message("导入成功!");
parent.layer.closeAll();
} else {
main.alert(data.msg);
}
} catch (e) {
} finally {
main.waitMe("hide");
}
},
error: function (data) {
main.message("导入失败:{0}".template(data.msg));
main.waitMe("hide");
},
// Form数据
data: formData,
//Options to tell JQuery not to process data or worry about content-type
cache: false,
contentType: false,
processData: false
});
});
}
function progressHandlingFunction(e) {
if (e.lengthComputable) {
$('progress').attr({ value: e.loaded, max: e.total });
}
}
function closeTradeVolUploadWindow() {
try { window.parent.layer.closeAll(); } catch (e) { }
}
</script>
}
@using (Html.BeginForm("tradeVolUpload", "trade_volatility", FormMethod.Post, new { id = "tradeVolUploadForm" }))
{
<div class="well" style="margin:0px auto;margin-top:10px;">
<fieldset>
<legend>选择文件</legend>
<!--目前框架新增和修改同一界面,造成的问题就是输入的字段新增和修改都一样-->
@if (Model != null)
{
<input type="hidden" value="@Model.id" name="id" id="id" />
}
<input type="file" id="openFile" name="file" accept=".xlsx" />
</fieldset>
</div>
<div style="margin:0px auto;padding:10px;">
@MyControls.Btn("批量波动率导入", "upload()")
@MyControls.Btn("批量波动率模板下载", "main.downloadFiles('/App_Docs/导入模板/批量波动率模板.xlsx')")
@MyControls.Btn("关闭", "closeTradeVolUploadWindow()")
</div>
}