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/MvcShipping/DAL/MsCtExplan/MsCtExplanDAL.cs

198 lines
8.8 KiB
C#

using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.MvcShipping.Models.MsCtExplan;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.EntityDA;
using DSWeb.Areas.CommMng.Models;
using HcUtility.Comm;
using System.Data.SqlClient;
using DSWeb.DataAccess;
using HcUtility.Core;
using DSWeb.Areas.CommMng.DAL;
namespace DSWeb.MvcShipping.DAL.MsCtExplanDAL
{
public class MsCtExplanDAL
{
#region 查询
static public List<MsCtExplan> GetDataList(string strCondition, string userid, string usercode, string companyid,string sort = null)
{
string strCtSTARTGID = BasicDataRefDAL.GetCtSTARTGID(userid);
var strSql = new StringBuilder();
strSql.Append("SELECT *,MODIFIEDUSERNAME=(select top 1 SHOWNAME from [user] where gid=ct_explan.MODIFIEDUSER) from ct_explan where STARTGID='" + strCtSTARTGID + "'");// CORPID='" + companyid + "'
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
//
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by EXPLANTYPE");
}
return SetData(strSql);
}
static public MsCtExplan GetData(string condition, string companyid,string userid)
{
string strCtSTARTGID = BasicDataRefDAL.GetCtSTARTGID(userid);
var strSql = new StringBuilder();
strSql.Append("SELECT *,MODIFIEDUSERNAME=(select top 1 SHOWNAME from [user] where gid=ct_explan.MODIFIEDUSER) from ct_explan where STARTGID='" + strCtSTARTGID + "'");// CORPID='" + companyid + "'
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
var list=SetData(strSql);
if (list.Count > 0)
return list[0];
return new MsCtExplan();
}
private static List<MsCtExplan> SetData(StringBuilder strSql)
{
var headList = new List<MsCtExplan>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
#region 手动添加(所有类别)
/*
MsCtExplan data2 = new MsCtExplan();
#region Set DB data to Object
data2.GID = "(所有类别)";//唯一编码
data2.EXPLANTYPE = "(所有类别)";//摘要类别
data2.MODULETYPE = "";//财务/出纳模块
data2.STARTGID = "";//账套启用GID
data2.CORPID = "";//分公司代码
data2.MODIFIEDUSER = "";//更改操作人gid
data2.MODIFIEDTIME = DateTime.Now;
data2.MODIFIEDUSERNAME = "";//更改人
#endregion
headList.Add(data2);
*/
#endregion
//
while (reader.Read())
{
MsCtExplan data = new MsCtExplan();
#region Set DB data to Object
data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]));//唯一编码
data.EXPLANTYPE = (reader["EXPLANTYPE"] == null ? "" : Convert.ToString(reader["EXPLANTYPE"]));//摘要类别
data.MODULETYPE = (reader["MODULETYPE"] == null ? "" : Convert.ToString(reader["MODULETYPE"]));//财务/出纳模块
data.STARTGID = (reader["STARTGID"] == null ? "" : Convert.ToString(reader["STARTGID"]));//账套启用GID
data.CORPID = (reader["CORPID"] == null ? "" : Convert.ToString(reader["CORPID"]));//分公司代码
data.MODIFIEDUSER = (reader["MODIFIEDUSER"] == null ? "" : Convert.ToString(reader["MODIFIEDUSER"]));//更改操作人gid
if (data.MODIFIEDTIME != null)
data.MODIFIEDTIME = Convert.ToDateTime(reader["MODIFIEDTIME"]);//更改操作时间
data.MODIFIEDUSERNAME = (reader["MODIFIEDUSERNAME"] == null ? "" : Convert.ToString(reader["MODIFIEDUSERNAME"]));//更改人
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 查询明细
static public List<MsCtExplanDetail> GetDataListDetail(string strCondition, string userid, string usercode, string companyid, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT *,MODIFIEDUSERNAME=(select top 1 SHOWNAME from [user] where gid=ct_explan_detail.MODIFIEDUSER) from ct_explan_detail where 1=1");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
//
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by EXPLAN");
}
return SetDataDetail(strSql);
}
static public MsCtExplanDetail GetDataDetail(string condition, string companyid)
{
var strSql = new StringBuilder();
strSql.Append("SELECT *,MODIFIEDUSERNAME=(select top 1 SHOWNAME from [user] where gid=ct_explan_detail.MODIFIEDUSER) from ct_explan_detail where 1=1");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
var list = SetDataDetail(strSql);
if (list.Count > 0)
return list[0];
return new MsCtExplanDetail();
}
private static List<MsCtExplanDetail> SetDataDetail(StringBuilder strSql)
{
var headList = new List<MsCtExplanDetail>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsCtExplanDetail data = new MsCtExplanDetail();
#region Set DB data to Object
data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]));//唯一编码
data.LINKGID = (reader["LINKGID"] == null ? "" : Convert.ToString(reader["LINKGID"]));//摘要GID
data.EXPLAN = (reader["EXPLAN"] == null ? "" : Convert.ToString(reader["EXPLAN"]));//内容
data.MODIFIEDUSER = (reader["MODIFIEDUSER"] == null ? "" : Convert.ToString(reader["MODIFIEDUSER"]));//更改操作人gid
if (data.MODIFIEDTIME != null)
data.MODIFIEDTIME = Convert.ToDateTime(reader["MODIFIEDTIME"]);//更改操作时间
data.MODIFIEDUSERNAME = (reader["MODIFIEDUSERNAME"] == null ? "" : Convert.ToString(reader["MODIFIEDUSERNAME"]));//更改人
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 删除
public static DBResult Delete(MsCtExplan head, string strUSERID)
{
string strCtSTARTGID = BasicDataRefDAL.GetCtSTARTGID(strUSERID);
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdDelete = db.GetSqlStringCommand("delete from ct_explan_detail where LINKGID='" + head.GID.ToString().Trim() + "'");
db.ExecuteNonQuery(cmdDelete, tran);
cmdDelete = db.GetSqlStringCommand("delete from ct_explan where STARTGID='" + strCtSTARTGID + "' and GID='" + head.GID.ToString().Trim() + "'");
db.ExecuteNonQuery(cmdDelete, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "删除出现错误,请重试!";
return result;
}
}
result.Success = true;
result.Message = "操作成功";
return result;
}
#endregion
}
}