Month: July 2016

SQL Server Dapper

Helper class to mitigate working with Dapper against SQL Server database Download demo Dapper 1.42.0 – 54 KB Download demo Dapper 1.50.2 – 545 KB Download demo Dapper 1.50.2 .NET Core – 41 KB Download SqlHelper (All versions) – 59 KB Introduction Dapper has emerged as one of the more powerful micro-ORMs out there. Its main focus is mapping database tables to POCOs (Plain Old CLR Objects) and it does that very quickly by all accounts. One of its strong points is its “genericness” to databases. Its inner implementation uses only DB interfaces such as IDbConnection, IDbCommand, IDbTransaction. There are no database-specific implementations (like SqlConnection which is SQL Server specific) so any data provider that implements these interfaces is good to go with Dapper. That strength can also be a bit of a weakness. Every database has its own little quirks and different ways of doing things and it’s usually up to the user to write these things beforehand. A good example of a database-specific thing is SQL Server Table Valued Parameter or TVP for short. There are also some more common tasks, when working with data providers, that you want to encapsulate into a helper class. All these reasons and more were my motivation to write this helper class, the ubiquitous SqlHelper, which is designed specifically to mitigate working with Dapper against SQL Server database. Connection String and...

Read More

Easy Backup and Restore MySQL database utility.

Easiest tool to backup and restore Mysql database from windows. Download DEMO – 200.8 KB Download MySQL_Backup_Restore.zip – 255.5 KB Introduction It is the basic, easy to use MySQL database Backup/Restore utility. Background It is basically developed for non programmers. So, anyone can use it. The simplest tool for the job. Using the code Backup method takes two arguments, i.e, path to save the backup file and connection string. //  Backup MySql database private void MySQLBackup(string path, string constring){    string file = path + txt_database.Text + “_” + DateTime.Now.ToString(“yyyy-MM-dd_hh-mm-ss”) + “.sql”;    using (MySqlConnection conn = new MySqlConnection(constring))    {       using (MySqlCommand cmd = new MySqlCommand())       {          using (MySqlBackup mb = new MySqlBackup(cmd))          {             cmd.Connection = conn;             conn.Open();             mb.ExportToFile(file);             conn.Close();          }       }    }} Now to the restore method with the same two arguments // Restore MySQL(.sql) file to the databaseprivate void RestoreSQL(string file, string constring){   using (MySqlConnection conn = new MySqlConnection(constring))   {      using (MySqlCommand cmd = new MySqlCommand())      {         using (MySqlBackup mb = new MySqlBackup(cmd))         {            cmd.Connection = conn;            conn.Open();            mb.ImportFromFile(file);            conn.Close();         }      }  ...

Read More

High-performance finite elements with C#

Igor Gribanov Performing linear static analysis on a tetrahedral mesh with a little bit of help from a third-party solver. Introduction Open-source finite element (FE) codes are usually written in C++ and come as large libraries with thick user manuals. It is not surprising, because FE computations are complex and require high performance. Managed code was not intended to compete in performance with C, so languages like C# would be unlikely candidates for scientific computation. But is this the case with finite elements? FE formulations exist for various models in thermodynamics, electromagnetism, continuum mechanics and other areas of physics. Most often they assemble and solve a linear system of equations K~u~=f~ , either once or multiple times. This step is the most computationally expensive, since the matrix K~ is usually quite large. Solving a linear system is an algorithmic problem, which has little to do with finite elements, so this taks is usually delegated to a separate algorithm. Therefore, the Finite Element code itself can be written in C#, making use of the managed collections and LINQ query operations with minimal memory fragmentation. This article describes an implementation of an established technique in solid mechanics – linear static analysis. When external loads are applied to a deformable object, they create internal stresses and strains in the material, resulting in reaction forces and in deformation of the object. Static analysis...

Read More

ASP.NET Don’ts and Dos

Vincent Maverick Durano This post highlights the Dos and the Don’ts in general regarding ASP.NET. Introduction Some folks may keep falling into a trap and are unaware of what they are doing. This post highlights the Dos and the Don’ts in general regarding ASP.NET. The majority of the items listed are taken from the ASP.NET team recommendations. Though this may not be a complete checklist, it covers some of the most common “gotchas” folks run into. If you know other tips about the Dos and Don’ts in ASP.NET in general, feel free to drop a comment so I can update the list. Control Adapters If some of you are still using Control Adapters, especially those WebForms folks – you should avoid it, as much as possible. Avoid: Control Adapters, as these were created to support mobile controls rendering different markups for different devices. Prefer: CSS media queries, responsive design and mobile specific views. Style Properties on Controls Try to Avoid: The four thousand specific control style properties, e.g. EditItemTemplate-AlternateItem-Font-ForeColor-SomeStyle-Blah-Blah :S Using inline CSS styles, e.g. style=“color:yellow;text-align:center;” Prefer: CSS stylesheets. You can roll your own or use Bootstrap or a combination of your own CSS. JavaScript Frameworks and AjaxControlToolkit Try to Avoid: Mixing your jQuery code, or other JS frameworks code with WebForm’s AjaxControlToolkit controls to avoid functionality issues. Prefer: Stick to the specific control libraries. UpdatePanel Control Do Not:...

Read More

Simple Form Submission With Bootstrap Modal – ASP.NET WebForm

SagSD Adding dropdown item using bootstrap modal window and Ajax in ASP.NET webform and postioning the modal window Download source code – 9 MB Introduction This is a small project where we submit a form in a bootstrap modal window using update panel Ajax and close it. Code Add a Webform project with .NET 4.5.2. By default, Bootstrap template is created with bootstrap CSS and bootstrap JS files. Let us consider a situation where we add a category from a bootstrap modal to a dropdown. Create a Modal Window at the bottom of aspx page. <div class=”modal   ” id=”sample_modal” role=”dialog” tabindex=”-1″ ><div class=”modal-dialog “><div class=” modal-content”><div class=”modal-header”>Modal Heading</div><div class=”modal-body col-sm-12″><div class=”form-group “><label class=”col-sm-4 control-label”>New Category</label><div class=”col-sm-8″><asp:TextBox ID=”txtCat”  CssClass=”form-control”  runat=”server” ></asp:TextBox><asp:RequiredFieldValidator ID=”rfv1″ CssClass=”alert-danger” ControlToValidate=”txtCat” ValidationGroup=”save-modal” SetFocusOnError=”true” Display=”Dynamic” runat=”server” ErrorMessage=”Please Enter category!!!”></asp:RequiredFieldValidator></div></div></div><div class=”modal-footer”><asp:Button ID=”btn_save”  runat=”server” CssClass=”btn btn-primary” Text=”Add” OnClick=”btn_save_Click” ValidationGroup=”save-modal”   /><button type=”button” class=”btn btn-default pull-right” data-dismiss=”modal”>Close</button></div></div></div></div> Add Update panel to implement Ajax with bootstrap modal. Modal will look like below: <div class=”modal   ” id=”sample_modal” role=”dialog” tabindex=”-1″ ><div class=”modal-dialog “><asp:UpdatePanel ID=”UpdatePanel2″ runat=”server” EnableViewState=”true”><ContentTemplate><div class=” modal-content”><div class=”modal-header”>Modal Heading</div><div class=”modal-body col-sm-12″><div class=”form-group “><label class=”col-sm-4 control-label”>New Category</label><div class=”col-sm-8″> <asp:TextBox ID=”txtCat”  CssClass=”form-control”  runat=”server” ></asp:TextBox><asp:RequiredFieldValidator ID=”rfv1″ CssClass=”alert-danger” ControlToValidate=”txtCat” ValidationGroup=”save-modal” SetFocusOnError=”true” Display=”Dynamic” runat=”server” ErrorMessage=”Please Enter category!!!”></asp:RequiredFieldValidator></div></div></div><div class=”modal-footer”><asp:Button ID=”btn_save”  runat=”server” CssClass=”btn btn-primary” Text=”Add” OnClick=”btn_save_Click” ValidationGroup=”save-modal”   /><button type=”button” class=”btn btn-default pull-right” data-dismiss=”modal”>Close</button></div></div></ContentTemplate></asp:UpdatePanel></div></div> Write a function to handle server side click event of save button. Something like below: protected void btn_save_Click(object...

Read More