private int GetSiteVisitNumber(int siteId) { // test to see if an internal visit number is present in the incoming dataset var existingSiteVisitId = Get("SiteVisit.ExistingSiteVisitID"); if (!String.IsNullOrEmpty(existingSiteVisitId)) { var visit = MaterialService.GetSiteVisit(Int32.Parse(existingSiteVisitId)); if (visit != null) { return visit.SiteVisitID; } } // No existing visit found? need to create it var iDateType = FIXED_DATE; var strSiteVisitName = Get("SiteVisit.Visit Name"); var strCollector = Get("SiteVisit.Collector(s)"); var strCasualDate = Get("SiteVisit.Casual time"); int? startDate = GetConvert<int?>("SiteVisit.Start Date", null, false); if (!startDate.HasValue) { iDateType = CASUAL_DATE; } else { strCasualDate = Get("SiteVisit.Start Date", strCasualDate); } int? endDate = GetConvert<int?>("SiteVisit.End Date", null); if (!endDate.HasValue) { var sEndDate = Get("SiteVisit.End Date"); if (!string.IsNullOrWhiteSpace(sEndDate)) { if (iDateType == FIXED_DATE) { throw new Exception("Invalid end date value - start date is in fixed format, end date is not"); } else { if (string.IsNullOrWhiteSpace(strCasualDate)) { strCasualDate = sEndDate; } } } } var timeStart = GetConvert<int?>("SiteVisit.Start Time", null); var timeEnd = GetConvert<int?>("SiteVisit.End Time"); var strFieldNumber = Get("SiteVisit.Field number"); if (string.IsNullOrWhiteSpace(strSiteVisitName)) { if (startDate.HasValue && startDate.Value > 0) { if (iDateType == FIXED_DATE) { strSiteVisitName = strCollector + ", " + DateUtils.BLDateToStr(startDate.Value); } else { strSiteVisitName = strCollector + ", " + strCasualDate; } } else { if (endDate.HasValue && endDate.Value > 0) { if (iDateType == FIXED_DATE) { strSiteVisitName = strCollector + ", " + DateUtils.BLDateToStr(endDate.Value); } else { strSiteVisitName = strCollector + ", " + strCasualDate; } } else { strSiteVisitName = strCollector; } } } if (_lastSiteVisit != null && _lastSiteVisit.Equals(siteId, strSiteVisitName, strCollector, startDate, endDate, timeStart, timeEnd, strFieldNumber, strCasualDate)) { return _lastSiteVisit.SiteVisitID; } else { var visit = new SiteVisit { SiteVisitName = strSiteVisitName, SiteID = siteId, FieldNumber = strFieldNumber, Collector = strCollector, DateType = iDateType, DateStart = startDate, DateEnd = endDate, TimeStart = timeStart, TimeEnd = timeEnd, CasualTime = strCasualDate }; var siteVisitID = Service.ImportSiteVisit(visit); _lastSiteVisit = new CachedSiteVisit { SourceRowID = CurrentRowId, SiteVisitID = siteVisitID, SiteID = siteId, Collector = strCollector, FieldNumber = strFieldNumber, SiteVisitName = strSiteVisitName, DateEnd = endDate, DateStart = startDate, TimeEnd = timeEnd, TimeStart = timeStart, CasualDate = strCasualDate }; return siteVisitID; } }
public static string FormatSiteVisitName(SiteVisit visit) { return Format(Config.GetProfile<string>(PluginManager.Instance.User, "Material.SiteVisitNameFormat", DEFAULT_SITE_VISIT_NAME_FORMAT), visit); }
public void UpdateSiteVisit(SiteVisit siteVisit) { StoredProcUpdate("spSiteVisitUpdate", _P("intSiteVisitID", siteVisit.SiteVisitID), _P("vchrSiteVisitName", siteVisit.SiteVisitName), _P("vchrFieldNumber", siteVisit.FieldNumber), _P("vchrCollector", siteVisit.Collector), _P("tintDateType", siteVisit.DateType), _P("intDateStart", siteVisit.DateStart), _P("intDateEnd", siteVisit.DateEnd), _P("intTimeStart", siteVisit.TimeStart), _P("intTimeEnd", siteVisit.TimeEnd), _P("vchrCasualTime", siteVisit.CasualTime)); }
public int ImportSiteVisit(SiteVisit siteVisit) { return StoredProcReturnVal("spSiteVisitImportGetID", _P("vchrSiteVisitName", siteVisit.SiteVisitName), _P("intSiteID", siteVisit.SiteID), _P("vchrFieldNumber", siteVisit.FieldNumber), _P("vchrCollector", siteVisit.Collector), _P("tintDateType", siteVisit.DateType), _P("intDateStart", siteVisit.DateStart), _P("intDateEnd", siteVisit.DateEnd), _P("intTimeStart", siteVisit.TimeStart), _P("intTimeEnd", siteVisit.TimeEnd), _P("vchrCasualTime", siteVisit.CasualTime)); }