protected void cmdNew_Click(object sender, EventArgs e)
 {
     txtDate.Text = "";
     txtHours.Text = "0";
     ddlDepartment.SelectedIndex = -1;
     ddlResoures.SelectedIndex = -1;
     ddlProject.SelectedIndex = -1;
     txtDescription.Text = "";
     lblError.Text = "";
     _currentProjectHours = null;
     Session["CurrentProjectHours"] = _currentProjectHours;
     RefreshEntriesDateSpread();
     updEntries.Update();
 }
        protected void cmdSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                if (ddlProject.SelectedIndex == 0)
                {
                    lblProjectCheck.Text = "Please select a project.";
                    Page.SetFocus(ddlProject);
                    return;
                }
                lblProjectCheck.Text = "";
                if (ddlResoures.SelectedIndex == 0)
                {
                    lblResouresCheck.Text = "Please select a resource type.";
                    Page.SetFocus(ddlResoures);
                    return;
                }
                lblResouresCheck.Text = "";

                if (ddlDepartment.SelectedIndex == 0)
                {
                    lblDepartmentCheck.Text = "Please select a department.";
                    Page.SetFocus(ddlDepartment);
                    return;
                }
                lblDepartmentCheck.Text = "";
                if (txtDate.Text == "" || txtHours.Text == "" || txtHours.Text == "0")
                {
                    lblError.Text = "Please fill in all fields";
                    return;
                }
                if (txtDate.Text == "")
                {
                    lblDateCheck.Text = "Please select a date.";
                    Page.SetFocus(txtDate);
                    return;
                }
                lblDateCheck.Text = "";
                if (txtHours.Text == "" || txtHours.Text == "0")
                {
                    lblHoursCheck.Text = "Please input your hours.";
                    Page.SetFocus(txtHours);
                    return;
                }
                lblHoursCheck.Text = "";

                _currentProjectHours = (TimeProjectHours)Session["CurrentProjectHours"];
                bool insertGood = false;
                if (_currentProjectHours == null)
                {
                    //new projectHours object
                    TimeProjectHours projectHours = TimeProjectHours.New();

                    //fill object with data
                    projectHours.DateOfWork = DateTime.ParseExact(txtDate.Text, "M/d/yyyy", CultureInfo.InvariantCulture);
                    projectHours.HoursOfWork = Convert.ToInt32(txtHours.Text);
                    projectHours.TimeDepartmentID = Convert.ToInt32(ddlDepartment.SelectedValue);
                    projectHours.TimeResourceID = Convert.ToInt32(ddlResoures.SelectedValue);
                    projectHours.TimeEmployeeID = (int)Session["TimeEmployeeID"];
                    projectHours.TimeProjectID = Convert.ToInt32(ddlProject.SelectedValue);
                    projectHours.Description = txtDescription.Text;
                    projectHours.Status = 1;
                    projectHours.Type = 1;

                    //save the new projectHours
                    projectHours.Save();

                    insertGood = projectHours.TimeProjectHoursID > 0;
                }
                else
                {
                    _currentProjectHours.DateOfWork = DateTime.ParseExact(txtDate.Text, "M/d/yyyy", CultureInfo.InvariantCulture);
                    _currentProjectHours.HoursOfWork = Convert.ToInt32(txtHours.Text);
                    _currentProjectHours.TimeDepartmentID = Convert.ToInt32(ddlDepartment.SelectedValue);
                    _currentProjectHours.TimeResourceID = Convert.ToInt32(ddlResoures.SelectedValue);
                    _currentProjectHours.TimeEmployeeID = (int)Session["TimeEmployeeID"];
                    _currentProjectHours.TimeProjectID = Convert.ToInt32(ddlProject.SelectedValue);
                    _currentProjectHours.Description = txtDescription.Text;
                    _currentProjectHours.Status = 1;
                    _currentProjectHours.Type = 1;

                    //save the new projectHours
                    _currentProjectHours.Save();

                    insertGood = _currentProjectHours.TimeProjectHoursID > 0;
                }

                if (insertGood)
                {
                    txtDate.Text = "";
                    txtHours.Text = "0";
                    ddlDepartment.SelectedIndex = -1;
                    ddlResoures.SelectedIndex = -1;
                    ddlProject.SelectedIndex = -1;
                    txtDescription.Text = "";
                    lblError.Text = "";
                    _currentProjectHours = null;
                    Session["CurrentProjectHours"] = _currentProjectHours;
                    RefreshEntriesDateSpread();
                    updEntries.Update();

                    lblSuccessTitle.Text = "Success!";
                    lblSuccessMessage.Text = "Successfully submitted data!";
                    mpSuccess.Show();
                }
                else
                {
                    lblSuccessTitle.Text = "Error!";
                    lblSuccessMessage.Text = "Error submitting data!";
                    mpSuccess.Show();
                }
            }
            catch (Exception ex)
            {
                lblSuccessTitle.Text = "Error!";
                lblSuccessMessage.Text = "Error submitting data! " + ex.Message;
                mpSuccess.Show();
            }
        }
        protected void rptCustomers_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            try
            {
                if (e.CommandName == "Edit")
                {
                    string allKeys = Convert.ToString(e.CommandArgument);
                    int pkID = Convert.ToInt32(allKeys);
                    _currentProjectHours = TimeProjectHours.Read(pkID);
                    Session["CurrentProjectHours"] = _currentProjectHours;
                    txtDate.Text = _currentProjectHours.DateOfWork.ToString("M/d/yyyy", CultureInfo.InvariantCulture);
                    txtHours.Text = _currentProjectHours.HoursOfWork.ToString();
                    ddlDepartment.SelectedValue = ddlDepartment.Items.FindByValue(_currentProjectHours.TimeDepartmentID.ToString()).Value;
                    ddlResoures.SelectedValue = ddlResoures.Items.FindByValue(_currentProjectHours.TimeResourceID.ToString()).Value;
                    ddlProject.SelectedValue = ddlProject.Items.FindByValue(_currentProjectHours.TimeProjectID.ToString()).Value;
                    txtDescription.Text = _currentProjectHours.Description;
                    ddlProject.Focus();
                }

                if (e.CommandName == "Delete")
                {
                    string allKeys = Convert.ToString(e.CommandArgument);
                    int pkID = Convert.ToInt32(allKeys);
                    _currentProjectHours = TimeProjectHours.Read(pkID);
                    _currentProjectHours.Delete();
                    _currentProjectHours = null;
                    Session["CurrentProjectHours"] = _currentProjectHours;
                    RefreshEntriesDateSpread();
                    updEntries.Update();
                    ddlProject.Focus();
                    lblSuccessMessage.Text = "Successfully deleted data!";
                    mpSuccess.Show();
                }
            }
            catch (Exception ex)
            {

            }
        }
 protected void rptCustomers_ItemCommand(object source, RepeaterCommandEventArgs e)
 {
     if (e.CommandName == "Delete")
     {
         string allKeys = Convert.ToString(e.CommandArgument);
         int pkID = Convert.ToInt32(allKeys);
         _currentProjectHours = TimeProjectHours.Read(pkID);
         _currentProjectHours.Delete();
         _currentProjectHours = null;
         Session["CurrentProjectHours"] = _currentProjectHours;
         //RefreshEntries();
         //updEntries.Update();
     }
 }