예제 #1
0
        private static void ImportExcelXml(Stream stream, WfMatrix matrix, Action notifier)
        {
            WorkbookNode workbook = new WorkbookNode();

            workbook.Load(stream);

            ExceptionHelper.FalseThrow(workbook.Worksheets.Contains("Matrix"),
                                       "The workbook must contains a 'Matrix' worksheet.");

            NamedLocationCollection fieldLocations = workbook.Names.ToLocations();

            TableNode table = workbook.Worksheets["Matrix"].Table;

            int baseRowIndex = GetStartRow(fieldLocations);

            RowNode titleRow = table.GetRowByIndex(baseRowIndex);

            int currentRowIndex = table.Rows.IndexOf(titleRow) + 1;

            if (table.Rows.Count > currentRowIndex)
            {
                int currentVirtualRow = baseRowIndex;
                int count             = table.Rows.Count - currentRowIndex;
                for (int i = 0; i < count; i++)
                {
                    RowNode row = table.Rows[currentRowIndex];

                    if (row.Index > 0)
                    {
                        currentVirtualRow = row.Index;
                    }
                    else
                    {
                        currentVirtualRow++;
                    }

                    GenerateMatrixRow(matrix, row, fieldLocations, i);

                    if (notifier != null)
                    {
                        notifier();
                    }

                    currentRowIndex++;
                }
            }
            WfMatrixAdapter.Instance.DeleteByProcessKey(matrix.ProcessKey);
            WfMatrixAdapter.Instance.Update(matrix);
        }
예제 #2
0
        protected void uploadProgress_DoUploadProgress(HttpPostedFile file, UploadProgressResult result)
        {
            ExceptionHelper.FalseThrow(Path.GetExtension(file.FileName).ToLower() == ".xml",
                                       "'{0}' must be a xml file.", file.FileName);

            WorkbookNode workbook = new WorkbookNode();

            workbook.Load(file.InputStream);

            ExceptionHelper.FalseThrow(workbook.Worksheets.Contains("Matrix"),
                                       "The workbook must contains a 'Matrix' worksheet.");

            NamedLocationCollection fieldLocations = workbook.Names.ToLocations();

            TableNode table = workbook.Worksheets["Matrix"].Table;

            StringBuilder strB = new StringBuilder();

            int baseRowIndex = GetStartRow(fieldLocations);

            RowNode titleRow = table.GetRowByIndex(baseRowIndex);

            int currentRowIndex = table.Rows.IndexOf(titleRow) + 1;

            if (table.Rows.Count > currentRowIndex)
            {
                UploadProgressStatus status = new UploadProgressStatus();

                status.CurrentStep = 1;
                status.MinStep     = 0;
                status.MaxStep     = table.Rows.Count - currentRowIndex;

                int currentVirtualRow = baseRowIndex;

                for (int i = status.MinStep; i < status.MaxStep; i++)
                {
                    RowNode row = table.Rows[currentRowIndex];

                    if (row.Index > 0)
                    {
                        currentVirtualRow = row.Index;
                    }
                    else
                    {
                        currentVirtualRow++;
                    }

                    if (strB.Length > 0)
                    {
                        strB.Append("\n");
                    }

                    strB.AppendFormat("Processed={0}, Row={1}:", (i + 1), currentVirtualRow);

                    foreach (CellLocation location in fieldLocations)
                    {
                        CellNode cell = row.GetCellByIndex(location.Column);

                        strB.AppendFormat(";Name={0}, Value={1}", location.Name, cell != null ? cell.Data.Value : string.Empty);
                    }

                    status.CurrentStep = i;
                    status.Response();

                    currentRowIndex++;
                }

                status.CurrentStep = status.MaxStep;
                status.Response();
            }

            result.DataChanged = true;
            result.CloseWindow = false;
            result.ProcessLog  = strB.ToString();
        }
        /// <summary>
        /// 导入Excel Xml格式的文件
        /// </summary>
        /// <param name="stream"></param>
        private void ImportFromXml(Stream stream)
        {
            WorkbookNode workbook = new WorkbookNode();

            workbook.Load(stream);

            ExceptionHelper.FalseThrow(workbook.Worksheets.Contains("Matrix"),
                                       "The workbook must contains a 'Matrix' worksheet.");

            SOARole role = null;

            ServiceBrokerContext.Current.SaveContextStates();
            try
            {
                if (this.AppCodeName.IsNotEmpty() && this.RoleCodeName.IsNotEmpty())
                {
                    role = new SOARole(this.AppCodeName + ":" + this.RoleCodeName);
                }
                else
                {
                    role = new SOARole(this.Definition)
                    {
                        ID = RoleID
                    }
                };

                role.Rows.Clear();

                NamedLocationCollection fieldLocations = workbook.Names.ToLocations();

                TableNode table = workbook.Worksheets["Matrix"].Table;

                int baseRowIndex = GetStartRow(fieldLocations);

                RowNode titleRow = table.GetRowByIndex(baseRowIndex);

                int currentRowIndex = table.Rows.IndexOf(titleRow) + 1;

                if (table.Rows.Count > currentRowIndex)
                {
                    UploadProgressStatus status = new UploadProgressStatus();

                    status.CurrentStep = 1;
                    status.MinStep     = 0;
                    status.MaxStep     = table.Rows.Count - currentRowIndex;

                    int currentVirtualRow = baseRowIndex;

                    for (int i = status.MinStep; i < status.MaxStep; i++)
                    {
                        RowNode row = table.Rows[currentRowIndex];

                        if (row.Index > 0)
                        {
                            currentVirtualRow = row.Index;
                        }
                        else
                        {
                            currentVirtualRow++;
                        }

                        GenerateMatrixRow(role, row, fieldLocations, i);

                        status.CurrentStep = i;
                        status.Response();

                        currentRowIndex++;
                    }

                    status.CurrentStep = status.MaxStep;
                    status.Response();
                }
                //插入记录
                SOARolePropertiesAdapter.Instance.Update(role);
            }
            finally
            {
                ServiceBrokerContext.Current.RestoreSavedStates();
            }
        }