public virtual SqlCommand GetSqlCommandForGetGetCustomValues(DescriptorColection colection, string tableName)
        {
            string selectCustom = @"SELECT * FROM " + tableName + " ";

            if (colection.ListField != null && colection.ListField.Count > 0)
            {
                //Truong hop chi lay 1 vai truong cu the
                var field = "";
                for (int i = 0; i < colection.ListField.Count; i++)
                {
                    if (i == colection.ListField.Count - 1)
                    {
                        field += colection.ListField[i]; //Bo qua dau phay cuoi cung
                    }
                    else
                    {
                        field += colection.ListField[i] + ",";
                    }
                }
                if (!string.IsNullOrEmpty(field))
                {
                    selectCustom = string.Format(@"SELECT {0} FROM " + tableName + " ", field);
                }
            }
            if (colection != null && colection.Descriptors.Count > 0)
            {
                selectCustom += DescriptorUtil.GetWhereString(colection);
            }

            var sqlcommand = new SqlCommand {
                CommandType = CommandTypeText, CommandText = selectCustom
            };

            return(sqlcommand);
        }
        public static List <MemberInfo> GetListMemberInCustomerVangLai()
        {
            //Lay tat ca member la nhom khach hang
            try
            {
                //Select * from MemberInfo where MemberType = 3 and CustomerGroup = 3
                var entityQry = new EntityQuery
                {
                    EntityName  = MemberInfo.EntityName(),
                    QueryAction = EntityGet.GetCustomValues
                };
                var colection = new DescriptorColection
                {
                    Logical = LogicalOperator.AND
                };

                var descriptorSession = new Descriptor {
                    Logical = LogicalOperator.AND
                };
                descriptorSession.Descriptors.Add(new Descriptor
                {
                    FieldName  = MemberInfo.MemberInfoFields.MemberType.ToString(),
                    FieldValue = Descriptor.GetInputValue((int)MemberType.Customer),
                    Operator   = DataOperator.IsEqualTo
                });
                descriptorSession.Descriptors.Add(new Descriptor
                {
                    FieldName  = MemberInfo.MemberInfoFields.CustomerGroup.ToString(),
                    FieldValue = Descriptor.GetInputValue((int)CustomerGroup.VL),
                    Operator   = DataOperator.IsEqualTo
                });
                colection.Descriptors.Add(descriptorSession);

                entityQry.DescriptorColection = colection;
                entityQry = GetEntityQuery(entityQry);

                if (entityQry.ReturnValue != null)
                {
                    var listValue = entityQry.ReturnValue.Select(baseEntity =>
                                                                 baseEntity.GetEntity() as MemberInfo).ToList();
                    return(listValue);
                }
            }
            catch (Exception ex)
            {
                LogTo.Error(ex.ToString());
            }
            return(new List <MemberInfo>());
        }
 public static string GetWhereString(DescriptorColection colection)
 {
     try
     {
         if (colection == null)
         {
             return(string.Empty);
         }
         var agrs = GetStringByList(colection.Logical, colection.Descriptors);
         if (string.IsNullOrWhiteSpace(agrs))
         {
             return(string.Empty);
         }
         return(" WHERE " + agrs);
     }
     catch (Exception ex)
     {
         LogTo.Error(ex.ToString());
     }
     return(string.Empty);
 }