You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/CW/CwVouchersAddingInvoice.asp...

954 lines
61 KiB
C#

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using DSWeb.EntityDA;
using DSWeb.Models;
using JsonHelper;
using System.Xml;
namespace DSWeb.CW
{
public partial class CwVouchersAddingInvoice : System.Web.UI.Page
{
public string strHandle = "";
public string strGIDS = "";
T_ALL_DA T_ALL_DA = new T_ALL_DA();
public string strUserID;//用户GID
public string strCompanyID;//公司GID
public string strShowName;//用户显示名
public string strDeptName;//部门名称
protected void Page_Load(object sender, EventArgs e)
{
if (Session["USERID"] != null)
{
strUserID = Session["USERID"].ToString().Trim();
this.hdUserID.Value = strUserID.Trim();
}
else
{
Server.Transfer("~/Error/FriendError.aspx");
return;
}
if (Session["SHOWNAME"] != null)
{
strShowName = Session["SHOWNAME"].ToString();
}
if (Session["COMPANYID"] != null)
{
strCompanyID = Session["COMPANYID"].ToString();
}
if (Session["DEPTNAME"] != null)
{
strDeptName = Session["DEPTNAME"].ToString();
}
if (Request.QueryString["handle"] != null)
{
strHandle = Request.QueryString["handle"].ToString().Trim().ToLower();
}
if (Request.QueryString["gids"] != null)
{
strGIDS = Request.QueryString["gids"].ToString().Trim().ToLower();
}
//grid
if (!IsPostBack)
{
this.hd_comboPREPARED.Value = strShowName.Trim();
tbVOUDATE.Text = T_ALL_DA.GetStrSQL("rq", "select convert(char(10),getdate(),20) as rq");
tbRATE.Text = T_ALL_DA.GetStrSQL("VALUE", "select top 1 VALUE from currency_exchange where COMPANYID='" + strCompanyID + "' and ISDELETE=0 and [type]='common'");
}
//加载下拉框
Page.ClientScript.RegisterStartupScript(this.GetType(), "key0", "<script>initcomboPREPARED();</script>");
}
protected String getBSNO()
{
string strBSNO = Guid.NewGuid().ToString();
strBSNO = strBSNO.Replace("-", "");
strBSNO = "VOU" + strBSNO;
return strBSNO;
}
protected void btnEnter_Click(object sender, EventArgs e)
{
string strEXPLAN = "";
string sSQL = "";
int iResult = 0;
string zt = "";
if (cbISRATE.Checked == false && tbRATE.Text.Trim() == "")
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key1", "<script>alert('如果不“按照系统录入汇率”计算,则“凭证美元汇率”不允许为空!');</script>");
return;
}
//
if (strGIDS.Trim() != "")
{
//帐套设置
sSQL = "SELECT top 1 * from cw_design where AR<>'' and ARFC<>'' and MBINCOME<>'' and TMFCI<>'' and AMAR<>'' and AMARFC<>'' and AABWI<>'' and AMFCI<>''";
DataSet ds = T_ALL_DA.GetAllSQL(sSQL);
if (ds == null)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key1", "<script>alert('请先设置帐套信息!');</script>");
return;
}
//
string sGids = strGIDS.Trim().Replace(",", "','");
sGids = "'" + sGids.Trim() + "'";
//合并生成发票凭证
//if (ds.Tables[0].Rows[0]["ISMGSC"].ToString().Trim() == "True")
//{
// iResult = getSC(ds, sGids.Trim(), "", strEXPLAN, "", "", "", "");
// zt += iResult;
//}
//else
//{
string[] items = sGids.Trim().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
if (items.Length > 0)
{
for (int i = 0; i < items.Length; i++)
{
strEXPLAN = "";
sSQL = "select *";
sSQL += ", FAPCODE=(select top 1 FAPCODE from info_client where SHORTNAME=" + strHandle + ".CUSTOMERNAME)";
sSQL += ", FARCODE=(select top 1 FARCODE from info_client where SHORTNAME=" + strHandle + ".CUSTOMERNAME)";
sSQL += ", DEPTID=(select top 1 FINANCESOFTCODE from sys_dept where DEPTNAME=(select DEPTNAME from user_baseinfo where USERID=" + strHandle + ".APPLICANT) and LINKID='" + strCompanyID + "')";
sSQL += ", EMPLID=(select top 1 FINANCESOFTCODE from user_baseinfo where USERID in (select gid from [user] where ISDELETED=0 and SHOWNAME=" + strHandle + ".APPLICANT) and COMPANYNAME=(select [NAME] from [company] where GID='" + strCompanyID + "'))";
sSQL += " from " + strHandle + " where gid in(" + items[i].ToString().Trim() + ")";
DataSet ds5 = T_ALL_DA.GetAllSQL(sSQL);
if (ds5 != null)
{
//ISCLIENTNAME 是否客户名称
//ISCUSTNO 是否委托编号//发票单号
//ISMBLNO 是否主提单号//发票号
//ISVESSEL 是否船名
//ISVOYNO 是否航次
//ISCOTCODE 是否业务编号
//ISETD 是否航期
if (ds.Tables[0].Rows[0]["ISCLIENTNAME"].ToString().Trim() == "True")
{
strEXPLAN += " " + ds5.Tables[0].Rows[0]["CUSTOMERNAME"].ToString().Trim();
}
if (ds.Tables[0].Rows[0]["ISCUSTNO"].ToString().Trim() == "True")
{
//strEXPLAN += " " + ds5.Tables[0].Rows[0]["CUSTNO"].ToString().Trim();
strEXPLAN += " " + ds5.Tables[0].Rows[0]["INVOICENO"].ToString().Trim();
}
if (ds.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
{
strEXPLAN += " " + ds5.Tables[0].Rows[0]["MBLNO"].ToString().Trim();
}
if (ds.Tables[0].Rows[0]["ISVESSEL"].ToString().Trim() == "True" || ds.Tables[0].Rows[0]["ISVOYNO"].ToString().Trim() == "True")
{
//strEXPLAN += " " + ds5.Tables[0].Rows[0]["VESSELVOYAGE"].ToString().Trim();
}
iResult = getSC(ds, items[i].ToString().Trim(), "", strEXPLAN, ds5.Tables[0].Rows[0]["DEPTID"].ToString().Trim(), ds5.Tables[0].Rows[0]["EMPLID"].ToString().Trim(), "", ds5.Tables[0].Rows[0]["MBLNO"].ToString().Trim(), ds5.Tables[0].Rows[0]["INVOICENO"].ToString().Trim());
}
zt += "," + iResult;
}
}
//}
//
if (zt.IndexOf("-") > 0)
{
Response.Write("<script>alert('部分凭证生成出错!');history.back();</script>");
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "key3", "<script>alert('生成凭证成功!');window.opener.location.reload();window.close();history.back();</script>");
}
}
}
#region 生成凭证
/// <summary>
/// 生成凭证
/// </summary>
/// <param name="ds">帐套设置数据集</param>
/// <param name="sGids">发票编号</param>
/// <param name="strVESSEL">船名航次</param>
/// <param name="strEXPLAN">规则生成的摘要</param>
/// <returns></returns>
protected int getSC(DataSet ds, string sGids, string strVESSEL, string strEXPLAN, string strDEPTID, string strEMPLID, string strAPPLICANT, string strBLNO,string strINVNO)
{
#region 基本函数
string sSQL = "";
Decimal iAMTDR = 0;
//Decimal iAMTCR = 0;
int iResult = 0;
//差额主营业务收入
Decimal dRMBS = 0;
Decimal dRMBF = 0;
Decimal dUSDS = 0;
Decimal dUSDF = 0;
int n = 0;
Decimal dEXCHANGERATE =0;
#endregion
#region 其他常用科目设置
//其他常用科目设置 应收RMB
sSQL = "SELECT top 1 * from cw_accitems where ACCID='" + ds.Tables[0].Rows[0]["AR"].ToString().Trim() + "'";
DataSet ds2 = T_ALL_DA.GetAllSQL(sSQL);
//其他常用科目设置 应收USD
sSQL = "SELECT top 1 * from cw_accitems where ACCID='" + ds.Tables[0].Rows[0]["ARFC"].ToString().Trim() + "'";
DataSet ds6 = T_ALL_DA.GetAllSQL(sSQL);
//其他常用科目设置 收入RMB
sSQL = "SELECT top 1 * from cw_accitems where ACCID='" + ds.Tables[0].Rows[0]["MBINCOME"].ToString().Trim() + "'";
DataSet ds8 = T_ALL_DA.GetAllSQL(sSQL);
//其他常用科目设置 收入USD
sSQL = "SELECT top 1 * from cw_accitems where ACCID='" + ds.Tables[0].Rows[0]["TMFCI"].ToString().Trim() + "'";
DataSet ds10 = T_ALL_DA.GetAllSQL(sSQL);
//其他常用科目设置 空运应收RMB
sSQL = "SELECT top 1 * from cw_accitems where ACCID='" + ds.Tables[0].Rows[0]["AMAR"].ToString().Trim() + "'";
DataSet dsAMAR = T_ALL_DA.GetAllSQL(sSQL);
//其他常用科目设置 空运应收USD
sSQL = "SELECT top 1 * from cw_accitems where ACCID='" + ds.Tables[0].Rows[0]["AMARFC"].ToString().Trim() + "'";
DataSet dsAMARFC = T_ALL_DA.GetAllSQL(sSQL);
//其他常用科目设置 空运收入RMB
sSQL = "SELECT top 1 * from cw_accitems where ACCID='" + ds.Tables[0].Rows[0]["AABWI"].ToString().Trim() + "'";
DataSet dsAABWI = T_ALL_DA.GetAllSQL(sSQL);
//其他常用科目设置 空运收入USD
sSQL = "SELECT top 1 * from cw_accitems where ACCID='" + ds.Tables[0].Rows[0]["AMFCI"].ToString().Trim() + "'";
DataSet dsAMFCI = T_ALL_DA.GetAllSQL(sSQL);
#endregion
#region 摘要
//ISRPCLIENTNAME 是否收付客户名称
//ISRPCOTCODE 是否收付业务编号//发票单号
//ISRPETD 是否收付航期
//ISRPMBLNO 是否收付主提单号//发票号
//ISRPCUSTNO 是否收付委托编号
//ISRPVESSEL 是否收付船名
//ISRPVOYNO 是否收付航次
string strISEXPLAN = "";
//if (ds.Tables[0].Rows[0]["ISRPCLIENTNAME"].ToString().Trim() == "True")
//{
// strISEXPLAN += " " + ds.Tables[0].Rows[0]["CUSTOMERNAME"].ToString().Trim();
//}
if (ds.Tables[0].Rows[0]["ISCUSTNO"].ToString().Trim() == "True")
{
//strISEXPLAN += ",CUSTNO";
strISEXPLAN += ",INVOICENO";
}
if (ds.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
{
strISEXPLAN += ",MBLNO";
}
if (ds.Tables[0].Rows[0]["ISVESSEL"].ToString().Trim() == "True")
{
//strISEXPLAN += ",VESSEL";
}
if (ds.Tables[0].Rows[0]["ISVOYNO"].ToString().Trim() == "True")
{
//strISEXPLAN += ",VOYNO";
}
strISEXPLAN += ",OPLBNAME_HD";
#endregion
//
if (strHandle.Trim() == "ch_fee_invoice")
{
#region 语句
string strORDNO = getBSNO();
CwVouchersDA CwVouchersDA = new CwVouchersDA();
IList<CwVouitemsEntity> CwVouitemsEntities = new List<CwVouitemsEntity>();
//
//(CASE WHEN FEETYPE = 1 THEN '应收账款' ELSE '应付账款' END) as 类型 注:此发票凭证默认为'应收账款'
//,CUSTOMERNAME 客户名称
//,EXCHANGERATE 汇率
//,CURRENCY 币别`
//,SUM(AMOUNT) AS 金额
//,SUM(AMOUNT*EXCHANGERATE) AS 合计金额
if (cbISRATE.Checked == true)
{
sSQL = "SELECT FAPCODE,FARCODE,CUSTOMERNAME,EXCHANGERATE,CURRENCY,SUM(AMOUNT) AS je,SUM(AMOUNT*EXCHANGERATE) AS hj " + strISEXPLAN;
sSQL += " From VW_ch_fee_invoice WHERE 1=1 and gid in (" + sGids.Trim() + ") " + strVESSEL;
sSQL += " GROUP BY FAPCODE,FARCODE,CUSTOMERNAME,EXCHANGERATE,CURRENCY,INVOICECUSTNAME" + strISEXPLAN;
sSQL += " ORDER BY CURRENCY,CUSTOMERNAME" + strISEXPLAN;
}
else
{
sSQL = "SELECT FAPCODE,FARCODE,CUSTOMERNAME," + tbRATE.Text.Trim() + " as EXCHANGERATE,CURRENCY,SUM(AMOUNT) AS je,SUM(AMOUNT*" + tbRATE.Text.Trim() + ") AS hj " + strISEXPLAN;
sSQL += " From VW_ch_fee_invoice WHERE 1=1 and gid in (" + sGids.Trim() + ") " + strVESSEL;
sSQL += " GROUP BY FAPCODE,FARCODE,CUSTOMERNAME,EXCHANGERATE,CURRENCY,INVOICECUSTNAME" + strISEXPLAN;
sSQL += " ORDER BY CURRENCY,CUSTOMERNAME" + strISEXPLAN;
}
#endregion
DataSet ds1 = T_ALL_DA.GetAllSQL(sSQL);
if (ds1 != null)
{
#region 应收账款
for (int i = 0; i < ds1.Tables[0].Rows.Count; i++)
{
n = i;// +1;
CwVouitemsEntity CwVouitemsEntity = new CwVouitemsEntity();
//CwVouitemsEntity.GID 唯一编码 newid()
CwVouitemsEntity.ORDNO = strORDNO.Trim();
CwVouitemsEntity.ITEMNO = n;// 行号
CwVouitemsEntity.PACCID = "";//父级科目贷码
CwVouitemsEntity.PROPERTY = 0;//科目属性
CwVouitemsEntity.GRADE = 0;//科目级别
//
iAMTDR = iAMTDR + Decimal.Parse(ds1.Tables[0].Rows[i]["hj"].ToString().Trim());
if (ds1.Tables[0].Rows[i]["CURRENCY"].ToString().Trim() == "RMB")
{
#region RMB
CwVouitemsEntity.AMTDR = Decimal.Parse(ds1.Tables[0].Rows[i]["je"].ToString().Trim());//本位币借方金额(互斥)
CwVouitemsEntity.AMTCR = 0;//本位币贷方金额(互斥)
CwVouitemsEntity.ISFCY = false;//是否外币
CwVouitemsEntity.FCYNO = "RMB";//外币编号usd
CwVouitemsEntity.FCYDR = 0;//外币借方金额
CwVouitemsEntity.FCYCR = 0;//外币贷方金额
dRMBS += Decimal.Parse(ds1.Tables[0].Rows[i]["je"].ToString().Trim());//本位币借方金额(互斥)
if (ds1.Tables[0].Rows[i]["OPLBNAME_HD"].ToString().Trim() == "")//是否空运
{
#region 海运业务及其他业务(不包含空运)
CwVouitemsEntity.ACCID = ds.Tables[0].Rows[0]["AR"].ToString().Trim();//应收账款科目贷码
if (ds2 == null)
{
CwVouitemsEntity.ACCNAME = "";//科目名称
CwVouitemsEntity.ISDEPTACC = false;//核算部门,按规则设置生成
CwVouitemsEntity.ISEMPLACC = false;//核算人员,按规则设置生成
CwVouitemsEntity.ISCORPACC = false;//核算客户,按规则设置生成
CwVouitemsEntity.ISITEMACC = false;//核算项目,按规则设置生成
CwVouitemsEntity.DC = "D";//借方向
}
else
{
CwVouitemsEntity.ACCNAME = ds2.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
CwVouitemsEntity.ISDEPTACC = Boolean.Parse(ds2.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
CwVouitemsEntity.ISEMPLACC = Boolean.Parse(ds2.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
CwVouitemsEntity.ISCORPACC = Boolean.Parse(ds2.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
CwVouitemsEntity.ISITEMACC = Boolean.Parse(ds2.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
if (ds2.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
{
CwVouitemsEntity.DC = "D";//借方向
}
else
{
CwVouitemsEntity.DC = "C";//贷方向
}
}
#endregion
}
else
{
#region 空运业务
CwVouitemsEntity.ACCID = ds.Tables[0].Rows[0]["AMAR"].ToString().Trim();//应收账款科目贷码
if (dsAMAR == null)
{
CwVouitemsEntity.ACCNAME = "";//科目名称
CwVouitemsEntity.ISDEPTACC = false;//核算部门,按规则设置生成
CwVouitemsEntity.ISEMPLACC = false;//核算人员,按规则设置生成
CwVouitemsEntity.ISCORPACC = false;//核算客户,按规则设置生成
CwVouitemsEntity.ISITEMACC = false;//核算项目,按规则设置生成
CwVouitemsEntity.DC = "D";//借方向
}
else
{
CwVouitemsEntity.ACCNAME = dsAMAR.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
CwVouitemsEntity.ISDEPTACC = Boolean.Parse(dsAMAR.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
CwVouitemsEntity.ISEMPLACC = Boolean.Parse(dsAMAR.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
CwVouitemsEntity.ISCORPACC = Boolean.Parse(dsAMAR.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
CwVouitemsEntity.ISITEMACC = Boolean.Parse(dsAMAR.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
if (dsAMAR.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
{
CwVouitemsEntity.DC = "D";//借方向
}
else
{
CwVouitemsEntity.DC = "C";//贷方向
}
}
#endregion
}
#endregion
}
else if (ds1.Tables[0].Rows[i]["CURRENCY"].ToString().Trim() != "RMB")
{
#region USD
CwVouitemsEntity.AMTDR = Decimal.Parse(ds1.Tables[0].Rows[i]["hj"].ToString().Trim());//本位币借方金额(互斥)
CwVouitemsEntity.AMTCR = 0;//本位币贷方金额(互斥)
CwVouitemsEntity.ISFCY = true;//是否外币
CwVouitemsEntity.FCYNO = "USD";//外币编号usd
CwVouitemsEntity.FCYDR = Decimal.Parse(ds1.Tables[0].Rows[i]["je"].ToString().Trim());//外币借方金额
CwVouitemsEntity.FCYCR = 0;//外币贷方金额
dUSDS += Decimal.Parse(ds1.Tables[0].Rows[i]["je"].ToString().Trim());//本位币借方金额(互斥)
if (ds1.Tables[0].Rows[i]["OPLBNAME_HD"].ToString().Trim() == "")//是否空运
{
#region 海运业务及其他业务(不包含空运)
CwVouitemsEntity.ACCID = ds.Tables[0].Rows[0]["ARFC"].ToString().Trim();//应收账款外币科目贷码
if (ds6 == null)
{
CwVouitemsEntity.ACCNAME = "";//科目名称
CwVouitemsEntity.ISDEPTACC = false;//核算部门,按规则设置生成
CwVouitemsEntity.ISEMPLACC = false;//核算人员,按规则设置生成
CwVouitemsEntity.ISCORPACC = false;//核算客户,按规则设置生成
CwVouitemsEntity.ISITEMACC = false;//核算项目,按规则设置生成
CwVouitemsEntity.DC = "D";//借方向
}
else
{
CwVouitemsEntity.ACCNAME = ds6.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
CwVouitemsEntity.ISDEPTACC = Boolean.Parse(ds6.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
CwVouitemsEntity.ISEMPLACC = Boolean.Parse(ds6.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
CwVouitemsEntity.ISCORPACC = Boolean.Parse(ds6.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
CwVouitemsEntity.ISITEMACC = Boolean.Parse(ds6.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
if (ds6.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
{
CwVouitemsEntity.DC = "D";//借方向
}
else
{
CwVouitemsEntity.DC = "C";//贷方向
}
}
#endregion
}
else
{
#region 空运业务
CwVouitemsEntity.ACCID = ds.Tables[0].Rows[0]["AMARFC"].ToString().Trim();//应收账款外币科目贷码
if (dsAMARFC == null)
{
CwVouitemsEntity.ACCNAME = "";//科目名称
CwVouitemsEntity.ISDEPTACC = false;//核算部门,按规则设置生成
CwVouitemsEntity.ISEMPLACC = false;//核算人员,按规则设置生成
CwVouitemsEntity.ISCORPACC = false;//核算客户,按规则设置生成
CwVouitemsEntity.ISITEMACC = false;//核算项目,按规则设置生成
CwVouitemsEntity.DC = "D";//借方向
}
else
{
CwVouitemsEntity.ACCNAME = dsAMARFC.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
CwVouitemsEntity.ISDEPTACC = Boolean.Parse(dsAMARFC.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
CwVouitemsEntity.ISEMPLACC = Boolean.Parse(dsAMARFC.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
CwVouitemsEntity.ISCORPACC = Boolean.Parse(dsAMARFC.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
CwVouitemsEntity.ISITEMACC = Boolean.Parse(dsAMARFC.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
if (dsAMARFC.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
{
CwVouitemsEntity.DC = "D";//借方向
}
else
{
CwVouitemsEntity.DC = "C";//贷方向
}
}
#endregion
}
#endregion
}
#region 其他
CwVouitemsEntity.CORPID = ds1.Tables[0].Rows[i]["FARCODE"].ToString().Trim();//客户(系统)
CwVouitemsEntity.CUSTOMERNAME = ds1.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim();//客户(系统)
//
CwVouitemsEntity.FCYEXRATE = Decimal.Parse(ds1.Tables[0].Rows[i]["EXCHANGERATE"].ToString().Trim());//汇率
dEXCHANGERATE = Decimal.Parse(ds1.Tables[0].Rows[i]["EXCHANGERATE"].ToString().Trim());//汇率
CwVouitemsEntity.QTYUNIT = "";//数量包装单位
CwVouitemsEntity.QTYDR = 0;//借方数量
CwVouitemsEntity.QTYCR = 0;//贷方数量
CwVouitemsEntity.EXPLAN = strEXPLAN;//摘要,规则生成
CwVouitemsEntity.DEPTID = strDEPTID;//部门(系统)
CwVouitemsEntity.EMPLID = strEMPLID;//人员(系统)
CwVouitemsEntity.SALE = strAPPLICANT;//人员名称
CwVouitemsEntity.PITEMID = 0;//父级项目编号
CwVouitemsEntity.ITEMID = "0";//项目编号
CwVouitemsEntity.FIELD1 = "";//预留字段1
CwVouitemsEntity.FIELD2 = "";//预留字段2
CwVouitemsEntity.FIELD3 = "";//预留字段3
CwVouitemsEntity.FIELD4 = "";//预留字段4
CwVouitemsEntity.FIELD5 = "";//预留字段5
CwVouitemsEntity.FIELD6 = "";//预留字段6
CwVouitemsEntity.FIELD7 = "";//预留字段7
CwVouitemsEntity.FIELD8 = "";//预留字段8
CwVouitemsEntity.FIELD9 = "";//预留字段9
CwVouitemsEntity.FIELD10 = "";//预留字段10
if (ds.Tables[0].Rows[0]["ISVBM"].ToString().Trim() == "True")
{
CwVouitemsEntity.ISSYS = false;//是否手动录入
}
else
{
CwVouitemsEntity.ISSYS = true;//是否手动录入
}
CwVouitemsEntity.FSETTLCODE = "";//结算方式
CwVouitemsEntity.FSETTLENO = "";//财务辅助编号
CwVouitemsEntity.MODIFIEDUSER = strUserID;//最后一次更新操作人
CwVouitemsEntity.BLNO = strBLNO;//
//if (strBLNO.Trim() == "")
//{
// if (ds.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
// {
// CwVouitemsEntity.BLNO = ds1.Tables[0].Rows[i]["mblno"].ToString().Trim();//
// }
// if (ds.Tables[0].Rows[0]["ISCUSTNO"].ToString().Trim() == "True")
// {
// CwVouitemsEntity.BLNO = ds1.Tables[0].Rows[i]["INVOICENO"].ToString().Trim();//
// }
//}
if (ds.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
{
CwVouitemsEntity.BLNO = strBLNO;//
}
if (ds.Tables[0].Rows[0]["ISCUSTNO"].ToString().Trim() == "True")
{
CwVouitemsEntity.BLNO = strINVNO;//
}
#endregion
CwVouitemsEntities.Add(CwVouitemsEntity);
}
#endregion
#region 主营业务收入
//利润
Decimal dRMB = dRMBS - dRMBF;
Decimal dUSD = dUSDS - dUSDF;
//收入\成本 生成 全额\差额
Decimal strJie = dRMBS + dUSDS * dEXCHANGERATE;
Decimal strDai = dRMBF + dUSDF * dEXCHANGERATE;
if (ds.Tables[0].Rows[0]["ISTCOIIED"].ToString().Trim() == "True")//是否核算外币
{
#region 核算外币
for (int j = 0; j < ds1.Tables[0].Rows.Count; j++)
{
n = n + 1;
CwVouitemsEntity CwVouitemsEntity2 = new CwVouitemsEntity();
//CwVouitemsEntity2.GID 唯一编码 newid()
CwVouitemsEntity2.ORDNO = strORDNO.Trim();
CwVouitemsEntity2.ITEMNO = n;// 行号
CwVouitemsEntity2.PACCID = "";//父级科目贷码
CwVouitemsEntity2.PROPERTY = 0;//科目属性
CwVouitemsEntity2.GRADE = 0;//科目级别
//
if (ds1.Tables[0].Rows[j]["CURRENCY"].ToString().Trim() == "RMB")
{
#region RMB
CwVouitemsEntity2.AMTDR = 0;//本位币借方金额(互斥)
CwVouitemsEntity2.AMTCR = Decimal.Parse(ds1.Tables[0].Rows[j]["je"].ToString().Trim());//本位币贷方金额(互斥)
strDai = strDai + Decimal.Parse(ds1.Tables[0].Rows[j]["je"].ToString().Trim());
CwVouitemsEntity2.ISFCY = false;//是否外币
CwVouitemsEntity2.FCYNO = "RMB";//外币编号usd
CwVouitemsEntity2.FCYDR = 0;//外币借方金额
CwVouitemsEntity2.FCYCR = 0;//外币贷方金额
//dRMBS += Decimal.Parse(ds1.Tables[0].Rows[j]["je"].ToString().Trim());//本位币借方金额(互斥)
if (ds1.Tables[0].Rows[j]["OPLBNAME_HD"].ToString().Trim() == "")//是否空运
{
#region 海运业务及其他业务(不包含空运)
CwVouitemsEntity2.ACCID = ds.Tables[0].Rows[0]["MBINCOME"].ToString().Trim();//主营业务收入科目贷码
if (ds8 == null)
{
CwVouitemsEntity2.ACCNAME = "";//科目名称
CwVouitemsEntity2.ISDEPTACC = false;//核算部门,按规则设置生成
CwVouitemsEntity2.ISEMPLACC = false;//核算人员,按规则设置生成
CwVouitemsEntity2.ISCORPACC = false;//核算客户,按规则设置生成
CwVouitemsEntity2.ISITEMACC = false;//核算项目,按规则设置生成
CwVouitemsEntity2.DC = "C";//贷方向
}
else
{
CwVouitemsEntity2.ACCNAME = ds8.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
CwVouitemsEntity2.ISDEPTACC = Boolean.Parse(ds8.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
CwVouitemsEntity2.ISEMPLACC = Boolean.Parse(ds8.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
CwVouitemsEntity2.ISCORPACC = Boolean.Parse(ds8.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
CwVouitemsEntity2.ISITEMACC = Boolean.Parse(ds8.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
CwVouitemsEntity2.DC = "C";//贷方向
//if (ds8.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
//{
// CwVouitemsEntity2.DC = "D";//借方向
//}
//else
//{
// CwVouitemsEntity2.DC = "C";//贷方向
//}
}
#endregion
}
else
{
#region 空运业务
CwVouitemsEntity2.ACCID = ds.Tables[0].Rows[0]["AABWI"].ToString().Trim();//主营业务收入科目贷码
if (dsAABWI == null)
{
CwVouitemsEntity2.ACCNAME = "";//科目名称
CwVouitemsEntity2.ISDEPTACC = false;//核算部门,按规则设置生成
CwVouitemsEntity2.ISEMPLACC = false;//核算人员,按规则设置生成
CwVouitemsEntity2.ISCORPACC = false;//核算客户,按规则设置生成
CwVouitemsEntity2.ISITEMACC = false;//核算项目,按规则设置生成
CwVouitemsEntity2.DC = "C";//贷方向
}
else
{
CwVouitemsEntity2.ACCNAME = dsAABWI.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
CwVouitemsEntity2.ISDEPTACC = Boolean.Parse(dsAABWI.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
CwVouitemsEntity2.ISEMPLACC = Boolean.Parse(dsAABWI.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
CwVouitemsEntity2.ISCORPACC = Boolean.Parse(dsAABWI.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
CwVouitemsEntity2.ISITEMACC = Boolean.Parse(dsAABWI.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
CwVouitemsEntity2.DC = "C";//贷方向
//if (dsAABWI.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
//{
// CwVouitemsEntity2.DC = "D";//借方向
//}
//else
//{
// CwVouitemsEntity2.DC = "C";//贷方向
//}
}
#endregion
}
#endregion
}
else if (ds1.Tables[0].Rows[j]["CURRENCY"].ToString().Trim() != "RMB")
{
#region USD
CwVouitemsEntity2.AMTDR = 0;//本位币借方金额(互斥)
CwVouitemsEntity2.AMTCR = Decimal.Parse(ds1.Tables[0].Rows[j]["hj"].ToString().Trim());//本位币贷方金额(互斥)
strDai = strDai + Decimal.Parse(ds1.Tables[0].Rows[j]["hj"].ToString().Trim());
CwVouitemsEntity2.ISFCY = true;//是否外币
CwVouitemsEntity2.FCYNO = "USD";//外币编号usd
CwVouitemsEntity2.FCYDR = 0;//外币借方金额
CwVouitemsEntity2.FCYCR = Decimal.Parse(ds1.Tables[0].Rows[j]["je"].ToString().Trim());//外币贷方金额
//dUSDS += Decimal.Parse(ds1.Tables[0].Rows[j]["je"].ToString().Trim());//本位币借方金额(互斥)
if (ds1.Tables[0].Rows[j]["OPLBNAME_HD"].ToString().Trim() == "")//是否空运
{
#region 海运业务及其他业务(不包含空运)
CwVouitemsEntity2.ACCID = ds.Tables[0].Rows[0]["TMFCI"].ToString().Trim();//主营收入外币科目贷码
if (ds10 == null)
{
CwVouitemsEntity2.ACCNAME = "";//科目名称
CwVouitemsEntity2.ISDEPTACC = false;//核算部门,按规则设置生成
CwVouitemsEntity2.ISEMPLACC = false;//核算人员,按规则设置生成
CwVouitemsEntity2.ISCORPACC = false;//核算客户,按规则设置生成
CwVouitemsEntity2.ISITEMACC = false;//核算项目,按规则设置生成
CwVouitemsEntity2.DC = "C";//贷方向
}
else
{
CwVouitemsEntity2.ACCNAME = ds10.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
CwVouitemsEntity2.ISDEPTACC = Boolean.Parse(ds10.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
CwVouitemsEntity2.ISEMPLACC = Boolean.Parse(ds10.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
CwVouitemsEntity2.ISCORPACC = Boolean.Parse(ds10.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
CwVouitemsEntity2.ISITEMACC = Boolean.Parse(ds10.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
CwVouitemsEntity2.DC = "C";//贷方向
//if (ds10.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
//{
// CwVouitemsEntity2.DC = "D";//借方向
//}
//else
//{
// CwVouitemsEntity2.DC = "C";//贷方向
//}
}
#endregion
}
else
{
#region 空运业务
CwVouitemsEntity2.ACCID = ds.Tables[0].Rows[0]["AMFCI"].ToString().Trim();//主营收入外币科目贷码
if (dsAMFCI == null)
{
CwVouitemsEntity2.ACCNAME = "";//科目名称
CwVouitemsEntity2.ISDEPTACC = false;//核算部门,按规则设置生成
CwVouitemsEntity2.ISEMPLACC = false;//核算人员,按规则设置生成
CwVouitemsEntity2.ISCORPACC = false;//核算客户,按规则设置生成
CwVouitemsEntity2.ISITEMACC = false;//核算项目,按规则设置生成
CwVouitemsEntity2.DC = "C";//贷方向
}
else
{
CwVouitemsEntity2.ACCNAME = dsAMFCI.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
CwVouitemsEntity2.ISDEPTACC = Boolean.Parse(dsAMFCI.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
CwVouitemsEntity2.ISEMPLACC = Boolean.Parse(dsAMFCI.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
CwVouitemsEntity2.ISCORPACC = Boolean.Parse(dsAMFCI.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
CwVouitemsEntity2.ISITEMACC = Boolean.Parse(dsAMFCI.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
CwVouitemsEntity2.DC = "C";//贷方向
//if (dsAMFCI.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
//{
// CwVouitemsEntity2.DC = "D";//借方向
//}
//else
//{
// CwVouitemsEntity2.DC = "C";//贷方向
//}
}
#endregion
}
#endregion
}
#region 其他
CwVouitemsEntity2.CORPID = "";// strEMPLID;//人员(系统)本来应该放客户
CwVouitemsEntity2.CUSTOMERNAME = "";// strAPPLICANT;//人员(系统)本来应该放客户
//
CwVouitemsEntity2.FCYEXRATE = Decimal.Parse(ds1.Tables[0].Rows[j]["EXCHANGERATE"].ToString().Trim());//汇率
dEXCHANGERATE = Decimal.Parse(ds1.Tables[0].Rows[j]["EXCHANGERATE"].ToString().Trim());//汇率
CwVouitemsEntity2.QTYUNIT = "";//数量包装单位
CwVouitemsEntity2.QTYDR = 0;//借方数量
CwVouitemsEntity2.QTYCR = 0;//贷方数量
CwVouitemsEntity2.EXPLAN = strEXPLAN;//摘要,规则生成
CwVouitemsEntity2.DEPTID = strDEPTID;//部门(系统)
CwVouitemsEntity2.EMPLID = strEMPLID;//人员(系统)
CwVouitemsEntity2.SALE = strAPPLICANT;//人员名称
CwVouitemsEntity2.PITEMID = 0;//父级项目编号
CwVouitemsEntity2.ITEMID = "0";//项目编号
CwVouitemsEntity2.FIELD1 = "";//预留字段1
CwVouitemsEntity2.FIELD2 = "";//预留字段2
CwVouitemsEntity2.FIELD3 = "";//预留字段3
CwVouitemsEntity2.FIELD4 = "";//预留字段4
CwVouitemsEntity2.FIELD5 = "";//预留字段5
CwVouitemsEntity2.FIELD6 = "";//预留字段6
CwVouitemsEntity2.FIELD7 = "";//预留字段7
CwVouitemsEntity2.FIELD8 = "";//预留字段8
CwVouitemsEntity2.FIELD9 = "";//预留字段9
CwVouitemsEntity2.FIELD10 = "";//预留字段10
if (ds.Tables[0].Rows[0]["ISVBM"].ToString().Trim() == "True")
{
CwVouitemsEntity2.ISSYS = false;//是否手动录入
}
else
{
CwVouitemsEntity2.ISSYS = true;//是否手动录入
}
CwVouitemsEntity2.FSETTLCODE = "";//结算方式
CwVouitemsEntity2.FSETTLENO = "";//财务辅助编号
CwVouitemsEntity2.MODIFIEDUSER = strUserID;//最后一次更新操作人
CwVouitemsEntity2.BLNO = strBLNO;//
if (ds.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
{
CwVouitemsEntity2.BLNO = strBLNO;//
}
if (ds.Tables[0].Rows[0]["ISCUSTNO"].ToString().Trim() == "True")
{
CwVouitemsEntity2.BLNO = strINVNO;//
}
#endregion
CwVouitemsEntities.Add(CwVouitemsEntity2);
}
#endregion
}
else
{
#region 不 核算外币
//收入
n = n + 1;
CwVouitemsEntity CwVouitemsEntity2 = new CwVouitemsEntity();
//CwVouitemsEntity2.GID 唯一编码 newid()
CwVouitemsEntity2.ORDNO = strORDNO.Trim();
CwVouitemsEntity2.ITEMNO = n;// 行号
CwVouitemsEntity2.PACCID = "";//父级科目贷码
CwVouitemsEntity2.PROPERTY = 0;//科目属性
CwVouitemsEntity2.GRADE = 0;//科目级别
CwVouitemsEntity2.AMTDR = 0;//本位币借方金额(互斥)
CwVouitemsEntity2.AMTCR = dRMBS + (dUSDS * dEXCHANGERATE);//本位币贷方金额(互斥)
strDai = strDai + dRMBS + (dUSDS * dEXCHANGERATE);
CwVouitemsEntity2.ISFCY = false;//是否外币
CwVouitemsEntity2.FCYNO = "RMB";//外币编号usd
CwVouitemsEntity2.FCYDR = 0;//外币借方金额
CwVouitemsEntity2.FCYCR = 0;//外币贷方金额
if (ds1.Tables[0].Rows[0]["OPLBNAME_HD"].ToString().Trim() == "")//是否空运
{
#region 海运业务及其他业务(不包含空运)
CwVouitemsEntity2.ACCID = ds.Tables[0].Rows[0]["MBINCOME"].ToString().Trim();//主营业务收入科目贷码
if (ds8 == null)
{
CwVouitemsEntity2.ACCNAME = "";//科目名称
CwVouitemsEntity2.ISDEPTACC = false;//核算部门,按规则设置生成
CwVouitemsEntity2.ISEMPLACC = false;//核算人员,按规则设置生成
CwVouitemsEntity2.ISCORPACC = false;//核算客户,按规则设置生成
CwVouitemsEntity2.ISITEMACC = false;//核算项目,按规则设置生成
CwVouitemsEntity2.DC = "C";//贷方向
}
else
{
CwVouitemsEntity2.ACCNAME = ds8.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
CwVouitemsEntity2.ISDEPTACC = Boolean.Parse(ds8.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
CwVouitemsEntity2.ISEMPLACC = Boolean.Parse(ds8.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
CwVouitemsEntity2.ISCORPACC = Boolean.Parse(ds8.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
CwVouitemsEntity2.ISITEMACC = Boolean.Parse(ds8.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
CwVouitemsEntity2.DC = "C";//贷方向
//if (ds8.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
//{
// CwVouitemsEntity2.DC = "D";//借方向
//}
//else
//{
// CwVouitemsEntity2.DC = "C";//贷方向
//}
}
#endregion
}
else
{
#region 空运业务
CwVouitemsEntity2.ACCID = ds.Tables[0].Rows[0]["AABWI"].ToString().Trim();//主营业务收入科目贷码
if (dsAABWI == null)
{
CwVouitemsEntity2.ACCNAME = "";//科目名称
CwVouitemsEntity2.ISDEPTACC = false;//核算部门,按规则设置生成
CwVouitemsEntity2.ISEMPLACC = false;//核算人员,按规则设置生成
CwVouitemsEntity2.ISCORPACC = false;//核算客户,按规则设置生成
CwVouitemsEntity2.ISITEMACC = false;//核算项目,按规则设置生成
CwVouitemsEntity2.DC = "C";//贷方向
}
else
{
CwVouitemsEntity2.ACCNAME = dsAABWI.Tables[0].Rows[0]["ACCNAME"].ToString().Trim();//科目名称
CwVouitemsEntity2.ISDEPTACC = Boolean.Parse(dsAABWI.Tables[0].Rows[0]["ISDEPTACC"].ToString().Trim());//核算部门,按规则设置生成
CwVouitemsEntity2.ISEMPLACC = Boolean.Parse(dsAABWI.Tables[0].Rows[0]["ISEMPLACC"].ToString().Trim());//核算人员,按规则设置生成
CwVouitemsEntity2.ISCORPACC = Boolean.Parse(dsAABWI.Tables[0].Rows[0]["ISCORPACC"].ToString().Trim());//核算客户,按规则设置生成
CwVouitemsEntity2.ISITEMACC = Boolean.Parse(dsAABWI.Tables[0].Rows[0]["ISITEMACC"].ToString().Trim());//核算项目,按规则设置生成
CwVouitemsEntity2.DC = "C";//贷方向
//if (dsAABWI.Tables[0].Rows[0]["DC"].ToString().Trim() == "借")
//{
// CwVouitemsEntity2.DC = "D";//借方向
//}
//else
//{
// CwVouitemsEntity2.DC = "C";//贷方向
//}
}
#endregion
}
#region 其他
CwVouitemsEntity2.CORPID = "";// strEMPLID;//人员(系统)本来应该放客户
CwVouitemsEntity2.CUSTOMERNAME = "";// strAPPLICANT;//人员(系统)本来应该放客户
CwVouitemsEntity2.FCYEXRATE = 1;//汇率
//dEXCHANGERATE = Decimal.Parse(ds1.Tables[0].Rows[j]["EXCHANGERATE"].ToString().Trim());//汇率
CwVouitemsEntity2.QTYUNIT = "";//数量包装单位
CwVouitemsEntity2.QTYDR = 0;//借方数量
CwVouitemsEntity2.QTYCR = 0;//贷方数量
CwVouitemsEntity2.EXPLAN = strEXPLAN;//摘要,规则生成
CwVouitemsEntity2.DEPTID = strDEPTID;//部门(系统)
CwVouitemsEntity2.EMPLID = strEMPLID;//人员(系统)
CwVouitemsEntity2.SALE = strAPPLICANT;//人员名称
CwVouitemsEntity2.PITEMID = 0;//父级项目编号
CwVouitemsEntity2.ITEMID = "0";//项目编号
CwVouitemsEntity2.FIELD1 = "";//预留字段1
CwVouitemsEntity2.FIELD2 = "";//预留字段2
CwVouitemsEntity2.FIELD3 = "";//预留字段3
CwVouitemsEntity2.FIELD4 = "";//预留字段4
CwVouitemsEntity2.FIELD5 = "";//预留字段5
CwVouitemsEntity2.FIELD6 = "";//预留字段6
CwVouitemsEntity2.FIELD7 = "";//预留字段7
CwVouitemsEntity2.FIELD8 = "";//预留字段8
CwVouitemsEntity2.FIELD9 = "";//预留字段9
CwVouitemsEntity2.FIELD10 = "";//预留字段10
if (ds.Tables[0].Rows[0]["ISVBM"].ToString().Trim() == "True")
{
CwVouitemsEntity2.ISSYS = false;//是否手动录入
}
else
{
CwVouitemsEntity2.ISSYS = true;//是否手动录入
}
CwVouitemsEntity2.FSETTLCODE = "";//结算方式
CwVouitemsEntity2.FSETTLENO = "";//财务辅助编号
CwVouitemsEntity2.MODIFIEDUSER = strUserID;//最后一次更新操作人
CwVouitemsEntity2.BLNO = strBLNO;//
if (ds.Tables[0].Rows[0]["ISMBLNO"].ToString().Trim() == "True")
{
CwVouitemsEntity2.BLNO = strBLNO;//
}
if (ds.Tables[0].Rows[0]["ISCUSTNO"].ToString().Trim() == "True")
{
CwVouitemsEntity2.BLNO = strINVNO;//
}
#endregion
CwVouitemsEntities.Add(CwVouitemsEntity2);
#endregion
}
#endregion
#region 插入主表
string rq = tbVOUDATE.Text.Trim();
CwVouchersEntity CwVouchersEntity = new CwVouchersEntity();
CwVouchersEntity.ORDNO = strORDNO.Trim();//唯一编码 newid() varchar (36)
CwVouchersEntity.VOUDATE = DateTime.Parse(rq.Trim());//凭证日期="";//datetime="";// 
CwVouchersEntity.ACCYEAR = rq.Trim().Substring(0, 4);//年="";//int="";// 
int iM1 = rq.Trim().IndexOf("-") + 1;
int iM2 = rq.Trim().LastIndexOf("-");
CwVouchersEntity.ACCMONTH = rq.Trim().Substring(iM1, iM2 - iM1);//月="";//int="";// 
string strVOUNO = getVOUNO(rq.Trim().Substring(0, 4), rq.Trim().Substring(iM1, iM2 - iM1));
CwVouchersEntity.VOUNO = strVOUNO;//月初清零 varchar (16)
if (iM2 - iM1 == 1)
{
strVOUNO = rq.Trim().Substring(0, 4) + "0" + rq.Trim().Substring(iM1, iM2 - iM1) + strVOUNO;
}
else
{
strVOUNO = rq.Trim().Substring(0, 4) + rq.Trim().Substring(iM1, iM2 - iM1) + strVOUNO;
}
CwVouchersEntity.VOUALLNO = strVOUNO;//月初清零 varchar (16)
CwVouchersEntity.VKNO = ds.Tables[0].Rows[0]["TVW"].ToString().Trim();//凭证字="";//varchar="";//(8)
CwVouchersEntity.ATTACHS = int.Parse(ds.Tables[0].Rows[0]["AFFIXNO"].ToString().Trim());//附件(单据)数="";//int="";// 
CwVouchersEntity.AMTDR = strJie;// iAMTDR;//本位币借方="";//numeric(18, 2)="";// 
CwVouchersEntity.AMTCR = strDai;//iAMTDR;// iAMTCR;//本位币贷方="";//numeric(18, 2)="";// 
CwVouchersEntity.FCY = "";//是否含有外币科目="";//varchar="";//(1)
CwVouchersEntity.QTY = "";//是否含有数量科目="";//varchar="";//(1)
CwVouchersEntity.VOUPROP = "";//凭证属性="";//varchar="";//(1)
//CwVouchersEntity.PREPARED = T_ALL_DA.GetStrSQL("FINANCESOFTCODE", "select top 1 FINANCESOFTCODE from user_baseinfo where USERID in (select top 1 gid from [user] where SHOWNAME='" + this.hd_comboPREPARED.Value.Trim() + "' and ISDELETED=0)");//制单人="";//varchar="";//(10)
CwVouchersEntity.PREPARED = this.hd_comboPREPARED.Value.Trim();//制单人="";//varchar="";//(10)
CwVouchersEntity.CHECKED = "";//审核人="";//varchar="";//(10)
CwVouchersEntity.ENTERED = "";//记账人="";//varchar="";//(10)
CwVouchersEntity.ERRMSG = "";//错误信息="";//varchar="";//(6)
CwVouchersEntity.ISDELETE = false;//是否废除="";//bit="";//Y
CwVouchersEntity.DELETEUSER = "";//废除操作人="";//Varchar(36)="";//Y
//CwVouchersEntity.DELETETIME="";//废除时间="";//Datetime="";//Y
#endregion
//生成入库
string strSel = " and gid in(" + sGids + ") " + strVESSEL;
iResult = CwVouchersDA.setInsertAll(CwVouchersEntity, CwVouitemsEntities, "" + strHandle + "", strVOUNO, strSel, strUserID, 3);
}
else
{
iResult = -1;
}
}
else
{
iResult = -1;
}
return iResult;
}
#endregion
protected String getVOUNO(string strY, string strM)
{
string sVOUNO = "";
string strVOUNO = "select top 1 VOUNO from cw_vouchers where ACCYEAR='" + strY + "' and ACCMONTH='" + strM + "' order by convert(decimal(10),VOUNO) desc";
strVOUNO = T_ALL_DA.GetStrSQL("VOUNO", strVOUNO);
if (strVOUNO.Trim() == "")
{
strVOUNO = "0001";
}
else
{
sVOUNO = (int.Parse(strVOUNO) + 1).ToString().Trim();
strVOUNO = sVOUNO;
for (int i = 0; i < 4 - sVOUNO.Length; i++)
{
strVOUNO = "0" + strVOUNO;
}
}
return strVOUNO;
}
//
}
}