using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DEVGIS.Lib.Common;
using DEVGIS.Common;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace DEVGIS.Controls
{
public partial class MyDataGridView : DataGridView
{
private string filename;
/// <summary>
/// 保存的文件名
/// </summary>
public string FileName
{
get { return filename; }
set { this.filename = value; }
}
public MyDataGridView()
{
InitializeComponent();
InitItems();
}
public MyDataGridView(IContainer container)
{
container.Add(this);
InitializeComponent();
InitItems();
}
private void InitItems()
{
this.BackgroundColor = Color.White;
this.EnableHeadersVisualStyles = false;
this.ColumnHeadersDefaultCellStyle.BackColor =Color.FromArgb(191,219,255);
this.RowHeadersDefaultCellStyle.BackColor = Color.FromArgb(191, 219, 255);
this.AllowUserToResizeRows = false;
ContextMenuStrip cm = new ContextMenuStrip();
cm.Items.Add("导出", null, mi_Click);
this.ContextMenuStrip = cm;
}
void mi_Click(object sender, EventArgs e)
{
SaveFileDialog sa = new SaveFileDialog();
sa.Filter = "Excel(2007)|*.xlsx";
sa.FileName = FileName + "(" + DateTime.Now.ToString("yyyyMMddHHmmss") + ")";
if (sa.ShowDialog() == DialogResult.OK)
{
DataExport de = new DataExport();
string path = sa.FileName;
bool b = de.DataGridviewShowToExcel(path, this);
if (this.Rows.Count > 0)
{
if (b)//为true,导出成功
{
PublicDim.ShowInfoMessage("信息导出成功!");
}
else
{
PublicDim.ShowInfoMessage("信息导出失败!");
}
}
else
{
PublicDim.ShowInfoMessage("没有可导出的数据!");
}
}
}
protected override void OnRowPostPaint(DataGridViewRowPostPaintEventArgs e)
{
base.OnRowPostPaint(e);
if (this.RowHeadersVisible)
{
SetRowNumber(this, e);
}
}
private void SetRowNumber(DataGridView dgvPackList, DataGridViewRowPostPaintEventArgs e)
{
System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(e.RowBounds.Location.X,
e.RowBounds.Location.Y,
dgvPackList.RowHeadersWidth - 4,
e.RowBounds.Height);
TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
dgvPackList.RowHeadersDefaultCellStyle.Font,
rectangle,
dgvPackList.RowHeadersDefaultCellStyle.ForeColor,
TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
}
protected override void OnCellPainting(DataGridViewCellPaintingEventArgs e)
{
base.OnCellPainting(e);
if (e.ColumnIndex == -1 && e.RowIndex == -1)
{
bool mouseOver = e.CellBounds.Contains(PointToClient(Cursor.Position));
LinearGradientBrush brush = new LinearGradientBrush(
e.CellBounds,
mouseOver ? RowHeadersDefaultCellStyle.BackColor : RowHeadersDefaultCellStyle.BackColor,
RowHeadersDefaultCellStyle.BackColor,
LinearGradientMode.Vertical);
using (brush)
{
e.Graphics.FillRectangle(brush, e.CellBounds);
Rectangle border = e.CellBounds;
// border.Width -= 1;
e.Graphics.DrawRectangle(Pens.Gray, border);
}
e.PaintContent(e.CellBounds);
e.Handled = true;
}
else if (e.RowIndex == -1)
{
//标题行
bool mouseOver = e.CellBounds.Contains(PointToClient(Cursor.Position));
LinearGradientBrush brush = new LinearGradientBrush(
e.CellBounds,
mouseOver ? RowHeadersDefaultCellStyle.BackColor : RowHeadersDefaultCellStyle.BackColor,
RowHeadersDefaultCellStyle.BackColor,
LinearGradientMode.Vertical);
using (brush)
{
e.Graphics.FillRectangle(brush, e.CellBounds);
Rectangle border = e.CellBounds;
// border.Width -= 1;
e.Graphics.DrawRectangle(Pens.Gray, border);
}
e.PaintContent(e.CellBounds);
e.Handled = true;
}
else if (e.ColumnIndex == -1)
{
//标题列
bool mouseOver = e.CellBounds.Contains(PointToClient(Cursor.Position));
LinearGradientBrush brush = new LinearGradientBrush(
e.CellBounds,
mouseOver ? RowHeadersDefaultCellStyle.BackColor : RowHeadersDefaultCellStyle.BackColor,
RowHeadersDefaultCellStyle.BackColor,
LinearGradientMode.Vertical);
using (brush)
{
e.Graphics.FillRectangle(brush, e.CellBounds);
Rectangle border = e.CellBounds;
// border.Width -= 1;
e.Graphics.DrawRectangle(Pens.Gray, border);
}
e.PaintContent(e.CellBounds);
e.Handled = true;
}
}
}
}
专业从事基于C#,WinForm ,WPF,Silverlight,WCF以及MS Sql Server 2000/2005/2008/2012 Oracle 9i/10g/11g数据库系统的ERP,CRM,企业进销存等各种数据库管理系统开发。Asp.net,Asp.net mvc,Webservice,WCF, Webapi等服务程序开发。
基于Oracle MySQL MSSql postgresql各种数据库的管理系统数据同步服务。以及基于MapXtreme, Arcgis Engine ,以及基于Arcgis for silverlight/Javascript的WebGIS等相关的GIS系统二次开发。基于Windows 10 Mobile的移动端开发方案。针对各种系统的二次开发维护,并提供相关开发的技术性支持,如程序BUG解决,应用系统架构,技术难题攻克等相关技术服务。
联系方式: QQ :80163278(devgis) 邮箱:devgis@qq.com