Exemplo n.º 1
0
        public static T Update <T>(DBCommand cmd, string entityName, T instance, IDictionary <IAttributeDefinition, object> changes) where T : class
        {
            switch (entityName)
            {
            case "Application":
                return(UpdateApplication(cmd, instance as IApplication, changes) as T);

            case "Customer":
                return(UpdateCustomer(cmd, instance as ICustomer, changes) as T);

            case "User":
                return(UpdateUser(cmd, instance as IUser, changes) as T);

            case "Collection":
                return(UpdateCollection(cmd, instance as ICollection, changes) as T);

            case "Case":
                return(UpdateCase(cmd, instance as ICase, changes) as T);

            case "Status":
                return(UpdateStatus(cmd, instance as IStatus, changes) as T);

            default:
                Debug.Assert(false, "Didn't implement entity updater for the entity " + entityName);
                return(null);
            }
        }
Exemplo n.º 2
0
        private static ICollection UpdateCollection(DBCommand cmd, ICollection instance, IDictionary <IAttributeDefinition, object> changes)
        {
            var od = AppCore.AppSingleton.FindObjDef <CollectionObjDef>();

            if (!(instance is CollectionProxy))
            {
                Debug.Assert(false, "The given instance is not proxy type.");
            }

            var entity  = instance as CollectionProxy;
            var orginal = entity.Original as CollectionProxy;

            foreach (IAttributeDefinition attr in changes.Keys)
            {
                if (attr == od.PrimaryKey)
                {
                    continue;
                }
                orginal.SetValue(attr, changes[attr]);
            }

            //if (entity.AppId == orginal.AppId && entity.App != null)
            //    orginal.App = cmd.Update("Application", entity.App) as IApplication;

            return(entity);
        }
Exemplo n.º 3
0
        public static ICase Update(DBCommand cmd, ICase instance, string type, string text)
        {
            instance.Type = type;
            instance.Text = text;

            return(cmd.Update("Case", instance));
        }
Exemplo n.º 4
0
        public static IUser Update(DBCommand cmd, IUser instance, string name, string password, UserRole?role)
        {
            instance.Name     = name;
            instance.Password = password;
            instance.Role     = role;

            return(cmd.Update("User", instance));
        }
Exemplo n.º 5
0
        public static ICustomer Update(DBCommand cmd, ICustomer instance, string id, string name, string sex, string phone, string address)
        {
            instance.ID      = id;
            instance.Name    = name;
            instance.Sex     = sex;
            instance.Phone   = phone;
            instance.Address = address;

            return(cmd.Update("Customer", instance));
        }
Exemplo n.º 6
0
        public static IStatus Create(DBCommand cmd, string id, string value)
        {
            var od = AppCore.AppSingleton.FindObjDef <StatusObjDef>();

            return(cmd.Create <IStatus>("Status", new Dictionary <IAttributeDefinition, object>()
            {
                { od.PrimaryKey, id },
                { od.Value, value },
            }));
        }
Exemplo n.º 7
0
        public static ICollection Create(DBCommand cmd, string id, decimal?value, decimal?offset)
        {
            var od = AppCore.AppSingleton.FindObjDef <CollectionObjDef>();

            return(cmd.Create <ICollection>("Collection", new Dictionary <IAttributeDefinition, object>()
            {
                { od.PrimaryKey, id },
                { od.Value, value == null ? null : value.Value + "" },
                { od.Offset, offset == null ? null : offset.Value + "" }
            }));
        }
Exemplo n.º 8
0
        public static ICase Create(DBCommand cmd, string id, string type, string text)
        {
            var od = AppCore.AppSingleton.FindObjDef <CaseObjDef>();

            return(cmd.Create <ICase>("Case", new Dictionary <IAttributeDefinition, object>()
            {
                { od.PrimaryKey, id },
                { od.Type, type },
                { od.Text, text }
            }));
        }
Exemplo n.º 9
0
        public static IUser Create(DBCommand cmd, string id, string name, string password, UserRole?role)
        {
            var od = AppCore.AppSingleton.FindObjDef <UserObjDef>();

            return(cmd.Create <IUser>("User", new Dictionary <IAttributeDefinition, object>()
            {
                { od.PrimaryKey, id },
                { od.Name, name },
                { od.Password, password },
                { od.Role, role }
            }));
        }
Exemplo n.º 10
0
        public static ICustomer Create(DBCommand cmd, string id, string name, string sex, string phone, string address)
        {
            var od = AppCore.AppSingleton.FindObjDef <CustomerObjDef>();

            return(cmd.Create <ICustomer>("Customer", new Dictionary <IAttributeDefinition, object>()
            {
                { od.PrimaryKey, id },
                { od.Name, name },
                { od.Sex, sex },
                { od.Phone, phone },
                { od.Address, address }
            }));
        }
Exemplo n.º 11
0
        public static IApplication Update(DBCommand cmd, IApplication instance, string id,
                                          string customerId, string region, DateTime?dateApplied,
                                          DateTime?dateTraved, string offNoteNo, DateTime?offNoteDate, string remark)
        {
            instance.ID          = id;
            instance.CustomerID  = customerId;
            instance.Region      = region;
            instance.DateApplied = dateApplied;
            instance.DateTraved  = dateTraved;
            instance.OffNoteDate = offNoteDate;
            instance.OffNoteNo   = offNoteNo;
            instance.Remark      = remark;

            return(cmd.Update("Application", instance));
        }
Exemplo n.º 12
0
        private static IUser UpdateUser(DBCommand cmd, IUser instance, IDictionary <IAttributeDefinition, object> changes)
        {
            if (!(instance is UserProxy))
            {
                Debug.Assert(false, "The given instance is not proxy type.");
            }

            var entity  = instance as UserProxy;
            var orginal = entity.Original as UserProxy;

            foreach (IAttributeDefinition attr in changes.Keys)
            {
                orginal.SetValue(attr, changes[attr]);
            }

            return(entity);
        }
Exemplo n.º 13
0
        private static IApplication UpdateApplication(DBCommand cmd, IApplication instance, IDictionary <IAttributeDefinition, object> changes)
        {
            if (!(instance is ApplicationProxy))
            {
                Debug.Assert(false, "The given instance is not proxy type.");
            }

            var entity  = instance as ApplicationProxy;
            var orginal = entity.Original as ApplicationProxy;

            foreach (IAttributeDefinition attr in changes.Keys)
            {
                orginal.SetValue(attr, changes[attr]);
            }

            if (entity.customerId == orginal.customerId && entity.customer != null)
            {
                orginal.customer = cmd.Update("Customer", entity.customer) as ICustomer;
            }

            return(entity);
        }
Exemplo n.º 14
0
        public static IApplication Create(DBCommand cmd, string id, /*string type, string subType,*/
                                          string customerId, string region, DateTime?dateApplied,
                                          DateTime?dateTraved, string offNoteNo, DateTime?offNoteDate, string remark)
        {
            var od = AppCore.AppSingleton.FindObjDef <ApplicationObjDef>();

            return(cmd.Create <IApplication>("Application", new Dictionary <IAttributeDefinition, object>()
            {
                { od.PrimaryKey, id },
                //{od.Type, type},
                //{od.SubType, subType},
                { od.CustomerID, customerId },
                //{od.CustomerName, customerName},
                //{od.CustomerSex, customerSex},
                { od.Region, region },
                { od.DateApplied, dateApplied },
                { od.DateTraved, dateTraved },
                { od.OffNoteNo, offNoteNo },
                { od.OffNoteDate, offNoteDate },
                { od.Remark, remark }
            }));
        }
Exemplo n.º 15
0
 public static IList <ICustomer> GetAll(DBCommand cmd, IDictionary <IAttributeDefinition, object> criterias)
 {
     return(cmd.GetAll <ICustomer>("Customer", criterias));
 }
Exemplo n.º 16
0
 public static IUser Delete(DBCommand cmd, IUser instance)
 {
     return(cmd.Delete("User", instance));
 }
Exemplo n.º 17
0
 public static ICustomer Get(DBCommand cmd, string id)
 {
     return(cmd.Get <ICustomer>("Customer", id));
 }
Exemplo n.º 18
0
 public static IStatus Delete(DBCommand cmd, IStatus instance)
 {
     return(cmd.Delete("Status", instance));
 }
Exemplo n.º 19
0
        public static IStatus Update(DBCommand cmd, IStatus instance, string value)
        {
            instance.Value = value;

            return(cmd.Update("Status", instance));
        }
Exemplo n.º 20
0
 public static IUser Get(DBCommand cmd, string id)
 {
     return(cmd.Get <IUser>("User", id));
 }
Exemplo n.º 21
0
 public static ICase Get(DBCommand cmd, string id)
 {
     return(cmd.Get <ICase>("Case", id));
 }
Exemplo n.º 22
0
 public static ICollection Delete(DBCommand cmd, ICollection instance)
 {
     return(cmd.Delete("Collection", instance));
 }
Exemplo n.º 23
0
 public static IUser Get(DBCommand cmd, IDictionary <IAttributeDefinition, object> criterias)
 {
     return(cmd.GetAll <IUser>("User", criterias).FirstOrDefault());
 }
Exemplo n.º 24
0
 public static ICustomer Delete(DBCommand cmd, ICustomer instance)
 {
     return(cmd.Delete("Customer", instance));
 }
Exemplo n.º 25
0
 public static IList <ICustomer> GetAllPaged(DBCommand cmd, IDictionary <IAttributeDefinition, object> criterias, ref int pageNum, int pageSize, ref int pageCount, ref int itemCount)
 {
     return(cmd.GetAllPaged <ICustomer>("Customer", criterias, ref pageCount, ref pageNum, ref itemCount, pageSize));
 }
Exemplo n.º 26
0
 public static IStatus Get(DBCommand cmd, string id)
 {
     return(cmd.Get <IStatus>("Status", id));
 }
Exemplo n.º 27
0
 public static ICollection Get(DBCommand cmd, string id)
 {
     return(cmd.Get <ICollection>("Collection", id));
 }
Exemplo n.º 28
0
        public static IList <IApplication> GetAllPaged(DBCommand cmd, IDictionary <IAttributeDefinition, object> criterias, ref int pageNum, int pageSize, ref int pageCount, ref int itemCount)
        {
            if (!AppCore.AppSingleton.ObjectDefinitions.ContainsKey("Application"))
            {
                Debug.Assert(false, "Unimplemented entity [Application]");
            }
            ApplicationObjDef appOd = AppCore.AppSingleton.FindObjDef <ApplicationObjDef>();

            if (!AppCore.AppSingleton.ObjectDefinitions.ContainsKey("Status"))
            {
                Debug.Assert(false, "Unimplemented entity [Status]");
            }
            StatusObjDef statusOd = AppCore.AppSingleton.FindObjDef <StatusObjDef>();

            if (!AppCore.AppSingleton.ObjectDefinitions.ContainsKey("User"))
            {
                Debug.Assert(false, "Unimplemented entity [User]");
            }
            UserObjDef userOd = AppCore.AppSingleton.FindObjDef <UserObjDef>();

            if (!criterias.ContainsKey(userOd.Role))
            {
                Debug.Assert(false, "Criterias should contains UserRole of entity [User]");
            }
            UserRole role = (UserRole)Convert.ChangeType(criterias[userOd.Role], typeof(UserRole));

            if (role == UserRole.None)
            {
                role = UserRole.Client;
            }
            criterias.Remove(userOd.Role);

            var sqlBuilder = new StringBuilder();

            string table     = string.Format("[{0}]", appOd.TableName);
            string tabStatus = string.Format("[{0}]", statusOd.TableName);
            string fileds    = string.Join(",", appOd.Attributes.Values.Select(a => string.Format("[{0}]", a.Column)).ToArray());
            string criterion = string.Join(" and ",
                                           criterias.Keys.Where(a => a != userOd.Role).Select(a => string.Format("[{0}]=@{0}", a.Column)).ToArray());

            string fieldsWithAlias    = "comp." + fileds.Replace(",", ",comp.");
            string criterionWithAlias = string.IsNullOrEmpty(criterion) ? "" : "comp." + criterion.Replace(" and ", " and comp.");

            string statusCriterion = "";

            switch (role)
            {
            case UserRole.Client:
                statusCriterion = string.Format("s.[{0}] in ( {1} ) or s.[{0}] is Null or s.[{0}]=''",
                                                statusOd.Value.Column, string.Join(",", role.GetVisibleStatus().Select(r => "'" + r.ToLabel() + "'").ToArray()));
                break;

            case UserRole.Business:
            case UserRole.Administrator:
            default:
                statusCriterion = string.Format("s.[{0}] in ( {1} )", statusOd.Value.Column, string.Join(",", role.GetVisibleStatus().Select(r => "'" + r.ToLabel() + "'").ToArray()));
                break;
            }

            if (!string.IsNullOrEmpty(criterionWithAlias))
            {
                statusCriterion = string.Format("({0}) and ({1})", statusCriterion, criterionWithAlias);
            }


            sqlBuilder.AppendLine(string.Format("SELECT {1}, (select count(org.[{2}])+1 from {0} [org] where org.[{2}] <comp.[{2}]) as Rank",
                                                table, fieldsWithAlias, appOd.PrimaryKey.Column));
            sqlBuilder.AppendLine(string.Format("FROM {0} [comp] left join {1} [s] on s.[{2}]=comp.[{3}]", table, tabStatus, statusOd.PrimaryKey.Column, appOd.PrimaryKey.Column));
            if (!string.IsNullOrEmpty(statusCriterion))
            {
                sqlBuilder.AppendLine(string.Format("Where {0}", statusCriterion));
            }
            sqlBuilder.AppendLine(string.Format("ORDER BY comp.[{0}]", appOd.PrimaryKey.Column));

            string sql = sqlBuilder.ToString();

            return(cmd.GetAllPaged <IApplication>("Application", sql, criterias, ref pageCount, ref pageNum, ref itemCount, pageSize));
        }
Exemplo n.º 29
0
        public static bool IsExisting(DBCommand cmd, IDictionary <IAttributeDefinition, object> criterias)
        {
            int count = cmd.Count("Customer", criterias);

            return(count > 0);
        }
Exemplo n.º 30
0
 public static ICase Delete(DBCommand cmd, ICase instance)
 {
     return(cmd.Delete("Case", instance));
 }