序言

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

如何去实现winform凭证

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

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

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

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

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

  1. try
  2. {
  3. string ReportPath = "", printtitle = "", printername = "";
  4. float paperlength = 0, paperwidth = 0;
  5.  
  6. string printModel = CommonArgs.printTypes.ContainsKey(printType) ? (printType == "托运单" ? "tydtype" : printType == "标签" ? "bqtype" : (CommonArgs.printTypes[printType] + "Model")) : "";
  7. printtitle = API.ReadINI("Print", printModel, "", CommonArgs.config);
  8. printtitle = printtitle == "" ? printType : printtitle;//如果是没有选择模板的,默认为打印类型,找一下配置
  9.  
  10. //查找配置信息
  11. DataRow[] drs = CommonClass.DsPrint.Tables[0].Select("title='" + printtitle + "'");
  12. if (drs.Length > 0)
  13. {
  14. paperlength = drs[0]["paperlength"].ToFloat();
  15. paperwidth = drs[0]["paperwidth"].ToFloat();
  16. ReportPath = drs[0]["grfname"].ToStringEx();
  17. }
  18. else
  19. {
  20. ReportPath = printType + ".grf";
  21. }
  22.  
  23. string reportpath = Application.StartupPath + "\\" + ReportPath;
  24. if (!System.IO.File.Exists(reportpath))
  25. {
  26. XtraMessageBox.Show("缺少相应的打印模板文件【" + ReportPath + "】!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
  27. return;
  28. }
  29. printername = GetPrinter(printType);
  30. if (printername == "" || !CommonClass.CheckPrinters(printername))
  31. {
  32. PrintDocument prtdoc = new PrintDocument();
  33. printername = prtdoc.PrinterSettings.PrinterName;//获取默认的打印机名
  34. ShowPrintDialog = true;
  35. }
  36.  
  37. Report.LoadFromFile(reportpath);
  38.  
  39. ds = new DataSet();
  40. ds.Tables.Add(dt.Copy());
  41. if (paperlength != 0)
  42. {
  43. Report.Printer.PaperLength = paperlength;
  44. Report.Printer.PaperWidth = paperwidth;
  45. Report.Printer.PaperSize = 256;
  46. Report.Printer.SheetPages = GRSheetPages.grsp1Pages;
  47. }
  48. Report.Printer.PrinterName = printername;
  49. Report.LoadDataFromXML(ds.GetXml());
  50. Report.Print(ShowPrintDialog);
  51. if (ShowPrintDialog) saveprinter(printType, Report.Printer.PrinterName);
  52.  
  53. //保存打印次数
  54. CommonClass.SetPrintCount(printType, dt);
  55. }
  56. catch (Exception ex)
  57. {
  58. XtraMessageBox.Show(ex.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  59. }

  

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

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

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

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

  1. public void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e, GridControl showgrid, GridView gridView1)
  2. {
  3. try
  4. {
  5.  
  6. int width = Math.Max(e.Bounds.Width, e.Column.Width);
  7. int spacewidth = width / 10; //空格宽度
  8. int intlen = 8;//整数位数
  9. int fe = 2; //小数位数
  10. string format = string.Empty;
  11. GridControl gridControl = showgrid;
  12. //获取小数位
  13. if (e.Column.ColumnEdit != null)
  14. {
  15. //format = (e.Column.ColumnEdit.DisplayFormat as FormatInfo).GetDisplayText(e.CellValue);
  16. format = e.CellValue == null || e.CellValue == DBNull.Value ? "" : e.CellValue.ToString();
  17. }
  18. else
  19. {
  20. //format = (e.Column.DisplayFormat as FormatInfo).GetDisplayText(e.CellValue);
  21. format = e.CellValue == null || e.CellValue == DBNull.Value ? "" : e.CellValue.ToString();
  22. }
  23. //10个整数位,2个小数位
  24. format = Convert.ToDecimal(format == "" ? "0" : format).ToString("N2");
  25. format = format.Replace(",", "");
  26. fe = format.Substring(format.IndexOf('.') + 1).Length;
  27. for (int i = 0; i < intlen + fe; i++)
  28. {
  29. if (i == 1 || i == 4)
  30. {
  31. e.Graphics.DrawLine(Pens.Blue, e.Bounds.Left + (i + 1) * spacewidth - 1, 0, e.Bounds.Left + (i + 1) * spacewidth - 1, gridControl.Height);
  32. }
  33. else if (i == 7)
  34. {
  35. e.Graphics.DrawLine(Pens.Red, e.Bounds.Left + (i + 1) * spacewidth - 1, 0, e.Bounds.Left + (i + 1) * spacewidth - 1, gridControl.Height);
  36. }
  37. else if (i == intlen + fe - 1)
  38. {
  39. 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);
  40. }
  41. else
  42. {
  43. e.Graphics.DrawLine(Pens.LightGray, e.Bounds.Left + (i + 1) * spacewidth - 1, 0, e.Bounds.Left + (i + 1) * spacewidth - 1, gridControl.Height);
  44. }
  45. }
  46.  
  47. var sf = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center };
  48.  
  49. //decimal v = e.CellValue == null || e.CellValue == DBNull.Value || e.CellValue.ToString() == "" ? 0 : Convert.ToDecimal(e.CellValue);
  50.  
  51. string s_int = format.Substring(0, format.IndexOf('.')); //((int)v).ToString();
  52. //两位小数
  53. string s_dec = format.ToString().Substring(format.ToString().IndexOf('.') + 1, fe);
  54. string s_value = s_int + s_dec;
  55. int a = 1;
  56. for (int i = s_value.Length - 1; i >= 0; i--)
  57. {
  58. //string ch = s_value[s_value.Length -i- 1].ToString();
  59. string ch = s_value[i].ToString();
  60. if (s_int == "0" && s_dec == "00") ch = "";
  61. int x = e.Bounds.Left + (intlen + fe - a) * spacewidth;
  62. int y = e.Bounds.Top;
  63. var rect = new RectangleF(x, y, spacewidth, e.Bounds.Height);
  64. e.Graphics.DrawString(ch, e.Column.AppearanceCell.Font, Brushes.Black, rect, sf);
  65. a++;
  66. }
  67. e.Handled = true;
  68.  
  69. }
  70. catch (Exception ex)
  71. {
  72. MsgBox.ShowError("输入金额过大!" + ex.Message);
  73. gridView1.SetRowCellValue(e.RowHandle, e.Column.FieldName, DBNull.Value);
  74. gridView1.FocusedColumn = e.Column;
  75. gridView1.ShowEditor();
  76. }
  77.  
  78. }
  79.  
  80. public void gridView1_CustomDrawColumnHeader(object sender, ColumnHeaderCustomDrawEventArgs e, GridControl showgrid, GridView gridView1, string type)
  81. {
  82. try
  83. {
  84. Pen penred = new Pen(Color.Red);
  85. Pen penblue = new Pen(Color.Blue);
  86. Pen pengray = new Pen(Color.LightGray);
  87. Pen fontpen = new Pen(Color.Black);
  88. int width = e.Bounds.Width;
  89. int spacewidth = width / 10; //计算格子宽度;一起10位数:8位整数 2位小数
  90. e.Painter.DrawObject(e.Info);
  91. 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);
  92. 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);
  93. string u = "千百十万千百十元角分";
  94. string ch = "";
  95. Pen temppen = pengray;
  96. Font font = new Font(e.Appearance.Font.FontFamily, (float)7.5);
  97. for (int i = 0; i < u.Length; i++)
  98. {
  99. ch = u[i].ToString();
  100.  
  101. if (i == 1 || i == 4)
  102. {
  103. temppen = penblue;
  104. }
  105. else if (i == 7)
  106. {
  107. temppen = penred;
  108. }
  109. else if (i == 9)
  110. {
  111. temppen = new Pen(Color.Black);
  112. }
  113. else
  114. {
  115. temppen = pengray;
  116. }
  117. e.Graphics.DrawString(ch, font, fontpen.Brush, e.Bounds.X + i * spacewidth, e.Bounds.Y + e.Bounds.Height / 2 + 1);
  118. 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);
  119. }
  120. e.Handled = true;
  121. }
  122. catch (Exception)
  123. {
  124. return; ;
  125. }
  126. }

汇总金额字体颜色控制

  1. private void gridView1_CustomDrawFooterCell(object sender, FooterCellCustomDrawEventArgs e)
  2. {
  3. if (e.Column == c0)
  4. {
  5. if (c0.SummaryText.Trim().Contains("借贷金额不平衡"))
  6. {
  7. AppearanceDefault footer = new AppearanceDefault(Color.Red, Color.Empty, new Font(AppearanceObject.DefaultFont, FontStyle.Bold));
  8. AppearanceHelper.Apply(e.Appearance, footer);
  9. }
  10. else
  11. {
  12. AppearanceDefault footer = new AppearanceDefault(Color.Green, Color.Empty, new Font(AppearanceObject.DefaultFont, FontStyle.Bold));
  13. AppearanceHelper.Apply(e.Appearance, footer);
  14. }
  15. }
  16. }

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

结束语

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

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. ret.data[0]._highlight = true iview table表格高亮

    ret.data[0]._highlight = true iview table表格高亮

  2. 个人项目(Word Count)

    一.Github项目地址 https://github.com/AllForward/GP_Homework/tree/master/个人项目 二.题目叙述 这个项目要求写一个命令行程序,模仿已有wc ...

  3. CompTIA Security+ 常见知识点

    前言: Security+ 认证是一种中立第三方认证,其发证机构为美国计算机行业协会CompTIA: 是和CISSP.CISA等共同包含在内的国际IT业热门认证之一,和CISSP偏重信息安全管理相比, ...

  4. SpringBoot 整合 MyCat 实现读写分离

    MyCat一个彻底开源的,面向企业应用开发的大数据库集群.基于阿里开源的Cobar产品而研发.能满足数据库数据大量存储:提高了查询性能.文章介绍如何实现MyCat连接MySQL实现主从分离,并集成Sp ...

  5. tensorflow 控制流操作,条件判断和循环操作

    Control flow operations: conditionals and loops When building complex models such as recurrent neura ...

  6. java面试基础篇-List

    一.ArrayList: 底层为数组实现,线程不安全,查询,修改快,增加删除慢, 数据结构:数组以0为下标依次连续进行存储 数组查询元素:根据下标查询就行 数组增加元素:如果需要给index为10的位 ...

  7. iOS 项目发布

    一.Apple开发者账号 1.1 开发者账号类型 个人级 公司级 企业级 公司和企业的可多人协作. 在苹果的开发者平台登录后,可在 People 界面邀请其他人员协作开发,邀请的人需要注册一个 app ...

  8. Java ArrayList自动扩容机制

    动态扩容 1.add(E e)方法中 ①  ensureCapacityInternal(size+1),确保内部容量,size是添加前数组内元素的数量 ②  elementData[size++] ...

  9. 纯html加css的键盘UI效果图

    先上效果图: 没有打字的功能,纯属是个界面图(一时无聊写的) 代码如下: <!DOCTYPE html> <html> <head> <meta charse ...

  10. 原生js判断手机端页面滚动停止

    var topValue = 0,// 上次滚动条到顶部的距离 interval = null;// 定时器 contactsList = document.getElementById(" ...