[原创][打印]打印代码初探
本帖最后由 Source_Liu 于 2011-7-20 09:27 编辑cad批量打印一直是我的心头病。想写一个小程序。又要工作。偷个懒,晒晒写好的部分源代码。发现问题请及时跟帖,程序未调试完。375798574
谢谢13楼提醒,低级错误,更新过了,请再下载一下
一、打印纸张:
分A、B 2个系列。大小如下表
规格 幅宽(mm) 长度(mm) 规格 幅宽(mm) 长度(mm)
A0 841 1189 B0 1030 1456
A1 594 841 B1 728 1030
A2 420 594 B2 515 728
A3 297 420 B3 364 515
A4 210 297 B4 257 364
A5 148 210 B5 182 257
A6 105 148 B6 128 182
A7 74 105 B7 91 128
A8 52 74 B8 64 91
A9 37 52 B9 45 64
A10 26 37 B10 32 45
现在多用A系列。同时根据GB要求,补充加长图幅。源码如下: \\基类
using System;
namespace Source.Page{
#region 纸张类
public abstract class SizeBase {
#region 内部变量:幅面长(X)、宽(Y)、幅面(Name)、ToString()
public abstract int X {//长边长度
get;
}
public abstract int Y {//短边长度
get;
}
public abstract string Name {
get;
}
public override string ToString() {
return this.Name;
}
#endregion
#region ==、!=、
public static bool operator ==(SizeBase a, SizeBase b) {
return a.X == b.X && a.Y == b.Y;
}
public static bool operator !=(SizeBase a, SizeBase b) {
return a.X != b.X || a.Y != b.Y;
}
public override bool Equals(object obj) {
if(!(obj is SizeBase)) return false;
return this == (SizeBase)obj;
}
public override int GetHashCode() {
return this.Name.GetHashCode();
}
#endregion
}
#endregion
}
//集合基类
using System;
using System.Collections.Generic;
using System.Text;
namespace Source.Page {
public abstract class SizesBase {
public abstract SizeBase[] Items {
get;
}
}
}
//using System;
namespace Source.Page {
public class SizesOfA : SizesBase {
#region 图幅集合数组
public override SizeBase[] Items {
get{
return new SizeOfA[]{
new SizeOfA(0),
new SizeOfA(1),
new SizeOfA(2),
new SizeOfA(3),
new SizeOfA(4),
new SizeOfA(5),
new SizeOfA(6),
new SizeOfA(7),
new SizeOfA(8),
new SizeOfA(9),
new SizeOfA(10)
};
}
}
#endregion
public SizeOfA this{
get {
return new SizeOfA(number);
}
}
}
} namespace Source.Page {
public class SizeOfA:SizeBase {
#region 常量
const string NameStart="A";
const int X0 = 1189;
const int Y0 = 841;
#endregion
#region 内部变量:图幅Number、宽、长、周边宽、装订线边宽、横幅标记
private int Number;//图幅Number
public override int X{//长边长度
get{
return ((this.Number & 1) == 0 ? X0 : Y0)>> (this.Number >> 1);
}
}
public override int Y {//短边长度
get{
return ((this.Number & 1) == 1 ? X0 : Y0) >> ((this.Number+1)>>1);//等同(Number) % 2==0 ?1189:841)/(2的Number/2次方)
}
}
public override string Name {
get {
return NameStart+this.Number.ToString().Trim();
}
}
public override string ToString() {
return this.Name;
}
#endregion
#region 构造函数:(number)
public SizeOfA(int number) {
this.Number = number;
}
#endregion
#region ==、!=、
public static bool operator ==(SizeOfA a, SizeOfA b) {
return a.Number == b.Number;
}
public static bool operator !=(SizeOfA a, SizeOfA b) {
return a.Number != b.Number;
}
public override bool Equals(object obj){
if(obj is SizeOfA) return this == (SizeOfA)obj;
else return base.Equals(obj);
}
public override int GetHashCode(){//继承SizeBase类
return this.Number.GetHashCode();
}
#endregion
}
} namespace Source.Page {
public class SizeOfB : SizeBase {
#region 常量
const string NameStart = "B";
const int X0 = 1456;
const int Y0 = 1030;
#endregion
#region 内部变量:图幅Number、宽、长、周边宽、装订线边宽、横幅标记
private int Number;//图幅Number
public override int X {//长边长度
get {
return ((this.Number & 1) == 0 ? X0 : Y0) >> (this.Number >> 1);
}
}
public override int Y {//短边长度
get {
return ((this.Number & 1) == 1 ? X0 : Y0) >> ((this.Number + 1) >> 1);//等同(Number) % 2==0 ?1189:841)/(2的Number/2次方)
}
}
public override string Name {
get {
return NameStart + this.Number.ToString().Trim();
}
}
public override string ToString() {
return this.Name;
}
#endregion
#region 构造函数:(number)
public SizeOfB(int number) {
this.Number = number;
}
#endregion
#region ==、!=、
public static bool operator ==(SizeOfB a, SizeOfB b) {
return a.Number == b.Number;
}
public static bool operator !=(SizeOfB a, SizeOfB b) {
return a.Number != b.Number;
}
public override bool Equals(object obj) {
if(obj is SizeOfB) return this == (SizeOfB)obj;
else return base.Equals(obj);
}
public override int GetHashCode() {//继承SizeBase类
return this.Number.GetHashCode();
}
#endregion
}
} namespace Source.Page {
//根据《技术制图 图纸幅面和格式》(GB/T 14689-2008)要求编写
//只实现加长部分。
public class SizeOfCADExtend : SizeBase {
#region 常量
const string NameStart = "A";
const string strMultiply = "x";
const int X0 = 1189;
const int Y0 = 841;
#endregion
#region 内部变量:图幅Number、加长、宽、长
private int Number;//图幅Number
private int Multiple;//加长倍数
public override int X {//长边长度
get {
return (((this.Number & 1) ==1 ? X0 : Y0)* this.Multiple) >> ((this.Number+1)>> 1);
}
}
public override int Y {//短边长度
get {
return ((this.Number & 1) == 0 ? X0 : Y0) >> (this.Number>> 1);
}
}
public override string Name {
get {
return NameStart + this.Number.ToString().Trim() + strMultiply + this.Multiple.ToString().Trim();
}
}
public override string ToString() {
return this.Name;
}
#endregion
#region 构造函数:(number,multiple)
public SizeOfCADExtend(int number,int multiple) {
this.Number = number;
this.Multiple=multiple;
}
#endregion
#region ==、!=、
public static bool operator ==(SizeOfCADExtend a, SizeOfCADExtend b) {
return a.Number == b.Number && a.Multiple==b.Multiple;
}
public static bool operator !=(SizeOfCADExtend a, SizeOfCADExtend b) {
return a.Number != b.Number || a.Multiple!=b.Multiple;
}
public override bool Equals(object obj) {
if(obj is SizeOfCADExtend) return this == (SizeOfCADExtend)obj;
else return base.Equals(obj);
}
public override int GetHashCode() {//继承SizeBase类
return this.Name.GetHashCode();
}
#endregion
}
} //using System;
namespace Source.Page {
public class SizesOfCAD : SizesBase {
#region 图幅集合数组
public override SizeBase[] Items {
get {
return new SizeBase[]{
new SizeOfA(0),
new SizeOfA(1),
new SizeOfA(2),
new SizeOfA(3),
new SizeOfA(4),
new SizeOfCADExtend(0,2),
new SizeOfCADExtend(0,3),
new SizeOfCADExtend(1,3),
new SizeOfCADExtend(1,4),
new SizeOfCADExtend(2,3),
new SizeOfCADExtend(2,4),
new SizeOfCADExtend(2,5),
new SizeOfCADExtend(3,3),
new SizeOfCADExtend(3,4),
new SizeOfCADExtend(3,5),
new SizeOfCADExtend(3,6),
new SizeOfCADExtend(3,7),
new SizeOfCADExtend(4,3),
new SizeOfCADExtend(4,4),
new SizeOfCADExtend(4,5),
new SizeOfCADExtend(4,6),
new SizeOfCADExtend(4,7),
new SizeOfCADExtend(4,8),
new SizeOfCADExtend(4,9)
};
}
}
#endregion
public SizeOfA this {
get {
return new SizeOfA(number);
}
}
}
} 部分代码,有界面吗,贴上来啊,或者编译好的程序也可以啊,直接明了
页:
[1]
2