国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

關于datagrid的打印

2024-07-21 02:20:26
字體:
來源:轉載
供稿:網友
using system;
using system.windows.forms;
using system.drawing;
using system.drawing.printing;
using system.data;
using system.collections;

namespace sx_mdi
{
/// <summary>
/// summary description for datagridprinter.
/// </summary>
public class datagridprinter
{

private printdocument theprintdocument;
private datatable thetable;
private datagrid thedatagrid;

public int rowcount = 0; // current count of rows;
private const int kverticalcellleeway = 10;
public int pagenumber = 1;

int pagewidth;
int pageheight;
int topmargin;
int bottommargin;

public string receieve_amount; //收貨數量
public string receieve_moneys; //收貨金額
public string send_amount; //發貨數量
public string send_moneys; //發貨金額


public datagridprinter(datagrid agrid, printdocument aprintdocument, datatable atable)
{
//
// todo: add constructor logic here
//
thedatagrid = agrid;
theprintdocument = aprintdocument;
thetable = atable;


//得到打印參數
pagewidth = theprintdocument.defaultpagesettings.papersize.width;
pageheight = theprintdocument.defaultpagesettings.papersize.height;
topmargin = theprintdocument.defaultpagesettings.margins.top;
bottommargin = theprintdocument.defaultpagesettings.margins.bottom;

}

public void getvalues(string sh_amount,string sh_moneys,string fh_amount,string fh_moneys)
{
//
// todo: add constructor logic here
//
receieve_amount = sh_amount;
receieve_moneys = sh_moneys;
send_amount = fh_amount;
send_moneys = fh_moneys;


}

public void drawheader(graphics g)
{
solidbrush forebrush = new solidbrush(thedatagrid.headerforecolor);
solidbrush backbrush = new solidbrush(thedatagrid.headerbackcolor);
pen thelinepen = new pen(thedatagrid.gridlinecolor, 1);
stringformat cellformat = new stringformat();
cellformat.trimming = stringtrimming.ellipsischaracter;
cellformat.formatflags = stringformatflags.nowrap | stringformatflags.linelimit;


g.drawstring("收發對比表",new font("arial", 20, fontstyle.bold), new solidbrush(thedatagrid.headerbackcolor), pagewidth/2 , topmargin, new stringformat());

int columnwidth = pagewidth/thetable.columns.count - 20;


int initialrowcount = rowcount;

// draw the table header
float startxposition = thedatagrid.location.x;
rectanglef nextcellbounds = new rectanglef(0,0, 0, 0);

rectanglef headerbounds = new rectanglef(0, 0, 0, 0);

headerbounds.x = thedatagrid.location.x;
headerbounds.y = thedatagrid.location.y + topmargin + (rowcount - initialrowcount) * (thedatagrid.font.sizeinpoints + kverticalcellleeway);
headerbounds.height = thedatagrid.font.sizeinpoints + kverticalcellleeway;
headerbounds.width = pagewidth;

g.fillrectangle(backbrush, headerbounds);

for (int k = 0; k < thetable.columns.count; k++)
{

string nextcolumn = thetable.columns[k].tostring();
switch(nextcolumn)
{
case "code":
nextcolumn ="收貨單號";
break;
case "bp_code":
nextcolumn = "衣服編號";
break;
case "bp_name":
nextcolumn = "衣服名稱";
break;
case "receieve_prices":
nextcolumn = "收貨價格";
break;
case "receieve_amounts":
nextcolumn = "收貨數量";
break;
case "receieve_moneys":
nextcolumn = "收貨金額";
break;
case "send_amunts":
nextcolumn = "發貨數量";
break;
case "send_prices":
nextcolumn = "發貨價格[元/打]";
break;
case "send_moneys":
nextcolumn = "發貨金額";
break;
default:
break;
}

rectanglef cellbounds = new rectanglef(startxposition, thedatagrid.location.y + topmargin + (rowcount - initialrowcount) * (thedatagrid.font.sizeinpoints + kverticalcellleeway),
columnwidth,
thedatagrid.headerfont.sizeinpoints + kverticalcellleeway);
nextcellbounds = cellbounds;

if (startxposition + columnwidth <= pagewidth)
{

g.drawstring(nextcolumn, thedatagrid.headerfont, forebrush, cellbounds, cellformat);
}

startxposition = startxposition + columnwidth;


}

if (thedatagrid.gridlinestyle != datagridlinestyle.none)
g.drawline(thelinepen, thedatagrid.location.x, nextcellbounds.bottom, pagewidth, nextcellbounds.bottom);
}

public bool drawrows(graphics g)
{
int lastrowbottom = topmargin;

try
{
solidbrush forebrush = new solidbrush(thedatagrid.forecolor);
solidbrush backbrush = new solidbrush(thedatagrid.backcolor);
solidbrush alternatingbackbrush = new solidbrush(thedatagrid.alternatingbackcolor);
pen thelinepen = new pen(thedatagrid.gridlinecolor, 1);
stringformat cellformat = new stringformat();
cellformat.trimming = stringtrimming.ellipsischaracter;
cellformat.formatflags = stringformatflags.nowrap | stringformatflags.linelimit;
int columnwidth = pagewidth/thetable.columns.count - 20;

int initialrowcount = rowcount;

rectanglef rowbounds = new rectanglef(0, 0, 0, 0);

// draw vertical lines

arraylist lines = new arraylist();

// draw the rows of the table


for (int i = initialrowcount; i < thetable.rows.count; i++)
{

datarow dr = thetable.rows[i];
int startxposition = thedatagrid.location.x;

rowbounds.x = thedatagrid.location.x;
rowbounds.y = thedatagrid.location.y + topmargin + ((rowcount - initialrowcount)+1) * (thedatagrid.font.sizeinpoints + kverticalcellleeway);
rowbounds.height = thedatagrid.font.sizeinpoints + kverticalcellleeway;
rowbounds.width = pagewidth;
lines.add(rowbounds.bottom);

if (i%2 == 0)
{
g.fillrectangle(backbrush, rowbounds);
}
else
{
g.fillrectangle(alternatingbackbrush, rowbounds);
}


for (int j = 0; j < thetable.columns.count; j++)
{



rectanglef cellbounds = new rectanglef(startxposition,
thedatagrid.location.y + topmargin + ((rowcount - initialrowcount) + 1) * (thedatagrid.font.sizeinpoints + kverticalcellleeway),
columnwidth,
thedatagrid.font.sizeinpoints + kverticalcellleeway);


if (startxposition + columnwidth <= pagewidth)
{
g.drawstring(dr[j].tostring(), thedatagrid.font, forebrush, cellbounds, cellformat);
lastrowbottom = (int)cellbounds.bottom;
}

startxposition = startxposition + columnwidth;
}


rowcount++;

if (rowcount * (thedatagrid.font.sizeinpoints + kverticalcellleeway) > (pageheight * pagenumber) - (bottommargin+topmargin))
{
drawhorizontallines(g, lines);
drawverticalgridlines(g, thelinepen, columnwidth, lastrowbottom);
return true;
}


}

drawhorizontallines(g, lines);
drawverticalgridlines(g, thelinepen, columnwidth, lastrowbottom);


rectanglef cellbound1 = new rectanglef(thedatagrid.location.x,
thedatagrid.location.y + topmargin + (rowcount + 1) * (thedatagrid.font.sizeinpoints + kverticalcellleeway),
columnwidth,
thedatagrid.font.sizeinpoints + kverticalcellleeway);

g.drawstring("合計:", thedatagrid.font, forebrush, cellbound1, new stringformat());


rectanglef cellbound2 = new rectanglef(thedatagrid.location.x+columnwidth,
thedatagrid.location.y + topmargin + (rowcount + 1) * (thedatagrid.font.sizeinpoints + kverticalcellleeway),
columnwidth,
thedatagrid.font.sizeinpoints + kverticalcellleeway);

g.drawstring(this.receieve_amount .tostring (), thedatagrid.font, forebrush, cellbound2, new stringformat());


rectanglef cellbound3 = new rectanglef(thedatagrid.location.x+2*columnwidth,
thedatagrid.location.y + topmargin + (rowcount + 1) * (thedatagrid.font.sizeinpoints + kverticalcellleeway),
columnwidth,
thedatagrid.font.sizeinpoints + kverticalcellleeway);

g.drawstring(this.receieve_moneys .tostring (), thedatagrid.font, forebrush, cellbound3, new stringformat());

rectanglef cellbound4 = new rectanglef(thedatagrid.location.x+3*columnwidth,
thedatagrid.location.y + topmargin + (rowcount + 1) * (thedatagrid.font.sizeinpoints + kverticalcellleeway),
columnwidth,
thedatagrid.font.sizeinpoints + kverticalcellleeway);

g.drawstring(this.send_amount .tostring (), thedatagrid.font, forebrush, cellbound4, new stringformat());

rectanglef cellbound5 = new rectanglef(thedatagrid.location.x+4*columnwidth,
thedatagrid.location.y + topmargin + (rowcount + 1) * (thedatagrid.font.sizeinpoints + kverticalcellleeway),
columnwidth,
thedatagrid.font.sizeinpoints + kverticalcellleeway);

g.drawstring(this.send_moneys .tostring (), thedatagrid.font, forebrush, cellbound5, new stringformat());


//g.drawstring("合計:", thedatagrid.headerfont, forebrush, cellbounds, cellformat);
return false;

}
catch (exception ex)
{
messagebox.show(ex.message.tostring());
return false;
}

}

void drawhorizontallines(graphics g, arraylist lines)
{
pen thelinepen = new pen(thedatagrid.gridlinecolor, 1);

if (thedatagrid.gridlinestyle == datagridlinestyle.none)
return;

for (int i = 0; i < lines.count; i++)
{
g.drawline(thelinepen, thedatagrid.location.x, (float)lines[i], pagewidth, (float)lines[i]);
}
}

void drawverticalgridlines(graphics g, pen thelinepen, int columnwidth, int bottom)
{
if (thedatagrid.gridlinestyle == datagridlinestyle.none)
return;

for (int k = 0; k < thetable.columns.count; k++)
{
g.drawline(thelinepen, thedatagrid.location.x + k*columnwidth,
thedatagrid.location.y + topmargin,
thedatagrid.location.x + k*columnwidth,
bottom);
}
}


public bool drawdatagrid(graphics g)
{

try
{
drawheader(g);
bool bcontinue = drawrows(g);
return bcontinue;
}
catch (exception ex)
{
messagebox.show(ex.message.tostring());
return false;
}

}

}

}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 景洪市| 孟连| 扬中市| 皋兰县| 壤塘县| 望谟县| 新巴尔虎右旗| 屏东县| 贡嘎县| 安达市| 东方市| 黔江区| 瑞丽市| 高雄县| 淳化县| 阳朔县| 河池市| 赤水市| 泸州市| 岳阳县| 周宁县| 辽源市| 建水县| 明水县| 湖北省| 峨眉山市| 津市市| 仁怀市| 潮州市| 宣恩县| 大悟县| 老河口市| 兴山县| 赣榆县| 泗阳县| 英吉沙县| 志丹县| 辛集市| 来宾市| 阳西县| 读书|