江老师:您好!由于新书通报不能输出表格式的文件,我想通过财产总账的统计程序变通一下,但相关的字段不知如何自定义,请赐教,谢谢!
财产总账的主要输出字段:
"序号,登录号,书名,著者,出版者,ISBN,出版版期,装订、开本页数,册数,单价,总价"
我想把“登录号,ISBN”两个字段改为“分类号905$d、种次号905$e”,通过这样更改后,输出的信息就为:"序号,分类号,书名,著者,出版者,种次号,出版版期,装订、开本页数,册数,单价,总价",再通过excel处理得到自己需要的文件。
// 财产总帐
// 最后修改时间: 2008/1/4
using System;
using System.Windows.Forms;
using System.IO;
using System.Text;
using System.Drawing;
using DigitalPlatform.MarcDom;
using DigitalPlatform.Statis;
using DigitalPlatform.Xml;
using DigitalPlatform.Text;
using dp1Batch;
public class MyBatch : Batch
{
public string strDengLuHao = ""; //分类号905$d 可重
public string strISBN = ""; //种次号 905$e
public string strShuMing = "";// 书名 200$a
public string strZhuZhe = ""; //著者 200$f
public string strChuBanZhe = "";//出版者 210$c
public string strChuBanRiQi = ""; //出版日期 205$a
public string strZaiTi = "";//载体形态 215$a(页码) ,215$d(尺寸)
public string strDanJia = ""; //单价 010$d
public string strCheShu = "";//册数 905$f
Table table = new Table(10);
string strOutFileName = ""; //输出文件类型
string strWordFileName = "f:\\test.doc"; // 缺省Word文件名
bool IsSort = false; //默认为不排序
public override void OnBegin(object sender, BatchEventArgs e)
{
// 询问页面
string strError;
HtmlForm window = new HtmlForm();
window.Url = this.ProjectDir + "\\input.html";
window.Size = new Size(700,500);
window.ShowDialog();
// 必须是OK
if (window.DialogResult != DialogResult.OK)
{
e.Continue = ContinueType.SkipAll;
return;
}
if (window.SubmitUrl == "action://ok/")
{
//取排序风格
string strIsSort = window.SubmitResult["sort"];
if(strIsSort == "on")
IsSort = true; //表示排序
// 输出文件类型
strOutFileName = window.SubmitResult["outfiletype"];
// 输出word文件名
strWordFileName = window.SubmitResult["filename"];
}
}
//普通表格模块
public void DoCommonTable()
{
/*
public string strDengLuHao = ""; //登录号905$b 可重
public string strISBN = ""; //ISBN号 010$a
public string strShuMing = "";// 书名 200$a
public string strZhuZhe = ""; //著者 200$f
public string strChuBanZhe = "";//出版者 210$c
public string strChuBanRiQi = ""; //出版日期 205$a
public string strZaiTi = "";//载体形态 215$a(页码) ,215$d(尺寸)
public string strDanJia = ""; //单价 010$d
public string strCheShu = "";//册数 905$f
*/
table.SetValue(Convert.ToString(this.RecIndex),
0,
strDengLuHao);
table.SetValue(Convert.ToString(this.RecIndex),
1,
strISBN);
table.SetValue(Convert.ToString(this.RecIndex),
2,
strShuMing);
table.SetValue(Convert.ToString(this.RecIndex),
3,
strZhuZhe);
table.SetValue(Convert.ToString(this.RecIndex),
4,
strChuBanZhe);
table.SetValue(Convert.ToString(this.RecIndex),
5,
strChuBanRiQi);
table.SetValue(Convert.ToString(this.RecIndex),
6,
strZaiTi);
table.SetValue(Convert.ToString(this.RecIndex),
7,
strCheShu);
table.SetValue(Convert.ToString(this.RecIndex),
8,
strDanJia);
//如果905$f有册数则按此计数,否则通过折分登录号,得到册数
int nCheShu = 0;
if (strCheShu == "")
{
nCheShu = GetCeShuFromDengLuHao(strDengLuHao);
}
else
{
nCheShu = Convert.ToInt32(strCheShu);
}
table.SetValue(Convert.ToString(this.RecIndex),
9,
nCheShu);
/* ????
int nCheShu = 0;
try
{
nCheShu = Convert.ToInt32(strCheShu);
}
catch
{
}
*/
//总价
Int64 v = 0;
try {
v = Batch.PriceToInt64(strDanJia);
}
catch {
v = 0; // TODO: strDanJia字符串格式有问题,这里可以报错
}
table.SetValue(Convert.ToString(this.RecIndex),
10,
(Int64)v*nCheShu);
}
//从登录号字符串折分单个登录号的个数,即册数
public int GetCeShuFromDengLuHao(string strDengLuHao)
{
string[] aDengLuHao = strDengLuHao.Split(new char[] {','});
for(int i=0;i<aDengLuHao.Length;i++)
{
string strOneDengLuHao = aDengLuHao[i];
string strLeft = "";
string strRight = "";
int nPosition = strOneDengLuHao.IndexOf('-');
if (nPosition > 0) // 001-3
{
strLeft = strOneDengLuHao.Substring(0,nPosition); // 001
strRight = strOneDengLuHao.Substring(nPosition+1); // 3
}
else if (nPosition == 0) // -1
{
strLeft = strOneDengLuHao.Substring(nPosition+1); // 1
}
else // 001
{
strLeft = strOneDengLuHao; // 001
}
if (strRight == "")
return 1;
string strRightPartOfLeft = strLeft.Substring(strLeft.Length - strRight.Length);
int nCount = 0;
try
{
nCount = Convert.ToInt32(strRight) - Convert.ToInt32(strRightPartOfLeft);
}
catch //忽略掉错误的字符串格式了
{}
return nCount;
}
return 0; // 2007/7/6 xietao new add
}
//排序表格模块
public void DoSortTable()
{
}
public override void OnMiddle(object sender, BatchEventArgs e)
{
if (IsSort == false)
{
DoCommonTable();
}
else
{
DoSortTable();
}
}
public override void OnEnd(object sender, BatchEventArgs e)
{
Int64 nHeJiZongJia = 0;
int nHeJiCheShu = 0;
for(int i=0;i<table.Count;i++)
{
nHeJiZongJia += (int)table.SearchValue(Convert.ToString(i),
9);
string cheShu = (string)table.SearchValue(Convert.ToString(i),
7);
try
{
nHeJiCheShu += Convert.ToInt32(cheShu);
}
catch
{}
}
if (StringUtil.IsInList("html",strOutFileName) == true)
{
string strOutputFileName = this.ProjectDir + "\\output.html";
StreamWriter sw = new StreamWriter(strOutputFileName,
false,
Encoding.UTF8);
sw.WriteLine("<html><head>");
sw.WriteLine("<meta http-equiv='Content-Type' content=\"text/html; charset=utf-8\">");
sw.WriteLine("<title></title>");
sw.WriteLine("<link rel=\"stylesheet\" href=\"./style.css\" type=\"text/css\">");
sw.WriteLine("</head><body>");
sw.WriteLine("<h3>分类统计表</h3>");
sw.WriteLine("<p>共计 ");
sw.WriteLine(" " + Convert.ToString(table.Count) + " 种");
sw.WriteLine(" " + Convert.ToString(nHeJiCheShu) + " 册");
sw.WriteLine(" " + Convert.ToString(nHeJiZongJia) + " 元</p>");
table.Sort("-1:a"); //按行标题降序
Report report = Report.BuildReport(table,
"序号,登录号,书名,著者,出版者,ISBN,出版版期,装订、开本页数,册数,单价,总价",
" ",
true);
if (report == null)
{
MessageBox.Show("表格为空");
return;
}
report[10].DataType = DataType.Price;
report[0].Sum = false;
report[1].Sum = false;
report[2].Sum = false;
report[3].Sum = false;
report[4].Sum = false;
report[5].Sum = false;
report[6].Sum = false;
report[7].Sum = false;
report[9].Sum = false;
report.SumLine = false;
//MessageBox.Show("1");
string strReportHtml = report.HtmlTable(table);
sw.WriteLine(strReportHtml);
sw.WriteLine("</body></html>");
sw.Close();
HtmlForm htmlWindow = new HtmlForm();
htmlWindow.Url = strOutputFileName;
htmlWindow.ShowDialog();
}
if (StringUtil.IsInList("word",strOutFileName) == true)
{
table.Sort("-1:a"); //按行标题降序
WordReport report = WordReport.BuildWordReport(table,
"序号,登录号,书名,著者,出版者,ISBN,出版版期,装订、开本页数,册数,单价,合计",
" ",
true);
if (report == null)
{
MessageBox.Show("表格为空");
return;
}
report[10].DataType = DataType.Price;
report[0].Sum = false;
report[1].Sum = false;
report[2].Sum = false;
report[3].Sum = false;
report[4].Sum = false;
report[5].Sum = false;
report[6].Sum = false;
report[7].Sum = false;
report[9].Sum = false;
report.SumLine = false;
WordTableFormat format = new WordTableFormat();
format.TableStyle = "彩色型 2";
report.OutputTable(table,
"财产帐",
format,
strWordFileName);
MessageBox.Show("输出结束,到'" + strWordFileName + "'");
}
}
}