2014年12月17日 星期三

[JavaScript]格林威治時間轉換

dates =  Fri Dec 19 2014 12:00:00 GMT+0800 (台北標準時間)
var d = new Date(dates);
var year = d.getFullYear();
var month = d.getMonth() + 1;
var day = d.getDate();
alert(year + "/" + month + "/" + day)
輸出結果: 2014/12/19

2014年12月15日 星期一

[MVC] DropDownListFor用法

View
@Html.DropDownListFor(m => m.Week,  new SelectList((System.Collections.IEnumerable)ViewData["WeekList"], "Value", "Text"))


Controller
 public ActionResult RoomOpenDateSet()
{
   ViewData["WeekList"] = roomOpenSetService.GetRoomOpenSetWeeksByRoomListID(roomListID);
}

Class
public List<SelectListItem> CreatWeekDropDownList(string roomListID)
{
            List<SelectListItem> items = new List<SelectListItem>();
            var query = roomOpenSetService.GetRoomOpenSetWeeksByRoomListID(roomListID);
            foreach (var item in query)
            {
               items.Add(new SelectListItem { Text = Enum.GetName(typeof(WeekList), item.Week), Value = item.Week.ToString() });
             }
  return items;
}

傳回html版==============================================================
 [HttpPost]
 public ActionResult GetWeekList(string roomListid)
 {
        return Json(sf.CreatWeekDropDownList(roomListid));
 }

public string CreatWeekDropDownList(string roomListID)
{
            List<SelectListItem> items = new List<SelectListItem>();
            StringBuilder result = new StringBuilder();
            int _roomListID = Convert.ToInt32(des.DESDecrypt(roomListID, "a"));
            var userList = roomOpenSetService.GetRoomOpenSetWeeksByRoomListID(_roomListID);
            result.Append("<select id=\"Week\" name=\"Week\">");
            result.Append("<option value=\"0\">==請選擇星期==</option>");
            foreach (var item in userList)
            {
                result.Append("<option value=\"" + item.Week + "\">" + item.Week + "</option>");
            }
            result.Append("</select>");

            return result.ToString();
}


JS
 $.ajax({
        url: '/SpaceControl/GetWeekList/',
        type: 'post',
        data: { roomListid: roomListID },
        cache: false,
        async: false,
        success: function (res) {
            alert(res);
            $("#Weeks").html(res);
        },
        error: function (x, e) {
            window.location.href = "/Share/ErrorPage?err=500";
        }
    });
=======================================================================

列舉
public enum WeekList
{
            一 = 1,
            二 = 2,
            三 = 3,
            四 = 4,
            五 = 5,
            六 = 6,
            日 = 7
 }


2014年12月10日 星期三

DropDownListFor從資料庫讀取

暫時先記錄一下,後續再整理
View
 @Html.DropDownListFor(m => m.CustomType, (SelectList)ViewBag.CustomTypeList, "==請選擇==")

Controller
 ViewBag.CustomTypeList = sf.CreatMasterCodeDropDownList("CustomType");

Class
#region CreatMasterCodeDropDownList()-產生下拉選單
        public SelectList CreatMasterCodeDropDownList(string columnName)
        {
            HotelSelectModels hsm = new HotelSelectModels();
            SelectList DDLItem = new SelectList(hsm.GetMasterCodeByColumnName(columnName), "Value", "Name");
            return DDLItem;
        }
 #endregion

Model
public List<HotelViewModel.MasterCodeModel> GetMasterCodeByColumnName(string columnName)
{
    List<HotelViewModel.MasterCodeModel> result = new List<HotelViewModel.MasterCodeModel>();
            using (HotelEntities db = new HotelEntities())
            {
                var query = db.MasterCode.Where(f => f.ColumnName == columnName).ToList();
                if (query.Count > 0)
                {
                    foreach (var item in query)
                    {
                        result.Add(new HotelViewModel.MasterCodeModel()
                        {
                            ColumnName = item.ColumnName,
                            Name = item.Name,
                            Value = item.Value
                        });
                    }
                }
            }
            return result;
 }

2014年12月4日 星期四

SQL 找出資料列中最大值的列表

select *
from 資料表名稱
where  欄位名稱 =
 (
   select max(欄位名稱) as max欄位名稱
   from  資料表名稱
)

2014年12月1日 星期一

SQL 找出重複資料

COUNT 表示出現的次數
SELECT CalumnName,COUNT(*)FROM TableName GROUP BY CalumnName HAVING COUNT(*) > 1

2014年11月25日 星期二

jQuery Datepicker 使用心得

重新賦予月曆 minDate/maxDate新的值
加這句即可 $('#CheckoutDate').datepick('destroy');

點選按鈕載入ReloadCheckDate








function ReloadCheckDate(checkInDate, checkOutDate) {

    $('#CheckoutDate').datepick('destroy');
    $('#CheckoutDate').datepick({
        minDate: checkInDate,
        maxDate: checkOutDate, showTrigger: '#calImg'
    });

}

2014年11月21日 星期五

C#合併兩個Dictionary

 使用Dictionary類別的擴充方法Concat串接兩個序列

Dictionary<Guid, ViewModel.EventModel> events = roomOpenService.GetRoomOpenEvents(roomListID);
 events = events.Concat(roomBookingService.GetRoomBookingEvents(roomListID)).ToDictionary(k => k.Key, v => v.Value);

Visual Studio JS intellisense 失效解決方式

  試了好久,發現到工具>選項>IntelliCode js項目設定啟用,重新開啟VS就正常了! 後來發現是TypeScript3.2版有問題停用,使用4.3版的TypeScript即可