My Latest Portfolio

My latest projects are :

  1. e-Procurement System For Sun Life Insurance
    Technology : .Net Core 7 (backend), MudBlazor (front end), SQL Server
    Role : Team member, developing backend, frontend and Store Procedure
  2. Brains (Hotel Rsv System)
    Technology : .Net Core 6, WiseJ, DevExpress, Reactive IO, SQL Server
    Role : Team member developing backend
  3. Employee Self Service System for United Tractors TBK
    Technology : .Net MVC 4.6, Hangfire, Razor View, SQL Server
    Role : Team lead, developing backend, frontend, and all aspect of Database
  4. Management System for Managed Pressure Operation, LLC
    Technology : PHP Code Igniter, Mysql
    Role : System Analyst, Programmer, IT Recruiter
  5. User Manual Blog for Management System for Managed Pressure Operation, LLC
    Technology : PHP wordpress, Mysql
    Role : Technical writer
  6. Corporate Website for Telkomsel
    Technology : PHP, Code Igniter, MySql
    Role : Team member, developing front end
  7. Proof Of Delivery System for Sicepat Express
    Technology : .Net Core 4.8, SQL Server
    Role : Team member, developing backend
  8. ETL System for Sicepat Express
    Technology : Highchart, D3.js, PostgreSQL
    Role : The only developer
  9. etc

How to Use Gmail for SMTP (Free or Business Account)

Here how to use Gmail server to send email from your app.

First, make a gmail account.
You don’t have to use “Google Workspace”. Free account also can use this feature.
Login to your gmail account.

Then open your account setting by click “manage your google account” menu from or open link “https://myaccount.google.com/

Open “security” on menu on left side.
Then activate 2-step verification.

If 2FA has been activated, link for “App Password” will be shown.
Create a new “app password”.

If 2FA has been activated before, then type “app passwords” on search bar.
When you found it, then you can create a new app password.

Now you can use your it on your gmail for SMTP.
Use your gmail email address as user name and app password as password.


Fix Cannot Access Localhost Due to auto redirect to HTTPS

Problem
Your localhost might suddenly stop working because it automatically goes to https instead of http.

Why this happen
As of 2020, Chrome automatically redirects all HTTP URLs to HTTPS.
And also it will auto-redirect again after chrome update, so better you remember how to solve it in hand.

Solution
On chrome, open “chrome://net-internals/#hsts” to change your hsts setting
Enter “localhost” (without quotes) in the box underneath “delete domain security policies

Improve App Performance with Output Caching

We can dramatically improve our ASP.NET MVC web application performance by taking advantage of output caching.

This feature save content from a controller action to a cache, to be use again when the same controller action is invoked.
For example, result from DB query can be use again thus decreasing DB access.

using System.Web.Mvc;
namespace MvcApplication1.Controllers
{
[HandleError]
public class HomeController : Controller
{
//Cache 10 second, server cache (all user will get same result)
[OutputCache(Duration=10, VaryByParam="none")]
public ActionResult Index()
{
Employee model = db.GetEmployee();
return View();
}

//Cache 1 day, browser cache (all user will get different result)
[OutputCache(Duration=3600, VaryByParam="none", Location=OutputCacheLocation.Client, NoStore=true)]
public string GetName()
{
return "Hi " + User.Identity.Name;
}

//Cache by param id : if id not same then read to DB
[OutputCache(Duration = int.MaxValue, VaryByParam = "id")]
public ActionResult Details(int id)
{
ViewData.Model = _dataContext.Movies.SingleOrDefault(m => m.Id == id);
return View();
}
}
}

Read more about Output Caching in here

SQL Server : Sample Upsert With Data Selected From Other Table – Good For Making Summary



Description
When summarizing data, will be better if we can jump directly to Database with pure SQL server query

Here my sample

DECLARE @NRP VARCHAR(50) = 'Test123';
DECLARE @YearPeriod INT = 2021;
DECLARE @TotalEarn INT = (SELECT ISNULL(SUM(PointValue),0) from DynamicRewardStarGazeItem WHERE NRP=@NRP AND YearPeriod=@YearPeriod AND IsEarned=1);
DECLARE @TotalUnEarn INT = (SELECT ISNULL(SUM(PointValue),0) from DynamicRewardStarGazeItem WHERE NRP=@NRP AND YearPeriod=@YearPeriod AND IsEarned=0)
DECLARE @Total INT = @TotalEarn-@TotalUnEarn                       

 UPDATE [EmployeeSummary] SET TotalPoint=@Total ,[UpdateBy]='{NRPApprover}'
                           ,[UpdateDate]=GETDATE() WHERE NRP=@NRP AND YearPeriod=@YearPeriod;
                    IF @@ROWCOUNT = 0
                    BEGIN
                    INSERT INTO [dbo].[EmployeeSummary]
                           ([NRP]
                           ,[YearPeriod]
                           ,[TotalPoint]
                           )
                     VALUES
                           (@NRP
                           ,@YearPeriod
                           ,@Total
                           );
                    END

Windows 11 : Fix Problem With 2nd Monitor

Problem Description
– input signal out of range

– Detect other display ‘didn’t find any another display’

– Extend these display failed with error message “Input signal out of range”

Why You Encounter The problem
– Second monitor having max resolution lower to you screen
Eg : Your first display is FHD (1920×1080 pixel) while your second monitor is only HD (1386×768 pixels)

How to fix it?
What you need to do is to set the second monitor on correct resolution.

Steps are
1. Select “Extend these display “

2. Go to “Advanced Display”

3. Select the second monitor

4. Click “Display Advanced properties For Display 2”

5. Click on list all modes : select a resolution that your second monitor can handle

Select a resolution that your second monitor can handle


6. All done
Your monitor should working now.
Else select lower resolution from what you select now

Using Sweet alert to display a div content

Sweet alert 2 (SWAL) is an interesting js addons for displaying popup.

But by default you cannot instruct SWAL to display a div.
What you can do is to put HTML tag inside a SWAL call.

Using jquery html() method you could get html content of any element.
So then you could use jquery html() to import then show it using SWAL.

Further more, you could use bootstrap call “modal fade” to hide the popup content by default.

Here my sample :

<i class="fa fa-globe fa-2x" onclick="showModal('@PopupDivID');"></i>
<div class="modal fade">
                                <div id="@PopupDivID">
                                    <table style="width:100%">
                                        <tr>
                                            <td>
                                                <iframe id="Map" height="200" frameborder="0" style="border:0; width:95%; padding: 8px;"
                                                        src="https://www.google.com/maps/embed/v1/place?key=@ViewBag.Key&q=@itemz.Lattitude,@itemz.Longitude" allowfullscreen>
                                                </iframe>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                            </div>

<script src="/~/Content/Libs/jqueryAlert/sweetalert2.all.min.js"/>
<script type="text/javascript">
    function showModal(name) {
        var Val = $("#" + name).html();
        Swal.fire({
            title: 'Pop info',
            html:Val,
            icon: 'info',
                showCancelButton: false,
                showCloseButton: true,
                showConfirmButton: false
        })
    }
</script>

Let me know if you need more explanation.

Simple Guide For SQL Server Trigger

Hi,
Lets make a trigger

What is SQL Server Trigger?
Trigger is a feature of SQL Server that able to make action (either insert or update or delete) in event of insert or update in a table.

My simple guide..

Lets dive to a very simple sample..

CREATE TRIGGER [dbo].[TriggerName] on [dbo].[TableName]
AFTER UPDATE --comment : if for insert => AFTER INSERT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON; 

DECLARE @param1Name     AS VARCHAR(8)
DECLARE @Param2Name     AS VARCHAR(500) 

SELECT  @Param1Name    = INSERTED.FieldName1,
        @Param2Name    = INSERTED.FieldName2
FROM INSERTED --comment: do not attemp to change this from 

IF UPDATE(FieldName1) --if FieldName1 is included in value that being changed
--If Trigger insert : IF INSERT(FieldName1) 
BEGIN 
            INSERT dbo.TableNameDestination
            ([DestinationField1],[DestinationField2])
            VALUES (@Param1Name, @Param2Name) 

END

END --end all

SQL Server – Add Table If Not Exist

Some approach is possible (like do a query to retrive a row from the table that wanted to be create), but the best is to check to INFORMATION_SCHEMA.TABLES as it is the authority for database structure.

Example :

IF (EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ‘dbo’ AND TABLE_NAME = ‘tblMyTable’))
BEGIN
CREATE TABLE [dbo].[tblMyTable]
(
[MYTABLE_ID] uniqueidentifier NOT NULL PRIMARY KEY,
[MYTABLE_ID_FIELDNAME] NVARCHAR(32) NOT NULL,
[__CREATE_TS] DATETIME NOT NULL DEFAULT (getutcdate()),
[__LAST_UPDATE_TS] DATETIME NULL
)
END