private void StartNotifier()
        {
            LoadRequest();

            if (notifierStatus.Contains("true"))
            {
                var startTimeSpan = TimeSpan.Zero;

                var periodTimeSpan = TimeSpan.FromMinutes(double.Parse(timeInterval));

                var timer = new System.Threading.Timer((e) =>
                {
                    SQLCon.DbCon();
                    SQLCon.sqlCommand    = new SqlCommand(@"SELECT DISTINCT AssignedTechnician FROM ServiceRequestInfoes WHERE Status = 0", SQLCon.sqlConnection);
                    SQLCon.sqlDataReader = SQLCon.sqlCommand.ExecuteReader();

                    while (SQLCon.sqlDataReader.Read())
                    {
                        techName += (SQLCon.sqlDataReader["AssignedTechnician"].ToString()) + ", \n";
                    }

                    notifyIcon1.Icon    = new System.Drawing.Icon(Path.GetFullPath(@"image\icons8_maintenance.ico"));
                    notifyIcon1.Text    = "URGENT REPAIR";
                    notifyIcon1.Visible = true;

                    notifyIcon1.BalloonTipTitle = "HAVE URGENT REPAIR";
                    notifyIcon1.BalloonTipText  = "There is a pending request for: \n" + techName;
                    notifyIcon1.BalloonTipIcon  = ToolTipIcon.Warning;
                    notifyIcon1.ShowBalloonTip(100);

                    techName = String.Empty;
                }, null, startTimeSpan, periodTimeSpan);
            }
        }
Exemple #2
0
        private void LoginValidation()
        {
            Cursor.Current = Cursors.WaitCursor;
            SQLCon.DbCon();
            SQLCon.sql        = "SELECT USER_ID, Username, Password, FirstName, LastName , AccessLevel, IsActive FROM Accounts WHERE Username=@1 AND Password=@2";
            SQLCon.sqlCommand = new SqlCommand(SQLCon.sql, SQLCon.sqlConnection);
            SQLCon.sqlCommand.Parameters.AddWithValue("@1", tb_Username.Text);
            SQLCon.sqlCommand.Parameters.AddWithValue("@2", tb_Password.Text);
            SQLCon.sqlDataReader = SQLCon.sqlCommand.ExecuteReader();

            while (SQLCon.sqlDataReader.Read())
            {
                AccountValidationClass.AccountID = Convert.ToInt32((SQLCon.sqlDataReader["USER_ID"].ToString()));
                AccountValidationClass.Username  = (SQLCon.sqlDataReader["Username"].ToString());
                AccountValidationClass.Password  = (SQLCon.sqlDataReader["Password"].ToString());
                AccountValidationClass.FirstName = (SQLCon.sqlDataReader["FirstName"].ToString());
                AccountValidationClass.LastName  = (SQLCon.sqlDataReader["LastName"].ToString());
                accountValidation = (SQLCon.sqlDataReader["IsActive"].ToString());
                role = (SQLCon.sqlDataReader["AccessLevel"].ToString());
            }


            if (AccountValidationClass.Username == tb_Username.Text && AccountValidationClass.Password == tb_Password.Text && accountValidation == "True")
            {
                if (role == "ADMIN")
                {
                    Notifyer_MainForm.accessLevel = "ADMIN";
                }
                else if (role == "TECHNICIAN")
                {
                    Notifyer_MainForm.accessLevel = "TECHNICIAN";
                }
                else if (role == "PROGRAMMER")
                {
                    Notifyer_MainForm.accessLevel = "PROGRAMMER";
                }

                this.Close();
            }
            else if (accountValidation == "False" && AccountValidationClass.Username == tb_Username.Text && AccountValidationClass.Password == tb_Password.Text)
            {
                MessageBox.Show("Your account has been suspended. Please contact the Administrator");
                tb_Password.Clear();
                tb_Username.Clear();
            }
            else
            {
                MessageBox.Show("Incorrect username or password");
                tb_Password.Clear();
                tb_Username.Clear();

                //}
                Cursor.Current = Cursors.Default;
            }
        }
        private void LoadRequest()
        {
            SQLCon.DbCon();
            SQLCon.sqlDataApater = new SqlDataAdapter(
                @"SELECT
                    T1.SR_ID,
                    T1.TypeOfServiceProvided AS [Type Of Service Provided],
                    T1.RequestedBy AS [Requested By],
                    T1.OfficeDepartmentName AS [Office],
                    T1.DateRequested AS [Date Requested],
                    T1.TimeLeft AS [Time Left],
                    T1.AssignedTechnician AS [Assigned Technician],
                    T1.RemarkDeatails AS [Remarks]
                FROM
                    ServiceRequestInfoes AS T1
                WHERE
                    T1.Status = 0
                  ", SQLCon.sqlConnection);
            SQLCon.dataTable = new DataTable();
            SQLCon.sqlDataApater.Fill(SQLCon.dataTable);
            dataGridView_ListOfRequest.DataSource = SQLCon.dataTable;
            dataGridView_ListOfRequest.Sort(dataGridView_ListOfRequest.Columns["Date Requested"], ListSortDirection.Ascending);
            DesignTable();


            foreach (DataGridViewRow row in dataGridView_ListOfRequest.Rows)
            {
                //CONVERTION FROM DATE TO SECONDS
                DateTime dateRequested = Convert.ToDateTime(row.Cells[4].Value.ToString());
                DateTime dateETA       = new DateTime();
                if (dateRequested.DayOfWeek == DayOfWeek.Thursday)
                {
                    dateETA = Convert.ToDateTime(dateRequested.AddDays(4));
                }
                else if (dateRequested.DayOfWeek == DayOfWeek.Friday)
                {
                    dateETA = Convert.ToDateTime(dateRequested.AddDays(5));
                }
                else
                {
                    dateETA = Convert.ToDateTime(dateRequested.AddDays(2));
                }

                //DateTime dateETA = Convert.ToDateTime(row.Cells[6].Value.ToString());

                TimeSpan remainingTime = dateETA - DateTime.Now;
                if (DateTime.Now < dateETA)
                {
                    int seconds  = Convert.ToInt32(remainingTime.TotalSeconds);
                    var timeLeft = TimeSpan.FromSeconds(int.Parse(seconds.ToString()));
                    var dateTime = String.Format("{0} days, {1} hours, {2} minutes, {3} seconds", timeLeft.Days, timeLeft.Hours, timeLeft.Minutes, timeLeft.Seconds);
                    row.Cells["Time Left"].Value           = dateTime;
                    row.Cells["Time Left"].Style.BackColor = Color.FromArgb(255, 82, 82);
                }
                else if (DateTime.Now > dateETA)
                {
                    var dateTime = String.Format("{0} days, {1} hours, {2} minutes, {3} seconds", 0, 0, 0, 0);
                    row.Cells["Time Left"].Value           = dateTime;
                    row.Cells["Time Left"].Style.BackColor = Color.Yellow;
                }
            }
        }