Beispiel #1
0
        public static void GenericAction <TEntity>(ReflectionEntityCache typeCache, IList <TEntity> objs, GenerateScriptsEnum method, IEnumerable <ReflectionPropertyCache> properties = null)
        {
            List <object> parameters = new List <object>();
            StringBuilder query      = new StringBuilder();

            foreach (TEntity obj in objs)
            {
                switch (method)
                {
                case GenerateScriptsEnum.GenerateInsertOrUpdate:
                    query.AppendLine(GenerateInsertOrUpdate(typeCache, obj, parameters, properties));
                    break;

                case GenerateScriptsEnum.GenerateInsert:
                    query.AppendLine(GenerateInsert(typeCache, obj, parameters));
                    break;
                }
            }

            List <string> columns = ExecuterManager.GetInstance().ExecuteQuerySimple <string>(query.ToString(), parameters.ToArray()).ToList();

            for (int i = 0; i < objs.Count; i++)
            {
                typeCache.PrimaryKey.SetValue(objs[i], columns[i].To(typeCache.PrimaryKey.Type));
            }
        }
Beispiel #2
0
        public ActionResult EditExecuter(int id)
        {
            var executer = ExecuterManager.FindExecuter(id);

            if (executer != null)
            {
                var set = new EditExecuterBindingModel
                {
                    FirstName          = executer.FirstName,
                    LastName           = executer.LastName,
                    MasterId           = executer.MasterId,
                    CollegeId          = executer.CollegeId,
                    EducationalGroupId = executer.EducationalGroupId,
                    Email   = executer.Email,
                    Phone   = executer.Phone,
                    Explain = executer.Explain,
                };
                ViewBag.ExecuterResearchgroup = ExecuterManager.FindExecuterResearchGroups(id);
                var colleges = CollegeManager.List();
                ViewBag.College          = colleges;
                ViewBag.EducationalGroup = EducationalGroupManager.FindByCollegeId(executer.CollegeId);
                ViewBag.ResearchGroup    = ResearchGroupManager.List();
                return(View(set));
            }
            return(RedirectToAction("Index"));
        }
Beispiel #3
0
        public SqlEntityHandler()
        {
            _executer            = ExecuterManager.GetInstance();
            _reflectionCache     = ReflectionEntityCache.GetOrCreateEntity <TEntity>();
            _expressionFunctions = new SqlExpressionFunctions();

            _query_delete = QueryBuilder.GenerateDelete(_reflectionCache.Name, _reflectionCache.PrimaryKey.Name);

            Init();
        }
Beispiel #4
0
        public ActionResult CreateProject(CreateProjectBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.ModelState = ModelState;
            }
            else
            {
                var result = ProjectManager.Create(model);
                switch (result)
                {
                case ProjectManager.createprojectstatus.failed:
                    ViewBag.Failed = Fa.Error;
                    break;

                case ProjectManager.createprojectstatus.duplicate:
                    ViewBag.Duplicate = Fa.DuplicateExecuter;
                    break;

                default:
                    return(RedirectToAction("Index"));
                }
            }
            ViewBag.Employers = EmployerManager.List();
            var colleges = CollegeManager.List();

            ViewBag.College       = colleges;
            ViewBag.ResearchGroup = ResearchGroupManager.List();
            if (colleges.Count > 0)
            {
                var educationalgroup = EducationalGroupManager.FindByCollegeId(colleges.FirstOrDefault().Id);
                ViewBag.EducationalGroup = educationalgroup;
                ViewBag.Executer         = ExecuterManager.FindByCollegeId(colleges.FirstOrDefault().Id);
            }
            else
            {
                ViewBag.EducationalGroup = new List <EducationalGroupModel>();
                ViewBag.Executer         = new List <ExecuterModel>();
            }
            ViewBag.ResearchGroup = ResearchGroupManager.List();
            return(View(model));
        }
Beispiel #5
0
        public ActionResult CreateProject()
        {
            ViewBag.Employers = EmployerManager.List();
            var colleges = CollegeManager.List();

            ViewBag.College       = colleges;
            ViewBag.ResearchGroup = ResearchGroupManager.List();
            if (colleges.Count > 0)
            {
                var educationalgroup = EducationalGroupManager.FindByCollegeId(colleges.FirstOrDefault().Id);
                ViewBag.EducationalGroup = educationalgroup;
                ViewBag.Executer         = ExecuterManager.FindByCollegeId(colleges.FirstOrDefault().Id);
            }
            else
            {
                ViewBag.EducationalGroup = new List <EducationalGroupModel>();
                ViewBag.Executer         = new List <ExecuterModel>();
            }
            ViewBag.ResearchGroup = ResearchGroupManager.List();
            return(View());
        }
Beispiel #6
0
        public virtual void CreateDb()
        {
            Type contextType = typeof(TContext);

            FieldInfo[] fields      = contextType.GetFields();
            Type        handlerType = typeof(SqlEntityHandler <>);

            _databaseHandler = new SqlDatabaseHandler(_conn);
            ExecuterManager.CreateInstance(_conn);

            foreach (FieldInfo field in fields)
            {
                if (field.FieldType.GetGenericTypeDefinition() == typeof(IEntityHandler <>))
                {
                    Type[] args = field.FieldType.GetGenericArguments();
                    Type   genericHandlerType = handlerType.MakeGenericType(args);
                    object handler            = Activator.CreateInstance(genericHandlerType);
                    field.SetValue(this, handler);
                }
            }
        }
Beispiel #7
0
        public ActionResult EditProject(int id)
        {
            var project = ProjectManager.Find(id);

            if (project != null)
            {
                var set = new EditProjectBindingModel
                {
                    ProjectId               = project.ProjectId,
                    Title                   = project.Title,
                    EmployerId              = project.EmployerId,
                    CollegeId               = project.CollegeId,
                    EducationalGroupId      = project.EducationalGroupId,
                    ExecuterId              = project.ExecuterId,
                    ResearchGroupId         = project.ResearchGroupId,
                    Price                   = project.Price,
                    OverHeadPrice           = project.OverHeadPrice,
                    ReceivePrice            = project.ReceivePrice,
                    RemainPrice             = project.RemainPrice,
                    PaymentPrice            = project.PaymentPrice,
                    MainContractId          = project.MainContractId,
                    MainContractDateStr     = Utility.DateToString(project.MainContractDate),
                    InternalContractId      = project.MainContractId,
                    InternalContractDateStr = Utility.DateToString(project.InternalContractDate),
                    ProjectEndDateStr       = Utility.DateToString(project.ProjectEndDate),
                    PhasesNum               = project.PhasesNum,
                    ProjectStatus           = project.ProjectStatus,
                    ProjectType             = project.ProjectType,
                    Explain                 = project.Explain,
                };
                var colleges = CollegeManager.List();
                ViewBag.College          = colleges;
                ViewBag.EducationalGroup = EducationalGroupManager.FindByCollegeId(project.CollegeId);
                ViewBag.ResearchGroup    = ResearchGroupManager.List();
                ViewBag.Employers        = EmployerManager.List();
                ViewBag.Executer         = ExecuterManager.FindByCollegeId(project.CollegeId);
                return(View(set));
            }
            return(RedirectToAction("Index"));
        }
Beispiel #8
0
        public static string GenerateInsert(ReflectionEntityCache typeCache, object obj, List <object> parameters)
        {
            StringBuilder values  = new StringBuilder(),
                          columns = new StringBuilder();

            foreach (ReflectionPropertyCache property in typeCache.Properties)
            {
                if (!property.IsPrimaryKey)
                {
                    object propertyVal  = property.GetValue(obj);
                    string propertyName = property.Name;

                    if (propertyVal != null && property.IsForeignObj)
                    {
                        ReflectionEntityCache fk = ReflectionEntityCache.GetOrCreateEntity(property.Type);
                        object fkPkValue         = fk.PrimaryKey.GetValue(propertyVal);

                        if (fkPkValue.Equals(fk.PrimaryKey.Type.GetDefaultValue()))
                        {
                            List <object> parametersFK = new List <object>();
                            string        insertFK     = GenerateInsert(fk, propertyVal, parametersFK);

                            fkPkValue = ExecuterManager.GetInstance().ExecuteQuery(insertFK, parametersFK.ToArray(), x => Mapper.ConvertFromType(x[0], fk.PrimaryKey.Type)).FirstOrDefault();
                            fk.PrimaryKey.SetValue(propertyVal, fkPkValue);
                        }

                        propertyVal  = fkPkValue;
                        propertyName = $"{property.Name}{fk.PrimaryKey.Name}";
                    }

                    columns.Append($"{propertyName}, ");
                    parameters.Add(propertyVal ?? string.Empty);
                    values.Append($"@{parameters.Count - 1}, ");
                }
            }

            return
                ($@"INSERT INTO {typeCache.Name} ({columns.SubstringLast()}) VALUES ({values.SubstringLast()});
SELECT IDENT_CURRENT('{typeCache.Name}');");
        }
Beispiel #9
0
        public ActionResult ProjectInfo(int id)
        {
            var project = ProjectManager.Find(id);

            if (project != null)
            {
                var set = new ProjectViewModel
                {
                    Title                = project.Title,
                    ProjectId            = project.ProjectId,
                    Price                = project.Price,
                    OverHeadPrice        = project.OverHeadPrice,
                    ReceivePrice         = project.ReceivePrice,
                    RemainPrice          = project.RemainPrice,
                    PaymentPrice         = project.PaymentPrice,
                    MainContractId       = project.MainContractId,
                    MainContractDate     = Utility.DateToString(project.MainContractDate),
                    InternalContractId   = project.MainContractId,
                    InternalContractDate = Utility.DateToString(project.InternalContractDate),
                    ProjectEndDate       = Utility.DateToString(project.ProjectEndDate),
                    PhasesNum            = project.PhasesNum,
                    ProjectStatus        = project.ProjectStatus,
                    ProjectType          = project.ProjectType,
                    Explain              = project.Explain,
                    Id = project.Id,
                };
                set.Employer = EmployerManager.Find(project.EmployerId).Name;
                var executer = ExecuterManager.FindExecuter(project.ExecuterId);
                set.Executer         = executer.FirstName + " " + executer.LastName;
                set.College          = CollegeManager.Find(project.CollegeId).Name;
                set.EducationalGroup = EducationalGroupManager.Find(project.EducationalGroupId).Name;
                set.ResearchGroup    = ResearchGroupManager.Find(project.ResearchGroupId).Name;
                ViewBag.ProjectInfo  = set;
                return(View());
            }
            return(RedirectToAction("Error"));
        }
Beispiel #10
0
        public ActionResult CreateExecuter(CreateExecuterBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.ModelState = ModelState;
            }
            else
            {
                var result = ExecuterManager.Create(model);
                switch (result)
                {
                case ExecuterManager.ExecuterStatus.failed:
                    ViewBag.Failed = Fa.Error;
                    break;

                case ExecuterManager.ExecuterStatus.duplicate:
                    ViewBag.Duplicate = Fa.DuplicateExecuter;
                    break;

                default:
                    return(RedirectToAction("Index"));
                }
            }
            var colleges = CollegeManager.List();

            ViewBag.College = colleges;
            if (colleges.Count > 0)
            {
                ViewBag.EducationalGroup = EducationalGroupManager.FindByCollegeId(colleges.FirstOrDefault().Id);
            }
            else
            {
                ViewBag.EducationalGroup = new List <EducationalGroupModel>();
            }
            return(View(model));
        }
Beispiel #11
0
 public ActionResult DeleteExecuter(int id)
 {
     ExecuterManager.Delete(id);
     return(RedirectToAction("Index"));
 }
Beispiel #12
0
        // GET: Executer
        public ActionResult Index()
        {
            var executers = ExecuterManager.List();

            return(View(executers));
        }
Beispiel #13
0
        public ActionResult ExecuterOfCollege(int id)
        {
            var executer = ExecuterManager.FindByCollegeId(id);

            return(PartialView(executer));
        }
Beispiel #14
0
 public IEnumerable <T> QuerySimple <T>(string sql, params object[] parameters)
 => ExecuterManager.GetInstance().ExecuteQuerySimple <T>(sql, parameters);
Beispiel #15
0
 public IEnumerable <TEntity> Query <TEntity>(string sql, object[] parameters = null, Func <IDataReader, TEntity> IdentifierExpression = null)
     where TEntity : class, new()
 => ExecuterManager.GetInstance().ExecuteQuery(sql, parameters, IdentifierExpression);
Beispiel #16
0
        public SqlDatabaseHandler(string conn)
        {
            string createTable = QueryBuilder.GenerateCreateDb(ref conn);

            ExecuterManager.CreateInstance(conn).ExecuteQuery(createTable);
        }
Beispiel #17
0
 public void Query(string sql, params object[] parameters)
 => ExecuterManager.GetInstance().ExecuteQuery(sql, parameters);