序言

现如今存在的财务软件层出不穷,怎么样让自己的业务系统与财务系统相结合,往往是很多公司头痛的问题。大多数公司也没有这个能力都去开发一套属于自己的财务软件,所以只有对接像金蝶用友这类的财务软件,花费大量的人力物力在两套系统中切换,从而开发属于自己的一套业务和财务一体化的系统迫在眉睫,去解决这些痛点。

如何去实现winform凭证

用C#语言开发,CS框架,DevExpress控件,实现出来的效果如下:

会计科目支持代码、科目和助记码的模糊搜索,可以进行快速找到相应的科目。同金蝶和用友专业的财务软件媲美了,功能齐全,操作方便简单。

录入凭证之前先对科目进行定义,科目都是财政部相对应的科目:

录入简单的凭证,进行测试,相对简单方便。

保存完进行打印,打印出来就是专业的会计凭证了,凭证的打印是用时锐浪进行实现的。同时支持A4纸张和套打都可以。

   try
{
string ReportPath = "", printtitle = "", printername = "";
float paperlength = 0, paperwidth = 0; string printModel = CommonArgs.printTypes.ContainsKey(printType) ? (printType == "托运单" ? "tydtype" : printType == "标签" ? "bqtype" : (CommonArgs.printTypes[printType] + "Model")) : "";
printtitle = API.ReadINI("Print", printModel, "", CommonArgs.config);
printtitle = printtitle == "" ? printType : printtitle;//如果是没有选择模板的,默认为打印类型,找一下配置 //查找配置信息
DataRow[] drs = CommonClass.DsPrint.Tables[0].Select("title='" + printtitle + "'");
if (drs.Length > 0)
{
paperlength = drs[0]["paperlength"].ToFloat();
paperwidth = drs[0]["paperwidth"].ToFloat();
ReportPath = drs[0]["grfname"].ToStringEx();
}
else
{
ReportPath = printType + ".grf";
} string reportpath = Application.StartupPath + "\\" + ReportPath;
if (!System.IO.File.Exists(reportpath))
{
XtraMessageBox.Show("缺少相应的打印模板文件【" + ReportPath + "】!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
printername = GetPrinter(printType);
if (printername == "" || !CommonClass.CheckPrinters(printername))
{
PrintDocument prtdoc = new PrintDocument();
printername = prtdoc.PrinterSettings.PrinterName;//获取默认的打印机名
ShowPrintDialog = true;
} Report.LoadFromFile(reportpath); ds = new DataSet();
ds.Tables.Add(dt.Copy());
if (paperlength != 0)
{
Report.Printer.PaperLength = paperlength;
Report.Printer.PaperWidth = paperwidth;
Report.Printer.PaperSize = 256;
Report.Printer.SheetPages = GRSheetPages.grsp1Pages;
}
Report.Printer.PrinterName = printername;
Report.LoadDataFromXML(ds.GetXml());
Report.Print(ShowPrintDialog);
if (ShowPrintDialog) saveprinter(printType, Report.Printer.PrinterName); //保存打印次数
CommonClass.SetPrintCount(printType, dt);
}
catch (Exception ex)
{
XtraMessageBox.Show(ex.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

  

锐浪设计文件如下,把相应的字段对应基本上就大功告成了。

如何用代码去实现凭证界面的开发

其实说到用代码去实现凭证这个界面的开发还是挺有难度的,CS不必BS那么容易去布局,这个界面实现起来没得几千行代码也是搞不定,难点还是在借方和贷方金额这里,整个界面下面是一张背景图。

借方和贷方金额实现代码:

        public void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e, GridControl showgrid, GridView gridView1)
{
try
{ int width = Math.Max(e.Bounds.Width, e.Column.Width);
int spacewidth = width / 10; //空格宽度
int intlen = 8;//整数位数
int fe = 2; //小数位数
string format = string.Empty;
GridControl gridControl = showgrid;
//获取小数位
if (e.Column.ColumnEdit != null)
{
//format = (e.Column.ColumnEdit.DisplayFormat as FormatInfo).GetDisplayText(e.CellValue);
format = e.CellValue == null || e.CellValue == DBNull.Value ? "" : e.CellValue.ToString();
}
else
{
//format = (e.Column.DisplayFormat as FormatInfo).GetDisplayText(e.CellValue);
format = e.CellValue == null || e.CellValue == DBNull.Value ? "" : e.CellValue.ToString();
}
//10个整数位,2个小数位
format = Convert.ToDecimal(format == "" ? "0" : format).ToString("N2");
format = format.Replace(",", "");
fe = format.Substring(format.IndexOf('.') + 1).Length;
for (int i = 0; i < intlen + fe; i++)
{
if (i == 1 || i == 4)
{
e.Graphics.DrawLine(Pens.Blue, e.Bounds.Left + (i + 1) * spacewidth - 1, 0, e.Bounds.Left + (i + 1) * spacewidth - 1, gridControl.Height);
}
else if (i == 7)
{
e.Graphics.DrawLine(Pens.Red, e.Bounds.Left + (i + 1) * spacewidth - 1, 0, e.Bounds.Left + (i + 1) * spacewidth - 1, gridControl.Height);
}
else if (i == intlen + fe - 1)
{
e.Graphics.DrawLine(new Pen(Color.Black, 1), e.Bounds.Left + (i + 1) * spacewidth - 1, 0, e.Bounds.Left + (i + 1) * spacewidth - 1, gridControl.Height);
}
else
{
e.Graphics.DrawLine(Pens.LightGray, e.Bounds.Left + (i + 1) * spacewidth - 1, 0, e.Bounds.Left + (i + 1) * spacewidth - 1, gridControl.Height);
}
} var sf = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }; //decimal v = e.CellValue == null || e.CellValue == DBNull.Value || e.CellValue.ToString() == "" ? 0 : Convert.ToDecimal(e.CellValue); string s_int = format.Substring(0, format.IndexOf('.')); //((int)v).ToString();
//两位小数
string s_dec = format.ToString().Substring(format.ToString().IndexOf('.') + 1, fe);
string s_value = s_int + s_dec;
int a = 1;
for (int i = s_value.Length - 1; i >= 0; i--)
{
//string ch = s_value[s_value.Length -i- 1].ToString();
string ch = s_value[i].ToString();
if (s_int == "0" && s_dec == "00") ch = "";
int x = e.Bounds.Left + (intlen + fe - a) * spacewidth;
int y = e.Bounds.Top;
var rect = new RectangleF(x, y, spacewidth, e.Bounds.Height);
e.Graphics.DrawString(ch, e.Column.AppearanceCell.Font, Brushes.Black, rect, sf);
a++;
}
e.Handled = true; }
catch (Exception ex)
{
MsgBox.ShowError("输入金额过大!" + ex.Message);
gridView1.SetRowCellValue(e.RowHandle, e.Column.FieldName, DBNull.Value);
gridView1.FocusedColumn = e.Column;
gridView1.ShowEditor();
} } public void gridView1_CustomDrawColumnHeader(object sender, ColumnHeaderCustomDrawEventArgs e, GridControl showgrid, GridView gridView1, string type)
{
try
{
Pen penred = new Pen(Color.Red);
Pen penblue = new Pen(Color.Blue);
Pen pengray = new Pen(Color.LightGray);
Pen fontpen = new Pen(Color.Black);
int width = e.Bounds.Width;
int spacewidth = width / 10; //计算格子宽度;一起10位数:8位整数 2位小数
e.Painter.DrawObject(e.Info);
e.Graphics.DrawLine(fontpen, e.Bounds.X, e.Bounds.Y + e.Bounds.Height / 2, e.Bounds.X + width, e.Bounds.Y + e.Bounds.Height / 2);
e.Graphics.DrawString(type, e.Appearance.Font, fontpen.Brush, (type == "金额" ? e.Bounds.X + width / 4 + 18 : e.Bounds.X + width / 4 + 5), e.Bounds.Y);
string u = "千百十万千百十元角分";
string ch = "";
Pen temppen = pengray;
Font font = new Font(e.Appearance.Font.FontFamily, (float)7.5);
for (int i = 0; i < u.Length; i++)
{
ch = u[i].ToString(); if (i == 1 || i == 4)
{
temppen = penblue;
}
else if (i == 7)
{
temppen = penred;
}
else if (i == 9)
{
temppen = new Pen(Color.Black);
}
else
{
temppen = pengray;
}
e.Graphics.DrawString(ch, font, fontpen.Brush, e.Bounds.X + i * spacewidth, e.Bounds.Y + e.Bounds.Height / 2 + 1);
e.Graphics.DrawLine(temppen, e.Bounds.X + (i + 1) * spacewidth, e.Bounds.Y + e.Bounds.Height / 2, e.Bounds.X + (i + 1) * spacewidth, e.Bounds.Y + e.Bounds.Height);
}
e.Handled = true;
}
catch (Exception)
{
return; ;
}
}

汇总金额字体颜色控制

        private void gridView1_CustomDrawFooterCell(object sender, FooterCellCustomDrawEventArgs e)
{
if (e.Column == c0)
{
if (c0.SummaryText.Trim().Contains("借贷金额不平衡"))
{
AppearanceDefault footer = new AppearanceDefault(Color.Red, Color.Empty, new Font(AppearanceObject.DefaultFont, FontStyle.Bold));
AppearanceHelper.Apply(e.Appearance, footer);
}
else
{
AppearanceDefault footer = new AppearanceDefault(Color.Green, Color.Empty, new Font(AppearanceObject.DefaultFont, FontStyle.Bold));
AppearanceHelper.Apply(e.Appearance, footer);
}
}
}

保存好的凭证,并可以打开查看业务明细:

结束语

以上就是财务凭证的实现,有兴趣朋友一起研究学习进步。  

winform怎么实现财务上凭证录入和打印的更多相关文章

  1. C#在WinForm下使用HttpWebRequest上传文件

    转自:http://blog.csdn.net/shihuan10430049/article/details/3734398 这段时间因项目需要,要实现WinForm下的文件上传,个人觉得采用FTP ...

  2. Lodop不要把客户端的打印机共享到服务器上 再在客户端打印

    客户端打印需要每个客户端都安装,Lodop插件方式和C-Lodop方式,都是安装一次后,无需再次安装,c-lodop默认也是开机自启动的.集中打印方式,可以打印到某台电脑(作为云主机)上,但是不能打印 ...

  3. .NetCore对接各大财务软件凭证API——金蝶系列(1)

    哈喽,又和大家见面了,虽然看文章的小伙伴不多,但是我相信总有一天,自己写的这些文章或多或少会对其他人有些帮助,让他们在相关的业务开发下能少走些弯路,那我的目的就达到了,好了,今天就正式开始我们的系列了 ...

  4. .NetCore对接各大财务软件凭证API——用友系列(1)

    一.前言 今天,我们转战用友系列的第一个产品---T+/Tplus.前两篇文章讲解分享的都是金蝶的产品,因为本身公司牵涉的业务有限,后续有金蝶其他产品的API对接业务时,会继续来分享经验. T+的AP ...

  5. .NetCore对接各大财务软件凭证API——用友系列(2)

    一. 前言 今天我们继续来分析用友系列的第二个产品--U8Cloud2.5 ,apilink方式的API.官网的API文档地址如下:U8API文档 因为我们主要是凭证对接,所以使用到的模块有总账.基础 ...

  6. .NetCore对接各大财务软件凭证API——用友系列(3)

    一. 前言 由于前段时间项目比较集中,所以停更了好久,终于来到我们用友的系列产品3---U8Cloud2.7了. 一,2.7和2.5的api方式有什么区别? 1.2.7版本以后可以直接使用u8c登入地 ...

  7. 通过winForm控制webForm的上传控件file的值

    文件上传是日常开发中经常遇到的,文件上传用的最多的当然是上传控件file了,一个form表单,其中有一点就是form表单的enctype属性设置为multipart/form-data,呵呵,这个在所 ...

  8. WinForm 控件(上)

    窗体的事件 每一个窗体都有一个事件,这个窗体加载完成之后执行哪一段代码 位置:1)右键属性→事件→load 双击进入 2)双击窗体任意一个位置进入 删除事件:先将事件页面里面的挂好的事件删除,再删后台 ...

  9. winform程序压缩文件上传,服务器端asp.net mvc进行接收解压

    期间编程没什么难度,唯一可能忽略导致结果失败是asp.net  mvc配置 对于压缩文件大的话,需要配置mvc的最大接收量: <system.web> <httpRuntime ma ...

随机推荐

  1. Tomcat 启动过滤器异常

    严重 [RMI TCP Connection(2)-127.0.0.1] org.apache.catalina.core.StandardContext.filterStart 启动过滤器异常 ja ...

  2. 妈妈再也不担心我面试被Redis问得脸都绿了

    长文前排提醒,收藏向前排提醒,素质三连 (转发 + 在看 + 留言) 前排提醒! 前言 Redis 作为一个开源的,高级的键值存储和一个适用的解决方案,已经越来越在构建 「高性能」.「可扩展」 的 W ...

  3. AdFind

    C++实现(未开源),用于查询域内信息 http://www.joeware.net/freetools/tools/adfind/index.htm 常用命令如下: 列出域控制器名称: AdFind ...

  4. 性能测试从零开始-LoadRunner入门

    写在前面 又到了公司每月的读书会,经过上个月的试运行后,公司把读书会纳入每月的绩效考核中,听到这个消息,当时我的内心是崩溃的,不过从另一方面来讲,对于我来说也一件好事儿,这样可以督促自己养成读书的习惯 ...

  5. 欢乐水杯(happy glass)中流体的一种实现!图文视频讲解 ! Cocos Creator!

    使用cocos creator v2.2.2 实现流体效果 ! 图文+视频讲解! 效果预览 实现原理 整体思路是参考论坛中的一个帖子 这款游戏中水的粘连效果在Construct3中利用图层很容易实现, ...

  6. hdu3368 dfs 下棋

    两颗黑子之间的白子可以翻装成黑子,两颗白子之间的黑子可以翻转成白子,对于一个给定位置,有八个方向有翻转其他颜色的子的可能.规则之一是下棋的位置一定要能翻转对方的子. 求最优情况:黑子能翻转的白子个数的 ...

  7. hdu1045 炮台的配置 dfs

    只要炮台在同一行或者同一列,就可以互相摧毁,遇到墙则无法对墙后的炮台造成伤害,可以通过dfs搜索n*n的方格,全部搜完算一轮,计算炮台数,并保存其最大值. 其中对于t编号的炮台,位置可以计算出是(t/ ...

  8. 决战Leetcode: easy part(1-50)

    本博客是个人原创的针对leetcode上的problem的解法,所有solution都基本通过了leetcode的官方Judging,个别未通过的例外情况会在相应部分作特别说明. 欢迎互相交流! em ...

  9. OpenCV-Python 读取显示图像 | 五

    目标 在这里,你将学习如何读取图像,如何显示图像以及如何将其保存回去 你将学习以下功能:cv.imread(),cv.imshow(),cv.imwrite() (可选)你将学习如何使用Matplot ...

  10. 密钥对格式转换:JKS到PEM

    此处脚本用途:Tomcat的JKS转换成Nginx的PEM格式. #!/bin/bash export JKS=$1 export PASS=$2 NAME=$(basename "$JKS ...