序言

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

如何去实现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);
}
}
}

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

结束语

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

最新文章

  1. 【Java每日一题】20161226
  2. 关于Java占用内存的研究
  3. c语言编译器(linux平台下安装c语言环境)一
  4. 单例模式中的多线程分析synchronized
  5. sql查询所有表以及表名的模糊查询
  6. 【flash】关于flash的制作透明gif的一个小技巧
  7. 安装DirectX SDK时出现Error Code:s1023 的解决方案
  8. Android 架构【转】
  9. HDU ACM 1098 Ignatius&amp;#39;s puzzle
  10. node 使用koa2 异步读文件
  11. 把网站打包快速在线生成ios app的正确方法
  12. .net 超长URL请求返回404错误-解决方法
  13. git 每次push和pull都需要提交密码
  14. python-day18 JS正则,组件BootStrap、EasyUI、JQueryUI1,插件轮播,django
  15. 解决chrome浏览器在win8下没有注册类的问题
  16. 视角同步NewViewTarget
  17. myEclips 中的项目复制重命名
  18. 禁用滚动视图ListView、ViewPager、ScrollView、HorizontalScrollView、WebView边界颜色渐变
  19. Centos6.5安装phpldapadmin
  20. 【bzoj3142】[Hnoi2013]数列 数学

热门文章

  1. 3.python正则匹配不到内容时消耗大量内存
  2. 工作中常用到的Java集合类有哪些?
  3. 新文预览 | IoU-aware Single-stage Object Detector for Accurate Localization
  4. thinkphp 前后端分离
  5. [IROS 2018]Semantic Mapping with Simultaneous Object Detection and Localization
  6. 【短道速滑一】OpenCV中cvResize函数使用双线性插值缩小图像到长宽大小一半时速度飞快(比最近邻还快)之异象解析和自我实现。
  7. 企业级自动化部署方案——ansible实现tomcat自动安装和配置
  8. ASP.NET Core AutoWrapper 自定义响应输出
  9. effective-java学习笔记---优先使用泛型方法30
  10. 从本地方法栈看到jni调用