举例:
生成供应商协配验收单
生成的文件对应
每个门店的店号不同
Voucher1
select '2010-03-31' , '转' , '0' , '0' , '2010-03-31' + '/' + '1243' + '供应商协配验收单' , '1243' , CONVERT(varchar(100), sum(OutCost)) , '0' , '0' , '0' , '0' ,'' ,'','', '201','','','' from FDXPH where FormDate >= '2010-03-01' and FormDate <= '2010-03-31' AND ShopCode = 001 StringBuilder strSql = new StringBuilder(); strSql.Append("select @EndDate , '转' , '0' , '0' ,"); strSql.Append("@EndDate + '/' + '1243' + '供应商协配验收单', '1243' ,"); strSql.Append(" CONVERT(varchar(100), sum(OutCost)) , '0' , '0' , '0' , '0' ,'' ,'','','',"); strSql.Append(" @CwStoreNo,'','',''"); strSql.Append(" FROM FDXPH "); strSql.Append(" where FormDate >= @StartDate "); strSql.Append(" and FormDate <= @EndDate "); strSql.Append(" AND ShopCode = @StoreNo"); SqlParameter[] parameters = { new SqlParameter("@EndDate", SqlDbType.Char,10), new SqlParameter("@CwStoreNo", SqlDbType.Char,3), new SqlParameter("@StartDate", SqlDbType.Char,10), new SqlParameter("@StoreNo", SqlDbType.Char,3)}; parameters[0].Value = EndDate; parameters[1].Value = CwStoreNo; parameters[2].Value = StartDate; parameters[3].Value = StoreNo; return DbHelperSQL.Query(strSql.ToString(), parameters);
voucher2
select '2010-03-31' , '转' , '0' , '0' , '2010-03-31' + '/' + '1243' + '供应商协配验收单' , '212103' , CONVERT(varchar(100),(round(sum(Cost),2)-round(sum(OutCost),2))) , '0' , '0' , '0' , '0' , '',' ', '','' , '','' , '' from FDXPH where FormDate >= '2010-03-01' and FormDate <= '2010-03-31' AND ShopCode = 001
VOUCHER3 单据明细
select '2010-03-31' , '转' , '0' , '0' , FDXPH.FormDate + '/' + FDXPH.YFormNo + '供应商协配验收单','212102' , '0' , CONVERT(varchar(100),round(FDXPH.Cost, 2)),'0','0', '0','','','' ,'','','', FDXPH.CustCode from FDXPH where FormDate >= '2010-03-01' And FormDate <= '2010-03-31' AND ShopCode = 001
协配采购接口生成的主要特点
///财务店号是普通店号+200
CwStoreNo = (int.Parse(StoreNo) + 200).ToString();
///薛佳岳添加为了使数据小数达到平衡
float v1=0, v2=0,v3=0;
foreach (DataRow dr in mytable.Rows)
{
v1 = v1 + float.Parse(dr[6].ToString());
v2 = v2 + float.Parse(dr[7].ToString());
}
v3 = v1 - v2;
///注意这里保存位小数
string tmp1= (float.Parse(mytablg()), 2);
}
v3 = Math.Round((v1 - v2),2);
///注意这里 更新在内存数据表中更新某一个数值
///保存2位小数
string tmp1 = (double.Parse(mytable.Rows[2][7].ToString()) + v3).ToString("F2");
mytable.Rows[2][7] = tmp1;
dataGridView1.DataSource = mytable;
.net C#导出带逗号分隔符的TXT文件
#region 导出 用来生成带 逗号分隔的TXT文件 private void button2_Click(object sender, EventArgs e) { if (dataGridView1.DataSource == null) { MessageBox.Show("没有需要导出的数据!"); return; } SaveFileDialog sfg = new SaveFileDialog(); sfg.Filter = "文本文件(*.txt)|*.txt"; DialogResult result = sfg.ShowDialog(); if (result == DialogResult.OK) { string fileName = sfg.FileName; DataTable dt = dataGridView1.DataSource as DataTable; if (dt != null) { SaveDataToCVS(dt, fileName); } } } private void SaveDataToCVS(DataTable dt, string fileName) { using (StreamWriter sw = new StreamWriter(fileName, false, Encoding.Default)) { string line; ///xuejiayue 2010-08月添加 为了适应用友格式 第一行的规定如下 line = "填制凭证,V800"; sw.WriteLine(line); foreach (DataRow dr in dt.Rows) { line = GenerateLine(dr); sw.WriteLine(line); } } } private string GenerateLine(DataRow dr) { string retLine = string.Empty; string field = string.Empty; int i = -1; int maxco = dr.Table.Columns.Count; foreach (DataColumn dc in dr.Table.Columns) { field = dr[dc.ColumnName].ToString(); i = dc.Ordinal; if (field.IndexOf('"') >= 0) { field = field.Replace("/"", "/"/""); } if (field.IndexOf(',') >= 0 || field.IndexOf('"') >= 0) { field = "/"" + field + "/""; } ///薛佳岳添加就是为了最后一列不添加逗号 if (i < maxco - 1) { retLine += field + ","; } else { retLine += field; } field = string.Empty; } return retLine; } #endregion
注意要用到
using System.IO;
using System.Collections;
using System.Text.RegularExpressions;
using System.Globalization;