コード例 #1
0
 /// <summary>
 /// Processes the login screen data
 /// </summary>
 /// <param name="data">The string from the textbox</param>
 private void ProcessData(string data)
 {
     if (data.StartsWith("qzu"))
     {
         MainWindow.AuthdEmployee = _empcol.FindEmployeeByID(int.Parse(data.Replace("qzu", "")));
         Close();
     }
     else if (data.Length > 0 & data.Length < 3)
     {
         LoginTitle.Text = _empcol.FindEmployeeByID(Convert.ToInt32(data)).FullName + " Please enter your Pin";
         CurrentEmployee = _empcol.FindEmployeeByID(Convert.ToInt32(data));
         _requirespin    = true;
     }
     else if (_requirespin)
     {
         if (CurrentEmployee.CheckPin(data))
         {
             MainWindow.AuthdEmployee = CurrentEmployee;
             _requirespin             = false;
             Close();
         }
         else
         {
             var msg = new WPFMsgBox("Error", "That is the wrong pin, please try again");
             msg.ShowDialog();
         }
     }
 }
コード例 #2
0
        /// <summary>
        /// Loads messages for a specified thread
        /// </summary>
        /// <param name="threadId"></param>
        /// <param name="firstLoad"></param>
        /// <param name="amountToLoad"></param>
        private void ProcessThreadId(int threadId, bool firstLoad = false, int amountToLoad = 100)
        {
            GC.Collect();
            var who          = CheckThreadUsers(threadId, false);
            var queryResults = null as ArrayList;

            try
            {
                if (firstLoad)
                {
                    var query = SQLServer.SelectData("SELECT TOP " + amountToLoad.ToString() + " * from whldata.messenger_messages WHERE threadid like'" + threadId.ToString() + "' ORDER BY messageid desc") as ArrayList;
                    if (query == null)
                    {
                        throw new NullReferenceException();
                    }
                    query.Reverse();
                    queryResults = query;

                    _lastMessageInThread = -1;
                    MessageStack.Children.Clear();
                }
                else
                {
                    var query = SQLServer.SelectData("SELECT TOP " + amountToLoad.ToString() + " * from whldata.messenger_messages WHERE threadid like'" + threadId.ToString() + "' AND messageid > '" + _lastMessageInThread.ToString() + "' ORDER BY messageid desc") as ArrayList;
                    if (query == null)
                    {
                        throw new NullReferenceException();
                    }
                    query.Reverse();
                    queryResults = query;
                }
            }
            catch (NullReferenceException)
            { }
            try
            {
                if (!who.Contains(AuthdEmployee))
                {
                    firstLoad      = false;
                    _currentThread = -1;
                    MessageStack.Children.Clear();
                    _lastMessageInThread = -1;
                    who.Clear();
                }
                else if (queryResults == null)
                {
                    throw new Exception("SQL Query Failed");
                }
                else if (queryResults.Count == 0)
                {
                    return;
                }
                else
                {
                    foreach (ArrayList result in queryResults)
                    {
                        var message = result[2].ToString().ToLower();
                        if (message.Contains(".jpg") || message.Contains(".jpeg") || message.Contains(".png"))
                        {
                            if (result[1].ToString() == AuthdEmployee.PayrollId.ToString())
                            {
                                var msg = new UserPictureControl
                                {
                                    ImageContainer = { Source = new BitmapImage(new Uri(message)) }
                                };
                                msg.InitializeComponent();
                                msg.MouseUp += Msg_MouseUp;
                                msg.TouchUp += Msg_TouchUp;
                                MessageStack.Children.Add(msg);
                            }
                            else
                            {
                                var otherMsg =
                                    new OtherPictureControl
                                {
                                    ImageContainer = { Source = new BitmapImage(new Uri(message)) },
                                    SenderName     =
                                    {
                                        Text = _empcol.FindEmployeeByID(int.Parse(result[1].ToString())).FullName
                                    }
                                };
                                otherMsg.MouseUp += OtherMsg_MouseUp;
                                otherMsg.TouchUp += OtherMsg_TouchUp;
                                otherMsg.InitializeComponent();
                                MessageStack.Children.Add(otherMsg);
                            }
                        }
                        else if (message.Contains("https://") || message.Contains("http://"))
                        {
                            if (result[1].ToString() == AuthdEmployee.PayrollId.ToString())
                            {
                                var msg = new SelfMessage {
                                    FromMessageBox = { Text = "" }
                                };
                                msg.FromMessageBox.Inlines.Clear();
                                var splitStrings = Regex.Split(result[2].ToString(), " ");

                                foreach (var splits in splitStrings)
                                {
                                    if (splits.Contains("http://") || splits.Contains("https://"))
                                    {
                                        var splitHyperlinks = Regex.Split(splits, " ");
                                        foreach (var hyperLinks in splitHyperlinks)
                                        {
                                            if (hyperLinks.Contains("http://") || hyperLinks.Contains("https://"))
                                            {
                                                var newHyperLink = new Hyperlink
                                                {
                                                    NavigateUri = new Uri(hyperLinks),
                                                };
                                                newHyperLink.Inlines.Add(hyperLinks);
                                                newHyperLink.RequestNavigate += NewHyperLink_RequestNavigate;
                                                msg.FromMessageBox.Inlines.Add(newHyperLink);
                                                msg.FromMessageBox.Inlines.Add(" ");
                                            }
                                            else
                                            {
                                                msg.FromMessageBox.Inlines.Add(splits + " ");
                                            }
                                        }
                                    }
                                    else
                                    {
                                        msg.FromMessageBox.Inlines.Add(splits + " ");
                                    }
                                }
                                msg.InitializeComponent();
                                MessageStack.Children.Add(msg);
                            }
                            else if (result[1].ToString() == "0")
                            {
                                var msg = new SystemNotiControl {
                                    SystemNoti = { Text = result[2].ToString() }
                                };
                                msg.InitializeComponent();
                                MessageStack.Children.Add(msg);
                            }
                            else if (result[1].ToString() != AuthdEmployee.PayrollId.ToString())
                            {
                                var msg = new OtherMessage {
                                    OtherMessageBox = { Text = "" }
                                };
                                msg.OtherMessageBox.Inlines.Clear();
                                var splitStrings = Regex.Split(result[2].ToString(), " ");
                                var lastString   = splitStrings.Last();
                                foreach (var splits in splitStrings)
                                {
                                    var isLast = splits == lastString;
                                    if (splits.Contains("http://") || splits.Contains("https://"))
                                    {
                                        var splitHyperlinks = Regex.Split(splits, " ");
                                        foreach (var hyperLinks in splitHyperlinks)
                                        {
                                            if (hyperLinks.Contains("http://") || hyperLinks.Contains("https://"))
                                            {
                                                var newHyperLink = new Hyperlink {
                                                    NavigateUri = new Uri(hyperLinks)
                                                };
                                                newHyperLink.Inlines.Add(hyperLinks);
                                                newHyperLink.RequestNavigate += NewHyperLink_RequestNavigate;
                                                if (isLast)
                                                {
                                                    msg.OtherMessageBox.Inlines.Add(newHyperLink);
                                                }
                                                else
                                                {
                                                    msg.OtherMessageBox.Inlines.Add(newHyperLink + " ");
                                                }
                                            }
                                            else
                                            {
                                                if (isLast)
                                                {
                                                    msg.OtherMessageBox.Inlines.Add(splits);
                                                }
                                                else
                                                {
                                                    msg.OtherMessageBox.Inlines.Add(splits + " ");
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (isLast)
                                        {
                                            msg.OtherMessageBox.Inlines.Add(splits);
                                        }
                                        else
                                        {
                                            msg.OtherMessageBox.Inlines.Add(splits + " ");
                                        }
                                    }
                                }
                                msg.SenderName.Text = _empcol.FindEmployeeByID(int.Parse(result[1].ToString())).FullName;
                                msg.InitializeComponent();
                                MessageStack.Children.Add(msg);
                            }
                        }
                        else if (result[1].ToString() == AuthdEmployee.PayrollId.ToString())
                        {
                            var msg = new SelfMessage {
                                FromMessageBox = { Text = result[2].ToString() }
                            };
                            msg.InitializeComponent();
                            MessageStack.Children.Add(msg);
                        }
                        else if (result[1].ToString() == "0")
                        {
                            var msg = new SystemNotiControl {
                                SystemNoti = { Text = result[2].ToString() }
                            };
                            msg.InitializeComponent();
                            MessageStack.Children.Add(msg);
                        }
                        else if (result[1].ToString() != AuthdEmployee.PayrollId.ToString())
                        {
                            var msg = new OtherMessage
                            {
                                OtherMessageBox = { Text = result[2].ToString() },
                                SenderName      =
                                {
                                    Text = _empcol.FindEmployeeByID(Int32.Parse(result[1].ToString())).FullName
                                }
                            };
                            msg.InitializeComponent();
                            MessageStack.Children.Add(msg);

                            if (firstLoad)
                            {
                                continue;
                            }
                            TextOnlyNotification[] notiText =
                            {
                                new TextOnlyNotification(result[2].ToString(), HandleNoti)
                            };
                            Notification.CreateNotification("Messenger", notiText, 20);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (e.Message != "Skip Foreach")
                {
                    var msgbox = new WPFMsgBox
                    {
                        Body        = { Text = e.Message },
                        DialogTitle = { Text = "Failed to load" }
                    };
                    msgbox.ShowDialog();
                }
            }
            finally
            {
                if (firstLoad)
                {
                    MessageScrollviewer.ScrollToEnd();            //Only scrolls to end on first load
                }
                ThreadUserTextBlock.Text = "";
                if (firstLoad)
                {
                    CurrentThreadPanel.Children.Clear();
                    foreach (var result in who)
                    {
                        var ctrl = new ContactControl(result)
                        {
                            ThreadUsers = { Content = result.FullName }
                        };
                        ctrl.AddToThreadButton.Click += RemoveFromThreadClick;
                        ctrl.InitializeComponent();
                        CurrentThreadPanel.Children.Add(ctrl);
                    }
                }

                if (who == null || who.Count == 0)
                {
                    ThreadUserTextBlock.Text = "";
                }
                else
                {
                    foreach (var result in who)
                    {
                        ThreadUserTextBlock.Text += result.FullName + ", ";
                    }
                    char[] removecomma = { ',', ' ' };
                    ThreadUserTextBlock.Text = ThreadUserTextBlock.Text.TrimEnd(removecomma);
                }


                var lastMessage = SQLServer.MSSelectDataDictionary("SELECT TOP 1 messageid from whldata.messenger_messages WHERE threadid like'" + threadId.ToString() + "' ORDER BY messageid desc");
                if (lastMessage.Count > 0)
                {
                    try
                    {
                        _lastMessageInThread = Convert.ToInt32(lastMessage[0]["messageid"]);
                    }
                    catch (Exception)
                    {
                        _lastMessageInThread = -1;
                    }
                }
                else
                {
                    _lastMessageInThread = -1;
                }
            }
        }