/// <summary> /// Save all materials to database (direct) /// </summary> /// <param name="companyId">companyId</param> public void Save(int companyId, int materialId) { MaterialsInformationTDS costHistoryExceptionsInformationChanges = (MaterialsInformationTDS)Data.GetChanges(); if (costHistoryExceptionsInformationChanges.CostHistoryExceptionsInformation.Rows.Count > 0) { MaterialsInformationCostHistoryExceptionsInformationGateway materialsInformationCostHistoryExceptionsInformationGateway = new MaterialsInformationCostHistoryExceptionsInformationGateway(costHistoryExceptionsInformationChanges); foreach (MaterialsInformationTDS.CostHistoryExceptionsInformationRow row in (MaterialsInformationTDS.CostHistoryExceptionsInformationDataTable)costHistoryExceptionsInformationChanges.CostHistoryExceptionsInformation) { // Insert new costs exceptions if ((!row.Deleted) && (!row.InDatabase)) { MaterialsCostHistoryExceptions materialsCostHistoryExceptions = new MaterialsCostHistoryExceptions(null); materialsCostHistoryExceptions.InsertDirect(row.CostID, row.RefID, materialId, row.Work_, row.Function_, row.UnitOfMeasurement, row.CostCad, row.CostUsd, row.Deleted, row.COMPANY_ID); } // Update costs exceptions if ((!row.Deleted) && (row.InDatabase)) { int costId = row.CostID; int refId = row.RefID; bool originalDeleted = row.Deleted; int originalCompanyId = companyId; // original values string originalWork = materialsInformationCostHistoryExceptionsInformationGateway.GetWork_Original(costId, refId); string originalFunction = materialsInformationCostHistoryExceptionsInformationGateway.GetFunction_Original(costId, refId); string originalUnitOfMeasurement = materialsInformationCostHistoryExceptionsInformationGateway.GetUnitOfMeasurementOriginal(costId, refId); decimal originalCostCad = materialsInformationCostHistoryExceptionsInformationGateway.GetCostCadOriginal(costId, refId); decimal originalCostUsd = materialsInformationCostHistoryExceptionsInformationGateway.GetCostUsdOriginal(costId, refId); // new values string newWork = materialsInformationCostHistoryExceptionsInformationGateway.GetWork_Original(costId, refId); string newFunction = materialsInformationCostHistoryExceptionsInformationGateway.GetFunction_Original(costId, refId); string newUnitOfMeasurement = materialsInformationCostHistoryExceptionsInformationGateway.GetUnitOfMeasurement(costId, refId); decimal newCostCad = materialsInformationCostHistoryExceptionsInformationGateway.GetCostCad(costId, refId); decimal newCostUsd = materialsInformationCostHistoryExceptionsInformationGateway.GetCostUsd(costId, refId); MaterialsCostHistoryExceptions materialsCostHistoryExceptions = new MaterialsCostHistoryExceptions(null); materialsCostHistoryExceptions.UpdateDirect(costId, refId, materialId, originalWork, originalFunction, originalUnitOfMeasurement, originalCostCad, originalCostUsd, originalDeleted, originalCompanyId, costId, refId, materialId, newWork, newFunction, newUnitOfMeasurement, newCostCad, newCostUsd, originalDeleted, originalCompanyId); } // Deleted costs exceptions if ((row.Deleted) && (row.InDatabase)) { MaterialsCostHistoryExceptions materialsCostHistoryExceptions = new MaterialsCostHistoryExceptions(null); materialsCostHistoryExceptions.DeleteDirect(row.CostID, row.RefID, row.COMPANY_ID); } } } }
protected void grdCostsExceptions_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 refId = Int32.Parse(((Label)e.Row.FindControl("lblExceptionRefIDEdit")).Text.Trim()); int costId = Int32.Parse(((Label)e.Row.FindControl("lblExceptionCostIDEdit")).Text.Trim()); MaterialsInformationCostHistoryExceptionsInformationGateway materialsInformationCostHistoryExceptionsInformationGateway = new MaterialsInformationCostHistoryExceptionsInformationGateway(materialsInformationTDS); string workFunction = materialsInformationCostHistoryExceptionsInformationGateway.GetWorkFunction(costId, refId); ((DropDownList)e.Row.FindControl("ddlExceptionWorkFunctionEdit")).SelectedValue = workFunction; string unitOfMeasurement = materialsInformationCostHistoryExceptionsInformationGateway.GetUnitOfMeasurement(costId, refId); ((DropDownList)e.Row.FindControl("ddlExceptionUnitOfMeasurementMaterialsEdit")).SelectedValue = unitOfMeasurement; } }