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/MsCwGenlegAccitems/MsCwGenlegAccitemsDAL.cs

719 lines
55 KiB
C#

2 years ago
using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.MvcShipping.Models.MsCwGenlegAccitems;
using DSWeb.MvcShipping.Models.MsCwAccitemsGl;
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.MsCwGenlegAccitemsDAL
{
public class MsCwGenlegAccitemsDAL
{
#region 查询
static public List<MsCwGenlegAccitems> GetDataList(string strCondition, string userid, string usercode, string companyid,string sort = null)
{
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(userid);
var strSql = new StringBuilder();
strSql.Append("SELECT *,LINKNAME=(select top 1 ACCNAME from [cw_accitems_gl] where gid=cw_genleg_accitems.LINKGID),MODIFIEDUSERNAME=(select top 1 SHOWNAME from [user] where gid=cw_genleg_accitems.MODIFIEDUSER),DR=isnull((case when CURRENCY='RMB' then AMTYEARDR else FCYYEARDR end),0),CR=isnull((case when CURRENCY='RMB' then AMTYEARCR else FCYYEARCR end),0)");
strSql.Append(" from cw_genleg_accitems where [STARTGID]='" + strCwSTARTGID + "' and ISDELETE=0");// 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 YEAR desc,MONTH desc,LINKNAME");
}
return SetData(strSql);
}
static public string GetDataListStr(string strCondition, string userid, string usercode, string companyid, string sort = null)
{
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(userid);
var strSql = new StringBuilder();
strSql.Append("SELECT *,LINKNAME=(select top 1 ACCNAME from [cw_accitems_gl] where gid=cw_genleg_accitems.LINKGID),MODIFIEDUSERNAME=(select top 1 SHOWNAME from [user] where gid=cw_genleg_accitems.MODIFIEDUSER),DR=isnull((case when CURRENCY='RMB' then AMTYEARDR else FCYYEARDR end),0),CR=isnull((case when CURRENCY='RMB' then AMTYEARCR else FCYYEARCR end),0)");
strSql.Append(" from cw_genleg_accitems where [STARTGID]='" + strCwSTARTGID + "' and ISDELETE=0");// 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 YEAR desc,MONTH desc,LINKNAME");
}
return strSql.ToString();
}
static public MsCwGenlegAccitems GetData(string condition, string companyid, string strUSERID)
{
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUSERID);
var strSql = new StringBuilder();
strSql.Append("SELECT *,LINKNAME=(select top 1 ACCNAME from [cw_accitems_gl] where gid=cw_genleg_accitems.LINKGID),MODIFIEDUSERNAME=(select top 1 SHOWNAME from [user] where gid=cw_genleg_accitems.MODIFIEDUSER),DR=isnull((case when CURRENCY='RMB' then AMTYEARDR else FCYYEARDR end),0),CR=isnull((case when CURRENCY='RMB' then AMTYEARCR else FCYYEARCR end),0) from cw_genleg_accitems where [STARTGID]='" + strCwSTARTGID + "' and (ISDELETE=0 or ISDELETE is null)");// and CORPID='" + companyid + "'
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" and " + condition);
}
var list=SetData(strSql);
if (list.Count > 0)
return list[0];
return new MsCwGenlegAccitems();
}
private static List<MsCwGenlegAccitems> SetData(StringBuilder strSql)
{
var headList = new List<MsCwGenlegAccitems>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsCwGenlegAccitems data = new MsCwGenlegAccitems();
#region Set DB data to Object
data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]));//唯一编码
data.YEAR = (reader["YEAR"] == null ? "" : Convert.ToString(reader["YEAR"]));//年
data.MONTH = (reader["MONTH"] == null ? "" : Convert.ToString(reader["MONTH"]));//月
data.LINKGID = (reader["LINKGID"] == null ? "" : Convert.ToString(reader["LINKGID"]));//科目GID
data.CURRENCY = (reader["CURRENCY"] == null ? "RMB" : Convert.ToString(reader["CURRENCY"]));//是否核算外币
data.DEPTACC = (reader["DEPTACC"] == null ? "" : Convert.ToString(reader["DEPTACC"]));//是否核算部门
data.EMPLACC = (reader["EMPLACC"] == null ? "" : Convert.ToString(reader["EMPLACC"]));//是否核算人员
data.CORPACC = (reader["CORPACC"] == null ? "" : Convert.ToString(reader["CORPACC"]));//是否算客户门
data.ITEMACC = (reader["ITEMACC"] == null ? "" : Convert.ToString(reader["ITEMACC"]));//是否核算项目
data.AMTYEARDR = (reader["AMTYEARDR"] == null ? 0 : Convert.ToDecimal(reader["AMTYEARDR"]));//RMB年初借方
data.AMTYEARCR = (reader["AMTYEARCR"] == null ? 0 : Convert.ToDecimal(reader["AMTYEARCR"]));//RMB年初贷方
data.AMTYEARBLC = (reader["AMTYEARBLC"] == null ? 0 : Convert.ToDecimal(reader["AMTYEARBLC"]));//RMB年初余额
data.AMTDR = (reader["AMTDR"] == null ? 0 : Convert.ToDecimal(reader["AMTDR"]));//RMB本月借方
data.AMTCR = (reader["AMTCR"] == null ? 0 : Convert.ToDecimal(reader["AMTCR"]));//RMB本月贷方
data.AMTBLC = (reader["AMTBLC"] == null ? 0 : Convert.ToDecimal(reader["AMTBLC"]));//RMB本月余额
data.AMTLASTDR = (reader["AMTLASTDR"] == null ? 0 : Convert.ToDecimal(reader["AMTLASTDR"]));//RMB累计借方
data.AMTLASTCR = (reader["AMTLASTCR"] == null ? 0 : Convert.ToDecimal(reader["AMTLASTCR"]));//RMB累计贷方
data.AMTLASTBLC = (reader["AMTLASTBLC"] == null ? 0 : Convert.ToDecimal(reader["AMTLASTBLC"]));//RMB累计余额
data.FCYYEARDR = (reader["FCYYEARDR"] == null ? 0 : Convert.ToDecimal(reader["FCYYEARDR"]));//USD年初借方
data.FCYYEARCR = (reader["FCYYEARCR"] == null ? 0 : Convert.ToDecimal(reader["FCYYEARCR"]));//USD年初贷方
data.FCYYEARBLC = (reader["FCYYEARBLC"] == null ? 0 : Convert.ToDecimal(reader["FCYYEARBLC"]));//USD年初余额
data.FCYDR = (reader["FCYDR"] == null ? 0 : Convert.ToDecimal(reader["FCYDR"]));//USD本月借方
data.FCYCR = (reader["FCYCR"] == null ? 0 : Convert.ToDecimal(reader["FCYCR"]));//USD本月贷方
data.FCYBLC = (reader["FCYBLC"] == null ? 0 : Convert.ToDecimal(reader["FCYBLC"]));//USD本月余额
data.FCYLASTDR = (reader["FCYLASTDR"] == null ? 0 : Convert.ToDecimal(reader["FCYLASTDR"]));//USD累计借方
data.FCYLASTCR = (reader["FCYLASTCR"] == null ? 0 : Convert.ToDecimal(reader["FCYLASTCR"]));//USD累计贷方
data.FCYLASTBLC = (reader["FCYLASTBLC"] == null ? 0 : Convert.ToDecimal(reader["FCYLASTBLC"]));//USD累计余额
data.QTYYEARDR = (reader["QTYYEARDR"] == null ? 0 : Convert.ToDecimal(reader["QTYYEARDR"]));//年初借方
data.QTYYEARCR = (reader["QTYYEARCR"] == null ? 0 : Convert.ToDecimal(reader["QTYYEARCR"]));//年初贷方
data.QTYYEARBLC = (reader["QTYYEARBLC"] == null ? 0 : Convert.ToDecimal(reader["QTYYEARBLC"]));//年初余额
data.QTYDR = (reader["QTYDR"] == null ? 0 : Convert.ToDecimal(reader["QTYDR"]));//本月借方
data.QTYCR = (reader["QTYCR"] == null ? 0 : Convert.ToDecimal(reader["QTYCR"]));//本月贷方
data.QTYBLC = (reader["QTYBLC"] == null ? 0 : Convert.ToDecimal(reader["QTYBLC"]));//本月余额
data.QTYLASTDR = (reader["QTYLASTDR"] == null ? 0 : Convert.ToDecimal(reader["QTYLASTDR"]));//累计借方
data.QTYLASTCR = (reader["QTYLASTCR"] == null ? 0 : Convert.ToDecimal(reader["QTYLASTCR"]));//累计贷方
data.QTYLASTBLC = (reader["QTYLASTBLC"] == null ? 0 : Convert.ToDecimal(reader["QTYLASTBLC"]));//累计余额
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"]));//删除人
string kjdE = reader["DELETETIME"].ToString();//删除时间
if (reader["DELETETIME"] != null && reader["DELETETIME"].ToString().Trim().IndexOf("0001") < 0 && reader["DELETETIME"].ToString().Trim().IndexOf("1900") < 0 && reader["DELETETIME"].ToString().Trim()!="")
{
data.DELETETIME = 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.LINKNAME = (reader["LINKNAME"] == null ? "" : Convert.ToString(reader["LINKNAME"]));//科目名称
data.MODIFIEDUSERNAME = (reader["MODIFIEDUSERNAME"] == null ? "" : Convert.ToString(reader["MODIFIEDUSERNAME"]));//更改人
data.DR = (reader["DR"] == null ? 0 : Convert.ToDecimal(reader["DR"]));
data.CR = (reader["CR"] == null ? 0 : Convert.ToDecimal(reader["CR"]));
data.ISENABLE = (reader["ISENABLE"] == null ? false : Convert.ToBoolean(reader["ISENABLE"]));
data.PFADR = (reader["PFADR"] == null ? 0 : Convert.ToDecimal(reader["PFADR"]));
data.PFACR = (reader["PFACR"] == null ? 0 : Convert.ToDecimal(reader["PFACR"]));
data.ACCDATE = (reader["ACCDATE"] == null ? "" : Convert.ToString(reader["ACCDATE"]));//会计期间
data.IsInitialEntry = (reader["IsInitialEntry"] == null ? false : Convert.ToBoolean(reader["IsInitialEntry"]));
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 查询期初列表
static public List<MsCwAccitemsGl> GetDataListCA(string strCondition, string strUserID)
{
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID);
string strCwACCDATE = BasicDataRefDAL.GetCwACCDATE(strUserID);
var strSql = new StringBuilder();
strSql.Append("SELECT GID,ACCID,ACCNAME,DETAILED,DC,ISFCY,ISDEPTACC,ISEMPLACC,ISCORPACC,ISITEMACC,REMARKS,[YEAR],[MONTH],PACCGID=(case when (PACCGID='ZC' or PACCGID='FZ' or PACCGID='GT' or PACCGID='QY' or PACCGID='CB' or PACCGID='SY') then '0' else PACCGID end),ACCATTRIBUTE,ACCTYPE,PACCID=(select top 1 ACCID from [cw_accitems_gl] as a where a.gid=cw_accitems_gl.PACCGID),PACCNAME=(select top 1 ACCNAME from [cw_accitems_gl] as b where b.gid=cw_accitems_gl.PACCGID),gid as [id],ACCID+' '+ACCNAME as [NAME],DR=isnull((select isnull(sum(QTYYEARDR),0) as QTYYEARDR from [cw_genleg_accitems] as c where c.[STARTGID]='" + strCwSTARTGID + "' and c.LINKGID=cw_accitems_gl.GID and IsInitialEntry=1),0),CR=isnull((select isnull(sum(QTYYEARCR),0) as QTYYEARCR from [cw_genleg_accitems] as d where d.[STARTGID]='" + strCwSTARTGID + "' and d.LINKGID=cw_accitems_gl.GID and IsInitialEntry=1),0),ISENABLE=isnull((select top 1 isnull(ISENABLE,0) as ISENABLE from [cw_genleg_accitems] as e where e.[STARTGID]='" + strCwSTARTGID + "' and e.ACCDATE=(select top 1 STARTMONTH from cw_design_startusing where [GID]='" + strCwSTARTGID + "') and e.LINKGID=cw_accitems_gl.GID),0),PFADR=isnull((select isnull(sum(PFADR),0) as PFADR from [cw_genleg_accitems] as c where c.[STARTGID]='" + strCwSTARTGID + "' and c.LINKGID=cw_accitems_gl.GID and IsInitialEntry=1),0),PFACR=isnull((select isnull(sum(PFACR),0) as PFACR from [cw_genleg_accitems] as d where d.[STARTGID]='" + strCwSTARTGID + "' and d.LINKGID=cw_accitems_gl.GID and IsInitialEntry=1),0),STARTMONTH=isnull((select top 1 STARTMONTH from [cw_design_startusing] where (ISDELETE=0 or ISDELETE is null) and gid=(select top 1 GID from [cw_genleg_accitems] as d where d.[STARTGID]='" + strCwSTARTGID + "' and d.LINKGID=cw_accitems_gl.GID and IsInitialEntry=1)),0)");
strSql.Append(" from [cw_accitems_gl] where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "'");
//
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(strCondition);
}
strSql.Append(" order by [YEAR],ACCID");
return SetDataCA(strSql);
}
private static List<MsCwAccitemsGl> SetDataCA(StringBuilder strSql)
{
var headList = new List<MsCwAccitemsGl>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsCwAccitemsGl data = new MsCwAccitemsGl();
#region Set DB data to Object
data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]).Trim());//唯一编码
data.ACCID = (reader["ACCID"] == null ? "" : Convert.ToString(reader["ACCID"]).Trim());//科目代码
data.ACCNAME = (reader["ACCNAME"] == null ? "" : Convert.ToString(reader["ACCNAME"]).Trim());//科目名称
data.DETAILED = (reader["DETAILED"] == null ? false : Convert.ToBoolean(reader["DETAILED"]));//是否末级科目(标志)
data.DC = (reader["DC"] == null ? "" : Convert.ToString(reader["DC"]).Trim());//借贷方向
data.ISFCY = (reader["ISFCY"] == null ? false : Convert.ToBoolean(reader["ISFCY"]));//是否核算外币
data.ISDEPTACC = (reader["ISDEPTACC"] == null ? false : Convert.ToBoolean(reader["ISDEPTACC"]));//是否核算部门
data.ISEMPLACC = (reader["ISEMPLACC"] == null ? false : Convert.ToBoolean(reader["ISEMPLACC"]));//是否核算人员
data.ISCORPACC = (reader["ISCORPACC"] == null ? false : Convert.ToBoolean(reader["ISCORPACC"]));//是否算客户门
data.ISITEMACC = (reader["ISITEMACC"] == null ? false : Convert.ToBoolean(reader["ISITEMACC"]));//是否核算项目
data.REMARKS = (reader["REMARKS"] == null ? "" : Convert.ToString(reader["REMARKS"]).Trim());//备注
data.YEAR = (reader["YEAR"] == null ? "" : Convert.ToString(reader["YEAR"]).Trim());//年
data.MONTH = (reader["MONTH"] == null ? "" : Convert.ToString(reader["MONTH"]).Trim());//月
data.PACCGID = (reader["PACCGID"] == null ? "" : Convert.ToString(reader["PACCGID"]).Trim());//父级科目代码
data.PACCID = (reader["PACCID"] == null ? "" : Convert.ToString(reader["PACCID"]).Trim());//父级科目ID
data.ACCATTRIBUTE = (reader["ACCATTRIBUTE"] == null ? "" : Convert.ToString(reader["ACCATTRIBUTE"]).Trim());//科目属性(资产、负债、共同、权益、成本、损益)
data.ISENABLE = (reader["ISENABLE"] == null ? false : Convert.ToBoolean(reader["ISENABLE"]));//是否启用
data.ACCTYPE = (reader["ACCTYPE"] == null ? "" : Convert.ToString(reader["ACCTYPE"]).Trim());
data.id = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]).Trim());//唯一编码
data.NAME = (reader["NAME"] == null ? "" : Convert.ToString(reader["NAME"]).Trim());//
if (data.DETAILED.ToString().Trim().ToLower() == "true")
{
data.leaf = true;
data.expanded = false;
}
else
{
data.leaf = false;
data.expanded = true;
}
data.DR = (reader["DR"] == null ? 0 : Convert.ToDecimal(reader["DR"]));
data.CR = (reader["CR"] == null ? 0 : Convert.ToDecimal(reader["CR"]));
data.PFADR = (reader["PFADR"] == null ? 0 : Convert.ToDecimal(reader["PFADR"]));
data.PFACR = (reader["PFACR"] == null ? 0 : Convert.ToDecimal(reader["PFACR"]));
data.STARTMONTH = (reader["STARTMONTH"] == null ? "" : Convert.ToString(reader["STARTMONTH"]).Trim());
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
static public List<MsCwAccitemsGl> GetDataListHJ(string strUserID)
{
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUserID);
string strCwACCDATE = BasicDataRefDAL.GetCwACCDATE(strUserID);
var strSql = new StringBuilder();
strSql.Append("select (case when isnull(sum(DR),0)=isnull(sum(CR),0) then '借贷平衡' else '借贷不平衡' end) as GID,isnull(sum(DR),0) as DR,isnull(sum(CR),0) as CR,isnull(sum(PFADR),0) as PFADR,isnull(sum(PFACR),0) as PFACR from (SELECT DR=isnull((select isnull(sum(QTYYEARDR),0) as QTYYEARDR from [cw_genleg_accitems] as c where c.[STARTGID]='" + strCwSTARTGID + "' and c.LINKGID=cw_accitems_gl.GID and IsInitialEntry=1),0),CR=isnull((select isnull(sum(QTYYEARCR),0) as QTYYEARCR from [cw_genleg_accitems] as d where d.[STARTGID]='" + strCwSTARTGID + "' and d.LINKGID=cw_accitems_gl.GID and IsInitialEntry=1),0),PFADR=isnull((select isnull(sum(PFADR),0) as PFADR from [cw_genleg_accitems] as c where c.[STARTGID]='" + strCwSTARTGID + "' and c.LINKGID=cw_accitems_gl.GID and IsInitialEntry=1),0),PFACR=isnull((select isnull(sum(PFACR),0) as PFACR from [cw_genleg_accitems] as d where d.[STARTGID]='" + strCwSTARTGID + "' and d.LINKGID=cw_accitems_gl.GID and IsInitialEntry=1),0) from [cw_accitems_gl] where [STARTGID]='" + strCwSTARTGID + "' and DETAILED=1 and [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4)) as a");
return SetDataHJ(strSql);
}
private static List<MsCwAccitemsGl> SetDataHJ(StringBuilder strSql)
{
var headList = new List<MsCwAccitemsGl>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsCwAccitemsGl data = new MsCwAccitemsGl();
#region Set DB data to Object
data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]).Trim());//唯一编码
data.DR = (reader["DR"] == null ? 0 : Convert.ToDecimal(reader["DR"]));
data.CR = (reader["CR"] == null ? 0 : Convert.ToDecimal(reader["CR"]));
data.PFADR = (reader["PFADR"] == null ? 0 : Convert.ToDecimal(reader["PFADR"]));
data.PFACR = (reader["PFACR"] == null ? 0 : Convert.ToDecimal(reader["PFACR"]));
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 保存/删除/入账/启用 期初列表
public static void SaveRow(MsCwAccitemsGl headData, string strUSERID, string strCOMPANYID, string CURRENCY)
{
var isPost = true;
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string PACCGID = headData.PACCGID.ToString().Trim();
string strCwACCDATE = BasicDataRefDAL.GetCwACCDATE(strUSERID);
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUSERID);
//ZC','FZ','GT','QY','CB','SY
if (headData.PACCGID.ToString().Trim() != "0" && headData.PACCGID.ToString().Trim() != "ZC" && headData.PACCGID.ToString().Trim() != "FZ" && headData.PACCGID.ToString().Trim() != "GT" && headData.PACCGID.ToString().Trim() != "QY" && headData.PACCGID.ToString().Trim() != "CB" && headData.PACCGID.ToString().Trim() != "SY")
{
string sSQL = "SELECT GID,ACCID,ACCNAME,DETAILED,DC,ISFCY,ISDEPTACC,ISEMPLACC,ISCORPACC,ISITEMACC,REMARKS,[YEAR],[MONTH],PACCGID=(case when (PACCGID='ZC' or PACCGID='FZ' or PACCGID='GT' or PACCGID='QY' or PACCGID='CB' or PACCGID='SY') then '0' else PACCGID end),ACCATTRIBUTE,ISENABLE,ACCTYPE,PACCID=(select top 1 ACCID from [cw_accitems_gl] as a where [STARTGID]='" + strCwSTARTGID + "' and a.gid=cw_accitems_gl.PACCGID),PACCNAME=(select top 1 ACCNAME from [cw_accitems_gl] as b where [STARTGID]='" + strCwSTARTGID + "' and b.gid=cw_accitems_gl.PACCGID),gid as [id],ACCID+' '+ACCNAME as [NAME],0 as DR,0 as CR from [cw_accitems_gl] where [STARTGID]='" + strCwSTARTGID + "' and [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) order by [YEAR],ACCID";
DataSet ds = T_ALL_DA.GetAllSQL(sSQL);
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
while (PACCGID.Trim() != "")
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
if (ds.Tables[0].Rows[i]["GID"].ToString().Trim() == PACCGID)
{
string pDC = ds.Tables[0].Rows[i]["DC"].ToString().Trim();
MsCwGenlegAccitems headRow = new MsCwGenlegAccitems();
string PACCGID_gid = T_ALL_DA.GetStrSQL("gid", "select top 1 isnull(gid,'') as gid from cw_genleg_accitems where [STARTGID]='" + strCwSTARTGID + "' and [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and LINKGID='" + PACCGID.Trim() + "' and DEPTACC='' and EMPLACC='' and CORPACC='' and ITEMACC='' and CURRENCY='" + CURRENCY + "'");//
if (PACCGID_gid.Trim() == "")//"add"
{
#region 默认值
headRow.YEAR = DateTime.Parse(strCwACCDATE + "-01").Year.ToString();//年
headRow.MONTH = DateTime.Parse(strCwACCDATE + "-01").Month.ToString();//月
if (DateTime.Parse(strCwACCDATE + "-01").Month.ToString().Length == 1)
{
headRow.MONTH = "0" + DateTime.Parse(strCwACCDATE + "-01").Month.ToString();//月
}
headRow.ACCDATE = headRow.YEAR.ToString() + "-" + headRow.MONTH.ToString();//月
headRow.LINKGID = PACCGID;//科目GID
headRow.DEPTACC = "";//核算部门
headRow.EMPLACC = "";//核算人员
headRow.CORPACC = "";//核算客户
headRow.ITEMACC = "";//核算项目
headRow.CURRENCY = CURRENCY;//币别
headRow.AMTYEARDR = headData.DR;//RMB期初借方
headRow.AMTYEARCR = headData.CR;//RMB期初贷方
headRow.AMTYEARBLC = (pDC == "借" ? (headRow.AMTYEARDR - headRow.AMTYEARCR) : (headRow.AMTYEARCR - headRow.AMTYEARDR));//RMB期初余额
headRow.AMTDR = 0;//RMB本月借方
headRow.AMTCR = 0;//RMB本月贷方
headRow.AMTBLC = 0;//RMB本月余额
headRow.AMTLASTDR = headData.DR;//RMB累计借方
headRow.AMTLASTCR = headData.CR;//RMB累计贷方
headRow.AMTLASTBLC = (pDC == "借" ? (headRow.AMTLASTDR - headRow.AMTLASTCR) : (headRow.AMTLASTCR - headRow.AMTLASTDR));//RMB累计余额
headRow.FCYYEARDR = 0;//外币期初借方
headRow.FCYYEARCR = 0;//外币期初贷方
headRow.FCYYEARBLC = 0;//外币期初余额
headRow.FCYDR = 0;//外币本月借方
headRow.FCYCR = 0;//外币本月贷方
headRow.FCYBLC = 0;//外币本月余额
headRow.FCYLASTDR = 0;//外币累计借方
headRow.FCYLASTCR = 0;//外币累计贷方
headRow.FCYLASTBLC = 0;//外币累计余额
Decimal rate = 1;
if (CURRENCY.Trim() != "RMB")
{
headRow.AMTYEARDR = 0;//RMB期初借方
headRow.AMTYEARCR = 0;//RMB期初贷方
headRow.AMTYEARBLC = 0;//RMB期初余额
headRow.AMTDR = 0;//RMB本月借方
headRow.AMTCR = 0;//RMB本月贷方
headRow.AMTBLC = 0;//RMB本月余额
headRow.AMTLASTDR = 0;//RMB累计借方
headRow.AMTLASTCR = 0;//RMB累计贷方
headRow.AMTLASTBLC = 0;//RMB累计余额
headRow.FCYYEARDR = headData.DR;//外币期初借方
headRow.FCYYEARCR = headData.CR;//外币期初贷方
headRow.FCYYEARBLC = (pDC == "借" ? (headRow.FCYYEARDR - headRow.FCYYEARCR) : (headRow.FCYYEARCR - headRow.FCYYEARDR));//外币期初余额
headRow.FCYDR = 0;//外币本月借方
headRow.FCYCR = 0;//外币本月贷方
headRow.FCYBLC = 0;//外币本月余额
headRow.FCYLASTDR = headData.DR;//外币累计借方
headRow.FCYLASTCR = headData.CR;//外币累计贷方
headRow.FCYLASTBLC = (pDC == "借" ? (headRow.FCYLASTDR - headRow.FCYLASTCR) : (headRow.FCYLASTCR - headRow.FCYLASTDR));//外币累计余额
rate = Decimal.Parse(T_ALL_DA.GetStrSQL("DEFAULTRATE", "SELECT top 1 DEFAULTRATE=isnull((select top 1 BEGRATE from cw_currency_rate where LINKGID=code_currency.GID and ISDELETE=0 and ACCDATE= '" + strCwACCDATE + "' and STARTGID='" + strCwSTARTGID + "'),DEFAULTRATE) from code_currency WITH(NOLOCK) where CODENAME='" + CURRENCY.Trim() + "'"));// and CORPID='" + strCOMPANYID + "'
}
headRow.QTYYEARDR = headData.DR * rate;//期初借方
headRow.QTYYEARCR = headData.CR * rate;//期初贷方
headRow.QTYYEARBLC = (pDC == "借" ? (headRow.QTYYEARDR - headRow.QTYYEARCR) : (headRow.QTYYEARCR - headRow.QTYYEARDR));//期初余额
headRow.QTYDR = 0;//本月借方
headRow.QTYCR = 0;//本月贷方
headRow.QTYBLC = 0;//本月余额
headRow.QTYLASTDR = headData.DR * rate;//累计借方
headRow.QTYLASTCR = headData.CR * rate;//累计贷方
headRow.QTYLASTBLC = (pDC == "借" ? (headRow.QTYLASTDR - headRow.QTYLASTCR) : (headRow.QTYLASTCR - headRow.QTYLASTDR));//累计余额
headRow.PFADR = headData.PFADR;//损益类科目本年累计数借方
headRow.PFACR = headData.PFACR;//损益类科目本年累计数贷方
headRow.CORPID = strCOMPANYID;//分公司代码
headRow.ISDELETE = false;//是否删除
headRow.DELETEUSER = strUSERID;//删除人
headRow.DELETETIME = DateTime.Now;//删除时间
headRow.CREATEUSER = strUSERID;//创建人gid
headRow.CREATETIME = DateTime.Now;//创建时间
headRow.MODIFIEDUSER = strUSERID;//更改操作人gid
headRow.MODIFIEDTIME = DateTime.Now;//更改操作时间
headRow.STARTGID = strCwSTARTGID;
headRow.IsInitialEntry = true;
#endregion
headRow.GID = Guid.NewGuid().ToString();//唯一编码
headRow.DbOperationType = DbOperationType.DbotIns;
}
else//"edit"
{
sSQL = "SELECT sum(AMTYEARDR) as AMTYEARDR,sum(AMTYEARCR) as AMTYEARCR,sum(case when '" + pDC + "'=DC then AMTYEARBLC else (-AMTYEARBLC) end) as AMTYEARBLC,sum(AMTDR) as AMTDR,sum(AMTCR) as AMTCR,sum(case when '" + pDC + "'=DC then AMTBLC else (-AMTBLC) end) as AMTBLC,sum(AMTLASTDR) as AMTLASTDR,sum(AMTLASTCR) as AMTLASTCR,sum(case when '" + pDC + "'=DC then AMTLASTBLC else (-AMTLASTBLC) end) as AMTLASTBLC,sum(FCYYEARDR) as FCYYEARDR,sum(FCYYEARCR) as FCYYEARCR,sum(case when '" + pDC + "'=DC then FCYYEARBLC else (-FCYYEARBLC) end) as FCYYEARBLC,sum(FCYDR) as FCYDR,sum(FCYCR) as FCYCR,sum(case when '" + pDC + "'=DC then FCYBLC else (-FCYBLC) end) as FCYBLC,sum(FCYLASTDR) as FCYLASTDR,sum(FCYLASTCR) as FCYLASTCR,sum(case when '" + pDC + "'=DC then FCYLASTBLC else (-FCYLASTBLC) end) as FCYLASTBLC,sum(QTYYEARDR) as QTYYEARDR,sum(QTYYEARCR) as QTYYEARCR,sum(case when '" + pDC + "'=DC then QTYYEARBLC else (-QTYYEARBLC) end) as QTYYEARBLC,sum(QTYDR) as QTYDR,sum(QTYCR) as QTYCR,sum(case when '" + pDC + "'=DC then QTYBLC else (-QTYBLC) end) as QTYBLC,sum(QTYLASTDR) as QTYLASTDR,sum(QTYLASTCR) as QTYLASTCR,sum(case when '" + pDC + "'=DC then QTYLASTBLC else (-QTYLASTBLC) end) as QTYLASTBLC,sum(PFADR) as PFADR,sum(PFACR) as PFACR from (select * from [VW_cw_genleg_accitems_gl] where IsInitialEntry=1 and [STARTGID]='" + strCwSTARTGID + "' and CURRENCY='" + CURRENCY + "' and LINKGID in(select gid from cw_accitems_gl where PACCGID='" + PACCGID.Trim() + "' and [STARTGID]='" + strCwSTARTGID + "')) as a";
DataSet dsLS = T_ALL_DA.GetAllSQL(sSQL);
if (dsLS != null)
{
if (dsLS.Tables[0].Rows.Count > 0)
{
#region 默认值
headRow.YEAR = DateTime.Parse(strCwACCDATE + "-01").Year.ToString();//年
headRow.MONTH = DateTime.Parse(strCwACCDATE + "-01").Month.ToString();//月
if (DateTime.Parse(strCwACCDATE + "-01").Month.ToString().Length == 1)
{
headRow.MONTH = "0" + DateTime.Parse(strCwACCDATE + "-01").Month.ToString();//月
}
headRow.ACCDATE = headRow.YEAR.ToString() + "-" + headRow.MONTH.ToString();//月
headRow.LINKGID = PACCGID.Trim();//科目GID
headRow.DEPTACC = "";//核算部门
headRow.EMPLACC = "";//核算人员
headRow.CORPACC = "";//核算客户
headRow.ITEMACC = "";//核算项目
headRow.CURRENCY = CURRENCY;//币别
headRow.AMTYEARDR = Decimal.Parse(dsLS.Tables[0].Rows[0]["AMTYEARDR"].ToString().Trim());//RMB期初借方
headRow.AMTYEARCR = Decimal.Parse(dsLS.Tables[0].Rows[0]["AMTYEARCR"].ToString().Trim());//RMB期初贷方
headRow.AMTYEARBLC = Decimal.Parse(dsLS.Tables[0].Rows[0]["AMTYEARBLC"].ToString().Trim());//RMB期初余额
headRow.AMTDR = Decimal.Parse(dsLS.Tables[0].Rows[0]["AMTDR"].ToString().Trim());//RMB本月借方
headRow.AMTCR = Decimal.Parse(dsLS.Tables[0].Rows[0]["AMTCR"].ToString().Trim());//RMB本月贷方
headRow.AMTBLC = Decimal.Parse(dsLS.Tables[0].Rows[0]["AMTBLC"].ToString().Trim());//RMB本月余额
headRow.AMTLASTDR = Decimal.Parse(dsLS.Tables[0].Rows[0]["AMTLASTDR"].ToString().Trim());//RMB累计借方
headRow.AMTLASTCR = Decimal.Parse(dsLS.Tables[0].Rows[0]["AMTLASTCR"].ToString().Trim());//RMB累计贷方
headRow.AMTLASTBLC = Decimal.Parse(dsLS.Tables[0].Rows[0]["AMTLASTBLC"].ToString().Trim());//RMB累计余额
headRow.FCYYEARDR = Decimal.Parse(dsLS.Tables[0].Rows[0]["FCYYEARDR"].ToString().Trim());//外币期初借方
headRow.FCYYEARCR = Decimal.Parse(dsLS.Tables[0].Rows[0]["FCYYEARCR"].ToString().Trim());//外币期初贷方
headRow.FCYYEARBLC = Decimal.Parse(dsLS.Tables[0].Rows[0]["FCYYEARBLC"].ToString().Trim());//外币期初余额
headRow.FCYDR = Decimal.Parse(dsLS.Tables[0].Rows[0]["FCYDR"].ToString().Trim());//外币本月借方
headRow.FCYCR = Decimal.Parse(dsLS.Tables[0].Rows[0]["FCYCR"].ToString().Trim());//外币本月贷方
headRow.FCYBLC = Decimal.Parse(dsLS.Tables[0].Rows[0]["FCYBLC"].ToString().Trim());//外币本月余额
headRow.FCYLASTDR = Decimal.Parse(dsLS.Tables[0].Rows[0]["FCYLASTDR"].ToString().Trim());//外币累计借方
headRow.FCYLASTCR = Decimal.Parse(dsLS.Tables[0].Rows[0]["FCYLASTCR"].ToString().Trim());//外币累计贷方
headRow.FCYLASTBLC = Decimal.Parse(dsLS.Tables[0].Rows[0]["FCYLASTBLC"].ToString().Trim());//外币累计余额
headRow.QTYYEARDR = Decimal.Parse(dsLS.Tables[0].Rows[0]["QTYYEARDR"].ToString().Trim());//期初借方
headRow.QTYYEARCR = Decimal.Parse(dsLS.Tables[0].Rows[0]["QTYYEARCR"].ToString().Trim());//期初贷方
headRow.QTYYEARBLC = Decimal.Parse(dsLS.Tables[0].Rows[0]["QTYYEARBLC"].ToString().Trim());//期初余额
headRow.QTYDR = Decimal.Parse(dsLS.Tables[0].Rows[0]["QTYDR"].ToString().Trim());//本月借方
headRow.QTYCR = Decimal.Parse(dsLS.Tables[0].Rows[0]["QTYCR"].ToString().Trim());//本月贷方
headRow.QTYBLC = Decimal.Parse(dsLS.Tables[0].Rows[0]["QTYBLC"].ToString().Trim());//本月余额
headRow.QTYLASTDR = Decimal.Parse(dsLS.Tables[0].Rows[0]["QTYLASTDR"].ToString().Trim());//累计借方
headRow.QTYLASTCR = Decimal.Parse(dsLS.Tables[0].Rows[0]["QTYLASTCR"].ToString().Trim());//累计贷方
headRow.QTYLASTBLC = Decimal.Parse(dsLS.Tables[0].Rows[0]["QTYLASTBLC"].ToString().Trim());//累计余额
headRow.PFADR = Decimal.Parse(dsLS.Tables[0].Rows[0]["PFADR"].ToString().Trim());//损益类科目本年累计数借方
headRow.PFACR = Decimal.Parse(dsLS.Tables[0].Rows[0]["PFACR"].ToString().Trim());//损益类科目本年累计数贷方
headRow.CORPID = strCOMPANYID;//分公司代码
headRow.ISDELETE = false;//是否删除
headRow.DELETEUSER = strUSERID;//删除人
headRow.DELETETIME = DateTime.Now;//删除时间
headRow.CREATEUSER = strUSERID;//创建人gid
headRow.CREATETIME = DateTime.Now;//创建时间
headRow.MODIFIEDUSER = strUSERID;//更改操作人gid
headRow.MODIFIEDTIME = DateTime.Now;//更改操作时间
headRow.STARTGID = strCwSTARTGID;
headRow.IsInitialEntry = true;
#endregion
headRow.GID = PACCGID_gid.Trim();//唯一编码
headRow.DbOperationType = DbOperationType.DbotUpd;
headRow.ModelUIStatus = "E";
}
}
}
//
if (isPost)
{
if (headRow != null)
{
var modb = new ModelObjectDB();
DBResult result = modb.Save(headRow);
}
}
//
if (ds.Tables[0].Rows[i]["PACCGID"].ToString().Trim() == "0" || ds.Tables[0].Rows[i]["PACCGID"].ToString().Trim() == "ZC" || ds.Tables[0].Rows[i]["PACCGID"].ToString().Trim() == "FZ" || ds.Tables[0].Rows[i]["PACCGID"].ToString().Trim() == "GT" || ds.Tables[0].Rows[i]["PACCGID"].ToString().Trim() == "QY" || ds.Tables[0].Rows[i]["PACCGID"].ToString().Trim() == "CB" || ds.Tables[0].Rows[i]["PACCGID"].ToString().Trim() == "SY")
{
PACCGID = "";
}
else
{
PACCGID = ds.Tables[0].Rows[i]["PACCGID"].ToString().Trim();
}
break;
}
}
}
}
}
}
}
public static DBResult DeleteDetail(MsCwAccitemsGl headData, MsCwGenlegAccitems head, string strUSERID, string strCOMPANYID)
{
int isSaveRow = 0;
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUSERID);
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (headData.ISENABLE == true)
{
tran.Rollback();
result.Success = false;
result.Message = "错误,已经入账的项目不允许删除!";
return result;
}
var cmdDelete = db.GetSqlStringCommand("delete from cw_genleg_accitems where GID='" + head.GID + "' and ISENABLE=0");
db.ExecuteNonQuery(cmdDelete, tran);
//
string ls = "select top 1 isnull(CURRENCY,'RMB') as CURRENCY from cw_genleg_accitems WITH(NOLOCK) where [STARTGID]='" + strCwSTARTGID + "' and LINKGID in(select gid from cw_accitems_gl where PACCGID='" + headData.PACCGID.ToString().Trim() + "' and [STARTGID]='" + strCwSTARTGID + "')";
string CURRENCY = T_ALL_DA.GetStrSQL("CURRENCY", ls);
if (CURRENCY.Trim() == "")
{
cmdDelete = db.GetSqlStringCommand("delete from cw_genleg_accitems where [STARTGID]='" + strCwSTARTGID + "' and LINKGID='" + headData.PACCGID.ToString().Trim() + "' and ISENABLE=0");
db.ExecuteNonQuery(cmdDelete, tran);
CURRENCY = "RMB";
}
else
{
isSaveRow = 1;
}
tran.Commit();
//
if (isSaveRow == 1)
{
SaveRow(headData, strUSERID, strCOMPANYID, CURRENCY);
}
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "删除出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "操作成功";
return result;
}
#region 判断是否有未入账的数据
public static int GetISENABLE(string strUSERID)
{
string strCwACCDATE = BasicDataRefDAL.GetCwACCDATE(strUSERID);
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUSERID);
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
//string sSQL = "select count(*) as icount from cw_accitems_gl where [YEAR]=SUBSTRING('" + strACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and gid not in (select LINKGID from cw_genleg_accitems where [YEAR]=SUBSTRING('" + strACCDATE + "',1,4)";
//if (strCwSTARTGID.Trim() != "")
//{
// sSQL += " and STARTGID='" + strCwSTARTGID + "'";
//}
//sSQL += ")";
string sSQL = "select count(*) as icount from cw_genleg_accitems where [STARTGID]='" + strCwSTARTGID + "' and (ISENABLE=0 or ISENABLE is null) and [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4)";
int icount = int.Parse(T_ALL_DA.GetStrSQL("icount", sSQL));
if (icount == 0)
{
sSQL = "select count(*) as icount from cw_genleg_accitems where [STARTGID]='" + strCwSTARTGID + "' and [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4)";
int icount2 = int.Parse(T_ALL_DA.GetStrSQL("icount", sSQL));
if (icount2 == 0)
{
icount = -1;
}
}
return icount;
}
#endregion
public static DBResult setISENABLE(string ISENABLE, string strUSERID, string strCOMPANYID)
{
var result = new DBResult();
string strCwACCDATE = BasicDataRefDAL.GetCwACCDATE(strUSERID);
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUSERID);
string strCwSTARTMONTH = BasicDataRefDAL.GetCwSTARTMONTH(strUSERID);
int icount = GetISENABLE(strUSERID);
if (icount == 0)
{
result.Success = false;
result.Message = "数据已入账,不予以操作!";
return result;
}
//
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdDelete = db.GetSqlStringCommand("update cw_accitems_gl set ISENABLE=" + ISENABLE + " where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and ISENABLE=0");
db.ExecuteNonQuery(cmdDelete, tran);
if (ISENABLE.Trim() == "1")
{
string sSQL = "insert into cw_genleg_accitems(GID,YEAR,MONTH,LINKGID,DEPTACC,EMPLACC,CORPACC,ITEMACC,CURRENCY,AMTYEARDR,AMTYEARCR,AMTYEARBLC,AMTDR,AMTCR,AMTBLC,AMTLASTDR,AMTLASTCR,AMTLASTBLC,FCYYEARDR,FCYYEARCR,FCYYEARBLC,FCYDR,FCYCR,FCYBLC,FCYLASTDR,FCYLASTCR,FCYLASTBLC,QTYYEARDR,QTYYEARCR,QTYYEARBLC,QTYDR,QTYCR,QTYBLC,QTYLASTDR,QTYLASTCR,QTYLASTBLC,CORPID,ISDELETE,DELETEUSER,DELETETIME,CREATEUSER,CREATETIME,MODIFIEDUSER,MODIFIEDTIME,ISENABLE,STARTGID,ACCDATE,IsInitialEntry) "
+ "(select newid() as GID, SUBSTRING('" + strCwACCDATE + "',1,4) as [YEAR],SUBSTRING('" + strCwACCDATE + "',6,2) as [MONTH],GID as LINKGID,'' as DEPTACC,'' as EMPLACC,'' as CORPACC,'' as ITEMACC,'RMB' as CURRENCY,0 as AMTYEARDR,0 as AMTYEARCR,0 as AMTYEARBLC,0 as AMTDR,0 as AMTCR,0 as AMTBLC,0 as AMTLASTDR,0 as AMTLASTCR,0 as AMTLASTBLC,0 as FCYYEARDR,0 as FCYYEARCR,0 as FCYYEARBLC,0 as FCYDR,0 as FCYCR,0 as FCYBLC,0 as FCYLASTDR,0 as FCYLASTCR,0 as FCYLASTBLC,0 as QTYYEARDR,0 as QTYYEARCR,0 as QTYYEARBLC,0 as QTYDR,0 as QTYCR,0 as QTYBLC,0 as QTYLASTDR,0 as QTYLASTCR,0 as QTYLASTBLC,'" + strCOMPANYID + "' as CORPID,0 as ISDELETE,'" + strUSERID + "' as DELETEUSER,getdate() as DELETETIME,'" + strUSERID + "' as CREATEUSER,getdate() as CREATETIME,'" + strUSERID + "' as MODIFIEDUSER,getdate() as MODIFIEDTIME,1 as ISENABLE,'" + strCwSTARTGID + "','" + strCwACCDATE + "',0 from cw_accitems_gl where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and [STARTGID]='" + strCwSTARTGID + "' and gid not in (select LINKGID from cw_genleg_accitems where [STARTGID]='" + strCwSTARTGID + "'";
if (strCwSTARTMONTH.Substring(0, 4) == strCwACCDATE.Substring(0, 4))
{
sSQL += " and ACCDATE='" + strCwSTARTMONTH + "'";
}
else
{
sSQL += " and ACCDATE=(SUBSTRING('" + strCwACCDATE + "',1,4)+'-01')";
}
sSQL += " ))";
cmdDelete = db.GetSqlStringCommand(sSQL);
db.ExecuteNonQuery(cmdDelete, tran);
cmdDelete = db.GetSqlStringCommand("update [cw_genleg_accitems] set [STARTGID]='" + strCwSTARTGID + "' where [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and (STARTGID='' or STARTGID is null)");
db.ExecuteNonQuery(cmdDelete, tran);
}
cmdDelete = db.GetSqlStringCommand("update cw_genleg_accitems set ISENABLE=" + ISENABLE + ",CORPID='" + strCOMPANYID + "',MODIFIEDUSER='" + strUSERID + "',MODIFIEDTIME=GETDATE() where [STARTGID]='" + strCwSTARTGID + "' and [YEAR]=SUBSTRING('" + strCwACCDATE + "',1,4) and ISENABLE=0");
db.ExecuteNonQuery(cmdDelete, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "“入账”出现错误,请重试!";
return result;
}
}
result.Success = true;
result.Message = "操作完成";
return result;
}
#region 设置启用、取消账套
public static DBResult setSTARTMONTH(string isSTART, string STARTMONTH, string strUSERID, string strCOMPANYID)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
if (isSTART.Trim() == "1")//启用账套
{
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string ls = "select count(*) as iSTART from cw_design_startusing where STARTMONTH='" + STARTMONTH.Trim() + "' and (ISDELETE=0 or ISDELETE is null) and ISENABLE=1";// and CORPID='"+strCOMPANYID+"' and ISLOGIN=1
int iSTART = int.Parse(T_ALL_DA.GetStrSQL("iSTART", ls));
if (iSTART > 0)
{
tran.Rollback();
result.Success = false;
result.Message = "账套已经启用!";
return result;
}
//
string strGID = Guid.NewGuid().ToString().Trim();
var cmdDelete = db.GetSqlStringCommand("INSERT INTO [cw_design_startusing]([GID],[STARTNAME],[STARTMONTH],[CORPID],[ISDELETE],[DELETEUSER],[DELETETIME],[CREATEUSER],[CREATETIME],[MODIFIEDUSER],[MODIFIEDTIME],[ISENABLE]) VALUES('" + strGID + "','账套" + STARTMONTH + "','" + STARTMONTH + "','" + strCOMPANYID + "',0,'" + strUSERID + "',GETDATE(),'" + strUSERID + "',GETDATE(),'" + strUSERID + "',GETDATE(),1)");
db.ExecuteNonQuery(cmdDelete, tran);
cmdDelete = db.GetSqlStringCommand("update [cw_genleg_accitems] set STARTGID='" + strGID + "' where [YEAR]=SUBSTRING('" + STARTMONTH + "',1,4) and (STARTGID='' or STARTGID is null)");
db.ExecuteNonQuery(cmdDelete, tran);
}
else//取消账套
{
//判断总账表中是否已经使用当前账套
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string ls = "select count(*) as iSTART from cw_genleg_accitems WITH(NOLOCK) where STARTGID in (select gid from cw_design_startusing where STARTMONTH='" + STARTMONTH.Trim() + "' (ISDELETE=0 or ISDELETE is null) and ISENABLE=1)";// and CORPID='"+strCOMPANYID+"' and ISLOGIN=1
int iSTART = int.Parse(T_ALL_DA.GetStrSQL("iSTART", ls));
if (iSTART > 0)
{
tran.Rollback();
result.Success = false;
result.Message = "账套已经被使用,不允许更改!";
return result;
}
else
{
var cmdDelete = db.GetSqlStringCommand("delete from [cw_design_startusing] where STARTMONTH='" + STARTMONTH + "' and (ISDELETE=0 or ISDELETE is null) and ISENABLE=1");// and CORPID='" + strCOMPANYID + "' and ISLOGIN=1
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 获取当前启用的账套
public static string GetSTARTMONTH(string STARTGID, string strCompanyID, string strUSERID)
{
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string sSQL = "select top 1 STARTMONTH 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 + "') order by STARTMONTH desc";
string sSTARTMONTH = T_ALL_DA.GetStrSQL("STARTMONTH", sSQL);
if (sSTARTMONTH.Trim() == "")
{
//return "请先设置帐套信息!";
return "-1";
}
return sSTARTMONTH.Trim();
}
#endregion
#endregion
#region 查询期初项目录入列表
static public List<MsCwGenlegAccitems> GetDataEdit(string strCondition, string companyid, string strUSERID)
{
string strCwSTARTGID = BasicDataRefDAL.GetCwSTARTGID(strUSERID);
var strSql = new StringBuilder();
strSql.Append("SELECT *,LINKNAME=(select top 1 ACCNAME from [cw_accitems_gl] where gid=cw_genleg_accitems.LINKGID),MODIFIEDUSERNAME=(select top 1 SHOWNAME from [user] where gid=cw_genleg_accitems.MODIFIEDUSER),DR=isnull((case when CURRENCY='RMB' then AMTYEARDR else FCYYEARDR end),0),CR=isnull((case when CURRENCY='RMB' then AMTYEARCR else FCYYEARCR end),0),PFADR=isnull(PFADR,0),CR=isnull(PFACR,0)");
strSql.Append(" from cw_genleg_accitems where [STARTGID]='" + strCwSTARTGID + "' and ISDELETE=0");// and CORPID='" + companyid + "'
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" and " + strCondition);
}
strSql.Append(" order by [YEAR] desc,CREATETIME");
return SetData(strSql);
}
#endregion
}
}