|
|
using System;
|
|
|
using System.Data;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Text;
|
|
|
using DSWeb.MvcShipping.Models.MsCtDesignStartusing;
|
|
|
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.MsCtDesignStartusingDAL
|
|
|
{
|
|
|
public class MsCtDesignStartusingDAL
|
|
|
{
|
|
|
#region 查询
|
|
|
static public List<MsCtDesignStartusing> GetDataList(string strCondition, string userid, string usercode, string companyid,string sort = null)
|
|
|
{
|
|
|
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(userid);
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append("SELECT *,MODIFIEDUSERNAME=(select top 1 SHOWNAME from [user] where gid=ct_design_startusing.MODIFIEDUSER and (ISDELETE=0 or ISDELETE is null)),STARTNAME=(select top 1 STARTNAME from [cw_design_startusing] where gid=ct_design_startusing.STARTGID and (ISDELETE=0 or ISDELETE is null)) from ct_design_startusing where ISDELETE=0 and STARTGID='" + strCwSTARTGID + "'");// and 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 STARTMONTH,CREATETIME");
|
|
|
}
|
|
|
return SetData(strSql);
|
|
|
}
|
|
|
|
|
|
static public MsCtDesignStartusing GetData(string condition, string companyid, string strUserID)
|
|
|
{
|
|
|
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID);
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append("SELECT *,MODIFIEDUSERNAME=(select top 1 SHOWNAME from [user] where gid=ct_design_startusing.MODIFIEDUSER and (ISDELETE=0 or ISDELETE is null)),STARTNAME=(select top 1 STARTNAME from [cw_design_startusing] where gid=ct_design_startusing.STARTGID and (ISDELETE=0 or ISDELETE is null)) from ct_design_startusing where ISDELETE=0 and STARTGID='" + strCwSTARTGID + "'");// and CORPID='" + companyid + "'
|
|
|
if (!string.IsNullOrEmpty(condition))
|
|
|
{
|
|
|
strSql.Append(" and " + condition);
|
|
|
}
|
|
|
var list=SetData(strSql);
|
|
|
if (list.Count > 0)
|
|
|
return list[0];
|
|
|
return new MsCtDesignStartusing();
|
|
|
}
|
|
|
|
|
|
private static List<MsCtDesignStartusing> SetData(StringBuilder strSql)
|
|
|
{
|
|
|
var headList = new List<MsCtDesignStartusing>();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
MsCtDesignStartusing data = new MsCtDesignStartusing();
|
|
|
#region Set DB data to Object
|
|
|
data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]));//唯一编码
|
|
|
data.STARTMONTH = (reader["STARTMONTH"] == null ? "" : Convert.ToString(reader["STARTMONTH"]));//启用年月
|
|
|
data.STARTGID = (reader["STARTGID"] == null ? "" : Convert.ToString(reader["STARTGID"]));//财务账套GID
|
|
|
data.STARTNAME = (reader["STARTNAME"] == null ? "" : Convert.ToString(reader["STARTNAME"]));//财务账套
|
|
|
data.ISENABLE = (reader["ISENABLE"] == null ? false : Convert.ToBoolean(reader["ISENABLE"]));//是否启用
|
|
|
data.CORPID = (reader["CORPID"] == null ? "" : Convert.ToString(reader["CORPID"]));//分公司代码
|
|
|
data.ISDELETE = (reader["ISDELETE"] == null ? false : Convert.ToBoolean(reader["ISDELETE"]));//是否删除
|
|
|
data.DELETEUSER = (reader["DELETEUSER"] == null ? "" : Convert.ToString(reader["DELETEUSER"]));//删除人
|
|
|
data.DELETETIME = (reader["DELETETIME"] == null ? DateTime.Now : Convert.ToDateTime(reader["DELETETIME"]));//删除时间
|
|
|
data.CREATEUSER = (reader["CREATEUSER"] == null ? "" : Convert.ToString(reader["CREATEUSER"]));//创建人gid
|
|
|
if (data.CREATETIME != null)
|
|
|
data.CREATETIME = Convert.ToDateTime(reader["CREATETIME"]);//创建时间
|
|
|
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(MsCtDesignStartusing head, string strUSERID)
|
|
|
{
|
|
|
var result = new DBResult();
|
|
|
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
|
|
|
string sSQL = "select STARTGID from ct_initial_balance where STARTGID='" + head.GID.ToString().Trim() + "'"
|
|
|
+ " union "
|
|
|
+ "select STARTGID from ct_bank_journal where STARTGID='" + head.GID.ToString().Trim() + "'"
|
|
|
+ " union "
|
|
|
+ "select STARTGID from ct_bank_deploy where STARTGID='" + head.GID.ToString().Trim() + "'";
|
|
|
string sGID = T_ALL_DA.GetStrSQL("STARTGID", sSQL);
|
|
|
if (sGID.Trim() == "")
|
|
|
{
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (var conn = db.CreateConnection())
|
|
|
{
|
|
|
conn.Open();
|
|
|
var tran = conn.BeginTransaction();
|
|
|
try
|
|
|
{
|
|
|
//var cmdDelete = db.GetSqlStringCommand("update ct_design_startusing set ISDELETE=1,DELETEUSER='" + strUSERID + "',DELETETIME=getdate() where GID='" + head.GID.ToString().Trim() + "'");
|
|
|
var cmdDelete = db.GetSqlStringCommand("delete from ct_design_startusing where 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;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
result.Success = false;
|
|
|
result.Message = "账期已经使用,不允许操作!";
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 启用
|
|
|
public static DBResult onISENABLE(MsCtDesignStartusing head, string 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("update ct_design_startusing set ISENABLE=0");
|
|
|
//db.ExecuteNonQuery(cmdDelete, tran);
|
|
|
|
|
|
var cmdDelete = db.GetSqlStringCommand("update ct_design_startusing set ISENABLE=1 where GID='" + head.GID.ToString().Trim() + "' and (ISDELETE=0 or ISDELETE is null)");
|
|
|
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
|
|
|
|
|
|
#region 所属账套
|
|
|
static public List<MsCtDesignStartusing> GetCtSTARTGID(string strCondition, string strUserID)
|
|
|
{
|
|
|
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID);
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append("SELECT GID,STARTNAME from cw_design_startusing where GID='" + strCwSTARTGID + "' and (ISDELETE=0 or ISDELETE is null) and ISENABLE=1");
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
|
{
|
|
|
strSql.Append(" and " + strCondition);
|
|
|
}
|
|
|
strSql.Append(" order by STARTNAME");
|
|
|
return SetSTARTGIDData(strSql);
|
|
|
}
|
|
|
|
|
|
private static List<MsCtDesignStartusing> SetSTARTGIDData(StringBuilder strSql)
|
|
|
{
|
|
|
var headList = new List<MsCtDesignStartusing>();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
MsCtDesignStartusing data = new MsCtDesignStartusing();
|
|
|
#region Set DB data to Object
|
|
|
data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]));//唯一编码
|
|
|
data.STARTNAME = (reader["STARTNAME"] == null ? "" : Convert.ToString(reader["STARTNAME"]));//财务账套GID
|
|
|
#endregion
|
|
|
headList.Add(data);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
return headList;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 返回财务当前账套和会计期间
|
|
|
public static string GetInitData(string condition, string strCompanyID, string strUSERID)
|
|
|
{
|
|
|
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
|
|
|
string strCwSTARTNAME = T_ALL_DA.GetStrSQL("STARTNAME", "select top 1 STARTNAME from cw_design_startusing WITH(NOLOCK) where (ISDELETE=0 or ISDELETE is null) and ISENABLE=1 and GID=(select top 1 STARTGID from [cw_design_startusing_user] WITH(NOLOCK) where USERGID='" + strUSERID + "')");
|
|
|
if (strCwSTARTNAME == "")
|
|
|
{
|
|
|
return "-1";
|
|
|
}
|
|
|
string strCwACCDATE = BasicDataRefDAL.GetCwACCDATE(strUSERID);
|
|
|
if (strCwSTARTNAME == "")
|
|
|
{
|
|
|
return "-1";
|
|
|
}
|
|
|
return strCwSTARTNAME + "," + strCwACCDATE;
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
}
|