protected T AlbianObjectCreater <T>(PropertyInfo[] properties, IDataReader dr, Hashtable reader, IDictionary <string, IMemberAttribute> members) where T : class, IAlbianObject, new() { T target = AlbianObjectFactory.CreateInstance <T>(); foreach (PropertyInfo property in properties) { IMemberAttribute member = members[property.Name]; if (!member.IsSave) { if (property.Name == "IsNew") //define by interface) { property.SetValue(target, false, null); //load from databse } continue; } object value = dr.GetValue(int.Parse(reader[member.FieldName].ToString())); if (null == value || DBNull.Value == value) { //property.SetValue(target, null, null); continue; } property.SetValue(target, value, null); } return(target); }
protected void btnSubmit_Click(object sender, EventArgs e) { Stopwatch sw = new Stopwatch(); sw.Start(); IBizOffer bizoffer = AlbianObjectFactory.CreateInstance <BizOffer>(); bizoffer.Id = AlbianObjectFactory.CreateId("BOFF"); bizoffer.CreateTime = DateTime.Now; bizoffer.Creator = txtSellerId.Text; bizoffer.Description = txtDesc.Text; bizoffer.Discount = null; bizoffer.IsDiscount = null; bizoffer.LastModifier = txtSellerId.Text; bizoffer.LastModifyTime = DateTime.Now; bizoffer.LastPrice = decimal.Parse(txtPrice.Text); bizoffer.Name = txtName.Text; bizoffer.Price = decimal.Parse(txtPrice.Text); bizoffer.SellerId = txtSellerId.Text; bizoffer.SellerName = txtSellerName.Text; bizoffer.State = BizofferState.Create; if (AlbianServiceRouter.GetService <IBizofferOperation>().Create(bizoffer)) { txtId.Text = bizoffer.Id; ClientScript.RegisterClientScriptBlock(this.GetType(), "Save", "<script language=\"javascript\" type=\"text/javascript\">alert(\"Create Success!\");</script>"); } else { ClientScript.RegisterClientScriptBlock(this.GetType(), "Save", "<script language=\"javascript\" type=\"text/javascript\">alert(\"Create Fail!\");</script>"); } sw.Stop(); Response.Write(sw.ElapsedMilliseconds); }
public bool Create(IUser user) { IUserDao dao = AlbianServiceRouter.ObjectGenerator <UserDao, IUserDao>(); ILogInfo log = AlbianObjectFactory.CreateInstance <LogInfo>(); log.Content = string.Format("创建用户,用户id为:{0}", user.Id); log.CreateTime = DateTime.Now; log.Creator = user.Id; log.Id = AlbianObjectFactory.CreateId("Log"); log.Style = InfoStyle.Registr; IList <IAlbianObject> infos = new List <IAlbianObject> { user, log }; return(dao.Create(infos)); }
public virtual bool Modify(IBizOffer bizoffer) { ILogInfo log = AlbianObjectFactory.CreateInstance <LogInfo>(); log.Content = string.Format("修改发布单,发布单id为:{0}", bizoffer.Id); log.CreateTime = DateTime.Now; log.Creator = bizoffer.Id; log.Id = AlbianObjectFactory.CreateId("Log"); log.Style = InfoStyle.Publish; IList <IAlbianObject> list = new List <IAlbianObject> { bizoffer, log }; IBizofferDao dao = AlbianServiceRouter.ObjectGenerator <BizofferDao, IBizofferDao>(); return(dao.Modify(list)); }
protected void btnSubmit_Click(object sender, EventArgs e) { IUser user = AlbianObjectFactory.CreateInstance <User>(); user.Id = AlbianObjectFactory.CreateId("User"); user.CreateTime = DateTime.Now; user.Creator = user.Id; user.LastModifier = user.Id; user.LastMofidyTime = DateTime.Now; user.Mail = txtMail.Text; user.Mobile = txtMobile.Text; user.Nickname = txtNickName.Text; user.Password = txtPassword.Text; user.RegistrDate = DateTime.Now; user.UserName = txtUserName.Text; bool isSuccess = AlbianServiceRouter.GetService <IUserOperation>().Create(user); txtID.Text = user.Id; }
public bool Modify(string id, string nickName) { IUserDao dao = AlbianServiceRouter.ObjectGenerator <UserDao, IUserDao>(); IUser user = dao.Load(id); user.Nickname = nickName; user.LastMofidyTime = DateTime.Now; user.LastModifier = id; ILogInfo log = AlbianObjectFactory.CreateInstance <LogInfo>(); log.Content = string.Format("修改用户,用户id为:{0}", user.Id); log.CreateTime = DateTime.Now; log.Creator = user.Id; log.Id = AlbianObjectFactory.CreateId("Log"); log.Style = InfoStyle.Modify; IList <IAlbianObject> infos = new List <IAlbianObject> { user, log }; return(dao.Modify(infos)); }
public IFakeCommandAttribute GenerateQuery <T>(string rountingName, int top, IFilterCondition[] where, IOrderByCondition[] orderby) where T : class, IAlbianObject, new() { Type type = typeof(T); string fullName = AssemblyManager.GetFullTypeName(type); object oProperties = PropertyCache.Get(fullName); PropertyInfo[] properties; if (null == oProperties) { if (null != Logger) { Logger.Error("Get the object property info from cache is null.Reflection now and add to cache."); } throw new PersistenceException("object property is null in the cache."); } properties = (PropertyInfo[])oProperties; object oAttribute = ObjectCache.Get(fullName); if (null == oAttribute) { if (null != Logger) { Logger.ErrorFormat("The {0} object attribute is null in the object cache.", fullName); } throw new Exception("The object attribute is null"); } StringBuilder sbSelect = new StringBuilder(); StringBuilder sbCols = new StringBuilder(); StringBuilder sbWhere = new StringBuilder(); StringBuilder sbOrderBy = new StringBuilder(); IObjectAttribute objectAttribute = (IObjectAttribute)oAttribute; IRoutingAttribute routing; if (!objectAttribute.RoutingAttributes.TryGetValue(rountingName, out routing)) { if (null != Logger) { Logger.WarnFormat("There is not routing of the {} object.Albian use the default routing tempate.", rountingName); } routing = objectAttribute.RountingTemplate; } if (0 == (PermissionMode.R & routing.Permission)) { if (null != Logger) { Logger.WarnFormat("The routing permission {0} is no enough.", routing.Permission); } return(null); } IStorageAttribute storageAttr = (IStorageAttribute)StorageCache.Get(routing.StorageName); if (null == storageAttr) { if (null != Logger) { Logger.WarnFormat( "No {0} rounting mapping storage attribute in the sotrage cache.Use default storage.", routing.Name); } storageAttr = (IStorageAttribute)StorageCache.Get(StorageParser.DefaultStorageName); } if (!storageAttr.IsHealth) { if (null != Logger) { Logger.WarnFormat("Routing:{0},Storage:{1} is not health.", routing.Name, storageAttr.Name); } return(null); } IDictionary <string, IMemberAttribute> members = objectAttribute.MemberAttributes; T target = AlbianObjectFactory.CreateInstance <T>(); foreach (PropertyInfo property in properties) { IMemberAttribute member = members[property.Name]; if (!member.IsSave) { continue; } sbCols.AppendFormat("{0},", member.FieldName); if (null != where) { foreach (IFilterCondition condition in where) //have better algorithm?? { if (condition.PropertyName == property.Name) { property.SetValue(target, condition.Value, null); //Construct the splite object break; } } } if (null != orderby) { foreach (IOrderByCondition order in orderby) { if (order.PropertyName == property.Name) { sbOrderBy.AppendFormat("{0} {1},", member.FieldName, System.Enum.GetName(typeof(SortStyle), order.SortStyle)); break; } } } } if (0 != sbOrderBy.Length) { sbOrderBy.Remove(sbOrderBy.Length - 1, 1); } if (0 != sbCols.Length) { sbCols.Remove(sbCols.Length - 1, 1); } IList <DbParameter> paras = new List <DbParameter>(); if (null != where && 0 != where.Length) { foreach (IFilterCondition condition in where) { IMemberAttribute member = members[condition.PropertyName]; if (!member.IsSave) { continue; } sbWhere.AppendFormat(" {0} {1} {2} {3} ", Utils.GetRelationalOperators(condition.Relational), member.FieldName, Utils.GetLogicalOperation(condition.Logical), DatabaseFactory.GetParameterName(storageAttr.DatabaseStyle, member.FieldName)); paras.Add(DatabaseFactory.GetDbParameter(storageAttr.DatabaseStyle, member.FieldName, member.DBType, condition.Value, member.Length)); } } string tableFullName = Utils.GetTableFullName(routing, target); switch (storageAttr.DatabaseStyle) { case DatabaseStyle.MySql: { sbSelect.AppendFormat("SELECT {0} FROM {1} WHERE 1=1 {2} {3} {4}", sbCols, tableFullName, sbWhere, 0 == sbOrderBy.Length ? string.Empty : string.Format("ORDER BY {0}", sbOrderBy), 0 == top ? string.Empty : string.Format("LIMIT {0}", top) ); break; } case DatabaseStyle.Oracle: { if (0 == top) { sbSelect.AppendFormat("SELECT {0} FROM {1} WHERE 1=1 {2} {3}", sbCols, tableFullName, sbWhere, 0 == sbOrderBy.Length ? string.Empty : string.Format("ORDER BY {0}", sbOrderBy)); } else { sbSelect.AppendFormat("SELECT A.* FROM (SELECT {0} FROM {1} WHERE 1=1 {2} {3})A WHERE ROWNUM <= {4}", sbCols, tableFullName, sbWhere, 0 == sbOrderBy.Length ? string.Empty : string.Format("ORDER BY {0}", sbOrderBy), top); } break; } case DatabaseStyle.SqlServer: default: { sbSelect.AppendFormat("SELECT {0} {1} FROM {2} WHERE 1=1 {3} {4}", 0 == top ? string.Empty : string.Format("TOP {0}", top), sbCols, tableFullName, sbWhere, 0 == sbOrderBy.Length ? string.Empty : string.Format("ORDER BY {0}", sbOrderBy)); break; } } IFakeCommandAttribute fakeCommand = new FakeCommandAttribute { CommandText = sbSelect.ToString(), Paras = ((List <DbParameter>)paras).ToArray(), StorageName = storageAttr.Name, }; return(fakeCommand); }