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/MsCurrencyExchange/MsCurrencyExchangeDAL.cs

658 lines
32 KiB
C#

2 years ago
using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.MvcShipping.Models.CurrencyExchange;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.Areas.CommMng.Models;
using HcUtility.Comm;
using DSWeb.MvcShipping.DAL.MsSysParamSet;
namespace DSWeb.MvcShipping.DAL.MsCurrencyExchange
{
public class MsCurrencyExchangeDAL
{
#region Inquery DataList
static public List<CurrencyExchange> GetDataList(string strCondition, string companyid, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT GID,CURRENCYID,VALUE,[TYPE],CRVALUE,CUSTOMVALUE,[STARTTIME],[ENDTIME],[CREATEUSER]");
strSql.Append(",[CREATETIME],[MODIFIEDUSER],[MODIFIEDTIME],[COMPANYID],LOCALCURR");
strSql.Append(",(select ShowName from [user] where GID=currency_exchange.CREATEUSER) as CREATEUSERREF");
strSql.Append(",(select CODENAME from [code_currency] where GID=currency_exchange.CURRENCYID) as CURRENCY,REMARK");
strSql.Append(" from currency_exchange where COMPANYID='" + 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 CURRENCYID,STARTTIME");
}
return SetData(strSql);
}
static public CurrencyExchange GetData(string condition, string companyid)
{
CurrencyExchange data = null;
var list = GetDataList(condition,companyid);
if (list.Count > 0)
data = list[0];
if (data == null)
{
data = new CurrencyExchange();
}
return data;
}
private static List<CurrencyExchange> SetData(StringBuilder strSql)
{
var headList = new List<CurrencyExchange>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CurrencyExchange data = new CurrencyExchange();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.CURRENCYID = Convert.ToString(reader["CURRENCYID"]);
data.CURRENCY = Convert.ToString(reader["CURRENCY"]);
if (reader["VALUE"] != DBNull.Value)
data.VALUE = Convert.ToString(reader["VALUE"]);
if (reader["CRVALUE"] != DBNull.Value)
data.CRVALUE = Convert.ToString(reader["CRVALUE"]);
if (reader["CUSTOMVALUE"] != DBNull.Value)
data.CUSTOMVALUE = Convert.ToString(reader["CUSTOMVALUE"]);//海关汇率
data.TYPE = Convert.ToString(reader["TYPE"]);
if (reader["STARTTIME"] != DBNull.Value)
data.STARTTIME = Convert.ToDateTime(reader["STARTTIME"]).ToString("yyyy-MM-dd");
if (reader["ENDTIME"] != DBNull.Value)
data.ENDTIME = Convert.ToDateTime(reader["ENDTIME"]).ToString("yyyy-MM-dd");
data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]);
data.CREATEUSERREF = Convert.ToString(reader["CREATEUSERREF"]);
if (reader["CREATETIME"] != DBNull.Value)
data.CREATETIME = Convert.ToDateTime(reader["CREATETIME"]).ToString("yyyy-MM-dd HH:mm:ss");
data.COMPANYID = Convert.ToString(reader["COMPANYID"]);
data.LOCALCURR = Convert.ToString(reader["LOCALCURR"]);
data.Remark = Convert.ToString(reader["REMARK"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
public static DBResult SaveDetail(List<CurrencyExchange> bodyList, string companyid,string userid,string LOCALCURR)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdInsert =
db.GetSqlStringCommand(
@"insert into currency_exchange (GID,CURRENCYID,VALUE,CRVALUE,CUSTOMVALUE,TYPE,STARTTIME,ENDTIME,COMPANYID,CREATEUSER,CREATETIME,LOCALCURR,REMARK)
values (@GID,@CURRENCYID,@VALUE,@CRVALUE,@CUSTOMVALUE,@TYPE,@STARTTIME,@ENDTIME,@COMPANYID,@CREATEUSER,@CREATETIME,@LOCALCURR,@REMARK) ");
var cmdUpdate =
db.GetSqlStringCommand(
@"update currency_exchange set CURRENCYID=@CURRENCYID,VALUE=@VALUE,CRVALUE=@CRVALUE,CUSTOMVALUE=@CUSTOMVALUE,TYPE=@TYPE,STARTTIME=@STARTTIME,ENDTIME=@ENDTIME,MODIFIEDUSER=@MODIFIEDUSER,MODIFIEDTIME=@MODIFIEDTIME,LOCALCURR=@LOCALCURR,REMARK=@REMARK where GID=@GID ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
if (enumValue.STARTTIME == "") enumValue.STARTTIME = null;
else
{
enumValue.STARTTIME = Convert.ToDateTime(enumValue.STARTTIME.Replace("GMT+0800 (中国标准时间)", "")).ToString("yyyy-MM-dd");
}
if (enumValue.ENDTIME == "") enumValue.ENDTIME = null;
else
{
enumValue.ENDTIME = Convert.ToDateTime(enumValue.ENDTIME.Replace("GMT+0800 (中国标准时间)", "")).ToString("yyyy-MM-dd");
}
if (enumValue.GID == "*" || enumValue.GID == "")
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@CURRENCYID", DbType.String, enumValue.CURRENCYID);
db.AddInParameter(cmdInsert, "@VALUE", DbType.String, enumValue.VALUE);
db.AddInParameter(cmdInsert, "@CRVALUE", DbType.String, enumValue.CRVALUE);
db.AddInParameter(cmdInsert, "@CUSTOMVALUE", DbType.String, enumValue.CUSTOMVALUE);
db.AddInParameter(cmdInsert, "@TYPE", DbType.String, enumValue.TYPE);
db.AddInParameter(cmdInsert, "@STARTTIME", DbType.String, enumValue.STARTTIME);
db.AddInParameter(cmdInsert, "@ENDTIME", DbType.String, enumValue.ENDTIME);
db.AddInParameter(cmdInsert, "@CREATETIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdInsert, "@CREATEUSER", DbType.String, userid);
db.AddInParameter(cmdInsert, "@COMPANYID", DbType.String, companyid);
db.AddInParameter(cmdInsert, "@LOCALCURR", DbType.String, LOCALCURR);
db.AddInParameter(cmdInsert, "@REMARK", DbType.String, enumValue.Remark);
db.ExecuteNonQuery(cmdInsert, tran);
}
else
{
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@CURRENCYID", DbType.String, enumValue.CURRENCYID);
db.AddInParameter(cmdUpdate, "@VALUE", DbType.String, enumValue.VALUE);
db.AddInParameter(cmdUpdate, "@CRVALUE", DbType.String, enumValue.CRVALUE);
db.AddInParameter(cmdUpdate, "@CUSTOMVALUE", DbType.String, enumValue.CUSTOMVALUE);
db.AddInParameter(cmdUpdate, "@TYPE", DbType.String, enumValue.TYPE);
db.AddInParameter(cmdUpdate, "@STARTTIME", DbType.String, enumValue.STARTTIME);
db.AddInParameter(cmdUpdate, "@ENDTIME", DbType.String, enumValue.ENDTIME);
db.AddInParameter(cmdUpdate, "@MODIFIEDTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdUpdate, "@MODIFIEDUSER", DbType.String, userid);
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID);
db.AddInParameter(cmdUpdate, "@LOCALCURR", DbType.String, LOCALCURR);
db.AddInParameter(cmdUpdate, "@REMARK", DbType.String, enumValue.Remark);
db.ExecuteNonQuery(cmdUpdate, tran);
}
}
}
tran.Commit();
}
catch (Exception e)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误<"+e.Message+">,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
public static DBResult UpBsExchange(CurrencyExchange bodyList, string type,string userid,string companyid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var sqlstr = " CORPID='" + companyid + "' ";
var EXCHANGENOTCOMPANY = MsSysParamSetDAL.GetData("PARAMNAME='EXCHANGENOTCOMPANY'");
if (EXCHANGENOTCOMPANY.PARAMVALUE == "1")
{
sqlstr = " 1=1 ";
}
var UPDATEEXRATEISNOTLOCK = MsSysParamSetDAL.GetData("PARAMNAME='UPDATEEXRATEISNOTLOCK'");
if (UPDATEEXRATEISNOTLOCK.PARAMVALUE == "1")
{
}
else {
sqlstr = sqlstr+ " and FEESTATUS=0 ";
}
var feestr = " 1=1 ";
if (type == "业务日期")
{
var startstr = Convert.ToDateTime(bodyList.STARTTIME.Replace("GMT+0800 (中国标准时间)", "")).ToString("yyyy-MM-dd");
var endstr = Convert.ToDateTime(bodyList.ENDTIME.Replace("GMT+0800 (中国标准时间)", "")).ToString("yyyy-MM-dd");
sqlstr =sqlstr+ " AND ETD>='" + startstr + "' AND ETD<='" + endstr + "'";
}
else if (type == "更改单建单日期")
{
var startstr = Convert.ToDateTime(bodyList.STARTTIME.Replace("GMT+0800 (中国标准时间)", "")).ToString("yyyy-MM-dd");
var endstr = Convert.ToDateTime(bodyList.ENDTIME.Replace("GMT+0800 (中国标准时间)", "")).ToString("yyyy-MM-dd");
sqlstr =sqlstr+ " AND CREATETIME>='" + startstr + "' AND CREATETIME<='" + endstr + "'";
}
else if (type == "更改单业务日期")
{
var startstr = Convert.ToDateTime(bodyList.STARTTIME.Replace("GMT+0800 (中国标准时间)", "")).ToString("yyyy-MM-dd");
var endstr = Convert.ToDateTime(bodyList.ENDTIME.Replace("GMT+0800 (中国标准时间)", "")).ToString("yyyy-MM-dd");
sqlstr = sqlstr + " AND ETD>='" + startstr + "' AND ETD<='" + endstr + "'";
}
else if (type == "更改单会计期间按业务日期汇率更新")
{
var startstr = Convert.ToDateTime(bodyList.STARTTIME.Replace("GMT+0800 (中国标准时间)", "")).ToString("yyyy-MM");
var endstr = Convert.ToDateTime(bodyList.ENDTIME.Replace("GMT+0800 (中国标准时间)", "")).ToString("yyyy-MM");
sqlstr = sqlstr + " AND ACCDATE>='" + startstr + "' AND ACCDATE<='" + endstr + "'";
}
else if (type == "费用录入日期")
{
var startstr = Convert.ToDateTime(bodyList.STARTTIME.Replace("GMT+0800 (中国标准时间)", "")).ToString("yyyy-MM-dd");
var endstr = Convert.ToDateTime(bodyList.ENDTIME.Replace("GMT+0800 (中国标准时间)", "")).ToString("yyyy-MM-dd");
feestr = feestr + " AND ENTERDATE>='" + startstr + "' AND ENTERDATE<='" + endstr + " 23:59:59'";
}
else
{
var startstr = Convert.ToDateTime(bodyList.STARTTIME.Replace("GMT+0800 (中国标准时间)", "")).ToString("yyyy-MM");
var endstr = Convert.ToDateTime(bodyList.ENDTIME.Replace("GMT+0800 (中国标准时间)", "")).ToString("yyyy-MM");
sqlstr =sqlstr+ " AND ACCDATE>='" + startstr + "' AND ACCDATE<='" + endstr + "'";
}
var cmdUpdate =
db.GetSqlStringCommand(
@"update ch_fee set EXCHANGERATE=@EXCHANGERATE where CURRENCY=@CURRENCY and feetype=1 and BSNO IN (SELECT BSNO FROM V_OP_BILL WHERE 1=1 AND OPTYPE='普通货' and " + sqlstr + ")");
var cmdUpdateCr =
db.GetSqlStringCommand(
@"update ch_fee set EXCHANGERATE=@EXCHANGERATE where CURRENCY=@CURRENCY and feetype=2 and BSNO IN (SELECT BSNO FROM V_OP_BILL WHERE 1=1 AND OPTYPE='普通货' and " + sqlstr + ")");
if (type != "更改单会计期间按业务日期汇率更新")
{
if (type == "更改单")
{
cmdUpdate =
db.GetSqlStringCommand(
@"update ch_fee set EXCHANGERATE=@EXCHANGERATE where CURRENCY=@CURRENCY and feetype=1 and BSNO IN (SELECT BSNO FROM V_OP_BILL WHERE 1=1 AND OPTYPE='更改单' and " + sqlstr + ")");
cmdUpdateCr =
db.GetSqlStringCommand(
@"update ch_fee set EXCHANGERATE=@EXCHANGERATE where CURRENCY=@CURRENCY and feetype=2 and BSNO IN (SELECT BSNO FROM V_OP_BILL WHERE 1=1 AND OPTYPE='更改单' and " + sqlstr + ")");
}
else if (type == "更改单建单日期" || type == "更改单业务日期")
{
cmdUpdate =
db.GetSqlStringCommand(
@"update ch_fee set EXCHANGERATE=@EXCHANGERATE where CURRENCY=@CURRENCY and feetype=1 and BSNO IN (SELECT BSNO FROM V_OP_BILL WHERE 1=1 AND OPTYPE='更改单' and " + sqlstr + ")");
cmdUpdateCr =
db.GetSqlStringCommand(
@"update ch_fee set EXCHANGERATE=@EXCHANGERATE where CURRENCY=@CURRENCY and feetype=2 and BSNO IN (SELECT BSNO FROM V_OP_BILL WHERE 1=1 AND OPTYPE='更改单' and " + sqlstr + ")");
}
else if (type == "费用录入日期")
{
cmdUpdate =
db.GetSqlStringCommand(
@"update ch_fee set EXCHANGERATE=@EXCHANGERATE where CURRENCY=@CURRENCY and feetype=1 and "+ feestr + " and BSNO IN (SELECT BSNO FROM V_OP_BILL WHERE 1=1 and " + sqlstr + ")");
cmdUpdateCr =
db.GetSqlStringCommand(
@"update ch_fee set EXCHANGERATE=@EXCHANGERATE where CURRENCY=@CURRENCY and feetype=2 and "+ feestr + " and BSNO IN (SELECT BSNO FROM V_OP_BILL WHERE 1=1 and " + sqlstr + ")");
}
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@CURRENCY", DbType.String, bodyList.CURRENCY);
db.AddInParameter(cmdUpdate, "@EXCHANGERATE", DbType.String, bodyList.VALUE);
db.ExecuteNonQuery(cmdUpdate, tran);
cmdUpdateCr.Parameters.Clear();
db.AddInParameter(cmdUpdateCr, "@CURRENCY", DbType.String, bodyList.CURRENCY);
db.AddInParameter(cmdUpdateCr, "@EXCHANGERATE", DbType.String, bodyList.CRVALUE);
db.ExecuteNonQuery(cmdUpdateCr, tran);
var cmdInsertlog =
db.GetSqlStringCommand(
@"insert into sys_log (GID,NAME,LOGTYPE,LOGTIME,LOGCONTENT,CREATEUSER)
values (@GID,@NAME,@LOGTYPE,@LOGTIME,@LOGCONTENT,@CREATEUSER) ");
cmdInsertlog.Parameters.Clear();
db.AddInParameter(cmdInsertlog, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsertlog, "@NAME", DbType.String, "同步本期汇率");
db.AddInParameter(cmdInsertlog, "@LOGTYPE", DbType.String, "UPDATE 更新操作");
db.AddInParameter(cmdInsertlog, "@LOGTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdInsertlog, "@LOGCONTENT", DbType.String, "按照" + type + "更新费用汇率,更新条件:("+feestr+") " + sqlstr + ";应收汇率更新为:" + bodyList.VALUE.ToString() + ";应付汇率更新为:" + bodyList.CRVALUE.ToString());
db.AddInParameter(cmdInsertlog, "@CREATEUSER", DbType.String, userid);
db.ExecuteNonQuery(cmdInsertlog, tran);
}
else {
var curexlist = GetDataList("",companyid);
foreach (var enumValue in curexlist)
{
var sqlstr2 = "";
var startstr = Convert.ToDateTime(enumValue.STARTTIME.Replace("GMT+0800 (中国标准时间)", "")).ToString("yyyy-MM-dd");
var endstr = Convert.ToDateTime(enumValue.ENDTIME.Replace("GMT+0800 (中国标准时间)", "")).ToString("yyyy-MM-dd");
sqlstr2 = sqlstr2 + " AND ETD>='" + startstr + "' AND ETD<='" + endstr + "'";
cmdUpdate =
db.GetSqlStringCommand(
@"update ch_fee set EXCHANGERATE=@EXCHANGERATE where CURRENCY=@CURRENCY and feetype=1 and BSNO IN (SELECT BSNO FROM V_OP_BILL WHERE 1=1 AND OPTYPE='更改单' and " + sqlstr+ sqlstr2 + ")");
cmdUpdateCr =
db.GetSqlStringCommand(
@"update ch_fee set EXCHANGERATE=@EXCHANGERATE where CURRENCY=@CURRENCY and feetype=2 and BSNO IN (SELECT BSNO FROM V_OP_BILL WHERE 1=1 AND OPTYPE='更改单' and " + sqlstr+ sqlstr2 + ")");
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@CURRENCY", DbType.String, enumValue.CURRENCY);
db.AddInParameter(cmdUpdate, "@EXCHANGERATE", DbType.String, enumValue.VALUE);
db.ExecuteNonQuery(cmdUpdate, tran);
cmdUpdateCr.Parameters.Clear();
db.AddInParameter(cmdUpdateCr, "@CURRENCY", DbType.String, enumValue.CURRENCY);
db.AddInParameter(cmdUpdateCr, "@EXCHANGERATE", DbType.String, enumValue.CRVALUE);
db.ExecuteNonQuery(cmdUpdateCr, tran);
var cmdInsertlog =
db.GetSqlStringCommand(
@"insert into sys_log (GID,NAME,LOGTYPE,LOGTIME,LOGCONTENT,CREATEUSER)
values (@GID,@NAME,@LOGTYPE,@LOGTIME,@LOGCONTENT,@CREATEUSER) ");
cmdInsertlog.Parameters.Clear();
db.AddInParameter(cmdInsertlog, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsertlog, "@NAME", DbType.String, "同步本期汇率");
db.AddInParameter(cmdInsertlog, "@LOGTYPE", DbType.String, "UPDATE 更新操作");
db.AddInParameter(cmdInsertlog, "@LOGTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdInsertlog, "@LOGCONTENT", DbType.String, "按照" + type + "更新费用汇率,更新条件:" + sqlstr+sqlstr2 + ";应收汇率更新为:" + enumValue.VALUE.ToString() + ";应付汇率更新为:" + enumValue.CRVALUE.ToString());
db.AddInParameter(cmdInsertlog, "@CREATEUSER", DbType.String, userid);
db.ExecuteNonQuery(cmdInsertlog, tran);
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
#region Inquery INV DataList
static public List<CurrencyExchange> GetDataInvList(string strCondition, string companyid, string sort = null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT GID,CURRENCYID,VALUE,[TYPE],[STARTTIME],[ENDTIME],[CREATEUSER]");
strSql.Append(",[CREATETIME],[MODIFIEDUSER],[MODIFIEDTIME],[COMPANYID]");
strSql.Append(",(select ShowName from [user] where GID=currency_exchange_inv.CREATEUSER) as CREATEUSERREF");
strSql.Append(",(select CODENAME from [code_currency] where GID=currency_exchange_inv.CURRENCYID) as CURRENCY");
strSql.Append(" from currency_exchange_inv where COMPANYID='" + 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 CURRENCYID,STARTTIME");
}
return SetInvData(strSql);
}
static public CurrencyExchange GetInvData(string condition, string companyid)
{
CurrencyExchange data = null;
var list = GetDataInvList(condition, companyid);
if (list.Count > 0)
data = list[0];
if (data == null)
{
data = new CurrencyExchange();
}
return data;
}
private static List<CurrencyExchange> SetInvData(StringBuilder strSql)
{
var headList = new List<CurrencyExchange>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
CurrencyExchange data = new CurrencyExchange();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.CURRENCYID = Convert.ToString(reader["CURRENCYID"]);
data.CURRENCY = Convert.ToString(reader["CURRENCY"]);
if (reader["VALUE"] != DBNull.Value)
data.VALUE = Convert.ToString(reader["VALUE"]);
data.TYPE = Convert.ToString(reader["TYPE"]);
if (reader["STARTTIME"] != DBNull.Value)
data.STARTTIME = Convert.ToDateTime(reader["STARTTIME"]).ToString("yyyy-MM-dd");
if (reader["ENDTIME"] != DBNull.Value)
data.ENDTIME = Convert.ToDateTime(reader["ENDTIME"]).ToString("yyyy-MM-dd");
data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]);
data.CREATEUSERREF = Convert.ToString(reader["CREATEUSERREF"]);
if (reader["CREATETIME"] != DBNull.Value)
data.CREATETIME = Convert.ToDateTime(reader["CREATETIME"]).ToString("yyyy-MM-dd HH:mm:ss");
data.COMPANYID = Convert.ToString(reader["COMPANYID"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public static DBResult DeleteInv(CurrencyExchange headdata)
{
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 currency_exchange_inv where GID=@GID ");
cmdDelete.Parameters.Clear();
db.AddInParameter(cmdDelete, "@GID", DbType.String, headdata.GID);
db.ExecuteNonQuery(cmdDelete, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "删除出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "删除成功" + result.Message;
return result;
}
#endregion
public static DBResult SaveInvDetail(List<CurrencyExchange> bodyList, string companyid, string userid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdInsert =
db.GetSqlStringCommand(
@"insert into currency_exchange_inv (GID,CURRENCYID,VALUE,TYPE,STARTTIME,ENDTIME,COMPANYID,CREATEUSER,CREATETIME)
values (@GID,@CURRENCYID,@VALUE,@TYPE,@STARTTIME,@ENDTIME,@COMPANYID,@CREATEUSER,@CREATETIME) ");
var cmdUpdate =
db.GetSqlStringCommand(
@"update currency_exchange_inv set CURRENCYID=@CURRENCYID,VALUE=@VALUE,TYPE=@TYPE,STARTTIME=@STARTTIME,ENDTIME=@ENDTIME,MODIFIEDUSER=@MODIFIEDUSER,MODIFIEDTIME=@MODIFIEDTIME where GID=@GID ");
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
if (enumValue.STARTTIME == "") enumValue.STARTTIME = null;
else
{
enumValue.STARTTIME = Convert.ToDateTime(enumValue.STARTTIME.Replace("GMT+0800 (中国标准时间)", "")).ToString("yyyy-MM-dd");
}
if (enumValue.ENDTIME == "") enumValue.ENDTIME = null;
else
{
enumValue.ENDTIME = Convert.ToDateTime(enumValue.ENDTIME.Replace("GMT+0800 (中国标准时间)", "")).ToString("yyyy-MM-dd");
}
if (enumValue.GID == "*" || enumValue.GID == "")
{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@CURRENCYID", DbType.String, enumValue.CURRENCYID);
db.AddInParameter(cmdInsert, "@VALUE", DbType.String, enumValue.VALUE);
db.AddInParameter(cmdInsert, "@TYPE", DbType.String, enumValue.TYPE);
db.AddInParameter(cmdInsert, "@STARTTIME", DbType.String, enumValue.STARTTIME);
db.AddInParameter(cmdInsert, "@ENDTIME", DbType.String, enumValue.ENDTIME);
db.AddInParameter(cmdInsert, "@CREATETIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdInsert, "@CREATEUSER", DbType.String, userid);
db.AddInParameter(cmdInsert, "@COMPANYID", DbType.String, companyid);
db.ExecuteNonQuery(cmdInsert, tran);
}
else
{
cmdUpdate.Parameters.Clear();
db.AddInParameter(cmdUpdate, "@CURRENCYID", DbType.String, enumValue.CURRENCYID);
db.AddInParameter(cmdUpdate, "@VALUE", DbType.String, enumValue.VALUE);
db.AddInParameter(cmdUpdate, "@TYPE", DbType.String, enumValue.TYPE);
db.AddInParameter(cmdUpdate, "@STARTTIME", DbType.String, enumValue.STARTTIME);
db.AddInParameter(cmdUpdate, "@ENDTIME", DbType.String, enumValue.ENDTIME);
db.AddInParameter(cmdUpdate, "@MODIFIEDTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdUpdate, "@MODIFIEDUSER", DbType.String, userid);
db.AddInParameter(cmdUpdate, "@GID", DbType.String, enumValue.GID);
db.ExecuteNonQuery(cmdUpdate, tran);
}
}
}
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "保存出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
}
}