|
|
|
|
using System;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using DSWeb.MvcShipping.Models.MsCwItem;
|
|
|
|
|
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.MsCwItemDAL
|
|
|
|
|
{
|
|
|
|
|
public class MsCwItemDAL
|
|
|
|
|
{
|
|
|
|
|
#region 查询
|
|
|
|
|
static public List<MsCwItem> 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=cw_item.MODIFIEDUSER) from cw_item where [STARTGID]='" + strCwSTARTGID + "' and (ISDELETE=0 or ISDELETE is null)");// 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 CREATETIME");
|
|
|
|
|
}
|
|
|
|
|
return SetData(strSql);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static public MsCwItem 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=cw_item.MODIFIEDUSER) from cw_item 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 MsCwItem();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static List<MsCwItem> SetData(StringBuilder strSql)
|
|
|
|
|
{
|
|
|
|
|
var headList = new List<MsCwItem>();
|
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
|
|
|
{
|
|
|
|
|
while (reader.Read())
|
|
|
|
|
{
|
|
|
|
|
MsCwItem data = new MsCwItem();
|
|
|
|
|
#region Set DB data to Object
|
|
|
|
|
data.GID = (reader["GID"] == null ? "" : Convert.ToString(reader["GID"]));//唯一编码
|
|
|
|
|
data.ITEMCODE = (reader["ITEMCODE"] == null ? "" : Convert.ToString(reader["ITEMCODE"]));//年
|
|
|
|
|
data.ITEMNAME = (reader["ITEMNAME"] == null ? "" : Convert.ToString(reader["ITEMNAME"]));//月
|
|
|
|
|
data.FINANCESOFTCODE = (reader["FINANCESOFTCODE"] == null ? "" : Convert.ToString(reader["FINANCESOFTCODE"]));//财务软件代码
|
|
|
|
|
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.MODIFIEDUSERNAME = (reader["MODIFIEDUSERNAME"] == null ? "" : Convert.ToString(reader["MODIFIEDUSERNAME"]));//更改人
|
|
|
|
|
data.STARTGID = (reader["STARTGID"] == null ? "" : Convert.ToString(reader["STARTGID"]));
|
|
|
|
|
#endregion
|
|
|
|
|
headList.Add(data);
|
|
|
|
|
}
|
|
|
|
|
reader.Close();
|
|
|
|
|
}
|
|
|
|
|
return headList;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 删除
|
|
|
|
|
public static DBResult Delete(MsCwItem 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 cw_item set ISDELETE=1,DELETEUSER='" + strUSERID.Trim() + "',DELETETIME=getdate() where GID='" + head.GID.ToString().Trim() + "'");
|
|
|
|
|
|
|
|
|
|
var cmdDelete = db.GetSqlStringCommand("DELETE from cw_item 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;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|