or
@(Html.Kendo().AutoComplete()
.Name("DiaryCodeAutoComplete")
.Filter("startswith")
.Placeholder("Select diary code...")
.DataTextField("Code")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("GetSelectList", "DiaryCode");
});
})
.Template("<
span
style
=
'font-weight: bold;'
>${data.Code}</
span
> <
span
style
=
'float:right'
>${data.Name}</
span
>")
)
@(Html.Kendo().Grid<
Kendo.Mvc.Examples.Models.ProductViewModel
>()
.Name("grid")
.HtmlAttributes(new { style = "width: 1100px;height:500px" })
.Columns(columns =>
{
columns.Template(e => { }).Width(25);
//columns.Bound(e => e.ProductName);
columns.Bound(e => e.ProductFamily).Width(150);
columns.Bound(e => e.ProductCode).Width(200);
columns.Bound(e => e.Dimensions).Width(100);
columns.Bound(e => e.Date.EditorTemplateName("DatePicker");
columns.Bound(e => e.Unit).Width(80);
columns.Bound(e => e.Quantity).Width(80);
columns.Template(e => { }).Width(30);
})
.ClientRowTemplate(@"
<
tr
class
=
'line1'
>
<
td
style
=
'font-size:larger'
><
div
class
=
'favorite'
>*</
div
></
td
>
<
td
colspan
=
13
>#: ProductName #</
td
>
</
tr
>
<
tr
class
=
'line2'
>
<
td
/>
<
td
class
=
'details'
>
<
span
class
=
'description'
>#: ProductFamily #</
span
>
</
td
>
<
td
class
=
'details'
>
<
span
>#: ProductCode #</
span
>
</
td
>
<
td
class
=
'details'
>
<
span
>#: Dimensions #</
span
>
</
td
>
<
td
class
=
'details'
>
<
div
class
=
'dateControl'
></
div
>
<
input
type
=
'text'
class
=
'datepicker'
/>
</
td
>
<
td
class
=
'details'
>
<
select
>
<
option
label
=
'Mts'
value
=
'1'
/>
<
option
label
=
'Kgs'
value
=
'2'
/>
<
option
label
=
'Lts'
value
=
'3'
/>
</
select
>
</
td
>
<
td
class
=
'details'
>
<
input
type
=
'text'
size
=
'1'
/>
</
td
>
<
td
class
=
'details'
>
<
a
href
=
'javascript:void();'
style
=
'text-decoration:none'
>
<
div
>+</
div
>
</
a
>
</
td
>
</
tr
>"
)
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("RowTemplate_Read", "Grid"))
.Update(update => update.Action("RowTemplate_Update", "Grid"))
)
.Scrollable()
)
@section HeadContent {
<
style
>
.title {
display: block;
font-size: 1.6em;
}
.description {
display: block;
padding-top: 1.6em;
}
.line1 {
border-top:thick !important;
border-top-style:solid !important;
border-top-color:red !important;
border-bottom:none !important;
margin-top:10px !important;
background: linear-gradient(to bottom, rgba(0,0,0,0.05), rgba(0,0,0,0.10));
}
.line2 {
grid-row:start !important;
border-top:none !important;
border-bottom:thick !important;
margin-bottom:10px !important;
background: linear-gradient(to bottom, rgba(0,0,0,0.10), rgba(0,0,0,0.15) 99% , rgba(0,0,0,0.8) 100%);
}
</
style
>
}
<
script
id
=
"dateTemplate"
type
=
"text/x-kendo-template"
>
@(Html.Kendo().DatePicker().Name("dpDate").ToClientTemplate())
</
script
>
<
script
>
$(function () {
$(".datepicker").datepicker();
});
$(document).ready(function () {
var tpl = kendo.template($("#dateTemplate").html());
$(".dateControl").html(tpl({}));
});
</
script
>
@model Kendo.Mvc.Examples.Models.ProductViewModel
@(Html.Kendo().DatePicker()
.Name(
"Date"
)
.Value(Model ==
null
? DateTime.Now : Model.Date)
.Format(
"d/M/yyyy"
)
)
@{
Layout =
"~/Views/Shared/Layout.cshtml"
;
}
@model IEnumerable<LiCPSAdmin2.Models.Adressen>
@(Html.Kendo().Grid(Model)
.Name(
"Adressen"
)
.Columns(columns =>
{
columns.Command(command =>
{
command.Edit().Text(
" "
);
command.Destroy().Text(
" "
);
}).Width(90).HtmlAttributes(
new
{ style =
"background-color: rgb(238, 238, 238)"
});
columns.Bound(p => p.Eadr).Title(
"Adresse"
).Width(90).HtmlAttributes(
new
{ style =
"text-align:center;"
});
columns.Bound(p => p.Nama).Title(
"Name"
).Width(200);
columns.Bound(p => p.Namb).Title(
"Name 2"
).Width(200);
columns.Bound(p => p.Namc).Title(
"Strasse"
);
columns.Bound(p => p.Namd).Title(
"Strasse 2"
);
columns.Bound(p => p.Name).Title(
"Plz, Ort"
);
columns.Bound(p => p.Namf).Title(
"Ort 2"
);
columns.Bound(p => p.Pstc).Title(
"PLZ"
).Width(90).HtmlAttributes(
new
{ style =
"text-align:center;"
});
columns.Bound(p => p.Ccty).Title(
"Land"
).Width(90).HtmlAttributes(
new
{ style =
"text-align:center;"
});
columns.Bound(p => p.BaLand).Title(
"Bezeichnung"
).Width(200).ClientTemplate(
" #= BaLand ? BaLand.Dsca : '' # "
).Filterable(filter => filter.UI(
"BaLandFilter"
));
})
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(50)
.Model(model =>
{
model.Id(p => p.Eadr);
model.Field(p => p.Eadr).Editable(
false
);
})
.Events(events => events.Error(
"error_handler"
))
.Create(create => create.Action(
"Create"
,
"Adressen"
))
.Read(read => read.Action(
"Read"
,
"Adressen"
))
.Update(update => update.Action(
"Edit"
,
"Adressen"
))
.Destroy(destroy => destroy.Action(
"Delete"
,
"Adressen"
))
)
.Events(events => events.Edit(
"edit_handler"
))
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Sortable(sortable => sortable.AllowUnsort(
true
).SortMode(GridSortMode.MultipleColumn))
.Filterable(filter => filter.Extra(
false
))
.ColumnResizeHandleWidth(5)
.Scrollable(scrollable => scrollable.Virtual(
true
))
.HtmlAttributes(
new
{ style =
"height:100%;"
})
.Navigatable(nav => nav.Enabled(
true
))
.Resizable(resize => resize.Columns(
true
))
.Reorderable(reordering => reordering.Columns(
true
))
.Pageable()
)
<script type=
"text/javascript"
>
function error_handler(e) {
if
(e.errors) {
var message =
"Errors:\n"
;
$.each(e.errors, function (key, value) {
if
(
'errors'
in
value) {
$.each(value.errors, function () {
message +=
this
+
"\n"
;
});
}
});
alert(message);
var grid = $(
"#Adressen"
).data(
"kendoGrid"
);
grid.cancelChanges();
}
};
function baland_change() {
$(
"#Ccty"
).val(
this
.value()).css({
'background-color'
:
'#fff'
}).trigger(
"change"
);
}
function edit_handler(e) {
$(
".k-grid-update"
).html(
"<span class=\"k-icon k-update\"></span>"
);
$(
".k-grid-cancel"
).html(
"<span class=\"k-icon k-cancel\"></span>"
);
e.container.find(
"#Ccty"
).focusout(function () {
e.container.find(
"#BaLand"
).data(
"kendoDropDownList"
).value($(
this
).val());
});
}
function BaLandFilter(element) {
element.kendoDropDownList({
dataSource: {
transport: {
read:
"@Url.Action("
FilterMenuCustomization_BaLand
")"
}
},
optionLabel:
"Bitte wählen"
});
}
</script>
@(Html.Kendo().DropDownList()
.Name(
"BaLand"
)
.BindTo((System.Collections.IEnumerable)TempData[
"Land"
])
.DataTextField(
"Dsca"
)
.DataValueField(
"Ccty"
)
.OptionLabel(
"Bitte wählen"
)
.Events(e => e
.Change(
"baland_change"
)
)
)
public
class
AdressenController : Controller
{
private
LiCPS_Develop_V20Entities db =
new
LiCPS_Develop_V20Entities();
protected
override
void
Dispose(
bool
disposing)
{
db.Dispose();
base
.Dispose(disposing);
}
// Index
public
ActionResult Index()
{
TempData[
"Land"
] = db.BaLand.ToList();
var adressen = db.Adressen.Include(a => a.BaLand).Distinct();
return
View(adressen.ToList());
}
public
ActionResult FilterMenuCustomization_BaLand()
{
return
Json(db.BaLand.Select(e => e.Dsca).Distinct(), JsonRequestBehavior.AllowGet);
}
// Grid
public
ActionResult Read([DataSourceRequest] DataSourceRequest request)
{
return
Json(((db.Adressen.Include(a => a.BaLand).Distinct()).ToList()).ToDataSourceResult(request));
}
[AcceptVerbs(HttpVerbs.Post)]
public
ActionResult Create([DataSourceRequest] DataSourceRequest request, Adressen adressen)
{
if
(adressen !=
null
&& ModelState.IsValid)
{
adressen.Eadr = Convert.ToInt32(HelperFunctions.getNextNumber(10, 2));
db.Adressen.Add(adressen);
db.Entry(adressen.BaLand).State = EntityState.Unchanged;
try
{
db.SaveChanges();
}
catch
(InvalidOperationException ex)
{
ModelState.AddModelError(
string
.Empty,
"Es ist ein Fehler aufgetreten! Der Datensatz wurde nicht erstellt"
);
}
catch
(DbEntityValidationException ex)
{
ModelState.AddModelError(
string
.Empty,
"Es ist ein Fehler aufgetreten! Der Datensatz wurde nicht erstellt"
);
}
catch
(DbUpdateException ex)
{
ModelState.AddModelError(
string
.Empty,
"Es ist ein Fehler aufgetreten! Die Adress-Nummer ist bereits vergeben."
);
}
}
return
Json(
new
[] { adressen }.ToDataSourceResult(request, ModelState));
}
[AcceptVerbs(HttpVerbs.Post)]
public
ActionResult Delete([DataSourceRequest] DataSourceRequest request, Adressen adressen)
{
Adressen Adressen =
null
;
if
(ModelState.IsValid)
{
Adressen = db.Adressen.Find(adressen.Eadr);
db.Adressen.Remove(Adressen);
db.SaveChanges();
}
return
Json(
new
[] { adressen }.ToDataSourceResult(request, ModelState));
}
[AcceptVerbs(HttpVerbs.Post)]
public
ActionResult Edit([DataSourceRequest] DataSourceRequest request, Adressen adressen)
{
if
(adressen !=
null
&& ModelState.IsValid)
{
db.Entry(adressen).State = EntityState.Modified;
db.Entry(adressen.BaLand).State = EntityState.Unchanged;
try
{
db.SaveChanges();
}
catch
(InvalidOperationException ex)
{
ModelState.AddModelError(
string
.Empty,
"Es ist ein Fehler aufgetreten! Der Datensatz wurde nicht gespeichert"
);
}
catch
(DbEntityValidationException ex)
{
ModelState.AddModelError(
string
.Empty,
"Es ist ein Fehler aufgetreten! Der Datensatz wurde nicht gespeichert"
);
}
catch
(DbUpdateException ex)
{
ModelState.AddModelError(
string
.Empty,
"Es ist ein Fehler aufgetreten! Der Datensatz wurde nicht gespeichert"
);
}
}
return
Json(
new
[] { adressen }.ToDataSourceResult(request, ModelState));
}
}
public
partial
class
Adressen
{
public
int
Eadr {
get
;
set
; }
public
string
Nama {
get
;
set
; }
public
string
Namb {
get
;
set
; }
public
string
Namc {
get
;
set
; }
public
string
Namd {
get
;
set
; }
public
string
Name {
get
;
set
; }
public
string
Namf {
get
;
set
; }
public
string
Pstc {
get
;
set
; }
public
string
Ccty {
get
;
set
; }
public
virtual
BaLand BaLand {
get
;
set
; }
}
public
partial
class
BaLand
{
public
string
Ccty {
get
;
set
; }
public
string
Dsca {
get
;
set
; }
public
string
Ictc {
get
;
set
; }
public
Nullable<
short
> Meec {
get
;
set
; }
public
string
Tfcd {
get
;
set
; }
}
function
MaterialsGrid(ticket_ID, grid_id, is_editable, default_billable) {
var
self =
this
;
self.ticket_ID = ticket_ID;
self.GRID_ID =
'#'
+ grid_id;
self.HANDLER_URL =
"/MaterialEntry"
;
self.IS_EDITABLE = is_editable;
self.DEFAULT_BILLABLE = default_billable;
self.material_source =
new
kendo.data.DataSource({
batch:
true
,
schema: {
model: {
id:
"MaterialEntryID"
,
fields: {
MaterialEntryID: { type:
"string"
},
TicketID: { type:
"string"
},
ItemID: { type:
"number"
, defaultValue: 0 },
ItemName: { type:
"string"
, defaultValue: GridCommon.emptyText },
Description: { type:
"string"
},
Quantity: { type:
"number"
, defaultValue: 0, validation: { required:
true
, min: 0 } },
Rate: { type:
"number"
, defaultValue: 0 },
Total: { type:
"number"
, defaultValue: 0 },
Billable: { type:
"boolean"
, defaultValue: self.DEFAULT_BILLABLE },
},
}
},
transport: {
read: {
url: self.HANDLER_URL +
"/Read"
,
dataType:
"json"
,
type:
"GET"
,
cache:
false
,
},
update: {
url: self.HANDLER_URL +
"/Update"
,
dataType:
"json"
,
type:
"PUT"
,
},
destroy: {
url: self.HANDLER_URL +
"/Destroy"
,
dataType:
"json"
,
type:
"POST"
,
},
create: {
url: self.HANDLER_URL +
"/Create"
,
dataType:
"json"
,
type:
"POST"
,
},
parameterMap:
function
(options, operation) {
if
(operation ===
"read"
) {
return
{ ticketID: self.ticket_ID };
}
if
(operation ===
"read"
) {
return
{ ticketID: self.ticket_ID };
}
else
if
(options.models) {
return
{ materials: kendo.stringify(options.models), ticketID: self.ticket_ID };
}
}
},
error: GridCommon.showCallBackError
});
self.items_src =
new
kendo.data.DataSource({
transport: {
read: {
url: self.HANDLER_URL +
"/GetItems"
,
dataType:
"json"
,
type:
"GET"
}
},
error: GridCommon.showCallBackError
});
self.itemDropDownEditor =
function
(container, options) {
$(
'<input required data-text-field="ExtendedItemName" data-value-field="ItemName" data-bind="value:'
+ options.field +
'"/>'
)
.appendTo(container)
.kendoDropDownList({
autoBind:
false
,
optionLabel: { ExtendedItemName: GridCommon.emptyText, ItemID: 0 },
dataSource: self.items_src,
change:
function
(e) {
options.model.set(
'ItemID'
, e.sender.dataItem().ItemID);
}
});
}
self.updateTotal =
function
(e) {
var
r = e.values.Rate ? e.values.Rate : e.model.Rate;
var
q = e.values.Quantity ? e.values.Quantity : e.model.Quantity;
e.model.set(
'Total'
, q * r);
}
self.init =
function
() {
var
tools =
null
;
var
row_commands =
null
;
if
(self.IS_EDITABLE) {
tools = [
{ name:
"save"
, text:
"Save"
},
{ name:
"cancel"
, text:
"Cancel"
},
{ name:
"create"
, text:
"Add"
},
{ template: GridCommon.toggleBillableTemplate(self.GRID_ID) }
];
row_commands = [{
name:
"destroy"
,
template:
'<a href="##" class="k-grid-delete"><img img src="/Content/images/icons/delete.png" /></a>'
}]
}
else
{
$(self.GRID_ID).addClass(
'readonly'
);
}
$(self.GRID_ID).kendoGrid({
toolbar: tools,
save: self.updateTotal,
columns: [
{ field:
"ItemName"
, title:
"Item Type"
, editor: self.itemDropDownEditor },
{ field:
"Description"
},
{ field:
"Quantity"
, title:
"QTY"
, width: 65, editor: GridCommon.numberEditor },
{ field:
"Rate"
, title:
"Price"
, format:
"{0:c}"
, width: 90, editor: GridCommon.numberEditor },
{ field:
"Total"
, editor: GridCommon.notEditable, format:
"{0:c}"
, width: 95 },
{ field:
"Billable"
, template:
'#= GridCommon.getBillableText(Billable) #'
, width: 100},
{ command: row_commands, width: 40 }
],
pageable:
false
,
scrollable:
true
,
editable: self.IS_EDITABLE,
navigatable:
true
,
sortable:
true
,
batch:
true
,
dataSource: self.material_source,
saveChanges: GridCommon.saveAll
});
}
}
@model Guid
<
div
class
=
"grid-wrapper"
>
<
div
id
=
"materials-data"
class
=
"grid-global-save"
>
<!-- grid will appear here -->
</
div
>
</
div
>
<
script
type
=
"text/javascript"
>
var mat_grid = new MaterialsGrid('@Model', 'materials-data', true, true);
$(document).ready(mat_grid.init);
</
script
>
[AcceptVerbs(HttpVerbs.Post)]
public
JsonResult Create([DataSourceRequest] DataSourceRequest request, IEnumerable<TempVM> materials, string ticketId)
{
ModelState.Remove(
"MaterialEntryId"
);
ModelState.Remove(
"Id"
);
return
Json(
""
);
}
public
class
TempVM
{
public
string
MaterialEntryID {
get
;
set
; }
public
string
TicketID {
get
;
set
; }
public
int
ItemID {
get
;
set
; }
public
string
Description {
get
;
set
; }
}
@Html.HiddenFor(model => model.Id)
<
div
class
=
"editor-label"
>
@Html.LabelFor(model => model.Name)
</
div
>
<
div
class
=
"editor-field"
>
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</
div
>
<
div
class
=
"editor-label"
>
@Html.LabelFor(model => model.OwnerId)
</
div
>
<
div
class
=
"editor-field"
>
@(Html.Kendo().DropDownList()
.Name("OwnerId")
.HtmlAttributes(new { style = "width: 250px" })
.DataTextField("NamePlusDepartment")
.DataValueField("Id")
.OptionLabel("Välj en person")
.DataValueField("Id")
.DataSource(source => {
source.Read(read =>
{
read.Action("GetPersonal", "List");
});
})
)
</
div
>
<
div
class
=
"editor-label"
>
@Html.LabelFor(model => model.ResponsibleId)
</
div
>
<
div
class
=
"editor-field"
>
@(Html.Kendo().DropDownList()
.Name("ResponsibleId")
.HtmlAttributes(new { style = "width: 250px" })
.DataTextField("NamePlusDepartment")
.DataValueField("Id")
.OptionLabel("Välj en person")
.DataSource(source => {
source.Read(read =>
{
read.Action("GetPersonal", "List");
});
})
)
</
div
>
public class PaymentsViewModel
{
public List<
CorporateViewModel
> Corporations { get; set; }
public List<
PaymentViewModel
> Payments { get; set; }
}
public ActionResult Payments_Read([DataSourceRequest]DataSourceRequest request)
{
//get corps
//get payments
PaymentsViewModel returnObj = new PaymentsViewModel();
returnObj.Corporations = corps;
returnObj.Payments = payments;
DataSourceResult result = returnObj.ToDataSourceResult(request); <== returns error
return Json(result);
}