R
Ronald S. Cook
In trying to figure out how to make function
MedicineClass.ApplyMedicinePriceChanges perform better, I ran Code Analysis
and got the following:
******************************************************************************************
Warning 1677 CA1506 : Microsoft.Maintainability :
'MedicineClass.ApplyMedicinePriceChanges(ProgramMedicinePrice, String, Guid,
Decimal)' is coupled with 34 different types from 9 different namespaces.
Rewrite or refactor the method to decrease its class coupling, or consider
moving the method to one of the other types it is tightly coupled with. A
class coupling above 40 indicates poor maintainability, a class coupling
between 40 and 30 indicates moderate maintainability, and a class coupling
below 30 indicates good maintainability.
D:\Win\FRC.COW.Feedyard.DAL\FRC.COW.Feedyard.DAL\Business
Classes\MedicineClass.cs 514 FRC.COW.Feedyard.DAL
******************************************************************************************
Does anyone have any idea what all this means?
Thanks if you have any thoughts. Below is the function for reference.
Ron
------------------------------------------------------------------------------------------------------------------------
public void ApplyMedicinePriceChanges(ProgramMedicinePrice
ProgramMedicinePrice, string AddOrEdit, Guid LoginId, Decimal
OldPriceIfWasEdited, void =, void 0) {
if ((ProgramMedicinePrice.ProgramMedicinePriceDate.Date <
DateTime.Today.Date)) {
// If equal to today or later, then we don't do any retro
pricing.
// We already know date is not earlier than start of current
billing period (caught in validation).
// Capture old price for when issuing credits.
Decimal OldPrice;
switch (AddOrEdit) {
case "Add":
OldPrice = GetOldPrice(ProgramMedicinePrice);
break;
case "Edit":
OldPrice = OldPriceIfWasEdited;
break;
}
// Get day before next date in database as will be the range end
date.
DateTime RangeEndDate = GetRangeEndDate(ProgramMedicinePrice);
// Has charge been invoiced?
// Then as long as the LotStatus <> cls, rej, pnd, or shp then
go total up numbers from AnimalMedicine & LotPenMedicine.
// If the LotStatus is CLS or SHP, then the charges have already
been invoiced and the individual charge is not repriced.
Charge _Charge;
ChargeClass _ChargeClass = new ChargeClass();
// AnimalMedicine.
************************************************************************************************************************
IList _AnimalMedicineList = From;
am;
dc.AnimalMedicines;
Where;
(ProgramMedicinePrice.ProgramId
& ((am.Animal.LotPen.Lot.Lookup.LookupValue !=
"CLS")
& ((am.Animal.LotPen.Lot.Lookup.LookupValue !=
"REJ")
& ((am.Animal.LotPen.Lot.Lookup.LookupValue !=
"PND")
& ((am.Animal.LotPen.Lot.Lookup.LookupValue !=
"SHP")
& am.AnimalMedicineIsCharged))))) = true;
(ProgramMedicinePrice.MedicineId
& ((am.AnimalMedicineDateTime >=
ProgramMedicinePrice.ProgramMedicinePriceDate)
& ((am.AnimalMedicineDateTime <= RangeEndDate)
& am.Animal.LotPen.Lot.ProgramId))) = true;
am.MedicineId = true;
Group;
By;
LotPenId = am.Animal.LotPenId;
Into;
SumOfDosage = Sum(am.AnimalMedicineDosage);
switch (LotPenId) {
case SumOfDosage:
ToList();
// Loop through summed LotPenId and Dosage records and
create Charge entries.
for (int i = 0; (i
<= (_AnimalMedicineList.Count - 1)); i++) {
// For each sum of medicines used in a LotPen, enter
a DEBIT charge with the NEW amount.
_Charge = new Charge();
_Charge.ChargeDate = DateTime.Today.Date;
_Charge.ChargeDollars =
(Decimal.Parse(ProgramMedicinePrice.ProgramMedicinePriceDollars) *
_AnimalMedicineList["SumOfDosage"]);
_Charge.LotPenId =
_AnimalMedicineList["LotPenId"];
_Charge.ChargeCodeId =
ProgramMedicinePrice.Medicine.ChargeCodeId;
_ChargeClass.AddCharge(_Charge, LoginId);
// For each sum of medicines used in a LotPen, enter
a CREDIT charge with the OLD amount.
_Charge = new Charge();
_Charge.ChargeDate = DateTime.Today.Date;
_Charge.ChargeDollars = (0
- (OldPrice *
_AnimalMedicineList["SumOfDosage"]));
// Make amount NEGATIVE for the credit using OLD
price.
_Charge.LotPenId =
_AnimalMedicineList["SumOfDosage"];
_Charge.ChargeCodeId =
ProgramMedicinePrice.Medicine.ChargeCodeId;
_ChargeClass.AddCharge(_Charge, LoginId);
}
//
****************************************************************************************************************************************
// LotPenMedicine.
************************************************************************************************************************
IList _LotPenMedicineList = From;
lpm;
dc.LotPenMedicines;
Where;
(ProgramMedicinePrice.ProgramId
& ((lpm.LotPen.Lot.Lookup.LookupValue !=
"CLS")
& ((lpm.LotPen.Lot.Lookup.LookupValue !=
"REJ")
& ((lpm.LotPen.Lot.Lookup.LookupValue !=
"PND")
& ((lpm.LotPen.Lot.Lookup.LookupValue !=
"SHP")
& lpm.LotPenMedicineIsCharged))))) = true;
(ProgramMedicinePrice.MedicineId
& ((lpm.LotPenMedicineDateTime >=
ProgramMedicinePrice.ProgramMedicinePriceDate)
& ((lpm.LotPenMedicineDateTime <=
RangeEndDate)
& lpm.LotPen.Lot.ProgramId))) = true;
lpm.MedicineId = true;
Group;
By;
LotPenId = lpm.LotPen.LotPenId;
Into;
SumOfDosage = Sum(lpm.LotPenMedicineDosage);
switch (LotPenId) {
case SumOfDosage:
ToList();
// Loop through summed LotPenId and Dosage
records and create Charge entries.
for (int i = 0; (i
<= (_LotPenMedicineList.Count - 1));
i++) {
// For each sum of medicines used in a
LotPen, enter a CREDIT charge with the NEW amount.
_Charge = new Charge();
_Charge.ChargeDate = DateTime.Today.Date;
_Charge.ChargeDollars =
(Decimal.Parse(ProgramMedicinePrice.ProgramMedicinePriceDollars) *
_LotPenMedicineList["SumOfDosage"]);
_Charge.LotPenId =
_LotPenMedicineList["LotPenId"];
_Charge.ChargeCodeId =
ProgramMedicinePrice.Medicine.ChargeCodeId;
_ChargeClass.AddCharge(_Charge, LoginId);
// For each sum of medicines used in a
LotPen, enter a DEBIT charge with the OLD amount.
_Charge = new Charge();
_Charge.ChargeDate = DateTime.Today.Date;
_Charge.ChargeDollars = (0
- (OldPrice *
_LotPenMedicineList["SumOfDosage"]));
// Make amount NEGATIVE for the debit using
OLD price.
_Charge.LotPenId =
_LotPenMedicineList["SumOfDosage"];
_Charge.ChargeCodeId =
ProgramMedicinePrice.Medicine.ChargeCodeId;
_ChargeClass.AddCharge(_Charge, LoginId);
}
//
****************************************************************************************************************************************
break;
}
break;
}
}
}
MedicineClass.ApplyMedicinePriceChanges perform better, I ran Code Analysis
and got the following:
******************************************************************************************
Warning 1677 CA1506 : Microsoft.Maintainability :
'MedicineClass.ApplyMedicinePriceChanges(ProgramMedicinePrice, String, Guid,
Decimal)' is coupled with 34 different types from 9 different namespaces.
Rewrite or refactor the method to decrease its class coupling, or consider
moving the method to one of the other types it is tightly coupled with. A
class coupling above 40 indicates poor maintainability, a class coupling
between 40 and 30 indicates moderate maintainability, and a class coupling
below 30 indicates good maintainability.
D:\Win\FRC.COW.Feedyard.DAL\FRC.COW.Feedyard.DAL\Business
Classes\MedicineClass.cs 514 FRC.COW.Feedyard.DAL
******************************************************************************************
Does anyone have any idea what all this means?
Thanks if you have any thoughts. Below is the function for reference.
Ron
------------------------------------------------------------------------------------------------------------------------
public void ApplyMedicinePriceChanges(ProgramMedicinePrice
ProgramMedicinePrice, string AddOrEdit, Guid LoginId, Decimal
OldPriceIfWasEdited, void =, void 0) {
if ((ProgramMedicinePrice.ProgramMedicinePriceDate.Date <
DateTime.Today.Date)) {
// If equal to today or later, then we don't do any retro
pricing.
// We already know date is not earlier than start of current
billing period (caught in validation).
// Capture old price for when issuing credits.
Decimal OldPrice;
switch (AddOrEdit) {
case "Add":
OldPrice = GetOldPrice(ProgramMedicinePrice);
break;
case "Edit":
OldPrice = OldPriceIfWasEdited;
break;
}
// Get day before next date in database as will be the range end
date.
DateTime RangeEndDate = GetRangeEndDate(ProgramMedicinePrice);
// Has charge been invoiced?
// Then as long as the LotStatus <> cls, rej, pnd, or shp then
go total up numbers from AnimalMedicine & LotPenMedicine.
// If the LotStatus is CLS or SHP, then the charges have already
been invoiced and the individual charge is not repriced.
Charge _Charge;
ChargeClass _ChargeClass = new ChargeClass();
// AnimalMedicine.
************************************************************************************************************************
IList _AnimalMedicineList = From;
am;
dc.AnimalMedicines;
Where;
(ProgramMedicinePrice.ProgramId
& ((am.Animal.LotPen.Lot.Lookup.LookupValue !=
"CLS")
& ((am.Animal.LotPen.Lot.Lookup.LookupValue !=
"REJ")
& ((am.Animal.LotPen.Lot.Lookup.LookupValue !=
"PND")
& ((am.Animal.LotPen.Lot.Lookup.LookupValue !=
"SHP")
& am.AnimalMedicineIsCharged))))) = true;
(ProgramMedicinePrice.MedicineId
& ((am.AnimalMedicineDateTime >=
ProgramMedicinePrice.ProgramMedicinePriceDate)
& ((am.AnimalMedicineDateTime <= RangeEndDate)
& am.Animal.LotPen.Lot.ProgramId))) = true;
am.MedicineId = true;
Group;
By;
LotPenId = am.Animal.LotPenId;
Into;
SumOfDosage = Sum(am.AnimalMedicineDosage);
switch (LotPenId) {
case SumOfDosage:
ToList();
// Loop through summed LotPenId and Dosage records and
create Charge entries.
for (int i = 0; (i
<= (_AnimalMedicineList.Count - 1)); i++) {
// For each sum of medicines used in a LotPen, enter
a DEBIT charge with the NEW amount.
_Charge = new Charge();
_Charge.ChargeDate = DateTime.Today.Date;
_Charge.ChargeDollars =
(Decimal.Parse(ProgramMedicinePrice.ProgramMedicinePriceDollars) *
_AnimalMedicineList["SumOfDosage"]);
_Charge.LotPenId =
_AnimalMedicineList["LotPenId"];
_Charge.ChargeCodeId =
ProgramMedicinePrice.Medicine.ChargeCodeId;
_ChargeClass.AddCharge(_Charge, LoginId);
// For each sum of medicines used in a LotPen, enter
a CREDIT charge with the OLD amount.
_Charge = new Charge();
_Charge.ChargeDate = DateTime.Today.Date;
_Charge.ChargeDollars = (0
- (OldPrice *
_AnimalMedicineList["SumOfDosage"]));
// Make amount NEGATIVE for the credit using OLD
price.
_Charge.LotPenId =
_AnimalMedicineList["SumOfDosage"];
_Charge.ChargeCodeId =
ProgramMedicinePrice.Medicine.ChargeCodeId;
_ChargeClass.AddCharge(_Charge, LoginId);
}
//
****************************************************************************************************************************************
// LotPenMedicine.
************************************************************************************************************************
IList _LotPenMedicineList = From;
lpm;
dc.LotPenMedicines;
Where;
(ProgramMedicinePrice.ProgramId
& ((lpm.LotPen.Lot.Lookup.LookupValue !=
"CLS")
& ((lpm.LotPen.Lot.Lookup.LookupValue !=
"REJ")
& ((lpm.LotPen.Lot.Lookup.LookupValue !=
"PND")
& ((lpm.LotPen.Lot.Lookup.LookupValue !=
"SHP")
& lpm.LotPenMedicineIsCharged))))) = true;
(ProgramMedicinePrice.MedicineId
& ((lpm.LotPenMedicineDateTime >=
ProgramMedicinePrice.ProgramMedicinePriceDate)
& ((lpm.LotPenMedicineDateTime <=
RangeEndDate)
& lpm.LotPen.Lot.ProgramId))) = true;
lpm.MedicineId = true;
Group;
By;
LotPenId = lpm.LotPen.LotPenId;
Into;
SumOfDosage = Sum(lpm.LotPenMedicineDosage);
switch (LotPenId) {
case SumOfDosage:
ToList();
// Loop through summed LotPenId and Dosage
records and create Charge entries.
for (int i = 0; (i
<= (_LotPenMedicineList.Count - 1));
i++) {
// For each sum of medicines used in a
LotPen, enter a CREDIT charge with the NEW amount.
_Charge = new Charge();
_Charge.ChargeDate = DateTime.Today.Date;
_Charge.ChargeDollars =
(Decimal.Parse(ProgramMedicinePrice.ProgramMedicinePriceDollars) *
_LotPenMedicineList["SumOfDosage"]);
_Charge.LotPenId =
_LotPenMedicineList["LotPenId"];
_Charge.ChargeCodeId =
ProgramMedicinePrice.Medicine.ChargeCodeId;
_ChargeClass.AddCharge(_Charge, LoginId);
// For each sum of medicines used in a
LotPen, enter a DEBIT charge with the OLD amount.
_Charge = new Charge();
_Charge.ChargeDate = DateTime.Today.Date;
_Charge.ChargeDollars = (0
- (OldPrice *
_LotPenMedicineList["SumOfDosage"]));
// Make amount NEGATIVE for the debit using
OLD price.
_Charge.LotPenId =
_LotPenMedicineList["SumOfDosage"];
_Charge.ChargeCodeId =
ProgramMedicinePrice.Medicine.ChargeCodeId;
_ChargeClass.AddCharge(_Charge, LoginId);
}
//
****************************************************************************************************************************************
break;
}
break;
}
}
}