/// <summary>
        /// Save all costs to database (direct)
        /// </summary>
        /// <param name="companyId">companyId</param>
        public void Save(int companyId)
        {
            UnitInformationTDS unitInformationChanges = (UnitInformationTDS)Data.GetChanges();

            if (unitInformationChanges.CostInformation.Rows.Count > 0)
            {
                UnitInformationCostInformationGateway unitInformationCostInformationGateway = new UnitInformationCostInformationGateway(unitInformationChanges);

                foreach (UnitInformationTDS.CostInformationRow row in (UnitInformationTDS.CostInformationDataTable)unitInformationChanges.CostInformation)
                {
                    // Insert new costs
                    if ((!row.Deleted) && (!row.InDatabase))
                    {
                        UnitsCostHistory unitsCostHistory = new UnitsCostHistory(null);
                        unitsCostHistory.InsertDirect(row.CostID, row.UnitID, row.Date, row.UnitOfMeasurement, row.CostCad, row.CostUsd, row.Deleted, row.COMPANY_ID);
                    }

                    // Update costs
                    if ((!row.Deleted) && (row.InDatabase))
                    {
                        int costId = row.CostID;
                        int materialId = row.UnitID;
                        bool originalDeleted = row.Deleted;
                        int originalCompanyId = companyId;

                        // original values
                        DateTime originalDate = unitInformationCostInformationGateway.GetDateOriginal(costId);
                        string originalUnitOfMeasurement = unitInformationCostInformationGateway.GetUnitOfMeasurementOriginal(costId);
                        decimal originalCostCad = unitInformationCostInformationGateway.GetCostCadOriginal(costId);
                        decimal originalCostUsd = unitInformationCostInformationGateway.GetCostUsdOriginal(costId);

                        // new values
                        DateTime newDate = unitInformationCostInformationGateway.GetDate(costId);
                        string newUnitOfMeasurement = unitInformationCostInformationGateway.GetUnitOfMeasurement(costId);
                        decimal newCostCad = unitInformationCostInformationGateway.GetCostCad(costId);
                        decimal newCostUsd = unitInformationCostInformationGateway.GetCostUsd(costId);

                        UnitsCostHistory unitsCostHistory = new UnitsCostHistory(null);
                        unitsCostHistory.UpdateDirect(costId, materialId, originalDate, originalUnitOfMeasurement, originalCostCad, originalCostUsd, originalDeleted, originalCompanyId, costId, materialId, newDate, newUnitOfMeasurement, newCostCad, newCostUsd, originalDeleted, originalCompanyId);
                    }

                    // Deleted costs
                    if ((row.Deleted) && (row.InDatabase))
                    {
                        UnitsCostHistory unitsCostHistory = new UnitsCostHistory(null);
                        unitsCostHistory.DeleteDirect(row.CostID, row.UnitID, row.COMPANY_ID);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        protected void grdCosts_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 costId = Int32.Parse(((Label)e.Row.FindControl("lblCostIDEdit")).Text.Trim());

                UnitInformationCostInformationGateway unitInformationCostInformationGateway = new UnitInformationCostInformationGateway(unitInformationTDS);
                string unitOfMeasurement = unitInformationCostInformationGateway.GetUnitOfMeasurement(costId);
                ((DropDownList)e.Row.FindControl("ddlUnitOfMeasurementUnitsEdit")).SelectedValue = unitOfMeasurement;
            }
        }
 // ////////////////////////////////////////////////////////////////////////
 // PUBLIC METHODS
 //
 /// <summary>
 /// LoadAllByUnitId
 /// </summary>
 /// <param name="unitId">unitId</param>              
 /// <param name="companyId">companyId</param>
 public void LoadAllByUnitId(int unitId, int companyId)
 {
     UnitInformationCostInformationGateway unitInformationCostInformationGateway = new UnitInformationCostInformationGateway(Data);
     unitInformationCostInformationGateway.LoadAllByUnitId(unitId, companyId);
 }