using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using DSWeb.DataAccess;
using DSWeb.Models;
using System.Data.SqlClient;
using System.Collections.Generic;
namespace DSWeb.EntityDA
{
public class OpSailingDateDA
{
private const string PARM_MODULE_GID = "@GID";
private const string PARM_MODULE_PORTDISCHARGE = "@PORTDISCHARGE";//卸货港
private const string PARM_MODULE_CARRIE = "@CARRIE"; //船公司
private const string PARM_MODULE_ETD = "@ETD";//开航日
private const string PARM_MODULE_TT = "@TT";//航程
private const string SQL_SELECT_INFO = "select GID,TITLE,CONTENTS,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,ISDELETE,DELETETIME,DELETEUSER,ISISSUE,BEGINTIME,ENDTIME,CORPID from op_sailingdate where GID=@GID";
private const string SQL_DELETE_INFO = "DELETE FROM op_sailingdate WHERE GID=@GID";
private string SQL_INSERT_INFO = "insert into op_sailingdate(GID,TITLE,CONTENTS,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,ISDELETE,DELETETIME,DELETEUSER,ISISSUE,CORPID) values(@GID,@TITLE,@CONTENTS,@CREATEUSER,getdate(),@MODIFIEDUSER,getdate(),0,getdate(),@DELETEUSER,0,@CORPID)";
private string SQL_UPDATE_INFO = "update op_sailingdate set TITLE=@TITLE,CONTENTS=@CONTENTS,MODIFIEDUSER=@MODIFIEDUSER,MODIFIEDTIME=getdate() where GID=@GID";
private string SQL_INSERT_URL = "insert into op_sailingdateurl(GID,LINKGID,AFFIXNAME,AFFIXURL,AFFIXSIZE,TABLENAME) values(@GID,@LINKGID,@AFFIXNAME,@AFFIXURL,@AFFIXSIZE,@TABLENAME)";
public OpSailingDateDA()
{
}
///
/// 返回 某字段
///
///
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;
}
#region 根据GID获取信息
///
/// 根据GID获取信息
///
///
///
public OpSailingDateEntity GetID(string strGID)
{
//初始化返回变量
OpSailingDateEntity OpSailingDateEntity = null;
//初始化参数并赋值
SqlParameter parm = new SqlParameter(PARM_MODULE_GID, SqlDbType.VarChar, 100);
parm.Value = strGID;
using (SqlDataReader sqlRead = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, SQL_SELECT_INFO, parm))
{
try
{
OpSailingDateEntity = new OpSailingDateEntity();
//读取字段值
while (sqlRead.Read())
{
if (!sqlRead.IsDBNull(0)) { OpSailingDateEntity.GID = sqlRead.GetString(0); }// 惟一编号
if (!sqlRead.IsDBNull(1)) { OpSailingDateEntity.TITLE = sqlRead.GetString(1); }// 标题
if (!sqlRead.IsDBNull(2)) { OpSailingDateEntity.CONTENTS = sqlRead.GetString(2); }// 内容
if (!sqlRead.IsDBNull(3)) { OpSailingDateEntity.CREATEUSER = sqlRead.GetString(3); }// 创建人
if (!sqlRead.IsDBNull(4)) { OpSailingDateEntity.CREATETIME = sqlRead.GetDateTime(4); }// 创建时间
if (!sqlRead.IsDBNull(5)) { OpSailingDateEntity.MODIFIEDUSER = sqlRead.GetString(5); }// 最后一次更新操作人
if (!sqlRead.IsDBNull(6)) { OpSailingDateEntity.MODIFIEDTIME = sqlRead.GetDateTime(6); }// 最后一次更新操作时间
if (!sqlRead.IsDBNull(7)) { OpSailingDateEntity.ISDELETE = sqlRead.GetBoolean(7); }// 是否删除
if (!sqlRead.IsDBNull(8)) { OpSailingDateEntity.DELETETIME = sqlRead.GetDateTime(8); }// 删除时间
if (!sqlRead.IsDBNull(9)) { OpSailingDateEntity.DELETEUSER = sqlRead.GetString(9); }// 删除操作人
if (!sqlRead.IsDBNull(10)) { OpSailingDateEntity.ISISSUE = sqlRead.GetBoolean(10); }// 是否发布
if (!sqlRead.IsDBNull(11)) { OpSailingDateEntity.BEGINTIME = sqlRead.GetDateTime(11); }//
if (!sqlRead.IsDBNull(12)) { OpSailingDateEntity.ENDTIME = sqlRead.GetDateTime(12); }//
if (!sqlRead.IsDBNull(13)) { OpSailingDateEntity.CORPID = sqlRead.GetString(13); }//
}
}
catch (Exception exceError)
{
//抛出异常
throw exceError;
}
}
return OpSailingDateEntity;
}
#endregion
///
/// 插入信息
///
/// url实体类
/// 值为1插入数据正常,-1操作异常
public int InserInfo(OpSailingDateUrlEntity osduEntity)
{
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
#region 插入url
SqlParameter[] inserParms = new SqlParameter[]
{
new SqlParameter("@GID",SqlDbType.VarChar,36),//惟一编号
new SqlParameter("@LINKGID",SqlDbType.VarChar,100),//连接gid
new SqlParameter("@AFFIXNAME",SqlDbType.VarChar,100),//附件名称
new SqlParameter("@AFFIXURL",SqlDbType.VarChar,300),//附件地址
new SqlParameter("@AFFIXSIZE",SqlDbType.VarChar,50),//附件大小
new SqlParameter("@TABLENAME",SqlDbType.VarChar,100),//附件大小
};
if (osduEntity != null)
{
if (osduEntity.GID != null)
{
inserParms[0].Value = osduEntity.GID;//惟一编号
inserParms[1].Value = osduEntity.LINKGID;//连接gid
inserParms[2].Value = osduEntity.AFFIXNAME;//附件名称
inserParms[3].Value = osduEntity.AFFIXURL;//附件地址
inserParms[4].Value = osduEntity.AFFIXSIZE;//附件大小
inserParms[5].Value = osduEntity.TABLENAME;//附件大小
iResult = -4;//插入url
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_URL, inserParms);
}
}
#endregion
//事务提交
sqlTran.Commit();
iResult = 1;//状态为1表示插入成功
}
catch (Exception execError)
{
iResult = -1;//有异常,插入失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
///
/// 插入信息
///
/// 实体类
/// url实体类
/// 值为1插入数据正常,-1操作异常
public int InserInfo(OpSailingDateEntity infoEntity, OpSailingDateUrlEntity osduEntity)
{
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
#region 插入信息
//获取参数
SqlParameter[] parms = new SqlParameter[]
{
new SqlParameter("@GID",SqlDbType.VarChar,36),//惟一编号
new SqlParameter("@TITLE",SqlDbType.VarChar,100),//标题
new SqlParameter("@CONTENTS",SqlDbType.VarChar,1024),//内容
new SqlParameter("@CREATEUSER",SqlDbType.VarChar,36),//创建人
new SqlParameter("@MODIFIEDUSER",SqlDbType.VarChar,36),//最后一次更新操作人
new SqlParameter("@DELETEUSER",SqlDbType.VarChar,36),//删除操作人
new SqlParameter("@CORPID",SqlDbType.VarChar,36),//
};
parms[0].Value = infoEntity.GID;//惟一编号
parms[1].Value = infoEntity.TITLE;//标题
parms[2].Value = infoEntity.CONTENTS;//内容
parms[3].Value = infoEntity.CREATEUSER;//创建人
parms[4].Value = infoEntity.MODIFIEDUSER;//最后一次更新操作人
parms[5].Value = infoEntity.DELETEUSER;//删除操作人
parms[6].Value = infoEntity.CORPID;//
iResult = -3;//插入信息
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_INFO, parms);
#endregion
#region 插入url
SqlParameter[] inserParms = new SqlParameter[]
{
new SqlParameter("@GID",SqlDbType.VarChar,36),//惟一编号
new SqlParameter("@LINKGID",SqlDbType.VarChar,36),//连接gid
new SqlParameter("@AFFIXNAME",SqlDbType.VarChar,100),//附件名称
new SqlParameter("@AFFIXURL",SqlDbType.VarChar,300),//附件地址
new SqlParameter("@AFFIXSIZE",SqlDbType.VarChar,50),//附件大小
new SqlParameter("@TABLENAME",SqlDbType.VarChar,100),//附件大小
};
if (osduEntity != null)
{
if (osduEntity.GID != null)
{
inserParms[0].Value = osduEntity.GID;//惟一编号
inserParms[1].Value = osduEntity.LINKGID;//连接gid
inserParms[2].Value = osduEntity.AFFIXNAME;//附件名称
inserParms[3].Value = osduEntity.AFFIXURL;//附件地址
inserParms[4].Value = osduEntity.AFFIXSIZE;//附件大小
inserParms[5].Value = osduEntity.TABLENAME;//附件大小
iResult = -4;//插入url
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_URL, inserParms);
}
}
#endregion
//事务提交
sqlTran.Commit();
iResult = 1;//状态为1表示插入成功
}
catch (Exception execError)
{
iResult = -1;//有异常,插入失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
///
/// 更新信息
///
/// 实体类
/// url实体类
///
public int UpdateInfo(OpSailingDateEntity infoEntity, OpSailingDateUrlEntity osduEntity)
{
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
#region 更新信息
//获取参数
SqlParameter[] parms = new SqlParameter[]
{
new SqlParameter("@GID",SqlDbType.VarChar,36),//惟一编号
new SqlParameter("@TITLE",SqlDbType.VarChar,100),//标题
new SqlParameter("@CONTENTS",SqlDbType.VarChar,1024),//内容
new SqlParameter("@MODIFIEDUSER",SqlDbType.VarChar,36),//最后一次更新操作人
};
parms[0].Value = infoEntity.GID;//惟一编号
parms[1].Value = infoEntity.TITLE;//标题
parms[2].Value = infoEntity.CONTENTS;//内容
parms[3].Value = infoEntity.MODIFIEDUSER;//最后一次更新操作人
iResult = -3;//更新信息
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_UPDATE_INFO, parms);
#endregion
#region 插入url
SqlParameter[] inserParms = new SqlParameter[]
{
new SqlParameter("@GID",SqlDbType.VarChar,36),//惟一编号
new SqlParameter("@LINKGID",SqlDbType.VarChar,36),//连接gid
new SqlParameter("@AFFIXNAME",SqlDbType.VarChar,100),//附件名称
new SqlParameter("@AFFIXURL",SqlDbType.VarChar,300),//附件地址
new SqlParameter("@AFFIXSIZE",SqlDbType.VarChar,50),//附件大小
new SqlParameter("@TABLENAME",SqlDbType.VarChar,100),//
};
if(osduEntity!=null)
{
if(osduEntity.GID!=null)
{
inserParms[0].Value = osduEntity.GID;//惟一编号
inserParms[1].Value = osduEntity.LINKGID;//连接gid
inserParms[2].Value = osduEntity.AFFIXNAME;//附件名称
inserParms[3].Value = osduEntity.AFFIXURL;//附件地址
inserParms[4].Value = osduEntity.AFFIXSIZE;//附件大小
inserParms[5].Value = osduEntity.TABLENAME;//
iResult = -4;//插入url
SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, SQL_INSERT_URL, inserParms);
}
}
#endregion
//事务提交
sqlTran.Commit();
iResult = 1;//状态为1表示插入成功
}
catch (Exception execError)
{
iResult = -1;//有异常,插入失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
#region 生成更新语句参数
///
/// 更新信息
///
/// 实体类
/// 值为1更新数据正常,-1操作异常
public int UpdateInfoCNTRTOTAL(string strSql, string strUserID)
{
int iResult = 0;
//
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
int existVal = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSql, null);
if (existVal > 0)
{
iResult = 1;
//
//strSql = strSql.Trim().Replace("'", "''");
//string str0 = "insert into sys_log(NAME,LOGTYPE,LOGCONTENT,CREATEUSER) values('更新所有op_sailingdate海运业务预订舱表集装箱字段','更新操作','" + strSql + "','" + strUserID + "')";
//bool bl0 = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str0);
}
else
{
iResult = -1;//执行异常
}
}
return iResult;
}
#endregion
#region 删除公告管理信息表
///
/// 删除公告管理信息表
///
/// 公告管理信息表GID
/// 删除人ID
/// 值1表示删除成功 值-1表示有异常,删除失败 值-2表示插入异常,事务已回滚成功
public String GetOpSailingDateDel(string strSel, string strUserID)
{
string alt = "";
string str = "update op_sailingdate set ISDELETE=1,DELETETIME=getdate(),DELETEUSER='"+strUserID+"' where 1=0 " + strSel;
bool bl = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str);
if (bl == false)
{
alt = "公告管理信息表op_sailingdate删除操作出错!";
return alt;
}
else
{
//T_ALL_DA T_ALL_DA = new T_ALL_DA();
//strSel = strSel.Trim().Replace("gid", "LINKGID");
//string sSQL = "select * from op_sailingdateurl where 1=0 " + strSel;
//DataSet ds = T_ALL_DA.GetAllSQL(sSQL);
//if (ds != null)
//{
// FTPDA FTPDA = new FTPDA();
// FTPDA.ErrorMsg = "";
// FTPDA.Uri = new Uri("ftp://223.7.22.167/");
// if (FTPDA.ErrorMsg.ToString().Trim() != "")
// {
// alt = FTPDA.ErrorMsg.ToString().Trim();
// }
// FTPDA.DirectoryPath = "//PriceCarrier//FTPFiles//";
// FTPDA.UserName = "hmw028167";
// FTPDA.Password = "hmw123456";
// string funame = "";
// //
// for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
// {
// funame = ds.Tables[0].Rows[i]["AFFIXNAME"].ToString().Trim();
// FTPDA.DeleteFile(funame);
// if (FTPDA.ErrorMsg.ToString().Trim() != "")
// {
// alt = FTPDA.ErrorMsg.ToString().Trim();
// }
// }
//}
//
//str = str.Trim().Replace("'", "''");
//string str0 = "insert into sys_log(NAME,LOGTYPE,LOGCONTENT,CREATEUSER) values('删除公告管理信息表op_sailingdate','删除操作','" + str + "','" + strUserID + "')";
//bool bl0 = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str0);
}
return alt;
}
#endregion
//
}
}