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.
289 lines
10 KiB
C#
289 lines
10 KiB
C#
using System;
|
|
using System.Data;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using DSWeb.MvcShipping.Models.DingTalkSet;
|
|
using Microsoft.Practices.EnterpriseLibrary.Data;
|
|
using DSWeb.Areas.CommMng.Models;
|
|
using HcUtility.Comm;
|
|
|
|
|
|
namespace DSWeb.MvcShipping.DAL.MsCodeDingTalkSet
|
|
{
|
|
public class MsCodeDingTalkSetDAL
|
|
{
|
|
#region Inquery DataList
|
|
|
|
static public List<CodeDingTalkSet> GetDataList(string strCondition, string companyid, string sort = null)
|
|
{
|
|
|
|
var strSql = new StringBuilder();
|
|
strSql.Append("SELECT ");
|
|
strSql.Append("GID,MODULENAME,AGENTID,APPKEY,APPSECRET,CORPID,PROCID,CALLBACK_AES_KEY,CALBACK_TOKEN,ISENABLE,PROCNAME,APITOKEN");
|
|
strSql.Append(" from code_DingTalkSet where 1=1 ");
|
|
if (!string.IsNullOrEmpty(companyid))
|
|
strSql.Append(" 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 MODULENAME");
|
|
|
|
}
|
|
return SetData(strSql);
|
|
}
|
|
|
|
static public CodeDingTalkSet GetData(string condition, string companyid)
|
|
{
|
|
CodeDingTalkSet data = null;
|
|
var list = GetDataList(condition,companyid);
|
|
if (list.Count > 0)
|
|
data = list[0];
|
|
|
|
if (data == null)
|
|
{
|
|
data = new CodeDingTalkSet();
|
|
}
|
|
|
|
return data;
|
|
}
|
|
|
|
|
|
private static List<CodeDingTalkSet> SetData(StringBuilder strSql)
|
|
{
|
|
var headList = new List<CodeDingTalkSet>();
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
CodeDingTalkSet data = new CodeDingTalkSet();
|
|
#region Set DB data to Object
|
|
data.GID = Convert.ToString(reader["GID"]);
|
|
data.MODULENAME = Convert.ToString(reader["MODULENAME"]);
|
|
data.AGENTID = Convert.ToString(reader["AGENTID"]).Trim();
|
|
data.APPKEY = Convert.ToString(reader["APPKEY"]).Trim();
|
|
data.APPSECRET = Convert.ToString(reader["APPSECRET"]).Trim();
|
|
data.PROCID = Convert.ToString(reader["PROCID"]).Trim();
|
|
data.PROCNAME = Convert.ToString(reader["PROCNAME"]).Trim();
|
|
data.CORPID = Convert.ToString(reader["CORPID"]);
|
|
data.CALLBACK_AES_KEY = Convert.ToString(reader["CALLBACK_AES_KEY"]).Trim();
|
|
data.CALBACK_TOKEN = Convert.ToString(reader["CALBACK_TOKEN"]).Trim();
|
|
data.APITOKEN = Convert.ToString(reader["APITOKEN"]).Trim();
|
|
if (reader["ISENABLE"] != DBNull.Value)
|
|
data.ISENABLE = Convert.ToBoolean(reader["ISENABLE"]);//货主箱标志,是否自有箱
|
|
#endregion
|
|
headList.Add(data);
|
|
}
|
|
reader.Close();
|
|
}
|
|
return headList;
|
|
}
|
|
#endregion
|
|
|
|
#region 明细表
|
|
|
|
static public List<CodeDingTalkSetDetail> GetBodyList(string strCondition, string sort = null)
|
|
{
|
|
var strSql = new StringBuilder();
|
|
strSql.Append("SELECT ");
|
|
strSql.Append("GID,MODULEID,TABLETYPE,DFIELDNAME,DDFIELDNAME,FIELDNAME,DEFAULTVALUE");
|
|
strSql.Append(" from code_DingTalkSet_Detail ");
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
{
|
|
strSql.Append(" where " + strCondition);
|
|
}
|
|
var sortstring = DatasetSort.Getsortstring(sort);
|
|
if (!string.IsNullOrEmpty(sortstring))
|
|
{
|
|
strSql.Append(" order by " + sortstring);
|
|
}
|
|
else
|
|
{
|
|
strSql.Append(" order by TABLETYPE DESC ");
|
|
}
|
|
|
|
return SetBodyData(strSql);
|
|
}
|
|
|
|
private static List<CodeDingTalkSetDetail> SetBodyData(StringBuilder strSql)
|
|
{
|
|
var bodyList = new List<CodeDingTalkSetDetail>();
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
CodeDingTalkSetDetail data = new CodeDingTalkSetDetail();
|
|
#region Set DB data to Object
|
|
data.GID = Convert.ToString(reader["GID"]);
|
|
data.MODULEID = Convert.ToString(reader["MODULEID"]);
|
|
data.TABLETYPE = Convert.ToString(reader["TABLETYPE"]);
|
|
data.DFIELDNAME = Convert.ToString(reader["DFIELDNAME"]);
|
|
data.DDFIELDNAME = Convert.ToString(reader["DDFIELDNAME"]);
|
|
data.FIELDNAME = Convert.ToString(reader["FIELDNAME"]);
|
|
data.DEFAULTVALUE = Convert.ToString(reader["DEFAULTVALUE"]);
|
|
#endregion
|
|
|
|
bodyList.Add(data);
|
|
}
|
|
reader.Close();
|
|
}
|
|
|
|
return bodyList;
|
|
}
|
|
|
|
|
|
|
|
|
|
public static DBResult SaveDetail(CodeDingTalkSet headData, List<CodeDingTalkSetDetail> bodyList)
|
|
{
|
|
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 code_DingTalkSet_Detail where MODULEID='" + headData.GID + "'");
|
|
db.ExecuteNonQuery(cmdDelete, tran);
|
|
|
|
var cmdInsert =
|
|
db.GetSqlStringCommand(
|
|
@"insert into code_DingTalkSet_Detail (GID,MODULEID,TABLETYPE,DFIELDNAME,DDFIELDNAME,FIELDNAME,DEFAULTVALUE)
|
|
values (@GID,@MODULEID,@TABLETYPE,@DFIELDNAME,@DDFIELDNAME,@FIELDNAME,@DEFAULTVALUE) ");
|
|
|
|
if (bodyList != null)
|
|
{
|
|
foreach (var enumValue in bodyList)
|
|
{
|
|
cmdInsert.Parameters.Clear();
|
|
|
|
db.AddInParameter(cmdInsert, "@GID", DbType.String, Guid.NewGuid().ToString());
|
|
db.AddInParameter(cmdInsert, "@MODULEID", DbType.String, headData.GID);
|
|
db.AddInParameter(cmdInsert, "@TABLETYPE", DbType.String, enumValue.TABLETYPE);
|
|
db.AddInParameter(cmdInsert, "@DFIELDNAME", DbType.String, enumValue.DFIELDNAME);
|
|
db.AddInParameter(cmdInsert, "@DDFIELDNAME", DbType.String, enumValue.DDFIELDNAME);
|
|
db.AddInParameter(cmdInsert, "@FIELDNAME", DbType.String, enumValue.FIELDNAME);
|
|
db.AddInParameter(cmdInsert, "@DEFAULTVALUE", DbType.String, enumValue.DEFAULTVALUE);
|
|
|
|
db.ExecuteNonQuery(cmdInsert, tran);
|
|
}
|
|
}
|
|
|
|
tran.Commit();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
tran.Rollback();
|
|
|
|
result.Success = false;
|
|
result.Message = "保存出现错误,请重试或联系系统管理员";
|
|
|
|
return result;
|
|
}
|
|
}
|
|
|
|
result.Success = true;
|
|
result.Message = "保存成功";
|
|
|
|
return result;
|
|
}
|
|
|
|
|
|
public static DBResult DeleteDetail(CodeDingTalkSet headData)
|
|
{
|
|
var result = new DBResult();
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
using (var conn = db.CreateConnection())
|
|
{
|
|
conn.Open();
|
|
var tran = conn.BeginTransaction();
|
|
|
|
try
|
|
{
|
|
|
|
var cmd = db.GetSqlStringCommand("delete from code_DingTalkSet where GID='" + headData.GID + "'");
|
|
db.ExecuteNonQuery(cmd, tran);
|
|
var cmdDelete = db.GetSqlStringCommand("delete from code_DingTalkSet_Detail where MODULEID='" + headData.GID + "'");
|
|
db.ExecuteNonQuery(cmdDelete, tran);
|
|
|
|
|
|
tran.Commit();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
tran.Rollback();
|
|
|
|
result.Success = false;
|
|
result.Message = "保存出现错误,请重试或联系系统管理员";
|
|
|
|
return result;
|
|
}
|
|
}
|
|
|
|
result.Success = true;
|
|
result.Message = "保存成功";
|
|
|
|
return result;
|
|
}
|
|
|
|
public static DBResult DeleteDetail2(string GID)
|
|
{
|
|
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 code_DingTalkSet_Detail where GID='" + GID + "'");
|
|
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 参照部分
|
|
|
|
#endregion
|
|
}
|
|
}
|