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/MsOpCtnFeeModelDuiCunDAL/MsOpCtnFeeModelDAL.cs

209 lines
8.7 KiB
C#

3 years ago
using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.Areas.CommMng.Models;
using HcUtility.Comm;
using DSWeb.Areas.CommMng.DAL;
using DSWeb.MvcShipping.Helper;
using DSWeb.MvcShipping.Models.MsStevedores;
using System.Transactions;
using System.Data.SqlClient;
using DSWeb.DataAccess;
using DSWeb.Areas.MvcShipping.Models.MsOpCtnFeeModelModel;
namespace DSWeb.Areas.MvcShipping.DAL.MsOpCtnFeeModelDuiCunDAL
{
public class MsOpCtnFeeModelDuiCunDAL
{
public static List<MsOpCtnFeeModel> GetDataList (string condition )
{
string sql = "select *,(select (CODENAME+'-'+SHORTNAME) as CodeAndName from info_client where CODENAME = PortAndYardCode) PortAndYardName from Op_Ctn_FEEMODEL where 1=1 and ModelType=2 ";
if (condition!="")
{
sql += " and "+ condition;
}
var list = new List<MsOpCtnFeeModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, sql))
{
while (reader.Read()) {
MsOpCtnFeeModel fm = new MsOpCtnFeeModel();
fm.GID = reader["GID"].ToString();
fm.ModelName = reader["ModelName"].ToString();
fm.PortAndYardCode = reader["PortAndYardCode"].ToString();
fm.PortAndYardName = reader["PortAndYardName"].ToString();
fm.Oper = reader["Oper"].ToString();
fm.Optime = reader["Optime"].ToString();
list.Add(fm);
}
}
return list;
}
public static List<MsOpCtnFeeDetailsModel> GetDataDetailsList ( string condition )
{
string sql = "select * from Op_Ctn_FEEMODEL_DETAILS";
if (condition!=""&&condition!=null)
{
sql += " where " + condition;
}
var list = new List<MsOpCtnFeeDetailsModel>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, sql))
{
while (reader.Read())
{
MsOpCtnFeeDetailsModel fmd = new MsOpCtnFeeDetailsModel();
fmd.GID = reader["GID"].ToString();
fmd.MainGID = reader["MainGID"].ToString();
fmd.XiangXing = reader["XiangXing"].ToString();
fmd.JiFeiDengJi = reader["JiFeiDengJi"].ToString();
fmd.ShouFuFangXiang = reader["ShouFuFangXiang"].ToString();
fmd.Optime = reader["Optime"].ToString();
fmd.JiFeiQuJian = reader["JiFeiQuJian"].ToString();
fmd.JiFeiDanJia = reader["JiFeiDanJia"].ToString();
fmd.Optime = reader["Optime"].ToString();
list.Add(fmd);
}
}
return list;
}
public static List<Ctn> GetCtn ( string condition = "" )
{
string sql = "select CTN from code_ctn";
if (condition!=""&&condition!=null)
{
sql += " where " + condition;
}
var list = new List<Ctn>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, sql))
{
while (reader.Read())
{
Ctn c = new Ctn();
c.CtnType = reader["CTN"].ToString();
list.Add(c);
}
}
return list;
}
public static bool Save ( MsOpCtnFeeModel fm, List<MsOpCtnFeeDetailsModel> fmdList, out string msg, out string MGID )
{
//保存主表
int Exmnum = 0;
int Exdnum = 0;
string GID = fm.GID;
string PGID = fm.GID;
bool mainRst = false;
string[] portstr = fm.PortAndYardName.Split('-');
if (portstr.Length > 1)
{
fm.PortAndYardCode = portstr[0];
}
Database db = DatabaseFactory.CreateDatabase();
if (GID==""||GID=="*")
{
//新增
GID = Guid.NewGuid().ToString();
PGID = GID;
StringBuilder sb = new StringBuilder();
sb.Append("insert into Op_Ctn_FEEMODEL (GID,ModelName,PortAndYardCode,Oper,ModelType) ");
sb.Append("values('" + GID + "','" + fm.ModelName + "','" + fm.PortAndYardCode + "','" + fm.Oper + "',2)");
Exmnum = db.ExecuteNonQuery(CommandType.Text, sb.ToString());
mainRst = Exmnum >0;
}
else
{
//修改
StringBuilder sb = new StringBuilder();
sb.Append("update Op_Ctn_FEEMODEL set ");
sb.Append("ModelName = '"+fm.ModelName+"',");
sb.Append("PortAndYardCode = '" + fm.PortAndYardCode + "',");
sb.Append("Oper = '" + fm.Oper + "'");
sb.Append(" where GID = '"+fm.GID+"'");
mainRst = db.ExecuteNonQuery(CommandType.Text,sb.ToString()) > 0;
}
if (mainRst)
{
try
{
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
//保存明细表
if (fmdList==null)
{
fmdList = new List<MsOpCtnFeeDetailsModel>();
}
foreach (var item in fmdList)
{
item.MainGID = PGID;
if (item.GID == "" || item.GID == "*")
{
//新增
string newGID = Guid.NewGuid().ToString();
item.GID = newGID;
StringBuilder sbd = new StringBuilder();
sbd.Append("insert into Op_Ctn_FEEMODEL_DETAILS (GID,MainGID,XiangXing,JiFeiDengJi,ShouFuFangXiang,JiFeiQuJian,JiFeiDanJia) ");
sbd.Append(" values (");
sbd.Append("'" + item.GID + "',");
sbd.Append("'" + item.MainGID + "',");
sbd.Append("'" + item.XiangXing + "',");
sbd.Append("'" + item.JiFeiDengJi + "',");
sbd.Append("'" + item.ShouFuFangXiang + "',");
sbd.Append("'" + item.JiFeiQuJian + "',");
sbd.Append("'" + item.JiFeiDanJia + "')");
var cmdInsertwork = db.GetSqlStringCommand(sbd.ToString());
Exdnum += db.ExecuteNonQuery(cmdInsertwork, tran);
}
else
{
//修改
StringBuilder sbd = new StringBuilder();
sbd.Append("update Op_Ctn_FEEMODEL_DETAILS set ");
sbd.Append("JiFeiDengJi='" + item.JiFeiDengJi + "',");
sbd.Append("ShouFuFangXiang='" + item.ShouFuFangXiang + "',");
sbd.Append("JiFeiQuJian='" + item.JiFeiQuJian + "',");
sbd.Append("JiFeiDanJia='" + item.JiFeiDanJia + "' ");
sbd.Append("where GID = '" + item.GID + "'");
var cmdUpdatework = db.GetSqlStringCommand(sbd.ToString());
Exdnum+= db.ExecuteNonQuery(cmdUpdatework, tran);
}
}
tran.Commit();
}
}
catch (Exception ex)
{
msg = "操作异常!"+ex.Message;
mainRst = false;
MGID = GID;
return mainRst;
}
MGID = GID;
msg ="操作完成!";
return mainRst;
}
else
{
MGID = GID;
msg ="主表数据保存失败!";
return false;
}
}
}
}