Example #1
0
        public async Task <IActionResult> OnPostFieldEditAsync()
        {
            IFormCollection requestForm = await Request.ReadFormAsync();

            string formId    = requestForm["formId"];
            string partId    = requestForm["fieldPart"];
            string fieldId   = requestForm["fieldId"];
            string fieldName = requestForm["fieldName"];
            string fieldNote = requestForm["fieldNote"];

            MtdFormPartField mtdFormPartField = await _context.MtdFormPartField.FindAsync(fieldId);

            if (mtdFormPartField == null)
            {
                return(NotFound());
            }

            mtdFormPartField.MtdFormPart = partId;
            mtdFormPartField.Name        = fieldName;
            mtdFormPartField.Description = fieldNote;

            _context.MtdFormPartField.Update(mtdFormPartField);
            await _context.SaveChangesAsync();

            return(Ok());
        }
Example #2
0
        public async Task <IActionResult> OnGetAsync(string idPart)
        {
            MtdFormPart = await _context.MtdFormPart.FindAsync(idPart);

            if (MtdFormPart == null)
            {
                return(NotFound());
            }

            MtdForm = await _context.MtdForm.Include(m => m.MtdFormHeader).FirstOrDefaultAsync(x => x.Id == MtdFormPart.MtdForm);

            string fieldId = Guid.NewGuid().ToString();

            MtdFormPartField = new MtdFormPartField
            {
                Id          = fieldId,
                MtdFormList = new MtdFormList {
                    Id = fieldId
                }
            };

            ViewData["fieldTypes"] = new SelectList(await _context.MtdSysType.Where(x => x.Active).OrderBy(x => x.Id).ToListAsync(), "Id", "Name", 1);
            ViewData["fieldForms"] = new SelectList(await _context.MtdForm.ToListAsync(), "Id", "Name");

            return(Page());
        }
Example #3
0
        public async Task <IActionResult> OnPostFieldCreateAsync()
        {
            IFormCollection requestForm = await Request.ReadFormAsync();

            string formId    = requestForm["formId"];
            string partId    = requestForm["partId"];
            string fieldId   = requestForm["fieldId"];
            string fieldName = requestForm["fieldName"];
            string fieldNote = requestForm["fieldNote"];
            string fieldType = requestForm["fieldType"];
            string fieldForm = requestForm["fieldForm"];

            int fieldTypeID = int.Parse(fieldType);

            bool check = Guid.TryParse(fieldId, out Guid result);

            if (!check)
            {
                fieldId = null;
            }

            bool isExists = await _context.MtdFormPartField.Where(x => x.MtdFormPart == partId).AnyAsync();

            int seq = 0;

            if (isExists)
            {
                seq = await _context.MtdFormPartField.Where(x => x.MtdFormPart == partId).MaxAsync(x => x.Sequence);
            }

            MtdFormPartField mtdFormPartField = new MtdFormPartField
            {
                Id          = fieldId,
                Name        = fieldName,
                Description = fieldNote,
                Active      = true,
                MtdFormPart = partId,
                MtdSysType  = fieldTypeID,
                Sequence    = seq + 1,
                Required    = false,
            };


            if (fieldTypeID == 11)
            {
                mtdFormPartField.MtdFormList = new MtdFormList {
                    Id = fieldId, MtdForm = fieldForm
                };
            }

            await _context.MtdFormPartField.AddAsync(mtdFormPartField);

            await _context.SaveChangesAsync();

            return(Ok());
        }
Example #4
0
        public async Task <IViewComponentResult> InvokeAsync(MtdFormPartField field, DataSet dataSet)
        {
            MtdStoreStack mtdStoreStack = await GetMtdStoreStackAsync(field, dataSet);

            if (mtdStoreStack == null)
            {
                mtdStoreStack = new MtdStoreStack();
            }
            string viewName = await GetViewNameAsync(field.MtdSysType, dataSet.Parts.FirstOrDefault().MtdSysStyle);

            ViewData["typeStyle"] = field.MtdFormPartNavigation.MtdSysStyle == 5 ? "Columns" : "Rows";

            return(View(viewName, mtdStoreStack));
        }
Example #5
0
        public async Task <IActionResult> OnPostFieldDeleteAsync()
        {
            string fieldId = Request.Form["fieldId"];

            MtdFormPartField mtdFormPartField = new MtdFormPartField
            {
                Id = fieldId
            };

            _context.MtdFormPartField.Remove(mtdFormPartField);
            await _context.SaveChangesAsync();


            return(Ok());
        }
Example #6
0
        public async Task <IViewComponentResult> InvokeAsync(MtdFormPartField field, DataSet dataSet)
        {
            MtdStoreStack mtdStoreStack = dataSet.Stack.Where(x => x.MtdFormPartField == field.Id).FirstOrDefault();

            string viewName = GetViewName(field.MtdSysType, dataSet.Parts.FirstOrDefault().MtdSysStyle);

            if (mtdStoreStack == null)
            {
                mtdStoreStack = new MtdStoreStack()
                {
                    MtdFormPartField           = field.Id,
                    MtdFormPartFieldNavigation = field,
                    MtdStore = dataSet.Store.Id
                };
            }

            CheckStackForNull(mtdStoreStack);

            if (field.MtdSysType == 11)
            {
                var fieldForList = await _context.MtdFormPartField.Include(m => m.MtdFormPartNavigation)
                                   .Where(x => x.MtdFormPartNavigation.MtdForm == field.MtdFormList.MtdForm & x.MtdSysType == 1)
                                   .OrderBy(o => o.MtdFormPartNavigation.Sequence).ThenBy(o => o.Sequence).FirstOrDefaultAsync();

                IList <long> stackIds = await _context.MtdStoreStack.Where(x => x.MtdFormPartField == fieldForList.Id).Select(x => x.Id).ToListAsync();

                var dataList = await _context.MtdStoreStack
                               .Include(m => m.MtdStoreStackText)
                               .Where(x => stackIds.Contains(x.Id))
                               .Select(x => new { Id = x.MtdStore, Name = x.MtdStoreStackText.Register })
                               .OrderBy(x => x.Name)
                               .ToListAsync();

                string idSelected = null;
                if (mtdStoreStack.MtdStoreLink != null)
                {
                    idSelected = mtdStoreStack.MtdStoreLink.MtdStore;
                }
                ViewData[field.Id] = new SelectList(dataList, "Id", "Name", idSelected);
            }

            ViewData["TypeStyle"] = field.MtdFormPartNavigation.MtdSysStyle == 5 ? "Columns" : "Rows";

            return(View(viewName, mtdStoreStack));
        }
Example #7
0
        private void SetValuefoCell(MtdStoreStack stack, MtdFormPartField field, ICell cell)
        {
            switch (field.MtdSysType)
            {
            case 2:
            {
                int result = 0;
                if (stack != null && stack.MtdStoreStackInt != null)
                {
                    result = stack.MtdStoreStackInt.Register;
                }
                ;

                cell.SetCellType(CellType.Numeric);
                cell.SetCellValue(result);
                break;
            }

            case 3:
            {
                double result = 0.00;
                if (stack != null && stack.MtdStoreStackDecimal != null)
                {
                    result = (double)stack.MtdStoreStackDecimal.Register;
                }
                cell.SetCellType(CellType.Numeric);
                cell.SetCellValue(result);
                break;
            }

            case 5:
            {
                // cell.SetCellType(CellType.String);
                bool check = false;
                if (stack != null && stack.MtdStoreStackDate != null)
                {
                    check = true;
                    cell.SetCellValue(stack.MtdStoreStackDate.Register.Date);
                }
                if (!check)
                {
                    cell.SetCellValue(0);
                }
                break;
            }

            case 6:
            {
                bool check = false;
                if (stack != null && stack.MtdStoreStackDate != null)
                {
                    check = true;
                    cell.SetCellValue(stack.MtdStoreStackDate.Register);
                }
                if (!check)
                {
                    cell.SetCellValue(0);
                }
                break;
            }

            case 10:
            {
                bool check = false;
                if (stack != null && stack.MtdStoreStackDate != null)
                {
                    check = true;
                    cell.SetCellValue(stack.MtdStoreStackDate.Register);
                }
                if (!check)
                {
                    cell.SetCellValue(0);
                }
                break;
            }

            case 11:
            {
                string result = "";
                if (stack != null && stack.MtdStoreLink != null)
                {
                    result = stack.MtdStoreLink.Register;
                }
                cell.SetCellType(CellType.String);
                cell.SetCellValue(result);
                break;
            }

            case 12:
            {
                int result = 0;
                if (stack != null && stack.MtdStoreStackInt != null)
                {
                    result = stack.MtdStoreStackInt.Register;
                }
                cell.SetCellType(CellType.Boolean);
                cell.SetCellValue(result);
                break;
            }

            default:
            {
                string result = "";
                if (stack != null && stack.MtdStoreStackText != null)
                {
                    result = stack.MtdStoreStackText.Register;
                }
                cell.SetCellValue(result);
                break;
            }
            }
        }
Example #8
0
 private async Task <MtdStoreStack> GetMtdStoreStackAsync(MtdFormPartField field, DataSet dataSet)
 {
     return(await Task.Run(() => GetMtdStoreStack(field, dataSet)));
 }
Example #9
0
 private MtdStoreStack GetMtdStoreStack(MtdFormPartField field, DataSet dataSet)
 {
     return(dataSet.Stack.Where(x => x.MtdFormPartField == field.Id).FirstOrDefault());
 }
Example #10
0
        public async Task <IViewComponentResult> InvokeAsync(string idForm)
        {
            var user = await _userHandler.GetUserAsync(HttpContext.User);

            List <string> partIds = await _userHandler.GetAllowPartsForView(user, idForm);

            MtdFilter filter = await _context.MtdFilter.FirstOrDefaultAsync(x => x.IdUser == user.Id && x.MtdForm == idForm);

            var query = _context.MtdFormPartField.Include(m => m.MtdFormPartNavigation)
                        .Where(x => x.MtdFormPartNavigation.MtdForm == idForm & x.Active & partIds.Contains(x.MtdFormPart))
                        .OrderBy(x => x.MtdFormPartNavigation.Sequence).ThenBy(x => x.Sequence);

            IList <MtdFormPartField> mtdFields;

            if (filter != null)
            {
                List <string> fieldIds = await _context.MtdFilterField.Where(x => x.MtdFilter == filter.Id)
                                         .Select(x => x.MtdFormPartField).ToListAsync();

                mtdFields = await query.Where(x => !fieldIds.Contains(x.Id)).ToListAsync();
            }
            else
            {
                mtdFields = await query.ToListAsync();
            }

            IList <MtdSysTerm> mtdSysTerms = await _context.MtdSysTerm.ToListAsync();

            List <SelectorList> storeList = new List <SelectorList>();

            foreach (var field in mtdFields.Where(x => x.MtdSysType == 11).ToList())
            {
                string idFormForList = await _context.MtdFormList.Where(x => x.Id == field.Id).Select(x => x.MtdForm).FirstOrDefaultAsync();

                MtdFormPartField fieldForList = await _context.MtdFormPartField.Include(m => m.MtdFormPartNavigation)
                                                .Where(x => x.MtdFormPartNavigation.MtdForm == idFormForList & x.MtdSysType == 1)
                                                .OrderBy(o => o.MtdFormPartNavigation.Sequence).ThenBy(o => o.Sequence).FirstOrDefaultAsync();

                if (idFormForList != null)
                {
                    List <SelecorStore> selecorStores = await _context.MtdStoreStack
                                                        .Include(x => x.MtdStoreStackText).Where(x => x.MtdFormPartField == fieldForList.Id)
                                                        .Select(x => new SelecorStore {
                        IdStore = x.MtdStore, Result = x.MtdStoreStackText.Register
                    })
                                                        .OrderBy(x => x.Result)
                                                        .ToListAsync();

                    SelectorList selectorList = new SelectorList
                    {
                        FieldAim = field,
                        FieldOut = fieldForList,
                        Store    = selecorStores
                    };

                    storeList.Add(selectorList);
                }
            }

            IList <MtdFilterScript> scripts = await _context.MtdFilterScript.Where(x => x.MtdFilter == filter.Id && x.Apply == 0).ToListAsync();

            SelectorModelView selector = new SelectorModelView()
            {
                IdForm            = idForm,
                MtdFormPartFields = mtdFields,
                MtdSysTerms       = mtdSysTerms,
                StoreList         = storeList,
                MtdFilterScripts  = scripts
            };

            return(View("Default", selector));
        }