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_HH_ZYController.cs

370 lines
15 KiB
C#

2 years ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using DSWeb.Areas.TruckMng.DAL.MsWl_HH_ZY;
using DSWeb.Areas.TruckMng.Models;
using DSWeb.Areas.TruckMng.Models.MsWl_HH_ZY;
using DSWeb.TruckMng.Comm.Cookie;
using DSWeb.TruckMng.Helper;
using DSWeb.TruckMng.Helper.Repository;
using HcUtility.Comm;
using HcUtility.Core;
using System.Data;
using System.Data.OleDb;
using System.IO;
using System.Text;
using System.Web.UI.MobileControls;
8 months ago
using DSWeb.SoftMng.Filter;
2 years ago
namespace DSWeb.Areas.TruckMng.Controllers
{
[JsonRequestBehavior]
public class MsWl_HH_ZYController : Controller
{
#region 基础界面
// GET: /TruckMng/MsWlTruck
public ActionResult Index()
{
return View();
}
//
// GET: /TruckMng/MsWlTruck/Edit
public ActionResult Edit()
{
return View();
}
//
// GET/TruckMng/MsWlTruck/GetDataList
#endregion
8 months ago
[SqlKeyWordsFilter(Type = "Action")]//sql 防注入过滤器
2 years ago
public ContentResult GetDataList(int start, int limit, string sort, string condition)
{
var dataList = MsWl_HH_ZYDAL.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 };
}
8 months ago
[SqlKeyWordsFilter(Type = "Action")]//sql 防注入过滤器
2 years ago
public ContentResult GetDataList_2(int start, int limit, string sort, string condition)
{
var dataList = MsWl_HH_ZYDAL.GetDataList_2(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 };
}
//
// GET/TruckMng/MsWlTruck/GetData/
8 months ago
[SqlKeyWordsFilter(Type = "Action")]//sql 防注入过滤器
2 years ago
public ContentResult GetData(string handle, string condition)
{
MsWl_HH_ZYmb head = null;
if (handle == "edit")
{
var list = MsWl_HH_ZYDAL.GetDataList(condition);
if (list.Count > 0)
head = list[0];
}
if (head == null)
{
head = new MsWl_HH_ZYmb();
}
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
//
// GET/TruckMng/MsWlTruck/Save
public ContentResult Save(string body, string delbody)
{
var BodyList = JsonConvert.Deserialize<List<MsWl_HH_ZYmb>>(body);
var DelBodyList = JsonConvert.Deserialize<List<MsWl_HH_ZYmb>>(delbody);
var modb = new ModelObjectRepository();
DBResult result = modb.SaveComm(
ModelObjectConvert<MsWl_HH_ZYmb>.ToModelObjectList(BodyList),
ModelObjectConvert<MsWl_HH_ZYmb>.ToModelObjectList(DelBodyList)
);
//刷新父窗口上的父节点
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
//Data = XXHDAL.GetData("M.ContractNo='" + head.ContractNo + "'")
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
/*
public ContentResult Delete(string data)
{
var head = JsonConvert.Deserialize<MsWlTruck>(data);
var modb = new ModelObjectDB();
DBResult result = modb.Delete(head);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult GetBodyList(string billno)
{
var condition = " TruckNo='" + billno + "' ";
List<MsWlTruckFuel> list = MsWlTruckDAL.GetBodyList(condition);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = list.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
#region 参照部分
public ContentResult GetDrvCodeList()
{
var list = MsWlTruckDAL.GetDrvCodeList(Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request));
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", data = list.ToList() });
return new ContentResult() { Content = json };
}
#endregion
*/
[HttpPost]
public ContentResult File ( string _Price_1, string _Price_2, string _Price_3 )
{
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) };
}
2 years ago
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) };
}
2 years ago
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。/r/n导入用excel表格需要是97-2003格式的xls(xlsx文件可能会导入失败)";
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 + "A3:X]", excelConn);
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_HH_ZYmb> headList;
//if (customerFieldName == "委托单位")
//{
var InsertCount = 0;
var UpdateCount = 0;
var UnKnowenTruckNo = "";
var isSucess = MsWl_HH_ZYDAL.ImportExcelData(Request, table, _Price_1, _Price_2, _Price_3, 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) };
}
/*}
else
{
var isSucess = MsWl_HH_ZYDAL.ImportExcelUpdateData(Request, table, out message, 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 = 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 ContentResult SetPrice ( string Price_1, string Price_2, string Price_3, string Pay_Amount_2, string GIdSql )
{
var modb = new ModelObjectDB();
var _str = " 1=1 AND GId in " + GIdSql;
DBResult result = MsWl_HH_ZYDAL.SetPrice(Price_1.Trim(), Price_2.Trim(), Price_3.Trim(), Pay_Amount_2.Trim(), _str);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult SetSettlement(string GIDList,string Amount_Settlement,string Type)
{
//var modb = new ModelObjectDB();
//var _str = " Where 1=1 AND GId in " + GIdSql;
DBResult result = MsWl_HH_ZYDAL.SetSettlement(GIDList.Trim(), Amount_Settlement.Trim(), Type);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult Submit(string GIDList)
{
DBResult result = MsWl_HH_ZYDAL.Submit(GIDList.Trim(), "1,6","2");
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult Repeal(string GIDList)
{
DBResult result = MsWl_HH_ZYDAL.Submit(GIDList.Trim(), "2", "1");
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult Reject(string GIDList)
{
DBResult result = MsWl_HH_ZYDAL.Submit(GIDList.Trim(), "2,0", "6");
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult Audit(string GIDList)
{
DBResult result = MsWl_HH_ZYDAL.Submit(GIDList.Trim(), "2", "0");
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
}