private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            UserModel model = this.DataContext as UserModel;
            model.Pwd = this.pwb.Password;
            model.ValidateAllProperty();
            if (model.HasError) return;
            User user = new User();
            user.Name = model.LoginID;
            user.Pwd = model.Pwd;
            try
            {
                if (_Service.AddUser(this._SessionId,user))
                {
                    MessageBox.Show("Success!");
                }
                else
                {
                    MessageBox.Show("The user with the same LoginID has already existed!");
                }
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Network not connected!");
               
            }

        }
Example #2
0
 public bool UpdateUser(string sessionId, User user)
 {
     lock (this._SycBlock)
     {
         if (!ClientManager.Default.Contains(sessionId)) return false;
         if (!IsUserExist(user) || IsUserExistWhenUpdate(user)) return false;
         try
         {
             user.LastModifedDate = DateTime.Now;
             XElement root = XElement.Load(configFile);
             XElement userElement = root.Descendants().Single(x => x.Attribute("Id").Value == user.Id.ToString());
             userElement.SetAttributeValue("Name", user.Name);
             userElement.SetAttributeValue("Pwd", user.Pwd);
             userElement.SetAttributeValue("Date", user.LastModifedDate.ToStandardDatetimeString());
             root.Save(configFile);
             user.Operation = UserOperateEnum.Updated;
             ClientManager.Default.Push(new UserMsg(user));
             return true;
         }
         catch (Exception exception)
         {
             AppDebug.LogEvent("ManagerService.QuotationManager.Service.UpdateUser", exception.ToString(), EventLogEntryType.Error);
             return false;
         }
     }
 }
Example #3
0
        public bool AddUser(string sessionId, User user)
        {
            lock (this._SycBlock)
            {
                if (!ClientManager.Default.Contains(sessionId)) return false;

                if (IsUserExistWhenAdd(user)) return false;
                try
                {
                    user.LastModifedDate = DateTime.Now;
                    user.Id = Guid.NewGuid();
                    XElement root = XElement.Load(configFile);
                    XElement userElement = new XElement("User");
                    userElement.SetAttributeValue("Id", user.Id.ToString());
                    userElement.SetAttributeValue("Name", user.Name);
                    userElement.SetAttributeValue("Pwd", user.Pwd);
                    userElement.SetAttributeValue("Date", user.LastModifedDate.ToStandardDatetimeString());
                    root.Add(userElement);
                    root.Save(configFile);
                    user.Operation = UserOperateEnum.Added;
                    ClientManager.Default.Push(new UserMsg(user));
                    return true;
                }
                catch (Exception exception)
                {
                    AppDebug.LogEvent("ManagerService.QuotationManager.Service.AddUser", exception.ToString(), EventLogEntryType.Error);
                    return false;
                }
            }
        }
Example #4
0
 public void AddUser(User user)
 {
     if (UserCol.Any(m => m.ID == user.Id)) return;
     Common.SynchronizationContext.Post(m =>
     {
         UserCol.Add(new UserModel { ID = user.Id, LoginID = user.Name, Pwd = user.Pwd, LastModifiedDate = user.LastModifedDate });
     }, null);
 }
Example #5
0
 public void DelUser(User user)
 {
     if (!UserCol.Any(m => m.ID == user.Id)) return;
     Common.SynchronizationContext.Post(m =>
     {
         var item = UserCol.Single(c => c.ID == user.Id);
         UserCol.Remove(item);
     }, null);
 }
Example #6
0
 public void UpdateUser(User user)
 {
     if (!UserCol.Any(m => m.ID == user.Id)) return;
     Common.SynchronizationContext.Post(m =>
     {
         var item = UserCol.Single(c => c.ID == user.Id);
         item.LoginID = user.Name;
         item.Pwd = user.Pwd;
         item.LastModifiedDate = user.LastModifedDate;
     }, null);
 }
Example #7
0
 void IFlexServiceCallback.PushUpdateUser(User user)
 {
     switch (user.Operation)
     {
         case UserOperateEnum.Added:
             UserManager.Default.AddUser(user);
             break;
         case UserOperateEnum.Deleted:
             UserManager.Default.DelUser(user);
             break;
         case UserOperateEnum.Updated:
             UserManager.Default.UpdateUser(user);
             break;
     }
 }
Example #8
0
        public bool DelUser(string sessionId, User user)
        {
            lock (this._SycBlock)
            {
                if (!ClientManager.Default.Contains(sessionId)) return false;
                if (!IsUserExist(user)) return false;
                try
                {
                    XElement root = XElement.Load(configFile);
                    XElement userElement = root.Descendants().Single(x => x.Attribute("Id").Value == user.Id.ToString());
                    userElement.Remove();
                    root.Save(configFile);
                    user.Operation = UserOperateEnum.Deleted;
                    ClientManager.Default.Push(new UserMsg(user));
                    return true;
                }
                catch (Exception exception)
                {
                    AppDebug.LogEvent("ManagerService.QuotationManager.Service.KeepAlive", exception.ToString(), EventLogEntryType.Error);
                    return false;
                }

            }
        }
 public UserMsg(User msg)
 {
     this.Msg = msg;
 }
Example #10
0
 private bool IsUserExistWhenAdd(User user)
 {
     try
     {
         XElement root = XElement.Load(configFile);
         return root.Descendants().Any(x => x.Attribute("Name").Value == user.Name.ToString());
     }
     catch (Exception exception)
     {
         AppDebug.LogEvent("ManagerService.QuotationManager.Service.IsUserExistWhenAdd", exception.ToString(), EventLogEntryType.Error);
         return false;
     }
 }
Example #11
0
 public User[] GetUserList(string sessionId)
 {
     lock (this._SycBlock)
     {
         if (!ClientManager.Default.Contains(sessionId)) return null;
         try
         {
             XElement xelment = XElement.Load(configFile);
             List<User> users = new List<User>();
             foreach (var item in xelment.Descendants())
             {
                 User user = new User();
                 user.Id = Guid.Parse(item.Attribute("Id").Value);
                 user.Name = item.Attribute("Name").Value;
                 user.Pwd = item.Attribute("Pwd").Value;
                 user.LastModifedDate = DateTime.Parse(item.Attribute("Date").Value);
                 users.Add(user);
             }
             return users.ToArray();
         }
         catch (Exception exception)
         {
             AppDebug.LogEvent("ManagerService.QuotationManager.Service.GetUserList", exception.ToString(), EventLogEntryType.Error);
             return null;
         }
     }
 }
Example #12
0
 bool IUserService.UpdateUser(string sessionID, User user)
 {
     return UserManager.Default.UpdateUser(sessionID, user);
 }