Exemple #1
0
        public async Task <IActionResult> Index(int id, int langId)
        {
            CheckDataViewModel checkDataViewModel = new CheckDataViewModel();
            GroupProvider      groupProvider      = await(from grp in providerDbContext.GroupProviders
                                                          where grp.Id == id
                                                          select new GroupProvider
            {
                HasOptions          = grp.HasOptions,
                HasSecondaryOptions = grp.HasSecondaryOptions,
                HasInput            = grp.HasInput,
                HasSecondaryInput   = grp.HasSecondaryInput,
                HasAdditionalInput  = grp.HasAdditionalInput
            }).FirstOrDefaultAsync();

            checkDataViewModel.HasOptions          = groupProvider.HasOptions;
            checkDataViewModel.HasSecondaryOptions = groupProvider.HasSecondaryOptions;
            checkDataViewModel.HasSecondaryInput   = groupProvider.HasSecondaryInput;
            checkDataViewModel.HasAdditionalInput  = groupProvider.HasAdditionalInput;
            checkDataViewModel.ContinueButtonText  = await(from lang in providerDbContext.LanguageConfigurations
                                                           join grpvbtntxt in providerDbContext.GroupProviderPageButtonTexts on lang.Id equals grpvbtntxt
                                                           .LangId
                                                           where lang.Id == langId
                                                           select grpvbtntxt.Text
                                                           ).FirstOrDefaultAsync();

            checkDataViewModel.LangId = await(from lang in providerDbContext.LanguageConfigurations
                                              where lang.Id == langId
                                              select lang.Id).FirstOrDefaultAsync();

            checkDataViewModel.CancelButtonText = await(from lang in providerDbContext.LanguageConfigurations
                                                        join grpvbtntxt in providerDbContext.GroupProviderPageButtonTexts on lang.Id equals grpvbtntxt
                                                        .LangId
                                                        where lang.Id == langId
                                                        select grpvbtntxt.Text
                                                        ).LastOrDefaultAsync();

            checkDataViewModel.ProviderName = await(from grp in providerDbContext.GroupProviders
                                                    where grp.Id == id
                                                    select grp.ProviderName).FirstOrDefaultAsync();

            checkDataViewModel.CoreProviderId = await(from core in providerDbContext.CoreProviders
                                                      join grvp in providerDbContext.GroupProviders on core.Id equals grvp.CoreProviderId
                                                      where grvp.Id == id
                                                      select core.Id).FirstOrDefaultAsync();
            if (checkDataViewModel.HasOptions == true)
            {
                checkDataViewModel.FirstOptionLabelText = (from grp in providerDbContext.GroupProviders
                                                           join prvopt in providerDbContext.ProviderOptions on grp.Id equals prvopt.GroupProviderId
                                                           where grp.Id == id
                                                           where prvopt.IsFirstOption == true
                                                           select prvopt.LabelText).FirstOrDefault();

                checkDataViewModel.FirstOptions = await providerDbContext.ProviderOptions.Include(x => x.GroupProvider)
                                                  .Where(x => x.GroupProviderId == id && x.IsFirstOption == true).Select(x => x.Text).ToListAsync();
            }

            if (checkDataViewModel.HasSecondaryOptions == true)
            {
                checkDataViewModel.SecindOptionLabelText = (from grp in providerDbContext.GroupProviders
                                                            join prvopt in providerDbContext.ProviderOptions on grp.Id equals prvopt.GroupProviderId
                                                            where grp.Id == id
                                                            select prvopt.LabelText).FirstOrDefault();

                checkDataViewModel.SecondOptions = await providerDbContext.ProviderOptions.Include(x => x.GroupProvider)
                                                   .Where(x => x.GroupProviderId == id && x.IsSecondaryOption == true).Select(x => x.Text).ToListAsync();
            }

            checkDataViewModel.FirstInputModel = await(from grp in providerDbContext.GroupProviders
                                                       join prvadinfo in providerDbContext.ProviderAdditionalInformations on grp.Id equals prvadinfo
                                                       .GroupProviderId
                                                       where grp.Id == id
                                                       select new FirstInputModel
            {
                InputText        = prvadinfo.InputText,
                InputValidLength = prvadinfo.FirstInputValidLength
            }).FirstOrDefaultAsync();

            if (checkDataViewModel.HasSecondaryInput == true)
            {
                checkDataViewModel.SecondInputModel = await(from grp in providerDbContext.GroupProviders
                                                            join prvadinfo in providerDbContext.ProviderAdditionalInformations on grp.Id equals prvadinfo
                                                            .GroupProviderId
                                                            where grp.Id == id
                                                            select new SecondInputModel
                {
                    InputText        = prvadinfo.SecondaryInputText,
                    InputValidLength = prvadinfo.SecondaryInputValidLength
                }).FirstOrDefaultAsync();
            }

            if (checkDataViewModel.HasAdditionalInput == true)
            {
                checkDataViewModel.AdditionalInputModel = await(from grp in providerDbContext.GroupProviders
                                                                join prvadinfo in providerDbContext.ProviderAdditionalInformations on grp.Id equals prvadinfo
                                                                .GroupProviderId
                                                                where grp.Id == id
                                                                select new AdditionalInputModel
                {
                    InputText        = prvadinfo.AdditionalInputText,
                    InputValidLength = prvadinfo.AdditionalInputValidLength
                }).FirstOrDefaultAsync();
            }

            checkDataViewModel.ImagePath = await(from grp in providerDbContext.GroupProviders
                                                 where grp.Id == id
                                                 select grp.ImagePath).FirstOrDefaultAsync();

            checkDataViewModel.CategoryName = await(from grp in providerDbContext.GroupProviders
                                                    join prvcat in providerDbContext.ProviderCategories on grp.ProviderCategroyId equals prvcat.Id
                                                    where grp.Id == id
                                                    select prvcat.Name).FirstOrDefaultAsync();

            return(View(checkDataViewModel));
        }
Exemple #2
0
        public async Task <ActionResult> ExportToExcel(CheckDataQueryViewModel model)
        {
            IList <LotTransaction> lstCheckData = new List <LotTransaction>();

            CheckDataViewModel m = new CheckDataViewModel();

            using (LotQueryServiceClient client = new LotQueryServiceClient())
            {
                await Task.Run(() =>
                {
                    PagingConfig cfg = new PagingConfig()
                    {
                        IsPaging = false,
                        OrderBy  = "CreateTime DESC",
                        Where    = GetQueryCondition(model)
                    };
                    MethodReturnResult <IList <LotTransaction> > result = client.GetTransaction(ref cfg);

                    if (result.Code == 0)
                    {
                        lstCheckData = result.Data;
                    }
                });
            }
            //创建工作薄。
            IWorkbook wb = new HSSFWorkbook();
            //设置EXCEL格式
            ICellStyle style = wb.CreateCellStyle();

            style.FillForegroundColor = 10;
            //有边框
            style.BorderBottom = BorderStyle.Thin;
            style.BorderLeft   = BorderStyle.Thin;
            style.BorderRight  = BorderStyle.Thin;
            style.BorderTop    = BorderStyle.Thin;
            IFont font = wb.CreateFont();

            font.Boldweight = 10;
            style.SetFont(font);
            ISheet ws = null;

            for (int j = 0; j < lstCheckData.Count; j++)
            {
                if (j % 65535 == 0)
                {
                    ws = wb.CreateSheet();
                    IRow row = ws.CreateRow(0);
                    #region //列名
                    ICell cell = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue(StringResource.ItemNo);  //项目号

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("批次号");

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("工单号");

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("产品料号");

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("线别");

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("等级");

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("花色");

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("实际功率");

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("实际电流");

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("实际最大电流");

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("实际电压");

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("实际最大电压");

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("实际填充因子");

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("分档名称");

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("子分档代码");

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("备注");

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("检验时间");

                    cell           = row.CreateCell(row.Cells.Count);
                    cell.CellStyle = style;
                    cell.SetCellValue("检验操作人");
                    #endregion
                    font.Boldweight = 5;
                }
                LotTransaction        obj        = lstCheckData[j];
                IRow                  rowData    = ws.CreateRow(j + 1);
                Lot                   lotObj     = m.GetLot(obj.LotNumber);
                IVTestData            ivtestData = m.GetIVTestData(obj.LotNumber);
                LotTransactionHistory lotHisObj  = m.GetLotTransactionHistory(obj.Key);

                #region //数据
                ICell cellData = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(j + 1);  //项目号

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(obj.LotNumber);  //批次号

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(obj.OrderNumber);  //工单号

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(lotHisObj != null ? lotHisObj.MaterialCode : string.Empty);

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(lotHisObj != null ? lotHisObj.LineCode : string.Empty);

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(lotObj != null ? lotObj.Grade : string.Empty);

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(lotObj != null ? lotObj.Color : string.Empty);

                if (ivtestData != null)
                {
                    cellData           = rowData.CreateCell(rowData.Cells.Count);
                    cellData.CellStyle = style;
                    cellData.SetCellValue(ivtestData.CoefPM);

                    cellData           = rowData.CreateCell(rowData.Cells.Count);
                    cellData.CellStyle = style;
                    cellData.SetCellValue(ivtestData.CoefISC);

                    cellData           = rowData.CreateCell(rowData.Cells.Count);
                    cellData.CellStyle = style;
                    cellData.SetCellValue(ivtestData.CoefIPM);

                    cellData           = rowData.CreateCell(rowData.Cells.Count);
                    cellData.CellStyle = style;
                    cellData.SetCellValue(ivtestData.CoefVOC);

                    cellData           = rowData.CreateCell(rowData.Cells.Count);
                    cellData.CellStyle = style;
                    cellData.SetCellValue(ivtestData.CoefVPM);

                    cellData           = rowData.CreateCell(rowData.Cells.Count);
                    cellData.CellStyle = style;
                    cellData.SetCellValue(ivtestData.CoefFF);
                }
                else
                {
                    cellData           = rowData.CreateCell(rowData.Cells.Count);
                    cellData.CellStyle = style;
                    cellData.SetCellValue(string.Empty);

                    cellData           = rowData.CreateCell(rowData.Cells.Count);
                    cellData.CellStyle = style;
                    cellData.SetCellValue(string.Empty);

                    cellData           = rowData.CreateCell(rowData.Cells.Count);
                    cellData.CellStyle = style;
                    cellData.SetCellValue(string.Empty);

                    cellData           = rowData.CreateCell(rowData.Cells.Count);
                    cellData.CellStyle = style;
                    cellData.SetCellValue(string.Empty);

                    cellData           = rowData.CreateCell(rowData.Cells.Count);
                    cellData.CellStyle = style;
                    cellData.SetCellValue(string.Empty);

                    cellData           = rowData.CreateCell(rowData.Cells.Count);
                    cellData.CellStyle = style;
                    cellData.SetCellValue(string.Empty);
                }

                if (ivtestData == null || string.IsNullOrEmpty(ivtestData.PowersetCode) || ivtestData.PowersetItemNo == null)
                {
                    cellData           = rowData.CreateCell(rowData.Cells.Count);
                    cellData.CellStyle = style;
                    cellData.SetCellValue(string.Empty);

                    cellData           = rowData.CreateCell(rowData.Cells.Count);
                    cellData.CellStyle = style;
                    cellData.SetCellValue(string.Empty);
                }
                else
                {
                    string powersetName = m.GetPowersetName(ivtestData.Key.LotNumber, ivtestData.PowersetCode, ivtestData.PowersetItemNo.Value);
                    cellData           = rowData.CreateCell(rowData.Cells.Count);
                    cellData.CellStyle = style;
                    cellData.SetCellValue(powersetName);

                    cellData           = rowData.CreateCell(rowData.Cells.Count);
                    cellData.CellStyle = style;
                    cellData.SetCellValue(ivtestData.PowersetSubCode);
                }

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(obj.Description);


                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(string.Format("{0:yyyy-MM-dd HH:mm:ss}", obj.CreateTime));

                cellData           = rowData.CreateCell(rowData.Cells.Count);
                cellData.CellStyle = style;
                cellData.SetCellValue(obj.Creator);


                #endregion
            }

            MemoryStream ms = new MemoryStream();
            wb.Write(ms);
            ms.Flush();
            ms.Position = 0;
            return(File(ms, "application/vnd.ms-excel", "CheckDataData.xls"));
        }