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/MvcShipping/DAL/RptOpReceipt/RptOpReceiptDAL.cs

224 lines
12 KiB
C#

3 years ago
using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using DSWeb.MvcShipping.Models.RptOpReceiptEntity;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.Areas.CommMng.Models;
using DSWeb.EntityDA;
using HcUtility.Comm;
using System.Data.SqlClient;
using HcUtility.Core;
using DSWeb.DataAccess;
using DSWeb.Models;
using DSWeb.MvcShipping.Helper;
using DSWeb.Areas.CommMng.DAL;
namespace DSWeb.MvcShipping.DAL.RptOpReceiptDAL
{
public class RptOpReceiptDAL
{
#region 查询
static public List<RptOpReceiptEntity> GetDataList(string strCondition, string strUserID, string strCompanyID, string usercode, string orgcode, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("select * from VW_OP_RECEIPT_SEA");
if (strCondition.Trim() != String.Empty)
{
strSql.Append(" where " + strCondition);
}
//
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else {
strSql.Append(" order by MBLNO,CREATETIME desc");//BSNO,
}
return SetData(strSql);
}
private static List<RptOpReceiptEntity> SetData(StringBuilder strSql)
{
var headList = new List<RptOpReceiptEntity>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
RptOpReceiptEntity data = new RptOpReceiptEntity();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.TRANCNO = Convert.ToString(reader["TRANCNO"]);
data.ISREPEAT = Convert.ToString(reader["ISREPEAT"]);
data.REPEAT_MAN = Convert.ToString(reader["REPEAT_MAN"]);
data.REPEAT_DATE = Convert.ToString(reader["REPEAT_DATE"]);
data.ISRECEIVE = Convert.ToString(reader["ISRECEIVE"]);
data.RETURN_MAN = Convert.ToString(reader["RETURN_MAN"]);
data.RETURN_DATE = Convert.ToString(reader["RETURN_DATE"]);
data.RETURN_TRANCER = Convert.ToString(reader["RETURN_TRANCER"]);
data.RETURN_TRANCNO = Convert.ToString(reader["RETURN_TRANCNO"]);
data.REMARK = Convert.ToString(reader["REMARK"]);
data.BSNO = Convert.ToString(reader["BSNO"]);
data.CORPID_NAME = Convert.ToString(reader["CORPID_NAME"]);
data.CORPID = Convert.ToString(reader["CORPID"]);
data.CREATEUSER_NAME = Convert.ToString(reader["CREATEUSER_NAME"]);
data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]);
data.CREATETIME = Convert.ToString(reader["CREATETIME"]);
data.MODIFIEDUSER_NAME = Convert.ToString(reader["MODIFIEDUSER_NAME"]);
data.MODIFIEDUSER = Convert.ToString(reader["MODIFIEDUSER"]);
data.MODIFIEDTIME = Convert.ToString(reader["MODIFIEDTIME"]);
data.OPLB = Convert.ToString(reader["OPLB"]);
data.OPLBNAME = Convert.ToString(reader["OPLBNAME"]);
data.RECEIPTNO = Convert.ToString(reader["RECEIPTNO"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
data.CUSTNO = Convert.ToString(reader["CUSTNO"]);
data.MBLNO = Convert.ToString(reader["MBLNO"]);
data.HBLNO = Convert.ToString(reader["HBLNO"]);
data.ETD = Convert.ToString(reader["ETD"]);
data.VESSEL = Convert.ToString(reader["VESSEL"]);
data.VOYNO = Convert.ToString(reader["VOYNO"]);
data.INPUTBY = Convert.ToString(reader["INPUTBY"]);
data.BSSTATUS = Convert.ToString(reader["BSSTATUS"]);
data.SALE = Convert.ToString(reader["SALE"]);
data.RECEIPTTYPE = Convert.ToString(reader["RECEIPTTYPE"]);
data.OP = Convert.ToString(reader["OP"]);
data.DOC = Convert.ToString(reader["DOC"]);
data.CUSTSERVICE = Convert.ToString(reader["CUSTSERVICE"]);
data.PORTLOAD = Convert.ToString(reader["PORTLOAD"]);
data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]);
data.CUSTOMNO = Convert.ToString(reader["CUSTOMNO"]);
data.CUSTOMNO2 = Convert.ToString(reader["CUSTOMNO2"]);
data.ACCDATE = Convert.ToString(reader["ACCDATE"]);
data.RECEIVE_MAN = Convert.ToString(reader["RECEIVE_MAN"]);
data.RECEIVE_DATE = Convert.ToString(reader["RECEIVE_DATE"]);
data.SEND_MAN = Convert.ToString(reader["SEND_MAN"]);
data.SEND_DATE = Convert.ToString(reader["SEND_DATE"]);
data.TRANCER = Convert.ToString(reader["TRANCER"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 删除
public static DBResult Delete_Main(string gids, string strUserID, string strCompanyID)
{
DBResult result = new DBResult();
if (gids.Trim() == "")
{
result.Success = false;
result.Message = "没有输入任何需要修改的数据";
}
gids = "'" + gids.Trim().Replace(",","','") + "'";
//
Database db = DatabaseFactory.CreateDatabase();
using (SqlTransaction sqlTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
try
{
#region 判断【ch_fee】中的费用状态是否允许删除
//string sbool = "0";
//T_ALL_DA T_ALL_DA = new T_ALL_DA();
//string ls = "select count(gid) nums from ch_fee where WMSOUTBSNO='" + gid + "' and (ISINVOICE=1 or AUDITSTATUS=1 or ORDERINVOICE<>0.00 or DEBITNO is not null or FEESTATUS<>1)";
//sbool = T_ALL_DA.GetStrSQL("nums", ls);
//if (sbool.Trim() == "0")
//{
// ls = "select count(gid) nums from ch_fee_do where feeid in (select gid from ch_fee where WMSOUTBSNO='" + gid + "')";
// sbool = T_ALL_DA.GetStrSQL("nums", ls);
// if (sbool.Trim() != "0")
// {
// sqlTran.Rollback();
// result.Success = false;
// result.Message = "有“已申请开票、已开发票或已对帐”的费用,不允许删除,请重新操作!";
// return result;
// }
//}
//else
//{
// sqlTran.Rollback();
// result.Success = false;
// result.Message = "有“已申请开票、已开发票、已对帐”的费用,不允许删除,请重新操作!";
// return result;
//}
#endregion
#region 判断是否有下一个阶段汇总的数据
string strError = "";
int iNum = 0;
string strSql = "select *,STARTBILLINGDATE_MAIN=(select top 1 STARTBILLINGDATE from wms_settlement_list where gid=wms_settlement_detail.DUIGID),ENDBILLINGDATE_MAIN=(select top 1 ENDBILLINGDATE from wms_settlement_list where gid=wms_settlement_detail.DUIGID) from wms_settlement_detail where ISDELETE=0 and DUIGID in (" + gids + ")";
DataSet ds = SqlHelper.ExecuteQueryDataset(sqlTran, CommandType.Text, strSql, null);
if (ds != null)
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
strSql = "select count(*) from wms_settlement_detail where BLNO='" + dr["BLNO"].ToString().Trim() + "' and DUIGID in (select gid from wms_settlement_list where STARTBILLINGDATE>'" + dr["ENDBILLINGDATE_MAIN"].ToString().Trim() + "')";
object statusObj = SqlHelper.ExecuteScalar(sqlTran, CommandType.Text, strSql, null);
if (statusObj != null)
{
iNum = int.Parse(statusObj.ToString().Trim());
}
if (iNum > 0)
{
strError += "、" + dr["BLNO"].ToString().Trim();
}
}
}
if (strError.Trim() != "")
{
strError = strError.Trim().Substring(1);
result.Success = false;
result.Message = "提单号" + strError + "已经有下一个阶段汇总的数据,因此不允许删除此账单!";
return result;
}
#endregion
#region 把【ch_fee】中WMSOUTBSNO与【仓储结算主表wms_settlement_list】GID关联的数据删除
strSql = "delete from ch_fee where WMSOUTBSNO in (" + gids + ")";
int existVal = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), null);
#endregion
#region 把【仓储结算关联表wms_settlement_date】中数据【ISDELETE】设为【1】
strSql = "update wms_settlement_date set ISDELETE=1,DELETEUSER='" + strUserID + "',DELETETIME=getdate() where DUIGID in (" + gids + ")";
existVal = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), null);
#endregion
#region 把【仓储结算明细表wms_settlement_detail】中数据【ISDELETE】设为【1】
strSql = "update wms_settlement_detail set ISDELETE=1,DELETEUSER='" + strUserID + "',DELETETIME=getdate() where DUIGID in (" + gids + ")";
existVal = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), null);
#endregion
#region 把【仓储结算主表wms_settlement_list】中数据【ISDELETE】设为【1】
strSql = "update wms_settlement_list set ISDELETE=1,DELETEUSER='" + strUserID + "',DELETETIME=getdate() where gid in (" + gids + ")";
existVal = SqlHelper.ExecuteNonQuery(sqlTran, CommandType.Text, strSql.ToString(), null);
#endregion
sqlTran.Commit();
}
catch (Exception)
{
sqlTran.Rollback();
result.Success = false;
result.Message = "删除出现错误,请重试或联系系统管理员";
return result;
}
finally
{
SqlHelper.CloseConnection();
sqlTran.Dispose();
}
}
result.Success = true;
result.Message = "删除数据成功";
return result;
}
#endregion
//
}
}