Beispiel #1
0
        /// <summary>
        /// 新增数据
        /// </summary>
        /// <param name="RoleObj"></param>
        /// <returns></returns>
        public bool Add(tblUser RoleObj)
        {
            //RoleObj.UserID = System.Guid.NewGuid();
            //获取当前登录用户的ID(Cookies)
            string strUserID = HttpContext.Current.User.Identity.Name;
            if (strUserID == string.Empty || strUserID == null)
            {
                return false;
            }
            System.Guid guidUserID = new Guid(strUserID);

            RoleObj.SendEmail = true;
            RoleObj.LastModifiedByID = guidUserID;
            RoleObj.CreatedByID = guidUserID;
            RoleObj.OwnerID = guidUserID;
            RoleObj.CreatedDate = Convert.ToDateTime(System.DateTime.Now);
            RoleObj.LastModifiedDate = Convert.ToDateTime(System.DateTime.Now);
            RoleObj.SystemModstamp = Convert.ToDateTime(System.DateTime.Now);
            RoleObj.IsDeleted = false;
            RoleObj.Avatar = this.GetImageIo();
            int counts = 0;
            //插入数据
            try
            {
                MWDatabaseEntities MWDB = new MWDatabaseEntities();
                MWDB.tblUser.AddObject(RoleObj);
                counts = MWDB.SaveChanges();
                if (counts > 0)
                {
                    string userHostAddress = HttpContext.Current.Request.UserHostAddress;
                    DbLoggerBLL.SysLogger.Info("Increase user successfully! User id: '"
                        + RoleObj.UserID + "'. User host address: '" + userHostAddress + "'. ");
                    return true;
                }
            }
            catch (Exception ex)
            {
                string userHostAddress = HttpContext.Current.Request.UserHostAddress;
                DbLoggerBLL.SysLogger.Error("Increase user failed! User id: '"
                    + RoleObj.UserID + "'. User host address: '" + userHostAddress + "'. Exception info:" + ex.Message);
                return false;
            }

            return false;
        }
Beispiel #2
0
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="RoleObj"></param>
        /// <returns></returns>
        public bool Update(tblUser UserNew)
        {
            tblUser UserOld;
            int counts = 0;//影响行数标记
            using (MWDatabaseEntities MWDB =new MWDatabaseEntities())
            {
                try
                {
                    UserOld = MWDB.tblUser.FirstOrDefault(t => t.UserID == UserNew.UserID);

                    //更新数据字段
                    UserOld.UserName = UserNew.UserName;
                    UserOld.LoginName = UserNew.LoginName;
                    UserOld.LoginPwd = UserNew.LoginPwd;
                    UserOld.UserCode = UserNew.UserCode;
                    UserOld.State = UserNew.State;
                    UserOld.Email = UserNew.Email;
                    UserOld.Desc = UserNew.Desc;
                    UserOld.Avatar = UserNew.Avatar;
                    //获取当前登录用户的ID(Cookies)
                    string strUserID = HttpContext.Current.User.Identity.Name;
                    if (string.IsNullOrEmpty(strUserID))
                    {
                        FormsAuthentication.RedirectToLoginPage();
                        return false;
                    }

                    UserOld.LastModifiedByID = new Guid(strUserID);
                    DateTime dates = System.DateTime.Now;
                    UserOld.LastModifiedDate = dates;
                    UserOld.SystemModstamp = dates;

                    ObjectStateEntry ose = MWDB.ObjectStateManager.GetObjectStateEntry(UserOld);
                    IEnumerable<string> list = ose.GetModifiedProperties();
                    string logBody = string.Empty;
                    foreach (string pr in list)
                    {
                        string strs = pr;//更新实体的属性名
                        string strNew = ose.CurrentValues[strs].ToString();
                        string strOld = ose.OriginalValues[strs].ToString();
                        if (strNew != strOld)
                        {
                            strNew = string.IsNullOrEmpty(strNew) ? "null" : strNew;//如果字符串为空,则将null赋给字符串
                            strOld = string.IsNullOrEmpty(strOld) ? "null" : strOld;
                            switch (strs)
                            {
                                case "LastModifiedByID":
                                    //系统字段不进行发送
                                    break;
                                case "LastModifiedDate":
                                    //系统字段不进行发送
                                    break;
                                case "SystemModstamp":
                                    //系统字段不进行发送
                                    break;
                                default:
                                    logBody += ", " + strs + ": '" + strOld + "'" + " had been changed '" + strNew + "'";
                                    break;
                            }
                        }
                    }

                    counts = MWDB.SaveChanges();
                    if (counts > 0)
                    {
                        string userHostAddress = HttpContext.Current.Request.UserHostAddress;
                        DbLoggerBLL.SysLogger.Info("Update user info failed! User update log: '"
                            + logBody + "'. User host address: '" + userHostAddress + "' .");
                        return true;
                    }
                }
                catch (Exception ex)
                {
                    string userHostAddress = HttpContext.Current.Request.UserHostAddress;
                    DbLoggerBLL.SysLogger.Error("Update user info failed! User id: '"
                            + UserNew.UserID + "'. User host address: '" + userHostAddress + "' . Exception info:" + ex.Message);
                    return false;
                }
            }
            return false;
        }
Beispiel #3
0
 /// <summary>
 /// 用于向 tblUser EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet&lt;T&gt; 属性的 .Add 方法。
 /// </summary>
 public void AddTotblUser(tblUser tblUser)
 {
     base.AddObject("tblUser", tblUser);
 }
        /// <summary>
        /// GridView的InsertCommand事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void GridUser_InsertCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
        {
            GridEditableItem edittedItem = e.Item.OwnerTableView.GetInsertItem();
            //获取控件
            RadTextBox textUserName = edittedItem.FindControl("textUserName") as RadTextBox;
            RadTextBox textLoginName = edittedItem.FindControl("textLoginName") as RadTextBox;
            RadTextBox textUserCode = edittedItem.FindControl("textUserCode") as RadTextBox;
            RadTextBox textEmail = edittedItem.FindControl("textEmail") as RadTextBox;
            RadTextBox textDesc = edittedItem.FindControl("textDesc") as RadTextBox;
            RadTextBox textLoginPwd = edittedItem.FindControl("textLoginPwd") as RadTextBox;

            RadComboBox ComBoxState = edittedItem.FindControl("ComBoxState") as RadComboBox;
            RadComboBox ComBoxRole = edittedItem.FindControl("ComBoxRole") as RadComboBox;
            System.Guid gTemp = System.Guid.NewGuid();
            UserBLL UserBLLs = new UserBLL();
            if (UserBLLs.ExistsLogName(textLoginName.Text))
            {
                //The user already exists
                //该用户已存在
                RadWindowManager1.RadAlert("The user already exists!", 300, 100, "Info", "");
                return;
            }
            //实例化Entity实体
            tblUser UserObj = new tblUser();
            UserObj.UserName = textUserName.Text;
            UserObj.LoginName = textLoginName.Text;
            UserObj.LoginPwd = textLoginPwd.Text;
            UserObj.UserCode = textUserCode.Text;
            UserObj.State = Convert.ToBoolean(ComBoxState.SelectedItem.Value);
            UserObj.Email = textEmail.Text;
            UserObj.Desc = textDesc.Text;
            UserObj.UserID = gTemp;

            UserBLLs.Add(UserObj);
            //创建目录文件夹
            Directory.CreateDirectory(Request.PhysicalApplicationPath + "FileUpLoad/" + gTemp);
            //*************************************************给用户配置角色
            RoleUserBLL Role_UserBLLs = new RoleUserBLL();
            if (ComBoxRole.SelectedItem.Value != string.Empty)
            {

                tblRole_User tblRole_UserObj = new tblRole_User();
                System.Guid gUserID = gTemp;
                System.Guid gRoleID = new Guid(ComBoxRole.SelectedItem.Value);
                tblRole_UserObj.UserID = gUserID;
                tblRole_UserObj.RoleID = gRoleID;
                Role_UserBLLs.Add(tblRole_UserObj);
            }
            //*************************************************给用户配置角色
            this.GridViewData();
        }
Beispiel #5
0
 /// <summary>
 /// 创建新的 tblUser 对象。
 /// </summary>
 /// <param name="userID">UserID 属性的初始值。</param>
 public static tblUser CreatetblUser(global::System.Guid userID)
 {
     tblUser tblUser = new tblUser();
     tblUser.UserID = userID;
     return tblUser;
 }