1 private T JsonDeserialize<T>(string jsonString) 2 3 { 4 5 DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T)); 6 7 MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonString)); 8 9 T obj = (T)ser.ReadObject(ms); 10 11 return obj; 12 13 }
List<aa> listDeleted = JsonDeserialize<List<aa>>("json文件");
public class aa{ public int ID{get;set;}; public string Name{get;set;}; }
行编辑
function EditSalegrid(queryData) {
Editgrid = $('#dg').datagrid({
nowrap: false,
title: '销售人员设置',
url: '/ajax/quotation/GetQuotationList.ashx',
align: 'right',
striped: true,
iconCls: 'icon-edit',
singleSelect: true,
toolbar: '#tb',
idField: 'id',
pageSize: '20',
rownumbers: true,
pagination: true,
sortName: 'id',
sortOrder: 'asc',
pageList: [20, 30, 40, 50, 100, 200],
queryParams: queryData, //异步查询的参数
columns: [[
{
'100',
title: '销售人员',
field: 'userid',
formatter: function (value, row) {
for (var i = 0; i < users.length; i++) {
if (users[i].id == value) return users[i].name;
}
},
editor: {
type: 'combobox',
options: {
valueField: 'id',
textField: 'name',
data: users,
required: true
}
}
}
,
{
'100',
title: '分成',
field: 'perc',
editor: { type: 'numberbox', options: { min: 0.1, precision: 1, max: 100, required: true} }
,
formatter: function (value, row) {
return value + '%';
}
}
,
{
'100',
title: '',
field: 'quotationid',
hidden: true
}
]],
onClickRow: function (rowIndex, rowData) {
onClickRow(rowIndex);
}
});
}
var editIndex = undefined;
function endEditing() {
if (editIndex == undefined) { return true }
if ($('#dg').datagrid('validateRow', editIndex)) {
$('#dg').datagrid('endEdit', editIndex);
editIndex = undefined;
return true;
} else {
return false;
}
}
function onClickRow(index) {
if (editIndex != index) {
if (endEditing()) {
$('#dg').datagrid('selectRow', index)
.datagrid('beginEdit', index);
editIndex = index;
} else {
$('#dg').datagrid('selectRow', editIndex);
}
}
}
function append() {
if (endEditing()) {
$('#dg').datagrid('appendRow', { perc: '100.1', quotationid: $('#hid_id').val() });
editIndex = $('#dg').datagrid('getRows').length - 1;
$('#dg').datagrid('selectRow', editIndex)
.datagrid('beginEdit', editIndex);
}
}
function removeit() {
if (editIndex == undefined) { return }
$('#dg').datagrid('cancelEdit', editIndex)
.datagrid('deleteRow', editIndex);
editIndex = undefined;
}
function accept() {
if (endEditing()) {
$('#dg').datagrid('acceptChanges');
}
}
function reject() {
$('#dg').datagrid('rejectChanges');
editIndex = undefined;
setTimeout("SetRule(" + $('#hid_pages').val() + ")", 400);
}
function getChanges() {
if (endEditing()) {
if ($('#dg').datagrid('getChanges').length) {
var rows = $('#dg').datagrid('getChanges');
var inserted = $('#dg').datagrid('getChanges', "inserted");
var deleted = $('#dg').datagrid('getChanges', "deleted");
var updated = $('#dg').datagrid('getChanges', "updated");
var effectRow = new Object();
if (inserted.length) {
effectRow["inserted"] = JSON.stringify(inserted);
}
if (deleted.length) {
effectRow["deleted"] = JSON.stringify(deleted);
}
if (updated.length) {
effectRow["updated"] = JSON.stringify(updated);
}
var rows = $('#dg').datagrid('getRows');
var p = 0;
var str = "";
for (var i = 0; i < rows.length; i++) {
p += parseFloat(rows[i].perc);
str += rows[i].userid+','
}
if (str.length > 0) {
str = str.substring(0, str.length - 1);
var t = str.split(',');
var arr=[];
for (var i = 0; i < t.length; i++) {
arr.push(t[i]+''); /* 避免他将ID当成数字 */
}
for (var i = 0; i < arr.length; i++) {
if (str.replace(arr[i] + '','', "").indexOf(arr[i] + ",") > 0) {
$.messager.alert('提示', '销售人员不能重复设置', 'error');
return;
}
}
}
if (Math.abs(p - 100) > 0.01) {
$.messager.alert('提示', '请检查分成,总分成不能大于100', 'error');
return;
}
$.post("/ajax/quotation/quotationsale.ashx", effectRow, function (rsp) {
if (rsp[0].success) {
$('#dg').datagrid('acceptChanges');
// setTimeout("SetRule(" + $('#hid_pages').val() + ")", 400);
$.messager.alert('提示', '设置成功', 'ok');
}
}, "JSON").error(function () {
$.messager.alert("提示", "抱歉出错了!");
});
}
}
}