Exemplo n.º 1
0
        private void TerminalUpdate()
        {
            TerminalUpdateTimer           = new System.Timers.Timer(10000);
            TerminalUpdateTimer.AutoReset = true;
            TerminalUpdateTimer.Elapsed  += (object sender, System.Timers.ElapsedEventArgs e) => {
                if (isConnected)
                {
                    DataTable dt = new DataTable();
                    dt = dbAccess.GetTerminalUpdate();
                    log.Write($"Processing  {dt.Rows.Count} Terminal Updates");
                    try
                    {
                        if (dt.Rows.Count > 0)
                        {
                            TerminalUpdateTimer.Stop();
                            // u_type 1 add,2 delete,3 update
                            if (dt.Rows.Count > 1)
                            {
                            }
                            foreach (DataRow Row in dt.Rows)
                            {
                                if ((byte)Row[1] == 1 || (byte)Row[1] == 3)     //Add / Modily Student
                                {
                                    if (TDecvice.AddUser(((int)Row[2]).ToString(), (string)Row[3]))
                                    {
                                        Row[4] = DateTime.Now;
                                        log.Write($"Student with Sid { ((int)Row[2]).ToString()}  Successfully added to Clock");
                                    }
                                }
                                else if ((byte)Row[1] == 2)    // Delete Student
                                {
                                    if (TDecvice.DeleteUser(((int)Row[2]).ToString()))
                                    {
                                        Row[4] = DateTime.Now;
                                        log.Write($"User with id {(int)Row[2]} Successfully Deleted From Clock");
                                    }
                                    else
                                    {
                                        if (!TDecvice.isUserExist(((int)Row[2]).ToString()))
                                        {
                                            Row[4] = DateTime.Now;
                                        }
                                    }
                                }
                                else
                                {
                                    log.Write($"Wrong Value called in terminal update as update type for update id  {(int)Row[0]} student {(string)Row[3]} ");
                                }
                            }



                            dbAccess.SetTerminalUpdate(dt); //Update the result to db.
                        }
                    }
                    catch (Exception ex)
                    {
                        log.Write("Terminal update block Error" + ex.Message);
                    }
                    finally
                    {
                        TerminalUpdateTimer.Start();
                    }
                }
                else
                {
                    log.Write("Terminal update Failed - Device Not connected");
                }
            };
            TerminalUpdateTimer.Start();
        }