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.
419 lines
16 KiB
C#
419 lines
16 KiB
C#
using System;
|
|
using System.Data;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using Microsoft.Practices.EnterpriseLibrary.Data;
|
|
using DSWeb.EntityDA;
|
|
using DSWeb.Areas.CommMng.Models;
|
|
using HcUtility.Comm;
|
|
using DSWeb.Areas.CommMng.DAL;
|
|
using DSWeb.MvcShipping.Models.MsOpSeaeTDCust;
|
|
|
|
namespace DSWeb.MvcShipping.DAL.MsOpSeaeEdiTDCust
|
|
{
|
|
public class MsOpSeaeTDCustDAL
|
|
{
|
|
#region 查询
|
|
static public List<MsOpSeaeTDCustModel> GetDataList(string strCondition, string userid, string usercode, string companyid,int start,int limit,out int totalCount, string sort = null)
|
|
{
|
|
var rangstr = GetRangDAStr("index", userid, usercode, companyid);
|
|
if (!string.IsNullOrEmpty(rangstr))
|
|
{
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
{
|
|
strCondition = strCondition + " and " + rangstr;
|
|
}
|
|
else
|
|
{
|
|
strCondition = rangstr;
|
|
}
|
|
}
|
|
//
|
|
var strSql = new StringBuilder();
|
|
strSql.Append("SELECT (SELECT SHOWNAME FROM [USER] WHERE GID = USERID) LianXiRenRef,* from Op_Seae_T_Cust");
|
|
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 CreateTime desc");
|
|
}
|
|
int total = 0;
|
|
StringBuilder sb = PagerHelper.PageSQL(strSql.ToString(),start,limit,out total);
|
|
totalCount = total;
|
|
return SetData(sb);
|
|
}
|
|
|
|
static public MsOpSeaeTDCustModel GetData(string condition)
|
|
{
|
|
var strSql = new StringBuilder();
|
|
strSql.Append("SELECT (SELECT SHOWNAME FROM [USER] WHERE GID = USERID) LianXiRenRef,* from Op_Seae_T_Cust");
|
|
if (!string.IsNullOrEmpty(condition))
|
|
{
|
|
strSql.Append(" where " + condition);
|
|
}
|
|
var list = SetData(strSql);
|
|
if (list.Count > 0)
|
|
return list[0];
|
|
return new MsOpSeaeTDCustModel();
|
|
}
|
|
|
|
|
|
private static List<MsOpSeaeTDCustModel> SetData(StringBuilder strSql)
|
|
{
|
|
var headList = new List<MsOpSeaeTDCustModel>();
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
MsOpSeaeTDCustModel data = new MsOpSeaeTDCustModel();
|
|
#region Set DB data to Object
|
|
data.GID = reader["GID"].ToString();
|
|
data.GroupName = reader["GroupName"].ToString();
|
|
data.ChuanGongSi = reader["ChuanGongSi"].ToString();
|
|
data.CreateTime = reader["CreateTime"].ToString();
|
|
data.UserID = Convert.ToString(reader["UserID"]);
|
|
data.BeiZhu = Convert.ToString(reader["BeiZhu"]);
|
|
data.LianXiRenRef = reader["LianXiRenRef"].ToString();
|
|
#endregion
|
|
headList.Add(data);
|
|
}
|
|
reader.Close();
|
|
}
|
|
return headList;
|
|
}
|
|
#endregion
|
|
|
|
#region 明细表
|
|
static public List<MsOpSeaeTDCustDetailsModel> GetBodyList(string strCondition)
|
|
{
|
|
var strSql = new StringBuilder();
|
|
strSql.Append("SELECT (SELECT SHOWNAME FROM [USER] WHERE GID = LianXiRen) LianXiRenRef,* from Op_Seae_T_CustDetails");
|
|
if (strCondition.Trim() != String.Empty)
|
|
{
|
|
strSql.Append(" where " + strCondition);
|
|
}
|
|
strSql.Append(" order by CreateTime");
|
|
return SetBodyData(strSql);
|
|
}
|
|
|
|
|
|
|
|
private static List<MsOpSeaeTDCustDetailsModel> SetBodyData(StringBuilder strSql)
|
|
{
|
|
var bodyList = new List<MsOpSeaeTDCustDetailsModel>();
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
MsOpSeaeTDCustDetailsModel data = new MsOpSeaeTDCustDetailsModel();
|
|
#region Set DB data to Object
|
|
data.GID = Convert.ToString(reader["GID"]);
|
|
data.CID = Convert.ToString(reader["CID"]);
|
|
data.COMNAME = Convert.ToString(reader["COMNAME"]);
|
|
data.LianXiRen = Convert.ToString(reader["LianXiRen"]);
|
|
data.Mobile = Convert.ToString(reader["Mobile"]);
|
|
data.EMail = Convert.ToString(reader["EMail"]);
|
|
data.LianXiRenRef = Convert.ToString(reader["LianXiRenRef"]);
|
|
#endregion
|
|
bodyList.Add(data);
|
|
}
|
|
reader.Close();
|
|
}
|
|
return bodyList;
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#region 保存明细
|
|
public static DBResult SaveDetail(MsOpSeaeTDCustModel headData, List<MsOpSeaeTDCustDetailsModel> bodyList)
|
|
{
|
|
var result = new DBResult();
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
using (var conn = db.CreateConnection())
|
|
{
|
|
conn.Open();
|
|
var tran = conn.BeginTransaction();
|
|
try
|
|
{
|
|
|
|
if (bodyList != null)
|
|
{
|
|
//string del = "delete from Op_Seae_T_CustDetails where cid = '"+headData.GID+"'";
|
|
//db.ExecuteNonQuery(CommandType.Text,del);
|
|
foreach (var enumValue in bodyList)
|
|
{
|
|
if (enumValue.GID == "*")
|
|
{
|
|
enumValue.GID = Guid.NewGuid().ToString();
|
|
var cmdInsert = db.GetSqlStringCommand(@"insert into Op_Seae_T_CustDetails (GID,CID,COMNAME,LianXiRen,Mobile,EMail) values ('" + enumValue.GID + "','"
|
|
+ headData.GID + "','" + enumValue.COMNAME + "','" + enumValue.LianXiRen + "','" + enumValue.Mobile + "','" + enumValue.EMail + "')");
|
|
db.ExecuteNonQuery(cmdInsert, tran);
|
|
}
|
|
else
|
|
{
|
|
var cmdUpdate = db.GetSqlStringCommand(@"update Op_Seae_T_CustDetails set COMNAME='" + enumValue.COMNAME + "',[LianXiRen]='" + enumValue.LianXiRen + "',Mobile='" + enumValue.Mobile + "',EMail='" + enumValue.EMail
|
|
+ "' where gid='" + enumValue.GID + "'");
|
|
db.ExecuteNonQuery(cmdUpdate, tran);
|
|
}
|
|
}
|
|
}
|
|
|
|
//
|
|
tran.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
tran.Rollback();
|
|
result.Success = false;
|
|
result.Message = "保存出现错误,请重试或联系系统管理员";
|
|
return result;
|
|
}
|
|
}
|
|
//
|
|
result.Success = true;
|
|
result.Message = "保存成功" + result.Message;
|
|
return result;
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region 删除
|
|
|
|
public static DBResult DeletePiLiang(string bsnos)
|
|
{
|
|
var result = new DBResult();
|
|
var billList = bsnos.Split(',');
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
using (var conn = db.CreateConnection())
|
|
{
|
|
conn.Open();
|
|
var tran = conn.BeginTransaction();
|
|
try
|
|
{
|
|
foreach (var bill in billList)
|
|
{
|
|
|
|
var cmdDelete = db.GetSqlStringCommand("delete from Op_Seae_T_CustDetails where cid='" + bill + "'");
|
|
db.ExecuteNonQuery(cmdDelete, tran);
|
|
cmdDelete = db.GetSqlStringCommand("delete from Op_Seae_T_Cust where gid='" + bill + "'");
|
|
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 DeleteDetail(MsOpSeaeTDCustModel 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 Op_Seae_T_Cust where gid='" + headData.GID + "'");
|
|
db.ExecuteNonQuery(cmdDelete, tran);
|
|
cmdDelete = db.GetSqlStringCommand("delete from Op_Seae_T_CustDetails where cid='" + 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(MsOpSeaeTDCustDetailsModel 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 Op_Seae_T_CustDetails where gid='" + 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;
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region 权限范围
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="tb"></param>
|
|
/// <param name="userid"></param>
|
|
/// <param name="username"></param>
|
|
/// <param name="companyid"></param>
|
|
/// <param name="type">0:VGM</param>
|
|
/// <returns></returns>
|
|
public static string GetRangDAStr(string tb, string userid, string username, string companyid,int type=0)
|
|
{
|
|
string str = "";
|
|
var strSql = new StringBuilder();
|
|
strSql.Append("SELECT ");
|
|
strSql.Append(" VISIBLERANGE,OPERATERANGE ");
|
|
strSql.Append(" from VW_User_Authority ");
|
|
strSql.Append(" where [NAME]='modTDCust' and USERID='" + userid + "' and ISDELETE=0");
|
|
|
|
string visiblerange = "4";
|
|
string operaterange = "4";
|
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
{
|
|
|
|
while (reader.Read())
|
|
{
|
|
visiblerange = Convert.ToString(reader["VISIBLERANGE"]);
|
|
operaterange = Convert.ToString(reader["OPERATERANGE"]);
|
|
break;
|
|
}
|
|
reader.Close();
|
|
}
|
|
if (visiblerange == "4")
|
|
{
|
|
str = "1=2";
|
|
}
|
|
else if (visiblerange == "3")
|
|
{
|
|
|
|
str = " (userid ='" + userid + "')";
|
|
|
|
}
|
|
else if (visiblerange == "2")
|
|
{
|
|
if (tb == "index")
|
|
{
|
|
var rangeDa = new RangeDA();
|
|
var deptname = rangeDa.GetDEPTNAME(userid);
|
|
var userstr = new StringBuilder();
|
|
userstr.Append(" select SHOWNAME from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "')");
|
|
Database userdb = DatabaseFactory.CreateDatabase();
|
|
using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString()))
|
|
{
|
|
str = "";
|
|
while (reader.Read())
|
|
{
|
|
if (str == "")
|
|
{
|
|
str = " (INPUTBY='" + Convert.ToString(reader["SHOWNAME"]) + "'";
|
|
}
|
|
else
|
|
{
|
|
str = str + " or INPUTBY='" + Convert.ToString(reader["SHOWNAME"]) + "'";
|
|
};
|
|
}
|
|
str = str + ")";
|
|
reader.Close();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
str = " (select u.companyid from user_company u where u.userid = lururenid )='" + companyid + "'";
|
|
}
|
|
|
|
}
|
|
else if (visiblerange == "1")
|
|
{
|
|
//str = " UPPER(Corpid)='" + companyid + "'";
|
|
str = " (select u.companyid from user_company u where u.userid = lururenid )='" + companyid + "'";
|
|
}
|
|
else if (visiblerange == "7")
|
|
{
|
|
str = " userid in (select gid from [user] where COMNAME = (select COMNAME from [user] where GID='" + userid + "'))";
|
|
}
|
|
return str;
|
|
}
|
|
#endregion
|
|
|
|
public static MsOpSeaeTDCustDetailsModel GetLXRInfo(string gid)
|
|
{
|
|
string sql = "select Mobile,EMAIL1 from user_baseinfo where userid = '"+gid+"' ";
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
MsOpSeaeTDCustDetailsModel data = new MsOpSeaeTDCustDetailsModel();
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, sql))
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
|
|
#region Set DB data to Object
|
|
data.Mobile = Convert.ToString(reader["Mobile"]);
|
|
data.EMail = Convert.ToString(reader["EMAIL1"]);
|
|
#endregion
|
|
}
|
|
reader.Close();
|
|
}
|
|
return data;
|
|
}
|
|
|
|
//CheckHasCom
|
|
public static bool CheckHasCom(string comname)
|
|
{
|
|
string sql = "select count(*) from [user] where comname = '" + comname + "' ";
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
int rst= Convert.ToInt32(db.ExecuteScalar(CommandType.Text,sql));
|
|
return rst>0;
|
|
}
|
|
|
|
}
|
|
}
|