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/MsOpSeaPlugin/MsOpSeaPluginDAL.cs

157 lines
5.4 KiB
C#

3 years ago
using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.MvcShipping.Models.MsOpSeaPlugin;
using DSWeb.Areas.CommMng.Models;
using HcUtility.Comm;
using DSWeb.Areas.CommMng.DAL;
using DSWeb.MvcShipping.Helper;
namespace DSWeb.MvcShipping.DAL.MsOpSeaPluginDal
{
public class MsOpSeaPluginDAL
{
static public List<MsOpSeaPluginCover> GetCoverDataList (string strCondition,int start,int limit,out int total,string sort = null)
{
var strSql = new StringBuilder();
strSql.Append(@"SELECT * FROM Op_SeaCover 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 OPTIME desc ");
}
int totalCount = 0;
StringBuilder sb = PagerHelper.PageSQL(strSql.ToString(), start, limit, out totalCount);
total = totalCount;
return SetData(sb);
}
private static List<MsOpSeaPluginCover> SetData ( StringBuilder strSql )
{
var headList = new List<MsOpSeaPluginCover>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsOpSeaPluginCover data = new MsOpSeaPluginCover();
#region Set DB data to Object
data.CID = reader["CID"].ToString();
data.BSNO = reader["BSNO"].ToString();
data.COVERTITLE = reader["COVERTITLE"].ToString();
data.COVERCONTEXT = reader["COVERCONTEXT"].ToString();
data.OPERATOR = reader["OPERATOR"].ToString();
data.OPTIME = reader["OPTIME"].ToString();
data.ISSYS = reader["ISSYS"].ToString();
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public static bool DeleteCover ( List<MsOpSeaPluginCover> list, out string msg )
{
string message;
string ids = "";
foreach (var m in list)
{
ids += "'" + m.CID + "',";
}
ids = ids.Substring(0,ids.Length-1);
Database db = DatabaseFactory.CreateDatabase();
string DelSql = "DELETE FROM Op_SeaCover WHERE CID 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;
}
public static MsOpSeaPluginCover GetData ( string conditions )
{
int total = 0;
MsOpSeaPluginCover cover = GetCoverDataList(conditions, 0, 1, out total)[0];
return cover;
}
/// <summary>
///
/// </summary>
/// <param name="cover"></param>
/// <param name="saveType">0:Insert 1:Update</param>
/// <returns></returns>
public static bool SaveCover (MsOpSeaPluginCover cover,int saveType)
{
StringBuilder sb = new StringBuilder();
if (saveType == 0)
{
sb.Append(@"insert into Op_SeaCover
values ('"+cover.CID+"',");
sb.Append(@"'"+cover.BSNO+"',");
sb.Append(@"'" + cover.COVERTITLE + "',");
sb.Append(@"'" + cover.COVERCONTEXT + "',");
sb.Append(@"'" + cover.OPERATOR + "',");
sb.Append(@"'" + cover.OPTIME + "','0'");
sb.Append(@")");
}
else
{
sb.Append(@"update Op_SeaCover ");
sb.Append(@"set BSNO = '" + cover.BSNO + "',");
sb.Append(@"COVERTITLE ='" + cover.COVERTITLE + "',");
sb.Append(@"COVERCONTEXT ='" + cover.COVERCONTEXT + "',");
sb.Append(@"OPERATOR ='" + cover.OPERATOR + "',");
sb.Append(@"OPTIME ='" + cover.OPTIME + "'");
sb.Append(@" where cid = '"+cover.CID+"'");
}
Database db = DatabaseFactory.CreateDatabase();
int rst= db.ExecuteNonQuery(CommandType.Text,sb.ToString());
return rst>0;
}
}
}