Page 1 of 1
Custom menu and custom page
Posted: Wed May 26, 2021 8:35 pm
by gmandelli
Good afternoon,
what's the best way to add a custom menu entry and associate a custom page where we would like to add a combo for for selecting one option and let the user confirm with a button click that will execute a stored procedure on the attached database?
Many thank for your suggestion.
Best regards,
John
Re: Custom menu and custom page
Posted: Thu May 27, 2021 7:07 am
by MichaelG
You need to create your own custom file. Please refer help file topic "Custom Files" as a start.
Re: Custom menu and custom page
Posted: Thu Jun 10, 2021 4:49 am
by gmandelli
I did the custom file with select list and button.
How can i invoke the stored procedure then?
I think it is a common problem and there isn't a clear example in the help.
Thanks.
Re: Custom menu and custom page
Posted: Thu Jun 10, 2021 7:45 am
by MichaelG
You can just use the Razor codes in your custom page to handle the request. For example:
@{
var req = Get("req");
}
@if (req == "1") {
//... process form here
} else {
//... request form here
}
Re: Custom menu and custom page
Posted: Sun Jun 13, 2021 9:44 pm
by gmandelli
Sorry,
ow does this fit with having a select list and a button that needs to be used to call the stored procedure:
<form>
<div class="container">
<p>Please select Year:</p>
<div>
<select class="selectpicker show-tick">
<option>2021</option>
<option>2022</option>
<option>2023</option>
<option>2024</option>
<option>2025</option>
<option>2026</option>
<option>2027</option>
<option>2028</option>
<option>2029</option>
<option>2030</option>
<option>2031</option>
<option>2032</option>
<option>2033</option>
<option>2034</option>
<option>2035</option>
</select>
</div>
<br>
<span class="caret"></span>
<button type="button" id="btnYear" class="btn btn-info">Inizialize</button>
</div>
</form>
What's the syntax for calling the stored procedure? In the help there is only samplke for doing a select.
Regards,
John
Re: Custom menu and custom page
Posted: Mon Jun 14, 2021 7:50 am
by MichaelG
Re: Custom menu and custom page
Posted: Mon Jun 14, 2021 9:50 pm
by gmandelli
Hi,
when i try to implement as suggested i got following error:
The name 'GetStoredProcCommand' does not exist in the current context
Here it is my implementation:
@{
var selyear = string.Empty;
if (Request.HasFormContentType)
{
selyear = Request.Form["selyear"];
}
}
<div style="margin-top:30px;">
<form method="post">
<div>
<select name="selyear" class="selectpicker show-tick">
<option hidden selected>Please select year...</option>
<option>2021</option>
<option>2022</option>
<option>2023</option>
<option>2024</option>
<option>2025</option>
<option>2026</option>
<option>2027</option>
<option>2028</option>
<option>2029</option>
<option>2030</option>
<option>2031</option>
<option>2032</option>
<option>2033</option>
<option>2034</option>
<option>2035</option>
</select>
</div>
<div><input type="submit" /></div>
</form>
</div>
@if (!string.IsNullOrEmpty(selyear))
{
// var dbhelper = GetConnection("DB");
// var cmd = dbhelper.GetStoredProcCommand("sp_Tenant_InitYearCalendar");
var cmd = GetStoredProcCommand("sp_Tenant_InitYearCalendar");
cmd.Parameters.Add("Tenant", SqlDbType.Int).Value = 1;
cmd.Parameters.Add("YearNum", SqlDbType.Int).Value = selyear;
cmd.Parameters.Add("retval", SqlDbType.Int).Value = 0;
cmd.Open();
cmd.ExecuteNonQuery();
<p>You choose year: @selyear!</p>
}
What's wrong?
BR,
John
Re: Custom menu and custom page
Posted: Tue Jun 15, 2021 7:32 am
by MichaelG
Change GetStoredProcCommand to:
var cmd = Connection.GetCommand("...");
cmd.CommandType = CommandType.StoredProcedure;
//...
Re: Custom menu and custom page
Posted: Tue Jun 15, 2021 11:54 pm
by gmandelli
Hello,
I fixed the db connection using the dbhelper.
This is now a working set:
@{ var selyear = string.Empty;
if (Request.HasFormContentType)
{
selyear = Request.Form["selyear"];
} }
<div style="margin-top:30px;">
<form method="post">
<div>
<select name="selyear" class="selectpicker show-tick">
<option hidden selected>Please select year...</option>
<option>2021</option>
<option>2022</option>
<option>2023</option>
<option>2024</option>
<option>2025</option>
<option>2026</option>
<option>2027</option>
<option>2028</option>
<option>2029</option>
<option>2030</option>
<option>2031</option>
<option>2032</option>
<option>2033</option>
<option>2034</option>
<option>2035</option>
</select>
</div>
<div><input type="submit" /></div>
</form>
</div>
@if (!string.IsNullOrEmpty(selyear))
{
int iYear = 0;
if (int.TryParse(selyear, out iYear))
{
try
{
var dbhelper = GetConnection("DB");
var cmd = dbhelper.GetCommand("sp_Tenant_InitYearCalendar");
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("Tenant", MySqlDbType.Int32).Value = 1;
cmd.Parameters.Add("YearNum", MySqlDbType.VarChar).Value = selyear;
cmd.Parameters.Add("retval", MySqlDbType.Int32);
cmd.Parameters["retval"].Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
<p>Sucessfully added year: @selyear!</p>
}
catch (Exception ex)
{
<p>Problem adding year! @ex.Message</p>
}
}
}
I hope this could help someone else.
Many thanks for helping.
Best regards,
John
Re: Custom menu and custom page
Posted: Wed Apr 26, 2023 3:53 pm
by tonivabian
very usefull. this is what i'm looking for