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/MsWl_ADL_FuelTruckListContr...

535 lines
21 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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.MsWl_Port;
using DSWeb.Areas.TruckMng.DAL.MsWl_Port;
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;
using DSWeb.Areas.CommMng.DAL;
using System.IO;
using System.Data.OleDb;
using DSWeb.TruckMng.Comm.Cookie;
using WebSqlHelper;
using System.Data.Common;
using DSWeb.SoftMng.Filter;
namespace DSWeb.Areas.TruckMng.Controllers
{
/// <summary>
/// 项目信息明细
/// </summary>
public class MsWl_ADL_FuelTruckListController : Controller
{
//
// GET: /Import/RptImportFeedetail/
public ActionResult Index()
{
return View();
}
public ActionResult Edit()
{
return View();
}
[SqlKeyWordsFilter(Type = "Action")]//sql 防注入过滤器
public ContentResult GetDataList ( int start, int limit, string sort, string condition )
{
var dataList = MsWl_ADLDAL.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 };
}
[SqlKeyWordsFilter(Type = "Action")]//sql 防注入过滤器
public ContentResult GetData(string handle, string condition)
{
MsWl_ADLFuelmb headData = null;
if (handle == "add")
{
headData = new MsWl_ADLFuelmb();
//headData.GID = PubSysDAL.GetBillNo("0123");
headData.AMOUNT = "0";
headData.FUELPRICE = "5";
headData.FUELPRICE_AGIO = "4";
headData.FUELRATE = "0";
headData.OVERLOADMIL = "0";
headData.REALFUEL = "0";
headData.RATEDFUEL = "0";
}
if (handle == "edit")
{
var list = MsWl_ADLDAL.GetDataList(condition,"");
if (list.Count > 0)
headData = list[0];
}
if (headData == null)
{
headData = new MsWl_ADLFuelmb();
}
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = headData });
return new ContentResult() { Content = json };
}
public ContentResult Save ( string opstatus, string data)
{
var head = JsonConvert.Deserialize<MsWl_ADLFuelmb>(data);
if (opstatus == "add")
{
head.GID = PubSysDAL.GetBillNo("0123");
head.DbOperationType = DbOperationType.DbotIns;
head.ModelUIStatus = "I";
}
else if (opstatus == "edit")
{
head.DbOperationType = DbOperationType.DbotUpd;
head.ModelUIStatus = "E";
}
else
{
head.DbOperationType = DbOperationType.DbotDel;
}
var modb = new ModelObjectRepository();
DBResult result = modb.Save(head);
var _count = MsWl_ADLDAL.MakeFuel(head.GID);
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = MsWl_ADLDAL.GetData(" GID='"+head.GID+"' ")
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult Delete ( string data )
{
var head = JsonConvert.Deserialize<MsWl_ADLFuelmb>(data);
var modb = new ModelObjectDBBill();
DBResult result = modb.Delete(head,
"Update tMsWl_FUELDateInput set BSNO='' where BSNO='" + head.GID + "'");
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult DeleteDetail ( string FuelDateInputList )
{
if (string.IsNullOrEmpty(FuelDateInputList)) {
var jsonRespose1 = new JsonResponse { Success = false, Message = "没有选中的内容" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose1) };
}
var _c = BasicDataRefDAL.ExecSql("delete from tMsWl_FUELDateInput where isnull(BSNO,'')='' and GID in(" + FuelDateInputList + ")");
var result = new DBResult();
if (_c > 0)
{
result.Success = true;
result.Message = "";
}
else {
result.Success = false;
result.Message = "没有可删除的导入信息,相关信息已经被加入统计列表。";
}
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#region 20160623 为爱德林增加的 容纳导入的加油信息的模块
public ContentResult GetFuelDateInputList ( int start, int limit, string sort, string condition )
{
var dataList = MsWl_ADLDAL.GetFuelDateInputList(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 };
}
[HttpPost]
public ContentResult File ( )
{
var jsonRespose = new JsonResponse { Success = false, Message = "" };
if (Request.Files.Count != 1)
{
jsonRespose.Success = false;
jsonRespose.Message = "请选择上传的文件";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
var file = Request.Files["file"];
if (file == null)
{
jsonRespose.Success = false;
jsonRespose.Message = "上传文件发生未知错误,请重新上传";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
if (Convert.ToString(Session["COMPANYID"]).ToString().Trim() == "" || Convert.ToString(Session["USERID"]).ToString().Trim() == "" || Convert.ToString(Session["CODENAME"]).ToString().Trim() == "" || Convert.ToString(Session["SHOWNAME"]).ToString().Trim() == "" || Convert.ToString(Session["DEPTNAME"]).ToString().Trim() == "")
{
var jsonRespose2 = new JsonResponse { Success = false, Message = "登录超时,请退出系统重新登录!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) };
}
string ext = Path.GetExtension(file.FileName).ToLower();
if (ext == ".asp" || ext == ".aspx")
{
jsonRespose.Success = false;
jsonRespose.Message = "不允许上传ASP或ASPX文件";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
var path = Server.MapPath("../../UploadFiles/Bs");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
var size = file.ContentLength;
var name = Path.GetFileName(file.FileName);
var usercode = CookieConfig.GetCookie_UserCode(Request);
string filename = path + "\\" + usercode + DateTime.Now.ToString("yyyyMMddHHmmssfff") + name;
if (System.IO.File.Exists(filename))
{
System.IO.File.Delete(filename);
}
file.SaveAs(filename);
if (!System.IO.File.Exists(filename))
{
jsonRespose.Success = false;
jsonRespose.Message = "上传的Excel不包含数据01";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
List<string> sheets = ExcelSheetName(filename);
if (sheets.Count == 0)
{
jsonRespose.Success = false;
jsonRespose.Message = filename + " 上传的Excel不包含数据02";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
try
{
var sheetname = sheets[0];
string excelConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filename +
";Extended Properties=Excel 8.0;";
OleDbDataAdapter oada = new OleDbDataAdapter("select * from [" + sheetname + "]", excelConn);//A2:AI
DataSet ds = new DataSet();
oada.Fill(ds);
if (ds.Tables.Count == 0)
{
jsonRespose.Success = false;
jsonRespose.Message = "上传的Excel不包含数据03";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
var table = ds.Tables[0];
if (table.Rows.Count == 0 || table.Rows.Count == 1)
{
jsonRespose.Success = false;
jsonRespose.Message = "上传的Excel不包含数据04";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
//var customerFieldName = table.Columns[0].ColumnName;
//if (customerFieldName != "订单列表")
//{
// jsonRespose.Success = false;
// jsonRespose.Message = "上传的Excel不是标准的格式请重新选择";
// return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
//}
var message = string.Empty;
List<MsWl_FuelDateInputmb> headList;
//if (customerFieldName == "委托单位")
//{
var InsertCount = 0;
var UpdateCount = 0;
var UnKnowenTruckNo = "";
var isSucess = ADL_ExcelData(Request, table, out message, out InsertCount, out UpdateCount, out UnKnowenTruckNo, out headList);
if (!isSucess)
{
jsonRespose.Success = false;
jsonRespose.Message = message;
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
var json = JsonConvert.Serialize(new
{
success = true,
Message = "上传成功,共处理" + Convert.ToString(headList.Count) + "条记录,其中新增" + Convert.ToString(InsertCount)
+ "个,更新" + Convert.ToString(UpdateCount) + "个。" + UnKnowenTruckNo,
data = headList.ToList()
});
return new ContentResult() { Content = json };
}
catch (Exception e)
{
jsonRespose.Success = false;
jsonRespose.Message = "读取Excel文件出错 " + e.Message;
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
public List<string> ExcelSheetName ( string filepath )
{
var al = new List<string>();
try
{
string strConn;
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filepath + ";Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
DataTable sheetNames = conn.GetOleDbSchemaTable
(System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
conn.Close();
foreach (DataRow dr in sheetNames.Rows)
{
al.Add(dr[2].ToString());
}
}
catch (Exception)
{
return new List<string>();
}
return al;
}
public static bool ADL_ExcelData ( HttpRequestBase request, DataTable table, out string msg,
out Int32 InsertCount, out Int32 UpdateCount, out string UnKnowenTruckNo, out List<MsWl_FuelDateInputmb> headList )
{
var isSucess = false;
msg = "";
headList = new List<MsWl_FuelDateInputmb>();
if (table == null) throw new ArgumentNullException("table");
var billNoList = new List<string>();
Database db = DatabaseFactory.CreateDatabase();
InsertCount = 0;
UpdateCount = 0;
UnKnowenTruckNo = "";
var UnKnowenDrvName = "";
using (DbConnection connection = db.CreateConnection())
//using (SqlTransaction idbTran = SqlHelper.BeginTransaction(SqlHelper.ConnectionStringLocalTransaction))
{
connection.Open();
try
{
var orgCode = CookieConfig.GetCookie_OrgCode(request);
var userCode = CookieConfig.GetCookie_UserCode(request);
var userName = CookieConfig.GetCookie_UserName(request);
var _i = -1;
//var ExpDate = "";
//var _ADLList = new List<MsWl_FuelDateInputmb>();
foreach (DataRow row in table.Rows)
{
_i++;
var _p = 0;
var _ADL = new MsWl_FuelDateInputmb();
//_ADL.ZH = Convert.ToString(row[_p + 0]);
_ADL.GID = System.Guid.NewGuid().ToString();
_ADL.STATION = Convert.ToString(row[_p + 0]);
_ADL.BLSH = Convert.ToString(row[_p + 1]);
_ADL.ZH = Convert.ToString(row[_p + 3]);
_ADL.KLX = Convert.ToString(row[_p + 5]);
_ADL.CKR = Convert.ToString(row[_p + 6]);
_ADL.CH = Convert.ToString(row[_p + 7]);
_ADL.JH = Convert.ToString(row[_p + 8]);
_ADL.YP = Convert.ToString(row[_p + 9]);
_ADL.FUEL = Convert.ToString(row[_p + 11]);
_ADL.PRICE = Convert.ToString(row[_p + 13]);
_ADL.AMOUNT = Convert.ToString(row[_p + 14]);
_ADL.YHED = Convert.ToString(row[_p + 15]);
_ADL.SS = Convert.ToString(row[_p + 17]);
_ADL.YE = Convert.ToString(row[_p + 18]);
_ADL.YY = Convert.ToString(row[_p + 19]);
_ADL.DEPT = Convert.ToString(row[_p + 20]);
_ADL.JYTIME = Convert.ToString(row[_p + 21]);
_ADL.inserted = "";
var TruckNo = _ADL.CH;
//TruckNo = TruckNo.Replace("T", "");
TruckNo = TruckNo.Replace("-", "");
TruckNo = TruckNo.Replace("金额:", "");
TruckNo = TruckNo.Trim();
if (TruckNo.Trim() == "")
{
continue;
}
var objTruckNo = db.ExecuteScalar(CommandType.Text, "select TruckNo from tMsWlTruck where TruckNo='" + TruckNo + "'");
var _TruckNo = Convert.ToString(objTruckNo);
if (string.IsNullOrEmpty(_TruckNo))
{
if (UnKnowenTruckNo == "") { UnKnowenTruckNo = "有如下工作编号的车辆在系统中不存在,请添加后重新导入:" + TruckNo; }
else UnKnowenTruckNo = UnKnowenTruckNo + "/" + TruckNo;
continue;
}
DbTransaction idbTran = connection.BeginTransaction();
//var TotalMil = Convert.ToString(row[3]);
//_TruckNo //第一列
/*
var Ctn20 = Convert.ToString(row[_p + 5]);
var Ctn40 = Convert.ToString(row[_p + 6]);
var Ctn45 = Convert.ToString(row[_p + 7]);
var Mov = Convert.ToString(row[_p + 9]);
*/
string strCheckRow = "select gid from tmswl_fueldateinput where CH = '" + _ADL.CH + "' and JYTIME='" + _ADL.JYTIME + "'";
object statusObj = SqlHelper.ExecuteScalar(db.ConnectionString, CommandType.Text, strCheckRow, null);
if (statusObj == null)
{
//_ADL.DbOperationType = DbOperationType.DbotIns;
}
else
{
_ADL.GID = statusObj.ToString();
_ADL.inserted = "0";
//_ADL.DbOperationType = DbOperationType.DbotUpd;
}
headList.Add(_ADL);
if (statusObj == null)
{
#region 托单数据生成
InsertCount++;
idbTran.Commit();
#endregion
}
else if (statusObj != null)
{
#region 托单数据生成,update
UpdateCount++;
idbTran.Commit();
#endregion
}
}
var modb = new ModelObjectRepository();
DBResult result = modb.SaveComm(
ModelObjectConvert<MsWl_FuelDateInputmb>.ToModelObjectList(headList),
ModelObjectConvert<MsWl_FuelDateInputmb>.ToModelObjectList(null)
);
isSucess = true;
}
catch (Exception exception)
{
//idbTran.Rollback();
isSucess = false;
msg = exception.Message;
}
}
UnKnowenTruckNo = UnKnowenTruckNo + " " + UnKnowenDrvName;
//根据插入情况修改inserted的值
/*
using (DbConnection connection = db.CreateConnection())
{
foreach (var _ADL in headList)
{
DbTransaction idbTran2 = connection.BeginTransaction();
string strCheckRow2 = "select gid from tMsWl_Port_FuelDate where GID = '" + _ADL.GID + "' ";
object statusObj2 = SqlHelper.ExecuteScalar(db.ConnectionString, CommandType.Text, strCheckRow2, null);
if (statusObj2 == null)
{
_ADL.inserted = "0";
}
else
{
_ADL.inserted = "1";
}
idbTran2.Commit();
}
}
*/
return isSucess;
}
public ContentResult AddADLFuel ( string GID,string GIDList )
{
var _count = 0;
//var corpcode = CookieConfig.GetCookie_OrgCode(Request);
//var userid = CookieConfig.GetCookie_UserId(Request);
_count = MsWl_ADLDAL.AddADLFuel(GID,GIDList);
var _success = false;
if (_count > 0)
{
_success = true;
}
_count = _count + MsWl_ADLDAL.MakeFuel(GID);
var json = JsonConvert.Serialize(new { Success = _success, Message = "查询成功", totalCount = _count });
return new ContentResult() { Content = json };
}
public ContentResult DelADLFuel(string GID, string GIDList)
{
var _count = 0;
//var corpcode = CookieConfig.GetCookie_OrgCode(Request);
//var userid = CookieConfig.GetCookie_UserId(Request);
_count = MsWl_ADLDAL.DelADLFuel(GIDList);
var _success = false;
if (_count > 0)
{
_success = true;
}
_count = _count+MsWl_ADLDAL.MakeFuel(GID);
var json = JsonConvert.Serialize(new { Success = _success, Message = "查询成功", totalCount = _count });
return new ContentResult() { Content = json };
}
#endregion
}
}