コード例 #1
0
    public List <clsTimeLogEntry> GetAllEntries(TimeLogDate beginDate, TimeLogDate endDate)
    {
        List <clsTimeLogEntry> entries = new List <clsTimeLogEntry>();

        entries = clsServer.GetAllEntries(beginDate, endDate);
        return(entries);
    }
コード例 #2
0
    private void btnRefresh_Click(object sender, EventArgs e)
    {
        try
        {
            if (txtBeginDate.Text == "" && TimeLogDate.TryParse(txtBeginDate.Text, out mBeginDate) == false)
            {
                mBeginDate = new TimeLogDate(1, 1, 1);
            }
            else
            {
                mBeginDate = TimeLogDate.Parse(txtBeginDate.Text);
            }

            if (txtEndDate.Text == "" && TimeLogDate.TryParse(txtEndDate.Text, out mEndDate) == false)
            {
                mEndDate = new TimeLogDate(9999, 12, 31);
            }
            else
            {
                mEndDate = TimeLogDate.Parse(txtEndDate.Text);
            }
        }
        catch
        {
            messageBoxOK("Must enter a valid date or leave it empty.");
        }

        refreshView();
    }
コード例 #3
0
 public void Deserialize(string serializedString)
 {
     string[] states = serializedString.Split('\t');
     mEntryID          = int.Parse(states[0]);
     EmployeeID        = states[1];
     HoursWorked       = double.Parse(states[2]);
     DateWorked        = TimeLogDate.Parse(states[3]);
     Description       = states[4];
     Billable          = bool.Parse(states[5]);
     DateTimeLastMaint = DateTime.Parse(states[6]);
 }
コード例 #4
0
    private void frmMain_Load(object sender, EventArgs e)
    {
        DateTime now = DateTime.Now;

        txtBeginDate.Text = now.ToShortDateString();
        txtEndDate.Text   = now.ToShortDateString();
        mBeginDate        = new TimeLogDate(now.Year, now.Month, now.Day);
        mEndDate          = new TimeLogDate(now.Year, now.Month, now.Day);

        refreshView();
    }
コード例 #5
0
    public void RestoreStateFromQuery(clsQueryResults results)
    {
        mEntryID    = (int)results.GetColValue("EntryID");
        EmployeeID  = (string)results.GetColValue("EmployeeID");
        HoursWorked = (double)results.GetColValue("HoursWorked");
        DateTime date = (DateTime)results.GetColValue("DateWorked");

        DateWorked        = new TimeLogDate(date.Year, date.Month, date.Day);
        Description       = (string)results.GetColValue("Description");
        Billable          = (bool)results.GetColValue("Billable");
        DateTimeLastMaint = (DateTime)results.GetColValue("DateTimeLastMaint");
    }
コード例 #6
0
 public static bool TryParse(string dateString, out TimeLogDate timeLogDate)
 {
     timeLogDate = new TimeLogDate();
     try
     {
         TimeLogDate date = TimeLogDate.Parse(dateString);
         timeLogDate = date;
         return(true);
     }
     catch
     {
         return(false);
     }
 }
コード例 #7
0
 public static TimeLogDate Parse(string dateString)
 {
     try
     {
         TimeLogDate timeLogDate = new TimeLogDate();
         DateTime    date        = DateTime.Parse(dateString);
         timeLogDate.Year  = date.Year;
         timeLogDate.Month = date.Month;
         timeLogDate.Day   = date.Day;
         return(timeLogDate);
     }
     catch
     {
         throw new Exception("String is not a valid date.");
     }
 }
コード例 #8
0
    private void getAllEntries()
    {
        TimeLogDate beginDate = TimeLogDate.Parse(Request.QueryString["beginDate"]);
        TimeLogDate endDate   = TimeLogDate.Parse(Request.QueryString["endDate"]);

        List <clsTimeLogEntry> entries = mTimeLogList.GetAllEntries(beginDate, endDate);

        string responseString = "";

        foreach (clsTimeLogEntry entry in entries)
        {
            responseString += entry.Serialize() + "\n";
        }

        Response.Write(responseString);
    }
コード例 #9
0
    public List <clsTimeLogEntry> GetAllEntries(TimeLogDate beginDate, TimeLogDate endDate)
    {
        List <clsTimeLogEntry> listBetweenDates = new List <clsTimeLogEntry>();
        string sql;

        using (clsDatabase db = new clsDatabase(mConnectionString))
            using (clsQueryResults results = new clsQueryResults())
            {
                db.Open();

                sql = "SELECT COUNT(*) AS NumRecords FROM TimeLogEntries WHERE DateWorked >= "
                      + db.ToSql(beginDate)
                      + " AND DateWorked <= " + db.ToSql(endDate);

                results.Open(db, sql);
                int count = (int)results.GetColValue("NumRecords");

                if (count > 500)
                {
                    throw new clsTooManyRecordsException("More than 500 matching records found.");
                }

                results.Close();

                sql = "SELECT * FROM TimeLogEntries WHERE DateWorked >= "
                      + db.ToSql(beginDate)
                      + " AND DateWorked <=" + db.ToSql(endDate)
                      + " ORDER BY DateWorked DESC, EmployeeID, HoursWorked";

                results.Open(db, sql);

                while (results.EOF == false)
                {
                    clsTimeLogEntry entry = new clsTimeLogEntry();
                    entry.RestoreStateFromQuery(results);
                    listBetweenDates.Add(entry);
                    results.MoveNext();
                }
            }

        return(listBetweenDates);
    }
コード例 #10
0
    public static List <clsTimeLogEntry> GetAllEntries(TimeLogDate beginDate, TimeLogDate endDate)
    {
        string action         = "getAllEntries";
        string arguments      = "&beginDate=" + beginDate.ToShortDateString() + "&endDate=" + endDate.ToShortDateString();
        string url            = createUrl(action, arguments);
        string responseString = getResponseString(url);

        List <clsTimeLogEntry> entries = new List <clsTimeLogEntry>();

        string[] serializedResponses = responseString.Split('\n');

        foreach (string serializedResponse in serializedResponses)
        {
            if (serializedResponse != "")
            {
                clsTimeLogEntry entry = new clsTimeLogEntry();
                entry.Deserialize(serializedResponse);
                entries.Add(entry);
            }
        }

        return(entries);
    }
コード例 #11
0
    private void btnOK_Click(object sender, System.EventArgs e)
    {
        if (validateForm() == false)
        {
            return;
        }

        mEntry.EmployeeID  = txtEmployeeID.Text;
        mEntry.DateWorked  = TimeLogDate.Parse(txtDateWorked.Text);
        mEntry.HoursWorked = double.Parse(cboHoursWorked.Text);
        mEntry.Billable    = chkBillable.Checked;
        mEntry.Description = txtDescription.Text;

        if (mMode == "Add")
        {
            mTimeLogList.Add(mEntry);
        }
        else
        {
            mTimeLogList.Update(mEntry);
        }

        DialogResult = DialogResult.OK;
    }
コード例 #12
0
 public string ToSql(TimeLogDate dateValue)
 {
     return("'" + dateValue.Year.ToString() + "-" + dateValue.Month.ToString() + "-" + dateValue.Day.ToString() + "'");
 }
コード例 #13
0
    private bool validateForm()
    {
        if (txtEmployeeID.Text == "")
        {
            frmMain.messageBoxOK("Employee ID is required.");
            txtEmployeeID.Focus();
            return(false);
        }

        // Check Date Worked.

        TimeLogDate dateWorked = new TimeLogDate();

        if (TimeLogDate.TryParse(txtDateWorked.Text, out dateWorked) == false)
        {
            frmMain.messageBoxOK("Data Worked must be a valid date.");
            txtDateWorked.Focus();
            return(false);
        }

        DateTime dateWorkedDateTime = DateTime.Parse(dateWorked.ToShortDateString());

        TimeSpan diff = DateTime.Now.Date.Subtract(dateWorkedDateTime);

        if (dateWorkedDateTime > DateTime.Now.Date ||
            diff.TotalDays > 7)
        {
            frmMain.messageBoxOK("Date Worked cannot be > today's date or more than 7 days in the past.");
            txtDateWorked.Focus();
            return(false);
        }

        // Check Hours Worked.

        double       hoursWorked;
        const string cInvalidHoursWorked = "Hours worked must be in the range .25 through 4.00 and be in .25 hour increments.";

        if (double.TryParse(cboHoursWorked.Text, out hoursWorked) == false)
        {
            frmMain.messageBoxOK(cInvalidHoursWorked);
            cboHoursWorked.Focus();
            return(false);
        }

        if (hoursWorked < .25 ||
            hoursWorked > 4 ||
            (hoursWorked % .25) != 0)
        {
            frmMain.messageBoxOK(cInvalidHoursWorked);
            cboHoursWorked.Focus();
            return(false);
        }

        // Check Description.

        if (txtDescription.Text.Length < 25)
        {
            frmMain.messageBoxOK("Description is required and must contain at least 25 characters.");
            txtDescription.Focus();
            return(false);
        }

        // If we get this far, then everything is OK.

        return(true);
    }