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/code_vesselModelDal/code_vessel.cs

453 lines
18 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DSWeb.Areas.MvcShipping.Models.Disport;
using System.Data;
using Microsoft.Practices.EnterpriseLibrary.Data;
using HcUtility.Comm;
using System.Text.RegularExpressions;
using System.Text;
using DSWeb.Areas.MvcShipping.Models.MsCodeVesselSetModel;
using DSWeb.MvcShipping.DAL.MsInfoClient;
using DSWeb.MvcShipping.DAL.MsOpSeaeDAL;
namespace DSWeb.Areas.MvcShipping.DAL.code_vesselModelDal
{
public class code_vessel
{
//查询code_vessel语句
static public List<code_vesselModel> GetVesselList(string condition)
{
StringBuilder sb = new StringBuilder("select z.vsid,z.vessel,z.cname,z.carrier,z.edicode from code_vessel ");
sb.Append(" as z ");
if (!string.IsNullOrEmpty(condition))
{
sb.Append(" where " + condition);
}
sb.Append(" order by vsid");
return SetData(sb);
}
#region 根据ID进行查询
static public List<code_vesselModel> GetVesselByID(object headData)
{
StringBuilder sb = new StringBuilder("select z.vsid,z.vessel,z.cname,z.carrier,z.edicode from code_vessel ");
sb.Append(" as z where z.vsid='"+headData+"'");
return SetData(sb);
}
#endregion
private static List<code_vesselModel> SetData(StringBuilder strSql)
{
var headList = new List<code_vesselModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
code_vesselModel data = new code_vesselModel();
#region Set DB data to Object
data.vsid = Convert.ToString(reader["vsid"]);
data.vessel = Convert.ToString(reader["vessel"]);
data.cname = Convert.ToString(reader["cname"]);
data.carrier = Convert.ToString(reader["carrier"]);
data.edicode = Convert.ToString(reader["edicode"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#region 查询code_voyno 航次资料
static public List<code_voynoModel> GetVoynoList(string headData)
{
string sql = "select *,(select VESSEL from code_vessel where vsid=code_voyno.vsid) as a,(select TOP 1 PORT from code_loadport where EDICODE=code_voyno.PORTLOAD) as PORTLOADREF "
+ ",(select TOP 1 PORT from code_disport where EDICODE=code_voyno.PORTDISCHARGE) as PORTDISCHARGEREF,(select TOP 1 PORT from code_disport where EDICODE=code_voyno.ENTREPORT) as ENTREPORTREF from code_voyno where vsid='" + headData + "'";
return SetFootData(sql);
}
static public List<code_voynoModel> GetVoynoListById(string headData)
{
string sql = "select *,(select VESSEL from code_vessel where vsid=code_voyno.vsid) as a,(select TOP 1 PORT from code_loadport where EDICODE=code_voyno.PORTLOAD) as PORTLOADREF "
+ ",(select TOP 1 PORT from code_disport where EDICODE=code_voyno.PORTDISCHARGE) as PORTDISCHARGEREF,(select TOP 1 PORT from code_disport where EDICODE=code_voyno.ENTREPORT) as ENTREPORTREF from code_voyno where vsid='" + headData + "'";
return SetFootData(sql);
}
private static List<code_voynoModel> SetFootData(string strSql)
{
var headList = new List<code_voynoModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
code_voynoModel data = new code_voynoModel();
#region Set DB data to Object
data.VOID = Convert.ToString(reader["VOID"]);
data.VSID = Convert.ToString(reader["VSID"]);
data.VOYNO = Convert.ToString(reader["VOYNO"]);
data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);
data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]);
data.PORTLOADREF = Convert.ToString(reader["PORTLOADREF"]);
data.PORTDISCHARGEREF = Convert.ToString(reader["PORTDISCHARGEREF"]);
data.ETD = cltime(Convert.ToString(reader["ETD"]));
data.CLOSINGDATE = cltime(Convert.ToString(reader["CLOSINGDATE"]));
data.ETA = cltime(Convert.ToString(reader["ETA"]));
data.CORPID = Convert.ToString(reader["CORPID"]);
data.YARDID = Convert.ToString(reader["YARDID"]);
data.ENTREPORT = Convert.ToString(reader["ENTREPORT"]);
data.ENTREPORTREF = Convert.ToString(reader["ENTREPORTREF"]);
data.VESSEL = Convert.ToString(reader["a"]);
data.ATD = cltime(Convert.ToString(reader["ATD"]));
data.CLOSEDOCDATE = clminute(Convert.ToString(reader["CLOSEDOCDATE"]));
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 删除
public static DBResult DeleteDetail(code_vesselModel headData)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmd = db.GetSqlStringCommand("delete from code_vessel where vsid='" + headData.vsid + "'");
db.ExecuteNonQuery(cmd, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "删除出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "删除成功";
return result;
}
#endregion
#region 删除航次
public static DBResult DeleteDetailFoot(code_voynoModel headData)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmd = db.GetSqlStringCommand("delete from code_voyno where void='" + headData.VOID + "'");
db.ExecuteNonQuery(cmd, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "删除出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "删除成功";
return result;
}
#endregion
#region 插入code_vessel表
public static DBResult InsertDetail(code_vesselModel headData)
{
var result = new DBResult();
try
{
string csql = "select count(vessel) as c from code_vessel where vessel='"+headData.vessel+ "'";
int findresult = Convert.ToInt32(findname(csql));
if (findresult > 0)
{
result.Success = false;
result.Message = "添加失败,船名英文名称、船公司不可重复添加!";
return result;
}
}
catch (Exception)
{
result.Success = false;
result.Message = "添加出现错误,请重试或联系系统管理员";
return result;
}
result.Success = true;
result.Message = "添加成功";
return result;
}
#endregion
#region 查询是否有重复的船名
public static DBResult InsertVessel(code_voynoModel headData)
{
var result = new DBResult();
try
{
string csql = "select count(VOYNO) as c from code_voyno where VSID='" + headData.VSID + "' and VOYNO='" + headData.VOYNO + "'";
int findresult = Convert.ToInt32(findname(csql));
if (findresult > 0)
{
result.Success = false;
result.Message = "添加失败,同一船名航次不可重复添加!";
return result;
}
}
catch (Exception e)
{
result.Success = false;
result.Message = "添加出现错误,请重试或联系系统管理员";
return result;
throw;
}
result.Success = true;
result.Message = "添加成功";
return result;
}
public static DBResult UpdateBsVesselVoy(code_voynoModel headData)
{
var result = new DBResult();
var mblnos = "";
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var bslist = MsOpSeaeDAL.GetFenList(" BSSTATUS=0 and VESSEL='" + headData.VESSEL + "' and VOYNO='" + headData.VOYNO + "' and PORTLOADID='" + headData.PORTLOAD + "'","","","",null,false);
if (bslist != null)
{
foreach (var enumValue in bslist)
{
if (headData.ETD != "" && enumValue.CUSTOMERNAME != "")// headData.STLDATE == "" &&
{
//根据客户、开船日计算账期
var _dmb = MsInfoClientDAL.GetSTLDATE(enumValue.CUSTOMERNAME, "海运出口", headData.ETD, enumValue.SALE,enumValue.CARRIER);
var STLNAME = _dmb.STLNAME;
var STLDATE = _dmb.STLDATE;
if (_dmb.STLNAME == "")
{
STLNAME = "现结买单";
STLDATE = headData.ETD;
}
var cmdupdate = db.GetSqlStringCommand(@"update op_seae set ETD='" + headData.ETD + "',ATD='" + headData.ATD + "',STLNAME='" + STLNAME + "',STLDATE='" + STLDATE + "' where BSNO='" + enumValue.BSNO + "'");
db.ExecuteNonQuery(cmdupdate, tran);
}
else
{
var cmdupdate = db.GetSqlStringCommand(@"update op_seae set ETD='" + headData.ETD + "',ATD='" + headData.ATD + "' where BSNO='" + enumValue.BSNO + "'");
db.ExecuteNonQuery(cmdupdate, tran);
}
}
}
tran.Commit();
var strSql = new StringBuilder();
strSql.Append("SELECT MBLNO FROM op_seae where BSSTATUS=1 and VESSEL='" + headData.VESSEL + "' and VOYNO='" + headData.VOYNO + "' and PORTLOADID='" + headData.PORTLOAD + "'");
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
mblnos = mblnos + Convert.ToString(reader["MBLNO"])+";";
}
}
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "更新出现错误,请重试或联系系统管理员";
return result;
}
}
if (mblnos == "") mblnos = "更新成功"; else mblnos = "提单号:" + mblnos + " 已业务锁定,无法更新!";
result.Success = true;
result.Message = mblnos;
return result;
}
#endregion
#region 插入code_vessel表
public static DBResult InsertVoyno(code_voynoModel headData)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
//var cmdDelete = db.GetSqlStringCommand("delete from code_voyno where vessel='" + headData.vessel + "'");
//db.ExecuteNonQuery(cmdDelete, tran);
string sql = string.Format(" insert into code_voyno values('{0}','{1}','{2}','{3}','{4}',{5},{6},{7},'{8}','{9}','{10}','" + headData.VESSEL + "'," + sqlnull(headData.ATD) + ",'"+headData.CLOSEDOCDATE+"')",
headData.DM_ID, headData.VSID, headData.VOYNO, headData.PORTLOAD, headData.PORTDISCHARGE, sqlnull(headData.ETD), sqlnull(headData.CLOSINGDATE), sqlnull(headData.ETA), headData.CORPID, headData.YARDID, headData.ENTREPORT);
var cmd = db.GetSqlStringCommand(sql);
db.ExecuteNonQuery(cmd, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功";
return result;
}
#endregion
#region 读取数据库返回结果
private static string findname(string strSql)
{
string c = "";
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
#region Set DB data to Object
c = Convert.ToString(reader["c"]);
#endregion
}
reader.Close();
}
return c;
}
#endregion
#region 获取航次列表
static public List<code_voynoModel> GetVoynotList()
{
string sql = "select voyno from code_voyno";
return SetVoynoData(sql);
}
private static List<code_voynoModel> SetVoynoData(string strSql)
{
var headList = new List<code_voynoModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
code_voynoModel data = new code_voynoModel();
#region Set DB data to Object
data.VOYNO = Convert.ToString(reader["voyno"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
public static DBResult SDetail(code_vesselModel headData)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdDelete = db.GetSqlStringCommand("delete from code_vessel where vsid='" + headData.vsid + "'");
db.ExecuteNonQuery(cmdDelete, tran);
string sql = string.Format("insert into code_vessel values('{0}','{1}','{2}','{3}','{4}')", headData.DM_ID, headData.vessel, headData.cname, headData.carrier, headData.edicode);
var cmd = db.GetSqlStringCommand(sql);
db.ExecuteNonQuery(cmd, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功";
return result;
}
static public string cltime(string s) {
if (s==""||s==null)
{
return s;
}
else
{
string sa = Convert.ToDateTime(s).ToString("yyyy-MM-dd");
return sa;
}
}
static public string clminute(string s)
{
if (s == "" || s == null)
{
return s;
}
else
{
string sa = Convert.ToDateTime(s).ToString("yyyy-MM-dd HH:mm");
return sa;
}
}
static public object sqlnull(string s)
{
if (s == "" || s == null)
{
return "null";
}
else
{
return "\'" + s + "\'";
}
}
}
}