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/Areas/Account/DAL/ChMonthClose/ChMonthCloseDAL.cs

447 lines
26 KiB
C#

3 years ago
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Text;
using DSWeb.MvcShipping.Models.MsChFee;
using DSWeb.MvcShipping.Models.MsOpAmend;
using HcUtility.Comm;
using HcUtility.Core;
using System.Data.SqlClient;
using WebSqlHelper;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.EntityDA;
using DSWeb.Areas.Account.Models.MsOpBill;
using DSWeb.Areas.CommMng.Models;
using DSWeb.Areas.CommMng.DAL;
using DSWeb.MvcShipping.DAL.MsChFeeDAL;
using DSWeb.MvcShipping.DAL.MsSysParamSet;
using DSWeb.MvcShipping.DAL.MsInfoClient;
using DSWeb.Areas.Account.Models.ChMonthClose;
namespace DSWeb.MvcShipping.DAL.ChMonthCloseDAL
{
public class ChMonthCloseDAL
{
#region 查询费用数据
static public Period GetData(string condition,string companyid)
{
var strSql = new StringBuilder();
strSql.Append("SELECT TOP 1 PERIOD,PYEAR,PMONTH,FDAY,TDAY,CLOSED,CLOSEUSER,CLOSEDATE,COMPANYID ");
strSql.Append(",(select ShowName from [user] where GID=PERIOD.CLOSEUSER) as CLOSEUSERREF");
strSql.Append(" from PERIOD where companyid='" + companyid + "' or companyid='ALL'");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" AND " + condition);
}
strSql.Append(" ORDER BY PERIOD DESC ");
var list = SetData(strSql);
if (list.Count > 0)
return GetNewData(list[0].PYEAR,list[0].PMONTH,list[0].FDAY,list[0].TDAY,companyid,list[0].PERIOD);
Period data = new Period();
return data;
}
private static List<Period> SetData(StringBuilder strSql)
{
var bodyList = new List<Period>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
Period data = new Period();
#region Set DB data to Object
data.PERIOD = Convert.ToString(reader["PERIOD"]);
data.PYEAR = Convert.ToInt16(reader["PYEAR"]);
data.PMONTH = Convert.ToInt16(reader["PMONTH"]);
data.FDAY = Convert.ToString(reader["FDAY"]);
data.TDAY = Convert.ToDateTime(reader["TDAY"]).ToString("yyyy-MM-dd");
data.CLOSED = Convert.ToString(reader["CLOSED"]);
data.CLOSEUSER = Convert.ToString(reader["CLOSEUSER"]);
data.CLOSEUSERREF = Convert.ToString(reader["CLOSEUSERREF"]);
data.CLOSEDATE = Convert.ToString(reader["CLOSEDATE"]);
data.COMPANYID = Convert.ToString(reader["COMPANYID"]);
#endregion
bodyList.Add(data);
}
reader.Close();
}
return bodyList;
}
static public Period GetNewData(int pyear, int pmonth, string fday, string tday, string companyid, string closeperiod)
{
int tmonth = 0;
int tyear = 0;
var closetype="会计期间";
if (pmonth == 12)
{
tmonth = 1;
tyear = pyear + 1;
}
else {
tyear = pyear;
tmonth = pmonth + 1;
}
var amonth = tmonth.ToString();
if (amonth.Length == 1)
amonth ="0"+amonth;
var periodday = DateTime.Now;
Period data = new Period();
var MONTHCLOSEDATE = MsSysParamSetDAL.GetData("PARAMNAME='MONTHCLOSEDATE'");
if (MONTHCLOSEDATE.PARAMVALUE != "0" && MONTHCLOSEDATE.PARAMVALUE != "")
{
periodday = Convert.ToDateTime(tyear.ToString() + "-" + amonth +"-"+ MONTHCLOSEDATE.PARAMVALUE);
data.CLOSEDAY = Convert.ToInt16(MONTHCLOSEDATE.PARAMVALUE);
}
else
{
periodday = Convert.ToDateTime(tyear.ToString() + "-" + amonth + "-01").AddMonths(1).AddDays(-1);
}
var MONTHCLOSEDATETYPE = MsSysParamSetDAL.GetData("PARAMNAME='MONTHCLOSEDATETYPE'");
if (MONTHCLOSEDATETYPE.PARAMVALUE == "1") closetype = "业务日期";
data.PERIOD = tyear.ToString()+"-"+ amonth;
data.PYEAR = tyear;
data.PMONTH = tmonth;
data.FDAY = Convert.ToDateTime(tday).AddDays(1).ToString("yyyy-MM-dd");
data.TDAY = periodday.ToString("yyyy-MM-dd");
data.COMPANYID = companyid;
data.CLOSEDATETYPE = closetype;
data.CLOSEPERIOD = closeperiod;
return data;
}
#endregion
public static DBResult MonthClose(Period period, string closetype, string companyid, string userid)
{
var result = new DBResult();
var aoffyear = period.PYEAR;
var aoffmonth = period.PMONTH;
var upyear = 0; var upmonth = 0;
var sSQL = "";
if (aoffmonth == 1)
{
upyear = aoffyear - 1;
upmonth = 12;
}
else {
upyear = aoffyear;
upmonth = aoffmonth-1;
}
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
var modb = new ModelObjectDB();
if (closetype == "-1")
{
var strupmonth = upmonth.ToString();
if (strupmonth.Length == 1)
strupmonth = "0" + strupmonth;
//Period upperiod = new Period();
//upperiod.PERIOD = upyear.ToString()+"-"+strupmonth;
//upperiod.PYEAR = upyear;
//upperiod.PMONTH = upmonth;
string blDelSQLPERIOD = "delete from PERIOD where PERIOD='" + upyear.ToString() + "-" + strupmonth+"'";
if (period.SUBCOMP != "")
blDelSQLPERIOD = blDelSQLPERIOD + " and COMPANYID='" + companyid + "'";
bool bl = T_ALL_DA.GetExecuteSqlCommand(blDelSQLPERIOD);
var blUpSQL = " insert into sys_log(GID,NAME,LOGTYPE,LOGTIME,LOGCONTENT,CREATEUSER) values(NEWID(),'" + upyear.ToString() + "-" + strupmonth + "','月末反结转','" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "','" + upyear.ToString() + "-" + strupmonth + "','" + userid + "')";
bl = T_ALL_DA.GetExecuteSqlCommand(blUpSQL);
if (bl)
{
string blDelSQL = "delete from ch_custbalance where year=" + upyear.ToString() + " and month=" + strupmonth.ToString();
if (period.SUBCOMP != "")
blDelSQL = blDelSQL + " and CORPID='" + companyid + "'";
bl = T_ALL_DA.GetExecuteSqlCommand(blDelSQL);
}
result.Success=bl;
return result;
}
period.CLOSEDATE = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
period.CLOSEUSER = userid;
period.DbOperationType = DbOperationType.DbotIns;
period.CLOSED = "T";
if (period.SUBCOMP != "")
period.COMPANYID = companyid;
else period.COMPANYID = "ALL";
result = modb.Save(period);
try
{
string blDelSQL2 = "delete from ch_custbalance where year=" + aoffyear.ToString() + " and month=" + aoffmonth.ToString();
if (period.SUBCOMP != "")
blDelSQL2 = blDelSQL2 + " and CORPID='" + companyid + "'";
bool bl2 = T_ALL_DA.GetExecuteSqlCommand(blDelSQL2);
string blSQL = "INSERT INTO ch_custbalance ([YEAR],[MONTH],[CUSTOMERNAME],[SALE],[BSSOURCE],[BSSOURCEDETAIL],[OPLBNAME],[CORPID],[SALEDEPT],[CURRENCY],";
blSQL += " [UPMONTHDRBAL],[MONTHDR],[MONTHDRSTL],[MONTHDRBAL],";
blSQL += "[UPMONTHTTLDRBAL],[MONTHTTLDR],[MONTHTTLDRSTL],[MONTHTTLDRBAL],[UPMONTHCRBAL],[MONTHCR],[MONTHCRSTL],[MONTHCRBAL],";
blSQL += "[UPMONTHTTLCRBAL],[MONTHTTLCR],[MONTHTTLCRSTL],[MONTHTTLCRBAL])";
blSQL += " SELECT '" + aoffyear.ToString() + "','" + aoffmonth.ToString() + "',CUSTOMERNAME,SALE,BSSOURCE,BSSOURCEDETAIL,OPLBNAME,CORPID,SALEDEPT,CURRENCY,";
blSQL += " MONTHDRBAL,0,0,MONTHDRBAL,";
blSQL += "MONTHTTLDRBAL,0,0,MONTHTTLDRBAL,MONTHCRBAL,0,0,MONTHCRBAL,";
blSQL += "MONTHTTLCRBAL,0,0,MONTHTTLCRBAL from ch_custbalance";
blSQL += " WHERE YEAR=" + upyear.ToString() + " AND MONTH=" + upmonth.ToString();
if (period.SUBCOMP != "")
blSQL += " and CORPID='" + companyid + "'";
bool blInsert = T_ALL_DA.GetExecuteSqlCommand(blSQL);
#region 更新应收账款
sSQL = "SELECT c.CUSTOMERNAME,c.FEETYPE,c.CURRENCY,c.EXCHANGERATE,b.BSSOURCE,b.BSSOURCEDETAIL,b.SALE,b.OPLBNAME,b.SALEDEPT,b.CORPID,sum(isnull(c.AMOUNT,0)) AMOUNT,sum(isnull(c.AMOUNT*c.EXCHANGERATE,0)) TTLAMOUNT";
sSQL += " FROM ch_fee c,v_op_bill b WHERE b.BSNO=c.BSNO AND c.AMOUNT<>0 ";
sSQL += " AND b.ACCDATE='" + period.PERIOD + "' AND b.FEESTATUS=1 ";
if (period.SUBCOMP != "")
sSQL += " and b.CORPID = '" + companyid + "'";
sSQL += " GROUP BY c.CUSTOMERNAME,c.FEETYPE,c.CURRENCY,c.EXCHANGERATE,b.BSSOURCE,b.BSSOURCEDETAIL,b.SALE,b.OPLBNAME,b.SALEDEPT,b.CORPID";
sSQL += " ORDER BY c.CUSTOMERNAME,c.FEETYPE,c.CURRENCY,c.EXCHANGERATE,b.BSSOURCE,b.BSSOURCEDETAIL,b.SALE,b.OPLBNAME,b.SALEDEPT,b.CORPID";
DataSet dsAP = T_ALL_DA.GetAllSQL(sSQL);
string sNum = "";
if (dsAP != null)
{
for (int i = 0; i < dsAP.Tables[0].Rows.Count; i++)
{
sSQL = "SELECT COUNT(*) as inum from ch_custbalance where YEAR=" + aoffyear.ToString() + " AND MONTH=" + aoffmonth.ToString() + " AND CORPID='" + dsAP.Tables[0].Rows[i]["CORPID"].ToString().Trim() + "' and CUSTOMERNAME='" + dsAP.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim() + "'";
sSQL += " and BSSOURCE='" + dsAP.Tables[0].Rows[i]["BSSOURCE"].ToString().Trim() + "' and BSSOURCEDETAIL='" + dsAP.Tables[0].Rows[i]["BSSOURCEDETAIL"].ToString().Trim() + "'";
sSQL += " and SALE='" + dsAP.Tables[0].Rows[i]["SALE"].ToString().Trim() + "' and OPLBNAME='" + dsAP.Tables[0].Rows[i]["OPLBNAME"].ToString().Trim() + "'";
sSQL += " and SALEDEPT='" + dsAP.Tables[0].Rows[i]["SALEDEPT"].ToString().Trim() + "' and CURRENCY='" + dsAP.Tables[0].Rows[i]["CURRENCY"].ToString().Trim() + "' ";
sNum = T_ALL_DA.GetStrSQL("inum", sSQL);
if (sNum == "" || sNum == "0")
{
blSQL = "INSERT INTO ch_custbalance ([YEAR],[MONTH],[CUSTOMERNAME],[SALE],[BSSOURCE],[BSSOURCEDETAIL],[OPLBNAME],[CORPID],[SALEDEPT],CURRENCY,";
blSQL += " [UPMONTHDRBAL],[MONTHDR],[MONTHDRSTL],[MONTHDRBAL],";
blSQL += "[UPMONTHTTLDRBAL],[MONTHTTLDR],[MONTHTTLDRSTL],[MONTHTTLDRBAL],[UPMONTHCRBAL],[MONTHCR],[MONTHCRSTL],[MONTHCRBAL],";
blSQL += "[UPMONTHTTLCRBAL],[MONTHTTLCR],[MONTHTTLCRSTL],[MONTHTTLCRBAL])";
blSQL += " VALUES('" + aoffyear.ToString() + "','" + aoffmonth.ToString() + "','" + dsAP.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim() + "',";
blSQL += "'" + dsAP.Tables[0].Rows[i]["SALE"].ToString().Trim() + "','" + dsAP.Tables[0].Rows[i]["BSSOURCE"].ToString().Trim() + "','" + dsAP.Tables[0].Rows[i]["BSSOURCEDETAIL"].ToString().Trim() + "',";
blSQL += "'" + dsAP.Tables[0].Rows[i]["OPLBNAME"].ToString().Trim() + "','" + dsAP.Tables[0].Rows[i]["CORPID"].ToString().Trim() + "','" + dsAP.Tables[0].Rows[i]["SALEDEPT"].ToString().Trim() + "','" + dsAP.Tables[0].Rows[i]["CURRENCY"].ToString().Trim() + "',";
if (dsAP.Tables[0].Rows[i]["FEETYPE"].ToString().Trim() == "1")
{
blSQL += "0," + dsAP.Tables[0].Rows[i]["AMOUNT"].ToString().Trim() + ",0," + dsAP.Tables[0].Rows[i]["AMOUNT"].ToString().Trim() + ",";
blSQL += "0," + dsAP.Tables[0].Rows[i]["TTLAMOUNT"].ToString().Trim() + ",0," + dsAP.Tables[0].Rows[i]["TTLAMOUNT"].ToString().Trim() + ",0,0,0,0,";
blSQL += "0,0,0,0)";
}
else
{
blSQL += "0,0,0,0,";
blSQL += "0,0,0,0,0," + dsAP.Tables[0].Rows[i]["AMOUNT"].ToString().Trim() + ",0," + dsAP.Tables[0].Rows[i]["AMOUNT"].ToString().Trim() + ",";
blSQL += "0," + dsAP.Tables[0].Rows[i]["TTLAMOUNT"].ToString().Trim() + ",0," + dsAP.Tables[0].Rows[i]["TTLAMOUNT"].ToString().Trim() + ")";
}
blInsert = T_ALL_DA.GetExecuteSqlCommand(blSQL);
}
else
{
blSQL = "UPDATE ch_custbalance SET ";
if (dsAP.Tables[0].Rows[i]["FEETYPE"].ToString().Trim() == "1")
{
blSQL += "MONTHDR=MONTHDR+" + dsAP.Tables[0].Rows[i]["AMOUNT"].ToString().Trim() + ",MONTHDRBAL=MONTHDRBAL+" + dsAP.Tables[0].Rows[i]["AMOUNT"].ToString().Trim() + "";
blSQL += ",MONTHTTLDR=MONTHTTLDR+" + dsAP.Tables[0].Rows[i]["TTLAMOUNT"].ToString().Trim() + ",MONTHTTLDRBAL=MONTHTTLDRBAL+" + dsAP.Tables[0].Rows[i]["TTLAMOUNT"].ToString().Trim() + "";
}
else
{
blSQL += "MONTHCR=MONTHCR+" + dsAP.Tables[0].Rows[i]["AMOUNT"].ToString().Trim() + ",MONTHCRBAL=MONTHCRBAL+" + dsAP.Tables[0].Rows[i]["AMOUNT"].ToString().Trim() + "";
blSQL += ",MONTHTTLCR=MONTHTTLCR+" + dsAP.Tables[0].Rows[i]["TTLAMOUNT"].ToString().Trim() + ",MONTHTTLCRBAL=MONTHTTLCRBAL+" + dsAP.Tables[0].Rows[i]["TTLAMOUNT"].ToString().Trim() + "";
}
blSQL += " where YEAR=" + aoffyear.ToString() + " AND MONTH=" + aoffmonth.ToString() + " AND CORPID='" + dsAP.Tables[0].Rows[i]["CORPID"].ToString().Trim() + "' and CUSTOMERNAME='" + dsAP.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim() + "'";
blSQL += " and BSSOURCE='" + dsAP.Tables[0].Rows[i]["BSSOURCE"].ToString().Trim() + "' and BSSOURCEDETAIL='" + dsAP.Tables[0].Rows[i]["BSSOURCEDETAIL"].ToString().Trim() + "'";
blSQL += " and SALE='" + dsAP.Tables[0].Rows[i]["SALE"].ToString().Trim() + "' and OPLBNAME='" + dsAP.Tables[0].Rows[i]["OPLBNAME"].ToString().Trim() + "'";
blSQL += " and SALEDEPT='" + dsAP.Tables[0].Rows[i]["SALEDEPT"].ToString().Trim() + "' and CURRENCY='" + dsAP.Tables[0].Rows[i]["CURRENCY"].ToString().Trim() + "' ";
blInsert = T_ALL_DA.GetExecuteSqlCommand(blSQL);
}
}
}
#endregion
#region 更新实收实付
sSQL = "SELECT CUSTOMERNAME,FEETYPE,ORIGCURRENCY CURRENCY,ORIGEXCHANGERATE EXCHANGERATE,BSSOURCE,BSSOURCEDETAIL,SALE,OPLBNAME,SALEDEPT,CORPID,sum(isnull(ORIGAMOUNT,0)) AMOUNT,sum(isnull(ORIGAMOUNT*ORIGEXCHANGERATE,0)) TTLAMOUNT";
sSQL += " FROM v_fee_do_settlement_bs WHERE ORIGAMOUNT<>0 ";
sSQL += " AND SETTLETIME>='" + period.FDAY + "' AND SETTLETIME<='" + period.TDAY + " 23:59:59'";
if (period.SUBCOMP != "")
sSQL += " and CORPID = '" + companyid + "'";
// sSQL += " AND CUSTOMERNAME='青岛中孚国际物流'";
sSQL += " GROUP BY CUSTOMERNAME,FEETYPE,ORIGCURRENCY,ORIGEXCHANGERATE,BSSOURCE,BSSOURCEDETAIL,SALE,OPLBNAME,SALEDEPT,CORPID";
sSQL += " ORDER BY CUSTOMERNAME,FEETYPE,ORIGCURRENCY,ORIGEXCHANGERATE,BSSOURCE,BSSOURCEDETAIL,SALE,OPLBNAME,SALEDEPT,CORPID";
dsAP = T_ALL_DA.GetAllSQL(sSQL);
if (dsAP != null)
{
for (int i = 0; i < dsAP.Tables[0].Rows.Count; i++)
{
sSQL = "SELECT COUNT(*) as inum from ch_custbalance where YEAR=" + aoffyear.ToString() + " AND MONTH=" + aoffmonth.ToString() + " AND CORPID='" + dsAP.Tables[0].Rows[i]["CORPID"].ToString().Trim() + "' and CUSTOMERNAME='" + dsAP.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim() + "'";
sSQL += " and BSSOURCE='" + dsAP.Tables[0].Rows[i]["BSSOURCE"].ToString().Trim() + "' and BSSOURCEDETAIL='" + dsAP.Tables[0].Rows[i]["BSSOURCEDETAIL"].ToString().Trim() + "'";
sSQL += " and SALE='" + dsAP.Tables[0].Rows[i]["SALE"].ToString().Trim() + "' and OPLBNAME='" + dsAP.Tables[0].Rows[i]["OPLBNAME"].ToString().Trim() + "'";
sSQL += " and SALEDEPT='" + dsAP.Tables[0].Rows[i]["SALEDEPT"].ToString().Trim() + "' and CURRENCY='" + dsAP.Tables[0].Rows[i]["CURRENCY"].ToString().Trim() + "'";
sNum = T_ALL_DA.GetStrSQL("inum", sSQL);
if (sNum == "" || sNum == "0")
{
blSQL = "INSERT INTO ch_custbalance ([YEAR],[MONTH],[CUSTOMERNAME],[SALE],[BSSOURCE],[BSSOURCEDETAIL],[OPLBNAME],[CORPID],CURRENCY,[SALEDEPT],";
blSQL += " [UPMONTHDRBAL],[MONTHDR],[MONTHDRSTL],[MONTHDRBAL],";
blSQL += "[UPMONTHTTLDRBAL],[MONTHTTLDR],[MONTHTTLDRSTL],[MONTHTTLDRBAL],[UPMONTHCRBAL],[MONTHCR],[MONTHCRSTL],[MONTHCRBAL],";
blSQL += "[UPMONTHTTLCRBAL],[MONTHTTLCR],[MONTHTTLCRSTL],[MONTHTTLCRBAL])";
blSQL += " VALUES('" + aoffyear.ToString() + "','" + aoffmonth.ToString() + "','" + dsAP.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim() + "',";
blSQL += "'" + dsAP.Tables[0].Rows[i]["SALE"].ToString().Trim() + "','" + dsAP.Tables[0].Rows[i]["BSSOURCE"].ToString().Trim() + "','" + dsAP.Tables[0].Rows[i]["BSSOURCEDETAIL"].ToString().Trim() + "',";
blSQL += "'" + dsAP.Tables[0].Rows[i]["OPLBNAME"].ToString().Trim() + "','" + dsAP.Tables[0].Rows[i]["CORPID"].ToString().Trim() + "','" + dsAP.Tables[0].Rows[i]["CURRENCY"].ToString().Trim() + "','" + dsAP.Tables[0].Rows[i]["SALEDEPT"].ToString().Trim() + "',";
if (dsAP.Tables[0].Rows[i]["FEETYPE"].ToString().Trim() == "1")
{
if (Convert.ToDecimal(dsAP.Tables[0].Rows[i]["AMOUNT"].ToString()) > 0)
{
blSQL += "0,0," + dsAP.Tables[0].Rows[i]["AMOUNT"].ToString().Trim() + ",-" + dsAP.Tables[0].Rows[i]["AMOUNT"].ToString().Trim() + ",";
blSQL += "0,0," + dsAP.Tables[0].Rows[i]["TTLAMOUNT"].ToString().Trim() + ",-" + dsAP.Tables[0].Rows[i]["TTLAMOUNT"].ToString().Trim() + ",0,0,0,0,";
blSQL += "0,0,0,0)";
}
else {
var amount = System.Math.Abs(Convert.ToDecimal(dsAP.Tables[0].Rows[i]["AMOUNT"].ToString()));
var ttlamount = System.Math.Abs(Convert.ToDecimal(dsAP.Tables[0].Rows[i]["TTLAMOUNT"].ToString()));
blSQL += "0,0,-" + amount.ToString().Trim() + "," + amount.ToString().Trim() + ",";
blSQL += "0,0,-" + ttlamount.ToString().Trim() + "," + ttlamount.ToString().Trim() + ",0,0,0,0,";
blSQL += "0,0,0,0)";
}
}
else
{
if (Convert.ToDecimal(dsAP.Tables[0].Rows[i]["AMOUNT"].ToString()) > 0)
{
blSQL += "0,0,0,0,";
blSQL += "0,0,0,0,0,0," + dsAP.Tables[0].Rows[i]["AMOUNT"].ToString().Trim() + ",-" + dsAP.Tables[0].Rows[i]["AMOUNT"].ToString().Trim() + ",";
blSQL += "0,0," + dsAP.Tables[0].Rows[i]["TTLAMOUNT"].ToString().Trim() + ",-" + dsAP.Tables[0].Rows[i]["TTLAMOUNT"].ToString().Trim() + ")";
}
else {
var amount = System.Math.Abs(Convert.ToDecimal(dsAP.Tables[0].Rows[i]["AMOUNT"].ToString()));
var ttlamount = System.Math.Abs(Convert.ToDecimal(dsAP.Tables[0].Rows[i]["TTLAMOUNT"].ToString()));
blSQL += "0,0,0,0,";
blSQL += "0,0,0,0,0,0,-" + amount.ToString().Trim() + "," + amount.ToString().Trim() + ",";
blSQL += "0,0,-" + ttlamount.ToString().Trim() + "," + ttlamount.ToString().Trim() + ")";
}
}
blInsert = T_ALL_DA.GetExecuteSqlCommand(blSQL);
}
else
{
blSQL = "UPDATE ch_custbalance SET ";
if (dsAP.Tables[0].Rows[i]["FEETYPE"].ToString().Trim() == "1")
{
if (Convert.ToDecimal(dsAP.Tables[0].Rows[i]["AMOUNT"].ToString()) > 0)
{
blSQL += "MONTHDRSTL=MONTHDRSTL+" + dsAP.Tables[0].Rows[i]["AMOUNT"].ToString().Trim() + ",MONTHDRBAL=MONTHDRBAL-" + dsAP.Tables[0].Rows[i]["AMOUNT"].ToString().Trim() + "";
blSQL += ",MONTHTTLDRSTL=MONTHTTLDRSTL+" + dsAP.Tables[0].Rows[i]["TTLAMOUNT"].ToString().Trim() + ",MONTHTTLDRBAL=MONTHTTLDRBAL-" + dsAP.Tables[0].Rows[i]["TTLAMOUNT"].ToString().Trim() + "";
}
else
{
var amount = System.Math.Abs(Convert.ToDecimal(dsAP.Tables[0].Rows[i]["AMOUNT"].ToString()));
var ttlamount = System.Math.Abs(Convert.ToDecimal(dsAP.Tables[0].Rows[i]["TTLAMOUNT"].ToString()));
blSQL += "MONTHDRSTL=MONTHDRSTL-" + amount.ToString().Trim() + ",MONTHDRBAL=MONTHDRBAL+" + amount.ToString().Trim() + "";
blSQL += ",MONTHTTLDRSTL=MONTHTTLDRSTL-" + ttlamount.ToString().Trim() + ",MONTHTTLDRBAL=MONTHTTLDRBAL+" + ttlamount.ToString().Trim() + "";
}
}
else
{
if (Convert.ToDecimal(dsAP.Tables[0].Rows[i]["AMOUNT"].ToString()) > 0)
{
blSQL += "MONTHCRSTL=MONTHCRSTL+" + dsAP.Tables[0].Rows[i]["AMOUNT"].ToString().Trim() + ",MONTHCRBAL=MONTHCRBAL-" + dsAP.Tables[0].Rows[i]["AMOUNT"].ToString().Trim() + "";
blSQL += ",MONTHTTLCRSTL=MONTHTTLCRSTL+" + dsAP.Tables[0].Rows[i]["TTLAMOUNT"].ToString().Trim() + ",MONTHTTLCRBAL=MONTHTTLCRBAL-" + dsAP.Tables[0].Rows[i]["TTLAMOUNT"].ToString().Trim() + "";
}
else
{
var amount = System.Math.Abs(Convert.ToDecimal(dsAP.Tables[0].Rows[i]["AMOUNT"].ToString()));
var ttlamount = System.Math.Abs(Convert.ToDecimal(dsAP.Tables[0].Rows[i]["TTLAMOUNT"].ToString()));
blSQL += "MONTHCRSTL=MONTHCRSTL-" + amount.ToString().Trim() + ",MONTHCRBAL=MONTHCRBAL+" + amount.ToString().Trim() + "";
blSQL += ",MONTHTTLCRSTL=MONTHTTLCRSTL-" + ttlamount.ToString().Trim() + ",MONTHTTLCRBAL=MONTHTTLCRBAL+" + ttlamount.ToString().Trim() + "";
}
}
blSQL += " where YEAR=" + aoffyear.ToString() + " AND MONTH=" + aoffmonth.ToString() + " AND CORPID='" + dsAP.Tables[0].Rows[i]["CORPID"].ToString().Trim() + "' and CUSTOMERNAME='" + dsAP.Tables[0].Rows[i]["CUSTOMERNAME"].ToString().Trim() + "'";
blSQL += " and BSSOURCE='" + dsAP.Tables[0].Rows[i]["BSSOURCE"].ToString().Trim() + "' and BSSOURCEDETAIL='" + dsAP.Tables[0].Rows[i]["BSSOURCEDETAIL"].ToString().Trim() + "'";
blSQL += " and SALE='" + dsAP.Tables[0].Rows[i]["SALE"].ToString().Trim() + "' and OPLBNAME='" + dsAP.Tables[0].Rows[i]["OPLBNAME"].ToString().Trim() + "'";
blSQL += " and SALEDEPT='" + dsAP.Tables[0].Rows[i]["SALEDEPT"].ToString().Trim() + "' and CURRENCY='" + dsAP.Tables[0].Rows[i]["CURRENCY"].ToString().Trim() + "'";
blInsert = T_ALL_DA.GetExecuteSqlCommand(blSQL);
}
}
}
#endregion
result.Success = true;
result.Message = "保存成功";
}
catch (Exception e) {
string blDelSQLPERIOD = "delete from PERIOD where PERIOD='" + period.PERIOD + "'";
if (period.SUBCOMP != "")
blDelSQLPERIOD = blDelSQLPERIOD + " and COMPANYID='" + companyid + "'";
bool bl = T_ALL_DA.GetExecuteSqlCommand(blDelSQLPERIOD);
result.Success =false;
result.Message = "结转出错:"+e.Message;
}
return result;
}
}
}