using System ;
using System.Linq ;
using System.Web.Mvc ;
using DSWeb.Areas.Account.DAL.Chfee_Jinzhang ;
using DSWeb.Areas.Account.Models.Chfee_jinzhang ;
using DSWeb.MvcShipping.Helper ;
using DSWeb.MvcShipping.Comm.Cookie ;
using DSWeb.Areas.CommMng.DAL ;
using System.Collections.Generic ;
using HcUtility.Comm ;
using HcUtility.Core ;
using DSWeb.EntityDA ;
using DSWeb.Areas.Account.Models.Chfee_Exrate ;
using System.Data ;
using DSWeb.Areas.Account.Models.Chfee_Bankdata ;
using DSWeb.Areas.Account.DAL.Chfee_bankdata ;
using System.IO ;
using DSWeb.Areas.Account.Models.Chfee_Invoice ;
using DSWeb.Areas.Account.Models.Chfee_Settlement ;
using DSWeb.SoftMng.Filter ;
using DSWeb.Areas.Account.Models.Chfee_Payapplication ;
using DSWeb.Areas.Account.DAL.Chfee_Settlement ;
using DSWeb.Areas.Dispatch.Helper ;
namespace DSWeb.Areas.Account.Controllers
{
[JsonRequestBehavior]
public class Chfee_bankdataController : Controller
{
/ /
// GET:
public ActionResult Index ( )
{
return View ( ) ;
}
/ /
// GET: /
public ActionResult Edit ( )
{
return View ( ) ;
}
public ActionResult StlIndex ( )
{
return View ( ) ;
}
public ActionResult StlMateIndex ( )
{
return View ( ) ;
}
public ActionResult InvIndex ( )
{
return View ( ) ;
}
public ActionResult PayIndex ( )
{
return View ( ) ;
}
/ /
// GET:
#region
[SqlKeyWordsFilter(Type = "Action")] //sql 防注入过滤器
public ContentResult GetDataList ( int start , int limit , string sort , string condition )
{
var dataList = ChBankdataDAL . GetDataList ( condition , Convert . ToString ( Session [ "USERID" ] ) , CookieConfig . GetCookie_UserCode ( Request ) , Convert . ToString ( Session [ "COMPANYID" ] ) , sort ) ;
var list = dataList . Skip ( start ) . Take ( limit ) ;
var json = JsonConvert . Serialize ( new { Success = true , Message = "查询成功" , totalCount = dataList . Count , data = list . ToList ( ) } ) ;
return new ContentResult ( ) { Content = json } ;
}
[SqlKeyWordsFilter(Type = "Action")] //sql 防注入过滤器
public ContentResult GetData ( string handle , string condition )
{
ChBankdata head = null ;
if ( handle = = "edit" )
{
var list = ChBankdataDAL . GetDataList ( condition , Convert . ToString ( Session [ "USERID" ] ) , CookieConfig . GetCookie_UserCode ( Request ) , Convert . ToString ( Session [ "COMPANYID" ] ) ) ;
if ( list . Count > 0 )
head = list [ 0 ] ;
}
if ( head = = null )
{
head = new ChBankdata ( ) ;
}
if ( handle = = "add" )
{
head . CREATEUSER = Convert . ToString ( Session [ "USERID" ] ) ;
head . CREATEUSERREF = Convert . ToString ( Session [ "SHOWNAME" ] ) ;
head . CORPID = Convert . ToString ( Session [ "COMPANYID" ] ) ;
}
var json = JsonConvert . Serialize (
new { Success = true , Message = "查询成功" , data = head } ) ;
return new ContentResult ( ) { Content = json } ;
}
[SqlKeyWordsFilter(Type = "Action")] //sql 防注入过滤器
public ContentResult GetDataSumList ( string condition )
{
var dataList = ChBankdataDAL . GetDataSumList ( condition , Convert . ToString ( Session [ "USERID" ] ) , CookieConfig . GetCookie_UserCode ( Request ) , Convert . ToString ( Session [ "COMPANYID" ] ) ) ;
var json = JsonConvert . Serialize ( new { Success = true , Message = "查询成功" , totalCount = dataList . Count , data = dataList . ToList ( ) } ) ;
return new ContentResult ( ) { Content = json } ;
}
/ /
public ContentResult Delete ( string data )
{
var headData = JsonConvert . Deserialize < ChBankdata > ( data ) ;
DBResult result ;
var modb = new ModelObjectDB ( ) ;
result = modb . Delete ( headData ) ;
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
public ContentResult DeleteList ( string data )
{
var headData = JsonConvert . Deserialize < List < ChBankdata > > ( data ) ;
DBResult result = new DBResult ( ) ;
foreach ( var bill in headData )
{
var modb = new ModelObjectDB ( ) ;
result = modb . Delete ( bill ) ;
}
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
#region 匹配结算
public ContentResult AddBankDataStlDetail ( string billno , string data )
{
var bodyList = JsonConvert . Deserialize < List < ChSettlement > > ( data ) ;
DBResult result = ChBankdataDAL . AddBankDataStlDetail ( bodyList , billno , Convert . ToString ( Session [ "USERID" ] ) , Convert . ToString ( Session [ "SHOWNAME" ] ) ) ;
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
public ContentResult AddAutoBankDataStlDetail ( string condition , string fitcondition )
{
DBResult result = ChBankdataDAL . AddAutoBankDataStlDetail ( condition , fitcondition , Convert . ToString ( Session [ "USERID" ] ) , Convert . ToString ( Session [ "SHOWNAME" ] ) , Convert . ToString ( Session [ "COMPANYID" ] ) ) ;
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
# endregion
public ContentResult AddBankDataDetail ( string billno , string data )
{
var bodyList = JsonConvert . Deserialize < List < ChInvoice > > ( data ) ;
DBResult result = ChBankdataDAL . AddBankDataDetail ( bodyList , billno , Convert . ToString ( Session [ "USERID" ] ) , Convert . ToString ( Session [ "SHOWNAME" ] ) ) ;
if ( result . Success ) {
var dataList = ChBankdataDAL . GetDataList ( "GID='" + billno + "'" , Convert . ToString ( Session [ "USERID" ] ) , CookieConfig . GetCookie_UserCode ( Request ) , Convert . ToString ( Session [ "COMPANYID" ] ) , null ) ;
var curr = "RMB" ;
decimal AMOUNT = 0 ;
decimal FITAMOUNT = 0 ;
if ( dataList ! = null & & dataList . Count ! = 0 ) {
foreach ( var bill in dataList ) {
curr = bill . CURRENCY . Replace ( "CNY" , "RMB" ) . Trim ( ) ;
AMOUNT = bill . AMOUNT ;
}
}
bool isfit = false ;
if ( bodyList ! = null & & bodyList . Count ! = 0 ) {
var addinvlist = ChsettlementDAL . GetRecvInvAllDataList ( "BILLNO in (select BILLNO FROM ch_fee_bankdata_fitdetail WHERE LINKGID='" + billno + "')" , Convert . ToString ( Session [ "USERID" ] ) , CookieConfig . GetCookie_UserCode ( Request ) , Convert . ToString ( Session [ "COMPANYID" ] ) ) ;
if ( addinvlist ! = null & & addinvlist . Count ! = 0 ) {
foreach ( var inv in addinvlist ) {
if ( inv . RECVCURR = = curr ) FITAMOUNT = FITAMOUNT + inv . DOAMOUNT ;
}
}
}
if ( FITAMOUNT = = AMOUNT ) isfit = true ;
if ( isfit )
ChBankdataDAL . AddAutoBankDataSTL ( dataList , Convert . ToString ( Session [ "USERID" ] ) , CookieConfig . GetCookie_UserCode ( Request ) , Convert . ToString ( Session [ "COMPANYID" ] ) ) ;
}
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
[SqlKeyWordsFilter(Type = "Action")] //sql 防注入过滤器
public ContentResult AddBankDataPayDetail ( string billno , string data )
{
var bodyList = JsonConvert . Deserialize < List < ChPaySettlement > > ( data ) ;
DBResult result = ChBankdataDAL . AddBankDataPayDetail ( bodyList , billno , Convert . ToString ( Session [ "USERID" ] ) , Convert . ToString ( Session [ "SHOWNAME" ] ) ) ;
if ( result . Success )
{
var dataList = ChBankdataDAL . GetDataList ( "GID='" + billno + "'" , Convert . ToString ( Session [ "USERID" ] ) , CookieConfig . GetCookie_UserCode ( Request ) , Convert . ToString ( Session [ "COMPANYID" ] ) , null ) ;
var curr = "RMB" ;
decimal AMOUNT = 0 ;
decimal FITAMOUNT = 0 ;
if ( dataList ! = null & & dataList . Count ! = 0 )
{
foreach ( var bill in dataList )
{
curr = bill . CURRENCY . Replace ( "CNY" , "RMB" ) . Trim ( ) ;
AMOUNT = bill . AMOUNT ;
}
}
bool isfit = false ;
if ( bodyList ! = null & & bodyList . Count ! = 0 )
{
var addinvlist = ChsettlementDAL . GetPayDCDataAllList ( "cm.BILLNO in (select BILLNO FROM ch_fee_bankdata_fitdetail WHERE LINKGID='" + billno + "')" , "" , "RMB" ) ;
if ( addinvlist ! = null & & addinvlist . Count ! = 0 )
{
foreach ( var inv in addinvlist )
{
if ( curr = = "RMB" ) FITAMOUNT = FITAMOUNT + inv . STLAMOUNT ;
if ( curr = = "USD" ) FITAMOUNT = FITAMOUNT + inv . USDSTLAMOUNT ;
if ( curr ! = "RMB" & & curr ! = "USD" ) FITAMOUNT = FITAMOUNT + inv . OTSTLAMOUNT ;
}
}
}
if ( FITAMOUNT = = AMOUNT ) isfit = true ;
if ( isfit )
ChBankdataDAL . AddAutoBankDataSTL ( dataList , Convert . ToString ( Session [ "USERID" ] ) , CookieConfig . GetCookie_UserCode ( Request ) , Convert . ToString ( Session [ "COMPANYID" ] ) ) ;
}
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
[SqlKeyWordsFilter(Type = "Action")] //sql 防注入过滤器
public ContentResult AddAutoBankDataDetail ( string condition , string fitcondition , string payfitcondition )
{
//Dictionary<string, string> dicData = new Dictionary<string, string>();
//dicData.Add("PCNO", "20240821101000");
//dicData.Add("CORPID", "Comcab2d43f60454327af30a131fc1d3abd");
//var rtn = WebRequestHelper.DoPostHead("http://localhost:10200//Account/Chfee_bankdata/AddAutoBankDataDetailJk", dicData,"");
//var jsonRespose = new jsonresponse { success = false, message = rtn };
//return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
DBResult result = ChBankdataDAL . AddAutoBankDataDetail ( condition , fitcondition , payfitcondition , Convert . ToString ( Session [ "USERID" ] ) , Convert . ToString ( Session [ "SHOWNAME" ] ) , Convert . ToString ( Session [ "COMPANYID" ] ) ) ;
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
[System.Web.Mvc.HttpPost]
public ContentResult AddAutoBankDataDetailJk ( )
{
string PCNO = Request . Headers [ "PCNO" ] ;
if ( string . IsNullOrEmpty ( PCNO ) ) {
var json4 = DSWeb . MvcShipping . Helper . JsonConvert . Serialize (
new { Code = 4 , Msg = "代码不能为空!" } ) ;
return new ContentResult ( ) { Content = json4 } ;
}
string CORPID = Request . Headers [ "CORPID" ] ;
string USERID = Request . Headers [ "USERID" ] ;
DBResult result = ChBankdataDAL . AddAutoBankDataDetail ( "PCNO='" + PCNO + "'" , "" , "" , USERID , "自动" , CORPID ) ;
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
public ContentResult DelBankDataDetail ( string data )
{
var bodyList = JsonConvert . Deserialize < List < ChBankdata > > ( data ) ;
DBResult result = ChBankdataDAL . DelBankDataDetail ( bodyList ) ;
var jsonRespose = new JsonResponse { Success = result . Success , Message = result . Message } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
[HttpPost]
public ContentResult ImpExcel ( )
{
if ( Convert . ToString ( Session [ "COMPANYID" ] ) . ToString ( ) . Trim ( ) = = "" | | Convert . ToString ( Session [ "USERID" ] ) . ToString ( ) . Trim ( ) = = "" | | Convert . ToString ( Session [ "CODENAME" ] ) . ToString ( ) . Trim ( ) = = "" | | Convert . ToString ( Session [ "SHOWNAME" ] ) . ToString ( ) . Trim ( ) = = "" | | Convert . ToString ( Session [ "DEPTNAME" ] ) . ToString ( ) . Trim ( ) = = "" )
{
var jsonRespose2 = new JsonResponse { Success = false , Message = "登录超时,请退出系统重新登录!" } ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose2 ) } ;
}
var jsonRespose = new JsonResponse { Success = false , Message = "" } ;
if ( Request . Files . Count ! = 1 )
{
jsonRespose . Success = false ;
jsonRespose . Message = "请选择上传的文件" ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
var file = Request . Files [ "DsLoadExcel" ] ;
if ( file = = null )
{
jsonRespose . Success = false ;
jsonRespose . Message = "上传文件发生未知错误,请重新上传" ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
String fileExt = Path . GetExtension ( file . FileName ) . ToLower ( ) ;
if ( fileExt = = ".asp" | | fileExt = = ".aspx" )
{
jsonRespose . Success = false ;
jsonRespose . Message = "不允许上传ASP或ASPX文件" ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
var path = Server . MapPath ( "../../UploadFiles/ImpBsExcel" ) ;
if ( ! Directory . Exists ( path ) )
{
Directory . CreateDirectory ( path ) ;
}
var imptype = Request . Form [ "imptype" ] ;
var size = file . ContentLength ;
var name = Path . GetFileName ( file . FileName ) ;
var usercode = CookieConfig . GetCookie_UserCode ( Request ) ;
string filename = path + "\\" + usercode + DateTime . Now . ToString ( "yyyyMMddHHmmssfff" ) + name ;
if ( System . IO . File . Exists ( filename ) )
{
System . IO . File . Delete ( filename ) ;
}
file . SaveAs ( filename ) ;
if ( ! System . IO . File . Exists ( filename ) )
{
jsonRespose . Success = false ;
jsonRespose . Message = "上传的Excel不包含数据01" ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
try
{
string ext = Path . GetExtension ( file . FileName ) . ToLower ( ) ;
if ( ext ! = ".xls" & & ext ! = ".xlsx" & & ext ! = ".csv" )
{
jsonRespose . Success = false ;
jsonRespose . Message = "上传的文件不是Excel文件" ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
var strMsg = "" ;
System . Data . DataTable table = new System . Data . DataTable ( ) ;
if ( ext = = ".csv" )
table = ChBankdataDAL . CSV2DataTable ( filename , out strMsg ) ;
else
table = ExcelHelper . ReadStreamToDataTable ( file . InputStream , out strMsg , null , true , 1 ) ;
var result = new DBResult ( ) ;
if ( ! string . IsNullOrEmpty ( strMsg ) )
{
jsonRespose . Success = false ;
jsonRespose . Message = strMsg ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
if ( table . Rows . Count > 0 )
{
T_ALL_DA T_ALL_DA = new T_ALL_DA ( ) ;
var BLCOUNT = T_ALL_DA . GetStrSQL ( "BLCOUNT" , "select isnull(MAX(PCNO),0) BLCOUNT from ch_fee_bankdata where CORPID='" + Convert . ToString ( Session [ "COMPANYID" ] ) + "' " ) ;
if ( ext = = ".csv" )
result = ChBankdataDAL . ImpBankData ( table , BLCOUNT , Convert . ToString ( Session [ "USERID" ] ) , CookieConfig . GetCookie_UserCode ( Request ) , Convert . ToString ( Session [ "COMPANYID" ] ) ) ;
else result = ChBankdataDAL . ImpBankData2 ( table , BLCOUNT , Convert . ToString ( Session [ "USERID" ] ) , CookieConfig . GetCookie_UserCode ( Request ) , Convert . ToString ( Session [ "COMPANYID" ] ) ) ;
}
else
{
jsonRespose . Success = false ;
jsonRespose . Message = "excel无数据! " ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
var json = JsonConvert . Serialize ( new
{
success = result . Success ,
Message = result . Message
} ) ;
return new ContentResult ( ) { Content = json } ;
}
catch ( Exception e )
{
jsonRespose . Success = false ;
jsonRespose . Message = "读取Excel文件出错, 请确认文件正确性" + e . Message ;
return new ContentResult ( ) { Content = JsonConvert . Serialize ( jsonRespose ) } ;
}
}
# endregion
#region 参照部分
# endregion
}
}