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/TruckMng/Controllers/LTJYDistanceController.cs

199 lines
7.5 KiB
C#

2 years ago
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using DSWeb.Areas.TruckMng.Models.CityDistance;
using DSWeb.Areas.CommMng.Models;
using DSWeb.TruckMng.Helper;
using DSWeb.TruckMng.Helper.Repository;
using Microsoft.Practices.EnterpriseLibrary.Data;
using HcUtility.Comm;
using HcUtility.Core;
8 months ago
using DSWeb.SoftMng.Filter;
2 years ago
namespace DSWeb.Areas.TruckMng.Controllers
{
/// <summary>
/// 良通捷运费用计划表
/// </summary>
public class LTJYDistanceController : Controller
{
//
// GET: /Import/RptImportFeedetail/
public ActionResult Index()
{
return View();
}
public ActionResult Edit()
{
return View();
}
public ContentResult GetDataList(int start, int limit, string sort, string condition)
{
var dataList = GetDataList(condition,sort);
var list = dataList.Skip(start).Take(limit);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
private static List<PC_LTJY_Distancemb> GetDataList(string strCondition, string sort)
{
var strSql = new StringBuilder();
strSql.Append(" select * from PC_LTJY_Distance ");
if (!string.IsNullOrEmpty(strCondition))
{
//strSql.Append(" where " + strCondition);
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
return SetData(strSql);
}
private static List<PC_LTJY_Distancemb> SetData(StringBuilder strSql)
{
var headList = new List<PC_LTJY_Distancemb>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var data = new PC_LTJY_Distancemb();
#region Set DB data to Object
data.id = Convert.ToString(reader["id"]);
data.NAME = Convert.ToString(reader["NAME"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
data.PRICETYPE = Convert.ToString(reader["PRICETYPE"]);
data.DISTANCE = Convert.ToString(reader["DISTANCE"]);
data.PRICE = Convert.ToString(reader["PRICE"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public ContentResult GetPriceList(string CUSTOMERNAME, string DetiNation, string BsType,string BLTYPE,string Ton)
{
PC_LTJY_Distancemb head = null;
head = GetPriceList_P(CUSTOMERNAME, DetiNation, BsType);
if (head == null)
{
head = new PC_LTJY_Distancemb();
head.CUSTOMERNAME = "" ;
head.NAME = "";
head.PRICETYPE = "";
head.PRICE = "0";
}
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
private static PC_LTJY_Distancemb GetPriceList_P(string CUSTOMERNAME, string DetiNation,string BsType)
{
var strSql = new StringBuilder();
strSql.Append(" declare @a int ");
strSql.Append(" declare @CUSTOMERNAME varchar(50) ");
strSql.Append(" declare @DetiNation varchar(50) ");
strSql.Append(" declare @BsType varchar(50) ");
strSql.Append(" set @CUSTOMERNAME='"+CUSTOMERNAME+"' ");
strSql.Append(" set @a=(select count(*) from PC_LTJY_Distance where CUSTOMERNAME=@CUSTOMERNAME and NAME=@DetiNation) ");
strSql.Append(" set @DetiNation='"+DetiNation+"' ");
strSql.Append(" set @BsType='"+BsType+"' ");
strSql.Append(" if @a>0 ");
strSql.Append(" begin ");
if (BsType == "") {
strSql.Append(" select top 1 * from PC_LTJY_Distance where CUSTOMERNAME=@CUSTOMERNAME and NAME=@DetiNation order by price ");
}
else
{
strSql.Append(" select top 1 * from PC_LTJY_Distance where CUSTOMERNAME=@CUSTOMERNAME and PRICETYPE=@BsType and NAME=@DetiNation order by price ");
}
strSql.Append(" END ");
strSql.Append(" else ");
strSql.Append(" BEGIN ");
if (BsType == "")
{
strSql.Append(" select top 1 * from PC_LTJY_Distance where CUSTOMERNAME='' and NAME=@DetiNation order by price ");
}
else
{
strSql.Append(" select top 1 * from PC_LTJY_Distance where CUSTOMERNAME='' and PRICETYPE=@BsType and NAME=@DetiNation order by price ");
}
strSql.Append(" END ");
return SetData1(strSql);
}
private static PC_LTJY_Distancemb SetData1(StringBuilder strSql)
{
var headList = new List<PC_LTJY_Distancemb>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var data = new PC_LTJY_Distancemb();
#region Set DB data to Object
data.id = Convert.ToString(reader["id"]);
data.NAME = Convert.ToString(reader["NAME"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
data.PRICETYPE = Convert.ToString(reader["PRICETYPE"]);
data.DISTANCE = Convert.ToString(reader["DISTANCE"]);
data.PRICE = Convert.ToString(reader["PRICE"]);
#endregion
headList.Add(data);
}
reader.Close();
}
if (headList.Count > 0)
{
return headList[0];
}
else { return null; }
}
public ContentResult Save(string ProjectBody, string ProjectDelBody)
{
var ProjectBodyList = JsonConvert.Deserialize<List<PC_LTJY_Distancemb>>(ProjectBody);
var ProjectDelBodyList = JsonConvert.Deserialize<List<PC_LTJY_Distancemb>>(ProjectDelBody);
var modb = new ModelObjectRepository();
DBResult result = modb.SaveComm(
ModelObjectConvert<PC_LTJY_Distancemb>.ToModelObjectList(ProjectBodyList),
ModelObjectConvert<PC_LTJY_Distancemb>.ToModelObjectList(ProjectDelBodyList)
);
//刷新父窗口上的父节点
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
//Data = XXHDAL.GetData("M.ContractNo='" + head.ContractNo + "'")
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
}