/// <summary> /// get card module XML by id /// </summary> /// <param name="id"></param> /// <returns></returns> public CardsXML GetCardModule(Guid id) { string cardmodulexml = string.Empty; CardsXML cardModule = null; try { cardmodulexml = ProcessCardModuleDAL.GetCardModuleXML(id); cardModule = SerializeHelper .DeserializeXMLChar <CardsXML>(cardmodulexml); } catch (Exception) { throw; } return(cardModule); }
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; } } }
/// <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(); }