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/MsWlDriverController.cs

656 lines
23 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.Linq;
using System.Web.Mvc;
using DSWeb.Areas.TruckMng.DAL.MsWlDriver;
using DSWeb.Areas.TruckMng.Models;
using DSWeb.TruckMng.Comm.Cookie;
using DSWeb.TruckMng.Helper;
using HcUtility.Comm;
using HcUtility.Core;
using System.IO;
using System.Collections.Generic;
using DSWeb.TruckMng.Helper.Repository;
namespace DSWeb.Areas.TruckMng.Controllers
{
[JsonRequestBehavior]
public class MsWlDriverController : Controller
{
//
// GET: /TruckMng/MsWlDriver
public ActionResult Index()
{
return View();
}
//
// GET: /TruckMng/MsWlDriver/Edit
public ActionResult Edit()
{
return View();
}
public ActionResult Salary ( )
{
return View();
}
//
// GET/TruckMng/MsWlDriver/GetDataList
#region 司机信息
public ContentResult GetDataList(int start, int limit, string sort, string condition)
{
var dataList = MsWlDriverDAL.GetDataList(condition, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request),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/MsWlDriver/GetData/
public ContentResult GetData(string handle, string condition)
{
MsWlDriver head = null;
if (handle == "edit")
{
var list = MsWlDriverDAL.GetDataList(condition, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request));
if (list.Count > 0)
head = list[0];
}
if (head == null)
{
head = new MsWlDriver();
}
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
//
// GET/TruckMng/MsWlDriver/Save
public ContentResult Save(string opstatus, string data)
{
MsWlDriver head = JsonConvert.Deserialize<MsWlDriver>(data);
if (opstatus == "add")
{
head.DbOperationType = DbOperationType.DbotIns;
head.GID = Guid.NewGuid().ToString();
if (head.OrgCode==null||head.OrgCode=="")
{
head.OrgCode = CookieConfig.GetCookie_OrgCode(Request);
}
}
else if (opstatus == "edit")
{
head.DbOperationType = DbOperationType.DbotUpd;
}
else
{
head.DbOperationType = DbOperationType.DbotDel;
}
var modb = new ModelObjectDB();
DBResult result = modb.Save(head);
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = MsWlDriverDAL.GetData("GID='" + head.GID + "'", Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request))
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult Delete(string data)
{
var head = JsonConvert.Deserialize<MsWlDriver>(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) };
}
#endregion
#region 司机模块附件
public ContentResult GetFileList(string PID)
{
var dataList = MsWlDriverDAL.GetUpLoadFileList("PID='"+PID+"'");
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult SaveFile(string bsno, string body)
{
int iResult = 0;
var bodyList = JsonConvert.Deserialize<List<Models.MsUpLoadFile>>(body);
var result = new DBResult();
if (bodyList != null)
{
iResult = MsWlDriverDAL.SaveFileList(bodyList, bsno);
}
if (iResult == 1)
{
result.Success = true;
result.Message = "更新成功!";
}
else if (iResult == 0)
{
result.Success = false;
result.Message = "出现错误,未更新!";
}
else if (iResult == -1)
{
result.Success = false;
result.Message = "有异常,插入失败!";
}
else if (iResult == -2)
{
result.Success = false;
result.Message = "插入异常,事务已回滚成功!";
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
// Data = MsChFeeDAL.GetDataList(headData.BillNo, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request))
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
[HttpPost]
public ContentResult UploadFile()
{
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["LoadImage"];
var fileGID = Request.Form["fileGid"];
if (file == null)
{
jsonRespose.Success = false;
jsonRespose.Message = "上传文件发生未知错误,请重新上传";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
var path = Server.MapPath("../../UploadFiles/MsDriver");
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 = "上传文件发生未知错误,请重新上传";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
try
{
var message = string.Empty;
var isSucess = MsWlDriverDAL.UpdateFileData(Request, filename,fileGID,out message);
if (!isSucess)
{
jsonRespose.Success = false;
jsonRespose.Message = message;
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
var json = JsonConvert.Serialize(new { success = true, Message = "上传成功!", data = filename });
return new ContentResult() { Content = json };
}
catch (Exception)
{
jsonRespose.Success = false;
jsonRespose.Message = "上传文件出错,请确认文件正确性";
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
public ContentResult DeleteUploadFile(string data)
{
int iResult = 0;
var bodyList = data;
var result = new DBResult();
if (bodyList != "" || bodyList != null)
{
iResult = MsWlDriverDAL.DeleteUploadFile(bodyList);
}
if (iResult == 1)
{
result.Success = true;
result.Message = "删除成功!";
}
else if (iResult == 0)
{
result.Success = false;
result.Message = "出现错误,未删除!";
}
else if (iResult == -1)
{
result.Success = false;
result.Message = "有异常,删除失败!";
}
else if (iResult == -2)
{
result.Success = false;
result.Message = "删除异常,事务已回滚成功!";
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
// Data = MsChFeeDAL.GetDataList(headData.BillNo, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request))
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#endregion
#region 司机工资提成
public ContentResult GetDataList_Salary ( int start, int limit, string sort, string condition )
{
var dataList = MsWlDriver_SalaryDAL.GetDataList(condition, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request), 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/MsWlDriver/GetData/
public ContentResult GetData_Salary ( string handle, string condition )
{
MsWlDriver head = null;
if (handle == "edit")
{
var list = MsWlDriverDAL.GetDataList(condition, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request));
if (list.Count > 0)
head = list[0];
}
if (head == null)
{
head = new MsWlDriver();
}
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
//
// GET/TruckMng/MsWlDriver/Save
public ContentResult SaveList_Salary ( string data )
{
var dataList = JsonConvert.Deserialize<List<MsWlDriver_Salary>>(data);
foreach (var _d in dataList){
if (_d.ACCDATE.Length > 7) {
_d.ACCDATE = _d.ACCDATE.Substring(0, 7);
}
if (_d.GID == "" || _d.GID == "*")
{
_d.DbOperationType = DbOperationType.DbotIns;
_d.ModelUIStatus = "I";
_d.GID = System.Guid.NewGuid().ToString();
}
else
{
_d.DbOperationType = DbOperationType.DbotUpd;
_d.ModelUIStatus = "E";
}
}
var result = new DBResult();
var _L = ModelObjectConvert<MsWlDriver_Salary>.ToModelObjectList(dataList);
//var _DL = ModelObjectConvert<MsWlPcHead_ADLEdit>.ToModelObjectList(DeldataList);
var modb = new ModelObjectRepository();
result = modb.SaveHead(_L);
//刷新父窗口上的父节点
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 DeleteSalary ( string data )
{
int iResult = 0;
var bodyList = data;
var result = new DBResult();
if (bodyList != "" || bodyList != null)
{
iResult = MsWlDriver_SalaryDAL.Delete(bodyList);
}
if (iResult == 1)
{
result.Success = true;
result.Message = "删除成功!";
}
else if (iResult == 0)
{
result.Success = false;
result.Message = "出现错误,未删除!";
}
else if (iResult == -1)
{
result.Success = false;
result.Message = "有异常,删除失败!";
}
else if (iResult == -2)
{
result.Success = false;
result.Message = "删除异常,事务已回滚成功!";
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
// Data = MsChFeeDAL.GetDataList(headData.BillNo, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request))
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult MakeSalary ( string ACCDATE,string EXPDATEBGN,string EXPDATEEND )
{
var result = new DBResult();
var DrvList = MsWlDriverDAL.GetDataList(" DrvClass<>'3' ", Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request), "");
//根据每个司机的devcode和expdatebgn,expdateend 合计
var DrvCodeList = "";
foreach (var _d in DrvList) {
if (DrvCodeList == "")
{
DrvCodeList = "'" + _d.DrvCode + "'";
}
else {
DrvCodeList += ",'" + _d.DrvCode + "'";
}
}
var SalaryList = MsWlDriver_SalaryDAL.GetSalary(DrvCodeList, EXPDATEBGN, EXPDATEEND);
var InsertSalaryList = new List<MsWlDriver_Salary>();
foreach (var _d in DrvList)
{
var Salaryhead = new MsWlDriver_Salary();
var Salary = SalaryList.Find(( sd ) => { return sd.DRVCODE == _d.DrvCode; });
if (Salary != null)
{
Salaryhead.GID = System.Guid.NewGuid().ToString();
Salaryhead.DRVCODE = Salary.DRVCODE;
Salaryhead.ACCDATE = ACCDATE;
Salaryhead.EXPDATEBGN = EXPDATEBGN;
Salaryhead.EXPDATEEND = EXPDATEEND;
Salaryhead.AMOUNT_0 = Salary.AMOUNT_0;
Salaryhead.BASESALARY = Salary.BASESALARY;
if (Salaryhead.BASESALARY == "") { Salaryhead.BASESALARY = "0"; }
Salaryhead.DbOperationType = DbOperationType.DbotIns;
Salaryhead.ModelUIStatus = "I";
InsertSalaryList.Add(Salaryhead);
}
else {
Salaryhead.GID = System.Guid.NewGuid().ToString();
Salaryhead.DRVCODE = _d.DrvCode;
Salaryhead.ACCDATE = ACCDATE;
Salaryhead.EXPDATEBGN = EXPDATEBGN;
Salaryhead.EXPDATEEND = EXPDATEEND;
Salaryhead.AMOUNT_0 = "0";
Salaryhead.BASESALARY = _d.BASESALARY;
if (Salaryhead.BASESALARY == "") { Salaryhead.BASESALARY = "0"; }
Salaryhead.DbOperationType = DbOperationType.DbotIns;
Salaryhead.ModelUIStatus = "I";
InsertSalaryList.Add(Salaryhead);
}
}
if (InsertSalaryList.Count > 0) {
var _L = ModelObjectConvert<MsWlDriver_Salary>.ToModelObjectList(InsertSalaryList);
var modb = new ModelObjectRepository();
result = modb.SaveHead(_L);
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
// Data = MsChFeeDAL.GetDataList(headData.BillNo, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request))
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult MakeSalary_List ( string data )
{
var dataList = JsonConvert.Deserialize<List<MsWlDriver_Salary>>(data);
var result = new DBResult();
/*
var DrvCodeList = "";
foreach (var _d in dataList)
{
if (DrvCodeList == "")
{
DrvCodeList = "'" + _d.DRVCODE + "'";
}
else
{
DrvCodeList += ",'" + _d.DRVCODE + "'";
}
}
*/
foreach (var _d in dataList)
{
if (_d.GID == "")
{
_d.GID = System.Guid.NewGuid().ToString();
_d.DbOperationType = DbOperationType.DbotIns;
_d.ModelUIStatus = "I";
}
else {
_d.DbOperationType = DbOperationType.DbotUpd;
_d.ModelUIStatus = "E";
}
if (_d.ACCDATE.Length > 7)
{
_d.ACCDATE = _d.ACCDATE.Substring(0, 7);
}
if (_d.ISLOCK == "1")
{
continue;
}
var DrvList = MsWlDriverDAL.GetDataList(" DrvCode ='"+_d.DRVCODE+"' ", Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request), "");
var SalaryList = MsWlDriver_SalaryDAL.GetSalary("'"+_d.DRVCODE+"'", _d.EXPDATEBGN, _d.EXPDATEEND);
var InsertSalaryList = new List<MsWlDriver_Salary>();
var Salary = SalaryList.Find(( sd ) => { return sd.DRVCODE == _d.DRVCODE; });
var _Drv = DrvList.Find(( Drv ) => { return Drv.DrvCode == _d.DRVCODE; });
if (Salary != null)
{
//_d.DRVCODE = Salary.DRVCODE;
//Salaryhead.ACCDATE = ACCDATE;
//Salaryhead.EXPDATEBGN = EXPDATEBGN;
//Salaryhead.EXPDATEEND = EXPDATEEND;
_d.BASESALARY = Salary.BASESALARY;
_d.AMOUNT_0 = Salary.AMOUNT_0;
_d.BONUS = Convert.ToString((Convert.ToDecimal(_d.AMOUNT_0) - Convert.ToDecimal(_d.RKF)) * 0.1M);
_d.AMOUNT = Convert.ToString(Convert.ToDecimal(_d.BASESALARY) + Convert.ToDecimal(_d.BONUS));
_d.SETTLEMENT = _d.AMOUNT;
}
else
{
_d.BASESALARY = "0";
if (_Drv != null) {
if (_Drv.BASESALARY != "") {
_d.BASESALARY = _Drv.BASESALARY;
}
}
_d.AMOUNT_0 = "0";
_d.BONUS = Convert.ToString((Convert.ToDecimal(_d.AMOUNT_0) - Convert.ToDecimal(_d.RKF)) * 0.1M);
_d.AMOUNT = Convert.ToString(Convert.ToDecimal(_d.BASESALARY) + Convert.ToDecimal(_d.BONUS));
_d.SETTLEMENT = _d.AMOUNT;
}
}
if (dataList.Count > 0)
{
var _L = ModelObjectConvert<MsWlDriver_Salary>.ToModelObjectList(dataList);
var modb = new ModelObjectRepository();
result = modb.SaveHead(_L);
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
// Data = MsChFeeDAL.GetDataList(headData.BillNo, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request))
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult PayandLock (string PAYTYPE, string data )
{
var dataList = JsonConvert.Deserialize<List<MsWlDriver_Salary>>(data);
var result = new DBResult();
foreach (var _d in dataList)
{
if (_d.GID == "")
{
_d.GID = System.Guid.NewGuid().ToString();
_d.DbOperationType = DbOperationType.DbotIns;
_d.ModelUIStatus = "I";
}
else
{
_d.DbOperationType = DbOperationType.DbotUpd;
_d.ModelUIStatus = "E";
}
if (_d.ACCDATE.Length > 7)
{
_d.ACCDATE = _d.ACCDATE.Substring(0, 7);
}
if (PAYTYPE == "1")
{
//_d.SETTLEMENT = _d.AMOUNT;
_d.ISLOCK = "1";
}
else {
//_d.SETTLEMENT = "0";
_d.ISLOCK = "0";
}
}
if (dataList.Count > 0)
{
var _L = ModelObjectConvert<MsWlDriver_Salary>.ToModelObjectList(dataList);
var modb = new ModelObjectRepository();
result = modb.SaveHead(_L);
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
// Data = MsChFeeDAL.GetDataList(headData.BillNo, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request))
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#endregion
#region 参照部分
#endregion
}
}