protected void gvMaster_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { if (!Convert.IsDBNull(gvMaster.DataKeys[e.Row.RowIndex].Value)) { int masterid = Convert.ToInt32(gvMaster.DataKeys[e.Row.RowIndex].Value); MasterInfo master = new MasterInfo(masterid); int stateid = Convert.ToInt32(master.State); Label lblState = e.Row.FindControl("lblState") as Label; if (stateid == 0) { lblState.Text = "δ����"; } else if (stateid == 1) { lblState.Text = "�ѷ���"; } else if (stateid == 2) { lblState.Text = "ͨ��"; } else if (stateid == 3) { lblState.Text = "����"; } } } }
protected void btnAddUser_Click(object sender, EventArgs e) { if (IsPageValid()) { string strName = txtUserName.Text.ToString(); bool isexit = MasterInfo.IsUserExit(strName); if (!isexit) { try { MasterInfo master = new MasterInfo(); master.MasterName = txtUserName.Text.ToString(); master.MasterPsd = txtNewPsd.Text.ToString(); master.DepartId = Convert.ToInt32(ddlDepart.SelectedValue.ToString()); DateTime time = DateTime.Now; master.CreateDate = time; master.EmployeeId = Convert.ToInt32(ddlEmployee.SelectedValue.ToString()); master.State = 0; master.IsApply = 0; master.Save(); FileEmployee(); Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script language='javascript'>alert('��ӳɹ���');</script>"); } catch (Exception Ex) { ClientScript.RegisterStartupScript(this.GetType(), "Save", "alert('����ʧ�ܣ�" + Ex.Message + "');", true); } } else { Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script language='javascript'>alert('�û����Ѵ��ڣ���������ӣ�');</script>"); } } }
protected void btnSave_Click(object sender, EventArgs e) { int roleid = Convert.ToInt32(rblRole.SelectedValue); int masterid = Convert.ToInt32(Request.QueryString["MasterId"].ToString()); MasterInfo master = new MasterInfo(masterid); if (rblIsOver.SelectedItem.Text == "ͨ��") { master.State = 2; master.Save(); try { //��ӽ�ɫ if (RoleInfo.isRoleMaster(masterid)) { RoleInfo.UpdateRoleMasters(masterid); } else { RoleMasterInfo rm = new RoleMasterInfo(); rm.RoleId = roleid; rm.MasterId = masterid; rm.IsPass = 1; rm.Save(); } //���Ȩ�� if (RoleInfo.isActionMaster(masterid)) { RoleInfo.DelActionMaster(masterid); AddActionMaster(masterid); } else { AddActionMaster(masterid); } master.IsApply = 1; master.Save(); Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script language='javascript'>alert('Ȩ�����óɹ���');</script>"); } catch (Exception Ex) { ClientScript.RegisterStartupScript(this.GetType(), "Save", "alert('����ʧ�ܣ�" + Ex.Message + "');", true); } } else { master.State = 3; master.Save(); } }
public MasterInfo GetMasterInfoById(int MasterId) { MasterInfo masterInfo = null;// try { masterInfo = new MasterInfo(MasterId); } catch (AppException) { return null; } return masterInfo; }
private void LoadFromId(int masterId) { if (CachedEntityCommander.IsTypeRegistered(typeof(MasterInfo))) { MasterInfo masterInfo = Find(GetList(), masterId); if (masterInfo == null) { throw new AppException("未能在缓存中找到相应的键值对象"); } Copy(masterInfo, this); } else { Master master = new Master(masterId); if (master.IsNew) { throw new AppException("尚未初始化"); } LoadFromDAL(this, master); } }
//数据持久化 internal static void SaveToDb(MasterInfo pMasterInfo, Master pMaster,bool pIsNew) { pMaster.MasterId = pMasterInfo.masterId; pMaster.MasterName = pMasterInfo.masterName; pMaster.MasterPsd = pMasterInfo.masterPsd; pMaster.DepartId = pMasterInfo.departId; pMaster.CreateDate = pMasterInfo.createDate; pMaster.EmployeeId = pMasterInfo.employeeId; pMaster.IsApply = pMasterInfo.isApply; pMaster.State = pMasterInfo.state; pMaster.IsNew=pIsNew; string UserName = SubsonicHelper.GetUserName(); try { pMaster.Save(UserName); } catch(Exception ex) { LogManager.getInstance().getLogger(typeof(MasterInfo)).Error(ex); if(ex.Message.Contains("插入重复键"))//违反了唯一键 { throw new AppException("此对象已经存在");//此处等待优化可以从唯一约束中直接取出提示来,如果没有的话,默认为原始的出错提示 } throw new AppException("保存失败"); } pMasterInfo.masterId = pMaster.MasterId; //如果缓存存在,更新缓存 if (CachedEntityCommander.IsTypeRegistered(typeof(MasterInfo))) { ResetCache(); } }
/// <summary> /// 批量装载 /// </summary> internal static void LoadFromDALPatch(List< MasterInfo> pList, MasterCollection pCollection) { foreach (Master master in pCollection) { MasterInfo masterInfo = new MasterInfo(); LoadFromDAL(masterInfo, master ); pList.Add(masterInfo); } }
//从后台获取数据 internal static void LoadFromDAL(MasterInfo pMasterInfo, Master pMaster) { pMasterInfo.masterId = pMaster.MasterId; pMasterInfo.masterName = pMaster.MasterName; pMasterInfo.masterPsd = pMaster.MasterPsd; pMasterInfo.departId = pMaster.DepartId; pMasterInfo.createDate = pMaster.CreateDate; pMasterInfo.employeeId = pMaster.EmployeeId; pMasterInfo.isApply = pMaster.IsApply; pMasterInfo.state = pMaster.State; pMasterInfo.Loaded=true; }
/// <summary> /// 复制为另一个对象 /// </summary> /// <param name="pIndustryTypeInfoTo"></param> public void CopyTo(MasterInfo pMasterInfoTo) { Copy(this, pMasterInfoTo); }
/// <summary> /// 获得分页列表,无论是否是缓存实体都从数据库直接拿取数据 /// </summary> /// <param name="pPageIndex">页数</param> /// <param name="pPageSize">每页列表</param> /// <param name="pOrderBy">排序</param> /// <param name="pSortExpression">排序字段</param> /// <param name="pRecordCount">列表行数</param> /// <returns>数据分页</returns> public static List<MasterInfo> GetPagedList(int pPageIndex,int pPageSize,SortDirection pOrderBy,string pSortExpression,out int pRecordCount) { if(pPageIndex<=1) pPageIndex=1; List< MasterInfo> list = new List< MasterInfo>(); Query q = Master .CreateQuery(); q.PageIndex = pPageIndex; q.PageSize = pPageSize; q.ORDER_BY(pSortExpression,pOrderBy.ToString()); MasterCollection collection=new MasterCollection(); collection.LoadAndCloseReader(q.ExecuteReader()); foreach (Master master in collection) { MasterInfo masterInfo = new MasterInfo(); LoadFromDAL(masterInfo, master); list.Add(masterInfo); } pRecordCount=q.GetRecordCount(); return list; }
/// <summary> /// 获得数据列表 /// </summary> /// <returns></returns> public static List<MasterInfo> GetList() { string cacheKey = GetCacheKey(); //本实体已经注册成缓存实体,并且缓存存在的时候,直接从缓存取 if (CachedEntityCommander.IsTypeRegistered(typeof(MasterInfo)) && CachedEntityCommander.GetCache(cacheKey) != null) { return CachedEntityCommander.GetCache(cacheKey) as List< MasterInfo>; } else { List< MasterInfo> list =new List< MasterInfo>(); MasterCollection collection=new MasterCollection(); Query qry = new Query(Master.Schema); collection.LoadAndCloseReader(qry.ExecuteReader()); foreach(Master master in collection) { MasterInfo masterInfo= new MasterInfo(); LoadFromDAL(masterInfo,master); list.Add(masterInfo); } //生成缓存 if (CachedEntityCommander.IsTypeRegistered(typeof(MasterInfo))) { CachedEntityCommander.SetCache(cacheKey, list); } return list; } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //��ɫȨ�� rblRoleBind(); ckblRightBind(); //��ʼ����ɫȨ�� int masterId = Convert.ToInt32(Request.QueryString["MasterId"].ToString()); MasterInfo master = new MasterInfo(masterId); EmployeeInfo em = new EmployeeInfo(master.EmployeeId); lblUser.Text = master.MasterName.ToString(); lblEmployee.Text = em.EmployeeName.ToString(); InitRole(masterId); InitAction(masterId); if (master.State == 1) { btnSend.Enabled = false; } } }
public List <MasterInfo> GetPagedList(int pPageIndex, int pPageSize, SortDirection pOrderBy, string pSortExpression, out int pRecordCount) { return(MasterInfo.GetPagedList(pPageIndex, pPageSize, pOrderBy, pSortExpression, out pRecordCount)); }
public void DeleteById(MasterInfo pMasterInfo) { MasterInfo masterInfo = new MasterInfo(pMasterInfo.MasterId); masterInfo.Delete(); }
protected void gvMaster_RowUpdating(object sender, GridViewUpdateEventArgs e) { int masterid = Convert.ToInt32(gvMaster.DataKeys[e.RowIndex].Value); TextBox txtMasterName = gvMaster.Rows[e.RowIndex].FindControl("txtMasterName") as TextBox; try { MasterInfo master = new MasterInfo(masterid); master.MasterName = txtMasterName.Text.ToString(); master.Save(); gvMaster.EditIndex = -1; gvDataBind(); } catch (Exception Ex) { ClientScript.RegisterStartupScript(this.GetType(), "Save", "alert('����ʧ�ܣ�" + Ex.Message + "');", true); } }
public List <MasterInfo> GetMasterInfoList() { return(MasterInfo.GetList()); }
public object SaveMasterInfo(MasterInfo masterInfo) { masterInfo.Save(); return masterInfo . MasterId; }
public object SaveMasterInfo(MasterInfo masterInfo) { masterInfo.Save(); return(masterInfo.MasterId); }
/// <summary> /// 复制一个对象,采用硬编码的方式,避免反射的低效 /// </summary> /// <param name="pIndustryTypeInfoFrom"></param> /// <param name="pIndustryTypeInfoTo"></param> public static void Copy(MasterInfo pMasterInfoFrom, MasterInfo pMasterInfoTo) { pMasterInfoTo.MasterId = pMasterInfoFrom.masterId; pMasterInfoTo.MasterName = pMasterInfoFrom.masterName; pMasterInfoTo.MasterPsd = pMasterInfoFrom.masterPsd; pMasterInfoTo.DepartId = pMasterInfoFrom.departId; pMasterInfoTo.CreateDate = pMasterInfoFrom.createDate; pMasterInfoTo.EmployeeId = pMasterInfoFrom.employeeId; pMasterInfoTo.IsApply = pMasterInfoFrom.isApply; pMasterInfoTo.State = pMasterInfoFrom.state; pMasterInfoTo.Loaded=pMasterInfoFrom.Loaded; }