1. Run Visual Studio 2017
2. Click file -> Source Control -> Advanced -> Change Source Control
3. Select a solution or project to unbind, and click Unbind
C# is powerful, easy to learn and the best language to get concepts of programming!
Thursday, November 8, 2018
Thursday, June 1, 2017
How to see 'EntityValidationErrors' property for more details
Exception Message
Validation failed for one or more entities. See 'EntityValidationErrors' property for more details
Code Behind(cs) file
Validation failed for one or more entities. See 'EntityValidationErrors' property for more details
Code Behind(cs) file
try
{
// Your code...
dbcontext.SaveChanges();
}
catch (System.Data.Entity.Validation.DbEntityValidationException e)
{
foreach (var eErr in e.EntityValidationErrors)
{
// Write log to Output
System.Diagnostics.Debug.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
eErr.Entry.Entity.GetType().Name, eErr.Entry.State);
foreach (var vErr in eErr.ValidationErrors)
{
System.Diagnostics.Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
vErr.PropertyName, vErr.ErrorMessage);
}
/*
// Write log to Console
System.Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
eErr.Entry.Entity.GetType().Name, eErr.Entry.State);
foreach (var vErr in eErr.ValidationErrors)
{
System.Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
vErr.PropertyName, vErr.ErrorMessage);
}
*/
}
throw;
}
Thursday, December 22, 2016
jQuery Selectors
Links
http://www.w3schools.com/jquery/jquery_ref_selectors.asp
http://www.w3schools.com/jquery/jquery_ref_selectors.asp
| Selector | Example | Selects |
|---|---|---|
| * | $("*") | All elements |
| #id | $("#lastname") | The element with id="lastname" |
| .class | $(".intro") | All elements with class="intro" |
| .class,.class | $(".intro,.demo") | All elements with the class "intro" or "demo" |
| element | $("p") | All <p> elements |
| el1,el2,el3 | $("h1,div,p") | All <h1>, <div> and <p> elements |
| :first | $("p:first") | The first <p> element |
| :last | $("p:last") | The last <p> element |
| :even | $("tr:even") | All even <tr> elements |
| :odd | $("tr:odd") | All odd <tr> elements |
| :first-child | $("p:first-child") | All <p> elements that are the first child of their parent |
| :first-of-type | $("p:first-of-type") | All <p> elements that are the first <p> element of their parent |
| :last-child | $("p:last-child") | All <p> elements that are the last child of their parent |
| :last-of-type | $("p:last-of-type") | All <p> elements that are the last <p> element of their parent |
| :nth-child(n) | $("p:nth-child(2)") | All <p> elements that are the 2nd child of their parent |
| :nth-last-child(n) | $("p:nth-last-child(2)") | All <p> elements that are the 2nd child of their parent, counting from the last child |
| :nth-of-type(n) | $("p:nth-of-type(2)") | All <p> elements that are the 2nd <p> element of their parent |
| :nth-last-of-type(n) | $("p:nth-last-of-type(2)") | All <p> elements that are the 2nd <p> element of their parent, counting from the last child |
| :only-child | $("p:only-child") | All <p> elements that are the only child of their parent |
| :only-of-type | $("p:only-of-type") | All <p> elements that are the only child, of its type, of their parent |
| parent > child | $("div > p") | All <p> elements that are a direct child of a <div> element |
| parent descendant | $("div p") | All <p> elements that are descendants of a <div> element |
| element + next | $("div + p") | The <p> element that are next to each <div> elements |
| element ~ siblings | $("div ~ p") | All <p> elements that are siblings of a <div> element |
| :eq(index) | $("ul li:eq(3)") | The fourth element in a list (index starts at 0) |
| :gt(no) | $("ul li:gt(3)") | List elements with an index greater than 3 |
| :lt(no) | $("ul li:lt(3)") | List elements with an index less than 3 |
| :not(selector) | $("input:not(:empty)") | All input elements that are not empty |
| :header | $(":header") | All header elements <h1>, <h2> ... |
| :animated | $(":animated") | All animated elements |
| :focus | $(":focus") | The element that currently has focus |
| :contains(text) | $(":contains('Hello')") | All elements which contains the text "Hello" |
| :has(selector) | $("div:has(p)") | All <div> elements that have a <p> element |
| :empty | $(":empty") | All elements that are empty |
| :parent | $(":parent") | All elements that are a parent of another element |
| :hidden | $("p:hidden") | All hidden <p> elements |
| :visible | $("table:visible") | All visible tables |
| :root | $(":root") | The document's root element |
| :lang(language) | $("p:lang(de)") | All <p> elements with a lang attribute value starting with "de" |
| [attribute] | $("[href]") | All elements with a href attribute |
| [attribute=value] | $("[href='default.htm']") | All elements with a href attribute value equal to "default.htm" |
| [attribute!=value] | $("[href!='default.htm']") | All elements with a href attribute value not equal to "default.htm" |
| [attribute$=value] | $("[href$='.jpg']") | All elements with a href attribute value ending with ".jpg" |
| [attribute|=value] | $("[title|='Tomorrow']") | All elements with a title attribute value equal to 'Tomorrow', or starting with 'Tomorrow' followed by a hyphen |
| [attribute^=value] | $("[title^='Tom']") | All elements with a title attribute value starting with "Tom" |
| [attribute~=value] | $("[title~='hello']") | All elements with a title attribute value containing the specific word "hello" |
| [attribute*=value] | $("[title*='hello']") | All elements with a title attribute value containing the word "hello" |
| :input | $(":input") | All input elements |
| :text | $(":text") | All input elements with type="text" |
| :password | $(":password") | All input elements with type="password" |
| :radio | $(":radio") | All input elements with type="radio" |
| :checkbox | $(":checkbox") | All input elements with type="checkbox" |
| :submit | $(":submit") | All input elements with type="submit" |
| :reset | $(":reset") | All input elements with type="reset" |
| :button | $(":button") | All input elements with type="button" |
| :image | $(":image") | All input elements with type="image" |
| :file | $(":file") | All input elements with type="file" |
| :enabled | $(":enabled") | All enabled input elements |
| :disabled | $(":disabled") | All disabled input elements |
| :selected | $(":selected") | All selected input elements |
| :checked | $(":checked") | All checked input elements |
Friday, October 28, 2016
How to force HTML table cell as text in Excel
<td> style to force the cell as text: mso-number-format:"\@";
<td> style to force the cell as number: mso-number-format:General;
Code Behind(cs) file
<td> style to force the cell as number: mso-number-format:General;
Code Behind(cs) file
public PartialViewResult ExcelFile()
{
StringBuilder table = new StringBuilder();
table.AppendLine("<table>");
table.AppendLine("<thead>");
table.AppendLine("<tr>");
table.AppendLine("<th>Date</th>");
table.AppendLine("<th>Store</th>");
table.AppendLine("</tr>");
table.AppendLine("</thead>");
table.AppendLine("<tbody>");
table.AppendLine("<tr>");
table.Append("<td>10/27/2016</td>");
table.Append("<td style='mso-number-format:\"\\@\"'>0001</td>");
table.AppendLine("</tr>");
table.AppendLine("<tr>");
table.Append("<td>10/27/2016</td>");
table.Append("<td style='mso-number-format:\"\\@\"'>0002</td>");
table.AppendLine("</tr>");
table.AppendLine("</tbody>");
table.AppendLine("</table>");
Response.ContentType = "application/force-download";
Response.AddHeader("content-disposition", "attachment; filename=ExcelFile_" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls");
Response.Write("<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">");
Response.Write("<head>");
Response.Write("<META http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">");
Response.Write("<!--[if gte mso 9]><xml>");
Response.Write("<x:ExcelWorkbook>");
Response.Write("<x:ExcelWorksheets>");
Response.Write("<x:ExcelWorksheet>");
Response.Write("<x:Name>ExcelFile</x:Name>");
Response.Write("<x:WorksheetOptions>");
Response.Write("<x:Print>");
Response.Write("<x:ValidPrinterInfo/>");
Response.Write("</x:Print>");
Response.Write("</x:WorksheetOptions>");
Response.Write("</x:ExcelWorksheet>");
Response.Write("</x:ExcelWorksheets>");
Response.Write("</x:ExcelWorkbook>");
Response.Write("</xml>");
Response.Write("<![endif]--> ");
Response.Write("</head>");
Response.Write(table.ToString());
Response.Flush();
return PartialView();
}
Wednesday, April 6, 2016
How to launch the Android emulator from the command line?
1. Go to SDK folder
Go to android sdk folder in which "android.bat" and "emulator.exe" are located.
ex) Default folder on Windows: C:\Users\{user}\AppData\Local\Android\sdk\tools
2. Run AVD manager
Type in "android avd" in the command prompt to launch the Android Virtual Devices manager.
3. Create AVD
Create a AVD by clicking "Create..." button.
Or you can just use the one already created from the list.
4. Launch emulator
Run the AVD either by using command "emulator -avd <name>" or by clicking "Start..." button on the AVD manager.
Go to android sdk folder in which "android.bat" and "emulator.exe" are located.
ex) Default folder on Windows: C:\Users\{user}\AppData\Local\Android\sdk\tools
2. Run AVD manager
Type in "android avd" in the command prompt to launch the Android Virtual Devices manager.
3. Create AVD
Create a AVD by clicking "Create..." button.
Or you can just use the one already created from the list.
4. Launch emulator
Run the AVD either by using command "emulator -avd <name>" or by clicking "Start..." button on the AVD manager.
Tuesday, April 5, 2016
How to install app in Android emulator?
1. Launch emulator
Go to here to see how to launch Android Emulator.
2. Copy the apk file to platform-tools folder
ex) Default folder on Windows: C:\Users\{user}\AppData\Local\Android\sdk\platform-tools
3. Go to command prompt
Type "adb install filename.apk" to install
Type "adb install -r filename.apk" to re-install
4. Run emulator then you will see the app is installed.
Go to here to see how to launch Android Emulator.
2. Copy the apk file to platform-tools folder
ex) Default folder on Windows: C:\Users\{user}\AppData\Local\Android\sdk\platform-tools
3. Go to command prompt
Type "adb install filename.apk" to install
Type "adb install -r filename.apk" to re-install
4. Run emulator then you will see the app is installed.
Friday, March 11, 2016
How to pass javascript array to C# code behind
Used jquery version: jquery-1.8.3.min.js
html(cshtml) file
Code Behind(cs) file
html(cshtml) file
function updateNotification() {
var ids = [1, 2, 3, 4, 5];
if (ids.length > 0) {
$.ajax({
traditional: true, // Should be true
type: "POST",
url: "/Notification/Update", // Url to pass
data: { ids: ids },
dataType: "json",
success: function (result) {
},
error: function (result) {
}
});
}
}
Code Behind(cs) file
[HttpPost]
public JsonResult Update(int[] ids)
{
// ids is int array
return Json(new { result = true });
}
Wednesday, December 16, 2015
[C# 초보 강좌] 예제로 배우는 C# 01
예제로 배우는 C# 첫번째 강좌입니다.
책을 봐도 잘 모르시겠다는 분들이나, 개념은 알겠는데 막상 프로그램을 못하시는 분들을 위한 강좌입니다.
비주얼 스튜디오를 깔고 Hello C# 프로그램을 통해서 기본 구조를 익히겠습니다.
전체 설명은 아래 YouTube를 참조하시고 코드 부분만 밑에 넣도록 하겠습니다.
HelloCSharp.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HelloCSharp
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello C#");
Console.WriteLine("Hello " + args[0]);
Console.ReadKey();
}
}
}
Tuesday, December 8, 2015
[C# 강의 중급] 라이브러리를 만들자 04 - 확장 메소드
C# 라이브러리를 만들자 네번째 강의입니다.
자신의 라이브러리를 구축하는 것은 프로그래머로서 재산을 축적하 것과 같다고 생각합니다.
오늘은 String과 DateTime에 Extension Methods를 추가하는 클래스를 만들어 라이브러리에 넣도록 하겠습니다.
전체 설명은 아래 YouTube를 참조하시고 코드 부분만 밑에 넣도록 하겠습니다.
BabyCarrot.Extensions.StringExtensions
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BabyCarrot.Extensions
{
public static class StringExtensions
{
#region Methods
public static bool IsNumeric(this string s)
{
long result;
return long.TryParse(s, out result);
}
public static bool IsDateTime(this string s)
{
if (String.IsNullOrEmpty(s))
{
return false;
}
else
{
DateTime result;
return DateTime.TryParse(s, out result);
}
}
#endregion
}
}
BabyCarrot.Extensions.DateTimeExtensions
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BabyCarrot.Extensions
{
public static class DateTimeExtensions
{
#region Methods
public static DateTime FirstDateOfMonth(this DateTime date)
{
return new DateTime(date.Year, date.Month, 1);
}
public static DateTime LastDateOfMonth(this DateTime date)
{
return new DateTime(date.Year, date.Month, DateTime.DaysInMonth(date.Year, date.Month));
}
#endregion
}
}
Monday, December 7, 2015
[C# 강의 중급] 라이브러리를 만들자 03 - Log Manager 확장
C# 라이브러리를 만들자 세번째 강의입니다.
자신의 라이브러리를 구축하는 것은 프로그래머로서 재산을 축적하 것과 같다고 생각합니다.
이전 강의에서 만들었던 LogManager Class를 몇 개의 Option을 이용해서 확장해 보겠습니다.
전체 설명은 아래 YouTube를 참조하시고 코드 부분만 밑에 넣도록 하겠습니다.
BabyCarrot.Tools.LogManager
using System;
using System.IO;
namespace BabyCarrot.Tools
{
public enum LogType { Daily, Monthly }
public class LogManager
{
private string _path;
#region Constructors
public LogManager(string path, LogType logType, string prefix, string postfix)
{
_path = path;
_SetLogPath(logType, prefix, postfix);
}
public LogManager(string prefix, string postfix)
: this(Path.Combine(Application.Root, "Log"), LogType.Daily, prefix, postfix)
{
}
public LogManager()
: this(Path.Combine(Application.Root, "Log"), LogType.Daily, null, null)
{
}
#endregion
#region Methods
private void _SetLogPath(LogType logType, string prefix, string postfix)
{
string path = String.Empty;
string name = String.Empty;
switch (logType)
{
case LogType.Daily:
path = String.Format(@"{0}\{1}\", DateTime.Now.Year, DateTime.Now.ToString("MM"));
name = DateTime.Now.ToString("yyyyMMdd");
break;
case LogType.Monthly:
path = String.Format(@"{0}\", DateTime.Now.Year);
name = DateTime.Now.ToString("yyyyMM");
break;
}
_path = Path.Combine(_path, path);
if (!Directory.Exists(_path))
Directory.CreateDirectory(_path);
if (!String.IsNullOrEmpty(prefix))
name = prefix + name;
if (!String.IsNullOrEmpty(postfix))
name = name + postfix;
name += ".txt";
_path = Path.Combine(_path, name);
}
public void Write(string data)
{
try
{
using (StreamWriter writer = new StreamWriter(_path, true))
{
writer.Write(data);
}
}
catch (Exception ex)
{ }
}
public void WriteLine(string data)
{
try
{
using (StreamWriter writer = new StreamWriter(_path, true))
{
writer.WriteLine(DateTime.Now.ToString("yyyyMMdd HH:mm:ss\t") + data);
}
}
catch (Exception ex)
{ }
}
#endregion
}
}
[C# 강의 중급] 라이브러리를 만들자 02 - Log Manager
C# 라이브러리를 만들자 두번째 강의입니다.
자신의 라이브러리를 구축하는 것은 프로그래머로서 재산을 축적하 것과 같다고 생각합니다.
Log를 파일에 기록하는 LogManager Class를 라이브러리에 추가합니다.
전체 설명은 아래 YouTube를 참조하시고 코드 부분만 밑에 넣도록 하겠습니다.
BabyCarrot.Tools.LogManager
using System;
using System.IO;
namespace BabyCarrot.Tools
{
public class LogManager
{
private string _path;
#region Constructors
public LogManager(string path)
{
_path = path;
_SetLogPath();
}
public LogManager()
: this(Path.Combine(Application.Root, "Log"))
{
}
#endregion
#region Methods
private void _SetLogPath()
{
if (!Directory.Exists(_path))
Directory.CreateDirectory(_path);
string logFile = DateTime.Now.ToString("yyyyMMdd") + ".txt";
_path = Path.Combine(_path, logFile);
}
public void Write(string data)
{
try
{
using (StreamWriter writer = new StreamWriter(_path, true))
{
writer.Write(data);
}
}
catch (Exception ex)
{ }
}
public void WriteLine(string data)
{
try
{
using (StreamWriter writer = new StreamWriter(_path, true))
{
writer.WriteLine(DateTime.Now.ToString("yyyyMMdd HH:mm:ss\t") + data);
}
}
catch (Exception ex)
{ }
}
#endregion
}
}
Saturday, December 5, 2015
How to setup syntax highlighter on blogger
We are going to use SyntaxHighlighter to highlight codes.
It's quite simple and easy but if you want to use the 'Dynamic Views' Template on Blogger, then you need a simple trick.
1. First, back up your current template.
If something goes wrong, you can restore the original template anytime.
2. Open your template in 'Edit HTML' mode.
3. Copy and paste the following code right before </head> tag.
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/> <link href='http://alexgorbatchev.com/pub/sh/current/styles/shThemeDefault.css' rel='stylesheet' type='text/css'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushDelphi.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPhp.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushRuby.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js' type='text/javascript'/> <script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushVb.js' type='text/javascript'/>
4. If you are NOT using 'Dynamic Views' template,
then copy and paste the following code just before </body> tag.
<script language='javascript'>
SyntaxHighlighter.config.bloggerMode = true;
SyntaxHighlighter.all();
</script>
5. Save template.
6. Now you are ready to use SyntaxHighlighter with <pre></pre> tag.
Escape '<' and '>' to '<' and '>' in your code to highlight.
Change class name depending on the code between pre tags.
For html, xml, xhtml, xslt, <pre class='brush: html'>.
For c# <pre class='brush: csharp'>.
You can find more here.
<pre class="brush: html">
<div>html div tag</div>
</pre>
<pre class="brush: csharp">
function void csharpFunction()
{
return;
}
</pre>
7. If you are using 'Dynamic Views' template, copy and paste the following code at the bottom of every page in 'HTML' edit mode.
<script type="text/javascript">
$(document).ready(function () {
$("pre").each(function () {
SyntaxHighlighter.highlight(undefined, this);
});
});
</script>
Friday, December 4, 2015
[C# 강의 중급] 라이브러리를 만들자 01
C# 라이브러리를 만들자 첫번째 강의입니다.
자신의 라이브러리를 구축하는 것은 프로그래머로서 재산을 축적하 것과 같다고 생각합니다.
전체 설명은 아래 YouTube를 참조하시고 코드 부분만 밑에 넣도록 하겠습니다.
BabyCarrot.Tools.Application
using System;
namespace BabyCarrot.Tools
{
public static class Application
{
#region Properties
// 현재 실행된 Application이 위치한 폴더
public static string Root
{
get
{
return AppDomain.CurrentDomain.BaseDirectory;
}
}
#endregion
}
}
Subscribe to:
Posts (Atom)




