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.
346 lines
14 KiB
C#
346 lines
14 KiB
C#
using System;
|
|
using System.Data;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using Microsoft.Practices.EnterpriseLibrary.Data;
|
|
using HcUtility.Comm;
|
|
using System.Data.SqlClient;
|
|
using DSWeb.MvcShipping.Helper;
|
|
using DSWeb.Areas.CommMng.DAL;
|
|
using DSWeb.Areas.MvcShipping.Models.MsOpSeaeEdiTemplate;
|
|
using DSWeb.MvcShipping.DAL.MsOpSeaeEdiDAL;
|
|
using DSWeb.EntityDA;
|
|
|
|
namespace DSWeb.Areas.MvcShipping.DAL.MsOpSeaeEdiTemplate
|
|
{
|
|
public class MsOpSeaeEdiTemplateDAL
|
|
{
|
|
public static List<MsOpSeaeEdiTemplateModel> GetDataList(string strCondition,string userid,string comid,string showname, int start, int limit, out int total, string sort = null)
|
|
{
|
|
//var rangstr = GetRangDAStr("index", userid, "", comid);
|
|
//if (!string.IsNullOrEmpty(rangstr))
|
|
//{
|
|
// if (!string.IsNullOrEmpty(strCondition))
|
|
// {
|
|
// strCondition = strCondition + " and " + rangstr;
|
|
// }
|
|
// else
|
|
// {
|
|
// strCondition = rangstr;
|
|
// }
|
|
//}
|
|
|
|
var strSql = new StringBuilder();
|
|
strSql.Append(@"select * from OP_SEAE_EDI_TEMPLATE where 1=1 ");
|
|
|
|
if (!string.IsNullOrEmpty(strCondition))
|
|
{
|
|
strSql.Append(" and " + strCondition);
|
|
}
|
|
if (!string.IsNullOrEmpty(sort))
|
|
{
|
|
var so = JsonConvert.Deserialize<List<SortObject>>(sort);
|
|
string orderbyStr = " order by ";
|
|
foreach (var s in so)
|
|
{
|
|
orderbyStr += s.property + " " + s.direction + ",";
|
|
}
|
|
orderbyStr = orderbyStr.Substring(0, orderbyStr.Length - 1);
|
|
strSql.Append(orderbyStr);
|
|
}
|
|
else
|
|
{
|
|
strSql.Append(" order by createtime ");
|
|
}
|
|
int totalCount = 0;
|
|
StringBuilder sb = PagerHelper.PageSQL(strSql.ToString(), start, limit, out totalCount);
|
|
total = totalCount;
|
|
return SetData(sb);
|
|
}
|
|
|
|
private static List<MsOpSeaeEdiTemplateModel> SetData(StringBuilder strSql)
|
|
{
|
|
var headList = new List<MsOpSeaeEdiTemplateModel>();
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
MsOpSeaeEdiTemplateModel data = new MsOpSeaeEdiTemplateModel();
|
|
#region Set DB data to Object
|
|
data.gid = reader["gid"].ToString();
|
|
data.TEMPLATENAME = reader["TEMPLATENAME"].ToString();
|
|
data.COMPANYID = reader["COMPANYID"].ToString();
|
|
data.USERID = reader["USERID"].ToString();
|
|
data.TYPE = reader["TYPE"].ToString();
|
|
data.NAME = reader["NAME"].ToString();
|
|
data.ADDRESS = reader["ADDRESS"].ToString();
|
|
data.ADDRESS2 = reader["ADDRESS2"].ToString();
|
|
data.ADDRESS3 = reader["ADDRESS3"].ToString();
|
|
data.COUNTRY = reader["COUNTRY"].ToString();
|
|
data.CITY = reader["CITY"].ToString();
|
|
data.PROVINCE = reader["PROVINCE"].ToString();
|
|
data.CODETYPE = reader["CODETYPE"].ToString();
|
|
data.CODE = reader["CODE"].ToString();
|
|
data.TEL = reader["TEL"].ToString();
|
|
data.POSTCODE = reader["POSTCODE"].ToString();
|
|
data.ATTN = reader["ATTN"].ToString();
|
|
data.CreateTime = reader["CreateTime"].ToString();
|
|
data.DisplayName = data.TEMPLATENAME + "-" + data.NAME;
|
|
#endregion
|
|
headList.Add(data);
|
|
}
|
|
reader.Close();
|
|
}
|
|
return headList;
|
|
}
|
|
|
|
public static bool Delete(List<MsOpSeaeEdiTemplateModel> list, out string msg)
|
|
{
|
|
string message;
|
|
string ids = "";
|
|
foreach (var m in list)
|
|
{
|
|
ids += "'" + m.gid + "',";
|
|
}
|
|
ids = ids.Substring(0, ids.Length - 1);
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
|
string DelSql = "DELETE FROM OP_SEAE_EDI_TEMPLATE WHERE gid IN (" + ids + ")";
|
|
bool result = false;
|
|
try
|
|
{
|
|
result = db.ExecuteNonQuery(CommandType.Text, DelSql) > 0;
|
|
if (result)
|
|
{
|
|
message = "删除成功!";
|
|
}
|
|
else
|
|
{
|
|
message = "删除失败!";
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result = false;
|
|
message = ex.Message;
|
|
}
|
|
msg = message;
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="opbs"></param>
|
|
/// <param name="saveType">0:新增 1:更新</param>
|
|
/// <param name="msg"></param>
|
|
/// <returns></returns>
|
|
public static bool Save(MsOpSeaeEdiTemplateModel et, int saveType, out string msg)
|
|
{
|
|
string message = "";
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
bool result = false;
|
|
string BSDATE = DateTime.Now.ToString("yyyy-MM-dd");
|
|
if (saveType==0)
|
|
{
|
|
//新增
|
|
StringBuilder sbIns = new StringBuilder();
|
|
sbIns.Append("insert into OP_SEAE_EDI_TEMPLATE ");
|
|
sbIns.Append("(");
|
|
sbIns.Append("gid,");
|
|
sbIns.Append("TEMPLATENAME,");
|
|
sbIns.Append("COMPANYID,");
|
|
sbIns.Append("USERID,");
|
|
sbIns.Append("TYPE,");
|
|
sbIns.Append("NAME,");
|
|
sbIns.Append("ADDRESS,");
|
|
sbIns.Append("ADDRESS2,");
|
|
sbIns.Append("ADDRESS3,");
|
|
sbIns.Append("COUNTRY,");
|
|
sbIns.Append("CITY,");
|
|
sbIns.Append("PROVINCE,");
|
|
sbIns.Append("CODETYPE,");
|
|
sbIns.Append("CODE,");
|
|
sbIns.Append("POSTCODE,");
|
|
sbIns.Append("ATTN,");
|
|
sbIns.Append("TEL");
|
|
sbIns.Append(")");
|
|
sbIns.Append(" values (");
|
|
sbIns.Append("'" + et.gid + "',");
|
|
sbIns.Append("'" + et.TEMPLATENAME + "',");
|
|
sbIns.Append("'" + et.COMPANYID + "',");
|
|
sbIns.Append("'" + et.USERID + "',");
|
|
sbIns.Append("'" + et.TYPE + "',");
|
|
sbIns.Append("'" + et.NAME.Replace("'","''") + "',");
|
|
sbIns.Append("'" + et.ADDRESS.Replace("'", "''") + "',");
|
|
sbIns.Append("'" + et.ADDRESS2.Replace("'", "''") + "',");
|
|
sbIns.Append("'" + et.ADDRESS3.Replace("'", "''") + "',");
|
|
sbIns.Append("'" + et.COUNTRY + "',");
|
|
sbIns.Append("'" + et.CITY + "',");
|
|
sbIns.Append("'" + et.PROVINCE + "',");
|
|
sbIns.Append("'" + et.CODETYPE + "',");
|
|
sbIns.Append("'" + et.CODE + "',");
|
|
sbIns.Append("'" + et.POSTCODE + "',");
|
|
sbIns.Append("'" + et.ATTN + "',");
|
|
sbIns.Append("'" + et.TEL + "'");
|
|
sbIns.Append(")");
|
|
try
|
|
{
|
|
result = db.ExecuteNonQuery(CommandType.Text, sbIns.ToString()) > 0;
|
|
if (result)
|
|
{
|
|
message = "添加成功!";
|
|
}
|
|
else
|
|
{
|
|
message = "添加失败!";
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
msg = ex.Message;
|
|
return false;
|
|
throw;
|
|
}
|
|
}
|
|
else if(saveType==1)
|
|
{
|
|
//更新
|
|
StringBuilder sbUpd = new StringBuilder();
|
|
sbUpd.Append("update OP_SEAE_EDI_TEMPLATE set ");
|
|
sbUpd.Append("TEMPLATENAME= '" + et.TEMPLATENAME + "',");
|
|
sbUpd.Append("COMPANYID= '" + et.COMPANYID + "',");
|
|
sbUpd.Append("TYPE= '" + et.TYPE + "',");
|
|
sbUpd.Append("NAME= '" + et.NAME + "',");
|
|
sbUpd.Append("ADDRESS= '" + et.ADDRESS.Replace("'", "''") + "',");
|
|
sbUpd.Append("ADDRESS2='" + et.ADDRESS2.Replace("'", "''") + "',");
|
|
sbUpd.Append("ADDRESS3='" + et.ADDRESS3.Replace("'", "''") + "',");
|
|
sbUpd.Append("COUNTRY= '" + et.COUNTRY.Replace("'", "''") + "',");
|
|
sbUpd.Append("CITY='" + et.CITY + "',");
|
|
sbUpd.Append("PROVINCE='" + et.PROVINCE + "',");
|
|
sbUpd.Append("CODETYPE= '" + et.CODETYPE + "',");
|
|
sbUpd.Append("CODE= '" + et.CODE + "',");
|
|
sbUpd.Append("POSTCODE='" + et.POSTCODE + "',");
|
|
sbUpd.Append("ATTN='" + et.ATTN + "',");
|
|
sbUpd.Append("TEL= '" + et.TEL + "'");
|
|
|
|
sbUpd.Append(" where GID = '" + et.gid + "'");
|
|
try
|
|
{
|
|
result = db.ExecuteNonQuery(CommandType.Text,sbUpd.ToString()) > 0;
|
|
if (result)
|
|
{
|
|
message = "更新成功!";
|
|
}
|
|
else
|
|
{
|
|
message = "更新失败!";
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
msg = ex.Message;
|
|
return false;
|
|
throw;
|
|
}
|
|
}
|
|
msg = message;
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
#region 权限范围
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <param name="tb"></param>
|
|
/// <param name="userid"></param>
|
|
/// <param name="username"></param>
|
|
/// <param name="companyid"></param>
|
|
/// <param name="type"></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]='modMBList' 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 = " companyid='" + companyid + "'";
|
|
}
|
|
|
|
}
|
|
else if (visiblerange == "1")
|
|
{
|
|
str = " companyid='" + companyid + "'";
|
|
}
|
|
else if (visiblerange == "7")
|
|
{
|
|
str = " gid in (select gid from OP_SEAE_EDI_TEMPLATE where userid in (select gid from [user] where COMNAME = (select COMNAME from [user] where GID='" + userid + "')))";
|
|
}
|
|
return str;
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
} |