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/Areas/CommMng/DAL/PubSysDAL.cs

248 lines
10 KiB
C#

2 years ago
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.Common;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Web;
using DSWeb.Areas.CommMng.Models;
using DSWeb.EntityDA;
using DSWeb.TruckMng.Comm.Cookie;
using HcUtility.Comm;
using Microsoft.Practices.EnterpriseLibrary.Data;
namespace DSWeb.Areas.CommMng.DAL
{
public class PubSysDAL
{
public static List<SysEnumValue> GetEnumValueList(decimal enumTypeId)
{
return GetEnumValueList(enumTypeId, String.Empty);
}
public static List<SysEnumValue> GetEnumValueList(decimal enumTypeId, string sCondition)
{
var strSql = new StringBuilder();
strSql.Append("Select LangId,EnumTypeId,EnumValueId,EnumValueName,EnumValueName_2,IsDefault,DispIndex,VerNo ");
strSql.Append(" from tSysEnumValue ");
strSql.Append(" where EnumTypeId=" + enumTypeId);
if (sCondition != String.Empty)
{
strSql.Append(" and " + sCondition);
}
strSql.Append(" order by EnumTypeID,dispindex,EnumValueID");
Database db = DatabaseFactory.CreateDatabase();
var evList = new List<SysEnumValue>();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var evData = new SysEnumValue();
evData.LangId = Convert.ToDecimal(reader["LangId"]);
evData.EnumTypeId = Convert.ToDecimal(reader["EnumTypeId"]);
evData.EnumValueId = Convert.ToString(reader["EnumValueId"]);
evData.EnumValueName = Convert.ToString(reader["EnumValueName"]);
evData.EnumValueName_2 = Convert.ToString(reader["EnumValueName_2"]);
evData.IsDefault = Convert.ToString(reader["IsDefault"]);
evData.DispIndex = Convert.ToDecimal(reader["DispIndex"]);
evData.VerNo = Convert.ToString(reader["VerNo"]);
evData.EnumValueAndName = evData.EnumValueId + "-" + evData.EnumValueName;
evList.Add(evData);
}
reader.Close();
}
var evDatanew = new SysEnumValue();
evDatanew.LangId =100;
evDatanew.EnumTypeId =100;
evDatanew.EnumValueId ="";
evDatanew.EnumValueName ="";
evDatanew.EnumValueName_2 ="";
evDatanew.IsDefault ="";
evDatanew.DispIndex =100;
evDatanew.VerNo ="";
evDatanew.EnumValueAndName ="";
evList.Add(evDatanew);
return evList;
}
public static string GetBillNo(string billType)
{
var cookies = new Cookies();
var orgCode = cookies.getCookie(CookieConstant.OrgCode);//登录组织
Database db = DatabaseFactory.CreateDatabase();
var cmd = db.GetStoredProcCommand("sSysGetBillNo");
db.AddInParameter(cmd, "@ps_BillType", DbType.String, billType);
db.AddInParameter(cmd, "@ps_OrgCode", DbType.String, orgCode);
db.AddOutParameter(cmd, "@ps_BillNo", DbType.String, 20);
db.AddInParameter(cmd, "@ps_RefBillNo", DbType.String, null);
db.ExecuteNonQuery(cmd);
return Convert.ToString(db.GetParameterValue(cmd, "@ps_BillNo"));
}
public static DBResult Account(string billno, string ywtype,
string userId, string userCode, string userName)
{
Database db = DatabaseFactory.CreateDatabase();
var cmd = db.GetStoredProcCommand("sMsSysAccount");
db.AddInParameter(cmd, "@ps_BillNo", DbType.String, billno);
db.AddInParameter(cmd, "@ps_YwType", DbType.String, ywtype);
db.AddInParameter(cmd, "@ps_UserId", DbType.String, userId);
db.AddInParameter(cmd, "@ps_UserCode", DbType.String, userCode);
db.AddInParameter(cmd, "@ps_UserName", DbType.String, userName);
db.AddOutParameter(cmd, "@pi_Result", DbType.Int32, 20);
db.AddOutParameter(cmd, "@ps_Message", DbType.String, 2000);
db.ExecuteNonQuery(cmd);
var result = new DBResult();
result.Success = Convert.ToInt32(db.GetParameterValue(cmd, "@pi_Result")) == 1;
result.Message = Convert.ToString(db.GetParameterValue(cmd, "@ps_Message"));
return result;
}
#region 调用存储过程返回数据集
/// <summary>
/// 根据存储过程返回DataSet
/// </summary>
/// <param name="prcName">存储过程名称</param>
/// <param name="dbparams">参数列表(不包含存储过程的返回游标)</param>
/// <param name="curnames">存储过程的返回游标名称列表</param>
/// <returns>DataSet</returns>
public static DBDataSetResult GetMsSqlPrcDataSet(string prcName, List<CustomDbParamter> dbparams,
List<string> curnames)
{
var dbrptResult = new DBDataSetResult();
dbrptResult.Success = false;
Debug.Assert(curnames != null, "参数curnames不能为空");
if (curnames.Count == 0)
{
dbrptResult.Message = "参数curnames长度不能为0";
}
int iResult = -1;
string sMessage = String.Empty;
var dataSet = new DataSet();
var ConnectionStringLocalTransaction = "";
var connectstr = ConfigurationManager.ConnectionStrings["DongShengRpt"];
if (connectstr != null)
ConnectionStringLocalTransaction = ConfigurationManager.ConnectionStrings["DongShengRpt"].ConnectionString;
Database db = DatabaseFactory.CreateDatabase();
if (!string.IsNullOrEmpty(ConnectionStringLocalTransaction)) db = DatabaseFactory.CreateDatabase("DongShengRpt");
using (IDbConnection idbconn = db.CreateConnection())
{
using (DbCommand cmd = db.GetStoredProcCommand(prcName))
{
cmd.CommandTimeout = 1200000; //要加这一句
idbconn.Open();
try
{
IDbTransaction idbtran = idbconn.BeginTransaction();
try
{
cmd.Transaction = (DbTransaction)idbtran;
foreach (DbParameter param in dbparams)
{
switch (param.Direction)
{
case ParameterDirection.Input:
db.AddInParameter(cmd, param.ParameterName, param.DbType, param.Value);
break;
case ParameterDirection.Output:
db.AddOutParameter(cmd, param.ParameterName, param.DbType, param.Size);
break;
case ParameterDirection.InputOutput:
case ParameterDirection.ReturnValue:
db.AddParameter(cmd, param.ParameterName, param.DbType, param.Direction,
param.SourceColumn, DataRowVersion.Default, param.Value);
break;
}
}
db.AddOutParameter(cmd, "@pi_result", DbType.Int32, 32);
db.AddOutParameter(cmd, "@ps_Message", DbType.String, 2000);
db.LoadDataSet(cmd, dataSet, curnames.ToArray(), (DbTransaction)idbtran);
iResult = Convert.ToInt32(db.GetParameterValue(cmd, "@pi_Result"));
sMessage = Convert.ToString(db.GetParameterValue(cmd, "@ps_Message"));
idbtran.Commit();
}
catch (Exception e)
{
idbtran.Rollback();
iResult = -1; // Convert.ToInt32(db.GetParameterValue(cmd, "pi_Result"));
sMessage = e.Message;//sMessage = Convert.ToString(db.GetParameterValue(cmd, "ps_Message"));
}
}
finally
{
idbconn.Close();
}
}
}
if (iResult == 1)
{
dbrptResult.Success = true;
dbrptResult.Message = "查询成功!";
dbrptResult.DataSet = dataSet;
}
else
{
dbrptResult.Success = false;
dbrptResult.Message = "查询失败:" + sMessage;
dbrptResult.Success = false;
}
return dbrptResult;
}
/// <summary>
/// 根据存储过程返回DataTable
/// </summary>
/// <param name="prcName">存储过程名称</param>
/// <param name="dbparams">参数列表(不包含存储过程的返回游标)</param>
/// <returns>DataSet</returns>
public static DBDataSetResult GetMsSqlPrcDataSet(string prcName, List<CustomDbParamter> dbparams, string curName)
{
var curnames = new List<string>();
curnames.Add(curName);
return GetMsSqlPrcDataSet(prcName, dbparams, curnames);
}
#endregion
public static string getGuid()
{
Guid guid = Guid.NewGuid();
return guid.ToString().Replace("-", "").ToUpper();
}
#region 直接执行sql命令
static public int ExecSql ( string StrSql )
{
Database db = DatabaseFactory.CreateDatabase();
var _count = db.ExecuteNonQuery(CommandType.Text, StrSql);
return _count;
}
#endregion
}
}