Ejemplo n.º 1
0
        /// <summary>
        /// 方法说明:初始化单元格
        /// 作    者:jason.tang
        /// 完成时间:2012-12-17
        /// </summary>
        /// <param name="listRows">行数</param>
        /// <param name="listColumns">列数</param>
        /// <param name="isInit">是否新建的初始化</param>
        private void InitDataGridView(List <int> listRows, List <int> listColumns, DataGridView datagridview)
        {
            int index = 0;

            //增加列
            DataGridViewTextBoxColumnEx column = new DataGridViewTextBoxColumnEx();

            listColWidth  = new List <int>();
            listRowHeight = new List <int>();

            foreach (int i in listColumns)
            {
                column       = new DataGridViewTextBoxColumnEx();
                column.Width = i;
                if (index == listColumns.Count - 1)
                {
                    column.Width = i - 3;
                }
                datagridview.Columns.Insert(index, column);
                listColWidth.Add(column.Width);
                index++;
            }

            index = 0;
            //增加行
            foreach (int i in listRows)
            {
                datagridview.Rows.Insert(index, 1);
                index++;
            }

            //行高设定
            index = 0;
            foreach (DataGridViewRow row in datagridview.Rows)
            {
                if (index < listRows.Count)
                {
                    row.Height = listRows[index];
                }
                if (index == datagridview.Rows.Count - 1)
                {
                    row.Height = row.Height - 3;
                }
                listRowHeight.Add(row.Height);
                index++;
            }


            float pageSize    = (float)_breadth;
            float size        = _breadth < 4 ? 8f - _breadth * 1.5f : 4f - _breadth;
            Font  defaultFont = this.Font;

            foreach (DataGridViewRow row in datagridview.Rows)
            {
                foreach (DataGridViewColumn col in datagridview.Columns)
                {
                    row.Cells[col.Index].Style.Font     = new Font(defaultFont.FontFamily, defaultFont.Size - size, defaultFont.Style);
                    row.Cells[col.Index].Style.WrapMode = DataGridViewTriState.True;

                    List <DataGridViewCustomerCellStyle> listCellStyle = new List <DataGridViewCustomerCellStyle>();
                    DataGridViewCustomerCellStyle        cellStyle     = new DataGridViewCustomerCellStyle();
                    cellStyle.Font     = defaultFont;
                    cellStyle.WrapMode = DataGridViewTriState.True;
                    listCellStyle.Add(cellStyle);
                    ((DataGridViewTextBoxCellEx)row.Cells[col.Index]).CustStyle = listCellStyle;
                    ((DataGridViewTextBoxCellEx)row.Cells[col.Index]).SpanCell  = new Point(-1, -1);
                }
            }
        }
Ejemplo n.º 2
0
        private void GetCard(ProcessCard _card, DataGridView datagridview)
        {
            ProcessCardBLL pcBll       = new ProcessCardBLL();
            ProcessCard    processCard = new ProcessCard();
            CardsXML       cards       = new CardsXML();
            //DataGridView datagridview = new DataGridView();
            Guid cardid = _card.ID;

            if (cardid != null)
            {
                processCard = pcBll.GetProcessCard(cardid);
                cards       = processCard.Card;
                //if (!isNew)
                //    this.Tag = id;
            }

            if (cards == null)
            {
                return;
            }

            datagridview.Tag = processCard.Name;

            int index = 0;

            //Panel pn = new Panel();
            foreach (Card card in cards.Cards)
            {
                //pn = new Panel();
                //pn.BorderStyle = BorderStyle.FixedSingle;
                //pn.Width = pnlPlanningCard.Width;
                //pn.Height = pnlPlanningCard.Height;
                //pn.AutoScroll = false;

                //pn.Name = string.Format("pnCard{0}@{1}", Guid.NewGuid().ToString(), pageCount + 1);

                if (index > 0)
                {
                    datagridview      = new DataGridView();
                    datagridview.Name = string.Format("dgvCard{0}", card.Id.ToString());
                    datagridview.RowHeadersVisible    = false;
                    datagridview.ColumnHeadersVisible = false;
                    //datagridview.Dock = DockStyle.Top;
                    datagridview.AllowUserToResizeColumns = false;
                    datagridview.AllowUserToResizeRows    = false;
                    datagridview.ReadOnly   = true;
                    datagridview.ScrollBars = ScrollBars.None;
                    datagridview.DefaultCellStyle.SelectionBackColor = datagridview.DefaultCellStyle.BackColor;
                    datagridview.DefaultCellStyle.SelectionForeColor = Color.Black;
                    datagridview.AutoGenerateColumns = false;
                    pnlPlanningCard.Controls.Add(datagridview);
                }

                index++;
                int Width   = Convert.ToInt32(card.Width);
                int Height  = Convert.ToInt32(card.Height);
                int breadth = int.Parse(card.CardRange.Replace("A", ""));

                cardWidth   = Width;
                cardHeight  = Height;
                cardBreadth = breadth;

                //if (datagridview.Name == "dgvCard")
                //{
                ResizeControls(Width, Height, breadth, datagridview);
                //}

                List <DataGridViewRow> listRow = new List <DataGridViewRow>();

                if (card.Rows == null)
                {
                    continue;
                }

                int rows    = card.Rows.Length;
                int columns = card.Rows[0].Cells.Length;

                List <int> listWidth  = new List <int>();
                List <int> listHeight = new List <int>();

                foreach (Row row in card.Rows)
                {
                    listHeight.Add(Convert.ToInt32(row.Height));
                }

                foreach (Cell cell in card.Rows[0].Cells)
                {
                    listWidth.Add(Convert.ToInt32(cell.Width));
                }

                InitDataGridView(listHeight, listWidth, datagridview);

                DataGridViewTextBoxCellEx            cellEx;
                List <DataGridViewCustomerCellStyle> listCellStyle;
                DataGridViewCustomerCellStyle        cellStyle;
                List <int> listPadding;
                try
                {
                    foreach (Row row in card.Rows)
                    {
                        foreach (Cell cell in row.Cells)
                        {
                            cellEx                   = ((DataGridViewTextBoxCellEx)datagridview.Rows[cell.PointX].Cells[cell.PointY]);
                            cellEx.CellTag           = processCard.Name;
                            cellEx.Style.Alignment   = cell.Alignment == null ? DataGridViewContentAlignment.NotSet : (DataGridViewContentAlignment)Enum.Parse(typeof(DataGridViewContentAlignment), cell.Alignment);
                            cellEx.Style.BackColor   = cell.BackGround == null || int.Parse(cell.BackGround) == 0 ? Color.Empty : Color.FromArgb(int.Parse(cell.BackGround));
                            cellEx.BottomBorderColor = cell.BottomBorderColor == null || int.Parse(cell.BottomBorderColor) == 0 ? Color.Empty : Color.FromArgb(int.Parse(cell.BottomBorderColor));
                            cellEx.BottomBorderWidth = Convert.ToInt32(cell.BottomBorderWidth);
                            cellEx.CellEditType      = (ComboBoxSourceHelper.CellType)Enum.Parse(typeof(ComboBoxSourceHelper.CellType), cell.CellType);
                            cellEx.ColumnSpan        = cell.ColSpan;
                            if (!string.IsNullOrEmpty(cellEx.CellSource) && ModuleObject != null)
                            {
                                foreach (PropertyInfo pi in ModuleObject.GetType().GetProperties())
                                {
                                    if (pi.Name.ToLower() == cellEx.CellSource.ToLower())
                                    {
                                        cellEx.Value = pi.GetValue(ModuleObject, new object[] { });
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                cellEx.Value = cell.Content;
                            }
                            string[] spanCell = cell.SpanCell.Split(new char[] { ',' });
                            cellEx.SpanCell = new Point(int.Parse(spanCell[0]), int.Parse(spanCell[1]));

                            #region 处理CellStyle

                            listCellStyle = new List <DataGridViewCustomerCellStyle>();
                            listPadding   = new List <int>();
                            if (cellEx.CustStyle == null)
                            {
                                cellStyle           = new DataGridViewCustomerCellStyle();
                                cellStyle.Alignment = cell.Alignment == null ? DataGridViewContentAlignment.NotSet : (DataGridViewContentAlignment)Enum.Parse(typeof(DataGridViewContentAlignment), cell.Alignment);
                                cellStyle.BackColor = cell.BackGround == null || int.Parse(cell.BackGround) == 0 ? Color.Empty : Color.FromArgb(int.Parse(cell.BackGround));
                                if (cell.FontFamily == null || cell.ZoomFontSize == null || cell.FontStyle == null)
                                {
                                    cellStyle.Font = preFont;
                                }
                                else
                                {
                                    cellStyle.Font = new Font(cell.FontFamily, float.Parse(cell.ZoomFontSize), (FontStyle)Enum.Parse(typeof(FontStyle), cell.FontStyle));
                                }

                                cellStyle.ForeColor = cell.ForeColor == null ? preColor : Color.FromArgb(int.Parse(cell.ForeColor));

                                preFont  = cellStyle.Font;
                                preColor = cellStyle.ForeColor;

                                cellStyle.WrapMode = (DataGridViewTriState)Enum.Parse(typeof(DataGridViewTriState), cell.WrapMode.ToString());
                                if (cell.Padding == null)
                                {
                                    listPadding.Add(0);
                                    listPadding.Add(0);
                                    listPadding.Add(0);
                                    listPadding.Add(0);
                                }
                                else
                                {
                                    string[] padding = cell.Padding.Split(new char[] { ',' });
                                    foreach (string pad in padding)
                                    {
                                        listPadding.Add(int.Parse(pad));
                                    }
                                }
                                cellStyle.Padding = new System.Windows.Forms.Padding(listPadding[0], listPadding[1], listPadding[2], listPadding[3]);
                                listCellStyle.Add(cellStyle);
                                cellEx.CustStyle = listCellStyle;
                            }

                            #endregion

                            //cell.ContentType;
                            //cell.DataSrc;
                            //cell.DetailCells;

                            if (cell.FontFamily == null || cell.FontSize == null || cell.FontStyle == null)
                            {
                                cellEx.Style.Font = preFont;
                            }
                            else
                            {
                                cellEx.Style.Font = new Font(cell.FontFamily, float.Parse(cell.FontSize), (FontStyle)Enum.Parse(typeof(FontStyle), cell.FontStyle));
                            }

                            cellEx.Style.ForeColor = cell.ForeColor == null ? preColor : Color.FromArgb(int.Parse(cell.ForeColor));

                            preFont  = cellEx.Style.Font;
                            preColor = cellEx.Style.ForeColor;

                            cellEx.LeftBorderColor = Color.FromArgb(int.Parse(cell.LeftBorderColor));
                            cellEx.LeftBorderWidth = Convert.ToInt32(cell.LeftBorderWidth);
                            //cell.Name;
                            cellEx.RightBorderColor = Color.FromArgb(int.Parse(cell.RightBorderColor));
                            cellEx.RightBorderWidth = Convert.ToInt32(cell.RightBorderWidth);
                            cellEx.RowSpan          = cell.RowSpan;
                            cellEx.TopBorderColor   = Color.FromArgb(int.Parse(cell.TopBorderColor));
                            cellEx.TopBorderWidth   = Convert.ToInt32(cell.TopBorderWidth);

                            cellEx.LeftTopRightBottom = cell.LeftTopRightBottom;
                            cellEx.LeftBottomRightTop = cell.LeftBottomRightTop;
                            cellEx.CellContent        = string.IsNullOrEmpty(cell.ContentType) ? (ComboBoxSourceHelper.CellContent)Enum.Parse(typeof(ComboBoxSourceHelper.CellContent), "0") :
                                                        (ComboBoxSourceHelper.CellContent)Enum.Parse(typeof(ComboBoxSourceHelper.CellContent), cell.ContentType);

                            cellEx.Style.WrapMode = (DataGridViewTriState)Enum.Parse(typeof(DataGridViewTriState), cell.WrapMode.ToString());
                            cellEx.CellSource     = cell.CellSource;

                            string parentName = datagridview.Parent.Name;
                            //明细框单元格
                            if (cellEx.CellEditType == (ComboBoxSourceHelper.CellType)Enum.Parse(typeof(ComboBoxSourceHelper.CellType), "2"))
                            {
                                Rectangle rect = datagridview.GetCellDisplayRectangle(cellEx.ColumnIndex, cellEx.RowIndex, false);
                                int       top  = rect.Y - 1;
                                int       left = rect.X - 1;

                                List <DetailGridViewTextBoxColumn> dicColumns = new List <DetailGridViewTextBoxColumn>();
                                object objDetailProperty = cell.DetailCells;
                                //明细框
                                AddDetailGridView(top, left, objDetailProperty, cellEx, datagridview, dicColumns);
                                cellEx.DetailProperty = dicColumns;
                            }
                            else if (cellEx.CellEditType == (ComboBoxSourceHelper.CellType)Enum.Parse(typeof(ComboBoxSourceHelper.CellType), "3"))  //页码
                            {
                                cellEx.Value = 1;
                            }
                            else if (cellEx.CellEditType == (ComboBoxSourceHelper.CellType)Enum.Parse(typeof(ComboBoxSourceHelper.CellType), "4"))  //页数
                            {
                                cellEx.Value = 1;
                            }
                        }
                    }

                    //读取图片
                    if (card.ImageObjects != null && card.ImageObjects.Length > 0)
                    {
                        foreach (ImageObject image in card.ImageObjects)
                        {
                            LoadImage(image, datagridview);
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("读取模板文件失败,无法新建卡片", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 方法说明:根据模板ID打开模板
        /// 作    者:jason.tang
        /// 完成时间:2013-01-21
        /// </summary>
        /// <param name="moduleId">模板ID</param>
        /// <param name="dgv">操作的DataGrid</param>
        private void GetTemplate(ProcessCardModule module, DataGridView dgv)
        {
            ProcessCardModuleBLL pcmDll     = new ProcessCardModuleBLL();
            CardsXML             cardmodule = new CardsXML();

            Model.ProcessCardModule pcm = new ProcessCardModule();

            string moduleId = module.Id.ToString();

            try
            {
                Guid gid = new Guid(moduleId);
                pcm        = pcmDll.GetProcessCardModule(gid);
                cardmodule = pcm.CardModule;
            }
            catch
            {
                return;
            }

            Card card = cardmodule.Cards.FirstOrDefault <Card>();

            int Width  = Convert.ToInt32(card.Width);
            int Height = Convert.ToInt32(card.Height);

            _breadth = int.Parse(card.CardRange.Replace("A", ""));
            ResizeInitGridView(Width, Height, dgv);

            List <DataGridViewRow> listRow = new List <DataGridViewRow>();


            if (card.Rows == null || card.Rows.Length == 0)
            {
                return;
            }

            int rows    = card.Rows.Length;
            int columns = card.Rows[0].Cells.Length;

            dgv.Rows.Clear();
            dgv.Columns.Clear();

            List <int> listWidth  = new List <int>();
            List <int> listHeight = new List <int>();

            foreach (Row row in card.Rows)
            {
                listHeight.Add(Convert.ToInt32(row.Height));
            }

            foreach (Cell cell in card.Rows[0].Cells)
            {
                listWidth.Add(Convert.ToInt32(cell.Width));
            }

            InitDataGridView(listHeight, listWidth, dgv);
            DataGridViewTextBoxCellEx            cellEx;
            List <DataGridViewCustomerCellStyle> listCellStyle;
            DataGridViewCustomerCellStyle        cellStyle;
            List <int> listPadding;

            try
            {
                foreach (Row row in card.Rows)
                {
                    foreach (Cell cell in row.Cells)
                    {
                        cellEx = ((DataGridViewTextBoxCellEx)dgv.Rows[cell.PointX].Cells[cell.PointY]);
                        cellEx.Style.Alignment   = (DataGridViewContentAlignment)Enum.Parse(typeof(DataGridViewContentAlignment), cell.Alignment);
                        cellEx.Style.BackColor   = int.Parse(cell.BackGround) == 0 ? Color.White : Color.FromArgb(int.Parse(cell.BackGround));
                        cellEx.BottomBorderColor = Color.FromArgb(int.Parse(cell.BottomBorderColor));
                        cellEx.BottomBorderWidth = Convert.ToInt32(cell.BottomBorderWidth);
                        cellEx.CellEditType      = (ComboBoxSourceHelper.CellType)Enum.Parse(typeof(ComboBoxSourceHelper.CellType), cell.CellType);
                        cellEx.ColumnSpan        = cell.ColSpan;
                        cellEx.Value             = cell.Content;
                        string[] spanCell = cell.SpanCell.Split(new char[] { ',' });
                        cellEx.SpanCell = new Point(int.Parse(spanCell[0]), int.Parse(spanCell[1]));

                        #region 处理CellStyle

                        listCellStyle = new List <DataGridViewCustomerCellStyle>();
                        listPadding   = new List <int>();
                        if (cellEx.CustStyle == null)
                        {
                            cellStyle           = new DataGridViewCustomerCellStyle();
                            cellStyle.Alignment = (DataGridViewContentAlignment)Enum.Parse(typeof(DataGridViewContentAlignment), cell.Alignment);
                            cellStyle.BackColor = int.Parse(cell.BackGround) == 0 ? Color.White : Color.FromArgb(int.Parse(cell.BackGround));
                            cellStyle.Font      = new Font(cell.FontFamily, float.Parse(cell.ZoomFontSize), (FontStyle)Enum.Parse(typeof(FontStyle), cell.FontStyle));
                            cellStyle.ForeColor = Color.FromArgb(int.Parse(cell.ForeColor));
                            cellStyle.WrapMode  = (DataGridViewTriState)Enum.Parse(typeof(DataGridViewTriState), cell.WrapMode.ToString());

                            string[] padding = cell.Padding.Split(new char[] { ',' });
                            foreach (string pad in padding)
                            {
                                listPadding.Add(int.Parse(pad));
                            }
                            cellStyle.Padding = new System.Windows.Forms.Padding(listPadding[0], listPadding[1], listPadding[2], listPadding[3]);
                            listCellStyle.Add(cellStyle);
                            cellEx.CustStyle = listCellStyle;
                        }

                        #endregion

                        //cell.ContentType;
                        //cell.DataSrc;
                        //cell.DetailCells;

                        cellEx.Style.Font      = new Font(cell.FontFamily, float.Parse(cell.FontSize), (FontStyle)Enum.Parse(typeof(FontStyle), cell.FontStyle));
                        cellEx.Style.ForeColor = Color.FromArgb(int.Parse(cell.ForeColor));
                        cellEx.LeftBorderColor = Color.FromArgb(int.Parse(cell.LeftBorderColor));
                        cellEx.LeftBorderWidth = Convert.ToInt32(cell.LeftBorderWidth);
                        //cell.Name;
                        cellEx.RightBorderColor = Color.FromArgb(int.Parse(cell.RightBorderColor));
                        cellEx.RightBorderWidth = Convert.ToInt32(cell.RightBorderWidth);
                        cellEx.RowSpan          = cell.RowSpan;
                        cellEx.TopBorderColor   = Color.FromArgb(int.Parse(cell.TopBorderColor));
                        cellEx.TopBorderWidth   = Convert.ToInt32(cell.TopBorderWidth);

                        cellEx.LeftTopRightBottom = cell.LeftTopRightBottom;
                        cellEx.LeftBottomRightTop = cell.LeftBottomRightTop;
                        cellEx.CellContent        = string.IsNullOrEmpty(cell.ContentType) ? (ComboBoxSourceHelper.CellContent)Enum.Parse(typeof(ComboBoxSourceHelper.CellContent), "0") :
                                                    (ComboBoxSourceHelper.CellContent)Enum.Parse(typeof(ComboBoxSourceHelper.CellContent), cell.ContentType);

                        cellEx.Style.WrapMode = (DataGridViewTriState)Enum.Parse(typeof(DataGridViewTriState), cell.WrapMode.ToString());
                        cellEx.CellSource     = cell.CellSource;

                        //明细框单元格
                        if (cellEx.CellEditType == (ComboBoxSourceHelper.CellType)Enum.Parse(typeof(ComboBoxSourceHelper.CellType), "2"))
                        {
                            Rectangle rect = dgv.GetCellDisplayRectangle(cellEx.ColumnIndex, cellEx.RowIndex, false);
                            int       top  = rect.Y - 1;
                            int       left = rect.X - 1;

                            List <DetailGridViewTextBoxColumn> dicColumns = new List <DetailGridViewTextBoxColumn>();
                            object objDetailProperty = cell.DetailCells;
                            //明细框
                            AddDetailGridView(top, left, objDetailProperty, dicColumns, dgv, cellEx);
                            cellEx.DetailProperty = dicColumns;
                        }
                    }
                }
                //读取图片
                if (card.ImageObjects != null && card.ImageObjects.Length > 0)
                {
                    foreach (ImageObject image in card.ImageObjects)
                    {
                        LoadImage(image, dgv);
                    }
                }
            }
            catch
            {
                dgv.Rows.Clear();
                dgv.Columns.Clear();
                MessageBox.Show("模板文件打开失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            //dgvCardModule.Refresh();
        }