예제 #1
0
        /// <summary>
        /// Edit current item
        /// </summary>
        /// 
        public override void Edit()
        {
            UserInfo info = FocusedEntity;
            if (info != null)
            {
                using (FormUser frm = new FormUser())
                {
                    frm.Entity = info.User;
                    if (frm.ShowDialog(this) == DialogResult.OK)
                    {
                        if (info.User.IsNew)
                        {
                            try
                            {
                                User usr = ClientEnvironment.UserService.Save(info.User);
                                UserList.Add(new UserInfo(usr));
                            }
                            catch (EntityException ex)
                            {
                                // 2think: what details should we show?
                                // 2think: how to localize?
                                using (FrmEntityExceptionDetails form = new FrmEntityExceptionDetails(ex))
                                {
                                    form.Text = GetLocalized("CannotSaveUser");
                                    form.ShowDialog(this);
                                }
                            }
                        }
                        else
                        {
                            try
                            {
                                User usr = ClientEnvironment.UserService.SaveOrUpdate(info.User);
                                UserList.ResetItemById(usr.ID);
                            }
                            catch (EntityException ex)
                            {
                                // 2think: what details should we show?
                                // 2think: how to localize?
                                using (FrmEntityExceptionDetails form = new FrmEntityExceptionDetails(ex))
                                {
                                    form.Text = GetLocalized("CannotSaveUser");
                                    form.ShowDialog(this);
                                }
                            }
                        }
                    }
                }

                UserList.ResetItemById(info.User.ID); 
            }
            RefreshData();
        }
예제 #2
0
 /// <summary>
 /// Add new item
 /// </summary>
 public override void Add()
 {
     User usr = ClientEnvironment.UserService.CreateEntity();
     using (FormUser frm = new FormUser())
     {
         frm.Entity = usr;
         if (frm.ShowDialog(this) == DialogResult.OK)
         {
             if (usr.IsNew)
             {
                 try
                 {
                     usr = ClientEnvironment.UserService.Save(usr);
                     UserList.Add(new UserInfo(usr));
                     for (int row = 0 ; row < UserList.Count; row++)
                     {
                         if ( UserList[row].User.ID == usr.ID)
                         {
                             focusedRow = row;
                             break;
                         }
                     }
                     focusedUser = new UserInfo(usr);
                     isRowNotFixed = true;
                     fixedTimes = 3;
                     fixFocusedEntity();
                 }
                 catch (EntityException ex)
                 {
                     // 2think: what details should we show?
                     // 2think: how to localize?
                     using (FrmEntityExceptionDetails form = new FrmEntityExceptionDetails(ex))
                     {
                         form.Text = GetLocalized("CannotSaveUser");
                         form.ShowDialog(this);
                     }
                 }
             }
             else
             {
                 try
                 {
                     usr = ClientEnvironment.UserService.SaveOrUpdate(usr);
                     UserList.ResetItemById(usr.ID);
                 }
                 catch (EntityException ex)
                 {
                     // 2think: what details should we show?
                     // 2think: how to localize?
                     using (FrmEntityExceptionDetails form = new FrmEntityExceptionDetails(ex))
                     {
                         form.Text = GetLocalized("CannotSaveUser");
                         form.ShowDialog(this);
                     }
                 }
             }
         }
     }
  //   RefreshData(); //******************!!!!!!!!!
 }