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.

245 lines
10 KiB
C#

using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using DSWeb.Areas.TruckMng.Models.MsWl_Port;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.EntityDA;
using DSWeb.Areas.CommMng.Models;
using System.Web;
using System.Data.Common;
using DSWeb.TruckMng.Comm.Cookie;
using WebSqlHelper;
using DSWeb.Areas.TruckMng.Controllers;
namespace DSWeb.Areas.TruckMng.DAL.MsWl_Port
{
public partial class MsWl_ADLDAL
{
#region 主表
public static List<MsWl_ADLFuelmb> GetDataList(string strCondition, string sort)
{
var strSql = new StringBuilder();
/*
strSql.Append(" select GID,TRUCKNO,DRVCODE,(select DrvName from tMsWlDriver where drvcode=a.drvcode) DRVNAME,dbo.trimdate(EXPDATE_BGN) EXPDATE_BGN,dbo.trimdate(EXPDATE_END) EXPDATE_END,REALFUEL,FUELPRICE,FUELPRICE_AGIO,AMOUNT,REMARK ");
strSql.Append(" ,isnull((select sum(RatedFuel) from tmswlpchead where expdate between a.expdate_bgn and a.expdate_end and truckno=a.truckno and drvcode=a.drvcode),0) RATEDFUEL ");
strSql.Append(" ,isnull((select sum(OVERLOADMIL) from tmswlpchead where expdate between a.expdate_bgn and a.expdate_end and truckno=a.truckno and drvcode=a.drvcode),0) OVERLOADMIL ");
strSql.Append(" ,isnull((select max(fueltotal) from tmswltruckfuel where truckno=a.truckno ),0) FUELRATE ");
strSql.Append(" ,convert(bigint ,a.TimeMark) as TimeMark ");
strSql.Append(" from tmswl_adlfuel a ");*/
strSql.Append(" select *,Convert(numeric(18,2),(FuelPrice-FuelPrice_agio)*(RatedFuel-RealFuel)) SaveAmount ");
//strSql.Append(" ");
strSql.Append(" ,RATEDFUEL*FuelPrice RatedFuelAmount,RATEDFUEL-REALFUEL FuelRemain");
strSql.Append(" from VW_ADLFuelDate a");
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 GID");
return SetData(strSql);
}
public static MsWl_ADLFuelmb GetData ( string condition )
{
MsWl_ADLFuelmb head = null;
var list = GetDataList(condition, "");
if (list.Count > 0)
head = list[0];
if (head == null)
{
head = new MsWl_ADLFuelmb();
}
return head;
}
private static List<MsWl_ADLFuelmb> SetData ( StringBuilder strSql )
{
var headList = new List<MsWl_ADLFuelmb>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var data = new MsWl_ADLFuelmb();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.TRUCKNO = Convert.ToString(reader["TRUCKNO"]);
data.DRVCODE = Convert.ToString(reader["DRVCODE"]);
data.DRVNAME = Convert.ToString(reader["DRVNAME"]);
data.EXPDATE_BGN = Convert.ToString(reader["EXPDATE_BGN"]);
data.EXPDATE_END = Convert.ToString(reader["EXPDATE_END"]);
data.REALFUEL = Convert.ToString(reader["REALFUEL"]);
data.FUELPRICE = Convert.ToString(reader["FUELPRICE"]);
data.FUELPRICE_AGIO = Convert.ToString(reader["FUELPRICE_AGIO"]);
data.AMOUNT = Convert.ToString(reader["AMOUNT"]);
data.REMARK = Convert.ToString(reader["REMARK"]);
data.RATEDFUEL = Convert.ToString(reader["RATEDFUEL"]);
data.OVERLOADMIL = Convert.ToString(reader["OVERLOADMIL"]);
data.FUELRATE = Convert.ToString(reader["FUELRATE"]);
data.TimeMark = Convert.ToDecimal(reader["TimeMark"]);
data.SAVEAMOUNT = Convert.ToString(reader["SAVEAMOUNT"]);
data.RatedFuelAmount = Convert.ToString(reader["RatedFuelAmount"]);
data.FuelRemain = Convert.ToString(reader["FuelRemain"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
#endregion
#region 爱德林 导入的加油记录
public static List<MsWl_FuelDateInputmb> GetFuelDateInputList ( string strCondition, string sort )
{
var strSql = new StringBuilder();
strSql.Append(" select *,case when isnull(BSNO,'')<>'' then 1 else 0 end inserted ");
strSql.Append(" from tMsWl_FuelDateInput ");
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 CKR,CH,JYTIME");
return SetFuelDateInputList(strSql);
}
public static MsWl_FuelDateInputmb GetFuelDateInputData ( string condition )
{
MsWl_FuelDateInputmb head = null;
var list = GetFuelDateInputList(condition, "");
if (list.Count > 0)
head = list[0];
if (head == null)
{
head = new MsWl_FuelDateInputmb();
}
return head;
}
private static List<MsWl_FuelDateInputmb> SetFuelDateInputList ( StringBuilder strSql )
{
var headList = new List<MsWl_FuelDateInputmb>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var data = new MsWl_FuelDateInputmb();
#region Set DB data to Object
data.GID = Convert.ToString(reader["GID"]);
data.STATION = Convert.ToString(reader["STATION"]);
data.BLSH = Convert.ToString(reader["BLSH"]);
data.ZH = Convert.ToString(reader["ZH"]);
data.KLX = Convert.ToString(reader["KLX"]);
data.CKR = Convert.ToString(reader["CKR"]);
data.CH = Convert.ToString(reader["CH"]);
data.JH = Convert.ToString(reader["JH"]);
data.YP = Convert.ToString(reader["YP"]);
data.FUEL = Convert.ToString(reader["FUEL"]);
data.PRICE = Convert.ToString(reader["PRICE"]);
data.AMOUNT = Convert.ToString(reader["AMOUNT"]);
data.YHED = Convert.ToString(reader["YHED"]);
data.SS = Convert.ToString(reader["SS"]);
data.YE = Convert.ToString(reader["YE"]);
data.YY = Convert.ToString(reader["YY"]);
data.DEPT = Convert.ToString(reader["DEPT"]);
data.JYTIME = Convert.ToString(reader["JYTIME"]);
data.inserted = Convert.ToString(reader["inserted"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
//从导入加入到加油记录
static public int AddADLFuel (string GID, string FeeList )
{
var _count = 0;
var strSql = new StringBuilder();
if (FeeList != "")
{
/*
strSql.Append(" insert into tMsWl_Port_FuelDate(GID,TRUCKNO,DRVCODE,FUELTYPE,FUELQTY,FUELDATE) ");
strSql.Append(" select GID,CH,(select drvcode from tMsWlDriver where drvname=CKR),YP,FUEL,JYTIME ");
strSql.Append(" from tmswl_fueldateinput where GID in(" + FeeList + ") ");
*/
strSql.Append(" update tmswl_fueldateinput set BSNO='"+GID+"' where GID in(" + FeeList + ") ");
Database db = DatabaseFactory.CreateDatabase();
_count = db.ExecuteNonQuery(CommandType.Text, strSql.ToString());
}
return _count;
}
//取消导入
static public int DelADLFuel ( string FeeList )
{
var _count = 0;
var strSql = new StringBuilder();
if (FeeList != "")
{
/*
strSql.Append(" delete from tMsWl_Port_FuelDate where GID in(" + FeeList + ") ");
* */
strSql.Append(" update tmswl_fueldateinput set BSNO='' where GID in(" + FeeList + ") ");
Database db = DatabaseFactory.CreateDatabase();
_count = db.ExecuteNonQuery(CommandType.Text, strSql.ToString());
}
return _count;
}
//重新计算总实际加油量
static public int MakeFuel(string GID)
{
var _count = 0;
var strSql = new StringBuilder();
var strSql2 = new StringBuilder();
if (GID != "")
{
/*
strSql.Append(" delete from tMsWl_Port_FuelDate where GID in(" + FeeList + ") ");
* */
strSql.Append(" update tmswl_adlfuel set RealFuel=isnull((select sum(FUEL) from tmswl_fueldateinput where isnull(bsno,'')<>'' and BSNO='" + GID + "'),0) where GID='" + GID + "'");
Database db = DatabaseFactory.CreateDatabase();
_count = db.ExecuteNonQuery(CommandType.Text, strSql.ToString());
strSql2.Append(" update tmswl_adlfuel set Amount=((select RatedFuel from VW_ADLFuelDate where GID='" + GID + "')-(select RealFuel from VW_ADLFuelDate where GID='" + GID + "'))*(FuelPrice_agio) where GID='" + GID + "'");
Database db2 = DatabaseFactory.CreateDatabase();
_count = db2.ExecuteNonQuery(CommandType.Text, strSql2.ToString());
}
return _count;
}
#endregion
}
}