public object Hour(object time) { #if !NETSTANDARD return(DateAndTime.Hour(Convert.ToDateTime(time))); #else return(Convert.ToDateTime(time).Hour); #endif }
public void Fields() { var now = DateTime.UtcNow; var calendar = System.Threading.Thread.CurrentThread.CurrentCulture.Calendar; Assert.Equal(calendar.GetYear(now), DateAndTime.Year(now)); Assert.Equal(calendar.GetMonth(now), DateAndTime.Month(now)); Assert.Equal(calendar.GetDayOfMonth(now), DateAndTime.Day(now)); Assert.Equal(calendar.GetHour(now), DateAndTime.Hour(now)); Assert.Equal(calendar.GetMinute(now), DateAndTime.Minute(now)); Assert.Equal(calendar.GetSecond(now), DateAndTime.Second(now)); }
public static int StrToBLTime(string timeStr) { try { if (timeStr == null) { return(0); } var time = DateAndTime.TimeValue(timeStr); return((DateAndTime.Hour(time) * 100) + DateAndTime.Minute(time)); } catch (Exception) { return(0); } }
//private uint CRC32(string DataStr) //{ // uint returnValue = 0; // uint crc32Result = 0; // short i = 0; // short strLen = 0; // short iLookup = 0; // crc32Result = 0xFFFFFFFF; // strLen = (short)DataStr.Length; // for (i = 1; i <= strLen; i++) // { // iLookup = Convert.ToInt16((crc32Result & 0xFF) ^ Strings.Asc(DataStr.Substring(i - 1, 1))); // crc32Result = Convert.ToUInt32(((crc32Result & 0xFFFFFF00) / 0x100) & 16777215); // nasty shr 8 with vb :/ // crc32Result = crc32Result ^ Convert.ToUInt32(crc32Table[iLookup]); // } // if (crc32Result < 0) // { // returnValue = ~(crc32Result); // } // else // { // returnValue = crc32Result; // } // return returnValue; //} public void WriteToLog(string MsgStr) { string FileName = ""; short fnum = 0; short i; string NewFName = ""; try { if (Chaps_Main.Register_Renamed.WritePosLog) { { FileName = Chaps_Main.Logs_Path + "XML.log"; } if (FileSystem.Dir(FileName) != "") { if (FileSystem.FileLen(FileName) > 1000000) { NewFName = Chaps_Main.Logs_Path + "XML" + DateAndTime.Day(DateAndTime.Today).ToString("00") + DateAndTime.Hour(DateAndTime.TimeOfDay).ToString("00") + ".log"; Variables.CopyFile(FileName, NewFName, 0); Variables.DeleteFile(FileName); } } fnum = (short)(FileSystem.FreeFile()); FileSystem.FileOpen(fnum, FileName, OpenMode.Append); FileSystem.PrintLine(fnum, DateTime.Now + " " + MsgStr); FileSystem.FileClose(fnum); } } catch { goto Err_End; } Err_End: 1.GetHashCode(); //VBConversions note: C# requires an executable line here, so a dummy line was added. }
/// <summary> /// 生成 GPGGA 数据 /// </summary> /// <returns></returns> public string GenerateGPGGAcode() { double posnum = 0; double minutes = 0; DateTime UTCTime = DateTime.UtcNow; //$GPGGA,052158,4158.7333,N,09147.4277,W,2,08,3.1,260.4,M,-32.6,M,,*79 string mycode = "GPGGA,"; if (UTCTime.Hour < 10)// DateAndTime.Hour(UTCTime) < "10") { mycode = mycode + "0"; } mycode = mycode + System.Convert.ToString(DateAndTime.Hour(UTCTime)); if (UTCTime.Minute < 10)//DateAndTime.Minute(UTCTime) < "10") { mycode = mycode + "0"; } mycode = mycode + System.Convert.ToString(DateAndTime.Minute(UTCTime)); if (UTCTime.Second < 10)// DateAndTime.Second(UTCTime) < "10") { mycode = mycode + "0"; } mycode = mycode + System.Convert.ToString(DateAndTime.Second(UTCTime)); mycode = mycode + ","; posnum = 0;// (Math.Abs(OldReceiverForm.Default.NtripParam.ManualLat)); minutes = posnum % 1; posnum = posnum - minutes; minutes = minutes * 60; posnum = (posnum * 100) + minutes; mycode = mycode + posnum.ToString("0000.00####"); if (posnum > 0) //if (MainForm.Default.NtripParam.ManualLon > 0) { mycode = mycode + ",N,"; } else { mycode = mycode + ",S,"; } // posnum = (Math.Abs(OldReceiverForm.Default.NtripParam.ManualLon)); minutes = posnum % 1; posnum = posnum - minutes; minutes = minutes * 60; posnum = (posnum * 100) + minutes; mycode = mycode + posnum.ToString("00000.00####"); // if (OldReceiverForm.Default.NtripParam.ManualLon > 0) { mycode = mycode + ",E,"; } // else { mycode = mycode + ",W,"; } mycode = mycode + "4,10,1,200,M,1,M,"; mycode = mycode + ((DateAndTime.Second(DateTime.Now) % 6) + 3) + ",0"; mycode = "$" + mycode + "*" + CalculateChecksum(mycode); //Add checksum satData return(mycode); }
public static int Hour(DateTime TimeValue) { return(DateAndTime.Hour(TimeValue)); }
public static void WriteToLogFile(string MsgStr) { string FileName = ""; // static short FL = 0; VBConversions Note: Static variable moved to class level and renamed WriteToLogFile_FL. Local static variables are not supported in C#. string NewFName = ""; short fnum = 0; Chaps_Main.Register_Renamed = new CStoreCommander.Entities.Register { WritePosLog = true }; try { if (Chaps_Main.Register_Renamed.WritePosLog) { FileName = @"C:\APILog\PosLog.txt"; WriteToLogFile_FL++; if (WriteToLogFile_FL > 100) { WriteToLogFile_FL = (short)0; if (FileSystem.Dir(FileName) != "") { if (FileSystem.FileLen(FileName) > 1000000) { NewFName = Chaps_Main.Logs_Path + "PosLog" + DateAndTime.Day(DateAndTime.Today).ToString("00") + DateAndTime.Hour(DateAndTime.TimeOfDay).ToString("00") + ".txt"; Variables.CopyFile(FileName, NewFName, 0); Variables.DeleteFile(FileName); } } } fnum = (short)(FileSystem.FreeFile()); FileSystem.FileOpen(fnum, FileName, OpenMode.Append); FileSystem.PrintLine(fnum, DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt") + Strings.Space(3) + MsgStr); FileSystem.FileClose(fnum); } } catch { goto err1; } err1: 1.GetHashCode(); //VBConversions note: C# requires an executable line here, so a dummy line was added. }
private void frmStockTakeCSV_Load(System.Object eventSender, System.EventArgs eventArgs) { // ERROR: Not supported in C#: OnErrorStatement if (modRecordSet.cnnDB == null) { if (openConnection() == true) { } } //creating table name Te_Name = "HandHeld" + Strings.Trim(Convert.ToString(DateAndTime.Year(DateAndTime.Today))) + Strings.Trim(Convert.ToString(DateAndTime.Month(DateAndTime.Today))) + Strings.Trim(Convert.ToString(DateAndTime.Day(DateAndTime.Today))) + Strings.Trim(Convert.ToString(DateAndTime.Hour(DateAndTime.Now))) + Strings.Trim(Convert.ToString(DateAndTime.Minute(DateAndTime.Now))) + Strings.Trim(Convert.ToString(DateAndTime.Second(DateAndTime.Now))) + "_" + My.MyProject.Forms.frmMenu.lblUser.Tag; loadLanguage(); lMWNo = My.MyProject.Forms.frmMWSelect.getMWNo(); if (lMWNo > 1) { //Set rsWH = getRS("SELECT * FROM Warehouse WHERE WarehouseID=" & lMWNo & ";") //Report.txtWH.SetText rsWH("Warehouse_Name") } }
//public static object Hex(object number) //{ // if (number == null) // { // return ZERO; // } // else if (number is DBNull) // { // return number; // } // else // { // return string.Format("{0:X}", number); // } //} public object Hour(object time) { return(DateAndTime.Hour(Convert.ToDateTime(time))); }
/// <summary> /// Method to write to log file /// </summary> /// <param name="msgStr"></param> protected void WriteToLogFile(string msgStr) { try { var register = CacheManager.GetRegister(PosId); if (register.WritePosLog) { var logPath = @"C:\APILog\"; var fileName = logPath + "PosLog_" + PosId + ".txt"; WriteToLogFileFl++; if (WriteToLogFileFl > 100) { WriteToLogFileFl = (short)0; if (FileSystem.Dir(fileName) != "") { if (FileSystem.FileLen(fileName) > 1000000) { var newFName = logPath + "PosLog_" + PosId + DateAndTime.Day(DateAndTime.Today).ToString("00") + DateAndTime.Hour(DateAndTime.TimeOfDay).ToString("00") + ".txt"; Variables.CopyFile(fileName, newFName, 0); Variables.DeleteFile(fileName); } } } using (StreamWriter fileWriter = new StreamWriter(fileName, true)) { fileWriter.WriteLine(DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss tt") + Strings.Space(3) + msgStr); } } } catch (Exception ex) { } }
public decimal DateToJulDate(DateTime vdatDate) { decimal DateToJulDate = default(decimal); if ((DateTime.Compare(vdatDate, new DateTime(499230432000000000L)) < 0) | (DateTime.Compare(vdatDate, new DateTime(693937151990000000L)) > 0)) { Information.Err().Raise(50000, "UtilTime", "Datum außerhalb des Gültigkeitsbereiches."); return(DateToJulDate); } try { DateToJulDate = checked (MakeJulDate((short)DateAndTime.Day(vdatDate), (short)DateAndTime.Month(vdatDate), (short)DateAndTime.Year(vdatDate), (short)DateAndTime.Hour(vdatDate), (short)DateAndTime.Minute(vdatDate), (short)DateAndTime.Second(vdatDate), 0)); return(DateToJulDate); } catch (Exception ex2) { ProjectData.SetProjectError(ex2); Exception ex = ex2; string dstrErrMsg = ExceptionHelper.GetExceptionMessage(ex); Information.Err().Raise(50000, "UtilTime", "Fehler beim Konvertieren des Datums.\n" + dstrErrMsg); ProjectData.ClearProjectError(); return(DateToJulDate); } }
public void CrearLibro() { Random random = new Random(); this.Filename = this.prtRutaParaExportacion.Trim().Length > 0 ? this.prtRutaParaExportacion : "C:\\Exportacion_Excel"; if (!Directory.Exists(this.Filename)) { Directory.CreateDirectory(this.Filename); } this.Filename = this.Filename + "\\" + this.prtTitulo + " " + DateAndTime.DatePart(DateInterval.Day, DateTime.Now, FirstDayOfWeek.Sunday, FirstWeekOfYear.Jan1).ToString() + DateAndTime.Month(DateTime.Now).ToString() + DateAndTime.Year(DateTime.Now).ToString() + DateAndTime.Hour(DateTime.Now).ToString() + DateAndTime.Minute(DateTime.Now).ToString() + DateAndTime.Second(DateTime.Now).ToString() + ".xlsx"; if (File.Exists(this.Filename)) { File.Delete(this.Filename); } if (File.Exists(this.Filename)) { return; } this.chkexcel = false; this.oexcel = (Application)Interaction.CreateObject("Excel.Application", ""); // ISSUE: reference to a compiler-generated method this.obook = this.oexcel.Workbooks.Add((object)Missing.Value); this.oexcel.Application.DisplayAlerts = true; this.chkexcel = true; }
public void subErrorHandlerInitialization(ref ErrorHandler.ErrorHandler objErrorHandlerIn) { //===================================================================== // Procedure Name : gsubErrorHandlerInitialization // Parameters Passed : Global Object of Error HAndler // Returns : None // Purpose : To initialize error handling object // Description : // Assumptions : // Dependencies : // Author : Mangesh Shardul // Created : 14 sept 2004 11:30 am // Revisions : //===================================================================== try { if (IsNothing(gobjErrorHandler) == true) { gobjErrorHandler = new ErrorHandler.ErrorHandler(); } objErrorHandlerIn.CompanyName = Application.ProductName; objErrorHandlerIn.ErrorLogFolder = "ErrorLogs"; objErrorHandlerIn.ErrorLogFileName = Application.StartupPath + "\\" + objErrorHandlerIn.ErrorLogFolder + "\\ErrorLog-" + DateAndTime.DateString + "-" + DateAndTime.Hour(Now) + "-" + DateAndTime.Minute(Now) + "-" + DateAndTime.Second(Now) + ".log"; objErrorHandlerIn.VersionMajor = Application.ProductVersion; objErrorHandlerIn.ProductName = Application.ProductName; objErrorHandlerIn.ExecutionTrailFolder = "ExecutionLogs"; objErrorHandlerIn.ExecutionLogFileName = Application.StartupPath + "\\" + objErrorHandlerIn.ExecutionTrailFolder + "\\ExecutionLog-" + DateAndTime.DateString + "-" + DateAndTime.Hour(Now) + "-" + DateAndTime.Minute(Now) + "-" + DateAndTime.Second(Now) + ".log"; //--- Check for the folders if not create the folders if (!Directory.Exists(Application.StartupPath + "\\" + objErrorHandlerIn.ErrorLogFolder)) { //--- Create the folder Directory.CreateDirectory(Application.StartupPath + "\\" + objErrorHandlerIn.ErrorLogFolder); } if (!Directory.Exists(Application.StartupPath + "\\" + objErrorHandlerIn.ExecutionTrailFolder)) { //--- Create the folder Directory.CreateDirectory(Application.StartupPath + "\\" + objErrorHandlerIn.ExecutionTrailFolder); } } catch (Exception ex) { //--------------------------------------------------------- //Error Handling and logging gobjErrorHandler.ErrorDescription = ex.Message; gobjErrorHandler.ErrorMessage = ex.Message; gobjErrorHandler.WriteErrorLog(ex); //--------------------------------------------------------- } finally { //--------------------------------------------------------- //Writing Execution log if (CONST_CREATE_EXECUTION_LOG == 1) { gobjErrorHandler.WriteExecutionLog(); } //--------------------------------------------------------- } }