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/EntityDA/CRMClientVisitDA.cs

355 lines
16 KiB
C#

using System;
using System.Data;
using System.Configuration;
using System.Linq;
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 System.Xml.Linq;
using DSWeb.Models;
using WebSqlHelper;
using System.Data.SqlClient;
using System.Text;
namespace DSWeb.EntityDA
{
//潜在客户信息表
public partial class CRMClientVisitDA
{
/// <summary>
/// 增加一条数据
/// </summary>
public int Add(CRMClientVisitEntity model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into crm_info_client_visit(");
strSql.Append("GID,NEXTCONTENT,NEXTDATE,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,ISLOCK,LOCKTIME,LOCKUSER,CLIENTGID,SHORTNAME,CONTACTNAME,SALE,VISITWAY,VISITCONTENT,VISITDATE,NEXTACTION");
strSql.Append(") values (");
strSql.Append("@GID,@NEXTCONTENT,@NEXTDATE,@CREATEUSER,getdate(),@MODIFIEDUSER,getdate(),1,getdate(),@LOCKUSER,@CLIENTGID,@SHORTNAME,@CONTACTNAME,@SALE,@VISITWAY,@VISITCONTENT,@VISITDATE,@NEXTACTION");
strSql.Append(") ");
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,36) ,
new SqlParameter("@NEXTCONTENT", SqlDbType.VarChar,1024) ,
new SqlParameter("@NEXTDATE", SqlDbType.DateTime) ,
new SqlParameter("@CREATEUSER", SqlDbType.VarChar,36) ,
//new SqlParameter("@CREATETIME", SqlDbType.DateTime) ,
new SqlParameter("@MODIFIEDUSER", SqlDbType.VarChar,36) ,
//new SqlParameter("@MODIFIEDTIME", SqlDbType.DateTime) ,
//new SqlParameter("@ISLOCK", SqlDbType.Bit,1) ,
//new SqlParameter("@LOCKTIME", SqlDbType.DateTime) ,
new SqlParameter("@LOCKUSER", SqlDbType.VarChar,36) ,
new SqlParameter("@CLIENTGID", SqlDbType.VarChar,100) ,
new SqlParameter("@SHORTNAME", SqlDbType.VarChar,20) ,
new SqlParameter("@CONTACTNAME", SqlDbType.VarChar,20) ,
new SqlParameter("@SALE", SqlDbType.VarChar,20) ,
new SqlParameter("@VISITWAY", SqlDbType.VarChar,50) ,
new SqlParameter("@VISITCONTENT", SqlDbType.VarChar,1024) ,
new SqlParameter("@VISITDATE", SqlDbType.DateTime) ,
new SqlParameter("@NEXTACTION", SqlDbType.VarChar,50)
};
parameters[0].Value = model.GID;
parameters[1].Value = model.NEXTCONTENT;
parameters[2].Value = model.NEXTDATE;
parameters[3].Value = model.CREATEUSER;
//parameters[4].Value = model.CREATETIME;
parameters[4].Value = model.MODIFIEDUSER;
//parameters[6].Value = model.MODIFIEDTIME;
//parameters[7].Value = model.ISLOCK;
//parameters[8].Value = model.LOCKTIME;
parameters[5].Value = model.LOCKUSER;
parameters[6].Value = model.CLIENTGID;
parameters[7].Value = model.SHORTNAME;
parameters[8].Value = model.CONTACTNAME;
parameters[9].Value = model.SALE;
parameters[10].Value = model.VISITWAY;
parameters[11].Value = model.VISITCONTENT;
parameters[12].Value = model.VISITDATE;
parameters[13].Value = model.NEXTACTION;
//
int iResult = 0;
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
int existVal = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSql.ToString(), parameters);
if (existVal > 0)
{
iResult = 1;
//
//string str0 = "insert into sys_log(NAME,LOGTYPE,LOGCONTENT,CREATEUSER) values('增加信息','增加操作','GID=" + model.GID.ToString() + "','" + model.MODIFIEDUSER.ToString() + "')";
//bool bl0 = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str0);
}
else
{
iResult = -1;//执行异常
}
}
return iResult;
}
/// <summary>
/// 更新一条数据
/// </summary>
public int Update(CRMClientVisitEntity model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update crm_info_client_visit set ");
strSql.Append(" GID = @GID , ");
strSql.Append(" NEXTCONTENT = @NEXTCONTENT , ");
strSql.Append(" NEXTDATE = @NEXTDATE , ");
//strSql.Append(" CREATEUSER = @CREATEUSER , ");
//strSql.Append(" CREATETIME = @CREATETIME , ");
strSql.Append(" MODIFIEDUSER = @MODIFIEDUSER , ");
strSql.Append(" MODIFIEDTIME = getdate() , ");
//strSql.Append(" ISLOCK = @ISLOCK , ");
//strSql.Append(" LOCKTIME = @LOCKTIME , ");
//strSql.Append(" LOCKUSER = @LOCKUSER , ");
//strSql.Append(" CLIENTGID = @CLIENTGID , ");
//strSql.Append(" SHORTNAME = @SHORTNAME , ");
strSql.Append(" CONTACTNAME = @CONTACTNAME , ");
strSql.Append(" SALE = @SALE , ");
strSql.Append(" VISITWAY = @VISITWAY , ");
strSql.Append(" VISITCONTENT = @VISITCONTENT , ");
strSql.Append(" VISITDATE = @VISITDATE , ");
strSql.Append(" NEXTACTION = @NEXTACTION ");
strSql.Append(" where GID=@GID");
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,36) ,
new SqlParameter("@NEXTCONTENT", SqlDbType.VarChar,1024) ,
new SqlParameter("@NEXTDATE", SqlDbType.DateTime) ,
//new SqlParameter("@CREATEUSER", SqlDbType.VarChar,36) ,
//new SqlParameter("@CREATETIME", SqlDbType.DateTime) ,
new SqlParameter("@MODIFIEDUSER", SqlDbType.VarChar,36) ,
//new SqlParameter("@MODIFIEDTIME", SqlDbType.DateTime) ,
//new SqlParameter("@ISLOCK", SqlDbType.Bit,1) ,
//new SqlParameter("@LOCKTIME", SqlDbType.DateTime) ,
//new SqlParameter("@LOCKUSER", SqlDbType.VarChar,36) ,
//new SqlParameter("@CLIENTGID", SqlDbType.VarChar,100) ,
//new SqlParameter("@SHORTNAME", SqlDbType.VarChar,20) ,
new SqlParameter("@CONTACTNAME", SqlDbType.VarChar,20) ,
new SqlParameter("@SALE", SqlDbType.VarChar,20) ,
new SqlParameter("@VISITWAY", SqlDbType.VarChar,50) ,
new SqlParameter("@VISITCONTENT", SqlDbType.VarChar,1024) ,
new SqlParameter("@VISITDATE", SqlDbType.DateTime) ,
new SqlParameter("@NEXTACTION", SqlDbType.VarChar,50)
};
parameters[0].Value = model.GID;
parameters[1].Value = model.NEXTCONTENT;
parameters[2].Value = model.NEXTDATE;
//parameters[3].Value = model.CREATEUSER;
//parameters[4].Value = model.CREATETIME;
parameters[3].Value = model.MODIFIEDUSER;
//parameters[6].Value = model.MODIFIEDTIME;
//parameters[7].Value = model.ISLOCK;
//parameters[8].Value = model.LOCKTIME;
//parameters[9].Value = model.LOCKUSER;
//parameters[4].Value = model.CLIENTGID;
//parameters[5].Value = model.SHORTNAME;
parameters[4].Value = model.CONTACTNAME;
parameters[5].Value = model.SALE;
parameters[6].Value = model.VISITWAY;
parameters[7].Value = model.VISITCONTENT;
parameters[8].Value = model.VISITDATE;
parameters[9].Value = model.NEXTACTION;
//
int iResult = 0;
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
int existVal = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSql.ToString(), parameters);
if (existVal > 0)
{
iResult = 1;
//
//string str0 = "insert into sys_log(NAME,LOGTYPE,LOGCONTENT,CREATEUSER) values('更新信息表','更新操作','GID=" + model.GID.ToString() + "','" + model.MODIFIEDUSER.ToString() + "')";
//bool bl0 = SqlHelper.ExecuteSqlCommand(SqlHelper.ConnectionStringLocalTransaction, str0);
}
else
{
iResult = -1;//执行异常
}
}
return iResult;
}
/// <summary>
/// 删除一条数据
/// </summary>
public int Delete(string GID)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from crm_info_client_visit ");
strSql.Append(" where GID=@GID");
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,36)};
parameters[0].Value = GID;
//
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql.ToString(), parameters);
iResult = 1;//状态为1表示删除成功
sqlTran.Commit();
}
catch (Exception execError)
{
iResult = -1;//有异常,删除失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
/// <summary>
/// 删除一条数据
/// </summary>
public int Deletes(string GIDS)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from crm_info_client_visit ");
strSql.Append(" where GID in (" + GIDS + ")");
//
int iResult = 0;
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql.ToString(), null);
iResult = 1;//状态为1表示删除成功
sqlTran.Commit();
}
catch (Exception execError)
{
iResult = -1;//有异常,删除失败
sqlTran.Rollback();
iResult = -2;//插入异常,事务已回滚成功
throw execError;
}
finally
{
SqlHelper.CloseConnection();
}
}
return iResult;
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public CRMClientVisitEntity GetModel(string GID)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select GID, NEXTCONTENT, NEXTDATE, CREATEUSER, CREATETIME, MODIFIEDUSER, MODIFIEDTIME, ISLOCK, LOCKTIME, LOCKUSER, CLIENTGID, SHORTNAME, CONTACTNAME, SALE, VISITWAY, VISITCONTENT, VISITDATE, NEXTACTION ");
strSql.Append(" from crm_info_client_visit ");
strSql.Append(" where GID=@GID");
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,36)};
parameters[0].Value = GID;
CRMClientVisitEntity model = new CRMClientVisitEntity();
DataSet ds = SqlHelper.Query(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
model.GID = ds.Tables[0].Rows[0]["GID"].ToString();
model.NEXTCONTENT = ds.Tables[0].Rows[0]["NEXTCONTENT"].ToString();
if (ds.Tables[0].Rows[0]["NEXTDATE"].ToString() != "")
{
model.NEXTDATE = DateTime.Parse(ds.Tables[0].Rows[0]["NEXTDATE"].ToString());
}
model.CREATEUSER = ds.Tables[0].Rows[0]["CREATEUSER"].ToString();
if (ds.Tables[0].Rows[0]["CREATETIME"].ToString() != "")
{
model.CREATETIME = DateTime.Parse(ds.Tables[0].Rows[0]["CREATETIME"].ToString());
}
model.MODIFIEDUSER = ds.Tables[0].Rows[0]["MODIFIEDUSER"].ToString();
if (ds.Tables[0].Rows[0]["MODIFIEDTIME"].ToString() != "")
{
model.MODIFIEDTIME = DateTime.Parse(ds.Tables[0].Rows[0]["MODIFIEDTIME"].ToString());
}
if (ds.Tables[0].Rows[0]["ISLOCK"].ToString() != "")
{
if ((ds.Tables[0].Rows[0]["ISLOCK"].ToString() == "1") || (ds.Tables[0].Rows[0]["ISLOCK"].ToString().ToLower() == "true"))
{
model.ISLOCK = true;
}
else
{
model.ISLOCK = false;
}
}
if (ds.Tables[0].Rows[0]["LOCKTIME"].ToString() != "")
{
model.LOCKTIME = DateTime.Parse(ds.Tables[0].Rows[0]["LOCKTIME"].ToString());
}
model.LOCKUSER = ds.Tables[0].Rows[0]["LOCKUSER"].ToString();
model.CLIENTGID = ds.Tables[0].Rows[0]["CLIENTGID"].ToString();
model.SHORTNAME = ds.Tables[0].Rows[0]["SHORTNAME"].ToString();
model.CONTACTNAME = ds.Tables[0].Rows[0]["CONTACTNAME"].ToString();
model.SALE = ds.Tables[0].Rows[0]["SALE"].ToString();
model.VISITWAY = ds.Tables[0].Rows[0]["VISITWAY"].ToString();
model.VISITCONTENT = ds.Tables[0].Rows[0]["VISITCONTENT"].ToString();
if (ds.Tables[0].Rows[0]["VISITDATE"].ToString() != "")
{
model.VISITDATE = DateTime.Parse(ds.Tables[0].Rows[0]["VISITDATE"].ToString());
}
model.NEXTACTION = ds.Tables[0].Rows[0]["NEXTACTION"].ToString();
return model;
}
else
{
return null;
}
}
/// <summary>
/// 获得数据列表
/// </summary>
public DataSet GetList(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select * ");
strSql.Append(" FROM crm_info_client_visit ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
//
DataSet DS = SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql.ToString());
try
{
if (DS.Tables[0].Rows.Count <= 0)
{
DS = null;
}
}
catch
{
DS = null;
}
return DS;
}
//
}
}