แสดงบทความที่มีป้ายกำกับ c# แสดงบทความทั้งหมด
แสดงบทความที่มีป้ายกำกับ c# แสดงบทความทั้งหมด
วันจันทร์ที่ 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"; }Scriptupload Folder
Controllor
public ActionResult uploadFolder() { return View(); } [HttpPost] public async TaskWeb configUploadHomeReport() { 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; }
Result
Derivative
วันอังคารที่ 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
วันจันทร์ที่ 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 Listls = 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
สมัครสมาชิก:
บทความ (Atom)