Example #1
0
        private void UserSave()
        {
            MainBar.Focus();

                if (txtPassConfirm.Text != txtPassword.Text)
                {
                    MessageBox.Show("两次输入的密码不一致,保存失败。");
                    return;
              }

            if (model.FUserName == null || model.FCompanyName == null )
            {
                    MessageBox.Show("必须录入用户名和公司。");
                    return;
                }

            if (model.FID == 0 || model.FID.ToString() == "")
            {
                var tempObj = visaORM.User.FirstOrDefault(u => u.FUserName == model.FUserName);
                {
                    if (tempObj != null)
                    {
                        MessageBox.Show("该用户名已经存在,请使用其他用户名");
                        return;
                    }
                }

                visaORM.User.AddObject(model);
                model.FIsDelete = false;

                visaORM.SaveChanges();
                NowUserId = model.FID;

                userList.Add(model);

                //getDefaultModel = 0;

                InitData();
            }
            else
            {

                if (visaORM.ObjectStateManager.GetObjectStateEntries(EntityState.Modified).Count() == 0)
                {
                    visaORM.User.Attach(model);

                }
                visaORM.ObjectStateManager.ChangeObjectState(model, EntityState.Modified);
                visaORM.SaveChanges();
                NowUserId = model.FID;

            }

                var list = from m in visaORM.TB_Menu
                           join ur in visaORM.TB_UserRights
                           on m.FID equals ur.FMenuID
                           where m.FType==1 && ur.FUserID==model.FID
                           select ur;

                foreach (TB_UserRights urObj in list)
                {
                    visaORM.DeleteObject(urObj);
                }

                selectedMenu.Clear();

                foreach (var nodeObjLevel1 in MenuTree.View.Nodes)
                {
                    foreach (var nodeObjLevel2 in nodeObjLevel1.Nodes)
                    {
                        foreach (var nodeObjLevel3 in nodeObjLevel2.Nodes)
                        {
                            if (nodeObjLevel3.IsChecked==true)
                            {
                                selectedMenu.Add(nodeObjLevel3.Content as TB_Menu);
                            }

                        }
                        if (nodeObjLevel2.IsChecked == true)
                        {
                            selectedMenu.Add(nodeObjLevel2.Content as TB_Menu);
                        }

                    }
                    if (nodeObjLevel1.IsChecked == true)
                    {
                        selectedMenu.Add(nodeObjLevel1.Content as TB_Menu);
                    }

                }

                TB_UserRights urModel;
                foreach (var menuObj in selectedMenu)
                {
                    urModel = new TB_UserRights();
                    urModel.FUserID = model.FID;
                    urModel.FMenuID = menuObj.FID;
                    urModel.FCreateDate = DateTime.Now;
                    urModel.FCreateUser = MainContext.UserID;
                    urModel.FModifyDate = DateTime.Now;
                    urModel.FModifyUser = MainContext.UserID;
                    urModel.FStatus = true;

                    visaORM.TB_UserRights.AddObject(urModel);

                }

                TB_UserRights outMenuObj;
                if (CreateURModel( cbTable2Admin,out outMenuObj)==true)
                {
                    if (outMenuObj != null) visaORM.TB_UserRights.AddObject(outMenuObj);
                }
                else
                {
                    if (outMenuObj != null) visaORM.DeleteObject(outMenuObj);
                }

                visaORM.SaveChanges();

            InitData();

            MessageBox.Show("保存成功");
        }
Example #2
0
 /// <summary>
 /// 创建新的 TB_UserRights 对象。
 /// </summary>
 /// <param name="fID">FID 属性的初始值。</param>
 public static TB_UserRights CreateTB_UserRights(global::System.Int32 fID)
 {
     TB_UserRights tB_UserRights = new TB_UserRights();
     tB_UserRights.FID = fID;
     return tB_UserRights;
 }
Example #3
0
        /// <summary>
        /// 判断复选框是否勾选,判断是否已经有数据
        /// </summary>
        /// <param name="menuCheckEdit">菜单复选框</param>
        /// <param name="urModel"></param>
        /// <returns></returns>
        bool CreateURModel(CheckEdit menuCheckEdit, out TB_UserRights urModel)
        {
            urModel = null;
            string rightString = menuCheckEdit.Name.Replace("cb", "");
            TB_Menu mObj = visaORM.TB_Menu.FirstOrDefault(m => m.FName == rightString);
            if (mObj == null)
            {
                DXMessageBox.Show(rightString + "已在数据中被删除");
                return true;
            }

            if (menuCheckEdit.IsChecked == true)
            {

                TB_UserRights urObj = visaORM.TB_UserRights.FirstOrDefault(ur => ur.FMenuID == mObj.FID && ur.FStatus == true && ur.FUserID == MainContext.UserID);
                if (urObj!=null)
                {
                    return true;
                }

                urModel = new TB_UserRights();

                urModel.FUserID = model.FID;
                urModel.FMenuID = mObj.FID;
                urModel.FCreateDate = DateTime.Now;
                urModel.FCreateUser = MainContext.UserID;
                urModel.FModifyDate = DateTime.Now;
                urModel.FModifyUser = MainContext.UserID;
                urModel.FStatus = true;

                return true;
            }
            else
            {

                urModel = visaORM.TB_UserRights.FirstOrDefault(ur => ur.FMenuID == mObj.FID && ur.FUserID == MainContext.UserID);
                return false;
            }
        }
Example #4
0
 /// <summary>
 /// 用于向 TB_UserRights EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet&lt;T&gt; 属性的 .Add 方法。
 /// </summary>
 public void AddToTB_UserRights(TB_UserRights tB_UserRights)
 {
     base.AddObject("TB_UserRights", tB_UserRights);
 }