.NET汇出指定类型文档方法
if (this.chkPS.Checked)
{
//从PS_detail取数据
///Modified By Rain 2014-02-06
/// 汇出PS档案 脚本查询确实一个栏位:Description
/// 这里加上。但是为了不影响原来代码 这里进行新增一个方法 名字加上后缀:_WithDescription
DataSet ds = _EPDA.GetPSData_WithDescription(this.ddlFormType.SelectedItem.Value, Convert.ToDateTime(this.CalendarPickerAccountingDate.DateValue).ToString(CommonDefine.DATE_SHORT_FORMAT),
Convert.ToDateTime(this.CalendarPickerPaymentDate.DateValue).ToString(CommonDefine.DATE_SHORT_FORMAT));
if (ds.Tables[0].Rows.Count > 0)
{
#region 产生分录档文件
string fileNameFix = "TWZ900EPEIML2";
if (this.ddlFormType.SelectedItem.Value.Equals(CommonDefine.FORM_KIND.CARRFORM2))
{
//fileNameFix = "TWZ904EPEIML2";edit by Rain --檔名TWZ900EPEIML2调整为TWZ904PCEIML2
fileNameFix = "TWZ904EPEIML2";
}
//读取流水号
string s2 = _DA.GetSerialNo(1);
string fileName = string.Format("{0}{1}{2}.FT",
DateTime.Today.ToString(CommonDefine.DATE_FORMAT_LIST), fileNameFix, s2);
string svrPath = _DA.GetDataFromConfig(this.ddlFormType.SelectedItem.Value, "upload_path_ps");
StreamWriter sw = new StreamWriter(svrPath + "\\" + fileName, false, System.Text.Encoding.GetEncoding(950));
#region 表头
sw.WriteLine(string.Format("# FILE NAME :{0}", fileName));
sw.WriteLine(string.Format("# FILE REFERENCE : {0}{1}{2}", DateTime.Now.ToString(CommonDefine.DATETIME_FORMAT_LIST), fileNameFix, s2));
sw.WriteLine("# VERSION NUMBER : 1.00");
sw.WriteLine(string.Format("# GENERATION DATE :{0} E08", DateTime.Now.ToString(CommonDefine.DATETIME_FORMAT_LIST)));
sw.WriteLine("# CHARACTER SET : ENG");
#endregion
#region 表身
StringBuilder str;
int j = 0;
#region 循环产生每条数据
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
dr = ds.Tables[0].Rows[i];
//如果AMOUNT_DEBIT,AMOUNT_CREDIT均无值,则不产生这笔资料 Add by Rain2014.05.29
if (Convert.ToInt32(dr["AMOUNT_DEBIT"]) == 0 && Convert.ToInt32(dr["AMOUNT_CREDIT"]) == 0)
{
continue;
}
//如果AMOUNT_DEBIT,AMOUNT_CREDIT均有值,则产生两笔资料
else if (Convert.ToInt32(dr["AMOUNT_DEBIT"]) > 0 && Convert.ToInt32(dr["AMOUNT_CREDIT"]) > 0)
{
int temp_AMOUNT_DEBIT = Convert.ToInt32(dr["AMOUNT_DEBIT"]);
int temp_AMOUNT_CREDIT = Convert.ToInt32(dr["AMOUNT_CREDIT"]);
dr["AMOUNT_CREDIT"] = 0;
sw.WriteLine(getPsString(dr));
j++;
dr["AMOUNT_DEBIT"] = 0;
dr["AMOUNT_CREDIT"] = temp_AMOUNT_CREDIT;
sw.WriteLine(getPsString(dr));
j++;
}
else
{
sw.WriteLine(getPsString(dr));
j++;
}
}//end for
#endregion
#endregion
#region 表尾
//sw.WriteLine(string.Format("# ROWS COUNT : {0}", ds.Tables[0].Rows.Count.ToString()));
sw.WriteLine(string.Format("# ROWS COUNT : {0}", j.ToString()));
#endregion
sw.Close();
#endregion
}
else
{
ShowAlert(localize.NoData);
exportSuc = false;
return;
}
}
if (this.ddlFormType.SelectedItem.Value.Equals(CommonDefine.FORM_KIND.CARRFORM3))
{
if (this.chkBank.Checked)
{
//从EP_BankDetail取数据
DataSet dsBank = _EPBKDA.GetBankFileData(this.CalendarPickerAccountingDate.SelectedDate.ToString(CommonDefine.DATE_SHORT_FORMAT),
this.CalendarPickerPaymentDate.SelectedDate.ToString(CommonDefine.DATE_SHORT_FORMAT));
if (dsBank.Tables[0].Rows.Count > 0)
{
#region 产生银行档文件
string fileNameFix = "Epe-BK-";
//读取流水号
string s2 = _DA.GetSerialNo(6);
string fileName = string.Format("{0}{1}{2}.csv",
fileNameFix, DateTime.Today.ToString(CommonDefine.DATE_FORMAT_LIST), s2);
string svrPath = _DA.GetDataFromConfig(this.ddlFormType.SelectedItem.Value, "upload_path_bank");
StreamWriter sw = new StreamWriter(svrPath + "\\" + fileName, false, System.Text.Encoding.GetEncoding(950));
#region 表头
//计算总金额
int sum = 0;
for (int i = 0; i < dsBank.Tables[0].Rows.Count; i++)
{
sum += Convert.ToInt32(dsBank.Tables[0].Rows[i]["SumTravelFee"]);
}
sw.WriteLine(string.Format("發放筆數;{0};差旅費發放總額;{1};;", dsBank.Tables[0].Rows.Count.ToString(), sum.ToString()));
sw.WriteLine(string.Format("員工編號;發放方式;計算日期;差旅費金額;手續費;實發金額"));
#endregion
#region 表身
StringBuilder str;
#region 循环产生每条数据
for (int i = 0; i < dsBank.Tables[0].Rows.Count; i++)
{
dr = dsBank.Tables[0].Rows[i];
str = new StringBuilder();
//員工編號
str.Append(string.Format("{0};", dr["EMP_NO"].ToString()));
//發放方式
str.Append(string.Format("{0};", dr["PAY_TERM"].ToString()));
//計算日期
str.Append(string.Format("{0};", Convert.ToDateTime(dr["PAYDATE"]).ToString("yyyy/M/d")));
//差旅費金額
str.Append(string.Format("{0};", dr["SumTravelFee"].ToString()));
//手續費
str.Append(string.Format("{0};", dr["SumRemittanceFee"].ToString()));
//實發金額
str.Append(dr["SUMACTUALFEE"].ToString());
sw.WriteLine(str.ToString());
}
#endregion
#endregion
#region 表尾
sw.Close();
#endregion
#endregion
}
else
{
ShowAlert(localize.NoData);
exportSuc = false;
return;
}
}
}
//.txt
if (this.chkChkVAT.Checked)
{
#region 产生媒体档(Check VAT)
//读取流水号
string VATs2 = _DA.GetSerialNo(9);
//导出文件前先更新流水号
DataSet dsVAT = _EPDA.GetVATData(this.ddlFormType.SelectedItem.Value, Convert.ToDateTime(this.CalendarPickerAccountingDate.DateValue).ToString(CommonDefine.DATE_SHORT_FORMAT),
Convert.ToDateTime(this.CalendarPickerPaymentDate.DateValue).ToString(CommonDefine.DATE_SHORT_FORMAT), "7");
int reCount = 0;
for (int i = 0; i < dsVAT.Tables.Count; i++)
{
if (dsVAT.Tables[i].Rows.Count > 0)
{
reCount = reCount + 1;
}
}
if (reCount > 0)
{
//add by Rain 根据FORM_KIND区分fileName,若为CARRFORM2则为VAT -PCE ,若为CARRFORM3 则为VAT-EPE
string fileNameIndex = "VAT-EPE-";
if (this.ddlFormType.SelectedItem.Value.Equals(CommonDefine.FORM_KIND.CARRFORM2))
{
fileNameIndex = "VAT-PCE-";
}
for (int i = 0; i < dsVAT.Tables.Count; i++)
{
if (dsVAT.Tables[i].Rows.Count > 0)
{
string VATfileName = string.Format("{0}{1}{2}_{3}.txt", fileNameIndex,
DateTime.Today.ToString(CommonDefine.DATE_FORMAT_LIST), VATs2, dsVAT.Tables[i].Rows[0]["Chr_VatBInvoice"].ToString());
string svrPathVAT = _DA.GetDataFromConfig(this.ddlFormType.SelectedItem.Value, "upload_path_checkvat");
StreamWriter swVAT = new StreamWriter(svrPathVAT + "\\" + VATfileName, false, System.Text.Encoding.GetEncoding(950));
CreateCheckVAT(dsVAT.Tables[i], swVAT);
swVAT.Close();
}
}
}
else
{
ShowAlert(localize.NoData);
exportSuc = false;
return;
}
#endregion
}