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.

1722 lines
80 KiB
C#

10 months ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DSWeb.Models;
using WebSqlHelper;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace DSWeb.EntityDA
{
public class Opsean
{
SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction);
/// <summary>
/// 返回 某字段
/// </summary>
/// <returns></returns>
public string GetStrSQL(string strfield, string strSQL)
{
string alt = "";
DataSet DS = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, strSQL);
if (DS != null)
{
if (DS.Tables[0].Rows.Count > 0)
{
alt = DS.Tables[0].Rows[0]["" + strfield + ""].ToString();
}
}
return alt;
}
/// <summary>
/// 返回 数据集
/// </summary>
/// <returns></returns>
public DataSet GetAllSQL(string strSQL)
{
DataSet DS = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, strSQL);
try
{
if (DS.Tables[0].Rows.Count <= 0)
{
DS = null;
}
}
catch
{
DS = null;
}
return DS;
}
//添加委托表里的数据
public int AddInfo(OpseanEntity opEntity)
{
string etdtime = opEntity.ETD.ToString().IndexOf("0001") > -1 ? "" : opEntity.ETD.ToString();
string etatime = opEntity.ETA.ToString().IndexOf("0001") > -1 ? "" : opEntity.ETA.ToString();
StringBuilder str = new StringBuilder();
str.Append("INSERT INTO [op_sean]([BSNO],[ORDERTYPE],[BSSTATUS],[FEESTATUS],[ACCDATE],[MBLNO],[CUSTNO],[CUSTOMERNAME],[SHIPPER],[CONSIGNEE],[VESSEL],[VOYNO],");
if(etdtime!="")
{
str.Append("[ETD],");
}
if (etatime != "")
{
str.Append("[ETA],");
}
str.Append("[PORTLOAD],[PORTDISCHARGE],[GOODSNAME],[GROSSWEIGHT],[MEASUREMENT],[INPUTBY],[INPUTTIME],[CORPID],[OP],[SALE],[CARRIER],[GROSSWEIGHTUNIT],[MEASUREMENTUNIT],[LOADADDRESS],[DELIVERADDRESS])");
str.Append("VALUES(@BSNO,@ORDERTYPE,@BSSTATUS,@FEESTATUS,@ACCDATE,@MBLNO,@CUSTNO,@CUSTOMERNAME,@SHIPPER,@CONSIGNEE,@VESSEL,@VOYNO,");
if (etdtime != "")
{
str.Append("@ETD,");
}
if (etatime != "")
{
str.Append("@ETA,");
}
str.Append("@PORTLOAD,@PORTDISCHARGE,@GOODSNAME,@GROSSWEIGHT");
str.Append(",@MEASUREMENT,@INPUTBY,@INPUTTIME,@CORPID,@OP,@SALE,@CARRIER,@GROSSWEIGHTUNIT,@MEASUREMENTUNIT,@LOADADDRESS,@DELIVERADDRESS)");
SqlParameter[] para = { new SqlParameter("@BSNO",opEntity.BSNO),
new SqlParameter("@ORDERTYPE",opEntity.ORDERTYPE),
new SqlParameter("@BSSTATUS",opEntity.BSSTATUS),
new SqlParameter("@FEESTATUS",opEntity.FEESTATUS),
new SqlParameter("@ACCDATE",opEntity.ACCDATE),
new SqlParameter("@MBLNO",opEntity.MBLNO),
new SqlParameter("@CUSTNO",opEntity.CUSTNO),
new SqlParameter("@CUSTOMERNAME",opEntity.CUSTOMERNAME),
new SqlParameter("@SHIPPER",opEntity.SHIPPER),
new SqlParameter("@CONSIGNEE",opEntity.CONSIGNEE),
new SqlParameter("@VESSEL",opEntity.VESSEL),
new SqlParameter("@VOYNO",opEntity.VOYNO),
new SqlParameter("@ETD",etdtime),
new SqlParameter("@ETA",etatime),
new SqlParameter("@PORTLOAD",opEntity.PORTLOAD),
new SqlParameter("@PORTDISCHARGE",opEntity.PORTDISCHARGE),
new SqlParameter("@GOODSNAME",opEntity.GOODSNAME),
new SqlParameter("@GROSSWEIGHT",opEntity.GROSSWEIGHT),
new SqlParameter("@MEASUREMENT",opEntity.MEASUREMENT),
new SqlParameter("@INPUTBY",opEntity.INPUTBY),
new SqlParameter("@INPUTTIME",opEntity.INPUTTIME),
new SqlParameter("@CORPID",opEntity.CORPID),
new SqlParameter("@OP",opEntity.OP),
new SqlParameter("@SALE",opEntity.SALE),
new SqlParameter("@CARRIER",opEntity.CARRIER),
new SqlParameter("@GROSSWEIGHTUNIT",opEntity.Grossweightunit),
new SqlParameter("@MEASUREMENTUNIT",opEntity.Measurementunit),
new SqlParameter("@LOADADDRESS",opEntity.LOADADDRESS),
new SqlParameter("@DELIVERADDRESS",opEntity.DELIVERADDRESS)
};
int result = 0;
using (conn)
{
int extnon = SqlHelper.ExecuteNonQuery(conn,CommandType.Text,str.ToString(),para);
if (extnon > 0)
{
result = 1;//执行成功
}
else
{
result = -1;//执行失败
}
}
return result;
}
/// <summary>
///根据主键删除数据
/// </summary>
/// <param name="BSNOid"></param>
/// <returns></returns>
public int DeleteOpseanInfo(string BSNOid)
{
StringBuilder str = new StringBuilder();
str.Append("delete from [op_sean] ");
str.Append("where BSNO=@BSNO");
SqlParameter[] para = new SqlParameter[] { new SqlParameter("@BSNO",BSNOid) };
int result = 0;
using (conn)
{
int extnon = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, str.ToString(), para);
if (extnon > 0)
{
result = 1;//执行成功
}
else
{
result = -1;//执行失败
}
}
return result;
}
/// <summary>
/// 修改数据
/// </summary>
/// <param name="opseanEn"></param>
/// <returns></returns>
public int UpteInfo(OpseanEntity opseanEn)
{
//string etdtime = opseanEn.ETD.ToString().IndexOf("0001") > -1 ? null : opseanEn.ETD.ToString();
//string etatime = opseanEn.ETA.ToString().IndexOf("0001") > -1 ? null : opseanEn.ETA.ToString();
//string newetdtime;
//string newetatime;
string etdtime = opseanEn.ETD.ToString().IndexOf("0001") > -1 ? "" : opseanEn.ETD.ToString();
string etatime = opseanEn.ETA.ToString().IndexOf("0001") > -1 ? "" : opseanEn.ETA.ToString();
StringBuilder sqlstr = new StringBuilder();
sqlstr.Append("UPDATE [op_sean] SET ");
sqlstr.Append("[CUSTOMERNAME] = @CUSTOMERNAME,[SHIPPER] = @SHIPPER,[CONSIGNEE] = @CONSIGNEE,[VESSEL] = @VESSEL,[VOYNO] = @VOYNO,");
if (etdtime == "")
{
sqlstr.Append("[ETD] =NULL,");
}
else
{
sqlstr.Append("[ETD] =@ETD,");
//etdtime = opseanEn.ETD.ToString();
}
if (etatime == "")
{
sqlstr.Append("[ETA] = NULL,");
}
else
{
sqlstr.Append("[ETA] =@ETA,");
//etatime = opseanEn.ETA.ToString();
}
sqlstr.Append("[PORTLOAD] = @PORTLOAD,[PORTDISCHARGE] = @PORTDISCHARGE,[GOODSNAME] = @GOODSNAME,");
sqlstr.Append("[GROSSWEIGHT] = @GROSSWEIGHT,[MEASUREMENT] = @MEASUREMENT,[OP] = @OP,[SALE] = @SALE,[CARRIER] = @CARRIER,UPDATEPPER=@UPDATEPPER,UPDATETIME=@UPDATETIME,GROSSWEIGHTUNIT=@GROSSWEIGHTUNIT,MEASUREMENTUNIT=@MEASUREMENTUNIT,LOADADDRESS=@LOADADDRESS,DELIVERADDRESS=@DELIVERADDRESS ");
sqlstr.Append(" WHERE BSNO=@BSNO ");
SqlParameter[] para = new SqlParameter[] {
new SqlParameter("@CUSTOMERNAME",opseanEn.CUSTOMERNAME),
new SqlParameter("@SHIPPER",opseanEn.SHIPPER),
new SqlParameter("@CONSIGNEE",opseanEn.CONSIGNEE),
new SqlParameter("@VESSEL",opseanEn.VESSEL),
new SqlParameter("@VOYNO",opseanEn.VOYNO),
new SqlParameter("@ETD",etdtime),
new SqlParameter("@ETA",etatime),
new SqlParameter("@PORTLOAD",opseanEn.PORTLOAD),
new SqlParameter("@PORTDISCHARGE",opseanEn.PORTDISCHARGE),
new SqlParameter("@GOODSNAME",opseanEn.GOODSNAME),
new SqlParameter("@GROSSWEIGHT",opseanEn.GROSSWEIGHT),
new SqlParameter("@MEASUREMENT",opseanEn.MEASUREMENT),
new SqlParameter("@OP",opseanEn.OP),
new SqlParameter("@SALE",opseanEn.SALE),
new SqlParameter("@CARRIER",opseanEn.CARRIER),
new SqlParameter("@UPDATEPPER",opseanEn.Updatepper),
new SqlParameter("@UPDATETIME",opseanEn.Updatetime),
new SqlParameter("@GROSSWEIGHTUNIT",opseanEn.Grossweightunit),
new SqlParameter("@MEASUREMENTUNIT",opseanEn.Measurementunit),
new SqlParameter("@LOADADDRESS",opseanEn.LOADADDRESS),
new SqlParameter("@DELIVERADDRESS",opseanEn.DELIVERADDRESS),
new SqlParameter("@BSNO",opseanEn.BSNO)
};
int result = 0;
using (conn)
{
int extnon = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, sqlstr.ToString(), para);
if (extnon > 0)
{
result = 1;//执行成功
}
else
{
result = -1;//执行失败
}
}
return result;
}
/// <summary>
/// 根据主键,查询委托信息()
/// </summary>
/// <param name="bsonID"></param>
/// <returns></returns>
public OpseanEntity GetInfoByBusnoID(string bsonID)
{
StringBuilder strr = new StringBuilder();
OpseanEntity oppean = new OpseanEntity();
strr.Append("SELECT BSSTATUS,FEESTATUS,ACCDATE,MBLNO,CUSTNO,CUSTOMERNAME,SHIPPER,CONSIGNEE,VESSEL,VOYNO,ETD,ETA,PORTLOAD,");
strr.Append("PORTDISCHARGE,GOODSNAME,GROSSWEIGHT,MEASUREMENT,INPUTBY,OP,SALE,CARRIER,GROSSWEIGHTUNIT,MEASUREMENTUNIT,LOADADDRESS,DELIVERADDRESS FROM [op_sean] ");
strr.Append(" WHERE BSNO=@BSNO ");
SqlParameter[] para=new SqlParameter[]{new SqlParameter("@BSNO",bsonID)};
DataSet DS;
try
{
DS = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction.ToString(), CommandType.Text, strr.ToString(), para);
if (DS.Tables[0].Rows.Count > 0)
{
oppean.BSSTATUS = Convert.ToBoolean(DS.Tables[0].Rows[0]["BSSTATUS"].ToString());
oppean.FEESTATUS = Convert.ToBoolean(DS.Tables[0].Rows[0]["FEESTATUS"].ToString());
oppean.ACCDATE = DS.Tables[0].Rows[0]["ACCDATE"].ToString();
oppean.MBLNO = DS.Tables[0].Rows[0]["MBLNO"].ToString();
oppean.CUSTNO = DS.Tables[0].Rows[0]["CUSTNO"].ToString();
oppean.CUSTOMERNAME = DS.Tables[0].Rows[0]["CUSTOMERNAME"].ToString();
oppean.SHIPPER = DS.Tables[0].Rows[0]["SHIPPER"].ToString();
oppean.CONSIGNEE = DS.Tables[0].Rows[0]["CONSIGNEE"].ToString();
oppean.VESSEL = DS.Tables[0].Rows[0]["VESSEL"].ToString();
oppean.VOYNO = DS.Tables[0].Rows[0]["VOYNO"].ToString();
if (DS.Tables[0].Rows[0]["ETD"].ToString() != "")
{
oppean.ETD = Convert.ToDateTime(DS.Tables[0].Rows[0]["ETD"].ToString());
}
if (DS.Tables[0].Rows[0]["ETA"].ToString() != "")
{
oppean.ETA = Convert.ToDateTime(DS.Tables[0].Rows[0]["ETA"].ToString());
}
oppean.PORTLOAD = DS.Tables[0].Rows[0]["PORTLOAD"].ToString();
oppean.PORTDISCHARGE = DS.Tables[0].Rows[0]["PORTDISCHARGE"].ToString();
oppean.GOODSNAME = DS.Tables[0].Rows[0]["GOODSNAME"].ToString();
oppean.GROSSWEIGHT = Convert.ToDecimal(DS.Tables[0].Rows[0]["GROSSWEIGHT"].ToString());
oppean.MEASUREMENT = Convert.ToDecimal(DS.Tables[0].Rows[0]["MEASUREMENT"].ToString());
oppean.INPUTBY = DS.Tables[0].Rows[0]["INPUTBY"].ToString();
oppean.OP = DS.Tables[0].Rows[0]["OP"].ToString();
oppean.SALE = DS.Tables[0].Rows[0]["SALE"].ToString();
oppean.CARRIER = DS.Tables[0].Rows[0]["CARRIER"].ToString();
oppean.Grossweightunit = DS.Tables[0].Rows[0]["GROSSWEIGHTUNIT"].ToString();
oppean.Measurementunit = DS.Tables[0].Rows[0]["MEASUREMENTUNIT"].ToString();
oppean.LOADADDRESS = DS.Tables[0].Rows[0]["LOADADDRESS"].ToString();
oppean.DELIVERADDRESS = DS.Tables[0].Rows[0]["DELIVERADDRESS"].ToString();
return oppean;
}
else
{
return oppean;
}
}
catch (Exception eorr)
{
throw eorr;
}
}
/// <summary>
/// 根据ID查询Sean的所有信息---------费用
/// </summary>
/// <param name="bsnoID"></param>
/// <returns></returns>
public OpseanEntity GetAllSeanInfo(string bsnoID)
{
OpseanEntity oppean = new OpseanEntity();
StringBuilder sqlstr = new StringBuilder();
sqlstr.Append("SELECT BSNO,ORDERTYPE,BSSTATUS,FEESTATUS,ACCDATE,MBLNO,CUSTNO,CUSTOMERNAME,SHIPPER,CONSIGNEE,VESSEL,VOYNO,ETD,ETA,PORTLOAD,PORTDISCHARGE,GOODSNAME,GROSSWEIGHT,");
sqlstr.Append("MEASUREMENT,INPUTBY,INPUTTIME,CORPID,OP,SALE,CARRIER,UPDATEPPER,UPDATETIME,GROSSWEIGHTUNIT,MEASUREMENTUNIT FROM [op_sean] WHERE BSNO=@BSNO");
SqlParameter[] para = new SqlParameter[] {
new SqlParameter("@BSNO",bsnoID)
};
using (SqlDataReader sqlread = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr.ToString(), para))
{
try
{
while (sqlread.Read())
{
if (!sqlread.IsDBNull(0)) { oppean.BSNO = sqlread.GetString(0); };
if (!sqlread.IsDBNull(1)) { oppean.ORDERTYPE = sqlread.GetString(1); }
if (!sqlread.IsDBNull(2)) { oppean.BSSTATUS = sqlread.GetBoolean(2); }
if (!sqlread.IsDBNull(3)) { oppean.FEESTATUS = sqlread.GetBoolean(3); }
if (!sqlread.IsDBNull(4)) { oppean.ACCDATE = sqlread.GetString(4); }
if (!sqlread.IsDBNull(5)) { oppean.MBLNO = sqlread.GetString(5); }
if (!sqlread.IsDBNull(6)) { oppean.CUSTNO = sqlread.GetString(6); }
if (!sqlread.IsDBNull(7)) { oppean.CUSTOMERNAME = sqlread.GetString(7); }
if (!sqlread.IsDBNull(8)) { oppean.SHIPPER = sqlread.GetString(8); }
if (!sqlread.IsDBNull(9)) { oppean.CONSIGNEE = sqlread.GetString(9); }
if (!sqlread.IsDBNull(10)) { oppean.VESSEL = sqlread.GetString(10); }
if (!sqlread.IsDBNull(11)) { oppean.VOYNO = sqlread.GetString(11); }
if (!sqlread.IsDBNull(12)) { oppean.ETD = sqlread.GetDateTime(12); }
if (!sqlread.IsDBNull(13)) { oppean.ETA = sqlread.GetDateTime(13); }
if (!sqlread.IsDBNull(14)) { oppean.PORTLOAD = sqlread.GetString(14); }
if (!sqlread.IsDBNull(15)) { oppean.PORTDISCHARGE = sqlread.GetString(15); }
if (!sqlread.IsDBNull(16)) { oppean.GOODSNAME = sqlread.GetString(16); }
if (!sqlread.IsDBNull(17)) { oppean.GROSSWEIGHT = sqlread.GetDecimal(17); }
if (!sqlread.IsDBNull(18)) { oppean.MEASUREMENT = sqlread.GetDecimal(18); }
if (!sqlread.IsDBNull(19)) { oppean.INPUTBY = sqlread.GetString(19); }
if (!sqlread.IsDBNull(20)) { oppean.INPUTTIME = sqlread.GetDateTime(20); }
if (!sqlread.IsDBNull(21)) { oppean.CORPID = sqlread.GetString(21); }
if (!sqlread.IsDBNull(22)) { oppean.OP = sqlread.GetString(22); }
if (!sqlread.IsDBNull(23)) { oppean.SALE = sqlread.GetString(23); }
if (!sqlread.IsDBNull(24)) { oppean.CARRIER = sqlread.GetString(24); }
if (!sqlread.IsDBNull(25)) { oppean.Updatepper = sqlread.GetString(25); }
if (!sqlread.IsDBNull(26)) { oppean.Updatetime = sqlread.GetDateTime(26); }
if (!sqlread.IsDBNull(27)) { oppean.Grossweightunit = sqlread.GetString(27); }
if (!sqlread.IsDBNull(28)) { oppean.Measurementunit = sqlread.GetString(28); }
}
}
catch (Exception error)
{
throw error;
}
}
return oppean;
}
/// <summary>
/// 根据bsno主键锁上内贸委托的费用状态
/// </summary>
/// <param name="bsno"></param>
/// <returns></returns>
public int LockSeanFeeStatus(string bsno)
{
string sqlstr = "UPDATE [op_sean] SET FEESTATUS=1 WHERE BSNO=@BSNO";
SqlParameter[] param = new SqlParameter[] { new SqlParameter("@BSNO",bsno)};
int iresult=0;
using (SqlTransaction sqltran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
SqlHelper.ExecuteNonQuery(sqltran, CommandType.Text, sqlstr, param);
sqltran.Commit();
iresult = 1;
}
catch (Exception error)
{
iresult = -1;
sqltran.Rollback();
iresult = -2;
throw error;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iresult;
}
/// <summary>
/// 根据bsno主键给上锁的内贸委托
/// </summary>
/// <param name="bsno"></param>
/// <returns></returns>
public int UnLockSeanFeeStatus(string bsno)
{
string sqlstr = "UPDATE [op_sean] SET FEESTATUS=0 WHERE BSNO=@BSNO";
SqlParameter[] param = new SqlParameter[] { new SqlParameter("@BSNO",bsno)};
int iresult = 0;
using (SqlTransaction sqltran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
SqlHelper.ExecuteNonQuery(sqltran, CommandType.Text, sqlstr, param);
sqltran.Commit();
iresult = 1;
}
catch (Exception error)
{
iresult = -1;
sqltran.Rollback();
iresult = -2;
throw error;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iresult;
}
/// <summary>
/// 根据登录人的公司id查询他的客户信息
/// </summary>
/// <param name="strCompanyID"></param>
/// <returns></returns>
public DataSet GetCustomName(string strCompanyID)
{
//System.Collections.ArrayList[] arlist=new System.Collections.ArrayList[20];
string sqlstr = "SELECT SHORTNAME,CORPID,NAME,(NAME+'_'+SHORTNAME)AS NEWNAME FROM [info_client] WHERE 1=1 AND ISCONTROLLER='True' AND ISSTOP=0 AND (CORPID=@CORPID OR gid IN(select clientid from info_client_share where ISSHARE=1 and companyid=@CORPID))";
SqlParameter[] para = new SqlParameter[] {
new SqlParameter("@CORPID",strCompanyID)
};
DataSet ds;
try
{
ds = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction.ToString(), CommandType.Text, sqlstr, para);
if (ds.Tables[0].Rows.Count > 0)
{
return ds;
}
else
{
return ds = null;
}
}
catch (Exception error)
{
throw error;
}
}
/// <summary>
/// 返回所有 船名
/// </summary>
/// <returns></returns>
public DataSet GetTCodeVessel()
{
string str = "select VSID,VESSEL,CNAME,(VESSEL+'_'+CNAME)AS NEWVESSL from code_vessel";
DataSet DS = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, str);
try
{
if (DS.Tables[0].Rows.Count <= 0)
{
DS = null;
}
}
catch
{
DS = null;
}
return DS;
}
/// <summary>
/// 根据公司id获取属性为船公司的信息
/// </summary>
/// <param name="strCompanyID"></param>
/// <returns></returns>
public DataSet GetCarrierName(string strCompanyID)
{
StringBuilder sqlstr = new StringBuilder();
sqlstr.Append("select SHORTNAME,NAME,(NAME+'_'+SHORTNAME)AS NEWNAME from info_client where 1=1 and (ISCARRIER='True') ");
sqlstr.Append("and ISSTOP=0 and (CORPID=@CompanyID or gid in(select clientid from info_client_share ");
sqlstr.Append("where ISSHARE=1 and companyid=@CompanyID)) order by CODENAME");
SqlParameter[] para = new SqlParameter[] {
new SqlParameter("@CompanyID",strCompanyID)
};
DataSet ds;
try
{
ds = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr.ToString(), para);
}
catch
{
ds = null;
}
return ds;
}
/// <summary>
/// 返回所有 起运港口
/// </summary>
/// <returns></returns>
public DataSet GetTCodeLoadport()
{
string str = "select *,(PORT+'_'+CNAME)AS NEWPORT from code_loadport ";
DataSet DS = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, str);
try
{
if (DS.Tables[0].Rows.Count <= 0)
{
DS = null;
}
}
catch
{
DS = null;
}
return DS;
}
/// <summary>
/// 返回所有 卸货港、目的港、交货地
/// </summary>
/// <returns></returns>
public DataSet GetTCodeDisport()
{
string str = "select PORT,CNAME,(PORT+'_'+CNAME)AS NEWPORT from code_disport order by PORT";
DataSet DS = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, str);
try
{
if (DS.Tables[0].Rows.Count <= 0)
{
DS = null;
}
}
catch
{
DS = null;
}
return DS;
}
/// <summary>
/// 返回所有 分公司代码
/// </summary>
/// <param name="strUserID">用户GID</param>
/// <returns></returns>
public String GetCORPID(string strUserID)
{
string str = "select COMPANYID from user_company where USERID='" + strUserID + "' and COMPANYID in (select GID from [company] where ISDELETED=0 and ISDISABLE=0)";
DataSet DS = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, str);
if (DS.Tables[0].Rows.Count > 0)
{
str = DS.Tables[0].Rows[0]["COMPANYID"].ToString();
}
else
{
str = "";
}
return str;
}
/// <summary>
/// 根据员工id和工作类型返回揽货人及发货人信息
/// </summary>
/// <param name="userID"></param>
/// <returns></returns>
public DataSet GetSaleManInfo(string strUserID, string worktype)
{
string strCORPID = GetCORPID(strUserID);
string str = "select CODENAME,SHOWNAME from [user] where GID in(select USERID from user_company where COMPANYID='" + strCORPID + "' and USERID in(select USERID from user_userattribute where ATTRIBUTEID in(select GID from user_attribute where [NAME]='" + worktype + "') and value='true')) and ISDISABLE=0 and ISDELETED=0";
DataSet ds;
using(ds = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, str))
{
if (ds.Tables[0].Rows.Count > 0)
{
return ds;
}
else
{
return ds=null;
}
}
}
/// <summary>
/// 获得货物信息--名称等
/// </summary>
/// <returns></returns>
public DataSet GetGoodsInfo()
{
string str = "select GOODCODE, GOODNAME,(GOODCODE+'_'+GOODNAME) AS CODEANDNAME from code_goods order by GOODCODE";
DataSet DS = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, str);
try
{
if (DS.Tables[0].Rows.Count <= 0)
{
DS = null;
}
}
catch
{
DS = null;
}
return DS;
}
/// <summary>
/// 根据委托编号加载集装箱信息
/// </summary>
/// <param name="bsno"></param>
/// <returns></returns>
//public DataSet GetBoxInfo(string bsno)
//{
// StringBuilder sqlstr = new StringBuilder();
// DataSet ds;
// sqlstr.Append("SELECT CTN_ID,CTN,CTNALL,CTNNUM,CNTRNO,SEALNO,PKGS,KINDPKGS,KGS,TAREWEIGHT,CBM,REMARK FROM op_ctn");
// try
// {
// if (bsno == "" || bsno == null)
// {
// sqlstr.Append(" WHERE 1<0 ");
// ds = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction.ToString(),CommandType.Text,sqlstr.ToString());
// return ds;
// }
// else
// {
// sqlstr.Append(" WHERE BSNO =@BSNO ORDER BY CTN_ID");
// SqlParameter[] param = new SqlParameter[] {
// new SqlParameter("@BSNO",bsno)
// };
// ds = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction.ToString(), CommandType.Text, sqlstr.ToString(), param);
// return ds;
// }
// }
// catch (Exception error)
// {
// throw error;
// }
//}
public DataSet GetBoxInfo(string bsno)
{
StringBuilder sqlstr1 = new StringBuilder();
sqlstr1.Append("CREATE FUNCTION dbo.f_strUnite(@id varchar(100),@bsno varchar(100)) ");
sqlstr1.Append("RETURNS varchar(100) ");
sqlstr1.Append("AS ");
sqlstr1.Append("BEGIN ");
sqlstr1.Append("DECLARE @str varchar(10) ");
sqlstr1.Append("SET @str = '' ");
sqlstr1.Append(" SELECT @str = @str +','+ CONVERT(varchar(10),D.TEAMTYPE) FROM ( ");
sqlstr1.Append("select A.CTN_ID,BSNO,CTN,CTNNUM,CNTRNO,SEALNO,PKGS,KINDPKGS,KGS,TAREWEIGHT,CBM,GOODSNAME,A.REMARK,");
sqlstr1.Append(" C.TEAMTYPE FROM [op_ctn] A INNER JOIN [op_ctn_truck] B ON A.CTN_ID=B.CTN_ID INNER JOIN [op_letter_truck] C ON B.LE_ID=C.LE_ID WHERE 1>0 ");
//sqlstr1.Append("WHERE A.BSNO IN (SELECT BSNO FROM[op_sean]WHERE CORPID=@companyid AND BSSTATUS=0) ");
sqlstr1.Append(" and A.BSNO=@bsno ");
sqlstr1.Append("AND C.ISTEAMSTATUS=1");
sqlstr1.Append("GROUP BY A.CTN_ID,BSNO,CTN,CTNNUM,CNTRNO,SEALNO,PKGS,KINDPKGS,KGS,TAREWEIGHT,CBM,A.REMARK,B.TEAMTYPE,C.TEAMTYPE,GOODSNAME ");
sqlstr1.Append(")D WHERE D.CTN_ID=@id ");
sqlstr1.Append("RETURN STUFF(@str, 1, 1, '') ");
sqlstr1.Append(" END ");
sqlstr1.Append(" GO");
StringBuilder sqlstr2 = new StringBuilder();
//sqlstr2.Append("SELECT distinct A.CTN_ID,BSNO,CTN,CTNNUM,CNTRNO,SEALNO,PKGS,KINDPKGS,KGS,TAREWEIGHT,CBM,GOODSNAME,A.REMARK,");
//sqlstr2.Append("dbo.f_strUnite(A.CTN_ID,BSNO) AS NEWSTATUS FROM [op_ctn] A left JOIN ");
//sqlstr2.Append("[op_ctn_truck] B ON A.CTN_ID=B.CTN_ID left JOIN [op_letter_truck] C ON B.LE_ID=C.LE_ID WHERE ");
sqlstr2.Append("SELECT distinct A.CTN_ID,BSNO,CTN,CTNNUM,CNTRNO,SEALNO,PKGS,KINDPKGS,KGS,TAREWEIGHT,CBM,GOODSNAME,A.REMARK,");
sqlstr2.Append("dbo.f_strUnite(A.CTN_ID,BSNO) AS NEWSTATUS,[dbo].[f_strUnite2](A.CTN_ID,BSNO)AS NEWISTATUS FROM [op_ctn] A left JOIN ");
sqlstr2.Append("[op_ctn_truck] B ON A.CTN_ID=B.CTN_ID left JOIN [op_letter_truck] C ON B.LE_ID=C.LE_ID WHERE ");
if (bsno != "")
{
sqlstr2.Append(" A.BSNO=@BSNO ");
}
else
{
sqlstr2.Append("1<0 ");
}
//sqlstr2.Append("AND C.ISTEAMSTATUS=1 ");
sqlstr2.Append("GROUP BY A.CTN_ID,BSNO,CTN,CTNNUM,CNTRNO,SEALNO,PKGS,KINDPKGS,KGS,TAREWEIGHT,CBM,A.REMARK,B.TEAMTYPE,GOODSNAME,C.ISTEAMSTATUS");
StringBuilder sqlstr3 = new StringBuilder();
sqlstr3.Append("drop function dbo.f_strUnite");
SqlParameter[] param = new SqlParameter[] {
new SqlParameter("@BSNO",bsno),
};
DataSet ds;
try
{
ds = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr2.ToString(), param);
}
catch (Exception error)
{
throw error;
}
#region
//using (SqlTransaction sqlstran = SqlHelper.BeginTransaction (SqlHelper.ConnectionStringLocalTransaction))
//{
// try
// {
// //SqlHelper.ExecuteNonQuery(sqlstran, CommandType.Text, sqlstr1.ToString());
// ds = SqlHelper.ExecuteDataset(sqlstran.ToString(), CommandType.Text, sqlstr2.ToString(), param);
// //SqlHelper.ExecuteNonQuery(sqlstran, CommandType.Text, sqlstr3.ToString());
// sqlstran.Commit();
// }
// catch (Exception error)
// {
// sqlstran.Rollback();
// throw error;
// }
// finally
// {
// SqlHelper.CloseConnection();
// }
//}
#endregion
return ds;
}
/// <summary>
/// 集装箱中箱型
/// </summary>
/// <returns></returns>
public DataSet GetAllCtn()
{
//List<string> listt=new List<string>();
string sqlstr = "select * from code_ctn order by CTN";
//SqlDataReader read = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction.ToString(),CommandType.Text,sqlstr);
//while (read.Read())
//{
//}
DataSet ds;
using ( ds= SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr))
{
if (ds.Tables[0].Rows.Count < 0)
{
ds = null;
}
}
return ds;
}
/// <summary>
/// 集装箱包装类型
/// </summary>
/// <returns></returns>
public DataSet GetALLPkgs()
{
string str = "select * from code_package order by PKGS";
DataSet DS = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, str);
try
{
if (DS.Tables[0].Rows.Count <= 0)
{
DS = null;
}
}
catch
{
DS = null;
}
return DS;
}
/// <summary>
/// 修改opctn的信息
/// </summary>
/// <returns></returns>
public int UpdateOpCtn(OpctnEntity opctn)
{
StringBuilder sqlstr = new StringBuilder();
sqlstr.Append("UPDATE [op_ctn] SET [CTN] = @CTN,[CTNNUM] = @CTNNUM,");
sqlstr.Append("[CNTRNO] = @CNTRNO,[SEALNO] = @SEALNO,[PKGS] = @PKGS,[KGS] = @KGS,[CBM] = @CBM,[REMARK] = @REMARK, ");
sqlstr.Append("[KINDPKGS] = @KINDPKGS,[TAREWEIGHT] = @TAREWEIGHTWHERE,[GOODSNAME]=@GOODSNAME WHERE CTN_ID=@CTNID");
SqlParameter[] param = new SqlParameter[] {
new SqlParameter("@CTN",opctn.CTN),
new SqlParameter("@CTNNUM",opctn.CTNNUM),
new SqlParameter("@CNTRNO",opctn.CNTRNO),
new SqlParameter("@SEALNO",opctn.SEALNO),
new SqlParameter("@PKGS",opctn.PKGS),
new SqlParameter("@KGS",opctn.KGS),
new SqlParameter("@CBM",opctn.CBM),
new SqlParameter("@REMARK",opctn.REMARK),
new SqlParameter("@KINDPKGS",opctn.KINDPKGS),
new SqlParameter("@TAREWEIGHTWHERE",opctn.TAREWEIGHT),
new SqlParameter("@CTNID",opctn.CTN_ID),
new SqlParameter("@GOODSNAME",opctn.Goodsname)
};
int result = 0;
using (conn)
{
try
{
SqlHelper.ExecuteNonQuery(conn, CommandType.Text, sqlstr.ToString(), param);
result = 1;
}
catch (Exception error)
{
result = -1;
throw error;
}
}
return result;
}
/// <summary>
/// 添加新的集装箱箱型箱量信息
/// </summary>
/// <param name="strBsno"></param>
/// <returns></returns>
public void CreatNewContainer(string ctnid ,string strBsno)
{
StringBuilder sqlstr = new StringBuilder();
sqlstr.Append(" INSERT INTO [op_ctn]([CTN_ID],[BSNO],[CTNNUM])");
sqlstr.Append(" VALUES(@CTN_ID,@BSNO,@CTNNUM)");
SqlParameter[] param = new SqlParameter[] {
new SqlParameter("@CTN_ID",ctnid),
new SqlParameter("@BSNO",strBsno),
new SqlParameter("@CTNNUM",1)
};
try
{
SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction.ToString(), CommandType.Text, sqlstr.ToString(), param);
}
catch (Exception error)
{
throw error;
}
}
/// <summary>
/// 获取新添加 的集装箱箱型箱量信息
/// </summary>
/// <param name="ctnid"></param>
/// <returns></returns>
public DataSet GetNewContainer(string bsno)
{
//string sqlstr = "select * from [op_ctn] where 1=1 and bsno='"+bsno.Trim()+"' order by bsno desc ";
StringBuilder sqlstr2 = new StringBuilder();
sqlstr2.Append("SELECT distinct A.CTN_ID,BSNO,CTN,CTNNUM,CNTRNO,SEALNO,PKGS,KINDPKGS,KGS,TAREWEIGHT,CBM,GOODSNAME,A.REMARK,");
sqlstr2.Append("dbo.f_strUnite(A.CTN_ID,BSNO) AS NEWSTATUS,[dbo].[f_strUnite2](A.CTN_ID,BSNO)AS NEWISTATUS FROM [op_ctn] A left JOIN ");
sqlstr2.Append("[op_ctn_truck] B ON A.CTN_ID=B.CTN_ID left JOIN [op_letter_truck] C ON B.LE_ID=C.LE_ID WHERE ");
if (bsno != "")
{
sqlstr2.Append(" A.BSNO=@BSNO ");
}
else
{
sqlstr2.Append("1<0 ");
}
//sqlstr2.Append("AND C.ISTEAMSTATUS=1 ");
sqlstr2.Append("GROUP BY A.CTN_ID,BSNO,CTN,CTNNUM,CNTRNO,SEALNO,PKGS,KINDPKGS,KGS,TAREWEIGHT,CBM,A.REMARK,B.TEAMTYPE,C.TEAMTYPE,GOODSNAME order by CTNNUM asc");
SqlParameter[] param=new SqlParameter[]{new SqlParameter("@BSNO",bsno)};
DataSet ds;
try
{
ds = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction.ToString(), CommandType.Text, sqlstr2.ToString(),param);
}
catch (Exception error)
{
ds = null;
throw error;
}
return ds;
}
/// <summary>
/// 通过主键删除ctn的信息
/// </summary>
/// <param name="CTNIDS"></param>
/// <returns></returns>
public int DeleteCtnByID(string[] CTNIDS)
{
string sqlstr = "delete from [op_ctn] where ";
for (int i = 0; i <= CTNIDS.Length - 1; i++)
{
sqlstr += " CTN_ID='" + CTNIDS[i] + "' OR";
}
sqlstr = sqlstr.Substring(0, sqlstr.Length - 3);
int result = 0;
try
{
SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr);
result = 1;
}
catch (Exception error)
{
result = -1;
throw error;
}
return result;
}
/// <summary>
/// 根据ctnid删除信息
/// </summary>
/// <param name="ID"></param>
/// <returns></returns>
public int DelteCTNBYID(string ID)
{
string sqlstr = "delete from [op_ctn] where CTN_ID='"+ID+"' ";
int result = 0;
try
{
SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr);
result = 1;
}
catch (Exception error)
{
result = -1;
throw error;
}
return result;
}
/// <summary>
/// 根据ctnid删除多项集装箱信息
/// </summary>
/// <param name="sqlstr"></param>
/// <returns></returns>
public int DelteCtnID(string sqlstr)
{
int result = 0;
try
{
SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction.ToString(), CommandType.Text, sqlstr);
result = 1;
}
catch
{
result = -1;
throw;
}
return result;
}
/// <summary>
/// 判断新的运单号是否存在
/// </summary>
/// <param name="newMblno"></param>
/// <returns></returns>
public int ConfirMblnoIfExist(string newMblno)
{
string sqlstr = "select count(*) from dbo.op_sean where mblno=@mblno ";
SqlParameter[] param = new SqlParameter[] { new SqlParameter("@mblno", newMblno) };
int iresult;
try
{
iresult = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr, param));
}
catch (Exception error)
{
throw error;
}
return iresult;
}
//////////////////////////////////////////////////////******************内贸信息显示\|/*********************************//////////////////////////////////////////////////
/// <summary>
/// 获得内贸委托信息的数据
/// </summary>
/// <param name="companyID"></param>
/// <returns></returns>
public DataSet GetOPSEAN(string companyID)
{
StringBuilder sqlstr = new StringBuilder();
sqlstr.Append("SELECT CARRIER,VOYNO FROM [op_sean] WHERE CORPID=@CORPID order by INPUTTIME desc");
SqlParameter[] param = new SqlParameter[] {
new SqlParameter("@CORPID",companyID)
};
DataSet ds;
try
{
ds = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr.ToString(), param);
}
catch (Exception error)
{
ds = null;
throw error;
}
return ds;
}
/// <summary>
/// 根据条件查询
/// </summary>
/// <returns></returns>
public DataSet GetDataByConditon(string etdtime,string etatime,string accdate,string allsearch)
{
StringBuilder sqlstr=new StringBuilder();
sqlstr.Append("SELECT distinct A.BSNO,ORDERTYPE,BSSTATUS,FEESTATUS,ACCDATE,MBLNO,CUSTNO,CUSTOMERNAME,SHIPPER,CONSIGNEE, VESSEL,VOYNO,ETD,");
sqlstr.Append("ETA,PORTLOAD,PORTDISCHARGE,A.GOODSNAME,GROSSWEIGHT,MEASUREMENT,INPUTBY,INPUTTIME,CORPID,OP,SALE,CARRIER,UPDATEPPER,UPDATETIME,GROSSWEIGHTUNIT,MEASUREMENTUNIT,LOADADDRESS,DELIVERADDRESS FROM [op_sean] as A LEFT JOIN [op_ctn] as B ON A.BSNO=B.BSNO WHERE 1=1");
#region
if (etdtime != ""&&etatime=="")
{
sqlstr.Append(" and ETD!<'"+ Convert.ToDateTime(etdtime)+"'");
}
if (etdtime != "" && etatime !="")
{
sqlstr.Append(" and ETD!< '"+ Convert.ToDateTime(etdtime)+"' and ETA!>'"+Convert.ToDateTime(etatime)+"'");
}
if (etdtime =="" && etatime != "")
{
sqlstr.Append(" and ETA!>'" +Convert.ToDateTime(etatime) + "'");
}
if (accdate != "")
{
sqlstr.Append(" and ACCDATE='" + accdate.Trim() + "'");
}
if (allsearch != "")
{
sqlstr.Append(" and (VESSEL like '%" + allsearch.Trim() + "%' or VOYNO like '%" + allsearch.Trim() + "%' or MBLNO like '%" + allsearch.Trim() + "%' or CUSTOMERNAME like '%" + allsearch.Trim() + "%' or CNTRNO like '%"+allsearch.Trim()+"%' ");
sqlstr.Append(" or SHIPPER like '%" + allsearch.Trim() + "%' or CONSIGNEE like '%" + allsearch.Trim() + "%' or SALE like '%" + allsearch.Trim() + "%' or LOADADDRESS like '%" + allsearch.Trim() + "%' or DELIVERADDRESS like '%" + allsearch.Trim() + "%' ");
sqlstr.Append(" or SEALNO like '%" + allsearch.Trim() + "%' or CARRIER like '%" + allsearch.Trim() + "%' or A.GOODSNAME like '%" + allsearch.Trim() + "%' or PORTLOAD like '%" + allsearch.Trim() + "%' or PORTDISCHARGE like '%"+allsearch.Trim()+"%'");
sqlstr.Append(") ");
}
#endregion
DataSet ds;
try
{
ds = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr.ToString());
}
catch
{
ds = null;
}
return ds;
}
/// <summary>
/// 委托信息导出excel语句
/// </summary>
/// <param name="etdtime"></param>
/// <param name="etatime"></param>
/// <param name="vessname"></param>
/// <param name="voyonum"></param>
/// <param name="mblno"></param>
/// <param name="custoname"></param>
/// <param name="accdate"></param>
/// <param name="cntrno"></param>
/// <param name="shipper"></param>
/// <param name="consignee"></param>
/// <param name="sale"></param>
/// <param name="loadaddress"></param>
/// <param name="deliveraddress"></param>
/// <param name="sealno"></param>
/// <param name="carrier"></param>
/// <param name="goodname"></param>
/// <param name="portload"></param>
/// <param name="portdischarge"></param>
/// <returns></returns>
public DataSet SetOpseanEcxel(string etdtime, string etatime,string accdate,string allsearch)
{
StringBuilder sqlstr = new StringBuilder();
sqlstr.Append("SELECT distinct CUSTNO,CUSTOMERNAME,ORDERTYPE,(CASE BSSTATUS WHEN '0' THEN '未锁定' ELSE '已锁定' end) AS BSSTATUS,");
sqlstr.Append("(CASE FEESTATUS WHEN '0' THEN '未锁定' ELSE '已锁定' end)AS FEESTATUS,ACCDATE,MBLNO,SHIPPER,");
sqlstr.Append("CONSIGNEE,CARRIER, VESSEL,VOYNO,ETD,ETA,PORTLOAD,PORTDISCHARGE,A.GOODSNAME,GROSSWEIGHT,GROSSWEIGHTUNIT,MEASUREMENT,MEASUREMENTUNIT,OP,SALE,INPUTBY,INPUTTIME,UPDATEPPER,UPDATETIME,LOADADDRESS,DELIVERADDRESS");
sqlstr.Append(" FROM [op_sean] as A LEFT JOIN [op_ctn] as B ON A.BSNO=B.BSNO WHERE 1=1");
#region
if (etdtime != "" && etatime =="")
{
sqlstr.Append(" and ETD!<'" + etdtime + "'");
}
if (etdtime != "" && etatime != "")
{
sqlstr.Append(" and ETD!< '" + etdtime + "' and ETA!>'" + etatime + "'");
}
if (etdtime == "" && etatime != "")
{
sqlstr.Append(" and ETA!>'" + etatime + "'");
}
if (accdate != "")
{
sqlstr.Append(" and ACCDATE='" + accdate.Trim() + "'");
}
if (allsearch != "")
{
sqlstr.Append(" and (VESSEL like '%" + allsearch.Trim() + "%' or VOYNO like '%" + allsearch.Trim() + "%' or MBLNO like '%" + allsearch.Trim() + "%' or CUSTOMERNAME like '%" + allsearch.Trim() + "%' or CNTRNO like '%" + allsearch.Trim() + "%' ");
sqlstr.Append(" or SHIPPER like '%" + allsearch.Trim() + "%' or CONSIGNEE like '%" + allsearch.Trim() + "%' or SALE like '%" + allsearch.Trim() + "%' or LOADADDRESS like '%" + allsearch.Trim() + "%' or DELIVERADDRESS like '%" + allsearch.Trim() + "%' ");
sqlstr.Append(" or SEALNO like '%" + allsearch.Trim() + "%' or CARRIER like '%" + allsearch.Trim() + "%' or A.GOODSNAME like '%" + allsearch.Trim() + "%' or PORTLOAD like '%" + allsearch.Trim() + "%' or PORTDISCHARGE like '%" + allsearch.Trim() + "%'");
sqlstr.Append(") ");
}
#endregion
DataSet ds;
try
{
ds = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr.ToString());
}
catch
{
ds = null;
}
return ds;
}
/// <summary>
///一次 删除多个内贸信息byBSNO
/// </summary>
/// <param name="bsno"></param>
public int DeleteSeanInfo(string[] bsno)
{
string sqlstr = "delete from [op_sean] where";
for (int i = 0; i <= bsno.Length - 1; i++)
{
sqlstr += " BSNO='"+bsno[i]+"' or";
}
sqlstr = sqlstr.Substring(0, sqlstr.Length - 3);
int resutl = 0;
try
{
SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr);
resutl = 1;
}
catch (Exception error)
{
resutl = 0;
throw error;
}
return resutl;
}
//********************************************集装箱生成派车单*****************************************
/// <summary>
/// 获得所有已经存在派车单的信息---完成或未完成
/// </summary>
/// <returns></returns>
public DataSet GetNewCtnInfo()
{
StringBuilder sqlstr = new StringBuilder();
sqlstr.Append("select A.LE_ID,A.TRUCK,A.INPUTTIME,A.TEAMTYPE,A.ISTEAMSTATUS,A.INPUTBY from [op_letter_truck] A where 1>0 ");
sqlstr.Append(" and (A.TEAMTYPE=0 or A.TEAMTYPE=1) and A.LE_ID IN(select B.LE_ID from [op_ctn_truck] B where ");
sqlstr.Append(" (B.TEAMTYPE=0 or B.TEAMTYPE=1)) ");
DataSet ds;
try
{
ds=SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr.ToString());
}
catch (Exception error)
{
ds=null;
throw error;
}
return ds;
}
/// <summary>
/// 根据条件查询派车通知信息
/// </summary>
/// <param name="startime"></param>
/// <param name="enttime"></param>
/// <param name="truck"></param>
/// <param name="teamtype"></param>
/// <returns></returns>
public DataTable SearchTrucBy(string startime, string enttime, string teamtypeload,string teamtypesend,string moresearch)
{
StringBuilder sqlstr = new StringBuilder();
//sqlstr.Append("select A.LE_ID,A.TRUCK,A.INPUTTIME,A.TEAMTYPE,A.ISTEAMSTATUS,A.INPUTBY from [op_letter_truck] A inner join [op_ctn_truck] B ON A.LE_ID=B.LE_ID ");
sqlstr.Append("select distinct A.LE_ID,A.TRUCK,A.INPUTTIME,A.TEAMTYPE,A.ISTEAMSTATUS,A.INPUTBY from [op_letter_truck] A left join [op_ctn_truck] B ON A.LE_ID=B.LE_ID ");
sqlstr.Append(" inner join [op_ctn] C on B.CTN_ID=C.CTN_ID INNER JOIN [op_sean] D on C.BSNO=D.BSNO ");
sqlstr.Append(" where 1>0 ");
if (startime != "" && enttime != "")
{
sqlstr.Append(" and A.INPUTTIME between '"+ Convert.ToDateTime(startime.ToString().Trim())+"' and '"+ Convert.ToDateTime(enttime.ToString().Trim())+"' ");
}
if (startime != ""&&enttime=="")
{
sqlstr.Append(" and A.INPUTTIME !< '"+ Convert.ToDateTime(startime.ToString().Trim())+"' ");
}
if (startime == "" && enttime != "")
{
sqlstr.Append(" and A.INPUTTIME !> '"+ Convert.ToDateTime(enttime.ToString().Trim())+"' ");
}
if (teamtypeload != ""&&teamtypesend!="")
{
sqlstr.Append(" and (A.TEAMTYPE=0 or A.TEAMTYPE=1) ");
}
if (teamtypeload != "" && teamtypesend == "")
{
sqlstr.Append(" and A.TEAMTYPE=0 ");
}
if (teamtypeload == "" && teamtypesend != "")
{
sqlstr.Append(" and A.TEAMTYPE=1 ");
}
if (moresearch != "")
{
sqlstr.Append(" and(");
sqlstr.Append("A.TRUCK like '%" + moresearch.ToString() + "%' or D.MBLNO LIKE '%" + moresearch.Trim() + "%' or D.DCUSTOMERNAME LIKE '%" + moresearch.Trim() + "%' ");
sqlstr.Append(" or C.CTN like '%" + moresearch.Trim() + "%' or C.CTNNUM like '%" + moresearch.Trim() + "%' or D.LOADADDRESS LIKE '%" + moresearch.Trim() + "%' ");
sqlstr.Append(" or D.DELIVERADDRESS LIKE '%" + moresearch.Trim() + "%' or D.VESSEL like '%" + moresearch.Trim() + "%' or D.VOYNO like '%"+moresearch.Trim()+"%' ");
sqlstr.Append(" or B.DRIVER LIKE '%" + moresearch.Trim() + "%' or B.TRUCKNO LIKE '%" + moresearch.Trim() + "%' or C.CNTRNO like '%" + moresearch.Trim() + "%' or C.SEALNO like '%"+moresearch.Trim()+"%'");
sqlstr.Append(") ");
}
sqlstr.Append(" GROUP BY A.LE_ID,A.TRUCK,A.INPUTTIME,A.TEAMTYPE,A.ISTEAMSTATUS,A.INPUTBY ");
DataTable table;
try
{
table = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr.ToString()).Tables[0];
}
catch (Exception error)
{
throw error;
}
return table;
}
/// <summary>
/// 根据id出多项派车通知单信息
/// </summary>
/// <param name="items"></param>
/// <returns></returns>
public int DeleteLetterTruckbyID(string[] items)
{
string leids = "";
string sqlstr = "delete from [op_letter_truck] where ";
string updatesql = "update [op_ctn_truck] set le_id=null ,teamtype=null,isteamstatus=null where ";
for (int i = 0; i <= items.Length - 1;i++)
{
leids += " LE_ID='" + items[i] + "' or";
}
leids = leids.Substring(0, leids.Length - 3);
sqlstr = sqlstr + leids;
updatesql = updatesql + leids;
int iresult = 0;
using (SqlTransaction tran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr.Trim());
SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, updatesql.Trim());
tran.Commit();
iresult = 1;
}
catch (Exception error)
{
tran.Rollback();
iresult = -1;
throw error;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iresult;
}
//**************************************************派车单制作*******************************************
/// <summary>
/// 获得没有形成单据或者形成单据的的集装箱信息
/// </summary>
/// <param name="companyID">登录人的公司id</param>
/// <returns></returns>
public DataTable GetCtnEmptyInfo(string companyID)
{
StringBuilder sqlstr = new StringBuilder();
#region
//sqlstr.Append("select A.CTN_ID,A.BSNO,CTN,CTNNUM,CNTRNO,SEALNO,KGS,REMARK,GOODSNAME, ");
//sqlstr.Append(" GID,LE_ID,TRUCKNO,DRIVER,IDENTITYCARD,MOBILE,B.TEAMTYPE,B.ISTEAMSTATUS from [op_ctn] A full JOIN [op_ctn_truck] B ");
//sqlstr.Append(" ON A.CTN_ID=B.CTN_ID WHERE A.BSNO IN(select bsno from [op_sean] where CORPID=@companyID and BSSTATUS=0) or (B.TEAMTYPE=0 AND B.ISTEAMSTATUS=0) ");
//sqlstr.Append(" ORDER BY A.CTN_ID ");
//sqlstr.Append("select A.CTN_ID,A.BSNO,CTN,CTNNUM,CNTRNO,SEALNO,KGS,REMARK,GOODSNAME,GID,LE_ID,TRUCKNO,DRIVER,IDENTITYCARD,MOBILE,B.TEAMTYPE,B.ISTEAMSTATUS from [op_ctn] A left join [op_ctn_truck] B");
//sqlstr.Append(" ON A.CTN_ID=B.CTN_ID WHERE A.BSNO IN(select bsno from [op_sean] where CORPID=@companyID and BSSTATUS=0) and A.CTN_ID NOT in (select CTN_ID from [op_ctn_truck] where TEAMTYPE=0) order by A.CTN_ID desc");
//////sqlstr.Append(" select A.CTN_ID,A.BSNO,CTN,CTNNUM,CNTRNO,SEALNO,KGS,REMARK,A.GOODSNAME,MBLNO,CUSTNO,(VESSEL+'/'+VOYNO)as VessAndVoyno,");
//////sqlstr.Append("GID,TRUCKNO,DRIVER,IDENTITYCARD,MOBILE,TEAMTYPE,ISTEAMSTATUS from [op_sean] B INNER JOIN [op_ctn] A ON B.BSNO=A.BSNO LEFT JOIN [op_ctn_truck] C ON A.CTN_ID=C.CTN_ID ");
//////sqlstr.Append("WHERE B.BSSTATUS=0 AND B.CORPID=@companyID AND A.CTN_ID NOT in (select CTN_ID from [op_ctn_truck] where teamtype=0) order by A.CTN_ID desc");
#endregion
sqlstr.Append("select A.CTN_ID,A.BSNO,CTN,CTNNUM,CNTRNO,SEALNO,KGS,REMARK,A.GOODSNAME,MBLNO,CUSTNO,(VESSEL+'/'+VOYNO)as VessAndVoyno,");
sqlstr.Append("GID,TRUCKNO,DRIVER,IDENTITYCARD,MOBILE,TEAMTYPE,ISTEAMSTATUS ");
sqlstr.Append("from [op_sean] B INNER JOIN [op_ctn] A ON B.BSNO=A.BSNO LEFT JOIN [op_ctn_truck] C ON A.CTN_ID=C.CTN_ID ");
sqlstr.Append("WHERE B.BSSTATUS=0 AND B.CORPID=@companyID AND A.CTN_ID NOT in (select distinct CTN_ID FROM [op_ctn_truck] where (TEAMTYPE=0 or TEAMTYPE=1)) ");
sqlstr.Append("union ");
sqlstr.Append("select A.CTN_ID,A.BSNO,CTN,CTNNUM,CNTRNO,SEALNO,KGS,REMARK,A.GOODSNAME,MBLNO,CUSTNO,(VESSEL+'/'+VOYNO)as VessAndVoyno,");
sqlstr.Append("null AS GID,null AS TRUCKNO,null AS DRIVER,null AS IDENTITYCARD,null AS MOBILE,null AS TEAMTYPE,null AS ISTEAMSTATUS ");
sqlstr.Append("from [op_sean] B INNER JOIN [op_ctn] A ON B.BSNO=A.BSNO LEFT JOIN [op_ctn_truck] C ON A.CTN_ID=C.CTN_ID ");
sqlstr.Append("WHERE B.BSSTATUS=0 AND B.CORPID=@companyID ");
sqlstr.Append("AND A.CTN_ID in (select CTN_ID FROM [op_ctn_truck] where TEAMTYPE=1 AND ISTEAMSTATUS=0 GROUP BY CTN_ID HAVING count(CTN_ID)=1) ");
SqlParameter[] param = new SqlParameter[] { new SqlParameter("@companyID",companyID) };
DataTable table;
try
{
table = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr.ToString(), param).Tables[0];
}
catch (Exception error)
{
table = null;
throw error;
}
return table;
}
/// <summary>
/// 根据多项通知单id获得需要编辑的派车单信息
/// </summary>
/// <param name="gid"></param>
/// <returns></returns>
public DataTable GetCtnEditInfo(string[] gid,string companyID)
{
StringBuilder sqltr = new StringBuilder();
sqltr.Append(" select A.CTN_ID,A.BSNO,CTN,CTNNUM,CNTRNO,SEALNO,KGS,REMARK,A.GOODSNAME,MBLNO,CUSTNO,(VESSEL+'/'+VOYNO)as VessAndVoyno,LOADADDRESS,DELIVERADDRESS, ");
sqltr.Append(" GID,TRUCKNO,DRIVER,IDENTITYCARD,MOBILE,TEAMTYPE,ISTEAMSTATUS ");
sqltr.Append(" from [op_sean] B INNER JOIN [op_ctn] A ON B.BSNO=A.BSNO LEFT JOIN [op_ctn_truck] C ON A.CTN_ID=C.CTN_ID WHERE B.CORPID=@companyID AND (");
for (int i = 0; i <= gid.Length - 1; i++)
{
sqltr.Append(" C.LE_ID='"+gid[i].Trim()+"' or ");
}
sqltr = sqltr.Remove(sqltr.Length-3,3);
sqltr.Append(" )");
SqlParameter[] param = new SqlParameter[] { new SqlParameter("@companyID",companyID) };
DataTable table;
try
{
table = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqltr.ToString(),param).Tables[0];
}
catch (Exception error)
{
table = null;
throw error;
}
return table;
}
/// <summary>
/// 加载一项编辑信息
/// </summary>
/// <param name="gid"></param>
/// <param name="companyId"></param>
/// <returns></returns>
public DataTable GetOneEditIfno(string gid, string companyId)
{
string sqlstr = "select A.CTN_ID,A.BSNO,CTN,CTNNUM,CNTRNO,SEALNO,KGS,REMARK,A.GOODSNAME,MBLNO,CUSTNO,(VESSEL+'/'+VOYNO)as VessAndVoyno,LOADADDRESS,DELIVERADDRESS, "
+ "GID,TRUCKNO,DRIVER,IDENTITYCARD,MOBILE,TEAMTYPE,ISTEAMSTATUS "
+ "from [op_sean] B INNER JOIN [op_ctn] A ON B.BSNO=A.BSNO LEFT JOIN [op_ctn_truck] C ON A.CTN_ID=C.CTN_ID where B.CORPID=@companyID AND C.LE_ID=@LE_ID ";
SqlParameter[] param = new SqlParameter[] {
new SqlParameter("@companyID",companyId),
new SqlParameter("@LE_ID",gid)
};
DataTable table;
try
{
table = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr, param).Tables[0];
}
catch (Exception error)
{
table = null;
throw error;
}
return table;
}
/// <summary>
/// 向【op_ctn_truck】中添加新的信息
/// </summary>
/// <param name="optctnruck"></param>
/// <returns></returns>
public bool InertNewCtnTruck(OpCtnTruckEntity optctnruck,string newid)
{
StringBuilder sqlstr = new StringBuilder();
sqlstr.Append(" insert into [op_ctn_truck ](GID,CTN_ID,TRUCKNO,DRIVER,IDENTITYCARD,MOBILE) ");
sqlstr.Append(" values(@GID,@CTN_ID,@TRUCKNO,@DRIVER,@IDENTITYCARD,@MOBILE)");
SqlParameter[] param = new SqlParameter[] {
new SqlParameter("@GID",newid),
new SqlParameter("@CTN_ID",optctnruck.CTN_ID),
new SqlParameter("@TRUCKNO",optctnruck.TRUCKNO),
new SqlParameter("@DRIVER",optctnruck.DRIVER),
new SqlParameter("@IDENTITYCARD",optctnruck.IDENTITYCARD),
new SqlParameter("@MOBILE",optctnruck.MOBILE)
};
bool boo = false;
try
{
boo = SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr.ToString(), param) > 0 ? true : false;
}
catch(Exception error)
{
throw error;
}
return boo;
}
/// <summary>
/// 查询op_ctn_truck是信息判断是否已经存在信息
/// </summary>
/// <param name="ctnid"></param>
/// <returns></returns>
public DataTable GetIsExistsCtnTruck(string ctnid)
{
string sqltr = "select GID,CTN_ID,LE_ID,TRUCKNO,DRIVER,IDENTITYCARD,MOBILE from [op_ctn_truck ] where CTN_ID=@CTN_ID ";
SqlParameter[] param = new SqlParameter[] { new SqlParameter("@CTN_ID",ctnid) };
DataTable table;
try
{
table = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqltr, param).Tables[0];
}
catch
{
throw;
}
return table;
}
/// <summary>
/// 修改op_ctn_truck信息
/// </summary>
/// <param name="opctnTruck"></param>
/// <returns></returns>
public bool UpdateCtnTruck(OpCtnTruckEntity opctnTruck)
{
string sqlstr = "update [op_ctn_truck ] set TRUCKNO=@TRUCKNO,DRIVER=@DRIVER,IDENTITYCARD=@IDENTITYCARD,MOBILE=@MOBILE where GID=@GID";
SqlParameter[] param = new SqlParameter[] {
new SqlParameter("@TRUCKNO",opctnTruck.TRUCKNO),
new SqlParameter("@DRIVER",opctnTruck.DRIVER),
new SqlParameter("@IDENTITYCARD",opctnTruck.IDENTITYCARD),
new SqlParameter("@MOBILE",opctnTruck.MOBILE),
new SqlParameter("@GID",opctnTruck.GID)
};
bool result;
try
{
result = SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr, param) > 0 ? true : false;
}
catch (Exception error)
{
throw new Exception(error.Message, error);
}
return result;
}
/// <summary>
/// 查询制作的派车单信息
/// </summary>
/// <param name="vessVoyno">船名/航次</param>
/// <param name="loadGood">装货状态</param>
/// <param name="sendGood">送货状态</param>
/// <returns></returns>
public DataTable GetSearchCtnTruckInfo(string allsearch, string loadGood, string sendGood, string companyid)
{
StringBuilder sqlstr = new StringBuilder();
#region 1
//sqlstr.Append(" select A.CTN_ID,A.BSNO,CTN,CTNNUM,CNTRNO,SEALNO,KGS,REMARK,GOODSNAME,");
//sqlstr.Append(" GID,LE_ID,TRUCKNO,DRIVER,IDENTITYCARD,MOBILE,B.TEAMTYPE,B.ISTEAMSTATUS from ");
//sqlstr.Append("(select CTN_ID,BSNO,CTN,CTNNUM,CNTRNO,SEALNO,KGS,REMARK,GOODSNAME from[op_ctn] where BSNO in ");
//sqlstr.Append(" (select bsno from [op_sean] where CORPID='"+companyid+"' and BSSTATUS=0 ");
//if (vessVoyno != "")
//{
// sqlstr.Append(" AND (VESSEL like '%"+vessVoyno.Trim()+"%' OR VOYNO like '%"+vessVoyno.Trim()+"%')");
//}
//sqlstr.Append(" ))A FULL JOIN [op_ctn_truck] B ON A.CTN_ID=B.CTN_ID where 1>0 ");
//if (loadGood != ""&&sendGood=="")
//{
// sqlstr.Append(" AND A.CTN_ID NOT IN(select CTN_ID from [op_ctn_truck] where TEAMTYPE=0) ");
//}
//if (loadGood == "" && sendGood != "")
//{
// sqlstr.Append(" and A.CTN_ID NOT IN(select CTN_ID from [op_ctn_truck] where TEAMTYPE=1) ");
//}
//sqlstr.Append(" ORDER BY A.CTN_ID desc ");
#endregion
#region 2
//sqlstr.Append("select A.CTN_ID,A.BSNO,CTN,CTNNUM,CNTRNO,SEALNO,KGS,REMARK,A.GOODSNAME,MBLNO,CUSTNO,(VESSEL+'/'+VOYNO)as VessAndVoyno,");
//sqlstr.Append("GID,TRUCKNO,DRIVER,IDENTITYCARD,MOBILE,TEAMTYPE,ISTEAMSTATUS from [op_sean] B INNER JOIN [op_ctn] A ON B.BSNO=A.BSNO ");
//sqlstr.Append("LEFT JOIN [op_ctn_truck] C ON A.CTN_ID=C.CTN_ID WHERE 1>0 AND A.CTN_ID in (select CTN_ID from [op_ctn_truck]) AND B.BSSTATUS=0 ");
//sqlstr.Append(" AND B.CORPID='"+companyid+"' ");
//if (vessVoyno != "")
//{
// sqlstr.Append(" AND (VESSEL like '%" + vessVoyno.Trim() + "%' OR VOYNO like '%" + vessVoyno.Trim() + "%')");
//}
//if (loadGood != "" && sendGood == "")
//{
// sqlstr.Append(" AND A.CTN_ID NOT IN(select CTN_ID from [op_ctn_truck] where TEAMTYPE=0) ");
//}
//if (loadGood == "" && sendGood != "")
//{
// sqlstr.Append(" and A.CTN_ID NOT IN(select CTN_ID from [op_ctn_truck] where TEAMTYPE=1) ");
//}
#endregion
sqlstr.Append("select A.CTN_ID,A.BSNO,CTN,CTNNUM,CNTRNO,SEALNO,KGS,REMARK,A.GOODSNAME,MBLNO,CUSTNO,(VESSEL+'/'+VOYNO)as VessAndVoyno,LOADADDRESS,DELIVERADDRESS,");
sqlstr.Append("GID,TRUCKNO,DRIVER,IDENTITYCARD,MOBILE,TEAMTYPE,ISTEAMSTATUS ");
sqlstr.Append("from [op_sean] B INNER JOIN [op_ctn] A ON B.BSNO=A.BSNO LEFT JOIN [op_ctn_truck] C ON A.CTN_ID=C.CTN_ID ");
sqlstr.Append("WHERE 1>0 AND B.CORPID=@companyid ");
if (allsearch != "")
{
sqlstr.Append(" AND (VESSEL like '%" + allsearch.Trim() + "%' OR VOYNO like '%" + allsearch.Trim() + "%' or MBLNO like '%"+allsearch.Trim()+"%' ");
sqlstr.Append(" or LOADADDRESS LIKE '%" + allsearch.Trim() + "%' OR DELIVERADDRESS LIKE '%" + allsearch.Trim() + "%' or CUSTOMERNAME LIKE '%" + allsearch.Trim() + "%' ");
sqlstr.Append(" or CTN like '%" + allsearch.Trim() + "%' or CTNNUM like '%"+allsearch.Trim()+"%' ");
sqlstr.Append(") ");
}
sqlstr.Append("AND A.CTN_ID NOT in (select distinct CTN_ID FROM [op_ctn_truck] where (TEAMTYPE=0 or TEAMTYPE=1)) ");
sqlstr.Append("union ");
sqlstr.Append("select A.CTN_ID,A.BSNO,CTN,CTNNUM,CNTRNO,SEALNO,KGS,REMARK,A.GOODSNAME,MBLNO,CUSTNO,(VESSEL+'/'+VOYNO)as VessAndVoyno,LOADADDRESS,DELIVERADDRESS,");
sqlstr.Append("null AS GID,null AS TRUCKNO,null AS DRIVER,null AS IDENTITYCARD,null AS MOBILE,null AS TEAMTYPE,null AS ISTEAMSTATUS ");
sqlstr.Append("from [op_sean] B INNER JOIN [op_ctn] A ON B.BSNO=A.BSNO LEFT JOIN [op_ctn_truck] C ON A.CTN_ID=C.CTN_ID ");
sqlstr.Append("WHERE 1>0 AND B.CORPID=@companyid ");
if (allsearch != "")
{
sqlstr.Append(" AND (VESSEL like '%" + allsearch.Trim() + "%' OR VOYNO like '%" + allsearch.Trim() + "%' or MBLNO like '%" + allsearch.Trim() + "%' ");
sqlstr.Append(" or LOADADDRESS LIKE '%" + allsearch.Trim() + "%' OR DELIVERADDRESS LIKE '%" + allsearch.Trim() + "%' or CUSTOMERNAME LIKE '%" + allsearch.Trim() + "%' ");
sqlstr.Append(" or CTN like '%" + allsearch.Trim() + "%' or CTNNUM like '%" + allsearch.Trim() + "%' ");
sqlstr.Append(") ");
}
if (loadGood != "" && sendGood == "")
{
sqlstr.Append(" AND A.CTN_ID in (select CTN_ID FROM [op_ctn_truck] where TEAMTYPE=1 AND ISTEAMSTATUS=0 GROUP BY CTN_ID HAVING count(CTN_ID)=1) ");
}
if (loadGood == "" && sendGood != "")
{
sqlstr.Append(" AND A.CTN_ID in (select CTN_ID FROM [op_ctn_truck] where TEAMTYPE=0 AND (ISTEAMSTATUS=0 or ISTEAMSTATUS=1) GROUP BY CTN_ID HAVING count(CTN_ID)=1) ");
}
SqlParameter[] param = new SqlParameter[] { new SqlParameter("@companyid",companyid) };
DataTable table;
try
{
table = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr.ToString(),param).Tables[0];
}
catch (Exception error)
{
table = null;
throw error;
}
return table;
}
/// <summary>
/// 获取承运车队信息
/// </summary>
/// <param name="companyid"></param>
/// <returns></returns>
public DataTable GetTeamInfo(string companyid)
{
string sqlstr = "select GID,CODENAME,SHORTNAME,DESCRIPTION,(CODENAME+'_'+SHORTNAME) as NewColumns from [info_client] where 1>0 and ISTRUCK=1 and STATUS=0 and CORPID=@CORPID";
SqlParameter[] param = new SqlParameter[] { new SqlParameter("@CORPID",companyid) };
DataTable table;
try
{
table = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr, param).Tables[0];
}
catch (Exception error)
{
throw new Exception(error.Message,error);
}
return table;
}
/// <summary>
/// 获得某个集装箱的所在的车队
/// </summary>
/// <param name="ctnid"></param>
/// <returns></returns>
public DataTable GetExistsTeam(string ctnid)
{
StringBuilder sqlstr = new StringBuilder();
sqlstr.Append("select A.GID,A.CTN_ID,A.LE_ID,B.TRUCK,B.TEAMTYPE from [op_ctn_truck] A inner join [op_letter_truck] B ON A.LE_ID=B.LE_ID where A.CTN_ID='" + ctnid.Trim() + "'");
DataTable table;
try
{
table = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr.ToString()).Tables[0];
}
catch (Exception error)
{
throw new Exception(error.Message,error);
}
return table;
}
/// <summary>
/// 获得某个派车单的车队
/// </summary>
/// <param name="leid"></param>
/// <returns></returns>
public string GetMenuTruckByLeid(string leid)
{
string team = "";
string sqlstr = "select truck from [op_letter_truck] where le_id='"+leid+"' ";
try
{
team = SqlHelper.ExecuteScalar(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr).ToString();
}
catch (Exception error)
{
throw new Exception(error.Message, error);
}
return team;
}
/// <summary>
/// 生成派车单
/// </summary>
/// <param name="LE_ID"></param>
/// <param name="TRUCK"></param>
/// <param name="INPUTTIME"></param>
/// <param name="TEAMTYPE"></param>
/// <param name="ISTEAMSTATUS"></param>
/// <param name="INPUTBY"></param>
/// <param name="GID"></param>
/// <param name="CTN_ID"></param>
/// <returns></returns>
public bool GenerateMenuTruck(string LE_ID,string TRUCK,DateTime INPUTTIME,int TEAMTYPE,bool ISTEAMSTATUS,string INPUTBY,string[] CTN_ID)
{
StringBuilder sqlstr1 = new StringBuilder();
sqlstr1.Append("insert into [op_letter_truck](LE_ID,TRUCK,INPUTTIME,TEAMTYPE,ISTEAMSTATUS,INPUTBY) ");
sqlstr1.Append("values(@LE_ID,@TRUCK,@INPUTTIME,@TEAMTYPE,@ISTEAMSTATUS,@INPUTBY)");
SqlParameter[] patam1 = new SqlParameter[] {
new SqlParameter("@LE_ID",LE_ID),
new SqlParameter("@TRUCK",TRUCK),
new SqlParameter("@INPUTTIME",INPUTTIME),
new SqlParameter("@TEAMTYPE",TEAMTYPE),
new SqlParameter("@ISTEAMSTATUS",ISTEAMSTATUS),
new SqlParameter("@INPUTBY",INPUTBY)
};
StringBuilder sqlstr2 = new StringBuilder();
sqlstr2.Append("update [op_ctn_truck] set LE_ID=@LE_ID,TEAMTYPE=@TEAMTYPE,ISTEAMSTATUS=@ISTEAMSTATUS ");
sqlstr2.Append("where 1>0 and (");
for (int i = 0; i < CTN_ID.Length; i++)
{
sqlstr2.Append(" CTN_ID='" + CTN_ID[i] + "' or ");
}
sqlstr2 = sqlstr2.Remove(sqlstr2.Length-3,3);
sqlstr2.Append(")");
sqlstr2.Append(" and teamtype is null and isteamstatus is null ");
SqlParameter[] param2 = new SqlParameter[] {
new SqlParameter("@LE_ID",LE_ID),
new SqlParameter("@TEAMTYPE",TEAMTYPE),
new SqlParameter("@ISTEAMSTATUS",ISTEAMSTATUS)
};
bool resutl=false;
using (SqlTransaction sqltran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
SqlHelper.ExecuteNonQuery(sqltran, CommandType.Text, sqlstr1.ToString(), patam1);
SqlHelper.ExecuteNonQuery(sqltran, CommandType.Text, sqlstr2.ToString(), param2);
sqltran.Commit();
resutl = true;
}
catch (Exception error)
{
sqltran.Rollback();
throw error;
}
finally
{
SqlHelper.CloseConnection();
}
}
return resutl;
}
/// <summary>
/// 修改派车单的状态
/// </summary>
/// <param name="leid"></param>
/// <returns>成功返回true否则false</returns>
public bool ChangeLetterStatus(string leid)
{
string sqlstr1 = "update [op_letter_truck] set ISTEAMSTATUS=1 where LE_ID=@LE_ID";
string sqlstr2 = "update [op_ctn_truck] set ISTEAMSTATUS=1 where LE_ID=@LE_ID";
SqlParameter[] param = new SqlParameter[] {
new SqlParameter("@LE_ID",leid)
};
bool result = false;
using (SqlTransaction sqltran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr1, param);
SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr2, param);
sqltran.Commit();
result = true;
}
catch (Exception error)
{
sqltran.Rollback();
throw error;
}
finally
{
SqlHelper.CloseConnection();
}
}
return result;
}
/// <summary>
/// 根据派车单单ID获取要打印的司机信息id
/// </summary>
/// <param name="gid"></param>
/// <returns></returns>
public DataTable GetGIDTruck(string LEID)
{
string[] leids = LEID.Split(',') ;
string sqlstr = "select gid from [op_ctn_truck] C join [op_letter_truck] T on C.LE_ID=T.LE_ID where ";
string str = "";
for (int i = 0; i < leids.Length; i++)
{
str += " T.LE_ID='" + leids[i].ToString() + "' or";
}
sqlstr = sqlstr + str.Remove(str.Length - 3, 3);
SqlParameter[] param = new SqlParameter[] { new SqlParameter("@LE_ID",LEID) };
DataTable table;
try
{
table = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr, param).Tables[0];
}
catch (Exception error)
{
throw error;
}
return table;
}
/// <summary>
/// 生成新的派车单信息,保存与生成集合
/// </summary>
/// <param name="ctnTruckEnetity"></param>
/// <returns></returns>
public bool NewMakeLetterTruck(OpCtnTruckEntity ctnTruckEnetity)
{
StringBuilder sqlstr1 = new StringBuilder();
sqlstr1.Append("insert into [op_ctn_truck ](GID,CTN_ID,LE_ID,TEAMTYPE,ISTEAMSTATUS,TRUCKNO,DRIVER,IDENTITYCARD,MOBILE) values(@GID,@CTN_ID,@LE_ID,@TEAMTYPE,@ISTEAMSTATUS,@TRUCKNO,@DRIVER,@IDENTITYCARD,@MOBILE)");
SqlParameter[] param = new SqlParameter[] {
new SqlParameter("@GID",ctnTruckEnetity.GID),
new SqlParameter("@CTN_ID",ctnTruckEnetity.CTN_ID),
new SqlParameter("@LE_ID",ctnTruckEnetity.LE_ID),
new SqlParameter("@TEAMTYPE",ctnTruckEnetity.TEAMTYPE),
new SqlParameter("@ISTEAMSTATUS",ctnTruckEnetity.ISTEAMSTATUS),
new SqlParameter("@TRUCKNO",ctnTruckEnetity.TRUCKNO),
new SqlParameter("@DRIVER",ctnTruckEnetity.DRIVER),
new SqlParameter("@IDENTITYCARD",ctnTruckEnetity.IDENTITYCARD),
new SqlParameter("@MOBILE",ctnTruckEnetity.MOBILE)
};
StringBuilder sqlstr2 = new StringBuilder();
sqlstr2.Append("insert into [op_letter_truck](LE_ID,TRUCK,INPUTTIME,TEAMTYPE,ISTEAMSTATUS,INPUTBY) values(@LE_ID,@TRUCK,@INPUTTIME,@TEAMTYPE,@ISTEAMSTATUS,@INPUTBY)");
return true;
}
/// <summary>
/// 查询该状态下的集装箱是否存在在op_ctn_truck中
/// </summary>
/// <param name="status">状态</param>
/// <param name="ctnid">集装箱id</param>
/// <returns></returns>
public DataTable CountNumCtn(int status,string ctnid)
{
string sqlstr = "select gid,ctn_id,teamtype,isteamstatus from [op_ctn_truck] where teamtype is null and ctn_id='" + ctnid.ToString().Trim() + "'";
DataTable table;
try
{
table = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, sqlstr).Tables[0];
}
catch (Exception error)
{
throw error;
}
return table;
}
}
}