Posts

Showing posts from December, 2014

PDF from MVC Razor - with heading

Image
Today I was tasked with creating a PDF from a report that had two queries - a header section and detail section. After looking at all the viable options I was tempted by iTextSharp but was faced with the challenge of implementing it in razor.  I then came across this nifty dll written specifically for that purpose and it utilizes iTextSharp to do it. RazorPDF  was the answer.  Al Nyveldt did an excellent job with it and includes a github download with great samples.  The one challenge he didn't cover was my example of two queries to make a more comprehensive report. As shown in the example (screenshot of my pdf generated using this tool) I have header information as well as additional data laid out in a table. To accomplish this I created a ViewModel in my Data project with a simple class that incorporated two references.  One to the header data and one to the Zipcode detail.     public class Fran_Zip_ViewModel     {         public IEnumerable FranZip { get; set; }

#MakeItHappen

Microsoft is making New Years Resolutions come true.  Mine are so big that I am not sure how they could help but thought I would lay it out here for you. 2015 New Years Resolution To get out of debt enough that I can concentrate on bringing my ideas to fruition.  For years I have been making software for my employers while never seeming to have the time to develop my own ideas.  Over the years I have supported domains that I one day will have the time to work on. Some of my domains: ItsaBigDeal.com I envision a daily deal (similar to Woot) and a subscription site combined  If you don't know what a subscription site is - they are becoming a big deal (see mysubscriptionaddiction.com ) ReportMinder.com Wow software out there for daycares/elderly care centers has some deficiencies and I think I can build a better web/app based software UltimateSpaces.com Not sure what I want to do with this domain but it is a great domain. Some of the regionall

Case Statement within Linq

var numberText = ( from n in numbers where n > 0 select new { Number = n , Text = ( n == 1 ? "One" : n == 2 ? "Two" : n == 3 ? "Three" : "Unknown" ) } );

Single Value from Data Entity - not in entity collection

Example of a single computed value from database, not a declared entity type  private decimal getTuneupAmount(DateTime dateCompleted,int classid, int  id)         {        string sql = @"SELECT  (count(ow.orderworkid) * (select tuneupamount from mastertable)) as TuneupAmount";                         sql += " from tbl_o o ";                         sql += " join tbl_work ow on o.orderid=ow.orderid ";                         sql += " join _setup s on ow.taskcodenumber=s.TaskCodeNumber and s.typeid =2 ";                         sql += " WHERE   ow.soldbyid =" + id + "  and ow.solddate ='" + dateCompleted+ "' and o.classcodeid=" + classid + " ";                         sql += " group by soldbyid,ClassCodeID, ow.solddate";  var tuneamt = (_dbContextZ.Database.SqlQuery (sql).SingleOrDefault());                                 decimal retval = 0;             if (tuneamt != null)

Merging Data with LINQ

var terms = from t in HRSystemDB . Terminations select new { Month = t . TerminationDate . Month , Year = term1 . TerminationDate . Year , IsHire = false }; var hires = from emp in HRSystemDB . Persons . OfType < Employee >() select new { Month = emp . HireDate . Month , Year = emp . HireDate . Year IsHire = true }; // Now we can merge the two inputs into one var summary = terms . Concat ( hires ); // And group the data using month or year var res = from s in summary group s by new { s . Year , s . Month } into g select new { Period = g . Key , Hires = g . Count ( info => info . IsHire ), Terminations = g . Count ( info => ! info . IsHire ) }

C#, MVC Tips and Stuff

A list of things that I have found handy to know... Tip #1 Boolean Enum Comparison Not to return an enum value from say an abbreviation to a long string but just to determine if your value is a valid value in the enum list.  So you have your Enums declared in a base class or some other class something like this:  public enum MyCustomEnumGroup     {         ABC,         MQP,         RAD,         STY     } Then wherever you need  to check your string to see if the string you are passing in is in the Enum Group call it as shown below, this returns a boolean based on the match to the enumgroup.   if (Enum.IsDefined(typeof(MyCustomEnumGroup),mystringtopassin))

Wrapping my head around MVC - one page, two views

I am really loving MVC, only really immersed in it for a couple of months but it is all coming together for me lately.  The most difficult challenge I faced in the beginning was generating a mixed context view, by that I mean something more akin to a normal web page. Maybe some header information at top and a grid of data below.  At first it was really easy to get something like a customers orders in the grid but how to display another grid of customer address information on the same page.  So to accomplish this lets say that you have a class that has the orders info. Orders.cs customerid orderid balance description And you have a customer class Customers.cs customerid customername streetaddress Cust_ordersDTO .cs CustomerID orderid balance description CustomerName StreetAddress public List< Cust_orders > AddressList { get; set; } public List< Cust_orders > OrderList { get; set; } So you will need to make a new class that has all properties combined in

Booleans in Linq

Using a nullable Boolean (bool?) datatype in LINQ can cause some issues You can return those values by using the nullable operator as shown below   Transfer = e.Transfer ?? false This will return the value from e.Transfer and if the value is null will return False