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.

692 lines
23 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using DSWeb.Areas.TruckMng.Models.Comm;
using DSWeb.Areas.CommMng.DAL;
using DSWeb.Areas.Import.DAL.Finance;
using DSWeb.Areas.Import.Models.Finance;
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.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.Areas.CommMng.Models;
namespace DSWeb.Areas.Import.Controllers
{
[JsonRequestBehavior]
public class FinanceController : Controller
{
//
// GET: /Import/FinanceOut
public ActionResult Index()
{
return View();
}
//
// GET: /Import/FinanceOut/Edit
public ActionResult Edit()
{
return View();
}
public ActionResult AppIndex()
{
return View();
}
//
// GET: /Import/FinanceOut/Edit
public ActionResult AppEdit()
{
return View();
}
public ActionResult BankStlIndex()
{
return View();
}
public ActionResult BankStlEdit()
{
return View();
}
// Get:/Import/FinanceOut/GetDataList
public ContentResult GetDataList(int start, int limit, string condition, string sort)
{
var _condition = condition;
List<Financemb> list = FinanceDAL.GetDataList(_condition, sort);
var listpage = list.Skip(start).Take(limit);
var json = JsonConvert.Serialize
(new { Success = true, Message = "查询成功", totalCount = list.Count, data = listpage.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetData(string handle, string condition)
{
Financemb head = null;
if (handle == "edit")
{
var _condition = condition;
List<Financemb> list = FinanceDAL.GetDataList(_condition, "");
if (list.Count > 0)
head = list[0];
}
if (head == null)
{
head = new Financemb();
head.OP = Convert.ToString(Session["USERID"]);
head.OPREF = Convert.ToString(Session["SHOWNAME"]);
}
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
public ContentResult Delete(string data)
{
var head = JsonConvert.Deserialize<Financemb>(data);
var isfee = FinanceDAL.GetFeeCount(head.F_NO);
if (isfee)
{
var jsonRespose = new JsonResponse { Success = false, Message = "此票业务存在费用,请先删除费用才能删除此票业务!" };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var BSNO = head.F_NO;
var modb = new ModelObjectDB();
DBResult result = modb.Delete(head);
if (result.Success == true) {
FinanceDAL.DeleteDetail(BSNO);
var dataList = FinanceDAL.GetBodyList("c.F_NO='" + BSNO + "'");
result = FinanceDAL.DelBill(BSNO, dataList);
}
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
}
public ContentResult Save(string opstatus, string data, string FinanceFee, string FinanceBank)
{
Financemb head = JsonConvert.Deserialize<Financemb>(data);
var FinanceFeeList = JsonConvert.Deserialize<List<MsChFee>>(FinanceFee);
var FinanceFeeDelList = JsonConvert.Deserialize<List<MsChFee>>("");
var FinanceBankList = JsonConvert.Deserialize<List<FinanceBank>>(FinanceBank);
if (opstatus == "add")
{
head.DbOperationType = DbOperationType.DbotIns;
head.ModelUIStatus = "I";
head.F_NO = PubSysDAL.GetBillNo("0206"); //获取GID
}
else if (opstatus == "edit")
{
head.DbOperationType = DbOperationType.DbotUpd;
head.ModelUIStatus = "E";
}
else
{
head.DbOperationType = DbOperationType.DbotDel;
}
if (head.STARTDATE == "") head.STARTDATE = null;
if (head.ENDDATE == "") head.ENDDATE = null;
if (head.BANKENDDATE == "") head.BANKENDDATE = null;
var modb = new ModelObjectRepository();
DBResult result = modb.Save(head,
ModelObjectConvert<MsChFee>.ToModelObjectList(FinanceFeeList),
ModelObjectConvert<MsChFee>.ToModelObjectList(FinanceFeeDelList)
);
if (result.Success == true) FinanceDAL.SaveBank(head.F_NO, FinanceBankList);
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = FinanceDAL.GetData("F_NO='" + head.F_NO + "'","")
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult AuditSave(string opstatus, string data, string FinanceFee,string FinanceBank)
{
Financemb head = JsonConvert.Deserialize<Financemb>(data);
var FinanceFeeList = JsonConvert.Deserialize<List<MsChFee>>(FinanceFee);
var FinanceFeeDelList = JsonConvert.Deserialize<List<MsChFee>>("");
var FinanceBankList = JsonConvert.Deserialize<List<FinanceBank>>(FinanceBank);
if (opstatus == "add")
{
head.DbOperationType = DbOperationType.DbotIns;
head.ModelUIStatus = "I";
head.F_NO = PubSysDAL.GetBillNo("0206"); //获取GID
}
else if (opstatus == "edit")
{
head.DbOperationType = DbOperationType.DbotUpd;
head.ModelUIStatus = "E";
}
else
{
head.DbOperationType = DbOperationType.DbotDel;
}
head.F_STATUS = "已融出";
if (head.STARTDATE == "") head.STARTDATE = null;
if (head.ENDDATE == "") head.ENDDATE = null;
if (head.BANKENDDATE == "") head.BANKENDDATE = null;
var modb = new ModelObjectRepository();
DBResult result = modb.Save(head,
ModelObjectConvert<MsChFee>.ToModelObjectList(FinanceFeeList),
ModelObjectConvert<MsChFee>.ToModelObjectList(FinanceFeeDelList)
);
if (result.Success == true) FinanceDAL.SaveBank(head.F_NO, FinanceBankList);
//if (result.Success == true) FinanceDAL.SaveFinanceFee(head,Convert.ToString(Session["USERID"]));
//if (result.Success == true) FinanceDAL.CreateBankFee(head.F_NO, FinanceBankList,Convert.ToString(Session["USERID"]));
if (result.Success == true) FinanceDAL.AuditFinancelStatus(head.F_NO);
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = FinanceDAL.GetData("F_NO='" + head.F_NO + "'", "")
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
//融资的业务
public ContentResult GetFinanceBody(int start, int limit, string condition, string sort = "")
{
var _condition = condition;
List<FinanceBodymb> list = FinanceDAL.GetFinanceList(_condition, sort);
var listpage = list.Skip(start).Take(limit);
var json = JsonConvert.Serialize
(new { Success = true, Message = "查询成功", totalCount = list.Count, data = listpage.ToList() });
return new ContentResult() { Content = json };
}
#region 查询待融资的业务
public ContentResult GetBodyList(string condition)
{
var _condition = condition;
List<FinanceTradeBody> list = FinanceDAL.GetBodyList(_condition);
var json = JsonConvert.Serialize
(new { Success = true, Message = "查询成功", totalCount = list.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetBodyAddList(string condition)
{
var _condition = condition;
List<FinanceTradeBody> list = FinanceDAL.GetBodyAddList(_condition);
var json = JsonConvert.Serialize
(new { Success = true, Message = "查询成功", totalCount = list.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult AddBill(string billno, string addbody)
{
var bodyList = JsonConvert.Deserialize<List<FinanceTradeBody>>(addbody);
var result = new DBResult();
if (bodyList != null)
{
result = FinanceDAL.AddBill(billno, bodyList);
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult DelBill(string data, string billno)
{
var bodyList = JsonConvert.Deserialize<List<FinanceTradeBody>>(data);
DBResult result = FinanceDAL.DelBill(billno,bodyList);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#endregion
#region 提交和撤销融资申请
public ContentResult SubmitAudit(string bill)
{
DBResult result = FinanceDAL.SubmitAudit(Convert.ToString(Session["USERID"]), bill);
var json = JsonConvert.Serialize(result);
return new ContentResult() { Content = json };
}
public ContentResult SubmitAuditBack(string bill)
{
DBResult result = FinanceDAL.SubmitAuditBack( Convert.ToString(Session["USERID"]), bill);
var json = JsonConvert.Serialize(result);
return new ContentResult() { Content = json };
}
public ContentResult SubmitAuditList(string bills)
{
DBResult result = FinanceDAL.SubmitAuditList( Convert.ToString(Session["USERID"]), bills);
var json = JsonConvert.Serialize(result);
return new ContentResult() { Content = json };
}
public ContentResult SubmitAuditBackList(string bills)
{
DBResult result = FinanceDAL.SubmitAuditBackList( Convert.ToString(Session["USERID"]), bills);
var json = JsonConvert.Serialize(result);
return new ContentResult() { Content = json };
}
#endregion
#region 银行明细
public ContentResult GetBankList(string condition)
{
var _condition = condition;
List<FinanceBank> list = FinanceDAL.GetBankList(_condition);
var json = JsonConvert.Serialize
(new { Success = true, Message = "查询成功", totalCount = list.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult DeleteBank(string F_NO, string data)
{
int iResult = 0;
var result = new DBResult();
if (data != "" || data != null)
{
iResult = FinanceDAL.DeleteBank(data);
}
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 GetBankStlData(string handle, string condition)
{
FinanceBodymb head = null;
if (handle == "edit")
{
var _condition = condition;
List<FinanceBodymb> list = FinanceDAL.GetFinanceList(_condition, "");
if (list.Count > 0)
head = list[0];
}
if (head == null)
{
head = new FinanceBodymb();
head.GID = Guid.NewGuid().ToString();
head.OP = Convert.ToString(Session["USERID"]);
head.OPREF = Convert.ToString(Session["SHOWNAME"]);
head.F_TYPE = "3";
}
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", data = head });
return new ContentResult() { Content = json };
}
public ContentResult SaveBankStl(string opstatus, string data)
{
FinanceBodymb head = JsonConvert.Deserialize<FinanceBodymb>(data);
if (opstatus == "add")
{
head.DbOperationType = DbOperationType.DbotIns;
head.ModelUIStatus = "I";
head.F_NO = PubSysDAL.GetBillNo("0206"); //获取GID
}
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 jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = FinanceDAL.GetFinanceData("F_NO='" + head.F_NO + "'", "")
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult DeleteBankStl(string data)
{
var head = JsonConvert.Deserialize<FinanceBodymb>(data);
var BSNO = head.F_NO;
var modb = new ModelObjectDB();
DBResult result = modb.Delete(head);
if (result.Success == true)
{
var dataList = FinanceDAL.GetBankStlDetailList(" d.F_NO='" + BSNO + "'","");
result = FinanceDAL.DelBankStlBill(BSNO, dataList);
if (dataList != null)
{
foreach (var enumValue in dataList)
{
FinanceDAL.p_update_Finance(enumValue.F_NO);
}
}
}
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult AddBankStlBill(string billno, string addbody)
{
var bodyList = JsonConvert.Deserialize<List<Financemb>>(addbody);
var result = new DBResult();
if (bodyList != null)
{
result = FinanceDAL.AddBankStlBill(billno, bodyList);
if (result.Success == true) {
if (bodyList != null)
{
foreach (var enumValue in bodyList)
{
FinanceDAL.p_update_Finance(enumValue.F_NO);
}
}
}
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult DelBankStlBill(string data, string billno)
{
var bodyList = JsonConvert.Deserialize<List<Financemb>>(data);
DBResult result = FinanceDAL.DelBankStlBill(billno, bodyList);
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult GetAddBankFinalList(int start, int limit, string condition, string sort)
{
var _condition = condition;
List<Financemb> list = FinanceDAL.GetAddBankFinalList(_condition, sort);
var listpage = list.Skip(start).Take(limit);
var json = JsonConvert.Serialize
(new { Success = true, Message = "查询成功", totalCount = list.Count, data = listpage.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetBankStlDetailList(int start, int limit, string condition, string sort)
{
var _condition = condition;
List<Financemb> list = FinanceDAL.GetBankStlDetailList(_condition, sort);
var listpage = list.Skip(start).Take(limit);
var json = JsonConvert.Serialize
(new { Success = true, Message = "查询成功", totalCount = list.Count, data = listpage.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult SubmitBankStl(string bill,string body)
{
var head = JsonConvert.Deserialize<FinanceBodymb>(bill);
var bodyList = JsonConvert.Deserialize<List<Financemb>>(body);
DBResult result = FinanceDAL.SubmitBankStl(head,bodyList,Convert.ToString(Session["USERID"]));
var json = JsonConvert.Serialize(result);
return new ContentResult() { Content = json };
}
public ContentResult SubmitBackBankStl(string bill)
{
var head = JsonConvert.Deserialize<FinanceBodymb>(bill);
DBResult result = FinanceDAL.SubmitBackBankStl(head);
var json = JsonConvert.Serialize(result);
return new ContentResult() { Content = json };
}
#endregion
#region 增加业务到import_finance_body
public ContentResult SaveBody(string F_NO, string body)
{
var bodyList = JsonConvert.Deserialize<List<FinanceBodymb>>(body);
var result = new DBResult();
if (bodyList != null)
{
result = FinanceDAL.SaveBody(F_NO,bodyList,false);
if (result.Success) { FinanceDAL.p_update_Finance(F_NO); }
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public ContentResult CreateBodyFee(string F_NO, string body)
{
var bodyList = JsonConvert.Deserialize<List<FinanceBodymb>>(body);
var result = new DBResult();
if (bodyList != null)
{
var iresult = FinanceDAL.CreateBodyFee(F_NO, bodyList, Convert.ToString(Session["USERID"]));
if (iresult == 1) result=FinanceDAL.SaveBody(F_NO, bodyList, true);
if (result.Success) { FinanceDAL.p_update_Finance(F_NO); }
}
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
public int AddFinance(string F_NO, string feesql)
{
var strSql = new StringBuilder();
strSql.Append(" insert into import_finance_body select newid() GID, '" + F_NO + "' as F_NO,contractno from import_main where " + feesql );
//strSql.Append(" where " + feesql);
return setAddFinance(strSql);//ExecuteNonQuery
}
private static int setAddFinance(StringBuilder strSql)
{
var _count = 0;
Database db = DatabaseFactory.CreateDatabase();
_count = db.ExecuteNonQuery(CommandType.Text, strSql.ToString());
return _count;
}
#endregion
#region 从import_finance_body删除业务
public ContentResult DeleteBody(string F_NO, string data)
{
int iResult = 0;
var bodyList = data;
var result = new DBResult();
if (bodyList != "" || bodyList != null)
{
iResult = FinanceDAL.DeleteBody(bodyList);
}
if (iResult == 1)
{
FinanceDAL.p_update_Finance(F_NO);
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) };
}
private static int setDelFinance(StringBuilder strSql)
{
var _count = 0;
Database db = DatabaseFactory.CreateDatabase();
_count = db.ExecuteNonQuery(CommandType.Text, strSql.ToString());
return _count;
}
#endregion
#region 参照部分
#endregion
}
}