예제 #1
0
        private void UpdateActivityTime(DateTime dt)
        {
            LinqChat1DataContext db = new LinqChat1DataContext();
            var users = from u in db.UserInformations
                        where u.UserID == (string)Session[SMSAppUtilities.SessionKeys.SESSION_LOGIN_USER]
                        select u;

            foreach (var u in users)
            {
                u.LastActivityTime = dt;
                db.SubmitChanges();
            }
        }
예제 #2
0
        public void InsertMessage(string text, string toUserid)
        {
            LinqChat1DataContext db = new LinqChat1DataContext();
            string  date            = DateTime.Now.ToString();
            Message message         = new Message();

            message.UserID    = Session[SMSAppUtilities.SessionKeys.SESSION_LOGIN_USER].ToString();
            message.ToUserID  = toUserid;
            message.TimeStamp = DateTime.Now;
            message.Text      = text.Replace("<", "");
            message.Color     = "black";
            db.Messages.InsertOnSubmit(message);
            db.SubmitChanges();
            UpdateActivityTime(Convert.ToDateTime(date));
        }
예제 #3
0
        public string GetMessages(string stat)
        {
            SqlConnection cn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["SMSConnectionString"].ConnectionString);

            cn.Open();
            string qry;

            if (stat == "on")
            {
                qry = "select * from Message where TimeStamp >  convert(datetime,'" + (DateTime)Session["LastMsg"] + "') and ToUserID='" + (string)Session[SMSAppUtilities.SessionKeys.SESSION_LOGIN_USER] + "' order by ToUserID,TimeStamp";
            }
            else
            {
                LinqChat1DataContext db = new LinqChat1DataContext();
                var usr = (from u in db.UserInformations
                           where u.UserID == (string)Session[SMSAppUtilities.SessionKeys.SESSION_LOGIN_USER]
                           select u).SingleOrDefault();
                qry = "select * from Message where TimeStamp >  convert(datetime,'" + usr.LastActivityTime + "') and ToUserID='" + (string)Session["ChatUserID"] + "' order by ToUserID,TimeStamp";
            }
            Session["LastMsg"] = DateTime.Now;
            SqlDataAdapter da = new SqlDataAdapter(qry, cn);
            DataTable      dt = new DataTable();

            da.Fill(dt);
            UpdateActivityTime((DateTime)Session["LastMsg"]);
            StringBuilder        sb  = new StringBuilder();
            JavaScriptSerializer jss = new JavaScriptSerializer();

            jss.Serialize(RowsToDictionary(dt), sb);
            cn.Dispose();
            da.Dispose();
            dt.Dispose();
            string json = sb.ToString();

            return(json);
        }
예제 #4
0
        public string GetLoggedInUsers()
        {
            try
            {
                LinqChat1DataContext db = new LinqChat1DataContext();
                string        userIcon;
                StringBuilder sb = new StringBuilder();

                var Users = (from u in db.UserInformations
                             where u.UserID != (string)Session[SMSAppUtilities.SessionKeys.SESSION_LOGIN_USER] && u.Role != (string)Session["role"]
                             orderby u.LastActivityTime descending
                             select u);
                int k     = 0;
                var roles = (from r in db.UserRoleMasters
                             where r.UserRole != (string)Session["role"]
                             select r);

                foreach (var role in roles)
                {
                    sb.Append("<div style='font-family:Arial;font-size:13px'><b>" + role.UserRole + "</b></div>");
                    int i = 1;
                    foreach (var User in Users)
                    {
                        if (User.Role == role.UserRole)
                        {
                            if (User.LastActivityTime == null)
                            {
                                User.LastActivityTime = DateTime.Now;
                                db.SubmitChanges();
                            }
                            if ((DateTime.Now - (DateTime)User.LastActivityTime).TotalSeconds > 14)
                            {
                                sb.Append("<div style='padding:0 0 0 20px'>");
                                userIcon = "<img src='Images/offline.png' style='vertical-align:middle' alt=''>  ";
                                sb.Append(userIcon + "<a href=\"#\" onclick=\"AddNewWindow('" + Session[SMSAppUtilities.SessionKeys.SESSION_LOGIN_USER].ToString() + "','" + User.UserID + "');\">" + User.UserID + "</a><br>");
                                sb.Append("</div>");
                            }
                            else
                            {
                                sb.Append("<div style='padding:0 0 0 20px'>");
                                userIcon = "<img src='Images/online.png' style='vertical-align:middle' alt=''>  ";
                                sb.Append(userIcon + "<a href=\"#\" onclick=\"AddNewWindow('" + Session[SMSAppUtilities.SessionKeys.SESSION_LOGIN_USER].ToString() + "','" + User.UserID + "');\">" + User.UserID + "</a><br>");
                                sb.Append("</div>");
                            }
                            k++;
                            i = 0;
                        }
                        if (k > 9)
                        {
                            k = 0;
                            break;
                        }
                    }
                    if (i == 1)
                    {
                        sb.Append("<div style='padding:0 0 0 20px;color:red'>");
                        sb.Append("No Registered Users");
                        sb.Append("</div>");
                    }
                }
                return(sb.ToString());
            }
            catch (Exception ex)
            {
                return(ex.Message + " " + ex.InnerException + " " + ex.Source);
            }
        }