コード例 #1
0
ファイル: EntityUpdater.cs プロジェクト: baikangwang/TJVISA
        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);
            }
        }
コード例 #2
0
ファイル: EntityUpdater.cs プロジェクト: baikangwang/TJVISA
        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);
        }
コード例 #3
0
ファイル: CaseDAL.cs プロジェクト: baikangwang/TJVISA
        public static ICase Update(DBCommand cmd, ICase instance, string type, string text)
        {
            instance.Type = type;
            instance.Text = text;

            return(cmd.Update("Case", instance));
        }
コード例 #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));
        }
コード例 #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));
        }
コード例 #6
0
ファイル: StatusDAL.cs プロジェクト: baikangwang/TJVISA
        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 },
            }));
        }
コード例 #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 + "" }
            }));
        }
コード例 #8
0
ファイル: CaseDAL.cs プロジェクト: baikangwang/TJVISA
        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 }
            }));
        }
コード例 #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 }
            }));
        }
コード例 #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 }
            }));
        }
コード例 #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));
        }
コード例 #12
0
ファイル: EntityUpdater.cs プロジェクト: baikangwang/TJVISA
        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);
        }
コード例 #13
0
ファイル: EntityUpdater.cs プロジェクト: baikangwang/TJVISA
        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);
        }
コード例 #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 }
            }));
        }
コード例 #15
0
 public static IList <ICustomer> GetAll(DBCommand cmd, IDictionary <IAttributeDefinition, object> criterias)
 {
     return(cmd.GetAll <ICustomer>("Customer", criterias));
 }
コード例 #16
0
 public static IUser Delete(DBCommand cmd, IUser instance)
 {
     return(cmd.Delete("User", instance));
 }
コード例 #17
0
 public static ICustomer Get(DBCommand cmd, string id)
 {
     return(cmd.Get <ICustomer>("Customer", id));
 }
コード例 #18
0
ファイル: StatusDAL.cs プロジェクト: baikangwang/TJVISA
 public static IStatus Delete(DBCommand cmd, IStatus instance)
 {
     return(cmd.Delete("Status", instance));
 }
コード例 #19
0
ファイル: StatusDAL.cs プロジェクト: baikangwang/TJVISA
        public static IStatus Update(DBCommand cmd, IStatus instance, string value)
        {
            instance.Value = value;

            return(cmd.Update("Status", instance));
        }
コード例 #20
0
 public static IUser Get(DBCommand cmd, string id)
 {
     return(cmd.Get <IUser>("User", id));
 }
コード例 #21
0
ファイル: CaseDAL.cs プロジェクト: baikangwang/TJVISA
 public static ICase Get(DBCommand cmd, string id)
 {
     return(cmd.Get <ICase>("Case", id));
 }
コード例 #22
0
 public static ICollection Delete(DBCommand cmd, ICollection instance)
 {
     return(cmd.Delete("Collection", instance));
 }
コード例 #23
0
 public static IUser Get(DBCommand cmd, IDictionary <IAttributeDefinition, object> criterias)
 {
     return(cmd.GetAll <IUser>("User", criterias).FirstOrDefault());
 }
コード例 #24
0
 public static ICustomer Delete(DBCommand cmd, ICustomer instance)
 {
     return(cmd.Delete("Customer", instance));
 }
コード例 #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));
 }
コード例 #26
0
ファイル: StatusDAL.cs プロジェクト: baikangwang/TJVISA
 public static IStatus Get(DBCommand cmd, string id)
 {
     return(cmd.Get <IStatus>("Status", id));
 }
コード例 #27
0
 public static ICollection Get(DBCommand cmd, string id)
 {
     return(cmd.Get <ICollection>("Collection", id));
 }
コード例 #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));
        }
コード例 #29
0
        public static bool IsExisting(DBCommand cmd, IDictionary <IAttributeDefinition, object> criterias)
        {
            int count = cmd.Count("Customer", criterias);

            return(count > 0);
        }
コード例 #30
0
ファイル: CaseDAL.cs プロジェクト: baikangwang/TJVISA
 public static ICase Delete(DBCommand cmd, ICase instance)
 {
     return(cmd.Delete("Case", instance));
 }