Пример #1
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;
                }
            }
        }
Пример #2
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);
        }