Ejemplo n.º 1
0
        private FpSpread LoadSpread(FpSpread spread, Guid moduleID)
        {
            try
            {
                ProgressScreen.Current.ShowSplashScreen();
                ProgressScreen.Current.SetStatus = "正在打开模板...";
                //增加水印、图章
                //spread.Watermark = ModuleHelperClient.GetWatermarkByModuleID(moduleID);
                Dictionary <Guid, SheetView>            SheetCollection = new Dictionary <Guid, SheetView>();
                List <FarPoint.CalcEngine.FunctionInfo> Infos           = FunctionItemInfoUtil.getFunctionItemInfos();
                JZDocument           defaultDocument            = ModuleHelperClient.GetDefaultDocument(moduleID);
                List <JZFormulaData> CrossSheetLineFormulaInfos = ModuleHelperClient.GetLineFormulaByModuleIndex(moduleID);

                foreach (JZSheet sheet in defaultDocument.Sheets)
                {
                    ProgressScreen.Current.SetStatus = "正在初始化表单‘" + sheet.Name + "’";
                    String    sheetXML  = ModuleHelperClient.GetSheetXMLByID(sheet.ID);
                    SheetView SheetView = Serializer.LoadObjectXml(typeof(SheetView), sheetXML, "SheetView") as SheetView;
                    SheetView.Tag               = sheet.ID;
                    SheetView.SheetName         = sheet.Name;
                    SheetView.Cells[0, 0].Value = "";
                    SheetView.Protect           = true;
                    FpSpread.Sheets.Add(SheetView);

                    DataTable dtCellStyle = ModuleHelperClient.GetCellStyleBySheetID(sheet.ID);
                    for (int i = 0; i < dtCellStyle.Rows.Count; i++)
                    {
                        if (dtCellStyle.Rows[i]["CellStyle"] != null)
                        {
                            JZCellStyle CurrentCellStyle = Newtonsoft.Json.JsonConvert.DeserializeObject <JZCellStyle>(dtCellStyle.Rows[i]["CellStyle"].ToString());
                            if (CurrentCellStyle != null)
                            {
                                string strCellName = dtCellStyle.Rows[i]["CellName"].ToString();
                                Cell   cell        = SheetView.Cells[strCellName];
                                cell.ForeColor = CurrentCellStyle.ForColor;
                                cell.BackColor = CurrentCellStyle.BackColor;
                                cell.Font      = new Font(CurrentCellStyle.FamilyName, CurrentCellStyle.FontSize, CurrentCellStyle.FontStyle);
                            }
                        }
                    }

                    SheetCollection.Add(sheet.ID, SheetView);
                    foreach (FarPoint.CalcEngine.FunctionInfo Info in Infos)
                    {
                        SheetView.AddCustomFunction(Info);
                    }
                }
                ProgressScreen.Current.SetStatus = "正在初始化跨表公式...";
                spread.LoadFormulas(false);
                foreach (JZFormulaData formula in CrossSheetLineFormulaInfos)
                {
                    if (!SheetCollection.ContainsKey(formula.SheetIndex))
                    {
                        continue;
                    }
                    SheetView Sheet = SheetCollection[formula.SheetIndex];

                    Cell cell = Sheet.Cells[formula.RowIndex, formula.ColumnIndex];
                    if (cell != null)
                    {
                        try
                        {
                            if (formula.Formula.ToUpper().Trim() == "NA()")
                            {
                                cell.Formula = "";
                            }
                            else
                            {
                                cell.Formula = formula.Formula;
                            }
                        }
                        catch
                        {
                        }
                    }
                }

                spread.LoadFormulas(true);
                ProgressScreen.Current.SetStatus = "正在显示资料...";

                return(spread);
            }
            catch (Exception ex)
            {
            }
            finally
            {
                try
                {
                    //this.RemoveOwnedForm(ProgressScreen.Current);
                    ProgressScreen.Current.CloseSplashScreen();
                }
                catch
                {
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        private void LogDialog_Load(object sender, EventArgs e)
        {
            ProgressScreen.Current.ShowSplashScreen();
            this.AddOwnedForm(ProgressScreen.Current);
            InitLogCategoryInfo();
            Dictionary <Guid, SheetView> SheetCollection = new Dictionary <Guid, SheetView>();

            try
            {
                List <FarPoint.CalcEngine.FunctionInfo> Infos = FunctionItemInfoUtil.getFunctionItemInfos();
                FpSpread.Sheets.Clear();
                if (dataID == Guid.Empty)
                {
                    return;
                }
                JZDocument document        = DocumentHelperClient.GetDocumentByID(dataID);
                JZDocument defaultDocument = ModuleHelperClient.GetDefaultDocument(moduleID);

                List <JZFormulaData> CrossSheetFormulaInfos = ModuleHelperClient.GetFormulaByModuleIndex(moduleID);

                foreach (JZSheet sheet in defaultDocument.Sheets)
                {
                    ProgressScreen.Current.SetStatus = "正在初始化表单‘" + sheet.Name + "’";
                    String    sheetXML  = ModuleHelperClient.GetSheetXMLByID(sheet.ID);
                    SheetView SheetView = Serializer.LoadObjectXml(typeof(SheetView), sheetXML, "SheetView") as SheetView;
                    SheetView.Tag               = sheet.ID;
                    SheetView.SheetName         = sheet.Name;
                    SheetView.Cells[0, 0].Value = "";
                    SheetView.Protect           = true;
                    FpSpread.Sheets.Add(SheetView);

                    SheetCollection.Add(sheet.ID, SheetView);
                    foreach (FarPoint.CalcEngine.FunctionInfo Info in Infos)
                    {
                        SheetView.AddCustomFunction(Info);
                    }
                    foreach (JZCell dataCellDefault in sheet.Cells)
                    {
                        Cell    cell     = SheetView.Cells[dataCellDefault.Name];
                        Object  value    = JZCommonHelper.GetCellValue(document, sheet.ID, dataCellDefault.Name);
                        Boolean hasValue = true;
                        if (value == null || value.ToString() == "")
                        {
                            hasValue = false;
                        }
                        if (cell != null)
                        {
                            cell.Font = defaultFont;
                            if (cell.CellType is DownListCellType)
                            {
                                DownListCellType CellType = cell.CellType as DownListCellType;
                                CellType.DropDownButton = false;
                                CellType.DesignMode     = false;
                                cell.Value = value;
                            }
                            else if (cell.CellType is TextCellType)
                            {
                                TextCellType CellType = cell.CellType as TextCellType;
                                if (CellType.FieldType.Description == FieldType.Text.Description)
                                {
                                    CellType.Multiline = true;
                                    CellType.WordWrap  = true;
                                }
                                CellType.MaxLength = CellType.FieldType.Length;
                                if (hasValue)
                                {
                                    cell.Value = value.ToString().Trim('\r', '\n');;
                                }
                            }
                            else if (cell.CellType is LongTextCellType)
                            {
                                LongTextCellType CellType = cell.CellType as LongTextCellType;
                                if (CellType.FieldType.Description == FieldType.LongText.Description)
                                {
                                    CellType.Multiline = true;
                                    CellType.WordWrap  = true;
                                }
                                CellType.MaxLength = CellType.FieldType.Length;
                                if (hasValue)
                                {
                                    cell.Value = value.ToString().Trim('\r', '\n');;
                                }
                            }
                            else if (cell.CellType is DateTimeCellType)
                            {
                                DateTimeCellType CellType = cell.CellType as DateTimeCellType;
                                CellType.MinimumDate = new DateTime(1753, 1, 1);
                                CellType.MaximumDate = new DateTime(9999, 12, 31);
                                cell.Value           = value;
                            }
                            else if (cell.CellType is RichTextCellType)
                            {
                                RichTextCellType CellType = cell.CellType as RichTextCellType;
                                CellType.Multiline = false;
                                CellType.WordWrap  = false;
                                CellType.MaxLength = CellType.FieldType.Length;
                                if (hasValue)
                                {
                                    cell.Value = value.ToString().Trim('\r', '\n');;
                                }
                            }
                            else if (cell.CellType is NumberCellType)
                            {
                                NumberCellType CellType = cell.CellType as NumberCellType;
                                CellType.MaximumValue = 999999999.9999;
                                CellType.MinimumValue = -999999999.9999;
                                cell.Value            = value;
                            }
                            else if (cell.CellType is MaskCellType)
                            {
                                MaskCellType CellType = cell.CellType as MaskCellType;
                                CellType.Mask = "00000000000000000000000000000000000";
                                if (CellType.CustomMaskCharacters != null && CellType.CustomMaskCharacters.Length > 0)
                                {
                                    CellType.CustomMaskCharacters[0] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-()()复检";
                                }
                                cell.Value = value;
                            }
                            else if (cell.CellType is ImageCellType)
                            {
                                if (value != null)
                                {
                                    cell.Value = JZCommonHelper.StringToBitmap(value.ToString());
                                }
                            }
                            else
                            {
                                cell.Value = value;
                            }
                        }
                    }
                }

                ProgressScreen.Current.SetStatus = "正在初始化跨表公式...";

                foreach (JZFormulaData formula in CrossSheetFormulaInfos)
                {
                    SheetView Sheet = SheetCollection[formula.SheetIndex];
                    try
                    {
                        Sheet.Cells[formula.RowIndex, formula.ColumnIndex].Formula = formula.Formula;
                    }
                    catch
                    {
                    }
                }

                FpSpread.LoadFormulas(true);

                ProgressScreen.Current.SetStatus = "正在显示资料...";

                UpdateChart();
                UpdateEquation();
                SetNotes();
                //设置只读模式
                if (ReadOnly)
                {
                    foreach (SheetView sheet in FpSpread.Sheets)
                    {
                        sheet.OperationMode = OperationMode.ReadOnly;
                    }
                }
            }
            catch (TimeoutException ex1)
            {
                MessageBox.Show("网络原因造成数据无法访问,请检查本机网络连接,或稍后再试!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show("加载试验模板出错!\r\n原因:" + (ex.InnerException != null ? ex.InnerException.Message : ex.Message), "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                try
                {
                    this.RemoveOwnedForm(ProgressScreen.Current);
                    ProgressScreen.Current.CloseSplashScreen();
                    this.Activate();
                }
                catch (Exception ex1) { }
            }
        }
Ejemplo n.º 3
0
        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker      = sender as BackgroundWorker;
            DataExportClass  Params      = e.Argument as DataExportClass;
            Font             defaultFont = new Font("宋体", 9f);
            String           Path        = Params.path;

            if (string.IsNullOrEmpty(Path))
            {
                return;
            }

            MyCell fpSpread = new MyCell();

            fpSpread.Watermark = ModuleHelperClient.GetWatermarkByModuleID(moduleID);
            //初始化模板样式
            List <FarPoint.CalcEngine.FunctionInfo> Infos = FunctionItemInfoUtil.getFunctionItemInfos();
            List <JZFormulaData> CrossSheetFormulaInfos   = ModuleHelperClient.GetFormulaByModuleIndex(moduleID);
            Dictionary <Sys_Document, JZDocument> list    = DocumentHelperClient.GetDocumentDataListByModuleIDAndTestRoomCode(moduleID, testRoomCode);

            if (list.Count == 0)
            {
                return;
            }

            Dictionary <Sys_Document, JZDocument> .Enumerator em = list.GetEnumerator();
            int i = 0;

            while (em.MoveNext())
            {
                Sys_Document docBase = em.Current.Key;
                JZDocument   doc     = em.Current.Value;

                if (i == 0)
                {
                    foreach (JZSheet sheet in doc.Sheets)
                    {
                        ProgressScreen.Current.SetStatus = string.Format("正在准备表单{0}...", sheet.Name);
                        String    sheetXML  = ModuleHelperClient.GetSheetXMLByID(sheet.ID);
                        SheetView SheetView = Serializer.LoadObjectXml(typeof(SheetView), sheetXML, "SheetView") as SheetView;
                        SheetView.Tag               = sheet.ID;
                        SheetView.SheetName         = sheet.Name;
                        SheetView.Cells[0, 0].Value = "";
                        SheetView.Protect           = true;
                        fpSpread.Sheets.Add(SheetView);

                        foreach (FarPoint.CalcEngine.FunctionInfo Info in Infos)
                        {
                            SheetView.AddCustomFunction(Info);
                        }
                    }
                    fpSpread.LoadFormulas(true);
                }
                i = i + 1;

                worker.ReportProgress((int)(((float)i / (float)list.Count) * 100));

                foreach (JZSheet sheet in doc.Sheets)
                {
                    SheetView sheetV = null;

                    for (int j = 0; j < fpSpread.Sheets.Count; j++)
                    {
                        if (new Guid(fpSpread.Sheets[j].Tag.ToString()) == sheet.ID)
                        {
                            sheetV = fpSpread.Sheets[j];
                            break;
                        }
                    }
                    if (sheetV == null)
                    {
                        break;
                    }
                    foreach (JZCell dataCell in sheet.Cells)
                    {
                        Cell cell = sheetV.Cells[dataCell.Name];

                        if (cell != null)
                        {
                            cell.Font = defaultFont;
                            if (cell.CellType is ImageCellType)
                            {
                                if (dataCell.Value != null)
                                {
                                    cell.Value = JZCommonHelper.StringToBitmap(dataCell.Value.ToString());
                                }
                            }
                            else
                            {
                                cell.Value = dataCell.Value;
                            }
                        }
                    }
                }
                try
                {
                    //保存资料到指定目录
                    String reportNumber = docBase.BGBH == "" ? "无报告编号" + i.ToString() : docBase.BGBH;

                    ExcelWarningList ewl      = new ExcelWarningList();
                    string           fileName = Path + "\\" + moduleName + "-" + reportNumber + ".xls";
                    fpSpread.SaveExcel(fileName, ExcelSaveFlags.NoFlagsSet, ewl);
                }
                catch
                { }
            }
        }