本文整理汇总了C#中DBContext.Close方法的典型用法代码示例。如果您正苦于以下问题:C# DBContext.Close方法的具体用法?C# DBContext.Close怎么用?C# DBContext.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBContext
的用法示例。
在下文中一共展示了DBContext.Close方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToRongBao
//.........这里部分代码省略.........
}
else if (dayUnSumMoney < minMoney)
{
string reason = checkPass == null ? "金额小于当日下限" : checkPass;
db.ExecuteCommand("update transactionsum set status =-3,results ='" + reason + "' where id=" + dr["id"]);
checkPass = "今日总金额" + dayUnSumMoney + "," + reason;
}
else
{
//满足条件后消除限额
stepName = "查询是否有满足条件后消除限额的数据";
DataTable beforeDisabelDt = db.QueryTable("select id,tradeMoney from transactionsum where status = -3 and terminal ='" + terminal + "' and createDate < '" + todayEndStr + "'");
if (beforeDisabelDt.Rows.Count > 0)
{ //如果有恢复原来的,则组织成一条再发
LogStep("合并数据,之前暂停的有" + beforeDisabelDt.Rows.Count + "条");
decimal tempMoney = 0;
string canUploadIdArr = "";
int canUploadCount = 0;
for (int i = 0; i < beforeDisabelDt.Rows.Count; i++)
{
decimal rowMoney = Convert.ToDecimal(beforeDisabelDt.Rows[i]["tradeMoney"]);
if (tempMoney + rowMoney > maxMoney) continue;//如果合并后的金额还是大于当日限额,则超出部分不结
tempMoney += rowMoney;
canUploadCount++;
canUploadIdArr += "," + beforeDisabelDt.Rows[i]["id"];
}
if (canUploadCount == 0) LogStep("汇总成一条记录,但还是超过限额,有" + beforeDisabelDt.Rows.Count + "条记录不会被上传结算");
else
{
if (tempMoney > minMoney) checkPass = null;//如果当日累计达到条件,则该笔就算未达到也加入合并
if (checkPass == null)
{
canUploadIdArr = dr["id"] + canUploadIdArr;//加上自己(满足条件的这条+原来被暂停的那条)
//汇总成新的记录
object scalar = db.ExecScalar("insert into transactionsum(sum2Id,tradeMoney,discountMoney,tixianfeiMoney,finallyMoney,status,terminal,createDate,batchCount) select -1,sum(tradeMoney),sum(discountMoney),sum(tixianfeiMoney),sum(finallyMoney),0," + terminal + ",'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "',sum(batchCount) from transactionsum where id in (" + canUploadIdArr + "); select @@identity");
if (scalar == null) throw new Exception("汇总成新的记录异常,identity is null");
int newSumId = Convert.ToInt32(scalar);
//合并后作废原来的
db.ExecuteCommand("update transactionsum set status = -1,sum2Id=" + newSumId + ",results= isnull(results,'')+ ' 合并到" + newSumId + "' where id in ( " + canUploadIdArr + ")");
sql = selectSqlFields+" where a.id=" + newSumId;
dr = db.QueryTable(sql).Rows[0];//提交合并后的到rongbao
}
}
}
}
}
else
{
LogStep("终端" + terminal + "(合并),开始上传");
}
db.Close();
}
if (checkPass != null)
{
resultData.Message = terminal + ":" + checkPass;
}
else
{
SentRowToRongBao( dr, batchCurrnum, batchDate, terminal, ref stepName);
resultData.Result = new string[] { batchCurrnum, batchDate, terminal };
}
}
catch (Exception ex)
{
resultData.Message = stepName + "时发生异常:" + ex.Message;
LogError(stepName, ex);
if (dt != null)
{
try
{
using (DBContext context = new DBContext())
{
foreach (DataRow dr in dt.Rows)
{
resultData.Message = resultData.Message.Replace('\'', ' ');
string errorStatus = "-2";
if (ex is System.Net.WebException && ex.Message.IndexOf("The remote name could not be resolved") > -1)
{
LogStep("网络问题,下次继续传");
errorStatus = "0";
}
sql = "update transactionSum set status= " + errorStatus + " ,results = '" + resultData.Message + "' where batchCurrnum='" + batchCurrnum + "' and id='" + dr["id"] + "' and status= 1";
context.ExecuteCommand(sql);
}
}
}
catch (MySqlException e)
{
resultData.Message += " , 更新失败标记也失败!" + e.Message;
LogError("更新失败标记", ex);
}
}
}
finally
{
inUploadRongbao = false;
}
return Json (resultData, JsonRequestBehavior.AllowGet);
}
示例2: SentRowToRongBao
/// <summary>
/// 发送到融宝,注意:上传融宝之前提交一样事务
/// </summary>
/// <param name="dr"></param>
/// <param name="batchCurrnum"></param>
/// <param name="batchDate"></param>
/// <param name="terminal"></param>
/// <param name="errorItem"></param>
private void SentRowToRongBao(DataRow dr, string batchCurrnum, string batchDate, string terminal, ref string errorItem)
{
LogStep("添加代付手续费");
decimal daifufei = Convert.ToDecimal(dr["daifufei"]);
dr["money"] = Convert.ToDecimal(dr["money"]) - daifufei;
string cerFile = getSetting("rongbao_public", true);
LogStep("更新待上传标记");
string sql = @"update transactionSum set status= 1,results='正在结算', batchCurrnum='" + batchCurrnum + "'" +
", uploadDate='" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "'" +
",faren='" + dr["faren"] + "' " +
",shanghuName='" + dr["shanghuName"] + "' " +
",bankName='" + dr["bankName"] + "' " +
",bankName2='" + dr["bankName2"] + "' " +
",bankName3='" + dr["bankName3"] + "' " +
",province='" + dr["province"] + "' " +
",city='" + dr["city"] + "' " +
",bankAccount='" + dr["bankAccount"] + "' " +
",sourceAccount='" + dr["sourceAccount"] + "' " +
",tel='" + dr["tel"] + "' " +
" where id='" + dr["id"] + "'";
using (DBContext db = new DBContext())
{
db.ExecuteCommand(sql);//标记状态为待上传
db.Close();
}
errorItem = "上传融宝处理";
Common.RongBao.RSACryptionClass testClass = new Common.RongBao.RSACryptionClass(cerFile, "");
string returnStr = testClass.Sent(dr.Table, batchCurrnum, batchDate);
LogStep("融宝执行成功,更新成功状态");
sql = "update transactionSum set status= 2,daifufei=" + daifufei + ",finallyMoney=" + dr["money"] + ",results='银行处理中' where id='" + dr["id"] + "'";
using (DBContext db = new DBContext())
{
db.ExecuteCommand(sql);
errorItem = null;
string msgTitle = Convert.ToDateTime(dr["createDate"]).ToString("HH:mm:ss") + dr["faren"] + "消费额" + dr["tradeMoney"] + "元,准备出款" + dr["money"] + "元";
string msgContent = "<p>终端" + dr["terminal"] + ",法人:" + dr["faren"] + ",商户:" + dr["shanghuName"] + "</p>";
msgContent += "<p>" + dr["createDate"] + "发起结算:" + dr["tradeMoney"] + "元,需要给客户打款:" + dr["money"] + "元</p>";
msgContent += "<p><a href='https://bgp.reapal.com/tbAgentpayInfo/agentpaylist'>点此前往融宝审核</a></p>";
string emails = getSetting("emails");
foreach (string mail in emails.Split(','))
{
SentEmail(mail, msgContent, msgTitle, db);
}
}
}
示例3: SyncJingKongPosData
//.........这里部分代码省略.........
//while (true)
//{
// try
// {
// string timeJson = http.DoGet("http://www.easybots.cn/api/holiday.php?d=" + tempTime);
// if (string.IsNullOrEmpty(timeJson)) throw new Exception("节假日返回值为空");
// string[] tempArr = timeJson.Substring(1, timeJson.Length - 2).Split(':');
// if (tempArr.Length != 2) throw new Exception("节假日返回值有变动");
// isHoldDay = Convert.ToInt32(tempArr[1].Replace('\"', ' ').Trim()) > 0;
// break;
// }
// catch (System.Net.WebException ex)
// {
// tryCount--;
// if (tryCount < 0) { GetLocalHolday(tempTime, db); break; }
// LogError("使用网络节假日发生网络异常,重试"+ tryCount, ex);
// }
// catch (Exception ex)
// {
// LogStep("easybots节假日返回异常(" + ex.Message + "),尝试读取本地设置");
// }
// break;
//}
}
LogStep("计算手续费");
calcMoney(customerInfo, localItem);
LogStep("保存交易记录");
localItem.status = 0;
db.DoSave("", localItem);
newItemList.Add(localItem);
}
LogStep("查询是否有结算交易");
string sql = "select time,id from TransactionLogs where terminal='" + terminal + "' and tradeName in ('批上送结束(平账)','批上送结束(不平账)') and resultCode='00' and status =0";
DataTable dt = db.QueryTable(sql);
if (dt.Rows.Count > 0)
{
LogStep("有" + dt.Rows.Count + "笔结算数据,开始结算");
foreach (DataRow dr in dt.Rows)
{
string time = dr["time"].ToString();
string sumLogId = dr["id"].ToString();
sql = "select max(time) prevTime from TransactionLogs where terminal='" + terminal + "' and Status=0 and tradeName in ('批上送结束(平账)','批上送结束(不平账)') and resultCode='00' and time < '" + time + "'";
object o = db.ExecScalar(sql);
string prevTime = o.ToString();
//sum log of (消费)
sql = "select count(0) batchCount,sum(tradeMoney) tradeMoney,sum(discountMoney) discountMoney,sum(tixianfeiMoney) tixianfeiMoney from transactionLogs ";
string publicWhere = " where terminal='" + terminal + "' and Status=0 and isValid = 1 and resultCode='00'";
if (string.IsNullOrEmpty(prevTime))
publicWhere += " and time < '" + time + "'";
else
publicWhere += " and time between '" + prevTime + "' and '" + time + "'";
sql += publicWhere;
DataTable dtSum = db.QueryTable(sql);
if (dtSum.Rows.Count == 0 || dtSum.Rows[0]["batchCount"].Equals(0) || dtSum.Rows[0]["tradeMoney"] == DBNull.Value) continue;
TransactionSum sumData = new TransactionSum();
sumData.shanghuName = customerInfo.shanghuName;
sumData.faren = customerInfo.faren;
sumData.tradeMoney = Convert.ToDouble(dtSum.Rows[0]["tradeMoney"]);
sumData.discountMoney = Convert.ToDouble(dtSum.Rows[0]["discountMoney"]);
sumData.tixianfeiMoney = Convert.ToDouble(dtSum.Rows[0]["tixianfeiMoney"]);
sumData.finallyMoney = Convert.ToDouble(sumData.tradeMoney) - Convert.ToDouble(sumData.discountMoney) - Convert.ToDouble(sumData.tixianfeiMoney);
sumData.status = 0;
sumData.batchCount = Convert.ToInt32(dtSum.Rows[0]["batchCount"]);
sumData.createDate = time;//(new Date()).Format("yyyy-MM-dd hh:mm:ss");用结算记录的时间
sumData.terminal = terminal;
db.DoSave("", sumData);//保存结算数据
//更新交易记录的标记
sql = "update TransactionLogs set sumid=" + sumData.id + " , status =1 " + publicWhere;
db.ExecuteCommand(sql);
sql = "update TransactionLogs set sumid=" + sumData.id + " , status =1 where id = " + sumLogId;
db.ExecuteCommand(sql);
}
}
else
{
LogStep("不需要结算");
}
if (maxTime == DateTime.MinValue) maxTime = DateTime.Today;
//update lastQuery
sql = "update Customers set lastQuery ='" + maxTime.ToString("yyyy-MM-dd") + "' where terminal='" + terminal + "' ";
db.ExecuteCommand(sql);
LogStep("关闭连接");
db.Close();
resultData.Result = newItemList;
}
catch (Exception ex)
{
resultData.Message = stepName + "时发生异常:" + ex.Message + "\r\nDBStepMessage:" + db.GetStepMsg();
LogError(stepName, ex);
db.Dispose();
}
finally {
System.Web.HttpContext.Current.Application.UnLock();
}
return resultData;
}