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.

487 lines
21 KiB
C#

10 months ago
using System;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using WebSqlHelper;
using DSWeb.Models;
namespace DSWeb.EntityDA
{
public class CRMInfoFAQDA
{
/// <summary>
/// 是否存在该条数据
/// </summary>
public bool Exists(string GID)
{
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(1) from crm_info_faq");
strSql.Append(" where ");
strSql.Append(" GID = @GID ");
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,36)};
parameters[0].Value = GID;
try
{
return bool.Parse(SqlHelper.ExecuteNonQuery(conn, CommandType.Text, strSql.ToString(), parameters).ToString());
}
catch
{
return false;
}
}
}
/// <summary>
/// 增加一条数据
/// </summary>
public int Add(CRMInfoFAQEntity model)
{
string strSql = "insert into crm_info_faq(";
strSql += "GID,PORTLOAD,PORTDISCHARGE,{0}CNTRTOTAL,ISTHROUGH,GOODSNAME,KGS,PRICE,SHORTNAME,PROBLEMGID,PROBLEMTYPE,PROBLEMTITLE,PROBLEMCONTENT,ISPROBLEM,ISTYPE,CREATEUSER,CREATETIME,CLIENTGID,FAQREPLYMAN";
strSql += ") values (";
strSql += "@GID,@PORTLOAD,@PORTDISCHARGE,{1}@CNTRTOTAL,@ISTHROUGH,@GOODSNAME,@KGS,@PRICE,@SHORTNAME,@PROBLEMGID,@PROBLEMTYPE,@PROBLEMTITLE,@PROBLEMCONTENT,@ISPROBLEM,@ISTYPE,@CREATEUSER,getdate(),@CLIENTGID,@FAQREPLYMAN";
strSql += ") ";
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,36) ,
new SqlParameter("@PORTLOAD", SqlDbType.VarChar,60) ,
new SqlParameter("@PORTDISCHARGE", SqlDbType.VarChar,60) ,
//new SqlParameter("@ETD", SqlDbType.DateTime) ,
new SqlParameter("@CNTRTOTAL", SqlDbType.VarChar,100) ,
new SqlParameter("@ISTHROUGH", SqlDbType.Bit,1) ,
new SqlParameter("@GOODSNAME", SqlDbType.VarChar,30) ,
new SqlParameter("@KGS", SqlDbType.Decimal,9) ,
new SqlParameter("@PRICE", SqlDbType.Decimal,9) ,
new SqlParameter("@SHORTNAME", SqlDbType.VarChar,20) ,
new SqlParameter("@PROBLEMGID", SqlDbType.VarChar,36) ,
new SqlParameter("@PROBLEMTYPE", SqlDbType.VarChar,100) ,
new SqlParameter("@PROBLEMTITLE", SqlDbType.VarChar,100) ,
new SqlParameter("@PROBLEMCONTENT", SqlDbType.VarChar,1024) ,
new SqlParameter("@ISPROBLEM", SqlDbType.Bit,1) ,
new SqlParameter("@ISTYPE", SqlDbType.Bit,1) ,
new SqlParameter("@CREATEUSER", SqlDbType.VarChar,36) ,
new SqlParameter("@CLIENTGID", SqlDbType.VarChar,100) ,
new SqlParameter("@FAQREPLYMAN", SqlDbType.VarChar,20) ,
//new SqlParameter("@CREATETIME", SqlDbType.DateTime)
};
parameters[0].Value = model.GID;
parameters[1].Value = model.PORTLOAD;
parameters[2].Value = model.PORTDISCHARGE;
//parameters[3].Value = model.ETD;
parameters[3].Value = model.CNTRTOTAL;
parameters[4].Value = model.ISTHROUGH;
parameters[5].Value = model.GOODSNAME;
parameters[6].Value = model.KGS;
parameters[7].Value = model.PRICE;
parameters[8].Value = model.SHORTNAME;
parameters[9].Value = model.PROBLEMGID;
parameters[10].Value = model.PROBLEMTYPE;
parameters[11].Value = model.PROBLEMTITLE;
parameters[12].Value = model.PROBLEMCONTENT;
parameters[13].Value = model.ISPROBLEM;
parameters[14].Value = model.ISTYPE;
parameters[15].Value = model.CREATEUSER;
parameters[16].Value = model.CLIENTGID;
parameters[17].Value = model.FAQREPLYMAN;
//parameters[17].Value = model.CREATETIME;
string strETD = model.ETD.ToString().IndexOf("0001") > -1 ? "" : "'" + model.ETD.ToString() + "',";
string strETD_name = strETD.Equals("") ? "" : "ETD,";
strSql = String.Format(strSql, strETD_name, strETD);
//
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;
}
else
{
iResult = -1;//插入失败
}
}
return iResult;
}
/// <summary>
/// 更新一条数据
/// </summary>
public int Update(CRMInfoFAQEntity model)
{
string strSql = "update crm_info_faq set ";
strSql += " PORTLOAD = @PORTLOAD , ";
strSql += " PORTDISCHARGE = @PORTDISCHARGE , ";
strSql += " {0}{1}";
strSql += " CNTRTOTAL = @CNTRTOTAL , ";
strSql += " ISTHROUGH = @ISTHROUGH , ";
strSql += " GOODSNAME = @GOODSNAME , ";
strSql += " KGS = @KGS , ";
strSql += " PRICE = @PRICE , ";
strSql += " SHORTNAME = @SHORTNAME , ";
strSql += " PROBLEMGID = @PROBLEMGID , ";
strSql += " PROBLEMTYPE = @PROBLEMTYPE , ";
strSql += " PROBLEMTITLE = @PROBLEMTITLE , ";
strSql += " PROBLEMCONTENT = @PROBLEMCONTENT , ";
strSql += " ISPROBLEM = @ISPROBLEM , ";
strSql += " ISTYPE = @ISTYPE , ";
strSql += " CREATEUSER = @CREATEUSER , ";
strSql += " CREATETIME = getdate(), ";
strSql += " CLIENTGID = @CLIENTGID, ";
strSql += " FAQREPLYMAN = @FAQREPLYMAN ";
strSql += " where GID=@GID ";
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,36) ,
new SqlParameter("@PORTLOAD", SqlDbType.VarChar,60) ,
new SqlParameter("@PORTDISCHARGE", SqlDbType.VarChar,60) ,
//new SqlParameter("@ETD", SqlDbType.DateTime) ,
new SqlParameter("@CNTRTOTAL", SqlDbType.VarChar,100) ,
new SqlParameter("@ISTHROUGH", SqlDbType.Bit,1) ,
new SqlParameter("@GOODSNAME", SqlDbType.VarChar,30) ,
new SqlParameter("@KGS", SqlDbType.Decimal,9) ,
new SqlParameter("@PRICE", SqlDbType.Decimal,9) ,
new SqlParameter("@SHORTNAME", SqlDbType.VarChar,20) ,
new SqlParameter("@PROBLEMGID", SqlDbType.VarChar,36) ,
new SqlParameter("@PROBLEMTYPE", SqlDbType.VarChar,100) ,
new SqlParameter("@PROBLEMTITLE", SqlDbType.VarChar,100) ,
new SqlParameter("@PROBLEMCONTENT", SqlDbType.VarChar,1024) ,
new SqlParameter("@ISPROBLEM", SqlDbType.Bit,1) ,
new SqlParameter("@ISTYPE", SqlDbType.Bit,1) ,
new SqlParameter("@CREATEUSER", SqlDbType.VarChar,36) ,
new SqlParameter("@CLIENTGID", SqlDbType.VarChar,100) ,
new SqlParameter("@FAQREPLYMAN", SqlDbType.VarChar,20) ,
//new SqlParameter("@CREATETIME", SqlDbType.DateTime)
};
parameters[0].Value = model.GID;
parameters[1].Value = model.PORTLOAD;
parameters[2].Value = model.PORTDISCHARGE;
//parameters[3].Value = model.ETD;
parameters[3].Value = model.CNTRTOTAL;
parameters[4].Value = model.ISTHROUGH;
parameters[5].Value = model.GOODSNAME;
parameters[6].Value = model.KGS;
parameters[7].Value = model.PRICE;
parameters[8].Value = model.SHORTNAME;
parameters[9].Value = model.PROBLEMGID;
parameters[10].Value = model.PROBLEMTYPE;
parameters[11].Value = model.PROBLEMTITLE;
parameters[12].Value = model.PROBLEMCONTENT;
parameters[13].Value = model.ISPROBLEM;
parameters[14].Value = model.ISTYPE;
parameters[15].Value = model.CREATEUSER;
parameters[16].Value = model.CLIENTGID;
parameters[17].Value = model.FAQREPLYMAN;
//parameters[17].Value = model.CREATETIME;
string strETD = model.ETD.ToString().IndexOf("0001") > -1 ? "null," : "'" + model.ETD.ToString() + "',";
string strETD_name = "ETD=";
strSql = String.Format(strSql, strETD_name, strETD);
//
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_faq ");
strSql.Append(" where GID=@GID ");
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,36) };
parameters[0].Value = GID;
//
int iResult = 0;
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
int existVal = SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql.ToString(), parameters);
if (existVal > 0)
{
iResult = 1;
}
else
{
iResult = -1;//删除失败
}
}
return iResult;
}
/// <summary>
/// 批量删除数据
/// </summary>
public bool Deletes(string GIDlist)
{
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from crm_info_faq ");
strSql.Append(" where GID in (" + GIDlist + ") ");
int rows = SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql.ToString());
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
}
/// <summary>
/// 批量删除数据
/// </summary>
public bool DeleteList(string GIDlist)
{
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
StringBuilder strSql = new StringBuilder();
strSql.Append("delete from crm_info_faq ");
strSql.Append(" where GID in (" + GIDlist + ") ");
int rows = SqlHelper.ExecuteNonQuery(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql.ToString());
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
}
/// <summary>
/// 得到一个对象实体
/// </summary>
public CRMInfoFAQEntity GetModel(string GID)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select GID, PORTLOAD, PORTDISCHARGE, ETD, CNTRTOTAL, ISTHROUGH, GOODSNAME, KGS, PRICE, SHORTNAME, PROBLEMGID, PROBLEMTYPE, PROBLEMTITLE, PROBLEMCONTENT, ISPROBLEM, ISTYPE, CREATEUSER, CREATETIME,CLIENTGID,FAQREPLYMAN ");
strSql.Append(" from crm_info_faq ");
strSql.Append(" where GID=@GID ");
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,36) };
parameters[0].Value = GID;
CRMInfoFAQEntity model = new CRMInfoFAQEntity();
DataSet ds = SqlHelper.Query(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
model.GID = ds.Tables[0].Rows[0]["GID"].ToString();
model.PORTLOAD = ds.Tables[0].Rows[0]["PORTLOAD"].ToString();
model.PORTDISCHARGE = ds.Tables[0].Rows[0]["PORTDISCHARGE"].ToString();
if (ds.Tables[0].Rows[0]["ETD"].ToString() != "")
{
model.ETD = DateTime.Parse(ds.Tables[0].Rows[0]["ETD"].ToString());
}
model.CNTRTOTAL = ds.Tables[0].Rows[0]["CNTRTOTAL"].ToString();
if (ds.Tables[0].Rows[0]["ISTHROUGH"].ToString() != "")
{
if ((ds.Tables[0].Rows[0]["ISTHROUGH"].ToString() == "1") || (ds.Tables[0].Rows[0]["ISTHROUGH"].ToString().ToLower() == "true"))
{
model.ISTHROUGH = true;
}
else
{
model.ISTHROUGH = false;
}
}
model.GOODSNAME = ds.Tables[0].Rows[0]["GOODSNAME"].ToString();
if (ds.Tables[0].Rows[0]["KGS"].ToString() != "")
{
model.KGS = decimal.Parse(ds.Tables[0].Rows[0]["KGS"].ToString());
}
if (ds.Tables[0].Rows[0]["PRICE"].ToString() != "")
{
model.PRICE = decimal.Parse(ds.Tables[0].Rows[0]["PRICE"].ToString());
}
model.SHORTNAME = ds.Tables[0].Rows[0]["SHORTNAME"].ToString();
model.PROBLEMGID = ds.Tables[0].Rows[0]["PROBLEMGID"].ToString();
model.PROBLEMTYPE = ds.Tables[0].Rows[0]["PROBLEMTYPE"].ToString();
model.PROBLEMTITLE = ds.Tables[0].Rows[0]["PROBLEMTITLE"].ToString();
model.PROBLEMCONTENT = ds.Tables[0].Rows[0]["PROBLEMCONTENT"].ToString();
if (ds.Tables[0].Rows[0]["ISPROBLEM"].ToString() != "")
{
if ((ds.Tables[0].Rows[0]["ISPROBLEM"].ToString() == "1") || (ds.Tables[0].Rows[0]["ISPROBLEM"].ToString().ToLower() == "true"))
{
model.ISPROBLEM = true;
}
else
{
model.ISPROBLEM = false;
}
}
if (ds.Tables[0].Rows[0]["ISTYPE"].ToString() != "")
{
if ((ds.Tables[0].Rows[0]["ISTYPE"].ToString() == "1") || (ds.Tables[0].Rows[0]["ISTYPE"].ToString().ToLower() == "true"))
{
model.ISTYPE = true;
}
else
{
model.ISTYPE = false;
}
}
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.CLIENTGID = ds.Tables[0].Rows[0]["CLIENTGID"].ToString();
model.FAQREPLYMAN = ds.Tables[0].Rows[0]["FAQREPLYMAN"].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_faq ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
//
return SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql.ToString());
}
/// <summary>
/// 获得前n行数据
/// </summary>
public DataSet GetList(int top, string strWhere, string filedOrder)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select ");
if (top > 0)
{
strSql.Append(" top " + top.ToString());
}
strSql.Append(" GID, PROBLEMGID, PROBLEMTYPE, PROBLEMTITLE, PROBLEMCONTENT, ISPROBLEM, ISTYPE, CREATEUSER, CREATETIME,CLIENTGID,FAQREPLYMAN ");
strSql.Append(" FROM crm_info_faq ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
strSql.Append(" order by " + filedOrder);
return SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql.ToString());
}
/// <summary>
/// 获取记录总数
/// </summary>
public int GetRecordCount(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(1) FROM crm_info_faq ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
object obj = SqlHelper.GetSingle(SqlHelper.ConnectionStringLocalTransaction, strSql.ToString());
if (obj == null)
{
return 0;
}
else
{
return Convert.ToInt32(obj);
}
}
/// <summary>
/// 分页获取数据列表
/// </summary>
public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("SELECT * FROM ( ");
strSql.Append(" SELECT ROW_NUMBER() OVER (");
if (!string.IsNullOrEmpty(orderby.Trim()))
{
strSql.Append("order by T." + orderby);
}
else
{
strSql.Append("order by T.GID desc");
}
strSql.Append(")AS Row, T.* from crm_info_faq T ");
if (!string.IsNullOrEmpty(strWhere.Trim()))
{
strSql.Append(" WHERE " + strWhere);
}
strSql.Append(" ) TT");
strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
return SqlHelper.ExecuteDataset(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, strSql.ToString());
}
/// <summary>
/// 分页获取数据列表
/// </summary>
public DataSet GetList(int PageSize, int PageIndex, string strWhere)
{
SqlParameter[] parameters = {
new SqlParameter("@tblName", SqlDbType.VarChar, 255),
new SqlParameter("@fldName", SqlDbType.VarChar, 255),
new SqlParameter("@PageSize", SqlDbType.Int),
new SqlParameter("@PageIndex", SqlDbType.Int),
new SqlParameter("@IsReCount", SqlDbType.Bit),
new SqlParameter("@OrderType", SqlDbType.Bit),
new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
};
parameters[0].Value = "crm_info_faq";
parameters[1].Value = "GID";
parameters[2].Value = PageSize;
parameters[3].Value = PageIndex;
parameters[4].Value = 0;
parameters[5].Value = 0;
parameters[6].Value = strWhere;
return SqlHelper.RunProcedure(SqlHelper.ConnectionStringLocalTransaction.ToString(), "UP_GetRecordByPage", parameters, "ds");
}
}
}