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> /// 方法说明:新建卡片 /// 作 者:jason.tang /// 完成时间:2013-03-05 /// </summary> private void NewCard() { using (CardModuleChooseFrm chooseFrm = new CardModuleChooseFrm()) { if (chooseFrm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { ProcessCardFrm frm = new ProcessCardFrm(); frm.ProcessFolderId = chooseFrm.ProcessFolderId; if (tcDesignView.SelectedTab == tbMaterial) { frm.Name = string.Format("ProcessCardFrm-{0}-NAVG", Guid.NewGuid().ToString()); } else { frm.Name = string.Format("ProcessCardFrm-{0}-NAVP", Guid.NewGuid().ToString()); } if (!string.IsNullOrEmpty(chooseFrm.ProcessCardId)) { //frm.TabText = chooseFrm.ProcessCardName; //MainFrm.mainFrm.OpenModule(frm); //bool result = frm.OpenCard(null, chooseFrm.ProcessCardId, true); //if (!result) //{ // MainFrm.mainFrm.CloseModule(frm); //} //添加节点 ProcessCardBLL bll = new ProcessCardBLL(); ProcessCard card = bll.GetProcessCard(new Guid(chooseFrm.ProcessCardId)); string baseid = AddNodeInMaterial(card, frm.ProcessFolderId); if (string.IsNullOrEmpty(baseid)) { MessageBox.Show("该物料下已包含相同的卡片", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } MaterialCardRelation materialCardRelation = new MaterialCardRelation(); materialCardRelation.MaterialCardRelationId = Guid.NewGuid(); materialCardRelation.MaterialId = new Guid(baseid); materialCardRelation.ProcessCardId = card.ID; if (tcDesignView.SelectedTab == tbMaterial) { materialCardRelation.Type = 1; } else { materialCardRelation.Type = 2; } Kingdee.CAPP.BLL.MaterialCardRelationBLL.AddMaterialCardRelationData(materialCardRelation); return; } #region 设置新增卡片Tab的TabText及Name int tag = 1; int index = 1; List <int> listIndex = new List <int>(); foreach (DockContent form in this.MdiChildren) { if (form.Name.StartsWith("ProcessCardFrm") && form.TabText.StartsWith(chooseFrm.ModuleName)) { tag = int.Parse(form.TabText.Substring(form.TabText.IndexOf("-") + 1)); listIndex.Add(tag); } } listIndex.Sort(); foreach (var i in listIndex) { if (i > 1 && index == 1) { index = 1; break; } if (index > 1) { if (i - listIndex[index - 2] > 1) { index = listIndex[index - 2] + 1; break; } } index++; } frm.TabText = string.Format("{0}-{1}", chooseFrm.ModuleName, index); #endregion frm.ModuleId = chooseFrm.ModuleId; frm.ModuleName = chooseFrm.ModuleName; if (tcDesignView.SelectedTab == tbMaterial) { frm.ModuleObject = tvMaterialDesign.SelectedNode.Tag; frm.PBomID = string.Empty; } else { frm.ModuleObject = tvMaterialPBom.SelectedNode.Tag; frm.PBomID = tvMaterialPBom.SelectedNode.Name; } MainFrm.mainFrm.OpenModule(frm); } } }