Posted by Michael Horvath under Technology  .Net MVC  on Apr 10 2020

Our main site includes a Buy page that allows our customers to purchase activation keys for the Windows Desktop applications they've downloaded from our site. This Buy page was originally fragmented in design that is there were more than one forms on the view page. These were causing a headache with keeping the data on the different forms persisting when interacting on the other forms. A friend of mine gave me advice that I should make these separate forms into one form and use different actions in my controller for the page to handle the various control inputs like button clicks, etc. It turned out to be great advice. This page now works great with none of the strange quirks that I had spent quite a bit of time trying to eliminate.

I have included the source code from my view page here to show how the view is implemented. The controller code is much like any controller code for a view and is not included in this post, but should anyone have any questions about that feel free to contact me. Here is a snippet from one of the controller actions though that show how this action is decorated to make the view work with the controller action.

...
        [HttpPost]
        [ValidateAntiForgeryToken]
        [MultipleButton(Name = "action", Argument = "BuySearch")]
        public ActionResult BuySearch([Bind(Include = "ID,Price")] tblPRESSInventory tblPRESSInventory, string sortOrder, string currentFilter, string searchString, string clearSearch, int? page, string currentEmail, string customerID, int productID = 1)
        {
            ViewBag.CurrentSort = sortOrder;
            ViewBag.ProductID = productID;
            ViewBag.CurrentProductID = productID.ToString();
            ViewBag.CustomerID = customerID;

            bool alreadyPaid = false;

            var tempProduct = db2.tblPRESSInventories.Find(productID);
 ...
            return View(items.ToPagedList(pageNumber, pageSize));
        }
 ...

Also needed to make the MultipleButton decoration work is this class definition.

...
    [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
    public class MultipleButtonAttribute : ActionNameSelectorAttribute
    {
        public string Name { get; set; }
        public string Argument { get; set; }

        public override bool IsValidName(ControllerContext controllerContext, string actionName, MethodInfo methodInfo)
        {
            var isValidName = false;
            var keyValue = string.Format("{0}:{1}", Name, Argument);
            var value = controllerContext.Controller.ValueProvider.GetValue(keyValue);

            if (value != null)
            {
                controllerContext.Controller.ControllerContext.RouteData.Values[Name] = Argument;
                isValidName = true;
            }

            return isValidName;
        }
    }
...
    

Here's the view code, note that this is used as a partial view in a couple of other views so that code does not have to duplicate the page. Those views correspond to the actions like the example above the BuySearch action. Anyway here's the complete view code. Note that the file extension was changed to add a .txt to end of filename so that you can download this file. Not sure how to grant permission for you to download the file with its correct file extension.

Buy.cshtml

The last touch on the view page is the paged list pager controls displayed below the table of inventory items. This makes use of the PagedListRenderOptions to make the links in the pager control trigger post to the controller. That turned out to be fairly straightforward to implement once I knew where to look for help.

...
            @Html.PagedListPager(Model, page => Url.Action("Buy",
    new { page }), new PagedListRenderOptions { FunctionToTransformEachPageLink = (liTag, aTag) => { aTag.Attributes.Remove("href"); aTag.Attributes.Add("href", "javascript:void(0);"); aTag.Attributes.Add("onclick","updatePage('" + aTag.InnerHtml + "'," + Model.PageCount + ");"); liTag.InnerHtml = aTag.ToString(); return liTag; } })
...

I hope this helps someone who is having similar problems in implementing a form with multiple buttons that need post event handlers.

Thanks for reading and have a blessed day!

Tagged MVC Views 
Posted by Michael Horvath under Technology  SQL Server  on Mar 05 2020

We recently had the need for a string split function on our SQL Server 2014 database server, but found that there is not a built in function for that version of SQL Server.  So we researched it a little and found a function definiton that mostly suited our requirements.  We took the liberty of making changes that meet our requirements.  (We wanted a StringSplit function that works in a similar fashion to the C# string.Split function.  We modified the function downloaded from internet website contained in the comments of our script definition to also return empty strings in the 'array' (really a table, but SQL Server 2014 does not support indexable array as best as we can tell).)

While testing our version of the StringSplit function we found a need for a StringFormat function that makes use of StringSplit.  Anyway long story short, we implemented a StringFormat function.

Use the following links to download the function create scripts and feel free to make any modifications you see fit for your purposes.

Note: the QueryToCreateStringFormat_3Function.sql file is one of ten versions of function wrappers to allow for different numbers of parameters from your calling script.  The pattern is that the underscore number value indicates how many parameters to pass into this function _3 indicates that three parameters other than the FormatSpecifierString are passed into the function.  It is fairly easy to create the other nine versions of the function starting with this function.

Thanks for reading our post and we hope these functions can be of use to you!

QueryToCreateSplitStringsFunction.sql

QueryToCreateStringFormatFunction.sql

QueryToCreateStringFormat_3Function.sql



Tagged SQL Server 
Posted by Michael Horvath under Technology  .Net MVC  on Feb 27 2020

We've been working on updates to the sBlog.Net engine.  Changes are being made to the v3.0 git hub version that was downloaded and built/ deployed to our server.  We have added a new setting to the database backend that controls the number of years included in the archives panel of the sidebar.  The archives panel was also updated to display the month/year combinations in three columns instead of one so that this panel takes up less vertical screen space. We also have added a web.config setting to allow for emails to be sent to admin under certain conditions such as exception logging and user requests for login accounts.  The email handler was updated to work with our admin's smtp mail server.  A few changes to the styles to make the Bootswatch Slate theme consistent for authors page and comments.  A few patches to handle paging a little bit better when a user is on a blog page other than page one and they click the link for blog authors and the blog pages paging logic was inverted to make the next page increment to next higher page number and previous page to decrement to the next lower page number.

We also added a site icon which was setup with our logo.  Once our changes that are not specific to Horvath Software Solutions instance of sBlog.Net have been proven to work correctly and are in keeping with the design of orginal developer of sBlog.Net, we may publish our changes to the git hub repository.

Thanks for reading our post!

Tagged Blog Engine  .Net MVC 
Posted by Michael Horvath under Technology  on Feb 19 2020

Within your post paste the following html. Note: the id of the video element has been changed in the snippet because the snippet is valid html and we had two elements with the same id so our player control buttons ceased functioning properly. Live and learn! Thanks for your patience while this was broken!

...

...

 


About this movie... this movie was produced from video clips taken using my iPhone of first the water fall at Lake Catherine, Arkansas and second clip the water fall at the Seven Hollows Grotto Petit Jean State Park, Arkansas using the iMovie application on a Mac OS computer.

Update from August 8, 2020... added clip from Louisiana Purchase State Park in Arkansas.

To play this movie right click the thumbnail and select show controls. Then press play on the controls. Otherwise use these buttons.

Tagged Audio/Video 
Posted by Michael Horvath under Technology  on Feb 16 2020

This post is a first for me with an image file embedded in the post.

The following is a photo taken at Lake DeGray in Arkansas:

Sunrise Photo Over Lake DeGray in Arkansas

 

Tagged --no tags--

<< Previous Page
Next Page >>