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.

834 lines
25 KiB
C#

using System;
using HcUtility.Core;
using Newtonsoft.Json;
using DSWeb.Areas.CommMng.DAL;
using System.Web.Mvc;
using System.IO;
using DSWeb.TruckMng.Helper;
using System.Collections.Generic;
using DSWeb.MvcShipping.DAL.MsSysParamSet;
using DSWeb.MvcShipping.DAL.MsChFeeDAL;
using HcUtility.Comm;
namespace DSWeb.Areas.CommMng.Models
{
[JsonObject]
//用于解析要向表中保存的url地址的相关信息
public class FileUrlModel
{
#region
private string _TableName = string.Empty;
private string _KeyName = string.Empty;
private string _KeyValue = string.Empty;
private string _UrlName = string.Empty;
private string _UrlValue = string.Empty;
private string _ImgName = string.Empty;
private string _INDATABASE = string.Empty;
private string _FilePath = string.Empty;
private string ModelName = "";
private string ChildName = "";
private string ExName = "";//扩展名 在savefile时获取
#endregion
#region
public string TableName
{
get { return _TableName; }
set { _TableName = value; }
}
public string KeyName
{
get { return _KeyName; }
set { _KeyName = value; }
}
public string KeyValue
{
get { return _KeyValue; }
set { _KeyValue = value; }
}
public string UrlName
{
get { return _UrlName; }
set { _UrlName = value; }
}
public string UrlValue
{
get { return _UrlValue; }
set { _UrlValue = value; }
}
public string ImgName
{
get { return _ImgName; }
set { _ImgName = value; }
}
public string INDATABASE
{
get { return _INDATABASE; }
set { _INDATABASE = value; }
}
public bool needintoDatabase {
get {
if (_INDATABASE == "True" || _INDATABASE == "true") {
return true;
}return false;
}
}
public string FilePath
{
get { return _FilePath; }
set { _FilePath = value; }
}
public string Savefilename
{
get {
var _r = Savefilename_head;
_r += ExName;
return _r;
}
}
public string Savefilename_head
{
get
{
var _r = KeyValue;
if (!String.IsNullOrEmpty(ChildName))
{
_r += "_" + ChildName;
}
return _r;
}
}
#endregion
public static string _urlbase= "../../UploadFiles";
private string getSQL() {
var sql = String.Format("update {0} set {1}='{2}' where {3}='{4}'", TableName, UrlName, UrlValue, KeyName, KeyValue);
return sql;
}
public int DoUpdate() {
var _r = BasicDataRefDAL.ExecSql(getSQL());
return _r;
}
private string getInsert_info_files_SQL()
{
var sql = String.Format($"insert into info_files (GID,PID,FILENAME,FILEPATH) values ('{Guid.NewGuid().ToString()}','{KeyValue}','{Savefilename}','{getFileName()}')");
return sql;
}
public int DoInsert_info_files()
{
var _r = BasicDataRefDAL.ExecSql(getInsert_info_files_SQL());
return _r;
}
public FileUrlModel() {
}
public FileUrlModel(string ModelName)
{
var path = System.Web.HttpContext.Current.Server.MapPath(FileUrlModel._urlbase);
setModelValue(ModelName, path);
}
public FileUrlModel(string head,string ModelName,string ChildName="") {
var _Info = DSWeb.TruckMng.Helper.JsonConvert.Deserialize<FileUrlModel>(head);
var path = System.Web.HttpContext.Current.Server.MapPath(FileUrlModel._urlbase);
setModelValue(ModelName, path, ChildName);
//ChildName用于表示在某一模块下的多种类型文件 如info_client(往来单位)下添加电子章 或其他种类图片
this.SetValue(_Info);
}
private void setModelValue(string ModelName,string path, string ChildName = "") {
if (ModelName == "FactoryCargoname_TAGPIC")
{//进口贸易-厂号商品名称管理
TableName = "Import_Cargoname";
KeyName = "GID";
UrlName = "TAGPICURL";
FilePath = path + "\\" + ModelName;
this.ModelName = ModelName;
this.ChildName = ChildName;
}
if (ModelName == "InfoClient_Img")
{//往来单位-图片管理
//需要写入数据库
TableName = "Info_Client_IMG";
KeyName = "GID";
UrlName = "IMGURL";
ImgName = "IMG";
FilePath = path + "\\" + ModelName;
this.ModelName = ModelName;
this.ChildName = ChildName;
//INDATABASE = true;
}
if (ModelName == "SysUser_Head")
{
//系统用户 头像
TableName = "USER_BASEINFO";
KeyName = "USERID";
UrlName = "IMAGEURL";
FilePath = path + "\\" + ModelName;
this.ModelName = ModelName;
this.ChildName = ChildName;
//INDATABASE = true;
}
if (ModelName == "SysUser_Sign")
{
//系统用户 签名 需写入数据库
TableName = "USER_BASEINFO";
KeyName = "USERID";
UrlName = "SIGNATUREURL";
ImgName = "AIGNATURE";
FilePath = path + "\\" + ModelName;
this.ModelName = ModelName;
this.ChildName = ChildName;
//INDATABASE = true;
}
if (ModelName == "Price_Quotation")
{
//系统用户 签名 需写入数据库
TableName = "Op_SeaPrice_Quotation";
KeyName = "BSNO";
UrlName = "PDFURL";
FilePath = path + "\\" + ModelName;
this.ModelName = ModelName;
this.ChildName = ChildName;
//INDATABASE = true;
}
}
public void SetValue(FileUrlModel info)
{
if (!string.IsNullOrEmpty(info.TableName))
{
TableName = info.TableName;
}
if (!string.IsNullOrEmpty(info.KeyName))
{
KeyName = info.KeyName;
}
if (!string.IsNullOrEmpty(info.UrlName))
{
UrlName = info.UrlName;
}
if (!string.IsNullOrEmpty(info.KeyValue))
{
KeyValue = info.KeyValue;
}
if (!string.IsNullOrEmpty(info.UrlValue))
{
UrlValue = info.UrlValue;
}
if (!string.IsNullOrEmpty(info.INDATABASE))
{
INDATABASE = info.INDATABASE;
}
}
private static string getexname(System.Web.HttpPostedFileBase file) {
return Path.GetExtension(file.FileName);
}
private string getFileName() {
var _r = FilePath + "\\" + Savefilename;
return _r;
}
/// <summary>
/// 保存方法 返回值为文件url
/// </summary>
/// <param name="file"></param>
/// <returns></returns>
public string SaveFile(System.Web.HttpPostedFileBase file,string savetype="")
{
//获得文件扩展名
ExName = getexname(file);
//首先 如没有目录则建立目录
if (!Directory.Exists(FilePath))
{
Directory.CreateDirectory(FilePath);
}
string filename = getFileName();
//如存在同名文件则删除
string[] fileNames = Directory.GetFiles(FilePath);
foreach (string _file in fileNames)
{
if (_file.IndexOf(Savefilename_head, StringComparison.OrdinalIgnoreCase) >= 0) {
File.Delete(_file);
}
}
//if (File.Exists(filename))
//{
// File.Delete(filename);
//}
//保存文件
file.SaveAs(filename);
if (File.Exists(filename))
{
//向数据库写入url
UrlValue = _urlbase + "/" + ModelName + "/" + Savefilename;
if (savetype == "")
{//通常保存方法
DoUpdate();
//调取升级数据库内图片字段的方法
if (needintoDatabase)
{
BasicDataRefDAL.SaveFileIntoDB(this, UrlValue);
}
}
else {
if (savetype == "info_files") {
//文件信息写入info_files表内
DoInsert_info_files();
}
}
//返回是否存在此文件
return UrlValue;
}
else return "";
}
}
[JsonObject]
public class PrintSql
{
public string sql1 { get; set; }
public string sql2 { get; set; }
public string sql3 { get; set; }
public string sql4 { get; set; }
public string sql5 { get; set; }
public string sql6 { get; set; }
public string sql7 { get; set; }
public string sql8 { get; set; }
}
/// <summary>
/// 用于传递session等control层数据
/// </summary>
public class USERINFO
{
public string USERID { get; set; }
public string BLSTATUSSTR { get; set; }
public string ISENABLECUSTRANGE { get; set; }
public USERINFO()
{
}
public USERINFO(string USERID, string BLSTATUSSTR = "", string ISENABLECUSTRANGE = "")
{
this.USERID = USERID;
this.BLSTATUSSTR = BLSTATUSSTR;
this.ISENABLECUSTRANGE = ISENABLECUSTRANGE;
}
}
[JsonObject]
public class StoreModifyResultStatus
{
public string GID { get; set; }
public string STORENAME { get; set; }
public string TABLENAME { get; set; }
public string MODIFIEDTIME { get; set; }
}
[JsonObject]
public class StoreModifyStatusMb: ModelObjectBillHead
{
public static List<StoreModifyStatusMb> StoreModifyStatusList {
get {
return (List<StoreModifyStatusMb>)BasicDataRefDAL.GetStoreModifyStatusCache();
}
}
public static List<StoreModifyResultStatus> getstatus()
{
try
{
var result = new List<StoreModifyResultStatus>();
var StoreModifyStatusList = (List<StoreModifyStatusMb>) BasicDataRefDAL.GetStoreModifyStatusCache();
foreach (var item in StoreModifyStatusList)
{
var status = new StoreModifyResultStatus();
status.GID = item.GID;
status.STORENAME = item.STORENAME;
status.TABLENAME = item.TABLENAME;
//status.DISPLAYFIELD = item.GID;
//status.VALUEFIELD = item.GID;
//status.DISPLAYFIELD2 = item.GID;
//status.CONDITION = item.GID;
status.MODIFIEDTIME = item.MODIFIEDTIME;
result.Add(status);
}
return result;
}
catch (Exception e) {
BasicDataRefDAL.ResetStoreModifyStatus();
return getstatus();
}
}
#region private Fields
private string _GID = string.Empty;
private string _STORENAME = string.Empty;
private string _TABLENAME = string.Empty;
private string _DISPLAYFIELD = string.Empty;
private string _VALUEFIELD = string.Empty;
private string _DISPLAYFIELD2 = "''";
private string _CONDITION = string.Empty;
private string _MODIFIEDTIME = string.Empty;
public List<PubStore> PubStoreList = new List<PubStore>();
/// <summary>
/// 刷新指定的store
/// 目前只有USERID="EVERYONE"的能调用到这个方法
/// </summary>
/// <param name="STORENAME"></param>
/// <param name="USERID"></param>
public static DBResult RefreshStore(string STORENAME, USERINFO USERINFO)
{
var sqlstr = "";
DBResult result = new DBResult();
//sqlstr = getSqlStr(STORENAME, USERINFO);
var evList = getDBStore(STORENAME, USERINFO);
if (StoreModifyStatusList.Exists(x => x.STORENAME == STORENAME))
{
var _t = StoreModifyStatusList.Find(t => t.STORENAME == STORENAME);
if (_t.PubStoreList.Exists(x => x.STOREUSERID == USERINFO.USERID))
{
_t.PubStoreList.Find(x => x.STOREUSERID == USERINFO.USERID).storelist = evList;
result.setMessage(true, "");
}
else {
var newpubstore = new PubStore();
newpubstore.STOREUSERID = USERINFO.USERID;
newpubstore.storelist = evList;
_t.PubStoreList.Add(newpubstore);
result.setMessage(true, "");
}
}
return result;
//if (evList.Count == 0)
//{
// return Json(new { success = false });
//}
//else
//{
// var blank = new GeneralModel();
// blank.GID = "";
// blank.GVALUE = "";
// blank.GVALUE2 = "";
// evList.Add(blank);
// return Json(new { success = true, data = evList.ToList() });
//}
return result;
}
/// <summary>
/// 从数据库取store内容
/// </summary>
/// <param name="STORENAME"></param>
/// <param name="USERINFO"></param>
/// <returns></returns>
private static List<PubStoremb> getDBStore(string STORENAME, USERINFO USERINFO)
{
var sqlstr = getSqlStr(STORENAME, USERINFO);
var evList = BasicDataRefDAL.getPubExtendStore(sqlstr);
return evList;
}
public static List<PubStoremb> getStore(string STORENAME, USERINFO USERINFO) {
//如果是那种区分userid的 就不写入内存 直接从数据库取值
/*
if (USERINFO.USERID != "EVERYONE")
{
return getDBStore(STORENAME, USERINFO);
}
var result = new List<PubStoremb>();
if (StoreModifyStatusList.Exists(x => x.STORENAME == STORENAME)) {
var _t = StoreModifyStatusList.Find(t => t.STORENAME == STORENAME);
if (_t.PubStoreList.Exists(x => x.STOREUSERID == USERINFO.USERID)) {
result = _t.PubStoreList.Find(x => x.STOREUSERID == USERINFO.USERID).storelist;
return result;
}
}
var _r = RefreshStore(STORENAME, USERINFO);
if (_r.Success) {
result = getStore(STORENAME, USERINFO);
}
return result;*/
//20200407 取消内存缓存的逻辑 改为完全从数据库读取
return getDBStore(STORENAME, USERINFO);
}
//public static void setList(List<StoreModifyStatusMb> currentlist) {
// StoreModifyStatusList.Clear();
// foreach (var sms in currentlist) {
// var newitem = new StoreModifyStatusMb();
// newitem.GID = sms.GID;
// newitem.STORENAME = sms.STORENAME;
// newitem.TABLENAME = sms.TABLENAME;
// newitem.DISPLAYFIELD = sms.DISPLAYFIELD;
// newitem.VALUEFIELD = sms.VALUEFIELD;
// newitem.DISPLAYFIELD2 = sms.DISPLAYFIELD2;
// newitem.CONDITION = sms.CONDITION;
// newitem.MODIFIEDTIME = sms.MODIFIEDTIME;
// StoreModifyStatusList.Add(newitem);
// }
//}
public static string getSql() {
return " select GID,STORENAME,TABLENAME,dbo.trimtime(MODIFIEDTIME) MODIFIEDTIME,DISPLAYFIELD,DISPLAYFIELD2,VALUEFIELD,CONDITION from t_sys_StoreModifyStatus ";
}
/// <summary>
/// 根据storename分配相应的现存查询方法
/// </summary>
/// <param name="STORENAME"></param>
/// <param name="USERINFO"></param>
/// <returns></returns>
public static string getSqlStr(string STORENAME, USERINFO USERINFO) {
string result = "";
var modcondition = "";
if (STORENAME == "INFOCLIENT_ISCONTROLLER" || STORENAME == "INFOCLIENT_INV" || STORENAME == "INFOCLIENT_ALL")
{
if (!string.IsNullOrWhiteSpace(USERINFO.BLSTATUSSTR))
{
modcondition = USERINFO.BLSTATUSSTR;
}
if (USERINFO.ISENABLECUSTRANGE == "1")
{
if (!string.IsNullOrWhiteSpace(modcondition)) modcondition += " and ";
modcondition += " (SHORTNAME in (SELECT SHORTNAME from info_client_range where USERID='" + USERINFO.USERID + "' ) or SHORTNAME not in (SELECT SHORTNAME from info_client_range )) ";
}
}
if (StoreModifyStatusList.Exists(x => x.STORENAME == STORENAME))
{
var _t = StoreModifyStatusList.Find(t => t.STORENAME == STORENAME);
if (!string.IsNullOrWhiteSpace(_t.VALUEFIELD))
{//有VALUEFIELD的使用通用查询方法
if (string.IsNullOrWhiteSpace(_t.DISPLAYFIELD2)) _t.DISPLAYFIELD2 = "''";
result = "select " + _t.VALUEFIELD + " as GID," + _t.DISPLAYFIELD + " as GVALUE , " + _t.DISPLAYFIELD2 + " as GVALUE2 from " + _t.TABLENAME;
var _condition = _t.CONDITION;
if (!string.IsNullOrWhiteSpace(modcondition))
{
if (!string.IsNullOrWhiteSpace(_condition))
{
_condition += " and " + modcondition;
}
else
{
_condition = modcondition;
}
}
if (!string.IsNullOrWhiteSpace(_condition))
{
result += " where " + _condition.Replace("[[USERID]]", "'" + USERINFO.USERID + "'");
}
result += " order by " + _t.DISPLAYFIELD;
}
else {
//没有valuefield的使用独立方法
if (_t.STORENAME == "IMPORT_SELLER") {
//进口贸易 贸易商 isagent=1
result = BasicDataRefDAL.GetTrader_Getsqlstr(" isagent=1 ").ToString();
}
if (_t.STORENAME == "IMPORT_BUYER")
{
//进口贸易 客户 isagentcn=1
result = BasicDataRefDAL.GetTrader_Getsqlstr(" isagentcn=1 ").ToString();
}
if (_t.STORENAME == "HSCODE")
{
result = BasicDataRefDAL.GetCargoTax_Sqlstr("").ToString();
}
if (_t.STORENAME == "CIQCODE")
{
result = BasicDataRefDAL.GetCargociqRefList_Sqlstr("").ToString();
}
//往来单位开票信息
if (_t.STORENAME == "INFOCLIENT_INV")
{
result = BasicDataRefDAL.GetCustomInvRefList_SqlStr("", USERINFO.ISENABLECUSTRANGE, USERINFO.USERID).ToString();
}
//国内港口信息
if (_t.STORENAME == "CODE_PORTLOAD")
{
result = BasicDataRefDAL.GetCodeLoadportList_Sqlstr("").ToString();
}
//国际港口信息
if (_t.STORENAME == "CODE_PORTDISCHARGE")
{
result = BasicDataRefDAL.GetCodeDisportList_DisplayWithCNAME_Sqlstr("").ToString();
}
//场站信息
if (_t.STORENAME == "OPSEAE_YARD")
{
result = BasicDataRefDAL.GetCustomInvRefList_SqlStr(" ISYARD=1 ").ToString();
}
if (_t.STORENAME == "CODE_FEE")
{
result = MsChFeeDAL.GetFeeTypeRefList_Sqlstr("").ToString();
}
if (_t.STORENAME == "INFOCLIENT_ALL")
{
result = BasicDataRefDAL.GetCustomInvRefList_SqlStr("", USERINFO.ISENABLECUSTRANGE, USERINFO.USERID).ToString();
}
if (_t.STORENAME == "INFOCLIENT_CARRIER")
{
result = BasicDataRefDAL.GetCustomInvRefList_SqlStr(" ISCARRIER=1 ", USERINFO.ISENABLECUSTRANGE, USERINFO.USERID).ToString();
}
}
}
return result;
}
[ModelDB(MDBType = ModelDBOprationType.All, IsPrimary = true)]
public string GID
{
get { return _GID; }
set { _GID = value; }
}
/// <summary>
/// store的名字 如 INFOCLIENT_CARRIER 等,用于表示这个数据集的内容
/// </summary>
public string STORENAME
{
get { return _STORENAME.ToUpper(); }
set { _STORENAME = value; }
}
public string TABLENAME
{
get { return _TABLENAME.ToUpper(); }
set { _TABLENAME = value; }
}
[ModelDB]
public string MODIFIEDTIME
{
get { return _MODIFIEDTIME; }
set { _MODIFIEDTIME = value; }
}
public string DISPLAYFIELD
{
get { return _DISPLAYFIELD; }
set { _DISPLAYFIELD = value; }
}
public string VALUEFIELD
{
get { return _VALUEFIELD; }
set { _VALUEFIELD = value; }
}
public string DISPLAYFIELD2
{
get { return _DISPLAYFIELD2; }
set { _DISPLAYFIELD2 = value; }
}
public string CONDITION
{
get { return _CONDITION; }
set { _CONDITION = value; }
}
#endregion
public StoreModifyStatusMb()
{
// TableName = "tMsWlPcHead";
TableName = "t_sys_StoreModifyStatus";
}
public string getrangstr(string USERID) {
var result = "";
return result;
}
public override string GetBillNoFieldName()
{
return "GID";
}
public override string GetTimeMarkFieldName()
{
return "";
}
}
/// <summary>
///
/// </summary>
public class PubStore
{
public string STOREUSERID { get; set; }
public List<PubStoremb> storelist { get; set; }
}
[JsonObject]//通用store数据集
public class PubStoremb : ModelObjectBillHead
{
public override Dictionary<string, ModelDBOprationType> GetPKey()
{//用于给扩展的动态数据提供主键字段名
var d = new Dictionary<string, ModelDBOprationType>() { { "GID", ModelDBOprationType.All } };
return d;
}
public Dictionary<string, string> SaveDic = new Dictionary<string, string>();
public PubStoremb()
{
//TableName = "Op_INTERNALTRADE";
}
public override string GetBillNoFieldName()
{
return "GID";
}
public override string GetTimeMarkFieldName()
{
return "";
}
}
[JsonObject]//用于费用历史引入的v_op_bs数据集
public class VOPBSmb : ModelObjectBillHead
{
public override Dictionary<string, ModelDBOprationType> GetPKey()
{//用于给扩展的动态数据提供主键字段名
var d = new Dictionary<string, ModelDBOprationType>() { { "BSNO", ModelDBOprationType.All } };
return d;
}
public VOPBSmb()
{
//TableName = "Op_INTERNALTRADE";
}
public override string GetBillNoFieldName()
{
return "BSNO";
}
public override string GetTimeMarkFieldName()
{
return "";
}
}
}