2016年3月30日 星期三

[問卷調查] 我愛小寶貝 I love my baby

請家裡有小朋友的爸爸媽媽協助填寫一下小弟的問卷! 謝謝您!



建立您自己的使用者意見反應調查問卷

2016年3月29日 星期二

[AngularJS] Angular-Http-Loader sample

 AngularJS   angular-http-loader  



▌Background


I was looking for a solution for showing Loading-element after sending Http request and before receiving Http response.

Then I found angular-http-loader (by wongatech), which is an easy-to-use directive.
The document and demo on his blog is clear, so I will make a quick go-thru here.

Environment

l   Visual Studio 2015 Ent.
l   AngularJS 1.4.8



Implement



Install angular-http-loader

Use bower to install it.

bower install --save angular-http-loader




Javascript

Include angular-http-loader.min.js into the web page. Then open the javascript to use it.

var app =
angular.module('app', ['ng.httpLoader'])
.config([
        'httpMethodInterceptorProvider',
        function (httpMethodInterceptorProvider) {
            httpMethodInterceptorProvider.whitelistDomain("http://localhost:12340/");
            //httpMethodInterceptorProvider.whitelistLocalRequests();

        }
])
.controller('CustomerIndexCtrl', function ($scope, $http, $q) {
    //TODO : Implement the http methods…
});

httpMethodInterceptorProvider.whitelistDomain("http://localhost:12340/")  :
===>  Add remote web server to the white list.

httpMethodInterceptorProvider.whitelistLocalRequests()
===>  Add local server to the white list.




Html

Put a div with the following directives:

1.  ng-http-loader

For all requests :
<div class="Loading" ng-http-loader template="XXX.html"></div>

Only Http GET :
<div class="Loading" ng-http-loader methods="GET" template="XXX.html"></div>

Http GET and POST
<div class="Loading" ng-http-loader methods="['GET','POST']" template="XXX.html"></div>


2.  ttl
Set the minimum time (seconds) for displaying the loading element.

3.  template
The loading element.

4.  title
Put a title on the template.


<script src="~/bower_components/angular-http-loader/app/package/js/angular-http-loader.min.js"></script>

<div ng-app="app" ng-controller="CustomerIndexCtrl">
    <div class="Loading" ng-http-loader methods="GET" ttl="5" title="Loading..." template="~/Html/Loading.html"></div>
    <!—TODO : Implement the html content here -->
</div>



Template Html

<span>{{title}}</span>
<img src="../Content/images/gif/ajax-loader.gif" />

PS. You can generate a loading GIF on ajaxload!


Result



Reference


2016年3月23日 星期三

[TFS] Query database

 ALM   Team Foundation Server  




環境

l   Team Foundation Server 2013 Update 5
l   SQL SERVER Management Studio  2012


How to query the TFS database



重點在於以下幾個表格 (位於 TFS_XXXXCollection 資料庫)

Table Name
描述
Fields
欄位明細表
WorkItemsAre
Work Item 的屬性
WorkItemsLatest
Work Item 的最後屬性
WorkItemsWere
Work Item 的歷史紀錄
WorkItemsLatestUsed
Work Item 修改的最後紀錄


Sample SQL : 查詢工作最新資訊

WorkItemsAre,WorkItemsLatest, WorkItemsWere 存放的屬性,除了基本欄位,其他幾乎都是以Fld序號表示的欄位名稱, 所以必須要到Fields去查詢工作屬性對應的Fld序號


SELECT ColName, NAME, ReferenceName FROM FIELDS
WHERE NAME = '專業領域'
--AND ReferenceName LIKE '%XXX%'

SELECT TOP 5 ID, Fld10019 FROM WorkItemsLatest
WHERE Fld10019 IS NOT NULL



查詢結果:






Sample SQL : 查詢工作歷史資訊

SELECT ColName,Name,ReferenceName from Fields
where NAME='變更日期'
GO

SELECT [Id],[Title],[Changed Date],[State]
FROM [Tfs_MISCollection].[dbo].[WorkItemsWere]
where Id=36390
GO







Sample SQL : AD帳號

如果要查詢AD帳號和對應 TFS儲存的PersonId

select DISTINCT [System.PersonId] AS TfsId,[System.AuthorizedAs] AS AdId from WorkItemsLatestUsed




2016年3月16日 星期三

[Sql Server] Avoid using ntext , text, and image data types


From MSDN

ntext , text, and image data types will be removed in a future version of Microsoft SQL Server. Avoid using these data types in new development work, and plan to modify applications that currently use them. Use nvarchar(max), varchar(max), and varbinary(max) instead.




[Visual Studio] Create DbContext from ERD

 Visual Studio    Entity Framework   ERD



Introduction


There are many tools for designing ERD. However, most of them are not free for personal use. Besides, how to transfer the ERD models to the real POCOs in our programming environment is another potential point.

So, using the Visual Studio to create ERD is one of the best practices. You can get the free version and it definitely has high integration on your design and development with Entity Framework.



Environment

l   Visual Studio 2015 Ent.



Lets start it!


ERD

Create a new project and add “ADO.NET Entity Data Model (EDM)” to our new project.







Now you can design the ERD!

 


POCO

Right click on the design tool and select “Add Code Generation Item” to generate POCO classes from the ERD.

 




Reference



2016年3月15日 星期二

[Trouble Shooting] 開發SSIS封裝的限制

今天再度遇到了相容性的問題 ~~!


使用Visual Studio 2015開發的SSIS 封裝,無法正常在Sql Server 2012Integration Service上執行;


參考以下文章:


採取最快的解決方式,以舊版Visual Studio 2012Integration Service專案範本重新建立封裝,即可順利執行。 幸好還留著 Visual Studio 2012 ...

2016年3月9日 星期三

[MVC] Upload file template

 Upload File    MVC





Introduction


This article will introduce how to implement Upload file function with MVC and System.Web.HttpPostedFileBase.


Related article


Environment

l   Visual Studio 2015 Ent.



Implement


ViewModel

public class VmFile
    {
        public string FileName { get; set; }
        public HttpPostedFileBase FileBase { get; set; }
    }

public class VmDownloadFile
    {
        public string FileName { get; set; }
        public string Uri { get; set; }
    }


View

l   Upload

@model JB.Sample.FileUpload.Website.Models.VmFile

@using (Html.BeginForm("Index", "File", System.Web.Mvc.FormMethod.Post, new { enctype = "multipart/form-data" }))
{
     <input type="file" id="FileBase" name="FileBase" style="margin-top:5px;">
     <input type="submit" value="Upload" class="btn btn-default" />
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}


這邊的重點在於HTML file input的名稱必須和View Modelproperty name 相同, 這樣在POST才會正確rendorView Model


l   Query and download

@model IEnumerable<JB.Sample.FileUpload.Website.Models.VmDownloadFile>
@foreach (var item in Model)
{
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.FileName)
        </td>
        <td>
            @{
                string applicationUri = Url.Content(string.Concat("~/Upload/", item.FileName));
            }
            <a href="@applicationUri">
                <img style="width:15px;height:15px" src="~/Content/Images/file.jpg" />
            </a>
        </td>
    </tr>
}

</table>



Controller


l   Upload action

private static string SAVED_FILES_PATH = "~/Upload/";

// GET: File/Create
 [HttpPost]
public ActionResult Index(VmUploadFile viewModel)
{
            //Validations
            if (!this.validateViewModel())
            {
                return View(viewModel);
            }

            string fileExtension = string.Empty;
            int maxContentLength = 1024 * 1024 * 10; //max bit = 10 MB
            string[] allowedFileExtensions = new string[] { ".pdf" }; //File extensions contraints

            if (viewModel.FileBase != null)
            {
                if (viewModel.FileBase.ContentLength > 0)
                {
                    #region Validation

                    fileExtension = System.IO.Path.GetExtension(viewModel.FileBase.FileName);
                    if (!allowedFileExtensions.Contains(fileExtension))
                    {
                        ModelState.AddModelError("DownloadFilesError", "檔案類型不符合規定,允許上傳的格式: " + string.Join(", ", allowedFileExtensions));
                        return View(viewModel);
                    }
                    else if (viewModel.FileBase.ContentLength > maxContentLength)
                    {
                        ModelState.AddModelError("DownloadFilesError", "檔案大小超過限制,檔案大小限制為: " + (maxContentLength / 1024 / 1024) + " MB");
                        return View(viewModel);
                    }

                    #endregion

                    #region Rename (Not neccessary)

                    if (string.IsNullOrEmpty(viewModel.FileName))
                    {
                        Guid id = Guid.NewGuid();
                        viewModel.FileName = $"{id}_{DateTime.Now.ToString("yyyyMMdd")}{fileExtension}";
                    }

                    #endregion

                    #region The callback of duplicated file name - Delete it.

                    string fullPath = Request.MapPath(SAVED_FILES_PATH + viewModel.FileName);
                    if (System.IO.File.Exists(fullPath))
                    {
                        System.IO.File.Delete(fullPath);
                    }

                    #endregion

                    #region Save it to the server side

                    var physicalPath = Path.Combine(Server.MapPath("~/Upload/"), viewModel.FileName);
                    viewModel.FileBase.SaveAs(physicalPath);

                    #endregion
                }
            }

            return RedirectToAction("Download");
}



l   Download action

public ActionResult Download()
{
            #region Get all downloadabled files on server
            var downloadFiles = getAllFiles();
            #endregion

            return View(downloadFiles);
}



private IEnumerable<VmDownloadFile> getAllFiles()
{
            List<VmDownloadFile> downloadFiles = new List<VmDownloadFile>();
            string filepath = Server.MapPath(SAVED_FILES_PATH);
            DirectoryInfo d = new DirectoryInfo(filepath);

            foreach (var file in d.GetFiles("*.pdf"))
            {
                downloadFiles.Add(new VmDownloadFile()
                {
                    FileName = file.Name,
                    Uri = Path.Combine(SAVED_FILES_PATH, file.Name)
                });
            }

            return downloadFiles;
}



Results















Reference