/// <summary> /// Save all costs to database (direct) /// </summary> /// <param name="companyId">companyId</param> public void Save(int companyId) { MaterialsInformationTDS costHistoryInformationChanges = (MaterialsInformationTDS)Data.GetChanges(); if (costHistoryInformationChanges.CostHistoryInformation.Rows.Count > 0) { MaterialsInformationCostHistoryInformationGateway materialsInformationCostHistoryInformationGateway = new MaterialsInformationCostHistoryInformationGateway(costHistoryInformationChanges); foreach (MaterialsInformationTDS.CostHistoryInformationRow row in (MaterialsInformationTDS.CostHistoryInformationDataTable)costHistoryInformationChanges.CostHistoryInformation) { // Insert new costs if ((!row.Deleted) && (!row.InDatabase)) { MaterialsCostHistory materialsCostHistory = new MaterialsCostHistory(null); materialsCostHistory.InsertDirect(row.CostID, row.MaterialID, 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.MaterialID; bool originalDeleted = row.Deleted; int originalCompanyId = companyId; // original values DateTime originalDate = materialsInformationCostHistoryInformationGateway.GetDateOriginal(costId, materialId); string originalUnitOfMeasurement = materialsInformationCostHistoryInformationGateway.GetUnitOfMeasurementOriginal(costId, materialId); decimal originalCostCad = materialsInformationCostHistoryInformationGateway.GetCostCadOriginal(costId, materialId); decimal originalCostUsd = materialsInformationCostHistoryInformationGateway.GetCostUsdOriginal(costId, materialId); // new values DateTime newDate = materialsInformationCostHistoryInformationGateway.GetDate(costId, materialId); string newUnitOfMeasurement = materialsInformationCostHistoryInformationGateway.GetUnitOfMeasurement(costId, materialId); decimal newCostCad = materialsInformationCostHistoryInformationGateway.GetCostCad(costId, materialId); decimal newCostUsd = materialsInformationCostHistoryInformationGateway.GetCostUsd(costId, materialId); MaterialsCostHistory materialsCostHistory = new MaterialsCostHistory(null); materialsCostHistory.UpdateDirect(costId, materialId, originalDate, originalUnitOfMeasurement, originalCostCad, originalCostUsd, originalDeleted, originalCompanyId, costId, materialId, newDate, newUnitOfMeasurement, newCostCad, newCostUsd, originalDeleted, originalCompanyId); } // Deleted costs if ((row.Deleted) && (row.InDatabase)) { MaterialsCostHistory materialsCostHistory = new MaterialsCostHistory(null); materialsCostHistory.DeleteDirect(row.CostID, row.MaterialID, row.COMPANY_ID); } } } }
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 materialId = Int32.Parse(hdfCurrentMaterialId.Value); int costId = Int32.Parse(((Label)e.Row.FindControl("lblCostIDEdit")).Text.Trim()); MaterialsInformationCostHistoryInformationGateway materialsInformationCostHistoryInformationGateway = new MaterialsInformationCostHistoryInformationGateway(materialsInformationTDS); string unitOfMeasurement = materialsInformationCostHistoryInformationGateway.GetUnitOfMeasurement(costId, materialId); ((DropDownList)e.Row.FindControl("ddlUnitOfMeasurementMaterialsEdit")).SelectedValue = unitOfMeasurement; } }
// //////////////////////////////////////////////////////////////////////// // PUBLIC METHODS // /// <summary> /// LoadAllByMaterialId /// </summary> /// <param name="materialId">materialId</param> /// <param name="companyId">companyId</param> public void LoadAllByMaterialId(int materialId, int companyId) { MaterialsInformationCostHistoryInformationGateway materialsInformationCostHistoryInformationGateway = new MaterialsInformationCostHistoryInformationGateway(Data); materialsInformationCostHistoryInformationGateway.LoadAllByMaterialId(materialId, companyId); }