Ejemplo n.º 1
0
 /// <summary>
 /// 新增数据
 /// </summary>
 /// <param name="RoleObj"></param>
 /// <returns></returns>
 public bool Add(tblRole RoleObj)
 {
     //获取当前登录用户的ID(Cookies)
     string strUserID = HttpContext.Current.User.Identity.Name;
     if (string.IsNullOrEmpty(strUserID))
     {
         FormsAuthentication.RedirectToLoginPage();
         return false;
     }
     System.Guid guidUserID = new Guid(strUserID);
     RoleObj.RoleID = System.Guid.NewGuid();
     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;
     int counts = 0;
     //插入数据
     try
     {
         using (MWDatabaseEntities MWDB = new MWDatabaseEntities())
         {
             MWDB.tblRole.AddObject(RoleObj);
             counts = MWDB.SaveChanges();
             if (counts > 0)
             {
                 string userHostAddress = HttpContext.Current.Request.UserHostAddress;
                 DbLoggerBLL.SysLogger.Info("Increase role info successfully! Role ID: '"
                     + RoleObj.RoleID + "'. User host address: '" + userHostAddress + "'");
                 return true;
             }
         }
     }
     catch (Exception ex)
     {
         string userHostAddress = HttpContext.Current.Request.UserHostAddress;
         DbLoggerBLL.SysLogger.Error("Increase role info failed! Role ID: '"
             + RoleObj.RoleID + "'. User host address: '" + userHostAddress + "' . Exception info:"+ ex.Message);
         return false;
     }
     return false;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 创建新的 tblRole 对象。
 /// </summary>
 /// <param name="roleID">RoleID 属性的初始值。</param>
 /// <param name="createdByID">CreatedByID 属性的初始值。</param>
 /// <param name="lastModifiedByID">LastModifiedByID 属性的初始值。</param>
 /// <param name="createdDate">CreatedDate 属性的初始值。</param>
 /// <param name="lastModifiedDate">LastModifiedDate 属性的初始值。</param>
 /// <param name="ownerID">OwnerID 属性的初始值。</param>
 /// <param name="isDeleted">IsDeleted 属性的初始值。</param>
 /// <param name="systemModstamp">SystemModstamp 属性的初始值。</param>
 public static tblRole CreatetblRole(global::System.Guid roleID, global::System.Guid createdByID, global::System.Guid lastModifiedByID, global::System.DateTime createdDate, global::System.DateTime lastModifiedDate, global::System.Guid ownerID, global::System.Boolean isDeleted, global::System.DateTime systemModstamp)
 {
     tblRole tblRole = new tblRole();
     tblRole.RoleID = roleID;
     tblRole.CreatedByID = createdByID;
     tblRole.LastModifiedByID = lastModifiedByID;
     tblRole.CreatedDate = createdDate;
     tblRole.LastModifiedDate = lastModifiedDate;
     tblRole.OwnerID = ownerID;
     tblRole.IsDeleted = isDeleted;
     tblRole.SystemModstamp = systemModstamp;
     return tblRole;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 用于向 tblRole EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet&lt;T&gt; 属性的 .Add 方法。
 /// </summary>
 public void AddTotblRole(tblRole tblRole)
 {
     base.AddObject("tblRole", tblRole);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="RoleObj"></param>
        /// <returns></returns>
        public bool Update(tblRole RoleNew)
        {
            tblRole RoleOld;
            int counts = 0;//影响行数标记
            using (MWDatabaseEntities MWDB = new MWDatabaseEntities())
            {
                try
                {
                    RoleOld = MWDB.tblRole.First(t => t.RoleID == RoleNew.RoleID);
                    //更新数据字段
                    RoleOld.RoleName = RoleNew.RoleName;
                    RoleOld.RoleCode = RoleNew.RoleCode;
                    RoleOld.State = RoleNew.State;
                    RoleOld.Desc = RoleNew.Desc;

                    //获取当前登录用户的ID(Cookies)
                    string strUserID = HttpContext.Current.User.Identity.Name;
                    if (string.IsNullOrEmpty(strUserID))
                    {
                        FormsAuthentication.RedirectToLoginPage();
                        return false;
                    }
                    System.Guid guidUserID = new Guid(strUserID);
                    RoleOld.LastModifiedByID = guidUserID;
                    RoleOld.LastModifiedDate = System.DateTime.Now;
                    RoleOld.SystemModstamp = System.DateTime.Now;

                    //日志处理
                    ObjectStateEntry ose = MWDB.ObjectStateManager.GetObjectStateEntry(RoleOld);
                    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 role info failed! Role update log: '"
                            + logBody + "'. User host address: '" + userHostAddress + "' .");
                        return true;
                    }
                }
                catch (Exception ex)
                {
                    string userHostAddress = HttpContext.Current.Request.UserHostAddress;
                    DbLoggerBLL.SysLogger.Error("Update role info failed! Role ID: '"
                        + RoleNew.RoleID + "'. User host address: '" + userHostAddress + "' . Exception info:" + ex.Message);
                    return false;
                }
            }
            return false;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// GridView的InsertCommand事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void GridRole_InsertCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
        {
            GridEditableItem edittedItem = e.Item.OwnerTableView.GetInsertItem();
            //获取控件
            RadTextBox textRoleName = edittedItem.FindControl("txtRoleName") as RadTextBox;
            RadTextBox textRoleCode = edittedItem.FindControl("textRoleCode") as RadTextBox;
            RadTextBox textDesc = edittedItem.FindControl("textDesc") as RadTextBox;
            RadComboBox ComBoxState = edittedItem.FindControl("ComBoxState") as RadComboBox;

            //实例化Entity实体
            tblRole roleObj = new tblRole();
            roleObj.RoleName = textRoleName.Text;
            roleObj.RoleCode = textRoleCode.Text;
            roleObj.Desc = textDesc.Text;
            roleObj.State = Convert.ToDecimal(ComBoxState.SelectedItem.Value);
            RoleBLL RoleBLLs = new RoleBLL();
            RoleBLLs.Add(roleObj);
            this.GridViewData();
        }