示例#1
0
        public static NumberCellType CreateNumberCellType()
        {
            NumberCellType cellType = new NumberCellType();

            cellType.DecimalPlaces    = 2;
            cellType.DecimalSeparator = ".";
            cellType.Separator        = ",";
            cellType.ShowSeparator    = true;

            cellType.MaximumValue = (Math.Pow(10, 10 /*จำนวนหลัก*/) - 1);
            cellType.MinimumValue = (-1) * (Math.Pow(10, 10 /*จำนวนหลัก*/) - 1);


            return(cellType);
        }
示例#2
0
        /// <summary>
        /// Get format string for Excel's cell.
        /// </summary>
        /// <param name="cellType">Specific CellType</param>
        /// <returns></returns>
        private string GetExcelCellFormatString(ICellType cellType)
        {
            string strFormat = "";

            if (cellType is NumberCellType)
            {
                NumberCellType numberCellType = (NumberCellType)cellType;
                if (numberCellType.DecimalPlaces < 0)
                {
                    strFormat = "#,##0.00";
                }
                else if (numberCellType.DecimalPlaces == 0)
                {
                    if (numberCellType.ShowSeparator)
                    {
                        strFormat = "#,##0";
                    }
                    else
                    {
                        strFormat = "#0";
                    }
                }
                else
                {
                    string decimalPlace = "";
                    decimalPlace = decimalPlace.PadLeft(numberCellType.DecimalPlaces, '0');
                    strFormat    = "#,##0." + decimalPlace;
                }
            }
            else if (cellType is DateTimeCellType)
            {
                DateTimeCellType dateTimeCellType = (DateTimeCellType)cellType;
                if (dateTimeCellType.UserDefinedFormat == String.Empty)
                {
                    strFormat = CommonLib.Common.CurrentUserInfomation.DateFormat.ToString();// CommonLib.Common.CurrentUserInfomation.DateFormat.ToString();
                }
                else
                {
                    strFormat = dateTimeCellType.UserDefinedFormat;
                }
            }
            else
            {
                strFormat = "@";
            }

            return(strFormat);
        }
示例#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) { }
            }
        }
示例#4
0
        private void DataDialog_Load(object sender, EventArgs e)
        {
            ProgressScreen.Current.ShowSplashScreen();
            this.AddOwnedForm(ProgressScreen.Current);

            Dictionary <Guid, SheetView> SheetCollection = new Dictionary <Guid, SheetView>();
            JZDocument           document               = DocumentHelperClient.GetDocumentByID(DataID);
            JZDocument           defaultDocument        = ModuleHelperClient.GetDefaultDocument(ModuleID);
            List <JZFormulaData> CrossSheetFormulaInfos = ModuleHelperClient.GetLineFormulaByModuleIndex(ModuleID);

            FpSpread.Sheets.Clear();
            LoadSpread(FpSpread, ModuleID);
            #region 初始化表单
            foreach (JZSheet sheet in defaultDocument.Sheets)
            {
                SheetView SheetView = GetSheet(sheet.ID);
                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)
                    {
                        #region 处理单元格
                        cell.Locked = false;
                        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
                            {
                                cell.Value = value;
                            }
                        }
                        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
                            {
                                cell.Value = value;
                            }
                        }
                        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
                            {
                                cell.Value = value;
                            }
                        }
                        else if (cell.CellType is DeleteLineCellType)
                        {//删除线
                            DeleteLineCellType CellType = cell.CellType as DeleteLineCellType;
                            CellType.Multiline = true;
                            CellType.WordWrap  = true;
                            CellType.MaxLength = CellType.FieldType.Length;
                            cell.CellType      = CellType;
                            object objOld = cell.Text;
                            if (hasValue)
                            {
                                cell.Value = new System.Text.RegularExpressions.Regex("'+").Replace(value.ToString(), "'"); //value.ToString();
                                if (string.IsNullOrEmpty(cell.Text))
                                {
                                    RichTextBox rt = new RichTextBox();
                                    rt.Text    = objOld == null ? "" : objOld.ToString();
                                    rt.Font    = new Font("宋体", 10.5f, FontStyle.Regular);
                                    cell.Value = rt.Rtf;
                                }
                            }
                            else
                            {
                                RichTextBox rt = new RichTextBox();
                                rt.Text    = objOld == null ? "" : objOld.ToString();
                                rt.Font    = new Font("宋体", 10.5f, FontStyle.Regular);
                                cell.Value = rt.Rtf;
                            }
                        }
                        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;
                            for (int i = CellType.Mask.Length; i < CellType.FieldType.Length; i++)
                            {
                                CellType.Mask += "0";
                            }


                            if (CellType.CustomMaskCharacters != null && CellType.CustomMaskCharacters.Length > 0)
                            {
                                CellType.CustomMaskCharacters[0] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-()ⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩ()复检";
                            }
                            if (value == null || value.ToString().Trim() == "")
                            {
                                cell.Value = null;
                            }
                            else
                            {
                                cell.Value = value.ToString().Trim();
                            }
                        }
                        else if (cell.CellType is ImageCellType)
                        {
                            if (value != null)
                            {
                                cell.Value = JZCommonHelper.StringToBitmap(value.ToString());
                            }
                            else
                            {
                                cell.Value = null;
                            }
                        }
                        else if (cell.CellType is HyperLinkCellType)
                        {
                            if (value != null)
                            {
                                List <string>     lstLink  = new List <string>();
                                HyperLinkCellType hlnkCell = new HyperLinkCellType();
                                try
                                {
                                    lstLink       = Newtonsoft.Json.JsonConvert.DeserializeObject <List <string> >(value.ToString());
                                    hlnkCell.Text = lstLink[0];
                                    hlnkCell.Link = lstLink[1];
                                }
                                catch
                                {
                                    hlnkCell.Text = value.ToString();
                                    hlnkCell.Link = "";
                                }

                                cell.CellType = hlnkCell;
                                //cell.Value = value;
                            }
                            else
                            {
                                HyperLinkCellType hlnkCell = new HyperLinkCellType();
                                cell.CellType = hlnkCell;
                            }
                        }
                        else
                        {
                            cell.Value = value;
                        }
                        #endregion
                        JZCellProperty p = cell.Tag as JZCellProperty;
                        #region 处理单元格属性
                        if (p != null)
                        {
                            cell.Locked = false;
                        }
                        else
                        {
                            //  logger.Error("未能设置数据区信息:单元格" + dataCellDefault.Name + ",表单:" + sheet.Name);
                        }
                        #endregion
                    }
                }
                #region 线路单元格样式
                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);
                        }
                    }
                }
                #endregion
            }
            #endregion

            UpdateChart();
            UpdateEquation();

            //设置只读模式
            if (ReadOnly)
            {
                foreach (SheetView sheet in FpSpread.Sheets)
                {
                    sheet.OperationMode = OperationMode.ReadOnly;
                }
            }
        }
示例#5
0
        public static ICellType CreateCellType(string CellType)
        {
            ICellType Result = null;

            switch (CellType.ToLower())
            {
            case "文本":
                Result = new TextCellType();
                break;

            case "数字":
                Result = new NumberCellType();
                break;

            case "百分号":
                Result = new PercentCellType();
                break;

            case "图片":
                Result = new ImageCellType();
                break;

            case "超链接":
                Result = new HyperLinkCellType();
                break;

            case "货币":
                Result = new CurrencyCellType();
                break;

            case "日期时间":
                Result = new DateTimeCellType();
                break;

            case "复选框":
                Result = new CheckBoxCellType();
                break;

            case "上下标":
                Result = new RichTextCellType();
                break;

            case "条形码":
                Result = new BarCodeCellType();
                break;

            case "下拉框":
                Result = new DownListCellType();
                break;

            case "掩码":
                Result = new MaskCellType();
                break;

            case "删除线":
                Result = new DeleteLineCellType();
                break;

            default:
                Result = new TextCellType();
                break;
            }

            return(Result);
        }