using System ;
using System.Data ;
using System.Collections.Generic ;
using System.Text ;
using DSWeb.MvcShipping.Models.MsCwGenlegAccitems ;
using DSWeb.MvcShipping.Models.MsCwAccitemsGl ;
using Microsoft.Practices.EnterpriseLibrary.Data ;
using DSWeb.EntityDA ;
using DSWeb.Areas.CommMng.Models ;
using HcUtility.Comm ;
using System.Data.SqlClient ;
using DSWeb.DataAccess ;
using HcUtility.Core ;
using DSWeb.Areas.CommMng.DAL ;
using DSWeb.Common.DB ;
using DSWeb.MvcShipping.Helper ;
using DSWeb.Areas.MvcShipping.Helper ;
using Quartz.Util ;
using System.Linq ;
using DSWeb.Areas.MvcShipping.Models.Message.VGM ;
using DSWeb.MvcShipping.Models.MsOpSeae ;
using Microsoft.Owin ;
using System.Runtime.Remoting.Messaging ;
using System.IO ;
using System.Net.Http ;
using System.Threading.Tasks ;
using DSWeb.Areas.Import.Models.ImportTrade ;
using System.Net ;
using System.Web ;
using static DSWeb . MvcShipping . DAL . MsOpSeaeEdiDAL . MsOpSeaeEdiDAL ;
using System.Collections.Specialized ;
using System.Data.Entity.Migrations ;
using DSWeb.Areas.MvcShipping.Comm ;
using Ivony.Fluent ;
using System.Configuration ;
using DSWeb.MvcShipping.DAL.MsOpExpressDAL ;
using DSWeb.MvcShipping.Models.MsSysThirdPartyAccount ;
using System.Web.Mvc ;
using System.Reflection ;
using NPOI.SS.Formula.Functions ;
//using java.lang;
namespace DSWeb.MvcShipping.DAL.OP_SERVICEBILLDAL
{
public class OP_SERVICEBILLDAL
{
#region 查询
const string HeadSql = " SELECT BSNO,PARENTID,CORPID,SALECORPID,DEPT,SALEDEPT,SALE,BILLSTATUS,BSSTATUS,FEESTATS,MBLNO,CUSTNO,CUSTOMNO,CONTRACTNO,SERVICETYPE,INPUTBY,TEL,ACCDATE,BSDATE,MODIFIEDUSER,MODIFIEDTIME,ETA,ATA,VESSEL,VOYNO,FORWARDER,SHIPAGENCY,CARRIER,CUSTOMERNAME,FEE_1 ,FEE_2,REMARK,SERVICE,DJYID,''OT1,''OT2,''OT3,''OT4 FROM OP_SERVICEBILL where 1=1 " ;
public static List < OP_SERVICEBILL_md > GetDataList ( int start , int limit , string sort , string condition , VW_user_md userinfo , ref int count )
{
var cdc = new CommonDataContext ( ) ;
var Condition = new OP_SERVICEBILL_md . SearchParam ( ) ;
try
{
Condition = JsonConvert . Deserialize < OP_SERVICEBILL_md . SearchParam > ( condition ) ;
}
catch {
}
//range
var rangestr = GetRangDAStr ( userinfo ) ;
//condition
var strCondition = condition ;
var sortstring = DatasetSort . Getsortstring ( sort ) ; ;
var param = new BasicDataRefDAL . PagedQuaryParam ( ) ;
param . strSql = HeadSql ;
param . strCondition = strCondition ;
param . rangestr = rangestr ;
param . sortstring = sortstring ;
param . defaultsortstr = "BSDATE desc" ;
param . start = start ;
param . limit = limit ;
var strSql = BasicDataRefDAL . PagedQuaryStr ( param ) ;
count = BasicDataRefDAL . PagedCount ( param ) ;
return SetData ( strSql ) ;
}
public static string GetDataListStr ( string condition , VW_user_md userinfo )
{
var cdc = new CommonDataContext ( ) ;
var Condition = new OP_SERVICEBILL_md . SearchParam ( ) ;
try
{
Condition = JsonConvert . Deserialize < OP_SERVICEBILL_md . SearchParam > ( condition ) ;
}
catch
{
}
//range
var rangestr = GetRangDAStr ( userinfo ) ;
//condition
var strCondition = "" ;
var sortstring = "" ;
var param = new BasicDataRefDAL . PagedQuaryParam ( ) ;
param . strSql = HeadSql ;
param . strCondition = strCondition ;
param . rangestr = rangestr ;
param . sortstring = sortstring ;
param . defaultsortstr = "ETA desc" ;
param . start = 0 ;
param . limit = 9999 ;
var strSql = BasicDataRefDAL . PagedQuaryStr ( param ) ;
return strSql . ToString ( ) ;
}
private static List < OP_SERVICEBILL_md > SetData ( System . Text . StringBuilder strSql )
{
var bodyList = new List < OP_SERVICEBILL_md > ( ) ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( IDataReader reader = db . ExecuteReader ( CommandType . Text , strSql . ToString ( ) ) )
{
while ( reader . Read ( ) )
{
OP_SERVICEBILL_md data = new OP_SERVICEBILL_md ( ) ;
#region Set DB data to Object
data . BSNO = Convert . ToString ( reader [ "BSNO" ] ) ;
data . PARENTID = Convert . ToString ( reader [ "PARENTID" ] ) ;
data . CORPID = Convert . ToString ( reader [ "CORPID" ] ) ;
data . SALECORPID = Convert . ToString ( reader [ "SALECORPID" ] ) ;
data . DEPT = Convert . ToString ( reader [ "DEPT" ] ) ;
data . SALEDEPT = Convert . ToString ( reader [ "SALEDEPT" ] ) ;
data . SALE = Convert . ToString ( reader [ "SALE" ] ) ;
data . BILLSTATUS = Convert . ToString ( reader [ "BILLSTATUS" ] ) ;
data . BSSTATUS = Convert . ToString ( reader [ "BSSTATUS" ] ) ;
data . FEESTATS = Convert . ToString ( reader [ "FEESTATS" ] ) ;
data . MBLNO = Convert . ToString ( reader [ "MBLNO" ] ) ;
data . CUSTNO = Convert . ToString ( reader [ "CUSTNO" ] ) ;
data . CUSTOMNO = Convert . ToString ( reader [ "CUSTOMNO" ] ) ;
data . CONTRACTNO = Convert . ToString ( reader [ "CONTRACTNO" ] ) ;
data . SERVICETYPE = Convert . ToString ( reader [ "SERVICETYPE" ] ) ;
data . INPUTBY = Convert . ToString ( reader [ "INPUTBY" ] ) ;
data . TEL = Convert . ToString ( reader [ "TEL" ] ) ;
data . ACCDATE = Convert . ToString ( reader [ "ACCDATE" ] ) ;
if ( reader [ "BSDATE" ] ! = DBNull . Value )
data . BSDATE = Convert . ToDateTime ( reader [ "BSDATE" ] ) ;
data . MODIFIEDUSER = Convert . ToString ( reader [ "MODIFIEDUSER" ] ) ;
if ( reader [ "MODIFIEDTIME" ] ! = DBNull . Value )
data . MODIFIEDTIME = Convert . ToDateTime ( reader [ "MODIFIEDTIME" ] ) ;
if ( reader [ "ETA" ] ! = DBNull . Value )
data . ETA = Convert . ToDateTime ( reader [ "ETA" ] ) ;
if ( reader [ "ATA" ] ! = DBNull . Value )
data . ATA = Convert . ToDateTime ( reader [ "ATA" ] ) ;
data . VESSEL = Convert . ToString ( reader [ "VESSEL" ] ) ;
data . VOYNO = Convert . ToString ( reader [ "VOYNO" ] ) ;
data . SHIPAGENCY = Convert . ToString ( reader [ "SHIPAGENCY" ] ) ;
data . FORWARDER = Convert . ToString ( reader [ "FORWARDER" ] ) ;
data . CARRIER = Convert . ToString ( reader [ "CARRIER" ] ) ;
data . CUSTOMERNAME = Convert . ToString ( reader [ "CUSTOMERNAME" ] ) ;
if ( reader [ "FEE_1" ] ! = DBNull . Value )
data . FEE_1 = Convert . ToDecimal ( reader [ "FEE_1" ] ) ;
if ( reader [ "FEE_2" ] ! = DBNull . Value )
data . FEE_2 = Convert . ToDecimal ( reader [ "FEE_2" ] ) ;
data . SERVICE = Convert . ToString ( reader [ "SERVICE" ] ) ;
data . REMARK = Convert . ToString ( reader [ "REMARK" ] ) ;
if ( reader [ "DJYID" ] ! = DBNull . Value )
data . DJYID = Convert . ToInt64 ( reader [ "DJYID" ] ) ;
# endregion
bodyList . Add ( data ) ;
}
reader . Close ( ) ;
}
if ( bodyList . Count > 0 )
{
var cdc = new CommonDataContext ( ) ;
var bsnolist = bodyList . Select ( s = > s . BSNO ) . ToList ( ) ;
var doclist = cdc . Receipt_Doc . Where ( x = > bsnolist . Contains ( x . BSNO ) ) . ToList ( ) ;
foreach ( var item in bodyList )
{
var doc = doclist . Where ( x = > x . BSNO = = item . BSNO ) . ToList ( ) ;
item . OT1 = GetfileStr ( doc , "原始单据" ) ;
//item.OT1 = GetfileStr(doc, "原始单据");
item . OT3 = GetfileStr ( doc , "账单" ) ;
item . OT4 = GetfileStr ( doc , "发票" ) ;
}
}
return bodyList ;
}
//private static string GetfileStr(List<Receipt_Doc_md> doclist,string receipttype) {
// var result = "";
// if (receipttype == "原始单据") {
// var doc = doclist.Where(x => x.RECEIPTTYPE != "账单" && x.RECEIPTTYPE != "发票").ToList();
// if(doc!=null && doc.Count>0)
// result = JsonConvert.Serialize(doc);
// }
// else
// if (doclist.Exists(x => x.RECEIPTTYPE == receipttype))
// {
// var doc = doclist.Where(x => x.RECEIPTTYPE == receipttype).ToList();
// if (doc != null && doc.Count > 0)
// result = JsonConvert.Serialize(doc);
// }
// return result;
//}
private static string GetfileStr ( List < Receipt_Doc_md > doclist , string receipttype )
{
var result = "" ;
if ( receipttype = = "原始单据" )
{
var doc = doclist . Where ( x = > x . RECEIPTTYPE ! = "账单" & & x . RECEIPTTYPE ! = "发票" ) . ToList ( ) ;
if ( doc ! = null & & doc . Count > 0 )
result = doc . Count . ToString ( ) ;
}
else
if ( doclist . Exists ( x = > x . RECEIPTTYPE = = receipttype ) )
{
var doc = doclist . Where ( x = > x . RECEIPTTYPE = = receipttype ) . ToList ( ) ;
if ( doc ! = null & & doc . Count > 0 )
result = doc . Count . ToString ( ) ;
}
return result ;
}
public static string GetRangDAStr ( VW_user_md userinfo )
{
string str = "" ;
var strSql = new StringBuilder ( ) ;
strSql . Append ( "SELECT " ) ;
strSql . Append ( " VISIBLERANGE,OPERATERANGE,AUTHORITYID,VSSQL " ) ;
strSql . Append ( " from VW_User_Authority " ) ;
strSql . Append ( " where [NAME]='modOP_SERVICEBILL' and USERID='" + userinfo . USERID + "' and ISDELETE=0" ) ;
string visiblerange = "4" ;
string operaterange = "4" ;
string AUTHORITYID = "" ;
string VSSQL = "" ;
Database db = DatabaseFactory . CreateDatabase ( ) ;
using ( IDataReader reader = db . ExecuteReader ( CommandType . Text , strSql . ToString ( ) ) )
{
while ( reader . Read ( ) )
{
visiblerange = Convert . ToString ( reader [ "VISIBLERANGE" ] ) ;
operaterange = Convert . ToString ( reader [ "OPERATERANGE" ] ) ;
AUTHORITYID = Convert . ToString ( reader [ "AUTHORITYID" ] ) ;
VSSQL = Convert . ToString ( reader [ "VSSQL" ] ) ;
break ;
}
reader . Close ( ) ;
}
if ( visiblerange = = "4" )
{
str = "1=2" ;
}
else if ( visiblerange = = "3" )
{
str = " (INPUTBY='" + userinfo . SHOWNAME + "' OR SALE='" + userinfo . SHOWNAME + "' )" ;
}
else if ( visiblerange = = "2" )
{
str = $" (DEPT='{userinfo.deptgid}' or SALEDEPT='{userinfo.deptgid}') " ;
}
else if ( visiblerange = = "1" )
{
str = $" (UPPER(CORPID)='{userinfo.COMPANYID}' or SALECORPID='{userinfo.COMPANYID}') " ;
}
else if ( visiblerange = = "5" )
{
var userstr = new StringBuilder ( ) ;
userstr . Append ( " select COMPANYID from user_authority_range_company where userid='" + userinfo . USERID + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1" ) ;
Database userdb = DatabaseFactory . CreateDatabase ( ) ;
using ( IDataReader reader = userdb . ExecuteReader ( CommandType . Text , userstr . ToString ( ) ) )
{
str = "" ;
while ( reader . Read ( ) )
{
if ( str = = "" )
{
str = $" (Corpid='{userinfo.COMPANYID}' or SALECORPID='{userinfo.COMPANYID}' " ;
}
else
{
str = str + $" or Corpid='{userinfo.COMPANYID}' or SALECORPID='{userinfo.COMPANYID}'" ;
} ;
}
str = str + ")" ;
reader . Close ( ) ;
}
}
else if ( visiblerange = = "6" )
{
//if (tb == "index")
//{
str = " EXISTS (select 1 from user_authority_range_op P left join [user] u on (u.GID=P.OPID) where (B.OP=U.SHOWNAME OR B.SALE=U.SHOWNAME OR B.CUSTSERVICE=U.SHOWNAME OR B.DOC=U.SHOWNAME OR B.FRCUSTSERVICE=U.SHOWNAME OR B.INPUTBY=U.SHOWNAME) AND P.userid='" + userinfo . USERID + "' and P.AUTHORITYID='" + AUTHORITYID + "' and P.VISIBLERANGE=1) " ;
//}
//else
//{
// str = " (UPPER(B.Corpid)='" + companyid + "' or B.SALECORPID='" + companyid + "') ";
//}
}
VSSQL = VSSQL . Trim ( ) ;
if ( ! string . IsNullOrEmpty ( VSSQL ) )
{
if ( ! string . IsNullOrEmpty ( str ) )
{
str = str + " and (" + VSSQL + ") " ;
}
else
{
str = " (" + VSSQL + ") " ;
}
}
return str ;
}
# endregion
public static DBResult SendSerivceFile ( OP_SERVICEBILL_md head , string filepath , Receipt_Doc_md file , int fileType ) {
var result = new DBResult ( ) ;
var SERVICEBILL = ConfigurationManager . AppSettings [ "SERVICEBILL_URL" ] ;
var url = SERVICEBILL + "/api/Open/AnnexUpload" ;
var values = new NameValueCollection ( ) ;
values [ "fileType" ] = fileType . ToString ( ) ;
var headers = new NameValueCollection ( ) ;
var accCfg = MsSysThirdPartyAccount . MsSysThirdPartyAccountDAL . GetData ( $" THIRDPARTY='委托结算服务key' and USERID in(select gid from [user] where SHOWNAME='{head.INPUTBY}') " ) ;
//headers["USER_KEY"] = "0c635164b5b140828d156f178c86113c";
//headers["USER_SECRET"] = "7d23ef98894358e261996f46fb7d63aa8428a3d558cb21ed116f88c77642ba781c361c94cb1a8031";
headers [ "USER_KEY" ] = accCfg . ACCOUNT ;
headers [ "USER_SECRET" ] = accCfg . ACCOUNTPSW ;
var _r = WebRequestHelper . HttpPostData ( url , 90000 , "file" , filepath , file . URL , values , headers ) ;
var _rd = JsonConvert . Deserialize < SERVICEBILL_RTN > ( _r ) ;
file . documentAttachedCode = _rd . data . ToString ( ) ;
var cdc = new CommonDataContext ( ) ;
cdc . Receipt_Doc . AddOrUpdate ( file ) ;
cdc . SaveChanges ( ) ;
return result ;
}
public static DBResult 下 单 ( OP_SERVICEBILL_md head )
{
var result = new DBResult ( ) ;
//var url = "http://60.209.125.238:30819/api/Open/OrderSubmit";
var SERVICEBILL = ConfigurationManager . AppSettings [ "SERVICEBILL_URL" ] ;
var url = SERVICEBILL + "/api/Open/OrderSubmit" ;
var mblnolist = new List < string > ( ) ;
mblnolist . Add ( head . MBLNO ) ;
var cdc = new CommonDataContext ( ) ;
var receiptList = cdc . Receipt_Doc . Where ( x = > x . BSNO = = head . BSNO ) . ToList ( ) ;
var company = cdc . company . FirstOrDefault ( x = > x . GID = = head . CORPID ) ;
var 文 件 idList = receiptList . Select ( s = > s . documentAttachedCode ) ;
var 文 件 intList = new List < long > ( ) ;
foreach ( var id in 文 件 idList ) {
文 件 intList . Add ( Convert . ToInt64 ( id ) ) ;
}
//var values = new NameValueCollection();
//values["MblnoList"] = JsonConvert.Serialize(mblnolist);
//var item = ConfigurationManager.AppSettings["SERVICEBILLCompanyid"];
//values["CompanyId"] = item;
//values["CompanyName"] = company.FULLNAME;
//var inputuser = cdc.User.FirstOrDefault(x => x.SHOWNAME == head.INPUTBY);
//values["ContactId"] = inputuser.GID;
//values["ContactName"] = head.INPUTBY;
//values["ContactTel"] = head.TEL;
//values["ServiceType"] = "1";
//values["ProjectType"] = head.SERVICE;
//values["Remark"] = head.REMARK;
//values["AnnexIdList"] = JsonConvert.Serialize(文件intList);
var sendinfo = new SERVICEBILL_ 下 单 ( ) ;
sendinfo . MblnoList = mblnolist ;
var item = ConfigurationManager . AppSettings [ "SERVICEBILLCompanyid" ] ;
sendinfo . CompanyId = item ;
sendinfo . CompanyName = company . FULLNAME ;
var inputuser = cdc . User . FirstOrDefault ( x = > x . SHOWNAME = = head . INPUTBY ) ;
sendinfo . ContactId = inputuser . GID ;
sendinfo . ContactName = head . INPUTBY ;
sendinfo . ContactTel = head . TEL ;
sendinfo . ServiceType = 1 ;
sendinfo . ProjectType = head . SERVICE ;
sendinfo . Remark = head . REMARK ;
sendinfo . AnnexIdList = 文 件 intList ;
var headers = new NameValueCollection ( ) ;
var accCfg = MsSysThirdPartyAccount . MsSysThirdPartyAccountDAL . GetData ( $" THIRDPARTY='委托结算服务key' and USERID in(select gid from [user] where SHOWNAME='{head.INPUTBY}') " ) ;
//headers["USER_KEY"] = "0c635164b5b140828d156f178c86113c";
//headers["USER_SECRET"] = "7d23ef98894358e261996f46fb7d63aa8428a3d558cb21ed116f88c77642ba781c361c94cb1a8031";
headers [ "USER_KEY" ] = accCfg . ACCOUNT ;
headers [ "USER_SECRET" ] = accCfg . ACCOUNTPSW ;
var strSendObj = JsonConvert . Serialize ( sendinfo ) ;
var rtn = WebRequestHelper . DoPost_JSON_Header ( url , strSendObj , 10000 , headers ) ;
var _rd = JsonConvert . Deserialize < SERVICEBILL_RTN_ 下 单 > ( rtn ) ;
if ( _rd . success = = true )
{
head . DJYID = _rd . data [ 0 ] . OrderId ;
head . BILLSTATUS = "已下单" ;
cdc . OP_SERVICEBILL . AddOrUpdate ( head ) ;
cdc . SaveChanges ( ) ;
result . OK ( _rd . msg ) ;
}
else {
result . SetErrorInfo ( _rd . msg ) ;
}
return result ;
}
public static DBResult 反 馈 ( OP_SERVICEBILL_md head )
{
var result = new DBResult ( ) ;
//var url = "http://60.209.125.238:30819/api/Open/BindAnnexOrInfo";
var SERVICEBILL = ConfigurationManager . AppSettings [ "SERVICEBILL_URL" ] ;
var url = SERVICEBILL + "/api/Open/BindAnnexOrInfo" ;
var mblnolist = new List < string > ( ) ;
mblnolist . Add ( head . MBLNO ) ;
var cdc = new CommonDataContext ( ) ;
var receiptList = cdc . Receipt_Doc . Where ( x = > x . BSNO = = head . BSNO ) . ToList ( ) ;
var company = cdc . company . FirstOrDefault ( x = > x . GID = = head . CORPID ) ;
var 文 件 idList = receiptList . Select ( s = > s . documentAttachedCode ) ;
var 文 件 intList = new List < long > ( ) ;
foreach ( var id in 文 件 idList )
{
文 件 intList . Add ( Convert . ToInt64 ( id ) ) ;
}
//var values = new NameValueCollection();
//values["OrderId"] = head.DJYID.ToString();
//values["OperType"] = "2";
//values["AnnexIdList"] = JsonConvert.Serialize(文件intList);
//values["MailFlag"] = "";
//values["MailBillNo"] = "";
//values["Remark"] = head.REMARK;
var sendinfo = new SERVICEBILL_ 反 馈 ( ) ;
sendinfo . OrderId = ( Int64 ) head . DJYID ;
sendinfo . OperType = 2 ;
sendinfo . AnnexIdList = 文 件 intList ;
sendinfo . Remark = head . REMARK2 ;
var headers = new NameValueCollection ( ) ;
var accCfg = MsSysThirdPartyAccount . MsSysThirdPartyAccountDAL . GetData ( $" THIRDPARTY='委托结算服务key' and USERID in(select gid from [user] where SHOWNAME='{head.INPUTBY}') " ) ;
//headers["USER_KEY"] = "0c635164b5b140828d156f178c86113c";
//headers["USER_SECRET"] = "7d23ef98894358e261996f46fb7d63aa8428a3d558cb21ed116f88c77642ba781c361c94cb1a8031";
headers [ "USER_KEY" ] = accCfg . ACCOUNT ;
headers [ "USER_SECRET" ] = accCfg . ACCOUNTPSW ;
var strSendObj = JsonConvert . Serialize ( sendinfo ) ;
var rtn = WebRequestHelper . DoPost_JSON_Header ( url , strSendObj , 10000 , headers ) ;
var _rd = JsonConvert . Deserialize < SERVICEBILL_RTN_ 下 单 > ( rtn ) ;
if ( _rd . success = = true )
{
result . OK ( _rd . msg ) ;
}
else
{
result . SetErrorInfo ( _rd . msg ) ;
}
return result ;
}
public static DBResult 下 载 附 件 ( OP_SERVICEBILL_md head , Int64 annexId , string RECEIPTTYPE )
{
var result = new DBResult ( ) ;
//var url = "http://60.209.125.238:30819/api/Open/BindAnnexOrInfo";
var SERVICEBILL = ConfigurationManager . AppSettings [ "SERVICEBILL_URL" ] ;
var url = SERVICEBILL + "/api/Open/AnnexDownload" ;
var cdc = new CommonDataContext ( ) ;
var values = new Dictionary < string , string >
{
{ "annexId" , annexId . ToString ( ) }
} ;
//values["annexId"] = annexId.ToString();
var accCfg = MsSysThirdPartyAccount . MsSysThirdPartyAccountDAL . GetData ( $" THIRDPARTY='委托结算服务key' and USERID in(select gid from [user] where SHOWNAME='{head.INPUTBY}') " ) ;
var headers = new Dictionary < string , string >
{
{ "USER_KEY" , accCfg . ACCOUNT } ,
{ "USER_SECRET" , accCfg . ACCOUNTPSW }
} ;
//headers["USER_KEY"] = "0c635164b5b140828d156f178c86113c";
//headers["USER_SECRET"] = "7d23ef98894358e261996f46fb7d63aa8428a3d558cb21ed116f88c77642ba781c361c94cb1a8031";
//headers["USER_KEY"] = accCfg.ACCOUNT;
//headers["USER_SECRET"] = accCfg.ACCOUNTPSW;
var filename = "" ;
var rtnstream = DSWeb . Areas . Dispatch . Helper . WebRequestHelper . DoGetFile_Header_Param ( url , headers , values , out filename ) ;
filename = HttpUtility . UrlDecode ( filename , System . Text . Encoding . UTF8 ) ;
//var basepath = "../../UploadFiles/MsOpFiles/";
var basepath = ConfigurationManager . AppSettings [ "DS7PATH" ] ;
var path = basepath + "UploadFiles\\MsOpFiles\\" ;
if ( ! Directory . Exists ( path ) )
{
Directory . CreateDirectory ( path ) ;
}
var savefilename = DateTime . Now . ToString ( "yyyyMMddHHmmssffff" ) + filename ;
var currfile = cdc . Receipt_Doc . Where ( x = > x . BSNO = = head . BSNO & & x . documentAttachedCode = = annexId . ToString ( ) ) . ToList ( ) ;
if ( currfile ! = null & & currfile . Count > 0 )
{
var currfileitem = currfile [ 0 ] ;
savefilename = currfileitem . Driect_URL . Replace ( basepath , "" ) ;
}
else
{
}
var savepath = "../../UploadFiles/MsOpFiles/" + savefilename ;
var fullpath = path + savefilename ;
//if (File.Exists(fullpath))
//{
// File.Delete(fullpath);
//}
using ( var fileStream = File . Create ( fullpath ) )
{
rtnstream . CopyTo ( fileStream ) ;
}
var newfile = new Receipt_Doc_md ( ) ;
newfile . GID = Guid . NewGuid ( ) . ToString ( ) ;
newfile . BSNO = head . BSNO ;
newfile . URL = filename ;
newfile . Driect_URL = savepath ;
newfile . documentAttachedCode = annexId . ToString ( ) ;
//var filetype = "";
//if (RECEIPTTYPE == "1") filetype = "原始单据";
//if (RECEIPTTYPE == "2") filetype = "账单";
//if (RECEIPTTYPE == "3") filetype = "发票";
newfile . RECEIPTTYPE = RECEIPTTYPE ;
//var currfile = cdc.Receipt_Doc.Where(x => x.BSNO == head.BSNO && x.documentAttachedCode == newfile.documentAttachedCode).ToList();
if ( currfile ! = null & & currfile . Count > 0 )
{
//var updrec= new
}
else {
cdc . Receipt_Doc . Add ( newfile ) ;
cdc . SaveChanges ( ) ;
}
return result ;
}
public static SysThirdPartyAccount GetThirdPartyInfo ( OP_SERVICEBILL_md head ) {
var accCfg = MsSysThirdPartyAccount . MsSysThirdPartyAccountDAL . GetData ( $" THIRDPARTY='委托结算服务key' and USERID in(select gid from [user] where SHOWNAME='{head.INPUTBY}') " ) ;
return accCfg ;
}
/// <summary>
/// 判断需要配置的项目是否已配置
/// </summary>
/// <returns></returns>
public static DBResult CheckSetting ( OP_SERVICEBILL_md head )
{
var result = new DBResult ( ) ;
result . OK ( ) ;
var cdc = new CommonDataContext ( ) ;
//var inputuser = cdc.User.FirstOrDefault(x => x.SHOWNAME == head.INPUTBY);
//if (string.IsNullOrWhiteSpace(inputuser.DJY_UID))
//{
// result.SetErrorInfo($"{head.INPUTBY} 此用户基本信息当中没有配置【大简云UID】");
//}
CheckWebconfig ( "SERVICEBILL" , ref result ) ;
CheckWebconfig ( "SERVICEBILLCompanyid" , ref result ) ;
CheckWebconfig ( "SERVICEBILL_URL" , ref result ) ;
CheckWebconfig ( "SERVICEBILL_MQUri" , ref result ) ;
CheckWebconfig ( "SERVICEBILL_QueuePrefix" , ref result ) ;
CheckWebconfig ( "DS7PATH" , ref result ) ;
var 第 三 方 账 号 = GetThirdPartyInfo ( head ) ;
if ( string . IsNullOrWhiteSpace ( 第 三 方 账 号 . ACCOUNT ) )
{
result . SetErrorInfo ( $"{head.INPUTBY} 此用户没有配置【委托结算服务key】的账号和密钥" ) ;
}
return result ;
}
private static void CheckWebconfig ( string itemname , ref DBResult result )
{
var item = ConfigurationManager . AppSettings [ itemname ] ;
if ( string . IsNullOrWhiteSpace ( item ) )
{
result . SetErrorInfo ( $"系统配置文件中没有配置【{itemname}】项目" ) ;
}
}
}
public class SERVICEBILL_RTN {
public Int32 code { get ; set ; }
public bool success { get ; set ; }
public string msg { get ; set ; }
//public string msgDev { get; set; }
public object data { get ; set ; }
}
public class SERVICEBILL_ 下 单
{
public List < string > MblnoList { get ; set ; } = new List < string > ( ) ;
public string CompanyId { get ; set ; }
public string CompanyName { get ; set ; }
public string ContactId { get ; set ; }
public string ContactName { get ; set ; }
public string ContactTel { get ; set ; }
public int ServiceType { get ; set ; }
public string ProjectType { get ; set ; }
public string Remark { get ; set ; }
public List < Int64 > AnnexIdList { get ; set ; } = new List < Int64 > ( ) ;
public SERVICEBILL_ 下 单 ( ) { }
public SERVICEBILL_ 下 单 ( OP_SERVICEBILL_md head )
{
MblnoList . Add ( head . MBLNO ) ;
}
}
public class SERVICEBILL_ 反 馈
{
public Int64 OrderId { get ; set ; } = 0 ;
public int OperType { get ; set ; } = 0 ;
public List < Int64 > AnnexIdList { get ; set ; } = new List < Int64 > ( ) ;
public bool? MailFlag { get ; set ; } = null ;
public string MailBillNo { get ; set ; }
public string Remark { get ; set ; }
}
public class 下 单 data {
public Int64 ? OrderId { get ; set ; }
public string Mblno { get ; set ; }
}
public class SERVICEBILL_RTN_ 下 单 : SERVICEBILL_RTN
{
public List < 下 单 data > data { get ; set ; }
}
}