2014年9月24日 星期三

DataTable to List to Json

DataTable to List

var r = Shared.Process(this.ws, "TraBULLETINGet", form);

List<Bulletin> bulletin = new List<Bulletin>();

foreach (DataRow dr in r.ds.Tables["T1"].Rows)
 {
   bulletin.Add(new Bulletin { TITLE = dr["TITLE"].ToString(), DES = dr["DES"].ToString(), CREATE_DATE = dr["CREATE_DATE"].ToString() });
 }

var jsonSerialiser = new JavaScriptSerializer();
var json = jsonSerialiser.Serialize(bulletin);

public class Bulletin
 {
     public string TITLE { get; set; }
     public string DES { get; set; }
     public string CREATE_DATE { get; set; }
 }

.NET讀取csv檔

錯誤:不是一個有效的路徑。請確定路徑名稱是拼對的,而且檔案位於您所連接的伺服器上。

string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\;Extended Properties='text'";
using (OleDbConnection conn = new OleDbConnection(strConn))
{
   DataTable dt = new DataTable();
   using (OleDbDataAdapter adapter = new OleDbDataAdapter(@"select  * from [aa.csv]", conn))
     {
       adapter.Fill(dt);
     }
}

2014年9月19日 星期五

Oracle 修改 SEQUENCE

修改INCREMENT(可以為負),再執行NEXTVAL

ALTER SEQUENCE seq INCREMENT BY 100;
SELECT seq.NEXTVAL FROM DUAL;

執行完記得改回1

ALTER SEQUENCE seq INCREMENT BY 1;

2014年9月15日 星期一

常用SQL,老是忘記...

SELECT SUM(A) AS A,SUM(B) AS B FROM (
SELECT 3 AS A,0 AS B
UNION ALL
SELECT 0 AS A,4 AS B
)A 

2014年9月14日 星期日

ASP.NET MVC Route Attribute


Route屬性

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace MvcMusicStore.Controllers
{
    public class DemoRouteController : ApiController
    {
        //GET: api/DemoRoute/5
        [Route("customers/{id}/orders")]
        [HttpGet]
        public string FindValue(int id)
        {
            return id.ToString();
        }
    }
}

SQL SERVER Loop

非必要,盡量少用Cursor

DECLARE @count INT
DECLARE @max INT
 SET @count = 0
 SET @max = 5
 WHILE (@count<@max)
 BEGIN
    SELECT @count
    Set @count=@count+1
 END

SQL SERVER 開啟 執行計畫 Execution plan



Visual Studio 修改專案檔 csproj



ASP.NET MVC (Model, View, Controller 簡單範例)

Model

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebApplication1.Models
{
    public class Album
    {
        public int AlbumID { get; set; }
        public string Title { get; set; }
    }
}

List Controller

public ActionResult Index()
        {
            List albums = new List();
            albums.Add(new Album { AlbumID = 1, Title = "Sting" });
            albums.Add(new Album { AlbumID = 2, Title = "Joan" });
            return View(albums);
        }

List View

@model IEnumerable<WebApplication1.Models.Album>

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Title)
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Title)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id=item.AlbumID }) |
            @Html.ActionLink("Details", "Details", new { id=item.AlbumID }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.AlbumID })
        </td>
    </tr>
}

</table>

Detail Controller

public ActionResult Details(int id)
        {
            var album = new Album { AlbumID = id, Title = "Hello" };
            return View(album);
        }

Detail View

@model WebApplication1.Models.Album

@{
    ViewBag.Title = "Details";
}

<h2>Details</h2>

<div>
    <h4>Album</h4>
 <hr />
    <dl class="dl-horizontal">
        <dt>
            @Html.DisplayNameFor(model => model.Title)
        </dt>

        <dd>
            @Html.DisplayFor(model => model.Title)
        </dd>

    </dl>
</div>
<p>
    @Html.ActionLink("Edit", "Edit", new { id = Model.AlbumID }) |
    @Html.ActionLink("Back to List", "Index")
</p>

2014年9月4日 星期四

Visual Studio 2012 加入Web 參考

 



IE11 看不到列印按鈕 (ReportViewer)


  1. 確認目前安裝的ReportViewer版本
  2. 安裝最新版ReportViewer(11.0.3452.0)  http://www.microsoft.com/zh-tw/download/details.aspx?id=35747
  3. 安裝.NET Framework 4.5.1
  4. 重開機


2014年9月3日 星期三

C#執行EXE檔加參數

C#執行EXE檔加參數
string text = "";
string strUser = "894128";
string strPath = HttpContext.Current.Server.MapPath("~/OfficeUpload/");
System.IO.File.WriteAllText(strPath + strUser + ".txt", text);
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = Path.GetFileName(strPath + "/StockMergeRpt.exe");
psi.WorkingDirectory = Path.GetDirectoryName(strPath + "/StockMergeRpt.exe");
psi.Arguments = "-i " + strUser + ".txt -o " + strUser + ".doc";
Process.Start(psi);