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/MvcShipping/DAL/MsOpSeaeBaoXian/MsOpSeaeBaoXianDAL.cs

236 lines
7.9 KiB
C#

using DSWeb.Areas.MvcShipping.Models.MsOpSeaeBaoXian;
using DSWeb.MvcShipping.Helper;
using Microsoft.Practices.EnterpriseLibrary.Data;
using qingdaoport;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
namespace DSWeb.Areas.MvcShipping.DAL.MsOpSeaeBaoXian
{
public class MsOpSeaeBaoXianDAL
{
public static OpSeaeBaoXianModel_Login loginWX(string userid,string comid)
{
try
{
string whlURL = "http://service.logsafer.net:8920/auth/user/loginWX?serverkey=180005&serverid=kb11dsrjqd&clientid=" + comid;
WebRequest request = WebRequest.Create(whlURL);
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string url = response.ResponseUri.AbsoluteUri;
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
string content = reader.ReadToEnd();
OpSeaeBaoXianModel_Login data = JsonConvert.Deserialize<OpSeaeBaoXianModel_Login>(content);
return data;
}
catch (Exception)
{
return null;
throw;
}
}
public static OpSeaeBaoXianModel_Query_Response query(string userid,string type,string comid)
{
string url = "http://service.logsafer.net:8920/interface/queryapply/query";
string paraData = GetQueryParm(userid, type,comid);
string header = GetTokenHeader(userid,comid);
string resp = HttpHelper.HttpPost(url,paraData,"UTF-8",header);
try
{
OpSeaeBaoXianModel_Query_Response data = JsonConvert.Deserialize<OpSeaeBaoXianModel_Query_Response>(resp);
return data;
}
catch (Exception)
{
OpSeaeBaoXianModel_Query_Response data = new OpSeaeBaoXianModel_Query_Response();
data.success = "false";
data.message = resp;
return data;
}
}
public static OpSeaeBaoXianModel_Apply_Response apply(OpSeaeBaoXianModel_Apply_Requst model,string userid,string comid)
{
string url = "http://service.logsafer.net:8920/interface/applypolicy/apply";
string fptt = "";
string comname = GetComname(userid, out fptt);
string dianhua = "";
string name = GetLianXiRenAndDianHuaWithUserid(userid,out dianhua);
model.serverkey = "180005";
model.companyname = comname;
model.invoiceissuing = comname;
model.holdercontact = name;
model.holderphone = dianhua;
string paraData = GetApplyParm(userid,model,comid);
string header = GetTokenHeader(userid,comid);
string resp = HttpHelper.HttpPost(url, paraData, "UTF-8", header);
OpSeaeBaoXianModel_Apply_Response data = JsonConvert.Deserialize<OpSeaeBaoXianModel_Apply_Response>(resp);
return data;
}
private static string GetQueryParm(string userid,string type,string pcomid)
{
string comid = getBXIDwithComid(pcomid);
OpSeaeBaoXianModel_Query_Requst rq = new OpSeaeBaoXianModel_Query_Requst();
string fptt = "";
string comname = GetComname(userid,out fptt);
rq.serverkey = "180005";
rq.clientid = comid;
rq.querytype = type;
rq.companyname = comname;
rq.invoiceissuing = fptt;
rq.username = "";
rq.orgcode = "";
rq.address = "";
rq.tel = "";
rq.mail = "";
rq.cusqq = "";
rq.fixedtelephone = "";
return JsonConvert.Serialize(rq);
}
private static string GetApplyParm(string userid, OpSeaeBaoXianModel_Apply_Requst rq,string pcomid)
{
string comid = getBXIDwithComid(pcomid);
string fptt = "";
string comname = GetComname(userid, out fptt);
rq.serverkey = "180005";
rq.clientid = comid;
rq.companyname = comname;
rq.invoiceissuing = fptt;
return JsonConvert.Serialize(rq);
}
private static string GetComname(string userid,out string FPTT)
{
Database db = DatabaseFactory.CreateDatabase();
string sql = @"select c.FULLNAME,c.BILLRISES from user_company uc
left join company c on uc.COMPANYID = c.GID
where uc.USERID = '" + userid+"'";
string fp = "";
string name = "";
try
{
using (IDataReader reader = db.ExecuteReader(CommandType.Text, sql))
{
while (reader.Read())
{
if (reader["BILLRISES"] != DBNull.Value)
{
fp = reader["BILLRISES"].ToString();
}
if (reader["FULLNAME"] != DBNull.Value)
{
name = reader["FULLNAME"].ToString();
}
}
}
}
catch (Exception)
{
fp = "";
name = "";
}
finally
{
FPTT = fp;
}
return name;
}
private static string GetLianXiRenAndDianHuaWithUserid(string userid,out string dianhua) {
Database db = DatabaseFactory.CreateDatabase();
string sql = @"select u.SHOWNAME,ub.OFFICEPHONE from [user] u
left join user_baseinfo ub on u.GID = ub.USERID where u.gid = '"+userid+"'";
string dh = "";
string name = "";
try
{
using (IDataReader reader = db.ExecuteReader(CommandType.Text, sql))
{
while (reader.Read())
{
if (reader["SHOWNAME"] != DBNull.Value)
{
name = reader["SHOWNAME"].ToString();
}
if (reader["OFFICEPHONE"] != DBNull.Value)
{
dh = reader["OFFICEPHONE"].ToString();
}
}
}
}
catch (Exception)
{
dh = "";
name = "";
}
finally
{
dianhua = dh;
}
return name;
}
private static string GetTokenHeader(string userid,string pcomid)
{
string comid = getBXIDwithComid(pcomid);
try
{
OpSeaeBaoXianModel_Login model = loginWX(userid,comid);
return "token:"+model.result.token;
}
catch (Exception)
{
return "";
throw;
}
}
private static string getBXIDwithComid(string comid)
{
string bxid = "";
Database db = DatabaseFactory.CreateDatabase();
string sql = @"select top 1 bxid from company where gid = '"+comid+"'";
try
{
var bx = db.ExecuteScalar(CommandType.Text, sql);
if (bx != null && bx != DBNull.Value)
{
bxid = bx.ToString();
}
else
{
bxid = "";
}
}
catch (Exception)
{
bxid= "";
}
return bxid;
}
}
}