/// <summary> /// Save all materials to database (direct) /// </summary> /// <param name="companyId">companyId</param> public void Save(int companyId) { MaterialInformationTDS materialInformationChanges = (MaterialInformationTDS)Data.GetChanges(); if (materialInformationChanges.MaterialInformation.Rows.Count > 0) { MaterialInformationGateway materialInformationGateway = new MaterialInformationGateway(materialInformationChanges); foreach (MaterialInformationTDS.MaterialInformationRow row in (MaterialInformationTDS.MaterialInformationDataTable)materialInformationChanges.MaterialInformation) { // Insert new materials if ((!row.Deleted) && (!row.InDatabase)) { AssetSewerMaterial assetSewerMaterial = new AssetSewerMaterial(null); assetSewerMaterial.InsertDirect(row.AssetID, row.RefID, row.MaterialType, row.Date_, row.Deleted, row.COMPANY_ID); } // Update materials if ((!row.Deleted) && (row.InDatabase)) { int assetId = row.AssetID; int refId = row.RefID; bool originalDeleted = false; int originalCompanyId = companyId; // original values string originalMaterialType = materialInformationGateway.GetMaterialTypeOriginal(assetId, refId); DateTime originalDate_ = materialInformationGateway.GetDate_Original(assetId, refId); // new values string newMaterialType = materialInformationGateway.GetMaterialType(assetId, refId); AssetSewerMaterial assetSewerMaterial = new AssetSewerMaterial(null); assetSewerMaterial.UpdateDirect(assetId, refId, originalMaterialType, originalDate_, originalCompanyId, originalDeleted, assetId, refId, newMaterialType, originalDate_, originalCompanyId, originalDeleted); } // Deleted materials if ((row.Deleted) && (row.InDatabase)) { AssetSewerMaterial assetSewerMaterial = new AssetSewerMaterial(null); assetSewerMaterial.DeleteDirect(row.AssetID, row.RefID, row.COMPANY_ID); } } } }
/// <summary> /// Insert a material /// </summary> /// <param name="lateral_assetId">lateral_assetId</param> /// <param name="material">material</param> /// <param name="companyId">companyId</param> private void InsertMaterial(int lateral_assetId, string material, int companyId) { LfsAssetSewerLateralGateway lfsAssetSewertLateralGateway = new LfsAssetSewerLateralGateway(null); if (!lfsAssetSewertLateralGateway.IsUsedInMaterials(lateral_assetId, material, companyId)) { MaterialInformationGateway materialInformationGateway = new MaterialInformationGateway(); materialInformationGateway.LoadAllByAssetId(lateral_assetId, companyId); AssetSewerMaterial assetSewerMaterial = new AssetSewerMaterial(materialInformationGateway.Data); assetSewerMaterial.InsertDirect(lateral_assetId, materialInformationGateway.Table.Rows.Count + 1, material, DateTime.Now, false, companyId); } }