วันอังคารที่ 2 มิถุนายน พ.ศ. 2558
SQL DATEDIFF converting date and/or time from character string
ไม่มีความคิดเห็น:
Posted by
Aagkasit Tontan
at
23:31
Labels:
DATEDIFF,
Error,
ISDATE,
SQL,
SQL SERVER
I Use Function for [Worked]
ALTER FUNCTION [dbo].[FNDATEDIFF] ( -- Add the parameters for the function here @StartDate VARCHAR(8), @EndDate VARCHAR(8) ) RETURNS VARCHAR(8) AS BEGIN IF (isdate(@StartDate) = 0) RETURN 0 IF (isdate(@EndDate) = 0) RETURN 0 RETURN DATEDIFF(day,@StartDate,@EndDate) END
How to Use
select dbo.FNDATEDIFF('20110725','20110923') as 'DiffDate'
select dbo.FNDATEDIFF('20110725','') as 'DiffDate'
select dbo.FNDATEDIFF('','') as 'DiffDate'
select dbo.FNDATEDIFF('','20110923') as 'DiffDate'
Result
DiffDate 60 DiffDate 0 DiffDate 0 DiffDate 0
วันจันทร์ที่ 18 พฤษภาคม พ.ศ. 2558
Uploading a Folder in Asp.net MVC4
2 ความคิดเห็น:
Posted by
Aagkasit Tontan
at
03:24
Labels:
Asp.net Mvc4,
c#,
Upload Folder,
Uploading a Folder
View
@{
ViewBag.Title = "uploadFolder";
}
upload Folder
ScriptControllor
public ActionResult uploadFolder()
{
return View();
}
[HttpPost]
public async Task UploadHomeReport()
{
try
{
foreach (string file in Request.Files)
{
var fileContent = Request.Files[file];
if (fileContent != null && fileContent.ContentLength > 0)
{
// get a stream
var stream = fileContent.InputStream;
// and optionally write the file to disk
var fileName = fileContent.FileName;
fileName = fileName.Replace(@"/",@"\");
string[] arr = fileName.Split('\\');
//\tculms\sub\sub1
var tempPath = string.Empty;
for (int i = 0; i < arr.Length; i++) {
if (!isFolder(arr[i]))
{
var targetPath = string.Empty;
if (i == 0)
{
targetPath = Path.Combine(Server.MapPath("~/Images"), arr[i]);
tempPath = tempPath + "\\" + arr[i];
if (!System.IO.Directory.Exists(targetPath))
{
System.IO.Directory.CreateDirectory(targetPath);
}
}
else
{
tempPath = tempPath + "\\" + arr[i];
targetPath = Server.MapPath("~/Images") + tempPath;
//targetPath = Path.Combine(Server.MapPath("~/Images"), tempPath);
if (!System.IO.Directory.Exists(targetPath))
{
System.IO.Directory.CreateDirectory(targetPath);
}
}
}
}
var path = Path.Combine(Server.MapPath("~/Images"), fileName);
using (var fileStream = System.IO.File.Create(path))
{
stream.CopyTo(fileStream);
}
}
}
}
catch (Exception)
{
Response.StatusCode = (int)HttpStatusCode.BadRequest;
return Json("Upload failed");
}
return Json("File uploaded successfully");
}
private bool isFolder(string txt) {
var arr = txt.ToCharArray();
for (int i = 0; i < arr.Length;i++ )
{
if (arr[i] == '.') {
return true;
}
}
return false;
}
Web configResult
Derivative
วันพุธที่ 8 เมษายน พ.ศ. 2558
[c#] Accessing a network file share
static void Main(string[] args)
{
//var system = System.IO.Directory.GetFiles(@"\\LENOVO-PC\joke\teacher\");
DirectoryInfo dir = new DirectoryInfo(@"\\LENOVO-PC\joke\teacher\");//
FileInfo fi = new FileInfo(@"\\LENOVO-PC\joke\teacher\image\1857784.jpg");
bool exists = fi.Exists;
while (true) { }
}
ตัวอย่างจาก
http://stackoverflow.com/questions/20138569/reading-files-from-server-is-being-mapped-always-c-drive
http://stackoverflow.com/questions/18240909/accessing-a-network-file-share-with-c-sharp
วันอังคารที่ 31 มีนาคม พ.ศ. 2558
C# Calculate Standard Deviation (Using List Object)
ไม่มีความคิดเห็น:
Posted by
Aagkasit Tontan
at
21:34
Labels:
c#,
Grade Calculator,
SD,
Standard Deviation
สร้าง Class StandardDeviation ไว้คำนวนค่าหาส่วนเบี่ยงเบนมาตรฐาน(S.D.) ในกรณีข้อมูลไม่ได้มีการแจกแจงความถี่
จากตัวอย่าง : http://www.stvc.ac.th/elearning/stat/csu3.html
public class StandardDeviation {
private double ExP2 { set; get; } //Ex^2
private double Ex2 { set; get; }//(Ex)^2
private List listScore { set; get; }
private int n { set; get; }
private double sum {set;get;}
public StandardDeviation(List scores){
this.listScore = scores;
this.n = scores.Count;
}
public double Calculator(){
calExP2();
CalEx2();
/*แทนค่าในสูตร
สูตร s.d = รูท nEx^2 - (Ez)^2 / n(n-1)
*/
double g1 = this.n*this.ExP2 - this.Ex2;
int g2 = this.n * (this.n - 1);
sum = Math.Sqrt(g1 / g2);
return sum;
}
private void calExP2(){
for (int i = 0; i < this.listScore.Count; i++) {
this.ExP2 = this.ExP2 + (this.listScore[i] * this.listScore[i]);
}
}
private void CalEx2() {
for (int i = 0; i < this.listScore.Count; i++ )
{
this.Ex2 = this.Ex2 + this.listScore[i];
}
this.Ex2 = (this.Ex2 * this.Ex2);
}
}
ตัวอย่างการเรียกใช้งานจากตัวอย่าง : http://www.stvc.ac.th/elearning/stat/csu3.html
//Ex2.จากข้อมูลต่อไปนี้จงหาส่วนเบี่ยงเบนมาตรฐาน 1, 2, 4, 6, 8, 9
List listScore = new List();
listScore.Add(1d);// 1, 2, 4, 6, 8, 9
listScore.Add(2d);
listScore.Add(4d);
listScore.Add(6d);
listScore.Add(8d);
listScore.Add(9d);
//1.การหาส่วนเบี่ยงเบนมาตรฐาน(S.D.) ในกรณีข้อมูลไม่ได้มีการแจกแจงความถี่
StandardDeviation sd = new StandardDeviation(listScore);
Console.WriteLine("SD : "+ sd.Calculator());
Console.ReadLine();
ผลการรันโปรแกรมC# Calculate Grade T-Score (Using List Object)
ไม่มีความคิดเห็น:
Posted by
Aagkasit Tontan
at
21:23
Labels:
c#,
Grade Calculator,
Grade Calculator Custom,
Grade Calculator Dynamic,
T-Score
สมมุติ มีคะแนนนักเรียนดังนี้ คนที่ 1 มี 1 คะแนน คนที่ 2 มี 2 คะแนน คนที่ 3 มี 4 คะแนน คนที่ 4 มี 6 คะแนน คนที่ 5 มี 8 คะแนน คนที่ 6 มี 9 คะแนน ให้ตัดเกรดของนักเรียนเหล่านี้ โดยวิธีตัดเกรดด้วย T-Score ที่มาของโจทย์ : http://www.stvc.ac.th/elearning/stat/csu3.htmlใช้การคำนวณ SD จากบทความที่แล้ว C# Calculate Standard Deviation (Using List Object)
class Program
{
static void Main(string[] args)
{
//Ex2.จากข้อมูลต่อไปนี้จงหาส่วนเบี่ยงเบนมาตรฐาน 1, 2, 4, 6, 8, 9
List listScore = new List();
listScore.Add(1d);// 1, 2, 4, 6, 8, 9
listScore.Add(2d);
listScore.Add(4d);
listScore.Add(6d);
listScore.Add(8d);
listScore.Add(9d);
//1.การหาส่วนเบี่ยงเบนมาตรฐาน(S.D.) ในกรณีข้อมูลไม่ได้มีการแจกแจงความถี่
StandardDeviation sd = new StandardDeviation(listScore);
//จาก สมการ T = 10Z + 50
//1 หา z = (14- ค่าเฉลี่ยเรขาคณิต ) / SD
double sd_ = sd.Calculator();//3.22
double xbar = average(listScore);//1.5
for (int i = 0; i < listScore.Count; i++) {
double z = (listScore[i] - xbar) / sd_; //14
//Console.WriteLine("Z Score : " + z);
double t = 10 * z + 50;
Console.WriteLine(listScore[i]+" To T Score : " + t);
}
Console.ReadLine();
}
static double average(List listScore)
{
double sum = 0.0d;
int n = listScore.Count;
for (int i = 0; i < listScore.Count; i++)
{
sum = sum + listScore[i];
}
double result = sum / n;
return result;
}
}
รันแล้วเราก็จะได้ คะแนนนักเรียนออกมาจากนั้นเอาโปรแกรมตัดเกรดจากบทความ c# Grade Calculator (Using List Object) มาใช้
static void Main(string[] args)
{
//Ex2.จากข้อมูลต่อไปนี้จงหาส่วนเบี่ยงเบนมาตรฐาน 1, 2, 4, 6, 8, 9
List listScore = new List();
listScore.Add(1d);// 1, 2, 4, 6, 8, 9
listScore.Add(2d);
listScore.Add(4d);
listScore.Add(6d);
listScore.Add(8d);
listScore.Add(9d);
//ตั้งค่าเกรด
List ls = new List();
ls.Add(new Grades(49f, "F"));
ls.Add(new Grades(49.5f, "D"));
ls.Add(new Grades(55f, "D+"));
ls.Add(new Grades(60f, "C"));
ls.Add(new Grades(65f, "P"));
ls.Add(new Grades(70f, "B"));
ls.Add(new Grades(75f, "B+"));
ls.Add(new Grades(80f, "A"));
//1.การหาส่วนเบี่ยงเบนมาตรฐาน(S.D.) ในกรณีข้อมูลไม่ได้มีการแจกแจงความถี่
StandardDeviation sd = new StandardDeviation(listScore);
//จาก สมการ T = 10Z + 50
//1 หา z = (14- ค่าเฉลี่ยเรขาคณิต ) / SD
double sd_ = sd.Calculator();//3.22
double xbar = average(listScore);//1.5
for (int i = 0; i < listScore.Count; i++)
{
double z = (listScore[i] - xbar) / sd_; //14
//Console.WriteLine("Z Score : " + z);
double t = 10 * z + 50;
//Console.WriteLine(listScore[i] + " To T Score : " + t);
Console.WriteLine(listScore[i] + " To T Score : " + t + " -> grade : " + CalGrade((float)t, ls));
}
Console.ReadLine();
}
จะได้ผลเกรดดังนี้อยากได้โค้ดทั้งหมด ติดต่อผมทางได้นี้นะครับ (ไม่มีค่าใช้จ่ายใดๆแค่อยากรู้ว่ามีคนเอาใช้จริงๆหรือเปล่า)
Facebook: https://www.facebook.com/DotNetUnderLine
E-mail: agkasit.ecp7@gmail.com
วันพฤหัสบดีที่ 26 กุมภาพันธ์ พ.ศ. 2558
elfinder Browser file use getFileCallback [worked]
elfinder Browser file use getFileCallback
//html
//script
$('#select-button').click(function () {
var f = $('#elfinder').elfinder({
url: '/connector', // connector route defined in \App_Start\RouteConfig.cs
lang: 'en',
onlyMimes: ["image"], // display all images
customData: { folder: "teacher", subFolder: null },
height: 490,
docked: false,
dialog: { width: 400, modal: true },
closeOnEditorCallback: true,
getFileCallback: function (url) {
console.log(url.url);
$('#new_file').val(url.url);
// CLOSE ELFINDER HERE
$('#elfinder').remove(); //remove Elfinder
location.reload(); //reload Page for second selection
}
}).elfinder('instance');
});
});
link: http://stackoverflow.com/questions/20400817/close-elfinder-programatically-after-file-selection?answertab=active#tab-top
วันจันทร์ที่ 16 กุมภาพันธ์ พ.ศ. 2558
c# Grade Calculator (Using List Object)
ไม่มีความคิดเห็น:
Posted by
Aagkasit Tontan
at
02:37
Labels:
c#,
Grade Calculator,
Grade Calculator Custom,
Grade Calculator Dynamic,
List,
List Object
//Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GradeCalculatorUsingListObject
{
class Program
{
static void Main(string[] args)
{
//add list Grade
List ls = new List();
ls.Add(new Grades(49f, "F"));
ls.Add(new Grades(49.5f, "D"));
ls.Add(new Grades(55f, "D+"));
ls.Add(new Grades(60f, "C"));
ls.Add(new Grades(65f, "P"));
ls.Add(new Grades(70f, "B"));
ls.Add(new Grades(75f, "B+"));
ls.Add(new Grades(80f, "A"));
//
//float point = 49f;
Console.WriteLine("49.5f : grade : " + CalGrade(49.5f, ls));
Console.WriteLine("0 : grade : " + CalGrade(0, ls));
Console.WriteLine("72 : grade : " + CalGrade(72, ls));
Console.WriteLine("70 : grade : " + CalGrade(70, ls));
Console.WriteLine("43 : grade : " + CalGrade(43, ls));
Console.WriteLine("28 : grade : " + CalGrade(28, ls));
Console.WriteLine("97 : grade : " + CalGrade(97, ls));
Console.WriteLine("23 : grade : " + CalGrade(23, ls));
Console.WriteLine("84 : grade : " + CalGrade(84, ls));
Console.WriteLine("64 : grade : " + CalGrade(64, ls));
Console.WriteLine("72 : grade : " + CalGrade(74, ls));
Console.ReadLine();
}
public static string CalGrade(float point, List list)
{
//int[] arr = { 800, 11, 50, 771, 649, 770, 240, 9 };
int current = 0;
int next = 0;
for (int write = 0; write < list.Count - 1; write++)
{
current = write;
next = current + 1;
//55 <= 56 <= 60
if (list[current].score <= point && point <= list[next].score)
{
if (list[current].score >= point)
{
return list[current].grade;
}
else if (list[next].score <= point)
{
return list[next].grade;
}
else if (list[next].score >= point)
{
return list[current].grade;
}
}
else if (list[current].score > point)
{
return list[current].grade;
}
else if (list[current].score <= point && point >= list[next].score)
{
if (current == (list.Count - 2))
{
return list[current + 1].grade;
}
}
}
return null;
}
public class Grades
{
public float score { set; get; }
public string grade { set; get; }
public Grades(float score, string grade)
{
this.score = score;
this.grade = grade;
}
}
}
}
download code full : https://www.dropbox.com/s/1e41ezbnxl0i5r0/GradeCalculatorUsingListObject.rar?dl=0
Asp.net Mvc4 Could not load file or assembly 'WebGrease"
ไม่มีความคิดเห็น:
Posted by
Aagkasit Tontan
at
00:38
Labels:
Asp.net Mvc4,
Could not load file or assembly
Could not load file or assembly 'WebGrease, Version=1.5.1.25624, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
answer worked : http://stackoverflow.com/questions/19851912/could-not-load-file-or-assembly-webgrease-version-1-5-1-25624-culture-neutral
answer worked : http://stackoverflow.com/questions/19851912/could-not-load-file-or-assembly-webgrease-version-1-5-1-25624-culture-neutral
สมัครสมาชิก:
ความคิดเห็น (Atom)