none
How to replace DateOnlyRecord with DateTimeRecord ? RRS feed

  • Question

  • I have zk machine have attendance of more users and i need to get last record per machine

    meaning last user making attendance i need to get it 

    or any way can get last record per machine 

    i need only to using datetime not date 

    calling button 

    private void btnPullData_Click(object sender, EventArgs e) { try { ShowStatusBar(string.Empty, true); ICollection<MachineInfo> lstMachineInfo = manipulator.GetLogData(objZkeeper, int.Parse(tbxMachineNumber.Text.Trim())); DateTime LastRecord = DateTime.Today.AddDays(-1); lstMachineInfo = lstMachineInfo.Where(x => x.DateOnlyRecord > LastRecord).ToList(); if (lstMachineInfo != null && lstMachineInfo.Count > 0) { BindToGridView(lstMachineInfo); ShowStatusBar(lstMachineInfo.Count + " records found !!", true); } else DisplayListOutput("No records found"); } catch (Exception ex) { DisplayListOutput(ex.Message); } }

    and function it self as below

     public ICollection<MachineInfo> GetLogData(ZkemClient objZkeeper, int machineNumber)
            {
                string dwEnrollNumber1 = "";
                int dwVerifyMode = 0;
                int dwInOutMode = 0;
                int dwYear = 0;
                int dwMonth = 0;
                int dwDay = 0;
                int dwHour = 0;
                int dwMinute = 0;
                int dwSecond = 0;
                int dwWorkCode = 0;
    
                ICollection<MachineInfo> lstEnrollData = new List<MachineInfo>();
    
                objZkeeper.ReadAllGLogData(machineNumber);
    
                while (objZkeeper.SSR_GetGeneralLogData(machineNumber, out dwEnrollNumber1, out dwVerifyMode, out dwInOutMode, out dwYear, out dwMonth, out dwDay, out dwHour, out dwMinute, out dwSecond, ref dwWorkCode))
    
    
                {
                    string inputDate = new DateTime(dwYear, dwMonth, dwDay, dwHour, dwMinute, dwSecond).ToString();
    
                    MachineInfo objInfo = new MachineInfo();
                    objInfo.MachineNumber = machineNumber;
                    objInfo.IndRegID = int.Parse(dwEnrollNumber1);
                    objInfo.DateTimeRecord = inputDate;
    
                    lstEnrollData.Add(objInfo);
                }
    
                return lstEnrollData;
            }

    class machineinfo as following

    public class MachineInfo
        {
            public int MachineNumber { get; set; }
            public int IndRegID { get; set; }
            public string DateTimeRecord { get; set; }
    
            public DateTime DateOnlyRecord
            {
                get { return DateTime.Parse(DateTime.Parse(DateTimeRecord).ToString("yyyy-MM-dd")); }
            }
            public DateTime TimeOnlyRecord
            {
                get { return DateTime.Parse(DateTime.Parse(DateTimeRecord).ToString("hh:mm:ss tt")); }
            }
    
        }

    i need to  replace 

    replace (x => x.DateOnlyRecord > LastRecord) with

    DateTimeRecord


    Wednesday, April 3, 2019 3:44 PM

Answers

  • can any one help me actual i need to get last record per machine attendance

    on day today 

    what i do above get attendance on same day or today only

    but i need to replace 

    DateOnlyRecord with DatetimeRecord

    problem i face i need to convert string to date time but cannot do that

    replace
    (x => x.DateOnlyRecord )
    with
    DateTimeRecord
    because Dateonly record is datetime
    but datetimerecord is string


    Hi   engahmedbarbary, 

    Thank you for posting here. Based on your question, You can use the Convert.ToDateTime() method to replace x => x.DateOnlyRecord  with  x => Convert.ToDateTime( x.DateTimeRecord ):

    lstMachineInfo = lstMachineInfo.Where(x => Convert.ToDateTime( x.DateTimeRecord ) > LastRecord).ToList();               

    The result  is shown below:



    Best Regards

    Yong Lu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Thursday, April 4, 2019 9:19 AM
    Moderator

All replies

  • can any one help me actual i need to get last record per machine attendance

    on day today 

    what i do above get attendance on same day or today only

    but i need to replace 

    DateOnlyRecord with DatetimeRecord

    problem i face i need to convert string to date time but cannot do that

    replace
    (x => x.DateOnlyRecord )
    with
    DateTimeRecord
    because Dateonly record is datetime
    but datetimerecord is string

    Wednesday, April 3, 2019 8:17 PM
  • can any one help me actual i need to get last record per machine attendance

    on day today 

    what i do above get attendance on same day or today only

    but i need to replace 

    DateOnlyRecord with DatetimeRecord

    problem i face i need to convert string to date time but cannot do that

    replace
    (x => x.DateOnlyRecord )
    with
    DateTimeRecord
    because Dateonly record is datetime
    but datetimerecord is string


    Hi   engahmedbarbary, 

    Thank you for posting here. Based on your question, You can use the Convert.ToDateTime() method to replace x => x.DateOnlyRecord  with  x => Convert.ToDateTime( x.DateTimeRecord ):

    lstMachineInfo = lstMachineInfo.Where(x => Convert.ToDateTime( x.DateTimeRecord ) > LastRecord).ToList();               

    The result  is shown below:



    Best Regards

    Yong Lu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Thursday, April 4, 2019 9:19 AM
    Moderator