public void SetFromRow(KlonsPDataSet.ITEMSRow dr, bool forrep = false) { DR = dr; Events = new List <EventInfo>(); var drs_ev = dr.GetITEMS_EVENTSRows() .OrderBy(d => d.DT) .ThenBy(d => d.EVENTSRow.ID < 0 ? int.MaxValue / 2 - d.EVENTSRow.ID : d.EVENTSRow.ID); IdIt = dr.ID; Id = IdIt; ItemRegNr = dr.REG_NR; ItemName = dr.NAME; int i = 1; foreach (var dr_ev in drs_ev) { EventInfo ev = null; if (forrep) { ev = new EventInfo(); } else { ev = new EventRepInfo(); } ev.SetFromRow(dr_ev); ev.SNR = i; Events.Add(ev); i++; } }
public string DoCalc() { StateOK = false; KlonsPDataSet.ITEMSRow dr = null; if (IdIt == int.MinValue || (dr = MyData.DataSetKlons.ITEMS.FindByID(IdIt)) == null) { return("Nav atrasts pamatlīdzeklis."); } if (!replacePartData1.fDATE.HasValue) { return("Nav norādīts datums."); } var dt = replacePartData1.fDATE.Value; var it = new ItemInfo(); it.SetFromRow(dr); if (!it.IsGoodEventDate(dt)) { return("Nekorekts datums."); } var rt = it.CheckItem(); if (rt != "OK") { return(rt); } it.Events2 = new List <EventInfo>(); var ev = new EventInfo(); it.Events2.Add(ev); ev.Dt = dt; ev.XEvent = EEvent.apr; rt = it.FullCalc(); if (rt != "OK") { return(rt); } replacePartData1.fMtUsed = ev.MtUsed; replacePartData1.fDeprec = DataTasks.Round(replacePartData1.fValue * (decimal)ev.RateD * (decimal)ev.MtUsed / 12.0M, 2); replacePartData1.fValueLeft = replacePartData1.fValue - replacePartData1.fDeprec; replacePartData1.fValueC = 0.0M; replacePartData1.fDeprecC = -replacePartData1.fDeprec; replacePartData1.fTaxValueC = replacePartData1.fDeprec; var sdoc = replacePartData1.fDoc.Nz(); replacePartData1.fDescr = $"detaļas vērtība {replacePartData1.fValue:N2}, nolietojuma periods {replacePartData1.fMtUsed} mēn., " + $"izslēgtais nolietojums {replacePartData1.fDeprec:N2}, amortizētās izmaksas {replacePartData1.fValueLeft:N2}"; replacePartData1.fDescr = replacePartData1.fDescr.LeftMax(200); StateOK = true; return("OK"); }