/// <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 <YeWuInfo> GetPagedList(int pPageIndex, int pPageSize, SortDirection pOrderBy, string pSortExpression, out int pRecordCount) { if (pPageIndex <= 1) { pPageIndex = 1; } List <YeWuInfo> list = new List <YeWuInfo>(); Query q = YeWu.CreateQuery(); q.PageIndex = pPageIndex; q.PageSize = pPageSize; q.ORDER_BY(pSortExpression, pOrderBy.ToString()); YeWuCollection collection = new YeWuCollection(); collection.LoadAndCloseReader(q.ExecuteReader()); foreach (YeWu yeWu in collection) { YeWuInfo yeWuInfo = new YeWuInfo(); LoadFromDAL(yeWuInfo, yeWu); list.Add(yeWuInfo); } pRecordCount = q.GetRecordCount(); return(list); }
protected void btnTJ_Click(object sender, EventArgs e) { linqYeWuDataContext yw = new linqYeWuDataContext(); YeWu newyw = new YeWu(); newyw.Yw_JingJi = Session["Yg_XingMing"].ToString(); newyw.Yw_JingJiId = Convert.ToInt32(Session["Yg_Id"]); newyw.Yw_KeHu = labKH.Text; newyw.Yw_KeHuId = Convert.ToInt32(labBH.Text); newyw.Yw_LeiXing = Convert.ToInt32(drlLX.SelectedValue); newyw.Yw_MianJi = Convert.ToInt32(txtMJ.Text); newyw.Yw_JiaGe = Convert.ToInt32(txtJG.Text); newyw.Yw_ShangQuan = Convert.ToInt32(drlSQ.SelectedValue); newyw.Yw_BeiZhu = txtQT.Text; newyw.Yw_YouXiaoQi = Convert.ToDateTime(txtRQ.Text); newyw.Yw_TianJiaShiJian = DateTime.Now; yw.YeWu.InsertOnSubmit(newyw); yw.SubmitChanges(); Response.Write("<Script language=javascript>"); Response.Write("window.alert('添加业务成功!');"); Response.Write("window.location='YeWuBJ.aspx?id="); Response.Write(newyw.Yw_Id); Response.Write("'</script>"); }
//数据持久化 internal static void SaveToDb(YeWuInfo pYeWuInfo, YeWu pYeWu, bool pIsNew) { pYeWu.YeWuId = pYeWuInfo.yeWuId; pYeWu.YeWuName = pYeWuInfo.yeWuName; pYeWu.IsNew = pIsNew; string UserName = SubsonicHelper.GetUserName(); try { pYeWu.Save(UserName); } catch (Exception ex) { LogManager.getInstance().getLogger(typeof(YeWuInfo)).Error(ex); if (ex.Message.Contains("插入重复键")) //违反了唯一键 { throw new AppException("此对象已经存在"); //此处等待优化可以从唯一约束中直接取出提示来,如果没有的话,默认为原始的出错提示 } throw new AppException("保存失败"); } pYeWuInfo.yeWuId = pYeWu.YeWuId; //如果缓存存在,更新缓存 if (CachedEntityCommander.IsTypeRegistered(typeof(YeWuInfo))) { ResetCache(); } }
/// <summary> /// 保存 /// </summary> public override void Save() { if (!m_Loaded) //新增 { YeWu yeWu = new YeWu(); SaveToDb(this, yeWu, true); } else //修改 { YeWu yeWu = new YeWu(yeWuId); if (yeWu.IsNew) { throw new AppException("该数据已经不存在了"); } SaveToDb(this, yeWu, false); } }
/// <summary> /// 删除 /// </summary> /// <returns>是否成功</returns> public override void Delete() { if (!m_Loaded) { throw new AppException("尚未初始化"); } bool result = (YeWu.Delete(YeWuId) == 1); //更新缓存 if (result && CachedEntityCommander.IsTypeRegistered(typeof(YeWuInfo))) { ResetCache(); } if (!result) { throw new AppException("删除失败,数据可能被删除"); } }
private void LoadFromId(int yeWuId) { if (CachedEntityCommander.IsTypeRegistered(typeof(YeWuInfo))) { YeWuInfo yeWuInfo = Find(GetList(), yeWuId); if (yeWuInfo == null) { throw new AppException("未能在缓存中找到相应的键值对象"); } Copy(yeWuInfo, this); } else { YeWu yeWu = new YeWu(yeWuId); if (yeWu.IsNew) { throw new AppException("尚未初始化"); } LoadFromDAL(this, yeWu); } }
//从后台获取数据 internal static void LoadFromDAL(YeWuInfo pYeWuInfo, YeWu pYeWu) { pYeWuInfo.yeWuId = pYeWu.YeWuId; pYeWuInfo.yeWuName = pYeWu.YeWuName; pYeWuInfo.Loaded = true; }
private void LoadFromId(int yeWuId) { if (CachedEntityCommander.IsTypeRegistered(typeof(YeWuInfo))) { YeWuInfo yeWuInfo=Find(GetList(), yeWuId); if(yeWuInfo==null) throw new AppException("未能在缓存中找到相应的键值对象"); Copy(yeWuInfo, this); } else { YeWu yeWu=new YeWu( yeWuId); if(yeWu.IsNew) throw new AppException("尚未初始化"); LoadFromDAL(this, yeWu); } }
//数据持久化 internal static void SaveToDb(YeWuInfo pYeWuInfo, YeWu pYeWu,bool pIsNew) { pYeWu.YeWuId = pYeWuInfo.yeWuId; pYeWu.YeWuName = pYeWuInfo.yeWuName; pYeWu.IsNew=pIsNew; string UserName = SubsonicHelper.GetUserName(); try { pYeWu.Save(UserName); } catch(Exception ex) { LogManager.getInstance().getLogger(typeof(YeWuInfo)).Error(ex); if(ex.Message.Contains("插入重复键"))//违反了唯一键 { throw new AppException("此对象已经存在");//此处等待优化可以从唯一约束中直接取出提示来,如果没有的话,默认为原始的出错提示 } throw new AppException("保存失败"); } pYeWuInfo.yeWuId = pYeWu.YeWuId; //如果缓存存在,更新缓存 if (CachedEntityCommander.IsTypeRegistered(typeof(YeWuInfo))) { ResetCache(); } }
//从后台获取数据 internal static void LoadFromDAL(YeWuInfo pYeWuInfo, YeWu pYeWu) { pYeWuInfo.yeWuId = pYeWu.YeWuId; pYeWuInfo.yeWuName = pYeWu.YeWuName; pYeWuInfo.Loaded=true; }
/// <summary> /// 保存 /// </summary> public override void Save() { if(!m_Loaded)//新增 { YeWu yeWu=new YeWu(); SaveToDb(this, yeWu,true); } else//修改 { YeWu yeWu=new YeWu(yeWuId); if(yeWu.IsNew) throw new AppException("该数据已经不存在了"); SaveToDb(this, yeWu,false); } }
public static DataTable getYewu() { Query q = YeWu.Query(); return(q.ExecuteDataSet().Tables[0]); }
partial void DeleteYeWu(YeWu instance);
partial void UpdateYeWu(YeWu instance);
partial void InsertYeWu(YeWu instance);