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.

294 lines
13 KiB
C#

9 months ago
using System;
using System.Data;
using System.Text;
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.Models;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Collections;
using WebSqlHelper;
using System.Linq;
using System.Xml.Linq;
namespace DSWeb.EntityDA
{
public class InfoClientContractDA
{
public InfoClientContractDA()
{
}
/// <summary>
/// 增加一条数据
/// </summary>
public int Add(InfoClientContractEntity model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("insert into info_client_contract(");
strSql.Append("GID,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,LINKID,CONTRACTNO,{0}{2}{4}CHIEF,REMARK,CORPID,DEPTGID");
strSql.Append(") values (");
strSql.Append("@GID,@CREATEUSER,getdate(),@MODIFIEDUSER,getdate(),@LINKID,@CONTRACTNO,{1}{3}{5}@CHIEF,@REMARK,@CORPID,@DEPTGID");
strSql.Append(") ");
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,36) ,
new SqlParameter("@CREATEUSER", SqlDbType.VarChar,36) ,
new SqlParameter("@MODIFIEDUSER", SqlDbType.VarChar,36) ,
new SqlParameter("@LINKID", SqlDbType.VarChar,100) ,
new SqlParameter("@CONTRACTNO", SqlDbType.VarChar,100) ,
new SqlParameter("@CHIEF", SqlDbType.VarChar,20) ,
new SqlParameter("@REMARK", SqlDbType.VarChar,1024) ,
new SqlParameter("@CORPID", SqlDbType.VarChar,36) ,
new SqlParameter("@DEPTGID", SqlDbType.VarChar,36)
//new SqlParameter("@SIGNINGDATE", SqlDbType.DateTime) ,
//new SqlParameter("@STARTDATE", SqlDbType.DateTime) ,
//new SqlParameter("@CANCELDATE", SqlDbType.DateTime) ,
};
parameters[0].Value = model.GID;
parameters[1].Value = model.CREATEUSER;
parameters[2].Value = model.MODIFIEDUSER;
parameters[3].Value = model.LINKID;
parameters[4].Value = model.CONTRACTNO;
parameters[5].Value = model.CHIEF;
parameters[6].Value = model.REMARK;
parameters[7].Value = model.CORPID;
parameters[8].Value = model.DEPTGID;
//parameters[5].Value = model.SIGNINGDATE;
//parameters[6].Value = model.STARTDATE;
//parameters[7].Value = model.CANCELDATE;
//
string strSIGNINGDATE = model.SIGNINGDATE.ToString().IndexOf("0001") > -1 ? "" : "'" + model.SIGNINGDATE.ToString() + "',";
string strSIGNINGDATE_name = strSIGNINGDATE.Equals("") ? "" : "SIGNINGDATE,";
string strSTARTDATE = model.STARTDATE.ToString().IndexOf("0001") > -1 ? "" : "'" + model.STARTDATE.ToString() + "',";
string strSTARTDATE_name = strSTARTDATE.Equals("") ? "" : "STARTDATE,";
string strCANCELDATE = model.CANCELDATE.ToString().IndexOf("0001") > -1 ? "" : "'" + model.CANCELDATE.ToString() + "',";
string strCANCELDATE_name = strCANCELDATE.Equals("") ? "" : "CANCELDATE,";
string sSql = String.Format(strSql.ToString().Trim(), strSIGNINGDATE_name, strSIGNINGDATE, strSTARTDATE_name, strSTARTDATE, strCANCELDATE_name, strCANCELDATE);
//
int iResult = 0;
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
int existVal = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, sSql, 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(InfoClientContractEntity model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("update info_client_contract set ");
strSql.Append(" MODIFIEDUSER = @MODIFIEDUSER , ");
strSql.Append(" MODIFIEDTIME = getdate() , ");
strSql.Append(" CONTRACTNO = @CONTRACTNO , ");
strSql.Append(" {0}{1}{2}{3}{4}{5} ");
strSql.Append(" CHIEF = @CHIEF , ");
strSql.Append(" REMARK = @REMARK, ");
strSql.Append(" CORPID = @CORPID, ");
strSql.Append(" DEPTGID = @DEPTGID ");
strSql.Append(" where GID=@GID ");
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,36) ,
new SqlParameter("@MODIFIEDUSER", SqlDbType.VarChar,36) ,
new SqlParameter("@CONTRACTNO", SqlDbType.VarChar,100) ,
new SqlParameter("@CHIEF", SqlDbType.VarChar,20) ,
new SqlParameter("@REMARK", SqlDbType.VarChar,1024) ,
new SqlParameter("@CORPID", SqlDbType.VarChar,36) ,
new SqlParameter("@DEPTGID", SqlDbType.VarChar,36)
//new SqlParameter("@SIGNINGDATE", SqlDbType.DateTime) ,
//new SqlParameter("@STARTDATE", SqlDbType.DateTime) ,
//new SqlParameter("@CANCELDATE", SqlDbType.DateTime) ,
};
parameters[0].Value = model.GID;
parameters[1].Value = model.MODIFIEDUSER;
parameters[2].Value = model.CONTRACTNO;
parameters[3].Value = model.CHIEF;
parameters[4].Value = model.REMARK;
parameters[5].Value = model.CORPID;
parameters[6].Value = model.DEPTGID;
//parameters[2].Value = model.SIGNINGDATE;
//parameters[3].Value = model.STARTDATE;
//parameters[4].Value = model.CANCELDATE;
//
string strSIGNINGDATE = model.SIGNINGDATE.ToString().IndexOf("0001") > -1 ? "null," : "'" + model.SIGNINGDATE.ToString() + "',";
string strSIGNINGDATE_name = "SIGNINGDATE=";
string strSTARTDATE = model.STARTDATE.ToString().IndexOf("0001") > -1 ? "null," : "'" + model.STARTDATE.ToString() + "',";
string strSTARTDATE_name = "STARTDATE=";
string strCANCELDATE = model.CANCELDATE.ToString().IndexOf("0001") > -1 ? "null," : "'" + model.CANCELDATE.ToString() + "',";
string strCANCELDATE_name = "CANCELDATE=";
string sSql = String.Format(strSql.ToString().Trim(), strSIGNINGDATE_name, strSIGNINGDATE, strSTARTDATE_name, strSTARTDATE, strCANCELDATE_name, strCANCELDATE);
//
int iResult = 0;
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
int existVal = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, sSql, 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 info_client_contract ");
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 InfoClientContractEntity GetModel(string GID)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select GID, CREATEUSER, CREATETIME, MODIFIEDUSER, MODIFIEDTIME, LINKID, CONTRACTNO, SIGNINGDATE, STARTDATE, CANCELDATE, CHIEF, REMARK, CORPID, DEPTGID");
strSql.Append(" from info_client_contract ");
strSql.Append(" where GID=@GID ");
SqlParameter[] parameters = {
new SqlParameter("@GID", SqlDbType.VarChar,36) };
parameters[0].Value = GID;
InfoClientContractEntity model = new InfoClientContractEntity();
DataSet ds = SqlHelper.Query(strSql.ToString(), parameters);
if (ds.Tables[0].Rows.Count > 0)
{
model.GID = ds.Tables[0].Rows[0]["GID"].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());
}
model.LINKID = ds.Tables[0].Rows[0]["LINKID"].ToString();
model.CONTRACTNO = ds.Tables[0].Rows[0]["CONTRACTNO"].ToString();
if (ds.Tables[0].Rows[0]["SIGNINGDATE"].ToString() != "")
{
model.SIGNINGDATE = DateTime.Parse(ds.Tables[0].Rows[0]["SIGNINGDATE"].ToString());
}
if (ds.Tables[0].Rows[0]["STARTDATE"].ToString() != "")
{
model.STARTDATE = DateTime.Parse(ds.Tables[0].Rows[0]["STARTDATE"].ToString());
}
if (ds.Tables[0].Rows[0]["CANCELDATE"].ToString() != "")
{
model.CANCELDATE = DateTime.Parse(ds.Tables[0].Rows[0]["CANCELDATE"].ToString());
}
model.CHIEF = ds.Tables[0].Rows[0]["CHIEF"].ToString();
model.REMARK = ds.Tables[0].Rows[0]["REMARK"].ToString();
model.CORPID = ds.Tables[0].Rows[0]["CORPID"].ToString();
model.DEPTGID = ds.Tables[0].Rows[0]["DEPTGID"].ToString();
return model;
}
else
{
return null;
}
}
/// <summary>
/// 获得数据列表
/// </summary>
public DataSet GetList(string strWhere)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("select * ");
strSql.Append(" FROM info_client_contract ");
if (strWhere.Trim() != "")
{
strSql.Append(" where " + strWhere);
}
//
DataSet DS = SqlHelper.OpenSqlDataSet(SqlHelper.ConnectionStringLocalTransaction, strSql.ToString());
try
{
if (DS.Tables[0].Rows.Count <= 0)
{
DS = null;
}
}
catch
{
DS = null;
}
return DS;
}
//
}
}