コード例 #1
0
        public async Task <IViewComponentResult> InvokeAsync(IList <MtdStoreStack> stack, string idStore, string idField, int idType)
        {
            string viewName = await GetViewNameAsync(idType);

            MtdStoreStack storeStack = await GetStoreStackAsync(stack, idStore, idField);

            CellModelView cellModel = new CellModelView
            {
                MtdStoreStack = storeStack ?? new MtdStoreStack()
            };

            return(View(viewName, cellModel));
        }
コード例 #2
0
ファイル: Viewer.cs プロジェクト: nakinnubis/OrderMaker
        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));
        }
コード例 #3
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));
        }
コード例 #4
0
 private void CheckStackForNull(MtdStoreStack mtdStoreStack)
 {
     if (mtdStoreStack.MtdStoreStackDate == null)
     {
         mtdStoreStack.MtdStoreStackDate = new MtdStoreStackDate();
     }
     if (mtdStoreStack.MtdStoreStackDecimal == null)
     {
         mtdStoreStack.MtdStoreStackDecimal = new MtdStoreStackDecimal();
     }
     if (mtdStoreStack.MtdStoreStackFile == null)
     {
         mtdStoreStack.MtdStoreStackFile = new MtdStoreStackFile();
     }
     if (mtdStoreStack.MtdStoreStackInt == null)
     {
         mtdStoreStack.MtdStoreStackInt = new MtdStoreStackInt();
     }
     if (mtdStoreStack.MtdStoreStackText == null)
     {
         mtdStoreStack.MtdStoreStackText = new MtdStoreStackText();
     }
 }
コード例 #5
0
ファイル: ActionController.cs プロジェクト: lulzzz/OrderMaker
        private IWorkbook CreateWorkbook(IList <MtdStore> mtdStores, IList <MtdFormPartField> partFields, IList <MtdStoreStack> storeStack)
        {
            IWorkbook workbook = new XSSFWorkbook();

            ISheet sheet1   = workbook.CreateSheet("Sheet1");
            var    rowIndex = 0;
            var    colIndex = 0;
            IRow   rowTitle = sheet1.CreateRow(rowIndex);

            rowTitle.CreateCell(0).SetCellValue("ID");
            foreach (var field in partFields)
            {
                colIndex++;
                rowTitle.CreateCell(colIndex).SetCellValue(field.Name);
            }

            colIndex = 0;
            rowIndex++;
            foreach (var store in mtdStores)
            {
                IRow row = sheet1.CreateRow(rowIndex);
                row.CreateCell(colIndex).SetCellValue(store.Sequence.ToString("D9"));
                foreach (var field in partFields)
                {
                    colIndex++;
                    MtdStoreStack stack = storeStack.FirstOrDefault(x => x.MtdStore == store.Id && x.MtdFormPartField == field.Id);
                    ICell         cell  = row.CreateCell(colIndex);
                    SetValuefoCell(stack, field, cell);
                }
                colIndex = 0;
                rowIndex++;
            }

            sheet1.AutoSizeColumn(0);
            return(workbook);
        }
コード例 #6
0
        private async void CloneStore(string idStore)
        {
            var q = from n in _context.MtdStoreStack.Where(x => x.MtdStore == idStore)
                    group n by n.MtdFormPartField into g
                    select new { idField = g.Key, idStack = g.FirstOrDefault(x => x.Id == g.Max(m => m.Id)).Id };

            List <long> ids = await q.Select(x => x.idStack).ToListAsync();


            IList <MtdStoreStack> stack = await _context.MtdStoreStack
                                          .Include(x => x.MtdStoreStackDate)
                                          .Include(x => x.MtdStoreStackText)
                                          .Include(x => x.MtdStoreStackInt)
                                          .Include(x => x.MtdStoreStackDecimal)
                                          .Include(x => x.MtdStoreStackFile)
                                          .Include(x => x.MtdStoreLink)
                                          .Where(x => ids.Contains(x.Id))
                                          .ToListAsync();

            string idForm = await _context.MtdStore.Where(s => s.Id == idStore).Select(x => x.MtdForm).FirstOrDefaultAsync();

            int maxSeq = await _context.MtdStore.Where(x => x.MtdForm == idForm).MaxAsync(s => s.Sequence);

            maxSeq++;

            MtdStore mtdStore = new MtdStore()
            {
                Sequence = maxSeq,
                MtdForm  = idForm
            };


            foreach (MtdStoreStack storeStack in stack)
            {
                MtdStoreStack newStack = new MtdStoreStack()
                {
                    MtdStore          = storeStack.MtdStore,
                    MtdFormPartField  = storeStack.MtdFormPartField,
                    MtdStoreStackDate = storeStack.MtdStoreStackDate != null ? new MtdStoreStackDate {
                        Register = storeStack.MtdStoreStackDate.Register
                    } : null,
                    MtdStoreStackText = storeStack.MtdStoreStackText != null ? new MtdStoreStackText {
                        Register = storeStack.MtdStoreStackText.Register
                    } : null,
                    MtdStoreStackInt = storeStack.MtdStoreStackInt != null ? new MtdStoreStackInt {
                        Register = storeStack.MtdStoreStackInt.Register
                    } : null,
                    MtdStoreStackDecimal = storeStack.MtdStoreStackDecimal != null ? new MtdStoreStackDecimal {
                        Register = storeStack.MtdStoreStackDecimal.Register
                    } : null,

                    MtdStoreStackFile = storeStack.MtdStoreStackFile != null ? new MtdStoreStackFile
                    {
                        Register = storeStack.MtdStoreStackFile.Register,
                        FileName = storeStack.MtdStoreStackFile.FileName,
                        FileSize = storeStack.MtdStoreStackFile.FileSize,
                        FileType = storeStack.MtdStoreStackFile.FileType
                    } : null,

                    MtdStoreLink = storeStack.MtdStoreLink,
                };

                mtdStore.MtdStoreStack.Add(newStack);
            }

            _context.MtdStore.Add(mtdStore);
            await _context.SaveChangesAsync();
        }
コード例 #7
0
        public async Task <IActionResult> OnPostSaveAsync()
        {
            IFormCollection requestForm = await Request.ReadFormAsync();

            string Id = requestForm["idStore"];

            MtdStore mtdStore = await _context.MtdStore.FirstOrDefaultAsync(x => x.Id == Id);

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

            WebAppUser webAppUser = await _userHandler.GetUserAsync(HttpContext.User);

            bool isEditor = await _userHandler.IsEditor(webAppUser, mtdStore.MtdForm, mtdStore.Id);

            ApprovalHandler approvalHandler = new ApprovalHandler(_context, mtdStore.Id);
            ApprovalStatus  approvalStatus  = await approvalHandler.GetStatusAsync(webAppUser);

            if (!isEditor || approvalStatus == ApprovalStatus.Rejected || approvalStatus == ApprovalStatus.Waiting)
            {
                return(Ok(403));
            }

            MtdLogDocument mtdLog = new MtdLogDocument
            {
                MtdStore = mtdStore.Id,
                TimeCh   = DateTime.Now,
                UserId   = webAppUser.Id,
                UserName = webAppUser.Title
            };


            OutData outData = await CreateDataAsync(Id, webAppUser, TypeAction.Edit, requestForm);

            List <MtdStoreStack> stackNew = outData.MtdStoreStacks;


            IList <MtdStoreStack> stackOld = await _context.MtdStoreStack
                                             .Include(m => m.MtdStoreStackText)
                                             .Include(m => m.MtdStoreStackDecimal)
                                             .Include(m => m.MtdStoreStackFile)
                                             .Include(m => m.MtdStoreStackDate)
                                             .Include(m => m.MtdStoreStackInt)
                                             .Include(m => m.MtdStoreLink)
                                             .Where(x => x.MtdStore == Id).ToListAsync();

            foreach (MtdStoreStack stack in stackOld)
            {
                MtdStoreStack stackForField = stackNew.SingleOrDefault(x => x.MtdFormPartField == stack.MtdFormPartField);
                if (stackForField != null)
                {
                    stack.MtdStoreStackText    = stackForField.MtdStoreStackText;
                    stack.MtdStoreLink         = stackForField.MtdStoreLink;
                    stack.MtdStoreStackDate    = stackForField.MtdStoreStackDate;
                    stack.MtdStoreStackDecimal = stackForField.MtdStoreStackDecimal;
                    stack.MtdStoreStackFile    = stackForField.MtdStoreStackFile;
                    stack.MtdStoreStackInt     = stackForField.MtdStoreStackInt;
                }
            }


            try
            {
                if (stackNew.Count > 0)
                {
                    int count = await _context.MtdStoreLink.Where(x => x.MtdStore == Id).CountAsync();

                    if (count > 0)
                    {
                        string titleText             = outData.MtdStoreStacks.FirstOrDefault(x => x.MtdFormPartField == outData.MtdFormPartField.Id).MtdStoreStackText.Register;
                        IList <MtdStoreLink> linkIds = await _context.MtdStoreLink.Where(x => x.MtdStore == Id).Select(x => new MtdStoreLink {
                            Id = x.Id, MtdStore = x.MtdStore, Register = titleText
                        }).ToListAsync();

                        _context.MtdStoreLink.UpdateRange(linkIds);
                    }

                    _context.MtdStoreStack.UpdateRange(stackOld);


                    List <MtdStoreStack> stackNewOnly = stackNew.Where(x => !stackOld.Select(f => f.MtdFormPartField).Contains(x.MtdFormPartField)).ToList();

                    if (stackNewOnly.Any())
                    {
                        await _context.MtdStoreStack.AddRangeAsync(stackNewOnly);
                    }

                    _context.MtdLogDocument.Add(mtdLog);
                    await _context.SaveChangesAsync();
                }
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!MtdStoreExists(Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(Ok());
        }
コード例 #8
0
        private async Task <OutData> CreateDataAsync(string Id, WebAppUser user, TypeAction typeAction, IFormCollection requestForm)
        {
            var store = await _context.MtdStore
                        .Include(m => m.MtdFormNavigation)
                        .ThenInclude(p => p.MtdFormPart)
                        .FirstOrDefaultAsync(m => m.Id == Id);

            List <string> partsIds   = new List <string>();
            bool          isReviewer = await _userHandler.IsReviewer(user, store.MtdForm);

            ApprovalHandler approvalHandler = new ApprovalHandler(_context, store.Id);
            List <string>   blockedParts    = new List <string>();

            if (!isReviewer)
            {
                blockedParts = await approvalHandler.GetBlockedPartsIds();
            }

            foreach (var part in store.MtdFormNavigation.MtdFormPart)
            {
                switch (typeAction)
                {
                case TypeAction.Create:
                {
                    if (await _userHandler.IsCreatorPartAsync(user, part.Id))
                    {
                        partsIds.Add(part.Id);
                    }
                    break;
                }

                default:
                {
                    if (await _userHandler.IsEditorPartAsync(user, part.Id) && !blockedParts.Contains(part.Id))
                    {
                        partsIds.Add(part.Id);
                    }
                    break;
                }
                }
            }


            var fields = await _context.MtdFormPartField.Include(m => m.MtdFormPartNavigation)
                         .Where(x => partsIds.Contains(x.MtdFormPartNavigation.Id))
                         .OrderBy(x => x.MtdFormPartNavigation.Sequence)
                         .ThenBy(x => x.Sequence)
                         .ToListAsync();

            var titleField = fields.FirstOrDefault(x => x.MtdSysType == 1);

            List <MtdStoreStack> stackNew = new List <MtdStoreStack>();

            foreach (MtdFormPartField field in fields)
            {
                string        data          = requestForm[field.Id];
                MtdStoreStack mtdStoreStack = new MtdStoreStack()
                {
                    MtdStore         = Id,
                    MtdFormPartField = field.Id
                };


                switch (field.MtdSysType)
                {
                case 2:
                {
                    if (data != string.Empty)
                    {
                        bool isOkInt = int.TryParse(data, out int result);
                        if (isOkInt)
                        {
                            mtdStoreStack.MtdStoreStackInt = new MtdStoreStackInt {
                                Register = result
                            };
                        }
                    }
                    break;
                }

                case 3:
                {
                    if (data != string.Empty)
                    {
                        string separ       = CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator;
                        bool   isOkDecimal = decimal.TryParse(data.Replace(".", separ), out decimal result);
                        if (isOkDecimal)
                        {
                            mtdStoreStack.MtdStoreStackDecimal = new MtdStoreStackDecimal {
                                Register = result
                            };
                        }
                    }
                    break;
                }

                case 5:
                case 6:
                case 10:
                {
                    if (data != string.Empty)
                    {
                        bool isOkDate = DateTime.TryParse(data, out DateTime dateTime);
                        if (isOkDate)
                        {
                            mtdStoreStack.MtdStoreStackDate = new MtdStoreStackDate {
                                Register = dateTime
                            };
                        }
                    }
                    break;
                }

                case 7:
                case 8:
                {
                    var actionDelete = requestForm[$"{field.Id}-delete"];

                    if (actionDelete.FirstOrDefault() == null || actionDelete.FirstOrDefault() == "false")
                    {
                        IFormFile file = requestForm.Files.FirstOrDefault(x => x.Name == field.Id);

                        if (file != null)
                        {
                            byte[] streamArray = new byte[file.Length];
                            await file.OpenReadStream().ReadAsync(streamArray, 0, streamArray.Length);

                            mtdStoreStack.MtdStoreStackFile = new MtdStoreStackFile()
                            {
                                Register = streamArray,
                                FileName = file.FileName,
                                FileSize = streamArray.Length,
                                FileType = file.ContentType
                            };
                        }

                        if (file == null)
                        {
                            MtdStoreStack stackOld = await _context.MtdStoreStack
                                                     .Include(m => m.MtdStoreStackFile)
                                                     .OrderByDescending(x => x.Id)
                                                     .FirstOrDefaultAsync(x => x.MtdStore == Id & x.MtdFormPartField == field.Id);

                            if (stackOld != null && stackOld.MtdStoreStackFile != null)
                            {
                                mtdStoreStack.MtdStoreStackFile = new MtdStoreStackFile()
                                {
                                    FileName = stackOld.MtdStoreStackFile.FileName,
                                    FileSize = stackOld.MtdStoreStackFile.FileSize,
                                    Register = stackOld.MtdStoreStackFile.Register,
                                    FileType = stackOld.MtdStoreStackFile.FileType,
                                };
                            }
                        }
                    }

                    break;
                }

                case 11:
                {
                    if (data != string.Empty)
                    {
                        string datalink = Request.Form[$"{field.Id}-datalink"];
                        mtdStoreStack.MtdStoreLink = new MtdStoreLink {
                            MtdStore = data, Register = datalink
                        };
                    }

                    break;
                }

                case 12:
                {
                    bool isOkCheck = bool.TryParse(data, out bool check);
                    if (isOkCheck)
                    {
                        mtdStoreStack.MtdStoreStackInt = new MtdStoreStackInt {
                            Register = check ? 1 : 0
                        };
                    }
                    break;
                }

                default:
                {
                    if (data != string.Empty)
                    {
                        mtdStoreStack.MtdStoreStackText = new MtdStoreStackText()
                        {
                            Register = data
                        };
                    }
                    break;
                }
                }

                stackNew.Add(mtdStoreStack);
            }

            OutData outParam = new OutData()
            {
                MtdFormPartField = titleField,
                MtdStoreStacks   = stackNew,
            };

            return(outParam);
        }
コード例 #9
0
ファイル: ActionController.cs プロジェクト: lulzzz/OrderMaker
        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;
            }
            }
        }