Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > .NET Framework > Forum > อธิบายการทำงานของโปรแกรมหน่อยครับผมยังไม่ค่อยเข้าใจ ภาษาC# Win (Windows App)



 

อธิบายการทำงานของโปรแกรมหน่อยครับผมยังไม่ค่อยเข้าใจ ภาษาC# Win (Windows App)

 



Topic : 070726



โพสกระทู้ ( 3 )
บทความ ( 0 )



สถานะออฟไลน์




Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WindowsFormsApplication1
{
    class DateDifference
    {
        private DateTime _FromDate;
        private DateTime _ToDate;
        private int _Year = 0;
        private int _Month = 0;
        private int _Day = 0;

        public int Year
        {
            get { return _Year; }
            set { _Year = value; }
        }
        public int Month
        {
            get { return _Month; }
            set { _Month = value; }
        }
        public int Day
        {
            get { return _Day; }
            set { _Day = value; }
        }
        public DateTime FromDate
        {
            get { return _FromDate; }
            set { _FromDate = value; }
        }
        public DateTime ToDate
        {
            get { return _ToDate; }
            set { _ToDate = value; }
        }

        /// <summary>
        /// defining Number of days in month; index 0=> january and 11=> December
        /// february contain either 28 or 29 days, that's why here value is -1
        /// which wil be calculate later.
        /// </summary>
        private int[] monthDay = new int[12] { 31, -1, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

        public DateDifference(DateTime argFromDate)
        {
            _ToDate = DateTime.Now;
            _FromDate = argFromDate;
            CalcDifferenceDate();
        }

        public DateDifference(DateTime argFromDate, DateTime argToDate)
        {
            _ToDate = argToDate;
            _FromDate = argFromDate;
            CalcDifferenceDate();
        }

        private void SwapDate(ref DateTime LeftDate, ref DateTime RightDate)
        {
            DateTime tempDate;
            if (LeftDate > RightDate)
            {
                tempDate = LeftDate;
                LeftDate = RightDate;
                RightDate = tempDate;
            }
            else
            {
                LeftDate = LeftDate;
                RightDate = RightDate;
            }
        }

        private void CalcDifferenceDate()
        {

            SwapDate(ref _FromDate, ref _ToDate);
            int carryFlag = 0;

            // ***************************
            // Day calculation 
            if (this.FromDate.Day > this.ToDate.Day)
                carryFlag = this.monthDay[this.FromDate.Month - 1];

            // febuary detect
            if (carryFlag == -1)
            {
                if (CheckedLeapYear(this.FromDate))
                    // leap year february contain 29 days
                    carryFlag = 29;
                else
                    carryFlag = 28;
            }

            if (carryFlag != 0)
            {
                this.Day = (this.ToDate.Day + carryFlag) - this.FromDate.Day;
                carryFlag = 1;
            }
            else
                this.Day = this.ToDate.Day - this.FromDate.Day;

            // ***************************
            // Month calculation 

            if ((this.FromDate.Month + carryFlag) > this.ToDate.Month)
            {
                this.Month = (this.ToDate.Month + 12) - (this.FromDate.Month + carryFlag);
                carryFlag = 1;
            }
            else
            {
                this.Month = this.ToDate.Month - (this.FromDate.Month + carryFlag);
                carryFlag = 0;
            }

            this.Year = this.ToDate.Year - (this.FromDate.Year + carryFlag);
        } 


        private bool CheckedLeapYear(DateTime checkedDate)
        {
            int myYear = checkedDate.Year;
            return (((myYear % 4) == 0) && ((myYear % 100) != 0) || ((myYear % 400) == 0));
        }

        public string ToString(string argYearUnit, string argMonthUnit, string argDayUnit)
        {
            string retStr = string.Empty;
            if (this.Year > 0)
                retStr = retStr + string.Format("{0} {1} ", this.Year.ToString("#,##0"), argYearUnit);
            if (this.Month > 0)
                retStr = retStr + string.Format("{0} {1} ", this.Month.ToString("#,##0"), argMonthUnit);
            if (this.Day > 0)
                retStr = retStr + string.Format("{0} {1} ", this.Day.ToString("#,##0"), argDayUnit);
            return retStr.Trim();
        }

        public override string ToString()
        {
            return this.ToString("ปี ", "เดือน ", "วัน ");

        }
    }
}





Tag : .NET, Win (Windows App), C#, VS 2010 (.NET 4.x)







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2011-12-21 21:23:07 By : pandatudtu View : 858 Reply : 2
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

น่าจะเป็น function เกี่ยวกับการจัดการวันที่ เช่น diff หรือ compare ครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-12-21 21:28:22 By : webmaster
 


 

No. 2



โพสกระทู้ ( 3 )
บทความ ( 0 )



สถานะออฟไลน์


ใช่ครับคือเป็นฟังชั่นในการคำนวนวันอะครับผมอยากทราบการทำงานแค่ช่วงนี้อะครับว่ามันทำการคำนวณวันยังไงถึงได้วันตาปฏิทินอะครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-12-21 22:14:15 By : pandatudtu
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : อธิบายการทำงานของโปรแกรมหน่อยครับผมยังไม่ค่อยเข้าใจ ภาษาC# Win (Windows App)
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่