Ejemplo n.º 1
0
        private void LoadSheets()
        {
            ProgressScreen.Current.ShowSplashScreen();
            this.AddOwnedForm(ProgressScreen.Current);
            Dictionary <Guid, SheetView>            SheetCollection = new Dictionary <Guid, SheetView>();
            List <FarPoint.CalcEngine.FunctionInfo> Infos           = FunctionItemInfoUtil.getFunctionItemInfos();

            try
            {
                CrossSheetFormulaCache.Clear();
                FpSpread.Sheets.Clear();

                List <JZFormulaData> CrossSheetLineFormulaInfos = ModuleHelperClient.GetLineFormulaByModuleIndex(moduleID);

                foreach (Sys_Sheet sheet in sheetsList)
                {
                    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.ZoomFactor = 1.0F;
                    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);
                            }
                        }
                    }

                    foreach (FarPoint.CalcEngine.FunctionInfo Info in Infos)
                    {
                        SheetView.AddCustomFunction(Info);
                    }
                    if (!SheetCollection.ContainsKey(sheet.ID))
                    {
                        SheetCollection.Add(sheet.ID, SheetView);
                    }
                }
                FpSpread.LoadFormulas(true);
                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)
                    {
                        if (formula.Formula.ToUpper().Trim() == "NA()")
                        {
                            cell.Formula = "";
                        }
                        else
                        {
                            cell.Formula = formula.Formula;
                        }
                        if (formula.FormulaType == 1)
                        {
                            cell.BackColor = Color.Blue;
                        }
                        string key = string.Format("{0}_{1}_{2}", formula.SheetIndex, formula.RowIndex, formula.ColumnIndex);
                        if (ForLine)
                        {//线路公式
                            if (formula.FormulaType == 1)
                            {
                                if (!CrossSheetFormulaCache.ContainsKey(key))
                                {
                                    CrossSheetFormulaCache.Add(key, formula);
                                }
                                else
                                {
                                    CrossSheetFormulaCache[key] = formula;
                                }
                            }
                        }
                        else
                        {
                            if (!CrossSheetFormulaCache.ContainsKey(key))
                            {
                                CrossSheetFormulaCache.Add(key, formula);
                            }
                            else
                            {
                                CrossSheetFormulaCache[key] = formula;
                            }
                        }
                    }
                }

                FpSpread.LoadFormulas(true);
                fpSpreadEditor1.EnableToolStrip(true);
                UpdateChart();
                UpdateEquation();
            }
            catch (Exception ex)
            {
                MessageBox.Show("加载模板出错!\r\n原因:" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.RemoveOwnedForm(ProgressScreen.Current);
                ProgressScreen.Current.CloseSplashScreen();
                this.Activate();
            }
        }
Ejemplo n.º 2
0
        private void SheetDesinger_Load(object sender, EventArgs e)
        {
            ProgressScreen.Current.ShowSplashScreen();
            this.AddOwnedForm(ProgressScreen.Current);

            ProgressScreen.Current.SetStatus = "正在初始化表单...";

            try
            {
                Sys_Sheet sheetItem = ModuleHelperClient.GetSheetItemByID(sheetID);
                FpSpread.Sheets.Clear();

                if (ModuleHelperClient.IsContainerXml(sheetItem.SheetXML))
                {
                    sheetItem.SheetXML = sheetItem.SheetXML;
                }
                else
                {
                    sheetItem.SheetXML = JZCommonHelper.GZipDecompressString(sheetItem.SheetXML);
                }

                SheetView SheetView = Serializer.LoadObjectXml(typeof(SheetView), sheetItem.SheetXML, "SheetView") as SheetView;

                SheetView.SheetName = sheetItem.Name;

                List <FarPoint.CalcEngine.FunctionInfo> Infos = FunctionItemInfoUtil.getFunctionItemInfos();
                foreach (FarPoint.CalcEngine.FunctionInfo Info in Infos)
                {
                    SheetView.AddCustomFunction(Info);
                }

                List <JZCell> sheetDataAreaCells = Newtonsoft.Json.JsonConvert.DeserializeObject <List <JZCell> >(sheetItem.SheetData);
                if (sheetDataAreaCells != null)
                {
                    foreach (JZCell cell in sheetDataAreaCells)
                    {
                        dataCells.Add(SheetView.Cells[cell.Name]);
                    }
                }

                FpSpread.Sheets.Add(SheetView);
                dtCellStyle = ModuleHelperClient.GetCellStyleBySheetID(sheetID);
                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);
                        }
                    }
                }

                FpSpread.LoadFormulas(true);
                fpSheetEditor1.EnableToolStrip(true);

                UpdateChart();
                UpdateEquation();
            }
            catch (Exception ex)
            {
                MessageBox.Show("加载表单出错!\r\n原因:" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.RemoveOwnedForm(ProgressScreen.Current);
                ProgressScreen.Current.CloseSplashScreen();
                this.Activate();
            }
        }
Ejemplo n.º 3
0
        private void LoadSpread(Guid moduleID)
        {
            try
            {
                ProgressScreen.Current.ShowSplashScreen();
                ProgressScreen.Current.SetStatus = "正在打开模板...";
                FpSpread = new MyCell();
                //增加水印、图章
                FpSpread.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 = "正在初始化跨表公式...";
                FpSpread.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
                        {
                        }
                    }
                }
                FpSpread.LoadFormulas(true);
                ProgressScreen.Current.SetStatus = "正在显示资料...";
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToString());
            }
            finally
            {
                try
                {
                    //this.RemoveOwnedForm(ProgressScreen.Current);
                    ProgressScreen.Current.CloseSplashScreen();
                }
                catch
                {
                }
            }
        }