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

370 lines
14 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;
namespace DSWeb.Areas.TruckMng.Controllers
{
[JsonRequestBehavior]
public class MsWl_HH_ZY_AuditController : Controller
{
//
// GET: /TruckMng/MsWlTruck
public ActionResult Index()
{
return View();
}
//
// GET: /TruckMng/MsWlTruck/Edit
public ActionResult Edit()
{
return View();
}
//
// GET/TruckMng/MsWlTruck/GetDataList
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 };
}
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/
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()
{
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 + "A3:H]", 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,"0","0","0", 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)
{
jsonRespose.Success = false;
jsonRespose.Message = "读取Excel文件出错请确认文件正确性";
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 Amount_2, string GIdSql)
{
var modb = new ModelObjectDB();
var _str = " Where 1=1 AND GId in " + GIdSql;
DBResult result = MsWl_HH_ZYDAL.SetPrice(Price_1.Trim(), Price_2.Trim(),"", 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) };
}
}
}