Exemple #1
0
        public static FpSpread GetModuleByID(Guid moduleID, JZDocument document, String DBName)
        {
            if (moduleList.ContainsKey(moduleID))
            {
                return(moduleList[moduleID]);
            }
            else
            {
                FpSpread fpSpread = new FpSpread();
                try
                {
                    Dictionary <Guid, SheetView>            SheetCollection = new Dictionary <Guid, SheetView>();
                    List <FarPoint.CalcEngine.FunctionInfo> Infos           = DBHelper.CallLocalService("Yqun.BO.BusinessManager.dll", "GetFunctionInfosNew", new object[] { }, DBName) as List <FarPoint.CalcEngine.FunctionInfo>;

                    foreach (JZSheet sheet in document.Sheets)
                    {
                        String    xml       = DBHelper.CallLocalService("Yqun.BO.BusinessManager.dll", "GetSheetXMLByID", new object[] { sheet.ID }, DBName).ToString();
                        String    sheetXML  = JZCommonHelper.GZipDecompressString(xml);
                        SheetView SheetView = Serializer.LoadObjectXml(typeof(SheetView), sheetXML, "SheetView") as SheetView;
                        SheetView.Tag = sheet.ID;
                        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);
                        }
                    }
                    moduleList.Add(moduleID, fpSpread);
                }
                catch (Exception ex)
                {
                    logger.Error("采集构造Farpoint组件错误:" + ex.Message);
                    return(null);
                }
                return(fpSpread);
            }
        }
Exemple #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();
            }
        }
Exemple #3
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) { }
            }
        }
Exemple #4
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();
            }
        }
Exemple #5
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
                {
                }
            }
        }
Exemple #6
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
                { }
            }
        }