public void TestInsertingAnStaffRecord() { // Arrange var commandMock = new Mock <IDbCommand>(); commandMock.Setup(m => m.ExecuteNonQuery()).Verifiable(); var connectionMock = new Mock <IDbConnection>(); connectionMock.Setup(m => m.CreateCommand()).Returns(commandMock.Object); var connectionFactoryMock = new Mock <IDbConnectionFactory>(); connectionFactoryMock.Setup(m => m.CreateConnection(connectionMock.Object.ToString())); var mockUserFunction = new UserFunctions(); Staff newStaff = new Staff(); newStaff.Forename = "Charlotte"; newStaff.Surname = "Harrison"; newStaff.DateOfBirth = DateAndTime.DateValue("11/12/1997"); // Act var result = mockUserFunction.AddStaffRecordToDB(newStaff); //Assert //commandMock.Setup(m => m.ExecuteNonQuery()).Equals(1); NUnit.Framework.Assert.IsTrue(result == "Staff has been successfully saved in database"); }
private void Clean() { txt_box1.Text = ""; txt_box2.Text = ""; txt_box3.Text = ""; date_picker.Value = DateAndTime.DateValue("February 24, 1987"); }
/// <summary> /// Converts a date in string form to BLDate. Uses the VB6 compatibility classes to parse the date. If this fails, attempts to interpret the date /// as a BLDate /// </summary> /// <param name="date">The string to convert</param> /// <returns>An 8 digit string</returns> public static string DateStrToBLDate(string date) { if (String.IsNullOrEmpty(date)) { return(date); } String message; if (IsValidBLDate(date, out message)) { return(date); } // Try 'international' date format variants (YYYY-MM-dd, YYYY-MM or YYYY) var matcher = YearMonthDayRegex.Match(date); if (matcher.Success) { return(String.Format("{0}{1}{2}", matcher.Groups[1], matcher.Groups[2], matcher.Groups[3])); } matcher = YearMonthRegex.Match(date); if (matcher.Success) { return(String.Format("{0}{1}00", matcher.Groups[1], matcher.Groups[2])); } matcher = YearRegex.Match(date); if (matcher.Success) { return(String.Format("{0}0000", matcher.Groups[1])); } date = date.Trim(); if (Information.IsDate(date)) { var dt = DateAndTime.DateValue(date); var regex = new Regex("^\\w+[^\\w]_\\w+$"); if (regex.IsMatch(date)) { // we have a partial date, and the day has probably been defaulted to 1 // temp should be in format YYYYMMDD, so replace the last two digits with 00 return(date.Substring(0, 6) + "00"); } return(DateToBLDate(dt)); } return(null); }
//=============================================================================== // Declares //=============================================================================== // Note: add a project conditional compile argument "IncludeCreate" // if the CreateShortKey is to be compiled into the application. //#If IncludeCreate = 1 Then internal string CreateShortKey(string SerialNumber, string Licensee, int ProductCode, System.DateTime ExpireDate, short UserData, int RegisteredLevel) { //=============================================================================== // CreateShortKey - Creates a new serial number. // // SerialNumber The serial number is generated from the app name, version, // and password, along with the HDD firmware serial number, // which makes it unique for the machine running the app. // Licensee Name of party to whom this license is issued. // ProductCode A unique number assigned to this product. This is created // from the app private key and is a 4 digit integer. // ExpireDate Use this field for time-based serial numbers. This allows // serial number to be issued that expire in two weeks or at // the end of the year. // UserData This field is caller defined. Currently we are using // the MaxUser and LicType (using a LoByte/HiByte packed field). // RegisteredLevel This is the Registered Level from Alugen. Long only. // RETURNS A License Key in the form of "233C-3912-00FF-BE49" //=============================================================================== string[] KeySegs = new string[5]; int i = 0; // convert each segment value to a hex string KeySegs[Segments.iProdCode] = HexWORD(ProductCode); KeySegs[Segments.iExpire] = HexWORD(DateAndTime.DateValue((string)(System.DateTime)ExpireDate.ToString("yyyy/MM/dd")).Subtract(DateAndTime.DateValue((string)1970 / 01 / 01 12 : 00 : 00 AM)).Days); KeySegs[Segments.iUserData] = HexWORD(UserData); // Compute CRC against pertinent info. KeySegs[Segments.iCRC] = HexWORD(CRC(System.Text.UnicodeEncoding.Unicode.GetBytes(Strings.UCase(Licensee + KeySegs[Segments.iProdCode] + KeySegs[Segments.iExpire] + KeySegs[Segments.iUserData] + SerialNumber)))); // Perform bit swaps for (i = 0; i <= m_nSwaps - 1; i++) { SwapBit(ref m_Bits(i), ref KeySegs); } // Calculate the CRC used to perform // simple user input validation. KeySegs[Segments.iCRC2] = HexWORD(CRC(System.Text.UnicodeEncoding.Unicode.GetBytes(Strings.UCase(Licensee + KeySegs[Segments.iProdCode] + KeySegs[Segments.iExpire] + KeySegs[Segments.iUserData] + KeySegs[Segments.iCRC])))); // Return the key to the caller return(Strings.UCase(KeySegs[Segments.iProdCode] + "-" + KeySegs[Segments.iExpire] + "-" + KeySegs[Segments.iUserData] + "-" + KeySegs[Segments.iCRC] + "-" + KeySegs[Segments.iCRC2]) + "-" + Strings.StrReverse(HexWORD(RegisteredLevel))); }
private int AddMaterial(int siteVisitId, int taxonId) { var sparcService = new MaterialService(User); var sMaterialName = Get("Material.Material name"); var sAccessionNumber = Get("Material.Accession number"); var sRegistrationNumber = Get("Material.Registration number"); var sCollectorNumber = Get("Material.Collector number"); var sIDBy = Get("Material.Identified by"); var sIDOn = Get("Material.Identified on"); if (!string.IsNullOrWhiteSpace(sIDOn)) { string message; if (DateUtils.IsValidBLDate(sIDOn, out message)) { sIDOn = string.Format("{0:dd MMM yyyy}", DateUtils.MakeCompatibleBLDate(Int32.Parse(sIDOn))); } else { if (!Information.IsDate(sIDOn)) { throw new Exception("'Identified on' value (" + sIDOn + ") is not a valid date time! " + message); } } } var sIDRef = Get("Material.Identification reference"); var sIDRefPage = Get("Material.Identification reference page"); var sIDMethod = Get("Material.Identification method"); var sIDAccuracy = Get("Material.Identification accuracy"); var sIDNameQualifier = Get("Material.Name qualifier"); var sIDNotes = Get("Material.Identification notes"); var sInstitution = Get("Material.Institute"); var sCollectMethod = Get("Material.Collection method"); var sAbundance = Get("Material.Abundance"); var sMacroHabitat = Get("Material.Macrohabitat"); var sMicrohabitat = Get("Material.Microhabitat"); var sSource = Get("Material.Source"); var sSpecialLabel = Get("Material.Special label"); var bCreateLabel = GetConvert <bool>("Material.Create Label", false); var sDateStart = Get("SiteVisit.Start Date", "0"); string sOriginalLabel = ""; if (bCreateLabel) { if (sDateStart != "0") { string message; if (DateUtils.IsValidBLDate(sDateStart, out message)) { sDateStart = BuildDate(sDateStart); } } sOriginalLabel = "Import derived: " + Get("Site.Locality") + "; " + Get("SiteVisit.Collector(s)") + "; " + sDateStart; } else { sOriginalLabel = Get("Material.Original label"); } if (string.IsNullOrWhiteSpace(sMaterialName)) { if (!string.IsNullOrWhiteSpace(sInstitution)) { if (!string.IsNullOrWhiteSpace(sAccessionNumber)) { sMaterialName = string.Format("{0}:{1}", sInstitution, sAccessionNumber); } else { if (!string.IsNullOrWhiteSpace(sRegistrationNumber)) { sMaterialName = string.Format("{0}:{1}", sInstitution, sRegistrationNumber); } } } else { if (!string.IsNullOrWhiteSpace(sAccessionNumber)) { sMaterialName = sAccessionNumber; } else { if (!string.IsNullOrWhiteSpace(sRegistrationNumber)) { sMaterialName = sRegistrationNumber; } } } } var material = new Material { MaterialName = sMaterialName, SiteVisitID = siteVisitId, AccessionNumber = sAccessionNumber, RegistrationNumber = sRegistrationNumber, CollectorNumber = sCollectorNumber, BiotaID = taxonId, IdentifiedBy = sIDBy, IdentificationDate = (string.IsNullOrWhiteSpace(sIDOn) ? null : new DateTime?(DateAndTime.DateValue(sIDOn))), IdentificationReferenceID = (!string.IsNullOrWhiteSpace(sIDRef) && sIDRef.IsNumeric()) ? Int32.Parse(sIDRef) : 0, IdentificationRefPage = sIDRefPage, IdentificationMethod = sIDMethod, IdentificationAccuracy = sIDAccuracy, IdentificationNameQualification = sIDNameQualifier, IdentificationNotes = sIDNotes, Institution = sInstitution, CollectionMethod = sCollectMethod, Abundance = sAbundance, MacroHabitat = sMacroHabitat, MicroHabitat = sMicrohabitat, Source = sSource, SpecialLabel = sSpecialLabel, OriginalLabel = sOriginalLabel }; return(Service.ImportMaterial(material)); }
public static DateTime DateValue(string StringDate) { return(DateAndTime.DateValue(StringDate)); }
/// <summary> /// Returns a Date value containing the date information represented by a string, with the time information set to midnight (00:00:00). /// </summary> /// <returns></returns> public static DateTime DateValue(string value) { return(DateAndTime.DateValue(value)); }
public string FetchRailList(bool ActiveUnits) { short DayAmt = 0; int RecCount = 0; string BookingNumbers = ""; string Sql = ""; MdlContainerManagement.RailSight RailStructure; int TotalRecords = 0; string TempLine = ""; var UnitLineStatus = default(char); if (ActiveUnits == true) { Sql = "Select * From VW_UnitSource Where Active = 1 and UnitStatus <> 'RELEASED' Order By UnitNumber"; } else { Sql = "Select * From VW_UnitSource Where Active = 0 UnitStatus = 'RELEASED' Order By UnitNumber"; } var DbObjDataTable = new DataTable(); var DbObjAdapter = new System.Data.SqlClient.SqlDataAdapter(Sql, DBConnect); var DbObjCommand = new System.Data.SqlClient.SqlCommandBuilder(DbObjAdapter); DbObjAdapter.Fill(DbObjDataTable); TotalRecords = DbObjDataTable.Rows.Count; if (TotalRecords > 0) { BookingInfo = new string[TotalRecords]; Refresh(); foreach (DataRow RailListRow in DbObjDataTable.Rows) { RailStructure.UnitNumber = MdlContainerManagement.DoFunctions.PadToString(Conversions.ToString(RailListRow["OriginalUnitNumber"]), 16); // .CustomerName = DoFunctions.PadToString(RailListRow("Consignee Name"), 50) RailStructure.CustomerName = MdlContainerManagement.DoFunctions.PadToString(Conversions.ToString(RailListRow["CustomerName"]), 50); RailStructure.UnitStatus = RailList1.ConvertUnitStatus(Conversions.ToString(RailListRow["UnitStatus"])); if (Information.IsDate(RailListRow["LastTraced"]) == true) { RailStructure.LastUpdate = MdlContainerManagement.DoFunctions.DateToNum(DateAndTime.DateValue(Conversions.ToString(RailListRow["LastTraced"]))); } else { RailStructure.LastUpdate = MdlContainerManagement.DoFunctions.MKL(0); } if (!(Information.IsDBNull(RailListRow["CallDate"]) == true)) { RailStructure.CallDate = MdlContainerManagement.DoFunctions.DateToNum(Conversions.ToDate(RailListRow["CallDate"])); } else { RailStructure.CallDate = MdlContainerManagement.DoFunctions.MKL(0); } RailStructure.ArrivalDate = MdlContainerManagement.DoFunctions.MKL(0); if (Information.IsDate(RailListRow["BillDate"]) == true) { RailStructure.WayBillDate = MdlContainerManagement.DoFunctions.DateToNum(DateAndTime.DateValue(Conversions.ToString(RailListRow["BillDate"]))); } else { RailStructure.WayBillDate = MdlContainerManagement.DoFunctions.MKL(0); } // .ShipperName = DoFunctions.PadToString(RailListRow("Shipper Name"), 35) RailStructure.ShipperName = MdlContainerManagement.DoFunctions.PadToString(Conversions.ToString(RailListRow["ShipperName"]), 35); if (RailListRow.IsNull("OriginLocation") == true) { RailStructure.OriginLocation = MdlContainerManagement.DoFunctions.PadToString(Conversions.ToString(' '), 35); } else { RailStructure.OriginLocation = MdlContainerManagement.DoFunctions.PadToString(Conversions.ToString(RailListRow["OriginLocation"]), 35); } if (RailListRow.IsNull("UnitLine") == true) { RailStructure.SASC = MdlContainerManagement.DoFunctions.PadToString("", 4); } else { RailStructure.SASC = MdlContainerManagement.DoFunctions.PadToString(Conversions.ToString(RailListRow["UnitLine"]), 4); } if (RailListRow.IsNull("ETADate") == true) { RailStructure.ETADate = MdlContainerManagement.DoFunctions.MKL(0); RailStructure.ETADays = MdlContainerManagement.DoFunctions.MKI(0); } else { RailStructure.ETADate = MdlContainerManagement.DoFunctions.DateToNum(DateAndTime.DateValue(Conversions.ToString(RailListRow["ETADate"]))); DayAmt = (short)DateAndTime.DateDiff(DateInterval.Day, DateAndTime.Today.Date, DateAndTime.DateValue(Conversions.ToString(RailListRow["ETADate"]))); if (DayAmt > 0) { RailStructure.ETADays = MdlContainerManagement.DoFunctions.MKI(DayAmt); } else { RailStructure.ETADays = MdlContainerManagement.DoFunctions.MKI(0); } } RailStructure.EquipType = MdlContainerManagement.DoFunctions.PadToString(Conversions.ToString(RailListRow["UnitType"]), 6); if (RailListRow.IsNull("TotalBilled") == true) { RailStructure.WgtMT = MdlContainerManagement.DoFunctions.MKS(0f); } else { RailStructure.WgtMT = MdlContainerManagement.DoFunctions.MKS(Conversions.ToSingle(RailListRow["TotalBilled"])); } RailStructure.Bags = MdlContainerManagement.DoFunctions.MKL(0); if (RailListRow.IsNull("LastLocation") == true) { RailStructure.SightingLocation = MdlContainerManagement.DoFunctions.PadToString(Conversions.ToString(' '), 13); } else { RailStructure.SightingLocation = MdlContainerManagement.DoFunctions.PadToString(Conversions.ToString(RailListRow["LastLocation"]), 13); } RailStructure.CaargoDescription = MdlContainerManagement.DoFunctions.PadToString(Conversions.ToString(' '), 15); BookingInfo[RecCount] = ""; TempLine += Conversions.ToString('\0') + RailStructure.UnitNumber + RailStructure.CustomerName + Conversions.ToString(RailStructure.UnitStatus) + RailStructure.LastUpdate + RailStructure.SightingLocation + RailStructure.ETADate + RailStructure.ETADays + RailStructure.CallDate + RailStructure.ArrivalDate + RailStructure.WayBillDate + RailStructure.ShipperName + RailStructure.OriginLocation + RailStructure.SASC + RailStructure.EquipType + RailStructure.WgtMT + RailStructure.Bags + RailStructure.CaargoDescription + Conversions.ToString(UnitLineStatus) + MdlContainerManagement.DoFunctions.MKL(0) + MdlContainerManagement.DoFunctions.MKL(Conversions.ToInteger(RailListRow["UnitSourceId"])); RecCount += 1; } } deactivateBtns(); return(TempLine); }
private string FetchThisBooking(string ThisBookNumber, int railListID) { short x = 0; short cnt = 0; string SQL = ""; string BookingLine = ""; string BookingNumber = ""; string DeliverBook = ""; string SSLineCode = ""; string DeliverCanTotal = ""; string LRDDate = ""; char LRDTime = '\0'; string TerminalName = ""; string VesselName = ""; char SplitBooking = '\0'; string DeliverBookings = ""; string TempLine = ""; string ChangedMask = ""; string DeliverReadyCans = ""; int BookCount = 0; short TotalCans = 0; short DeliverCans = 0; string bkLetter; string unit; string recordKeyQuery; if (railListID == 0) { recordKeyQuery = "[RailListID] is null"; } else { recordKeyQuery = "[RailListID] = '" + railListID.ToString() + "'"; } SQL = @"select b.*, [MiniBookingOrder], MiniUnitOrder, bus.Unit from Bookings as b join MiniBooking as mb on b.[Booking Number] = mb.[BookingNumber] and b.[Booking Number] = '" + ThisBookNumber + @"' join [Booking Unit Sources] bus on bus.[Minibooking ID] = mb.[MiniBookingId] and " + recordKeyQuery + " and Unit = '" + focusedUnitNumber + @"' left join MiniUnit as mu on mu.MiniUnitId = bus.MiniUnitID order by [MiniBookingOrder] "; var DbObjDataTable = new DataTable(); var DbObjAdapter = new System.Data.SqlClient.SqlDataAdapter(SQL, DBConnect); var DbObjCommand = new System.Data.SqlClient.SqlCommandBuilder(DbObjAdapter); DbObjAdapter.Fill(DbObjDataTable); Refresh(); foreach (DataRow BookNum in DbObjDataTable.Rows) { bool multiMB = DbObjDataTable.Select(Conversions.ToString(Operators.AddObject(Operators.AddObject("[Booking Number] = '", BookNum["Booking Number"]), "'"))).Length > 1; if (multiMB) { bkLetter = "(" + MdlBookingManagement.digitToLetter(BookNum["MiniBookingOrder"]) + ")"; } else { bkLetter = ""; } BookingNumber = MdlContainerManagement.DoFunctions.PadToString(Strings.Trim(Conversions.ToString(BookNum["Booking Number"])) + bkLetter, 40); if (!string.IsNullOrEmpty(Strings.RTrim(BookingNumber))) { if (!BookNum.IsNull("LRD") & Information.IsDate(BookNum["LRD"])) { LRDDate = MdlContainerManagement.DoFunctions.DateToNum(DateAndTime.DateValue(Conversions.ToString(BookNum["LRD"]))); } else { LRDDate = MdlContainerManagement.DoFunctions.MKL(0); } if (BookNum.IsNull("Terminal Name") == true) { TerminalName = MdlContainerManagement.DoFunctions.PadToString(Conversions.ToString(' '), 40); } else { TerminalName = MdlContainerManagement.DoFunctions.PadToString(Conversions.ToString(BookNum["Terminal Name"]), 40); } if (BookNum.IsNull("Vessel Name") == true) { VesselName = MdlContainerManagement.DoFunctions.PadToString(Conversions.ToString(' '), 50); } else { VesselName = MdlContainerManagement.DoFunctions.PadToString(Conversions.ToString(BookNum["Vessel Name"]), 50); } if (BookNum.IsNull("Split Booking") == false && Conversions.ToBoolean(Operators.ConditionalCompareObjectEqual(BookNum["Split Booking"], true, false))) { SplitBooking = '\u0001'; } else { SplitBooking = '\0'; } if (BookNum.IsNull("SS Line Code") == true) { SSLineCode = MdlContainerManagement.DoFunctions.PadToString(Conversions.ToString(' '), 10); } else { SSLineCode = MdlContainerManagement.DoFunctions.PadToString(Conversions.ToString(BookNum["SS Line Code"]), 10); } LRDTime = '\0'; ChangedMask = Conversions.ToString('\0') + Conversions.ToString('\0') + Conversions.ToString('\0') + Conversions.ToString('\0'); // DeliverBook = Mid(DeliverBookings, x, 40) DeliverCanTotal = MdlContainerManagement.DoFunctions.MKL(Conversions.ToInteger(BookNum["Number Of Cans"])); if (multiMB) { if (!Information.IsDBNull(BookNum["MiniUnitOrder"])) { bkLetter = "(" + MdlBookingManagement.digitToLetter(BookNum["MiniUnitOrder"]).ToUpper() + ")"; } else { bkLetter = ""; } } else { bkLetter = ""; } unit = MdlContainerManagement.DoFunctions.PadToString(Strings.Trim(Conversions.ToString(BookNum["Unit"])) + bkLetter, 40); TempLine = Conversions.ToString('\0') + BookingNumber + unit + SSLineCode + LRDDate + Conversions.ToString(LRDTime) + TerminalName + VesselName + Conversions.ToString(SplitBooking) + DeliverCanTotal + MdlContainerManagement.DoFunctions.MKL(0) + MdlContainerManagement.DoFunctions.MKL(0) + MdlContainerManagement.DoFunctions.MKL(0) + MdlContainerManagement.DoFunctions.MKL(0) + ChangedMask; BookingLine += TempLine; // Next x // End If } } return(BookingLine); }