Monday, August 21, 2006

Form DateCalculator

Sometimes I need to calculate date, this form can help
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DateCalculator
{
    public partial class FrmDateCalculator : Form
    {
        public FrmDateCalculator()
        {
            InitializeComponent();
        }

        private void btnIncrease_Click(object sender, EventArgs e)
        {
            txtResult.Text = dtpDate.Value.AddDays((double)nddDays.Value).ToShortDateString();
        }

        private void btnDecrease_Click(object sender, EventArgs e)
        {
            txtResult.Text = dtpDate.Value.AddDays(-(double)nddDays.Value).ToShortDateString();
        }

        private void btnTryFeb_Click(object sender, EventArgs e)
        {
            DateTime dtm = new DateTime(DateTime.Today.Year, 2, 30);
            txtResult.Text = dtm.ToShortDateString();
        }

        private void btnGetPrevMonday_Click(object sender, EventArgs e)
        {
            DateTime dtmStart = DateTime.Today;
            DateTime dtmValue = dtpDate.Value;
            int intDayOfWeek = Convert.ToInt32(dtmValue.DayOfWeek);

            if (intDayOfWeek == 0)
            {
                dtmValue = dtmValue.AddDays(-1);
                intDayOfWeek = 6;
            }
            dtmStart = dtmValue.AddDays(-((intDayOfWeek+6)-7));
            
            DateTime dtmEnd = dtmStart.AddDays(6);
            MessageBox.Show(dtmStart.ToString("dd/MM/yyyy") + " - " + dtmEnd.ToString("dd/MM/yyyy"));
        }

        private void btnMinValue_Click(object sender, EventArgs e)
        {
            DateTime dtm1 = DateTime.MinValue;
            DateTime dtm2 = new DateTime(1900, 1, 1);
            bool blnEqual = dtm1 == dtm2;
            MessageBox.Show(dtm1.ToString("dd/MM/yyyy") + " == " + dtm2.ToString("dd/MM/yyyy") + " -> " + blnEqual.ToString());
        }
    }
    
}
As you can see, this form already using "partial" keyword. With "partial", the definition of a class, struct or interface can be splitted into multiple files.

Saturday, August 12, 2006

CVS and His Tortoise

So far, for source code repository or simply called "source control", I only using Visual Sourcesafe. My new employer is not only using Microsoft Technologies, in fact our main product is written in Borland Delphi. How we manage the source code? If you guess that we copy to another folder, backup it or zip-it, you guess it correctly. Now, this is not KISS (Keep it simple, stupid) anymore, this is really-really-really stupid. We are in urgency to look for a source control. And we stumbled upon CVS and it's Windows client; Tortoise CVS.
If you're a Windows user using CVS, and you're currently not using Tortoise CVS, I suggest you better to look into it. It integrates nicely with your Windows Explorer, ease your job significantly. Currently they are in a 1.9.x release, but I'm using the 1.8.x version (as in x.y.z, if y is an even number, it's considered stable release). Check their website for more information (and download)