Exemplo n.º 1
0
 private void dgv_DataModelTemplate_SelectionChanged(object sender, EventArgs e)
 {
     if (dgv_DataModelTemplate.SelectedRows.Count == 0)
     {
         foreach (DataGridViewRow row in dgv_DataModelTemplate.Rows)
         {
             row.DefaultCellStyle.BackColor = Color.White;
         }
     }
     else
     {
         foreach (DataGridViewRow row in dgv_DataModelTemplate.Rows)
         {
             if (row != dgv_DataModelTemplate.SelectedRows[0])
             {
                 row.DefaultCellStyle.BackColor = Color.White;
             }
             else
             {
                 row.DefaultCellStyle.BackColor = Color.LightSeaGreen;
                 DataBlockTemplateModel dbtm = row.DataBoundItem as DataBlockTemplateModel;
                 uc_CurrentDataModelView.AddDataControls(dbtm);
                 nud_PaddingLeft.Value   = dbtm.PaddingLeft;
                 nud_PaddingTop.Value    = dbtm.PaddingTop;
                 nud_PaddingRight.Value  = dbtm.PaddingRight;
                 nud_PaddingBottom.Value = dbtm.PaddingBottom;
                 cb_FontFamily.Text      = dbtm.FontFamilyName;
                 nud_FontSize.Value      = (decimal)dbtm.FontSize;
                 nud_Distance.Value      = dbtm.Distance;
                 nud_ColumnNum.Value     = dbtm.ColumnNum;
                 nud_LineWidth.Value     = dbtm.LineWidth;
             }
         }
     }
 }
Exemplo n.º 2
0
        private void btn_Create_Click(object sender, EventArgs e)
        {
            if (new Fm_AddNewDataBlockTemplate().ShowDialog() == DialogResult.Cancel)
            {
                return;
            }
            uc_CurrentDataModelView.Edit = false;
            btn_Edit.Text = "编辑";
            DataBlockTemplateModel newModel = DataBlockTemplateModel.CreateNewInstance(Fm_AddNewDataBlockTemplate.ModelName,
                                                                                       cb_FontFamily.SelectedValue.ToString(), (float)nud_FontSize.Value,
                                                                                       pageWidth, (int)nud_ColumnNum.Value, (int)nud_Distance.Value, (int)nud_LineWidth.Value,
                                                                                       (int)nud_PaddingLeft.Value, (int)nud_PaddingTop.Value, (int)nud_PaddingRight.Value, (int)nud_PaddingBottom.Value);

            PrintDatas.dataBlockTMList.Add(newModel);
            dataBlockModelBList.Add(newModel);
            foreach (DataGridViewRow row in dgv_DataModelTemplate.Rows)
            {
                DataBlockTemplateModel dbtm = row.DataBoundItem as DataBlockTemplateModel;
                if (dbtm.ModelID == newModel.ModelID)
                {
                    row.Selected = true;
                    break;
                }
            }
            uc_CurrentDataModelView.AddDataControls(newModel);
        }
Exemplo n.º 3
0
        public void AddDataControls(DataBlockTemplateModel templateModel)
        {
            ResetArea();
            int width = this.pn_Area.Width / templateModel.ColumnNum;

            for (int i = 0; i < templateModel.ColumnNum; i++)
            {
                DataBlockModel newDataBlockModel = PrintDatas.dataBlockMList.Find(m => m.TemplateModelID == templateModel.ModelID &&
                                                                                  m.Index == i);
                DataBlockControl dc = new DataBlockControl(1, newDataBlockModel, true);
                dc.Dock = DockStyle.Left;
                dc.DataSelectedEvent += Dc_DataSelectedEvent;
                dc.DataKeyDownEvent  += Dc_DataKeyDownEvent;
                currentDBList.Add(dc);
                this.pn_Area.Controls.Add(dc);
                dc.BringToFront();
            }
            currentDBList[currentDBList.Count - 1].Dock = DockStyle.Fill;
            foreach (var dc in currentDBList)
            {
                dc.FontFamilyName = templateModel.FontFamilyName;
                dc.FontSize       = templateModel.FontSize;
                dc.Distance       = templateModel.Distance;
                dc.LineWidth      = templateModel.LineWidth;
            }
        }
Exemplo n.º 4
0
        private void dgv_DataModelTemplate_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
        {
            DataBlockTemplateModel currentModel = e.Row.DataBoundItem as DataBlockTemplateModel;

            uc_CurrentDataModelView.DeleteAllBlockControls(currentModel.ModelID);
            PrintDatas.dataBlockMList = PrintDatas.dataBlockMList.Where(d => d.TemplateModelID != currentModel.ModelID).ToList();
            PrintDatas.dataBlockTMList.Remove(currentModel);
        }
Exemplo n.º 5
0
        private void Tsi_Click(object sender, EventArgs e)
        {
            if (fields.Count(f => f.CurrentField.FieldType == FieldType.DataBlock) > 0)
            {
                MessageBox.Show("一个模板只能有一个数据块!");
                return;
            }
            ToolStripItem          tsi = sender as ToolStripItem;
            Point                  p   = this.PointToClient(new Point(cm_FieldManager.Left, cm_FieldManager.Top));
            string                 dataBlockTemplateName = tsi.Text;
            DataBlockTemplateModel dbtm = PrintDatas.dataBlockTMList.Find(t => t.ModelName == dataBlockTemplateName &&
                                                                          t.PageWidth == PaintManager.CurrentView.FixedPageSize.Width);
            DrawingControlBase dcb = PaintManager.AddANewControl(FieldModel.CreateANewDataBlock(
                                                                     PaintManager.CurrentDataManager.ModelID, dbtm.ModelName, dbtm.FontFamilyName,
                                                                     (decimal)dbtm.FontSize, PaintManager.CurrentView.FixedPageSize.Width, 60));

            if (dcb != null)
            {
                dcb.FixedLocationInView = p;
            }
        }
Exemplo n.º 6
0
        public void AddDataControls(DataBlockTemplateModel templateModel)
        {
            CurrentTemplateModel = templateModel;
            RemoveAllDataBlockControls();
            PaddingLeft   = templateModel.PaddingLeft;
            PaddingTop    = templateModel.PaddingTop;
            PaddingRight  = templateModel.PaddingRight;
            PaddingBottom = templateModel.PaddingBottom;
            ColumnNum     = templateModel.ColumnNum;
            PageWidth     = templateModel.PageWidth;
            int width = this.pn_Area.Width / ColumnNum;

            for (int i = 0; i < ColumnNum; i++)
            {
                DataBlockModel newDataBlockModel = PrintDatas.dataBlockMList.Find(m => m.TemplateModelID == templateModel.ModelID &&
                                                                                  m.Index == i);
                if (newDataBlockModel == null)
                {
                    newDataBlockModel = DataBlockModel.CreateNewInstance();
                    PrintDatas.dataBlockMList.Add(newDataBlockModel);
                    newDataBlockModel.ColumnWidth     = (int)(width / Percentage);
                    newDataBlockModel.Index           = i;
                    newDataBlockModel.TemplateModelID = templateModel.ModelID;
                }
                DataBlockControl dc = new DataBlockControl(Percentage, newDataBlockModel, false);
                dc.Dock = DockStyle.Left;
                dc.DataSelectedEvent += Dc_DataSelectedEvent;
                dataControls.Add(dc);
                this.pn_Area.Controls.Add(dc);
                dc.BringToFront();
            }
            dataControls[dataControls.Count - 1].Dock = DockStyle.Fill;
            FontFamilyName = templateModel.FontFamilyName;
            FontSize       = templateModel.FontSize;
            Distance       = templateModel.Distance;
            LineWidth      = templateModel.LineWidth;
        }
Exemplo n.º 7
0
        public static int PrintDataBlock(FieldModel fm, List <List <DataBlockMapping> > dbmappingListList, PrintPageEventArgs e)
        {
            //判断数据块模板是否存在
            DataBlockTemplateModel dbtm = DataManager.DataBlockTemplateM.Find(t => t.ModelName == fm.FieldName);

            if (dbtm == null)
            {
                throw new Exception("数据块模板丢失");
            }
            //获取行高度
            Font  printFont  = new Font(new FontFamily(dbtm.FontFamilyName), dbtm.FontSize);
            float fontHeight = e.Graphics.MeasureString("高", printFont).Height;
            //获取该模板对应的数据块模板
            List <DataBlockModel> dbmList = DataManager.DataBlockM.Where(m => m.TemplateModelID == dbtm.ModelID).
                                            OrderBy(m => m.Index).ToList();
            //每一行的打印坐标X(左缩进+数据块位置(一般为0))
            int locationX = dbtm.PaddingLeft + fm.LocationX;
            //打印的Y坐标(数据块坐标+上缩进+行高+行间距)
            int locationY = dbtm.PaddingTop + (int)fontHeight + dbtm.Distance;
            //分割线的宽度(减掉左右缩进)
            int lineWidth = fm.TextAreaWidth - dbtm.PaddingLeft - dbtm.PaddingRight;

            //打印表头列名
            if (!CurrentPrintPage.DataBlockContinue)
            {
                foreach (var dbm in dbmList)
                {
                    e.Graphics.DrawString(dbm.ColumnName, printFont,
                                          Brushes.Black, new PointF(locationX, fm.LocationY + dbtm.PaddingTop));
                    locationX += dbm.ColumnWidth;
                }
                locationY = fm.LocationY + dbtm.PaddingTop + (int)fontHeight + dbtm.Distance;
                //画分割线(上)
                PrintLine(new FieldModel()
                {
                    LocationX      = dbtm.PaddingLeft + fm.LocationX,
                    LocationY      = locationY,
                    TextAreaWidth  = lineWidth,
                    TextAreaHeight = dbtm.LineWidth
                }, 0, DashStyle.Solid, e);
                locationY += dbtm.LineWidth;
            }

            //打印数据行,要处理分页问题
            locationY += dbtm.Distance * 2;
            for (int i = 0; i < dbmappingListList.Count;)
            {
                var dbmappingList = dbmappingListList[i];
                //判断纸张是否支持下一行打印,为了简便,当剩余高度不足两个行高+两个行间距+分割线宽度+5(弹性距离),则换页
                if ((fontHeight + dbtm.Distance) * 2 + dbtm.LineWidth + 5 >
                    CommonFunction.Millimeter2Pix(CurrentPrintPage.PrintEntity.PageModel.Height) - locationY)
                {
                    //换页处理
                    CurrentPrintPage.DataBlockContinue = e.HasMorePages = true;
                    return(0);
                }
                //打印下一行
                bool doubleHeight = false;
                locationX = dbtm.PaddingLeft + fm.LocationX;
                foreach (var dbm in dbmList)
                {
                    DataBlockMapping dbmapping = dbmappingList.Find(m => m.PrintName == dbm.ColumnName);
                    if (dbmapping == null)
                    {
                        continue;
                    }
                    if (e.Graphics.MeasureString(dbmapping.DataValue, printFont).Width > dbm.ColumnWidth)
                    {
                        e.Graphics.DrawString(dbmapping.DataValue, printFont,
                                              Brushes.Black, new RectangleF(locationX, locationY, dbm.ColumnWidth, fontHeight * 2));
                        doubleHeight = true;
                    }
                    else
                    {
                        e.Graphics.DrawString(dbmapping.DataValue, printFont,
                                              Brushes.Black, new PointF(locationX, locationY));
                    }
                    locationX += dbm.ColumnWidth;
                }
                //打印完之后删数据
                dbmappingListList.Remove(dbmappingList);

                locationY += (doubleHeight ? (int)(fontHeight * 2) : (int)fontHeight) + dbtm.Distance;
                if (dbmappingListList.IndexOf(dbmappingList) < dbmappingListList.Count - 1)
                {
                    //画分割线(数据)
                    PrintLine(new FieldModel()
                    {
                        LocationX      = dbtm.PaddingLeft + fm.LocationX,
                        LocationY      = locationY,
                        TextAreaWidth  = lineWidth,
                        TextAreaHeight = 1
                    }, 0, DashStyle.Dot, e);
                    locationY += dbtm.Distance + 1;
                }
            }

            //画分割线(下)
            PrintLine(new FieldModel()
            {
                LocationX      = dbtm.PaddingLeft + fm.LocationX,
                LocationY      = locationY,
                TextAreaWidth  = lineWidth,
                TextAreaHeight = dbtm.LineWidth
            }, 0, DashStyle.Solid, e);
            locationY += dbtm.LineWidth;
            int adjustHeight = locationY - fm.TextAreaHeight - fm.LocationY - dbtm.PaddingTop;

            CurrentPrintPage.DataBlockContinue = e.HasMorePages = false;
            CurrentPrintPage.PrintEntity.Fields.Remove(fm);
            return(adjustHeight);
        }