Tuesday, April 9, 2019

Calculate relative time in C#

const int SECOND = 1;
const int MINUTE = 60 * SECOND;
const int HOUR = 60 * MINUTE;
const int DAY = 24 * HOUR;
const int MONTH = 30 * DAY;

var ts = new TimeSpan(DateTime.UtcNow.Ticks - yourDate.Ticks);
double delta = Math.Abs(ts.TotalSeconds);

if (delta < 1 * MINUTE)
  return ts.Seconds == 1 ? "one second ago" : ts.Seconds + " seconds ago";

if (delta < 2 * MINUTE)
  return "a minute ago";

if (delta < 45 * MINUTE)
  return ts.Minutes + " minutes ago";

if (delta < 90 * MINUTE)
  return "an hour ago";

if (delta < 24 * HOUR)
  return ts.Hours + " hours ago";

if (delta < 48 * HOUR)
  return "yesterday";

if (delta < 30 * DAY)
  return ts.Days + " days ago";

if (delta < 12 * MONTH)
{
  int months = Convert.ToInt32(Math.Floor((double)ts.Days / 30));
  return months <= 1 ? "one month ago" : months + " months ago";
}
else
{
  int years = Convert.ToInt32(Math.Floor((double)ts.Days / 365));
  return years <= 1 ? "one year ago" : years + " years ago";
}

Source : https://stackoverflow.com/questions/11/calculate-relative-time-in-c-sharp?page=1&tab=active#tab-top

Wednesday, April 3, 2019

SSRS : Setting up a A4 page in Reporting Services

สรุป วิธีการตั้งค่าหน้ากระดาษเพื่อเวลา print แล้วไม่ขึ้นหน้าใหม่เป็น Blank 

1. Report => Report properties => Paper size A4 => width 21 cm
2. เอาขนาด  width ลบ ออก ด้วย margin ซ้ายขวา  21 - 1.5- 1.5 = 18
3. เอาค่าที่ได้ไปใส่ใน Body(คลิกพื้นที่ขาวด้านข้างทางขวา จะโชว์ Body properties) => width

Hi,

I'm always a bit rusty when i start building reports in Reporting Services after a while. One thing i always has to figure out is how to set up the page size, body and margins. In a article on Microsoft you can find more information about this subjct. You can set the properties in the properties window or you can set the properties with report properties window (Menu -> Report -> Report properties). The relation between page, body, header and footer looks conceptual like the diagam below.


Below you can see how i manually set the page size of the report with A4 paper settings.


And don't forget to set the body properties:


The formula of setting the PageSize Width, bodysize and margins is this: Page Width = Body Width+ Left margin + Right Margin. In my case 21= 19+1+1.

In case of the height of the report you need to set the pagesize. In case of A4 : 29,7cm. In case of the body height you can set whatever you wan't. By setting the PageSize Height property the height of A4 is maintained and when the body height is larger than the pageSize (minus top margin and bottom margin) more pages are displayed/printed.

It's also possible to set the properties with the report properties window. Below you can see an example in inches.



We end up with the follow values for the proprties:








Thursday, January 31, 2019

Datasets pane in Visual Studio for SSRS report

If anyone is interested: Ctrl+Alt+D combo helped me.

In Visual Studio 2013 running SSDTBI for VS 2013 the option has moved to the "View" menu, and confusingly it only shows if an actual report has focus. So click somewhere in your report, and thenclick "View"
enter image description here
Or as stated by others Ctrl+Alt+d still works, though only if you have a report focussed.