/// <summary>
        /// Save all Units Costing Sheets
        /// </summary>
        /// <param name="companyId">companyId</param>
        /// <param name="costingSheetId">costingSheetId</param>
        public void Save(int companyId, int costingSheetId)
        {
            ProjectCostingSheetInformationTDS unitsInformationChanges = (ProjectCostingSheetInformationTDS)Data.GetChanges();

            if (unitsInformationChanges.UnitsInformation.Rows.Count > 0)
            {
                ProjectCostingSheetInformationUnitsInformationGateway projectCostingSheetInformationUnitsInformationGateway = new ProjectCostingSheetInformationUnitsInformationGateway(unitsInformationChanges);

                foreach (ProjectCostingSheetInformationTDS.UnitsInformationRow row in (ProjectCostingSheetInformationTDS.UnitsInformationDataTable)unitsInformationChanges.UnitsInformation)
                {
                    // Insert new costing sheet Units
                    if ((!row.Deleted) && (!row.InDatabase))
                    {
                        ProjectCostingSheetUnits units = new ProjectCostingSheetUnits(null);
                        units.InsertDirect(costingSheetId, row.Work_, row.UnitID, row.RefID, row.UnitOfMeasurement, row.Quantity, row.CostCad, row.TotalCostCad, row.CostUsd, row.TotalCostUsd, row.Deleted, row.COMPANY_ID, row.StartDate, row.EndDate, row.Function_);
                    }

                    // Update costing sheet Units
                    if ((!row.Deleted) && (row.InDatabase))
                    {
                        string work_ = row.Work_;
                        int unitId = row.UnitID;
                        int refId = row.RefID;
                        bool deleted = false;

                        //original values
                        string originalUnitOfMeasurement = projectCostingSheetInformationUnitsInformationGateway.GetUnitOfMeasurementOriginal(costingSheetId, work_, unitId, refId);
                        double originalQuantity = projectCostingSheetInformationUnitsInformationGateway.GetQuantityOriginal(costingSheetId, work_, unitId, refId);
                        decimal originalCostCad = projectCostingSheetInformationUnitsInformationGateway.GetCostCadOriginal(costingSheetId, work_, unitId, refId);
                        decimal originalTotalCostCad = projectCostingSheetInformationUnitsInformationGateway.GetTotalCostCadOriginal(costingSheetId, work_, unitId, refId);
                        decimal originalCostUsd = projectCostingSheetInformationUnitsInformationGateway.GetCostUsdOriginal(costingSheetId, work_, unitId, refId);
                        decimal originalTotalCostUsd = projectCostingSheetInformationUnitsInformationGateway.GetTotalCostUsdOriginal(costingSheetId, work_, unitId, refId);
                        DateTime originalStartDate = projectCostingSheetInformationUnitsInformationGateway.GetStartDateOriginal(costingSheetId, work_, unitId, refId);
                        DateTime originalEndDate = projectCostingSheetInformationUnitsInformationGateway.GetEndDateOriginal(costingSheetId, work_, unitId, refId);
                        string originalFunction_ = projectCostingSheetInformationUnitsInformationGateway.GetFunction_Original(costingSheetId, work_, unitId, refId);

                        //original values
                        string newUnitOfMeasurement = projectCostingSheetInformationUnitsInformationGateway.GetUnitOfMeasurement(costingSheetId, work_, unitId, refId);
                        double newQuantity = projectCostingSheetInformationUnitsInformationGateway.GetQuantity(costingSheetId, work_, unitId, refId);
                        decimal newCostCad = projectCostingSheetInformationUnitsInformationGateway.GetCostCad(costingSheetId, work_, unitId, refId);
                        decimal newTotalCostCad = projectCostingSheetInformationUnitsInformationGateway.GetTotalCostCad(costingSheetId, work_, unitId, refId);
                        decimal newCostUsd = projectCostingSheetInformationUnitsInformationGateway.GetCostUsd(costingSheetId, work_, unitId, refId);
                        decimal newTotalCostUsd = projectCostingSheetInformationUnitsInformationGateway.GetTotalCostUsd(costingSheetId, work_, unitId, refId);
                        DateTime newStartDate = projectCostingSheetInformationUnitsInformationGateway.GetStartDate(costingSheetId, work_, unitId, refId);
                        DateTime newEndDate = projectCostingSheetInformationUnitsInformationGateway.GetEndDate(costingSheetId, work_, unitId, refId);
                        string newFunction_ = projectCostingSheetInformationUnitsInformationGateway.GetFunction_(costingSheetId, work_, unitId, refId);

                        ProjectCostingSheetUnits units = new ProjectCostingSheetUnits(null);
                        units.UpdateDirect(costingSheetId, work_, unitId, refId, originalUnitOfMeasurement, originalQuantity, originalCostCad, originalTotalCostCad, originalCostUsd, originalTotalCostUsd, deleted, companyId, originalStartDate, originalEndDate, originalFunction_, newUnitOfMeasurement, newQuantity, newCostCad, newTotalCostCad, newCostUsd, newTotalCostUsd, deleted, companyId, newStartDate, newEndDate, newFunction_);
                    }

                    // Delete costing sheet Units
                    if ((row.Deleted) && (row.InDatabase))
                    {
                        ProjectCostingSheetUnits units = new ProjectCostingSheetUnits(null);
                        units.DeleteDirect(row.CostingSheetID, row.Work_, row.UnitID, row.RefID, row.COMPANY_ID);
                    }
                }
            }
        }
        protected void grdUnits_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            // Edit items
            if ((e.Row.RowType == DataControlRowType.DataRow) && ((e.Row.RowState == DataControlRowState.Edit) || (e.Row.RowState == (DataControlRowState.Edit | DataControlRowState.Alternate))))
            {
                int costingSheetId = Int32.Parse(((Label)e.Row.FindControl("lblCostingSheetIDEdit")).Text.Trim());
                int unitId = Int32.Parse(((Label)e.Row.FindControl("lblUnitIDEdit")).Text.Trim());
                int refId = Int32.Parse(((Label)e.Row.FindControl("lblRefIDEdit")).Text.Trim());
                string work_ = ((Label)e.Row.FindControl("lblWork_Edit")).Text.Trim();

                ProjectCostingSheetInformationUnitsInformationGateway projectCostingSheetInformationUnitsInformationGateway = new ProjectCostingSheetInformationUnitsInformationGateway(projectCostingSheetInformationTDS);
                string unitOfMeasurement = projectCostingSheetInformationUnitsInformationGateway.GetUnitOfMeasurement(costingSheetId, work_, unitId, refId);
                ((DropDownList)e.Row.FindControl("ddlUnitOfMeasurementUnitsEdit")).SelectedValue = unitOfMeasurement;

                bool inDatabase = projectCostingSheetInformationUnitsInformationGateway.GetInDatabase(costingSheetId, work_, unitId, refId);

                if (inDatabase)
                {
                    ((RadDatePicker)e.Row.FindControl("tkrdpEndDateEdit")).Calendar.Enabled = false;
                    ((RadDatePicker)e.Row.FindControl("tkrdpEndDateEdit")).DateInput.ReadOnly = true;

                    ((RadDatePicker)e.Row.FindControl("tkrdpStartDateEdit")).Calendar.Enabled = false;
                    ((RadDatePicker)e.Row.FindControl("tkrdpStartDateEdit")).DateInput.ReadOnly = true;
                }

                ((RadDatePicker)e.Row.FindControl("hdfFrom")).SelectedDate = Convert.ToDateTime(hdfFromDate.Value);
                ((RadDatePicker)e.Row.FindControl("hdfTo")).SelectedDate = Convert.ToDateTime(hdfToDate.Value);
            }

            // Footer Item
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                ((RadDatePicker)e.Row.FindControl("hdfFrom")).SelectedDate = Convert.ToDateTime(hdfFromDate.Value);
                ((RadDatePicker)e.Row.FindControl("hdfTo")).SelectedDate = Convert.ToDateTime(hdfToDate.Value);
            }
        }