<div class="container" style="overflow:hidden;padding:20px;">
<form class="form-horizontal" method="post" id="formImport" οnsubmit="return false">
<div>
<input type="file" id="openFile" name="file" accept="text/csv" />
@*<input type="file" accept="text/csv" name="openFile" id="openFile" οnchange=uploadChange()>*@
@*<input style="width:50%; height: 28px; text-align: left;" type="button" id="uploadfileButton" οnclick="openFile.click();" value="请选择..." />*@
<a class="btn btn-link" href="/eodPrice/EodSpotPriceList" target="_blank">操作历史</a>
</div>
<div style="margin: 0px auto; padding: 10px;">
<input class="btn btn-primary" type="button" οnclick="importGuoTouDatas();return false;" value="导入数据" />
<input class="btn btn-primary" type="button" οnclick="layer.closeAll();return false;" value="关闭" />
</div>
</form>
</div>
function importGuoTouDatas() {
/*上传的文件file*/
if (!checkSubmitData()) return;
var formData = new FormData($('#formImport')[0]);
var ClientId = $("#ClientId").val();
formData.append("ClientId", ClientId);
main.post('/eodPrice/UploadSettlementClientSpotBill', formData, {
cache: false,
contentType: false,
processData: false
}).done(function (data) {
SearchClick();
layer.closeAll();
if (data.obj) {
//document.getElementById('errormessage').innerHTML = data.obj
layer.open({
type: 1,
area: ['420px', '240px'], //宽高
content: data.obj,
});
}
});
}
function checkSubmitData() {
//非CSV文件不允许用户导入
var fileName = $('#openFile').val();
if (fileName == "") {
main.message("请选择文件!");
return false;
}
var axx = "csv";
var arr = "xlsx";
var index = fileName.lastIndexOf(".");
var ext = fileName.substr(index + 1);
if (ext == arr) {
return true;
}
else if (ext == axx) {
return true;
}
else {
main.message("请导入xlsx格式文件!");
}
return true;
}
public ActionResult UploadSettlementClientSpotBill(HttpPostedFileBase file, int ClientId = 0)
{
try
{
if (file == null || string.IsNullOrWhiteSpace(file.FileName))
{
return JsonError("未获取上传文件");
}
var fileExtension = Path.GetExtension(file.FileName);
if (fileExtension.ToLowerInvariant() != ".xlsx")
{
return JsonError("请上传xlsx格式的文件");
}
var result = new SettlementPriceImportService(CurUser).ImportClientSpotxlsxDatas(file.InputStream);
return JsonSuccess(null, html);
}
catch (Exception ex)
{
return JsonError(ex.Message);
}
}