How to enable create / insert in a AxGridView in Enterprise Portal (Dynamics AX 2009) - axapta

There must be a way to enable creation and insertion of a record from a AxGridView without using the Tunnel and Wizard approach. From what I have found on the Internet so far, the only example is using a Wizard, and I honestly don't find that to be a user friendly approach.
Has anyone tried to enable insertion of records directly from a AxGridView?

Yes it is possible to enter data through AxGridView. Just enable Editing, deleting for that control. And one more thing to make new row - you have to make addditional button - create new line, and code behind:
protected void NewLine_Click(object sender, EventArgs e)
{
int editIdx = AxGridView1.EditIndex;
try
{
// Save the last unsaved line if any
if (AxGridView1.EditIndex != -1 && AxGridView1.Rows.Count > 0)
{
this.AxGridView1.UpdateRow(AxGridView1.EditIndex, true);
}
DataSetViewRow dsvr = this.dsv.AddNew();
}
catch (System.Exception ex)
{
AxExceptionCategory exceptionCategory;
if (!AxControlExceptionHandler.TryHandleException(this, ex, out exceptionCategory))
{
// Throw the fatal exception
throw;
}
if (exceptionCategory == AxExceptionCategory.NonFatal)
{
AxGridView1.EditIndex = editIdx;
}
}
}
private DataSetView dsv //get dataset view
{
get
{
DataSet dataSet = this.AxDataSource1.GetDataSet();
return dataSet.DataSetViews[this.AxGridView1.DataMember];
}
}

Related

Nested subscription to messages on xamarin forms

I'm new with Xamarin forms and don't know how to deal with this case. I've tryed to implement it in several ways but with no success.
I have a page where when user makes an action (write a text on a text box and send it with enter key) my app must make some checkings. Depending on the result of the checks, it could be necessary to show a modal page with a list of item to select. Ones user makes the selection process must continue with other checks. And here is my problem, because in this next checkings I have to show another page. User must make a selection/enter some date, and then continue to complete the proccess, but this page is not appear.
I'm using the messagingCenter to subscribe to the modal pages. First modal page appears and makes the selection well. Second modal page is never shown and then proccess never complets.
Here is some of my code:
NavigationPage navigationPage = new NavigationPage(new ListItemsPage(products));
Navigation.PushModalAsync(navigationPage);
MessagingCenter.Subscribe<ListItemsPage, Guid?>(this, "Select product", (obj, item) =>
{
try
{
if (item != null)
{
product = products.SingleOrDefault(x => x.Guid == item);
if (product != null) ProcessLine(product);
}
}
catch(Exception ex)
{
throw ex;
}
finally
{
MessagingCenter.Unsubscribe<ListItemsPage, Guid?>(this, "Select product");
}
});
On ListItemsPage I have this code whe item is selected:
private void MenuItem_Clicked(object sender, EventArgs e)
{
// some logic...
Navigation.PopModalAsync();
MessagingCenter.Send(this, "Select product", SelectedGuid);
}
SelectedGuid is a Guid type data and when debbugin is well selected.
Problems comes when goes to ProcessLine method.
private void ProcessLine(Product product) {
// make some logic...
NavigationPage navigationPage = new NavigationPage(new ControlUnitsPage(model));
Navigation.PushModalAsync(navigationPage);
MessagingCenter.Subscribe<ControlUnitsPage, ControlUnits>(this, "Select units, date and lot code", (obj, item) =>
{
try
{
if (item != null)
{
_date = item.Date;
_code = item.Code;
_units = item.Units;
Save(productLine, product, _units, _date,_code);
}
}
catch(Exception ex)
{
throw ex;
}
finally
{
MessagingCenter.Unsubscribe<ControlUnitsPage, ControlUnits>(this, "Select units, date and lot code");
}
});
}
ControlUnitsPage has the same structure as the last one page. First makes a PopModalAsync and then sends the message sending an instance of ControlUnits type.
private void Button_Clicked(object sender, EventArgs e)
{
//some logic...
Item = new ControlUnits() { Date = DateField.Date, Code = CodeField.Text, Units = int.Parse(SelectedUnits.Value.ToString()) };
Navigation.PopModalAsync();
MessagingCenter.Send(this, "Select units, date and lot code", Item);
}
I think problem is in the order of invoking method but dont know what is the properly order because I am not able to understand how pushmodal, popmodal methods work, whether or not I should use await with it if after that comes a subscription. I really don't know and I need help, please.
Thank you so much!
your Send and Subscribe calls both need to use matching parameters
if Subscribe looks like this
MessagingCenter.Subscribe<ControlUnitsPage, ControlUnits>(this, "Select units, date and lot code", (obj, item) => ... );
then Send needs to match
MessagingCenter.Send<ControlUnitsPage, ControlUnits>(this, "Select units, date and lot code", Item);

Firebase Dynamic Links in Unity

Where should I put this chunk of code in order the listener function works every time I enter the app from the deep link?
Now in my unity mobile app I have this code in the initial load, however it does not work well.
The first case of entering the app from the deep link is not being handled. Only after initial load when I click the deep link my listener function works (as the listener is already set).
Is there any solution to this issue?
void Start()
{
DynamicLinks.DynamicLinkReceived += OnDynamicLink;
}
// Display the dynamic link received by the application.
void OnDynamicLink(object sender, EventArgs args)
{
var dynamicLinkEventArgs = args as ReceivedDynamicLinkEventArgs;
Debug.LogFormat("Received dynamic link {0}", dynamicLinkEventArgs.ReceivedDynamicLink.Url.OriginalString);
}
Test this, feel free to edit.
void Start()
{
StartCoroutine(WaitLoader()); //Loader
}
public void trueAwoken()
{
DynamicLinks.DynamicLinkReceived += OnDynamicLink;
}
public IEnumerator WaitLoader()
{
int i = 0;
while (i < 5) // Potential for true load state 5 (increase this 0-1000+?, it depends on your build?)
{
i++;
//Debug.Log("Waiting: " + i + "/" + Time.deltaTime);
yield return new WaitForFixedUpdate();
}
trueAwoken();
}

How to persist search criteria and results of a c# .NET application page

Scenario:
User submits search criteria and selects an item from search results on the same page, which navigates to a new page of details for the selected item.
When the User returns to the search screen, the search criteria & results (including selected page and sort-order) should be preserved from their last visit.
Related information:
All form submissions are POSTs.
Navigation back to the search screen may not be available from last browser history (e.g. more than one details screen may be encountered, or the user may navigate directly to the search screen from an alternative menu.)
Search results are provided using Telerik RadGrid control.
I'm looking for a generic solution that will be able to be applied to different search screens.
In some instances, the item may be DELETED from within the details screen, and should therefore not appear in the search results when the screen is next encountered.
Thoughts:
I've read a lot of suggested methods for addressing various parts of this scenario, but I'm still confused; no comprehensively "correct" solution jumps to the forefront.
I guess I'm asking for recommendations/approach rather than a whole solution spelled out for me (although that would be nice! ;-)
The .NET VIEWSTATE would seem to do exactly what I'm after (with the exception of #5) - Is there some way of leveraging off this so that viewstate can be used between pages, and not just between postbacks to the same page? (e.g. can I store/restore viewstate to/from a session variable or something? I haven't seen this suggested anywhere and I'm wondering if there's a reason why.)
Thanks in advance.
Thanks for all the advice.
For the benefit of others, here is a solution to this issue (no doubt there's room for improvement, but this works satisfactorily for the moment).
4 functions...
StoreSearchCookie - Persist the state/values of a panel of search criteria and a results grid in a cookie with a specified UID.
RestoreSearchCookie_Criteria - Read the cookie and re-populate the search criteira
RestoreSearchCookie_Results - Read the cookie and restore the grid state.
FindFormControls - Helper method to recursively find form-input controls in a container (pinched & modified from elsewhere on Stack Overflow)
NB...
I haven't addressed the multiple-tabs issue because our application doesn't allow them anyway.
RestoreSearchResults utilises GridSettingsPersister.cs available from Telerik website, (but I had to modify it to store the page number as well)
Usage is as follows...
protected void Page_PreRender(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
// Store the state of the page
StoreSearchCookie("SomeSearchPage", pnlSearchCriteria, gridResults);
}
else
{
// Restore search criteria
RestoreSearchCookie_Criteria("SomeSearchPage");
// Re-invoke the search here
DoSearch(); // (for example)
// Restore the grid state
RestoreSearchCookie_Results("SomeSearchPage");
}
}
Code follows...
protected void StoreSearchCookie(string cookieName, Panel SearchPanel, RadGrid ResultsGrid)
{
try
{
HttpCookie cookieCriteria = new HttpCookie("StoredSearchCriteria_" + cookieName);
// 1. Store the search criteria
//
List<Control> controls = new List<Control>();
FindFormControls(controls, SearchPanel);
foreach (Control control in controls)
{
string id = control.ID;
string parentId = control.Parent.ID;
string uid = string.Format("{0}>{1}", parentId, id);
string value = "";
Type type = control.GetType();
bool isValidType = true; // Optimistic!
if (type == typeof(TextBox))
{
value = ((TextBox)control).Text;
}
else if (type == typeof(DropDownList))
{
value = ((DropDownList)control).SelectedValue;
}
else if (type == typeof(HiddenField))
{
value = ((HiddenField)control).Value;
}
else if (type == typeof(RadioButton))
{
value = ((RadioButton)control).Checked.ToString();
}
else if (type == typeof(CheckBox))
{
value = ((CheckBox)control).Checked.ToString();
}
else
{
isValidType = false;
}
if (isValidType)
{
cookieCriteria.Values[uid] = value;
}
}
cookieCriteria.Expires = DateTime.Now.AddDays(1d);
Response.Cookies.Add(cookieCriteria);
// 2. Persist the grid settings
//
GridSettingsPersister SavePersister = new GridSettingsPersister(ResultsGrid);
HttpCookie cookieResults = new HttpCookie("StoredSearchResults_" + cookieName);
cookieResults.Values["GridId"] = ResultsGrid.ID;
cookieResults.Values["GridSettings"] = SavePersister.SaveSettings();
cookieResults.Expires = DateTime.Now.AddDays(1d);
Response.Cookies.Add(cookieResults);
}
catch (Exception exception)
{
Logger.Write(exception);
}
}
protected void RestoreSearchCookie_Criteria(string cookieName)
{
try
{
HttpCookie cookieCriteria = Request.Cookies["StoredSearchCriteria_" + cookieName];
if (cookieCriteria != null)
{
foreach (string key in cookieCriteria.Values.AllKeys)
{
string value = cookieCriteria[key];
string[] ids = key.Split('>');
string parentId = ids[0];
string id = ids[1];
Control control = FindControl(parentId).FindControl(id);
Type type = control.GetType();
if (type == typeof(TextBox))
{
((TextBox)control).Text = value;
}
else if (type == typeof(DropDownList))
{
((DropDownList)control).SelectByValue(value);
}
else if (type == typeof(HiddenField))
{
((HiddenField)control).Value = value;
}
else if (type == typeof(RadioButton))
{
((RadioButton)control).Checked = Boolean.Parse(value);
}
else if (type == typeof(CheckBox))
{
((CheckBox)control).Checked = Boolean.Parse(value);
}
}
}
}
catch (Exception exception)
{
Logger.Write(exception);
}
}
protected void RestoreSearchCookie_Results(string cookieName)
{
try
{
HttpCookie cookieResults = Request.Cookies["StoredSearchResults_" + cookieName];
if (cookieResults != null)
{
string gridId = cookieResults.Values["GridId"];
string settings = cookieResults.Values["GridSettings"];
RadGrid grid = (RadGrid)FindControl(gridId);
GridSettingsPersister LoadPersister = new GridSettingsPersister(grid);
LoadPersister.LoadSettings(settings);
grid.Rebind();
}
}
catch (Exception exception)
{
Logger.Write(exception);
}
}
private void FindFormControls(List<Control> foundSofar, Control parent)
{
List<Type> types = new List<Type> { typeof(TextBox), typeof(DropDownList), typeof(RadioButton), typeof(CheckBox), typeof(HiddenField) };
foreach (Control control in parent.Controls)
{
if (types.Any(item => item == control.GetType()))
{
foundSofar.Add(control);
}
if (control.Controls.Count > 0)
{
this.FindFormControls(foundSofar, control); // Use recursion to find all descendants.
}
}
}

ASPxComboBox Filtering Large DataSet Using XpoDataSource (DevExpress)

I tried to Filter an ASPxComboBox that gets data using an XpoDataSource, note that restoring and filtering data from a small data set works fine , the issue start when I try to filter large dataset - about 70000 records- from datasource the ComboBox loading becomes very slow since XpoDataSource gets all data from database table .
So I created a criteria for the XpoDataSource to reduce number of records restored ,then the ComboBox Keeps repeating the top 10 records while scrolling down the ComboBox, I don't know where the problem is.
I realized that what I need is similar to the example in the following link
But using an XpoDataSource instead of SqlDataSource1 .
I don't know how to write a similar code for an XpoDataSource .
this is my code :
protected void cmbServices_OnItemRequestedByValue_SQL(object source, DevExpress.Web.ASPxEditors.ListEditItemRequestedByValueEventArgs e)
{
try
{
string criteria = "";
if (string.IsNullOrEmpty(e.Value.ToString()) || e.Value.ToString().Length < 3)
{
criteria = "1 = 2";
}
else
{
criteria =
string.Format("(( Code like '{0}%' OR ProductName like '{0}%') AND CustomerId = {1})", e.Value.ToString(), (cmbServicesActivities != null && cmbServicesActivities.Value != null) ? cmbServicesActivities.Value.ToString() : "0");
}
dsServices.Session = LookupsSession;
dsServices.Criteria = criteria;
cmbServicesDescription.DataSource = dsServices;
cmbServicesDescription.DataBind();
}
catch (Exception exc)
{
Debug.WriteLine(exc.Message);
}
}
The Following Example demonstrates the answer of my question
public partial class _Default : System.Web.UI.Page {
Session session = XpoHelper.GetNewSession();
protected void cmb_ItemRequestedByValue(object source, DevExpress.Web.ASPxEditors.ListEditItemRequestedByValueEventArgs e) {
MyObject obj = session.GetObjectByKey<MyObject>(e.Value);
if (obj != null) {
cmb.DataSource = new MyObject[] { obj };
cmb.DataBindItems();
}
}
protected void cmb_ItemsRequestedByFilterCondition(object source, DevExpress.Web.ASPxEditors.ListEditItemsRequestedByFilterConditionEventArgs e) {
XPCollection<MyObject> collection = new XPCollection<MyObject>(session);
collection.SkipReturnedObjects = e.BeginIndex;
collection.TopReturnedObjects = e.EndIndex - e.BeginIndex + 1;
collection.Criteria = new BinaryOperator("Title", String.Format("%{0}%", e.Filter), BinaryOperatorType.Like);
collection.Sorting.Add(new SortProperty("Oid", DevExpress.Xpo.DB.SortingDirection.Ascending));
cmb.DataSource = collection;
cmb.DataBindItems();
}

primary key violation if case sensitive

Suppose I've the 'dom' table which contains two fields
code
name
Code should be primary key. In case if I enter values('SD', 'domnic')
then again if I enter ('SD', 'domnic1')
in asp.net I've wrote validation so i can receive alert message.
protected void ButtonSave_Click(object sender, EventArgs e)
{
try
{
if (Mode == "Add")
{
primarykeyValidation();-------------->validation
if (strpkval == TextBoxWorkshopid.Text)
{
Alert.Show("code Already Exists");
TextBoxWorkshopid.Text = string.Empty;
TextBoxWorkshopid.Focus();
return;
}
}
...
public void primarykeyValidation()
{
DataSet dspkval = new DataSet();
try
{
objaccess.Option = "P";
objaccess.code= TextBoxWorkshopid.Text;
dspkval = objaccess.retriveOutsideWorkshops();
if (dspkval != null && dspkval.Tables.Count != 0 && dspkval.Tables[0].Rows.Count != 0)
{
strpkval = dspkval.Tables[0].Rows[0]["CODE"].ToString();
}
}
catch (System.Exception ex)
{
throw ex;
}
}
In case I enter('sd','domnic') it won't show the message just error thrown due to violation of primary key.
In "P" option I've wrote query as
select code from xxx where code=#code
so if i enter small case'sd' then i sholud receive alert message that "code aleady exits but it wouldnt show the
message........
1) Configure your database for case sensitivity. Known as collation. It does affect the entire database, though.
2) You can force a given query to have specific collation: http://web.archive.org/web/20080811231016/http://sqlserver2000.databases.aspfaq.com:80/how-can-i-make-my-sql-queries-case-sensitive.html.
3) You could modify the business logic so that all PK values are made upper case before being sent to the database in the first place. You'd have to do this for updates/inserts as well as queries though, so it could get messy (and be careful that your queries are still sargable i.e. don't put UPPER(#code) in your queries - actually modify the value before putting it in the parameter).

Resources