public RelateInfo GetRelateInfoById(int RelateId) { RelateInfo relateInfo = null;// try { relateInfo = new RelateInfo(RelateId); } catch (AppException) { return null; } return relateInfo; }
protected void btnAdd_Click(object sender, EventArgs e) { if (IsPageValid()) { try { ClientInfo client = new ClientInfo(); client.Address = txtAddress.Text.ToString(); client.ClientName = txtClientName.Text.ToString(); client.MailNo = txtMailNo.Text.ToString(); client.Fax = txtFax.Text.ToString(); client.Telephone = txtTelephone.Text.ToString(); if (ddlClientLevel.SelectedValue != "") { client.ClientLevelId = Convert.ToInt32(ddlClientLevel.SelectedValue); } client.ClientTypeId = Convert.ToInt32(ddlClientType.SelectedValue); client.SheetNum = txtClientNum.Text.ToString(); client.Save(); RelateInfo relate = new RelateInfo(); relate.ClientId = client.ClientId; relate.Position = txtPosition.Text.ToString(); relate.Email = txtEmail.Text.ToString(); relate.Memo = txtMemo.Text.ToString(); relate.Mobile = txtMobile.Text.ToString(); relate.RelateName = txtRelateName.Text.ToString(); relate.Save(); Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script language='javascript'>alert('��ӳɹ���');</script>"); // ClearForms(); } catch (Exception Ex) { ClientScript.RegisterStartupScript(this.GetType(), "Save", "alert('����ʧ�ܣ�" + Ex.Message + "');", true); } } }
protected void btnAdd_Click(object sender, EventArgs e) { try { int ClientId = Convert.ToInt32(Request["ClientId"].ToString()); RelateInfo relate = new RelateInfo(); relate.ClientId = ClientId; relate.Email = txtEmail.Text.ToString(); relate.Memo = txtMemo.Text.ToString(); relate.Mobile = txtMobile.Text.ToString(); relate.RelateName = txtRelateName.Text.ToString(); relate.Position = txtPosition.Text.ToString(); relate.Save(); Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script language='javascript'>alert('��ӳɹ���');</script>"); ClearForms(); } catch(Exception Ex) { ClientScript.RegisterStartupScript(this.GetType(), "Save", "alert('����ʧ�ܣ�" + Ex.Message + "');", true); } }
protected void gvRelate_RowUpdating(object sender, GridViewUpdateEventArgs e) { int RelateId = Convert.ToInt32(gvRelate.DataKeys[e.RowIndex].Value); RelateInfo relate = new RelateInfo(RelateId); TextBox txtEmail = gvRelate.Rows[e.RowIndex].FindControl("txtEmail") as TextBox; TextBox txtRelateName=gvRelate.Rows[e.RowIndex].FindControl("txtRelateName") as TextBox; TextBox txtMobile=gvRelate.Rows[e.RowIndex].FindControl("txtMobile") as TextBox; TextBox txtMemo=gvRelate.Rows[e.RowIndex].FindControl("txtMemo") as TextBox; TextBox txtPosition = gvRelate.Rows[e.RowIndex].FindControl("txtPosition") as TextBox; try { relate.Email = txtEmail.Text.ToString(); relate.RelateName = txtRelateName.Text.ToString(); relate.Mobile = txtMobile.Text.ToString(); relate.Memo = txtMemo.Text.ToString(); relate.Position = txtPosition.Text.ToString(); relate.Save(); gvRelate.EditIndex = -1; gv2DataBind(e.RowIndex); } catch (Exception Ex) { ClientScript.RegisterStartupScript(this.GetType(), "Save", "alert('����ʧ�ܣ�" + Ex.Message + "');", true); } }
//数据持久化 internal static void SaveToDb(RelateInfo pRelateInfo, Relate pRelate,bool pIsNew) { pRelate.RelateId = pRelateInfo.relateId; pRelate.RelateName = pRelateInfo.relateName; pRelate.Mobile = pRelateInfo.mobile; pRelate.Email = pRelateInfo.email; pRelate.Memo = pRelateInfo.memo; pRelate.ClientId = pRelateInfo.clientId; pRelate.Position = pRelateInfo.position; pRelate.IsNew=pIsNew; string UserName = SubsonicHelper.GetUserName(); try { pRelate.Save(UserName); } catch(Exception ex) { LogManager.getInstance().getLogger(typeof(RelateInfo)).Error(ex); if(ex.Message.Contains("插入重复键"))//违反了唯一键 { throw new AppException("此对象已经存在");//此处等待优化可以从唯一约束中直接取出提示来,如果没有的话,默认为原始的出错提示 } throw new AppException("保存失败"); } pRelateInfo.relateId = pRelate.RelateId; //如果缓存存在,更新缓存 if (CachedEntityCommander.IsTypeRegistered(typeof(RelateInfo))) { ResetCache(); } }
/// <summary> /// 批量装载 /// </summary> internal static void LoadFromDALPatch(List< RelateInfo> pList, RelateCollection pCollection) { foreach (Relate relate in pCollection) { RelateInfo relateInfo = new RelateInfo(); LoadFromDAL(relateInfo, relate ); pList.Add(relateInfo); } }
//从后台获取数据 internal static void LoadFromDAL(RelateInfo pRelateInfo, Relate pRelate) { pRelateInfo.relateId = pRelate.RelateId; pRelateInfo.relateName = pRelate.RelateName; pRelateInfo.mobile = pRelate.Mobile; pRelateInfo.email = pRelate.Email; pRelateInfo.memo = pRelate.Memo; pRelateInfo.clientId = pRelate.ClientId; pRelateInfo.position = pRelate.Position; pRelateInfo.Loaded=true; }
/// <summary> /// 复制为另一个对象 /// </summary> /// <param name="pIndustryTypeInfoTo"></param> public void CopyTo(RelateInfo pRelateInfoTo) { Copy(this, pRelateInfoTo); }
/// <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<RelateInfo> GetPagedList(int pPageIndex,int pPageSize,SortDirection pOrderBy,string pSortExpression,out int pRecordCount) { if(pPageIndex<=1) pPageIndex=1; List< RelateInfo> list = new List< RelateInfo>(); Query q = Relate .CreateQuery(); q.PageIndex = pPageIndex; q.PageSize = pPageSize; q.ORDER_BY(pSortExpression,pOrderBy.ToString()); RelateCollection collection=new RelateCollection(); collection.LoadAndCloseReader(q.ExecuteReader()); foreach (Relate relate in collection) { RelateInfo relateInfo = new RelateInfo(); LoadFromDAL(relateInfo, relate); list.Add(relateInfo); } pRecordCount=q.GetRecordCount(); return list; }
/// <summary> /// 获得数据列表 /// </summary> /// <returns></returns> public static List<RelateInfo> GetList() { string cacheKey = GetCacheKey(); //本实体已经注册成缓存实体,并且缓存存在的时候,直接从缓存取 if (CachedEntityCommander.IsTypeRegistered(typeof(RelateInfo)) && CachedEntityCommander.GetCache(cacheKey) != null) { return CachedEntityCommander.GetCache(cacheKey) as List< RelateInfo>; } else { List< RelateInfo> list =new List< RelateInfo>(); RelateCollection collection=new RelateCollection(); Query qry = new Query(Relate.Schema); collection.LoadAndCloseReader(qry.ExecuteReader()); foreach(Relate relate in collection) { RelateInfo relateInfo= new RelateInfo(); LoadFromDAL(relateInfo,relate); list.Add(relateInfo); } //生成缓存 if (CachedEntityCommander.IsTypeRegistered(typeof(RelateInfo))) { CachedEntityCommander.SetCache(cacheKey, list); } return list; } }
/// <summary> /// 复制一个对象,采用硬编码的方式,避免反射的低效 /// </summary> /// <param name="pIndustryTypeInfoFrom"></param> /// <param name="pIndustryTypeInfoTo"></param> public static void Copy(RelateInfo pRelateInfoFrom, RelateInfo pRelateInfoTo) { pRelateInfoTo.RelateId = pRelateInfoFrom.relateId; pRelateInfoTo.RelateName = pRelateInfoFrom.relateName; pRelateInfoTo.Mobile = pRelateInfoFrom.mobile; pRelateInfoTo.Email = pRelateInfoFrom.email; pRelateInfoTo.Memo = pRelateInfoFrom.memo; pRelateInfoTo.ClientId = pRelateInfoFrom.clientId; pRelateInfoTo.Position = pRelateInfoFrom.position; pRelateInfoTo.Loaded=pRelateInfoFrom.Loaded; }
public object SaveRelateInfo(RelateInfo relateInfo) { relateInfo.Save(); return relateInfo . RelateId; }
public void DeleteById(RelateInfo pRelateInfo) { RelateInfo relateInfo = new RelateInfo(pRelateInfo.RelateId); relateInfo.Delete(); }