
var strFile = '';
var json = '';
$(document).ready(function () {
    $('input[type=file]').change(function (event) {
        var fileName = $(this).val();
        $('#txtPath').val(fileName);
        if (this.files.length > 0) {
            var file = event.target.files[0];
            var reader = new FileReader();
            reader.readAsDataURL(file);
            reader.onload = function () {
                strFile = reader.result;
            };
        }
    });
});

function save() {
    if (json !="") {
        refreshParent('refreshGrid(' + JSON.stringify(json) + ',' + cboWorkShop.GetValue() + ',' + cboYear.GetValue() + cboMonth.GetValue() + ')');
        closeTopModal();
    }
    else {
        alert("فایل را انتخاب کنید");
    }
    
}

function getSample() {

    ajax({
        url: "Salary/ClockDeviceInputFile/SampleFile",
        success: function (result) {
            var link = document.createElement('a');
            link.download = 'Gheyas_Karkard';
            link.href = result.d;
            link.click();
            $(link).remove();
        }
    });
}

function insertToTable(items) {
    debugger;
    deleteGridRows(grdInputFile);
    for (var i = 0; i < items.length; i++) {
        grdInputFile.AddNewRow();
        grdInputFile.batchEditApi.EndEdit();
        var trs = getGridTableRows(grdInputFile);
        var lastRow = getGridRowId($(trs[trs.length - 1]));
        for (var j = 0; j < grdInputFile.GetColumnsCount() ; j++) {
            var column = grdInputFile.GetColumn(j);
            grdInputFile.batchEditApi.SetCellValue(lastRow, column.fieldName, items[i][column.fieldName]);
        }
    }
}