private void Save()
        {
            // Validate data
            bool validData = false;

            Page.Validate("General");
            if (Page.IsValid)
            {
                validData = true;

                // ... Validate notes tab
                if (ValidateNotesFooter())
                {
                    Page.Validate("notesDataAdd");
                    if (!Page.IsValid)
                    {
                        validData = false;
                    }
                }

                Page.Validate("notesDataEdit");
                if (!Page.IsValid)
                {
                    validData = false;
                }
            }

            // For valid data
            if (validData)
            {
                // Notes Gridview, if the gridview is edition mode
                if (grdNotes.EditIndex >= 0)
                {
                    grdNotes.UpdateRow(grdNotes.EditIndex, true);
                }

                // Save cost and notes data
                GrdNotesAdd();

                // Costs Gridview, if the gridview is edition mode
                if (grdCosts.EditIndex >= 0)
                {
                    grdCosts.UpdateRow(grdCosts.EditIndex, true);
                }

                // Save costs data
                GrdCostsAdd();

                // Costs Exceptions Gridview, if the gridview is edition mode
                if (grdCostsExceptions.EditIndex >= 0)
                {
                    grdCostsExceptions.UpdateRow(grdCostsExceptions.EditIndex, true);
                }

                // Save costs exceptions data
                GrdCostsExceptionsAdd();

                // Save data
                int companyId = Int32.Parse(hdfCompanyId.Value);
                int employeeId = Int32.Parse(hdfCurrentEmployeeId.Value);

                // ... Get basic employee data
                string newFirstName = tbxFisrtName.Text.Trim();
                string newLastName = tbxLastName.Text.Trim();
                string newEmail = tbxeMail.Text.Trim();
                string newType = ddlType.SelectedValue;
                string newState = ddlState.SelectedValue;
                bool newIsSalesman = ckbxIsSalesman.Checked;
                bool newRequestProjectTime = ckbxRequestTimesheet.Checked;
                bool newSalaried = ckbxSalaried.Checked;
                bool newAssignableSrs = ckbxAssignableSrs.Checked;
                string newJobClass = ddlJobClassType.SelectedValue;
                string newCategory = ddlCategory.SelectedValue;
                string newPersonalAgency = ddlPersonalAgency.SelectedValue;
                bool newVacationsManager = ckbxVacationsManager.Checked;
                bool newApproveTimesheets = ckbxApproveTimesheets.Checked;
                string newCrew = ""; if (ddlCrew.SelectedValue != "") newCrew = ddlCrew.SelectedValue;

                // Update basic information data
                EmployeeInformationBasicInformation employeeInformationBasicInformation = new EmployeeInformationBasicInformation(employeeInformationTDS);
                employeeInformationBasicInformation.Update(employeeId, newFirstName, newLastName, newType, newState, newIsSalesman, newRequestProjectTime, newSalaried, newEmail, newAssignableSrs, newJobClass, newCategory, newPersonalAgency, newVacationsManager, newApproveTimesheets, newCrew);

                // Update categories approve timesheets data
                EmployeeInformationCategoryApproveTimesheetsInformation employeeInformationCategoryApproveTimesheetsInformation = new EmployeeInformationCategoryApproveTimesheetsInformation(employeeInformationTDS);
                employeeInformationCategoryApproveTimesheetsInformation.Update(employeeId, "Field", ckbxField.Checked);
                employeeInformationCategoryApproveTimesheetsInformation.Update(employeeId, "Field 44", ckbxField44.Checked);
                employeeInformationCategoryApproveTimesheetsInformation.Update(employeeId, "Mechanic/Manufactoring", ckbxMechanicManufactoring.Checked);
                employeeInformationCategoryApproveTimesheetsInformation.Update(employeeId, "Office/admin", ckbxOfficeAdmin.Checked);
                employeeInformationCategoryApproveTimesheetsInformation.Update(employeeId, "Special Forces", ckbxSpecialForces.Checked);

                // Insert type to history
                EmployeeInformationTypeHistoryInformation employeeInformationTypeHistoryInformation = new EmployeeInformationTypeHistoryInformation(employeeInformationTDS);
                employeeInformationTypeHistoryInformation.Insert(employeeId, DateTime.Now, newType, false, companyId, false);

                // Store datasets
                Session["employeeInformationTDS"] = employeeInformationTDS;

                // Update database
                UpdateDatabase();

                ViewState["update"] = "yes";

                // Redirect
                string url = "";
                if (Request.QueryString["source_page"] == "employees_navigator2.aspx" )
                {
                    url = "./employees_navigator2.aspx?source_page=employees_edit.aspx&employee_id=" + hdfCurrentEmployeeId.Value + GetNavigatorState() + "&update=yes";
                }

                if (Request.QueryString["source_page"] == "employees_summary.aspx")
                {
                    string activeTab = hdfActiveTab.Value;
                    url = "./employees_summary.aspx?source_page=employees_edit.aspx&employee_id=" + hdfCurrentEmployeeId.Value + "&active_tab=" + activeTab + GetNavigatorState() + "&update=yes";
                }

                Response.Redirect(url);
            }
        }
        private void UpdateDatabase()
        {
            int companyId = Int32.Parse(hdfCompanyId.Value);
            int employeeId = Int32.Parse(hdfCurrentEmployeeId.Value);

            DB.Open();
            DB.BeginTransaction();
            try
            {
                // Save type history information
                EmployeeInformationTypeHistoryInformation employeeInformationTypeHistoryInformation = new EmployeeInformationTypeHistoryInformation(employeeInformationTDS);
                employeeInformationTypeHistoryInformation.Save(employeeId, companyId);

                // Save notes information
                EmployeeInformationNoteInformation employeeInformationNoteInformation = new EmployeeInformationNoteInformation(employeeInformationTDS);
                employeeInformationNoteInformation.Save(companyId);

                // Save costs information
                EmployeeInformationCostInformation employeeInformationCostInformation = new EmployeeInformationCostInformation(employeeInformationTDS);
                employeeInformationCostInformation.Save(companyId);

                // Save costs exceptions information
                EmployeeInformationCostExceptionsInformation employeeInformationCostExceptionsInformation = new EmployeeInformationCostExceptionsInformation(employeeInformationTDS);
                employeeInformationCostExceptionsInformation.Save(companyId, employeeId);

                // Save categories approve timesheets information
                EmployeeInformationCategoryApproveTimesheetsInformation employeeInformationCategoryApproveTimesheetsInformation = new EmployeeInformationCategoryApproveTimesheetsInformation(employeeInformationTDS);
                employeeInformationCategoryApproveTimesheetsInformation.Save();

                // Save employee information
                EmployeeInformationBasicInformation employeeInformationBasicInformation = new EmployeeInformationBasicInformation(employeeInformationTDS);
                employeeInformationBasicInformation.Save(companyId);

                DB.CommitTransaction();

                // Store datasets
                employeeInformationTDS.AcceptChanges();
                Session["employeeInformationTDS"] = employeeInformationTDS;
            }
            catch (Exception ex)
            {
                DB.RollbackTransaction();

                string url = string.Format("./../../error_page.aspx?error={0}", ex.Message.Replace('\n', ' '));
                Response.Redirect(url);
            }
        }
        private void Delete()
        {
            int currentEmployeeId = int.Parse(hdfCurrentEmployeeId.Value);

            // Delete type history
            EmployeeInformationTDS employeeInformationTDS = new EmployeeInformationTDS();
            EmployeeInformationTypeHistoryInformation employeeInformationTypeHistoryInformation = new EmployeeInformationTypeHistoryInformation(employeeInformationTDS);
            employeeInformationTypeHistoryInformation.DeleteAll(currentEmployeeId);

            // Delete employee
            EmployeeNavigator employeeNavigator = new EmployeeNavigator(employeeNavigatorTDS);
            employeeNavigator.Delete(currentEmployeeId);

            // Store datasets
            Session["employeeNavigatorTDS"] = employeeNavigatorTDS;
            Session["employeeInformationTDS"] = employeeInformationTDS;
        }