|
|
using System;
|
|
|
using System.Data;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Text;
|
|
|
using DSWeb.MvcShipping.Models.MsStevedores;
|
|
|
using Microsoft.Practices.EnterpriseLibrary.Data;
|
|
|
using DSWeb.Areas.CommMng.Models;
|
|
|
using HcUtility.Comm;
|
|
|
using DSWeb.MvcShipping.Helper;
|
|
|
using DSWeb.Areas.CommMng.DAL;
|
|
|
using DSWeb.MvcShipping.Models.WMSNew;
|
|
|
|
|
|
|
|
|
namespace DSWeb.MvcShipping.DAL.MsStevedores
|
|
|
{
|
|
|
public class MsStevedoresDAL
|
|
|
{
|
|
|
static public List<Stevedores> GetDataList ( string strCondition, int start, int limit, out int total, string sort = null )
|
|
|
{
|
|
|
|
|
|
var strSql = new StringBuilder();
|
|
|
strSql.Append(@"SELECT * FROM wms_stevedores where delflag = 0 ");
|
|
|
|
|
|
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 updatetime ");
|
|
|
}
|
|
|
int totalCount = 0;
|
|
|
StringBuilder sb = PagerHelper.PageSQL(strSql.ToString(), start, limit, out totalCount);
|
|
|
total = totalCount;
|
|
|
return SetData(sb);
|
|
|
}
|
|
|
|
|
|
private static List<Stevedores> SetData ( StringBuilder sb )
|
|
|
{
|
|
|
var headList = new List<Stevedores>();
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
using (IDataReader reader = db.ExecuteReader(CommandType.Text, sb.ToString()))
|
|
|
{
|
|
|
while (reader.Read())
|
|
|
{
|
|
|
Stevedores data = new Stevedores();
|
|
|
#region Set DB data to Object
|
|
|
data.GID = reader["GID"].ToString();
|
|
|
data.NAME = reader["NAME"].ToString();
|
|
|
data.CODE = reader["CODE"].ToString();
|
|
|
data.PHONE = reader["PHONE"].ToString();
|
|
|
data.UpdateTime = reader["UpdateTime"].ToString();
|
|
|
data.OTHER = reader["OTHER"].ToString();
|
|
|
data.PriceJian = float.Parse(reader["PriceJian"].ToString());
|
|
|
data.PriceLiangTon = float.Parse(reader["PriceLiangTon"].ToString());
|
|
|
#endregion
|
|
|
headList.Add(data);
|
|
|
}
|
|
|
reader.Close();
|
|
|
}
|
|
|
return headList;
|
|
|
}
|
|
|
|
|
|
public static bool Delete ( List<Stevedores> 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 = "UPDATE wms_stevedores SET DELFLAG = 1 WHERE GID IN (" + ids + ")";
|
|
|
bool result = false;
|
|
|
try
|
|
|
{
|
|
|
result = db.ExecuteNonQuery(CommandType.Text, DelSql) > 0;
|
|
|
if (result)
|
|
|
{
|
|
|
message = "删除成功!";
|
|
|
string DelDetSql = "DELETE FROM WMS_IN WHERE ASSOCIATEDNO IN (" + ids + ")";
|
|
|
db.ExecuteNonQuery(CommandType.Text, DelDetSql);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
message = "删除失败!";
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
result = false;
|
|
|
message = ex.Message;
|
|
|
}
|
|
|
msg = message;
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
public static Stevedores GetData ( string conditions )
|
|
|
{
|
|
|
int total = 0;
|
|
|
var list = GetDataList(conditions, 0, 1, out total);
|
|
|
Stevedores s = list.Count > 0?list[0]:null ;
|
|
|
return s;
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
///
|
|
|
/// </summary>
|
|
|
/// <param name="sd"></param>
|
|
|
/// <param name="saveType">0:新增 1:修改</param>
|
|
|
/// <returns></returns>
|
|
|
public static bool Save (Stevedores sd,int saveType,out string msg) {
|
|
|
|
|
|
//string checkRst = Check(sd);
|
|
|
//if (checkRst!="")
|
|
|
//{
|
|
|
// msg = checkRst;
|
|
|
// return false;
|
|
|
//}
|
|
|
if (saveType == 0)
|
|
|
{
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
sb.Append(@"insert into wms_stevedores (GID,NAME,CODE,PHONE,OTHER,PriceJian,PriceLiangTon) values ");
|
|
|
sb.Append(@"(");
|
|
|
sb.Append("'"+sd.GID + "',");
|
|
|
sb.Append("'" + sd.NAME + "',");
|
|
|
sb.Append("'" + sd.CODE + "',");
|
|
|
sb.Append("'" + sd.PHONE + "',");
|
|
|
sb.Append("'" + sd.OTHER + "',");
|
|
|
sb.Append("'" + sd.PriceJian + "',");
|
|
|
sb.Append("'" + sd.PriceLiangTon + "')");
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
try
|
|
|
{
|
|
|
int rst = db.ExecuteNonQuery(CommandType.Text, sb.ToString());
|
|
|
msg = rst>0?"保存成功!":"保存失败!";
|
|
|
|
|
|
return rst>0;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
msg = "保存失败!";
|
|
|
throw ex;
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
sb.Append(@"update wms_stevedores set ");
|
|
|
sb.Append(@"NAME = '" + sd.NAME + "',");
|
|
|
sb.Append(@"PHONE = '" + sd.PHONE + "',");
|
|
|
sb.Append(@"CODE = '" + sd.CODE + "',");
|
|
|
sb.Append(@"PriceLiangTon = '" + sd.PriceLiangTon + "',");
|
|
|
sb.Append(@"PriceJian = '" + sd.PriceJian + "',");
|
|
|
sb.Append(@"OTHER = '" + sd.OTHER + "'");
|
|
|
sb.Append(@"WHERE GID = '" + sd.GID + "'");
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
try
|
|
|
{
|
|
|
int rst = db.ExecuteNonQuery(CommandType.Text, sb.ToString());
|
|
|
msg = rst > 0 ? "保存成功!" : "保存失败!";
|
|
|
return rst > 0;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
|
|
|
msg = "保存失败!";
|
|
|
throw ex;
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private static string Check ( Stevedores sd ) {
|
|
|
string sql1 = "select count(*) from wms_stevedores where name = '"+sd.NAME+"'";
|
|
|
Database db = DatabaseFactory.CreateDatabase();
|
|
|
int cnt1 = Convert.ToInt32(db.ExecuteScalar(CommandType.Text,sql1));
|
|
|
if (cnt1>0)
|
|
|
{
|
|
|
return "姓名已存在,请重新输入!";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
string sql2 = "select count(*) from wms_stevedores where code = '" + sd.CODE + "'";
|
|
|
int cnt2 = Convert.ToInt32(db.ExecuteScalar(CommandType.Text, sql2));
|
|
|
if (cnt2>0)
|
|
|
{
|
|
|
return "代码已存在,请重新输入!";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return "";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|