TypeScript Aktion
public static ClientActionAddService(event: any, customData: CustomData) {
let paramter: CustomData = {};
paramter.RemarkMessage = customData.RemarkMessage;
paramter.ServiceDate = customData.ServiceDate;
BA.Ui.Dialog.DialogManager.OpenDialog("BA.Training.AddServiceDialog", customData, customData,
function (result: BA.Ui.Dialog.DialogResult, customData: CustomData) {
if (result.ButtonId == 'okButton') {
let igniterParams: CustomData = {};
igniterParams.RemarkMessage = result.Data.Remark;
igniterParams.ServiceDate = result.Data.Date;
customData["MassOperationIgniterParameters"] = JSON.stringify(igniterParams);
BA.Ui.Actions.GridActions.StartMassOperation(event, customData);
}
}
);
}
Dialog Model
public class AddServiceDialogModel
{
[BARequired]
public string Remark { get; set; }
[BARequired]
public DateTime Date { get; set; }
}
Dialog
[DialogImplementation("BA.Training.AddServiceDialog")]
public class AddServiceDialog : DialogImplementationBase
{
public override void CreateDialogContent(DevExFormModel formModel, HttpRequestBase request, ModelStateDictionary modelState, Dictionary<String, Object> parameter, object bindObject = null)
{
AddServiceDialogModel dataModel;
if (bindObject == null)
dataModel = new AddServiceDialogModel { Date = DateTime.Now, Remark = parameter.Get("RemarkMessage")?.ToString() };
else
dataModel = (AddServiceDialogModel)bindObject;
formModel.Title = "95437073-8D05-4650-8F75-4B53AEB4A456".Translate();
formModel.FormGuid = "A758783B-D133-4359-8A63-B91574C15220".ToGuid();
formModel.DataSource = dataModel;
formModel.Width = 600;
LayoutPanelControl layout = new LayoutPanelControl()
{
Id = "DEB77CD6-1823-445F-A70D-A0E6001E4351".ToGuid(),
ColumnCount = 2,
WrapContentAtWidth = 400,
//StretchLastItem = true,
};
layout.AddBreakpoint(new BreakpointRule() { Name = "S", ColumnCount = 1, MaxWidth = 500 });
Controls.Add(layout);
DateEditControl dateTime = new DateEditControl()
{
Id = "70C9B90B-832C-460A-9A9F-E83463C0CC1F".ToGuid(),
Caption = "B2A43538-EF7C-416F-89AB-F501D09AE6E3",
ShowTimeSection = false,
ColSpan = 1,
OrmFieldName = nameof(AddServiceDialogModel.Date)
};
layout.Controls.Add(dateTime);
TextEditControl textControl = new TextEditControl()
{
Id = "6DF2D790-8710-4A69-9530-49DAA3F31B36".ToGuid(),
Caption = "5D49A7FE-8165-4FDC-953F-A194BCFFCE26",
ColSpan = 1,
OrmFieldName = nameof(AddServiceDialogModel.Remark)
};
layout.Controls.Add(textControl);
formModel.AddButton("BA.Training.InputButton", "5d49a7fe-8165-4fdc-953f-a194bcffce26".Translate(), false, "BA.Training.Actions.InputButton");
formModel.AddButton(DialogButtonIds.OkButton, "OK", true);
formModel.AddButton(DialogButtonIds.CancelButton, "Cancel", false, "BA.Ui.Dialog.DialogManager.DialogDefaultCancel");
MVCxFormLayoutItemCollection formControls = DevExFormLayoutTranslator.TranslateControls(Controls, formModel.DataSource, formModel, null, requestContext: request);
DevExFormPartModel partModel = new DevExFormPartModel();
partModel.Controls = formControls;
partModel.FormName = "dialogPart";
formModel.LayoutName = EnumFormLayout.SingleColumn.LayoutName;
formModel.LayoutPanels.Add(partModel);
request.ConfigurationGuid(formModel.FormGuid);
}
public override DialogResultModel HandleAction(HttpRequestBase request, ModelStateDictionary modelState, Dictionary<String, Object> parameter, String buttonId, object bindObject, string propertyPrefix = "")
{
DialogResultModel result = base.HandleAction(request, modelState, parameter, buttonId, bindObject, propertyPrefix);
if(buttonId == DialogButtonIds.OkButton && modelState.IsValid)
{
AddServiceDialogModel dataModel = (AddServiceDialogModel)bindObject;
result.Data = dataModel;
}
return result;
}
}
TypeScript Button
public static InputButton(button: BA.Ui.Dialog.BADialogButton, evt: ASPxClientButtonClickEventArgs) {
var texts = [];
var titleGuid = "41aba083-e37a-4709-98d4-1d685496459c";
var messageGuid = "5d49a7fe-8165-4fdc-953f-a194bcffce26";
texts.push(titleGuid);
texts.push(messageGuid);
BA.Ui.Translations.TranslationTools.GetTranslations(texts, function (results) {
BA.Ui.MessageBox.ShowPrompt(results[titleGuid], results[messageGuid], 200, function (result) {
let textBoxName: string = BA.Ui.Dialog.DialogManager.GetDialogControlName(button, "Remark");
if (window[textBoxName]) {
let box: BAClientTextBox = <BAClientTextBox>window[textBoxName];
box.SetValue(result);
}
});
}, false);
}
Angepasster Igniter
public override ActionResult Ignite()
{
if (SomethingSelected)
{
if (IgnitionModel.Parameters.TryGetValue("RemarkMessage", out object remarkObj) && remarkObj is string remark && !string.IsNullOrWhiteSpace(remark))
{
Session session = Api.ORM.GetNewSession();
IEnumerable<Guid> oids = Records.Select(ff => ff.Oid);
IQueryable<OrmEngine> engines = Api.ORM.GetQuery<OrmEngine>(session).Where(ff => oids.Contains(ff.Oid));
DateTime date;
if (IgnitionModel.Parameters.TryGetValue("ServiceDate", out object dateObj) && dateObj is DateTime)
date = (DateTime)dateObj;
else
date = DateTime.Now;
int counter = 0;
foreach (OrmEngine engine in engines)
{
OrmSubEngineServices service = engine.Services.AddNewObject();
service.SortOrder = engine.Services.Count() - 1;
service.ServiceDate = date;
service.Remark = remark;
engine.Save();
counter++;
}
Api.ClientCommunication.CreateSuccess(Api.User.CurrentUserGuid(), "dd1ceadc-6808-4583-b6b7-dda73188b5a8".Translate(counter));
return new JsonResult() { Data = new JsonFormResult() { RefreshGrid = true } };
}
else
Api.ClientCommunication.CreateError(Api.User.CurrentUserGuid(), "d49ef787-3ad1-4f66-bb12-b2660fd71738".Translate());
}
return null;
}