private void SaveItem() { _pickListView = getPickListHeader(null); _isPickListLocalized = !string.IsNullOrWhiteSpace(_pickListView.DefaultLanguage); if (string.IsNullOrEmpty(txtItemText.Text)) { throw new ValidationException(GetLocalResourceObject("error_InvalidItemName").ToString()); } if (_isPickListLocalized && string.IsNullOrEmpty(txtCode.Text)) { throw new ValidationException(GetLocalResourceObject("error_InvalidItemCode").ToString()); } var keyChanged = false; if (_pickListItemView == null && !string.IsNullOrEmpty(hdPickListItemId.Value) && !string.IsNullOrEmpty(hdPickListId.Value)) { _pickListItemView = EntityFactory.GetByCompositeId(typeof(IPickListItemView), new[] { "PickListItemId", "PickListId" }, new object[] { hdPickListItemId.Value, hdPickListId.Value }) as IPickListItemView; } if (_pickListItemView != null) { keyChanged = !string.Equals(_pickListItemView.Code, txtCode.Text) || !string.Equals(_pickListItemView.LanguageCode, cboLanguage.SelectedValue); } PickListHelper.DialogTypes dtMode = PickListHelper.StringToDialogTypes(hdMode.Value); if (keyChanged || (string.IsNullOrEmpty(hdPickListItemId.Value) && dtMode == PickListHelper.DialogTypes.Add) || dtMode == PickListHelper.DialogTypes.Localize) { var order = Convert.ToInt32(txtOrder.Text); PickList pl = PickList.AddNewPickListItem(hdPickListId.Value, txtItemText.Text, txtCode.Text, txtFilter.Text, cboLanguage.SelectedValue, order, string.Empty); if (chkIsDefaultItem.Checked) { PickList.SetAsDefaultItemCode(hdPickListId.Value, pl.ItemId); } } else { PickList pl = PickList.GetPickListItemById(hdPickListId.Value, hdPickListItemId.Value); pl.Shorttext = txtCode.Text; pl.Text = txtItemText.Text; var orderValue = Convert.ToInt32(txtOrder.Text); pl.Id = orderValue; pl.Filter = txtFilter.Text; pl.LanguageCode = cboLanguage.SelectedValue; PickList.SavePickListItem(pl); if (chkIsDefaultItem.Checked && string.IsNullOrEmpty(hdIsDefault.Value)) { PickList.SetAsDefaultItemCode(hdPickListId.Value, pl.ItemId); } if (!chkIsDefaultItem.Checked && !string.IsNullOrEmpty(hdIsDefault.Value)) { PickList.SetAsDefaultItemCode(hdPickListId.Value, string.Empty); } } var picklistService = ApplicationContext.Current.Services.Get <IPickListService>(true); picklistService.ClearPickListCache(); var refresher = PageWorkItem.Services.Get <IPanelRefreshService>(); refresher.RefreshAll(); }
protected void grdPicklistItems_RowCommand(object sender, GridViewCommandEventArgs e) { if (e == null || string.IsNullOrWhiteSpace(e.CommandName)) { return; } PickListHelper.DialogTypes commandName = PickListHelper.StringToDialogTypes(e.CommandName); switch (commandName) { case PickListHelper.DialogTypes.Edit: var editRowIndex = Convert.ToInt32(e.CommandArgument); if (DialogService != null) { DialogService.SetSpecs(285, 600, "AddEditPickListItem"); DialogService.DialogParameters.Clear(); DialogService.DialogParameters.Add("MODE", PickListHelper.DialogTypes.Edit); DialogService.DialogParameters.Add("PickListId", grdPicklistItems.DataKeys[editRowIndex].Values[1].ToString()); DialogService.DialogParameters.Add("PickListItemId", grdPicklistItems.DataKeys[editRowIndex].Values[0].ToString()); DialogService.ShowDialog(); } break; case PickListHelper.DialogTypes.Delete: var deleteRowIndex = Convert.ToInt32(e.CommandArgument); var selectedItem = PickList.GetPickListItemById( grdPicklistItems.DataKeys[deleteRowIndex].Values[1].ToString(), grdPicklistItems.DataKeys[deleteRowIndex].Values[0].ToString()); var isDefaultLanguage = PickList.IsItemADefaultLanguageItem(selectedItem); if (isDefaultLanguage) { PickList.DeletePickListItemsByCode(selectedItem); } else { PickList.DeletePickList(selectedItem); } var picklistService = ApplicationContext.Current.Services.Get <IPickListService>(true); picklistService.ClearPickListCache(); var refresher = PageWorkItem.Services.Get <IPanelRefreshService>(); refresher.RefreshAll(); break; case PickListHelper.DialogTypes.Localize: string[] ids = e.CommandArgument.ToString().Split(';'); if (DialogService != null) { DialogService.SetSpecs(285, 600, "AddEditPickListItem"); DialogService.DialogParameters.Clear(); DialogService.DialogParameters.Add("MODE", PickListHelper.DialogTypes.Localize); DialogService.DialogParameters.Add("PickListId", ids[0]); DialogService.DialogParameters.Add("PickListItemId", ids[1]); DialogService.ShowDialog(); } break; } }
protected void btnSaveNew_Click(object sender, EventArgs e) { //save dialog form SaveItem(); PickListHelper.DialogTypes dtMode = PickListHelper.StringToDialogTypes(hdMode.Value); var isLocalized = dtMode == PickListHelper.DialogTypes.Localize; // clean up service values DialogService.DialogParameters.Remove("MODE"); if (!isLocalized) { DialogService.DialogParameters.Remove("PickListItemId"); } // set service to add mode DialogService.DialogParameters.Add("MODE", isLocalized ? PickListHelper.DialogTypes.Localize : PickListHelper.DialogTypes.Add); // close the current dialog to refresh the dialog title, tools, and controls Page.ClientScript.RegisterOnSubmitStatement(typeof(Page), "closePage", "window.onunload = CloseWindow();"); // bring up the new dialog DialogService.ShowDialog(); }